skia2/docs/SkColor_Reference.bmh

806 lines
24 KiB
Plaintext
Raw Normal View History

#Topic Color
#Alias Color_Reference ##
#Code
#Populate
##
Color constants can be helpful to write code, documenting the meaning of values
the represent transparency and color values. The use of Color constants is not
required.
#Subtopic Functions
#Line # routines to read, write, and manipulate SkColor ##
##
# ------------------------------------------------------------------------------
#Subtopic Alpha
#Line # transparency of Color ##
Alpha represents the transparency of Color. Color with Alpha of zero is fully
transparent. Color with Alpha of 255 is fully opaque. Some, but not all pixel
formats contain Alpha. Pixels with Alpha may store it as unsigned integers or
floating point values. Unsigned integer Alpha ranges from zero, fully
transparent, to all bits set, fully opaque. Floating point Alpha ranges from
zero, fully transparent, to one, fully opaque.
#Alias Alpha
#Substitute alpha
##
#Typedef uint8_t SkAlpha
#Line # defines Alpha as eight bits ##
#Code
#Populate
##
8-bit type for an alpha value. 255 is 100% opaque, zero is 100% transparent.
#Typedef ##
#Subtopic ##
# ------------------------------------------------------------------------------
#Typedef uint32_t SkColor
#Line # defines Color as 32 bits ##
#Code
#Populate
##
32-bit ARGB Color value, Unpremultiplied. Color components are always in
a known order. This is different from SkPMColor, which has its bytes in a configuration
dependent order, to match the format of kBGRA_8888_SkColorType bitmaps. SkColor
is the type used to specify colors in SkPaint and in gradients.
Color that is Premultiplied has the same component values as Color
that is Unpremultiplied if Alpha is 255, fully opaque, although may have the
component values in a different order.
#SeeAlso SkPMColor
#Typedef ##
# ------------------------------------------------------------------------------
#Method static constexpr inline SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
#In Functions
#Line # returns Color_Alpha and RGB combined ##
Returns Color value from 8-bit component values. Asserts if SK_DEBUG is defined
if a, r, g, or b exceed 255. Since Color is Unpremultiplied, a may be smaller
than the largest of r, g, and b.
#Param a amount of Alpha, from fully transparent (0) to fully opaque (255) ##
#Param r amount of red, from no red (0) to full red (255) ##
#Param g amount of green, from no green (0) to full green (255) ##
#Param b amount of blue, from no blue (0) to full blue (255) ##
#Return color and alpha, Unpremultiplied ##
#Example
canvas->drawColor(SK_ColorRED);
canvas->clipRect(SkRect::MakeWH(150, 150));
canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0xFF, 0x00));
canvas->clipRect(SkRect::MakeWH(75, 75));
canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0x00, 0xFF));
##
#SeeAlso SkColorSetRGB SkPaint::setARGB SkPaint::setColor SkColorSetA
#Method ##
# ------------------------------------------------------------------------------
#Define SkColorSetRGB
#Line # returns opaque Color ##
#Code
#Populate
##
Returns Color value from 8-bit component values, with Alpha set
fully opaque to 255.
#Param r amount of red, from no red (0) to full red (255) ##
#Param g amount of green, from no green (0) to full green (255) ##
#Param b amount of blue, from no blue (0) to full blue (255) ##
#Return color with opaque alpha ##
#Example
canvas->drawColor(SK_ColorRED);
canvas->clipRect(SkRect::MakeWH(150, 150));
canvas->drawColor(SkColorSetRGB(0x00, 0xFF, 0x00));
canvas->clipRect(SkRect::MakeWH(75, 75));
canvas->drawColor(SkColorSetRGB(0x00, 0x00, 0xFF));
##
#SeeAlso SkColorSetARGB
#Define ##
# ------------------------------------------------------------------------------
#Define SkColorGetA
#Line # returns Alpha component ##
#Code
#Populate
##
Returns Alpha byte from Color value.
#Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
#Example
SkPaint paint;
paint.setAntiAlias(true);
paint.setColor(SK_ColorRED);
for (int alpha = 255; alpha >= 0; alpha -= 17) {
paint.setAlpha(alpha);
canvas->drawRect({5, 5, 100, 20}, paint);
SkAlpha alphaInPaint = SkColorGetA(paint.getColor());
canvas->drawString(std::to_string(alphaInPaint).c_str(), 110, 18, paint);
canvas->translate(0, 15);
}
##
#SeeAlso SkPaint::getAlpha
#Define ##
# ------------------------------------------------------------------------------
#Define SkColorGetR
#Line # returns red component ##
#Code
#Populate
##
Returns red component of Color, from zero to 255.
#Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
#Return red byte ##
#Example
#Image 3
canvas->drawBitmap(source, 0, 0);
SkPaint bgPaint;
bgPaint.setColor(0xafffffff);
canvas->drawRect({20, 50, 80, 70}, bgPaint);
uint8_t red = SkColorGetR(source.getColor(226, 128));
canvas->drawString(std::to_string(red).c_str(), 40, 65, SkPaint());
canvas->drawLine(80, 70, 226, 128, SkPaint());
##
#SeeAlso SkColorGetG SkColorGetB
#Define ##
# ------------------------------------------------------------------------------
#Define SkColorGetG
#Line # returns green component ##
#Code
#Populate
##
Returns green component of Color, from zero to 255.
#Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
#Return green byte ##
#Example
#Image 3
canvas->drawBitmap(source, 0, 0);
SkPaint bgPaint;
bgPaint.setColor(0xafffffff);
canvas->drawRect({20, 50, 80, 70}, bgPaint);
uint8_t green = SkColorGetG(source.getColor(57, 192));
canvas->drawString(std::to_string(green).c_str(), 40, 65, SkPaint());
canvas->drawLine(80, 70, 57, 192, SkPaint());
##
#SeeAlso SkColorGetR SkColorGetB
#Define ##
# ------------------------------------------------------------------------------
#Define SkColorGetB
#Line # returns blue component ##
#Code
#Populate
##
Returns blue component of Color, from zero to 255.
#Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
#Return blue byte ##
#Example
#Image 3
canvas->drawBitmap(source, 0, 0);
SkPaint bgPaint;
bgPaint.setColor(0xafffffff);
canvas->drawRect({20, 50, 80, 70}, bgPaint);
uint8_t blue = SkColorGetB(source.getColor(168, 170));
canvas->drawString(std::to_string(blue).c_str(), 40, 65, SkPaint());
canvas->drawLine(80, 70, 168, 170, SkPaint());
##
#SeeAlso SkColorGetR SkColorGetG
#Define ##
# ------------------------------------------------------------------------------
#Method static constexpr inline SkColor SkColorSetA(SkColor c, U8CPU a)
#In Functions
#Line # returns Color with transparency ##
Returns Unpremultiplied Color with red, blue, and green set from c; and alpha set
from a. Alpha component of c is ignored and is replaced by a in result.
#Param c packed RGB, eight bits per component ##
#Param a Alpha: transparent at zero, fully opaque at 255 ##
#Return Color with transparency ##
#Example
#Image 3
canvas->drawBitmap(source, 0, 0);
for (int y = 0; y < 256; y += 16) {
for (int x = 0; x < 256; x += 16) {
SkColor color = source.getColor(x + 8, y + 8);
SkPaint paint;
paint.setColor(SkColorSetA(color, x + y));
canvas->drawRect(SkRect::MakeXYWH(x, y, 16, 16), paint);
}
}
##
#SeeAlso SkColorSetARGB
#Method ##
# ------------------------------------------------------------------------------
#Subtopic Alpha_Constants
#In Constant
#Line # constants for Alpha ##
#Filter SK_Alpha
#Code
#Populate
##
Alpha constants are conveniences to represent fully transparent and fully
opaque colors and masks. Their use is not required.
#Const SK_AlphaTRANSPARENT 0x00
#Line # fully transparent SkAlpha ##
Represents fully transparent SkAlpha value. SkAlpha ranges from zero,
fully transparent; to 255, fully opaque.
##
#Const SK_AlphaOPAQUE 0xFF
#Line # fully opaque SkAlpha ##
Represents fully opaque SkAlpha value. SkAlpha ranges from zero,
fully transparent; to 255, fully opaque.
##
#Example
#Image 1
#Height 128
#Description
Color the parts of the bitmap red if they mostly contain transparent pixels.
##
std::vector<int32_t> srcPixels;
srcPixels.resize(source.height() * source.rowBytes());
SkPixmap pixmap(SkImageInfo::MakeN32Premul(source.width(), source.height()),
&srcPixels.front(), source.rowBytes());
source.readPixels(pixmap, 0, 0);
for (int y = 0; y < 16; ++y) {
for (int x = 0; x < 16; ++x) {
int32_t* blockStart = &srcPixels.front() + y * source.width() * 16 + x * 16;
size_t transparentCount = 0;
for (int fillY = 0; fillY < source.height() / 16; ++fillY) {
for (int fillX = 0; fillX < source.width() / 16; ++fillX) {
const SkColor color = SkUnPreMultiply::PMColorToColor(blockStart[fillX]);
transparentCount += SkColorGetA(color) == SK_AlphaTRANSPARENT;
}
blockStart += source.width();
}
if (transparentCount > 200) {
blockStart = &srcPixels.front() + y * source.width() * 16 + x * 16;
for (int fillY = 0; fillY < source.height() / 16; ++fillY) {
for (int fillX = 0; fillX < source.width() / 16; ++fillX) {
blockStart[fillX] = SK_ColorRED;
}
blockStart += source.width();
}
}
}
}
SkBitmap bitmap;
bitmap.installPixels(pixmap);
canvas->drawBitmap(bitmap, 0, 0);
##
# ------------------------------------------------------------------------------
#Example
#Image 1
#Height 128
#Description
Color the parts of the bitmap green if they contain fully opaque pixels.
##
std::vector<int32_t> srcPixels;
srcPixels.resize(source.height() * source.rowBytes());
SkPixmap pixmap(SkImageInfo::MakeN32Premul(source.width(), source.height()),
&srcPixels.front(), source.rowBytes());
source.readPixels(pixmap, 0, 0);
for (int y = 0; y < source.height(); ++y) {
for (int x = 0; x < source.width(); ++x) {
SkPMColor pixel = srcPixels[y * source.width() + x];
const SkColor color = SkUnPreMultiply::PMColorToColor(pixel);
if (SkColorGetA(color) == SK_AlphaOPAQUE) {
srcPixels[y * source.width() + x] = SK_ColorGREEN;
}
}
}
SkBitmap bitmap;
bitmap.installPixels(pixmap);
canvas->drawBitmap(bitmap, 0, 0);
##
#SeeAlso SkAlpha SK_ColorTRANSPARENT SK_ColorBLACK
#Subtopic Alpha_Constants ##
#Subtopic Color_Constants
#In Constant
#Line # constants for Color ##
#Filter SK_Color
#Code
#Populate
##
Color names are provided as conveniences, but are not otherwise special.
The values chosen for names may not be the same as values used by
SVG, HTML, CSS, or colors named by a platform.
#Const SK_ColorTRANSPARENT 0x00000000
#Line # transparent Color ##
Represents fully transparent SkColor. May be used to initialize a destination
containing a mask or a non-rectangular image.
##
#Const SK_ColorBLACK 0xFF000000
#Line # black Color ##
Represents fully opaque black.
##
#Const SK_ColorDKGRAY 0xFF444444
#Line # dark gray Color ##
Represents fully opaque dark gray.
Note that SVG_darkgray is equivalent to 0xFFA9A9A9.
##
#Const SK_ColorGRAY 0xFF888888
#Line # gray Color ##
Represents fully opaque gray.
Note that HTML_Gray is equivalent to 0xFF808080.
##
#Const SK_ColorLTGRAY 0xFFCCCCCC
#Line # light gray Color ##
Represents fully opaque light gray. HTML_Silver is equivalent to 0xFFC0C0C0.
Note that SVG_lightgray is equivalent to 0xFFD3D3D3.
##
#Const SK_ColorWHITE 0xFFFFFFFF
#Line # white Color ##
Represents fully opaque white.
##
#Const SK_ColorRED 0xFFFF0000
#Line # red Color ##
Represents fully opaque red.
##
#Const SK_ColorGREEN 0xFF00FF00
#Line # green Color ##
Represents fully opaque green. HTML_Lime is equivalent.
Note that HTML_Green is equivalent to 0xFF008000.
##
#Const SK_ColorBLUE 0xFF0000FF
#Line # blue Color ##
Represents fully opaque blue.
##
#Const SK_ColorYELLOW 0xFFFFFF00
#Line # yellow Color ##
Represents fully opaque yellow.
##
#Const SK_ColorCYAN 0xFF00FFFF
#Line # cyan Color ##
Represents fully opaque cyan. HTML_Aqua is equivalent.
##
#Const SK_ColorMAGENTA 0xFFFF00FF
#Line # magenta Color ##
Represents fully opaque magenta. HTML_Fuchsia is equivalent.
##
#Example
###$
$Function
#define SKIA_COLOR_PAIR(name) "SK_Color" #name, SK_Color##name
$$
void draw(SkCanvas* canvas) {
struct ColorCompare {
const char* fSVGName;
SkColor fSVGColor;
const char* fSkiaName;
SkColor fSkiaColor;
} colorCompare[] = { // see https://www.w3.org/TR/SVG/types.html#ColorKeywords
{"black", SkColorSetRGB( 0, 0, 0), SKIA_COLOR_PAIR(BLACK) },
{"darkgray", SkColorSetRGB(169, 169, 169), SKIA_COLOR_PAIR(DKGRAY) },
{"gray", SkColorSetRGB(128, 128, 128), SKIA_COLOR_PAIR(GRAY) },
{"lightgray", SkColorSetRGB(211, 211, 211), SKIA_COLOR_PAIR(LTGRAY) },
{"white", SkColorSetRGB(255, 255, 255), SKIA_COLOR_PAIR(WHITE) },
{"red", SkColorSetRGB(255, 0, 0), SKIA_COLOR_PAIR(RED) },
{"green", SkColorSetRGB( 0, 128, 0), SKIA_COLOR_PAIR(GREEN) },
{"blue", SkColorSetRGB( 0, 0, 255), SKIA_COLOR_PAIR(BLUE) },
{"yellow", SkColorSetRGB(255, 255, 0), SKIA_COLOR_PAIR(YELLOW) },
{"aqua", SkColorSetRGB( 0, 255, 255), SKIA_COLOR_PAIR(CYAN) },
{"fuchsia", SkColorSetRGB(255, 0, 255), SKIA_COLOR_PAIR(MAGENTA) },
};
SkPaint paint;
paint.setAntiAlias(true);
paint.setTextSize(14);
for (auto compare : colorCompare) {
paint.setStyle(SkPaint::kFill_Style);
paint.setColor(compare.fSVGColor);
canvas->drawRect({5, 5, 15, 15}, paint);
paint.setColor(SK_ColorBLACK);
canvas->drawString(compare.fSVGName, 20, 16, paint);
paint.setColor(compare.fSkiaColor);
canvas->drawRect({105, 5, 115, 15}, paint);
paint.setColor(SK_ColorBLACK);
canvas->drawString(compare.fSkiaName, 120, 16, paint);
paint.setStyle(SkPaint::kStroke_Style);
canvas->drawRect({5, 5, 15, 15}, paint);
canvas->drawRect({105, 5, 115, 15}, paint);
canvas->translate(0, 20);
}
}
$$$#
##
#Example
#Description
SK_ColorTRANSPARENT sets Color Alpha and components to zero.
##
#Image 3
std::vector<uint32_t> srcPixels;
constexpr int width = 256;
constexpr int height = 256;
srcPixels.resize(width * height);
SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(width, height);
SkPixmap pixmap(imageInfo, &srcPixels.front(), imageInfo.minRowBytes());
pixmap.erase(SK_ColorTRANSPARENT);
pixmap.erase(SK_ColorRED, { 24, 24, 192, 192 } );
pixmap.erase(SK_ColorTRANSPARENT, { 48, 48, 168, 168 } );
SkBitmap bitmap;
bitmap.installPixels(pixmap);
canvas->drawBitmap(bitmap, 0, 0);
canvas->drawBitmap(bitmap, 48, 48);
##
#Example
#Description
SK_ColorBLACK sets Color Alpha to one and components to zero.
##
std::vector<uint32_t> srcPixels;
constexpr int width = 256;
constexpr int height = 256;
srcPixels.resize(width * height);
SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(width, height);
SkPixmap pixmap(imageInfo, &srcPixels.front(), imageInfo.minRowBytes());
pixmap.erase(SK_ColorTRANSPARENT);
pixmap.erase(SK_ColorRED, { 24, 24, 192, 192 } );
pixmap.erase(SK_ColorBLACK, { 48, 48, 168, 168 } );
SkBitmap bitmap;
bitmap.installPixels(pixmap);
canvas->drawBitmap(bitmap, 0, 0);
canvas->drawBitmap(bitmap, 48, 48);
##
#Example
#Description
SK_ColorWHITE sets Color Alpha and components to one.
##
std::vector<uint32_t> srcPixels;
constexpr int width = 256;
constexpr int height = 256;
srcPixels.resize(width * height);
SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(width, height);
SkPixmap pixmap(imageInfo, &srcPixels.front(), imageInfo.minRowBytes());
pixmap.erase(SK_ColorTRANSPARENT);
pixmap.erase(SK_ColorRED, { 24, 24, 192, 192 } );
pixmap.erase(SK_ColorWHITE, { 48, 48, 168, 168 } );
SkBitmap bitmap;
bitmap.installPixels(pixmap);
canvas->drawBitmap(bitmap, 0, 0);
canvas->drawBitmap(bitmap, 48, 48);
##
#SeeAlso SK_ColorTRANSPARENT SkCanvas::clear SK_AlphaOPAQUE
#Subtopic Color_Constants ##
# ------------------------------------------------------------------------------
#Subtopic HSV
#Line # hue saturation value color representation ##
#Subtopic Hue
Hue represents an angle, in degrees, on a color wheel. Hue has a positive value
modulo 360, where zero degrees is red.
##
#Subtopic Saturation
Saturation represents the intensity of the color. Saturation varies from zero,
with no Hue contribution; to one, with full Hue contribution.
##
#Subtopic Value
Value represents the lightness of the color. Value varies from zero, black; to
one, full brightness.
##
#Method void SkRGBToHSV(U8CPU red, U8CPU green, U8CPU blue, SkScalar hsv[3])
#In Functions
#Line # converts RGB to HSV ##
Converts RGB to its HSV components.
hsv[0] contains HSV_Hue, a value from zero to less than 360.
hsv[1] contains HSV_Saturation, a value from zero to one.
hsv[2] contains HSV_Value, a value from zero to one.
#Param red red component value from zero to 255 ##
#Param green green component value from zero to 255 ##
#Param blue blue component value from zero to 255 ##
#Param hsv three element array which holds the resulting HSV components
##
#Example
#Image 3
canvas->drawBitmap(source, 0, 0);
SkPaint bgPaint;
bgPaint.setColor(0xafffffff);
canvas->drawRect({20, 30, 110, 90}, bgPaint);
SkScalar hsv[3];
SkColor c = source.getColor(226, 128);
SkRGBToHSV(SkColorGetR(c), SkColorGetG(c), SkColorGetB(c), hsv);
canvas->drawString(("h: " + std::to_string(hsv[0]).substr(0, 6)).c_str(), 27, 45, SkPaint());
canvas->drawString(("s: " + std::to_string(hsv[1]).substr(0, 6)).c_str(), 27, 65, SkPaint());
canvas->drawString(("v: " + std::to_string(hsv[2]).substr(0, 6)).c_str(), 27, 85, SkPaint());
canvas->drawLine(110, 90, 226, 128, SkPaint());
##
#SeeAlso SkColorToHSV SkHSVToColor
#Method ##
# ------------------------------------------------------------------------------
#Method void SkColorToHSV(SkColor color, SkScalar hsv[3])
#In Functions
#Line # converts RGB to HSV ##
Converts ARGB to its HSV components. Alpha in ARGB is ignored.
hsv[0] contains HSV_Hue, and is assigned a value from zero to less than 360.
hsv[1] contains HSV_Saturation, a value from zero to one.
hsv[2] contains HSV_Value, a value from zero to one.
#Param color ARGB color to convert
##
#Param hsv three element array which holds the resulting HSV components
##
#Example
#Image 3
canvas->drawBitmap(source, 0, 0);
for (int y = 0; y < 256; ++y) {
for (int x = 0; x < 256; ++x) {
SkScalar hsv[3];
SkColorToHSV(source.getColor(x, y), hsv);
hsv[1] = 1 - hsv[1];
SkPaint paint;
paint.setColor(SkHSVToColor(hsv));
canvas->drawRect(SkRect::MakeXYWH(x, y, 1, 1), paint);
}
}
##
#SeeAlso SkRGBToHSV SkHSVToColor
#Method ##
# ------------------------------------------------------------------------------
#Method SkColor SkHSVToColor(U8CPU alpha, const SkScalar hsv[3])
#In Functions
#Line # converts HSV with Alpha to RGB ##
Converts HSV components to an ARGB color. Alpha is passed through unchanged.
hsv[0] represents HSV_Hue, an angle from zero to less than 360.
hsv[1] represents HSV_Saturation, and varies from zero to one.
hsv[2] represents HSV_Value, and varies from zero to one.
Out of range hsv values are pinned.
#Param alpha Alpha component of the returned ARGB color
##
#Param hsv three element array which holds the input HSV components
##
#Return ARGB equivalent to HSV
##
#Example
#Image 3
canvas->drawBitmap(source, 0, 0);
for (int y = 0; y < 256; ++y) {
for (int x = 0; x < 256; ++x) {
SkColor color = source.getColor(x, y);
SkScalar hsv[3];
SkColorToHSV(color, hsv);
hsv[0] = hsv[0] + 90 >= 360 ? hsv[0] - 270 : hsv[0] + 90;
SkPaint paint;
paint.setColor(SkHSVToColor(x + y, hsv));
canvas->drawRect(SkRect::MakeXYWH(x, y, 1, 1), paint);
}
}
##
#SeeAlso SkColorToHSV SkRGBToHSV
#Method ##
# ------------------------------------------------------------------------------
#Method SkColor SkHSVToColor(const SkScalar hsv[3])
#In Functions
#Line # converts HSV to RGB ##
Converts HSV components to an ARGB color. Alpha is set to 255.
hsv[0] represents HSV_Hue, an angle from zero to less than 360.
hsv[1] represents HSV_Saturation, and varies from zero to one.
hsv[2] represents HSV_Value, and varies from zero to one.
Out of range hsv values are pinned.
#Param hsv three element array which holds the input HSV components
##
#Return RGB equivalent to HSV
##
#Example
#Image 3
canvas->drawBitmap(source, 0, 0);
for (int y = 0; y < 256; ++y) {
for (int x = 0; x < 256; ++x) {
SkColor color = source.getColor(x, y);
SkScalar hsv[3];
SkColorToHSV(color, hsv);
hsv[0] = hsv[0] + 90 >= 360 ? hsv[0] - 270 : hsv[0] + 90;
SkPaint paint;
paint.setColor(SkHSVToColor(hsv));
canvas->drawRect(SkRect::MakeXYWH(x, y, 1, 1), paint);
}
}
##
#SeeAlso SkColorToHSV SkRGBToHSV
#Method ##
#Subtopic HSV ##
# ------------------------------------------------------------------------------
#Subtopic PMColor
#Line # color components premultiplied by Alpha ##
#Typedef uint32_t SkPMColor
#Line # defines Premultiplied Color as 32 bits ##
#Code
#Populate
##
32-bit ARGB color value, Premultiplied. The byte order for this value is
configuration dependent, matching the format of kBGRA_8888_SkColorType bitmaps.
This is different from SkColor, which is Unpremultiplied, and is always in the
same byte order.
#Typedef ##
# ------------------------------------------------------------------------------
#Method SkPMColor SkPreMultiplyARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
#In Functions
#Line # converts Unpremultiplied ARGB to Premultiplied PMColor ##
Returns a SkPMColor value from Unpremultiplied 8-bit component values.
#Param a amount of Alpha, from fully transparent (0) to fully opaque (255) ##
#Param r amount of red, from no red (0) to full red (255) ##
#Param g amount of green, from no green (0) to full green (255) ##
#Param b amount of blue, from no blue (0) to full blue (255) ##
#Return Premultiplied Color ##
#Example
#Height 128
#Width 300
SkPMColor premultiplied = SkPreMultiplyARGB(160, 128, 160, 192);
canvas->drawString("Unpremultiplied:", 20, 20, SkPaint());
canvas->drawString("alpha=160 red=128 green=160 blue=192", 20, 40, SkPaint());
canvas->drawString("Premultiplied:", 20, 80, SkPaint());
std::string str = "alpha=" + std::to_string(SkColorGetA(premultiplied));
str += " red=" + std::to_string(SkColorGetR(premultiplied));
str += " green=" + std::to_string(SkColorGetG(premultiplied));
str += " blue=" + std::to_string(SkColorGetB(premultiplied));
canvas->drawString(str.c_str(), 20, 100, SkPaint());
##
#SeeAlso SkPreMultiplyColor
#Method ##
# ------------------------------------------------------------------------------
#Method SkPMColor SkPreMultiplyColor(SkColor c)
#In Functions
#Line # converts Unpremultiplied Color to Premultiplied PMColor ##
Returns PMColor closest to Color c. Multiplies c RGB components by the c Alpha,
and arranges the bytes to match the format of kN32_SkColorType.
#Param c Unpremultiplied ARGB Color ##
#Return Premultiplied Color ##
#Example
#Height 128
#Width 300
SkColor unpremultiplied = SkColorSetARGB(160, 128, 160, 192);
SkPMColor premultiplied = SkPreMultiplyColor(unpremultiplied);
canvas->drawString("Unpremultiplied:", 20, 20, SkPaint());
std::string str = "alpha=" + std::to_string(SkColorGetA(unpremultiplied));
str += " red=" + std::to_string(SkColorGetR(unpremultiplied));
str += " green=" + std::to_string(SkColorGetG(unpremultiplied));
str += " blue=" + std::to_string(SkColorGetB(unpremultiplied));
canvas->drawString(str.c_str(), 20, 40, SkPaint());
canvas->drawString("Premultiplied:", 20, 80, SkPaint());
str = "alpha=" + std::to_string(SkColorGetA(premultiplied));
str += " red=" + std::to_string(SkColorGetR(premultiplied));
str += " green=" + std::to_string(SkColorGetG(premultiplied));
str += " blue=" + std::to_string(SkColorGetB(premultiplied));
canvas->drawString(str.c_str(), 20, 100, SkPaint());
##
#SeeAlso SkPreMultiplyARGB
#Method ##
#Subtopic PMColor ##
#Topic Color ##