Пример #1
0
def test_copy_layer_from():
    with TemporaryDirectory('_src') as srcdir, TemporaryDirectory('_dst') as dstdir:
        src_1 = GimpFile(os.path.join(srcdir, 'file1.xcf'))\
            .create('Background', np.zeros(shape=(1, 1), dtype=np.uint8))\
            .add_layer_from_numpy('White', np.ones(shape=(1, 1), dtype=np.uint8)*255)
        src_2 = GimpFile(os.path.join(srcdir, 'file2.xcf'))\
            .create('Background', np.zeros(shape=(1, 1), dtype=np.uint8)) \
            .add_layer_from_numpy('White', np.ones(shape=(1, 1), dtype=np.uint8)*255)

        dst_1 = GimpFile(os.path.join(dstdir, 'file1.xcf')) \
            .create('Background', np.zeros(shape=(1, 1), dtype=np.uint8)) \
            .add_layer_from_numpy('White', np.zeros(shape=(1, 1), dtype=np.uint8)*255)
        dst_2 = GimpFile(os.path.join(dstdir, 'file2.xcf')) \
            .create('Background', np.zeros(shape=(1, 1), dtype=np.uint8))

        src_collection = GimpFileCollection([src_1.get_file(), src_2.get_file()])
        dst_collection = GimpFileCollection([dst_1.get_file(), dst_2.get_file()])

        dst_collection.copy_layer_from(src_collection, 'White', layer_position=1, timeout_in_seconds=10)

        assert np.all(dst_1.layer_to_numpy('White') == 255)
        assert ['Background', 'White'] == dst_1.layer_names()
        assert 'White' in dst_2.layer_names()
        assert np.all(dst_2.layer_to_numpy('White') == 255)
        assert ['Background', 'White'] == dst_2.layer_names()
Пример #2
0
def test_merge_mask_layer_from_with_mask_not_available_in_files_in_both_collections_and_foreground_color_black():
    with TemporaryDirectory('_src') as srcdir, TemporaryDirectory('_dst') as dstdir:
        src_1 = GimpFile(os.path.join(srcdir, 'file1.xcf')) \
            .create_empty(2, 1, GimpFileType.GRAY)

        dst_1 = GimpFile(os.path.join(dstdir, 'file1.xcf')) \
            .create_empty(2, 1, GimpFileType.GRAY)

        src_collection = GimpFileCollection([src_1.get_file()])
        dst_collection = GimpFileCollection([dst_1.get_file()])

        dst_collection.merge_mask_layer_from(src_collection, 'Mask', MaskForegroundColor.BLACK, timeout_in_seconds=10)

        assert np.all(dst_1.layer_to_numpy('Mask') == [[255], [255]])
        assert ['Mask'] == dst_1.layer_names()
Пример #3
0
def test_remove_layers_by_name():
    data = np.array([[0, 255]], dtype=np.uint8)
    with TemporaryDirectory('_files') as dir:
        file1 = GimpFile(os.path.join(dir, 'file1.xcf')) \
            .create('Background', data) \
            .add_layer_from_numpy('Layer 1', data) \
            .add_layer_from_numpy('Layer 2', data) \
            .add_layer_from_numpy('Layer 3', data)
        file2 = GimpFile(os.path.join(dir, 'file2.xcf')) \
            .create('Background', data) \
            .add_layer_from_numpy('Layer 1', data) \
            .add_layer_from_numpy('Layer 2', data)

        collection = GimpFileCollection([file1.get_file(), file2.get_file()])
        collection.remove_layers_by_name(['Layer 1', 'Layer 3'], timeout_in_seconds=10)

        assert file1.layer_names() == ['Layer 2', 'Background']
        assert file2.layer_names() == ['Layer 2', 'Background']
Пример #4
0
def test_merge_mask_layer_from_with_color():
    with TemporaryDirectory('_src') as srcdir, TemporaryDirectory('_dst') as dstdir:
        src_1 = GimpFile(os.path.join(srcdir, 'file1.xcf'))\
            .create('Mask', np.array([[[255, 255, 255], [0, 0, 0]]], dtype=np.uint8))

        dst_1 = GimpFile(os.path.join(dstdir, 'file1.xcf')) \
            .create('Mask', np.array([[[0, 0, 0], [255, 255, 255]]], dtype=np.uint8))
        dst_2 = GimpFile(os.path.join(dstdir, 'file2.xcf')) \
            .create('Mask', np.array([[[0, 0, 0], [255, 255, 255]]], dtype=np.uint8))

        src_collection = GimpFileCollection([src_1.get_file()])
        dst_collection = GimpFileCollection([dst_1.get_file(), dst_2.get_file()])

        dst_collection.merge_mask_layer_from(src_collection, 'Mask', MaskForegroundColor.WHITE, timeout_in_seconds=10)

        assert np.all(dst_1.layer_to_numpy('Mask') == [[255, 255, 255], [255, 255, 255]])
        assert ['Mask'] == dst_1.layer_names()
        assert 'Mask' in dst_2.layer_names()
        assert np.all(dst_2.layer_to_numpy('Mask') == [[0, 0, 0], [255, 255, 255]])
        assert ['Mask'] == dst_2.layer_names()