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