Fredrik Lundh is sharing code with you

Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.

Don't show this again

effbot / pil-2009-raclette http://effbot.org/zone/pil-index.htm

Work repository for PIL 1.1.7 and beyond. The "default" branch should be fairly solid, the other branches less so. For production use, see the pil-117 repository.

Clone this repository (size: 1.6 MB): HTTPS / SSH
hg clone https://bitbucket.org/effbot/pil-2009-raclette
hg clone ssh://hg@bitbucket.org/effbot/pil-2009-raclette

pil-2009-raclette / Tests / test_imagechops.py

from tester import *

from PIL import Image
from PIL import ImageChops

def test_sanity():
    pass # FIXME

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))