Updated the get_images_from_skps tool to check for ICC profile support

Tool will now check for and output all unsuccessfully parsed ICC
profiles in input sksp images if --testColorCorrectionSupported is set
as a flag. All ICC-aware codecs had to be slightly modified in order to
expose this information, as the logic for accessing the ICC profiles is
all within the codecs. If --writeFailedImages is set, it will also
output all images whoses ICC profiles were not supported.

TBR=reed@google.com

BUG=skia:

Change-Id: Ic310d82bdebf92f8d3bc0ad3dcc688136b6de377
Reviewed-on: https://skia-review.googlesource.com/5355
Reviewed-by: Leon Scroggins <scroggo@google.com>
Reviewed-by: Matt Sarett <msarett@google.com>
Commit-Queue: Robert Aftias <raftias@google.com>
diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp
index 9a08755..7867fd0 100644
--- a/src/codec/SkJpegCodec.cpp
+++ b/src/codec/SkJpegCodec.cpp
@@ -229,6 +229,7 @@
         Origin orientation = get_exif_orientation(decoderMgr->dinfo());
         sk_sp<SkData> iccData = get_icc_profile(decoderMgr->dinfo());
         sk_sp<SkColorSpace> colorSpace = nullptr;
+        bool unsupportedICC = false;
         if (iccData) {
             SkColorSpace_Base::InputColorFormat inputColorFormat =
                     SkColorSpace_Base::InputColorFormat::kRGB;
@@ -247,6 +248,7 @@
                                                     inputColorFormat);
             if (!colorSpace) {
                 SkCodecPrintf("Could not create SkColorSpace from ICC data.\n");
+                unsupportedICC = true;
             }
         }
         if (!colorSpace) {
@@ -256,8 +258,10 @@
 
         const int width = decoderMgr->dinfo()->image_width;
         const int height = decoderMgr->dinfo()->image_height;
-        *codecOut = new SkJpegCodec(width, height, info, stream, decoderMgr.release(),
-                std::move(colorSpace), orientation);
+        SkJpegCodec* codec = new SkJpegCodec(width, height, info, stream, decoderMgr.release(),
+                                             std::move(colorSpace), orientation);
+        codec->setUnsupportedICC(unsupportedICC);
+        *codecOut = codec;
     } else {
         SkASSERT(nullptr != decoderMgrOut);
         *decoderMgrOut = decoderMgr.release();
diff --git a/src/codec/SkPngCodec.cpp b/src/codec/SkPngCodec.cpp
index 758ffa5..b8576fb 100644
--- a/src/codec/SkPngCodec.cpp
+++ b/src/codec/SkPngCodec.cpp
@@ -326,8 +326,8 @@
 #endif // LIBPNG >= 1.6
 
 // Returns a colorSpace object that represents any color space information in
-// the encoded data.  If the encoded data contains no color space, this will
-// return NULL.
+// the encoded data.  If the encoded data contains an invalid/unsupported color space,
+// this will return NULL. If there is no color space information, it will guess sRGB
 sk_sp<SkColorSpace> read_color_space(png_structp png_ptr, png_infop info_ptr) {
 
 #if (PNG_LIBPNG_VER_MAJOR > 1) || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR >= 6)
@@ -410,9 +410,9 @@
 
 #endif // LIBPNG >= 1.6
 
-    // Report that there is no color space information in the PNG.  SkPngCodec is currently
-    // implemented to guess sRGB in this case.
-    return nullptr;
+    // Report that there is no color space information in the PNG.
+    // Guess sRGB in this case.
+    return SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
 }
 
 void SkPngCodec::allocateStorage(const SkImageInfo& dstInfo) {
@@ -984,8 +984,9 @@
     if (fOutCodec) {
         SkASSERT(nullptr == *fOutCodec);
         sk_sp<SkColorSpace> colorSpace = read_color_space(fPng_ptr, fInfo_ptr);
+        const bool unsupportedICC = !colorSpace;
         if (!colorSpace) {
-            // Treat unmarked pngs as sRGB.
+            // Treat unsupported/invalid color spaces as sRGB.
             colorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
         }
 
@@ -1014,6 +1015,7 @@
             *fOutCodec = new SkPngInterlacedDecoder(encodedInfo, imageInfo, fStream,
                     fChunkReader, fPng_ptr, fInfo_ptr, bitDepth, numberPasses);
         }
+        (*fOutCodec)->setUnsupportedICC(unsupportedICC);
     }
 
 
diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp
index 09913c7..dbc141e 100644
--- a/src/codec/SkWebpCodec.cpp
+++ b/src/codec/SkWebpCodec.cpp
@@ -62,10 +62,13 @@
     WebPChunkIterator chunkIterator;
     SkAutoTCallVProc<WebPChunkIterator, WebPDemuxReleaseChunkIterator> autoCI(&chunkIterator);
     sk_sp<SkColorSpace> colorSpace = nullptr;
+    bool unsupportedICC = false;
     if (WebPDemuxGetChunk(demux, "ICCP", 1, &chunkIterator)) {
         colorSpace = SkColorSpace::MakeICC(chunkIterator.chunk.bytes, chunkIterator.chunk.size);
+        if (!colorSpace) {
+            unsupportedICC = true;
+        }
     }
-
     if (!colorSpace) {
         colorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
     }
@@ -140,8 +143,11 @@
     }
 
     SkEncodedInfo info = SkEncodedInfo::Make(color, alpha, 8);
-    return new SkWebpCodec(features.width, features.height, info, std::move(colorSpace),
-                           streamDeleter.release(), demux.release(), std::move(data));
+    SkWebpCodec* codecOut = new SkWebpCodec(features.width, features.height, info,
+                                            std::move(colorSpace), streamDeleter.release(),
+                                            demux.release(), std::move(data));
+    codecOut->setUnsupportedICC(unsupportedICC);
+    return codecOut;
 }
 
 SkISize SkWebpCodec::onGetScaledDimensions(float desiredScale) const {