mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-14 11:26:27 +03:00
Reorg+add test for #452
This commit is contained in:
parent
404b245d89
commit
598d97daff
|
@ -9,49 +9,43 @@ def color(mode):
|
||||||
else:
|
else:
|
||||||
return tuple(range(1, bands+1))
|
return tuple(range(1, bands+1))
|
||||||
|
|
||||||
def test_pixel():
|
|
||||||
|
|
||||||
def pixel(mode):
|
|
||||||
|
def check(mode, c=None):
|
||||||
|
if not c:
|
||||||
c = color(mode)
|
c = color(mode)
|
||||||
|
|
||||||
|
#check putpixel
|
||||||
im = Image.new(mode, (1, 1), None)
|
im = Image.new(mode, (1, 1), None)
|
||||||
im.putpixel((0, 0), c)
|
im.putpixel((0, 0), c)
|
||||||
return im.getpixel((0, 0))
|
assert_equal(im.getpixel((0, 0)), c,
|
||||||
|
"put/getpixel roundtrip failed for mode %s, color %s" %
|
||||||
|
(mode, c))
|
||||||
|
|
||||||
assert_equal(pixel("1"), 1)
|
# check inital color
|
||||||
assert_equal(pixel("L"), 1)
|
im = Image.new(mode, (1, 1), c)
|
||||||
assert_equal(pixel("LA"), (1, 2))
|
assert_equal(im.getpixel((0, 0)), c,
|
||||||
assert_equal(pixel("I"), 1)
|
"initial color failed for mode %s, color %s " %
|
||||||
assert_equal(pixel("I;16"), 1)
|
(mode, color))
|
||||||
assert_equal(pixel("I;16B"), 1)
|
|
||||||
assert_equal(pixel("F"), 1.0)
|
|
||||||
assert_equal(pixel("P"), 1)
|
|
||||||
assert_equal(pixel("PA"), (1, 2))
|
|
||||||
assert_equal(pixel("RGB"), (1, 2, 3))
|
|
||||||
assert_equal(pixel("RGBA"), (1, 2, 3, 4))
|
|
||||||
assert_equal(pixel("RGBX"), (1, 2, 3, 4))
|
|
||||||
assert_equal(pixel("CMYK"), (1, 2, 3, 4))
|
|
||||||
assert_equal(pixel("YCbCr"), (1, 2, 3))
|
|
||||||
|
|
||||||
def test_image():
|
def test_basic():
|
||||||
|
for mode in ("1", "L", "LA", "I", "I;16", "I;16B", "F",
|
||||||
|
"P", "PA", "RGB", "RGBA", "RGBX", "CMYK","YCbCr"):
|
||||||
|
check(mode)
|
||||||
|
|
||||||
def pixel(mode):
|
def test_signedness():
|
||||||
im = Image.new(mode, (1, 1), color(mode))
|
# see https://github.com/python-imaging/Pillow/issues/452
|
||||||
return im.getpixel((0, 0))
|
# pixelaccess is using signed int* instead of uint*
|
||||||
|
for mode in ("I;16", "I;16B"):
|
||||||
|
check(mode, 2**15-1)
|
||||||
|
check(mode, 2**15)
|
||||||
|
check(mode, 2**15+1)
|
||||||
|
check(mode, 2**16-1)
|
||||||
|
|
||||||
assert_equal(pixel("1"), 1)
|
check("I", 2**31-1)
|
||||||
assert_equal(pixel("L"), 1)
|
check("I", 2**31)
|
||||||
assert_equal(pixel("LA"), (1, 2))
|
check("I", 2**31+1)
|
||||||
assert_equal(pixel("I"), 1)
|
check("I", 2**32-1)
|
||||||
assert_equal(pixel("I;16"), 1)
|
|
||||||
assert_equal(pixel("I;16B"), 1)
|
|
||||||
assert_equal(pixel("F"), 1.0)
|
|
||||||
assert_equal(pixel("P"), 1)
|
|
||||||
assert_equal(pixel("PA"), (1, 2))
|
|
||||||
assert_equal(pixel("RGB"), (1, 2, 3))
|
|
||||||
assert_equal(pixel("RGBA"), (1, 2, 3, 4))
|
|
||||||
assert_equal(pixel("RGBX"), (1, 2, 3, 4))
|
|
||||||
assert_equal(pixel("CMYK"), (1, 2, 3, 4))
|
|
||||||
assert_equal(pixel("YCbCr"), (1, 2, 3))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user