From 3358df7da4fc238757205564a6d4018ad5e34bb5 Mon Sep 17 00:00:00 2001 From: DRC Date: Mon, 18 Nov 2024 13:40:08 -0500 Subject: [PATCH] Exclude more code if !(C|D)_LOSSLESS_SUPPORTED --- jccolor.c | 10 ++++++++++ jcmaster.c | 2 ++ jcparam.c | 4 ++++ jdapimin.c | 4 ++++ jdcolor.c | 8 ++++++++ jdmaster.c | 2 ++ 6 files changed, 30 insertions(+) diff --git a/jccolor.c b/jccolor.c index cd3a6a7a5..cc7337be0 100644 --- a/jccolor.c +++ b/jccolor.c @@ -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) { diff --git a/jcmaster.c b/jcmaster.c index 5d8917834..acedeef1a 100644 --- a/jcmaster.c +++ b/jcmaster.c @@ -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); diff --git a/jcparam.c b/jcparam.c index f3a62afc0..d74623c20 100644 --- a/jcparam.c +++ b/jcparam.c @@ -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) { diff --git a/jdapimin.c b/jdapimin.c index 30d92841a..f2419f8ad 100644 --- a/jdapimin.c +++ b/jdapimin.c @@ -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 */ } } diff --git a/jdcolor.c b/jdcolor.c index e5c7b58eb..c142158f8 100644 --- a/jdcolor.c +++ b/jdcolor.c @@ -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; diff --git a/jdmaster.c b/jdmaster.c index 80a4842ac..0db6f1763 100644 --- a/jdmaster.c +++ b/jdmaster.c @@ -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);