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