Skip to content

Commit

Permalink
Exclude more code if !(C|D)_LOSSLESS_SUPPORTED
Browse files Browse the repository at this point in the history
  • Loading branch information
dcommander committed Nov 18, 2024
1 parent 4e55d44 commit 3358df7
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions jccolor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 &&
Expand All @@ -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)) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions jcmaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions jcparam.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions jdapimin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
}
}
Expand Down
8 changes: 8 additions & 0 deletions jdcolor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions jdmaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3358df7

Please sign in to comment.