2018-04-16 12:37:38 +00:00
|
|
|
#Topic Color
|
2018-05-30 13:21:49 +00:00
|
|
|
#Alias Color_Reference ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-10-08 18:57:48 +00:00
|
|
|
#Code
|
2018-04-16 12:37:38 +00:00
|
|
|
#Populate
|
|
|
|
##
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
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.
|
|
|
|
|
2018-10-08 18:57:48 +00:00
|
|
|
#Subtopic Functions
|
|
|
|
#Line # routines to read, write, and manipulate SkColor ##
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#Subtopic Alpha
|
2018-10-08 18:57:48 +00:00
|
|
|
#Line # transparency of Color ##
|
2018-05-16 11:07:07 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2018-05-30 13:21:49 +00:00
|
|
|
#Alias Alpha
|
|
|
|
#Substitute alpha
|
|
|
|
##
|
2018-05-16 11:07:07 +00:00
|
|
|
|
2018-04-16 12:37:38 +00:00
|
|
|
#Typedef uint8_t SkAlpha
|
2018-05-16 11:07:07 +00:00
|
|
|
#Line # defines Alpha as eight bits ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#Code
|
2018-10-16 14:30:28 +00:00
|
|
|
#Populate
|
2018-05-17 16:17:28 +00:00
|
|
|
##
|
|
|
|
|
2018-06-07 13:59:07 +00:00
|
|
|
8-bit type for an alpha value. 255 is 100% opaque, zero is 100% transparent.
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Typedef ##
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#Subtopic ##
|
|
|
|
|
2018-04-16 12:37:38 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Typedef uint32_t SkColor
|
2018-05-16 11:07:07 +00:00
|
|
|
#Line # defines Color as 32 bits ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#Code
|
2018-10-16 14:30:28 +00:00
|
|
|
#Populate
|
2018-05-17 16:17:28 +00:00
|
|
|
##
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
32-bit ARGB Color value, Unpremultiplied. Color components are always in
|
2018-04-16 12:37:38 +00:00
|
|
|
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.
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
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
|
|
|
|
|
2018-04-16 12:37:38 +00:00
|
|
|
#Typedef ##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method static constexpr inline SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
|
2018-10-08 18:57:48 +00:00
|
|
|
#In Functions
|
2018-05-17 16:17:28 +00:00
|
|
|
#Line # returns Color_Alpha and RGB combined ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
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.
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#Param a amount of Alpha, from fully transparent (0) to fully opaque (255) ##
|
2018-05-17 16:17:28 +00:00
|
|
|
#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) ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#Return color and alpha, Unpremultiplied ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Example
|
2018-05-16 11:07:07 +00:00
|
|
|
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));
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#SeeAlso SkColorSetRGB SkPaint::setARGB SkPaint::setColor SkColorSetA
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Method ##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Define SkColorSetRGB
|
2018-05-16 11:07:07 +00:00
|
|
|
#Line # returns opaque Color ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Code
|
2018-10-16 14:30:28 +00:00
|
|
|
#Populate
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
Returns Color value from 8-bit component values, with Alpha set
|
|
|
|
fully opaque to 255.
|
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#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) ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#Return color with opaque alpha ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Example
|
2018-05-16 11:07:07 +00:00
|
|
|
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));
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#SeeAlso SkColorSetARGB
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Define ##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Define SkColorGetA
|
2018-05-16 11:07:07 +00:00
|
|
|
#Line # returns Alpha component ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Code
|
2018-10-16 14:30:28 +00:00
|
|
|
#Populate
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
Returns Alpha byte from Color value.
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Example
|
2018-10-08 18:57:48 +00:00
|
|
|
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);
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#SeeAlso SkPaint::getAlpha
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Define ##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Define SkColorGetR
|
2018-05-17 16:17:28 +00:00
|
|
|
#Line # returns red component ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Code
|
2018-10-16 14:30:28 +00:00
|
|
|
#Populate
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
Returns red component of Color, from zero to 255.
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
|
|
|
|
#Return red byte ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Example
|
2018-05-17 16:17:28 +00:00
|
|
|
#Image 3
|
2018-10-08 18:57:48 +00:00
|
|
|
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());
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#SeeAlso SkColorGetG SkColorGetB
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Define ##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Define SkColorGetG
|
2018-05-17 16:17:28 +00:00
|
|
|
#Line # returns green component ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Code
|
2018-10-16 14:30:28 +00:00
|
|
|
#Populate
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
Returns green component of Color, from zero to 255.
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
|
|
|
|
#Return green byte ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Example
|
2018-05-17 16:17:28 +00:00
|
|
|
#Image 3
|
2018-10-08 18:57:48 +00:00
|
|
|
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());
|
2018-05-17 16:17:28 +00:00
|
|
|
canvas->drawLine(80, 70, 57, 192, SkPaint());
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#SeeAlso SkColorGetR SkColorGetB
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Define ##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Define SkColorGetB
|
2018-05-17 16:17:28 +00:00
|
|
|
#Line # returns blue component ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Code
|
2018-10-16 14:30:28 +00:00
|
|
|
#Populate
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
Returns blue component of Color, from zero to 255.
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#Param color SkColor, a 32-bit unsigned int, in 0xAARRGGBB format ##
|
|
|
|
#Return blue byte ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Example
|
2018-05-17 16:17:28 +00:00
|
|
|
#Image 3
|
2018-10-08 18:57:48 +00:00
|
|
|
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());
|
2018-05-17 16:17:28 +00:00
|
|
|
canvas->drawLine(80, 70, 168, 170, SkPaint());
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#SeeAlso SkColorGetR SkColorGetG
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Define ##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method static constexpr inline SkColor SkColorSetA(SkColor c, U8CPU a)
|
2018-10-08 18:57:48 +00:00
|
|
|
#In Functions
|
2018-05-17 16:17:28 +00:00
|
|
|
#Line # returns Color with transparency ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
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.
|
2018-05-16 11:07:07 +00:00
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#Param c packed RGB, eight bits per component ##
|
|
|
|
#Param a Alpha: transparent at zero, fully opaque at 255 ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#Return Color with transparency ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Example
|
2018-05-17 16:17:28 +00:00
|
|
|
#Image 3
|
2018-10-08 18:57:48 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#SeeAlso SkColorSetARGB
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Method ##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#Subtopic Alpha_Constants
|
|
|
|
#In Constant
|
|
|
|
#Line # constants for Alpha ##
|
2018-10-16 14:30:28 +00:00
|
|
|
#Filter SK_Alpha
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Code
|
2018-10-16 14:30:28 +00:00
|
|
|
#Populate
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
Alpha constants are conveniences to represent fully transparent and fully
|
|
|
|
opaque colors and masks. Their use is not required.
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#Const SK_AlphaTRANSPARENT 0x00
|
|
|
|
#Line # fully transparent SkAlpha ##
|
|
|
|
Represents fully transparent SkAlpha value. SkAlpha ranges from zero,
|
|
|
|
fully transparent; to 255, fully opaque.
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
2018-05-16 11:07:07 +00:00
|
|
|
#Const SK_AlphaOPAQUE 0xFF
|
|
|
|
#Line # fully opaque SkAlpha ##
|
|
|
|
Represents fully opaque SkAlpha value. SkAlpha ranges from zero,
|
|
|
|
fully transparent; to 255, fully opaque.
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#Example
|
2018-05-16 11:07:07 +00:00
|
|
|
#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);
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-04-16 12:37:38 +00:00
|
|
|
#Example
|
2018-05-16 11:07:07 +00:00
|
|
|
#Image 1
|
|
|
|
#Height 128
|
2018-10-16 14:30:28 +00:00
|
|
|
#Description
|
|
|
|
Color the parts of the bitmap green if they contain fully opaque pixels.
|
|
|
|
##
|
2018-05-16 11:07:07 +00:00
|
|
|
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);
|
|
|
|
##
|
|
|
|
|
2018-10-16 14:30:28 +00:00
|
|
|
#SeeAlso SkAlpha SK_ColorTRANSPARENT SK_ColorBLACK
|
2018-05-16 11:07:07 +00:00
|
|
|
|
|
|
|
#Subtopic Alpha_Constants ##
|
|
|
|
|
|
|
|
#Subtopic Color_Constants
|
|
|
|
#In Constant
|
|
|
|
#Line # constants for Color ##
|
2018-10-16 14:30:28 +00:00
|
|
|
#Filter SK_Color
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Code
|
2018-10-16 14:30:28 +00:00
|
|
|
#Populate
|
2018-05-16 11:07:07 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
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.
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#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.
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
2018-05-16 11:07:07 +00:00
|
|
|
#Const SK_ColorBLACK 0xFF000000
|
|
|
|
#Line # black Color ##
|
|
|
|
Represents fully opaque black.
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
2018-05-16 11:07:07 +00:00
|
|
|
#Const SK_ColorDKGRAY 0xFF444444
|
|
|
|
#Line # dark gray Color ##
|
|
|
|
Represents fully opaque dark gray.
|
|
|
|
Note that SVG_darkgray is equivalent to 0xFFA9A9A9.
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
2018-05-16 11:07:07 +00:00
|
|
|
#Const SK_ColorGRAY 0xFF888888
|
|
|
|
#Line # gray Color ##
|
|
|
|
Represents fully opaque gray.
|
|
|
|
Note that HTML_Gray is equivalent to 0xFF808080.
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
2018-05-16 11:07:07 +00:00
|
|
|
#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.
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
2018-05-16 11:07:07 +00:00
|
|
|
#Const SK_ColorWHITE 0xFFFFFFFF
|
|
|
|
#Line # white Color ##
|
|
|
|
Represents fully opaque white.
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
2018-05-16 11:07:07 +00:00
|
|
|
#Const SK_ColorRED 0xFFFF0000
|
|
|
|
#Line # red Color ##
|
|
|
|
Represents fully opaque red.
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
2018-05-16 11:07:07 +00:00
|
|
|
#Const SK_ColorGREEN 0xFF00FF00
|
|
|
|
#Line # green Color ##
|
|
|
|
Represents fully opaque green. HTML_Lime is equivalent.
|
|
|
|
Note that HTML_Green is equivalent to 0xFF008000.
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
2018-05-16 11:07:07 +00:00
|
|
|
#Const SK_ColorBLUE 0xFF0000FF
|
|
|
|
#Line # blue Color ##
|
|
|
|
Represents fully opaque blue.
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
2018-05-16 11:07:07 +00:00
|
|
|
#Const SK_ColorYELLOW 0xFFFFFF00
|
|
|
|
#Line # yellow Color ##
|
|
|
|
Represents fully opaque yellow.
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
2018-05-16 11:07:07 +00:00
|
|
|
#Const SK_ColorCYAN 0xFF00FFFF
|
|
|
|
#Line # cyan Color ##
|
|
|
|
Represents fully opaque cyan. HTML_Aqua is equivalent.
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
2018-05-16 11:07:07 +00:00
|
|
|
#Const SK_ColorMAGENTA 0xFFFF00FF
|
|
|
|
#Line # magenta Color ##
|
|
|
|
Represents fully opaque magenta. HTML_Fuchsia is equivalent.
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
2018-10-16 14:30:28 +00:00
|
|
|
#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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$$$#
|
|
|
|
##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Example
|
2018-10-16 14:30:28 +00:00
|
|
|
#Description
|
|
|
|
SK_ColorTRANSPARENT sets Color Alpha and components to zero.
|
|
|
|
##
|
2018-05-17 16:17:28 +00:00
|
|
|
#Image 3
|
2018-05-16 11:07:07 +00:00
|
|
|
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);
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#Example
|
2018-10-16 14:30:28 +00:00
|
|
|
#Description
|
|
|
|
SK_ColorBLACK sets Color Alpha to one and components to zero.
|
|
|
|
##
|
2018-05-16 11:07:07 +00:00
|
|
|
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);
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#Example
|
2018-10-16 14:30:28 +00:00
|
|
|
#Description
|
|
|
|
SK_ColorWHITE sets Color Alpha and components to one.
|
|
|
|
##
|
2018-05-16 11:07:07 +00:00
|
|
|
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);
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
2018-10-16 14:30:28 +00:00
|
|
|
#SeeAlso SK_ColorTRANSPARENT SkCanvas::clear SK_AlphaOPAQUE
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#Subtopic Color_Constants ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Subtopic HSV
|
2018-10-08 18:57:48 +00:00
|
|
|
#Line # hue saturation value color representation ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#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
|
2018-06-07 13:59:07 +00:00
|
|
|
Saturation represents the intensity of the color. Saturation varies from zero,
|
|
|
|
with no Hue contribution; to one, with full Hue contribution.
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#Subtopic Value
|
2018-06-07 13:59:07 +00:00
|
|
|
Value represents the lightness of the color. Value varies from zero, black; to
|
|
|
|
one, full brightness.
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#Method void SkRGBToHSV(U8CPU red, U8CPU green, U8CPU blue, SkScalar hsv[3])
|
2018-10-08 18:57:48 +00:00
|
|
|
#In Functions
|
2018-05-17 16:17:28 +00:00
|
|
|
#Line # converts RGB to HSV ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
Converts RGB to its HSV components.
|
2018-06-07 13:59:07 +00:00
|
|
|
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.
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#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
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#Example
|
2018-05-17 16:17:28 +00:00
|
|
|
#Image 3
|
2018-10-08 18:57:48 +00:00
|
|
|
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());
|
2018-05-17 16:17:28 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso SkColorToHSV SkHSVToColor
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Method ##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#Method void SkColorToHSV(SkColor color, SkScalar hsv[3])
|
2018-10-08 18:57:48 +00:00
|
|
|
#In Functions
|
2018-05-16 11:07:07 +00:00
|
|
|
#Line # converts RGB to HSV ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
Converts ARGB to its HSV components. Alpha in ARGB is ignored.
|
2018-06-07 13:59:07 +00:00
|
|
|
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.
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#Param color ARGB color to convert
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
2018-05-16 11:07:07 +00:00
|
|
|
#Param hsv three element array which holds the resulting HSV components
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#Example
|
2018-05-17 16:17:28 +00:00
|
|
|
#Image 3
|
2018-10-08 18:57:48 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2018-05-17 16:17:28 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso SkRGBToHSV SkHSVToColor
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Method ##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#Method SkColor SkHSVToColor(U8CPU alpha, const SkScalar hsv[3])
|
2018-10-08 18:57:48 +00:00
|
|
|
#In Functions
|
2018-05-16 11:07:07 +00:00
|
|
|
#Line # converts HSV with Alpha to RGB ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
Converts HSV components to an ARGB color. Alpha is passed through unchanged.
|
2018-06-07 13:59:07 +00:00
|
|
|
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.
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
Out of range hsv values are pinned.
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#Param alpha Alpha component of the returned ARGB color
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
2018-05-16 11:07:07 +00:00
|
|
|
#Param hsv three element array which holds the input HSV components
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#Return ARGB equivalent to HSV
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#Example
|
2018-05-17 16:17:28 +00:00
|
|
|
#Image 3
|
2018-10-08 18:57:48 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2018-05-17 16:17:28 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso SkColorToHSV SkRGBToHSV
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Method ##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#Method SkColor SkHSVToColor(const SkScalar hsv[3])
|
2018-10-08 18:57:48 +00:00
|
|
|
#In Functions
|
2018-05-17 16:17:28 +00:00
|
|
|
#Line # converts HSV to RGB ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-06-07 13:59:07 +00:00
|
|
|
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.
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
Out of range hsv values are pinned.
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#Param hsv three element array which holds the input HSV components
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#Return RGB equivalent to HSV
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#Example
|
2018-05-17 16:17:28 +00:00
|
|
|
#Image 3
|
2018-10-08 18:57:48 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2018-05-17 16:17:28 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso SkColorToHSV SkRGBToHSV
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Method ##
|
|
|
|
|
|
|
|
#Subtopic HSV ##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#Subtopic PMColor
|
2018-10-08 18:57:48 +00:00
|
|
|
#Line # color components premultiplied by Alpha ##
|
2018-05-16 11:07:07 +00:00
|
|
|
|
2018-04-16 12:37:38 +00:00
|
|
|
#Typedef uint32_t SkPMColor
|
2018-05-16 11:07:07 +00:00
|
|
|
#Line # defines Premultiplied Color as 32 bits ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#Code
|
2018-10-16 14:30:28 +00:00
|
|
|
#Populate
|
2018-05-17 16:17:28 +00:00
|
|
|
##
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
32-bit ARGB color value, Premultiplied. The byte order for this value is
|
2018-04-16 12:37:38 +00:00
|
|
|
configuration dependent, matching the format of kBGRA_8888_SkColorType bitmaps.
|
2018-05-16 11:07:07 +00:00
|
|
|
This is different from SkColor, which is Unpremultiplied, and is always in the
|
2018-04-16 12:37:38 +00:00
|
|
|
same byte order.
|
|
|
|
|
|
|
|
#Typedef ##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#Method SkPMColor SkPreMultiplyARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
|
2018-10-08 18:57:48 +00:00
|
|
|
#In Functions
|
2018-05-16 11:07:07 +00:00
|
|
|
#Line # converts Unpremultiplied ARGB to Premultiplied PMColor ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
Returns a SkPMColor value from Unpremultiplied 8-bit component values.
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#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) ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#Return Premultiplied Color ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Example
|
2018-05-17 16:17:28 +00:00
|
|
|
#Height 128
|
|
|
|
#Width 300
|
2018-10-08 18:57:48 +00:00
|
|
|
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));
|
2018-05-17 16:17:28 +00:00
|
|
|
canvas->drawString(str.c_str(), 20, 100, SkPaint());
|
2018-04-16 12:37:38 +00:00
|
|
|
##
|
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#SeeAlso SkPreMultiplyColor
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Method ##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#Method SkPMColor SkPreMultiplyColor(SkColor c)
|
2018-10-08 18:57:48 +00:00
|
|
|
#In Functions
|
2018-05-16 11:07:07 +00:00
|
|
|
#Line # converts Unpremultiplied Color to Premultiplied PMColor ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
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.
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#Param c Unpremultiplied ARGB Color ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
2018-05-17 16:17:28 +00:00
|
|
|
#Return Premultiplied Color ##
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Example
|
2018-05-17 16:17:28 +00:00
|
|
|
#Height 128
|
|
|
|
#Width 300
|
2018-10-08 18:57:48 +00:00
|
|
|
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));
|
2018-05-17 16:17:28 +00:00
|
|
|
canvas->drawString(str.c_str(), 20, 100, SkPaint());
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso SkPreMultiplyARGB
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
#Method ##
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#Subtopic PMColor ##
|
|
|
|
|
2018-04-16 12:37:38 +00:00
|
|
|
#Topic Color ##
|