예제 #1
0
def decode_prediction(data, w, h, bytes_per_pixel):
    if bytes_per_pixel == 1:
        arr = be_array_from_bytes("B", data)
        arr = _delta_decode(arr, 2**8, w, h)

    elif bytes_per_pixel == 2:
        arr = be_array_from_bytes("H", data)
        arr = _delta_decode(arr, 2**16, w, h)

    elif bytes_per_pixel == 4:

        # 32bit channels are also encoded using delta encoding,
        # but it make no sense to apply delta compression to bytes.
        # It is possible to apply delta compression to 2-byte or 4-byte
        # words, but it seems it is not the best way either.
        # In PSD, each 4-byte item is split into 4 bytes and these
        # bytes are packed together: "123412341234" becomes "111222333444";
        # delta compression is applied to the packed data.
        #
        # So we have to (a) decompress data from the delta compression
        # and (b) recombine data back to 4-byte values.

        arr = array.array(str("B"), data)
        arr = _delta_decode(arr, 2**8, w * 4, h)
        arr = _restore_byte_order(arr, w, h)
        arr = array.array(str("f"), arr)
    else:
        return None

    return arr.tostring()
예제 #2
0
def decode_prediction(data, w, h, bytes_per_pixel):
    if bytes_per_pixel == 1:
        arr = be_array_from_bytes("B", data)
        arr = _delta_decode(arr, 2**8, w, h)

    elif bytes_per_pixel == 2:
        arr = be_array_from_bytes("H", data)
        arr = _delta_decode(arr, 2**16, w, h)

    elif bytes_per_pixel == 4:

        # 32bit channels are also encoded using delta encoding,
        # but it make no sense to apply delta compression to bytes.
        # It is possible to apply delta compression to 2-byte or 4-byte
        # words, but it seems it is not the best way either.
        # In PSD, each 4-byte item is split into 4 bytes and these
        # bytes are packed together: "123412341234" becomes "111222333444";
        # delta compression is applied to the packed data.
        #
        # So we have to (a) decompress data from the delta compression
        # and (b) recombine data back to 4-byte values.

        arr = array.array(str("B"), data)
        arr = _delta_decode(arr, 2**8, w*4, h)
        arr = _restore_byte_order(arr, w, h)
        arr = array.array(str("f"), arr)
    else:
        return None

    return arr.tostring()
def decode_prediction(data, w, h, depth):
    if depth == 8:
        arr = be_array_from_bytes('B', data)
        arr = _delta_decode(arr, 0x100, w, h)
    elif depth == 16:
        arr = be_array_from_bytes('H', data)
        arr = _delta_decode(arr, 0x10000, w, h)
    elif depth == 32:
        arr = array.array('B', data)
        arr = _delta_decode(arr, 0x100, w * 4, h)
        arr = _restore_byte_order(arr, w, h)
    else:
        raise ValueError('Invalid pixel size %d' % (depth))

    return getattr(arr, 'tobytes', getattr(arr, 'tostring'))()
예제 #4
0
def _decode_layer_groups_enabled_id(data):
    return be_array_from_bytes("B", data)
예제 #5
0
def _decode_layer_selection(data):
    return be_array_from_bytes("I", data[2:])
예제 #6
0
def _decode_layer_group_info(data):
    return be_array_from_bytes("H", data)
예제 #7
0
def _from_32bit_raw(data, size):
    pixels = be_array_from_bytes("f", data)
    im = Image.new("F", size)
    im.putdata(pixels, 255, 0)
    return im
예제 #8
0
def _decode_layer_group_info(data):
    return be_array_from_bytes("H", data)
예제 #9
0
def _decode_layer_groups_enabled_id(data):
    return be_array_from_bytes("B", data)
예제 #10
0
def _decode_layer_selection(data):
    return be_array_from_bytes("I", data[2:])
예제 #11
0
def _from_32bit_raw(data, size):
    pixels = be_array_from_bytes("f", data)
    return pixels
예제 #12
0
def _from_32bit_raw(data, size):
    pixels = be_array_from_bytes("f", data)
    im = Image.new("F", size)
    im.putdata(pixels, 255, 0)
    return im