Merge branch 'main' into dev

This commit is contained in:
DRC
2023-01-17 18:31:31 -06:00
5 changed files with 37 additions and 32 deletions

View File

@@ -101,6 +101,10 @@ strides to pass to `tjDecompressToYUVPlanes()`. This caused a buffer overrun
and subsequent segfault if the desired image dimensions exceeded the scaled and subsequent segfault if the desired image dimensions exceeded the scaled
image dimensions. image dimensions.
7. Fixed an issue whereby, when decompressing a 12-bit-per-component JPEG image
(`-DWITH_12BIT=1`) using an alpha-enabled output color space such as
`JCS_EXT_RGBA`, the alpha channel was set to 255 rather than 4095.
2.1.4 2.1.4
===== =====

View File

@@ -398,7 +398,7 @@ public class TJDecompressor implements Closeable {
int pitch, int desiredHeight, int pixelFormat, int pitch, int desiredHeight, int pixelFormat,
int flags) throws TJException { int flags) throws TJException {
if (jpegBuf == null && yuvImage == null) if (jpegBuf == null && yuvImage == null)
throw new IllegalStateException(NO_ASSOC_ERROR); throw new IllegalStateException("No source image is associated with this instance");
if (dstBuf == null || x < 0 || y < 0 || pitch < 0 || if (dstBuf == null || x < 0 || y < 0 || pitch < 0 ||
(yuvImage != null && (desiredWidth < 0 || desiredHeight < 0)) || (yuvImage != null && (desiredWidth < 0 || desiredHeight < 0)) ||
pixelFormat < 0 || pixelFormat >= TJ.NUMPF || flags < 0) pixelFormat < 0 || pixelFormat >= TJ.NUMPF || flags < 0)
@@ -681,7 +681,7 @@ public class TJDecompressor implements Closeable {
int stride, int desiredHeight, int pixelFormat, int stride, int desiredHeight, int pixelFormat,
int flags) throws TJException { int flags) throws TJException {
if (jpegBuf == null && yuvImage == null) if (jpegBuf == null && yuvImage == null)
throw new IllegalStateException(NO_ASSOC_ERROR); throw new IllegalStateException("No source image is associated with this instance");
if (dstBuf == null || x < 0 || y < 0 || stride < 0 || if (dstBuf == null || x < 0 || y < 0 || stride < 0 ||
(yuvImage != null && (desiredWidth < 0 || desiredHeight < 0)) || (yuvImage != null && (desiredWidth < 0 || desiredHeight < 0)) ||
pixelFormat < 0 || pixelFormat >= TJ.NUMPF || flags < 0) pixelFormat < 0 || pixelFormat >= TJ.NUMPF || flags < 0)

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-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2009, 2011, 2015, 2022, D. R. Commander. * Copyright (C) 2009, 2011, 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.
* *
@@ -63,10 +63,10 @@ ycc_rgb_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
SCALEBITS))]; SCALEBITS))];
outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]]; outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
/* Set unused byte to 0xFF so it can be interpreted as an opaque */ /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
/* alpha channel value */ /* opaque alpha channel value */
#ifdef RGB_ALPHA #ifdef RGB_ALPHA
outptr[RGB_ALPHA] = 0xFF; outptr[RGB_ALPHA] = _MAXJSAMPLE;
#endif #endif
outptr += RGB_PIXELSIZE; outptr += RGB_PIXELSIZE;
} }
@@ -98,10 +98,10 @@ gray_rgb_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
outptr = *output_buf++; outptr = *output_buf++;
for (col = 0; col < num_cols; col++) { for (col = 0; col < num_cols; col++) {
outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col]; outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
/* Set unused byte to 0xFF so it can be interpreted as an opaque */ /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
/* alpha channel value */ /* opaque alpha channel value */
#ifdef RGB_ALPHA #ifdef RGB_ALPHA
outptr[RGB_ALPHA] = 0xFF; outptr[RGB_ALPHA] = _MAXJSAMPLE;
#endif #endif
outptr += RGB_PIXELSIZE; outptr += RGB_PIXELSIZE;
} }
@@ -134,10 +134,10 @@ rgb_rgb_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
outptr[RGB_RED] = inptr0[col]; outptr[RGB_RED] = inptr0[col];
outptr[RGB_GREEN] = inptr1[col]; outptr[RGB_GREEN] = inptr1[col];
outptr[RGB_BLUE] = inptr2[col]; outptr[RGB_BLUE] = inptr2[col];
/* Set unused byte to 0xFF so it can be interpreted as an opaque */ /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
/* alpha channel value */ /* opaque alpha channel value */
#ifdef RGB_ALPHA #ifdef RGB_ALPHA
outptr[RGB_ALPHA] = 0xFF; outptr[RGB_ALPHA] = _MAXJSAMPLE;
#endif #endif
outptr += RGB_PIXELSIZE; outptr += RGB_PIXELSIZE;
} }

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) 2011, 2015, 2020, 2022, D. R. Commander. * Copyright (C) 2011, 2015, 2020, 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.
* *
@@ -57,7 +57,7 @@ h2v1_merged_upsample_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
outptr[RGB_GREEN] = range_limit[y + cgreen]; outptr[RGB_GREEN] = range_limit[y + cgreen];
outptr[RGB_BLUE] = range_limit[y + cblue]; outptr[RGB_BLUE] = range_limit[y + cblue];
#ifdef RGB_ALPHA #ifdef RGB_ALPHA
outptr[RGB_ALPHA] = 0xFF; outptr[RGB_ALPHA] = _MAXJSAMPLE;
#endif #endif
outptr += RGB_PIXELSIZE; outptr += RGB_PIXELSIZE;
y = *inptr0++; y = *inptr0++;
@@ -65,7 +65,7 @@ h2v1_merged_upsample_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
outptr[RGB_GREEN] = range_limit[y + cgreen]; outptr[RGB_GREEN] = range_limit[y + cgreen];
outptr[RGB_BLUE] = range_limit[y + cblue]; outptr[RGB_BLUE] = range_limit[y + cblue];
#ifdef RGB_ALPHA #ifdef RGB_ALPHA
outptr[RGB_ALPHA] = 0xFF; outptr[RGB_ALPHA] = _MAXJSAMPLE;
#endif #endif
outptr += RGB_PIXELSIZE; outptr += RGB_PIXELSIZE;
} }
@@ -81,7 +81,7 @@ h2v1_merged_upsample_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
outptr[RGB_GREEN] = range_limit[y + cgreen]; outptr[RGB_GREEN] = range_limit[y + cgreen];
outptr[RGB_BLUE] = range_limit[y + cblue]; outptr[RGB_BLUE] = range_limit[y + cblue];
#ifdef RGB_ALPHA #ifdef RGB_ALPHA
outptr[RGB_ALPHA] = 0xFF; outptr[RGB_ALPHA] = _MAXJSAMPLE;
#endif #endif
} }
} }
@@ -131,7 +131,7 @@ h2v2_merged_upsample_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
outptr0[RGB_GREEN] = range_limit[y + cgreen]; outptr0[RGB_GREEN] = range_limit[y + cgreen];
outptr0[RGB_BLUE] = range_limit[y + cblue]; outptr0[RGB_BLUE] = range_limit[y + cblue];
#ifdef RGB_ALPHA #ifdef RGB_ALPHA
outptr0[RGB_ALPHA] = 0xFF; outptr0[RGB_ALPHA] = _MAXJSAMPLE;
#endif #endif
outptr0 += RGB_PIXELSIZE; outptr0 += RGB_PIXELSIZE;
y = *inptr00++; y = *inptr00++;
@@ -139,7 +139,7 @@ h2v2_merged_upsample_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
outptr0[RGB_GREEN] = range_limit[y + cgreen]; outptr0[RGB_GREEN] = range_limit[y + cgreen];
outptr0[RGB_BLUE] = range_limit[y + cblue]; outptr0[RGB_BLUE] = range_limit[y + cblue];
#ifdef RGB_ALPHA #ifdef RGB_ALPHA
outptr0[RGB_ALPHA] = 0xFF; outptr0[RGB_ALPHA] = _MAXJSAMPLE;
#endif #endif
outptr0 += RGB_PIXELSIZE; outptr0 += RGB_PIXELSIZE;
y = *inptr01++; y = *inptr01++;
@@ -147,7 +147,7 @@ h2v2_merged_upsample_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
outptr1[RGB_GREEN] = range_limit[y + cgreen]; outptr1[RGB_GREEN] = range_limit[y + cgreen];
outptr1[RGB_BLUE] = range_limit[y + cblue]; outptr1[RGB_BLUE] = range_limit[y + cblue];
#ifdef RGB_ALPHA #ifdef RGB_ALPHA
outptr1[RGB_ALPHA] = 0xFF; outptr1[RGB_ALPHA] = _MAXJSAMPLE;
#endif #endif
outptr1 += RGB_PIXELSIZE; outptr1 += RGB_PIXELSIZE;
y = *inptr01++; y = *inptr01++;
@@ -155,7 +155,7 @@ h2v2_merged_upsample_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
outptr1[RGB_GREEN] = range_limit[y + cgreen]; outptr1[RGB_GREEN] = range_limit[y + cgreen];
outptr1[RGB_BLUE] = range_limit[y + cblue]; outptr1[RGB_BLUE] = range_limit[y + cblue];
#ifdef RGB_ALPHA #ifdef RGB_ALPHA
outptr1[RGB_ALPHA] = 0xFF; outptr1[RGB_ALPHA] = _MAXJSAMPLE;
#endif #endif
outptr1 += RGB_PIXELSIZE; outptr1 += RGB_PIXELSIZE;
} }
@@ -171,14 +171,14 @@ h2v2_merged_upsample_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
outptr0[RGB_GREEN] = range_limit[y + cgreen]; outptr0[RGB_GREEN] = range_limit[y + cgreen];
outptr0[RGB_BLUE] = range_limit[y + cblue]; outptr0[RGB_BLUE] = range_limit[y + cblue];
#ifdef RGB_ALPHA #ifdef RGB_ALPHA
outptr0[RGB_ALPHA] = 0xFF; outptr0[RGB_ALPHA] = _MAXJSAMPLE;
#endif #endif
y = *inptr01; y = *inptr01;
outptr1[RGB_RED] = range_limit[y + cred]; outptr1[RGB_RED] = range_limit[y + cred];
outptr1[RGB_GREEN] = range_limit[y + cgreen]; outptr1[RGB_GREEN] = range_limit[y + cgreen];
outptr1[RGB_BLUE] = range_limit[y + cblue]; outptr1[RGB_BLUE] = range_limit[y + cblue];
#ifdef RGB_ALPHA #ifdef RGB_ALPHA
outptr1[RGB_ALPHA] = 0xFF; outptr1[RGB_ALPHA] = _MAXJSAMPLE;
#endif #endif
} }
} }

