mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Fix for #2258, 2 bit palette images corrupted
This commit is contained in:
parent
b3f8b5fa7d
commit
88c43b61b7
|
@ -1,6 +1,6 @@
|
|||
from helper import unittest, PillowTestCase
|
||||
|
||||
from PIL import ImagePalette
|
||||
from PIL import ImagePalette, Image
|
||||
|
||||
ImagePalette = ImagePalette.ImagePalette
|
||||
|
||||
|
@ -125,6 +125,19 @@ class TestImagePalette(PillowTestCase):
|
|||
self.assertEqual(rawmode, "RGB")
|
||||
self.assertEqual(data_in, data_out)
|
||||
|
||||
def test_2bit_palette(self):
|
||||
# issue #2258, 2 bit palettes are corrupted.
|
||||
outfile = self.tempfile('temp.png')
|
||||
|
||||
rgb = b'\x00' * 2 + b'\x01' * 2 + b'\x02' * 2
|
||||
img = Image.frombytes('P', (6, 1), rgb)
|
||||
img.putpalette('\xFF\x00\x00' '\x00\xFF\x00' '\x00\x00\xFF') # RGB
|
||||
img.save(outfile, format='PNG')
|
||||
|
||||
reloaded = Image.open(outfile)
|
||||
|
||||
self.assert_image_equal(img, reloaded)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -194,6 +194,7 @@ packP2(UINT8* out, const UINT8* in, int pixels)
|
|||
case 2:
|
||||
out[0] = (in[0] << 6) |
|
||||
((in[1] & 3) << 4);
|
||||
break;
|
||||
case 1:
|
||||
out[0] = (in[0] << 6);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user