]> granicus.if.org Git - libjpeg-turbo/commitdiff
jpeg_crop_scanlines: Handle gray images w/ samp!=1
authorDRC <information@libjpeg-turbo.org>
Wed, 6 Dec 2017 17:59:04 +0000 (11:59 -0600)
committerDRC <information@libjpeg-turbo.org>
Wed, 6 Dec 2017 17:59:04 +0000 (11:59 -0600)
Since the sampling factor has no meaning for single-component images,
the decompressor ignores it, and jpeg_crop_scanlines() should as well.

Fixes #195

ChangeLog.md
jdapistd.c

index d7d31ca8f4d70dcc5e21b6d9fe9cb256820572d9..f5fe44bf8511a37b3291e40abac9eefb387e3df1 100644 (file)
@@ -37,6 +37,10 @@ end of a single-scan (non-progressive) image, subsequent calls to
 `jpeg_consume_input()` would return `JPEG_SUSPENDED` rather than
 `JPEG_REACHED_EOI`.
 
+9. `jpeg_crop_scanlines()` now works correctly when decompressing grayscale
+JPEG images that were compressed with a sampling factor other than 1 (for
+instance, with `cjpeg -grayscale -sample 2x2`).
+
 
 1.5.2
 =====
index 14fc6e31a6c8eb964d036dd803894fe8c85b79d9..105121df2bef4d6b89eec412192a34ab735c2078 100644 (file)
@@ -190,7 +190,10 @@ jpeg_crop_scanline (j_decompress_ptr cinfo, JDIMENSION *xoffset,
    * single-pass decompression case, allowing us to use the same MCU column
    * width for all of the components.
    */
-  align = cinfo->_min_DCT_scaled_size * cinfo->max_h_samp_factor;
+  if (cinfo->comps_in_scan == 1 && cinfo->num_components == 1)
+    align = cinfo->_min_DCT_scaled_size;
+  else
+    align = cinfo->_min_DCT_scaled_size * cinfo->max_h_samp_factor;
 
   /* Adjust xoffset to the nearest iMCU boundary <= the requested value */
   input_xoffset = *xoffset;
@@ -215,6 +218,9 @@ jpeg_crop_scanline (j_decompress_ptr cinfo, JDIMENSION *xoffset,
 
   for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
        ci++, compptr++) {
+    int hsf = (cinfo->comps_in_scan == 1 && cinfo->num_components == 1) ?
+              1 : compptr->h_samp_factor;
+
     /* Set downsampled_width to the new output width. */
     orig_downsampled_width = compptr->downsampled_width;
     compptr->downsampled_width =
@@ -228,11 +234,10 @@ jpeg_crop_scanline (j_decompress_ptr cinfo, JDIMENSION *xoffset,
      * values will be used in multi-scan decompressions.
      */
     cinfo->master->first_MCU_col[ci] =
-      (JDIMENSION) (long) (*xoffset * compptr->h_samp_factor) /
-                   (long) align;
+      (JDIMENSION) (long) (*xoffset * hsf) / (long) align;
     cinfo->master->last_MCU_col[ci] =
       (JDIMENSION) jdiv_round_up((long) ((*xoffset + cinfo->output_width) *
-                                         compptr->h_samp_factor),
+                                         hsf),
                                  (long) align) - 1;
   }