21
rdppm.c
View File

@@ -5,7 +5,7 @@
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2009 by Bill Allombert, Guido Vollbeding. * Modified 2009 by Bill Allombert, Guido Vollbeding.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2015-2017, 2020-2022, D. R. Commander. * Copyright (C) 2015-2017, 2020-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.
* *
@@ -180,13 +180,13 @@ get_text_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
if (maxval == _MAXJSAMPLE) { if (maxval == _MAXJSAMPLE) {
if (aindex >= 0) if (aindex >= 0)
GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
ptr[aindex] = 0xFF;) ptr[aindex] = _MAXJSAMPLE;)
else else
GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {}) GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
} else { } else {
if (aindex >= 0) if (aindex >= 0)
GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
ptr[aindex] = 0xFF;) ptr[aindex] = _MAXJSAMPLE;)
else else
GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {}) GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
} }
@@ -254,13 +254,13 @@ get_text_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
if (maxval == _MAXJSAMPLE) { if (maxval == _MAXJSAMPLE) {
if (aindex >= 0) if (aindex >= 0)
RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
ptr[aindex] = 0xFF;) ptr[aindex] = _MAXJSAMPLE;)
else else
RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {}) RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
} else { } else {
if (aindex >= 0) if (aindex >= 0)
RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
ptr[aindex] = 0xFF;) ptr[aindex] = _MAXJSAMPLE;)
else else
RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {}) RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
} }
@@ -346,12 +346,13 @@ get_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
bufferptr = source->iobuffer; bufferptr = source->iobuffer;
if (maxval == _MAXJSAMPLE) { if (maxval == _MAXJSAMPLE) {
if (aindex >= 0) if (aindex >= 0)
GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = 0xFF;) GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;)
else else
GRAY_RGB_READ_LOOP(*bufferptr++, {}) GRAY_RGB_READ_LOOP(*bufferptr++, {})
} else { } else {
if (aindex >= 0) if (aindex >= 0)
GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], ptr[aindex] = 0xFF;) GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
ptr[aindex] = _MAXJSAMPLE;)
else else
GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {}) GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
} }
@@ -414,12 +415,12 @@ get_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
bufferptr = source->iobuffer; bufferptr = source->iobuffer;
if (maxval == _MAXJSAMPLE) { if (maxval == _MAXJSAMPLE) {
if (aindex >= 0) if (aindex >= 0)
RGB_READ_LOOP(*bufferptr++, ptr[aindex] = 0xFF;) RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;)
else else
RGB_READ_LOOP(*bufferptr++, {}) RGB_READ_LOOP(*bufferptr++, {})
} else { } else {
if (aindex >= 0) if (aindex >= 0)
RGB_READ_LOOP(rescale[UCH(*bufferptr++)], ptr[aindex] = 0xFF;) RGB_READ_LOOP(rescale[UCH(*bufferptr++)], ptr[aindex] = _MAXJSAMPLE;)
else else
RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {}) RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
} }
@@ -544,7 +545,7 @@ get_word_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
ptr[bindex] = rescale[temp]; ptr[bindex] = rescale[temp];
if (aindex >= 0) if (aindex >= 0)
ptr[aindex] = 0xFF; ptr[aindex] = _MAXJSAMPLE;
ptr += ps; ptr += ps;
} }
return 1; return 1;