mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-05-30 02:33:07 +03:00
Merge pull request #2274 from wiredfool/issue_2258
Fix for 2 bit palette corruption #2258
This commit is contained in:
commit
03b9d718fc
|
@ -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(b'\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()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* The Python Imaging Library.
|
||||
* $Id$
|
||||
*
|
||||
|
@ -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