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