From de4bbac55eac877fb00052de73d714274b4fd37d Mon Sep 17 00:00:00 2001 From: DRC Date: Fri, 23 Aug 2024 12:48:01 -0400 Subject: [PATCH] TJCompressor.compress(): Fix lossls buf size calc --- ChangeLog.md | 5 +++++ java/org/libjpegturbo/turbojpeg/TJCompressor.java | 2 ++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index 6962f5f7..17558ff7 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -28,6 +28,11 @@ unless the `-precision` option was specified before the `-lossless` option. calling applications to generate 12-bit-per-sample arithmetic-coded lossy JPEG images using the TurboJPEG API. +5. Fixed an error ("Destination buffer is not large enough") that occurred when +attempting to generate a full-color lossless JPEG image using the TurboJPEG +Java API's `byte[] TJCompressor.compress()` method if the value of +`TJ.PARAM_SUBSAMP` was not `TJ.SAMP_444`. + 3.0.3 ===== diff --git a/java/org/libjpegturbo/turbojpeg/TJCompressor.java b/java/org/libjpegturbo/turbojpeg/TJCompressor.java index b18cb07d..dff38bf7 100644 --- a/java/org/libjpegturbo/turbojpeg/TJCompressor.java +++ b/java/org/libjpegturbo/turbojpeg/TJCompressor.java @@ -485,6 +485,8 @@ public class TJCompressor implements Closeable { } else { checkSubsampling(); int subsamp = get(TJ.PARAM_SUBSAMP); + if (get(TJ.PARAM_LOSSLESS) == 1 && subsamp != TJ.SAMP_GRAY) + subsamp = TJ.SAMP_444; buf = new byte[TJ.bufSize(srcWidth, srcHeight, subsamp)]; } compress(buf);