예제 #1
0
def test_alpha_blend_normal_rgb_with_opaque_source():
    cb = util.fill((2, 2), [0, 128, 255])
    cs = util.fill((2, 2), [255, 128, 0, 1])
    cr = alpha_blend(cb, cs, _normal)

    expected = split_alpha(cs)[0]
    assert cr == expected
예제 #2
0
def test_alpha_blend_normal_opaque_backdrop_with_transparent_source():
    cb = util.fill((2, 2), [0, 128, 255, 1])
    cs = util.fill((2, 2), [255, 128, 0, 0])
    cr = alpha_blend(cb, cs, _normal)

    expected = split_alpha(cb)[0]
    assert cr == expected
예제 #3
0
def test_alpha_blend_call_blending(mocker):
    cb = util.fill((2, 2), [0, 128, 255, 1])
    cs = util.fill((2, 2), [255, 128, 0, 1])

    return_value, _ = split_alpha(cs)
    normal_stub = mocker.Mock(return_value=return_value)
    alpha_blend(cb, cs, normal_stub)

    # TODO: assert with parameters
    normal_stub.assert_called_once()
예제 #4
0
def test_normal2():
    cb = util.fill((2, 2), [255, 128, 0, 1.])
    cs_array = np.array([
        [[0, 128, 255, .25], [0, 255, 128, .5]],
        [[128, 255, 0, .75], [128, 0, 255, .1]],
    ],
                        dtype=np.uint8)
    cs = Image.fromarray(cs_array)

    actual = css.blending.normal(cb, cs)
    expected, _ = split_alpha(Image.alpha_composite(cb, cs))
    assert actual == expected
예제 #5
0
def test_split_alpha_unsupported_mode():
    im = Image.new('L', (2, 2), 128)
    with pytest.raises(ValueError):
        split_alpha(im)
예제 #6
0
def test_split_alpha_rgb():
    im = util.fill((2, 2), [0, 128, 255])
    rgb, a = split_alpha(im)
    assert id(rgb) == id(im)
    assert a is None
예제 #7
0
def test_split_alpha_rgba():
    im = util.fill((2, 2), [0, 128, 255, .5])
    rgb, a = split_alpha(im)
    assert rgb == util.fill((2, 2), [0, 128, 255])
    assert a == Image.new('L', (2, 2), 128)