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

Side by Side Diff: include/gpu/GrColor.h

Issue 2088303002: Add GrColor4f type, store that in GrPaint. Linearize based on global flag. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix conversion to SkColor4f with new channel order 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 | include/gpu/GrPaint.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 /* 2 /*
3 * Copyright 2010 Google Inc. 3 * Copyright 2010 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 10
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 SkColor colorUPM = SkUnPreMultiply::PMColorToColor(colorPM); 162 SkColor colorUPM = SkUnPreMultiply::PMColorToColor(colorPM);
163 163
164 r = SkColorGetR(colorUPM); 164 r = SkColorGetR(colorUPM);
165 g = SkColorGetG(colorUPM); 165 g = SkColorGetG(colorUPM);
166 b = SkColorGetB(colorUPM); 166 b = SkColorGetB(colorUPM);
167 a = SkColorGetA(colorUPM); 167 a = SkColorGetA(colorUPM);
168 168
169 return GrColorPackRGBA(r, g, b, a); 169 return GrColorPackRGBA(r, g, b, a);
170 } 170 }
171 171
172
173 /**
174 * Similarly, GrColor4f is 4 floats for R, G, B, A, in that order. And like GrCol or, whether
175 * the color is premultiplied or not depends on the context.
176 */
177 struct GrColor4f {
178 float fRGBA[4];
179
180 GrColor4f() {}
181 GrColor4f(float r, float g, float b, float a) {
182 fRGBA[0] = r;
183 fRGBA[1] = g;
184 fRGBA[2] = b;
185 fRGBA[3] = a;
186 }
187
188 static GrColor4f FromGrColor(GrColor color) {
189 GrColor4f result;
190 GrColorToRGBAFloat(color, result.fRGBA);
191 return result;
192 }
193
194 static GrColor4f FromSkColor4f(const SkColor4f& color) {
195 return GrColor4f(color.fR, color.fG, color.fB, color.fA);
196 }
197
198 GrColor toGrColor() const {
199 return GrColorPackRGBA(
200 SkTPin<unsigned>(static_cast<unsigned>(fRGBA[0] * 255.0f + 0.5f), 0, 255),
201 SkTPin<unsigned>(static_cast<unsigned>(fRGBA[1] * 255.0f + 0.5f), 0, 255),
202 SkTPin<unsigned>(static_cast<unsigned>(fRGBA[2] * 255.0f + 0.5f), 0, 255),
203 SkTPin<unsigned>(static_cast<unsigned>(fRGBA[3] * 255.0f + 0.5f), 0, 255));
204 }
205
206 SkColor4f toSkColor4f() const {
207 return SkColor4f { fRGBA[0], fRGBA[1], fRGBA[2], fRGBA[3] };
208 }
209
210 GrColor4f opaque() const {
211 return GrColor4f(fRGBA[0], fRGBA[1], fRGBA[2], 1.0f);
212 }
213
214 GrColor4f premul() const {
215 float a = fRGBA[3];
216 return GrColor4f(fRGBA[0] * a, fRGBA[1] * a, fRGBA[2] * a, a);
217 }
218 };
219
172 /** 220 /**
173 * Flags used for bitfields of color components. They are defined so that the bi t order reflects the 221 * Flags used for bitfields of color components. They are defined so that the bi t order reflects the
174 * GrColor shift order. 222 * GrColor shift order.
175 */ 223 */
176 enum GrColorComponentFlags { 224 enum GrColorComponentFlags {
177 kR_GrColorComponentFlag = 1 << (GrColor_SHIFT_R / 8), 225 kR_GrColorComponentFlag = 1 << (GrColor_SHIFT_R / 8),
178 kG_GrColorComponentFlag = 1 << (GrColor_SHIFT_G / 8), 226 kG_GrColorComponentFlag = 1 << (GrColor_SHIFT_G / 8),
179 kB_GrColorComponentFlag = 1 << (GrColor_SHIFT_B / 8), 227 kB_GrColorComponentFlag = 1 << (GrColor_SHIFT_B / 8),
180 kA_GrColorComponentFlag = 1 << (GrColor_SHIFT_A / 8), 228 kA_GrColorComponentFlag = 1 << (GrColor_SHIFT_A / 8),
181 229
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 GR_STATIC_ASSERT(10 == kLATC_GrPixelConfig); 289 GR_STATIC_ASSERT(10 == kLATC_GrPixelConfig);
242 GR_STATIC_ASSERT(11 == kR11_EAC_GrPixelConfig); 290 GR_STATIC_ASSERT(11 == kR11_EAC_GrPixelConfig);
243 GR_STATIC_ASSERT(12 == kASTC_12x12_GrPixelConfig); 291 GR_STATIC_ASSERT(12 == kASTC_12x12_GrPixelConfig);
244 GR_STATIC_ASSERT(13 == kRGBA_float_GrPixelConfig); 292 GR_STATIC_ASSERT(13 == kRGBA_float_GrPixelConfig);
245 GR_STATIC_ASSERT(14 == kAlpha_half_GrPixelConfig); 293 GR_STATIC_ASSERT(14 == kAlpha_half_GrPixelConfig);
246 GR_STATIC_ASSERT(15 == kRGBA_half_GrPixelConfig); 294 GR_STATIC_ASSERT(15 == kRGBA_half_GrPixelConfig);
247 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFlags) == kGrPixelConfigCnt); 295 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFlags) == kGrPixelConfigCnt);
248 } 296 }
249 297
250 #endif 298 #endif
OLDNEW
« no previous file with comments | « no previous file | include/gpu/GrPaint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698