Disallow color quantization with lossless decomp

Color quantization is a legacy feature that serves little or no purpose
with lossless JPEG images.  9f756bc67a
eliminated interaction issues between the lossless decompressor and the
color quantizers related to out-of-range 12-bit samples, but referring
to #701, other interaction issues apparently still exist.  Such issues
are likely, given the fact that the color quantizers were not designed
with lossless decompression in mind.

This commit reverts 9f756bc67a, since the
issues it fixed are no longer relevant because of this commit and
2192560d74.

Fixed #672
Fixes #673
Fixes #674
Fixes #676
Fixes #677
Fixes #678
Fixes #679
Fixes #681
Fixes #683
Fixes #701
This commit is contained in:
DRC
2023-06-29 16:07:42 -04:00
parent c8d52f1c4c
commit bf9f319cb4
17 changed files with 66 additions and 92 deletions

View File

@@ -564,10 +564,10 @@ message(STATUS "CMAKE_EXECUTABLE_SUFFIX = ${CMAKE_EXECUTABLE_SUFFIX}")
set(JPEG16_SOURCES jcapistd.c jccolor.c jcdiffct.c jclossls.c jcmainct.c set(JPEG16_SOURCES jcapistd.c jccolor.c jcdiffct.c jclossls.c jcmainct.c
jcprepct.c jcsample.c jdapistd.c jdcolor.c jddiffct.c jdlossls.c jdmainct.c jcprepct.c jcsample.c jdapistd.c jdcolor.c jddiffct.c jdlossls.c jdmainct.c
jdpostct.c jdsample.c jquant1.c jquant2.c jutils.c) jdpostct.c jdsample.c jutils.c)
set(JPEG12_SOURCES ${JPEG16_SOURCES} jccoefct.c jcdctmgr.c jdcoefct.c set(JPEG12_SOURCES ${JPEG16_SOURCES} jccoefct.c jcdctmgr.c jdcoefct.c
jddctmgr.c jdmerge.c jdpostct.c jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jddctmgr.c jdmerge.c jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c
jidctint.c jidctred.c) jidctred.c jquant1.c jquant2.c)
set(JPEG_SOURCES ${JPEG12_SOURCES} jcapimin.c jchuff.c jcicc.c jcinit.c set(JPEG_SOURCES ${JPEG12_SOURCES} jcapimin.c jchuff.c jcicc.c jcinit.c
jclhuff.c jcmarker.c jcmaster.c jcomapi.c jcparam.c jcphuff.c jctrans.c jclhuff.c jcmarker.c jcmaster.c jcomapi.c jcparam.c jcphuff.c jctrans.c
jdapimin.c jdatadst.c jdatasrc.c jdhuff.c jdicc.c jdinput.c jdlhuff.c jdapimin.c jdatadst.c jdatasrc.c jdhuff.c jdicc.c jdinput.c jdlhuff.c
@@ -760,9 +760,9 @@ if(ENABLE_STATIC)
add_library(djpeg12-static OBJECT rdcolmap.c wrgif.c wrppm.c) add_library(djpeg12-static OBJECT rdcolmap.c wrgif.c wrppm.c)
set_property(TARGET djpeg12-static PROPERTY COMPILE_FLAGS set_property(TARGET djpeg12-static PROPERTY COMPILE_FLAGS
"-DBITS_IN_JSAMPLE=12 -DGIF_SUPPORTED -DPPM_SUPPORTED") "-DBITS_IN_JSAMPLE=12 -DGIF_SUPPORTED -DPPM_SUPPORTED")
add_library(djpeg16-static OBJECT rdcolmap.c wrgif.c wrppm.c) add_library(djpeg16-static OBJECT wrppm.c)
set_property(TARGET djpeg16-static PROPERTY COMPILE_FLAGS set_property(TARGET djpeg16-static PROPERTY COMPILE_FLAGS
"-DBITS_IN_JSAMPLE=16 -DGIF_SUPPORTED -DPPM_SUPPORTED") "-DBITS_IN_JSAMPLE=16 -DPPM_SUPPORTED")
add_executable(djpeg-static djpeg.c cdjpeg.c rdcolmap.c rdswitch.c wrbmp.c add_executable(djpeg-static djpeg.c cdjpeg.c rdcolmap.c rdswitch.c wrbmp.c
wrgif.c wrppm.c wrtarga.c $<TARGET_OBJECTS:djpeg12-static> wrgif.c wrppm.c wrtarga.c $<TARGET_OBJECTS:djpeg12-static>
$<TARGET_OBJECTS:djpeg16-static>) $<TARGET_OBJECTS:djpeg16-static>)

View File

@@ -10,11 +10,17 @@ images.
2. Fixed various segfaults and buffer overruns (CVE-2023-2804) that occurred 2. Fixed various segfaults and buffer overruns (CVE-2023-2804) that occurred
when attempting to decompress various specially-crafted malformed when attempting to decompress various specially-crafted malformed
12-bit-per-component lossless JPEG images. These issues were caused by 12-bit-per-component and 16-bit-per-component lossless JPEG images using color
out-of-range sample values that were not range-limited before being used as quantization or merged chroma upsampling/color conversion. The underlying
array indices. The issues were specific to 12-bit data precision, since that cause of these issues was that the color quantization and merged chroma
is the only data precision for which the range of the sample data type exceeds upsampling/color conversion algorithms were not designed with lossless
the valid sample range. decompression in mind. Since libjpeg-turbo explicitly does not support color
conversion when compressing or decompressing lossless JPEG images, merged
chroma upsampling/color conversion never should have been enabled for such
images. Color quantization is a legacy feature that serves little or no
purpose with lossless JPEG images, so it is also now disabled when
decompressing such images. (As a result, djpeg can no longer decompress a
lossless JPEG image into a GIF image.)
3. Fixed an oversight in 1.4 beta1[8] that caused various segfaults and buffer 3. Fixed an oversight in 1.4 beta1[8] that caused various segfaults and buffer
overruns when attempting to decompress various specially-crafted malformed overruns when attempting to decompress various specially-crafted malformed

View File

@@ -123,10 +123,6 @@ EXTERN(cjpeg_source_ptr) j16init_read_gif(j_compress_ptr cinfo);
EXTERN(djpeg_dest_ptr) jinit_write_gif(j_decompress_ptr cinfo, boolean is_lzw); EXTERN(djpeg_dest_ptr) jinit_write_gif(j_decompress_ptr cinfo, boolean is_lzw);
EXTERN(djpeg_dest_ptr) j12init_write_gif(j_decompress_ptr cinfo, EXTERN(djpeg_dest_ptr) j12init_write_gif(j_decompress_ptr cinfo,
boolean is_lzw); boolean is_lzw);
#ifdef D_LOSSLESS_SUPPORTED
EXTERN(djpeg_dest_ptr) j16init_write_gif(j_decompress_ptr cinfo,
boolean is_lzw);
#endif
EXTERN(cjpeg_source_ptr) jinit_read_ppm(j_compress_ptr cinfo); EXTERN(cjpeg_source_ptr) jinit_read_ppm(j_compress_ptr cinfo);
EXTERN(cjpeg_source_ptr) j12init_read_ppm(j_compress_ptr cinfo); EXTERN(cjpeg_source_ptr) j12init_read_ppm(j_compress_ptr cinfo);
#ifdef C_LOSSLESS_SUPPORTED #ifdef C_LOSSLESS_SUPPORTED
@@ -154,9 +150,6 @@ EXTERN(boolean) set_sample_factors(j_compress_ptr cinfo, char *arg);
EXTERN(void) read_color_map(j_decompress_ptr cinfo, FILE *infile); EXTERN(void) read_color_map(j_decompress_ptr cinfo, FILE *infile);
EXTERN(void) read_color_map_12(j_decompress_ptr cinfo, FILE *infile); EXTERN(void) read_color_map_12(j_decompress_ptr cinfo, FILE *infile);
#ifdef D_LOSSLESS_SUPPORTED
EXTERN(void) read_color_map_16(j_decompress_ptr cinfo, FILE *infile);
#endif
/* common support routines (in cdjpeg.c) */ /* common support routines (in cdjpeg.c) */

View File

@@ -1,4 +1,4 @@
.TH CJPEG 1 "30 November 2022" .TH CJPEG 1 "29 June 2023"
.SH NAME .SH NAME
cjpeg \- compress an image file to a JPEG file cjpeg \- compress an image file to a JPEG file
.SH SYNOPSIS .SH SYNOPSIS
@@ -182,6 +182,8 @@ unavailable when compressing or decompressing a lossless JPEG file:
- Color space conversion (the JPEG image will use the same color space as the - Color space conversion (the JPEG image will use the same color space as the
input image) input image)
.IP .IP
- Color quantization
.IP
- DCT/IDCT algorithm selection - DCT/IDCT algorithm selection
.IP .IP
- Smoothing - Smoothing

14
djpeg.c
View File

@@ -662,14 +662,9 @@ main(int argc, char **argv)
#endif #endif
#ifdef GIF_SUPPORTED #ifdef GIF_SUPPORTED
case FMT_GIF: case FMT_GIF:
if (cinfo.data_precision == 16) { if (cinfo.data_precision == 16)
#ifdef D_LOSSLESS_SUPPORTED
dest_mgr = j16init_write_gif(&cinfo, TRUE);
#else
ERREXIT1(&cinfo, JERR_BAD_PRECISION, cinfo.data_precision); ERREXIT1(&cinfo, JERR_BAD_PRECISION, cinfo.data_precision);
break; else if (cinfo.data_precision == 12)
#endif
} else if (cinfo.data_precision == 12)
dest_mgr = j12init_write_gif(&cinfo, TRUE); dest_mgr = j12init_write_gif(&cinfo, TRUE);
else else
dest_mgr = jinit_write_gif(&cinfo, TRUE); dest_mgr = jinit_write_gif(&cinfo, TRUE);
@@ -680,14 +675,13 @@ main(int argc, char **argv)
#endif #endif
#ifdef PPM_SUPPORTED #ifdef PPM_SUPPORTED
case FMT_PPM: case FMT_PPM:
if (cinfo.data_precision == 16) { if (cinfo.data_precision == 16)
#ifdef D_LOSSLESS_SUPPORTED #ifdef D_LOSSLESS_SUPPORTED
dest_mgr = j16init_write_ppm(&cinfo); dest_mgr = j16init_write_ppm(&cinfo);
#else #else
ERREXIT1(&cinfo, JERR_BAD_PRECISION, cinfo.data_precision); ERREXIT1(&cinfo, JERR_BAD_PRECISION, cinfo.data_precision);
break;
#endif #endif
} else if (cinfo.data_precision == 12) else if (cinfo.data_precision == 12)
dest_mgr = j12init_write_ppm(&cinfo); dest_mgr = j12init_write_ppm(&cinfo);
else else
dest_mgr = jinit_write_ppm(&cinfo); dest_mgr = jinit_write_ppm(&cinfo);

View File

@@ -6,7 +6,7 @@
* Lossless JPEG Modifications: * Lossless JPEG Modifications:
* Copyright (C) 1999, Ken Murchison. * Copyright (C) 1999, Ken Murchison.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2022-2023, D. R. Commander. * Copyright (C) 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -217,15 +217,7 @@ simple_upscale(j_decompress_ptr cinfo,
JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width) JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width)
{ {
do { do {
#if BITS_IN_JSAMPLE == 12
/* 12-bit is the only data precision for which the range of the sample data
* type exceeds the valid sample range. Thus, we need to range-limit the
* samples, because other algorithms may try to use them as array indices.
*/
*output_buf++ = (_JSAMPLE)((*diff_buf++ << cinfo->Al) & 0xFFF);
#else
*output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al); *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
#endif
} while (--width); } while (--width);
} }
@@ -234,11 +226,7 @@ noscale(j_decompress_ptr cinfo,
JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width) JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width)
{ {
do { do {
#if BITS_IN_JSAMPLE == 12
*output_buf++ = (_JSAMPLE)((*diff_buf++) & 0xFFF);
#else
*output_buf++ = (_JSAMPLE)(*diff_buf++); *output_buf++ = (_JSAMPLE)(*diff_buf++);
#endif
} while (--width); } while (--width);
} }

