Remove PDF JPEG shortcut, since it fails on grayscale JPEGs.
authorhalcanary <halcanary@google.com>
Tue, 2 Dec 2014 14:37:21 +0000 (06:37 -0800)
committerCommit bot <commit-bot@chromium.org>
Tue, 2 Dec 2014 14:37:21 +0000 (06:37 -0800)
BUG=436079

Review URL: https://codereview.chromium.org/767343002

gm/grayscalejpg.cpp [new file with mode: 0644]
gyp/gmslides.gypi
resources/grayscale.jpg [new file with mode: 0644]
src/pdf/SkPDFImage.cpp
tests/PDFJpegEmbedTest.cpp

diff --git a/gm/grayscalejpg.cpp b/gm/grayscalejpg.cpp
new file mode 100644 (file)
index 0000000..0c617bf
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Resources.h"
+#include "SkCanvas.h"
+#include "gm.h"
+
+/*
+ *  Test decoding grayscale JPEG
+ *  http://crbug.com/436079
+ */
+DEF_SIMPLE_GM(grayscalejpg, canvas, 128, 128) {
+    const char kResource[] = "grayscale.jpg";
+    SkBitmap bitmap;
+    if (GetResourceAsBitmap(kResource, &bitmap)) {
+        canvas->drawBitmap(bitmap, 0.0f, 0.0f);
+    } else {
+        SkDebugf("\nCould not decode file '%s'. Did you forget"
+                 " to set the resourcePath?\n", kResource);
+    }
+}
index f1ab2b7..5e1ae47 100644 (file)
@@ -99,6 +99,7 @@
         '../gm/gradientDirtyLaundry.cpp',
         '../gm/gradient_matrix.cpp',
         '../gm/gradtext.cpp',
+        '../gm/grayscalejpg.cpp',
         '../gm/hairlines.cpp',
         '../gm/hairmodes.cpp',
         '../gm/hittestpath.cpp',
diff --git a/resources/grayscale.jpg b/resources/grayscale.jpg
new file mode 100644 (file)
index 0000000..6c6ae32
Binary files /dev/null and b/resources/grayscale.jpg differ
index 0c9b741..122d2f2 100644 (file)
@@ -629,6 +629,7 @@ bool SkPDFImage::populate(SkPDFCatalog* catalog) {
     return true;
 }
 
+#if 0  // reenable when we can figure out the JPEG colorspace
 namespace {
 /**
  *  This PDFObject assumes that its constructor was handed
@@ -657,7 +658,7 @@ public:
             "/Subtype /Image\n"
             "/Width %d\n"
             "/Height %d\n"
-            "/ColorSpace /DeviceRGB\n"
+            "/ColorSpace /DeviceRGB\n"  // or DeviceGray
             "/BitsPerComponent 8\n"
             "/Filter /DCTDecode\n"
             "/ColorTransform 0\n"
@@ -702,11 +703,13 @@ static bool is_jfif_jpeg(SkData* data) {
                             sizeof(bytesSixToTen))));
 }
 }  // namespace
+#endif
 
 SkPDFObject* SkPDFCreateImageObject(
         const SkBitmap& bitmap,
         const SkIRect& subset,
         SkPicture::EncodeBitmap encoder) {
+#if 0  // reenable when we can figure out the JPEG colorspace
     if (SkIRect::MakeWH(bitmap.width(), bitmap.height()) == subset) {
         SkAutoTUnref<SkData> encodedData(ref_encoded_data(bitmap));
         if (is_jfif_jpeg(encodedData)) {
@@ -714,5 +717,6 @@ SkPDFObject* SkPDFCreateImageObject(
                               (encodedData, bitmap.width(), bitmap.height()));
         }
     }
+#endif
     return SkPDFImage::CreateImage(bitmap, subset, encoder);
 }
index c1d0ea8..422b59a 100644 (file)
@@ -84,7 +84,8 @@ DEF_TEST(PDFJpegEmbedTest, r) {
     SkASSERT(pdfData);
     pdf.reset();
 
-    REPORTER_ASSERT(r, is_subset_of(mandrillData, pdfData));
+    // Test disabled, waiting on resolution to http://skbug.com/3180
+    // REPORTER_ASSERT(r, is_subset_of(mandrillData, pdfData));
 
     // This JPEG uses a nonstandard colorspace - it can not be
     // embedded into the PDF directly.