Home | History | Annotate | Download | only in docs
      1 #Topic Color
      2 #Alias Color_Reference ##
      3 
      4 #Code
      5 #Populate
      6 ##
      7 
      8 Color constants can be helpful to write code, documenting the meaning of values
      9 the represent transparency and color values. The use of Color constants is not
     10 required.
     11 
     12 #Subtopic Functions
     13 #Line # routines to read, write, and manipulate SkColor ##
     14 ##
     15 
     16 # ------------------------------------------------------------------------------
     17 
     18 #Subtopic Alpha
     19 #Line # transparency of Color ##
     20 
     21 Alpha represents the transparency of Color. Color with Alpha of zero is fully
     22 transparent. Color with Alpha of 255 is fully opaque. Some, but not all pixel
     23 formats contain Alpha. Pixels with Alpha may store it as unsigned integers or
     24 floating point values. Unsigned integer Alpha ranges from zero, fully
     25 transparent, to all bits set, fully opaque. Floating point Alpha ranges from
     26 zero, fully transparent, to one, fully opaque.
     27 
     28 #Alias Alpha 
     29 #Substitute alpha
     30 ##
     31 
     32 #Typedef uint8_t SkAlpha
     33 #Line # defines Alpha as eight bits ##
     34 
     35 #Code
     36 #Populate
     37 ##
     38 
     39 8-bit type for an alpha value. 255 is 100% opaque, zero is 100% transparent.
     40 
     41 #Typedef ##
     42 
     43 #Subtopic ##
     44 
     45 # ------------------------------------------------------------------------------
     46 
     47 #Typedef uint32_t SkColor
     48 #Line # defines Color as 32 bits ##
     49 
     50 #Code
     51 #Populate
     52 ##
     53 
     54 32-bit ARGB Color value, Unpremultiplied. Color components are always in
     55 a known order. This is different from SkPMColor, which has its bytes in a configuration
     56 dependent order, to match the format of kBGRA_8888_SkColorType bitmaps. SkColor
     57 is the type used to specify colors in SkPaint and in gradients.
     58 
     59 Color that is Premultiplied has the same component values as Color
     60 that is Unpremultiplied if Alpha is 255, fully opaque, although may have the
     61 component values in a different order.
     62 
     63 #SeeAlso SkPMColor
     64 
     65 #Typedef ##
     66 
     67 # ------------------------------------------------------------------------------
     68 
     69 #Method static constexpr inline SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
     70 #In Functions
     71 #Line # returns Color_Alpha and RGB combined ##
     72 
     73 Returns Color value from 8-bit component values. Asserts if SK_DEBUG is defined
     74 if a, r, g, or b exceed 255. Since Color is Unpremultiplied, a may be smaller
     75 than the largest of r, g, and b.
     76 
     77 #Param a    amount of Alpha, from fully transparent (0) to fully opaque (255) ##
     78 #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) ##
     81 
     82 #Return color and alpha, Unpremultiplied ##
     83 
     84 #Example
     85     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));
     90 ##
     91 
     92 #SeeAlso SkColorSetRGB SkPaint::setARGB SkPaint::setColor SkColorSetA
     93 
     94 #Method ##
     95 
     96 # ------------------------------------------------------------------------------
     97 
     98 #Define SkColorSetRGB
     99 #Line # returns opaque Color ##
    100 
    101 #Code
    102 #Populate
    103 ##
    104 
    105 Returns Color value from 8-bit component values, with Alpha set
    106 fully opaque to 255.
    107 
    108 #Param r    amount of red, from no red (0) to full red (255) ##
    109 #Param g    amount of green, from no green (0) to full green (255) ##
    110 #Param b    amount of blue, from no blue (0) to full blue (255) ##
    111 
    112 #Return     color with opaque alpha ##
    113 
    114 #Example
    115     canvas->drawColor(SK_ColorRED);
    116     canvas->clipRect(SkRect::MakeWH(150, 150));
    117     canvas->drawColor(SkColorSetRGB(0x00, 0xFF, 0x00));
    118     canvas->clipRect(SkRect::MakeWH(75, 75));
    119     canvas->drawColor(SkColorSetRGB(0x00, 0x00, 0xFF));
    120 ##
    121 
    122 #SeeAlso SkColorSetARGB 
    123 
    124 #Define ##
    125 
    126 # ------------------------------------------------------------------------------
    127 
    128 #Define SkColorGetA
    129 #Line # returns Alpha component ##
    130 
    131 #Code
    132 #Populate
    133 ##
    134 
    135 Returns Alpha byte from Color value.
    136 
    137 #Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
    138 
    139 #Example
    140     SkPaint paint;
    141     paint.setAntiAlias(true);
    142     paint.setColor(SK_ColorRED);
    143     for (int alpha = 255; alpha >= 0; alpha -= 17) {
    144         paint.setAlpha(alpha);
    145         canvas->drawRect({5, 5, 100, 20}, paint);
    146         SkAlpha alphaInPaint = SkColorGetA(paint.getColor());
    147         canvas->drawString(std::to_string(alphaInPaint).c_str(), 110, 18, paint);
    148         canvas->translate(0, 15);
    149     }
    150 ##
    151 
    152 #SeeAlso SkPaint::getAlpha
    153 
    154 #Define ##
    155 
    156 # ------------------------------------------------------------------------------
    157 
    158 #Define SkColorGetR
    159 #Line # returns red component ##
    160 
    161 #Code
    162 #Populate
    163 ##
    164 
    165 Returns red component of Color, from zero to 255.
    166 
    167 #Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
    168 #Return red byte ##
    169 
    170 #Example
    171 #Image 3
    172    canvas->drawBitmap(source, 0, 0);
    173    SkPaint bgPaint;
    174    bgPaint.setColor(0xafffffff);
    175    canvas->drawRect({20, 50, 80, 70}, bgPaint);
    176    uint8_t red = SkColorGetR(source.getColor(226, 128));
    177    canvas->drawString(std::to_string(red).c_str(), 40, 65, SkPaint());
    178    canvas->drawLine(80, 70, 226, 128, SkPaint());
    179 ##
    180 
    181 #SeeAlso SkColorGetG SkColorGetB
    182 
    183 #Define ##
    184 
    185 # ------------------------------------------------------------------------------
    186 
    187 #Define SkColorGetG
    188 #Line # returns green component ##
    189 
    190 #Code
    191 #Populate
    192 ##
    193 
    194 Returns green component of Color, from zero to 255.
    195 
    196 #Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
    197 #Return green byte ##
    198 
    199 #Example
    200 #Image 3
    201    canvas->drawBitmap(source, 0, 0);
    202    SkPaint bgPaint;
    203    bgPaint.setColor(0xafffffff);
    204    canvas->drawRect({20, 50, 80, 70}, bgPaint);
    205    uint8_t green = SkColorGetG(source.getColor(57, 192));
    206    canvas->drawString(std::to_string(green).c_str(), 40, 65, SkPaint());
    207    canvas->drawLine(80, 70, 57, 192, SkPaint());
    208 ##
    209 
    210 #SeeAlso SkColorGetR SkColorGetB
    211 
    212 #Define ##
    213 
    214 # ------------------------------------------------------------------------------
    215 
    216 #Define SkColorGetB
    217 #Line # returns blue component ##
    218 
    219 #Code
    220 #Populate
    221 ##
    222 
    223 Returns blue component of Color, from zero to 255.
    224 
    225 #Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
    226 #Return blue byte ##
    227 
    228 #Example
    229 #Image 3
    230    canvas->drawBitmap(source, 0, 0);
    231    SkPaint bgPaint;
    232    bgPaint.setColor(0xafffffff);
    233    canvas->drawRect({20, 50, 80, 70}, bgPaint);
    234    uint8_t blue = SkColorGetB(source.getColor(168, 170));
    235    canvas->drawString(std::to_string(blue).c_str(), 40, 65, SkPaint());
    236    canvas->drawLine(80, 70, 168, 170, SkPaint());
    237 ##
    238 
    239 #SeeAlso SkColorGetR SkColorGetG
    240 
    241 #Define ##
    242 
    243 # ------------------------------------------------------------------------------
    244 
    245 #Method static constexpr inline SkColor SkColorSetA(SkColor c, U8CPU a)
    246 #In Functions
    247 #Line # returns Color with transparency ##
    248 
    249 Returns Unpremultiplied Color with red, blue, and green set from c; and alpha set
    250 from a. Alpha component of c is ignored and is replaced by a in result.
    251 
    252 #Param c  packed RGB, eight bits per component ##
    253 #Param a  Alpha: transparent at zero, fully opaque at 255 ##
    254 
    255 #Return Color with transparency ##
    256 
    257 #Example
    258 #Image 3
    259    canvas->drawBitmap(source, 0, 0);
    260    for (int y = 0; y < 256; y += 16) {
    261       for (int x = 0; x < 256; x += 16) {
    262         SkColor color = source.getColor(x + 8, y + 8);
    263         SkPaint paint;
    264         paint.setColor(SkColorSetA(color, x + y));
    265         canvas->drawRect(SkRect::MakeXYWH(x, y, 16, 16), paint);
    266      }
    267    }
    268 ##
    269 
    270 #SeeAlso SkColorSetARGB
    271 
    272 #Method ##
    273 
    274 # ------------------------------------------------------------------------------
    275 
    276 #Subtopic Alpha_Constants
    277 #In Constant
    278 #Line # constants for Alpha ##
    279 #Filter SK_Alpha
    280 
    281 #Code
    282 #Populate
    283 ##
    284 
    285 Alpha constants are conveniences to represent fully transparent and fully
    286 opaque colors and masks. Their use is not required.
    287 
    288 #Const SK_AlphaTRANSPARENT 0x00
    289 #Line # fully transparent SkAlpha ##
    290 Represents fully transparent SkAlpha value. SkAlpha ranges from zero,
    291 fully transparent; to 255, fully opaque.
    292 ##
    293 #Const SK_AlphaOPAQUE 0xFF
    294 #Line # fully opaque SkAlpha ##
    295 Represents fully opaque SkAlpha value. SkAlpha ranges from zero,
    296 fully transparent; to 255, fully opaque.
    297 ##
    298 
    299 #Example
    300 #Image 1
    301 #Height 128
    302 #Description
    303 Color the parts of the bitmap red if they mostly contain transparent pixels.
    304 ##
    305     std::vector<int32_t> srcPixels;
    306     srcPixels.resize(source.height() * source.rowBytes());
    307     SkPixmap pixmap(SkImageInfo::MakeN32Premul(source.width(), source.height()),
    308                     &srcPixels.front(), source.rowBytes());
    309     source.readPixels(pixmap, 0, 0);
    310     for (int y = 0; y < 16; ++y) {
    311         for (int x = 0; x < 16; ++x) {
    312             int32_t* blockStart = &srcPixels.front() + y * source.width() * 16 + x * 16;
    313             size_t transparentCount = 0;
    314             for (int fillY = 0; fillY < source.height() / 16; ++fillY) {
    315                 for (int fillX = 0; fillX < source.width() / 16; ++fillX) {
    316                     const SkColor color = SkUnPreMultiply::PMColorToColor(blockStart[fillX]);
    317                     transparentCount += SkColorGetA(color) == SK_AlphaTRANSPARENT;
    318                 }
    319                 blockStart += source.width();
    320             }
    321             if (transparentCount > 200) {
    322                 blockStart = &srcPixels.front() + y * source.width() * 16 + x * 16;
    323                 for (int fillY = 0; fillY < source.height() / 16; ++fillY) {
    324                     for (int fillX = 0; fillX < source.width() / 16; ++fillX) {
    325                         blockStart[fillX] = SK_ColorRED;
    326                     }
    327                     blockStart += source.width();
    328                 }
    329             }
    330         }
    331     }
    332     SkBitmap bitmap;
    333     bitmap.installPixels(pixmap);
    334     canvas->drawBitmap(bitmap, 0, 0);
    335 ##
    336 
    337 
    338 # ------------------------------------------------------------------------------
    339 
    340 #Example
    341 #Image 1
    342 #Height 128
    343 #Description
    344 Color the parts of the bitmap green if they contain fully opaque pixels.
    345 ##
    346     std::vector<int32_t> srcPixels;
    347     srcPixels.resize(source.height() * source.rowBytes());
    348     SkPixmap pixmap(SkImageInfo::MakeN32Premul(source.width(), source.height()),
    349                     &srcPixels.front(), source.rowBytes());
    350     source.readPixels(pixmap, 0, 0);
    351     for (int y = 0; y < source.height(); ++y) {
    352         for (int x = 0; x < source.width(); ++x) {
    353             SkPMColor pixel = srcPixels[y * source.width() + x];
    354             const SkColor color = SkUnPreMultiply::PMColorToColor(pixel);
    355             if (SkColorGetA(color) == SK_AlphaOPAQUE) {
    356                 srcPixels[y * source.width() + x] = SK_ColorGREEN;
    357             }
    358         }
    359     }
    360     SkBitmap bitmap;
    361     bitmap.installPixels(pixmap);
    362     canvas->drawBitmap(bitmap, 0, 0);
    363 ##
    364 
    365 #SeeAlso SkAlpha SK_ColorTRANSPARENT SK_ColorBLACK
    366 
    367 #Subtopic Alpha_Constants ##
    368 
    369 #Subtopic Color_Constants
    370 #In Constant
    371 #Line # constants for Color ##
    372 #Filter SK_Color
    373 
    374 #Code
    375 #Populate
    376 ##
    377 
    378 Color names are provided as conveniences, but are not otherwise special.
    379 The values chosen for names may not be the same as values used by
    380 SVG, HTML, CSS, or colors named by a platform.
    381 
    382 #Const SK_ColorTRANSPARENT 0x00000000
    383 #Line # transparent Color ##
    384     Represents fully transparent SkColor. May be used to initialize a destination
    385     containing a mask or a non-rectangular image.
    386 ##
    387 #Const SK_ColorBLACK 0xFF000000
    388 #Line # black Color ##
    389     Represents fully opaque black.
    390 ##
    391 #Const SK_ColorDKGRAY 0xFF444444
    392 #Line # dark gray Color ##
    393     Represents fully opaque dark gray.
    394     Note that SVG_darkgray is equivalent to 0xFFA9A9A9.
    395 ##
    396 #Const SK_ColorGRAY 0xFF888888
    397 #Line # gray Color ##
    398     Represents fully opaque gray.
    399     Note that HTML_Gray is equivalent to 0xFF808080.
    400 ##
    401 #Const SK_ColorLTGRAY 0xFFCCCCCC
    402 #Line # light gray Color ##
    403     Represents fully opaque light gray. HTML_Silver is equivalent to 0xFFC0C0C0.
    404     Note that SVG_lightgray is equivalent to 0xFFD3D3D3.
    405 ##
    406 #Const SK_ColorWHITE 0xFFFFFFFF
    407 #Line # white Color ##
    408     Represents fully opaque white.
    409 ##
    410 #Const SK_ColorRED 0xFFFF0000
    411 #Line # red Color ##
    412     Represents fully opaque red.
    413 ##
    414 #Const SK_ColorGREEN 0xFF00FF00
    415 #Line # green Color ##
    416     Represents fully opaque green. HTML_Lime is equivalent.
    417     Note that HTML_Green is equivalent to 0xFF008000.
    418 ##
    419 #Const SK_ColorBLUE 0xFF0000FF
    420 #Line # blue Color ##
    421     Represents fully opaque blue.
    422 ##
    423 #Const SK_ColorYELLOW 0xFFFFFF00
    424 #Line # yellow Color ##
    425     Represents fully opaque yellow.
    426 ##
    427 #Const SK_ColorCYAN 0xFF00FFFF
    428 #Line # cyan Color ##
    429     Represents fully opaque cyan. HTML_Aqua is equivalent.
    430 ##
    431 #Const SK_ColorMAGENTA 0xFFFF00FF
    432 #Line # magenta Color ##
    433     Represents fully opaque magenta. HTML_Fuchsia is equivalent.
    434 ##
    435 
    436 #Example
    437 ###$
    438 $Function
    439 #define SKIA_COLOR_PAIR(name) "SK_Color" #name, SK_Color##name
    440 $$
    441 void draw(SkCanvas* canvas) {
    442     struct ColorCompare {
    443         const char* fSVGName;
    444         SkColor fSVGColor;
    445         const char* fSkiaName;
    446         SkColor fSkiaColor;
    447     } colorCompare[] = {  // see https://www.w3.org/TR/SVG/types.html#ColorKeywords
    448         {"black",     SkColorSetRGB(  0,   0,   0),    SKIA_COLOR_PAIR(BLACK) },
    449         {"darkgray",  SkColorSetRGB(169, 169, 169),    SKIA_COLOR_PAIR(DKGRAY) },
    450         {"gray",      SkColorSetRGB(128, 128, 128),    SKIA_COLOR_PAIR(GRAY) },
    451         {"lightgray", SkColorSetRGB(211, 211, 211),    SKIA_COLOR_PAIR(LTGRAY) },
    452         {"white",     SkColorSetRGB(255, 255, 255),    SKIA_COLOR_PAIR(WHITE) },
    453         {"red",       SkColorSetRGB(255,   0,   0),    SKIA_COLOR_PAIR(RED) },
    454         {"green",     SkColorSetRGB(  0, 128,   0),    SKIA_COLOR_PAIR(GREEN) },
    455         {"blue",      SkColorSetRGB(  0,   0, 255),    SKIA_COLOR_PAIR(BLUE) },
    456         {"yellow",    SkColorSetRGB(255, 255,   0),    SKIA_COLOR_PAIR(YELLOW) },
    457         {"aqua",      SkColorSetRGB(  0, 255, 255),    SKIA_COLOR_PAIR(CYAN) },
    458         {"fuchsia",   SkColorSetRGB(255,   0, 255),    SKIA_COLOR_PAIR(MAGENTA) },
    459     };
    460     SkPaint paint;
    461     paint.setAntiAlias(true);
    462     paint.setTextSize(14);
    463     for (auto compare : colorCompare) {
    464         paint.setStyle(SkPaint::kFill_Style);
    465         paint.setColor(compare.fSVGColor);
    466         canvas->drawRect({5, 5, 15, 15}, paint);
    467         paint.setColor(SK_ColorBLACK);
    468         canvas->drawString(compare.fSVGName, 20, 16, paint);
    469         paint.setColor(compare.fSkiaColor);
    470         canvas->drawRect({105, 5, 115, 15}, paint);
    471         paint.setColor(SK_ColorBLACK);
    472         canvas->drawString(compare.fSkiaName, 120, 16, paint);
    473         paint.setStyle(SkPaint::kStroke_Style);
    474         canvas->drawRect({5, 5, 15, 15}, paint);
    475         canvas->drawRect({105, 5, 115, 15}, paint);
    476         canvas->translate(0, 20);
    477     }
    478 }
    479 $$$#
    480 ##
    481 
    482 #Example
    483 #Description
    484 SK_ColorTRANSPARENT sets Color Alpha and components to zero.
    485 ##
    486 #Image 3
    487     std::vector<uint32_t> srcPixels;
    488     constexpr int width = 256;
    489     constexpr int height = 256;
    490     srcPixels.resize(width * height);
    491     SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(width, height);
    492     SkPixmap pixmap(imageInfo, &srcPixels.front(), imageInfo.minRowBytes());
    493     pixmap.erase(SK_ColorTRANSPARENT);
    494     pixmap.erase(SK_ColorRED, { 24, 24, 192, 192 } );
    495     pixmap.erase(SK_ColorTRANSPARENT, { 48, 48, 168, 168 } );
    496     SkBitmap bitmap;
    497     bitmap.installPixels(pixmap);
    498     canvas->drawBitmap(bitmap, 0, 0);
    499     canvas->drawBitmap(bitmap, 48, 48);
    500 ##
    501 
    502 #Example
    503 #Description
    504 SK_ColorBLACK sets Color Alpha to one and components to zero.
    505 ##
    506     std::vector<uint32_t> srcPixels;
    507     constexpr int width = 256;
    508     constexpr int height = 256;
    509     srcPixels.resize(width * height);
    510     SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(width, height);
    511     SkPixmap pixmap(imageInfo, &srcPixels.front(), imageInfo.minRowBytes());
    512     pixmap.erase(SK_ColorTRANSPARENT);
    513     pixmap.erase(SK_ColorRED, { 24, 24, 192, 192 } );
    514     pixmap.erase(SK_ColorBLACK, { 48, 48, 168, 168 } );
    515     SkBitmap bitmap;
    516     bitmap.installPixels(pixmap);
    517     canvas->drawBitmap(bitmap, 0, 0);
    518     canvas->drawBitmap(bitmap, 48, 48);
    519 ##
    520 
    521 #Example
    522 #Description
    523 SK_ColorWHITE sets Color Alpha and components to one.
    524 ##
    525     std::vector<uint32_t> srcPixels;
    526     constexpr int width = 256;
    527     constexpr int height = 256;
    528     srcPixels.resize(width * height);
    529     SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(width, height);
    530     SkPixmap pixmap(imageInfo, &srcPixels.front(), imageInfo.minRowBytes());
    531     pixmap.erase(SK_ColorTRANSPARENT);
    532     pixmap.erase(SK_ColorRED, { 24, 24, 192, 192 } );
    533     pixmap.erase(SK_ColorWHITE, { 48, 48, 168, 168 } );
    534     SkBitmap bitmap;
    535     bitmap.installPixels(pixmap);
    536     canvas->drawBitmap(bitmap, 0, 0);
    537     canvas->drawBitmap(bitmap, 48, 48);
    538 ##
    539 
    540 #SeeAlso SK_ColorTRANSPARENT SkCanvas::clear SK_AlphaOPAQUE
    541 
    542 #Subtopic Color_Constants ##
    543 
    544 # ------------------------------------------------------------------------------
    545 
    546 #Subtopic HSV
    547 #Line # hue saturation value color representation ##
    548 
    549 #Subtopic Hue
    550 Hue represents an angle, in degrees, on a color wheel. Hue has a positive value
    551 modulo 360, where zero degrees is red.
    552 ##
    553 
    554 #Subtopic Saturation
    555 Saturation represents the intensity of the color. Saturation varies from zero,
    556 with no Hue contribution; to one, with full Hue contribution.
    557 ##
    558 
    559 #Subtopic Value
    560 Value represents the lightness of the color. Value varies from zero, black; to
    561 one, full brightness.
    562 ##
    563 
    564 #Method void SkRGBToHSV(U8CPU red, U8CPU green, U8CPU blue, SkScalar hsv[3])
    565 #In Functions
    566 #Line # converts RGB to HSV ##
    567 
    568 Converts RGB to its HSV components.
    569 hsv[0] contains HSV_Hue, a value from zero to less than 360.
    570 hsv[1] contains HSV_Saturation, a value from zero to one.
    571 hsv[2] contains HSV_Value, a value from zero to one.
    572 
    573 #Param red  red component value from zero to 255 ##
    574 #Param green  green component value from zero to 255 ##
    575 #Param blue  blue component value from zero to 255 ##
    576 #Param hsv  three element array which holds the resulting HSV components
    577 ##
    578 
    579 #Example
    580 #Image 3
    581    canvas->drawBitmap(source, 0, 0);
    582    SkPaint bgPaint;
    583    bgPaint.setColor(0xafffffff);
    584    canvas->drawRect({20, 30, 110, 90}, bgPaint);
    585    SkScalar hsv[3];
    586    SkColor c = source.getColor(226, 128);
    587    SkRGBToHSV(SkColorGetR(c), SkColorGetG(c), SkColorGetB(c), hsv);
    588    canvas->drawString(("h: " + std::to_string(hsv[0]).substr(0, 6)).c_str(), 27, 45, SkPaint());
    589    canvas->drawString(("s: " + std::to_string(hsv[1]).substr(0, 6)).c_str(), 27, 65, SkPaint());
    590    canvas->drawString(("v: " + std::to_string(hsv[2]).substr(0, 6)).c_str(), 27, 85, SkPaint());
    591    canvas->drawLine(110, 90, 226, 128, SkPaint());
    592 ##
    593 
    594 #SeeAlso SkColorToHSV SkHSVToColor
    595 
    596 #Method ##
    597 
    598 # ------------------------------------------------------------------------------
    599 
    600 #Method static void SkColorToHSV(SkColor color, SkScalar hsv[3])
    601 #In Functions
    602 #Line # converts RGB to HSV ##
    603 
    604 Converts ARGB to its HSV components. Alpha in ARGB is ignored.
    605 hsv[0] contains HSV_Hue, and is assigned a value from zero to less than 360.
    606 hsv[1] contains HSV_Saturation, a value from zero to one.
    607 hsv[2] contains HSV_Value, a value from zero to one.
    608 
    609 #Param color  ARGB color to convert
    610 ##
    611 #Param hsv  three element array which holds the resulting HSV components
    612 ##
    613 
    614 #Example
    615 #Image 3
    616    canvas->drawBitmap(source, 0, 0);
    617    for (int y = 0; y < 256; ++y) {
    618       for (int x = 0; x < 256; ++x) {
    619         SkScalar hsv[3];
    620         SkColorToHSV(source.getColor(x, y), hsv);
    621         hsv[1] = 1 - hsv[1];
    622         SkPaint paint;
    623         paint.setColor(SkHSVToColor(hsv));
    624         canvas->drawRect(SkRect::MakeXYWH(x, y, 1, 1), paint);
    625      }
    626    }
    627 ##
    628 
    629 #SeeAlso SkRGBToHSV SkHSVToColor
    630 
    631 #Method ##
    632 
    633 # ------------------------------------------------------------------------------
    634 
    635 #Method SkColor SkHSVToColor(U8CPU alpha, const SkScalar hsv[3])
    636 #In Functions
    637 #Line # converts HSV with Alpha to RGB ##
    638 
    639 Converts HSV components to an ARGB color. Alpha is passed through unchanged.
    640 hsv[0] represents HSV_Hue, an angle from zero to less than 360.
    641 hsv[1] represents HSV_Saturation, and varies from zero to one.
    642 hsv[2] represents HSV_Value, and varies from zero to one.
    643 
    644 Out of range hsv values are pinned.
    645 
    646 #Param alpha  Alpha component of the returned ARGB color
    647 ##
    648 #Param hsv  three element array which holds the input HSV components
    649 ##
    650 
    651 #Return  ARGB equivalent to HSV
    652 ##
    653 
    654 #Example
    655 #Image 3
    656    canvas->drawBitmap(source, 0, 0);
    657    for (int y = 0; y < 256; ++y) {
    658       for (int x = 0; x < 256; ++x) {
    659         SkColor color = source.getColor(x, y);
    660         SkScalar hsv[3];
    661         SkColorToHSV(color, hsv);
    662         hsv[0] = hsv[0] + 90 >= 360 ? hsv[0] - 270 : hsv[0] + 90;
    663         SkPaint paint;
    664         paint.setColor(SkHSVToColor(x + y, hsv));
    665         canvas->drawRect(SkRect::MakeXYWH(x, y, 1, 1), paint);
    666      }
    667    }
    668 ##
    669 
    670 #SeeAlso SkColorToHSV SkRGBToHSV
    671 
    672 #Method ##
    673 
    674 # ------------------------------------------------------------------------------
    675 
    676 #Method static SkColor SkHSVToColor(const SkScalar hsv[3])
    677 #In Functions
    678 #Line # converts HSV to RGB ##
    679 
    680 Converts HSV components to an ARGB color. Alpha is set to 255.
    681 hsv[0] represents HSV_Hue, an angle from zero to less than 360.
    682 hsv[1] represents HSV_Saturation, and varies from zero to one.
    683 hsv[2] represents HSV_Value, and varies from zero to one.
    684 
    685 Out of range hsv values are pinned.
    686 
    687 #Param hsv  three element array which holds the input HSV components
    688 ##
    689 
    690 #Return  RGB equivalent to HSV
    691 ##
    692 
    693 #Example
    694 #Image 3
    695    canvas->drawBitmap(source, 0, 0);
    696    for (int y = 0; y < 256; ++y) {
    697       for (int x = 0; x < 256; ++x) {
    698         SkColor color = source.getColor(x, y);
    699         SkScalar hsv[3];
    700         SkColorToHSV(color, hsv);
    701         hsv[0] = hsv[0] + 90 >= 360 ? hsv[0] - 270 : hsv[0] + 90;
    702         SkPaint paint;
    703         paint.setColor(SkHSVToColor(hsv));
    704         canvas->drawRect(SkRect::MakeXYWH(x, y, 1, 1), paint);
    705      }
    706    }
    707 ##
    708 
    709 #SeeAlso SkColorToHSV SkRGBToHSV
    710 
    711 #Method ##
    712 
    713 #Subtopic HSV ##
    714 
    715 # ------------------------------------------------------------------------------
    716 
    717 #Subtopic PM_Color
    718 #Line # color components premultiplied by Alpha ##
    719 
    720 #Typedef uint32_t SkPMColor
    721 #Line # defines Premultiplied Color as 32 bits ##
    722 
    723 #Code
    724 #Populate
    725 ##
    726 
    727 32-bit ARGB color value, Premultiplied. The byte order for this value is
    728 configuration dependent, matching the format of kBGRA_8888_SkColorType bitmaps.
    729 This is different from SkColor, which is Unpremultiplied, and is always in the
    730 same byte order.
    731 
    732 #Typedef ##
    733 
    734 # ------------------------------------------------------------------------------
    735 
    736 #Method SkPMColor SkPreMultiplyARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
    737 #In Functions
    738 #Line # converts Unpremultiplied ARGB to Premultiplied PM_Color ##
    739 
    740 Returns a SkPMColor value from Unpremultiplied 8-bit component values.
    741 
    742 #Param a    amount of Alpha, from fully transparent (0) to fully opaque (255) ##
    743 #Param r    amount of red, from no red (0) to full red (255) ##
    744 #Param g    amount of green, from no green (0) to full green (255) ##
    745 #Param b    amount of blue, from no blue (0) to full blue (255) ##
    746 
    747 #Return Premultiplied Color ##
    748 
    749 #Example
    750 #Height 128
    751 #Width 300
    752     SkPMColor premultiplied = SkPreMultiplyARGB(160, 128, 160, 192);
    753     canvas->drawString("Unpremultiplied:", 20, 20, SkPaint());
    754     canvas->drawString("alpha=160 red=128 green=160 blue=192", 20, 40, SkPaint());
    755     canvas->drawString("Premultiplied:", 20, 80, SkPaint());
    756     std::string str = "alpha=" + std::to_string(SkColorGetA(premultiplied));
    757     str += " red=" + std::to_string(SkColorGetR(premultiplied));
    758     str += " green=" + std::to_string(SkColorGetG(premultiplied));
    759     str += " blue=" + std::to_string(SkColorGetB(premultiplied));
    760     canvas->drawString(str.c_str(), 20, 100, SkPaint());
    761 ##
    762 
    763 #SeeAlso SkPreMultiplyColor
    764 
    765 #Method ##
    766 
    767 # ------------------------------------------------------------------------------
    768 
    769 #Method SkPMColor SkPreMultiplyColor(SkColor c)
    770 #In Functions
    771 #Line # converts Unpremultiplied Color to Premultiplied PM_Color ##
    772 
    773 Returns PM_Color closest to Color c. Multiplies c RGB components by the c Alpha,
    774 and arranges the bytes to match the format of kN32_SkColorType.
    775 
    776 #Param c  Unpremultiplied ARGB Color  ##
    777 
    778 #Return Premultiplied Color ##
    779 
    780 #Example
    781 #Height 128
    782 #Width 300
    783     SkColor unpremultiplied = SkColorSetARGB(160, 128, 160, 192);
    784     SkPMColor premultiplied = SkPreMultiplyColor(unpremultiplied);
    785     canvas->drawString("Unpremultiplied:", 20, 20, SkPaint());
    786     std::string str = "alpha=" + std::to_string(SkColorGetA(unpremultiplied));
    787     str += " red=" + std::to_string(SkColorGetR(unpremultiplied));
    788     str += " green=" + std::to_string(SkColorGetG(unpremultiplied));
    789     str += " blue=" + std::to_string(SkColorGetB(unpremultiplied));
    790     canvas->drawString(str.c_str(), 20, 40, SkPaint());
    791     canvas->drawString("Premultiplied:", 20, 80, SkPaint());
    792     str = "alpha=" + std::to_string(SkColorGetA(premultiplied));
    793     str += " red=" + std::to_string(SkColorGetR(premultiplied));
    794     str += " green=" + std::to_string(SkColorGetG(premultiplied));
    795     str += " blue=" + std::to_string(SkColorGetB(premultiplied));
    796     canvas->drawString(str.c_str(), 20, 100, SkPaint());
    797 ##
    798 
    799 #SeeAlso SkPreMultiplyARGB
    800 
    801 #Method ##
    802 
    803 #Subtopic PM_Color ##
    804 
    805 #Topic Color ##
    806