mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-11 17:56:18 +03:00
Working 1 bit sun_rle raster file
This commit is contained in:
parent
5df2851f85
commit
e43c91cf1c
BIN
Tests/images/sunraster.im1
Normal file
BIN
Tests/images/sunraster.im1
Normal file
Binary file not shown.
BIN
Tests/images/sunraster.im1.png
Normal file
BIN
Tests/images/sunraster.im1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
|
@ -21,5 +21,11 @@ class TestFileSun(PillowTestCase):
|
|||
lambda: SunImagePlugin.SunImageFile(invalid_file))
|
||||
|
||||
|
||||
|
||||
def test_im1(self):
|
||||
im = Image.open('Tests/images/sunraster.im1')
|
||||
target = Image.open('Tests/images/sunraster.im1.png')
|
||||
self.assert_image_equal(im, target)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -26,7 +26,6 @@ ImagingSunRleDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
|
|||
UINT8* ptr;
|
||||
UINT8 extra_data = 0;
|
||||
UINT8 extra_bytes = 0;
|
||||
int ct_bytes = 0;
|
||||
|
||||
ptr = buf;
|
||||
|
||||
|
@ -47,7 +46,6 @@ ImagingSunRleDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
|
|||
|
||||
/* Literal 0x80 (2 bytes) */
|
||||
n = 1;
|
||||
ct_bytes += n;
|
||||
|
||||
state->buffer[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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user