12-bit: Set alpha channel to 4095 rather than 255

This commit is contained in:
DRC
2023-01-17 11:04:38 -06:00
parent 0c0df2d0c7
commit 08cbc23334
4 changed files with 31 additions and 27 deletions

View File

@@ -41,6 +41,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

@@ -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, D. R. Commander. * Copyright (C) 2009, 2011, 2015, 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.
* *
@@ -62,10 +62,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 opaque */
/* alpha channel value */ /* 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;
} }
@@ -94,10 +94,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 opaque */
/* alpha channel value */ /* 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;
} }
@@ -130,10 +130,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 opaque */
/* alpha channel value */ /* 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, D. R. Commander. * Copyright (C) 2011, 2015, 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.
* *
@@ -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
} }
} }

20
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.
* *
@@ -179,13 +179,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)], {})
} }
@@ -253,13 +253,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)], {})
} }
@@ -345,12 +345,12 @@ 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++)], {})
} }
@@ -413,12 +413,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++)], {})
} }
@@ -543,7 +543,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;