aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2017-12-13 11:01:31 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-12-14 19:02:17 +0000
commitc38cce63b39f26d8b13e9ac564a1f2d6d7a8db68 (patch)
treea8990df027fd34b08e1aac17594602bb63ba5705 /tests
parent474d68791965f20f8e0dfa2bfb4d87300f1f29e0 (diff)
make SkColorSpace_New real
Some interesting things are starting to fall out already, like the fact that I needed to add a gamma_dst stage to be able to draw into gamma-transfer-fn destinations. I've also had to pass an SkAlphaType through to the linearize functions so that they can maintain premul invariants. I'm not sure this is actually a good idea... if you can, please double- check my logic at SkRasterPipeline.cpp:128? If it's correct logic, I'm going to need to do it all over the place. But I imagine you don't do this and somehow get away with it. Change-Id: I42cd9b161b54287d674225103ad9e19f8b388959 Reviewed-on: https://skia-review.googlesource.com/84680 Commit-Queue: Mike Klein <mtklein@chromium.org> Reviewed-by: Brian Osman <brianosman@google.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/SkColorSpace_NewTest.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/SkColorSpace_NewTest.cpp b/tests/SkColorSpace_NewTest.cpp
new file mode 100644
index 0000000000..a301a06f44
--- /dev/null
+++ b/tests/SkColorSpace_NewTest.cpp
@@ -0,0 +1,93 @@
+/*
+ * 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 "../src/jumper/SkJumper.h"
+#include "SkColorSpace_New.h"
+#include "SkRasterPipeline.h"
+#include "Test.h"
+#include <initializer_list>
+
+DEF_TEST(SkColorSpace_New_TransferFnBasics, r) {
+ auto gamut = SkMatrix44::I();
+ auto blending = SkColorSpace_New::Blending::AsEncoded;
+
+ SkColorSpace_New linearA{SkColorSpace_New::TransferFn::MakeLinear(), gamut, blending},
+ linearB{SkColorSpace_New::TransferFn::MakeGamma(1), gamut, blending},
+ srgb{SkColorSpace_New::TransferFn::MakeSRGB(), gamut, blending},
+ gamma{SkColorSpace_New::TransferFn::MakeGamma(2.2f), gamut, blending};
+
+ REPORTER_ASSERT(r, linearA.gammaIsLinear());
+ REPORTER_ASSERT(r, linearB.gammaIsLinear());
+ REPORTER_ASSERT(r, ! srgb.gammaIsLinear());
+ REPORTER_ASSERT(r, ! gamma.gammaIsLinear());
+
+ REPORTER_ASSERT(r, !linearA.gammaCloseToSRGB());
+ REPORTER_ASSERT(r, !linearB.gammaCloseToSRGB());
+ REPORTER_ASSERT(r, srgb.gammaCloseToSRGB());
+ REPORTER_ASSERT(r, ! gamma.gammaCloseToSRGB());
+
+ REPORTER_ASSERT(r, linearA.transferFn().equals(linearB.transferFn()));
+ REPORTER_ASSERT(r, !linearA.transferFn().equals( srgb.transferFn()));
+ REPORTER_ASSERT(r, !linearA.transferFn().equals( gamma.transferFn()));
+ REPORTER_ASSERT(r, !linearB.transferFn().equals( srgb.transferFn()));
+ REPORTER_ASSERT(r, !linearB.transferFn().equals( gamma.transferFn()));
+ REPORTER_ASSERT(r, ! srgb.transferFn().equals( gamma.transferFn()));
+}
+
+DEF_TEST(SkColorSpace_New_TransferFnStages, r) {
+ // We'll create a little SkRasterPipelineBlitter-like scenario,
+ // blending the same src color over the same dst color, but with
+ // three different transfer functions, for simplicity the same for src and dst.
+ SkColor src = 0x7f7f0000;
+
+ SkColor dsts[3];
+ for (SkColor& dst : dsts) {
+ dst = 0xff007f00;
+ }
+
+ auto gamut = SkMatrix44::I();
+ auto blending = SkColorSpace_New::Blending::Linear;
+ SkColorSpace_New linear{SkColorSpace_New::TransferFn::MakeLinear(), gamut, blending},
+ srgb{SkColorSpace_New::TransferFn::MakeSRGB(), gamut, blending},
+ gamma{SkColorSpace_New::TransferFn::MakeGamma(3), gamut, blending};
+ SkColor* dst = dsts;
+ for (const SkColorSpace_New* cs : {&linear, &srgb, &gamma}) {
+ SkJumper_MemoryCtx src_ctx = { &src, 0 },
+ dst_ctx = { dst++, 0 };
+
+ SkRasterPipeline_<256> p;
+
+ p.append(SkRasterPipeline::load_8888, &src_ctx);
+ cs->transferFn().linearizeSrc(&p, kUnpremul_SkAlphaType);
+ p.append(SkRasterPipeline::premul);
+
+ p.append(SkRasterPipeline::load_8888_dst, &dst_ctx);
+ cs->transferFn().linearizeDst(&p, kUnpremul_SkAlphaType);
+ p.append(SkRasterPipeline::premul_dst);
+
+ p.append(SkRasterPipeline::srcover);
+ p.append(SkRasterPipeline::unpremul);
+ cs->transferFn().encodeSrc(&p);
+ p.append(SkRasterPipeline::store_8888, &dst_ctx);
+ p.run(0,0,1,1);
+ }
+
+ // Double check the uninteresting channels: alpha's opaque, no blue.
+ REPORTER_ASSERT(r, SkColorGetA(dsts[0]) == 0xff && SkColorGetB(dsts[0]) == 0x00);
+ REPORTER_ASSERT(r, SkColorGetA(dsts[1]) == 0xff && SkColorGetB(dsts[1]) == 0x00);
+ REPORTER_ASSERT(r, SkColorGetA(dsts[2]) == 0xff && SkColorGetB(dsts[2]) == 0x00);
+
+ // Because we're doing linear blending, a more-exponential transfer function will
+ // brighten the encoded values more when linearizing. So we expect to see that
+ // linear is darker than sRGB, and sRGB in turn is darker than gamma 3.
+ REPORTER_ASSERT(r, SkColorGetR(dsts[0]) < SkColorGetR(dsts[1]));
+ REPORTER_ASSERT(r, SkColorGetR(dsts[1]) < SkColorGetR(dsts[2]));
+
+ REPORTER_ASSERT(r, SkColorGetG(dsts[0]) < SkColorGetG(dsts[1]));
+ REPORTER_ASSERT(r, SkColorGetG(dsts[1]) < SkColorGetG(dsts[2]));
+
+}