This commit is contained in:
hugovk 2014-06-05 12:30:59 +03:00
parent 45fd3b8bf5
commit 1f94ea1fc6
3 changed files with 0 additions and 133 deletions

View File

@ -1,15 +0,0 @@
from tester import *
from PIL import Image
def test_sanity():
assert_exception(ValueError, lambda: lena().tobitmap())
assert_no_exception(lambda: lena().convert("1").tobitmap())
im1 = lena().convert("1")
bitmap = im1.tobitmap()
assert_true(isinstance(bitmap, bytes))
assert_image_equal(im1, fromstring(bitmap))

View File

@ -1,56 +0,0 @@
from tester import *
from PIL import Image
from PIL import ImageChops
def test_sanity():
im = lena("L")
ImageChops.constant(im, 128)
ImageChops.duplicate(im)
ImageChops.invert(im)
ImageChops.lighter(im, im)
ImageChops.darker(im, im)
ImageChops.difference(im, im)
ImageChops.multiply(im, im)
ImageChops.screen(im, im)
ImageChops.add(im, im)
ImageChops.add(im, im, 2.0)
ImageChops.add(im, im, 2.0, 128)
ImageChops.subtract(im, im)
ImageChops.subtract(im, im, 2.0)
ImageChops.subtract(im, im, 2.0, 128)
ImageChops.add_modulo(im, im)
ImageChops.subtract_modulo(im, im)
ImageChops.blend(im, im, 0.5)
ImageChops.composite(im, im, im)
ImageChops.offset(im, 10)
ImageChops.offset(im, 10, 20)
def test_logical():
def table(op, a, b):
out = []
for x in (a, b):
imx = Image.new("1", (1, 1), x)
for y in (a, b):
imy = Image.new("1", (1, 1), y)
out.append(op(imx, imy).getpixel((0, 0)))
return tuple(out)
assert_equal(table(ImageChops.logical_and, 0, 1), (0, 0, 0, 255))
assert_equal(table(ImageChops.logical_or, 0, 1), (0, 255, 255, 255))
assert_equal(table(ImageChops.logical_xor, 0, 1), (0, 255, 255, 0))
assert_equal(table(ImageChops.logical_and, 0, 128), (0, 0, 0, 255))
assert_equal(table(ImageChops.logical_or, 0, 128), (0, 255, 255, 255))
assert_equal(table(ImageChops.logical_xor, 0, 128), (0, 255, 255, 0))
assert_equal(table(ImageChops.logical_and, 0, 255), (0, 0, 0, 255))
assert_equal(table(ImageChops.logical_or, 0, 255), (0, 255, 255, 255))
assert_equal(table(ImageChops.logical_xor, 0, 255), (0, 255, 255, 0))

View File

@ -1,62 +0,0 @@
from tester import *
from PIL import Image
from PIL import ImageMath
def pixel(im):
if hasattr(im, "im"):
return "%s %r" % (im.mode, im.getpixel((0, 0)))
else:
if isinstance(im, type(0)):
return int(im) # hack to deal with booleans
print(im)
A = Image.new("L", (1, 1), 1)
B = Image.new("L", (1, 1), 2)
F = Image.new("F", (1, 1), 3)
I = Image.new("I", (1, 1), 4)
images = {"A": A, "B": B, "F": F, "I": I}
def test_sanity():
assert_equal(ImageMath.eval("1"), 1)
assert_equal(ImageMath.eval("1+A", A=2), 3)
assert_equal(pixel(ImageMath.eval("A+B", A=A, B=B)), "I 3")
assert_equal(pixel(ImageMath.eval("A+B", images)), "I 3")
assert_equal(pixel(ImageMath.eval("float(A)+B", images)), "F 3.0")
assert_equal(pixel(ImageMath.eval("int(float(A)+B)", images)), "I 3")
def test_ops():
assert_equal(pixel(ImageMath.eval("-A", images)), "I -1")
assert_equal(pixel(ImageMath.eval("+B", images)), "L 2")
assert_equal(pixel(ImageMath.eval("A+B", images)), "I 3")
assert_equal(pixel(ImageMath.eval("A-B", images)), "I -1")
assert_equal(pixel(ImageMath.eval("A*B", images)), "I 2")
assert_equal(pixel(ImageMath.eval("A/B", images)), "I 0")
assert_equal(pixel(ImageMath.eval("B**2", images)), "I 4")
assert_equal(pixel(ImageMath.eval("B**33", images)), "I 2147483647")
assert_equal(pixel(ImageMath.eval("float(A)+B", images)), "F 3.0")
assert_equal(pixel(ImageMath.eval("float(A)-B", images)), "F -1.0")
assert_equal(pixel(ImageMath.eval("float(A)*B", images)), "F 2.0")
assert_equal(pixel(ImageMath.eval("float(A)/B", images)), "F 0.5")
assert_equal(pixel(ImageMath.eval("float(B)**2", images)), "F 4.0")
assert_equal(pixel(ImageMath.eval("float(B)**33", images)), "F 8589934592.0")
def test_logical():
assert_equal(pixel(ImageMath.eval("not A", images)), 0)
assert_equal(pixel(ImageMath.eval("A and B", images)), "L 2")
assert_equal(pixel(ImageMath.eval("A or B", images)), "L 1")
def test_convert():
assert_equal(pixel(ImageMath.eval("convert(A+B, 'L')", images)), "L 3")
assert_equal(pixel(ImageMath.eval("convert(A+B, '1')", images)), "1 0")
assert_equal(pixel(ImageMath.eval("convert(A+B, 'RGB')", images)), "RGB (3, 3, 3)")
def test_compare():
assert_equal(pixel(ImageMath.eval("min(A, B)", images)), "I 1")
assert_equal(pixel(ImageMath.eval("max(A, B)", images)), "I 2")
assert_equal(pixel(ImageMath.eval("A == 1", images)), "I 1")
assert_equal(pixel(ImageMath.eval("A == 2", images)), "I 0")