Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Enable the use of separate luminance/chrominance quality scaling with…
… libjpeg v6b code base as well

git-svn-id: https://libjpeg-turbo.svn.sourceforge.net/svnroot/libjpeg-turbo/trunk@251 3789f03b-4d11-0410-bbf8-ca57d06f2519
  • Loading branch information
dcommander committed Oct 11, 2010
1 parent 03d8af8 commit 8b89a36
Showing 1 changed file with 46 additions and 6 deletions.
52 changes: 46 additions & 6 deletions rdswitch.c
Expand Up @@ -2,6 +2,7 @@
* rdswitch.c
*
* Copyright (C) 1991-1996, Thomas G. Lane.
* Copyright (C) 2010, D. R. Commander.
* This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file.
*
Expand Down Expand Up @@ -71,7 +72,7 @@ read_text_integer (FILE * file, long * result, int * termchar)


#if JPEG_LIB_VERSION < 70
static int q_scale_factor = 100;
static int q_scale_factor[NUM_QUANT_TBLS] = {100, 100, 100, 100};
#endif

GLOBAL(boolean)
Expand Down Expand Up @@ -116,7 +117,8 @@ read_quant_tables (j_compress_ptr cinfo, char * filename, boolean force_baseline
jpeg_add_quant_table(cinfo, tblno, table, cinfo->q_scale_factor[tblno],
force_baseline);
#else
jpeg_add_quant_table(cinfo, tblno, table, q_scale_factor, force_baseline);
jpeg_add_quant_table(cinfo, tblno, table, q_scale_factor[tblno],
force_baseline);
#endif
tblno++;
}
Expand Down Expand Up @@ -271,6 +273,44 @@ read_scan_script (j_compress_ptr cinfo, char * filename)
#endif /* C_MULTISCAN_FILES_SUPPORTED */


#if JPEG_LIB_VERSION < 70
/* These are the sample quantization tables given in JPEG spec section K.1.
* The spec says that the values given produce "good" quality, and
* when divided by 2, "very good" quality.
*/
static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
16, 11, 10, 16, 24, 40, 51, 61,
12, 12, 14, 19, 26, 58, 60, 55,
14, 13, 16, 24, 40, 57, 69, 56,
14, 17, 22, 29, 51, 87, 80, 62,
18, 22, 37, 56, 68, 109, 103, 77,
24, 35, 55, 64, 81, 104, 113, 92,
49, 64, 78, 87, 103, 121, 120, 101,
72, 92, 95, 98, 112, 100, 103, 99
};
static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
17, 18, 24, 47, 99, 99, 99, 99,
18, 21, 26, 66, 99, 99, 99, 99,
24, 26, 56, 99, 99, 99, 99, 99,
47, 66, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99
};


LOCAL(void)
jpeg_default_qtables (j_compress_ptr cinfo, boolean force_baseline)
{
jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
q_scale_factor[0], force_baseline);
jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
q_scale_factor[1], force_baseline);
}
#endif


GLOBAL(boolean)
set_quality_ratings (j_compress_ptr cinfo, char *arg, boolean force_baseline)
/* Process a quality-ratings parameter string, of the form
Expand All @@ -292,21 +332,21 @@ set_quality_ratings (j_compress_ptr cinfo, char *arg, boolean force_baseline)
/* Convert user 0-100 rating to percentage scaling */
#if JPEG_LIB_VERSION >= 70
cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val);
#else
q_scale_factor[tblno] = jpeg_quality_scaling(val);
#endif
while (*arg && *arg++ != ',') /* advance to next segment of arg string */
;
} else {
/* reached end of parameter, set remaining factors to last value */
#if JPEG_LIB_VERSION >= 70
cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val);
#else
q_scale_factor[tblno] = jpeg_quality_scaling(val);
#endif
}
}
#if JPEG_LIB_VERSION >= 70
jpeg_default_qtables(cinfo, force_baseline);
#else
jpeg_set_quality(cinfo, val, force_baseline);
#endif
return TRUE;
}

Expand Down

0 comments on commit 8b89a36

Please sign in to comment.