示例#1
0
 def read(cls, fp, **kwargs):
     kind = SectionDivider(read_fmt('I', fp)[0])
     signature, key = None, None
     if is_readable(fp, 8):
         signature = read_fmt('4s', fp)[0]
         assert signature == b'8BIM', 'Invalid signature %r' % signature
         key = BlendMode(read_fmt('4s', fp)[0])
     sub_type = None
     if is_readable(fp, 4):
         sub_type = read_fmt('I', fp)[0]
     return cls(kind, signature=signature, key=key, sub_type=sub_type)
示例#2
0
    def _read_body(cls, fp, encoding, version):
        layer_info = LayerInfo.read(fp, encoding, version)
        global_layer_mask_info = None
        if is_readable(fp):
            global_layer_mask_info = GlobalLayerMaskInfo.read(fp)

        tagged_blocks = None
        if is_readable(fp):
            # For some reason, global tagged blocks aligns 4 byte
            tagged_blocks = TaggedBlocks.read(fp, version=version, padding=4)

        return cls(layer_info, global_layer_mask_info, tagged_blocks)
示例#3
0
 def read(cls, fp, **kwargs):
     items = []
     while is_readable(fp, 8):
         data = read_length_block(fp, fmt='Q', padding=4)
         with io.BytesIO(data) as f:
             items.append(LinkedLayer.read(f))
     return cls(items)
示例#4
0
 def read(cls, fp):
     items = []
     while is_readable(fp, 26):
         selector = PathResourceID(read_fmt('H', fp)[0])
         kls = TYPES.get(selector)
         items.append(kls.read(fp))
     return cls(items)
示例#5
0
 def read(cls, fp, **kwargs):
     items = []
     while is_readable(fp, 4):
         data = read_length_block(fp, padding=4)
         with io.BytesIO(data) as f:
             items.append(Pattern.read(f))
     return cls(items)
示例#6
0
 def read(cls, fp):
     slice_id, group_id, origin = read_fmt('3I', fp)
     associated_id = read_fmt('I', fp)[0] if origin == 1 else None
     name = read_unicode_string(fp)
     slice_type = read_fmt('I', fp)[0]
     bbox = read_fmt('4I', fp)
     url = read_unicode_string(fp)
     target = read_unicode_string(fp)
     message = read_unicode_string(fp)
     alt_tag = read_unicode_string(fp)
     cell_is_html = read_fmt('?', fp)[0]
     cell_text = read_unicode_string(fp)
     horizontal_align, vertical_align = read_fmt('2I', fp)
     alpha, red, green, blue = read_fmt('4B', fp)
     data = None
     if is_readable(fp, 4):
         # There is no easy distinction between descriptor block and
         # next slice v6 item here...
         current_position = fp.tell()
         version = read_fmt('I', fp)[0]
         fp.seek(-4, 1)
         if version == 16:
             try:
                 data = DescriptorBlock.read(fp)
                 if data.classID == b'\x00\x00\x00\x00':
                     data = None
                     raise ValueError(data)
             except ValueError:
                 logger.debug('Failed to read DescriptorBlock')
                 fp.seek(current_position)
     return cls(slice_id, group_id, origin, associated_id, name, slice_type,
                bbox, url, target, message, alt_tag, cell_is_html,
                cell_text, horizontal_align, vertical_align, alpha, red,
                green, blue, data)
示例#7
0
 def read(cls, fp, version=1, padding=1):
     items = []
     while is_readable(fp, 8):  # len(signature) + len(key) = 8
         block = TaggedBlock.read(fp, version, padding)
         if block is None:
             break
         items.append((block.key, block))
     return cls(items)
示例#8
0
 def read(cls, fp, **kwargs):
     version = read_fmt('I', fp)[0]
     assert version in (1, 2, 3), 'Invalid version %d' % (version)
     items = []
     while is_readable(fp, 8):
         with io.BytesIO(read_length_block(fp, fmt='Q', padding=4)) as f:
             items.append(FilterEffect.read(f))
     return cls(version=version, items=items)
