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