Exclude more code if !(C|D)_LOSSLESS_SUPPORTED

This commit is contained in:
DRC
2024-11-18 13:40:08 -05:00
parent 4e55d44658
commit 3358df7da4
6 changed files with 30 additions and 0 deletions

View File

@@ -607,9 +607,11 @@ _jinit_color_converter(j_compress_ptr cinfo)
*/
switch (cinfo->jpeg_color_space) {
case JCS_GRAYSCALE:
#ifdef C_LOSSLESS_SUPPORTED
if (cinfo->master->lossless &&
cinfo->in_color_space != cinfo->jpeg_color_space)
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
#endif
if (cinfo->num_components != 1)
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
if (cinfo->in_color_space == JCS_GRAYSCALE)
@@ -631,8 +633,10 @@ _jinit_color_converter(j_compress_ptr cinfo)
break;
case JCS_RGB:
#ifdef C_LOSSLESS_SUPPORTED
if (cinfo->master->lossless && !IsExtRGB(cinfo->in_color_space))
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
#endif
if (cinfo->num_components != 3)
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
if (rgb_red[cinfo->in_color_space] == 0 &&
@@ -652,9 +656,11 @@ _jinit_color_converter(j_compress_ptr cinfo)
break;
case JCS_YCbCr:
#ifdef C_LOSSLESS_SUPPORTED
if (cinfo->master->lossless &&
cinfo->in_color_space != cinfo->jpeg_color_space)
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
#endif
if (cinfo->num_components != 3)
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
if (IsExtRGB(cinfo->in_color_space)) {
@@ -679,9 +685,11 @@ _jinit_color_converter(j_compress_ptr cinfo)
break;
case JCS_CMYK:
#ifdef C_LOSSLESS_SUPPORTED
if (cinfo->master->lossless &&
cinfo->in_color_space != cinfo->jpeg_color_space)
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
#endif
if (cinfo->num_components != 4)
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
if (cinfo->in_color_space == JCS_CMYK) {
@@ -696,9 +704,11 @@ _jinit_color_converter(j_compress_ptr cinfo)
break;
case JCS_YCCK:
#ifdef C_LOSSLESS_SUPPORTED
if (cinfo->master->lossless &&
cinfo->in_color_space != cinfo->jpeg_color_space)
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
#endif
if (cinfo->num_components != 4)
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
if (cinfo->in_color_space == JCS_CMYK) {

View File

@@ -731,6 +731,7 @@ jinit_c_master_control(j_compress_ptr cinfo, boolean transcode_only)
cinfo->num_scans = 1;
}
#ifdef C_LOSSLESS_SUPPORTED
/* Disable smoothing and subsampling in lossless mode, since those are lossy
* algorithms. Set the JPEG colorspace to the input colorspace. Disable raw
* (downsampled) data input, because it isn't particularly useful without
@@ -747,6 +748,7 @@ jinit_c_master_control(j_compress_ptr cinfo, boolean transcode_only)
ci++, compptr++)
compptr->h_samp_factor = compptr->v_samp_factor = 1;
}
#endif
/* Validate parameters, determine derived values */
initial_setup(cinfo, transcode_only);

View File

@@ -300,9 +300,11 @@ jpeg_default_colorspace(j_compress_ptr cinfo)
case JCS_EXT_BGRA:
case JCS_EXT_ABGR:
case JCS_EXT_ARGB:
#ifdef C_LOSSLESS_SUPPORTED
if (cinfo->master->lossless)
jpeg_set_colorspace(cinfo, JCS_RGB);
else
#endif
jpeg_set_colorspace(cinfo, JCS_YCbCr);
break;
case JCS_YCbCr:
@@ -482,10 +484,12 @@ jpeg_simple_progression(j_compress_ptr cinfo)
if (cinfo->global_state != CSTATE_START)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
#ifdef C_LOSSLESS_SUPPORTED
if (cinfo->master->lossless) {
cinfo->master->lossless = FALSE;
jpeg_default_colorspace(cinfo);
}
#endif
/* Figure space needed for script. Calculation must match code below! */
if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {

View File

@@ -161,17 +161,21 @@ default_decompress_parms(j_decompress_ptr cinfo)
int cid2 = cinfo->comp_info[2].component_id;
if (cid0 == 1 && cid1 == 2 && cid2 == 3) {
#ifdef D_LOSSLESS_SUPPORTED
if (cinfo->master->lossless)
cinfo->jpeg_color_space = JCS_RGB; /* assume RGB w/out marker */
else
#endif
cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
} else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
else {
TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
#ifdef D_LOSSLESS_SUPPORTED
if (cinfo->master->lossless)
cinfo->jpeg_color_space = JCS_RGB; /* assume it's RGB */
else
#endif
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
}
}

View File

@@ -802,9 +802,11 @@ _jinit_color_deconverter(j_decompress_ptr cinfo)
switch (cinfo->out_color_space) {
case JCS_GRAYSCALE:
#ifdef D_LOSSLESS_SUPPORTED
if (cinfo->master->lossless &&
cinfo->jpeg_color_space != cinfo->out_color_space)
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
#endif
cinfo->out_color_components = 1;
if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
cinfo->jpeg_color_space == JCS_YCbCr) {
@@ -830,8 +832,10 @@ _jinit_color_deconverter(j_decompress_ptr cinfo)
case JCS_EXT_BGRA:
case JCS_EXT_ABGR:
case JCS_EXT_ARGB:
#ifdef D_LOSSLESS_SUPPORTED
if (cinfo->master->lossless && cinfo->jpeg_color_space != JCS_RGB)
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
#endif
cinfo->out_color_components = rgb_pixelsize[cinfo->out_color_space];
if (cinfo->jpeg_color_space == JCS_YCbCr) {
#ifdef WITH_SIMD
@@ -858,8 +862,10 @@ _jinit_color_deconverter(j_decompress_ptr cinfo)
break;
case JCS_RGB565:
#ifdef D_LOSSLESS_SUPPORTED
if (cinfo->master->lossless)
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
#endif
cinfo->out_color_components = 3;
if (cinfo->dither_mode == JDITHER_NONE) {
if (cinfo->jpeg_color_space == JCS_YCbCr) {
@@ -893,9 +899,11 @@ _jinit_color_deconverter(j_decompress_ptr cinfo)
break;
case JCS_CMYK:
#ifdef D_LOSSLESS_SUPPORTED
if (cinfo->master->lossless &&
cinfo->jpeg_color_space != cinfo->out_color_space)
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
#endif
cinfo->out_color_components = 4;
if (cinfo->jpeg_color_space == JCS_YCCK) {
cconvert->pub._color_convert = ycck_cmyk_convert;

View File

@@ -521,10 +521,12 @@ master_selection(j_decompress_ptr cinfo)
* particularly useful without subsampling and has not been tested in
* lossless mode.
*/
#ifdef D_LOSSLESS_SUPPORTED
if (cinfo->master->lossless) {
cinfo->raw_data_out = FALSE;
cinfo->scale_num = cinfo->scale_denom = 1;
}
#endif
/* Initialize dimensions and other stuff */
jpeg_calc_output_dimensions(cinfo);