2014-07-07 21:03:50 +04:00
|
|
|
from helper import unittest, PillowTestCase, lena
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
class TestImagePutData(PillowTestCase):
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_sanity(self):
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
im1 = lena()
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
data = list(im1.getdata())
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
im2 = Image.new(im1.mode, im1.size, 0)
|
|
|
|
im2.putdata(data)
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
self.assert_image_equal(im1, im2)
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
# readonly
|
|
|
|
im2 = Image.new(im1.mode, im2.size, 0)
|
|
|
|
im2.readonly = 1
|
|
|
|
im2.putdata(data)
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
self.assertFalse(im2.readonly)
|
|
|
|
self.assert_image_equal(im1, im2)
|
|
|
|
|
|
|
|
def test_long_integers(self):
|
|
|
|
# see bug-200802-systemerror
|
|
|
|
def put(value):
|
|
|
|
im = Image.new("RGBA", (1, 1))
|
|
|
|
im.putdata([value])
|
|
|
|
return im.getpixel((0, 0))
|
|
|
|
self.assertEqual(put(0xFFFFFFFF), (255, 255, 255, 255))
|
|
|
|
self.assertEqual(put(0xFFFFFFFF), (255, 255, 255, 255))
|
|
|
|
self.assertEqual(put(-1), (255, 255, 255, 255))
|
|
|
|
self.assertEqual(put(-1), (255, 255, 255, 255))
|
|
|
|
if sys.maxsize > 2**32:
|
|
|
|
self.assertEqual(put(sys.maxsize), (255, 255, 255, 255))
|
|
|
|
else:
|
|
|
|
self.assertEqual(put(sys.maxsize), (255, 255, 255, 127))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
|
|
|
|
# End of file
|