Skip to content

PyTurboJPEG 2.6.1

Latest

Choose a tag to compare

@lilohuang lilohuang released this 24 Oct 05:24

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_RGB now accepts all supported non-grayscale subsampling modes, including the default TJSAMP_422. Use TJSAMP_444 when 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 OSError instead of returning incomplete image data or empty JPEG output. Recognized recoverable warnings still emit UserWarning; unrecognized native warning messages now raise OSError.
  • Buffer reuse: Added checks to reject unsafe memory overlap between input and dst in encode() and decode() before writing.
  • ICC profile sizing: Corrected destination buffer estimates to include APP2 segment headers. Added an optional icc_profile argument to buffer_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.