blob: 349de3803df789026e5401ce9aad3c9a2f2ee3a0 [file] [log] [blame]
Cary Clark2d4bf5f2018-04-16 08:37:38 -04001#Topic Color
2#Alias Color_Reference
3
4#Subtopic Overview
Cary Clark682c58d2018-05-16 07:07:07 -04005#Populate
Cary Clark2d4bf5f2018-04-16 08:37:38 -04006##
7
8#Subtopic Define
9#Populate
10##
11
Cary Clark682c58d2018-05-16 07:07:07 -040012Color constants can be helpful to write code, documenting the meaning of values
13the represent transparency and color values. The use of Color constants is not
14required.
15
16#Subtopic Constant
17#Populate
18##
19
Cary Clark2d4bf5f2018-04-16 08:37:38 -040020#Subtopic Function
21#Populate
22##
23
24#Subtopic Typedef
25#Populate
26##
27
Cary Clark2d4bf5f2018-04-16 08:37:38 -040028
29 #Subtopic RGB
30 #Substitute RGB
31 #Subtopic Red
32 #Alias Red
33 #Subtopic ##
34 #Subtopic Blue
35 #Alias Blue
36 #Subtopic ##
37 #Subtopic Green
38 #Alias Green
39 #Subtopic ##
40 #Subtopic ##
41
42 #Subtopic ARGB
43 #Substitute ARGB
44 #Subtopic ##
45
46 #Subtopic RBG
47 #Substitute RBG
48 #Subtopic ##
49
50 #Subtopic RGB-565
51 #Substitute RGB-565
52 #Alias Color_RGB-565 # quit changing - to _ !
53 #Subtopic ##
54
55 #Subtopic Gray
56 ##
57
58# ------------------------------------------------------------------------------
59
Cary Clark682c58d2018-05-16 07:07:07 -040060#Subtopic Alpha
Cary Clark2d4bf5f2018-04-16 08:37:38 -040061
Cary Clark682c58d2018-05-16 07:07:07 -040062Alpha represents the transparency of Color. Color with Alpha of zero is fully
63transparent. Color with Alpha of 255 is fully opaque. Some, but not all pixel
64formats contain Alpha. Pixels with Alpha may store it as unsigned integers or
65floating point values. Unsigned integer Alpha ranges from zero, fully
66transparent, to all bits set, fully opaque. Floating point Alpha ranges from
67zero, fully transparent, to one, fully opaque.
68
69#Alias Alpha
70
71#Typedef uint8_t SkAlpha
72#Line # defines Alpha as eight bits ##
73
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400748-bit type for an alpha value. 0xFF is 100% opaque, 0x00 is 100% transparent.
75
76#Typedef ##
77
Cary Clark682c58d2018-05-16 07:07:07 -040078#Subtopic ##
79
Cary Clark2d4bf5f2018-04-16 08:37:38 -040080# ------------------------------------------------------------------------------
81
82#Typedef uint32_t SkColor
Cary Clark682c58d2018-05-16 07:07:07 -040083#Line # defines Color as 32 bits ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -040084
Cary Clark682c58d2018-05-16 07:07:07 -04008532-bit ARGB Color value, Unpremultiplied. Color components are always in
Cary Clark2d4bf5f2018-04-16 08:37:38 -040086a known order. This is different from SkPMColor, which has its bytes in a configuration
87dependent order, to match the format of kBGRA_8888_SkColorType bitmaps. SkColor
88is the type used to specify colors in SkPaint and in gradients.
89
Cary Clark682c58d2018-05-16 07:07:07 -040090Color that is Premultiplied has the same component values as Color
91that is Unpremultiplied if Alpha is 255, fully opaque, although may have the
92component values in a different order.
93
94#SeeAlso SkPMColor
95
Cary Clark2d4bf5f2018-04-16 08:37:38 -040096#Typedef ##
97
98# ------------------------------------------------------------------------------
99
100#Method static constexpr inline SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
101#In Function
Cary Clark682c58d2018-05-16 07:07:07 -0400102#Line # returns Color_Alpha and Color_RGB combined ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400103
Cary Clark682c58d2018-05-16 07:07:07 -0400104Returns Color value from 8-bit component values. Asserts if SK_DEBUG is defined
105if a, r, g, or b exceed 255. Since Color is Unpremultiplied, a may be smaller
106than the largest of r, g, and b.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400107
Cary Clark682c58d2018-05-16 07:07:07 -0400108#Param a amount of Alpha, from fully transparent (0) to fully opaque (255) ##
109#Param r amount of RGB_Red, from no red (0) to full red (255) ##
110#Param g amount of RGB_Green, from no green (0) to full green (255) ##
111#Param b amount of RGB_Blue, from no blue (0) to full blue (255) ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400112
Cary Clark682c58d2018-05-16 07:07:07 -0400113#Return color and alpha, Unpremultiplied ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400114
115#Example
Cary Clark682c58d2018-05-16 07:07:07 -0400116 canvas->drawColor(SK_ColorRED);
117 canvas->clipRect(SkRect::MakeWH(150, 150));
118 canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0xFF, 0x00));
119 canvas->clipRect(SkRect::MakeWH(75, 75));
120 canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0x00, 0xFF));
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400121##
122
Cary Clark682c58d2018-05-16 07:07:07 -0400123#SeeAlso SkColorSetRGB SkPaint::setARGB SkPaint::setColor
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400124
125#Method ##
126
127# ------------------------------------------------------------------------------
128
129#Define SkColorSetARGBInline
130
131#Code
132###$
133 #define SkColorSetARGBInline SkColorSetARGB
134$$$#
135##
136
Cary Clark682c58d2018-05-16 07:07:07 -0400137#Deprecated soon
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400138
139#Define ##
140
141# ------------------------------------------------------------------------------
142
143#Define SkColorSetARGBMacro
144
145#Code
146###$
147 #define SkColorSetARGBMacro SkColorSetARGB
148$$$#
149##
150
Cary Clark682c58d2018-05-16 07:07:07 -0400151#Deprecated soon
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400152
153#Define ##
154
155# ------------------------------------------------------------------------------
156
157#Define SkColorSetRGB
Cary Clark682c58d2018-05-16 07:07:07 -0400158#Line # returns opaque Color ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400159
160#Code
161###$
162 #define SkColorSetRGB(r, g, b) SkColorSetARGB(0xFF, r, g, b)
163$$$#
164##
165
Cary Clark682c58d2018-05-16 07:07:07 -0400166Returns Color value from 8-bit component values, with Alpha set
167fully opaque to 255.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400168
Cary Clark682c58d2018-05-16 07:07:07 -0400169#Param r amount of RGB_Red, from no red (0) to full red (255) ##
170#Param g amount of RGB_Green, from no green (0) to full green (255) ##
171#Param b amount of RGB_Blue, from no blue (0) to full blue (255) ##
172
173#Return color with opaque alpha ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400174
175#Example
Cary Clark682c58d2018-05-16 07:07:07 -0400176 canvas->drawColor(SK_ColorRED);
177 canvas->clipRect(SkRect::MakeWH(150, 150));
178 canvas->drawColor(SkColorSetRGB(0x00, 0xFF, 0x00));
179 canvas->clipRect(SkRect::MakeWH(75, 75));
180 canvas->drawColor(SkColorSetRGB(0x00, 0x00, 0xFF));
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400181##
182
183#SeeAlso incomplete
184
185#Define ##
186
187# ------------------------------------------------------------------------------
188
189#Define SkColorGetA
Cary Clark682c58d2018-05-16 07:07:07 -0400190#Line # returns Alpha component ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400191
192#Code
193###$
194 #define SkColorGetA(color) (((color) >> 24) & 0xFF)
195$$$#
196##
197
Cary Clark682c58d2018-05-16 07:07:07 -0400198Returns Alpha byte from Color value.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400199
Cary Clark682c58d2018-05-16 07:07:07 -0400200#Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400201
202#Example
203// incomplete
204##
205
206#SeeAlso incomplete
207
208#Define ##
209
210# ------------------------------------------------------------------------------
211
212#Define SkColorGetR
213#Line # incomplete ##
214
215#Code
216###$
217 #define SkColorGetR(color) (((color) >> 16) & 0xFF)
218$$$#
219##
220
Cary Clark682c58d2018-05-16 07:07:07 -0400221Returns red component of Color, from zero to 255.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400222
Cary Clark682c58d2018-05-16 07:07:07 -0400223#Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
224#Return red byte ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400225
226#Example
227// incomplete
228##
229
230#SeeAlso incomplete
231
232#Define ##
233
234# ------------------------------------------------------------------------------
235
236#Define SkColorGetG
237#Line # incomplete ##
238
239#Code
240###$
241 #define SkColorGetG(color) (((color) >> 8) & 0xFF)
242$$$#
243##
244
Cary Clark682c58d2018-05-16 07:07:07 -0400245Returns green component of Color, from zero to 255.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400246
Cary Clark682c58d2018-05-16 07:07:07 -0400247#Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
248#Return green byte ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400249
250#Example
251// incomplete
252##
253
254#SeeAlso incomplete
255
256#Define ##
257
258# ------------------------------------------------------------------------------
259
260#Define SkColorGetB
261#Line # incomplete ##
262
263#Code
264###$
265 #define SkColorGetB(color) (((color) >> 0) & 0xFF)
266$$$#
267##
268
Cary Clark682c58d2018-05-16 07:07:07 -0400269Returns blue component of Color, from zero to 255.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400270
Cary Clark682c58d2018-05-16 07:07:07 -0400271#Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
272#Return blue byte ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400273
274#Example
275// incomplete
276##
277
278#SeeAlso incomplete
279
280#Define ##
281
282# ------------------------------------------------------------------------------
283
284#Method static constexpr inline SkColor SkColorSetA(SkColor c, U8CPU a)
285#In Function
286#Line # incomplete ##
287
Cary Clark682c58d2018-05-16 07:07:07 -0400288Returns Color with red, blue, and green set from c; and alpha set from a.
289
290#Param c Unpremultiplied Color_ARGB ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400291#Param a incomplete ##
292
293#Return incomplete ##
294
295#Example
296// incomplete
297##
298
299#SeeAlso incomplete
300
301#Method ##
302
303# ------------------------------------------------------------------------------
304
Cary Clark682c58d2018-05-16 07:07:07 -0400305#Subtopic Alpha_Constants
306#In Constant
307#Line # constants for Alpha ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400308
309#Code
Cary Clark682c58d2018-05-16 07:07:07 -0400310 constexpr SkAlpha SK_AlphaTRANSPARENT = 0x00;
311 constexpr SkAlpha SK_AlphaOPAQUE = 0xFF;
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400312##
313
Cary Clark682c58d2018-05-16 07:07:07 -0400314Alpha constants are conveniences to represent fully transparent and fully
315opaque colors and masks. Their use is not required.
316
317#Const SK_AlphaTRANSPARENT 0x00
318#Line # fully transparent SkAlpha ##
319#Details Transparent
320Represents fully transparent SkAlpha value. SkAlpha ranges from zero,
321fully transparent; to 255, fully opaque.
322##
323#Const SK_AlphaOPAQUE 0xFF
324#Line # fully opaque SkAlpha ##
325#Details Opaque
326Represents fully opaque SkAlpha value. SkAlpha ranges from zero,
327fully transparent; to 255, fully opaque.
328##
329
330#Subtopic Transparent
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400331
332#Example
Cary Clark682c58d2018-05-16 07:07:07 -0400333#Image 1
334#Height 128
335#Description
336Color the parts of the bitmap red if they mostly contain transparent pixels.
337##
338 std::vector<int32_t> srcPixels;
339 srcPixels.resize(source.height() * source.rowBytes());
340 SkPixmap pixmap(SkImageInfo::MakeN32Premul(source.width(), source.height()),
341 &srcPixels.front(), source.rowBytes());
342 source.readPixels(pixmap, 0, 0);
343 for (int y = 0; y < 16; ++y) {
344 for (int x = 0; x < 16; ++x) {
345 int32_t* blockStart = &srcPixels.front() + y * source.width() * 16 + x * 16;
346 size_t transparentCount = 0;
347 for (int fillY = 0; fillY < source.height() / 16; ++fillY) {
348 for (int fillX = 0; fillX < source.width() / 16; ++fillX) {
349 const SkColor color = SkUnPreMultiply::PMColorToColor(blockStart[fillX]);
350 transparentCount += SkColorGetA(color) == SK_AlphaTRANSPARENT;
351 }
352 blockStart += source.width();
353 }
354 if (transparentCount > 200) {
355 blockStart = &srcPixels.front() + y * source.width() * 16 + x * 16;
356 for (int fillY = 0; fillY < source.height() / 16; ++fillY) {
357 for (int fillX = 0; fillX < source.width() / 16; ++fillX) {
358 blockStart[fillX] = SK_ColorRED;
359 }
360 blockStart += source.width();
361 }
362 }
363 }
364 }
365 SkBitmap bitmap;
366 bitmap.installPixels(pixmap);
367 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400368##
369
Cary Clark682c58d2018-05-16 07:07:07 -0400370#SeeAlso SkAlpha SK_ColorTRANSPARENT SK_AlphaOPAQUE
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400371
Cary Clark682c58d2018-05-16 07:07:07 -0400372#Subtopic Transparent ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400373
374# ------------------------------------------------------------------------------
375
Cary Clark682c58d2018-05-16 07:07:07 -0400376#Subtopic Opaque
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400377
378#Example
Cary Clark682c58d2018-05-16 07:07:07 -0400379#Image 1
380#Height 128
381 std::vector<int32_t> srcPixels;
382 srcPixels.resize(source.height() * source.rowBytes());
383 SkPixmap pixmap(SkImageInfo::MakeN32Premul(source.width(), source.height()),
384 &srcPixels.front(), source.rowBytes());
385 source.readPixels(pixmap, 0, 0);
386 for (int y = 0; y < source.height(); ++y) {
387 for (int x = 0; x < source.width(); ++x) {
388 SkPMColor pixel = srcPixels[y * source.width() + x];
389 const SkColor color = SkUnPreMultiply::PMColorToColor(pixel);
390 if (SkColorGetA(color) == SK_AlphaOPAQUE) {
391 srcPixels[y * source.width() + x] = SK_ColorGREEN;
392 }
393 }
394 }
395 SkBitmap bitmap;
396 bitmap.installPixels(pixmap);
397 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400398##
399
Cary Clark682c58d2018-05-16 07:07:07 -0400400#SeeAlso SkAlpha SK_AlphaTRANSPARENT
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400401
Cary Clark682c58d2018-05-16 07:07:07 -0400402#Subtopic Opaque ##
403#Subtopic Alpha_Constants ##
404
405#Subtopic Color_Constants
406#In Constant
407#Line # constants for Color ##
408
409# ------------------------------------------------------------------------------
410#Code
411 constexpr SkColor SK_ColorTRANSPARENT = SkColorSetARGB(0x00, 0x00, 0x00, 0x00);
412 constexpr SkColor SK_ColorBLACK = SkColorSetARGB(0xFF, 0x00, 0x00, 0x00);
413 constexpr SkColor SK_ColorDKGRAY = SkColorSetARGB(0xFF, 0x44, 0x44, 0x44);
414 constexpr SkColor SK_ColorGRAY = SkColorSetARGB(0xFF, 0x88, 0x88, 0x88);
415 constexpr SkColor SK_ColorLTGRAY = SkColorSetARGB(0xFF, 0xCC, 0xCC, 0xCC);
416 constexpr SkColor SK_ColorWHITE = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF);
417 constexpr SkColor SK_ColorRED = SkColorSetARGB(0xFF, 0xFF, 0x00, 0x00);
418 constexpr SkColor SK_ColorGREEN = SkColorSetARGB(0xFF, 0x00, 0xFF, 0x00);
419 constexpr SkColor SK_ColorBLUE = SkColorSetARGB(0xFF, 0x00, 0x00, 0xFF);
420 constexpr SkColor SK_ColorYELLOW = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0x00);
421 constexpr SkColor SK_ColorCYAN = SkColorSetARGB(0xFF, 0x00, 0xFF, 0xFF);
422 constexpr SkColor SK_ColorMAGENTA = SkColorSetARGB(0xFF, 0xFF, 0x00, 0xFF);
423##
424
425Color names are provided as conveniences, but are not otherwise special.
426The values chosen for names may not be the same as values used by
427SVG, HTML, CSS, or colors named by a platform.
428
429#Example
430###$
431$Function
432#define SKIA_COLOR_PAIR(name) "SK_Color" #name, SK_Color##name
433$$
434void draw(SkCanvas* canvas) {
435 struct ColorCompare {
436 const char* fSVGName;
437 SkColor fSVGColor;
438 const char* fSkiaName;
439 SkColor fSkiaColor;
440 } colorCompare[] = { // see https://www.w3.org/TR/SVG/types.html#ColorKeywords
441 {"black", SkColorSetRGB( 0, 0, 0), SKIA_COLOR_PAIR(BLACK) },
442 {"darkgray", SkColorSetRGB(169, 169, 169), SKIA_COLOR_PAIR(DKGRAY) },
443 {"gray", SkColorSetRGB(128, 128, 128), SKIA_COLOR_PAIR(GRAY) },
444 {"lightgray", SkColorSetRGB(211, 211, 211), SKIA_COLOR_PAIR(LTGRAY) },
445 {"white", SkColorSetRGB(255, 255, 255), SKIA_COLOR_PAIR(WHITE) },
446 {"red", SkColorSetRGB(255, 0, 0), SKIA_COLOR_PAIR(RED) },
447 {"green", SkColorSetRGB( 0, 128, 0), SKIA_COLOR_PAIR(GREEN) },
448 {"blue", SkColorSetRGB( 0, 0, 255), SKIA_COLOR_PAIR(BLUE) },
449 {"yellow", SkColorSetRGB(255, 255, 0), SKIA_COLOR_PAIR(YELLOW) },
450 {"aqua", SkColorSetRGB( 0, 255, 255), SKIA_COLOR_PAIR(CYAN) },
451 {"fuchsia", SkColorSetRGB(255, 0, 255), SKIA_COLOR_PAIR(MAGENTA) },
452 };
453 SkPaint paint;
454 paint.setAntiAlias(true);
455 paint.setTextSize(14);
456 for (auto compare : colorCompare) {
457 paint.setStyle(SkPaint::kFill_Style);
458 paint.setColor(compare.fSVGColor);
459 canvas->drawRect({5, 5, 15, 15}, paint);
460 paint.setColor(SK_ColorBLACK);
461 canvas->drawString(compare.fSVGName, 20, 16, paint);
462 paint.setColor(compare.fSkiaColor);
463 canvas->drawRect({105, 5, 115, 15}, paint);
464 paint.setColor(SK_ColorBLACK);
465 canvas->drawString(compare.fSkiaName, 120, 16, paint);
466 paint.setStyle(SkPaint::kStroke_Style);
467 canvas->drawRect({5, 5, 15, 15}, paint);
468 canvas->drawRect({105, 5, 115, 15}, paint);
469 canvas->translate(0, 20);
470 }
471}
472$$$#
473##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400474
475# ------------------------------------------------------------------------------
476
Cary Clark682c58d2018-05-16 07:07:07 -0400477#Const SK_ColorTRANSPARENT 0x00000000
478#Line # transparent Color ##
479#Details Transparent
480 Represents fully transparent SkColor. May be used to initialize a destination
481 containing a mask or a non-rectangular image.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400482##
Cary Clark682c58d2018-05-16 07:07:07 -0400483#Const SK_ColorBLACK 0xFF000000
484#Line # black Color ##
485#Details Black
486 Represents fully opaque black.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400487##
Cary Clark682c58d2018-05-16 07:07:07 -0400488#Const SK_ColorDKGRAY 0xFF444444
489#Line # dark gray Color ##
490 Represents fully opaque dark gray.
491 Note that SVG_darkgray is equivalent to 0xFFA9A9A9.
492##
493#Const SK_ColorGRAY 0xFF888888
494#Line # gray Color ##
495 Represents fully opaque gray.
496 Note that HTML_Gray is equivalent to 0xFF808080.
497##
498#Const SK_ColorLTGRAY 0xFFCCCCCC
499#Line # light gray Color ##
500 Represents fully opaque light gray. HTML_Silver is equivalent to 0xFFC0C0C0.
501 Note that SVG_lightgray is equivalent to 0xFFD3D3D3.
502##
503#Const SK_ColorWHITE 0xFFFFFFFF
504#Line # white Color ##
505 Represents fully opaque white.
506##
507#Const SK_ColorRED 0xFFFF0000
508#Line # red Color ##
509 Represents fully opaque red.
510##
511#Const SK_ColorGREEN 0xFF00FF00
512#Line # green Color ##
513 Represents fully opaque green. HTML_Lime is equivalent.
514 Note that HTML_Green is equivalent to 0xFF008000.
515##
516#Const SK_ColorBLUE 0xFF0000FF
517#Line # blue Color ##
518 Represents fully opaque blue.
519##
520#Const SK_ColorYELLOW 0xFFFFFF00
521#Line # yellow Color ##
522 Represents fully opaque yellow.
523##
524#Const SK_ColorCYAN 0xFF00FFFF
525#Line # cyan Color ##
526 Represents fully opaque cyan. HTML_Aqua is equivalent.
527##
528#Const SK_ColorMAGENTA 0xFFFF00FF
529#Line # magenta Color ##
530 Represents fully opaque magenta. HTML_Fuchsia is equivalent.
531##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400532
533# ------------------------------------------------------------------------------
534
Cary Clark682c58d2018-05-16 07:07:07 -0400535#Subtopic Transparent
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400536
537#Example
Cary Clark682c58d2018-05-16 07:07:07 -0400538 std::vector<uint32_t> srcPixels;
539 constexpr int width = 256;
540 constexpr int height = 256;
541 srcPixels.resize(width * height);
542 SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(width, height);
543 SkPixmap pixmap(imageInfo, &srcPixels.front(), imageInfo.minRowBytes());
544 pixmap.erase(SK_ColorTRANSPARENT);
545 pixmap.erase(SK_ColorRED, { 24, 24, 192, 192 } );
546 pixmap.erase(SK_ColorTRANSPARENT, { 48, 48, 168, 168 } );
547 SkBitmap bitmap;
548 bitmap.installPixels(pixmap);
549 canvas->drawBitmap(bitmap, 0, 0);
550 canvas->drawBitmap(bitmap, 48, 48);
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400551##
552
Cary Clark682c58d2018-05-16 07:07:07 -0400553#SeeAlso SK_AlphaTRANSPARENT SkCanvas::clear
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400554
Cary Clark682c58d2018-05-16 07:07:07 -0400555##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400556
557# ------------------------------------------------------------------------------
558
Cary Clark682c58d2018-05-16 07:07:07 -0400559#Subtopic Black
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400560
561#Example
Cary Clark682c58d2018-05-16 07:07:07 -0400562 std::vector<uint32_t> srcPixels;
563 constexpr int width = 256;
564 constexpr int height = 256;
565 srcPixels.resize(width * height);
566 SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(width, height);
567 SkPixmap pixmap(imageInfo, &srcPixels.front(), imageInfo.minRowBytes());
568 pixmap.erase(SK_ColorTRANSPARENT);
569 pixmap.erase(SK_ColorRED, { 24, 24, 192, 192 } );
570 pixmap.erase(SK_ColorBLACK, { 48, 48, 168, 168 } );
571 SkBitmap bitmap;
572 bitmap.installPixels(pixmap);
573 canvas->drawBitmap(bitmap, 0, 0);
574 canvas->drawBitmap(bitmap, 48, 48);
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400575##
576
Cary Clark682c58d2018-05-16 07:07:07 -0400577#SeeAlso SK_ColorTRANSPARENT
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400578
Cary Clark682c58d2018-05-16 07:07:07 -0400579##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400580
581# ------------------------------------------------------------------------------
582
Cary Clark682c58d2018-05-16 07:07:07 -0400583#Subtopic White
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400584
585#Example
Cary Clark682c58d2018-05-16 07:07:07 -0400586 std::vector<uint32_t> srcPixels;
587 constexpr int width = 256;
588 constexpr int height = 256;
589 srcPixels.resize(width * height);
590 SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(width, height);
591 SkPixmap pixmap(imageInfo, &srcPixels.front(), imageInfo.minRowBytes());
592 pixmap.erase(SK_ColorTRANSPARENT);
593 pixmap.erase(SK_ColorRED, { 24, 24, 192, 192 } );
594 pixmap.erase(SK_ColorWHITE, { 48, 48, 168, 168 } );
595 SkBitmap bitmap;
596 bitmap.installPixels(pixmap);
597 canvas->drawBitmap(bitmap, 0, 0);
598 canvas->drawBitmap(bitmap, 48, 48);
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400599##
600
Cary Clark682c58d2018-05-16 07:07:07 -0400601#SeeAlso SK_ColorTRANSPARENT
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400602
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400603##
604
Cary Clark682c58d2018-05-16 07:07:07 -0400605#Subtopic Color_Constants ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400606
607# ------------------------------------------------------------------------------
608
609#Subtopic HSV
610
611#Subtopic Hue
612Hue represents an angle, in degrees, on a color wheel. Hue has a positive value
613modulo 360, where zero degrees is red.
614##
615
616#Subtopic Saturation
617##
618
619#Subtopic Value
620##
621
622#Method SK_API void SkRGBToHSV(U8CPU red, U8CPU green, U8CPU blue, SkScalar hsv[3])
623#In Function
624#Line # incomplete ##
625
Cary Clark682c58d2018-05-16 07:07:07 -0400626Converts RGB components to HSV.
627hsv[0] contains Hue, a value from zero to less than 360.
628hsv[1] contains Saturation, a value from zero to one.
629hsv[2] contains Value, a value from zero to one.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400630
Cary Clark682c58d2018-05-16 07:07:07 -0400631#Param red red component value from zero to 255 ##
632#Param green green component value from zero to 255 ##
633#Param blue blue component value from zero to 255 ##
634#Param hsv three element array which holds the resulting HSV components
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400635##
636
637#Return incomplete ##
638
639#Example
640// incomplete
641##
642
643#SeeAlso incomplete
644
645#Method ##
646
647# ------------------------------------------------------------------------------
648
649#Method static inline void SkColorToHSV(SkColor color, SkScalar hsv[3])
650#In Function
Cary Clark682c58d2018-05-16 07:07:07 -0400651#Line # converts RGB to HSV ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400652
Cary Clark682c58d2018-05-16 07:07:07 -0400653Converts ARGB to its HSV components. Alpha in ARGB is ignored.
654hsv[0] contains Hue, and is assigned a value from zero to less than 360.
655hsv[1] contains Saturation, a value from zero to one.
656hsv[2] contains Value, a value from zero to one.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400657
Cary Clark682c58d2018-05-16 07:07:07 -0400658#Param color ARGB color to convert
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400659##
Cary Clark682c58d2018-05-16 07:07:07 -0400660#Param hsv three element array which holds the resulting HSV components
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400661##
662
663#Return incomplete ##
664
665#Example
666// incomplete
667##
668
669#SeeAlso incomplete
670
671#Method ##
672
673# ------------------------------------------------------------------------------
674
675#Method SK_API SkColor SkHSVToColor(U8CPU alpha, const SkScalar hsv[3])
676#In Function
Cary Clark682c58d2018-05-16 07:07:07 -0400677#Line # converts HSV with Alpha to RGB ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400678
Cary Clark682c58d2018-05-16 07:07:07 -0400679Converts HSV components to an ARGB color. The alpha component is passed through unchanged.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400680hsv[0] represents Hue, an angle from zero to less than 360.
681hsv[1] represents Saturation, and varies from zero to one.
682hsv[2] represents Value, and varies from zero to one.
683
684If hsv values are out of range, they are pinned.
685
Cary Clark682c58d2018-05-16 07:07:07 -0400686#Param alpha Alpha component of the returned ARGB color
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400687##
Cary Clark682c58d2018-05-16 07:07:07 -0400688#Param hsv three element array which holds the input HSV components
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400689##
690
Cary Clark682c58d2018-05-16 07:07:07 -0400691#Return ARGB equivalent to HSV
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400692##
693
694#Example
695// incomplete
696##
697
698#SeeAlso incomplete
699
700#Method ##
701
702# ------------------------------------------------------------------------------
703
704#Method static inline SkColor SkHSVToColor(const SkScalar hsv[3])
705#In Function
706#Line # incomplete ##
707
708Convert HSV components to an ARGB color. The alpha component set to 0xFF.
709hsv[0] represents Hue, an angle from zero to less than 360.
710hsv[1] represents Saturation, and varies from zero to one.
711hsv[2] represents Value, and varies from zero to one.
712
713If hsv values are out of range, they are pinned.
714
715#Param hsv 3 element array which holds the input HSV components.
716##
717
Cary Clark682c58d2018-05-16 07:07:07 -0400718#Return the resulting ARGB color
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400719##
720
721#Example
722// incomplete
723##
724
725#SeeAlso incomplete
726
727#Method ##
728
729#Subtopic HSV ##
730
731# ------------------------------------------------------------------------------
732
Cary Clark682c58d2018-05-16 07:07:07 -0400733#Subtopic PMColor
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400734
Cary Clark682c58d2018-05-16 07:07:07 -0400735#Typedef uint32_t SkPMColor
736#Line # defines Premultiplied Color as 32 bits ##
737
73832-bit ARGB color value, Premultiplied. The byte order for this value is
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400739configuration dependent, matching the format of kBGRA_8888_SkColorType bitmaps.
Cary Clark682c58d2018-05-16 07:07:07 -0400740This is different from SkColor, which is Unpremultiplied, and is always in the
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400741same byte order.
742
743#Typedef ##
744
745# ------------------------------------------------------------------------------
746
747#Method SK_API SkPMColor SkPreMultiplyARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
748#In Function
Cary Clark682c58d2018-05-16 07:07:07 -0400749#Line # converts Unpremultiplied ARGB to Premultiplied PMColor ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400750
Cary Clark682c58d2018-05-16 07:07:07 -0400751Return a SkPMColor value from Unpremultiplied 8-bit component values
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400752
753#Param a incomplete ##
754#Param r incomplete ##
755#Param g incomplete ##
756#Param b incomplete ##
757
758#Return incomplete ##
759
760#Example
761// incomplete
762##
763
764#SeeAlso incomplete
765
766#Method ##
767
768# ------------------------------------------------------------------------------
769
770#Method SK_API SkPMColor SkPreMultiplyColor(SkColor c)
771#In Function
Cary Clark682c58d2018-05-16 07:07:07 -0400772#Line # converts Unpremultiplied Color to Premultiplied PMColor ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400773
Cary Clark682c58d2018-05-16 07:07:07 -0400774Returns PMColor closest to Color c. Multiplies c RGB components by the c Alpha,
775and arranges the bytes to match the format of kN32_SkColorType.
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400776
777#Param c incomplete ##
778
779#Return incomplete ##
780
781#Example
782// incomplete
783##
784
785#SeeAlso incomplete
786
787#Method ##
788
Cary Clark682c58d2018-05-16 07:07:07 -0400789#Subtopic PMColor ##
790
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400791#Topic Color ##