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

Unified Diff: src/core/SkColorSpacePriv.h

Issue 2409383002: Add SkColorSpaceTransferFn to SkColorSpace (Closed)
Patch Set: Add more comments Created 4 years, 2 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/core/SkColorSpace.cpp ('k') | src/core/SkColorSpaceXform.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkColorSpacePriv.h
diff --git a/src/core/SkColorSpacePriv.h b/src/core/SkColorSpacePriv.h
index e7c8aaa10382345f44a30449f43fe1b55844952e..73038738ff60bc024ccf9a6fcbc8754855cb4174 100644
--- a/src/core/SkColorSpacePriv.h
+++ b/src/core/SkColorSpacePriv.h
@@ -7,6 +7,80 @@
#define SkColorSpacePrintf(...)
-inline bool color_space_almost_equal(float a, float b) {
+static inline bool color_space_almost_equal(float a, float b) {
return SkTAbs(a - b) < 0.01f;
}
+
+static inline bool is_zero_to_one(float v) {
+ return (0.0f <= v) && (v <= 1.0f);
+}
+
+static inline bool is_valid_transfer_fn(const SkColorSpaceTransferFn& coeffs) {
+ if (SkScalarIsNaN(coeffs.fA) || SkScalarIsNaN(coeffs.fB) ||
+ SkScalarIsNaN(coeffs.fC) || SkScalarIsNaN(coeffs.fD) ||
+ SkScalarIsNaN(coeffs.fE) || SkScalarIsNaN(coeffs.fF) ||
+ SkScalarIsNaN(coeffs.fG))
+ {
+ return false;
+ }
+
+ if (!is_zero_to_one(coeffs.fD)) {
+ return false;
+ }
+
+ if (coeffs.fD == 0.0f) {
+ // Y = (aX + b)^g + c for always
+ if (0.0f == coeffs.fA || 0.0f == coeffs.fG) {
+ SkColorSpacePrintf("A or G is zero, constant transfer function "
+ "is nonsense");
+ return false;
+ }
+ }
+
+ if (coeffs.fD == 1.0f) {
+ // Y = eX + f for always
+ if (0.0f == coeffs.fE) {
+ SkColorSpacePrintf("E is zero, constant transfer function is "
+ "nonsense");
+ return false;
+ }
+ }
+
+ if ((0.0f == coeffs.fA || 0.0f == coeffs.fG) && 0.0f == coeffs.fE) {
+ SkColorSpacePrintf("A or G, and E are zero, constant transfer function "
+ "is nonsense");
+ return false;
+ }
+
+ if (coeffs.fE < 0.0f) {
+ SkColorSpacePrintf("Transfer function must be increasing");
+ return false;
+ }
+
+ if (coeffs.fA < 0.0f || coeffs.fG < 0.0f) {
+ SkColorSpacePrintf("Transfer function must be positive or increasing");
+ return false;
+ }
+
+ return true;
+}
+
+static inline bool is_almost_srgb(const SkColorSpaceTransferFn& coeffs) {
+ return color_space_almost_equal(0.9479f, coeffs.fA) &&
+ color_space_almost_equal(0.0521f, coeffs.fB) &&
+ color_space_almost_equal(0.0000f, coeffs.fC) &&
+ color_space_almost_equal(0.0405f, coeffs.fD) &&
+ color_space_almost_equal(0.0774f, coeffs.fE) &&
+ color_space_almost_equal(0.0000f, coeffs.fF) &&
+ color_space_almost_equal(2.4000f, coeffs.fG);
+}
+
+static inline bool is_almost_2dot2(const SkColorSpaceTransferFn& coeffs) {
+ return color_space_almost_equal(1.0f, coeffs.fA) &&
+ color_space_almost_equal(0.0f, coeffs.fB) &&
+ color_space_almost_equal(0.0f, coeffs.fC) &&
+ color_space_almost_equal(0.0f, coeffs.fD) &&
+ color_space_almost_equal(0.0f, coeffs.fE) &&
+ color_space_almost_equal(0.0f, coeffs.fF) &&
+ color_space_almost_equal(2.2f, coeffs.fG);
+}
« no previous file with comments | « src/core/SkColorSpace.cpp ('k') | src/core/SkColorSpaceXform.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698