blob: cc6f10c4f1d845b0fb467c9caeb167690453d0a5 [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 Clark0d225392018-06-07 09:59:07 -04004#File
5Types, consts, functions, and macros for colors.
6##
7
Cary Clark2d4bf5f2018-04-16 08:37:38 -04008#Subtopic Overview
Cary Clark682c58d2018-05-16 07:07:07 -04009#Populate
Cary Clark2d4bf5f2018-04-16 08:37:38 -040010##
11
12#Subtopic Define
13#Populate
14##
15
Cary Clark682c58d2018-05-16 07:07:07 -040016Color constants can be helpful to write code, documenting the meaning of values
17the represent transparency and color values. The use of Color constants is not
18required.
19
20#Subtopic Constant
21#Populate
22##
23
Cary Clark2d4bf5f2018-04-16 08:37:38 -040024#Subtopic Function
25#Populate
26##
27
28#Subtopic Typedef
29#Populate
30##
31
Cary Clark2d4bf5f2018-04-16 08:37:38 -040032# ------------------------------------------------------------------------------
33
Cary Clark682c58d2018-05-16 07:07:07 -040034#Subtopic Alpha
Cary Clark2d4bf5f2018-04-16 08:37:38 -040035
Cary Clark682c58d2018-05-16 07:07:07 -040036Alpha represents the transparency of Color. Color with Alpha of zero is fully
37transparent. Color with Alpha of 255 is fully opaque. Some, but not all pixel
38formats contain Alpha. Pixels with Alpha may store it as unsigned integers or
39floating point values. Unsigned integer Alpha ranges from zero, fully
40transparent, to all bits set, fully opaque. Floating point Alpha ranges from
41zero, fully transparent, to one, fully opaque.
42
Cary Clark137b8742018-05-30 09:21:49 -040043#Alias Alpha
44#Substitute alpha
45##
Cary Clark682c58d2018-05-16 07:07:07 -040046
47#Typedef uint8_t SkAlpha
48#Line # defines Alpha as eight bits ##
49
Cary Clarkffb3d682018-05-17 12:17:28 -040050#Code
51typedef uint8_t SkAlpha;
52##
53
Cary Clark0d225392018-06-07 09:59:07 -0400548-bit type for an alpha value. 255 is 100% opaque, zero is 100% transparent.
Cary Clark2d4bf5f2018-04-16 08:37:38 -040055
56#Typedef ##
57
Cary Clark682c58d2018-05-16 07:07:07 -040058#Subtopic ##
59
Cary Clark2d4bf5f2018-04-16 08:37:38 -040060# ------------------------------------------------------------------------------
61
62#Typedef uint32_t SkColor
Cary Clark682c58d2018-05-16 07:07:07 -040063#Line # defines Color as 32 bits ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -040064
Cary Clarkffb3d682018-05-17 12:17:28 -040065#Code
66typedef uint32_t SkColor;
67##
68
Cary Clark682c58d2018-05-16 07:07:07 -04006932-bit ARGB Color value, Unpremultiplied. Color components are always in
Cary Clark2d4bf5f2018-04-16 08:37:38 -040070a known order. This is different from SkPMColor, which has its bytes in a configuration
71dependent order, to match the format of kBGRA_8888_SkColorType bitmaps. SkColor
72is the type used to specify colors in SkPaint and in gradients.
73
Cary Clark682c58d2018-05-16 07:07:07 -040074Color that is Premultiplied has the same component values as Color
75that is Unpremultiplied if Alpha is 255, fully opaque, although may have the
76component values in a different order.
77
78#SeeAlso SkPMColor
79
Cary Clark2d4bf5f2018-04-16 08:37:38 -040080#Typedef ##
81
82# ------------------------------------------------------------------------------
83
84#Method static constexpr inline SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
85#In Function
Cary Clarkffb3d682018-05-17 12:17:28 -040086#Line # returns Color_Alpha and RGB combined ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -040087
Cary Clark682c58d2018-05-16 07:07:07 -040088Returns Color value from 8-bit component values. Asserts if SK_DEBUG is defined
89if a, r, g, or b exceed 255. Since Color is Unpremultiplied, a may be smaller
90than the largest of r, g, and b.
Cary Clark2d4bf5f2018-04-16 08:37:38 -040091
Cary Clark682c58d2018-05-16 07:07:07 -040092#Param a amount of Alpha, from fully transparent (0) to fully opaque (255) ##
Cary Clarkffb3d682018-05-17 12:17:28 -040093#Param r amount of red, from no red (0) to full red (255) ##
94#Param g amount of green, from no green (0) to full green (255) ##
95#Param b amount of blue, from no blue (0) to full blue (255) ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -040096
Cary Clark682c58d2018-05-16 07:07:07 -040097#Return color and alpha, Unpremultiplied ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -040098
99#Example
Cary Clark682c58d2018-05-16 07:07:07 -0400100 canvas->drawColor(SK_ColorRED);
101 canvas->clipRect(SkRect::MakeWH(150, 150));
102 canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0xFF, 0x00));
103 canvas->clipRect(SkRect::MakeWH(75, 75));
104 canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0x00, 0xFF));
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400105##
106
Cary Clarkffb3d682018-05-17 12:17:28 -0400107#SeeAlso SkColorSetRGB SkPaint::setARGB SkPaint::setColor SkColorSetA
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400108
109#Method ##
110
111# ------------------------------------------------------------------------------
112
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400113#Define SkColorSetRGB
Cary Clark682c58d2018-05-16 07:07:07 -0400114#Line # returns opaque Color ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400115
116#Code
117###$
118 #define SkColorSetRGB(r, g, b) SkColorSetARGB(0xFF, r, g, b)
119$$$#
120##
121
Cary Clark682c58d2018-05-16 07:07:07 -0400122Returns Color value from 8-bit component values, with Alpha set
123fully opaque to 255.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400124
Cary Clarkffb3d682018-05-17 12:17:28 -0400125#Param r amount of red, from no red (0) to full red (255) ##
126#Param g amount of green, from no green (0) to full green (255) ##
127#Param b amount of blue, from no blue (0) to full blue (255) ##
Cary Clark682c58d2018-05-16 07:07:07 -0400128
129#Return color with opaque alpha ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400130
131#Example
Cary Clark682c58d2018-05-16 07:07:07 -0400132 canvas->drawColor(SK_ColorRED);
133 canvas->clipRect(SkRect::MakeWH(150, 150));
134 canvas->drawColor(SkColorSetRGB(0x00, 0xFF, 0x00));
135 canvas->clipRect(SkRect::MakeWH(75, 75));
136 canvas->drawColor(SkColorSetRGB(0x00, 0x00, 0xFF));
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400137##
138
Cary Clarkffb3d682018-05-17 12:17:28 -0400139#SeeAlso SkColorSetARGB
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400140
141#Define ##
142
143# ------------------------------------------------------------------------------
144
145#Define SkColorGetA
Cary Clark682c58d2018-05-16 07:07:07 -0400146#Line # returns Alpha component ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400147
148#Code
149###$
150 #define SkColorGetA(color) (((color) >> 24) & 0xFF)
151$$$#
152##
153
Cary Clark682c58d2018-05-16 07:07:07 -0400154Returns Alpha byte from Color value.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400155
Cary Clark682c58d2018-05-16 07:07:07 -0400156#Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400157
158#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400159 SkPaint paint;
160 paint.setAntiAlias(true);
161 paint.setColor(SK_ColorRED);
162 for (int alpha = 255; alpha >= 0; alpha -= 17) {
163 paint.setAlpha(alpha);
164 canvas->drawRect({5, 5, 100, 20}, paint);
165 SkAlpha alphaInPaint = SkColorGetA(paint.getColor());
166 canvas->drawString(std::to_string(alphaInPaint).c_str(), 110, 18, paint);
167 canvas->translate(0, 15);
168 }
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400169##
170
Cary Clarkffb3d682018-05-17 12:17:28 -0400171#SeeAlso SkPaint::getAlpha
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400172
173#Define ##
174
175# ------------------------------------------------------------------------------
176
177#Define SkColorGetR
Cary Clarkffb3d682018-05-17 12:17:28 -0400178#Line # returns red component ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400179
180#Code
181###$
182 #define SkColorGetR(color) (((color) >> 16) & 0xFF)
183$$$#
184##
185
Cary Clark682c58d2018-05-16 07:07:07 -0400186Returns red component of Color, from zero to 255.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400187
Cary Clark682c58d2018-05-16 07:07:07 -0400188#Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
189#Return red byte ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400190
191#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400192#Image 3
193 canvas->drawBitmap(source, 0, 0);
194 SkPaint bgPaint;
195 bgPaint.setColor(0xafffffff);
196 canvas->drawRect({20, 50, 80, 70}, bgPaint);
197 uint8_t red = SkColorGetR(source.getColor(226, 128));
198 canvas->drawString(std::to_string(red).c_str(), 40, 65, SkPaint());
199 canvas->drawLine(80, 70, 226, 128, SkPaint());
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400200##
201
Cary Clarkffb3d682018-05-17 12:17:28 -0400202#SeeAlso SkColorGetG SkColorGetB
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400203
204#Define ##
205
206# ------------------------------------------------------------------------------
207
208#Define SkColorGetG
Cary Clarkffb3d682018-05-17 12:17:28 -0400209#Line # returns green component ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400210
211#Code
212###$
213 #define SkColorGetG(color) (((color) >> 8) & 0xFF)
214$$$#
215##
216
Cary Clark682c58d2018-05-16 07:07:07 -0400217Returns green component of Color, from zero to 255.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400218
Cary Clark682c58d2018-05-16 07:07:07 -0400219#Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
220#Return green byte ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400221
222#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400223#Image 3
224 canvas->drawBitmap(source, 0, 0);
225 SkPaint bgPaint;
226 bgPaint.setColor(0xafffffff);
227 canvas->drawRect({20, 50, 80, 70}, bgPaint);
228 uint8_t green = SkColorGetG(source.getColor(57, 192));
229 canvas->drawString(std::to_string(green).c_str(), 40, 65, SkPaint());
230 canvas->drawLine(80, 70, 57, 192, SkPaint());
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400231##
232
Cary Clarkffb3d682018-05-17 12:17:28 -0400233#SeeAlso SkColorGetR SkColorGetB
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400234
235#Define ##
236
237# ------------------------------------------------------------------------------
238
239#Define SkColorGetB
Cary Clarkffb3d682018-05-17 12:17:28 -0400240#Line # returns blue component ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400241
242#Code
243###$
244 #define SkColorGetB(color) (((color) >> 0) & 0xFF)
245$$$#
246##
247
Cary Clark682c58d2018-05-16 07:07:07 -0400248Returns blue component of Color, from zero to 255.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400249
Cary Clark682c58d2018-05-16 07:07:07 -0400250#Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
251#Return blue byte ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400252
253#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400254#Image 3
255 canvas->drawBitmap(source, 0, 0);
256 SkPaint bgPaint;
257 bgPaint.setColor(0xafffffff);
258 canvas->drawRect({20, 50, 80, 70}, bgPaint);
259 uint8_t blue = SkColorGetB(source.getColor(168, 170));
260 canvas->drawString(std::to_string(blue).c_str(), 40, 65, SkPaint());
261 canvas->drawLine(80, 70, 168, 170, SkPaint());
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400262##
263
Cary Clarkffb3d682018-05-17 12:17:28 -0400264#SeeAlso SkColorGetR SkColorGetG
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400265
266#Define ##
267
268# ------------------------------------------------------------------------------
269
270#Method static constexpr inline SkColor SkColorSetA(SkColor c, U8CPU a)
271#In Function
Cary Clarkffb3d682018-05-17 12:17:28 -0400272#Line # returns Color with transparency ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400273
Cary Clarkffb3d682018-05-17 12:17:28 -0400274Returns Unpremultiplied Color with red, blue, and green set from c; and alpha set
275from a. Alpha component of c is ignored and is replaced by a in result.
Cary Clark682c58d2018-05-16 07:07:07 -0400276
Cary Clarkffb3d682018-05-17 12:17:28 -0400277#Param c packed RGB, eight bits per component ##
278#Param a Alpha: transparent at zero, fully opaque at 255 ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400279
Cary Clarkffb3d682018-05-17 12:17:28 -0400280#Return Color with transparency ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400281
282#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400283#Image 3
284 canvas->drawBitmap(source, 0, 0);
285 for (int y = 0; y < 256; y += 16) {
286 for (int x = 0; x < 256; x += 16) {
287 SkColor color = source.getColor(x + 8, y + 8);
288 SkPaint paint;
289 paint.setColor(SkColorSetA(color, x + y));
290 canvas->drawRect(SkRect::MakeXYWH(x, y, 16, 16), paint);
291 }
292 }
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400293##
294
Cary Clarkffb3d682018-05-17 12:17:28 -0400295#SeeAlso SkColorSetARGB
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400296
297#Method ##
298
299# ------------------------------------------------------------------------------
300
Cary Clark682c58d2018-05-16 07:07:07 -0400301#Subtopic Alpha_Constants
302#In Constant
303#Line # constants for Alpha ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400304
305#Code
Cary Clark682c58d2018-05-16 07:07:07 -0400306 constexpr SkAlpha SK_AlphaTRANSPARENT = 0x00;
307 constexpr SkAlpha SK_AlphaOPAQUE = 0xFF;
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400308##
309
Cary Clark682c58d2018-05-16 07:07:07 -0400310Alpha constants are conveniences to represent fully transparent and fully
311opaque colors and masks. Their use is not required.
312
313#Const SK_AlphaTRANSPARENT 0x00
314#Line # fully transparent SkAlpha ##
315#Details Transparent
316Represents fully transparent SkAlpha value. SkAlpha ranges from zero,
317fully transparent; to 255, fully opaque.
318##
319#Const SK_AlphaOPAQUE 0xFF
320#Line # fully opaque SkAlpha ##
321#Details Opaque
322Represents fully opaque SkAlpha value. SkAlpha ranges from zero,
323fully transparent; to 255, fully opaque.
324##
325
326#Subtopic Transparent
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400327
328#Example
Cary Clark682c58d2018-05-16 07:07:07 -0400329#Image 1
330#Height 128
331#Description
332Color the parts of the bitmap red if they mostly contain transparent pixels.
333##
334 std::vector<int32_t> srcPixels;
335 srcPixels.resize(source.height() * source.rowBytes());
336 SkPixmap pixmap(SkImageInfo::MakeN32Premul(source.width(), source.height()),
337 &srcPixels.front(), source.rowBytes());
338 source.readPixels(pixmap, 0, 0);
339 for (int y = 0; y < 16; ++y) {
340 for (int x = 0; x < 16; ++x) {
341 int32_t* blockStart = &srcPixels.front() + y * source.width() * 16 + x * 16;
342 size_t transparentCount = 0;
343 for (int fillY = 0; fillY < source.height() / 16; ++fillY) {
344 for (int fillX = 0; fillX < source.width() / 16; ++fillX) {
345 const SkColor color = SkUnPreMultiply::PMColorToColor(blockStart[fillX]);
346 transparentCount += SkColorGetA(color) == SK_AlphaTRANSPARENT;
347 }
348 blockStart += source.width();
349 }
350 if (transparentCount > 200) {
351 blockStart = &srcPixels.front() + y * source.width() * 16 + x * 16;
352 for (int fillY = 0; fillY < source.height() / 16; ++fillY) {
353 for (int fillX = 0; fillX < source.width() / 16; ++fillX) {
354 blockStart[fillX] = SK_ColorRED;
355 }
356 blockStart += source.width();
357 }
358 }
359 }
360 }
361 SkBitmap bitmap;
362 bitmap.installPixels(pixmap);
363 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400364##
365
Cary Clark682c58d2018-05-16 07:07:07 -0400366#SeeAlso SkAlpha SK_ColorTRANSPARENT SK_AlphaOPAQUE
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400367
Cary Clark682c58d2018-05-16 07:07:07 -0400368#Subtopic Transparent ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400369
370# ------------------------------------------------------------------------------
371
Cary Clark682c58d2018-05-16 07:07:07 -0400372#Subtopic Opaque
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400373
374#Example
Cary Clark682c58d2018-05-16 07:07:07 -0400375#Image 1
376#Height 128
377 std::vector<int32_t> srcPixels;
378 srcPixels.resize(source.height() * source.rowBytes());
379 SkPixmap pixmap(SkImageInfo::MakeN32Premul(source.width(), source.height()),
380 &srcPixels.front(), source.rowBytes());
381 source.readPixels(pixmap, 0, 0);
382 for (int y = 0; y < source.height(); ++y) {
383 for (int x = 0; x < source.width(); ++x) {
384 SkPMColor pixel = srcPixels[y * source.width() + x];
385 const SkColor color = SkUnPreMultiply::PMColorToColor(pixel);
386 if (SkColorGetA(color) == SK_AlphaOPAQUE) {
387 srcPixels[y * source.width() + x] = SK_ColorGREEN;
388 }
389 }
390 }
391 SkBitmap bitmap;
392 bitmap.installPixels(pixmap);
393 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400394##
395
Cary Clark682c58d2018-05-16 07:07:07 -0400396#SeeAlso SkAlpha SK_AlphaTRANSPARENT
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400397
Cary Clark682c58d2018-05-16 07:07:07 -0400398#Subtopic Opaque ##
399#Subtopic Alpha_Constants ##
400
401#Subtopic Color_Constants
402#In Constant
403#Line # constants for Color ##
404
405# ------------------------------------------------------------------------------
406#Code
407 constexpr SkColor SK_ColorTRANSPARENT = SkColorSetARGB(0x00, 0x00, 0x00, 0x00);
408 constexpr SkColor SK_ColorBLACK = SkColorSetARGB(0xFF, 0x00, 0x00, 0x00);
409 constexpr SkColor SK_ColorDKGRAY = SkColorSetARGB(0xFF, 0x44, 0x44, 0x44);
410 constexpr SkColor SK_ColorGRAY = SkColorSetARGB(0xFF, 0x88, 0x88, 0x88);
411 constexpr SkColor SK_ColorLTGRAY = SkColorSetARGB(0xFF, 0xCC, 0xCC, 0xCC);
412 constexpr SkColor SK_ColorWHITE = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF);
413 constexpr SkColor SK_ColorRED = SkColorSetARGB(0xFF, 0xFF, 0x00, 0x00);
414 constexpr SkColor SK_ColorGREEN = SkColorSetARGB(0xFF, 0x00, 0xFF, 0x00);
415 constexpr SkColor SK_ColorBLUE = SkColorSetARGB(0xFF, 0x00, 0x00, 0xFF);
416 constexpr SkColor SK_ColorYELLOW = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0x00);
417 constexpr SkColor SK_ColorCYAN = SkColorSetARGB(0xFF, 0x00, 0xFF, 0xFF);
418 constexpr SkColor SK_ColorMAGENTA = SkColorSetARGB(0xFF, 0xFF, 0x00, 0xFF);
419##
420
421Color names are provided as conveniences, but are not otherwise special.
422The values chosen for names may not be the same as values used by
423SVG, HTML, CSS, or colors named by a platform.
424
425#Example
426###$
427$Function
428#define SKIA_COLOR_PAIR(name) "SK_Color" #name, SK_Color##name
429$$
430void draw(SkCanvas* canvas) {
431 struct ColorCompare {
432 const char* fSVGName;
433 SkColor fSVGColor;
434 const char* fSkiaName;
435 SkColor fSkiaColor;
436 } colorCompare[] = { // see https://www.w3.org/TR/SVG/types.html#ColorKeywords
437 {"black", SkColorSetRGB( 0, 0, 0), SKIA_COLOR_PAIR(BLACK) },
438 {"darkgray", SkColorSetRGB(169, 169, 169), SKIA_COLOR_PAIR(DKGRAY) },
439 {"gray", SkColorSetRGB(128, 128, 128), SKIA_COLOR_PAIR(GRAY) },
440 {"lightgray", SkColorSetRGB(211, 211, 211), SKIA_COLOR_PAIR(LTGRAY) },
441 {"white", SkColorSetRGB(255, 255, 255), SKIA_COLOR_PAIR(WHITE) },
442 {"red", SkColorSetRGB(255, 0, 0), SKIA_COLOR_PAIR(RED) },
443 {"green", SkColorSetRGB( 0, 128, 0), SKIA_COLOR_PAIR(GREEN) },
444 {"blue", SkColorSetRGB( 0, 0, 255), SKIA_COLOR_PAIR(BLUE) },
445 {"yellow", SkColorSetRGB(255, 255, 0), SKIA_COLOR_PAIR(YELLOW) },
446 {"aqua", SkColorSetRGB( 0, 255, 255), SKIA_COLOR_PAIR(CYAN) },
447 {"fuchsia", SkColorSetRGB(255, 0, 255), SKIA_COLOR_PAIR(MAGENTA) },
448 };
449 SkPaint paint;
450 paint.setAntiAlias(true);
451 paint.setTextSize(14);
452 for (auto compare : colorCompare) {
453 paint.setStyle(SkPaint::kFill_Style);
454 paint.setColor(compare.fSVGColor);
455 canvas->drawRect({5, 5, 15, 15}, paint);
456 paint.setColor(SK_ColorBLACK);
457 canvas->drawString(compare.fSVGName, 20, 16, paint);
458 paint.setColor(compare.fSkiaColor);
459 canvas->drawRect({105, 5, 115, 15}, paint);
460 paint.setColor(SK_ColorBLACK);
461 canvas->drawString(compare.fSkiaName, 120, 16, paint);
462 paint.setStyle(SkPaint::kStroke_Style);
463 canvas->drawRect({5, 5, 15, 15}, paint);
464 canvas->drawRect({105, 5, 115, 15}, paint);
465 canvas->translate(0, 20);
466 }
467}
468$$$#
469##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400470
471# ------------------------------------------------------------------------------
472
Cary Clark682c58d2018-05-16 07:07:07 -0400473#Const SK_ColorTRANSPARENT 0x00000000
474#Line # transparent Color ##
475#Details Transparent
476 Represents fully transparent SkColor. May be used to initialize a destination
477 containing a mask or a non-rectangular image.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400478##
Cary Clark682c58d2018-05-16 07:07:07 -0400479#Const SK_ColorBLACK 0xFF000000
480#Line # black Color ##
481#Details Black
482 Represents fully opaque black.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400483##
Cary Clark682c58d2018-05-16 07:07:07 -0400484#Const SK_ColorDKGRAY 0xFF444444
485#Line # dark gray Color ##
486 Represents fully opaque dark gray.
487 Note that SVG_darkgray is equivalent to 0xFFA9A9A9.
488##
489#Const SK_ColorGRAY 0xFF888888
490#Line # gray Color ##
491 Represents fully opaque gray.
492 Note that HTML_Gray is equivalent to 0xFF808080.
493##
494#Const SK_ColorLTGRAY 0xFFCCCCCC
495#Line # light gray Color ##
496 Represents fully opaque light gray. HTML_Silver is equivalent to 0xFFC0C0C0.
497 Note that SVG_lightgray is equivalent to 0xFFD3D3D3.
498##
499#Const SK_ColorWHITE 0xFFFFFFFF
500#Line # white Color ##
501 Represents fully opaque white.
502##
503#Const SK_ColorRED 0xFFFF0000
504#Line # red Color ##
505 Represents fully opaque red.
506##
507#Const SK_ColorGREEN 0xFF00FF00
508#Line # green Color ##
509 Represents fully opaque green. HTML_Lime is equivalent.
510 Note that HTML_Green is equivalent to 0xFF008000.
511##
512#Const SK_ColorBLUE 0xFF0000FF
513#Line # blue Color ##
514 Represents fully opaque blue.
515##
516#Const SK_ColorYELLOW 0xFFFFFF00
517#Line # yellow Color ##
518 Represents fully opaque yellow.
519##
520#Const SK_ColorCYAN 0xFF00FFFF
521#Line # cyan Color ##
522 Represents fully opaque cyan. HTML_Aqua is equivalent.
523##
524#Const SK_ColorMAGENTA 0xFFFF00FF
525#Line # magenta Color ##
526 Represents fully opaque magenta. HTML_Fuchsia is equivalent.
527##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400528
529# ------------------------------------------------------------------------------
530
Cary Clark682c58d2018-05-16 07:07:07 -0400531#Subtopic Transparent
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400532
533#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400534#Image 3
Cary Clark682c58d2018-05-16 07:07:07 -0400535 std::vector<uint32_t> srcPixels;
536 constexpr int width = 256;
537 constexpr int height = 256;
538 srcPixels.resize(width * height);
539 SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(width, height);
540 SkPixmap pixmap(imageInfo, &srcPixels.front(), imageInfo.minRowBytes());
541 pixmap.erase(SK_ColorTRANSPARENT);
542 pixmap.erase(SK_ColorRED, { 24, 24, 192, 192 } );
543 pixmap.erase(SK_ColorTRANSPARENT, { 48, 48, 168, 168 } );
544 SkBitmap bitmap;
545 bitmap.installPixels(pixmap);
546 canvas->drawBitmap(bitmap, 0, 0);
547 canvas->drawBitmap(bitmap, 48, 48);
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400548##
549
Cary Clark682c58d2018-05-16 07:07:07 -0400550#SeeAlso SK_AlphaTRANSPARENT SkCanvas::clear
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400551
Cary Clark682c58d2018-05-16 07:07:07 -0400552##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400553
554# ------------------------------------------------------------------------------
555
Cary Clark682c58d2018-05-16 07:07:07 -0400556#Subtopic Black
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400557
558#Example
Cary Clark682c58d2018-05-16 07:07:07 -0400559 std::vector<uint32_t> srcPixels;
560 constexpr int width = 256;
561 constexpr int height = 256;
562 srcPixels.resize(width * height);
563 SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(width, height);
564 SkPixmap pixmap(imageInfo, &srcPixels.front(), imageInfo.minRowBytes());
565 pixmap.erase(SK_ColorTRANSPARENT);
566 pixmap.erase(SK_ColorRED, { 24, 24, 192, 192 } );
567 pixmap.erase(SK_ColorBLACK, { 48, 48, 168, 168 } );
568 SkBitmap bitmap;
569 bitmap.installPixels(pixmap);
570 canvas->drawBitmap(bitmap, 0, 0);
571 canvas->drawBitmap(bitmap, 48, 48);
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400572##
573
Cary Clark682c58d2018-05-16 07:07:07 -0400574#SeeAlso SK_ColorTRANSPARENT
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400575
Cary Clark682c58d2018-05-16 07:07:07 -0400576##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400577
578# ------------------------------------------------------------------------------
579
Cary Clark682c58d2018-05-16 07:07:07 -0400580#Subtopic White
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400581
582#Example
Cary Clark682c58d2018-05-16 07:07:07 -0400583 std::vector<uint32_t> srcPixels;
584 constexpr int width = 256;
585 constexpr int height = 256;
586 srcPixels.resize(width * height);
587 SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(width, height);
588 SkPixmap pixmap(imageInfo, &srcPixels.front(), imageInfo.minRowBytes());
589 pixmap.erase(SK_ColorTRANSPARENT);
590 pixmap.erase(SK_ColorRED, { 24, 24, 192, 192 } );
591 pixmap.erase(SK_ColorWHITE, { 48, 48, 168, 168 } );
592 SkBitmap bitmap;
593 bitmap.installPixels(pixmap);
594 canvas->drawBitmap(bitmap, 0, 0);
595 canvas->drawBitmap(bitmap, 48, 48);
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400596##
597
Cary Clark682c58d2018-05-16 07:07:07 -0400598#SeeAlso SK_ColorTRANSPARENT
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400599
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400600##
601
Cary Clark682c58d2018-05-16 07:07:07 -0400602#Subtopic Color_Constants ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400603
604# ------------------------------------------------------------------------------
605
606#Subtopic HSV
607
608#Subtopic Hue
609Hue represents an angle, in degrees, on a color wheel. Hue has a positive value
610modulo 360, where zero degrees is red.
611##
612
613#Subtopic Saturation
Cary Clark0d225392018-06-07 09:59:07 -0400614Saturation represents the intensity of the color. Saturation varies from zero,
615with no Hue contribution; to one, with full Hue contribution.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400616##
617
618#Subtopic Value
Cary Clark0d225392018-06-07 09:59:07 -0400619Value represents the lightness of the color. Value varies from zero, black; to
620one, full brightness.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400621##
622
Cary Clarkffb3d682018-05-17 12:17:28 -0400623#Method void SkRGBToHSV(U8CPU red, U8CPU green, U8CPU blue, SkScalar hsv[3])
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400624#In Function
Cary Clarkffb3d682018-05-17 12:17:28 -0400625#Line # converts RGB to HSV ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400626
Cary Clarkffb3d682018-05-17 12:17:28 -0400627Converts RGB to its HSV components.
Cary Clark0d225392018-06-07 09:59:07 -0400628hsv[0] contains HSV_Hue, a value from zero to less than 360.
629hsv[1] contains HSV_Saturation, a value from zero to one.
630hsv[2] contains HSV_Value, a value from zero to one.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400631
Cary Clark682c58d2018-05-16 07:07:07 -0400632#Param red red component value from zero to 255 ##
633#Param green green component value from zero to 255 ##
634#Param blue blue component value from zero to 255 ##
635#Param hsv three element array which holds the resulting HSV components
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400636##
637
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400638#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400639#Image 3
640 canvas->drawBitmap(source, 0, 0);
641 SkPaint bgPaint;
642 bgPaint.setColor(0xafffffff);
643 canvas->drawRect({20, 30, 110, 90}, bgPaint);
644 SkScalar hsv[3];
645 SkColor c = source.getColor(226, 128);
646 SkRGBToHSV(SkColorGetR(c), SkColorGetG(c), SkColorGetB(c), hsv);
647 canvas->drawString(("h: " + std::to_string(hsv[0]).substr(0, 6)).c_str(), 27, 45, SkPaint());
648 canvas->drawString(("s: " + std::to_string(hsv[1]).substr(0, 6)).c_str(), 27, 65, SkPaint());
649 canvas->drawString(("v: " + std::to_string(hsv[2]).substr(0, 6)).c_str(), 27, 85, SkPaint());
650 canvas->drawLine(110, 90, 226, 128, SkPaint());
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400651##
652
Cary Clarkffb3d682018-05-17 12:17:28 -0400653#SeeAlso SkColorToHSV SkHSVToColor
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400654
655#Method ##
656
657# ------------------------------------------------------------------------------
658
Cary Clarkffb3d682018-05-17 12:17:28 -0400659#Method void SkColorToHSV(SkColor color, SkScalar hsv[3])
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400660#In Function
Cary Clark682c58d2018-05-16 07:07:07 -0400661#Line # converts RGB to HSV ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400662
Cary Clark682c58d2018-05-16 07:07:07 -0400663Converts ARGB to its HSV components. Alpha in ARGB is ignored.
Cary Clark0d225392018-06-07 09:59:07 -0400664hsv[0] contains HSV_Hue, and is assigned a value from zero to less than 360.
665hsv[1] contains HSV_Saturation, a value from zero to one.
666hsv[2] contains HSV_Value, a value from zero to one.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400667
Cary Clark682c58d2018-05-16 07:07:07 -0400668#Param color ARGB color to convert
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400669##
Cary Clark682c58d2018-05-16 07:07:07 -0400670#Param hsv three element array which holds the resulting HSV components
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400671##
672
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400673#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400674#Image 3
675 canvas->drawBitmap(source, 0, 0);
676 for (int y = 0; y < 256; ++y) {
677 for (int x = 0; x < 256; ++x) {
678 SkScalar hsv[3];
Cary Clark929e4362018-06-19 09:07:28 -0400679 SkColorToHSV(source.getColor(x, y), hsv);
Cary Clark4d759752018-06-19 12:57:43 -0400680 hsv[1] = 1 - hsv[1];
Cary Clarkffb3d682018-05-17 12:17:28 -0400681 SkPaint paint;
682 paint.setColor(SkHSVToColor(hsv));
683 canvas->drawRect(SkRect::MakeXYWH(x, y, 1, 1), paint);
684 }
685 }
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400686##
687
Cary Clarkffb3d682018-05-17 12:17:28 -0400688#SeeAlso SkRGBToHSV SkHSVToColor
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400689
690#Method ##
691
692# ------------------------------------------------------------------------------
693
Cary Clarkffb3d682018-05-17 12:17:28 -0400694#Method SkColor SkHSVToColor(U8CPU alpha, const SkScalar hsv[3])
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400695#In Function
Cary Clark682c58d2018-05-16 07:07:07 -0400696#Line # converts HSV with Alpha to RGB ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400697
Cary Clarkffb3d682018-05-17 12:17:28 -0400698Converts HSV components to an ARGB color. Alpha is passed through unchanged.
Cary Clark0d225392018-06-07 09:59:07 -0400699hsv[0] represents HSV_Hue, an angle from zero to less than 360.
700hsv[1] represents HSV_Saturation, and varies from zero to one.
701hsv[2] represents HSV_Value, and varies from zero to one.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400702
Cary Clarkffb3d682018-05-17 12:17:28 -0400703Out of range hsv values are pinned.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400704
Cary Clark682c58d2018-05-16 07:07:07 -0400705#Param alpha Alpha component of the returned ARGB color
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400706##
Cary Clark682c58d2018-05-16 07:07:07 -0400707#Param hsv three element array which holds the input HSV components
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400708##
709
Cary Clark682c58d2018-05-16 07:07:07 -0400710#Return ARGB equivalent to HSV
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400711##
712
713#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400714#Image 3
715 canvas->drawBitmap(source, 0, 0);
716 for (int y = 0; y < 256; ++y) {
717 for (int x = 0; x < 256; ++x) {
718 SkColor color = source.getColor(x, y);
719 SkScalar hsv[3];
720 SkColorToHSV(color, hsv);
721 hsv[0] = hsv[0] + 90 >= 360 ? hsv[0] - 270 : hsv[0] + 90;
722 SkPaint paint;
723 paint.setColor(SkHSVToColor(x + y, hsv));
724 canvas->drawRect(SkRect::MakeXYWH(x, y, 1, 1), paint);
725 }
726 }
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400727##
728
Cary Clarkffb3d682018-05-17 12:17:28 -0400729#SeeAlso SkColorToHSV SkRGBToHSV
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400730
731#Method ##
732
733# ------------------------------------------------------------------------------
734
Cary Clarkffb3d682018-05-17 12:17:28 -0400735#Method SkColor SkHSVToColor(const SkScalar hsv[3])
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400736#In Function
Cary Clarkffb3d682018-05-17 12:17:28 -0400737#Line # converts HSV to RGB ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400738
Cary Clark0d225392018-06-07 09:59:07 -0400739Converts HSV components to an ARGB color. Alpha is set to 255.
740hsv[0] represents HSV_Hue, an angle from zero to less than 360.
741hsv[1] represents HSV_Saturation, and varies from zero to one.
742hsv[2] represents HSV_Value, and varies from zero to one.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400743
Cary Clarkffb3d682018-05-17 12:17:28 -0400744Out of range hsv values are pinned.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400745
Cary Clarkffb3d682018-05-17 12:17:28 -0400746#Param hsv three element array which holds the input HSV components
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400747##
748
Cary Clarkffb3d682018-05-17 12:17:28 -0400749#Return RGB equivalent to HSV
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400750##
751
752#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400753#Image 3
754 canvas->drawBitmap(source, 0, 0);
755 for (int y = 0; y < 256; ++y) {
756 for (int x = 0; x < 256; ++x) {
757 SkColor color = source.getColor(x, y);
758 SkScalar hsv[3];
759 SkColorToHSV(color, hsv);
760 hsv[0] = hsv[0] + 90 >= 360 ? hsv[0] - 270 : hsv[0] + 90;
761 SkPaint paint;
762 paint.setColor(SkHSVToColor(hsv));
763 canvas->drawRect(SkRect::MakeXYWH(x, y, 1, 1), paint);
764 }
765 }
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400766##
767
Cary Clarkffb3d682018-05-17 12:17:28 -0400768#SeeAlso SkColorToHSV SkRGBToHSV
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400769
770#Method ##
771
772#Subtopic HSV ##
773
774# ------------------------------------------------------------------------------
775
Cary Clark682c58d2018-05-16 07:07:07 -0400776#Subtopic PMColor
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400777
Cary Clark682c58d2018-05-16 07:07:07 -0400778#Typedef uint32_t SkPMColor
779#Line # defines Premultiplied Color as 32 bits ##
780
Cary Clarkffb3d682018-05-17 12:17:28 -0400781#Code
782typedef uint32_t SkPMColor;
783##
784
Cary Clark682c58d2018-05-16 07:07:07 -040078532-bit ARGB color value, Premultiplied. The byte order for this value is
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400786configuration dependent, matching the format of kBGRA_8888_SkColorType bitmaps.
Cary Clark682c58d2018-05-16 07:07:07 -0400787This is different from SkColor, which is Unpremultiplied, and is always in the
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400788same byte order.
789
790#Typedef ##
791
792# ------------------------------------------------------------------------------
793
Cary Clarkffb3d682018-05-17 12:17:28 -0400794#Method SkPMColor SkPreMultiplyARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400795#In Function
Cary Clark682c58d2018-05-16 07:07:07 -0400796#Line # converts Unpremultiplied ARGB to Premultiplied PMColor ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400797
Cary Clarkffb3d682018-05-17 12:17:28 -0400798Returns a SkPMColor value from Unpremultiplied 8-bit component values.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400799
Cary Clarkffb3d682018-05-17 12:17:28 -0400800#Param a amount of Alpha, from fully transparent (0) to fully opaque (255) ##
801#Param r amount of red, from no red (0) to full red (255) ##
802#Param g amount of green, from no green (0) to full green (255) ##
803#Param b amount of blue, from no blue (0) to full blue (255) ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400804
Cary Clarkffb3d682018-05-17 12:17:28 -0400805#Return Premultiplied Color ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400806
807#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400808#Height 128
809#Width 300
810 SkPMColor premultiplied = SkPreMultiplyARGB(160, 128, 160, 192);
811 canvas->drawString("Unpremultiplied:", 20, 20, SkPaint());
812 canvas->drawString("alpha=160 red=128 green=160 blue=192", 20, 40, SkPaint());
813 canvas->drawString("Premultiplied:", 20, 80, SkPaint());
814 std::string str = "alpha=" + std::to_string(SkColorGetA(premultiplied));
815 str += " red=" + std::to_string(SkColorGetR(premultiplied));
816 str += " green=" + std::to_string(SkColorGetG(premultiplied));
817 str += " blue=" + std::to_string(SkColorGetB(premultiplied));
818 canvas->drawString(str.c_str(), 20, 100, SkPaint());
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400819##
820
Cary Clarkffb3d682018-05-17 12:17:28 -0400821#SeeAlso SkPreMultiplyColor
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400822
823#Method ##
824
825# ------------------------------------------------------------------------------
826
Cary Clarkffb3d682018-05-17 12:17:28 -0400827#Method SkPMColor SkPreMultiplyColor(SkColor c)
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400828#In Function
Cary Clark682c58d2018-05-16 07:07:07 -0400829#Line # converts Unpremultiplied Color to Premultiplied PMColor ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400830
Cary Clark682c58d2018-05-16 07:07:07 -0400831Returns PMColor closest to Color c. Multiplies c RGB components by the c Alpha,
832and arranges the bytes to match the format of kN32_SkColorType.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400833
Cary Clarkffb3d682018-05-17 12:17:28 -0400834#Param c Unpremultiplied ARGB Color ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400835
Cary Clarkffb3d682018-05-17 12:17:28 -0400836#Return Premultiplied Color ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400837
838#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400839#Height 128
840#Width 300
841 SkColor unpremultiplied = SkColorSetARGB(160, 128, 160, 192);
842 SkPMColor premultiplied = SkPreMultiplyColor(unpremultiplied);
843 canvas->drawString("Unpremultiplied:", 20, 20, SkPaint());
844 std::string str = "alpha=" + std::to_string(SkColorGetA(unpremultiplied));
845 str += " red=" + std::to_string(SkColorGetR(unpremultiplied));
846 str += " green=" + std::to_string(SkColorGetG(unpremultiplied));
847 str += " blue=" + std::to_string(SkColorGetB(unpremultiplied));
848 canvas->drawString(str.c_str(), 20, 40, SkPaint());
849 canvas->drawString("Premultiplied:", 20, 80, SkPaint());
850 str = "alpha=" + std::to_string(SkColorGetA(premultiplied));
851 str += " red=" + std::to_string(SkColorGetR(premultiplied));
852 str += " green=" + std::to_string(SkColorGetG(premultiplied));
853 str += " blue=" + std::to_string(SkColorGetB(premultiplied));
854 canvas->drawString(str.c_str(), 20, 100, SkPaint());
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400855##
856
Cary Clarkffb3d682018-05-17 12:17:28 -0400857#SeeAlso SkPreMultiplyARGB
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400858
859#Method ##
860
Cary Clark682c58d2018-05-16 07:07:07 -0400861#Subtopic PMColor ##
862
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400863#Topic Color ##