| OLD | NEW |
| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 return to_4b(linear_to_srgb(x4) * Sk4f(255) + Sk4f(0.5f)); | 117 return to_4b(linear_to_srgb(x4) * Sk4f(255) + Sk4f(0.5f)); |
| 118 } | 118 } |
| 119 | 119 |
| 120 static inline Sk4f exact_Sk4f_fromS32(uint32_t src) { | 120 static inline Sk4f exact_Sk4f_fromS32(uint32_t src) { |
| 121 return exact_srgb_to_linear(to_4f(src) * Sk4f(1.0f/255)); | 121 return exact_srgb_to_linear(to_4f(src) * Sk4f(1.0f/255)); |
| 122 } | 122 } |
| 123 static inline uint32_t exact_Sk4f_toS32(const Sk4f& x4) { | 123 static inline uint32_t exact_Sk4f_toS32(const Sk4f& x4) { |
| 124 return to_4b(exact_linear_to_srgb(x4) * Sk4f(255) + Sk4f(0.5f)); | 124 return to_4b(exact_linear_to_srgb(x4) * Sk4f(255) + Sk4f(0.5f)); |
| 125 } | 125 } |
| 126 | 126 |
| 127 ////////////////////////////////////////////////////////////////////////////////
//////////////////// |
| 128 // An implementation of SrcOver from bytes to bytes in linear space that takes a
dvantage of the |
| 129 // observation that the 255's cancel. |
| 130 // invA = 1 - (As / 255); |
| 131 // |
| 132 // R = 255 * sqrt((Rs/255)^2 + (Rd/255)^2 * invA) |
| 133 // => R = 255 * sqrt((Rs^2 + Rd^2 * invA)/255^2) |
| 134 // => R = sqrt(Rs^2 + Rd^2 * invA) |
| 135 // Note: src is assumed to be linear. |
| 136 static inline void srcover_blend_srgb8888_srgb_1(uint32_t* dst, const Sk4f& src)
{ |
| 137 Sk4f d = srgb_to_linear(to_4f(*dst)); |
| 138 Sk4f invAlpha = 1.0f - Sk4f{src[SkPM4f::A]} * (1.0f / 255.0f); |
| 139 Sk4f r = linear_to_srgb(src + d * invAlpha) + 0.5f; |
| 140 *dst = to_4b(r); |
| 141 } |
| 142 |
| 143 static inline void srcover_srgb8888_srgb_1(uint32_t* dst, const uint32_t pixel)
{ |
| 144 if ((~pixel & 0xFF000000) == 0) { |
| 145 *dst = pixel; |
| 146 } else if ((pixel & 0xFF000000) != 0) { |
| 147 srcover_blend_srgb8888_srgb_1(dst, srgb_to_linear(to_4f(pixel))); |
| 148 } |
| 149 } |
| 150 |
| 127 #endif | 151 #endif |
| OLD | NEW |