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