WIP: runtime switch for how to interpret SkColor -vs- srgb
authorreed <reed@google.com>
Fri, 15 Apr 2016 17:48:01 +0000 (10:48 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 15 Apr 2016 17:48:01 +0000 (10:48 -0700)
Still very conflicted about the "right" way to proceed with this, but thought I'd experiment with a runtime flag, so we can practice seeing SKPs in various stages of "srgb correctness".

Other aspects to either fix, or at least provide runtime switches for:

- untagged images
- gradients
- colorshader
- drawVertices

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1891013002

TBR=

Review URL: https://codereview.chromium.org/1891013002

src/core/SkColor.cpp
src/core/SkPM4fPriv.h

index ab63300..1c6f0b6 100644 (file)
@@ -9,6 +9,8 @@
 #include "SkColorPriv.h"
 #include "SkFixed.h"
 
+bool gTreatSkColorAsSRGB;
+
 SkPMColor SkPreMultiplyARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
     return SkPremultiplyARGBInline(a, r, g, b);
 }
@@ -156,6 +158,11 @@ SkColor4f SkColor4f::FromColor(SkColor c) {
     Sk4f value = SkNx_shuffle<3,2,1,0>(SkNx_cast<float>(Sk4b::Load(&c)));
     SkColor4f c4;
     (value * Sk4f(1.0f / 255)).store(&c4);
+    if (gTreatSkColorAsSRGB) {
+        c4.fR = srgb_to_linear(c4.fR);
+        c4.fG = srgb_to_linear(c4.fG);
+        c4.fB = srgb_to_linear(c4.fB);
+    }
     return c4;
 }
 
index 48fdde7..b75dc71 100644 (file)
@@ -11,6 +11,8 @@
 #include "SkColorPriv.h"
 #include "SkPM4f.h"
 
+extern bool gTreatSkColorAsSRGB;
+
 static inline float get_alpha(const Sk4f& f4) {
     return f4[SkPM4f::A];
 }
@@ -42,6 +44,14 @@ static inline Sk4f linear_to_srgb(const Sk4f& l4) {
     return set_alpha(l4.sqrt(), get_alpha(l4));
 }
 
+static inline float srgb_to_linear(float x) {
+    return x * x;
+}
+
+static inline float linear_to_srgb(float x) {
+    return sqrtf(x);
+}
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 static inline Sk4f Sk4f_fromL32(uint32_t src) {