aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar Matt Sarett <msarett@google.com>2017-05-17 10:06:32 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-05-17 18:15:20 +0000
commit9f1c403362d8de6038328c7238b6ac56be552324 (patch)
treefb5d63addedb45773a1011bb8e4fc816d9cf240a /tools
parent78d1b428a8e8a0b76e88e9266d2893136acd5906 (diff)
Add tool to create test images with interesting color profiles
Bug: skia: Change-Id: Ia4f892368fceda4a99490f5bd29851837a7a6927 Reviewed-on: https://skia-review.googlesource.com/17212 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Matt Sarett <msarett@google.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/create_flutter_test_images.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/tools/create_flutter_test_images.cpp b/tools/create_flutter_test_images.cpp
new file mode 100644
index 0000000000..69a0d112a3
--- /dev/null
+++ b/tools/create_flutter_test_images.cpp
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkColorSpacePriv.h"
+#include "SkImage.h"
+#include "SkPngEncoder.h"
+
+#include "Resources.h"
+
+/**
+ * Create a color space that swaps the red, green, and blue channels.
+ */
+static sk_sp<SkColorSpace> gbr_color_space() {
+ float gbr[9];
+ gbr[0] = gSRGB_toXYZD50[1];
+ gbr[1] = gSRGB_toXYZD50[2];
+ gbr[2] = gSRGB_toXYZD50[0];
+ gbr[3] = gSRGB_toXYZD50[4];
+ gbr[4] = gSRGB_toXYZD50[5];
+ gbr[5] = gSRGB_toXYZD50[3];
+ gbr[6] = gSRGB_toXYZD50[7];
+ gbr[7] = gSRGB_toXYZD50[8];
+ gbr[8] = gSRGB_toXYZD50[6];
+ SkMatrix44 toXYZD50(SkMatrix44::kUninitialized_Constructor);
+ toXYZD50.set3x3RowMajorf(gbr);
+ return SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma, toXYZD50);
+}
+
+/**
+ * Create a color space with a steep transfer function.
+ */
+static sk_sp<SkColorSpace> tf_color_space() {
+ SkColorSpaceTransferFn fn;
+ fn.fA = 1.f; fn.fB = 0.f; fn.fC = 0.f; fn.fD = 0.f; fn.fE = 0.f; fn.fF = 0.f; fn.fG = 50.f;
+ return SkColorSpace::MakeRGB(fn, SkColorSpace::kSRGB_Gamut);
+}
+
+/**
+ * Create a wide gamut color space.
+ */
+static sk_sp<SkColorSpace> wide_gamut_color_space() {
+ return SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
+ SkColorSpace::kRec2020_Gamut);
+}
+
+int main(int argc, char** argv) {
+ sk_sp<SkImage> image = GetResourceAsImage("flutter_logo.jpg");
+ if (!image) {
+ SkDebugf("Cannot find flutter_logo.jpg in resources.\n");
+ return 1;
+ }
+
+ // Encode an image with a gbr color space.
+ SkImageInfo info = SkImageInfo::MakeN32(image->width(), image->height(), kOpaque_SkAlphaType,
+ gbr_color_space());
+ size_t rowBytes = info.minRowBytes();
+ SkAutoTMalloc<uint8_t> storage(rowBytes * image->height());
+ SkPixmap src(info, storage.get(), rowBytes);
+ image->readPixels(src, 0, 0, SkImage::kDisallow_CachingHint);
+ SkFILEWStream dst0("gbr.png");
+ SkPngEncoder::Options opts;
+ opts.fUnpremulBehavior = SkTransferFunctionBehavior::kIgnore; // Does not matter for opaque src
+ SkAssertResult(SkPngEncoder::Encode(&dst0, src, opts));
+
+ // Encode an image with steep transfer function.
+ src.setColorSpace(tf_color_space());
+ image->readPixels(src, 0, 0, SkImage::kDisallow_CachingHint);
+ SkFILEWStream dst1("tf.png");
+ SkAssertResult(SkPngEncoder::Encode(&dst1, src, opts));
+
+ // Encode a wide gamut image.
+ src.setColorSpace(wide_gamut_color_space());
+ image->readPixels(src, 0, 0, SkImage::kDisallow_CachingHint);
+ SkFILEWStream dst2("wide-gamut.png");
+ SkAssertResult(SkPngEncoder::Encode(&dst2, src, opts));
+
+ return 0;
+}