~ubuntu-branches/ubuntu/wily/python-imaging/wily

« back to all changes in this revision

Viewing changes to Tests/test_imagechops.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-01-31 20:49:20 UTC
  • mfrom: (27.1.1 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20130131204920-b5zshy6vgfvdionl
Tags: 1.1.7+1.7.8-1ubuntu1
Rewrite build dependencies to allow cross builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from tester import *
 
2
 
 
3
from PIL import Image
 
4
from PIL import ImageChops
 
5
 
 
6
def test_sanity():
 
7
 
 
8
    im = lena("L")
 
9
 
 
10
    ImageChops.constant(im, 128)
 
11
    ImageChops.duplicate(im)
 
12
    ImageChops.invert(im)
 
13
    ImageChops.lighter(im, im)
 
14
    ImageChops.darker(im, im)
 
15
    ImageChops.difference(im, im)
 
16
    ImageChops.multiply(im, im)
 
17
    ImageChops.screen(im, im)
 
18
 
 
19
    ImageChops.add(im, im)
 
20
    ImageChops.add(im, im, 2.0)
 
21
    ImageChops.add(im, im, 2.0, 128)
 
22
    ImageChops.subtract(im, im)
 
23
    ImageChops.subtract(im, im, 2.0)
 
24
    ImageChops.subtract(im, im, 2.0, 128)
 
25
 
 
26
    ImageChops.add_modulo(im, im)
 
27
    ImageChops.subtract_modulo(im, im)
 
28
 
 
29
    ImageChops.blend(im, im, 0.5)
 
30
    ImageChops.composite(im, im, im)
 
31
 
 
32
    ImageChops.offset(im, 10)
 
33
    ImageChops.offset(im, 10, 20)
 
34
 
 
35
def test_logical():
 
36
 
 
37
    def table(op, a, b):
 
38
        out = []
 
39
        for x in (a, b):
 
40
            imx = Image.new("1", (1, 1), x)
 
41
            for y in (a, b):
 
42
                imy = Image.new("1", (1, 1), y)
 
43
                out.append(op(imx, imy).getpixel((0, 0)))
 
44
        return tuple(out)
 
45
 
 
46
    assert_equal(table(ImageChops.logical_and, 0, 1), (0, 0, 0, 255))
 
47
    assert_equal(table(ImageChops.logical_or, 0, 1), (0, 255, 255, 255))
 
48
    assert_equal(table(ImageChops.logical_xor, 0, 1), (0, 255, 255, 0))
 
49
 
 
50
    assert_equal(table(ImageChops.logical_and, 0, 128), (0, 0, 0, 255))
 
51
    assert_equal(table(ImageChops.logical_or, 0, 128), (0, 255, 255, 255))
 
52
    assert_equal(table(ImageChops.logical_xor, 0, 128), (0, 255, 255, 0))
 
53
 
 
54
    assert_equal(table(ImageChops.logical_and, 0, 255), (0, 0, 0, 255))
 
55
    assert_equal(table(ImageChops.logical_or, 0, 255), (0, 255, 255, 255))
 
56
    assert_equal(table(ImageChops.logical_xor, 0, 255), (0, 255, 255, 0))