Esempio n. 1
0
def read(fp, encoding, depth):
    """
    Reads layers and masks information.
    """
    logger.debug('reading layers and masks information...')
    length = read_fmt("I", fp)[0]
    start_pos = fp.tell()

    logger.debug('length=%d, start_pos=%d', length, start_pos)

    layers = _read_layers(fp, encoding, depth)

    global_mask_info = None
    tagged_blocks = []

    remaining_length = length - (fp.tell() - start_pos)
    if remaining_length > 0:
        logger.debug('reading global mask info...')

        global_mask_info = _read_global_mask_info(fp)

        synchronize(fp) # hack hack hack
        remaining_length = length - (fp.tell() - start_pos)
        if remaining_length > 0:
            tagged_blocks = _read_layer_tagged_blocks(fp, remaining_length, 4)

            # remaining_length = length - (fp.tell() - start_pos)
            # if remaining_length > 0:
            #     fp.seek(remaining_length, 1)
            #     logger.debug('skipping %s bytes', remaining_length)

    return LayerAndMaskData(layers, global_mask_info, tagged_blocks)
Esempio n. 2
0
def read(fp, encoding, depth):
    """
    Reads layers and masks information.
    """
    logger.debug('reading layers and masks information...')
    length = read_fmt("I", fp)[0]
    start_pos = fp.tell()

    logger.debug('length=%d, start_pos=%d', length, start_pos)

    layers = _read_layers(fp, encoding, depth)

    global_mask_info = None
    tagged_blocks = []

    remaining_length = length - (fp.tell() - start_pos)
    if remaining_length > 0:
        logger.debug('reading global mask info...')

        global_mask_info = _read_global_mask_info(fp)

        synchronize(fp)  # hack hack hack
        remaining_length = length - (fp.tell() - start_pos)
        tagged_blocks = _read_layer_tagged_blocks(fp, remaining_length, 4)

        remaining_length = length - (fp.tell() - start_pos)
        if remaining_length > 0:
            fp.seek(remaining_length, 1)
            logger.debug('skipping %s bytes', remaining_length)

    return LayerAndMaskData(layers, global_mask_info, tagged_blocks)
Esempio n. 3
0
def read(fp, encoding, depth, version):
    """
    Reads layers and masks information.
    """
    if version == 1:
        length = read_fmt("I", fp)[0]
    elif version == 2:
        length = read_fmt("Q", fp)[0]
    start_pos = fp.tell()

    logger.debug('reading layers and masks information...')
    logger.debug('  length=%d, start_pos=%d', length, start_pos)

    global_mask_info = None
    tagged_blocks = []

    if length > 0:
        layers = _read_layers(fp, encoding, depth, version)

        remaining_length = length - (fp.tell() - start_pos)
        if remaining_length > 0:
            global_mask_info = _read_global_mask_info(fp)

            synchronize(fp)  # hack hack hack
            remaining_length = length - (fp.tell() - start_pos)

            logger.debug('reading tagged blocks...')
            logger.debug('  length=%d, start_pos=%d', remaining_length,
                         fp.tell())

            tagged_blocks = _read_layer_tagged_blocks(fp, remaining_length,
                                                      version, 4)

            remaining_length = length - (fp.tell() - start_pos)
            if remaining_length > 0:
                fp.seek(remaining_length, 1)
                logger.debug('skipping %s bytes', remaining_length)
    else:
        layers = _read_layers(fp, encoding, depth, version, 0)

    return LayerAndMaskData(layers, global_mask_info, tagged_blocks)
Esempio n. 4
0
def read(fp, encoding, depth):
    """
    Reads layers and masks information.
    """
    length = read_fmt("I", fp)[0]
    start_position = fp.tell()

    layers = _read_layers(fp, encoding, depth)

    # XXX: are tagged blocks really after the layers?
    # XXX: does global mask reading really work?
    global_mask_info = _read_global_mask_info(fp)

    consumed_bytes = fp.tell() - start_position
    synchronize(fp) # hack hack hack
    tagged_blocks = _read_layer_tagged_blocks(fp, length - consumed_bytes)

    consumed_bytes = fp.tell() - start_position
    fp.seek(length-consumed_bytes, 1)

    return LayerAndMaskData(layers, global_mask_info, tagged_blocks)