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

Side by Side Diff: src/core/SkColor.cpp

Issue 2097003003: remove experimental treat-skcolor-as-srgb flag (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix toSkColor 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 | « samplecode/SampleApp.cpp ('k') | src/core/SkPM4fPriv.h » ('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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 #include "SkColor.h" 8 #include "SkColor.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkFixed.h" 10 #include "SkFixed.h"
11 11
12 bool gTreatSkColorAsSRGB;
13
14 SkPMColor SkPreMultiplyARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) { 12 SkPMColor SkPreMultiplyARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
15 return SkPremultiplyARGBInline(a, r, g, b); 13 return SkPremultiplyARGBInline(a, r, g, b);
16 } 14 }
17 15
18 SkPMColor SkPreMultiplyColor(SkColor c) { 16 SkPMColor SkPreMultiplyColor(SkColor c) {
19 return SkPremultiplyARGBInline(SkColorGetA(c), SkColorGetR(c), 17 return SkPremultiplyARGBInline(SkColorGetA(c), SkColorGetR(c),
20 SkColorGetG(c), SkColorGetB(c)); 18 SkColorGetG(c), SkColorGetB(c));
21 } 19 }
22 20
23 /////////////////////////////////////////////////////////////////////////////// 21 ///////////////////////////////////////////////////////////////////////////////
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 SkASSERT((c4 >= Sk4f(0)).allTrue() && (c4 <= Sk4f(1)).allTrue()); 149 SkASSERT((c4 >= Sk4f(0)).allTrue() && (c4 <= Sk4f(1)).allTrue());
152 } 150 }
153 #endif 151 #endif
154 152
155 //////////////////////////////////////////////////////////////////////////////// /////////////////// 153 //////////////////////////////////////////////////////////////////////////////// ///////////////////
156 154
157 SkColor4f SkColor4f::FromColor(SkColor c) { 155 SkColor4f SkColor4f::FromColor(SkColor c) {
158 Sk4f value = SkNx_shuffle<2,1,0,3>(SkNx_cast<float>(Sk4b::Load(&c))); 156 Sk4f value = SkNx_shuffle<2,1,0,3>(SkNx_cast<float>(Sk4b::Load(&c)));
159 SkColor4f c4; 157 SkColor4f c4;
160 (value * Sk4f(1.0f / 255)).store(&c4); 158 (value * Sk4f(1.0f / 255)).store(&c4);
161 if (gTreatSkColorAsSRGB) { 159 c4.fR = srgb_to_linear(c4.fR);
162 c4.fR = srgb_to_linear(c4.fR); 160 c4.fG = srgb_to_linear(c4.fG);
163 c4.fG = srgb_to_linear(c4.fG); 161 c4.fB = srgb_to_linear(c4.fB);
164 c4.fB = srgb_to_linear(c4.fB);
165 }
166 return c4; 162 return c4;
167 } 163 }
168 164
169 SkColor SkColor4f::toSkColor() const { 165 SkColor SkColor4f::toSkColor() const {
170 SkColor result; 166 SkColor result;
171 Sk4f value = SkNx_shuffle<2, 1, 0, 3>(Sk4f::Load(this->vec())); 167 Sk4f value = Sk4f(linear_to_srgb(fB), linear_to_srgb(fG), linear_to_srgb(fR) , fA);
172 SkNx_cast<uint8_t>(value * Sk4f(255) + Sk4f(0.5f)).store(&result); 168 SkNx_cast<uint8_t>(value * Sk4f(255) + Sk4f(0.5f)).store(&result);
173 return result; 169 return result;
174 } 170 }
175 171
176 SkColor4f SkColor4f::Pin(float r, float g, float b, float a) { 172 SkColor4f SkColor4f::Pin(float r, float g, float b, float a) {
177 SkColor4f c4; 173 SkColor4f c4;
178 Sk4f::Min(Sk4f::Max(Sk4f(r, g, b, a), Sk4f(0)), Sk4f(1)).store(c4.vec()); 174 Sk4f::Min(Sk4f::Max(Sk4f(r, g, b, a), Sk4f(0)), Sk4f(1)).store(c4.vec());
179 return c4; 175 return c4;
180 } 176 }
181 177
182 SkPM4f SkColor4f::premul() const { 178 SkPM4f SkColor4f::premul() const {
183 auto src = Sk4f::Load(this->pin().vec()); 179 auto src = Sk4f::Load(this->pin().vec());
184 float srcAlpha = src[3]; // need the pinned version of our alpha 180 float srcAlpha = src[3]; // need the pinned version of our alpha
185 src = src * Sk4f(srcAlpha, srcAlpha, srcAlpha, 1); 181 src = src * Sk4f(srcAlpha, srcAlpha, srcAlpha, 1);
186 182
187 return SkPM4f::From4f(src); 183 return SkPM4f::From4f(src);
188 } 184 }
OLDNEW
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | src/core/SkPM4fPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698