Repository navigation
PyTurboJPEG 2.6.1 improves RGB JPEG encoding and fixes issues in error handling, buffer reuse, ICC profile handling, and source distribution packaging.
- RGB JPEG encoding:
jpeg_colorspace=TJCS_RGBnow accepts all supported non-grayscale subsampling modes, including the defaultTJSAMP_422. UseTJSAMP_444when all three channels need full spatial resolution. - Batch cropping: Fixed background placement when
crop_multiple()extends the canvas of a subsampled RGB JPEG. - Error handling: Fatal errors following a warning now raise
OSErrorinstead of returning incomplete image data or empty JPEG output. Recognized recoverable warnings still emitUserWarning; unrecognized native warning messages now raiseOSError. - Buffer reuse: Added checks to reject unsafe memory overlap between input and
dstinencode()anddecode()before writing. - ICC profile sizing: Corrected destination buffer estimates to include APP2 segment headers. Added an optional
icc_profileargument tobuffer_size(). - ICC profile limits: Profiles exceeding 16,707,345 bytes—the capacity of 255 ICC APP2 segments—now raise
ValueError. - Memory management: Fixed a native memory leak when copying an extracted ICC profile into Python fails.
- Packaging and tests: Included missing test helpers and fixtures in source distributions, added CI coverage for running tests from the built sdist, and expanded regression coverage.
When preallocating a destination buffer for ICC encoding, use:
dst = bytearray(jpeg.buffer_size(image, icc_profile=profile))
result, written = jpeg.encode(image, dst=dst, icc_profile=profile)Adding only len(profile) to the ordinary buffer size does not account for ICC segment headers. Pass the same subsampling to buffer_size() and encode(); for lossless encoding, size the buffer with TJSAMP_444.
Validated with libjpeg-turbo 3.0.0, 3.1.3, and 3.2.0. ICC embedding and extraction continue to require libjpeg-turbo 3.1 or later.