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