blob: c71ad1ff52c15155c759d677c5eb501559640c6a [file] [log] [blame]
Cary Clark2d4bf5f2018-04-16 08:37:38 -04001#Topic Color
Cary Clark137b8742018-05-30 09:21:49 -04002#Alias Color_Reference ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -04003
Cary Clark61313f32018-10-08 14:57:48 -04004#Code
Cary Clark2d4bf5f2018-04-16 08:37:38 -04005#Populate
6##
7
Cary Clark682c58d2018-05-16 07:07:07 -04008Color constants can be helpful to write code, documenting the meaning of values
9the represent transparency and color values. The use of Color constants is not
10required.
11
Cary Clark61313f32018-10-08 14:57:48 -040012#Subtopic Functions
13#Line # routines to read, write, and manipulate SkColor ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -040014##
15
Cary Clark2d4bf5f2018-04-16 08:37:38 -040016# ------------------------------------------------------------------------------
17
Cary Clark682c58d2018-05-16 07:07:07 -040018#Subtopic Alpha
Cary Clark61313f32018-10-08 14:57:48 -040019#Line # transparency of Color ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -040020
Cary Clark682c58d2018-05-16 07:07:07 -040021Alpha represents the transparency of Color. Color with Alpha of zero is fully
22transparent. Color with Alpha of 255 is fully opaque. Some, but not all pixel
23formats contain Alpha. Pixels with Alpha may store it as unsigned integers or
24floating point values. Unsigned integer Alpha ranges from zero, fully
25transparent, to all bits set, fully opaque. Floating point Alpha ranges from
26zero, fully transparent, to one, fully opaque.
27
Cary Clark137b8742018-05-30 09:21:49 -040028#Alias Alpha
29#Substitute alpha
30##
Cary Clark682c58d2018-05-16 07:07:07 -040031
32#Typedef uint8_t SkAlpha
33#Line # defines Alpha as eight bits ##
34
Cary Clarkffb3d682018-05-17 12:17:28 -040035#Code
36typedef uint8_t SkAlpha;
37##
38
Cary Clark0d225392018-06-07 09:59:07 -0400398-bit type for an alpha value. 255 is 100% opaque, zero is 100% transparent.
Cary Clark2d4bf5f2018-04-16 08:37:38 -040040
41#Typedef ##
42
Cary Clark682c58d2018-05-16 07:07:07 -040043#Subtopic ##
44
Cary Clark2d4bf5f2018-04-16 08:37:38 -040045# ------------------------------------------------------------------------------
46
47#Typedef uint32_t SkColor
Cary Clark682c58d2018-05-16 07:07:07 -040048#Line # defines Color as 32 bits ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -040049
Cary Clarkffb3d682018-05-17 12:17:28 -040050#Code
51typedef uint32_t SkColor;
52##
53
Cary Clark682c58d2018-05-16 07:07:07 -04005432-bit ARGB Color value, Unpremultiplied. Color components are always in
Cary Clark2d4bf5f2018-04-16 08:37:38 -040055a known order. This is different from SkPMColor, which has its bytes in a configuration
56dependent order, to match the format of kBGRA_8888_SkColorType bitmaps. SkColor
57is the type used to specify colors in SkPaint and in gradients.
58
Cary Clark682c58d2018-05-16 07:07:07 -040059Color that is Premultiplied has the same component values as Color
60that is Unpremultiplied if Alpha is 255, fully opaque, although may have the
61component values in a different order.
62
63#SeeAlso SkPMColor
64
Cary Clark2d4bf5f2018-04-16 08:37:38 -040065#Typedef ##
66
67# ------------------------------------------------------------------------------
68
69#Method static constexpr inline SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Cary Clark61313f32018-10-08 14:57:48 -040070#In Functions
Cary Clarkffb3d682018-05-17 12:17:28 -040071#Line # returns Color_Alpha and RGB combined ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -040072
Cary Clark682c58d2018-05-16 07:07:07 -040073Returns Color value from 8-bit component values. Asserts if SK_DEBUG is defined
74if a, r, g, or b exceed 255. Since Color is Unpremultiplied, a may be smaller
75than the largest of r, g, and b.
Cary Clark2d4bf5f2018-04-16 08:37:38 -040076
Cary Clark682c58d2018-05-16 07:07:07 -040077#Param a amount of Alpha, from fully transparent (0) to fully opaque (255) ##
Cary Clarkffb3d682018-05-17 12:17:28 -040078#Param r amount of red, from no red (0) to full red (255) ##
79#Param g amount of green, from no green (0) to full green (255) ##
80#Param b amount of blue, from no blue (0) to full blue (255) ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -040081
Cary Clark682c58d2018-05-16 07:07:07 -040082#Return color and alpha, Unpremultiplied ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -040083
84#Example
Cary Clark682c58d2018-05-16 07:07:07 -040085 canvas->drawColor(SK_ColorRED);
86 canvas->clipRect(SkRect::MakeWH(150, 150));
87 canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0xFF, 0x00));
88 canvas->clipRect(SkRect::MakeWH(75, 75));
89 canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0x00, 0xFF));
Cary Clark2d4bf5f2018-04-16 08:37:38 -040090##
91
Cary Clarkffb3d682018-05-17 12:17:28 -040092#SeeAlso SkColorSetRGB SkPaint::setARGB SkPaint::setColor SkColorSetA
Cary Clark2d4bf5f2018-04-16 08:37:38 -040093
94#Method ##
95
96# ------------------------------------------------------------------------------
97
Cary Clark2d4bf5f2018-04-16 08:37:38 -040098#Define SkColorSetRGB
Cary Clark682c58d2018-05-16 07:07:07 -040099#Line # returns opaque Color ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400100
101#Code
102###$
103 #define SkColorSetRGB(r, g, b) SkColorSetARGB(0xFF, r, g, b)
104$$$#
105##
106
Cary Clark682c58d2018-05-16 07:07:07 -0400107Returns Color value from 8-bit component values, with Alpha set
108fully opaque to 255.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400109
Cary Clarkffb3d682018-05-17 12:17:28 -0400110#Param r amount of red, from no red (0) to full red (255) ##
111#Param g amount of green, from no green (0) to full green (255) ##
112#Param b amount of blue, from no blue (0) to full blue (255) ##
Cary Clark682c58d2018-05-16 07:07:07 -0400113
114#Return color with opaque alpha ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400115
116#Example
Cary Clark682c58d2018-05-16 07:07:07 -0400117 canvas->drawColor(SK_ColorRED);
118 canvas->clipRect(SkRect::MakeWH(150, 150));
119 canvas->drawColor(SkColorSetRGB(0x00, 0xFF, 0x00));
120 canvas->clipRect(SkRect::MakeWH(75, 75));
121 canvas->drawColor(SkColorSetRGB(0x00, 0x00, 0xFF));
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400122##
123
Cary Clarkffb3d682018-05-17 12:17:28 -0400124#SeeAlso SkColorSetARGB
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400125
126#Define ##
127
128# ------------------------------------------------------------------------------
129
130#Define SkColorGetA
Cary Clark682c58d2018-05-16 07:07:07 -0400131#Line # returns Alpha component ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400132
133#Code
134###$
135 #define SkColorGetA(color) (((color) >> 24) & 0xFF)
136$$$#
137##
138
Cary Clark682c58d2018-05-16 07:07:07 -0400139Returns Alpha byte from Color value.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400140
Cary Clark682c58d2018-05-16 07:07:07 -0400141#Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400142
143#Example
Cary Clark61313f32018-10-08 14:57:48 -0400144 SkPaint paint;
145 paint.setAntiAlias(true);
146 paint.setColor(SK_ColorRED);
147 for (int alpha = 255; alpha >= 0; alpha -= 17) {
148 paint.setAlpha(alpha);
149 canvas->drawRect({5, 5, 100, 20}, paint);
150 SkAlpha alphaInPaint = SkColorGetA(paint.getColor());
151 canvas->drawString(std::to_string(alphaInPaint).c_str(), 110, 18, paint);
152 canvas->translate(0, 15);
153 }
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400154##
155
Cary Clarkffb3d682018-05-17 12:17:28 -0400156#SeeAlso SkPaint::getAlpha
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400157
158#Define ##
159
160# ------------------------------------------------------------------------------
161
162#Define SkColorGetR
Cary Clarkffb3d682018-05-17 12:17:28 -0400163#Line # returns red component ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400164
165#Code
166###$
167 #define SkColorGetR(color) (((color) >> 16) & 0xFF)
168$$$#
169##
170
Cary Clark682c58d2018-05-16 07:07:07 -0400171Returns red component of Color, from zero to 255.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400172
Cary Clark682c58d2018-05-16 07:07:07 -0400173#Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
174#Return red byte ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400175
176#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400177#Image 3
Cary Clark61313f32018-10-08 14:57:48 -0400178 canvas->drawBitmap(source, 0, 0);
179 SkPaint bgPaint;
180 bgPaint.setColor(0xafffffff);
181 canvas->drawRect({20, 50, 80, 70}, bgPaint);
182 uint8_t red = SkColorGetR(source.getColor(226, 128));
183 canvas->drawString(std::to_string(red).c_str(), 40, 65, SkPaint());
184 canvas->drawLine(80, 70, 226, 128, SkPaint());
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400185##
186
Cary Clarkffb3d682018-05-17 12:17:28 -0400187#SeeAlso SkColorGetG SkColorGetB
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400188
189#Define ##
190
191# ------------------------------------------------------------------------------
192
193#Define SkColorGetG
Cary Clarkffb3d682018-05-17 12:17:28 -0400194#Line # returns green component ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400195
196#Code
197###$
198 #define SkColorGetG(color) (((color) >> 8) & 0xFF)
199$$$#
200##
201
Cary Clark682c58d2018-05-16 07:07:07 -0400202Returns green component of Color, from zero to 255.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400203
Cary Clark682c58d2018-05-16 07:07:07 -0400204#Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
205#Return green byte ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400206
207#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400208#Image 3
Cary Clark61313f32018-10-08 14:57:48 -0400209 canvas->drawBitmap(source, 0, 0);
210 SkPaint bgPaint;
211 bgPaint.setColor(0xafffffff);
212 canvas->drawRect({20, 50, 80, 70}, bgPaint);
213 uint8_t green = SkColorGetG(source.getColor(57, 192));
214 canvas->drawString(std::to_string(green).c_str(), 40, 65, SkPaint());
Cary Clarkffb3d682018-05-17 12:17:28 -0400215 canvas->drawLine(80, 70, 57, 192, SkPaint());
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400216##
217
Cary Clarkffb3d682018-05-17 12:17:28 -0400218#SeeAlso SkColorGetR SkColorGetB
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400219
220#Define ##
221
222# ------------------------------------------------------------------------------
223
224#Define SkColorGetB
Cary Clarkffb3d682018-05-17 12:17:28 -0400225#Line # returns blue component ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400226
227#Code
228###$
229 #define SkColorGetB(color) (((color) >> 0) & 0xFF)
230$$$#
231##
232
Cary Clark682c58d2018-05-16 07:07:07 -0400233Returns blue component of Color, from zero to 255.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400234
Cary Clark682c58d2018-05-16 07:07:07 -0400235#Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
236#Return blue byte ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400237
238#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400239#Image 3
Cary Clark61313f32018-10-08 14:57:48 -0400240 canvas->drawBitmap(source, 0, 0);
241 SkPaint bgPaint;
242 bgPaint.setColor(0xafffffff);
243 canvas->drawRect({20, 50, 80, 70}, bgPaint);
244 uint8_t blue = SkColorGetB(source.getColor(168, 170));
245 canvas->drawString(std::to_string(blue).c_str(), 40, 65, SkPaint());
Cary Clarkffb3d682018-05-17 12:17:28 -0400246 canvas->drawLine(80, 70, 168, 170, SkPaint());
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400247##
248
Cary Clarkffb3d682018-05-17 12:17:28 -0400249#SeeAlso SkColorGetR SkColorGetG
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400250
251#Define ##
252
253# ------------------------------------------------------------------------------
254
255#Method static constexpr inline SkColor SkColorSetA(SkColor c, U8CPU a)
Cary Clark61313f32018-10-08 14:57:48 -0400256#In Functions
Cary Clarkffb3d682018-05-17 12:17:28 -0400257#Line # returns Color with transparency ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400258
Cary Clarkffb3d682018-05-17 12:17:28 -0400259Returns Unpremultiplied Color with red, blue, and green set from c; and alpha set
260from a. Alpha component of c is ignored and is replaced by a in result.
Cary Clark682c58d2018-05-16 07:07:07 -0400261
Cary Clarkffb3d682018-05-17 12:17:28 -0400262#Param c packed RGB, eight bits per component ##
263#Param a Alpha: transparent at zero, fully opaque at 255 ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400264
Cary Clarkffb3d682018-05-17 12:17:28 -0400265#Return Color with transparency ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400266
267#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400268#Image 3
Cary Clark61313f32018-10-08 14:57:48 -0400269 canvas->drawBitmap(source, 0, 0);
270 for (int y = 0; y < 256; y += 16) {
271 for (int x = 0; x < 256; x += 16) {
272 SkColor color = source.getColor(x + 8, y + 8);
273 SkPaint paint;
274 paint.setColor(SkColorSetA(color, x + y));
275 canvas->drawRect(SkRect::MakeXYWH(x, y, 16, 16), paint);
276 }
277 }
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400278##
279
Cary Clarkffb3d682018-05-17 12:17:28 -0400280#SeeAlso SkColorSetARGB
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400281
282#Method ##
283
284# ------------------------------------------------------------------------------
285
Cary Clark682c58d2018-05-16 07:07:07 -0400286#Subtopic Alpha_Constants
287#In Constant
288#Line # constants for Alpha ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400289
290#Code
Cary Clark682c58d2018-05-16 07:07:07 -0400291 constexpr SkAlpha SK_AlphaTRANSPARENT = 0x00;
292 constexpr SkAlpha SK_AlphaOPAQUE = 0xFF;
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400293##
294
Cary Clark682c58d2018-05-16 07:07:07 -0400295Alpha constants are conveniences to represent fully transparent and fully
296opaque colors and masks. Their use is not required.
297
298#Const SK_AlphaTRANSPARENT 0x00
299#Line # fully transparent SkAlpha ##
300#Details Transparent
301Represents fully transparent SkAlpha value. SkAlpha ranges from zero,
302fully transparent; to 255, fully opaque.
303##
304#Const SK_AlphaOPAQUE 0xFF
305#Line # fully opaque SkAlpha ##
306#Details Opaque
307Represents fully opaque SkAlpha value. SkAlpha ranges from zero,
308fully transparent; to 255, fully opaque.
309##
310
311#Subtopic Transparent
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400312
313#Example
Cary Clark682c58d2018-05-16 07:07:07 -0400314#Image 1
315#Height 128
316#Description
317Color the parts of the bitmap red if they mostly contain transparent pixels.
318##
319 std::vector<int32_t> srcPixels;
320 srcPixels.resize(source.height() * source.rowBytes());
321 SkPixmap pixmap(SkImageInfo::MakeN32Premul(source.width(), source.height()),
322 &srcPixels.front(), source.rowBytes());
323 source.readPixels(pixmap, 0, 0);
324 for (int y = 0; y < 16; ++y) {
325 for (int x = 0; x < 16; ++x) {
326 int32_t* blockStart = &srcPixels.front() + y * source.width() * 16 + x * 16;
327 size_t transparentCount = 0;
328 for (int fillY = 0; fillY < source.height() / 16; ++fillY) {
329 for (int fillX = 0; fillX < source.width() / 16; ++fillX) {
330 const SkColor color = SkUnPreMultiply::PMColorToColor(blockStart[fillX]);
331 transparentCount += SkColorGetA(color) == SK_AlphaTRANSPARENT;
332 }
333 blockStart += source.width();
334 }
335 if (transparentCount > 200) {
336 blockStart = &srcPixels.front() + y * source.width() * 16 + x * 16;
337 for (int fillY = 0; fillY < source.height() / 16; ++fillY) {
338 for (int fillX = 0; fillX < source.width() / 16; ++fillX) {
339 blockStart[fillX] = SK_ColorRED;
340 }
341 blockStart += source.width();
342 }
343 }
344 }
345 }
346 SkBitmap bitmap;
347 bitmap.installPixels(pixmap);
348 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400349##
350
Cary Clark682c58d2018-05-16 07:07:07 -0400351#SeeAlso SkAlpha SK_ColorTRANSPARENT SK_AlphaOPAQUE
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400352
Cary Clark682c58d2018-05-16 07:07:07 -0400353#Subtopic Transparent ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400354
355# ------------------------------------------------------------------------------
356
Cary Clark682c58d2018-05-16 07:07:07 -0400357#Subtopic Opaque
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400358
359#Example
Cary Clark682c58d2018-05-16 07:07:07 -0400360#Image 1
361#Height 128
362 std::vector<int32_t> srcPixels;
363 srcPixels.resize(source.height() * source.rowBytes());
364 SkPixmap pixmap(SkImageInfo::MakeN32Premul(source.width(), source.height()),
365 &srcPixels.front(), source.rowBytes());
366 source.readPixels(pixmap, 0, 0);
367 for (int y = 0; y < source.height(); ++y) {
368 for (int x = 0; x < source.width(); ++x) {
369 SkPMColor pixel = srcPixels[y * source.width() + x];
370 const SkColor color = SkUnPreMultiply::PMColorToColor(pixel);
371 if (SkColorGetA(color) == SK_AlphaOPAQUE) {
372 srcPixels[y * source.width() + x] = SK_ColorGREEN;
373 }
374 }
375 }
376 SkBitmap bitmap;
377 bitmap.installPixels(pixmap);
378 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400379##
380
Cary Clark682c58d2018-05-16 07:07:07 -0400381#SeeAlso SkAlpha SK_AlphaTRANSPARENT
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400382
Cary Clark682c58d2018-05-16 07:07:07 -0400383#Subtopic Opaque ##
384#Subtopic Alpha_Constants ##
385
386#Subtopic Color_Constants
387#In Constant
388#Line # constants for Color ##
389
390# ------------------------------------------------------------------------------
391#Code
392 constexpr SkColor SK_ColorTRANSPARENT = SkColorSetARGB(0x00, 0x00, 0x00, 0x00);
393 constexpr SkColor SK_ColorBLACK = SkColorSetARGB(0xFF, 0x00, 0x00, 0x00);
394 constexpr SkColor SK_ColorDKGRAY = SkColorSetARGB(0xFF, 0x44, 0x44, 0x44);
395 constexpr SkColor SK_ColorGRAY = SkColorSetARGB(0xFF, 0x88, 0x88, 0x88);
396 constexpr SkColor SK_ColorLTGRAY = SkColorSetARGB(0xFF, 0xCC, 0xCC, 0xCC);
397 constexpr SkColor SK_ColorWHITE = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF);
398 constexpr SkColor SK_ColorRED = SkColorSetARGB(0xFF, 0xFF, 0x00, 0x00);
399 constexpr SkColor SK_ColorGREEN = SkColorSetARGB(0xFF, 0x00, 0xFF, 0x00);
400 constexpr SkColor SK_ColorBLUE = SkColorSetARGB(0xFF, 0x00, 0x00, 0xFF);
401 constexpr SkColor SK_ColorYELLOW = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0x00);
402 constexpr SkColor SK_ColorCYAN = SkColorSetARGB(0xFF, 0x00, 0xFF, 0xFF);
403 constexpr SkColor SK_ColorMAGENTA = SkColorSetARGB(0xFF, 0xFF, 0x00, 0xFF);
404##
405
406Color names are provided as conveniences, but are not otherwise special.
407The values chosen for names may not be the same as values used by
408SVG, HTML, CSS, or colors named by a platform.
409
410#Example
411###$
412$Function
413#define SKIA_COLOR_PAIR(name) "SK_Color" #name, SK_Color##name
414$$
415void draw(SkCanvas* canvas) {
416 struct ColorCompare {
417 const char* fSVGName;
418 SkColor fSVGColor;
419 const char* fSkiaName;
420 SkColor fSkiaColor;
421 } colorCompare[] = { // see https://www.w3.org/TR/SVG/types.html#ColorKeywords
422 {"black", SkColorSetRGB( 0, 0, 0), SKIA_COLOR_PAIR(BLACK) },
423 {"darkgray", SkColorSetRGB(169, 169, 169), SKIA_COLOR_PAIR(DKGRAY) },
424 {"gray", SkColorSetRGB(128, 128, 128), SKIA_COLOR_PAIR(GRAY) },
425 {"lightgray", SkColorSetRGB(211, 211, 211), SKIA_COLOR_PAIR(LTGRAY) },
426 {"white", SkColorSetRGB(255, 255, 255), SKIA_COLOR_PAIR(WHITE) },
427 {"red", SkColorSetRGB(255, 0, 0), SKIA_COLOR_PAIR(RED) },
428 {"green", SkColorSetRGB( 0, 128, 0), SKIA_COLOR_PAIR(GREEN) },
429 {"blue", SkColorSetRGB( 0, 0, 255), SKIA_COLOR_PAIR(BLUE) },
430 {"yellow", SkColorSetRGB(255, 255, 0), SKIA_COLOR_PAIR(YELLOW) },
431 {"aqua", SkColorSetRGB( 0, 255, 255), SKIA_COLOR_PAIR(CYAN) },
432 {"fuchsia", SkColorSetRGB(255, 0, 255), SKIA_COLOR_PAIR(MAGENTA) },
433 };
434 SkPaint paint;
435 paint.setAntiAlias(true);
436 paint.setTextSize(14);
437 for (auto compare : colorCompare) {
438 paint.setStyle(SkPaint::kFill_Style);
439 paint.setColor(compare.fSVGColor);
440 canvas->drawRect({5, 5, 15, 15}, paint);
441 paint.setColor(SK_ColorBLACK);
442 canvas->drawString(compare.fSVGName, 20, 16, paint);
443 paint.setColor(compare.fSkiaColor);
444 canvas->drawRect({105, 5, 115, 15}, paint);
445 paint.setColor(SK_ColorBLACK);
446 canvas->drawString(compare.fSkiaName, 120, 16, paint);
447 paint.setStyle(SkPaint::kStroke_Style);
448 canvas->drawRect({5, 5, 15, 15}, paint);
449 canvas->drawRect({105, 5, 115, 15}, paint);
450 canvas->translate(0, 20);
451 }
452}
453$$$#
454##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400455
456# ------------------------------------------------------------------------------
457
Cary Clark682c58d2018-05-16 07:07:07 -0400458#Const SK_ColorTRANSPARENT 0x00000000
459#Line # transparent Color ##
460#Details Transparent
461 Represents fully transparent SkColor. May be used to initialize a destination
462 containing a mask or a non-rectangular image.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400463##
Cary Clark682c58d2018-05-16 07:07:07 -0400464#Const SK_ColorBLACK 0xFF000000
465#Line # black Color ##
466#Details Black
467 Represents fully opaque black.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400468##
Cary Clark682c58d2018-05-16 07:07:07 -0400469#Const SK_ColorDKGRAY 0xFF444444
470#Line # dark gray Color ##
471 Represents fully opaque dark gray.
472 Note that SVG_darkgray is equivalent to 0xFFA9A9A9.
473##
474#Const SK_ColorGRAY 0xFF888888
475#Line # gray Color ##
476 Represents fully opaque gray.
477 Note that HTML_Gray is equivalent to 0xFF808080.
478##
479#Const SK_ColorLTGRAY 0xFFCCCCCC
480#Line # light gray Color ##
481 Represents fully opaque light gray. HTML_Silver is equivalent to 0xFFC0C0C0.
482 Note that SVG_lightgray is equivalent to 0xFFD3D3D3.
483##
484#Const SK_ColorWHITE 0xFFFFFFFF
485#Line # white Color ##
486 Represents fully opaque white.
487##
488#Const SK_ColorRED 0xFFFF0000
489#Line # red Color ##
490 Represents fully opaque red.
491##
492#Const SK_ColorGREEN 0xFF00FF00
493#Line # green Color ##
494 Represents fully opaque green. HTML_Lime is equivalent.
495 Note that HTML_Green is equivalent to 0xFF008000.
496##
497#Const SK_ColorBLUE 0xFF0000FF
498#Line # blue Color ##
499 Represents fully opaque blue.
500##
501#Const SK_ColorYELLOW 0xFFFFFF00
502#Line # yellow Color ##
503 Represents fully opaque yellow.
504##
505#Const SK_ColorCYAN 0xFF00FFFF
506#Line # cyan Color ##
507 Represents fully opaque cyan. HTML_Aqua is equivalent.
508##
509#Const SK_ColorMAGENTA 0xFFFF00FF
510#Line # magenta Color ##
511 Represents fully opaque magenta. HTML_Fuchsia is equivalent.
512##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400513
514# ------------------------------------------------------------------------------
515
Cary Clark682c58d2018-05-16 07:07:07 -0400516#Subtopic Transparent
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400517
518#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400519#Image 3
Cary Clark682c58d2018-05-16 07:07:07 -0400520 std::vector<uint32_t> srcPixels;
521 constexpr int width = 256;
522 constexpr int height = 256;
523 srcPixels.resize(width * height);
524 SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(width, height);
525 SkPixmap pixmap(imageInfo, &srcPixels.front(), imageInfo.minRowBytes());
526 pixmap.erase(SK_ColorTRANSPARENT);
527 pixmap.erase(SK_ColorRED, { 24, 24, 192, 192 } );
528 pixmap.erase(SK_ColorTRANSPARENT, { 48, 48, 168, 168 } );
529 SkBitmap bitmap;
530 bitmap.installPixels(pixmap);
531 canvas->drawBitmap(bitmap, 0, 0);
532 canvas->drawBitmap(bitmap, 48, 48);
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400533##
534
Cary Clark682c58d2018-05-16 07:07:07 -0400535#SeeAlso SK_AlphaTRANSPARENT SkCanvas::clear
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400536
Cary Clark682c58d2018-05-16 07:07:07 -0400537##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400538
539# ------------------------------------------------------------------------------
540
Cary Clark682c58d2018-05-16 07:07:07 -0400541#Subtopic Black
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400542
543#Example
Cary Clark682c58d2018-05-16 07:07:07 -0400544 std::vector<uint32_t> srcPixels;
545 constexpr int width = 256;
546 constexpr int height = 256;
547 srcPixels.resize(width * height);
548 SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(width, height);
549 SkPixmap pixmap(imageInfo, &srcPixels.front(), imageInfo.minRowBytes());
550 pixmap.erase(SK_ColorTRANSPARENT);
551 pixmap.erase(SK_ColorRED, { 24, 24, 192, 192 } );
552 pixmap.erase(SK_ColorBLACK, { 48, 48, 168, 168 } );
553 SkBitmap bitmap;
554 bitmap.installPixels(pixmap);
555 canvas->drawBitmap(bitmap, 0, 0);
556 canvas->drawBitmap(bitmap, 48, 48);
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400557##
558
Cary Clark682c58d2018-05-16 07:07:07 -0400559#SeeAlso SK_ColorTRANSPARENT
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400560
Cary Clark682c58d2018-05-16 07:07:07 -0400561##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400562
563# ------------------------------------------------------------------------------
564
Cary Clark682c58d2018-05-16 07:07:07 -0400565#Subtopic White
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400566
567#Example
Cary Clark682c58d2018-05-16 07:07:07 -0400568 std::vector<uint32_t> srcPixels;
569 constexpr int width = 256;
570 constexpr int height = 256;
571 srcPixels.resize(width * height);
572 SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(width, height);
573 SkPixmap pixmap(imageInfo, &srcPixels.front(), imageInfo.minRowBytes());
574 pixmap.erase(SK_ColorTRANSPARENT);
575 pixmap.erase(SK_ColorRED, { 24, 24, 192, 192 } );
576 pixmap.erase(SK_ColorWHITE, { 48, 48, 168, 168 } );
577 SkBitmap bitmap;
578 bitmap.installPixels(pixmap);
579 canvas->drawBitmap(bitmap, 0, 0);
580 canvas->drawBitmap(bitmap, 48, 48);
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400581##
582
Cary Clark682c58d2018-05-16 07:07:07 -0400583#SeeAlso SK_ColorTRANSPARENT
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400584
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400585##
586
Cary Clark682c58d2018-05-16 07:07:07 -0400587#Subtopic Color_Constants ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400588
589# ------------------------------------------------------------------------------
590
591#Subtopic HSV
Cary Clark61313f32018-10-08 14:57:48 -0400592#Line # hue saturation value color representation ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400593
594#Subtopic Hue
595Hue represents an angle, in degrees, on a color wheel. Hue has a positive value
596modulo 360, where zero degrees is red.
597##
598
599#Subtopic Saturation
Cary Clark0d225392018-06-07 09:59:07 -0400600Saturation represents the intensity of the color. Saturation varies from zero,
601with no Hue contribution; to one, with full Hue contribution.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400602##
603
604#Subtopic Value
Cary Clark0d225392018-06-07 09:59:07 -0400605Value represents the lightness of the color. Value varies from zero, black; to
606one, full brightness.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400607##
608
Cary Clarkffb3d682018-05-17 12:17:28 -0400609#Method void SkRGBToHSV(U8CPU red, U8CPU green, U8CPU blue, SkScalar hsv[3])
Cary Clark61313f32018-10-08 14:57:48 -0400610#In Functions
Cary Clarkffb3d682018-05-17 12:17:28 -0400611#Line # converts RGB to HSV ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400612
Cary Clarkffb3d682018-05-17 12:17:28 -0400613Converts RGB to its HSV components.
Cary Clark0d225392018-06-07 09:59:07 -0400614hsv[0] contains HSV_Hue, a value from zero to less than 360.
615hsv[1] contains HSV_Saturation, a value from zero to one.
616hsv[2] contains HSV_Value, a value from zero to one.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400617
Cary Clark682c58d2018-05-16 07:07:07 -0400618#Param red red component value from zero to 255 ##
619#Param green green component value from zero to 255 ##
620#Param blue blue component value from zero to 255 ##
621#Param hsv three element array which holds the resulting HSV components
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400622##
623
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400624#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400625#Image 3
Cary Clark61313f32018-10-08 14:57:48 -0400626 canvas->drawBitmap(source, 0, 0);
627 SkPaint bgPaint;
628 bgPaint.setColor(0xafffffff);
629 canvas->drawRect({20, 30, 110, 90}, bgPaint);
630 SkScalar hsv[3];
631 SkColor c = source.getColor(226, 128);
632 SkRGBToHSV(SkColorGetR(c), SkColorGetG(c), SkColorGetB(c), hsv);
633 canvas->drawString(("h: " + std::to_string(hsv[0]).substr(0, 6)).c_str(), 27, 45, SkPaint());
634 canvas->drawString(("s: " + std::to_string(hsv[1]).substr(0, 6)).c_str(), 27, 65, SkPaint());
635 canvas->drawString(("v: " + std::to_string(hsv[2]).substr(0, 6)).c_str(), 27, 85, SkPaint());
636 canvas->drawLine(110, 90, 226, 128, SkPaint());
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400637##
638
Cary Clarkffb3d682018-05-17 12:17:28 -0400639#SeeAlso SkColorToHSV SkHSVToColor
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400640
641#Method ##
642
643# ------------------------------------------------------------------------------
644
Cary Clarkffb3d682018-05-17 12:17:28 -0400645#Method void SkColorToHSV(SkColor color, SkScalar hsv[3])
Cary Clark61313f32018-10-08 14:57:48 -0400646#In Functions
Cary Clark682c58d2018-05-16 07:07:07 -0400647#Line # converts RGB to HSV ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400648
Cary Clark682c58d2018-05-16 07:07:07 -0400649Converts ARGB to its HSV components. Alpha in ARGB is ignored.
Cary Clark0d225392018-06-07 09:59:07 -0400650hsv[0] contains HSV_Hue, and is assigned a value from zero to less than 360.
651hsv[1] contains HSV_Saturation, a value from zero to one.
652hsv[2] contains HSV_Value, a value from zero to one.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400653
Cary Clark682c58d2018-05-16 07:07:07 -0400654#Param color ARGB color to convert
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400655##
Cary Clark682c58d2018-05-16 07:07:07 -0400656#Param hsv three element array which holds the resulting HSV components
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400657##
658
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400659#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400660#Image 3
Cary Clark61313f32018-10-08 14:57:48 -0400661 canvas->drawBitmap(source, 0, 0);
662 for (int y = 0; y < 256; ++y) {
663 for (int x = 0; x < 256; ++x) {
664 SkScalar hsv[3];
665 SkColorToHSV(source.getColor(x, y), hsv);
666 hsv[1] = 1 - hsv[1];
667 SkPaint paint;
668 paint.setColor(SkHSVToColor(hsv));
669 canvas->drawRect(SkRect::MakeXYWH(x, y, 1, 1), paint);
670 }
671 }
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400672##
673
Cary Clarkffb3d682018-05-17 12:17:28 -0400674#SeeAlso SkRGBToHSV SkHSVToColor
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400675
676#Method ##
677
678# ------------------------------------------------------------------------------
679
Cary Clarkffb3d682018-05-17 12:17:28 -0400680#Method SkColor SkHSVToColor(U8CPU alpha, const SkScalar hsv[3])
Cary Clark61313f32018-10-08 14:57:48 -0400681#In Functions
Cary Clark682c58d2018-05-16 07:07:07 -0400682#Line # converts HSV with Alpha to RGB ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400683
Cary Clarkffb3d682018-05-17 12:17:28 -0400684Converts HSV components to an ARGB color. Alpha is passed through unchanged.
Cary Clark0d225392018-06-07 09:59:07 -0400685hsv[0] represents HSV_Hue, an angle from zero to less than 360.
686hsv[1] represents HSV_Saturation, and varies from zero to one.
687hsv[2] represents HSV_Value, and varies from zero to one.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400688
Cary Clarkffb3d682018-05-17 12:17:28 -0400689Out of range hsv values are pinned.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400690
Cary Clark682c58d2018-05-16 07:07:07 -0400691#Param alpha Alpha component of the returned ARGB color
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400692##
Cary Clark682c58d2018-05-16 07:07:07 -0400693#Param hsv three element array which holds the input HSV components
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400694##
695
Cary Clark682c58d2018-05-16 07:07:07 -0400696#Return ARGB equivalent to HSV
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400697##
698
699#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400700#Image 3
Cary Clark61313f32018-10-08 14:57:48 -0400701 canvas->drawBitmap(source, 0, 0);
702 for (int y = 0; y < 256; ++y) {
703 for (int x = 0; x < 256; ++x) {
704 SkColor color = source.getColor(x, y);
705 SkScalar hsv[3];
706 SkColorToHSV(color, hsv);
707 hsv[0] = hsv[0] + 90 >= 360 ? hsv[0] - 270 : hsv[0] + 90;
708 SkPaint paint;
709 paint.setColor(SkHSVToColor(x + y, hsv));
710 canvas->drawRect(SkRect::MakeXYWH(x, y, 1, 1), paint);
711 }
712 }
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400713##
714
Cary Clarkffb3d682018-05-17 12:17:28 -0400715#SeeAlso SkColorToHSV SkRGBToHSV
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400716
717#Method ##
718
719# ------------------------------------------------------------------------------
720
Cary Clarkffb3d682018-05-17 12:17:28 -0400721#Method SkColor SkHSVToColor(const SkScalar hsv[3])
Cary Clark61313f32018-10-08 14:57:48 -0400722#In Functions
Cary Clarkffb3d682018-05-17 12:17:28 -0400723#Line # converts HSV to RGB ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400724
Cary Clark0d225392018-06-07 09:59:07 -0400725Converts HSV components to an ARGB color. Alpha is set to 255.
726hsv[0] represents HSV_Hue, an angle from zero to less than 360.
727hsv[1] represents HSV_Saturation, and varies from zero to one.
728hsv[2] represents HSV_Value, and varies from zero to one.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400729
Cary Clarkffb3d682018-05-17 12:17:28 -0400730Out of range hsv values are pinned.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400731
Cary Clarkffb3d682018-05-17 12:17:28 -0400732#Param hsv three element array which holds the input HSV components
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400733##
734
Cary Clarkffb3d682018-05-17 12:17:28 -0400735#Return RGB equivalent to HSV
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400736##
737
738#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400739#Image 3
Cary Clark61313f32018-10-08 14:57:48 -0400740 canvas->drawBitmap(source, 0, 0);
741 for (int y = 0; y < 256; ++y) {
742 for (int x = 0; x < 256; ++x) {
743 SkColor color = source.getColor(x, y);
744 SkScalar hsv[3];
745 SkColorToHSV(color, hsv);
746 hsv[0] = hsv[0] + 90 >= 360 ? hsv[0] - 270 : hsv[0] + 90;
747 SkPaint paint;
748 paint.setColor(SkHSVToColor(hsv));
749 canvas->drawRect(SkRect::MakeXYWH(x, y, 1, 1), paint);
750 }
751 }
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400752##
753
Cary Clarkffb3d682018-05-17 12:17:28 -0400754#SeeAlso SkColorToHSV SkRGBToHSV
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400755
756#Method ##
757
758#Subtopic HSV ##
759
760# ------------------------------------------------------------------------------
761
Cary Clark682c58d2018-05-16 07:07:07 -0400762#Subtopic PMColor
Cary Clark61313f32018-10-08 14:57:48 -0400763#Line # color components premultiplied by Alpha ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400764
Cary Clark682c58d2018-05-16 07:07:07 -0400765#Typedef uint32_t SkPMColor
766#Line # defines Premultiplied Color as 32 bits ##
767
Cary Clarkffb3d682018-05-17 12:17:28 -0400768#Code
769typedef uint32_t SkPMColor;
770##
771
Cary Clark682c58d2018-05-16 07:07:07 -040077232-bit ARGB color value, Premultiplied. The byte order for this value is
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400773configuration dependent, matching the format of kBGRA_8888_SkColorType bitmaps.
Cary Clark682c58d2018-05-16 07:07:07 -0400774This is different from SkColor, which is Unpremultiplied, and is always in the
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400775same byte order.
776
777#Typedef ##
778
779# ------------------------------------------------------------------------------
780
Cary Clarkffb3d682018-05-17 12:17:28 -0400781#Method SkPMColor SkPreMultiplyARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Cary Clark61313f32018-10-08 14:57:48 -0400782#In Functions
Cary Clark682c58d2018-05-16 07:07:07 -0400783#Line # converts Unpremultiplied ARGB to Premultiplied PMColor ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400784
Cary Clarkffb3d682018-05-17 12:17:28 -0400785Returns a SkPMColor value from Unpremultiplied 8-bit component values.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400786
Cary Clarkffb3d682018-05-17 12:17:28 -0400787#Param a amount of Alpha, from fully transparent (0) to fully opaque (255) ##
788#Param r amount of red, from no red (0) to full red (255) ##
789#Param g amount of green, from no green (0) to full green (255) ##
790#Param b amount of blue, from no blue (0) to full blue (255) ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400791
Cary Clarkffb3d682018-05-17 12:17:28 -0400792#Return Premultiplied Color ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400793
794#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400795#Height 128
796#Width 300
Cary Clark61313f32018-10-08 14:57:48 -0400797 SkPMColor premultiplied = SkPreMultiplyARGB(160, 128, 160, 192);
798 canvas->drawString("Unpremultiplied:", 20, 20, SkPaint());
799 canvas->drawString("alpha=160 red=128 green=160 blue=192", 20, 40, SkPaint());
800 canvas->drawString("Premultiplied:", 20, 80, SkPaint());
801 std::string str = "alpha=" + std::to_string(SkColorGetA(premultiplied));
802 str += " red=" + std::to_string(SkColorGetR(premultiplied));
803 str += " green=" + std::to_string(SkColorGetG(premultiplied));
804 str += " blue=" + std::to_string(SkColorGetB(premultiplied));
Cary Clarkffb3d682018-05-17 12:17:28 -0400805 canvas->drawString(str.c_str(), 20, 100, SkPaint());
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400806##
807
Cary Clarkffb3d682018-05-17 12:17:28 -0400808#SeeAlso SkPreMultiplyColor
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400809
810#Method ##
811
812# ------------------------------------------------------------------------------
813
Cary Clarkffb3d682018-05-17 12:17:28 -0400814#Method SkPMColor SkPreMultiplyColor(SkColor c)
Cary Clark61313f32018-10-08 14:57:48 -0400815#In Functions
Cary Clark682c58d2018-05-16 07:07:07 -0400816#Line # converts Unpremultiplied Color to Premultiplied PMColor ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400817
Cary Clark682c58d2018-05-16 07:07:07 -0400818Returns PMColor closest to Color c. Multiplies c RGB components by the c Alpha,
819and arranges the bytes to match the format of kN32_SkColorType.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400820
Cary Clarkffb3d682018-05-17 12:17:28 -0400821#Param c Unpremultiplied ARGB Color ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400822
Cary Clarkffb3d682018-05-17 12:17:28 -0400823#Return Premultiplied Color ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400824
825#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400826#Height 128
827#Width 300
Cary Clark61313f32018-10-08 14:57:48 -0400828 SkColor unpremultiplied = SkColorSetARGB(160, 128, 160, 192);
829 SkPMColor premultiplied = SkPreMultiplyColor(unpremultiplied);
830 canvas->drawString("Unpremultiplied:", 20, 20, SkPaint());
831 std::string str = "alpha=" + std::to_string(SkColorGetA(unpremultiplied));
832 str += " red=" + std::to_string(SkColorGetR(unpremultiplied));
833 str += " green=" + std::to_string(SkColorGetG(unpremultiplied));
834 str += " blue=" + std::to_string(SkColorGetB(unpremultiplied));
835 canvas->drawString(str.c_str(), 20, 40, SkPaint());
836 canvas->drawString("Premultiplied:", 20, 80, SkPaint());
837 str = "alpha=" + std::to_string(SkColorGetA(premultiplied));
838 str += " red=" + std::to_string(SkColorGetR(premultiplied));
839 str += " green=" + std::to_string(SkColorGetG(premultiplied));
840 str += " blue=" + std::to_string(SkColorGetB(premultiplied));
Cary Clarkffb3d682018-05-17 12:17:28 -0400841 canvas->drawString(str.c_str(), 20, 100, SkPaint());
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400842##
843
Cary Clarkffb3d682018-05-17 12:17:28 -0400844#SeeAlso SkPreMultiplyARGB
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400845
846#Method ##
847
Cary Clark682c58d2018-05-16 07:07:07 -0400848#Subtopic PMColor ##
849
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400850#Topic Color ##