Merge pull request #133 from dcommander/jpeg_set_compress_profile

Change JBOOLEAN_USE_MOZ_DEFAULTS to an integer parameter
This commit is contained in:
fbossen
2014-12-14 17:21:21 +09:00
12 changed files with 67 additions and 49 deletions

View File

@@ -179,8 +179,8 @@ endif()
# Targets
#
set(JPEG_SOURCES jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c
jccompat.c jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c
set(JPEG_SOURCES jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jcext.c
jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c
jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c jdatadst.c
jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c jdinput.c jdmainct.c
jdmarker.c jdmaster.c jdmerge.c jdphuff.c jdpostct.c jdsample.c jdtrans.c

View File

@@ -16,7 +16,7 @@ HDRS = jchuff.h jdct.h jdhuff.h jerror.h jinclude.h jmemsys.h jmorecfg.h \
jpeg_nbits_table.h
libjpeg_la_SOURCES = $(HDRS) jcapimin.c jcapistd.c jccoefct.c jccolor.c \
jccompat.c jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c \
jcdctmgr.c jcext.c jchuff.c jcinit.c jcmainct.c jcmarker.c \
jcmaster.c jcomapi.c jcparam.c jcphuff.c jcprepct.c jcsample.c \
jctrans.c jdapimin.c jdapistd.c jdatadst.c jdatasrc.c jdcoefct.c \
jdcolor.c jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c \

View File

@@ -77,16 +77,6 @@ int jpeg_c_get_int_param (j_compress_ptr cinfo, J_INT_PARAM param)
Boolean Extension Parameters Supported by mozjpeg
-------------------------------------------------
* JBOOLEAN_USE_MOZ_DEFAULTS (default: TRUE)
This parameter controls the behavior of the jpeg_set_defaults() function and
should thus be set prior to calling that function. If this parameter is
TRUE, then jpeg_set_defaults() will configure the library to use the mozjpeg
defaults (which will enable settings that increase the compression ratio as
much as possible, at the expense of increased encoding time.) If this
parameter is FALSE, then jpeg_set_defaults() will configure the library to
use the libjpeg[-turbo] defaults (baseline entropy coding, no mozjpeg
extensions enabled.)
* JBOOLEAN_OPTIMIZE_SCANS (default: TRUE)
Specifies whether scan parameters should be optimized. Parameter
optimization is done as in jpgcrush. jpeg_simple_progression() should be called
@@ -145,6 +135,22 @@ Floating Point Extension Parameters Supported by mozjpeg
Integer Extension Parameters Supported by mozjpeg
-------------------------------------------------
* JINT_COMPRESS_PROFILE (default: JCP_MAX_COMPRESSION)
Select a compression profile, which is a set of default parameters that will
achieve a desired compression goal. This parameter controls the behavior of
the jpeg_set_defaults() function. Thus, setting JINT_COMPRESS_PROFILE does
not cause any other parameters to be modified until jpeg_set_defaults() is
called. The following compression profiles are supported:
- JCP_MAX_COMPRESSION (default)
Increase the compression ratio as much as possible, at the expense of
increased encoding time. This enables progressive entropy coding and all
mozjpeg extensions.
- JCP_FASTEST
Use the libjpeg[-turbo] defaults (baseline entropy coding, no mozjpeg
extensions enabled.)
* JINT_TRELLIS_FREQ_SPLIT (default: 8)
Specifies the position within the zigzag scan at which the split between
scans is positioned in the context of trellis quantization.

View File

@@ -480,7 +480,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
} else if (keymatch(arg, "revert", 3)) {
/* revert to old JPEG default */
jpeg_c_set_bool_param(cinfo, JBOOLEAN_USE_MOZ_DEFAULTS, FALSE);
jpeg_c_set_int_param(cinfo, JINT_COMPRESS_PROFILE, JCP_FASTEST);
jpeg_set_defaults(cinfo);
} else if (keymatch(arg, "sample", 2)) {

View File

@@ -99,7 +99,7 @@ jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
cinfo->master = (struct jpeg_comp_master *)
jpeg_get_small ((j_common_ptr) cinfo, sizeof(struct jpeg_comp_master));
MEMZERO(cinfo->master, sizeof(struct jpeg_comp_master));
cinfo->master->use_moz_defaults = TRUE;
cinfo->master->compress_profile = JCP_MAX_COMPRESSION;
}

View File

@@ -19,7 +19,6 @@ GLOBAL(boolean)
jpeg_c_bool_param_supported (j_compress_ptr cinfo, J_BOOLEAN_PARAM param)
{
switch (param) {
case JBOOLEAN_USE_MOZ_DEFAULTS:
case JBOOLEAN_OPTIMIZE_SCANS:
case JBOOLEAN_TRELLIS_QUANT:
case JBOOLEAN_TRELLIS_QUANT_DC:
@@ -40,9 +39,6 @@ jpeg_c_set_bool_param (j_compress_ptr cinfo, J_BOOLEAN_PARAM param,
boolean value)
{
switch(param) {
case JBOOLEAN_USE_MOZ_DEFAULTS:
cinfo->master->use_moz_defaults = value;
break;
case JBOOLEAN_OPTIMIZE_SCANS:
cinfo->master->optimize_scans = value;
break;
@@ -77,8 +73,6 @@ GLOBAL(boolean)
jpeg_c_get_bool_param (j_compress_ptr cinfo, J_BOOLEAN_PARAM param)
{
switch(param) {
case JBOOLEAN_USE_MOZ_DEFAULTS:
return cinfo->master->use_moz_defaults;
case JBOOLEAN_OPTIMIZE_SCANS:
return cinfo->master->optimize_scans;
case JBOOLEAN_TRELLIS_QUANT:
@@ -152,6 +146,7 @@ GLOBAL(boolean)
jpeg_c_int_param_supported (j_compress_ptr cinfo, J_INT_PARAM param)
{
switch (param) {
case JINT_COMPRESS_PROFILE:
case JINT_TRELLIS_FREQ_SPLIT:
case JINT_TRELLIS_NUM_LOOPS:
case JINT_BASE_QUANT_TBL_IDX:
@@ -167,6 +162,16 @@ GLOBAL(void)
jpeg_c_set_int_param (j_compress_ptr cinfo, J_INT_PARAM param, int value)
{
switch (param) {
case JINT_COMPRESS_PROFILE:
switch (value) {
case JCP_MAX_COMPRESSION:
case JCP_FASTEST:
cinfo->master->compress_profile = value;
break;
default:
ERREXIT(cinfo, JERR_BAD_PARAM_VALUE);
}
break;
case JINT_TRELLIS_FREQ_SPLIT:
cinfo->master->trellis_freq_split = value;
break;
@@ -190,6 +195,8 @@ GLOBAL(int)
jpeg_c_get_int_param (j_compress_ptr cinfo, J_INT_PARAM param)
{
switch (param) {
case JINT_COMPRESS_PROFILE:
return cinfo->master->compress_profile;
case JINT_TRELLIS_FREQ_SPLIT:
return cinfo->master->trellis_freq_split;
case JINT_TRELLIS_NUM_LOOPS:

View File

@@ -417,19 +417,9 @@ jpeg_set_defaults (j_compress_ptr cinfo)
cinfo->arith_ac_K[i] = 5;
}
#ifdef C_PROGRESSIVE_SUPPORTED
cinfo->scan_info = NULL;
cinfo->num_scans = 0;
if (!cinfo->master->use_moz_defaults) {
/* Default is no multiple-scan output */
cinfo->scan_info = NULL;
cinfo->num_scans = 0;
}
#else
/* Default is no multiple-scan output */
cinfo->scan_info = NULL;
cinfo->num_scans = 0;
#endif
/* Expect normal source image, not raw downsampled data */
cinfo->raw_data_in = FALSE;
@@ -438,7 +428,7 @@ jpeg_set_defaults (j_compress_ptr cinfo)
cinfo->arith_code = FALSE;
#ifdef ENTROPY_OPT_SUPPORTED
if (cinfo->master->use_moz_defaults)
if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION)
/* By default, do extra passes to optimize entropy coding */
cinfo->optimize_coding = TRUE;
else
@@ -465,7 +455,8 @@ jpeg_set_defaults (j_compress_ptr cinfo)
cinfo->do_fancy_downsampling = TRUE;
#endif
cinfo->master->overshoot_deringing = cinfo->master->use_moz_defaults;
cinfo->master->overshoot_deringing =
cinfo->master->compress_profile == JCP_MAX_COMPRESSION;
/* No input smoothing */
cinfo->smoothing_factor = 0;
@@ -499,14 +490,15 @@ jpeg_set_defaults (j_compress_ptr cinfo)
cinfo->master->dc_scan_opt_mode = 1;
#ifdef C_PROGRESSIVE_SUPPORTED
if (cinfo->master->use_moz_defaults) {
if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION) {
cinfo->master->optimize_scans = TRUE;
jpeg_simple_progression(cinfo);
} else
cinfo->master->optimize_scans = FALSE;
#endif
cinfo->master->trellis_quant = cinfo->master->use_moz_defaults;
cinfo->master->trellis_quant =
cinfo->master->compress_profile == JCP_MAX_COMPRESSION;
cinfo->master->lambda_log_scale1 = 14.75;
cinfo->master->lambda_log_scale2 = 16.5;
cinfo->master->quant_tbl_master_idx = 3;
@@ -877,7 +869,7 @@ jpeg_simple_progression (j_compress_ptr cinfo)
nscans = 10;
} else {
/* All-purpose script for other color spaces. */
if (cinfo->master->use_moz_defaults == TRUE) {
if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION) {
if (ncomps > MAX_COMPS_IN_SCAN)
nscans = 5 * ncomps; /* 2 DC + 4 AC scans per component */
else
@@ -909,7 +901,7 @@ jpeg_simple_progression (j_compress_ptr cinfo)
if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
/* Custom script for YCbCr color images. */
if (cinfo->master->use_moz_defaults == TRUE) {
if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION) {
/* scan defined in jpeg_scan_rgb.txt in jpgcrush */
/* Initial DC scan */
if (cinfo->master->dc_scan_opt_mode == 0)
@@ -957,7 +949,7 @@ jpeg_simple_progression (j_compress_ptr cinfo)
}
} else {
/* All-purpose script for other color spaces. */
if (cinfo->master->use_moz_defaults == TRUE) {
if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION) {
/* scan defined in jpeg_scan_bw.txt in jpgcrush */
/* DC component, no successive approximation */
scanptr = fill_dc_scans(scanptr, ncomps, 0, 0);

View File

@@ -208,6 +208,7 @@ JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code")
#endif
#endif
JMESSAGE(JERR_BAD_PARAM, "Bogus parameter")
JMESSAGE(JERR_BAD_PARAM_VALUE, "Bogus parameter value")
#ifdef JMAKE_ENUM_LIST

View File

@@ -58,7 +58,6 @@ struct jpeg_comp_master {
boolean is_last_pass; /* True during last pass */
/* Extension parameters */
boolean use_moz_defaults; /* TRUE=use Mozilla defaults */
boolean optimize_scans; /* TRUE=optimize progressive coding scans */
boolean trellis_quant; /* TRUE=use trellis quantization */
boolean trellis_quant_dc; /* TRUE=use trellis quant for DC coefficient */
@@ -72,6 +71,7 @@ struct jpeg_comp_master {
double norm_src[NUM_QUANT_TBLS][DCTSIZE2];
double norm_coef[NUM_QUANT_TBLS][DCTSIZE2];
int compress_profile; /* compression profile */
int dc_scan_opt_mode; /* DC scan optimization mode */
int quant_tbl_master_idx; /* Quantization table master index */
int trellis_freq_split; /* splitting point for frequency in trellis quantization */

View File

@@ -274,7 +274,6 @@ typedef enum {
/* Boolean extension parameters */
typedef enum {
JBOOLEAN_USE_MOZ_DEFAULTS = 0xAE2F5D7F, /* TRUE=use Mozilla defaults */
JBOOLEAN_OPTIMIZE_SCANS = 0x680C061E, /* TRUE=optimize progressive coding scans */
JBOOLEAN_TRELLIS_QUANT = 0xC5122033, /* TRUE=use trellis quantization */
JBOOLEAN_TRELLIS_QUANT_DC = 0x339D4C0C, /* TRUE=use trellis quant for DC coefficient */
@@ -295,6 +294,7 @@ typedef enum {
/* Integer parameters */
typedef enum {
JINT_COMPRESS_PROFILE = 0xE9918625, /* compression profile */
JINT_TRELLIS_FREQ_SPLIT = 0x6FAFF127, /* splitting point for frequency in trellis quantization */
JINT_TRELLIS_NUM_LOOPS = 0xB63EBF39, /* number of trellis loops */
JINT_BASE_QUANT_TBL_IDX = 0x44492AB1, /* base quantization table index */
@@ -302,6 +302,14 @@ typedef enum {
} J_INT_PARAM;
/* Values for the JINT_COMPRESS_PROFILE parameter (32-bit GUIDs) */
enum {
JCP_MAX_COMPRESSION = 0x5D083AAD, /* best compression ratio (progressive, all mozjpeg extensions) */
JCP_FASTEST = 0x2AEA5CB4 /* libjpeg[-turbo] defaults (baseline, no mozjpeg extensions) */
};
/* Common fields between JPEG compression and decompression master structs. */
#define jpeg_common_fields \

View File

@@ -44,7 +44,7 @@ static const char * progname; /* program name for error messages */
static char * outfilename; /* for -outfile switch */
static JCOPY_OPTION copyoption; /* -copy switch */
static jpeg_transform_info transformoption; /* image transformation options */
boolean memsrc; /* for -memsrc switch */
boolean memsrc = FALSE; /* for -memsrc switch */
#define INPUT_BUF_SIZE 4096
@@ -316,7 +316,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
} else if (keymatch(arg, "revert", 3)) {
/* revert to old JPEG default */
jpeg_c_set_bool_param(cinfo, JBOOLEAN_USE_MOZ_DEFAULTS, FALSE);
jpeg_c_set_int_param(cinfo, JINT_COMPRESS_PROFILE, JCP_FASTEST);
} else if (keymatch(arg, "rotate", 2)) {
/* Rotate 90, 180, or 270 degrees (measured clockwise). */
@@ -474,8 +474,10 @@ main (int argc, char **argv)
#endif
/* Specify data source for decompression */
if (jpeg_c_bool_param_supported(&dstinfo, JBOOLEAN_USE_MOZ_DEFAULTS))
memsrc = jpeg_c_get_bool_param(&dstinfo, JBOOLEAN_USE_MOZ_DEFAULTS); /* needed to revert to original */
if (jpeg_c_int_param_supported(&dstinfo, JINT_COMPRESS_PROFILE) &&
jpeg_c_get_int_param(&dstinfo, JINT_COMPRESS_PROFILE)
== JCP_MAX_COMPRESSION)
memsrc = TRUE; /* needed to revert to original */
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
if (memsrc) {
size_t nbytes;
@@ -561,8 +563,9 @@ main (int argc, char **argv)
/* Specify data destination for compression */
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
if (jpeg_c_bool_param_supported(&dstinfo, JBOOLEAN_USE_MOZ_DEFAULTS) &&
jpeg_c_get_bool_param(&dstinfo, JBOOLEAN_USE_MOZ_DEFAULTS))
if (jpeg_c_int_param_supported(&dstinfo, JINT_COMPRESS_PROFILE) &&
jpeg_c_get_int_param(&dstinfo, JINT_COMPRESS_PROFILE)
== JCP_MAX_COMPRESSION)
jpeg_mem_dest(&dstinfo, &outbuffer, &outsize);
else
#endif
@@ -584,8 +587,9 @@ main (int argc, char **argv)
/* Finish compression and release memory */
jpeg_finish_compress(&dstinfo);
if (jpeg_c_bool_param_supported(&dstinfo, JBOOLEAN_USE_MOZ_DEFAULTS) &&
jpeg_c_get_bool_param(&dstinfo, JBOOLEAN_USE_MOZ_DEFAULTS)) {
if (jpeg_c_int_param_supported(&dstinfo, JINT_COMPRESS_PROFILE) &&
jpeg_c_get_int_param(&dstinfo, JINT_COMPRESS_PROFILE)
== JCP_MAX_COMPRESSION) {
size_t nbytes;
unsigned char *buffer = outbuffer;

View File

@@ -240,7 +240,7 @@ static int setCompDefaults(struct jpeg_compress_struct *cinfo,
else jpeg_set_colorspace(cinfo, JCS_YCbCr);
/* Set scan pattern again as colorspace might have changed */
if (cinfo->master->use_moz_defaults)
if(cinfo->master->compress_profile == JCP_MAX_COMPRESSION)
jpeg_simple_progression(cinfo);
cinfo->comp_info[0].h_samp_factor=tjMCUWidth[subsamp]/8;