- jpeg_set_quality():对外的设置函数
- jpeg_quality_scaling():参数处理,差不多是反转一下。
int scale_factor = quality;
/* Safety limit on quality factor. Convert 0 to 1 to avoid zero divide. */
if (scale_factor 100)
{
scale_factor = 100;
}
if (scale_factor < 50)
{
scale_factor = 5000 / scale_factor;
}
else
{
scale_factor = 200 - scale_factor*2;
}
- jpeg_set_linear_quality():处理std_luminance_quant_tbl/std_chrominance_quant_tbl。注意参数scale_factor
- jpeg_add_quant_table:
//force_baseline=TRUE
//DCTSIZE2=8*8
//scale_factor:质量,整数,0-100
//basic_table:std_luminance_quant_tbl和std_chrominance_quant_tbl
for (i = 0; i < DCTSIZE2; i++)
{
//原来代码是long,并无必要。这里的50,是指默认表质量为50的意思
int temp = ( basic_table[i] * scale_factor + 50) / 100;
/* limit the values to the valid range */
if (temp 0x8FFFF)
{
//32767不如使用0x8FFF
temp = 0x8FFFF; /* max quantizer needed for 12 bits */
}
if (force_baseline && temp > 0xFF)
{
//255L不如使用0xFF
temp = 0xFF; /* limit to baseline range if requested */
}
(*qtblptr)->quantval[i] = (UINT16) temp;
}
-
50的质量表
/* 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
};