Update bundled libjpeg-turbo to version 3.0.4

[ChangeLog][Third-Party Code] libjpeg-turbo was updated to version 3.0.4

Pick-to: 6.8.0 6.7 6.7.3 6.5 6.2 5.15
Change-Id: Ifa437bfc9b99f386d792a045b0963f3690e322d9
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
(cherry picked from commit c1ee64834a04f03587d0a95d63365620951e072e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Eirik Aavitsland 2024-09-16 11:24:52 +02:00 committed by Qt Cherry-pick Bot
parent 21098bbb9c
commit d2b98a1147
17 changed files with 182 additions and 91 deletions

View File

@ -7,8 +7,8 @@
"Description": "The Independent JPEG Group's JPEG software", "Description": "The Independent JPEG Group's JPEG software",
"Homepage": "http://libjpeg-turbo.virtualgl.org/", "Homepage": "http://libjpeg-turbo.virtualgl.org/",
"Version": "3.0.3", "Version": "3.0.4",
"DownloadLocation": "https://github.com/libjpeg-turbo/libjpeg-turbo/releases/download/3.0.3/libjpeg-turbo-3.0.3.tar.gz", "DownloadLocation": "https://github.com/libjpeg-turbo/libjpeg-turbo/releases/download/3.0.4/libjpeg-turbo-3.0.4.tar.gz",
"License": "Independent JPEG Group License and BSD 3-Clause \"New\" or \"Revised\" License", "License": "Independent JPEG Group License and BSD 3-Clause \"New\" or \"Revised\" License",
"LicenseId": "IJG AND BSD-3-Clause", "LicenseId": "IJG AND BSD-3-Clause",

View File

@ -1,3 +1,61 @@
3.0.4
=====
### Significant changes relative to 3.0.3:
1. Fixed an issue whereby the CPU usage of the default marker processor in the
decompressor grew exponentially with the number of markers. This caused an
unreasonable slow-down in `jpeg_read_header()` if an application called
`jpeg_save_markers()` to save markers of a particular type and then attempted
to decompress a JPEG image containing an excessive number of markers of that
type.
2. Hardened the default marker processor in the decompressor to guard against
an issue (exposed by 3.0 beta2[6]) whereby attempting to decompress a
specially-crafted malformed JPEG image (specifically an image with a complete
12-bit-per-sample Start Of Frame segment followed by an incomplete
8-bit-per-sample Start Of Frame segment) using buffered-image mode and input
prefetching caused a segfault if the `fill_input_buffer()` method in the
calling application's custom source manager incorrectly returned `FALSE` in
response to a prematurely-terminated JPEG data stream.
3. Fixed an issue in cjpeg whereby, when generating a 12-bit-per-sample or
16-bit-per-sample lossless JPEG image, specifying a point transform value
greater than 7 resulted in an error ("Invalid progressive/lossless parameters")
unless the `-precision` option was specified before the `-lossless` option.
4. Fixed a regression introduced by 3.0.3[3] that made it impossible for
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`.
6. Fixed a segfault in djpeg that occurred if a negative width was specified
with the `-crop` option. Since the cropping region width was read into an
unsigned 32-bit integer, a negative width was interpreted as a very large
value. With certain negative width and positive left boundary values, the
bounds checks in djpeg and `jpeg_crop_scanline()` overflowed and did not detect
the out-of-bounds width, which caused a buffer overrun in the upsampling or
color conversion routine. Both bounds checks now use 64-bit integers to guard
against overflow, and djpeg now checks for negative numbers when it parses the
crop specification from the command line.
7. Fixed an issue whereby the TurboJPEG lossless transformation function and
methods checked the specified cropping region against the source image
dimensions and level of chrominance subsampling rather than the destination
image dimensions and level of chrominance subsampling, which caused some
cropping regions to be unduly rejected when performing 90-degree rotation,
270-degree rotation, transposition, transverse transposition, or grayscale
conversion.
8. Fixed an issue whereby the TurboJPEG lossless transformation function and
methods did not honor `TJXOPT_COPYNONE`/`TJTransform.OPT_COPYNONE` unless it
was specified for all lossless transforms.
3.0.3 3.0.3
===== =====
@ -38,10 +96,10 @@ easier to detect actual security issues, should they arise in the future.
`TJ.PARAM_MAXMEMORY` in the TurboJPEG Java API) and a corresponding TJBench `TJ.PARAM_MAXMEMORY` in the TurboJPEG Java API) and a corresponding TJBench
option (`-maxmemory`) for specifying the maximum amount of memory (in option (`-maxmemory`) for specifying the maximum amount of memory (in
megabytes) that will be allocated for intermediate buffers, which are used with megabytes) that will be allocated for intermediate buffers, which are used with
progressive JPEG compression and decompression, optimized baseline entropy progressive JPEG compression and decompression, Huffman table optimization,
coding, lossless JPEG compression, and lossless transformation. The new lossless JPEG compression, and lossless transformation. The new parameter and
parameter and option serve the same purpose as the `max_memory_to_use` field in option serve the same purpose as the `max_memory_to_use` field in the
the `jpeg_memory_mgr` struct in the libjpeg API, the `JPEGMEM` environment `jpeg_memory_mgr` struct in the libjpeg API, the `JPEGMEM` environment
variable, and the cjpeg/djpeg/jpegtran `-maxmemory` option. variable, and the cjpeg/djpeg/jpegtran `-maxmemory` option.
3. Introduced a new parameter (`TJPARAM_MAXPIXELS` in the TurboJPEG C API and 3. Introduced a new parameter (`TJPARAM_MAXPIXELS` in the TurboJPEG C API and
@ -68,7 +126,7 @@ within the functions.
2. Fixed two minor issues in the interblock smoothing algorithm that caused 2. Fixed two minor issues in the interblock smoothing algorithm that caused
mathematical (but not necessarily perceptible) edge block errors when mathematical (but not necessarily perceptible) edge block errors when
decompressing progressive JPEG images exactly two MCU blocks in width or that decompressing progressive JPEG images exactly two DCT blocks in width or that
use vertical chrominance subsampling. use vertical chrominance subsampling.
3. Fixed a regression introduced by 3.0 beta2[6] that, in rare cases, caused 3. Fixed a regression introduced by 3.0 beta2[6] that, in rare cases, caused
@ -179,11 +237,10 @@ through pointer arguments.
- `TJFLAG_LIMITSCANS`/`TJ.FLAG_LIMITSCANS` has been reimplemented as an - `TJFLAG_LIMITSCANS`/`TJ.FLAG_LIMITSCANS` has been reimplemented as an
API parameter (`TJPARAM_SCANLIMIT`/`TJ.PARAM_SCANLIMIT`) that allows the number API parameter (`TJPARAM_SCANLIMIT`/`TJ.PARAM_SCANLIMIT`) that allows the number
of scans to be specified. of scans to be specified.
- Optimized baseline entropy coding (the computation of optimal Huffman - Huffman table optimization can now be specified using a new API
tables, as opposed to using the default Huffman tables) can now be specified, parameter (`TJPARAM_OPTIMIZE`/`TJ.PARAM_OPTIMIZE`), a new transform option
using a new API parameter (`TJPARAM_OPTIMIZE`/`TJ.PARAM_OPTIMIZE`), a new (`TJXOPT_OPTIMIZE`/`TJTransform.OPT_OPTIMIZE`), and a new TJBench option
transform option (`TJXOPT_OPTIMIZE`/`TJTransform.OPT_OPTIMIZE`), and a new (`-optimize`.)
TJBench option (`-optimize`.)
- Arithmetic entropy coding can now be specified or queried, using a new - Arithmetic entropy coding can now be specified or queried, using a new
API parameter (`TJPARAM_ARITHMETIC`/`TJ.PARAM_ARITHMETIC`), a new transform API parameter (`TJPARAM_ARITHMETIC`/`TJ.PARAM_ARITHMETIC`), a new transform
option (`TJXOPT_ARITHMETIC`/`TJTransform.OPT_ARITHMETIC`), and a new TJBench option (`TJXOPT_ARITHMETIC`/`TJTransform.OPT_ARITHMETIC`), and a new TJBench
@ -426,9 +483,9 @@ prevented libjpeg-turbo from working properly with other linkers and also
represented a potential security risk. represented a potential security risk.
2. Fixed an issue whereby the `tjTransform()` function incorrectly computed the 2. Fixed an issue whereby the `tjTransform()` function incorrectly computed the
MCU block size for 4:4:4 JPEG images with non-unary sampling factors and thus iMCU size for 4:4:4 JPEG images with non-unary sampling factors and thus unduly
unduly rejected some cropping regions, even though those regions aligned with rejected some cropping regions, even though those regions aligned with 8x8 iMCU
8x8 MCU block boundaries. boundaries.
3. Fixed a regression introduced by 2.1 beta1[13] that caused the build system 3. Fixed a regression introduced by 2.1 beta1[13] that caused the build system
to enable the Arm Neon SIMD extensions when targetting Armv6 and other legacy to enable the Arm Neon SIMD extensions when targetting Armv6 and other legacy
@ -1010,16 +1067,15 @@ encounters a warning from the underlying libjpeg API (the default behavior is
to allow the operation to complete unless a fatal error is encountered.) to allow the operation to complete unless a fatal error is encountered.)
5. Introduced a new flag in the TurboJPEG C and Java APIs (`TJFLAG_PROGRESSIVE` 5. Introduced a new flag in the TurboJPEG C and Java APIs (`TJFLAG_PROGRESSIVE`
and `TJ.FLAG_PROGRESSIVE`, respectively) that causes the library to use and `TJ.FLAG_PROGRESSIVE`, respectively) that causes compression and transform
progressive entropy coding in JPEG images generated by compression and operations to generate progressive JPEG images. Additionally, a new transform
transform operations. Additionally, a new transform option option (`TJXOPT_PROGRESSIVE` in the C API and `TJTransform.OPT_PROGRESSIVE` in
(`TJXOPT_PROGRESSIVE` in the C API and `TJTransform.OPT_PROGRESSIVE` in the the Java API) has been introduced, allowing progressive JPEG images to be
Java API) has been introduced, allowing progressive entropy coding to be generated by selected transforms in a multi-transform operation.
enabled for selected transforms in a multi-transform operation.
6. Introduced a new transform option in the TurboJPEG API (`TJXOPT_COPYNONE` in 6. Introduced a new transform option in the TurboJPEG API (`TJXOPT_COPYNONE` in
the C API and `TJTransform.OPT_COPYNONE` in the Java API) that allows the the C API and `TJTransform.OPT_COPYNONE` in the Java API) that allows the
copying of markers (including EXIF and ICC profile data) to be disabled for a copying of markers (including Exif and ICC profile data) to be disabled for a
particular transform. particular transform.
7. Added two functions to the TurboJPEG C API (`tjLoadImage()` and 7. Added two functions to the TurboJPEG C API (`tjLoadImage()` and
@ -1150,13 +1206,13 @@ bug that has existed since the introduction of libjpeg v7/v8 API/ABI emulation
in libjpeg-turbo v1.1. in libjpeg-turbo v1.1.
7. The lossless transform features in jpegtran and the TurboJPEG API will now 7. The lossless transform features in jpegtran and the TurboJPEG API will now
always attempt to adjust the EXIF image width and height tags if the image size always attempt to adjust the Exif image width and height tags if the image size
changed as a result of the transform. This behavior has always existed when changed as a result of the transform. This behavior has always existed when
using libjpeg v8 API/ABI emulation. It was supposed to be available with using libjpeg v8 API/ABI emulation. It was supposed to be available with
libjpeg v7 API/ABI emulation as well but did not work properly due to a bug. libjpeg v7 API/ABI emulation as well but did not work properly due to a bug.
Furthermore, there was never any good reason not to enable it with libjpeg v6b Furthermore, there was never any good reason not to enable it with libjpeg v6b
API/ABI emulation, since the behavior is entirely internal. Note that API/ABI emulation, since the behavior is entirely internal. Note that
`-copy all` must be passed to jpegtran in order to transfer the EXIF tags from `-copy all` must be passed to jpegtran in order to transfer the Exif tags from
the source image to the destination image. the source image to the destination image.
8. Fixed several memory leaks in the TurboJPEG API library that could occur 8. Fixed several memory leaks in the TurboJPEG API library that could occur
@ -1178,7 +1234,7 @@ for two reasons: it allows testers to more easily work around the 2 GB limit
in libFuzzer, and it allows developers of security-sensitive applications to in libFuzzer, and it allows developers of security-sensitive applications to
more easily defend against one of the progressive JPEG exploits (LJT-01-004) more easily defend against one of the progressive JPEG exploits (LJT-01-004)
identified in identified in
[this report](http://www.libjpeg-turbo.org/pmwiki/uploads/About/TwoIssueswiththeJPEGStandard.pdf). [this report](https://libjpeg-turbo.org/pmwiki/uploads/About/TwoIssueswiththeJPEGStandard.pdf).
10. TJBench will now run each benchmark for 1 second prior to starting the 10. TJBench will now run each benchmark for 1 second prior to starting the
timer, in order to improve the consistency of the results. Furthermore, the timer, in order to improve the consistency of the results. Furthermore, the

View File

@ -89,9 +89,9 @@ The library is intended to be reused in other applications.
In order to support file conversion and viewing software, we have included In order to support file conversion and viewing software, we have included
considerable functionality beyond the bare JPEG coding/decoding capability; considerable functionality beyond the bare JPEG coding/decoding capability;
for example, the color quantization modules are not strictly part of JPEG for example, the color quantization modules are not strictly part of JPEG
decoding, but they are essential for output to colormapped file formats or decoding, but they are essential for output to colormapped file formats. These
colormapped displays. These extra functions can be compiled out of the extra functions can be compiled out of the library if not required for a
library if not required for a particular application. particular application.
We have also included "jpegtran", a utility for lossless transcoding between We have also included "jpegtran", a utility for lossless transcoding between
different JPEG processes, and "rdjpgcom" and "wrjpgcom", two simple different JPEG processes, and "rdjpgcom" and "wrjpgcom", two simple

View File

@ -71,7 +71,8 @@ JPEG images:
top of the TurboJPEG API. The TurboJPEG API is recommended for first-time top of the TurboJPEG API. The TurboJPEG API is recommended for first-time
users of libjpeg-turbo. Refer to [tjexample.c](tjexample.c) and users of libjpeg-turbo. Refer to [tjexample.c](tjexample.c) and
[TJExample.java](java/TJExample.java) for examples of its usage and to [TJExample.java](java/TJExample.java) for examples of its usage and to
<http://libjpeg-turbo.org/Documentation/Documentation> for API documentation. <https://libjpeg-turbo.org/Documentation/Documentation> for API
documentation.
- **libjpeg API**<br> - **libjpeg API**<br>
This is the de facto industry-standard API for compressing and decompressing This is the de facto industry-standard API for compressing and decompressing
@ -199,7 +200,7 @@ supported and which aren't.
NOTE: As of this writing, extensive research has been conducted into the NOTE: As of this writing, extensive research has been conducted into the
usefulness of DCT scaling as a means of data reduction and SmartScale as a usefulness of DCT scaling as a means of data reduction and SmartScale as a
means of quality improvement. Readers are invited to peruse the research at means of quality improvement. Readers are invited to peruse the research at
<http://www.libjpeg-turbo.org/About/SmartScale> and draw their own conclusions, <https://libjpeg-turbo.org/About/SmartScale> and draw their own conclusions,
but it is the general belief of our project that these features have not but it is the general belief of our project that these features have not
demonstrated sufficient usefulness to justify inclusion in libjpeg-turbo. demonstrated sufficient usefulness to justify inclusion in libjpeg-turbo.

View File

@ -6,7 +6,7 @@
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 1999-2006, MIYASAKA Masaru. * Copyright (C) 1999-2006, MIYASAKA Masaru.
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2011, 2014-2015, 2022, D. R. Commander. * Copyright (C) 2011, 2014-2015, 2022, 2024, 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.
* *
@ -114,8 +114,8 @@ flss(UINT16 val)
* Compute values to do a division using reciprocal. * Compute values to do a division using reciprocal.
* *
* This implementation is based on an algorithm described in * This implementation is based on an algorithm described in
* "How to optimize for the Pentium family of microprocessors" * "Optimizing subroutines in assembly language:
* (http://www.agner.org/assem/). * An optimization guide for x86 platforms" (https://agner.org/optimize).
* More information about the basic algorithm can be found in * More information about the basic algorithm can be found in
* the paper "Integer Division Using Reciprocals" by Robert Alverson. * the paper "Integer Division Using Reciprocals" by Robert Alverson.
* *

View File

@ -542,6 +542,10 @@ encode_one_block_simd(working_state *state, JCOEFPTR block, int last_dc_val,
JOCTET _buffer[BUFSIZE], *buffer; JOCTET _buffer[BUFSIZE], *buffer;
int localbuf = 0; int localbuf = 0;
#ifdef ZERO_BUFFERS
memset(_buffer, 0, sizeof(_buffer));
#endif
LOAD_BUFFER() LOAD_BUFFER()
buffer = jsimd_huff_encode_one_block(state, buffer, block, last_dc_val, buffer = jsimd_huff_encode_one_block(state, buffer, block, last_dc_val,

View File

@ -751,22 +751,25 @@ jinit_c_master_control(j_compress_ptr cinfo, boolean transcode_only)
/* Validate parameters, determine derived values */ /* Validate parameters, determine derived values */
initial_setup(cinfo, transcode_only); initial_setup(cinfo, transcode_only);
if (cinfo->master->lossless || /* TEMPORARY HACK ??? */ if (cinfo->arith_code)
(cinfo->progressive_mode && !cinfo->arith_code)) cinfo->optimize_coding = FALSE;
cinfo->optimize_coding = TRUE; /* assume default tables no good for else {
progressive mode or lossless mode */ if (cinfo->master->lossless || /* TEMPORARY HACK ??? */
for (i = 0; i < NUM_HUFF_TBLS; i++) { cinfo->progressive_mode)
if (cinfo->dc_huff_tbl_ptrs[i] != NULL || cinfo->optimize_coding = TRUE; /* assume default tables no good for
cinfo->ac_huff_tbl_ptrs[i] != NULL) { progressive mode or lossless mode */
empty_huff_tables = FALSE; for (i = 0; i < NUM_HUFF_TBLS; i++) {
break; if (cinfo->dc_huff_tbl_ptrs[i] != NULL ||
cinfo->ac_huff_tbl_ptrs[i] != NULL) {
empty_huff_tables = FALSE;
break;
}
} }
if (cinfo->data_precision == 12 && !cinfo->optimize_coding &&
(empty_huff_tables || using_std_huff_tables(cinfo)))
cinfo->optimize_coding = TRUE; /* assume default tables no good for
12-bit data precision */
} }
if (cinfo->data_precision == 12 && !cinfo->arith_code &&
!cinfo->optimize_coding &&
(empty_huff_tables || using_std_huff_tables(cinfo)))
cinfo->optimize_coding = TRUE; /* assume default tables no good for 12-bit
data precision */
/* Initialize my private state */ /* Initialize my private state */
if (transcode_only) { if (transcode_only) {

View File

@ -3,8 +3,8 @@
* *
* 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-1997, Thomas G. Lane. * Copyright (C) 1994-1997, Thomas G. Lane.
* It was modified by The libjpeg-turbo Project to include only code relevant * libjpeg-turbo Modifications:
* to libjpeg-turbo. * Copyright (C) 2024, 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.
* *
@ -51,6 +51,7 @@ jpeg_abort(j_common_ptr cinfo)
* A bit kludgy to do it here, but this is the most central place. * A bit kludgy to do it here, but this is the most central place.
*/ */
((j_decompress_ptr)cinfo)->marker_list = NULL; ((j_decompress_ptr)cinfo)->marker_list = NULL;
((j_decompress_ptr)cinfo)->master->marker_list_end = NULL;
} else { } else {
cinfo->global_state = CSTATE_START; cinfo->global_state = CSTATE_START;
} }

View File

@ -233,7 +233,7 @@ jpeg_set_defaults(j_compress_ptr cinfo)
* tables will be computed. This test can be removed if default tables * tables will be computed. This test can be removed if default tables
* are supplied that are valid for the desired precision. * are supplied that are valid for the desired precision.
*/ */
if (cinfo->data_precision == 12 && !cinfo->arith_code) if (cinfo->data_precision == 12)
cinfo->optimize_coding = TRUE; cinfo->optimize_coding = TRUE;
/* By default, use the simpler non-cosited sampling alignment */ /* By default, use the simpler non-cosited sampling alignment */

View File

@ -650,6 +650,11 @@ encode_mcu_AC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
size_t bits[8 / SIZEOF_SIZE_T]; size_t bits[8 / SIZEOF_SIZE_T];
int max_coef_bits = cinfo->data_precision + 2; int max_coef_bits = cinfo->data_precision + 2;
#ifdef ZERO_BUFFERS
memset(values_unaligned, 0, sizeof(values_unaligned));
memset(bits, 0, sizeof(bits));
#endif
entropy->next_output_byte = cinfo->dest->next_output_byte; entropy->next_output_byte = cinfo->dest->next_output_byte;
entropy->free_in_buffer = cinfo->dest->free_in_buffer; entropy->free_in_buffer = cinfo->dest->free_in_buffer;
@ -915,6 +920,11 @@ encode_mcu_AC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
size_t zerobits, signbits; size_t zerobits, signbits;
size_t bits[16 / SIZEOF_SIZE_T]; size_t bits[16 / SIZEOF_SIZE_T];
#ifdef ZERO_BUFFERS
memset(absvalues_unaligned, 0, sizeof(absvalues_unaligned));
memset(bits, 0, sizeof(bits));
#endif
entropy->next_output_byte = cinfo->dest->next_output_byte; entropy->next_output_byte = cinfo->dest->next_output_byte;
entropy->free_in_buffer = cinfo->dest->free_in_buffer; entropy->free_in_buffer = cinfo->dest->free_in_buffer;

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) 2010, 2015-2020, 2022-2023, D. R. Commander. * Copyright (C) 2010, 2015-2020, 2022-2024, D. R. Commander.
* Copyright (C) 2015, Google, Inc. * Copyright (C) 2015, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
@ -200,7 +200,8 @@ _jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
ERREXIT(cinfo, JERR_BAD_CROP_SPEC); ERREXIT(cinfo, JERR_BAD_CROP_SPEC);
/* xoffset and width must fall within the output image dimensions. */ /* xoffset and width must fall within the output image dimensions. */
if (*width == 0 || *xoffset + *width > cinfo->output_width) if (*width == 0 ||
(unsigned long long)(*xoffset) + *width > cinfo->output_width)
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
/* No need to do anything if the caller wants the entire width. */ /* No need to do anything if the caller wants the entire width. */
@ -482,7 +483,8 @@ _jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
/* Do not skip past the bottom of the image. */ /* Do not skip past the bottom of the image. */
if (cinfo->output_scanline + num_lines >= cinfo->output_height) { if ((unsigned long long)cinfo->output_scanline + num_lines >=
cinfo->output_height) {
num_lines = cinfo->output_height - cinfo->output_scanline; num_lines = cinfo->output_height - cinfo->output_scanline;
cinfo->output_scanline = cinfo->output_height; cinfo->output_scanline = cinfo->output_height;
(*cinfo->inputctl->finish_input_pass) (cinfo); (*cinfo->inputctl->finish_input_pass) (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) 2012, 2015, 2022, D. R. Commander. * Copyright (C) 2012, 2015, 2022, 2024, 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.
* *
@ -248,6 +248,9 @@ get_sof(j_decompress_ptr cinfo, boolean is_prog, boolean is_lossless,
jpeg_component_info *compptr; jpeg_component_info *compptr;
INPUT_VARS(cinfo); INPUT_VARS(cinfo);
if (cinfo->marker->saw_SOF)
ERREXIT(cinfo, JERR_SOF_DUPLICATE);
cinfo->progressive_mode = is_prog; cinfo->progressive_mode = is_prog;
cinfo->master->lossless = is_lossless; cinfo->master->lossless = is_lossless;
cinfo->arith_code = is_arith; cinfo->arith_code = is_arith;
@ -265,9 +268,6 @@ get_sof(j_decompress_ptr cinfo, boolean is_prog, boolean is_lossless,
(int)cinfo->image_width, (int)cinfo->image_height, (int)cinfo->image_width, (int)cinfo->image_height,
cinfo->num_components); cinfo->num_components);
if (cinfo->marker->saw_SOF)
ERREXIT(cinfo, JERR_SOF_DUPLICATE);
/* We don't support files in which the image height is initially specified */ /* We don't support files in which the image height is initially specified */
/* as 0 and is later redefined by DNL. As long as we have to check that, */ /* as 0 and is later redefined by DNL. As long as we have to check that, */
/* might as well have a general sanity check. */ /* might as well have a general sanity check. */
@ -819,13 +819,11 @@ save_marker(j_decompress_ptr cinfo)
/* Done reading what we want to read */ /* Done reading what we want to read */
if (cur_marker != NULL) { /* will be NULL if bogus length word */ if (cur_marker != NULL) { /* will be NULL if bogus length word */
/* Add new marker to end of list */ /* Add new marker to end of list */
if (cinfo->marker_list == NULL) { if (cinfo->marker_list == NULL || cinfo->master->marker_list_end == NULL) {
cinfo->marker_list = cur_marker; cinfo->marker_list = cinfo->master->marker_list_end = cur_marker;
} else { } else {
jpeg_saved_marker_ptr prev = cinfo->marker_list; cinfo->master->marker_list_end->next = cur_marker;
while (prev->next != NULL) cinfo->master->marker_list_end = cur_marker;
prev = prev->next;
prev->next = cur_marker;
} }
/* Reset pointer & calc remaining data length */ /* Reset pointer & calc remaining data length */
data = cur_marker->data; data = cur_marker->data;

View File

@ -40,8 +40,6 @@
* Create the message string table. * Create the message string table.
* We do this from the master message list in jerror.h by re-reading * We do this from the master message list in jerror.h by re-reading
* jerror.h with a suitable definition for macro JMESSAGE. * jerror.h with a suitable definition for macro JMESSAGE.
* The message table is made an external symbol just in case any applications
* want to refer to it directly.
*/ */
#define JMESSAGE(code, string) string, #define JMESSAGE(code, string) string,

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) 1992-1996, Thomas G. Lane. * Copyright (C) 1992-1996, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2017-2018, D. R. Commander. * Copyright (C) 2017-2018, 2024, 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.
* *
@ -31,7 +31,7 @@
GLOBAL(void *) GLOBAL(void *)
jpeg_get_small(j_common_ptr cinfo, size_t sizeofobject) jpeg_get_small(j_common_ptr cinfo, size_t sizeofobject)
{ {
return (void *)malloc(sizeofobject); return (void *)MALLOC(sizeofobject);
} }
GLOBAL(void) GLOBAL(void)
@ -48,7 +48,7 @@ jpeg_free_small(j_common_ptr cinfo, void *object, size_t sizeofobject)
GLOBAL(void *) GLOBAL(void *)
jpeg_get_large(j_common_ptr cinfo, size_t sizeofobject) jpeg_get_large(j_common_ptr cinfo, size_t sizeofobject)
{ {
return (void *)malloc(sizeofobject); return (void *)MALLOC(sizeofobject);
} }
GLOBAL(void) GLOBAL(void)

View File

@ -7,7 +7,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) 2015-2017, 2019, 2021-2022, D. R. Commander. * Copyright (C) 2015-2017, 2019, 2021-2022, 2024, D. R. Commander.
* Copyright (C) 2015, Google, Inc. * Copyright (C) 2015, Google, Inc.
* Copyright (C) 2021, Alex Richardson. * Copyright (C) 2021, Alex Richardson.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
@ -249,6 +249,9 @@ struct jpeg_decomp_master {
/* Last iMCU row that was successfully decoded */ /* Last iMCU row that was successfully decoded */
JDIMENSION last_good_iMCU_row; JDIMENSION last_good_iMCU_row;
/* Tail of list of saved markers */
jpeg_saved_marker_ptr marker_list_end;
}; };
/* Input control module */ /* Input control module */
@ -443,6 +446,12 @@ struct jpeg_color_quantizer {
#undef MIN #undef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b))
#ifdef ZERO_BUFFERS
#define MALLOC(size) calloc(1, size)
#else
#define MALLOC(size) malloc(size)
#endif
/* We assume that right shift corresponds to signed division by 2 with /* We assume that right shift corresponds to signed division by 2 with
* rounding towards minus infinity. This is correct for typical "arithmetic * rounding towards minus infinity. This is correct for typical "arithmetic

View File

@ -7,7 +7,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) 2009-2011, 2013-2014, 2016-2017, 2020, 2022-2023, * Copyright (C) 2009-2011, 2013-2014, 2016-2017, 2020, 2022-2024,
D. R. Commander. D. R. Commander.
* Copyright (C) 2015, Google, Inc. * Copyright (C) 2015, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
@ -18,6 +18,16 @@
* and perhaps jerror.h if they want to know the exact error codes. * and perhaps jerror.h if they want to know the exact error codes.
*/ */
/* NOTE: This header file does not include stdio.h, despite the fact that it
* uses FILE and size_t. That is by design, since the libjpeg API predates the
* widespread adoption of ANSI/ISO C. Referring to libjpeg.txt, it is a
* documented requirement that calling programs "include system headers that
* define at least the typedefs FILE and size_t" before including jpeglib.h.
* Technically speaking, changing that requirement by including stdio.h here
* would break backward API compatibility. Please do not file bug reports,
* feature requests, or pull requests regarding this.
*/
#ifndef JPEGLIB_H #ifndef JPEGLIB_H
#define JPEGLIB_H #define JPEGLIB_H
@ -575,11 +585,10 @@ struct jpeg_decompress_struct {
*/ */
int actual_number_of_colors; /* number of entries in use */ int actual_number_of_colors; /* number of entries in use */
JSAMPARRAY colormap; /* The color map as a 2-D pixel array JSAMPARRAY colormap; /* The color map as a 2-D pixel array
If data_precision is 12 or 16, then this is If data_precision is 12, then this is
actually a J12SAMPARRAY or a J16SAMPARRAY, actually a J12SAMPARRAY, so callers must
so callers must type-cast it in order to type-cast it in order to read/write 12-bit
read/write 12-bit or 16-bit samples from/to samples from/to the array. */
the array. */
/* State variables: these variables indicate the progress of decompression. /* State variables: these variables indicate the progress of decompression.
* The application may examine these but must not modify them. * The application may examine these but must not modify them.

View File

@ -86,22 +86,22 @@ static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
* Stephen Hawley's article "Ordered Dithering" in Graphics Gems I. * Stephen Hawley's article "Ordered Dithering" in Graphics Gems I.
* The values in this array must range from 0 to ODITHER_CELLS-1. * The values in this array must range from 0 to ODITHER_CELLS-1.
*/ */
{ 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 }, { 0, 192, 48, 240, 12, 204, 60, 252, 3, 195, 51, 243, 15, 207, 63, 255 },
{ 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 }, { 128, 64, 176, 112, 140, 76, 188, 124, 131, 67, 179, 115, 143, 79, 191, 127 },
{ 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 }, { 32, 224, 16, 208, 44, 236, 28, 220, 35, 227, 19, 211, 47, 239, 31, 223 },
{ 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 }, { 160, 96, 144, 80, 172, 108, 156, 92, 163, 99, 147, 83, 175, 111, 159, 95 },
{ 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 }, { 8, 200, 56, 248, 4, 196, 52, 244, 11, 203, 59, 251, 7, 199, 55, 247 },
{ 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 }, { 136, 72, 184, 120, 132, 68, 180, 116, 139, 75, 187, 123, 135, 71, 183, 119 },
{ 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 }, { 40, 232, 24, 216, 36, 228, 20, 212, 43, 235, 27, 219, 39, 231, 23, 215 },
{ 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 }, { 168, 104, 152, 88, 164, 100, 148, 84, 171, 107, 155, 91, 167, 103, 151, 87 },
{ 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 }, { 2, 194, 50, 242, 14, 206, 62, 254, 1, 193, 49, 241, 13, 205, 61, 253 },
{ 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 }, { 130, 66, 178, 114, 142, 78, 190, 126, 129, 65, 177, 113, 141, 77, 189, 125 },
{ 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 }, { 34, 226, 18, 210, 46, 238, 30, 222, 33, 225, 17, 209, 45, 237, 29, 221 },
{ 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 }, { 162, 98, 146, 82, 174, 110, 158, 94, 161, 97, 145, 81, 173, 109, 157, 93 },
{ 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 }, { 10, 202, 58, 250, 6, 198, 54, 246, 9, 201, 57, 249, 5, 197, 53, 245 },
{ 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 }, { 138, 74, 186, 122, 134, 70, 182, 118, 137, 73, 185, 121, 133, 69, 181, 117 },
{ 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 }, { 42, 234, 26, 218, 38, 230, 22, 214, 41, 233, 25, 217, 37, 229, 21, 213 },
{ 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 } { 170, 106, 154, 90, 166, 102, 150, 86, 169, 105, 153, 89, 165, 101, 149, 85 }
}; };