Index: gm/colorspace.cpp |
diff --git a/gm/colorspace.cpp b/gm/colorspace.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cb75d21ffbeac67ee640ec4d9bd33ad1f758e974 |
--- /dev/null |
+++ b/gm/colorspace.cpp |
@@ -0,0 +1,92 @@ |
+/* |
+ * Copyright 2016 Intel Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#include "gm.h" |
+#include "Resources.h" |
+#include "SkImage.h" |
+#include "SkData.h" |
+#include "SkColorSpace.h" |
+ |
+#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
+ |
+#ifdef SK_BUILD_FOR_MAC |
+#include <ApplicationServices/ApplicationServices.h> |
+#endif |
+ |
+#ifdef SK_BUILD_FOR_IOS |
+#include <CoreGraphics/CoreGraphics.h> |
+#endif |
+ |
+static void release_data(void* info, const void*, size_t len) { |
+ SkData* data = (SkData*)info; |
+ SkASSERT(data->size() == len); |
+ data->unref(); |
+} |
+ |
+static SkColorSpace* extract_cs(SkImage* img) { |
+ SkData* data = img->refEncoded(); |
+ if (!data) { |
+ return nullptr; |
+ } |
+ |
+ CGDataProviderRef provider = CGDataProviderCreateWithData(data, data->data(), data->size(), |
+ release_data); |
+ CGImageRef cgimg = CGImageCreateWithJPEGDataProvider(provider, nullptr, false, |
+ kCGRenderingIntentDefault); |
+ CFDataRef cfdata = CGColorSpaceCopyICCProfile(CGImageGetColorSpace(cgimg)); |
+ |
+ SkColorSpace* cs = SkColorSpace::NewICCProfile(CFDataGetBytePtr(cfdata), |
+ CFDataGetLength(cfdata)); |
+ |
+ CFRelease(cfdata); |
+ CGImageRelease(cgimg); |
+ CGDataProviderRelease(provider); |
+ return cs; |
+} |
+#else |
+static SkColorSpace* extract_cs(SkImage* img) { return nullptr; } |
+#endif |
+ |
+// test images from http://www.color.org/version4html.xalter |
+// |
+DEF_SIMPLE_GM(colorspace, canvas, 570, 440) { |
+ SkImage* image[] = { |
+ GetResourceAsImage("Upper_Left.jpg"), |
+ GetResourceAsImage("Upper_Right.jpg"), |
+ GetResourceAsImage("Lower_Left.jpg"), |
+ GetResourceAsImage("Lower_Right.jpg"), |
+ }; |
+ |
+ canvas->translate(10, 10); |
+ |
+ const SkScalar w = SkIntToScalar(image[0]->width()); |
+ const SkScalar h = SkIntToScalar(image[0]->height()); |
+ |
+ canvas->drawImage(image[0], 0, 0, nullptr); |
+ canvas->drawImage(image[1], w, 0, nullptr); |
+ canvas->drawImage(image[2], 0, h, nullptr); |
+ canvas->drawImage(image[3], w, h, nullptr); |
+ |
+ SkAutoTUnref<SkColorSpace> dev(SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named)); |
+ |
+ for (auto img : image) { |
+ SkAutoTUnref<SkColorSpace> cs(extract_cs(img)); |
+ if (cs) { |
+ enum Result { |
+ kFailure_Result, |
+ kIdentity_Result, |
+ kNormal_Result, |
+ }; |
+ |
+ SkFloat3x3 matrix; |
+ SkColorSpace::Result res = SkColorSpace::Concat(cs, dev, &matrix); |
+ SkDebugf("result[%d] ", res); |
+ matrix.dump(); |
+ } |
+ img->unref(); |
+ } |
+} |