2014-07-07 21:03:50 +04:00
|
|
|
from helper import unittest, PillowTestCase
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
Image.USE_CFFI_ACCESS = False
|
|
|
|
|
2014-01-06 09:36:13 +04:00
|
|
|
|
2012-10-16 00:26:38 +04:00
|
|
|
def color(mode):
|
|
|
|
bands = Image.getmodebands(mode)
|
|
|
|
if bands == 1:
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return tuple(range(1, bands+1))
|
|
|
|
|
2013-07-01 02:42:19 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
class TestImageGetPixel(PillowTestCase):
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def check(self, mode, c=None):
|
|
|
|
if not c:
|
|
|
|
c = color(mode)
|
2014-06-03 14:02:44 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
# check putpixel
|
|
|
|
im = Image.new(mode, (1, 1), None)
|
|
|
|
im.putpixel((0, 0), c)
|
|
|
|
self.assertEqual(
|
|
|
|
im.getpixel((0, 0)), c,
|
|
|
|
"put/getpixel roundtrip failed for mode %s, color %s" % (mode, c))
|
2013-12-20 09:38:31 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
# check inital color
|
|
|
|
im = Image.new(mode, (1, 1), c)
|
|
|
|
self.assertEqual(
|
|
|
|
im.getpixel((0, 0)), c,
|
|
|
|
"initial color failed for mode %s, color %s " % (mode, color))
|
2013-12-20 09:38:31 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_basic(self):
|
|
|
|
for mode in ("1", "L", "LA", "I", "I;16", "I;16B", "F",
|
|
|
|
"P", "PA", "RGB", "RGBA", "RGBX", "CMYK", "YCbCr"):
|
|
|
|
self.check(mode)
|
2013-12-20 09:38:31 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_signedness(self):
|
|
|
|
# see https://github.com/python-pillow/Pillow/issues/452
|
|
|
|
# pixelaccess is using signed int* instead of uint*
|
|
|
|
for mode in ("I;16", "I;16B"):
|
|
|
|
self.check(mode, 2**15-1)
|
|
|
|
self.check(mode, 2**15)
|
|
|
|
self.check(mode, 2**15+1)
|
|
|
|
self.check(mode, 2**16-1)
|
2014-06-03 14:02:44 +04:00
|
|
|
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
2013-07-01 02:42:19 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
# End of file
|