pytoshop.codecs¶
Coders and decoders for the various compression types in PSD.
-
pytoshop.codecs.
compress_constant_raw
(fd, value, width, rows, depth, version)[source]¶ Write a virtual image containing a constant to a raw stream.
Parameters: - fd (file-like object) – Writable file-like object, open in binary mode.
- value (int) – The constant value in the generated virtual image.
- width (int) – The width of the image, in pixels.
- rows (int) – The number of rows in the image, in pixels. This is
height * num_channels
. - depth (enums.ColorDepth) – The bit depth of the image. See
enums.ColorDepth
. - version (enums.Version) – The version of the PSD file. See
enums.Version
.
-
pytoshop.codecs.
compress_constant_rle
(fd, value, width, rows, depth, version)[source]¶ Write a virtual image containing a constant to a runlength-encoded stream.
Parameters: - fd (file-like object) – Writable file-like object, open in binary mode.
- value (int) – The constant value in the generated virtual image.
- width (int) – The width of the image, in pixels.
- rows (int) – The number of rows in the image, in pixels. This is
height * num_channels
. - depth (enums.ColorDepth) – The bit depth of the image. See
enums.ColorDepth
. - version (enums.Version) – The version of the PSD file. See
enums.Version
.
-
pytoshop.codecs.
compress_constant_zip
(fd, value, width, rows, depth, version)[source]¶ Write a virtual image containing a constant to a zip compressed stream.
Parameters: - fd (file-like object) – Writable file-like object, open in binary mode.
- value (int) – The constant value in the generated virtual image.
- width (int) – The width of the image, in pixels.
- rows (int) – The number of rows in the image, in pixels. This is
height * num_channels
. - depth (enums.ColorDepth) – The bit depth of the image. See
enums.ColorDepth
. - version (enums.Version) – The version of the PSD file. See
enums.Version
.
-
pytoshop.codecs.
compress_constant_zip_prediction
(fd, value, width, rows, depth, version)[source]¶ Write a virtual image containing a constant to a zip with prediction compressed stream.
Parameters: - fd (file-like object) – Writable file-like object, open in binary mode.
- value (int) – The constant value in the generated virtual image.
- width (int) – The width of the image, in pixels.
- rows (int) – The number of rows in the image, in pixels. This is
height * num_channels
. - depth (enums.ColorDepth) – The bit depth of the image. See
enums.ColorDepth
. - version (enums.Version) – The version of the PSD file. See
enums.Version
.
-
pytoshop.codecs.
compress_image
(fd, image, compression, shape, num_channels, depth, version)[source]¶ Write an image with the given compression type.
Parameters: - fd (file-like object) – Writable file-like object, open in binary mode.
- image (2-D numpy array or scalar) – The image to compress. Must be unsigned integer with 8, 16 or
32 bits. If depth is 1, the array should have dtype
uint8
with a byte per pixel. If a scalar, a “virtual” image will be used as if the image contained only that constant value. - compression (enums.Compression) – The compression format to use. See
enums.Compression
. - shape (2-tuple of int) – The shape of the image
(height, width)
. If image is an array, the shape is used to confirm it has the correct shape. If image is a constant, shape is used to generate the virtual constant image. - num_channels (int) – The number of color channels in the image. If image is an array, the num_channels is used to confirm it has the correct number of channels. If image is a constant, num_channels is used to generate the virtual constant image.
- depth (enums.ColorDepth) – The bit depth of the image. See
enums.ColorDepth
. If image is an array, the depth is used to confirm it has the correct number of channels. If image is a constant, depth is used to generate the virtual constant image. - version (enums.Version) – The version of the PSD file. See
enums.Version
.
-
pytoshop.codecs.
compress_raw
(fd, image, depth, version)[source]¶ Write a Numpy array to raw bytes in a file.
Parameters: - fd (file-like object) – Writable file-like object, open in binary mode.
- image (2-D numpy array) – The image to compress. Must be unsigned integer with 8, 16 or
32 bits. If depth is 1, the array should have dtype
uint8
with a byte per pixel. - depth (enums.ColorDepth) – The bit depth of the image. See
enums.ColorDepth
. - version (enums.Version) – The version of the PSD file. See
enums.Version
.
-
pytoshop.codecs.
compress_rle
(fd, image, depth, version)[source]¶ Write a Numpy array to a run length encoded stream.
Parameters: - fd (file-like object) – Writable file-like object, open in binary mode.
- image (2-D numpy array) – The image to compress. Must be unsigned integer with 8, 16 or
32 bits. If depth is 1, the array should have dtype
uint8
with a byte per pixel. - depth (enums.ColorDepth) – The bit depth of the image. See
enums.ColorDepth
. - version (enums.Version) – The version of the PSD file. See
enums.Version
.
-
pytoshop.codecs.
compress_zip
(fd, image, depth, version)[source]¶ Write a Numpy array to a zip (zlib) compressed stream.
Parameters: - fd (file-like object) – Writable file-like object, open in binary mode.
- image (2-D numpy array) – The image to compress. Must be unsigned integer with 8, 16 or
32 bits. If depth is 1, the array should have dtype
uint8
with a byte per pixel. - depth (enums.ColorDepth) – The bit depth of the image. See
enums.ColorDepth
. - version (enums.Version) – The version of the PSD file. See
enums.Version
.
-
pytoshop.codecs.
compress_zip_prediction
(fd, image, depth, version)[source]¶ Write a Numpy array to a zip (zlib) with prediction compressed stream.
Not supported for 1- or 32-bit images.
Parameters: - fd (file-like object) – Writable file-like object, open in binary mode.
- image (2-D numpy array) – The image to compress. Must be unsigned integer with 8, 16 or
32 bits. If depth is 1, the array should have dtype
uint8
with a byte per pixel. - depth (enums.ColorDepth) – The bit depth of the image. See
enums.ColorDepth
. - version (enums.Version) – The version of the PSD file. See
enums.Version
.
-
pytoshop.codecs.
decompress_image
(data, compression, shape, depth, version)[source]¶ Decompress data with the given compression.
Parameters: - data (bytes) – The raw bytes from the file.
- compression (enums.Compression) – The compression format to use. See
enums.Compression
. - shape (2-tuple of int) – The shape of the resulting array,
(height, width)
. - depth (enums.ColorDepth) – The bit depth of the image. See
enums.ColorDepth
. - version (enums.Version) – The version of the PSD file. See
enums.Version
.
Returns: image – The image data as a Numpy array.
Return type: numpy array
-
pytoshop.codecs.
decompress_raw
(data, shape, depth, version)[source]¶ Converts raw data to a Numpy array.
Parameters: - data (bytes) – The raw bytes from the file.
- shape (2-tuple of int) – The shape of the resulting array,
(height, width)
. - depth (enums.ColorDepth) – The bit depth of the image. See
enums.ColorDepth
. - version (enums.Version) – The version of the PSD file. See
enums.Version
.
Returns: image – The image data as a Numpy array. If depth is 1, the array is expanded to
uint8
with a byte per pixel.Return type: numpy array
-
pytoshop.codecs.
decompress_rle
(data, shape, depth, version)[source]¶ Decompress run length encoded data.
Parameters: - data (bytes) – The raw bytes from the file.
- shape (2-tuple of int) – The shape of the resulting array,
(height, width)
. - depth (enums.ColorDepth) – The bit depth of the image. See
enums.ColorDepth
. - version (enums.Version) – The version of the PSD file. See
enums.Version
.
Returns: image – The image data as a Numpy array. If depth is 1, the array is expanded to
uint8
with a byte per pixel.Return type: numpy array
-
pytoshop.codecs.
decompress_zip
(data, shape, depth, version)[source]¶ Decompress zip (zlib) encoded data.
Parameters: - data (bytes) – The raw bytes from the file.
- shape (2-tuple of int) – The shape of the resulting array,
(height, width)
. - depth (enums.ColorDepth) – The bit depth of the image. See
enums.ColorDepth
. - version (enums.Version) – The version of the PSD file. See
enums.Version
.
Returns: image – The image data as a Numpy array. If depth is 1, the array is expanded to
uint8
with a byte per pixel.Return type: numpy array
-
pytoshop.codecs.
decompress_zip_prediction
(data, shape, depth, version)[source]¶ Decompress zip (zlib) with prediction encoded data.
Not supported for 1- or 32-bit images.
Parameters: - data (bytes) – The raw bytes from the file.
- shape (2-tuple of int) – The shape of the resulting array,
(height, width)
. - depth (enums.ColorDepth) – The bit depth of the image. See
enums.ColorDepth
. - version (enums.Version) – The version of the PSD file. See
enums.Version
.
Returns: image – The image data as a Numpy array. If depth is 1, the array is expanded to
uint8
with a byte per pixel.Return type: numpy array