Merge branch 'ijg.lossless' into dev
Lossless: Accommodate LJT colorspace/SIMD exts In libjpeg-turbo, grayscale_convert() and null_convert() aren't the only lossless color conversion algorithms. We can also losslessly convert RGB to and from any of the extended RGB colorspaces, and some platforms have SIMD-accelerated null color conversion. This commit also disallows RGB565 output in lossless mode, and it moves the IsExtRGB() macro from cdjpeg.h to jpegint.h and repurposes it to make jinit_color_converter() and jinit_color_deconverter() more readable.
This commit is contained in:
21
jdcolor.c
21
jdcolor.c
@@ -776,10 +776,15 @@ _jinit_color_deconverter(j_decompress_ptr cinfo)
|
||||
/* Set out_color_components and conversion method based on requested space.
|
||||
* Also clear the component_needed flags for any unused components,
|
||||
* so that earlier pipeline stages can avoid useless computation.
|
||||
* NOTE: We do not allow any lossy color conversion algorithms in lossless
|
||||
* mode.
|
||||
*/
|
||||
|
||||
switch (cinfo->out_color_space) {
|
||||
case JCS_GRAYSCALE:
|
||||
if (cinfo->master->lossless &&
|
||||
cinfo->jpeg_color_space != cinfo->out_color_space)
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
cinfo->out_color_components = 1;
|
||||
if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
|
||||
cinfo->jpeg_color_space == JCS_YCbCr) {
|
||||
@@ -805,6 +810,8 @@ _jinit_color_deconverter(j_decompress_ptr cinfo)
|
||||
case JCS_EXT_BGRA:
|
||||
case JCS_EXT_ABGR:
|
||||
case JCS_EXT_ARGB:
|
||||
if (cinfo->master->lossless && cinfo->jpeg_color_space != JCS_RGB)
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
cinfo->out_color_components = rgb_pixelsize[cinfo->out_color_space];
|
||||
if (cinfo->jpeg_color_space == JCS_YCbCr) {
|
||||
#ifdef WITH_SIMD
|
||||
@@ -831,6 +838,8 @@ _jinit_color_deconverter(j_decompress_ptr cinfo)
|
||||
break;
|
||||
|
||||
case JCS_RGB565:
|
||||
if (cinfo->master->lossless)
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
cinfo->out_color_components = 3;
|
||||
if (cinfo->dither_mode == JDITHER_NONE) {
|
||||
if (cinfo->jpeg_color_space == JCS_YCbCr) {
|
||||
@@ -864,6 +873,9 @@ _jinit_color_deconverter(j_decompress_ptr cinfo)
|
||||
break;
|
||||
|
||||
case JCS_CMYK:
|
||||
if (cinfo->master->lossless &&
|
||||
cinfo->jpeg_color_space != cinfo->out_color_space)
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
cinfo->out_color_components = 4;
|
||||
if (cinfo->jpeg_color_space == JCS_YCCK) {
|
||||
cconvert->pub._color_convert = ycck_cmyk_convert;
|
||||
@@ -884,15 +896,6 @@ _jinit_color_deconverter(j_decompress_ptr cinfo)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Prevent lossy color conversion in lossless mode */
|
||||
if (cinfo->master->lossless) {
|
||||
if ((cinfo->out_color_space == JCS_GRAYSCALE &&
|
||||
cinfo->jpeg_color_space != JCS_GRAYSCALE) ||
|
||||
(cinfo->out_color_space != JCS_GRAYSCALE &&
|
||||
cconvert->pub._color_convert != null_convert))
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
}
|
||||
|
||||
if (cinfo->quantize_colors)
|
||||
cinfo->output_components = 1; /* single colormapped output component */
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user