Merge pull request #2274 from wiredfool/issue_2258

Fix for 2 bit palette corruption #2258
This commit is contained in:
Hugo 2016-12-04 12:27:40 +02:00 committed by GitHub
commit 03b9d718fc
2 changed files with 226 additions and 212 deletions

View File

@ -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()

View File

@ -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);
}