Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1 | #Topic Image_Info |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 2 | #Alias Image_Info_Reference ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 3 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 4 | #Code |
| 5 | #Populate |
| 6 | ## |
| 7 | |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 8 | Image_Info specifies the dimensions and encoding of the pixels in a Bitmap. |
| 9 | The dimensions are integral width and height. The encoding is how pixel |
| 10 | bits describe Color_Alpha, transparency; Color components red, blue, |
| 11 | and green; and Color_Space, the range and linearity of colors. |
| 12 | |
| 13 | Image_Info describes an uncompressed raster pixels. In contrast, Image |
| 14 | additionally describes compressed pixels like PNG, and Surface describes |
| 15 | destinations on the GPU. Image and Surface may be specified by Image_Info, |
| 16 | but Image and Surface may not contain Image_Info. |
| 17 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 18 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 19 | #Subtopic Alpha_Type |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 20 | #Line # encoding for pixel transparency ## |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 21 | #Alias Alpha_Type ## |
| 22 | #Alias Alpha_Types ## |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 23 | |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 24 | #PhraseDef list_of_alpha_types |
| 25 | kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, |
| 26 | kUnpremul_SkAlphaType |
| 27 | ## |
| 28 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 29 | #Enum SkAlphaType |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 30 | #Line # encoding for pixel transparency ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 31 | |
| 32 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 33 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 34 | ## |
| 35 | |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 36 | Describes how to interpret the alpha component of a pixel. A pixel may |
| 37 | be opaque, or Color_Alpha, describing multiple levels of transparency. |
| 38 | |
| 39 | In simple blending, Color_Alpha weights the draw color and the destination |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 40 | color to create a new color. If alpha describes a weight from zero to one, |
| 41 | new color is set to: #Formula # draw color * alpha + destination color * (1 - alpha) ##. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 42 | |
| 43 | In practice alpha is encoded in two or more bits, where 1.0 equals all bits set. |
| 44 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 45 | RGB may have Color_Alpha included in each component value; the stored |
| 46 | value is the original RGB multiplied by Color_Alpha. Premultiplied color |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 47 | components improve performance. |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 48 | |
| 49 | #Const kUnknown_SkAlphaType 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 50 | #Line # uninitialized ## |
| 51 | Alpha_Type is uninitialized. |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 52 | ## |
| 53 | #Const kOpaque_SkAlphaType 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 54 | #Line # pixel is opaque ## |
| 55 | #Details Opaque |
| 56 | Pixels are opaque. The Color_Type must have no explicit alpha |
| 57 | component, or all alpha components must be set to their maximum value. |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 58 | ## |
| 59 | #Const kPremul_SkAlphaType 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 60 | #Line # pixel components are Premultiplied by Alpha ## |
| 61 | #Details Premul |
| 62 | Pixels have Alpha Premultiplied into color components. |
| 63 | Surface pixels must be Premultiplied. |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 64 | ## |
| 65 | #Const kUnpremul_SkAlphaType 3 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 66 | #Line # pixel components are independent of Alpha ## |
| 67 | #Details Unpremul |
| 68 | Pixel color component values are independent of alpha value. |
| 69 | Images generated from encoded data like PNG do not Premultiply pixel color |
| 70 | components. kUnpremul_SkAlphaType is supported for Image pixels, but not for |
| 71 | Surface pixels. |
| 72 | ## |
| 73 | #Const kLastEnum_SkAlphaType 3 |
| 74 | #Line # last valid value ## |
| 75 | Used by tests to iterate through all valid values. |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 76 | ## |
| 77 | |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 78 | #NoExample |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 79 | ## |
| 80 | |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 81 | #SeeAlso SkColorType SkColorSpace |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 82 | |
| 83 | #Enum SkAlphaType ## |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 84 | |
| 85 | #Subtopic Opaque |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 86 | #Line # hints all pixels are opaque ## |
| 87 | Use kOpaque_SkAlphaType as a hint to optimize drawing when Alpha component |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 88 | of all pixel is set to its maximum value of 1.0; all alpha component bits are set. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 89 | If Image_Info is set to kOpaque_SkAlphaType but all alpha values are not 1.0, |
| 90 | results are undefined. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 91 | |
| 92 | #Example |
| 93 | #Height 64 |
| 94 | #Description |
| 95 | SkPreMultiplyARGB parameter a is set to 255, its maximum value, and is interpreted |
| 96 | as Color_Alpha of 1.0. kOpaque_SkAlphaType may be set to improve performance. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 97 | If SkPreMultiplyARGB parameter a is set to a value smaller than 255, |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 98 | kPremul_SkAlphaType must be used instead to avoid undefined results. |
| 99 | The four displayed values are the original component values, though not necessarily |
| 100 | in the same order. |
| 101 | ## |
| 102 | SkPMColor color = SkPreMultiplyARGB(255, 50, 100, 150); |
| 103 | SkString s; |
| 104 | s.printf("%u %u %u %u", SkColorGetA(color), SkColorGetR(color), |
| 105 | SkColorGetG(color), SkColorGetB(color)); |
| 106 | SkPaint paint; |
| 107 | paint.setAntiAlias(true); |
| 108 | canvas->drawString(s, 10, 62, paint); |
| 109 | canvas->scale(50, 50); |
| 110 | SkBitmap bitmap; |
| 111 | SkImageInfo imageInfo = SkImageInfo::Make(1, 1, kN32_SkColorType, kOpaque_SkAlphaType); |
| 112 | if (bitmap.installPixels(imageInfo, (void*) &color, imageInfo.minRowBytes())) { |
| 113 | canvas->drawBitmap(bitmap, 0, 0); |
| 114 | } |
| 115 | ## |
| 116 | |
| 117 | #Subtopic Opaque ## |
| 118 | |
| 119 | #Subtopic Premul |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 120 | #Line # stores components scaled by Alpha ## |
| 121 | Use kPremul_SkAlphaType when stored color components are the original color |
| 122 | multiplied by the alpha component. The alpha component range of 0.0 to 1.0 is |
| 123 | achieved by dividing the integer bit value by the maximum bit value. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 124 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 125 | #Code |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 126 | stored color = original color * alpha / max alpha |
| 127 | ## |
| 128 | |
| 129 | The color component must be equal to or smaller than the alpha component, |
| 130 | or the results are undefined. |
| 131 | |
| 132 | #Example |
| 133 | #Description |
| 134 | SkPreMultiplyARGB parameter a is set to 150, less than its maximum value, and is |
| 135 | interpreted as Color_Alpha of about 0.6. kPremul_SkAlphaType must be set, since |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 136 | SkPreMultiplyARGB parameter a is set to a value smaller than 255, |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 137 | to avoid undefined results. |
| 138 | The four displayed values reflect that the alpha component has been multiplied |
| 139 | by the original color. |
| 140 | ## |
| 141 | #Height 64 |
| 142 | SkPMColor color = SkPreMultiplyARGB(150, 50, 100, 150); |
| 143 | SkString s; |
| 144 | s.printf("%u %u %u %u", SkColorGetA(color), SkColorGetR(color), |
| 145 | SkColorGetG(color), SkColorGetB(color)); |
| 146 | SkPaint paint; |
| 147 | paint.setAntiAlias(true); |
| 148 | canvas->drawString(s, 10, 62, paint); |
| 149 | canvas->scale(50, 50); |
| 150 | SkBitmap bitmap; |
| 151 | SkImageInfo imageInfo = SkImageInfo::Make(1, 1, kN32_SkColorType, kPremul_SkAlphaType); |
| 152 | if (bitmap.installPixels(imageInfo, (void*) &color, imageInfo.minRowBytes())) { |
| 153 | canvas->drawBitmap(bitmap, 0, 0); |
| 154 | } |
| 155 | ## |
| 156 | |
| 157 | #Subtopic Premul ## |
| 158 | |
| 159 | #Subtopic Unpremul |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 160 | #Line # stores components without Alpha scaling ## |
| 161 | Use kUnpremul_SkAlphaType if stored color components are not divided by the |
| 162 | alpha component. Some drawing destinations may not support |
| 163 | kUnpremul_SkAlphaType. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 164 | |
| 165 | #Bug 7079 |
| 166 | #Example |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 167 | #Height 64 |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 168 | #Description |
| 169 | SkColorSetARGB parameter a is set to 150, less than its maximum value, and is |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 170 | interpreted as Color_Alpha of about 0.6. color is not Premultiplied; |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 171 | color components may have values greater than color alpha. |
| 172 | The four displayed values are the original component values, though not necessarily |
| 173 | in the same order. |
| 174 | ## |
| 175 | SkColor color = SkColorSetARGB(150, 50, 100, 255); |
| 176 | SkString s; |
| 177 | s.printf("%u %u %u %u", SkColorGetA(color), SkColorGetR(color), |
| 178 | SkColorGetG(color), SkColorGetB(color)); |
| 179 | SkPaint paint; |
| 180 | paint.setAntiAlias(true); |
| 181 | canvas->drawString(s, 10, 62, paint); |
| 182 | canvas->scale(50, 50); |
| 183 | SkBitmap bitmap; |
| 184 | SkImageInfo imageInfo = SkImageInfo::Make(1, 1, kN32_SkColorType, kUnpremul_SkAlphaType); |
| 185 | if (bitmap.installPixels(imageInfo, (void*) &color, imageInfo.minRowBytes())) { |
| 186 | canvas->drawBitmap(bitmap, 0, 0); |
| 187 | } |
| 188 | ## |
| 189 | |
| 190 | #Subtopic Unpremul ## |
| 191 | |
Cary Clark | fd32e72 | 2018-11-16 14:36:02 -0500 | [diff] [blame] | 192 | #Method static bool SkAlphaTypeIsOpaque(SkAlphaType at) |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 193 | #In Property |
| 194 | #Line # returns if Alpha_Type equals kOpaque_SkAlphaType ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 195 | #Populate |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 196 | |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 197 | #NoExample |
| 198 | ## |
| 199 | ## |
| 200 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 201 | #Subtopic Alpha_Type ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 202 | |
| 203 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 204 | #Subtopic Color_Type |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 205 | #Line # encoding for pixel color ## |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 206 | #Alias Color_Type ## |
| 207 | #Alias Color_Types ## |
Cary Clark | 2a8c48b | 2018-02-15 17:31:24 -0500 | [diff] [blame] | 208 | |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 209 | #PhraseDef list_of_color_types |
| 210 | kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, |
| 211 | kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, |
| 212 | kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, |
| 213 | kGray_8_SkColorType, kRGBA_F16_SkColorType |
| 214 | ## |
| 215 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 216 | #Enum SkColorType |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 217 | #Line # encoding for pixel color ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 218 | |
| 219 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 220 | #Populate |
| 221 | ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 222 | |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 223 | Describes how pixel bits encode color. A pixel may be an alpha mask, a |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 224 | grayscale, RGB, or ARGB. |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 225 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 226 | kN32_SkColorType selects the native 32-bit ARGB format. On Little_Endian |
| 227 | processors, pixels containing 8-bit ARGB components pack into 32-bit |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 228 | kBGRA_8888_SkColorType. On Big_Endian processors, pixels pack into 32-bit |
| 229 | kRGBA_8888_SkColorType. |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 230 | |
| 231 | #Const kUnknown_SkColorType 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 232 | #Line # uninitialized ## |
| 233 | Color_Type is set to kUnknown_SkColorType by default. If set, |
| 234 | encoding format and size is unknown. |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 235 | ## |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 236 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 237 | #Const kAlpha_8_SkColorType 1 |
| 238 | #Line # pixel with Alpha in 8-bit byte ## |
| 239 | #Details Alpha_8 |
| 240 | Stores 8-bit byte pixel encoding that represents transparency. Value of zero |
| 241 | is completely transparent; a value of 255 is completely opaque. |
| 242 | ## |
| 243 | |
| 244 | #Const kRGB_565_SkColorType 2 |
| 245 | #Line # pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word ## |
| 246 | #Details RGB_565 |
| 247 | Stores 16-bit word pixel encoding that contains five bits of blue, |
| 248 | six bits of green, and five bits of red. |
| 249 | ## |
| 250 | |
| 251 | #Const kARGB_4444_SkColorType 3 |
| 252 | #Line # pixel with 4 bits for alpha, red, green, blue; in 16-bit word ## |
| 253 | #Details ARGB_4444 |
| 254 | Stores 16-bit word pixel encoding that contains four bits of alpha, |
| 255 | four bits of blue, four bits of green, and four bits of red. |
| 256 | ## |
| 257 | |
| 258 | #Const kRGBA_8888_SkColorType 4 |
| 259 | #Line # pixel with 8 bits for red, green, blue, alpha; in 32-bit word ## |
| 260 | #Details RGBA_8888 |
| 261 | Stores 32-bit word pixel encoding that contains eight bits of red, |
| 262 | eight bits of green, eight bits of blue, and eight bits of alpha. |
| 263 | ## |
| 264 | |
| 265 | #Const kRGB_888x_SkColorType 5 |
| 266 | #Line # pixel with 8 bits each for red, green, blue; in 32-bit word ## |
| 267 | #Details RGB_888 |
| 268 | Stores 32-bit word pixel encoding that contains eight bits of red, |
| 269 | eight bits of green, eight bits of blue, and eight unused bits. |
| 270 | ## |
| 271 | |
| 272 | #Const kBGRA_8888_SkColorType 6 |
| 273 | #Line # pixel with 8 bits for blue, green, red, alpha; in 32-bit word ## |
| 274 | #Details BGRA_8888 |
| 275 | Stores 32-bit word pixel encoding that contains eight bits of blue, |
| 276 | eight bits of green, eight bits of red, and eight bits of alpha. |
| 277 | ## |
| 278 | |
| 279 | #Const kRGBA_1010102_SkColorType 7 |
| 280 | #Line # 10 bits for red, green, blue; 2 bits for alpha; in 32-bit word ## |
| 281 | #Details RGBA_1010102 |
| 282 | Stores 32-bit word pixel encoding that contains ten bits of red, |
| 283 | ten bits of green, ten bits of blue, and two bits of alpha. |
| 284 | ## |
| 285 | |
| 286 | #Const kRGB_101010x_SkColorType 8 |
| 287 | #Line # pixel with 10 bits each for red, green, blue; in 32-bit word ## |
| 288 | #Details RGB_101010 |
| 289 | Stores 32-bit word pixel encoding that contains ten bits of red, |
| 290 | ten bits of green, ten bits of blue, and two unused bits. |
| 291 | ## |
| 292 | |
| 293 | #Const kGray_8_SkColorType 9 |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 294 | #Line # pixel with grayscale level in 8-bit byte ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 295 | #Details Gray_8 |
| 296 | Stores 8-bit byte pixel encoding that equivalent to equal values for red, |
| 297 | blue, and green, representing colors from black to white. |
| 298 | ## |
| 299 | |
| 300 | #Const kRGBA_F16_SkColorType 10 |
| 301 | #Line # pixel with half floats for red, green, blue, alpha; in 64-bit word ## |
| 302 | #Details RGBA_F16 |
| 303 | Stores 64-bit word pixel encoding that contains 16 bits of blue, |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 304 | 16 bits of green, 16 bits of red, and 16 bits of alpha. Each component |
| 305 | is encoded as a half float. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 306 | ## |
| 307 | |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 308 | #Const kRGBA_F32_SkColorType 11 |
| 309 | #Line # pixel using C float for red, green, blue, alpha; in 128-bit word ## |
| 310 | #Details RGBA_F32 |
| 311 | Stores 128-bit word pixel encoding that contains 32 bits of blue, |
| 312 | 32 bits of green, 32 bits of red, and 32 bits of alpha. Each component |
| 313 | is encoded as a single precision float. |
| 314 | ## |
| 315 | |
| 316 | #Const kLastEnum_SkColorType 11 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 317 | #NoJustify |
| 318 | #Line # last valid value ## |
| 319 | Used by tests to iterate through all valid values. |
| 320 | ## |
| 321 | |
| 322 | #Const kN32_SkColorType 4 or 6 |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 323 | #Alias Native_Color_Type ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 324 | #NoJustify |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 325 | #Line # native ARGB 32-bit encoding ## |
| 326 | Encodes ARGB as either kRGBA_8888_SkColorType or |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 327 | kBGRA_8888_SkColorType, whichever is native to the platform. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 328 | ## |
| 329 | |
| 330 | #NoExample |
| 331 | ## |
| 332 | |
| 333 | #SeeAlso SkAlphaType SkColorSpace |
| 334 | |
| 335 | #Enum SkColorType ## |
| 336 | |
| 337 | #Subtopic Alpha_8 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 338 | #Line # encodes transparency only ## |
| 339 | Alpha pixels encode transparency without color information. Value of zero is |
| 340 | completely transparent; a value of 255 is completely opaque. Bitmap |
| 341 | pixels do not visibly draw, because its pixels have no color information. |
| 342 | When SkColorType is set to kAlpha_8_SkColorType, the paired SkAlphaType is |
| 343 | ignored. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 344 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 345 | #Example |
| 346 | #Description |
| 347 | Alpha pixels can modify another draw. orangePaint fills the bounds of bitmap, |
| 348 | with its transparency set to alpha8 pixel value. |
| 349 | ## |
| 350 | #Height 64 |
| 351 | canvas->scale(16, 16); |
| 352 | SkBitmap bitmap; |
| 353 | SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kAlpha_8_SkColorType, kOpaque_SkAlphaType); |
| 354 | bitmap.allocPixels(imageInfo); |
| 355 | SkCanvas offscreen(bitmap); |
| 356 | offscreen.clear(SK_ColorGREEN); |
| 357 | SkPaint orangePaint; |
| 358 | orangePaint.setARGB(0xFF, 0xFF, 0xA5, 0x00); |
| 359 | canvas->drawBitmap(bitmap, 0, 0, &orangePaint); |
| 360 | uint8_t alpha8[] = { 0xFF, 0xBB, 0x77, 0x33 }; |
| 361 | SkPixmap alphaPixmap(imageInfo, &alpha8, imageInfo.minRowBytes()); |
| 362 | if (bitmap.writePixels(alphaPixmap, 0, 0)) { |
| 363 | canvas->drawBitmap(bitmap, 2, 2, &orangePaint); |
| 364 | } |
| 365 | ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 366 | #SeeAlso Alpha Gray_8 |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 367 | ## |
| 368 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 369 | #Subtopic RGB_565 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 370 | #Line # encodes RGB in 16 bits ## |
| 371 | kRGB_565_SkColorType encodes RGB to fit in a 16-bit word. Red and blue |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 372 | components use five bits describing 32 levels. Green components, more sensitive |
| 373 | to the eye, use six bits describing 64 levels. kRGB_565_SkColorType has no |
| 374 | bits for Alpha. |
| 375 | |
| 376 | Pixels are fully opaque as if its Color_Alpha was set to one, and should |
| 377 | always be paired with kOpaque_SkAlphaType. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 378 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 379 | #Illustration |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 380 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 381 | #Example |
| 382 | #Height 96 |
| 383 | canvas->scale(16, 16); |
| 384 | SkBitmap bitmap; |
| 385 | SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGB_565_SkColorType, kOpaque_SkAlphaType); |
| 386 | bitmap.allocPixels(imageInfo); |
| 387 | SkCanvas offscreen(bitmap); |
| 388 | offscreen.clear(SK_ColorGREEN); |
| 389 | canvas->drawBitmap(bitmap, 0, 0); |
| 390 | auto pack565 = [](unsigned r, unsigned g, unsigned b) -> uint16_t { |
| 391 | return (b << 0) | (g << 5) | (r << 11); |
| 392 | }; |
| 393 | uint16_t red565[] = { pack565(0x1F, 0x00, 0x00), pack565(0x17, 0x00, 0x00), |
| 394 | pack565(0x0F, 0x00, 0x00), pack565(0x07, 0x00, 0x00) }; |
| 395 | uint16_t blue565[] = { pack565(0x00, 0x00, 0x1F), pack565(0x00, 0x00, 0x17), |
| 396 | pack565(0x00, 0x00, 0x0F), pack565(0x00, 0x00, 0x07) }; |
| 397 | SkPixmap redPixmap(imageInfo, &red565, imageInfo.minRowBytes()); |
| 398 | if (bitmap.writePixels(redPixmap, 0, 0)) { |
| 399 | canvas->drawBitmap(bitmap, 2, 2); |
| 400 | } |
| 401 | SkPixmap bluePixmap(imageInfo, &blue565, imageInfo.minRowBytes()); |
| 402 | if (bitmap.writePixels(bluePixmap, 0, 0)) { |
| 403 | canvas->drawBitmap(bitmap, 4, 4); |
| 404 | } |
| 405 | ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 406 | #SeeAlso ARGB_4444 RGBA_8888 |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 407 | ## |
| 408 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 409 | #Subtopic ARGB_4444 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 410 | #Line # encodes ARGB in 16 bits ## |
| 411 | kARGB_4444_SkColorType encodes ARGB to fit in 16-bit word. Each |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 412 | component: alpha, blue, green, and red; use four bits, describing 16 levels. |
| 413 | Note that kARGB_4444_SkColorType is misnamed; the acronym does not |
| 414 | describe the actual component order. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 415 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 416 | #Illustration |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 417 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 418 | If paired with kPremul_SkAlphaType: blue, green, and red components are |
| 419 | Premultiplied by the alpha value. If blue, green, or red is greater than alpha, |
| 420 | the drawn result is undefined. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 421 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 422 | If paired with kUnpremul_SkAlphaType: alpha, blue, green, and red components |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 423 | may have any value. There may be a performance penalty with Unpremultiplied |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 424 | pixels. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 425 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 426 | If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum; |
| 427 | blue, green, and red components are fully opaque. If any alpha component is |
| 428 | less than 15, the drawn result is undefined. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 429 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 430 | #Bug 7648 |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 431 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 432 | #Example |
| 433 | #Height 96 |
| 434 | canvas->scale(16, 16); |
| 435 | SkBitmap bitmap; |
| 436 | SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, kPremul_SkAlphaType); |
| 437 | bitmap.allocPixels(imageInfo); |
| 438 | SkCanvas offscreen(bitmap); |
| 439 | offscreen.clear(SK_ColorGREEN); |
| 440 | canvas->drawBitmap(bitmap, 0, 0); |
| 441 | auto pack4444 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint16_t { |
| 442 | return (a << 0) | (b << 4) | (g << 8) | (r << 12); |
| 443 | }; |
| 444 | uint16_t red4444[] = { pack4444(0xF, 0xF, 0x0, 0x0), pack4444(0xF, 0xb, 0x0, 0x0), |
| 445 | pack4444(0xF, 0x7, 0x0, 0x0), pack4444(0xF, 0x3, 0x0, 0x0) }; |
| 446 | uint16_t blue4444[] = { pack4444(0xF, 0x0, 0x0, 0xF), pack4444(0xF, 0x0, 0x0, 0xb), |
| 447 | pack4444(0xF, 0x0, 0x0, 0x7), pack4444(0xF, 0x0, 0x0, 0x3) }; |
| 448 | SkPixmap redPixmap(imageInfo, &red4444, imageInfo.minRowBytes()); |
| 449 | if (bitmap.writePixels(redPixmap, 0, 0)) { |
| 450 | canvas->drawBitmap(bitmap, 2, 2); |
| 451 | } |
| 452 | SkPixmap bluePixmap(imageInfo, &blue4444, imageInfo.minRowBytes()); |
| 453 | if (bitmap.writePixels(bluePixmap, 0, 0)) { |
| 454 | canvas->drawBitmap(bitmap, 4, 4); |
| 455 | } |
| 456 | ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 457 | #SeeAlso RGBA_8888 |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 458 | ## |
| 459 | |
| 460 | #Subtopic RGBA_8888 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 461 | #Line # encodes ARGB Big_Endian in 32 bits ## |
| 462 | kRGBA_8888_SkColorType encodes ARGB into a 32-bit word. Each component: |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 463 | red, green, blue, alpha; use eight bits, describing 256 levels. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 464 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 465 | #Illustration |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 466 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 467 | If paired with kPremul_SkAlphaType: red, green, and blue components are |
| 468 | Premultiplied by the alpha value. If red, green, or blue is greater than alpha, |
| 469 | the drawn result is undefined. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 470 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 471 | If paired with kUnpremul_SkAlphaType: alpha, red, green, and blue components |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 472 | may have any value. There may be a performance penalty with Unpremultiplied |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 473 | pixels. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 474 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 475 | If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum; |
| 476 | red, green, and blue components are fully opaque. If any alpha component is |
| 477 | less than 255, the drawn result is undefined. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 478 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 479 | On Big_Endian platforms, kRGBA_8888_SkColorType is the native Color_Type, and |
| 480 | will have the best performance. Use kN32_SkColorType to choose the best |
| 481 | Color_Type for the platform at compile time. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 482 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 483 | #Example |
| 484 | #Height 96 |
| 485 | canvas->scale(16, 16); |
| 486 | SkBitmap bitmap; |
| 487 | SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 488 | bitmap.allocPixels(imageInfo); |
| 489 | SkCanvas offscreen(bitmap); |
| 490 | offscreen.clear(SK_ColorGREEN); |
| 491 | canvas->drawBitmap(bitmap, 0, 0); |
| 492 | auto pack8888 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint32_t { |
| 493 | return (r << 0) | (g << 8) | (b << 16) | (a << 24); |
| 494 | }; |
| 495 | uint32_t red8888[] = { pack8888(0xFF, 0xFF, 0x0, 0x0), pack8888(0xFF, 0xbb, 0x0, 0x0), |
| 496 | pack8888(0xFF, 0x77, 0x0, 0x0), pack8888(0xFF, 0x33, 0x0, 0x0) }; |
| 497 | uint32_t blue8888[] = { pack8888(0xFF, 0x0, 0x0, 0x0FF), pack8888(0xFF, 0x0, 0x0, 0x0bb), |
| 498 | pack8888(0xFF, 0x0, 0x0, 0x077), pack8888(0xFF, 0x0, 0x0, 0x033) }; |
| 499 | SkPixmap redPixmap(imageInfo, &red8888, imageInfo.minRowBytes()); |
| 500 | if (bitmap.writePixels(redPixmap, 0, 0)) { |
| 501 | canvas->drawBitmap(bitmap, 2, 2); |
| 502 | } |
| 503 | SkPixmap bluePixmap(imageInfo, &blue8888, imageInfo.minRowBytes()); |
| 504 | if (bitmap.writePixels(bluePixmap, 0, 0)) { |
| 505 | canvas->drawBitmap(bitmap, 4, 4); |
| 506 | } |
| 507 | ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 508 | #SeeAlso RGB_888 BGRA_8888 |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 509 | ## |
| 510 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 511 | #Subtopic RGB_888 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 512 | #Line # encodes RGB in 32 bits ## |
| 513 | kRGB_888x_SkColorType encodes RGB into a 32-bit word. Each component: |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 514 | red, green, blue; use eight bits, describing 256 levels. Eight bits are |
| 515 | unused. Pixels described by kRGB_888x_SkColorType are fully opaque as if |
| 516 | their Color_Alpha was set to one, and should always be paired with |
| 517 | kOpaque_SkAlphaType. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 518 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 519 | #Illustration |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 520 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 521 | #Example |
| 522 | #Bug 7645 |
| 523 | #Height 96 |
| 524 | #Platform cpu |
| 525 | canvas->scale(16, 16); |
| 526 | SkBitmap bitmap; |
| 527 | SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGB_888x_SkColorType, kOpaque_SkAlphaType); |
| 528 | bitmap.allocPixels(imageInfo); |
| 529 | SkCanvas offscreen(bitmap); |
| 530 | offscreen.clear(SK_ColorGREEN); |
| 531 | canvas->drawBitmap(bitmap, 0, 0); |
| 532 | auto pack888 = [](unsigned r, unsigned g, unsigned b) -> uint32_t { |
| 533 | return (r << 0) | (g << 8) | (b << 16); |
| 534 | }; |
| 535 | uint32_t red888[] = { pack888(0xFF, 0x00, 0x00), pack888(0xbb, 0x00, 0x00), |
| 536 | pack888(0x77, 0x00, 0x00), pack888(0x33, 0x00, 0x00) }; |
| 537 | uint32_t blue888[] = { pack888(0x00, 0x00, 0xFF), pack888(0x00, 0x00, 0xbb), |
| 538 | pack888(0x00, 0x00, 0x77), pack888(0x00, 0x00, 0x33) }; |
| 539 | if (bitmap.installPixels(imageInfo, (void*) red888, imageInfo.minRowBytes())) { |
| 540 | canvas->drawBitmap(bitmap, 2, 2); |
| 541 | } |
| 542 | if (bitmap.installPixels(imageInfo, (void*) blue888, imageInfo.minRowBytes())) { |
| 543 | canvas->drawBitmap(bitmap, 4, 4); |
| 544 | } |
| 545 | ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 546 | #SeeAlso RGBA_8888 BGRA_8888 |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 547 | ## |
| 548 | |
| 549 | #Subtopic BGRA_8888 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 550 | #Line # encodes ARGB Little_Endian in 32 bits ## |
| 551 | kBGRA_8888_SkColorType encodes ARGB into a 32-bit word. Each component: |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 552 | blue, green, red, and alpha; use eight bits, describing 256 levels. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 553 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 554 | #Illustration |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 555 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 556 | If paired with kPremul_SkAlphaType: blue, green, and red components are |
| 557 | Premultiplied by the alpha value. If blue, green, or red is greater than alpha, |
| 558 | the drawn result is undefined. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 559 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 560 | If paired with kUnpremul_SkAlphaType: blue, green, red, and alpha components |
| 561 | may have any value. There may be a performance penalty with Unpremultiplied |
| 562 | pixels. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 563 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 564 | If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum; |
| 565 | blue, green, and red components are fully opaque. If any alpha component is |
| 566 | less than 255, the drawn result is undefined. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 567 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 568 | On Little_Endian platforms, kBGRA_8888_SkColorType is the native Color_Type, |
| 569 | and will have the best performance. Use kN32_SkColorType to choose the best |
| 570 | Color_Type for the platform at compile time. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 571 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 572 | #Example |
| 573 | #Height 96 |
| 574 | canvas->scale(16, 16); |
| 575 | SkBitmap bitmap; |
| 576 | SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kBGRA_8888_SkColorType, kPremul_SkAlphaType); |
| 577 | bitmap.allocPixels(imageInfo); |
| 578 | SkCanvas offscreen(bitmap); |
| 579 | offscreen.clear(SK_ColorGREEN); |
| 580 | canvas->drawBitmap(bitmap, 0, 0); |
| 581 | auto pack8888 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint32_t { |
| 582 | return (b << 0) | (g << 8) | (r << 16) | (a << 24); |
| 583 | }; |
| 584 | uint32_t red8888[] = { pack8888(0xFF, 0xFF, 0x0, 0x0), pack8888(0xFF, 0xbb, 0x0, 0x0), |
| 585 | pack8888(0xFF, 0x99, 0x0, 0x0), pack8888(0xFF, 0x55, 0x0, 0x0) }; |
| 586 | uint32_t blue8888[] = { pack8888(0xFF, 0x0, 0x0, 0x0FF), pack8888(0xFF, 0x0, 0x0, 0x0bb), |
| 587 | pack8888(0xFF, 0x0, 0x0, 0x099), pack8888(0xFF, 0x0, 0x0, 0x055) }; |
| 588 | SkPixmap redPixmap(imageInfo, &red8888, imageInfo.minRowBytes()); |
| 589 | if (bitmap.writePixels(redPixmap, 0, 0)) { |
| 590 | canvas->drawBitmap(bitmap, 2, 2); |
| 591 | } |
| 592 | SkPixmap bluePixmap(imageInfo, &blue8888, imageInfo.minRowBytes()); |
| 593 | if (bitmap.writePixels(bluePixmap, 0, 0)) { |
| 594 | canvas->drawBitmap(bitmap, 4, 4); |
| 595 | } |
| 596 | ## |
| 597 | #SeeAlso RGBA_8888 |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 598 | ## |
| 599 | |
| 600 | #Subtopic RGBA_1010102 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 601 | #Line # encodes ARGB ten bits per color component ## |
| 602 | kRGBA_1010102_SkColorType encodes ARGB into a 32-bit word. Each |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 603 | Color component: red, green, and blue; use ten bits, describing 1024 levels. |
| 604 | Two bits contain alpha, describing four levels. Possible alpha |
| 605 | values are zero: fully transparent; one: 33% opaque; two: 67% opaque; |
| 606 | three: fully opaque. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 607 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 608 | At present, Color in Paint does not provide enough precision to |
| 609 | draw all colors possible to a kRGBA_1010102_SkColorType Surface. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 610 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 611 | #Illustration |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 612 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 613 | If paired with kPremul_SkAlphaType: red, green, and blue components are |
| 614 | Premultiplied by the alpha value. If red, green, or blue is greater than the |
| 615 | alpha replicated to ten bits, the drawn result is undefined. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 616 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 617 | If paired with kUnpremul_SkAlphaType: alpha, red, green, and blue components |
| 618 | may have any value. There may be a performance penalty with Unpremultiplied |
| 619 | pixels. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 620 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 621 | If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum; |
| 622 | red, green, and blue components are fully opaque. If any alpha component is |
| 623 | less than three, the drawn result is undefined. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 624 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 625 | #Example |
| 626 | #Bug 7645 |
| 627 | #Height 96 |
| 628 | #Platform cpu |
| 629 | canvas->scale(16, 16); |
| 630 | SkBitmap bitmap; |
| 631 | SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGBA_1010102_SkColorType, kOpaque_SkAlphaType); |
| 632 | bitmap.allocPixels(imageInfo); |
| 633 | SkCanvas offscreen(bitmap); |
| 634 | offscreen.clear(SK_ColorGREEN); |
| 635 | canvas->drawBitmap(bitmap, 0, 0); |
| 636 | auto pack1010102 = [](unsigned r, unsigned g, unsigned b, unsigned a) -> uint32_t { |
| 637 | return (r << 0) | (g << 10) | (b << 20) | (a << 30); |
| 638 | }; |
| 639 | uint32_t redBits[] = { pack1010102(0x3FF, 0x000, 0x000, 0x3), |
| 640 | pack1010102(0x2ff, 0x000, 0x000, 0x3), |
| 641 | pack1010102(0x1ff, 0x000, 0x000, 0x3), |
| 642 | pack1010102(0x0ff, 0x000, 0x000, 0x3) }; |
| 643 | uint32_t blueBits[] = { pack1010102(0x000, 0x000, 0x3FF, 0x3), |
| 644 | pack1010102(0x000, 0x000, 0x2ff, 0x3), |
| 645 | pack1010102(0x000, 0x000, 0x1ff, 0x3), |
| 646 | pack1010102(0x000, 0x000, 0x0ff, 0x3) }; |
| 647 | if (bitmap.installPixels(imageInfo, (void*) redBits, imageInfo.minRowBytes())) { |
| 648 | canvas->drawBitmap(bitmap, 2, 2); |
| 649 | } |
| 650 | SkPixmap bluePixmap(imageInfo, &blueBits, imageInfo.minRowBytes()); |
| 651 | if (bitmap.installPixels(imageInfo, (void*) blueBits, imageInfo.minRowBytes())) { |
| 652 | canvas->drawBitmap(bitmap, 4, 4); |
| 653 | } |
| 654 | ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 655 | #SeeAlso RGB_101010 RGBA_8888 |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 656 | ## |
| 657 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 658 | #Subtopic RGB_101010 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 659 | #Line # encodes RGB ten bits per color component ## |
| 660 | kRGB_101010x_SkColorType encodes RGB into a 32-bit word. Each |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 661 | Color component: red, green, and blue; use ten bits, describing 1024 levels. |
| 662 | Two bits are unused. Pixels described by kRGB_101010x_SkColorType are fully |
| 663 | opaque as if its Color_Alpha was set to one, and should always be paired |
| 664 | with kOpaque_SkAlphaType. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 665 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 666 | At present, Color in Paint does not provide enough precision to |
| 667 | draw all colors possible to a kRGB_101010x_SkColorType Surface. |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 668 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 669 | #Illustration |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 670 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 671 | #Example |
| 672 | #Bug 7645 |
| 673 | #Height 96 |
| 674 | #Platform cpu |
| 675 | canvas->scale(16, 16); |
| 676 | SkBitmap bitmap; |
| 677 | SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGB_101010x_SkColorType, kOpaque_SkAlphaType); |
| 678 | bitmap.allocPixels(imageInfo); |
| 679 | SkCanvas offscreen(bitmap); |
| 680 | offscreen.clear(SK_ColorGREEN); |
| 681 | canvas->drawBitmap(bitmap, 0, 0); |
| 682 | auto pack101010x = [](unsigned r, unsigned g, unsigned b) -> uint32_t { |
| 683 | return (r << 0) | (g << 10) | (b << 20); |
| 684 | }; |
| 685 | uint32_t redBits[] = { pack101010x(0x3FF, 0x000, 0x000), pack101010x(0x2ff, 0x000, 0x000), |
| 686 | pack101010x(0x1ff, 0x000, 0x000), pack101010x(0x0ff, 0x000, 0x000) }; |
| 687 | uint32_t blueBits[] = { pack101010x(0x000, 0x000, 0x3FF), pack101010x(0x000, 0x000, 0x2ff), |
| 688 | pack101010x(0x000, 0x000, 0x1ff), pack101010x(0x000, 0x000, 0x0ff) }; |
| 689 | if (bitmap.installPixels(imageInfo, (void*) redBits, imageInfo.minRowBytes())) { |
| 690 | canvas->drawBitmap(bitmap, 2, 2); |
| 691 | } |
| 692 | SkPixmap bluePixmap(imageInfo, &blueBits, imageInfo.minRowBytes()); |
| 693 | if (bitmap.installPixels(imageInfo, (void*) blueBits, imageInfo.minRowBytes())) { |
| 694 | canvas->drawBitmap(bitmap, 4, 4); |
| 695 | } |
| 696 | ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 697 | #SeeAlso RGBA_1010102 |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 698 | ## |
| 699 | |
| 700 | #Subtopic Gray_8 |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 701 | #Line # encodes level of grayscale in 8 bits ## |
| 702 | kGray_8_SkColorType encodes grayscale level in eight bits that is equivalent |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 703 | to equal values for red, blue, and green, representing colors from black to |
| 704 | white. Pixels described by kGray_8_SkColorType are fully |
| 705 | opaque as if its Color_Alpha was set to one, and should always be paired with |
| 706 | kOpaque_SkAlphaType. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 707 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 708 | #Example |
| 709 | #Height 64 |
| 710 | canvas->scale(16, 16); |
| 711 | SkBitmap bitmap; |
| 712 | SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kGray_8_SkColorType, kOpaque_SkAlphaType); |
| 713 | bitmap.allocPixels(imageInfo); |
| 714 | SkCanvas offscreen(bitmap); |
| 715 | offscreen.clear(SK_ColorGREEN); |
| 716 | canvas->drawBitmap(bitmap, 0, 0); |
| 717 | uint8_t gray8[] = { 0xFF, 0xBB, 0x77, 0x33 }; |
| 718 | SkPixmap grayPixmap(imageInfo, &gray8, imageInfo.minRowBytes()); |
| 719 | if (bitmap.writePixels(grayPixmap, 0, 0)) { |
| 720 | canvas->drawBitmap(bitmap, 2, 2); |
| 721 | } |
| 722 | ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 723 | #SeeAlso Alpha_8 |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 724 | ## |
| 725 | |
| 726 | #Subtopic RGBA_F16 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 727 | #Line # encodes ARGB as half floats ## |
| 728 | kRGBA_F16_SkColorType encodes ARGB into a 64-bit word. Each component: |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 729 | blue, green, red, and alpha; use 16 bits, describing a floating point value, |
Cary Clark | 929e436 | 2018-06-19 09:07:28 -0400 | [diff] [blame] | 730 | from -65500 to 65000 with 3.31 decimal digits of precision. |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 731 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 732 | At present, Color in Paint does not provide enough precision or range to |
| 733 | draw all colors possible to a kRGBA_F16_SkColorType Surface. |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 734 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 735 | Each component encodes a floating point value using |
| 736 | #A Half floats # https://www.khronos.org/opengl/wiki/Small_Float_Formats ## |
| 737 | . Meaningful colors are represented by the range 0.0 to 1.0, although smaller |
| 738 | and larger values may be useful when used in combination with Transfer_Mode. |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 739 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 740 | #Illustration |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 741 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 742 | If paired with kPremul_SkAlphaType: blue, green, and red components are |
| 743 | Premultiplied by the alpha value. If blue, green, or red is greater than alpha, |
| 744 | the drawn result is undefined. |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 745 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 746 | If paired with kUnpremul_SkAlphaType: blue, green, red, and alpha components |
| 747 | may have any value. There may be a performance penalty with Unpremultiplied |
| 748 | pixels. |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 749 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 750 | If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum; |
| 751 | blue, green, and red components are fully opaque. If any alpha component is |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 752 | less than one, the drawn result is undefined. |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 753 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 754 | #ToDo |
| 755 | FloatToHalf should be replaced with SkFloatToHalf if/when that's made public |
| 756 | ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 757 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 758 | #Example |
| 759 | #Height 96 |
| 760 | #Function |
| 761 | union FloatUIntUnion { |
| 762 | uint32_t fUInt; |
| 763 | float fFloat; |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 764 | }; |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 765 | |
| 766 | uint16_t FloatToHalf(float f) { |
| 767 | static const FloatUIntUnion magic = { 15 << 23 }; |
| 768 | static const uint32_t round_mask = ~0xfffu; |
| 769 | FloatUIntUnion floatUnion; |
| 770 | floatUnion.fFloat = f; |
| 771 | uint32_t sign = floatUnion.fUInt & 0x80000000u; |
| 772 | floatUnion.fUInt ^= sign; |
| 773 | floatUnion.fUInt &= round_mask; |
| 774 | floatUnion.fFloat *= magic.fFloat; |
| 775 | floatUnion.fUInt -= round_mask; |
| 776 | return (floatUnion.fUInt >> 13) | (sign >> 16); |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 777 | } |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 778 | ## |
| 779 | |
| 780 | void draw(SkCanvas* canvas) { |
| 781 | canvas->scale(16, 16); |
| 782 | SkBitmap bitmap; |
| 783 | SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGBA_F16_SkColorType, kPremul_SkAlphaType); |
| 784 | bitmap.allocPixels(imageInfo); |
| 785 | SkCanvas offscreen(bitmap); |
| 786 | offscreen.clear(SK_ColorGREEN); |
| 787 | canvas->drawBitmap(bitmap, 0, 0); |
| 788 | auto H = [](float c) -> uint16_t { |
| 789 | return FloatToHalf(c); |
| 790 | }; |
| 791 | // R G B A |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 792 | uint16_t red_f16[][4] = { { H(1.0), H(0.0), H(0.0), H(1.0) }, |
| 793 | { H(.75), H(0.0), H(0.0), H(1.0) }, |
| 794 | { H(.50), H(0.0), H(0.0), H(1.0) }, |
| 795 | { H(.25), H(0.0), H(0.0), H(1.0) } }; |
| 796 | uint16_t blue_f16[][4] = { { H(0.0), H(0.0), H(1.0), H(1.0) }, |
| 797 | { H(0.0), H(0.0), H(.75), H(1.0) }, |
| 798 | { H(0.0), H(0.0), H(.50), H(1.0) }, |
| 799 | { H(0.0), H(0.0), H(.25), H(1.0) } }; |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 800 | SkPixmap redPixmap(imageInfo, red_f16, imageInfo.minRowBytes()); |
| 801 | if (bitmap.writePixels(redPixmap, 0, 0)) { |
| 802 | canvas->drawBitmap(bitmap, 2, 2); |
| 803 | } |
| 804 | SkPixmap bluePixmap(imageInfo, blue_f16, imageInfo.minRowBytes()); |
| 805 | if (bitmap.writePixels(bluePixmap, 0, 0)) { |
| 806 | canvas->drawBitmap(bitmap, 4, 4); |
| 807 | } |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 808 | } |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 809 | ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 810 | #SeeAlso SkColor4f |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 811 | ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 812 | |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 813 | #Subtopic RGBA_F32 |
| 814 | #Line # encodes ARGB as single precision floats ## |
| 815 | kRGBA_F32_SkColorType encodes ARGB into a 128-bit word. Each component: |
| 816 | blue, green, red, and alpha; use 32 bits, describing a floating point value, |
| 817 | from -3.402823e+38 to 3.402823e+38 with 7.225 decimal digits of precision. |
| 818 | |
| 819 | At present, Color in Paint does not provide enough precision or range to |
| 820 | draw all colors possible to a kRGBA_F32_SkColorType Surface. |
| 821 | |
| 822 | Each component encodes a floating point value using |
| 823 | #A single-precision floats # https://en.wikipedia.org/wiki/Single-precision_floating-point_format ## |
| 824 | . Meaningful colors are represented by the range 0.0 to 1.0, although smaller |
| 825 | and larger values may be useful when used in combination with Transfer_Mode. |
| 826 | |
| 827 | #Illustration |
| 828 | |
| 829 | If paired with kPremul_SkAlphaType: blue, green, and red components are |
| 830 | Premultiplied by the alpha value. If blue, green, or red is greater than alpha, |
| 831 | the drawn result is undefined. |
| 832 | |
| 833 | If paired with kUnpremul_SkAlphaType: blue, green, red, and alpha components |
| 834 | may have any value. There may be a performance penalty with Unpremultiplied |
| 835 | pixels. |
| 836 | |
| 837 | If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum; |
| 838 | blue, green, and red components are fully opaque. If any alpha component is |
| 839 | less than one, the drawn result is undefined. |
| 840 | |
| 841 | #NoExample |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 842 | canvas->scale(16, 16); |
| 843 | SkBitmap bitmap; |
| 844 | SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGBA_F32_SkColorType, kPremul_SkAlphaType); |
| 845 | bitmap.allocPixels(imageInfo); |
| 846 | SkCanvas offscreen(bitmap); |
| 847 | offscreen.clear(SK_ColorGREEN); |
| 848 | canvas->drawBitmap(bitmap, 0, 0); |
| 849 | // R G B A |
| 850 | float red_f32[][4] = { { 1.0, 0.0, 0.0, 1.0 }, |
| 851 | { .75, 0.0, 0.0, 1.0 }, |
| 852 | { .50, 0.0, 0.0, 1.0 }, |
| 853 | { .25, 0.0, 0.0, 1.0 } }; |
| 854 | float blue_f32[][4] = { { 0.0, 0.0, 1.0, 1.0 }, |
| 855 | { 0.0, 0.0, .75, 1.0 }, |
| 856 | { 0.0, 0.0, .50, 1.0 }, |
| 857 | { 0.0, 0.0, .25, 1.0 } }; |
| 858 | SkPixmap redPixmap(imageInfo, red_f32, imageInfo.minRowBytes()); |
| 859 | if (bitmap.writePixels(redPixmap, 0, 0)) { |
| 860 | canvas->drawBitmap(bitmap, 2, 2); |
| 861 | } |
| 862 | SkPixmap bluePixmap(imageInfo, blue_f32, imageInfo.minRowBytes()); |
| 863 | if (bitmap.writePixels(bluePixmap, 0, 0)) { |
| 864 | canvas->drawBitmap(bitmap, 4, 4); |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 865 | } |
| 866 | ## |
| 867 | #SeeAlso SkColor4f |
| 868 | ## |
| 869 | |
| 870 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 871 | #Subtopic Color_Type ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 872 | |
| 873 | # ------------------------------------------------------------------------------ |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 874 | |
| 875 | #Method int SkColorTypeBytesPerPixel(SkColorType ct) |
| 876 | #In Property |
| 877 | #Line # returns Color_Type byte size ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 878 | #Populate |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 879 | |
| 880 | #Example |
| 881 | #Height 192 |
| 882 | const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", |
| 883 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" }; |
| 884 | SkPaint paint; |
Mike Reed | 729bb19 | 2019-02-13 16:56:13 -0500 | [diff] [blame] | 885 | SkFont font(SkTypeface::MakeFromName("monospace", SkFontStyle()), 10); |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 886 | int y = 15; |
| 887 | canvas->drawString(" colorType bytes", 10, y, paint); |
| 888 | for (SkColorType colorType : { #list_of_color_types# |
| 889 | } ) { |
| 890 | int result = SkColorTypeBytesPerPixel(colorType); |
| 891 | SkString string; |
| 892 | string.printf("%13s %4d", colors[(int) colorType], result); |
Mike Reed | 729bb19 | 2019-02-13 16:56:13 -0500 | [diff] [blame] | 893 | canvas->drawString(string, 10, y += 14, font, paint); |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 894 | } |
| 895 | ## |
| 896 | #SeeAlso SkImageInfo::bytesPerPixel |
| 897 | ## |
| 898 | |
| 899 | # ------------------------------------------------------------------------------ |
| 900 | |
| 901 | #Method bool SkColorTypeIsAlwaysOpaque(SkColorType ct) |
| 902 | #In Property |
| 903 | #Line # returns if Color_Type includes Color_Alpha ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 904 | #Populate |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 905 | |
| 906 | #Example |
| 907 | #Height 192 |
| 908 | const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", |
| 909 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" }; |
| 910 | SkPaint paint; |
Mike Reed | 729bb19 | 2019-02-13 16:56:13 -0500 | [diff] [blame] | 911 | SkFont font(SkTypeface::MakeFromName("monospace", SkFontStyle()), 10); |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 912 | int y = 15; |
| 913 | canvas->drawString(" colorType bytes", 10, y, paint); |
| 914 | for (SkColorType colorType : { #list_of_color_types# |
| 915 | } ) { |
| 916 | bool result = SkColorTypeIsAlwaysOpaque(colorType); |
| 917 | SkString string; |
| 918 | string.printf("%13s %6s", colors[(int) colorType], result ? "true" : "false"); |
Mike Reed | 729bb19 | 2019-02-13 16:56:13 -0500 | [diff] [blame] | 919 | canvas->drawString(string, 10, y += 14, font, paint); |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 920 | } |
| 921 | ## |
| 922 | #SeeAlso SkColorTypeValidateAlphaType |
| 923 | ## |
| 924 | |
| 925 | # ------------------------------------------------------------------------------ |
| 926 | |
| 927 | #Method bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType, |
| 928 | SkAlphaType* canonical = nullptr) |
| 929 | #In Property |
| 930 | #Line # returns if Alpha_Type is valid ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 931 | #Populate |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 932 | |
| 933 | #Example |
| 934 | #Height 640 |
| 935 | const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", |
| 936 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" }; |
| 937 | const char* alphas[] = {"Unknown ", "Opaque ", "Premul ", "Unpremul"}; |
| 938 | SkAlphaType alphaTypes[] = { #list_of_alpha_types# |
| 939 | }; |
| 940 | SkPaint paint; |
Mike Reed | 729bb19 | 2019-02-13 16:56:13 -0500 | [diff] [blame] | 941 | SkFont font(SkTypeface::MakeFromName("monospace", SkFontStyle()), 10); |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 942 | int y = 15; |
| 943 | canvas->drawString(" colorType alphaType canonical", 10, y, paint); |
| 944 | for (SkColorType colorType : { #list_of_color_types# |
| 945 | } ) { |
| 946 | for (SkAlphaType alphaType : alphaTypes) { |
| 947 | SkAlphaType canonicalAlphaType = kUnknown_SkAlphaType; |
| 948 | bool result = SkColorTypeValidateAlphaType(colorType, alphaType, &canonicalAlphaType); |
| 949 | SkString string; |
| 950 | string.printf("%13s %10s %10s", colors[(int) colorType], alphas[(int) alphaType], |
| 951 | result ? alphas[(int) canonicalAlphaType] : "------ "); |
| 952 | canvas->drawString(string, 10, y += 14, paint); |
| 953 | } |
| 954 | } |
| 955 | ## |
| 956 | #SeeAlso SkColorTypeIsAlwaysOpaque |
| 957 | ## |
| 958 | |
| 959 | # ------------------------------------------------------------------------------ |
Cary Clark | 77295347 | 2018-02-12 09:38:08 -0500 | [diff] [blame] | 960 | #Subtopic YUV_ColorSpace |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 961 | #Line # color range of YUV pixels ## |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 962 | #Alias YUV_ColorSpace ## |
| 963 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 964 | #Enum SkYUVColorSpace |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 965 | #Line # color range of YUV pixels ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 966 | |
| 967 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 968 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 969 | ## |
| 970 | |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 971 | Describes color range of YUV pixels. The color mapping from YUV to RGB varies |
| 972 | depending on the source. YUV pixels may be generated by JPEG images, standard |
| 973 | video streams, or high definition video streams. Each has its own mapping from |
| 974 | YUV and RGB. |
| 975 | |
| 976 | JPEG YUV values encode the full range of 0 to 255 for all three components. |
| 977 | Video YUV values range from 16 to 235 for all three components. Details of |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 978 | encoding and conversion to RGB are described in |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 979 | #A YCbCr color space # https://en.wikipedia.org/wiki/YCbCr ## |
| 980 | . |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 981 | |
| 982 | #Const kJPEG_SkYUVColorSpace 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 983 | #Line # describes full range ## |
| 984 | Describes standard JPEG color space; |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 985 | #A CCIR 601 # https://en.wikipedia.org/wiki/Rec._601 ## |
| 986 | with full range of 0 to 255 for components. |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 987 | ## |
| 988 | #Const kRec601_SkYUVColorSpace 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 989 | #Line # describes SDTV range ## |
| 990 | Describes standard used by standard definition television; |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 991 | #A CCIR 601 # https://en.wikipedia.org/wiki/Rec._601 ## |
| 992 | with studio range of 16 to 235 range for components. |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 993 | ## |
| 994 | #Const kRec709_SkYUVColorSpace 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 995 | #Line # describes HDTV range ## |
| 996 | Describes standard used by high definition television; |
| 997 | #A Rec. 709 # https://en.wikipedia.org/wiki/Rec._709 ## |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 998 | with studio range of 16 to 235 range for components. |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 999 | ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1000 | #Const kLastEnum_SkYUVColorSpace 2 |
| 1001 | #Line # last valid value ## |
| 1002 | Used by tests to iterate through all valid values. |
| 1003 | ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1004 | |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 1005 | #NoExample |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1006 | ## |
| 1007 | |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 1008 | #SeeAlso SkImage::MakeFromYUVTexturesCopy SkImage::MakeFromNV12TexturesCopy |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1009 | |
| 1010 | #Enum SkYUVColorSpace ## |
Cary Clark | 77295347 | 2018-02-12 09:38:08 -0500 | [diff] [blame] | 1011 | #Subtopic YUV_ColorSpace ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1012 | |
| 1013 | # ------------------------------------------------------------------------------ |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1014 | |
| 1015 | #Struct SkImageInfo |
| 1016 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1017 | #Code |
| 1018 | #Populate |
| 1019 | ## |
| 1020 | |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 1021 | Describes pixel dimensions and encoding. Bitmap, Image, Pixmap, and Surface |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1022 | can be created from Image_Info. Image_Info can be retrieved from Bitmap and |
| 1023 | Pixmap, but not from Image and Surface. For example, Image and Surface |
| 1024 | implementations may defer pixel depth, so may not completely specify Image_Info. |
| 1025 | |
| 1026 | Image_Info contains dimensions, the pixel integral width and height. It encodes |
| 1027 | how pixel bits describe Color_Alpha, transparency; Color components red, blue, |
| 1028 | and green; and Color_Space, the range and linearity of colors. |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1029 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1030 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1031 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1032 | #Method SkImageInfo() |
| 1033 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1034 | #In Constructors |
Cary Clark | 82f1f74 | 2018-06-28 08:50:35 -0400 | [diff] [blame] | 1035 | #Line # creates with zeroed dimensions, kUnknown_SkColorType, kUnknown_SkAlphaType ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1036 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1037 | |
| 1038 | #Example |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1039 | #Height 32 |
| 1040 | #Description |
| 1041 | An empty Image_Info may be passed to SkCanvas::accessTopLayerPixels as storage |
| 1042 | for the Canvas actual Image_Info. |
| 1043 | ## |
| 1044 | SkImageInfo imageInfo; |
| 1045 | size_t rowBytes; |
| 1046 | SkIPoint origin; |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1047 | (void) canvas->accessTopLayerPixels(&imageInfo, &rowBytes, &origin); |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1048 | const char* alphaType[] = { "Unknown", "Opaque", "Premul", "Unpremul" }; |
| 1049 | SkString string; |
| 1050 | string.printf("k%s_SkAlphaType", alphaType[(int) imageInfo.alphaType()]); |
| 1051 | SkPaint paint; |
| 1052 | canvas->drawString(string, 20, 20, paint); |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1053 | ## |
| 1054 | |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1055 | #SeeAlso Make MakeN32 MakeS32 MakeA8 |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1056 | |
| 1057 | #Method ## |
| 1058 | |
| 1059 | # ------------------------------------------------------------------------------ |
| 1060 | |
| 1061 | #Method static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at, |
| 1062 | sk_sp<SkColorSpace> cs = nullptr) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1063 | #In Constructors |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1064 | #Line # creates Image_Info from dimensions, Color_Type, Alpha_Type, Color_Space ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1065 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1066 | |
| 1067 | #Example |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1068 | #Height 48 |
| 1069 | uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 }, |
| 1070 | { 0xAC, 0xA8, 0x89, 0xA7, 0x87 }, |
| 1071 | { 0x9B, 0xB5, 0xE5, 0x95, 0x46 }, |
| 1072 | { 0x90, 0x81, 0xC5, 0x71, 0x33 }, |
| 1073 | { 0x75, 0x55, 0x44, 0x40, 0x30 }}; |
| 1074 | SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType); |
| 1075 | SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5); |
| 1076 | SkBitmap bitmap; |
| 1077 | bitmap.installPixels(pixmap); |
| 1078 | canvas->scale(8, 8); |
| 1079 | canvas->drawBitmap(bitmap, 0, 0); |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1080 | ## |
| 1081 | |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1082 | #SeeAlso MakeN32 MakeN32Premul MakeS32 MakeA8 |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1083 | |
| 1084 | #Method ## |
| 1085 | |
| 1086 | # ------------------------------------------------------------------------------ |
| 1087 | |
| 1088 | #Method static SkImageInfo MakeN32(int width, int height, SkAlphaType at, |
| 1089 | sk_sp<SkColorSpace> cs = nullptr) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1090 | #In Constructors |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1091 | #Line # creates Image_Info with Native_Color_Type ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1092 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1093 | |
| 1094 | #Example |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1095 | #Height 128 |
| 1096 | SkBitmap bitmap; |
| 1097 | bitmap.allocPixels(SkImageInfo::MakeN32(16, 16, kPremul_SkAlphaType)); |
| 1098 | SkCanvas offscreen(bitmap); |
| 1099 | offscreen.clear(SK_ColorWHITE); |
| 1100 | SkPaint paint; |
| 1101 | offscreen.drawString("g", 0, 10, paint); |
| 1102 | canvas->scale(8, 8); |
| 1103 | canvas->drawBitmap(bitmap, 0, 0); |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1104 | ## |
| 1105 | |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1106 | #SeeAlso Make MakeN32Premul MakeS32 MakeA8 |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1107 | |
| 1108 | #Method ## |
| 1109 | |
| 1110 | # ------------------------------------------------------------------------------ |
| 1111 | |
| 1112 | #Method static SkImageInfo MakeS32(int width, int height, SkAlphaType at) |
| 1113 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1114 | #In Constructors |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1115 | #Line # creates Image_Info with Native_Color_Type, sRGB Color_Space ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1116 | #Populate |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1117 | |
| 1118 | #Example |
| 1119 | #Set sRGB |
| 1120 | #Height 128 |
| 1121 | #Description |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1122 | Top gradient is drawn to offScreen without Color_Space. It is darker than middle |
| 1123 | gradient, drawn to offScreen with sRGB Color_Space. Bottom gradient shares bits |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1124 | with middle, but does not specify the Color_Space in noColorSpaceBitmap. A source |
| 1125 | without Color_Space is treated as sRGB; the bottom gradient is identical to the |
| 1126 | middle gradient. |
| 1127 | ## |
| 1128 | const int width = 256; |
| 1129 | const int height = 32; |
| 1130 | SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
| 1131 | SkColor gradColors[] = { 0xFFAA0055, 0xFF11CC88 }; |
| 1132 | SkPoint gradPoints[] = { { 0, 0 }, { width, 0 } }; |
| 1133 | SkPaint gradPaint; |
| 1134 | gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr, |
| 1135 | SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode)); |
| 1136 | SkBitmap bitmap; |
| 1137 | bitmap.allocPixels(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType)); |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1138 | SkCanvas offScreen(bitmap); |
| 1139 | offScreen.drawRect(SkRect::MakeWH(width, height), gradPaint); |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1140 | canvas->drawBitmap(bitmap, 0, 0); |
| 1141 | bitmap.allocPixels(SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType)); |
| 1142 | SkCanvas sRGBOffscreen(bitmap); |
| 1143 | sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint); |
| 1144 | canvas->drawBitmap(bitmap, 0, 48); |
| 1145 | SkBitmap noColorSpaceBitmap; |
| 1146 | noColorSpaceBitmap.setInfo(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType)); |
| 1147 | noColorSpaceBitmap.setPixels(bitmap.getAddr(0, 0)); |
| 1148 | canvas->drawBitmap(noColorSpaceBitmap, 0, 96); |
| 1149 | ## |
| 1150 | |
| 1151 | #SeeAlso Make MakeN32 MakeN32Premul MakeA8 |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1152 | |
| 1153 | #Method ## |
| 1154 | |
| 1155 | # ------------------------------------------------------------------------------ |
| 1156 | |
| 1157 | #Method static SkImageInfo MakeN32Premul(int width, int height, sk_sp<SkColorSpace> cs = nullptr) |
| 1158 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1159 | #In Constructors |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1160 | #Line # creates Image_Info with Native_Color_Type, kPremul_SkAlphaType ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1161 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1162 | |
| 1163 | #Example |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 1164 | #Height 128 |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1165 | SkBitmap bitmap; |
| 1166 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(18, 18)); |
| 1167 | SkCanvas offscreen(bitmap); |
| 1168 | offscreen.clear(SK_ColorWHITE); |
| 1169 | SkPaint paint; |
Mike Reed | 729bb19 | 2019-02-13 16:56:13 -0500 | [diff] [blame] | 1170 | SkFont font(nullptr, 15); |
| 1171 | offscreen.drawString("\xF0\x9F\x98\xB8", 1, 15, font, paint); |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1172 | canvas->scale(6, 6); |
| 1173 | canvas->drawBitmap(bitmap, 0, 0); |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1174 | ## |
| 1175 | |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1176 | #SeeAlso MakeN32 MakeS32 MakeA8 Make |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1177 | |
| 1178 | #Method ## |
| 1179 | |
| 1180 | # ------------------------------------------------------------------------------ |
| 1181 | |
| 1182 | #Method static SkImageInfo MakeN32Premul(const SkISize& size) |
| 1183 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1184 | #In Constructors |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1185 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1186 | |
| 1187 | #Example |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 1188 | #Height 128 |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1189 | SkBitmap bitmap; |
| 1190 | bitmap.allocPixels(SkImageInfo::MakeN32Premul({18, 18})); |
| 1191 | SkCanvas offscreen(bitmap); |
| 1192 | offscreen.clear(SK_ColorWHITE); |
| 1193 | SkPaint paint; |
Mike Reed | 729bb19 | 2019-02-13 16:56:13 -0500 | [diff] [blame] | 1194 | SkFont font(nullptr, 15); |
| 1195 | offscreen.drawString("\xF0\x9F\x98\xB9", 1, 15, font, paint); |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1196 | canvas->scale(6, 6); |
| 1197 | canvas->drawBitmap(bitmap, 0, 0); |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1198 | ## |
| 1199 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1200 | #SeeAlso MakeN32 MakeS32 MakeA8 Make |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1201 | |
| 1202 | #Method ## |
| 1203 | |
| 1204 | # ------------------------------------------------------------------------------ |
| 1205 | |
| 1206 | #Method static SkImageInfo MakeA8(int width, int height) |
| 1207 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1208 | #In Constructors |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1209 | #Line # creates Image_Info with kAlpha_8_SkColorType, kPremul_SkAlphaType ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1210 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1211 | |
| 1212 | #Example |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1213 | #Height 64 |
| 1214 | uint8_t pixels[][8] = { { 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00}, |
| 1215 | { 0x00, 0x7f, 0xff, 0x3f, 0x3f, 0x7f, 0x3f, 0x00}, |
| 1216 | { 0x3f, 0xff, 0x7f, 0x00, 0x7f, 0xff, 0x7f, 0x00}, |
| 1217 | { 0x00, 0x3f, 0x00, 0x00, 0x3f, 0x7f, 0x3f, 0x00}, |
| 1218 | { 0x3f, 0x7f, 0x7f, 0x3f, 0x00, 0x00, 0x00, 0x00}, |
| 1219 | { 0x7f, 0xff, 0xff, 0x7f, 0x00, 0x3f, 0x7f, 0x3f}, |
| 1220 | { 0x7f, 0xff, 0xff, 0x7f, 0x00, 0x7f, 0xff, 0x7f}, |
| 1221 | { 0x3f, 0x7f, 0x7f, 0x3f, 0x00, 0x3f, 0x7f, 0x3f} }; |
| 1222 | SkBitmap bitmap; |
| 1223 | bitmap.installPixels(SkImageInfo::MakeA8(8, 8), |
| 1224 | (void*) pixels, sizeof(pixels[0])); |
| 1225 | SkPaint paint; |
| 1226 | canvas->scale(4, 4); |
| 1227 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) { |
| 1228 | paint.setColor(color); |
| 1229 | canvas->drawBitmap(bitmap, 0, 0, &paint); |
| 1230 | canvas->translate(12, 0); |
| 1231 | } |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1232 | ## |
| 1233 | |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1234 | #SeeAlso MakeN32 MakeS32 Make |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1235 | |
| 1236 | #Method ## |
| 1237 | |
| 1238 | # ------------------------------------------------------------------------------ |
| 1239 | |
| 1240 | #Method static SkImageInfo MakeUnknown(int width, int height) |
| 1241 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1242 | #In Constructors |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1243 | #Line # creates Image_Info with kUnknown_SkColorType, kUnknown_SkAlphaType ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1244 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1245 | |
| 1246 | #Example |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1247 | #Height 32 |
| 1248 | #Width 384 |
| 1249 | SkImageInfo info; // default constructor |
| 1250 | SkString string; |
| 1251 | string.printf("SkImageInfo() %c= SkImageInfo::MakeUnknown(0, 0)", |
| 1252 | info == SkImageInfo::MakeUnknown(0, 0) ? '=' : '!'); |
| 1253 | SkPaint paint; |
| 1254 | canvas->drawString(string, 0, 12, paint); |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1255 | ## |
| 1256 | |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1257 | #SeeAlso SkImageInfo() MakeN32 MakeS32 Make |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1258 | |
| 1259 | #Method ## |
| 1260 | |
| 1261 | # ------------------------------------------------------------------------------ |
| 1262 | |
| 1263 | #Method static SkImageInfo MakeUnknown() |
| 1264 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1265 | #In Constructors |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1266 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1267 | |
| 1268 | #Example |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1269 | #Height 32 |
| 1270 | #Width 384 |
| 1271 | SkImageInfo info; // default constructor |
| 1272 | SkString string; |
| 1273 | string.printf("SkImageInfo() %c= SkImageInfo::MakeUnknown()", |
| 1274 | info == SkImageInfo::MakeUnknown() ? '=' : '!'); |
| 1275 | SkPaint paint; |
| 1276 | canvas->drawString(string, 0, 12, paint); |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1277 | ## |
| 1278 | |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1279 | #SeeAlso SkImageInfo() MakeN32 MakeS32 Make |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1280 | |
| 1281 | #Method ## |
| 1282 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1283 | |
| 1284 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1285 | #Subtopic Property |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1286 | #Line # metrics and attributes ## |
| 1287 | ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1288 | |
| 1289 | #Method int width() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1290 | #In Property |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1291 | #Line # returns pixel column count ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1292 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1293 | |
| 1294 | #Example |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1295 | #Image 4 |
| 1296 | #Height 96 |
| 1297 | canvas->translate(10, 10); |
| 1298 | canvas->drawBitmap(source, 0, 0); |
| 1299 | SkImageInfo imageInfo = source.info(); |
| 1300 | canvas->translate(0, imageInfo.height()); |
| 1301 | SkPaint paint; |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1302 | canvas->drawLine(0, 10, imageInfo.width(), 10, paint); |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 1303 | canvas->drawString("width", imageInfo.width() / 2 - 15, 25, paint); |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1304 | ## |
| 1305 | |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1306 | #SeeAlso height SkBitmap::width SkPixelRef::width SkImage::width SkSurface::width |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1307 | |
| 1308 | #Method ## |
| 1309 | |
| 1310 | # ------------------------------------------------------------------------------ |
| 1311 | |
| 1312 | #Method int height() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1313 | #In Property |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1314 | #Line # returns pixel row count ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1315 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1316 | |
| 1317 | #Example |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1318 | #Image 4 |
| 1319 | #Height 96 |
| 1320 | canvas->translate(10, 20); |
| 1321 | canvas->drawBitmap(source, 0, 0); |
| 1322 | SkImageInfo imageInfo = source.info(); |
| 1323 | SkPaint paint; |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1324 | canvas->drawLine(imageInfo.width() + 10, 0, imageInfo.width() + 10, imageInfo.height(), paint); |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 1325 | canvas->drawString("height", imageInfo.width() + 15, imageInfo.height() / 2, paint); |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1326 | ## |
| 1327 | |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1328 | #SeeAlso width SkBitmap::height SkPixelRef::height SkImage::height SkSurface::height |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1329 | |
| 1330 | #Method ## |
| 1331 | |
| 1332 | # ------------------------------------------------------------------------------ |
| 1333 | |
| 1334 | #Method SkColorType colorType() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1335 | #In Property |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1336 | #Line # returns Color_Type ## |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 1337 | Returns Color_Type, one of: #list_of_color_types#. |
| 1338 | |
| 1339 | #Return Color_Type ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1340 | |
| 1341 | #Example |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1342 | const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", |
| 1343 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"}; |
| 1344 | SkImageInfo info = SkImageInfo::MakeA8(16, 32); |
| 1345 | SkDebugf("color type: k" "%s" "_SkColorType\n", colors[info.colorType()]); |
| 1346 | #StdOut |
| 1347 | color type: kAlpha_8_SkColorType |
| 1348 | ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1349 | ## |
| 1350 | |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1351 | #SeeAlso alphaType SkPixmap::colorType SkBitmap::colorType |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1352 | |
| 1353 | #Method ## |
| 1354 | |
| 1355 | # ------------------------------------------------------------------------------ |
| 1356 | |
| 1357 | #Method SkAlphaType alphaType() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1358 | #In Property |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1359 | #Line # returns Alpha_Type ## |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1360 | Returns Alpha_Type, one of: #list_of_alpha_types#. |
| 1361 | |
| 1362 | #Return Alpha_Type ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1363 | |
| 1364 | #Example |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1365 | const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; |
| 1366 | SkImageInfo info = SkImageInfo::MakeA8(16, 32); |
| 1367 | SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[info.alphaType()]); |
| 1368 | #StdOut |
| 1369 | alpha type: kPremul_SkAlphaType |
| 1370 | ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1371 | ## |
| 1372 | |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1373 | #SeeAlso colorType SkPixmap::alphaType SkBitmap::alphaType |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1374 | |
| 1375 | #Method ## |
| 1376 | |
| 1377 | # ------------------------------------------------------------------------------ |
| 1378 | |
| 1379 | #Method SkColorSpace* colorSpace() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1380 | #In Property |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1381 | #Line # returns Color_Space ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1382 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1383 | |
| 1384 | #Example |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1385 | #Description |
| 1386 | SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma |
| 1387 | and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma. |
| 1388 | ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1389 | SkImageInfo info = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType, |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1390 | SkColorSpace::MakeSRGBLinear()); |
| 1391 | SkColorSpace* colorSpace = info.colorSpace(); |
| 1392 | SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n", |
| 1393 | colorSpace->gammaCloseToSRGB() ? "true" : "false", |
| 1394 | colorSpace->gammaIsLinear() ? "true" : "false", |
| 1395 | colorSpace->isSRGB() ? "true" : "false"); |
| 1396 | #StdOut |
| 1397 | gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false |
| 1398 | ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1399 | ## |
| 1400 | |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1401 | #SeeAlso Color_Space SkPixmap::colorSpace SkBitmap::colorSpace |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1402 | |
| 1403 | #Method ## |
| 1404 | |
| 1405 | # ------------------------------------------------------------------------------ |
| 1406 | |
| 1407 | #Method sk_sp<SkColorSpace> refColorSpace() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1408 | #In Property |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1409 | #Line # returns Color_Space ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1410 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1411 | |
| 1412 | #Example |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1413 | SkImageInfo info1 = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType, |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1414 | SkColorSpace::MakeSRGBLinear()); |
| 1415 | SkImageInfo info2 = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType, |
| 1416 | info1.refColorSpace()); |
| 1417 | SkColorSpace* colorSpace = info2.colorSpace(); |
| 1418 | SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n", |
| 1419 | colorSpace->gammaCloseToSRGB() ? "true" : "false", |
| 1420 | colorSpace->gammaIsLinear() ? "true" : "false", |
| 1421 | colorSpace->isSRGB() ? "true" : "false"); |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1422 | ## |
| 1423 | |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1424 | #SeeAlso Color_Space SkBitmap::refColorSpace |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1425 | |
| 1426 | #Method ## |
| 1427 | |
| 1428 | # ------------------------------------------------------------------------------ |
| 1429 | |
| 1430 | #Method bool isEmpty() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1431 | #In Property |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1432 | #Line # returns if dimensions contain pixels ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1433 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1434 | |
| 1435 | #Example |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1436 | for (int width : { 0, 2 } ) { |
| 1437 | for (int height : { 0, 2 } ) { |
| 1438 | SkImageInfo imageInfo= SkImageInfo::MakeA8(width, height); |
| 1439 | SkDebugf("width: %d height: %d empty: %s\n", width, height, |
| 1440 | imageInfo.isEmpty() ? "true" : "false"); |
| 1441 | } |
| 1442 | } |
| 1443 | #StdOut |
| 1444 | width: 0 height: 0 empty: true |
| 1445 | width: 0 height: 2 empty: true |
| 1446 | width: 2 height: 0 empty: true |
| 1447 | width: 2 height: 2 empty: false |
| 1448 | ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1449 | ## |
| 1450 | |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1451 | #SeeAlso dimensions bounds SkBitmap::empty SkPixmap::bounds |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1452 | |
| 1453 | #Method ## |
| 1454 | |
| 1455 | # ------------------------------------------------------------------------------ |
| 1456 | |
| 1457 | #Method bool isOpaque() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1458 | #In Property |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1459 | #Line # returns if Alpha_Type is kOpaque_SkAlphaType ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1460 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1461 | |
| 1462 | #Example |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1463 | const int height = 2; |
| 1464 | const int width = 2; |
| 1465 | SkBitmap bitmap; |
| 1466 | SkImageInfo imageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType); |
| 1467 | bitmap.setInfo(imageInfo); |
| 1468 | for (int index = 0; index < 2; ++index) { |
| 1469 | bitmap.allocPixels(); |
| 1470 | bitmap.eraseColor(0x00000000); |
| 1471 | SkDebugf("isOpaque: %s\n", imageInfo.isOpaque() ? "true" : "false"); |
| 1472 | bitmap.eraseColor(0xFFFFFFFF); |
| 1473 | SkDebugf("isOpaque: %s\n", imageInfo.isOpaque() ? "true" : "false"); |
| 1474 | imageInfo = imageInfo.makeAlphaType(kOpaque_SkAlphaType); |
| 1475 | bitmap.setInfo(imageInfo); |
| 1476 | } |
| 1477 | #StdOut |
| 1478 | isOpaque: false |
| 1479 | isOpaque: false |
| 1480 | isOpaque: true |
| 1481 | isOpaque: true |
| 1482 | ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1483 | ## |
| 1484 | |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1485 | #SeeAlso Color_Alpha SkColorTypeValidateAlphaType SkBitmap::isOpaque SkImage::isOpaque SkPixmap::isOpaque |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1486 | |
| 1487 | #Method ## |
| 1488 | |
| 1489 | # ------------------------------------------------------------------------------ |
| 1490 | |
| 1491 | #Method SkISize dimensions() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1492 | #In Property |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1493 | #Line # returns width() and height() ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1494 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1495 | |
| 1496 | #Example |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1497 | const int height = 2; |
| 1498 | const int width = 2; |
| 1499 | SkImageInfo imageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType); |
| 1500 | SkISize dimensions = imageInfo.dimensions(); |
| 1501 | SkIRect bounds = imageInfo.bounds(); |
| 1502 | SkIRect dimensionsAsBounds = SkIRect::MakeSize(dimensions); |
| 1503 | SkDebugf("dimensionsAsBounds %c= bounds\n", dimensionsAsBounds == bounds ? '=' : '!'); |
| 1504 | #StdOut |
| 1505 | dimensionsAsBounds == bounds |
| 1506 | ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1507 | ## |
| 1508 | |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1509 | #SeeAlso width height bounds SkBitmap::dimensions |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1510 | |
| 1511 | #Method ## |
| 1512 | |
| 1513 | # ------------------------------------------------------------------------------ |
| 1514 | |
| 1515 | #Method SkIRect bounds() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1516 | #In Property |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1517 | #Line # returns width() and height() as Rectangle ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1518 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1519 | |
| 1520 | #Example |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1521 | #Height 64 |
| 1522 | #Image 4 |
| 1523 | canvas->scale(.5f, .5f); |
| 1524 | SkImageInfo imageInfo = source.info(); |
| 1525 | SkIRect bounds = imageInfo.bounds(); |
| 1526 | for (int x : { 0, bounds.width() } ) { |
| 1527 | for (int y : { 0, bounds.height() } ) { |
| 1528 | canvas->drawBitmap(source, x, y); |
| 1529 | } |
| 1530 | } |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1531 | ## |
| 1532 | |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1533 | #SeeAlso width height dimensions |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1534 | |
| 1535 | #Method ## |
| 1536 | |
| 1537 | # ------------------------------------------------------------------------------ |
| 1538 | |
| 1539 | #Method bool gammaCloseToSRGB() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1540 | #In Property |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1541 | #Line # returns if Color_Space gamma is approximately the same as sRGB ## |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1542 | |
| 1543 | Returns true if associated Color_Space is not nullptr, and Color_Space gamma |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1544 | is approximately the same as sRGB. |
| 1545 | This includes the |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1546 | ###$ |
| 1547 | $A sRGB transfer function $ https://en.wikipedia.org/wiki/SRGB#The_sRGB_transfer_function_(%22gamma%22) $$ |
| 1548 | $$$# |
| 1549 | as well as a gamma curve described by a 2.2 exponent. |
| 1550 | |
| 1551 | #Return true if Color_Space gamma is approximately the same as sRGB ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1552 | |
| 1553 | #Example |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1554 | #Height 144 |
| 1555 | const int width = 256; |
| 1556 | const int height = 64; |
| 1557 | auto drawLabel = [=](const char* what, bool closeToSRGB) -> void { |
| 1558 | SkString string; |
| 1559 | string.printf("%s gamma is %s" "close to sRGB", what, closeToSRGB ? "" : "not "); |
| 1560 | SkPaint paint; |
| 1561 | paint.setAntiAlias(true); |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 1562 | canvas->drawString(string, 20, 56, paint); |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1563 | }; |
| 1564 | SkColor gradColors[] = { 0xFFFF7F00, 0xFF00FF7F, 0xFF0000FF, 0xFF7F7FFF }; |
| 1565 | SkPoint gradPoints[] = { { 0, 0 }, { width, 0 }, { width * 2, 0 }, { width * 3, 0 } }; |
| 1566 | SkPaint gradPaint; |
| 1567 | gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr, |
| 1568 | SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode)); |
| 1569 | canvas->drawRect(SkRect::MakeWH(width, height), gradPaint); |
| 1570 | drawLabel("canvas", canvas->imageInfo().gammaCloseToSRGB()); |
| 1571 | SkBitmap bitmap; |
| 1572 | SkImageInfo offscreenInfo = SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType); |
| 1573 | bitmap.allocPixels(offscreenInfo); |
| 1574 | SkCanvas sRGBOffscreen(bitmap); |
| 1575 | sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint); |
| 1576 | canvas->translate(0, 80); |
| 1577 | canvas->drawBitmap(bitmap, 0, 0); |
| 1578 | drawLabel("offscreen", offscreenInfo.gammaCloseToSRGB()); |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1579 | ## |
| 1580 | |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1581 | #SeeAlso SkColorSpace::gammaCloseToSRGB |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1582 | |
| 1583 | #Method ## |
| 1584 | |
| 1585 | # ------------------------------------------------------------------------------ |
| 1586 | |
| 1587 | #Method SkImageInfo makeWH(int newWidth, int newHeight) const |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1588 | #In Constructors |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1589 | #Line # creates Image_Info with changed dimensions ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1590 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1591 | |
| 1592 | #Example |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1593 | #Height 144 |
| 1594 | #Image 3 |
| 1595 | SkImageInfo canvasImageInfo = canvas->imageInfo(); |
| 1596 | SkRect canvasBounds = SkRect::Make(canvasImageInfo.bounds()); |
| 1597 | canvas->drawBitmapRect(source, source.bounds(), canvasBounds, nullptr); |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1598 | SkImageInfo insetImageInfo = |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1599 | canvasImageInfo.makeWH(canvasBounds.width() / 2, canvasBounds.height() / 2); |
| 1600 | SkBitmap inset; |
| 1601 | inset.allocPixels(insetImageInfo); |
| 1602 | SkCanvas offscreen(inset); |
| 1603 | offscreen.drawBitmapRect(source, source.bounds(), SkRect::Make(inset.bounds()), nullptr); |
| 1604 | canvas->drawBitmap(inset, canvasBounds.width() / 4, canvasBounds.height() / 4); |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1605 | ## |
| 1606 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1607 | #SeeAlso Make makeAlphaType makeColorSpace makeColorType |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1608 | |
| 1609 | #Method ## |
| 1610 | |
| 1611 | # ------------------------------------------------------------------------------ |
| 1612 | |
| 1613 | #Method SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1614 | #In Constructors |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1615 | #Line # creates Image_Info with changed Alpha_Type ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1616 | #Populate |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1617 | |
| 1618 | #Example |
| 1619 | #Image 3 |
| 1620 | const int width = 256; |
| 1621 | const int height = 128; |
| 1622 | SkColor pixels[height][width]; |
| 1623 | for (int y = 0; y < height; ++y) { |
| 1624 | for (int x = 0; x < width; ++x) { |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1625 | int red = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 4 + y) * 0.03f))); |
| 1626 | int blue = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 3 + y) * 0.04f))); |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1627 | int green = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 2 + y) * 0.05f))); |
| 1628 | int alpha = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 1 + y) * 0.006f))); |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1629 | pixels[y][x] = |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1630 | SkColorSetARGB(alpha, red * alpha / 255, green * alpha / 255, blue * alpha / 255); |
| 1631 | } |
| 1632 | } |
| 1633 | SkBitmap bitmap; |
| 1634 | SkImageInfo info = SkImageInfo::Make(width, height, kBGRA_8888_SkColorType, kPremul_SkAlphaType); |
| 1635 | bitmap.installPixels(info, (void*) pixels, sizeof(SkColor) * width); |
| 1636 | canvas->drawBitmap(source, 0, 0); |
| 1637 | canvas->drawBitmap(bitmap, 0, 0); |
| 1638 | SkImageInfo unpremulInfo = info.makeAlphaType(kUnpremul_SkAlphaType); |
| 1639 | bitmap.installPixels(unpremulInfo, (void*) pixels, sizeof(SkColor) * width); |
| 1640 | canvas->drawBitmap(bitmap, 0, 128); |
| 1641 | ## |
| 1642 | |
| 1643 | #SeeAlso Make MakeA8 makeColorType makeColorSpace |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1644 | |
| 1645 | #Method ## |
| 1646 | |
| 1647 | # ------------------------------------------------------------------------------ |
| 1648 | |
| 1649 | #Method SkImageInfo makeColorType(SkColorType newColorType) const |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1650 | #In Constructors |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1651 | #Line # creates Image_Info with changed Color_Type ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1652 | #Populate |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1653 | |
| 1654 | #Example |
| 1655 | const int width = 256; |
| 1656 | const int height = 128; |
| 1657 | SkColor pixels[height][width]; |
| 1658 | for (int y = 0; y < height; ++y) { |
| 1659 | for (int x = 0; x < width; ++x) { |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1660 | int red = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 4 + y) * 0.03f))); |
| 1661 | int blue = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 3 + y) * 0.04f))); |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1662 | int green = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 2 + y) * 0.05f))); |
| 1663 | int alpha = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 1 + y) * 0.006f))); |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1664 | pixels[y][x] = |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1665 | SkColorSetARGB(alpha, red * alpha / 255, green * alpha / 255, blue * alpha / 255); |
| 1666 | } |
| 1667 | } |
| 1668 | SkBitmap bitmap; |
| 1669 | SkImageInfo info = SkImageInfo::Make(width, height, kBGRA_8888_SkColorType, kPremul_SkAlphaType); |
| 1670 | bitmap.installPixels(info, (void*) pixels, sizeof(SkColor) * width); |
| 1671 | canvas->drawBitmap(source, 0, 0); |
| 1672 | canvas->drawBitmap(bitmap, 0, 0); |
| 1673 | SkImageInfo rgbaInfo = info.makeColorType(kRGBA_8888_SkColorType); |
| 1674 | bitmap.installPixels(rgbaInfo, (void*) pixels, sizeof(SkColor) * width); |
| 1675 | canvas->drawBitmap(bitmap, 0, 128); |
| 1676 | ## |
| 1677 | |
| 1678 | #SeeAlso Make makeAlphaType makeColorSpace |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1679 | |
| 1680 | #Method ## |
| 1681 | |
| 1682 | # ------------------------------------------------------------------------------ |
| 1683 | |
| 1684 | #Method SkImageInfo makeColorSpace(sk_sp<SkColorSpace> cs) const |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1685 | #In Constructors |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1686 | #Line # creates Image_Info with changed Color_Space ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1687 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1688 | |
| 1689 | #Example |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1690 | #Height 224 |
| 1691 | const int width = 256; |
| 1692 | const int height = 64; |
| 1693 | auto drawLabel = [=](const char* what, bool closeToSRGB) -> void { |
| 1694 | SkString string; |
| 1695 | string.printf("%s gamma is %s" "close to sRGB", what, closeToSRGB ? "" : "not "); |
| 1696 | SkPaint paint; |
| 1697 | paint.setAntiAlias(true); |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 1698 | canvas->drawString(string, 20, 56, paint); |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1699 | }; |
| 1700 | SkColor gradColors[] = { 0xFFFF7F00, 0xFF00FF7F, 0xFF0000FF, 0xFF7F7FFF }; |
| 1701 | SkPoint gradPoints[] = { { 0, 0 }, { width, 0 }, { width * 2, 0 }, { width * 3, 0 } }; |
| 1702 | SkPaint gradPaint; |
| 1703 | gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr, |
| 1704 | SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode)); |
| 1705 | canvas->drawRect(SkRect::MakeWH(width, height), gradPaint); |
| 1706 | drawLabel("canvas", canvas->imageInfo().gammaCloseToSRGB()); |
| 1707 | SkBitmap bitmap; |
| 1708 | SkImageInfo offscreenInfo = SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType); |
| 1709 | bitmap.allocPixels(offscreenInfo); |
| 1710 | SkCanvas sRGBOffscreen(bitmap); |
| 1711 | sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint); |
| 1712 | canvas->translate(0, 80); |
| 1713 | canvas->drawBitmap(bitmap, 0, 0); |
| 1714 | drawLabel("offscreen", offscreenInfo.gammaCloseToSRGB()); |
| 1715 | SkImageInfo linearGamma = |
| 1716 | offscreenInfo.makeColorSpace(offscreenInfo.colorSpace()->makeLinearGamma()); |
| 1717 | bitmap.allocPixels(linearGamma); |
| 1718 | SkCanvas lgOffscreen(bitmap); |
| 1719 | lgOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint); |
| 1720 | canvas->translate(0, 80); |
| 1721 | canvas->drawBitmap(bitmap, 0, 0); |
| 1722 | drawLabel("linear", linearGamma.gammaCloseToSRGB()); |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1723 | ## |
| 1724 | |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1725 | #SeeAlso Make MakeS32 makeAlphaType makeColorType |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1726 | |
| 1727 | #Method ## |
| 1728 | |
| 1729 | # ------------------------------------------------------------------------------ |
| 1730 | |
| 1731 | #Method int bytesPerPixel() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1732 | #In Property |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1733 | #Line # returns number of bytes in pixel based on Color_Type ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1734 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1735 | |
| 1736 | #Example |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1737 | const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", |
| 1738 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"}; |
| 1739 | for (SkColorType colorType : { #list_of_color_types# |
| 1740 | } ) { |
| 1741 | SkImageInfo info = SkImageInfo::Make(1, 1, colorType, kOpaque_SkAlphaType); |
| 1742 | SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d\n", |
| 1743 | colors[colorType], 13 - strlen(colors[colorType]), " ", |
| 1744 | info.bytesPerPixel()); |
| 1745 | } |
| 1746 | #StdOut |
| 1747 | color: kUnknown_SkColorType bytesPerPixel: 0 |
| 1748 | color: kAlpha_8_SkColorType bytesPerPixel: 1 |
| 1749 | color: kRGB_565_SkColorType bytesPerPixel: 2 |
| 1750 | color: kARGB_4444_SkColorType bytesPerPixel: 2 |
| 1751 | color: kRGBA_8888_SkColorType bytesPerPixel: 4 |
| 1752 | color: kRGB_888x_SkColorType bytesPerPixel: 4 |
| 1753 | color: kBGRA_8888_SkColorType bytesPerPixel: 4 |
| 1754 | color: kRGBA_1010102_SkColorType bytesPerPixel: 4 |
| 1755 | color: kRGB_101010x_SkColorType bytesPerPixel: 4 |
| 1756 | color: kGray_8_SkColorType bytesPerPixel: 1 |
| 1757 | color: kRGBA_F16_SkColorType bytesPerPixel: 8 |
| 1758 | ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1759 | ## |
| 1760 | |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1761 | #SeeAlso width shiftPerPixel SkBitmap::bytesPerPixel |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1762 | |
| 1763 | #Method ## |
| 1764 | |
| 1765 | # ------------------------------------------------------------------------------ |
| 1766 | |
| 1767 | #Method int shiftPerPixel() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1768 | #In Property |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1769 | #Line # returns bit shift from pixels to bytes ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1770 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1771 | |
| 1772 | #Example |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1773 | const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", |
| 1774 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"}; |
| 1775 | for (SkColorType colorType : { #list_of_color_types# |
| 1776 | } ) { |
| 1777 | SkImageInfo info = SkImageInfo::Make(1, 1, colorType, kOpaque_SkAlphaType); |
| 1778 | SkDebugf("color: k" "%s" "_SkColorType" "%*s" "shiftPerPixel: %d\n", |
| 1779 | colors[colorType], 14 - strlen(colors[colorType]), " ", |
| 1780 | info.shiftPerPixel()); |
| 1781 | } |
| 1782 | #StdOut |
| 1783 | color: kUnknown_SkColorType shiftPerPixel: 0 |
| 1784 | color: kAlpha_8_SkColorType shiftPerPixel: 0 |
| 1785 | color: kRGB_565_SkColorType shiftPerPixel: 1 |
| 1786 | color: kARGB_4444_SkColorType shiftPerPixel: 1 |
| 1787 | color: kRGBA_8888_SkColorType shiftPerPixel: 2 |
| 1788 | color: kRGB_888x_SkColorType shiftPerPixel: 2 |
| 1789 | color: kBGRA_8888_SkColorType shiftPerPixel: 2 |
| 1790 | color: kRGBA_1010102_SkColorType shiftPerPixel: 2 |
| 1791 | color: kRGB_101010x_SkColorType shiftPerPixel: 2 |
| 1792 | color: kGray_8_SkColorType shiftPerPixel: 0 |
| 1793 | color: kRGBA_F16_SkColorType shiftPerPixel: 3 |
| 1794 | ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1795 | ## |
| 1796 | |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 1797 | #SeeAlso bytesPerPixel minRowBytes SkBitmap::shiftPerPixel SkPixmap::shiftPerPixel |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1798 | |
| 1799 | #Method ## |
| 1800 | |
| 1801 | # ------------------------------------------------------------------------------ |
| 1802 | |
| 1803 | #Method uint64_t minRowBytes64() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1804 | #In Property |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1805 | #Line # returns width() times bytesPerPixel in 64 bits ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1806 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1807 | |
| 1808 | #Example |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1809 | for (int shift = 24; shift < 32; ++shift) { |
| 1810 | int width = 1 << shift; |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1811 | SkImageInfo imageInfo = |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1812 | SkImageInfo::Make(width, 1, kRGBA_F16_SkColorType, kPremul_SkAlphaType); |
| 1813 | uint64_t minRowBytes = imageInfo.minRowBytes64(); |
| 1814 | bool widthTooLarge = (uint64_t) (int32_t) minRowBytes != minRowBytes; |
| 1815 | SkDebugf("RGBA_F16 width %d (0x%08x) %s\n", |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1816 | width, width, widthTooLarge ? "too large" : "OK"); |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1817 | } |
| 1818 | #StdOut |
| 1819 | RGBA_F16 width 16777216 (0x01000000) OK |
| 1820 | RGBA_F16 width 33554432 (0x02000000) OK |
| 1821 | RGBA_F16 width 67108864 (0x04000000) OK |
| 1822 | RGBA_F16 width 134217728 (0x08000000) OK |
| 1823 | RGBA_F16 width 268435456 (0x10000000) too large |
| 1824 | RGBA_F16 width 536870912 (0x20000000) too large |
| 1825 | RGBA_F16 width 1073741824 (0x40000000) too large |
| 1826 | RGBA_F16 width -2147483648 (0x80000000) too large |
| 1827 | ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1828 | ## |
| 1829 | |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1830 | #SeeAlso minRowBytes computeByteSize computeMinByteSize validRowBytes |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1831 | |
| 1832 | #Method ## |
| 1833 | |
| 1834 | # ------------------------------------------------------------------------------ |
| 1835 | |
| 1836 | #Method size_t minRowBytes() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1837 | #In Property |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1838 | #Line # returns width() times bytesPerPixel in 32 bits ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1839 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1840 | |
| 1841 | #Example |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1842 | for (int shift = 24; shift < 32; ++shift) { |
| 1843 | int width = 1 << shift; |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1844 | SkImageInfo imageInfo = |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1845 | SkImageInfo::Make(width, 1, kRGBA_F16_SkColorType, kPremul_SkAlphaType); |
| 1846 | size_t minRowBytes = imageInfo.minRowBytes(); |
| 1847 | bool widthTooLarge = !minRowBytes; |
| 1848 | SkDebugf("RGBA_F16 width %d (0x%08x) %s\n", |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1849 | width, width, widthTooLarge ? "too large" : "OK"); |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1850 | } |
| 1851 | #StdOut |
| 1852 | RGBA_F16 width 16777216 (0x01000000) OK |
| 1853 | RGBA_F16 width 33554432 (0x02000000) OK |
| 1854 | RGBA_F16 width 67108864 (0x04000000) OK |
| 1855 | RGBA_F16 width 134217728 (0x08000000) OK |
| 1856 | RGBA_F16 width 268435456 (0x10000000) too large |
| 1857 | RGBA_F16 width 536870912 (0x20000000) too large |
| 1858 | RGBA_F16 width 1073741824 (0x40000000) too large |
| 1859 | RGBA_F16 width -2147483648 (0x80000000) too large |
| 1860 | ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1861 | ## |
| 1862 | |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1863 | #SeeAlso minRowBytes64 computeByteSize computeMinByteSize validRowBytes |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1864 | |
| 1865 | #Method ## |
| 1866 | |
| 1867 | # ------------------------------------------------------------------------------ |
| 1868 | |
| 1869 | #Method size_t computeOffset(int x, int y, size_t rowBytes) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1870 | #In Utility |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1871 | #Line # returns byte offset within pixel array ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1872 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1873 | |
| 1874 | #Example |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 1875 | #Height 128 |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1876 | uint8_t pixels[][12] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00}, |
| 1877 | { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, |
| 1878 | { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00}, |
| 1879 | { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF}, |
| 1880 | { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, |
| 1881 | { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00}, |
| 1882 | { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, |
| 1883 | { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00} }; |
| 1884 | SkImageInfo imageInfo = SkImageInfo::MakeA8(8, 8); |
| 1885 | SkBitmap bitmap; |
| 1886 | bitmap.installPixels(imageInfo, (void*) pixels, sizeof(pixels[0])); |
| 1887 | SkPaint paint; |
| 1888 | paint.setColor(SK_ColorRED); |
| 1889 | canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint); |
| 1890 | size_t offset = imageInfo.computeOffset(2, 3, sizeof(pixels[0])); |
| 1891 | pixels[0][offset] = 0x7F; |
| 1892 | offset = imageInfo.computeOffset(5, 3, sizeof(pixels[0])); |
| 1893 | pixels[0][offset] = 0x7F; |
| 1894 | bitmap.installPixels(imageInfo, (void*) pixels, sizeof(pixels[0])); |
| 1895 | canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(128, 128), &paint); |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1896 | ## |
| 1897 | |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 1898 | #SeeAlso height width minRowBytes computeByteSize |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1899 | |
| 1900 | #Method ## |
| 1901 | |
| 1902 | # ------------------------------------------------------------------------------ |
| 1903 | |
Cary Clark | cb6bef0 | 2018-11-29 12:05:25 -0500 | [diff] [blame] | 1904 | #Method bool operator==(const SkImageInfo& other) const |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 1905 | #Line # compares Image_Info for equality ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1906 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1907 | |
| 1908 | #Example |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1909 | SkImageInfo info1 = SkImageInfo::Make(10, 20, kGray_8_SkColorType, kPremul_SkAlphaType); |
| 1910 | SkImageInfo info2 = SkImageInfo::Make(20, 10, kAlpha_8_SkColorType, kUnpremul_SkAlphaType); |
| 1911 | SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!'); |
| 1912 | info2 = info2.makeWH(10, 20); |
| 1913 | SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!'); |
| 1914 | info2 = info2.makeColorType(kGray_8_SkColorType); |
| 1915 | SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!'); |
| 1916 | info2 = info2.makeAlphaType(kPremul_SkAlphaType); |
| 1917 | SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!'); |
| 1918 | #StdOut |
| 1919 | info1 != info2 |
| 1920 | info1 != info2 |
| 1921 | info1 != info2 |
| 1922 | info1 == info2 |
| 1923 | ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1924 | ## |
| 1925 | |
Cary Clark | cb6bef0 | 2018-11-29 12:05:25 -0500 | [diff] [blame] | 1926 | #SeeAlso operator!=(const SkImageInfo& other) const SkColorSpace::Equals |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1927 | |
| 1928 | #Method ## |
| 1929 | |
| 1930 | # ------------------------------------------------------------------------------ |
| 1931 | |
Cary Clark | cb6bef0 | 2018-11-29 12:05:25 -0500 | [diff] [blame] | 1932 | #Method bool operator!=(const SkImageInfo& other) const |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 1933 | #Line # compares Image_Info for inequality ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1934 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1935 | |
| 1936 | #Example |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1937 | SkImageInfo info1 = SkImageInfo::Make(10, 20, kGray_8_SkColorType, kPremul_SkAlphaType); |
| 1938 | SkImageInfo info2 = SkImageInfo::Make(20, 10, kAlpha_8_SkColorType, kUnpremul_SkAlphaType); |
| 1939 | SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '='); |
| 1940 | info2 = info2.makeWH(10, 20); |
| 1941 | SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '='); |
| 1942 | info2 = info2.makeColorType(kGray_8_SkColorType); |
| 1943 | SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '='); |
| 1944 | info2 = info2.makeAlphaType(kPremul_SkAlphaType); |
| 1945 | SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '='); |
| 1946 | #StdOut |
| 1947 | info1 != info2 |
| 1948 | info1 != info2 |
| 1949 | info1 != info2 |
| 1950 | info1 == info2 |
| 1951 | ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1952 | ## |
| 1953 | |
Cary Clark | cb6bef0 | 2018-11-29 12:05:25 -0500 | [diff] [blame] | 1954 | #SeeAlso operator==(const SkImageInfo& other) const SkColorSpace::Equals |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1955 | |
| 1956 | #Method ## |
| 1957 | |
| 1958 | # ------------------------------------------------------------------------------ |
| 1959 | |
| 1960 | #Method size_t computeByteSize(size_t rowBytes) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1961 | #In Utility |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1962 | #Line # returns memory required by pixel buffer with given row bytes ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1963 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1964 | |
| 1965 | #Example |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 1966 | #Height 130 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1967 | SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2); |
| 1968 | const size_t size = info.computeByteSize(100000); |
| 1969 | SkAutoTMalloc<SkPMColor> storage(size); |
| 1970 | SkPMColor* pixels = storage.get(); |
| 1971 | SkBitmap bitmap; |
| 1972 | bitmap.setInfo(info); |
| 1973 | bitmap.setPixels(pixels); |
| 1974 | bitmap.eraseColor(SK_ColorRED); |
| 1975 | canvas->scale(50, 50); |
| 1976 | canvas->rotate(8); |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 1977 | canvas->drawBitmap(bitmap, 2, 0); |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1978 | ## |
| 1979 | |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 1980 | #SeeAlso computeMinByteSize validRowBytes |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1981 | |
| 1982 | #Method ## |
| 1983 | |
| 1984 | # ------------------------------------------------------------------------------ |
| 1985 | |
| 1986 | #Method size_t computeMinByteSize() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1987 | #In Utility |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1988 | #Line # returns least memory required by pixel buffer ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1989 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1990 | |
| 1991 | #Example |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 1992 | #Height 130 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1993 | SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2); |
| 1994 | const size_t size = info.computeMinByteSize(); |
| 1995 | SkAutoTMalloc<SkPMColor> storage(size); |
| 1996 | SkPMColor* pixels = storage.get(); |
| 1997 | SkBitmap bitmap; |
| 1998 | bitmap.setInfo(info); |
| 1999 | bitmap.setPixels(pixels); |
| 2000 | bitmap.eraseColor(SK_ColorRED); |
| 2001 | canvas->scale(50, 50); |
| 2002 | canvas->rotate(8); |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 2003 | canvas->drawBitmap(bitmap, 2, 0); |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 2004 | ## |
| 2005 | |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 2006 | #SeeAlso computeByteSize validRowBytes |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 2007 | |
| 2008 | #Method ## |
| 2009 | |
| 2010 | # ------------------------------------------------------------------------------ |
| 2011 | |
| 2012 | #Method static bool ByteSizeOverflowed(size_t byteSize) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2013 | #In Utility |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 2014 | #Line # checks result of computeByteSize and computeMinByteSize ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2015 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 2016 | |
| 2017 | #Example |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2018 | SkImageInfo info = SkImageInfo::MakeN32Premul(2, 1000000000); |
| 2019 | for (size_t rowBytes = 100000000; rowBytes < 10000000000000LL; rowBytes *= 10) { |
| 2020 | const size_t size = info.computeByteSize(rowBytes); |
| 2021 | SkDebugf("rowBytes:%llu size:%llu overflowed:%s\n", rowBytes, size, |
| 2022 | SkImageInfo::ByteSizeOverflowed(size) ? "true" : "false"); |
| 2023 | } |
| 2024 | #StdOut |
| 2025 | rowBytes:100000000 size:99999999900000008 overflowed:false |
| 2026 | rowBytes:1000000000 size:999999999000000008 overflowed:false |
| 2027 | rowBytes:10000000000 size:9999999990000000008 overflowed:false |
| 2028 | rowBytes:100000000000 size:18446744073709551615 overflowed:true |
| 2029 | rowBytes:1000000000000 size:18446744073709551615 overflowed:true |
| 2030 | ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 2031 | ## |
| 2032 | |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 2033 | #SeeAlso computeByteSize computeMinByteSize validRowBytes |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 2034 | |
| 2035 | #Method ## |
| 2036 | |
| 2037 | # ------------------------------------------------------------------------------ |
| 2038 | |
| 2039 | #Method bool validRowBytes(size_t rowBytes) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2040 | #In Utility |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 2041 | #Line # checks if row bytes is large enough to contain pixel row ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2042 | #Populate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 2043 | |
| 2044 | #Example |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2045 | SkImageInfo info = SkImageInfo::MakeN32Premul(16, 8); |
| 2046 | for (size_t rowBytes = 60; rowBytes < 72; rowBytes += sizeof(SkPMColor)) { |
| 2047 | SkDebugf("validRowBytes(%llu): %s\n", rowBytes, info.validRowBytes(rowBytes) ? |
| 2048 | "true" : "false"); |
| 2049 | } |
| 2050 | #StdOut |
| 2051 | validRowBytes(60): false |
| 2052 | validRowBytes(64): true |
| 2053 | validRowBytes(68): true |
| 2054 | ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 2055 | ## |
| 2056 | |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 2057 | #SeeAlso ByteSizeOverflowed computeByteSize computeMinByteSize |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 2058 | |
| 2059 | #Method ## |
| 2060 | |
| 2061 | # ------------------------------------------------------------------------------ |
| 2062 | |
| 2063 | #Method void reset() |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 2064 | #In Constructors |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 2065 | #Line # sets zero dimensions, kUnknown_SkColorType, kUnknown_SkAlphaType ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2066 | #Populate |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 2067 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 2068 | #Example |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2069 | SkImageInfo info = SkImageInfo::MakeN32Premul(16, 8); |
| 2070 | SkImageInfo copy = info; |
| 2071 | SkDebugf("info %c= copy\n", info == copy ? '=' : '!'); |
| 2072 | copy.reset(); |
| 2073 | SkDebugf("info %c= reset copy\n", info == copy ? '=' : '!'); |
| 2074 | SkDebugf("SkImageInfo() %c= reset copy\n", SkImageInfo() == copy ? '=' : '!'); |
| 2075 | #StdOut |
| 2076 | info == copy |
| 2077 | info != reset copy |
| 2078 | SkImageInfo() == reset copy |
| 2079 | ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 2080 | ## |
| 2081 | |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 2082 | #SeeAlso SkImageInfo() |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 2083 | |
| 2084 | #Method ## |
| 2085 | |
| 2086 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2087 | #Subtopic Utility |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2088 | #Line # rarely called management functions ## |
| 2089 | ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 2090 | |
| 2091 | #Method void validate() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2092 | #In Utility |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 2093 | #Line # asserts if Image_Info is invalid (debug only) ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2094 | #Populate |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 2095 | |
| 2096 | #NoExample |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 2097 | ## |
| 2098 | |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 2099 | #SeeAlso validRowBytes SkBitmap::validate |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 2100 | |
| 2101 | #Method ## |
| 2102 | |
| 2103 | #Struct SkImageInfo ## |
| 2104 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2105 | #Topic Image_Info ## |