def set_data(self, size, data, depth, compression=0, version=1): self.data = compress(data, compression, size[0], size[1], depth, version) self.depth = int(depth) self.pixel_depth = int(depth) self.rectangle = (0, 0, int(size[1]), int(size[0])) self.compression = Compression(compression) self.is_written = True
def set_data(self, data, header): """Set raw data and compress. :param data: list of raw data bytes corresponding channels. :param compression: compression type, see :py:class:`~psd_tools.constants.Compression`. :param header: See :py:class:`~psd_tools.psd.header.FileHeader`. :return: length of compressed data. """ self.data = compress(b''.join(data), self.compression, header.width, header.height * header.channels, header.depth, header.version) return len(self.data)
def set_data(self, data, width, height, depth, version=1): """Set raw channel data and compress to store. :param data: raw data bytes to write. :param compression: compression type, see :py:class:`~psd_tools.constants.Compression`. :param width: width. :param height: height. :param depth: bit depth of the pixel. :param version: psd file version. """ self.data = compress(data, self.compression, width, height, depth, version) return len(self.data)
def test_compress_decompress_fail(data, width, height, depth): decoded = decompress(data, Compression.ZIP_WITH_PREDICTION, width, height, depth) encoded = compress(decoded, Compression.ZIP_WITH_PREDICTION, width, height, depth) assert data == encoded
def test_compress_decompress(data, kind, width, height, depth, version): compressed = compress(data, kind, width, height, depth, version) output = decompress(compressed, kind, width, height, depth, version) assert output == data, 'output=%r, expected=%r' % (output, data)