示例#9
0
 def read(cls, fp, **kwargs):
     uuid = read_pascal_string(fp, encoding='ascii', padding=1)
     version = read_fmt('I', fp)[0]
     assert version <= 1, 'Invalid version %d' % (version)
     with io.BytesIO(read_length_block(fp, fmt='Q')) as f:
         rectangle, depth, max_channels, channels = cls._read_body(f)
     # Documentation is incorrect here.
     extra = FilterEffectExtra.read(fp) if is_readable(fp) else None
     return cls(uuid, version, rectangle, depth, max_channels, channels, extra)
示例#10
0
    def _read_body(cls, fp):
        def read_channel_range(f):
            values = read_fmt("4H", f)
            return [values[0:2], values[2:4]]

        composite_ranges = read_channel_range(fp)
        channel_ranges = []
        while is_readable(fp, 8):
            channel_ranges.append(read_channel_range(fp))
        return cls(composite_ranges, channel_ranges)
示例#11
0
 def read(cls, fp, version=1, padding=1, end_pos=None):
     items = []
     while is_readable(fp, 8):  # len(signature) + len(key) = 8
         if end_pos is not None and fp.tell() >= end_pos:
             break
         block = TaggedBlock.read(fp, version, padding)
         if block is None:
             break
         items.append((block.key, block))
     return cls(items)
示例#12
0
    def read(cls, fp, version=1, padding=1):
        """Read the element from a file-like object.

        :param fp: file-like object
        :param version: psd file version
        :rtype: :py:class:`.TaggedBlocks`
        """
        items = []
        while is_readable(fp, 8):  # len(signature) + len(key) = 8
            block = TaggedBlock.read(fp, version, padding)
            if block is None:
                break
            items.append((block.key, block))
        return cls(items)
示例#13
0
    def read(cls, fp, **kwargs):
        version = read_fmt('H', fp)[0]
        assert version == 2, 'Invalid version %d' % (version)
        items = [LevelRecord.read(fp) for _ in range(29)]

        extra_version = None
        if is_readable(fp, 6):
            signature, extra_version = read_fmt('4sH', fp)
            assert signature == b'Lvls', 'Invalid signature %r' % (signature)
            assert extra_version == 3, 'Invalid extra version %d' % (
                extra_version)
            count = read_fmt('H', fp)[0]
            items += [LevelRecord.read(fp) for _ in range(count - 29)]

        return cls(version=version, extra_version=extra_version, items=items)
示例#14
0
 def _read_body(cls, fp, *args, **kwargs):
     items = []
     while is_readable(fp, 4):
         item = ImageResource.read(fp, *args, **kwargs)
         items.append((item.key, item))
     return cls(items)
示例#15
0
 def read(cls, fp, **kwargs):
     items = []
     while is_readable(fp):
         items.append(read_pascal_string(fp, 'macroman', padding=1))
     return cls(items)
示例#16
0
 def read(cls, fp, **kwargs):
     items = []
     while is_readable(fp, 8):
         items.append(read_length_block(fp, fmt='Q'))
     return cls(items)
示例#17
0
 def read(cls, fp, **kwargs):
     items = []
     while is_readable(fp, 4):
         items.append(read_fmt('I', fp)[0])
     return cls(items)
示例#18
0
 def read(cls, fp, **kwargs):
     items = []
     while is_readable(fp):
         items.append(read_unicode_string(fp))
     return cls(items)
示例#19
0
 def read(cls, fp, **kwargs):
     items = []
     while is_readable(fp, 18):
         items.append(HalftoneScreen.read(fp))
     return cls(items)
示例#20
0
 def read(cls, fp, **kwargs):
     items = []
     while is_readable(fp, 28):
         items.append(TransferFunction.read(fp))
     return cls(items)
示例#21
0
 def read(cls, fp, **kwargs):
     values = read_fmt('8?', fp)
     if is_readable(fp):
         values += read_fmt('?', fp)
     return cls(*values)