mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Testing for p2la
This commit is contained in:
parent
12685ef7c1
commit
95de0b6d05
|
@ -123,6 +123,26 @@ class TestImageConvert(PillowTestCase):
|
|||
self.assertNotIn('transparency', p.info)
|
||||
p.save(f)
|
||||
|
||||
# ref https://github.com/python-pillow/Pillow/issues/1979
|
||||
|
||||
def test_p_la(self):
|
||||
def L(rgb):
|
||||
return int((rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000)
|
||||
|
||||
def convert_to_gray(im, pixel):
|
||||
if im.mode == 'P':
|
||||
color_id = im.getpixel(pixel)
|
||||
color = im.getpalette()[color_id * 3:(color_id+1)*3]
|
||||
return L(color)
|
||||
elif im.mode == 'LA':
|
||||
color = im.getpixel(pixel)
|
||||
return color[0]
|
||||
|
||||
im_p = hopper('P')
|
||||
im_la = im_p.convert('LA')
|
||||
self.assertEqual(convert_to_gray(im_p, (5, 5)),
|
||||
convert_to_gray(im_la, (5, 5)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue
Block a user