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

Unified Diff: src/core/SkPM4fPriv.h

Issue 2029373004: respect srgb gamma when building mips (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix warning Created 4 years, 6 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/SkMipMap.cpp ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPM4fPriv.h
diff --git a/src/core/SkPM4fPriv.h b/src/core/SkPM4fPriv.h
index bf5ff5a1ad44b4914caf36d005653dad4e20c5da..12bf7d0f36bb2b8bd608ebf56ea12e11e3862ca5 100644
--- a/src/core/SkPM4fPriv.h
+++ b/src/core/SkPM4fPriv.h
@@ -52,6 +52,48 @@ static inline float linear_to_srgb(float x) {
return sqrtf(x);
}
+static void assert_unit(float x) {
+ SkASSERT(x >= 0 && x <= 1);
+}
+
+static inline float exact_srgb_to_linear(float x) {
+ assert_unit(x);
+ float linear;
+ if (x <= 0.04045) {
+ linear = x / 12.92f;
+ } else {
+ linear = powf((x + 0.055f) / 1.055f, 2.4f);
+ }
+ assert_unit(linear);
+ return linear;
+}
+
+static inline float exact_linear_to_srgb(float x) {
+ assert_unit(x);
+ float srgb;
+ if (x <= 0.0031308f) {
+ srgb = x * 12.92f;
+ } else {
+ srgb = 1.055f * powf(x, 0.41666667f) - 0.055f;
+ }
+ assert_unit(srgb);
+ return srgb;
+}
+
+static inline Sk4f exact_srgb_to_linear(const Sk4f& x) {
+ Sk4f linear(exact_srgb_to_linear(x[0]),
+ exact_srgb_to_linear(x[1]),
+ exact_srgb_to_linear(x[2]), 1);
+ return set_alpha(linear, get_alpha(x));
+}
+
+static inline Sk4f exact_linear_to_srgb(const Sk4f& x) {
+ Sk4f srgb(exact_linear_to_srgb(x[0]),
+ exact_linear_to_srgb(x[1]),
+ exact_linear_to_srgb(x[2]), 1);
+ return set_alpha(srgb, get_alpha(x));
+}
+
///////////////////////////////////////////////////////////////////////////////////////////////////
static inline Sk4f Sk4f_fromL32(uint32_t src) {
@@ -77,4 +119,11 @@ static inline uint32_t Sk4f_toS32(const Sk4f& x4) {
return to_4b(linear_to_srgb(x4) * Sk4f(255) + Sk4f(0.5f));
}
+static inline Sk4f exact_Sk4f_fromS32(uint32_t src) {
+ return exact_srgb_to_linear(to_4f(src) * Sk4f(1.0f/255));
+}
+static inline uint32_t exact_Sk4f_toS32(const Sk4f& x4) {
+ return to_4b(exact_linear_to_srgb(x4) * Sk4f(255) + Sk4f(0.5f));
+}
+
#endif
« no previous file with comments | « src/core/SkMipMap.cpp ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698