View File

@@ -571,11 +571,7 @@ master_selection(j_decompress_ptr cinfo)
if (cinfo->enable_1pass_quant) { if (cinfo->enable_1pass_quant) {
#ifdef QUANT_1PASS_SUPPORTED #ifdef QUANT_1PASS_SUPPORTED
if (cinfo->data_precision == 16) if (cinfo->data_precision == 16)
#ifdef D_LOSSLESS_SUPPORTED
j16init_1pass_quantizer(cinfo);
#else
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
#endif
else if (cinfo->data_precision == 12) else if (cinfo->data_precision == 12)
j12init_1pass_quantizer(cinfo); j12init_1pass_quantizer(cinfo);
else else
@@ -590,11 +586,7 @@ master_selection(j_decompress_ptr cinfo)
if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) { if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
#ifdef QUANT_2PASS_SUPPORTED #ifdef QUANT_2PASS_SUPPORTED
if (cinfo->data_precision == 16) if (cinfo->data_precision == 16)
#ifdef D_LOSSLESS_SUPPORTED
j16init_2pass_quantizer(cinfo);
#else
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
#endif
else if (cinfo->data_precision == 12) else if (cinfo->data_precision == 12)
j12init_2pass_quantizer(cinfo); j12init_2pass_quantizer(cinfo);
else else

View File

@@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2022, D. R. Commander. * Copyright (C) 2022-2023, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -49,6 +49,7 @@ typedef my_post_controller *my_post_ptr;
/* Forward declarations */ /* Forward declarations */
#if BITS_IN_JSAMPLE != 16
METHODDEF(void) post_process_1pass(j_decompress_ptr cinfo, METHODDEF(void) post_process_1pass(j_decompress_ptr cinfo,
_JSAMPIMAGE input_buf, _JSAMPIMAGE input_buf,
JDIMENSION *in_row_group_ctr, JDIMENSION *in_row_group_ctr,
@@ -56,7 +57,8 @@ METHODDEF(void) post_process_1pass(j_decompress_ptr cinfo,
_JSAMPARRAY output_buf, _JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail); JDIMENSION out_rows_avail);
#ifdef QUANT_2PASS_SUPPORTED #endif
#if defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16
METHODDEF(void) post_process_prepass(j_decompress_ptr cinfo, METHODDEF(void) post_process_prepass(j_decompress_ptr cinfo,
_JSAMPIMAGE input_buf, _JSAMPIMAGE input_buf,
JDIMENSION *in_row_group_ctr, JDIMENSION *in_row_group_ctr,
@@ -85,6 +87,7 @@ start_pass_dpost(j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
switch (pass_mode) { switch (pass_mode) {
case JBUF_PASS_THRU: case JBUF_PASS_THRU:
#if BITS_IN_JSAMPLE != 16
if (cinfo->quantize_colors) { if (cinfo->quantize_colors) {
/* Single-pass processing with color quantization. */ /* Single-pass processing with color quantization. */
post->pub._post_process_data = post_process_1pass; post->pub._post_process_data = post_process_1pass;
@@ -97,14 +100,16 @@ start_pass_dpost(j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
((j_common_ptr)cinfo, post->whole_image, ((j_common_ptr)cinfo, post->whole_image,
(JDIMENSION)0, post->strip_height, TRUE); (JDIMENSION)0, post->strip_height, TRUE);
} }
} else { } else
#endif
{
/* For single-pass processing without color quantization, /* For single-pass processing without color quantization,
* I have no work to do; just call the upsampler directly. * I have no work to do; just call the upsampler directly.
*/ */
post->pub._post_process_data = cinfo->upsample->_upsample; post->pub._post_process_data = cinfo->upsample->_upsample;
} }
break; break;
#ifdef QUANT_2PASS_SUPPORTED #if defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16
case JBUF_SAVE_AND_PASS: case JBUF_SAVE_AND_PASS:
/* First pass of 2-pass quantization */ /* First pass of 2-pass quantization */
if (post->whole_image == NULL) if (post->whole_image == NULL)
@@ -117,7 +122,7 @@ start_pass_dpost(j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
post->pub._post_process_data = post_process_2pass; post->pub._post_process_data = post_process_2pass;
break; break;
#endif /* QUANT_2PASS_SUPPORTED */ #endif /* defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 */
default: default:
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
break; break;
@@ -131,6 +136,8 @@ start_pass_dpost(j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
* This is used for color precision reduction as well as one-pass quantization. * This is used for color precision reduction as well as one-pass quantization.
*/ */
#if BITS_IN_JSAMPLE != 16
METHODDEF(void) METHODDEF(void)
post_process_1pass(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf, post_process_1pass(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION *in_row_group_ctr, JDIMENSION *in_row_group_ctr,
@@ -156,8 +163,10 @@ post_process_1pass(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
*out_row_ctr += num_rows; *out_row_ctr += num_rows;
} }
#endif
#ifdef QUANT_2PASS_SUPPORTED
#if defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16
/* /*
* Process some data in the first pass of 2-pass quantization. * Process some data in the first pass of 2-pass quantization.
@@ -246,7 +255,7 @@ post_process_2pass(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
} }
} }
#endif /* QUANT_2PASS_SUPPORTED */ #endif /* defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 */
/* /*
@@ -271,6 +280,7 @@ _jinit_d_post_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
/* Create the quantization buffer, if needed */ /* Create the quantization buffer, if needed */
if (cinfo->quantize_colors) { if (cinfo->quantize_colors) {
#if BITS_IN_JSAMPLE != 16
/* The buffer strip height is max_v_samp_factor, which is typically /* The buffer strip height is max_v_samp_factor, which is typically
* an efficient number of rows for upsampling to return. * an efficient number of rows for upsampling to return.
* (In the presence of output rescaling, we might want to be smarter?) * (In the presence of output rescaling, we might want to be smarter?)
@@ -296,6 +306,9 @@ _jinit_d_post_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
cinfo->output_width * cinfo->out_color_components, cinfo->output_width * cinfo->out_color_components,
post->strip_height); post->strip_height);
} }
#else
ERREXIT(cinfo, JERR_NOTIMPL);
#endif
} }
} }

View File

@@ -431,10 +431,6 @@ struct jpeg_color_quantizer {
JSAMPARRAY output_buf, int num_rows); JSAMPARRAY output_buf, int num_rows);
void (*color_quantize_12) (j_decompress_ptr cinfo, J12SAMPARRAY input_buf, void (*color_quantize_12) (j_decompress_ptr cinfo, J12SAMPARRAY input_buf,
J12SAMPARRAY output_buf, int num_rows); J12SAMPARRAY output_buf, int num_rows);
#ifdef D_LOSSLESS_SUPPORTED
void (*color_quantize_16) (j_decompress_ptr cinfo, J16SAMPARRAY input_buf,
J16SAMPARRAY output_buf, int num_rows);
#endif
void (*finish_pass) (j_decompress_ptr cinfo); void (*finish_pass) (j_decompress_ptr cinfo);
void (*new_color_map) (j_decompress_ptr cinfo); void (*new_color_map) (j_decompress_ptr cinfo);
}; };
@@ -553,8 +549,6 @@ EXTERN(void) j16init_d_post_controller(j_decompress_ptr cinfo,
boolean need_full_buffer); boolean need_full_buffer);
EXTERN(void) j16init_upsampler(j_decompress_ptr cinfo); EXTERN(void) j16init_upsampler(j_decompress_ptr cinfo);
EXTERN(void) j16init_color_deconverter(j_decompress_ptr cinfo); EXTERN(void) j16init_color_deconverter(j_decompress_ptr cinfo);
EXTERN(void) j16init_1pass_quantizer(j_decompress_ptr cinfo);
EXTERN(void) j16init_2pass_quantizer(j_decompress_ptr cinfo);
EXTERN(void) jinit_d_diff_controller(j_decompress_ptr cinfo, EXTERN(void) jinit_d_diff_controller(j_decompress_ptr cinfo,
boolean need_full_buffer); boolean need_full_buffer);
EXTERN(void) j12init_d_diff_controller(j_decompress_ptr cinfo, EXTERN(void) j12init_d_diff_controller(j_decompress_ptr cinfo,

View File

@@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2009, 2015, 2022, D. R. Commander. * Copyright (C) 2009, 2015, 2022-2023, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -18,8 +18,7 @@
#include "jpeglib.h" #include "jpeglib.h"
#include "jsamplecomp.h" #include "jsamplecomp.h"
#if defined(QUANT_1PASS_SUPPORTED) && \ #if defined(QUANT_1PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16
(BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED))
/* /*
@@ -827,6 +826,10 @@ _jinit_1pass_quantizer(j_decompress_ptr cinfo)
if (cinfo->data_precision != BITS_IN_JSAMPLE) if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
/* Color quantization is not supported with lossless JPEG images */
if (cinfo->master->lossless)
ERREXIT(cinfo, JERR_NOTIMPL);
cquantize = (my_cquantize_ptr) cquantize = (my_cquantize_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_cquantizer)); sizeof(my_cquantizer));
@@ -858,5 +861,4 @@ _jinit_1pass_quantizer(j_decompress_ptr cinfo)
alloc_fs_workspace(cinfo); alloc_fs_workspace(cinfo);
} }
#endif /* defined(QUANT_1PASS_SUPPORTED) && #endif /* defined(QUANT_1PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 */
(BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)) */

View File

@@ -25,8 +25,7 @@
#include "jpeglib.h" #include "jpeglib.h"
#include "jsamplecomp.h" #include "jsamplecomp.h"
#if defined(QUANT_2PASS_SUPPORTED) && \ #if defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16
(BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED))
/* /*
@@ -1239,7 +1238,7 @@ _jinit_2pass_quantizer(j_decompress_ptr cinfo)
/* Make sure jdmaster didn't give me a case I can't handle */ /* Make sure jdmaster didn't give me a case I can't handle */
if (cinfo->out_color_components != 3 || if (cinfo->out_color_components != 3 ||
cinfo->out_color_space == JCS_RGB565) cinfo->out_color_space == JCS_RGB565 || cinfo->master->lossless)
ERREXIT(cinfo, JERR_NOTIMPL); ERREXIT(cinfo, JERR_NOTIMPL);
/* Allocate the histogram/inverse colormap storage */ /* Allocate the histogram/inverse colormap storage */
@@ -1291,5 +1290,4 @@ _jinit_2pass_quantizer(j_decompress_ptr cinfo)
} }
} }
#endif /* defined(QUANT_2PASS_SUPPORTED) && #endif /* defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 */
(BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)) */

View File

@@ -57,8 +57,6 @@
#define _upsample upsample_16 #define _upsample upsample_16
/* Use the 16-bit method in the jpeg_color_converter structure. */ /* Use the 16-bit method in the jpeg_color_converter structure. */
#define _color_convert color_convert_16 #define _color_convert color_convert_16
/* Use the 16-bit method in the jpeg_color_quantizer structure. */
#define _color_quantize color_quantize_16
#endif #endif
/* Global internal functions (jpegint.h) */ /* Global internal functions (jpegint.h) */
@@ -76,8 +74,6 @@
#define _jinit_d_post_controller j16init_d_post_controller #define _jinit_d_post_controller j16init_d_post_controller
#define _jinit_upsampler j16init_upsampler #define _jinit_upsampler j16init_upsampler
#define _jinit_color_deconverter j16init_color_deconverter #define _jinit_color_deconverter j16init_color_deconverter
#define _jinit_1pass_quantizer j16init_1pass_quantizer
#define _jinit_2pass_quantizer j16init_2pass_quantizer
#define _jinit_merged_upsampler j16init_merged_upsampler #define _jinit_merged_upsampler j16init_merged_upsampler
#define _jinit_d_diff_controller j16init_d_diff_controller #define _jinit_d_diff_controller j16init_d_diff_controller
#define _jinit_lossless_decompressor j16init_lossless_decompressor #define _jinit_lossless_decompressor j16init_lossless_decompressor
@@ -102,10 +98,7 @@
#endif #endif
#ifdef D_LOSSLESS_SUPPORTED #ifdef D_LOSSLESS_SUPPORTED
#define _jinit_write_gif j16init_write_gif
#define _jinit_write_ppm j16init_write_ppm #define _jinit_write_ppm j16init_write_ppm
#define _read_color_map read_color_map_16
#endif #endif
#elif BITS_IN_JSAMPLE == 12 #elif BITS_IN_JSAMPLE == 12

View File

@@ -5,7 +5,7 @@ Copyright (C) 1994-2013, Thomas G. Lane, Guido Vollbeding.
Lossless JPEG Modifications: Lossless JPEG Modifications:
Copyright (C) 1999, Ken Murchison. Copyright (C) 1999, Ken Murchison.
libjpeg-turbo Modifications: libjpeg-turbo Modifications:
Copyright (C) 2010, 2014-2018, 2020, 2022, D. R. Commander. Copyright (C) 2010, 2014-2018, 2020, 2022-2023, D. R. Commander.
Copyright (C) 2015, Google, Inc. Copyright (C) 2015, Google, Inc.
For conditions of distribution and use, see the accompanying README.ijg file. For conditions of distribution and use, see the accompanying README.ijg file.
@@ -120,8 +120,8 @@ supports 12-bit-per-component lossy or lossless JPEG if you set
cinfo->data_precision to 12 and 16-bit-per-component lossless JPEG if you set cinfo->data_precision to 12 and 16-bit-per-component lossless JPEG if you set
cinfo->data_precision to 16. Note that this causes the sample size to be cinfo->data_precision to 16. Note that this causes the sample size to be
larger than a char, so it affects the surrounding application's image data. larger than a char, so it affects the surrounding application's image data.
The sample applications cjpeg and djpeg can support 12-bit and 16-bit mode only The sample applications cjpeg and djpeg can support 12-bit mode only for PPM,
for PPM and GIF file formats. PGM, and GIF file formats and 16-bit mode only for PPM and PGM file formats.
Note that, when 12-bit data precision is enabled, the library always compresses Note that, when 12-bit data precision is enabled, the library always compresses
in Huffman optimization mode, in order to generate valid Huffman tables. This in Huffman optimization mode, in order to generate valid Huffman tables. This
@@ -1037,6 +1037,7 @@ jpeg_enable_lossless (j_compress_ptr cinfo, int predictor_selection_value,
* Downsampling/upsampling * Downsampling/upsampling
* Color space conversion (the JPEG image will use the same color * Color space conversion (the JPEG image will use the same color
space as the input image) space as the input image)
* Color quantization
* IDCT scaling * IDCT scaling
* Raw (downsampled) data input/output * Raw (downsampled) data input/output
* Transcoding of DCT coefficients * Transcoding of DCT coefficients

View File

@@ -87,9 +87,9 @@ target_link_libraries(cjpeg jpeg)
add_library(djpeg12 OBJECT ../rdcolmap.c ../wrgif.c ../wrppm.c) add_library(djpeg12 OBJECT ../rdcolmap.c ../wrgif.c ../wrppm.c)
set_property(TARGET djpeg12 PROPERTY COMPILE_FLAGS set_property(TARGET djpeg12 PROPERTY COMPILE_FLAGS
"-DBITS_IN_JSAMPLE=12 -DGIF_SUPPORTED -DPPM_SUPPORTED") "-DBITS_IN_JSAMPLE=12 -DGIF_SUPPORTED -DPPM_SUPPORTED")
add_library(djpeg16 OBJECT ../rdcolmap.c ../wrgif.c ../wrppm.c) add_library(djpeg16 OBJECT ../wrppm.c)
set_property(TARGET djpeg16 PROPERTY COMPILE_FLAGS set_property(TARGET djpeg16 PROPERTY COMPILE_FLAGS
"-DBITS_IN_JSAMPLE=16 -DGIF_SUPPORTED -DPPM_SUPPORTED") "-DBITS_IN_JSAMPLE=16 -DPPM_SUPPORTED")
add_executable(djpeg ../djpeg.c ../cdjpeg.c ../rdcolmap.c ../rdswitch.c add_executable(djpeg ../djpeg.c ../cdjpeg.c ../rdcolmap.c ../rdswitch.c
../wrbmp.c ../wrgif.c ../wrppm.c ../wrtarga.c $<TARGET_OBJECTS:djpeg12> ../wrbmp.c ../wrgif.c ../wrppm.c ../wrtarga.c $<TARGET_OBJECTS:djpeg12>
$<TARGET_OBJECTS:djpeg16>) $<TARGET_OBJECTS:djpeg16>)

View File

@@ -5,7 +5,7 @@ Copyright (C) 1991-2012, Thomas G. Lane, Guido Vollbeding.
Lossless JPEG Modifications: Lossless JPEG Modifications:
Copyright (C) 1999, Ken Murchison. Copyright (C) 1999, Ken Murchison.
libjpeg-turbo Modifications: libjpeg-turbo Modifications:
Copyright (C) 2022, D. R. Commander. Copyright (C) 2022-2023, D. R. Commander.
For conditions of distribution and use, see the accompanying README.ijg file. For conditions of distribution and use, see the accompanying README.ijg file.
@@ -443,8 +443,7 @@ Main controller --|
| scaling | scaling
Main controller --| Main controller --|
| |-- Upsampling | |-- Upsampling
|-- Postprocessing controller --| |-- Colorspace conversion |-- Postprocessing controller --|
|-- Color quantization
|-- Color precision reduction |-- Color precision reduction
As before, this diagram also represents typical control flow. The objects As before, this diagram also represents typical control flow. The objects

View File

@@ -183,6 +183,7 @@ Switches for advanced users:
* Quality/quantization table selection * Quality/quantization table selection
* Color space conversion (the JPEG image will use the * Color space conversion (the JPEG image will use the
same color space as the input image) same color space as the input image)
* Color quantization
* DCT/IDCT algorithm selection * DCT/IDCT algorithm selection
* Smoothing * Smoothing
* Downsampling/upsampling * Downsampling/upsampling

View File

@@ -5,7 +5,7 @@
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2015-2019 by Guido Vollbeding. * Modified 2015-2019 by Guido Vollbeding.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2015, 2017, 2022, D. R. Commander. * Copyright (C) 2015, 2017, 2022-2023, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -33,8 +33,7 @@
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#include "jsamplecomp.h" #include "jsamplecomp.h"
#if defined(GIF_SUPPORTED) && \ #if defined(GIF_SUPPORTED) && BITS_IN_JSAMPLE != 16
(BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED))
#define MAX_LZW_BITS 12 /* maximum LZW code size (4096 symbols) */ #define MAX_LZW_BITS 12 /* maximum LZW code size (4096 symbols) */
@@ -583,5 +582,4 @@ _jinit_write_gif(j_decompress_ptr cinfo, boolean is_lzw)
return (djpeg_dest_ptr)dest; return (djpeg_dest_ptr)dest;
} }
#endif /* defined(GIF_SUPPORTED) && #endif /* defined(GIF_SUPPORTED) && BITS_IN_JSAMPLE != 16 */
(BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)) */