Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Unified Diff: src/gpu/GrColorSpaceXform.cpp

Issue 2154753003: Introduce GrColorSpaceXform, for gamut conversion on textures (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: More progress & refactoring Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrClipMaskManager.cpp ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrColorSpaceXform.cpp
diff --git a/src/gpu/GrColorSpaceXform.cpp b/src/gpu/GrColorSpaceXform.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f60dbcd1c02a7cfbaf64887f7000b8b75332a605
--- /dev/null
+++ b/src/gpu/GrColorSpaceXform.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrColorSpaceXform.h"
+#include "SkColorSpace.h"
+
+static inline bool sk_float_almost_equals(float x, float y, float tol) {
+ return sk_float_abs(x - y) <= tol;
+}
+
+static inline bool matrix_is_almost_identity(const SkMatrix44& m,
+ SkMScalar tol = SK_MScalar1 / (1 << 12)) {
+ return
+ sk_float_almost_equals(m.getFloat(0, 0), 1.0f, tol) &&
+ sk_float_almost_equals(m.getFloat(0, 1), 0.0f, tol) &&
+ sk_float_almost_equals(m.getFloat(0, 2), 0.0f, tol) &&
+ sk_float_almost_equals(m.getFloat(0, 3), 0.0f, tol) &&
+ sk_float_almost_equals(m.getFloat(1, 0), 0.0f, tol) &&
+ sk_float_almost_equals(m.getFloat(1, 1), 1.0f, tol) &&
+ sk_float_almost_equals(m.getFloat(1, 2), 0.0f, tol) &&
+ sk_float_almost_equals(m.getFloat(1, 3), 0.0f, tol) &&
+ sk_float_almost_equals(m.getFloat(2, 0), 0.0f, tol) &&
+ sk_float_almost_equals(m.getFloat(2, 1), 0.0f, tol) &&
+ sk_float_almost_equals(m.getFloat(2, 2), 1.0f, tol) &&
+ sk_float_almost_equals(m.getFloat(2, 3), 0.0f, tol) &&
+ sk_float_almost_equals(m.getFloat(3, 0), 0.0f, tol) &&
+ sk_float_almost_equals(m.getFloat(3, 1), 0.0f, tol) &&
+ sk_float_almost_equals(m.getFloat(3, 2), 0.0f, tol) &&
+ sk_float_almost_equals(m.getFloat(3, 3), 1.0f, tol);
+}
+
+sk_sp<GrColorSpaceXform> GrColorSpaceXform::Make(SkColorSpace* src, SkColorSpace* dst) {
+ if (!src || !dst) {
+ // Invalid
+ return nullptr;
+ }
+
+ if (src == dst) {
+ // Quick equality check - no conversion needed in this case
+ return nullptr;
+ }
+
+ SkMatrix44 srcToDst(SkMatrix44::kUninitialized_Constructor);
+ if (!dst->xyz().invert(&srcToDst)) {
+ return nullptr;
+ }
+ srcToDst.postConcat(src->xyz());
+
+ if (matrix_is_almost_identity(srcToDst)) {
+ return nullptr;
+ }
+
+ return sk_make_sp<GrColorSpaceXform>(srcToDst);
+}
« no previous file with comments | « src/gpu/GrClipMaskManager.cpp ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698