Skip to content

Commit 31d957d

Browse files
author
Daniel Hugenroth
committed
Calculate jpeg_simple_progression nscans correctly with respect to dc_scan_opt_mode
1 parent 41dd774 commit 31d957d

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

jcparam.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,13 @@ jpeg_simple_progression (j_compress_ptr cinfo)
868868
ncomps = cinfo->num_components;
869869
if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
870870
/* Custom script for YCbCr color images. */
871-
nscans = 10;
871+
if (cinfo->master->dc_scan_opt_mode == 0) {
872+
nscans = 8; /* 1 DC scan for all components */
873+
} else if (cinfo->master->dc_scan_opt_mode == 1) {
874+
nscans = 10; /* 1 DC scan for each component */
875+
} else {
876+
nscans = 9; /* 1 DC scan for luminance and 1 DC scan for chroma */
877+
}
872878
} else {
873879
/* All-purpose script for other color spaces. */
874880
if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION) {
@@ -906,14 +912,16 @@ jpeg_simple_progression (j_compress_ptr cinfo)
906912
if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION) {
907913
/* scan defined in jpeg_scan_rgb.txt in jpgcrush */
908914
/* Initial DC scan */
909-
if (cinfo->master->dc_scan_opt_mode == 0)
915+
if (cinfo->master->dc_scan_opt_mode == 0) {
916+
/* 1 DC scan for all components */
910917
scanptr = fill_dc_scans(scanptr, ncomps, 0, 0);
911-
else if (cinfo->master->dc_scan_opt_mode == 1) {
918+
} else if (cinfo->master->dc_scan_opt_mode == 1) {
919+
/* 1 DC scan for each component */
912920
scanptr = fill_a_scan(scanptr, 0, 0, 0, 0, 0);
913921
scanptr = fill_a_scan(scanptr, 1, 0, 0, 0, 0);
914922
scanptr = fill_a_scan(scanptr, 2, 0, 0, 0, 0);
915-
}
916-
else {
923+
} else {
924+
/* 1 DC scan for luminance and 1 DC scan for chroma */
917925
scanptr = fill_dc_scans(scanptr, 1, 0, 0);
918926
scanptr = fill_a_scan_pair(scanptr, 1, 0, 0, 0, 0);
919927
}

0 commit comments

Comments
 (0)