2014-01-05 22:41:25 +04:00
|
|
|
from tester import *
|
|
|
|
|
|
|
|
from PIL import Image, PyAccess
|
|
|
|
|
|
|
|
import test_image_putpixel as put
|
|
|
|
import test_image_getpixel as get
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
import cffi
|
|
|
|
except:
|
|
|
|
skip()
|
|
|
|
|
|
|
|
Image.USE_CFFI_ACCESS = True
|
|
|
|
|
|
|
|
def test_put():
|
|
|
|
put.test_sanity()
|
|
|
|
|
|
|
|
def test_get():
|
2014-01-07 11:25:41 +04:00
|
|
|
get.test_basic()
|
|
|
|
get.test_signedness()
|
2014-01-05 22:41:25 +04:00
|
|
|
|
2014-01-06 09:18:53 +04:00
|
|
|
def _test_get_access(im):
|
|
|
|
""" Do we get the same thing as the old pixel access """
|
2014-01-05 22:41:25 +04:00
|
|
|
|
2014-01-06 09:18:53 +04:00
|
|
|
""" Using private interfaces, forcing a capi access and a pyaccess for the same image """
|
|
|
|
caccess = im.im.pixel_access(False)
|
|
|
|
access = PyAccess.new(im, False)
|
|
|
|
|
|
|
|
w,h = im.size
|
|
|
|
for x in range(0,w,10):
|
|
|
|
for y in range(0,h,10):
|
2014-01-07 11:25:41 +04:00
|
|
|
assert_equal(access[(x,y)], caccess[(x,y)])
|
2014-01-06 09:18:53 +04:00
|
|
|
|
|
|
|
def test_get_vs_c():
|
|
|
|
_test_get_access(lena('RGB'))
|
|
|
|
_test_get_access(lena('RGBA'))
|
|
|
|
_test_get_access(lena('L'))
|
2014-01-07 10:51:31 +04:00
|
|
|
_test_get_access(lena('LA'))
|
2014-01-06 09:18:53 +04:00
|
|
|
_test_get_access(lena('1'))
|
|
|
|
_test_get_access(lena('P'))
|
2014-01-07 10:51:31 +04:00
|
|
|
#_test_get_access(lena('PA')) # PA -- how do I make a PA image???
|
2014-01-09 08:23:20 +04:00
|
|
|
_test_get_access(lena('F'))
|
|
|
|
|
2014-01-07 11:25:41 +04:00
|
|
|
im = Image.new('I;16', (10,10), 40000)
|
|
|
|
_test_get_access(im)
|
|
|
|
im = Image.new('I;16L', (10,10), 40000)
|
|
|
|
_test_get_access(im)
|
|
|
|
im = Image.new('I;16B', (10,10), 40000)
|
|
|
|
_test_get_access(im)
|
2014-01-09 08:23:20 +04:00
|
|
|
|
|
|
|
|
2014-01-06 09:18:53 +04:00
|
|
|
|
|
|
|
def _test_set_access(im, color):
|
|
|
|
""" Are we writing the correct bits into the image? """
|
|
|
|
|
|
|
|
""" Using private interfaces, forcing a capi access and a pyaccess for the same image """
|
|
|
|
caccess = im.im.pixel_access(False)
|
|
|
|
access = PyAccess.new(im, False)
|
|
|
|
|
|
|
|
w,h = im.size
|
|
|
|
for x in range(0,w,10):
|
|
|
|
for y in range(0,h,10):
|
|
|
|
access[(x,y)] = color
|
2014-01-07 11:25:41 +04:00
|
|
|
assert_equal(color, caccess[(x,y)])
|
2014-01-06 09:18:53 +04:00
|
|
|
|
|
|
|
def test_set_vs_c():
|
|
|
|
_test_set_access(lena('RGB'), (255, 128,0) )
|
|
|
|
_test_set_access(lena('RGBA'), (255, 192, 128, 0))
|
|
|
|
_test_set_access(lena('L'), 128)
|
2014-01-07 10:51:31 +04:00
|
|
|
_test_set_access(lena('LA'), (128,128))
|
2014-01-06 09:18:53 +04:00
|
|
|
_test_set_access(lena('1'), 255)
|
|
|
|
_test_set_access(lena('P') , 128)
|
2014-01-07 10:51:31 +04:00
|
|
|
##_test_set_access(i, (128,128)) #PA -- undone how to make
|
2014-01-09 08:23:20 +04:00
|
|
|
_test_set_access(lena('F'), 1024.0)
|
|
|
|
|
2014-01-07 11:25:41 +04:00
|
|
|
im = Image.new('I;16', (10,10), 40000)
|
|
|
|
_test_set_access(im, 45000)
|
|
|
|
im = Image.new('I;16L', (10,10), 40000)
|
|
|
|
_test_set_access(im, 45000)
|
|
|
|
im = Image.new('I;16B', (10,10), 40000)
|
|
|
|
_test_set_access(im, 45000)
|
2014-01-06 09:18:53 +04:00
|
|
|
|