2014-06-10 13:10:47 +04:00
|
|
|
from helper import unittest, PillowTestCase, tearDownModule, lena
|
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
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
class TestImagePutPixel(PillowTestCase):
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_sanity(self):
|
2013-07-01 02:42:19 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
im1 = lena()
|
|
|
|
im2 = Image.new(im1.mode, im1.size, 0)
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
for y in range(im1.size[1]):
|
|
|
|
for x in range(im1.size[0]):
|
|
|
|
pos = x, y
|
|
|
|
im2.putpixel(pos, im1.getpixel(pos))
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
self.assert_image_equal(im1, im2)
|
2013-07-01 02:42:19 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
im2 = Image.new(im1.mode, im1.size, 0)
|
|
|
|
im2.readonly = 1
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
for y in range(im1.size[1]):
|
|
|
|
for x in range(im1.size[0]):
|
|
|
|
pos = x, y
|
|
|
|
im2.putpixel(pos, im1.getpixel(pos))
|
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)
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
im2 = Image.new(im1.mode, im1.size, 0)
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
pix1 = im1.load()
|
|
|
|
pix2 = im2.load()
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
for y in range(im1.size[1]):
|
|
|
|
for x in range(im1.size[0]):
|
|
|
|
pix2[x, y] = pix1[x, y]
|
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
|
|
|
# see test_image_getpixel for more tests
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
|
|
|
|
# End of file
|