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

Side by Side Diff: src/core/SkPM4fPriv.h

Issue 2046063002: linear -> sRGB: use fast approximate sqrt() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: found another 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 | « no previous file | src/core/SkXfermode4f.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 23 matching lines...) Expand all
34 34
35 static inline Sk4f to_4f_rgba(uint32_t b4) { 35 static inline Sk4f to_4f_rgba(uint32_t b4) {
36 return swizzle_rb_if_bgra(to_4f(b4)); 36 return swizzle_rb_if_bgra(to_4f(b4));
37 } 37 }
38 38
39 static inline Sk4f srgb_to_linear(const Sk4f& s4) { 39 static inline Sk4f srgb_to_linear(const Sk4f& s4) {
40 return set_alpha(s4 * s4, get_alpha(s4)); 40 return set_alpha(s4 * s4, get_alpha(s4));
41 } 41 }
42 42
43 static inline Sk4f linear_to_srgb(const Sk4f& l4) { 43 static inline Sk4f linear_to_srgb(const Sk4f& l4) {
44 return set_alpha(l4.sqrt(), get_alpha(l4)); 44 return set_alpha(l4.rsqrt().invert(), get_alpha(l4));
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
(...skipping 16 matching lines...) Expand all
71 71
72 static inline uint32_t Sk4f_toL32(const Sk4f& x4) { 72 static inline uint32_t Sk4f_toL32(const Sk4f& x4) {
73 return to_4b(x4 * Sk4f(255) + Sk4f(0.5f)); 73 return to_4b(x4 * Sk4f(255) + Sk4f(0.5f));
74 } 74 }
75 75
76 static inline uint32_t Sk4f_toS32(const Sk4f& x4) { 76 static inline uint32_t Sk4f_toS32(const Sk4f& x4) {
77 return to_4b(linear_to_srgb(x4) * Sk4f(255) + Sk4f(0.5f)); 77 return to_4b(linear_to_srgb(x4) * Sk4f(255) + Sk4f(0.5f));
78 } 78 }
79 79
80 #endif 80 #endif
OLDNEW
« no previous file with comments | « no previous file | src/core/SkXfermode4f.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698