Skip to content

Commit

Permalink
Add option to have single DC scan
Browse files Browse the repository at this point in the history
Add option to have a single DC scan wherein all components are
interleaved when using progressive mode. This may resolve compatibility
issues raised in #29 and #48.
This option is available through -onedcscan in cjpeg
  • Loading branch information
fbossen committed May 8, 2014
1 parent 8a99fca commit 13e2115
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions cjpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ usage (void)
#endif
fprintf(stderr, " -revert Revert to standard defaults (instead of mozjpeg defaults)\n");
fprintf(stderr, " -fastcrush Disable progressive scan optimization\n");
fprintf(stderr, " -onedcscan Use a single DC scan containing all components\n");
fprintf(stderr, " -notrellis Disable trellis optimization\n");
fprintf(stderr, " -tune-psnr Tune trellis optimization for PSNR\n");
fprintf(stderr, " -tune-hvs-psnr Tune trellis optimization for PSNR-HVS (default)\n");
Expand Down Expand Up @@ -342,6 +343,9 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
lval *= 1000L;
cinfo->mem->max_memory_to_use = lval * 1000L;

} else if (keymatch(arg, "onedcscan", 3)) {
cinfo->one_dc_scan = TRUE;

} else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
/* Enable entropy parm optimization. */
#ifdef ENTROPY_OPT_SUPPORTED
Expand Down
2 changes: 1 addition & 1 deletion jcmaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ select_scans (j_compress_ptr cinfo, int next_scan_number)

copy_buffer(cinfo, 0);

if (cinfo->num_scans > cinfo->num_scans_luma) {
if (cinfo->num_scans > cinfo->num_scans_luma && !cinfo->one_dc_scan) {
base_scan_idx = cinfo->num_scans_luma;

if (master->interleave_chroma_dc)
Expand Down
13 changes: 10 additions & 3 deletions jcparam.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,10 @@ jpeg_search_progression (j_compress_ptr cinfo)
/* last 4 done conditionally */

/* luma DC by itself */
scanptr = fill_dc_scans(scanptr, 1, 0, 0);
if (cinfo->one_dc_scan)
scanptr = fill_dc_scans(scanptr, ncomps, 0, 0);
else
scanptr = fill_dc_scans(scanptr, 1, 0, 0);

scanptr = fill_a_scan(scanptr, 0, 1, 8, 0, 0);
scanptr = fill_a_scan(scanptr, 0, 9, 63, 0, 0);
Expand Down Expand Up @@ -824,8 +827,12 @@ jpeg_simple_progression (j_compress_ptr cinfo)
if (cinfo->use_moz_defaults == TRUE) {
/* scan defined in jpeg_scan_rgb.txt in jpgcrush */
/* Initial DC scan */
scanptr = fill_dc_scans(scanptr, 1, 0, 0);
scanptr = fill_a_scan_pair(scanptr, 1, 0, 0, 0, 0);
if (cinfo->one_dc_scan)
scanptr = fill_dc_scans(scanptr, ncomps, 0, 0);
else {
scanptr = fill_dc_scans(scanptr, 1, 0, 0);
scanptr = fill_a_scan_pair(scanptr, 1, 0, 0, 0, 0);
}
/* Low frequency AC scans */
scanptr = fill_a_scan(scanptr, 0, 1, 8, 0, 2);
scanptr = fill_a_scan(scanptr, 1, 1, 8, 0, 0);
Expand Down
1 change: 1 addition & 0 deletions jpeglib.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ struct jpeg_compress_struct {

boolean use_moz_defaults; /* TRUE=use Mozilla defaults */
boolean optimize_scans; /* TRUE=optimize progressive coding scans */
boolean one_dc_scan; /* TRUE=use a single DC scan interleaving all components */
boolean trellis_quant; /* TRUE=use trellis quantization */
boolean trellis_eob_opt; /* TRUE=optimize for sequences of EOB */
boolean use_flat_quant_tbl; /* TRUE=use flat quantization table */
Expand Down

0 comments on commit 13e2115

Please sign in to comment.