]> granicus.if.org Git - libjpeg-turbo/commitdiff
TurboJPEG: Decompress 4:4:4 JPEGs with unusual SFs
authorDRC <information@libjpeg-turbo.org>
Mon, 21 Jan 2019 19:57:55 +0000 (13:57 -0600)
committerDRC <information@libjpeg-turbo.org>
Wed, 23 Jan 2019 17:18:17 +0000 (11:18 -0600)
Normally, 4:4:4 JPEGs have horizontal x vertical luminance & chrominance
sampling factors of 1x1.  However, it is technically legal to create
4:4:4 JPEGs with sampling factors of 2x1, 1x2, 3x1, or 1x3, since the
sums of the products of those sampling factors are still <= 10.  The
libjpeg API correctly decodes such images, so the TurboJPEG API should
as well.

Fixes #323

ChangeLog.md
turbojpeg.c

index e2d267dffd12e8019b625961a5bd45f2e2a9b29d..4b4b2ea7aec9479b690374e6af3683114b2d5411 100644 (file)
@@ -67,6 +67,12 @@ file's color table.
 decompress a specially-crafted malformed JPEG image with a specified image
 width or height of 0 using the C version of TJBench.
 
+12. The TurboJPEG API will now decompress 4:4:4 JPEG images with 2x1, 1x2, 3x1,
+or 1x3 luminance and chrominance sampling factors.  This is a non-standard way
+of specifying 1x subsampling (normally 4:4:4 JPEGs have 1x1 luminance and
+chrominance sampling factors), but the JPEG format and the libjpeg API both
+allow it.
+
 
 1.5.3
 =====
index 2aa05791c944bc2df9592664ea1f012904b19770..7ab49c01507efba7d79459bb7084e3adda2bbc3a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C)2009-2018 D. R. Commander.  All Rights Reserved.
+ * Copyright (C)2009-2019 D. R. Commander.  All Rights Reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -393,6 +393,24 @@ static int getSubsamp(j_decompress_ptr dinfo)
                                        retval=i;  break;
                                }
                        }
+                       /* Handle 4:4:4 images whose sampling factors are specified in
+                          non-standard ways. */
+                       if(dinfo->comp_info[0].h_samp_factor*dinfo->comp_info[0].v_samp_factor<=
+                               D_MAX_BLOCKS_IN_MCU/pixelsize[i] && i==TJSAMP_444)
+                       {
+                               int match=0;
+                               for(k=1; k<dinfo->num_components; k++) {
+                                       if(dinfo->comp_info[i].h_samp_factor==
+                                               dinfo->comp_info[0].h_samp_factor &&
+                                               dinfo->comp_info[i].v_samp_factor==
+                                               dinfo->comp_info[0].v_samp_factor)
+                                               match++;
+                                       if(match==dinfo->num_components-1)
+                                       {
+                                               retval=i;  break;
+                                       }
+                               }
+                       }
                }
        }
        return retval;