diff --git a/ChangeLog.md b/ChangeLog.md index 4fdb3704..ed410210 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -8,6 +8,17 @@ transform value greater than 7 resulted in an error ("Parameter value out of range".) +2. Fixed a regression introduced by 1.4 beta1[3] that prevented +`jpeg_set_defaults()` from resetting the Huffman tables to default (baseline) +values if Huffman table optimization or progressive mode was previously enabled +in the same libjpeg instance. + +3. Fixed an issue whereby lossless JPEG compression could not be disabled if it +was previously enabled in a libjpeg or TurboJPEG instance. +`jpeg_set_defaults()` now disables lossless JPEG compression in a libjpeg +instance, and setting `TJPARAM_LOSSLESS`/`TJ.PARAM_LOSSLESS` to `0` now +disables lossless JPEG compression in a TurboJPEG instance. + 3.0.4 ===== diff --git a/jcparam.c b/jcparam.c index 1d6e2254..f3a62afc 100644 --- a/jcparam.c +++ b/jcparam.c @@ -7,7 +7,7 @@ * Lossless JPEG Modifications: * Copyright (C) 1999, Ken Murchison. * libjpeg-turbo Modifications: - * Copyright (C) 2009-2011, 2018, 2023, D. R. Commander. + * Copyright (C) 2009-2011, 2018, 2023-2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -220,6 +220,9 @@ jpeg_set_defaults(j_compress_ptr cinfo) cinfo->scan_info = NULL; cinfo->num_scans = 0; + /* Default is lossy output */ + cinfo->master->lossless = FALSE; + /* Expect normal source image, not raw downsampled data */ cinfo->raw_data_in = FALSE; diff --git a/jstdhuff.c b/jstdhuff.c index 345b513d..39459012 100644 --- a/jstdhuff.c +++ b/jstdhuff.c @@ -4,7 +4,7 @@ * This file was part of the Independent JPEG Group's software: * Copyright (C) 1991-1998, Thomas G. Lane. * libjpeg-turbo Modifications: - * Copyright (C) 2013, 2022, D. R. Commander. + * Copyright (C) 2013, 2022, 2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -25,7 +25,7 @@ add_huff_table(j_common_ptr cinfo, JHUFF_TBL **htblptr, const UINT8 *bits, if (*htblptr == NULL) *htblptr = jpeg_alloc_huff_table(cinfo); - else + else if (cinfo->is_decompressor) return; /* Copy the number-of-symbols-of-each-code-length counts */ diff --git a/turbojpeg.c b/turbojpeg.c index 09d5424a..e9cd03c7 100644 --- a/turbojpeg.c +++ b/turbojpeg.c @@ -328,6 +328,8 @@ static int getPixelFormat(int pixelSize, int flags) static void setCompDefaults(tjinstance *this, int pixelFormat) { + int subsamp = this->subsamp; + this->cinfo.in_color_space = pf2cs[pixelFormat]; this->cinfo.input_components = tjPixelSize[pixelFormat]; jpeg_set_defaults(&this->cinfo); @@ -344,9 +346,9 @@ static void setCompDefaults(tjinstance *this, int pixelFormat) jpeg_enable_lossless(&this->cinfo, this->losslessPSV, this->losslessPt); #endif if (pixelFormat == TJPF_GRAY) - this->subsamp = TJSAMP_GRAY; - else if (this->subsamp != TJSAMP_GRAY) - this->subsamp = TJSAMP_444; + subsamp = TJSAMP_GRAY; + else if (subsamp != TJSAMP_GRAY) + subsamp = TJSAMP_444; return; } @@ -365,7 +367,7 @@ static void setCompDefaults(tjinstance *this, int pixelFormat) case TJCS_YCCK: jpeg_set_colorspace(&this->cinfo, JCS_YCCK); break; default: - if (this->subsamp == TJSAMP_GRAY) + if (subsamp == TJSAMP_GRAY) jpeg_set_colorspace(&this->cinfo, JCS_GRAYSCALE); else if (pixelFormat == TJPF_CMYK) jpeg_set_colorspace(&this->cinfo, JCS_YCCK); @@ -380,16 +382,16 @@ static void setCompDefaults(tjinstance *this, int pixelFormat) #endif this->cinfo.arith_code = this->arithmetic; - this->cinfo.comp_info[0].h_samp_factor = tjMCUWidth[this->subsamp] / 8; + this->cinfo.comp_info[0].h_samp_factor = tjMCUWidth[subsamp] / 8; this->cinfo.comp_info[1].h_samp_factor = 1; this->cinfo.comp_info[2].h_samp_factor = 1; if (this->cinfo.num_components > 3) - this->cinfo.comp_info[3].h_samp_factor = tjMCUWidth[this->subsamp] / 8; - this->cinfo.comp_info[0].v_samp_factor = tjMCUHeight[this->subsamp] / 8; + this->cinfo.comp_info[3].h_samp_factor = tjMCUWidth[subsamp] / 8; + this->cinfo.comp_info[0].v_samp_factor = tjMCUHeight[subsamp] / 8; this->cinfo.comp_info[1].v_samp_factor = 1; this->cinfo.comp_info[2].v_samp_factor = 1; if (this->cinfo.num_components > 3) - this->cinfo.comp_info[3].v_samp_factor = tjMCUHeight[this->subsamp] / 8; + this->cinfo.comp_info[3].v_samp_factor = tjMCUHeight[subsamp] / 8; }