Esempio n. 1
0
 def write(self, fp, **kwargs):
     written = write_fmt(fp, '3h', *self.shadows)
     written += write_fmt(fp, '3h', *self.midtones)
     written += write_fmt(fp, '3h', *self.highlights)
     written += write_fmt(fp, 'B', self.luminosity)
     written += write_padding(fp, written, 4)
     return written
Esempio n. 2
0
    def write(self, fp, padding=1, **kwargs):
        written = write_fmt(fp, '4sI', self.kind.value, self.version)
        written += write_pascal_string(fp, self.uuid, 'macroman', padding=1)
        written += write_unicode_string(fp, self.filename)
        written += write_fmt(fp, '4s4sQB', self.filetype, self.creator,
                             len(self.data) if self.data is not None else 0,
                             self.open_file is not None)
        if self.open_file is not None:
            written += self.open_file.write(fp, padding=1)

        if self.kind == LinkedLayerType.EXTERNAL:
            written += self.linked_file.write(fp, padding=1)
            if self.version > 3:
                written += write_fmt(fp, 'I4Bd', *self.timestamp)
            written += write_fmt(fp, 'Q', self.filesize)
            if self.version > 2:
                written += write_bytes(fp, self.data)
        elif self.kind == LinkedLayerType.ALIAS:
            written += write_fmt(fp, '8x')
        if self.kind == LinkedLayerType.DATA:
            written += write_bytes(fp, self.data)

        if self.child_id is not None:
            written += write_unicode_string(fp, self.child_id)
        if self.mod_time is not None:
            written += write_fmt(fp, 'd', self.mod_time)
        if self.lock_state is not None:
            written += write_fmt(fp, 'B', self.lock_state)

        if self.kind == LinkedLayerType.EXTERNAL and self.version == 2:
            written += write_bytes(fp, self.data)

        written += write_padding(fp, written, padding)
        return written
Esempio n. 3
0
 def write(self, fp, padding=4):
     written = 0
     for item in self:
         written += write_fmt(fp, 'H', item.selector.value)
         written += item.write(fp)
     written += write_padding(fp, written, padding)
     return written
 def write(self, fp, **kwargs):
     written = write_fmt(fp, '2H', self.version, len(self))
     for key in self:
         written += write_fmt(fp, '4s4s', b'8BIM', key.value)
         written += write_length_block(fp, lambda f: self[key].write(f))
     written += write_padding(fp, written, 4)
     return written
Esempio n. 5
0
 def write(self, fp, padding=4, **kwargs):
     written = 0
     for item in self:
         written += write_length_block(fp, lambda f: write_bytes(f, item),
                                       fmt='Q')
     written += write_padding(fp, written, padding)
     return written
Esempio n. 6
0
 def _write_body(self, fp):
     written = 0
     if self.overlay_color is not None:
         written = write_fmt(fp, '5H', *self.overlay_color)
         written += write_fmt(fp, 'HB', self.opacity, self.kind.value)
         written += write_padding(fp, written, 4)
     logger.debug('writing global layer mask info, len=%d' % (written))
     return written
Esempio n. 7
0
 def write(self, fp, padding=4, **kwargs):
     written = write_fmt(fp, '4sI', self.kind, self.version)
     written += write_pascal_string(fp, self.uuid, 'macroman', padding=1)
     written += write_fmt(fp, '4I', self.page, self.total_pages,
                          self.anti_alias, self.layer_type.value)
     written += write_fmt(fp, '8d', *self.transform)
     written += self.warp.write(fp, padding=1)
     written += write_padding(fp, written, padding)
     return written
Esempio n. 8
0
 def write(self, fp, **kwargs):
     written = write_fmt(fp, '2HI', self.major_version, self.minor_version,
                         len(self))
     for item in self:
         data = item.tobytes()
         written += write_fmt(fp, 'I', len(data) + 4)
         written += write_bytes(fp, data)
     written += write_padding(fp, written, 4)
     return written
Esempio n. 9
0
 def write(self, fp, **kwargs):
     written = write_fmt(fp, 'HBx', self.version, self.enable)
     written += write_fmt(fp, '3h', *self.colorization)
     written += write_fmt(fp, '3h', *self.master)
     for item in self.items:
         written += write_fmt(fp, '4h', *item[0])
         written += write_fmt(fp, '3h', *item[1])
     written += write_padding(fp, written, 4)
     return written
Esempio n. 10
0
 def write(self, fp, **kwargs):
     written = write_fmt(fp, 'H', self.version)
     if self.version == 3:
         written += write_fmt(fp, '3I', *self.xyz)
     else:
         written += write_fmt(fp, 'H4H', self.color_space,
                              *self.color_components)
     written += write_fmt(fp, 'IB', self.density, self.luminosity)
     written += write_padding(fp, written, 4)
     return written
