Allow disabling prog/opt/lossless if prev. enabled

- Due to an oversight, a113506d17
  (libjpeg-turbo 1.4 beta1) effectively made the call to
  std_huff_tables() in jpeg_set_defaults() a no-op if the Huffman tables
  were previously defined, which made it impossible to disable Huffman
  table optimization or progressive mode if they were previously enabled
  in the same API instance.  std_huff_tables() retains its previous
  behavior for decompression instances, but it now force-enables the
  standard (baseline) Huffman tables for compression instances.

- Due to another oversight, there was no way to disable lossless mode
  if it was previously enabled in a particular API instance.
  jpeg_set_defaults() now accomplishes this, which makes
  TJ*PARAM_LOSSLESS behave as intended/documented.

- Due to yet another oversight, setCompDefaults() in the TurboJPEG API
  library permanently modified the value of TJ*PARAM_SUBSAMP when
  generating a lossless JPEG image, which affected subsequent lossy
  compression operations.  This issue was hidden by the issue above and
  thus does not need to be publicly documented.

Fixes #792
This commit is contained in:
DRC
2024-10-24 13:25:10 -04:00
parent 00e71d4c07
commit 45fa88190f
4 changed files with 27 additions and 11 deletions

View File

@@ -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
=====

View File

@@ -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;

View File

@@ -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 */

View File

@@ -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;
}