コード例 #1
0
def test_channel_image_data():
    check_write_read(ChannelImageData(), layer_records=LayerRecords())

    layer_records = LayerRecords(
        [LayerRecord(channel_info=[
            ChannelInfo(id=0, length=18),
            ChannelInfo(id=-1, length=18),
        ])])
    channel_data_list = ChannelDataList([
        ChannelData(0, b'\xff' * 16),
        ChannelData(0, b'\xff' * 16),
    ])
    check_write_read(ChannelImageData([channel_data_list]), layer_records=layer_records)
コード例 #2
0
def test_channel_data_list():
    channel_info = [
        ChannelInfo(id=0, length=20),
        ChannelInfo(id=1, length=20),
        ChannelInfo(id=2, length=20),
        ChannelInfo(id=-1, length=20),
    ]
    channel_items = [
        ChannelData(0, b'\x00' * 18),
        ChannelData(0, b'\x00' * 18),
        ChannelData(0, b'\x00' * 18),
        ChannelData(0, b'\x00' * 18),
    ]
    check_write_read(ChannelDataList(channel_items), channel_info=channel_info)
コード例 #3
0
def test_layer_info():
    check_write_read(LayerInfo())

    layer_records = LayerRecords(
        [LayerRecord(channel_info=[
            ChannelInfo(id=0, length=18),
            ChannelInfo(id=-1, length=18),
        ])])
    channel_image_data = ChannelImageData(
        [ChannelDataList([
            ChannelData(0, b'\xff' * 16),
            ChannelData(0, b'\xff' * 16),
        ])])

    check_write_read(LayerInfo(1, layer_records, channel_image_data))
コード例 #4
0
def test_channel_data_data(compression, data, width, height, depth, version):
    channel = ChannelData(compression)
    channel.set_data(data, width, height, depth, version)
    output = channel.get_data(width, height, depth, version)
    assert output == data, 'output=%r, expected=%r' % (output, data)
コード例 #5
0
def test_channel_data():
    check_write_read(ChannelData(data=b''), length=0)
    check_write_read(ChannelData(data=b'\xFF' * 8), length=8)
コード例 #6
0
def test_channel_data():
    check_write_read(ChannelData())
コード例 #7
0
content_layer = find_content_layer(psd)

# pixel layer and content layer are required
# background layer is optional
if pixel_layer is None or content_layer is None:
    print("Error: Invalid PSD. PSD lacks device pixel layer or content smart object layer.")
    exit(1)

if not content_layer.has_mask():
    # create artifical mask from rectangular area of content layer
    left, top, right, bottom = content_layer.bbox
    width, height = content_layer.width, content_layer.height
    depth, version = psd.depth, psd.version
    # artificial channeldata, channelinfo, maskdata mimicking ones from iPhone11
    data = b'\xff' * (width * height)
    channel_data = ChannelData(compression=Compression.RLE)
    channel_data.set_data(data, width, height, depth, version)
    channel_info = ChannelInfo(id=ChannelID.USER_LAYER_MASK, length=channel_data._length)
    mask_data = MaskData(
        top=top,
        left=left,
        bottom=bottom,
        right=right,
        background_color=0
    )
else:
    # find mask channel info/data
    channel_index, channel_info = next((
        (i, info) 
        for i, info in enumerate(content_layer._record.channel_info)
        if info.id == ChannelID.USER_LAYER_MASK