Esempio n. 11
0
 def write(self, fp, padding=4, **kwargs):
     written = write_fmt(fp, 'H6d', self.version, *self.transform)
     written += write_fmt(fp, 'H', self.text_version)
     written += self.text_data.write(fp, padding=1)
     written += write_fmt(fp, 'H', self.warp_version)
     written += self.warp.write(fp, padding=1)
     written += write_fmt(fp, '4i', self.left, self.top, self.right,
                          self.bottom)
     written += write_padding(fp, written, padding)
     return written
Esempio n. 12
0
 def _write_body(self, fp, encoding, version, padding):
     start_pos = fp.tell()
     written = write_fmt(fp, 'h', self.layer_count)
     if self.layer_records:
         self._update_channel_length()
         written += self.layer_records.write(fp, encoding, version)
     logger.debug('  wrote layer records, len=%d' % (fp.tell() - start_pos))
     if self.channel_image_data:
         written += self.channel_image_data.write(fp)
     # Seems the padding size here is different between Photoshop and GIMP.
     written += write_padding(fp, written, padding)
     return written
Esempio n. 13
0
    def _write_extra(self, fp, encoding, version):
        written = 0
        if self.mask_data:
            written += self.mask_data.write(fp)
        else:
            written += write_fmt(fp, 'I', 0)

        written += self.blending_ranges.write(fp)
        written += write_pascal_string(fp, self.name, encoding, padding=4)
        written += self.tagged_blocks.write(fp, version, padding=1)
        written += write_padding(fp, written, 2)
        return written
Esempio n. 14
0
    def write(self, fp, **kwargs):
        written = write_fmt(fp, 'H', self.version)
        for index in range(29):
            written += self[index].write(fp)

        if self.extra_version is not None:
            written += write_fmt(fp, '4sH', b'Lvls', self.extra_version)
            written += write_fmt(fp, 'H', len(self))
            for index in range(29, len(self)):
                written += self[index].write(fp)

        written += write_padding(fp, written, 4)
        return written
Esempio n. 15
0
    def write(self, fp, **kwargs):
        written = write_fmt(fp, 'BHI', self.is_map, self.version,
                            self.count_map)
        if self.is_map:
            written += sum(write_fmt(fp, '256B', *item) for item in self.data)
        else:
            for points in self.data:
                written += write_fmt(fp, 'H', len(points))
                written += sum(write_fmt(fp, '2H', *item) for item in points)

        if self.extra is not None:
            written += self.extra.write(fp)

        written += write_padding(fp, written, 4)
        return written
Esempio n. 16
0
 def write(self, fp, **kwargs):
     written = write_fmt(fp, 'H2B', self.version, self.is_reversed,
                         self.is_dithered)
     written += write_unicode_string(fp, self.name)
     written += write_fmt(fp, 'H', len(self.color_stops))
     written += sum(stop.write(fp) for stop in self.color_stops)
     written += write_fmt(fp, 'H', len(self.transparency_stops))
     written += sum(stop.write(fp) for stop in self.transparency_stops)
     written += write_fmt(fp, '4HI2HIH', self.expansion, self.interpolation,
                          self.length, self.mode, self.random_seed,
                          self.show_transparency, self.use_vector_color,
                          self.roughness, self.color_model)
     written += write_fmt(fp, '4H', *self.minimum_color)
     written += write_fmt(fp, '4H', *self.maximum_color)
     written += write_fmt(fp, '2x')
     written += write_padding(fp, written, 4)
     return written
Esempio n. 17
0
    def _write_body(self, fp):
        written = write_fmt(fp, '4iB', self.top, self.left, self.bottom, self.right, self.background_color)
        written += self.flags.write(fp)

        # if self.real_flags is None and self.parameters is None:
        #     written += write_fmt(fp, '2x')
        #     assert written == 20

        if self.real_flags:
            written += self.real_flags.write(fp)
            written += write_fmt(fp, 'B4i', self.real_background_color, self.real_top, self.real_left, self.real_bottom,
                                 self.real_right)

        if self.flags.parameters_applied and self.parameters:
            written += self.parameters.write(fp)

        written += write_padding(fp, written, 4)
        return written
Esempio n. 18
0
 def write(self, fp, padding=4, **kwargs):
     written = write_fmt(fp, '4sI', self.kind, self.version)
     written += self.data.write(fp, padding=1)
     written += write_padding(fp, written, padding)
     return written
Esempio n. 19
0
 def write(self, fp, padding=4, **kwargs):
     written = write_fmt(fp, 'HI', self.version, self.data_version)
     written += self._write_body(fp)
     written += write_padding(fp, written, padding)
     return written
Esempio n. 20
0
 def write(self, fp, padding=4, **kwargs):
     written = write_fmt(fp, 'H3f', *attr.astuple(self))
     written += write_padding(fp, written, padding)
     return written