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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/core/SkMipMap.cpp ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkPM4fPriv_DEFINED 8 #ifndef SkPM4fPriv_DEFINED
9 #define SkPM4fPriv_DEFINED 9 #define SkPM4fPriv_DEFINED
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 } 45 }
46 46
47 static inline float srgb_to_linear(float x) { 47 static inline float srgb_to_linear(float x) {
48 return x * x; 48 return x * x;
49 } 49 }
50 50
51 static inline float linear_to_srgb(float x) { 51 static inline float linear_to_srgb(float x) {
52 return sqrtf(x); 52 return sqrtf(x);
53 } 53 }
54 54
55 static void assert_unit(float x) {
56 SkASSERT(x >= 0 && x <= 1);
57 }
58
59 static inline float exact_srgb_to_linear(float x) {
60 assert_unit(x);
61 float linear;
62 if (x <= 0.04045) {
63 linear = x / 12.92f;
64 } else {
65 linear = powf((x + 0.055f) / 1.055f, 2.4f);
66 }
67 assert_unit(linear);
68 return linear;
69 }
70
71 static inline float exact_linear_to_srgb(float x) {
72 assert_unit(x);
73 float srgb;
74 if (x <= 0.0031308f) {
75 srgb = x * 12.92f;
76 } else {
77 srgb = 1.055f * powf(x, 0.41666667f) - 0.055f;
78 }
79 assert_unit(srgb);
80 return srgb;
81 }
82
83 static inline Sk4f exact_srgb_to_linear(const Sk4f& x) {
84 Sk4f linear(exact_srgb_to_linear(x[0]),
85 exact_srgb_to_linear(x[1]),
86 exact_srgb_to_linear(x[2]), 1);
87 return set_alpha(linear, get_alpha(x));
88 }
89
90 static inline Sk4f exact_linear_to_srgb(const Sk4f& x) {
91 Sk4f srgb(exact_linear_to_srgb(x[0]),
92 exact_linear_to_srgb(x[1]),
93 exact_linear_to_srgb(x[2]), 1);
94 return set_alpha(srgb, get_alpha(x));
95 }
96
55 //////////////////////////////////////////////////////////////////////////////// /////////////////// 97 //////////////////////////////////////////////////////////////////////////////// ///////////////////
56 98
57 static inline Sk4f Sk4f_fromL32(uint32_t src) { 99 static inline Sk4f Sk4f_fromL32(uint32_t src) {
58 return to_4f(src) * Sk4f(1.0f/255); 100 return to_4f(src) * Sk4f(1.0f/255);
59 } 101 }
60 102
61 static inline Sk4f Sk4f_fromS32(uint32_t src) { 103 static inline Sk4f Sk4f_fromS32(uint32_t src) {
62 return srgb_to_linear(to_4f(src) * Sk4f(1.0f/255)); 104 return srgb_to_linear(to_4f(src) * Sk4f(1.0f/255));
63 } 105 }
64 106
65 // Color handling: 107 // Color handling:
66 // SkColor has an ordering of (b, g, r, a) if cast to an Sk4f, so the code swi zzles r and b to 108 // SkColor has an ordering of (b, g, r, a) if cast to an Sk4f, so the code swi zzles r and b to
67 // produce the needed (r, g, b, a) ordering. 109 // produce the needed (r, g, b, a) ordering.
68 static inline Sk4f Sk4f_from_SkColor(SkColor color) { 110 static inline Sk4f Sk4f_from_SkColor(SkColor color) {
69 return swizzle_rb(gTreatSkColorAsSRGB ? Sk4f_fromS32(color) : Sk4f_fromL32(c olor)); 111 return swizzle_rb(gTreatSkColorAsSRGB ? Sk4f_fromS32(color) : Sk4f_fromL32(c olor));
70 } 112 }
71 113
72 static inline uint32_t Sk4f_toL32(const Sk4f& x4) { 114 static inline uint32_t Sk4f_toL32(const Sk4f& x4) {
73 return to_4b(x4 * Sk4f(255) + Sk4f(0.5f)); 115 return to_4b(x4 * Sk4f(255) + Sk4f(0.5f));
74 } 116 }
75 117
76 static inline uint32_t Sk4f_toS32(const Sk4f& x4) { 118 static inline uint32_t Sk4f_toS32(const Sk4f& x4) {
77 return to_4b(linear_to_srgb(x4) * Sk4f(255) + Sk4f(0.5f)); 119 return to_4b(linear_to_srgb(x4) * Sk4f(255) + Sk4f(0.5f));
78 } 120 }
79 121
122 static inline Sk4f exact_Sk4f_fromS32(uint32_t src) {
123 return exact_srgb_to_linear(to_4f(src) * Sk4f(1.0f/255));
124 }
125 static inline uint32_t exact_Sk4f_toS32(const Sk4f& x4) {
126 return to_4b(exact_linear_to_srgb(x4) * Sk4f(255) + Sk4f(0.5f));
127 }
128
80 #endif 129 #endif
OLDNEW
« 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