From e43c91cf1c956022fac9c830032d5b3b03f1e6a7 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Sat, 19 Nov 2016 19:12:30 -0800 Subject: [PATCH] Working 1 bit sun_rle raster file --- Tests/images/sunraster.im1 | Bin 0 -> 2106 bytes Tests/images/sunraster.im1.png | Bin 0 -> 1774 bytes Tests/test_file_sun.py | 6 ++++++ libImaging/SunRleDecode.c | 26 +++++++++++++++++++++----- 4 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 Tests/images/sunraster.im1 create mode 100644 Tests/images/sunraster.im1.png diff --git a/Tests/images/sunraster.im1 b/Tests/images/sunraster.im1 new file mode 100644 index 0000000000000000000000000000000000000000..82c92bca923100c719a6dc039579e06953133ef5 GIT binary patch literal 2106 zcmaKt&2ig63`SRCW_VNyJf;ktWyuBPm}`2-EKA5GEu;>Wq7rn}L1X$o>~c*iwmcp{ z1n_<(ZZO4>0e-a|4->9@z_%}{p|Nl(gb$m_zgxF1&@r1mEyoa2sOydy` z0Y_q|E2^8OJ8CmcZ^Yzj8jZnuE>>A`_=f7Mc!1&onqu6VVqaiHRBAbO$%#`dP7`*T zfuqbs;v0$_Z>YXtUc!CB@PJ(x3rGrTwsDD~5+u3wP^#n)J;Et9Xq}*2Sy8hzc=B!7;u{Dc3G~dx>tYqs?@-oH1W`)O|;HniD_J+J}YRXXB0AmAFIj$hXJw zhVF5kBM>6-@*IL!oOr`3zU49h4ZBBRx%Aa$-zGro4mH=IdY%jwN#jn4nO=GN??4;_ zflf9~ItVr9Vq~%{nY~-Ym+qrGN; zpxi?zD@JoJ8Jt{jnaa9Qas|q6v@h5^sK)kbVXGIRcDkOO9o0VL?N}ieCC^K@D9xcn z36>^!QSzd+vZC%v3Ab^h-62=kUD=~iuF`tN+`vPu-ZfV5n_-zS%`T|uF|2~;r&RaU z=S;47Peqy2XLHUhmuk1xq1M*kAA8YZ>rP~O@?~6}N!>~odtR2foxoJD(}~ymleP8~ z;x_oWXFe`i9Qt`BmiLhUAzm5$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+O2P zw8buffer[state->x] = 0x80; @@ -60,7 +58,27 @@ ImagingSunRleDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) if (bytes < 3) break; - ct_bytes += n; + /* from (http://www.fileformat.info/format/sunraster/egff.htm) + + For example, a run of 100 pixels with the value of + 0Ah would encode as the values 80h 64h 0Ah. A + single pixel value of 80h would encode as the + values 80h 00h. The four unencoded bytes 12345678h + would be stored in the RLE stream as 12h 34h 56h + 78h. 100 pixels, n=100, not 100 pixels, n=99. + + But Wait! There's More! + (http://www.fileformat.info/format/sunraster/spec/598a59c4fac64c52897585d390d86360/view.htm) + + If the first byte is 0x80, and the second byte is + not zero, the record is three bytes long. The + second byte is a count and the third byte is a + value. Output (count+1) pixels of that value. + + 2 specs, same site, but Imagemagick and GIMP seem + to agree on the second one. + */ + n += 1; if (state->x + n > state->bytes) { extra_bytes = n; /* full value */ @@ -80,7 +98,6 @@ ImagingSunRleDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) /* Literal byte */ n = 1; - ct_bytes += n; state->buffer[state->x] = ptr[0]; @@ -103,7 +120,6 @@ ImagingSunRleDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) if (++state->y >= state->ysize) { /* End of file (errcode = 0) */ - printf("%d", ct_bytes); return -1; } }