From bf9f319cb4b86b130bee16af19fee95a1cdb5ef2 Mon Sep 17 00:00:00 2001 From: DRC Date: Thu, 29 Jun 2023 16:07:42 -0400 Subject: [PATCH] Disallow color quantization with lossless decomp Color quantization is a legacy feature that serves little or no purpose with lossless JPEG images. 9f756bc67a84d4566bf74a0c2432aa55da404021 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 9f756bc67a84d4566bf74a0c2432aa55da404021, since the issues it fixed are no longer relevant because of this commit and 2192560d74e6e6cf99dd05928885573be00a8208. Fixed #672 Fixes #673 Fixes #674 Fixes #676 Fixes #677 Fixes #678 Fixes #679 Fixes #681 Fixes #683 Fixes #701 --- CMakeLists.txt | 10 +++++----- ChangeLog.md | 16 +++++++++++----- cdjpeg.h | 7 ------- cjpeg.1 | 4 +++- djpeg.c | 14 ++++---------- jdlossls.c | 14 +------------- jdmaster.c | 8 -------- jdpostct.c | 27 ++++++++++++++++++++------- jpegint.h | 6 ------ jquant1.c | 12 +++++++----- jquant2.c | 8 +++----- jsamplecomp.h | 7 ------- libjpeg.txt | 7 ++++--- sharedlib/CMakeLists.txt | 4 ++-- structure.txt | 5 ++--- usage.txt | 1 + wrgif.c | 8 +++----- 17 files changed, 66 insertions(+), 92 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 83b4103d..efd101a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 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 - jddctmgr.c jdmerge.c jdpostct.c jfdctfst.c jfdctint.c jidctflt.c jidctfst.c - jidctint.c jidctred.c) + jddctmgr.c jdmerge.c jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c + jidctred.c jquant1.c jquant2.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 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) set_property(TARGET djpeg12-static PROPERTY COMPILE_FLAGS "-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 - "-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 wrgif.c wrppm.c wrtarga.c $ $) diff --git a/ChangeLog.md b/ChangeLog.md index c61565be..aadd7907 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -10,11 +10,17 @@ images. 2. Fixed various segfaults and buffer overruns (CVE-2023-2804) that occurred when attempting to decompress various specially-crafted malformed -12-bit-per-component lossless JPEG images. These issues were caused by -out-of-range sample values that were not range-limited before being used as -array indices. The issues were specific to 12-bit data precision, since that -is the only data precision for which the range of the sample data type exceeds -the valid sample range. +12-bit-per-component and 16-bit-per-component lossless JPEG images using color +quantization or merged chroma upsampling/color conversion. The underlying +cause of these issues was that the color quantization and merged chroma +upsampling/color conversion algorithms were not designed with lossless +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 overruns when attempting to decompress various specially-crafted malformed diff --git a/cdjpeg.h b/cdjpeg.h index 13609f66..471b9a3f 100644 --- a/cdjpeg.h +++ b/cdjpeg.h @@ -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) j12init_write_gif(j_decompress_ptr cinfo, 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) j12init_read_ppm(j_compress_ptr cinfo); #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_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) */ diff --git a/cjpeg.1 b/cjpeg.1 index 7ddce3c0..0815ca0c 100644 --- a/cjpeg.1 +++ b/cjpeg.1 @@ -1,4 +1,4 @@ -.TH CJPEG 1 "30 November 2022" +.TH CJPEG 1 "29 June 2023" .SH NAME cjpeg \- compress an image file to a JPEG file .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 input image) .IP +- Color quantization +.IP - DCT/IDCT algorithm selection .IP - Smoothing diff --git a/djpeg.c b/djpeg.c index 1f715316..f42d3543 100644 --- a/djpeg.c +++ b/djpeg.c @@ -662,14 +662,9 @@ main(int argc, char **argv) #endif #ifdef GIF_SUPPORTED case FMT_GIF: - if (cinfo.data_precision == 16) { -#ifdef D_LOSSLESS_SUPPORTED - dest_mgr = j16init_write_gif(&cinfo, TRUE); -#else + if (cinfo.data_precision == 16) ERREXIT1(&cinfo, JERR_BAD_PRECISION, cinfo.data_precision); - break; -#endif - } else if (cinfo.data_precision == 12) + else if (cinfo.data_precision == 12) dest_mgr = j12init_write_gif(&cinfo, TRUE); else dest_mgr = jinit_write_gif(&cinfo, TRUE); @@ -680,14 +675,13 @@ main(int argc, char **argv) #endif #ifdef PPM_SUPPORTED case FMT_PPM: - if (cinfo.data_precision == 16) { + if (cinfo.data_precision == 16) #ifdef D_LOSSLESS_SUPPORTED dest_mgr = j16init_write_ppm(&cinfo); #else ERREXIT1(&cinfo, JERR_BAD_PRECISION, cinfo.data_precision); - break; #endif - } else if (cinfo.data_precision == 12) + else if (cinfo.data_precision == 12) dest_mgr = j12init_write_ppm(&cinfo); else dest_mgr = jinit_write_ppm(&cinfo); diff --git a/jdlossls.c b/jdlossls.c index cfdca7e3..4d15e6bb 100644 --- a/jdlossls.c +++ b/jdlossls.c @@ -6,7 +6,7 @@ * Lossless JPEG Modifications: * Copyright (C) 1999, Ken Murchison. * 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 * file. * @@ -217,15 +217,7 @@ simple_upscale(j_decompress_ptr cinfo, JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width) { 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); -#endif } while (--width); } @@ -234,11 +226,7 @@ noscale(j_decompress_ptr cinfo, JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width) { do { -#if BITS_IN_JSAMPLE == 12 - *output_buf++ = (_JSAMPLE)((*diff_buf++) & 0xFFF); -#else *output_buf++ = (_JSAMPLE)(*diff_buf++); -#endif } while (--width); } diff --git a/jdmaster.c b/jdmaster.c index 4b3852d9..80a4842a 100644 --- a/jdmaster.c +++ b/jdmaster.c @@ -571,11 +571,7 @@ master_selection(j_decompress_ptr cinfo) if (cinfo->enable_1pass_quant) { #ifdef QUANT_1PASS_SUPPORTED if (cinfo->data_precision == 16) -#ifdef D_LOSSLESS_SUPPORTED - j16init_1pass_quantizer(cinfo); -#else ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); -#endif else if (cinfo->data_precision == 12) j12init_1pass_quantizer(cinfo); else @@ -590,11 +586,7 @@ master_selection(j_decompress_ptr cinfo) if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) { #ifdef QUANT_2PASS_SUPPORTED if (cinfo->data_precision == 16) -#ifdef D_LOSSLESS_SUPPORTED - j16init_2pass_quantizer(cinfo); -#else ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); -#endif else if (cinfo->data_precision == 12) j12init_2pass_quantizer(cinfo); else diff --git a/jdpostct.c b/jdpostct.c index e8500748..d38495f5 100644 --- a/jdpostct.c +++ b/jdpostct.c @@ -4,7 +4,7 @@ * This file was part of the Independent JPEG Group's software: * Copyright (C) 1994-1996, Thomas G. Lane. * 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. * @@ -49,6 +49,7 @@ typedef my_post_controller *my_post_ptr; /* Forward declarations */ +#if BITS_IN_JSAMPLE != 16 METHODDEF(void) post_process_1pass(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, @@ -56,7 +57,8 @@ METHODDEF(void) post_process_1pass(j_decompress_ptr cinfo, _JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, 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, _JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, @@ -85,6 +87,7 @@ start_pass_dpost(j_decompress_ptr cinfo, J_BUF_MODE pass_mode) switch (pass_mode) { case JBUF_PASS_THRU: +#if BITS_IN_JSAMPLE != 16 if (cinfo->quantize_colors) { /* Single-pass processing with color quantization. */ 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, (JDIMENSION)0, post->strip_height, TRUE); } - } else { + } else +#endif + { /* For single-pass processing without color quantization, * I have no work to do; just call the upsampler directly. */ post->pub._post_process_data = cinfo->upsample->_upsample; } break; -#ifdef QUANT_2PASS_SUPPORTED +#if defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 case JBUF_SAVE_AND_PASS: /* First pass of 2-pass quantization */ 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); post->pub._post_process_data = post_process_2pass; break; -#endif /* QUANT_2PASS_SUPPORTED */ +#endif /* defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 */ default: ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); 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. */ +#if BITS_IN_JSAMPLE != 16 + METHODDEF(void) post_process_1pass(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, @@ -156,8 +163,10 @@ post_process_1pass(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf, *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. @@ -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 */ if (cinfo->quantize_colors) { +#if BITS_IN_JSAMPLE != 16 /* The buffer strip height is max_v_samp_factor, which is typically * an efficient number of rows for upsampling to return. * (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, post->strip_height); } +#else + ERREXIT(cinfo, JERR_NOTIMPL); +#endif } } diff --git a/jpegint.h b/jpegint.h index 747b5464..65414201 100644 --- a/jpegint.h +++ b/jpegint.h @@ -431,10 +431,6 @@ struct jpeg_color_quantizer { JSAMPARRAY output_buf, int num_rows); void (*color_quantize_12) (j_decompress_ptr cinfo, J12SAMPARRAY input_buf, 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 (*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); EXTERN(void) j16init_upsampler(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, boolean need_full_buffer); EXTERN(void) j12init_d_diff_controller(j_decompress_ptr cinfo, diff --git a/jquant1.c b/jquant1.c index 67c1ae36..2e914b91 100644 --- a/jquant1.c +++ b/jquant1.c @@ -4,7 +4,7 @@ * This file was part of the Independent JPEG Group's software: * Copyright (C) 1991-1996, Thomas G. Lane. * 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 * file. * @@ -18,8 +18,7 @@ #include "jpeglib.h" #include "jsamplecomp.h" -#if defined(QUANT_1PASS_SUPPORTED) && \ - (BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)) +#if defined(QUANT_1PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 /* @@ -827,6 +826,10 @@ _jinit_1pass_quantizer(j_decompress_ptr cinfo) if (cinfo->data_precision != BITS_IN_JSAMPLE) 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) (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, sizeof(my_cquantizer)); @@ -858,5 +861,4 @@ _jinit_1pass_quantizer(j_decompress_ptr cinfo) alloc_fs_workspace(cinfo); } -#endif /* defined(QUANT_1PASS_SUPPORTED) && - (BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)) */ +#endif /* defined(QUANT_1PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 */ diff --git a/jquant2.c b/jquant2.c index 5984ed8c..9ba51fa8 100644 --- a/jquant2.c +++ b/jquant2.c @@ -25,8 +25,7 @@ #include "jpeglib.h" #include "jsamplecomp.h" -#if defined(QUANT_2PASS_SUPPORTED) && \ - (BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)) +#if defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 /* @@ -1239,7 +1238,7 @@ _jinit_2pass_quantizer(j_decompress_ptr cinfo) /* Make sure jdmaster didn't give me a case I can't handle */ 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); /* Allocate the histogram/inverse colormap storage */ @@ -1291,5 +1290,4 @@ _jinit_2pass_quantizer(j_decompress_ptr cinfo) } } -#endif /* defined(QUANT_2PASS_SUPPORTED) && - (BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)) */ +#endif /* defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 */ diff --git a/jsamplecomp.h b/jsamplecomp.h index 6594480f..f3f275e6 100644 --- a/jsamplecomp.h +++ b/jsamplecomp.h @@ -57,8 +57,6 @@ #define _upsample upsample_16 /* Use the 16-bit method in the jpeg_color_converter structure. */ #define _color_convert color_convert_16 -/* Use the 16-bit method in the jpeg_color_quantizer structure. */ -#define _color_quantize color_quantize_16 #endif /* Global internal functions (jpegint.h) */ @@ -76,8 +74,6 @@ #define _jinit_d_post_controller j16init_d_post_controller #define _jinit_upsampler j16init_upsampler #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_d_diff_controller j16init_d_diff_controller #define _jinit_lossless_decompressor j16init_lossless_decompressor @@ -102,10 +98,7 @@ #endif #ifdef D_LOSSLESS_SUPPORTED -#define _jinit_write_gif j16init_write_gif #define _jinit_write_ppm j16init_write_ppm - -#define _read_color_map read_color_map_16 #endif #elif BITS_IN_JSAMPLE == 12 diff --git a/libjpeg.txt b/libjpeg.txt index a695f6d0..2dae2d20 100644 --- a/libjpeg.txt +++ b/libjpeg.txt @@ -5,7 +5,7 @@ Copyright (C) 1994-2013, Thomas G. Lane, Guido Vollbeding. Lossless JPEG Modifications: Copyright (C) 1999, Ken Murchison. 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. 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 16. Note that this causes the sample size to be 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 -for PPM and GIF file formats. +The sample applications cjpeg and djpeg can support 12-bit mode only for PPM, +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 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 * Color space conversion (the JPEG image will use the same color space as the input image) + * Color quantization * IDCT scaling * Raw (downsampled) data input/output * Transcoding of DCT coefficients diff --git a/sharedlib/CMakeLists.txt b/sharedlib/CMakeLists.txt index 58923057..8e942569 100644 --- a/sharedlib/CMakeLists.txt +++ b/sharedlib/CMakeLists.txt @@ -87,9 +87,9 @@ target_link_libraries(cjpeg jpeg) add_library(djpeg12 OBJECT ../rdcolmap.c ../wrgif.c ../wrppm.c) set_property(TARGET djpeg12 PROPERTY COMPILE_FLAGS "-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 - "-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 ../wrbmp.c ../wrgif.c ../wrppm.c ../wrtarga.c $ $) diff --git a/structure.txt b/structure.txt index c0c6d8e4..030b8e88 100644 --- a/structure.txt +++ b/structure.txt @@ -5,7 +5,7 @@ Copyright (C) 1991-2012, Thomas G. Lane, Guido Vollbeding. Lossless JPEG Modifications: Copyright (C) 1999, Ken Murchison. 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. @@ -443,8 +443,7 @@ Main controller --| | scaling Main controller --| | |-- Upsampling - |-- Postprocessing controller --| |-- Colorspace conversion - |-- Color quantization + |-- Postprocessing controller --| |-- Color precision reduction As before, this diagram also represents typical control flow. The objects diff --git a/usage.txt b/usage.txt index ddd0d1f5..c1bba4ae 100644 --- a/usage.txt +++ b/usage.txt @@ -183,6 +183,7 @@ Switches for advanced users: * Quality/quantization table selection * Color space conversion (the JPEG image will use the same color space as the input image) + * Color quantization * DCT/IDCT algorithm selection * Smoothing * Downsampling/upsampling diff --git a/wrgif.c b/wrgif.c index c0fb10c1..23773573 100644 --- a/wrgif.c +++ b/wrgif.c @@ -5,7 +5,7 @@ * Copyright (C) 1991-1997, Thomas G. Lane. * Modified 2015-2019 by Guido Vollbeding. * 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 * file. * @@ -33,8 +33,7 @@ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "jsamplecomp.h" -#if defined(GIF_SUPPORTED) && \ - (BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)) +#if defined(GIF_SUPPORTED) && BITS_IN_JSAMPLE != 16 #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; } -#endif /* defined(GIF_SUPPORTED) && - (BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)) */ +#endif /* defined(GIF_SUPPORTED) && BITS_IN_JSAMPLE != 16 */