Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1 | #Topic Pixmap |
Cary Clark | e4aa371 | 2017-09-15 02:56:12 -0400 | [diff] [blame] | 2 | #Alias Pixmap_Reference |
| 3 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 4 | #Class SkPixmap |
| 5 | |
| 6 | Pixmap provides a utility to pair SkImageInfo with pixels and row bytes. |
| 7 | Pixmap is a low level class which provides convenience functions to access |
| 8 | raster destinations. Canvas can not draw Pixmap, nor does Pixmap provide |
| 9 | a direct drawing destination. |
| 10 | |
| 11 | Use Bitmap to draw pixels referenced by Pixmap; use Surface to draw into |
| 12 | pixels referenced by Pixmap. |
| 13 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 14 | Pixmap does not try to manage the lifetime of the pixel memory. Use Pixel_Ref |
| 15 | to manage pixel memory; Pixel_Ref is safe across threads. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 16 | |
| 17 | #Topic Overview |
| 18 | |
| 19 | #Subtopic Subtopics |
| 20 | #Table |
| 21 | #Legend |
Cary Clark | 5081eed | 2018-01-22 07:55:48 -0500 | [diff] [blame] | 22 | # name # description ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 23 | #Legend ## |
Cary Clark | 5081eed | 2018-01-22 07:55:48 -0500 | [diff] [blame] | 24 | # Constructors # list of functions that construct SkPath ## |
| 25 | # Member_Functions # list of static functions and member methods ## |
| 26 | # Related_Functions # similar methods grouped together ## |
| 27 | #Table ## |
| 28 | ## |
| 29 | |
| 30 | #Subtopic Related_Functions |
| 31 | #Table |
| 32 | #Legend |
| 33 | # name # description ## |
| 34 | #Legend ## |
| 35 | # Image_Info_Access # returns all or part of Image_Info ## |
| 36 | # Initialization # sets fields for use ## |
| 37 | # Readable_Address # returns read only pixels ## |
| 38 | # Reader # examine pixel value ## |
| 39 | # Writable_Address # returns writable pixels ## |
| 40 | # Writer # copy to pixel values ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 41 | #Table ## |
| 42 | #Subtopic ## |
| 43 | |
| 44 | #Subtopic Constructors |
| 45 | #Table |
| 46 | #Legend |
| 47 | # # description ## |
| 48 | #Legend ## |
Cary Clark | 5081eed | 2018-01-22 07:55:48 -0500 | [diff] [blame] | 49 | # SkPixmap() # constructs with default values ## |
| 50 | # SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) # constructs from Image_Info, pixels ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 51 | #Table ## |
| 52 | #Subtopic ## |
| 53 | |
| 54 | #Subtopic Member_Functions |
| 55 | #Table |
| 56 | #Legend |
Cary Clark | 5081eed | 2018-01-22 07:55:48 -0500 | [diff] [blame] | 57 | # name # description ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 58 | #Legend ## |
Cary Clark | 5081eed | 2018-01-22 07:55:48 -0500 | [diff] [blame] | 59 | # addr() # returns readable pixel address as void pointer ## |
| 60 | # addr16 # returns readable pixel address as 16-bit pointer ## |
| 61 | # addr32 # returns readable pixel address as 32-bit pointer ## |
| 62 | # addr64 # returns readable pixel address as 64-bit pointer ## |
| 63 | # addr8 # returns readable pixel address as 8-bit pointer ## |
| 64 | # addrF16 # returns readable pixel component address as 16-bit pointer ## |
| 65 | # alphaType # returns Image_Info Alpha_Type ## |
| 66 | # bounds() # returns width and height as Rectangle ## |
| 67 | # colorSpace # returns Image_Info Color_Space ## |
| 68 | # colorType # returns Image_Info Color_Type ## |
| 69 | # computeByteSize # returns size required for pixels ## |
| 70 | # computeIsOpaque # returns true if all pixels are opaque ## |
| 71 | # erase() # writes Color to pixels ## |
| 72 | # extractSubset # sets pointer to portion of original ## |
| 73 | # getColor # returns one pixel as Unpremultiplied Color ## |
| 74 | # height() # returns pixel row count ## |
| 75 | # info() # returns Image_Info ## |
| 76 | # isOpaque # returns true if Image_Info describes opaque pixels ## |
| 77 | # readPixels # copies and converts pixels ## |
| 78 | # reset() # reuses existing Pixmap with replacement values ## |
| 79 | # rowBytes # returns interval between rows in bytes ## |
| 80 | # rowBytesAsPixels # returns interval between rows in pixels ## |
| 81 | # scalePixels # scales and converts pixels ## |
| 82 | # setColorSpace # sets Image_Info Color_Space ## |
| 83 | # shiftPerPixel # returns bit shift from pixels to bytes ## |
| 84 | # width() # returns pixel column count ## |
| 85 | # writable_addr # returns writable pixel address as void pointer ## |
| 86 | # writable_addr16 # returns writable pixel address as 16-bit pointer ## |
| 87 | # writable_addr32 # returns writable pixel address as 32-bit pointer ## |
| 88 | # writable_addr64 # returns writable pixel address as 64-bit pointer ## |
| 89 | # writable_addr8 # returns writable pixel address as 8-bit pointer ## |
| 90 | # writable_addrF16 # returns writable pixel component address as 16-bit pointer ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 91 | #Table ## |
| 92 | #Subtopic ## |
| 93 | |
| 94 | #Topic Overview ## |
| 95 | |
| 96 | #Subtopic Initialization |
| 97 | |
| 98 | # ------------------------------------------------------------------------------ |
| 99 | |
| 100 | #Method SkPixmap() |
| 101 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 102 | #In Initialization |
| 103 | #Line # constructs with default values ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 104 | Creates an empty Pixmap without pixels, with kUnknown_SkColorType, with |
| 105 | kUnknown_SkAlphaType, and with a width and height of zero. Use |
| 106 | reset() to associate pixels, SkColorType, SkAlphaType, width, and height |
| 107 | after Pixmap has been created. |
| 108 | |
| 109 | #Return empty Pixmap ## |
| 110 | |
| 111 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 112 | void draw(SkCanvas* canvas) { |
| 113 | const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 114 | const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", |
| 115 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"}; |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 116 | SkPixmap pixmap; |
| 117 | for (int i = 0; i < 2; ++i) { |
| 118 | SkDebugf("width: %2d height: %2d", pixmap.width(), pixmap.height()); |
| 119 | SkDebugf(" color: k%s_SkColorType", colors[pixmap.colorType()]); |
| 120 | SkDebugf(" alpha: k%s_SkAlphaType\n", alphas[pixmap.alphaType()]); |
| 121 | pixmap.reset(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType), |
| 122 | nullptr, 0); |
| 123 | } |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 124 | } |
| 125 | #StdOut |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 126 | width: 0 height: 0 color: kUnknown_SkColorType alpha: kUnknown_SkAlphaType |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 127 | width: 25 height: 35 color: kRGBA_8888_SkColorType alpha: kOpaque_SkAlphaType |
| 128 | ## |
| 129 | ## |
| 130 | |
| 131 | #SeeAlso SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) reset() SkAlphaType SkColorType |
| 132 | |
| 133 | ## |
| 134 | |
| 135 | # ------------------------------------------------------------------------------ |
| 136 | |
| 137 | #Method SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) |
| 138 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 139 | #In Initialization |
| 140 | #Line # constructs from Image_Info, pixels ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 141 | Creates Pixmap from info width, height, SkAlphaType, and SkColorType. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 142 | addr points to pixels, or nullptr. rowBytes should be info.width() times |
| 143 | info.bytesPerPixel(), or larger. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 144 | |
| 145 | No parameter checking is performed; it is up to the caller to ensure that |
| 146 | addr and rowBytes agree with info. |
| 147 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 148 | The memory lifetime of pixels is managed by the caller. When Pixmap goes |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 149 | out of scope, addr is unaffected. |
| 150 | |
| 151 | Pixmap may be later modified by reset() to change its size, pixel type, or |
| 152 | storage. |
| 153 | |
| 154 | #Param info width, height, SkAlphaType, SkColorType of Image_Info ## |
| 155 | #Param addr pointer to pixels allocated by caller; may be nullptr ## |
| 156 | #Param rowBytes size of one row of addr; width times pixel size, or larger ## |
| 157 | |
| 158 | #Return initialized Pixmap ## |
| 159 | |
| 160 | #Example |
| 161 | #Image 3 |
| 162 | #Description |
| 163 | SkImage::MakeRasterCopy takes const SkPixmap& as an argument. The example |
| 164 | constructs a SkPixmap from the brace-delimited parameters. |
| 165 | ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 166 | SkDebugf("image alpha only = %s\n", image->isAlphaOnly() ? "true" : "false"); |
| 167 | SkPMColor pmColors = 0; |
| 168 | sk_sp<SkImage> copy = SkImage::MakeRasterCopy({SkImageInfo::MakeA8(1, 1), |
| 169 | (uint8_t*)&pmColors, |
| 170 | 1}); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 171 | SkDebugf("copy alpha only = %s\n", copy->isAlphaOnly() ? "true" : "false"); |
| 172 | #StdOut |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 173 | image alpha only = false |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 174 | copy alpha only = true |
| 175 | ## |
| 176 | ## |
| 177 | |
| 178 | #SeeAlso SkPixmap() reset() SkAlphaType SkColorType |
| 179 | |
| 180 | ## |
| 181 | |
| 182 | # ------------------------------------------------------------------------------ |
| 183 | |
| 184 | #Method void reset() |
| 185 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 186 | #In Initialization |
| 187 | #Line # reuses existing Pixmap with replacement values ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 188 | Sets width, height, row bytes to zero; pixel address to nullptr; SkColorType to |
| 189 | kUnknown_SkColorType; and SkAlphaType to kUnknown_SkAlphaType. |
| 190 | |
| 191 | The prior pixels are unaffected; it is up to the caller to release pixels |
| 192 | memory if desired. |
| 193 | |
| 194 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 195 | void draw(SkCanvas* canvas) { |
| 196 | const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 197 | const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", |
| 198 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"}; |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 199 | SkPixmap pixmap(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType), |
| 200 | nullptr, 0); |
| 201 | for (int i = 0; i < 2; ++i) { |
| 202 | SkDebugf("width: %2d height: %2d", pixmap.width(), pixmap.height()); |
| 203 | SkDebugf(" color: k%s_SkColorType", colors[pixmap.colorType()]); |
| 204 | SkDebugf(" alpha: k%s_SkAlphaType\n", alphas[pixmap.alphaType()]); |
| 205 | pixmap.reset(); |
| 206 | } |
| 207 | } |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 208 | #StdOut |
| 209 | width: 25 height: 35 color: kRGBA_8888_SkColorType alpha: kOpaque_SkAlphaType |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 210 | width: 0 height: 0 color: kUnknown_SkColorType alpha: kUnknown_SkAlphaType |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 211 | ## |
| 212 | ## |
| 213 | |
| 214 | #SeeAlso SkPixmap() SkAlphaType SkColorType |
| 215 | |
| 216 | ## |
| 217 | |
| 218 | # ------------------------------------------------------------------------------ |
| 219 | |
| 220 | #Method void reset(const SkImageInfo& info, const void* addr, size_t rowBytes) |
| 221 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 222 | #In Initialization |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 223 | Sets width, height, SkAlphaType, and SkColorType from info. |
| 224 | Sets pixel address from addr, which may be nullptr. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 225 | Sets row bytes from rowBytes, which should be info.width() times |
| 226 | info.bytesPerPixel(), or larger. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 227 | |
| 228 | Does not check addr. Asserts if built with SK_DEBUG defined and if rowBytes is |
| 229 | too small to hold one row of pixels. |
| 230 | |
| 231 | The memory lifetime pixels are managed by the caller. When Pixmap goes |
| 232 | out of scope, addr is unaffected. |
| 233 | |
| 234 | #Param info width, height, SkAlphaType, SkColorType of Image_Info ## |
| 235 | #Param addr pointer to pixels allocated by caller; may be nullptr ## |
| 236 | #Param rowBytes size of one row of addr; width times pixel size, or larger ## |
| 237 | |
| 238 | #Example |
| 239 | #Image 4 |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 240 | #Height 64 |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 241 | void draw(SkCanvas* canvas) { |
| 242 | std::vector<int32_t> pixels; |
| 243 | pixels.resize(image->height() * image->width() * 4); |
| 244 | SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType, |
| 245 | image->alphaType()), (const void*) &pixels.front(), image->width() * 4); |
| 246 | image->readPixels(pixmap, 0, 0); |
| 247 | int x = 0; |
| 248 | for (auto colorType : { kRGBA_8888_SkColorType, kBGRA_8888_SkColorType } ) { |
| 249 | pixmap.reset(SkImageInfo::Make(image->width(), image->height(), colorType, |
| 250 | image->alphaType()), (const void*) &pixels.front(), image->width() * 4); |
| 251 | SkBitmap bitmap; |
| 252 | bitmap.installPixels(pixmap); |
| 253 | canvas->drawBitmap(bitmap, x, 0); |
| 254 | x += 128; |
| 255 | } |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 256 | } |
| 257 | ## |
| 258 | |
| 259 | #SeeAlso SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) reset() SkAlphaType SkColorType |
| 260 | |
| 261 | ## |
| 262 | |
| 263 | # ------------------------------------------------------------------------------ |
| 264 | |
| 265 | #Method void setColorSpace(sk_sp<SkColorSpace> colorSpace) |
| 266 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 267 | #In Initialization |
| 268 | #Line # sets Image_Info Color_Space ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 269 | |
| 270 | Changes Color_Space in Image_Info; preserves width, height, SkAlphaType, and |
| 271 | SkColorType in Image, and leaves pixel address and row bytes unchanged. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 272 | Color_Space reference count is incremented. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 273 | |
| 274 | #Param colorSpace Color_Space moved to Image_Info ## |
| 275 | |
| 276 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 277 | void draw(SkCanvas* canvas) { |
| 278 | SkPixmap pixmap; |
| 279 | sk_sp<SkColorSpace> colorSpace1 = SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma, |
| 280 | SkColorSpace::kRec2020_Gamut); |
| 281 | SkDebugf("is %sunique\n", colorSpace1->unique() ? "" : "not "); |
| 282 | pixmap.setColorSpace(colorSpace1); |
| 283 | SkDebugf("is %sunique\n", colorSpace1->unique() ? "" : "not "); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 284 | } |
| 285 | #StdOut |
| 286 | is unique |
| 287 | is not unique |
| 288 | ## |
| 289 | ## |
| 290 | |
| 291 | #SeeAlso Color_Space SkImageInfo::makeColorSpace |
| 292 | |
| 293 | ## |
| 294 | |
| 295 | # ------------------------------------------------------------------------------ |
| 296 | |
| 297 | #Method bool SK_WARN_UNUSED_RESULT reset(const SkMask& mask) |
| 298 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 299 | #In Initialization |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 300 | Sets width, height, pixel address, and row bytes to Mask properties, if Mask |
| 301 | format is SkMask::kA8_Format; and returns true. Otherwise sets width, height, |
| 302 | row bytes to zero; pixel address to nullptr; SkColorType to kUnknown_SkColorType; |
| 303 | and SkAlphaType to kUnknown_SkAlphaType; and returns false. |
| 304 | |
| 305 | Failing to read the return value generates a compile time warning. |
| 306 | |
| 307 | #Param mask Mask containing pixels and dimensions ## |
| 308 | |
| 309 | #Return true if set to Mask properties ## |
| 310 | |
| 311 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 312 | const int width = 2; |
| 313 | const int height = 2; |
| 314 | uint8_t bytes[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; |
| 315 | SkMask mask; |
| 316 | mask.fFormat = SkMask::kA8_Format; |
| 317 | mask.fBounds = {0, 0, width, height}; |
| 318 | mask.fImage = bytes; |
| 319 | mask.fRowBytes = (width + 7) >> 3; |
| 320 | SkPixmap pixmap; |
| 321 | bool success = pixmap.reset(mask); |
| 322 | SkDebugf("success: %s width: %d height: %d\n", success ? "true " : "false", |
| 323 | pixmap.width(), pixmap.height()); |
| 324 | mask.fFormat = SkMask::kBW_Format; |
| 325 | success = pixmap.reset(mask); |
| 326 | SkDebugf("success: %s width: %d height: %d\n", success ? "true " : "false", |
| 327 | pixmap.width(), pixmap.height()); |
| 328 | #StdOut |
| 329 | success: true width: 2 height: 2 |
| 330 | success: false width: 0 height: 0 |
| 331 | ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 332 | ## |
| 333 | |
| 334 | #SeeAlso Mask reset() |
| 335 | |
| 336 | ## |
| 337 | |
| 338 | # ------------------------------------------------------------------------------ |
| 339 | |
| 340 | #Method bool SK_WARN_UNUSED_RESULT extractSubset(SkPixmap* subset, const SkIRect& area) const |
| 341 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 342 | #In Initialization |
| 343 | #Line # sets pointer to portion of original ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 344 | Sets subset width, height, pixel address to intersection of Pixmap with area, |
| 345 | if intersection is not empty; and return true. Otherwise, leave subset unchanged |
| 346 | and return false. |
| 347 | |
| 348 | Failing to read the return value generates a compile time warning. |
| 349 | |
| 350 | #Param subset storage for width, height, pixel address of intersection ## |
| 351 | #Param area bounds to intersect with Pixmap ## |
| 352 | |
| 353 | #Return true if intersection of Pixmap and area is not empty ## |
| 354 | |
| 355 | #Example |
| 356 | #Image 3 |
| 357 | #Height 128 |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 358 | void draw(SkCanvas* canvas) { |
| 359 | std::vector<int32_t> pixels; |
| 360 | pixels.resize(image->height() * image->width() * 4); |
| 361 | SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType, |
| 362 | image->alphaType()), (const void*) &pixels.front(), image->width() * 4); |
| 363 | image->readPixels(pixmap, 0, 0); |
| 364 | SkPixmap inset; |
| 365 | if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) { |
| 366 | SkBitmap bitmap; |
| 367 | bitmap.installPixels(inset); |
| 368 | canvas->drawBitmap(bitmap, 0, 0); |
| 369 | } |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 370 | } |
| 371 | ## |
| 372 | |
| 373 | #SeeAlso reset() SkIRect::intersect |
| 374 | |
| 375 | ## |
| 376 | |
| 377 | #Subtopic Initialization ## |
| 378 | |
| 379 | #Subtopic Image_Info_Access |
| 380 | |
| 381 | # ------------------------------------------------------------------------------ |
| 382 | |
| 383 | #Method const SkImageInfo& info() const |
| 384 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 385 | #In Image_Info_Access |
| 386 | #Line # returns Image_Info ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 387 | Returns width, height, Alpha_Type, Color_Type, and Color_Space. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 388 | |
| 389 | #Return reference to ImageInfo ## |
| 390 | |
| 391 | #Example |
| 392 | #Image 3 |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 393 | std::vector<int32_t> pixels; |
| 394 | pixels.resize(image->height() * image->width() * 4); |
| 395 | SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType, |
| 396 | image->alphaType()), (const void*) &pixels.front(), image->width() * 4); |
| 397 | image->readPixels(pixmap, 0, 0); |
| 398 | SkPixmap inset; |
| 399 | if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) { |
| 400 | const SkImageInfo& info = inset.info(); |
| 401 | const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 402 | const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", |
| 403 | "RGB_888x", "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"}; |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 404 | SkDebugf("width: %d height: %d color: %s alpha: %s\n", info.width(), info.height(), |
| 405 | colors[info.colorType()], alphas[info.alphaType()]); |
| 406 | } |
| 407 | #StdOut |
| 408 | width: 384 height: 384 color: BGRA_8888 alpha: Opaque |
| 409 | ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 410 | ## |
| 411 | |
| 412 | #SeeAlso Image_Info |
| 413 | |
| 414 | ## |
| 415 | |
| 416 | # ------------------------------------------------------------------------------ |
| 417 | |
| 418 | #Method size_t rowBytes() const |
| 419 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 420 | #In Image_Info_Access |
| 421 | #Line # returns interval between rows in bytes ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 422 | Returns row bytes, the interval from one pixel row to the next. Row bytes |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 423 | is at least as large as: |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 424 | #Formula |
| 425 | width() * info().bytesPerPixel() |
| 426 | ## |
| 427 | . |
| 428 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 429 | Returns zero if colorType is kUnknown_SkColorType. |
| 430 | It is up to the Bitmap creator to ensure that row bytes is a useful value. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 431 | |
| 432 | #Return byte length of pixel row ## |
| 433 | |
| 434 | #Example |
| 435 | SkPixmap badPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 2}; |
| 436 | SkPixmap okPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 8}; |
| 437 | for (auto& pixmap : { badPixmap, okPixmap } ) { |
| 438 | SkDebugf("rowBytes: %d minRowBytes: %d\n", pixmap.rowBytes(), |
| 439 | pixmap.info().minRowBytes()); |
| 440 | } |
| 441 | #StdOut |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 442 | rowBytes: 2 minRowBytes: 4 |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 443 | rowBytes: 8 minRowBytes: 4 |
| 444 | ## |
| 445 | ## |
| 446 | |
| 447 | #SeeAlso addr() info() SkImageInfo::minRowBytes |
| 448 | |
| 449 | ## |
| 450 | |
| 451 | # ------------------------------------------------------------------------------ |
| 452 | |
| 453 | #Method const void* addr() const |
| 454 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 455 | #In Image_Info_Access |
| 456 | #Line # returns readable pixel address as void pointer ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 457 | Returns pixel address, the base address corresponding to the pixel origin. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 458 | |
| 459 | It is up to the Pixmap creator to ensure that pixel address is a useful value. |
| 460 | |
| 461 | #Return pixel address ## |
| 462 | |
| 463 | #Example |
| 464 | #Image 3 |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 465 | std::vector<int32_t> pixels; |
| 466 | pixels.resize(image->height() * image->width() * 4); |
| 467 | SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType, |
| 468 | image->alphaType()), (const void*) &pixels.front(), image->width() * 4); |
| 469 | image->readPixels(pixmap, 0, 0); |
| 470 | SkDebugf("pixels address: 0x%llx\n", pixmap.addr()); |
| 471 | SkPixmap inset; |
| 472 | if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) { |
| 473 | SkDebugf("inset address: 0x%llx\n", inset.addr()); |
| 474 | } |
| 475 | #StdOut |
| 476 | #Volatile |
| 477 | pixels address: 0x7f2a440bb010 |
| 478 | inset address: 0x7f2a440fb210 |
| 479 | ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 480 | ## |
| 481 | |
| 482 | #SeeAlso addr(int x, int y) addr8 addr16 addr32 addr64 info() rowBytes() |
| 483 | |
| 484 | ## |
| 485 | |
| 486 | # ------------------------------------------------------------------------------ |
| 487 | |
| 488 | #Method int width() const |
| 489 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 490 | #In Image_Info_Access |
| 491 | #Line # returns pixel column count ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 492 | Returns pixel count in each pixel row. Should be equal or less than: |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 493 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 494 | #Formula |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 495 | rowBytes() / info().bytesPerPixel() |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 496 | ## |
| 497 | . |
| 498 | |
| 499 | #Return pixel width in Image_Info ## |
| 500 | |
| 501 | #Example |
| 502 | SkImageInfo info = SkImageInfo::MakeA8(16, 32); |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 503 | SkPixmap pixmap(info, nullptr, 64); |
| 504 | SkDebugf("pixmap width: %d info width: %d\n", pixmap.width(), info.width()); |
| 505 | #StdOut |
| 506 | pixmap width: 16 info width: 16 |
| 507 | ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 508 | ## |
| 509 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 510 | #SeeAlso height() SkImageInfo::width() |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 511 | |
| 512 | ## |
| 513 | |
| 514 | # ------------------------------------------------------------------------------ |
| 515 | |
| 516 | #Method int height() const |
| 517 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 518 | #In Image_Info_Access |
| 519 | #Line # returns pixel row count ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 520 | Returns pixel row count. |
| 521 | |
| 522 | #Return pixel height in Image_Info ## |
| 523 | |
| 524 | #Example |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 525 | SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64); |
| 526 | SkDebugf("pixmap height: %d info height: %d\n", pixmap.height(), pixmap.info().height()); |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 527 | #StdOut |
| 528 | pixmap height: 32 info height: 32 |
| 529 | ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 530 | ## |
| 531 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 532 | #SeeAlso width() ImageInfo::height() |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 533 | |
| 534 | ## |
| 535 | |
| 536 | # ------------------------------------------------------------------------------ |
| 537 | |
| 538 | #Method SkColorType colorType() const |
| 539 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 540 | #In Image_Info_Access |
| 541 | #Line # returns Image_Info Color_Type ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 542 | Returns Color_Type, one of: kUnknown_SkColorType, kAlpha_8_SkColorType, |
| 543 | kRGB_565_SkColorType, kARGB_4444_SkColorType, kRGBA_8888_SkColorType, |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 544 | kRGB_888x_SkColorType, kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, |
| 545 | kRGB_101010x_SkColorType, kGray_8_SkColorType, kRGBA_F16_SkColorType. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 546 | |
| 547 | #Return Color_Type in Image_Info ## |
| 548 | |
| 549 | #Example |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 550 | const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", |
| 551 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"}; |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 552 | SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64); |
| 553 | SkDebugf("color type: k" "%s" "_SkColorType\n", colors[pixmap.colorType()]); |
| 554 | #StdOut |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 555 | color type: kAlpha_8_SkColorType |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 556 | ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 557 | ## |
| 558 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 559 | #SeeAlso alphaType() SkImageInfo::colorType |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 560 | |
| 561 | ## |
| 562 | |
| 563 | # ------------------------------------------------------------------------------ |
| 564 | |
| 565 | #Method SkAlphaType alphaType() const |
| 566 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 567 | #In Image_Info_Access |
| 568 | #Line # returns Image_Info Alpha_Type ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 569 | Returns Alpha_Type, one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 570 | kPremul_SkAlphaType, kUnpremul_SkAlphaType. |
| 571 | |
| 572 | #Return Alpha_Type in Image_Info ## |
| 573 | |
| 574 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 575 | const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; |
| 576 | SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64); |
| 577 | SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[pixmap.alphaType()]); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 578 | #StdOut |
| 579 | alpha type: kPremul_SkAlphaType |
| 580 | ## |
| 581 | ## |
| 582 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 583 | #SeeAlso colorType() SkImageInfo::alphaType |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 584 | |
| 585 | ## |
| 586 | |
| 587 | # ------------------------------------------------------------------------------ |
| 588 | |
| 589 | #Method SkColorSpace* colorSpace() const |
| 590 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 591 | #In Image_Info_Access |
| 592 | #Line # returns Image_Info Color_Space ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 593 | Returns Color_Space associated with Image_Info. The |
| 594 | reference count of Color_Space is unchanged. The returned Color_Space is |
| 595 | immutable. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 596 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 597 | #Return Color_Space, the range of colors, in Image_Info ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 598 | |
| 599 | #Example |
| 600 | #Description |
| 601 | SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma |
| 602 | and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma. |
| 603 | ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 604 | SkPixmap pixmap(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType, |
| 605 | SkColorSpace::MakeSRGBLinear()), nullptr, 64); |
| 606 | SkColorSpace* colorSpace = pixmap.colorSpace(); |
| 607 | SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n", |
| 608 | colorSpace->gammaCloseToSRGB() ? "true" : "false", |
| 609 | colorSpace->gammaIsLinear() ? "true" : "false", |
| 610 | colorSpace->isSRGB() ? "true" : "false"); |
| 611 | #StdOut |
| 612 | gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false |
| 613 | ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 614 | ## |
| 615 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 616 | #SeeAlso Color_Space SkImageInfo::colorSpace |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 617 | |
| 618 | ## |
| 619 | |
| 620 | # ------------------------------------------------------------------------------ |
| 621 | |
| 622 | #Method bool isOpaque() const |
| 623 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 624 | #In Image_Info_Access |
| 625 | #Line # returns true if Image_Info describes opaque pixels ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 626 | Returns true if Alpha_Type is kOpaque_SkAlphaType. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 627 | Does not check if Color_Type allows Alpha, or if any pixel value has |
| 628 | transparency. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 629 | |
| 630 | #Return true if Image_Info has opaque Alpha_Type ## |
| 631 | |
| 632 | #Example |
| 633 | #Description |
| 634 | isOpaque ignores whether all pixels are opaque or not. |
| 635 | ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 636 | std::vector<uint32_t> pixels; |
| 637 | const int height = 2; |
| 638 | const int width = 2; |
| 639 | pixels.resize(height * width * 4); |
| 640 | SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType, |
| 641 | kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4); |
| 642 | for (int index = 0; index < 2; ++index) { |
| 643 | pixmap.erase(0x00000000); |
| 644 | SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false"); |
| 645 | pixmap.erase(0xFFFFFFFF); |
| 646 | SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false"); |
| 647 | pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType), |
| 648 | (const void*) &pixels.front(), width * 4); |
| 649 | } |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 650 | #StdOut |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 651 | isOpaque: false |
| 652 | isOpaque: false |
| 653 | isOpaque: true |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 654 | isOpaque: true |
| 655 | ## |
| 656 | ## |
| 657 | |
| 658 | #SeeAlso computeIsOpaque SkImageInfo::isOpaque |
| 659 | |
| 660 | ## |
| 661 | |
| 662 | # ------------------------------------------------------------------------------ |
| 663 | |
| 664 | #Method SkIRect bounds() const |
| 665 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 666 | #In Image_Info_Access |
| 667 | #Line # returns width and height as Rectangle ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 668 | Returns IRect { 0, 0, width(), height() }. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 669 | |
| 670 | #Return integral rectangle from origin to width() and height() ## |
| 671 | |
| 672 | #Example |
| 673 | for (int width : { 0, 2 } ) { |
| 674 | for (int height : { 0, 2 } ) { |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 675 | SkPixmap pixmap(SkImageInfo::MakeA8(width, height), nullptr, width); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 676 | SkDebugf("width: %d height: %d empty: %s\n", width, height, |
| 677 | pixmap.bounds().isEmpty() ? "true" : "false"); |
| 678 | } |
| 679 | } |
| 680 | #StdOut |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 681 | width: 0 height: 0 empty: true |
| 682 | width: 0 height: 2 empty: true |
| 683 | width: 2 height: 0 empty: true |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 684 | width: 2 height: 2 empty: false |
| 685 | ## |
| 686 | ## |
| 687 | |
| 688 | #SeeAlso height() width() IRect |
| 689 | |
| 690 | ## |
| 691 | |
| 692 | # ------------------------------------------------------------------------------ |
| 693 | |
| 694 | #Method int rowBytesAsPixels() const |
| 695 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 696 | #In Image_Info_Access |
| 697 | #Line # returns interval between rows in pixels ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 698 | |
| 699 | Returns number of pixels that fit on row. Should be greater than or equal to |
| 700 | width(). |
| 701 | |
| 702 | #Return maximum pixels per row ## |
| 703 | |
| 704 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 705 | for (int rowBytes : { 4, 5, 6, 7, 8} ) { |
| 706 | SkPixmap pixmap(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), nullptr, rowBytes); |
| 707 | SkDebugf("rowBytes: %d rowBytesAsPixels: %d\n", rowBytes, pixmap.rowBytesAsPixels()); |
| 708 | } |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 709 | #StdOut |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 710 | rowBytes: 4 rowBytesAsPixels: 1 |
| 711 | rowBytes: 5 rowBytesAsPixels: 1 |
| 712 | rowBytes: 6 rowBytesAsPixels: 1 |
| 713 | rowBytes: 7 rowBytesAsPixels: 1 |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 714 | rowBytes: 8 rowBytesAsPixels: 2 |
| 715 | ## |
| 716 | ## |
| 717 | |
| 718 | #SeeAlso rowBytes shiftPerPixel width SkImageInfo::bytesPerPixel |
| 719 | |
| 720 | ## |
| 721 | |
| 722 | # ------------------------------------------------------------------------------ |
| 723 | |
| 724 | #Method int shiftPerPixel() const |
| 725 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 726 | #In Image_Info_Access |
| 727 | #Line # returns bit shift from pixels to bytes ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 728 | Returns bit shift converting row bytes to row pixels. |
| 729 | Returns zero for kUnknown_SkColorType. |
| 730 | |
| 731 | #Return one of: 0, 1, 2, 3; left shift to convert pixels to bytes ## |
| 732 | |
| 733 | #Example |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 734 | const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", |
| 735 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"}; |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 736 | SkImageInfo info = SkImageInfo::MakeA8(1, 1); |
| 737 | for (SkColorType colorType : { kUnknown_SkColorType, kAlpha_8_SkColorType, |
| 738 | kRGB_565_SkColorType, kARGB_4444_SkColorType, |
| 739 | kRGBA_8888_SkColorType, kBGRA_8888_SkColorType, |
| 740 | kGray_8_SkColorType, kRGBA_F16_SkColorType } ) { |
| 741 | SkPixmap pixmap(info.makeColorType(colorType), nullptr, 4); |
| 742 | SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d shiftPerPixel: %d\n", |
| 743 | colors[colorType], 10 - strlen(colors[colorType]), " ", |
| 744 | pixmap.info().bytesPerPixel(), pixmap.shiftPerPixel()); |
| 745 | } |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 746 | #StdOut |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 747 | color: kUnknown_SkColorType bytesPerPixel: 0 shiftPerPixel: 0 |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 748 | color: kAlpha_8_SkColorType bytesPerPixel: 1 shiftPerPixel: 0 |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 749 | color: kRGB_565_SkColorType bytesPerPixel: 2 shiftPerPixel: 1 |
| 750 | color: kARGB_4444_SkColorType bytesPerPixel: 2 shiftPerPixel: 1 |
| 751 | color: kRGBA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2 |
| 752 | color: kBGRA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2 |
| 753 | color: kGray_8_SkColorType bytesPerPixel: 1 shiftPerPixel: 0 |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 754 | color: kRGBA_F16_SkColorType bytesPerPixel: 8 shiftPerPixel: 3 |
| 755 | ## |
| 756 | ## |
| 757 | |
| 758 | #SeeAlso rowBytes rowBytesAsPixels width SkImageInfo::bytesPerPixel |
| 759 | |
| 760 | ## |
| 761 | |
| 762 | # ------------------------------------------------------------------------------ |
| 763 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 764 | #Method size_t computeByteSize() const |
| 765 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 766 | #In Image_Info_Access |
| 767 | #Line # returns size required for pixels ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 768 | Returns minimum memory required for pixel storage. |
| 769 | Does not include unused memory on last row when rowBytesAsPixels exceeds width(). |
| 770 | Returns zero if result does not fit in size_t. |
| 771 | Returns zero if height() or width() is 0. |
| 772 | Returns height() times rowBytes if colorType is kUnknown_SkColorType. |
| 773 | |
| 774 | #Return size in bytes of image buffer ## |
| 775 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 776 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 777 | SkPixmap pixmap; |
| 778 | for (int width : { 1, 1000, 1000000 } ) { |
| 779 | for (int height: { 1, 1000, 1000000 } ) { |
| 780 | SkImageInfo imageInfo = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 781 | pixmap.reset(imageInfo, nullptr, width * 5); |
| 782 | SkDebugf("width: %7d height: %7d computeByteSize: %13lld\n", width, height, |
| 783 | pixmap.computeByteSize()); |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 784 | } |
| 785 | } |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 786 | #StdOut |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 787 | width: 1 height: 1 computeByteSize: 4 |
| 788 | width: 1 height: 1000 computeByteSize: 4999 |
| 789 | width: 1 height: 1000000 computeByteSize: 4999999 |
| 790 | width: 1000 height: 1 computeByteSize: 4000 |
| 791 | width: 1000 height: 1000 computeByteSize: 4999000 |
| 792 | width: 1000 height: 1000000 computeByteSize: 4999999000 |
| 793 | width: 1000000 height: 1 computeByteSize: 4000000 |
| 794 | width: 1000000 height: 1000 computeByteSize: 4999000000 |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 795 | width: 1000000 height: 1000000 computeByteSize: 4999999000000 |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 796 | ## |
| 797 | ## |
| 798 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 799 | #SeeAlso SkImageInfo::computeByteSize |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 800 | |
| 801 | ## |
| 802 | |
| 803 | #Subtopic Image_Info_Access ## |
| 804 | |
| 805 | #Subtopic Reader |
| 806 | |
| 807 | # ------------------------------------------------------------------------------ |
| 808 | |
| 809 | #Method bool computeIsOpaque() const |
| 810 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 811 | #In Reader |
| 812 | #Line # returns true if all pixels are opaque ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 813 | Returns true if all pixels are opaque. Color_Type determines how pixels |
| 814 | are encoded, and whether pixel describes Alpha. Returns true for Color_Types |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 815 | without alpha in each pixel; for other Color_Types, returns true if all |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 816 | pixels have alpha values equivalent to 1.0 or greater. |
| 817 | |
| 818 | For Color_Types kRGB_565_SkColorType or kGray_8_SkColorType: always |
| 819 | returns true. For Color_Types kAlpha_8_SkColorType, kBGRA_8888_SkColorType, |
| 820 | kRGBA_8888_SkColorType: returns true if all pixel Alpha values are 255. |
| 821 | For Color_Type kARGB_4444_SkColorType: returns true if all pixel Alpha values are 15. |
| 822 | For kRGBA_F16_SkColorType: returns true if all pixel Alpha values are 1.0 or |
| 823 | greater. |
| 824 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 825 | Returns false for kUnknown_SkColorType. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 826 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 827 | #Return true if all pixels have opaque values or Color_Type is opaque ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 828 | |
| 829 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 830 | std::vector<uint32_t> pixels; |
| 831 | const int height = 2; |
| 832 | const int width = 2; |
| 833 | pixels.resize(height * width * 4); |
| 834 | SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType, |
| 835 | kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4); |
| 836 | for (int index = 0; index < 2; ++index) { |
| 837 | pixmap.erase(0x00000000); |
| 838 | SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false"); |
| 839 | pixmap.erase(0xFFFFFFFF); |
| 840 | SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false"); |
| 841 | pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType), |
| 842 | (const void*) &pixels.front(), width * 4); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 843 | } |
| 844 | #StdOut |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 845 | computeIsOpaque: false |
| 846 | computeIsOpaque: true |
| 847 | computeIsOpaque: false |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 848 | computeIsOpaque: true |
| 849 | ## |
| 850 | ## |
| 851 | |
| 852 | #SeeAlso isOpaque Color_Type Alpha |
| 853 | |
| 854 | ## |
| 855 | |
| 856 | # ------------------------------------------------------------------------------ |
| 857 | |
| 858 | #Method SkColor getColor(int x, int y) const |
| 859 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 860 | #In Reader |
| 861 | #Line # returns one pixel as Unpremultiplied Color ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 862 | Returns pixel at (x, y) as Unpremultiplied Color. |
| 863 | Returns black with Alpha if Color_Type is kAlpha_8_SkColorType. |
| 864 | |
| 865 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 866 | built with SK_DEBUG defined; and returns undefined values or may crash if |
| 867 | SK_RELEASE is defined. Fails if Color_Type is kUnknown_SkColorType or |
| 868 | pixel address is nullptr. |
| 869 | |
| 870 | Color_Space in Image_Info is ignored. Some Color precision may be lost in the |
| 871 | conversion to Unpremultiplied Color; original pixel data may have additional |
| 872 | precision. |
| 873 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 874 | #Param x column index, zero or greater, and less than width() ## |
| 875 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 876 | |
| 877 | #Return pixel converted to Unpremultiplied Color ## |
| 878 | |
| 879 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 880 | const int w = 4; |
| 881 | const int h = 4; |
| 882 | std::vector<SkPMColor> storage; |
| 883 | storage.resize(w * h); |
| 884 | SkDebugf("Premultiplied:\n"); |
| 885 | for (int y = 0; y < h; ++y) { |
| 886 | SkDebugf("(0, %d) ", y); |
| 887 | for (int x = 0; x < w; ++x) { |
| 888 | int a = 0xFF * (x + y) / (w - 1 + h - 1); |
| 889 | storage[x + y * w] = SkPackARGB32(a, a * x / (w - 1), a * y / (h - 1), a); |
| 890 | SkDebugf("0x%08x%c", storage[x + y * w], x == w - 1 ? '\n' : ' '); |
| 891 | } |
| 892 | } |
| 893 | SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4); |
| 894 | SkDebugf("Unpremultiplied:\n"); |
| 895 | for (int y = 0; y < h; ++y) { |
| 896 | SkDebugf("(0, %d) ", y); |
| 897 | for (int x = 0; x < w; ++x) { |
| 898 | SkDebugf("0x%08x%c", pixmap.getColor(x, y), x == w - 1 ? '\n' : ' '); |
| 899 | } |
| 900 | } |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 901 | #StdOut |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 902 | Premultiplied: |
| 903 | (0, 0) 0x00000000 0x2a0e002a 0x55380055 0x7f7f007f |
| 904 | (0, 1) 0x2a000e2a 0x551c1c55 0x7f542a7f 0xaaaa38aa |
| 905 | (0, 2) 0x55003855 0x7f2a547f 0xaa7171aa 0xd4d48dd4 |
| 906 | (0, 3) 0x7f007f7f 0xaa38aaaa 0xd48dd4d4 0xffffffff |
| 907 | Unpremultiplied: |
| 908 | (0, 0) 0x00000000 0x2a5500ff 0x55a800ff 0x7fff00ff |
| 909 | (0, 1) 0x2a0055ff 0x555454ff 0x7fa954ff 0xaaff54ff |
| 910 | (0, 2) 0x5500a8ff 0x7f54a9ff 0xaaaaaaff 0xd4ffaaff |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 911 | (0, 3) 0x7f00ffff 0xaa54ffff 0xd4aaffff 0xffffffff |
| 912 | ## |
| 913 | ## |
| 914 | |
| 915 | #SeeAlso addr() readPixels |
| 916 | |
| 917 | ## |
| 918 | |
| 919 | #Subtopic Reader ## |
| 920 | |
| 921 | #Subtopic Readable_Address |
| 922 | |
| 923 | # ------------------------------------------------------------------------------ |
| 924 | |
| 925 | #Method const void* addr(int x, int y) const |
| 926 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 927 | #In Readable_Address |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 928 | Returns readable pixel address at (x, y). Returns nullptr if Pixel_Ref is nullptr. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 929 | |
| 930 | Input is not validated: out of bounds values of x or y trigger an assert() if |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 931 | built with SK_DEBUG defined. Returns nullptr if Color_Type is kUnknown_SkColorType. |
| 932 | |
| 933 | Performs a lookup of pixel size; for better performance, call |
| 934 | one of: addr8, addr16, addr32, addr64, or addrF16. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 935 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 936 | #Param x column index, zero or greater, and less than width() ## |
| 937 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 938 | |
| 939 | #Return readable generic pointer to pixel ## |
| 940 | |
| 941 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 942 | const int w = 4; |
| 943 | const int h = 4; |
| 944 | std::vector<SkPMColor> storage; |
| 945 | storage.resize(w * h); |
| 946 | SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 947 | SkDebugf("pixmap.addr(1, 2) %c= &storage[1 + 2 * w]\n", |
| 948 | pixmap.addr(1, 2) == &storage[1 + 2 * w] ? '=' : '!'); |
| 949 | #StdOut |
| 950 | pixmap.addr(1, 2) == &storage[1 + 2 * w] |
| 951 | ## |
| 952 | ## |
| 953 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 954 | #SeeAlso addr8 addr16 addr32 addr64 addrF16 getColor writable_addr SkBitmap::getAddr |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 955 | |
| 956 | ## |
| 957 | |
| 958 | # ------------------------------------------------------------------------------ |
| 959 | |
| 960 | #Method const uint8_t* addr8() const |
| 961 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 962 | #In Readable_Address |
| 963 | #Line # returns readable pixel address as 8-bit pointer ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 964 | Returns readable base pixel address. Result is addressable as unsigned 8-bit bytes. |
| 965 | Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType or |
| 966 | kGray_8_SkColorType, and is built with SK_DEBUG defined. |
| 967 | |
| 968 | One byte corresponds to one pixel. |
| 969 | |
| 970 | #Return readable unsigned 8-bit pointer to pixels ## |
| 971 | |
| 972 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 973 | const int w = 4; |
| 974 | const int h = 4; |
| 975 | uint8_t storage[w * h]; |
| 976 | SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType), |
| 977 | storage, w * sizeof(storage[0])); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 978 | SkDebugf("pixmap.addr8() %c= storage\n", |
| 979 | pixmap.addr8() == storage ? '=' : '!'); |
| 980 | #StdOut |
| 981 | pixmap.addr8() == storage |
| 982 | ## |
| 983 | ## |
| 984 | |
| 985 | #SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8 |
| 986 | |
| 987 | ## |
| 988 | |
| 989 | # ------------------------------------------------------------------------------ |
| 990 | |
| 991 | #Method const uint16_t* addr16() const |
| 992 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 993 | #In Readable_Address |
| 994 | #Line # returns readable pixel address as 16-bit pointer ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 995 | Returns readable base pixel address. Result is addressable as unsigned 16-bit words. |
| 996 | Will trigger an assert() if Color_Type is not kRGB_565_SkColorType or |
| 997 | kARGB_4444_SkColorType, and is built with SK_DEBUG defined. |
| 998 | |
| 999 | One word corresponds to one pixel. |
| 1000 | |
| 1001 | #Return readable unsigned 16-bit pointer to pixels ## |
| 1002 | |
| 1003 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1004 | const int w = 4; |
| 1005 | const int h = 4; |
| 1006 | uint16_t storage[w * h]; |
| 1007 | SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType), |
| 1008 | storage, w * sizeof(storage[0])); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1009 | SkDebugf("pixmap.addr16() %c= storage\n", |
| 1010 | pixmap.addr16() == storage ? '=' : '!'); |
| 1011 | #StdOut |
| 1012 | pixmap.addr16() == storage |
| 1013 | ## |
| 1014 | ## |
| 1015 | |
| 1016 | #SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16 |
| 1017 | |
| 1018 | ## |
| 1019 | |
| 1020 | # ------------------------------------------------------------------------------ |
| 1021 | |
| 1022 | #Method const uint32_t* addr32() const |
| 1023 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1024 | #In Readable_Address |
| 1025 | #Line # returns readable pixel address as 32-bit pointer ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1026 | Returns readable base pixel address. Result is addressable as unsigned 32-bit words. |
| 1027 | Will trigger an assert() if Color_Type is not kRGBA_8888_SkColorType or |
| 1028 | kBGRA_8888_SkColorType, and is built with SK_DEBUG defined. |
| 1029 | |
| 1030 | One word corresponds to one pixel. |
| 1031 | |
| 1032 | #Return readable unsigned 32-bit pointer to pixels ## |
| 1033 | |
| 1034 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1035 | const int w = 4; |
| 1036 | const int h = 4; |
| 1037 | uint32_t storage[w * h]; |
| 1038 | SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), |
| 1039 | storage, w * sizeof(storage[0])); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1040 | SkDebugf("pixmap.addr32() %c= storage\n", |
| 1041 | pixmap.addr32() == storage ? '=' : '!'); |
| 1042 | #StdOut |
| 1043 | pixmap.addr32() == storage |
| 1044 | ## |
| 1045 | ## |
| 1046 | |
| 1047 | #SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr32 |
| 1048 | |
| 1049 | ## |
| 1050 | |
| 1051 | # ------------------------------------------------------------------------------ |
| 1052 | |
| 1053 | #Method const uint64_t* addr64() const |
| 1054 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1055 | #In Readable_Address |
| 1056 | #Line # returns readable pixel address as 64-bit pointer ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1057 | Returns readable base pixel address. Result is addressable as unsigned 64-bit words. |
| 1058 | Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built |
| 1059 | with SK_DEBUG defined. |
| 1060 | |
| 1061 | One word corresponds to one pixel. |
| 1062 | |
| 1063 | #Return readable unsigned 64-bit pointer to pixels ## |
| 1064 | |
| 1065 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1066 | const int w = 4; |
| 1067 | const int h = 4; |
| 1068 | uint64_t storage[w * h]; |
| 1069 | SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType), |
| 1070 | storage, w * sizeof(storage[0])); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1071 | SkDebugf("pixmap.addr64() %c= storage\n", |
| 1072 | pixmap.addr64() == storage ? '=' : '!'); |
| 1073 | #StdOut |
| 1074 | pixmap.addr64() == storage |
| 1075 | ## |
| 1076 | ## |
| 1077 | |
| 1078 | #SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64 |
| 1079 | |
| 1080 | ## |
| 1081 | |
| 1082 | # ------------------------------------------------------------------------------ |
| 1083 | |
| 1084 | #Method const uint16_t* addrF16() const |
| 1085 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1086 | #In Readable_Address |
| 1087 | #Line # returns readable pixel component address as 16-bit pointer ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1088 | Returns readable base pixel address. Result is addressable as unsigned 16-bit words. |
| 1089 | Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built |
| 1090 | with SK_DEBUG defined. |
| 1091 | |
| 1092 | Each word represents one color component encoded as a half float. |
| 1093 | Four words correspond to one pixel. |
| 1094 | |
| 1095 | #Return readable unsigned 16-bit pointer to first component of pixels ## |
| 1096 | |
| 1097 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1098 | const int w = 4; |
| 1099 | const int h = 4; |
| 1100 | uint16_t storage[w * h * 4]; |
| 1101 | SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType), |
| 1102 | storage, w * 4 * sizeof(storage[0])); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1103 | SkDebugf("pixmap.addrF16() %c= storage\n", |
| 1104 | pixmap.addrF16() == storage ? '=' : '!'); |
| 1105 | #StdOut |
| 1106 | pixmap.addrF16() == storage |
| 1107 | ## |
| 1108 | ## |
| 1109 | |
| 1110 | #SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16 |
| 1111 | |
| 1112 | ## |
| 1113 | |
| 1114 | # ------------------------------------------------------------------------------ |
| 1115 | |
| 1116 | #Method const uint8_t* addr8(int x, int y) const |
| 1117 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1118 | #In Readable_Address |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1119 | Returns readable pixel address at (x, y). |
| 1120 | |
| 1121 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 1122 | built with SK_DEBUG defined. |
| 1123 | |
| 1124 | Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType or |
| 1125 | kGray_8_SkColorType, and is built with SK_DEBUG defined. |
| 1126 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1127 | #Param x column index, zero or greater, and less than width() ## |
| 1128 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1129 | |
| 1130 | #Return readable unsigned 8-bit pointer to pixel at (x, y) ## |
| 1131 | |
| 1132 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1133 | const int w = 4; |
| 1134 | const int h = 4; |
| 1135 | uint8_t storage[w * h]; |
| 1136 | SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType), |
| 1137 | storage, w * sizeof(storage[0])); |
| 1138 | SkDebugf("pixmap.addr8(1, 2) %c= &storage[1 + 2 * w]\n", |
| 1139 | pixmap.addr8(1, 2) == &storage[1 + 2 * w] ? '=' : '!'); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1140 | #StdOut |
| 1141 | pixmap.addr8(1, 2) == &storage[1 + 2 * w] |
| 1142 | ## |
| 1143 | ## |
| 1144 | |
| 1145 | #SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8 |
| 1146 | |
| 1147 | ## |
| 1148 | |
| 1149 | # ------------------------------------------------------------------------------ |
| 1150 | |
| 1151 | #Method const uint16_t* addr16(int x, int y) const |
| 1152 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1153 | #In Readable_Address |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1154 | Returns readable pixel address at (x, y). |
| 1155 | |
| 1156 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 1157 | built with SK_DEBUG defined. |
| 1158 | |
| 1159 | Will trigger an assert() if Color_Type is not kRGB_565_SkColorType or |
| 1160 | kARGB_4444_SkColorType, and is built with SK_DEBUG defined. |
| 1161 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1162 | #Param x column index, zero or greater, and less than width() ## |
| 1163 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1164 | |
| 1165 | #Return readable unsigned 16-bit pointer to pixel at (x, y) ## |
| 1166 | |
| 1167 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1168 | const int w = 4; |
| 1169 | const int h = 4; |
| 1170 | uint16_t storage[w * h]; |
| 1171 | SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType), |
| 1172 | storage, w * sizeof(storage[0])); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1173 | SkDebugf("pixmap.addr16(1, 2) %c= &storage[1 + 2 * w]\n", |
| 1174 | pixmap.addr16(1, 2) == &storage[1 + 2 * w] ? '=' : '!'); |
| 1175 | #StdOut |
| 1176 | pixmap.addr16(1, 2) == &storage[1 + 2 * w] |
| 1177 | ## |
| 1178 | ## |
| 1179 | |
| 1180 | #SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16 |
| 1181 | |
| 1182 | ## |
| 1183 | |
| 1184 | # ------------------------------------------------------------------------------ |
| 1185 | |
| 1186 | #Method const uint32_t* addr32(int x, int y) const |
| 1187 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1188 | #In Readable_Address |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1189 | Returns readable pixel address at (x, y). |
| 1190 | |
| 1191 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 1192 | built with SK_DEBUG defined. |
| 1193 | |
| 1194 | Will trigger an assert() if Color_Type is not kRGBA_8888_SkColorType or |
| 1195 | kBGRA_8888_SkColorType, and is built with SK_DEBUG defined. |
| 1196 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1197 | #Param x column index, zero or greater, and less than width() ## |
| 1198 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1199 | |
| 1200 | #Return readable unsigned 32-bit pointer to pixel at (x, y) ## |
| 1201 | |
| 1202 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1203 | const int w = 4; |
| 1204 | const int h = 4; |
| 1205 | uint32_t storage[w * h]; |
| 1206 | SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_8888_SkColorType, kPremul_SkAlphaType), |
| 1207 | storage, w * sizeof(storage[0])); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1208 | SkDebugf("pixmap.addr32(1, 2) %c= &storage[1 + 2 * w]\n", |
| 1209 | pixmap.addr32(1, 2) == &storage[1 + 2 * w] ? '=' : '!'); |
| 1210 | #StdOut |
| 1211 | pixmap.addr32(1, 2) == &storage[1 + 2 * w] |
| 1212 | ## |
| 1213 | ## |
| 1214 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1215 | #SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr64 |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1216 | |
| 1217 | ## |
| 1218 | |
| 1219 | # ------------------------------------------------------------------------------ |
| 1220 | |
| 1221 | #Method const uint64_t* addr64(int x, int y) const |
| 1222 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1223 | #In Readable_Address |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1224 | Returns readable pixel address at (x, y). |
| 1225 | |
| 1226 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 1227 | built with SK_DEBUG defined. |
| 1228 | |
| 1229 | Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built |
| 1230 | with SK_DEBUG defined. |
| 1231 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1232 | #Param x column index, zero or greater, and less than width() ## |
| 1233 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1234 | |
| 1235 | #Return readable unsigned 64-bit pointer to pixel at (x, y) ## |
| 1236 | |
| 1237 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1238 | const int w = 4; |
| 1239 | const int h = 4; |
| 1240 | uint64_t storage[w * h]; |
| 1241 | SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType), |
| 1242 | storage, w * sizeof(storage[0])); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1243 | SkDebugf("pixmap.addr64(1, 2) %c= &storage[1 + 2 * w]\n", |
| 1244 | pixmap.addr64(1, 2) == &storage[1 + 2 * w] ? '=' : '!'); |
| 1245 | #StdOut |
| 1246 | pixmap.addr64(1, 2) == &storage[1 + 2 * w] |
| 1247 | ## |
| 1248 | ## |
| 1249 | |
| 1250 | #SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64 |
| 1251 | |
| 1252 | ## |
| 1253 | |
| 1254 | # ------------------------------------------------------------------------------ |
| 1255 | |
| 1256 | #Method const uint16_t* addrF16(int x, int y) const |
| 1257 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1258 | #In Readable_Address |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1259 | Returns readable pixel address at (x, y). |
| 1260 | |
| 1261 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 1262 | built with SK_DEBUG defined. |
| 1263 | |
| 1264 | Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built |
| 1265 | with SK_DEBUG defined. |
| 1266 | |
| 1267 | Each unsigned 16-bit word represents one color component encoded as a half float. |
| 1268 | Four words correspond to one pixel. |
| 1269 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1270 | #Param x column index, zero or greater, and less than width() ## |
| 1271 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1272 | |
| 1273 | #Return readable unsigned 16-bit pointer to pixel component at (x, y) ## |
| 1274 | |
| 1275 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1276 | const int w = 4; |
| 1277 | const int h = 4; |
| 1278 | const int wordsPerPixel = 4; |
| 1279 | const int rowWords = w * wordsPerPixel; |
| 1280 | uint16_t storage[rowWords * h]; |
| 1281 | SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType), |
| 1282 | storage, rowWords * sizeof(storage[0])); |
| 1283 | SkDebugf("pixmap.addrF16(1, 2) %c= &storage[1 * wordsPerPixel + 2 * rowWords]\n", |
| 1284 | pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords] ? '=' : '!'); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1285 | #StdOut |
| 1286 | pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords] |
| 1287 | ## |
| 1288 | ## |
| 1289 | |
| 1290 | #SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16 |
| 1291 | |
| 1292 | ## |
| 1293 | |
| 1294 | #Subtopic Readable_Address ## |
| 1295 | |
| 1296 | #Subtopic Writable_Address |
| 1297 | |
| 1298 | # ------------------------------------------------------------------------------ |
| 1299 | |
| 1300 | #Method void* writable_addr() const |
| 1301 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1302 | #In Writable_Address |
| 1303 | #Line # returns writable pixel address as void pointer ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1304 | Returns writable base pixel address. |
| 1305 | |
| 1306 | #Return writable generic base pointer to pixels ## |
| 1307 | |
| 1308 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1309 | const int w = 4; |
| 1310 | const int h = 4; |
| 1311 | SkPMColor storage[w * h * 4]; |
| 1312 | SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4); |
| 1313 | SkDebugf("pixmap.writable_addr() %c= (void *)storage\n", |
| 1314 | pixmap.writable_addr() == (void *)storage ? '=' : '!'); |
| 1315 | pixmap.erase(0x00000000); |
| 1316 | *(SkPMColor*)pixmap.writable_addr() = 0xFFFFFFFF; |
| 1317 | SkDebugf("pixmap.getColor(0, 1) %c= 0x00000000\n", |
| 1318 | pixmap.getColor(0, 1) == 0x00000000 ? '=' : '!'); |
| 1319 | SkDebugf("pixmap.getColor(0, 0) %c= 0xFFFFFFFF\n", |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1320 | pixmap.getColor(0, 0) == 0xFFFFFFFF ? '=' : '!'); |
| 1321 | #StdOut |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1322 | pixmap.writable_addr() == (void *)storage |
| 1323 | pixmap.getColor(0, 1) == 0x00000000 |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1324 | pixmap.getColor(0, 0) == 0xFFFFFFFF |
| 1325 | ## |
| 1326 | ## |
| 1327 | |
| 1328 | #SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr() |
| 1329 | |
| 1330 | ## |
| 1331 | |
| 1332 | # ------------------------------------------------------------------------------ |
| 1333 | |
| 1334 | #Method void* writable_addr(int x, int y) const |
| 1335 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1336 | #In Writable_Address |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1337 | Returns writable pixel address at (x, y). |
| 1338 | |
| 1339 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 1340 | built with SK_DEBUG defined. Returns zero if Color_Type is kUnknown_SkColorType. |
| 1341 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1342 | #Param x column index, zero or greater, and less than width() ## |
| 1343 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1344 | |
| 1345 | #Return writable generic pointer to pixel ## |
| 1346 | |
| 1347 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1348 | const int w = 4; |
| 1349 | const int h = 4; |
| 1350 | SkPMColor storage[w * h * 4]; |
| 1351 | SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4); |
| 1352 | SkDebugf("pixmap.writable_addr() %c= (void *)storage\n", |
| 1353 | pixmap.writable_addr() == (void *)storage ? '=' : '!'); |
| 1354 | pixmap.erase(0x00000000); |
| 1355 | *(SkPMColor*)pixmap.writable_addr(1, 2) = 0xFFFFFFFF; |
| 1356 | SkDebugf("pixmap.getColor(0, 0) %c= 0x00000000\n", |
| 1357 | pixmap.getColor(0, 0) == 0x00000000 ? '=' : '!'); |
| 1358 | SkDebugf("pixmap.getColor(1, 2) %c= 0xFFFFFFFF\n", |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1359 | pixmap.getColor(1, 2) == 0xFFFFFFFF ? '=' : '!'); |
| 1360 | #StdOut |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1361 | pixmap.writable_addr() == (void *)storage |
| 1362 | pixmap.getColor(0, 0) == 0x00000000 |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1363 | pixmap.getColor(1, 2) == 0xFFFFFFFF |
| 1364 | ## |
| 1365 | ## |
| 1366 | |
| 1367 | #SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr() |
| 1368 | |
| 1369 | ## |
| 1370 | |
| 1371 | # ------------------------------------------------------------------------------ |
| 1372 | |
| 1373 | #Method uint8_t* writable_addr8(int x, int y) const |
| 1374 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1375 | #In Writable_Address |
| 1376 | #Line # returns writable pixel address as 8-bit pointer ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1377 | Returns writable pixel address at (x, y). Result is addressable as unsigned |
| 1378 | 8-bit bytes. Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType |
| 1379 | or kGray_8_SkColorType, and is built with SK_DEBUG defined. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1380 | |
| 1381 | One byte corresponds to one pixel. |
| 1382 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1383 | #Param x column index, zero or greater, and less than width() ## |
| 1384 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1385 | |
| 1386 | #Return writable unsigned 8-bit pointer to pixels ## |
| 1387 | |
| 1388 | #Example |
| 1389 | #Height 64 |
| 1390 | #Description |
| 1391 | Altering pixels after drawing Bitmap is not guaranteed to affect subsequent |
| 1392 | drawing on all platforms. Adding a second SkBitmap::installPixels after editing |
| 1393 | pixel memory is safer. |
| 1394 | ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1395 | void draw(SkCanvas* canvas) { |
| 1396 | uint8_t storage[][5] = {{ 0, 0, 64, 0, 0}, |
| 1397 | { 0, 128, 255, 128, 0}, |
| 1398 | {64, 255, 255, 255, 64}, |
| 1399 | { 0, 128, 255, 128, 0}, |
| 1400 | { 0, 0, 64, 0, 0}}; |
| 1401 | SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kPremul_SkAlphaType); |
| 1402 | SkPixmap pixmap(imageInfo, storage[0], 5); |
| 1403 | SkBitmap bitmap; |
| 1404 | bitmap.installPixels(pixmap); |
| 1405 | canvas->scale(10, 10); |
| 1406 | canvas->drawBitmap(bitmap, 0, 0); |
| 1407 | *pixmap.writable_addr8(2, 2) = 0; |
| 1408 | // bitmap.installPixels(pixmap); // uncomment to fix on GPU |
| 1409 | canvas->drawBitmap(bitmap, 10, 0); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1410 | } |
| 1411 | ## |
| 1412 | |
| 1413 | #SeeAlso writable_addr writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr() addr8 |
| 1414 | |
| 1415 | ## |
| 1416 | |
| 1417 | # ------------------------------------------------------------------------------ |
| 1418 | |
| 1419 | #Method uint16_t* writable_addr16(int x, int y) const |
| 1420 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1421 | #In Writable_Address |
| 1422 | #Line # returns writable pixel address as 16-bit pointer ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1423 | Returns writable_addr pixel address at (x, y). Result is addressable as unsigned |
| 1424 | 16-bit words. Will trigger an assert() if Color_Type is not kRGB_565_SkColorType |
| 1425 | or kARGB_4444_SkColorType, and is built with SK_DEBUG defined. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1426 | |
| 1427 | One word corresponds to one pixel. |
| 1428 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1429 | #Param x column index, zero or greater, and less than width() ## |
| 1430 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1431 | |
| 1432 | #Return writable unsigned 16-bit pointer to pixel ## |
| 1433 | |
| 1434 | #Example |
| 1435 | #Description |
| 1436 | Draw a five by five bitmap, and draw it again with a center black pixel. |
| 1437 | The low nibble of the 16-bit word is Alpha. |
| 1438 | ## |
| 1439 | #Height 64 |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1440 | uint16_t storage[][5] = {{ 0xCABF, 0xDABE, 0xCA9D, 0xC96C, 0xA39B }, |
| 1441 | { 0xACEE, 0xA87C, 0x893A, 0x4779, 0x8708 }, |
| 1442 | { 0x4B7C, 0x255B, 0x2559, 0x2557, 0x4656 }, |
| 1443 | { 0x9099, 0x8128, 0x2557, 0x4124, 0x3323 }, |
| 1444 | { 0x7547, 0x5505, 0x4434, 0x2012, 0x0000 }}; |
| 1445 | SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kARGB_4444_SkColorType, kPremul_SkAlphaType); |
| 1446 | SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5); |
| 1447 | SkBitmap bitmap; |
| 1448 | bitmap.installPixels(pixmap); |
| 1449 | canvas->scale(10, 10); |
| 1450 | canvas->drawBitmap(bitmap, 0, 0); |
| 1451 | *pixmap.writable_addr16(2, 2) = 0x000F; |
| 1452 | bitmap.installPixels(pixmap); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1453 | canvas->drawBitmap(bitmap, 10, 0); |
| 1454 | ## |
| 1455 | |
| 1456 | #SeeAlso writable_addr writable_addr8 writable_addr32 writable_addr64 writable_addrF16 addr() addr16 |
| 1457 | |
| 1458 | ## |
| 1459 | |
| 1460 | # ------------------------------------------------------------------------------ |
| 1461 | |
| 1462 | #Method uint32_t* writable_addr32(int x, int y) const |
| 1463 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1464 | #In Writable_Address |
| 1465 | #Line # returns writable pixel address as 32-bit pointer ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1466 | Returns writable pixel address at (x, y). Result is addressable as unsigned |
| 1467 | 32-bit words. Will trigger an assert() if Color_Type is not |
| 1468 | kRGBA_8888_SkColorType or kBGRA_8888_SkColorType, and is built with SK_DEBUG |
| 1469 | defined. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1470 | |
| 1471 | One word corresponds to one pixel. |
| 1472 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1473 | #Param x column index, zero or greater, and less than width() ## |
| 1474 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1475 | |
| 1476 | #Return writable unsigned 32-bit pointer to pixel ## |
| 1477 | |
| 1478 | #Example |
| 1479 | #Image 4 |
| 1480 | #Height 72 |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1481 | std::vector<int32_t> pixels; |
| 1482 | pixels.resize(image->height() * image->width() * 4); |
| 1483 | SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType, |
| 1484 | image->alphaType()), (const void*) &pixels.front(), image->width() * 4); |
| 1485 | image->readPixels(pixmap, 0, 0); |
| 1486 | for (int y = 0; y < pixmap.height() / 2; ++y) { |
| 1487 | for (int x = 0; x < pixmap.width(); ++x) { |
| 1488 | if ((x & 4) == (y & 4)) { |
| 1489 | SkTSwap(*pixmap.writable_addr32(x, y), |
| 1490 | *pixmap.writable_addr32(pixmap.width() - x, pixmap.height() - y)); |
| 1491 | } |
| 1492 | } |
| 1493 | } |
| 1494 | SkBitmap bitmap; |
| 1495 | bitmap.installPixels(pixmap); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1496 | canvas->drawBitmap(bitmap, 0, 0); |
| 1497 | ## |
| 1498 | |
| 1499 | #SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr64 writable_addrF16 addr() addr32 |
| 1500 | |
| 1501 | ## |
| 1502 | |
| 1503 | # ------------------------------------------------------------------------------ |
| 1504 | |
| 1505 | #Method uint64_t* writable_addr64(int x, int y) const |
| 1506 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1507 | #In Writable_Address |
| 1508 | #Line # returns writable pixel address as 64-bit pointer ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1509 | Returns writable pixel address at (x, y). Result is addressable as unsigned |
| 1510 | 64-bit words. Will trigger an assert() if Color_Type is not |
| 1511 | kRGBA_F16_SkColorType and is built with SK_DEBUG defined. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1512 | |
| 1513 | One word corresponds to one pixel. |
| 1514 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1515 | #Param x column index, zero or greater, and less than width() ## |
| 1516 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1517 | |
| 1518 | #Return writable unsigned 64-bit pointer to pixel ## |
| 1519 | |
| 1520 | #Example |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1521 | #Height 40 |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1522 | SkImageInfo info = SkImageInfo::Make(3, 3, kRGBA_F16_SkColorType, kPremul_SkAlphaType); |
| 1523 | uint64_t storage[9]; |
| 1524 | SkPixmap pixmap(info, storage, 3 * sizeof(uint64_t)); |
| 1525 | SkColor4f c4 { 1, 0.45f, 0.25f, 0.65f }; |
| 1526 | pixmap.erase(c4); |
| 1527 | SkBitmap bitmap; |
| 1528 | canvas->scale(10, 10); |
| 1529 | bitmap.installPixels(pixmap); |
| 1530 | canvas->drawBitmap(bitmap, 0, 0); |
| 1531 | *pixmap.writable_addr64(1, 1) |= 0x00ff000000000000LL; |
| 1532 | bitmap.installPixels(pixmap); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1533 | canvas->drawBitmap(bitmap, 10, 0); |
| 1534 | ## |
| 1535 | |
| 1536 | #SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addrF16 addr() addr64 |
| 1537 | |
| 1538 | ## |
| 1539 | |
| 1540 | # ------------------------------------------------------------------------------ |
| 1541 | |
| 1542 | #Method uint16_t* writable_addrF16(int x, int y) const |
| 1543 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1544 | #In Writable_Address |
| 1545 | #Line # returns writable pixel component address as 16-bit pointer ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1546 | Returns writable pixel address at (x, y). Result is addressable as unsigned |
| 1547 | 16-bit words. Will trigger an assert() if Color_Type is not |
| 1548 | kRGBA_F16_SkColorType and is built with SK_DEBUG defined. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1549 | |
| 1550 | Each word represents one color component encoded as a half float. |
| 1551 | Four words correspond to one pixel. |
| 1552 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1553 | #Param x column index, zero or greater, and less than width() ## |
| 1554 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1555 | |
| 1556 | #Return writable unsigned 16-bit pointer to first component of pixel ## |
| 1557 | |
| 1558 | #Example |
| 1559 | #Height 64 |
| 1560 | #Description |
| 1561 | Left bitmap is drawn with two pixels defined in half float format. Right bitmap |
| 1562 | is drawn after overwriting bottom half float color with top half float color. |
| 1563 | ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1564 | SkImageInfo info = SkImageInfo::Make(1, 2, kRGBA_F16_SkColorType, kPremul_SkAlphaType); |
| 1565 | uint16_t storage[2][4]; |
| 1566 | SkPixmap pixmap(info, storage[0], sizeof(uint64_t)); |
| 1567 | SkIRect topPixelBounds = {0, 0, 1, 1}; |
| 1568 | pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds); |
| 1569 | SkIRect bottomPixelBounds = {0, 1, 1, 2}; |
| 1570 | pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds); |
| 1571 | SkBitmap bitmap; |
| 1572 | canvas->scale(20, 20); |
| 1573 | bitmap.installPixels(pixmap); |
| 1574 | canvas->drawBitmap(bitmap, 0, 0); |
| 1575 | uint16_t* pixel2 = pixmap.writable_addrF16(0, 1); |
| 1576 | for (int i = 0; i < 4; ++i) { |
| 1577 | pixel2[i] = storage[0][i]; |
| 1578 | } |
| 1579 | bitmap.installPixels(pixmap); |
| 1580 | canvas->drawBitmap(bitmap, 4, 0); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1581 | ## |
| 1582 | |
| 1583 | #SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addr64 addr() addrF16 |
| 1584 | |
| 1585 | ## |
| 1586 | |
| 1587 | #Subtopic Writable_Address ## |
| 1588 | |
| 1589 | #Subtopic Writer |
| 1590 | |
| 1591 | # ------------------------------------------------------------------------------ |
| 1592 | |
| 1593 | #Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 1594 | int srcX, int srcY, SkTransferFunctionBehavior behavior) const |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1595 | #In Writer |
| 1596 | #Line # copies and converts pixels ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1597 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1598 | Copies a Rect of pixels to dstPixels. Copy starts at (srcX, srcY), and does not |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1599 | exceed Pixmap (width(), height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1600 | |
| 1601 | dstInfo specifies width, height, Color_Type, Alpha_Type, and |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1602 | Color_Space of destination. dstRowBytes specifics the gap from one destination |
| 1603 | row to the next. Returns true if pixels are copied. Returns false if |
| 1604 | dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes. |
| 1605 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1606 | Pixels are copied only if pixel conversion is possible. If Pixmap colorType is |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1607 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match. |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1608 | If Pixmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match. |
| 1609 | If Pixmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must |
| 1610 | match. If Pixmap colorSpace is nullptr, dstInfo.colorSpace must match. Returns |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1611 | false if pixel conversion is not possible. |
| 1612 | |
| 1613 | srcX and srcY may be negative to copy only top or left of source. Returns |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1614 | false if width() or height() is zero or negative. Returns false if: |
| 1615 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1616 | #Formula |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1617 | abs(srcX) >= Pixmap width() |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1618 | ## |
| 1619 | , or if |
| 1620 | #Formula |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1621 | abs(srcY) >= Pixmap height() |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1622 | ## |
| 1623 | . |
| 1624 | |
| 1625 | If behavior is SkTransferFunctionBehavior::kRespect: converts source |
| 1626 | pixels to a linear space before converting to dstInfo. |
| 1627 | If behavior is SkTransferFunctionBehavior::kIgnore: source |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1628 | pixels are treated as if they are linear, regardless of how they are encoded. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1629 | |
| 1630 | #Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ## |
| 1631 | #Param dstPixels destination pixel storage ## |
| 1632 | #Param dstRowBytes destination row length ## |
| 1633 | #Param srcX column index whose absolute value is less than width() ## |
| 1634 | #Param srcY row index whose absolute value is less than height() ## |
| 1635 | #Param behavior one of: SkTransferFunctionBehavior::kRespect, |
| 1636 | SkTransferFunctionBehavior::kIgnore |
| 1637 | ## |
| 1638 | |
| 1639 | #Return true if pixels are copied to dstPixels ## |
| 1640 | |
| 1641 | #Example |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1642 | #ToDo example doesn't do anything interesting since info colorSpace is nullptr ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1643 | #Image 3 |
| 1644 | void draw(SkCanvas* canvas) { |
| 1645 | SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height(), |
| 1646 | canvas->imageInfo().colorSpace() ? SkColorSpace::MakeSRGB() : nullptr); |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1647 | std::vector<int32_t> srcPixels; |
| 1648 | srcPixels.resize(image->height() * image->width() * 4); |
| 1649 | SkPixmap pixmap(info, (const void*) &srcPixels.front(), image->width() * 4); |
| 1650 | image->readPixels(pixmap, 0, 0); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1651 | SkTransferFunctionBehavior behavior = canvas->imageInfo().colorSpace() ? |
| 1652 | SkTransferFunctionBehavior::kRespect : SkTransferFunctionBehavior::kIgnore; |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1653 | std::vector<int32_t> dstPixels; |
| 1654 | dstPixels.resize(image->height() * image->width() * 4); |
| 1655 | int offset = 0; |
| 1656 | for (auto behavior : { SkTransferFunctionBehavior::kRespect, |
| 1657 | SkTransferFunctionBehavior::kIgnore} ) { |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1658 | pixmap.readPixels(info, &dstPixels.front(), image->width() * 4, offset, 0, behavior); |
| 1659 | offset += 128; |
| 1660 | } |
| 1661 | SkBitmap bitmap; |
| 1662 | SkPixmap dstmap(info, &dstPixels.front(), image->width() * 4); |
| 1663 | bitmap.installPixels(dstmap); |
| 1664 | canvas->drawBitmap(bitmap, 0, 0); |
| 1665 | } |
| 1666 | ## |
| 1667 | |
| 1668 | #SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels |
| 1669 | |
| 1670 | ## |
| 1671 | |
| 1672 | # ------------------------------------------------------------------------------ |
| 1673 | |
| 1674 | #Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes) const |
| 1675 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1676 | #In Writer |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1677 | Copies a Rect of pixels to dstPixels. Copy starts at (0, 0), and does not |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1678 | exceed Pixmap (width(), height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1679 | |
| 1680 | dstInfo specifies width, height, Color_Type, Alpha_Type, and |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1681 | Color_Space of destination. dstRowBytes specifics the gap from one destination |
| 1682 | row to the next. Returns true if pixels are copied. Returns false if |
| 1683 | dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes. |
| 1684 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1685 | Pixels are copied only if pixel conversion is possible. If Pixmap colorType is |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1686 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match. |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1687 | If Pixmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match. |
| 1688 | If Pixmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must |
| 1689 | match. If Pixmap colorSpace is nullptr, dstInfo.colorSpace must match. Returns |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1690 | false if pixel conversion is not possible. |
| 1691 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1692 | Returns false if Pixmap width() or height() is zero or negative. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1693 | |
| 1694 | #Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ## |
| 1695 | #Param dstPixels destination pixel storage ## |
| 1696 | #Param dstRowBytes destination row length ## |
| 1697 | |
| 1698 | #Return true if pixels are copied to dstPixels ## |
| 1699 | |
| 1700 | #Example |
| 1701 | #Height 128 |
| 1702 | #Description |
| 1703 | Transferring the gradient from 8 bits per component to 4 bits per component |
| 1704 | creates visible banding. |
| 1705 | ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1706 | std::vector<int32_t> pixels; |
| 1707 | const int width = 256; |
| 1708 | const int height = 64; |
| 1709 | pixels.resize(height * width * 4); |
| 1710 | SkImageInfo srcInfo = SkImageInfo::MakeN32Premul(width, height); |
| 1711 | SkPixmap srcPixmap(srcInfo, (const void*) &pixels.front(), width * 4); |
| 1712 | SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 }; |
| 1713 | SkPoint gradPoints[] = { { 0, 0 }, { 256, 0 } }; |
| 1714 | SkPaint paint; |
| 1715 | paint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr, |
| 1716 | SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode)); |
| 1717 | SkBitmap bitmap; |
| 1718 | bitmap.installPixels(srcPixmap); |
| 1719 | SkCanvas srcCanvas(bitmap); |
| 1720 | srcCanvas.drawRect(SkRect::MakeWH(width, height), paint); |
| 1721 | canvas->drawBitmap(bitmap, 0, 0); |
| 1722 | std::vector<int32_t> dstPixels; |
| 1723 | dstPixels.resize(height * width * 2); |
| 1724 | SkImageInfo dstInfo = srcInfo.makeColorType(kARGB_4444_SkColorType); |
| 1725 | srcPixmap.readPixels(dstInfo, &dstPixels.front(), width * 2); |
| 1726 | SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2); |
| 1727 | bitmap.installPixels(dstPixmap); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1728 | canvas->drawBitmap(bitmap, 0, 128); |
| 1729 | ## |
| 1730 | |
| 1731 | #SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels |
| 1732 | |
| 1733 | ## |
| 1734 | |
| 1735 | # ------------------------------------------------------------------------------ |
| 1736 | |
| 1737 | #Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, |
| 1738 | int srcY) const |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1739 | #In Writer |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1740 | |
| 1741 | Copies a Rect of pixels to dstPixels. Copy starts at (srcX, srcY), and does not |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1742 | exceed Pixmap (width(), height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1743 | |
| 1744 | dstInfo specifies width, height, Color_Type, Alpha_Type, and |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1745 | Color_Space of destination. dstRowBytes specifics the gap from one destination |
| 1746 | row to the next. Returns true if pixels are copied. Returns false if |
| 1747 | dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes. |
| 1748 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1749 | Pixels are copied only if pixel conversion is possible. If Pixmap colorType is |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1750 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match. |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1751 | If Pixmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match. |
| 1752 | If Pixmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must |
| 1753 | match. If Pixmap colorSpace is nullptr, dstInfo.colorSpace must match. Returns |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1754 | false if pixel conversion is not possible. |
| 1755 | |
| 1756 | srcX and srcY may be negative to copy only top or left of source. Returns |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1757 | false if Pixmap width() or height() is zero or negative. Returns false if: |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1758 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1759 | #Formula |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1760 | abs(srcX) >= Pixmap width() |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1761 | ## |
| 1762 | , or if |
| 1763 | #Formula |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1764 | abs(srcY) >= Pixmap height() |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1765 | ## |
| 1766 | . |
| 1767 | |
| 1768 | #Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ## |
| 1769 | #Param dstPixels destination pixel storage ## |
| 1770 | #Param dstRowBytes destination row length ## |
| 1771 | #Param srcX column index whose absolute value is less than width() ## |
| 1772 | #Param srcY row index whose absolute value is less than height() ## |
| 1773 | |
| 1774 | #Return true if pixels are copied to dstPixels ## |
| 1775 | |
| 1776 | #Example |
| 1777 | #Image 3 |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1778 | void draw(SkCanvas* canvas) { |
| 1779 | SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height()); |
| 1780 | std::vector<int32_t> srcPixels; |
| 1781 | const int rowBytes = image->width() * 4; |
| 1782 | srcPixels.resize(image->height() * rowBytes); |
| 1783 | SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes); |
| 1784 | image->readPixels(pixmap, 0, 0); |
| 1785 | for (int offset : { 32, 64, 96 } ) { |
| 1786 | std::vector<int32_t> dstPixels; |
| 1787 | dstPixels.resize(image->height() * rowBytes); |
| 1788 | pixmap.readPixels(info, &dstPixels.front(), rowBytes, offset, 0); |
| 1789 | SkBitmap bitmap; |
| 1790 | SkPixmap dstmap(info, &dstPixels.front(), rowBytes); |
| 1791 | bitmap.installPixels(dstmap); |
| 1792 | canvas->translate(32, 32); |
| 1793 | canvas->drawBitmap(bitmap, 0, 0); |
| 1794 | } |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1795 | } |
| 1796 | ## |
| 1797 | |
| 1798 | #SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels |
| 1799 | |
| 1800 | ## |
| 1801 | |
| 1802 | # ------------------------------------------------------------------------------ |
| 1803 | |
| 1804 | #Method bool readPixels(const SkPixmap& dst, int srcX, int srcY) const |
| 1805 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1806 | #In Writer |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1807 | Copies a Rect of pixels to dst. Copy starts at (srcX, srcY), and does not |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1808 | exceed Pixmap (width(), height()). dst specifies width, height, Color_Type, |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1809 | Alpha_Type, and Color_Space of destination. Returns true if pixels are copied. |
| 1810 | Returns false if dst.addr() equals nullptr, or dst.rowBytes is less than |
| 1811 | dst SkImageInfo::minRowBytes. |
| 1812 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1813 | Pixels are copied only if pixel conversion is possible. If Pixmap colorType is |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1814 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.info().colorType must match. |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1815 | If Pixmap colorType is kGray_8_SkColorType, dst.info().colorSpace must match. |
| 1816 | If Pixmap alphaType is kOpaque_SkAlphaType, dst.info().alphaType must |
| 1817 | match. If Pixmap colorSpace is nullptr, dst.info().colorSpace must match. Returns |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1818 | false if pixel conversion is not possible. |
| 1819 | |
| 1820 | srcX and srcY may be negative to copy only top or left of source. Returns |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1821 | false Pixmap width() or height() is zero or negative. Returns false if: |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1822 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1823 | #Formula |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1824 | abs(srcX) >= Pixmap width() |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1825 | ## |
| 1826 | , or if |
| 1827 | #Formula |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1828 | abs(srcY) >= Pixmap height() |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1829 | ## |
| 1830 | . |
| 1831 | |
| 1832 | #Param dst Image_Info and pixel address to write to ## |
| 1833 | #Param srcX column index whose absolute value is less than width() ## |
| 1834 | #Param srcY row index whose absolute value is less than height() ## |
| 1835 | |
| 1836 | #Return true if pixels are copied to dst ## |
| 1837 | |
| 1838 | #Example |
| 1839 | #Image 3 |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1840 | void draw(SkCanvas* canvas) { |
| 1841 | SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height()); |
| 1842 | std::vector<int32_t> srcPixels; |
| 1843 | const int rowBytes = image->width() * 4; |
| 1844 | srcPixels.resize(image->height() * rowBytes); |
| 1845 | SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes); |
| 1846 | image->readPixels(pixmap, 0, 0); |
| 1847 | for (int offset : { 32, 64, 96 } ) { |
| 1848 | std::vector<int32_t> dstPixels; |
| 1849 | dstPixels.resize(image->height() * rowBytes); |
| 1850 | SkPixmap dstmap(info, &dstPixels.front(), rowBytes); |
| 1851 | pixmap.readPixels(dstmap, offset, 0); |
| 1852 | SkBitmap bitmap; |
| 1853 | bitmap.installPixels(dstmap); |
| 1854 | canvas->translate(32, 32); |
| 1855 | canvas->drawBitmap(bitmap, 0, 0); |
| 1856 | } |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1857 | } |
| 1858 | ## |
| 1859 | |
| 1860 | #SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels |
| 1861 | |
| 1862 | ## |
| 1863 | |
| 1864 | # ------------------------------------------------------------------------------ |
| 1865 | |
| 1866 | #Method bool readPixels(const SkPixmap& dst) const |
| 1867 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1868 | #In Writer |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1869 | Copies pixels inside bounds() to dst. dst specifies width, height, Color_Type, |
| 1870 | Alpha_Type, and Color_Space of destination. Returns true if pixels are copied. |
| 1871 | Returns false if dst.addr() equals nullptr, or dst.rowBytes is less than |
| 1872 | dst SkImageInfo::minRowBytes. |
| 1873 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1874 | Pixels are copied only if pixel conversion is possible. If Pixmap colorType is |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1875 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match. |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1876 | If Pixmap colorType is kGray_8_SkColorType, dst Color_Space must match. |
| 1877 | If Pixmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must |
| 1878 | match. If Pixmap colorSpace is nullptr, dst Color_Space must match. Returns |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1879 | false if pixel conversion is not possible. |
| 1880 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1881 | Returns false if Pixmap width() or height() is zero or negative. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1882 | |
| 1883 | #Param dst Image_Info and pixel address to write to ## |
| 1884 | |
| 1885 | #Return true if pixels are copied to dst ## |
| 1886 | |
| 1887 | #Example |
| 1888 | #Image 3 |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1889 | void draw(SkCanvas* canvas) { |
| 1890 | SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height()); |
| 1891 | std::vector<int32_t> srcPixels; |
| 1892 | const int rowBytes = image->width() * 4; |
| 1893 | srcPixels.resize(image->height() * rowBytes); |
| 1894 | SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes); |
| 1895 | image->readPixels(pixmap, 0, 0); |
| 1896 | for (int index = 0; index < 3; ++index ) { |
| 1897 | std::vector<int32_t> dstPixels; |
| 1898 | dstPixels.resize(image->height() * rowBytes); |
| 1899 | SkPixmap dstmap(info, &dstPixels.front(), rowBytes); |
| 1900 | pixmap.readPixels(dstmap); |
| 1901 | SkBitmap bitmap; |
| 1902 | bitmap.installPixels(dstmap); |
| 1903 | canvas->translate(32, 32); |
| 1904 | canvas->drawBitmap(bitmap, 0, 0); |
| 1905 | } |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1906 | } |
| 1907 | ## |
| 1908 | |
| 1909 | #SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels |
| 1910 | |
| 1911 | ## |
| 1912 | |
| 1913 | # ------------------------------------------------------------------------------ |
| 1914 | |
| 1915 | #Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality) const |
| 1916 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1917 | #In Writer |
| 1918 | #Line # scales and converts pixels ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1919 | Copies Bitmap to dst, scaling pixels to fit dst.width() and dst.height(), and |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1920 | converting pixels to match dst.colorType and dst.alphaType. Returns true if |
| 1921 | pixels are copied. Returns false if dst.addr() is nullptr, or dst.rowBytes is |
| 1922 | less than dst SkImageInfo::minRowBytes. |
| 1923 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1924 | Pixels are copied only if pixel conversion is possible. If Pixmap colorType is |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1925 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match. |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1926 | If Pixmap colorType is kGray_8_SkColorType, dst Color_Space must match. |
| 1927 | If Pixmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must |
| 1928 | match. If Pixmap colorSpace is nullptr, dst Color_Space must match. Returns |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1929 | false if pixel conversion is not possible. |
| 1930 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1931 | Returns false if Bitmap width() or height() is zero or negative. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1932 | |
| 1933 | Scales the image, with filterQuality, to match dst.width() and dst.height(). |
| 1934 | filterQuality kNone_SkFilterQuality is fastest, typically implemented with |
| 1935 | Filter_Quality_Nearest_Neighbor. kLow_SkFilterQuality is typically implemented with |
| 1936 | Filter_Quality_Bilerp. kMedium_SkFilterQuality is typically implemented with |
| 1937 | Filter_Quality_Bilerp, and Filter_Quality_MipMap when size is reduced. |
| 1938 | kHigh_SkFilterQuality is slowest, typically implemented with Filter_Quality_BiCubic. |
| 1939 | |
| 1940 | #Param dst Image_Info and pixel address to write to ## |
| 1941 | #Param filterQuality one of: kNone_SkFilterQuality, kLow_SkFilterQuality, |
| 1942 | kMedium_SkFilterQuality, kHigh_SkFilterQuality |
| 1943 | ## |
| 1944 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1945 | #Return true if pixels are scaled to fit dst ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1946 | |
| 1947 | #Example |
| 1948 | #Image 3 |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1949 | void draw(SkCanvas* canvas) { |
| 1950 | SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height()); |
| 1951 | std::vector<int32_t> srcPixels; |
| 1952 | int rowBytes = image->width() * 4; |
| 1953 | srcPixels.resize(image->height() * rowBytes); |
| 1954 | SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes); |
| 1955 | image->readPixels(pixmap, 0, 0); |
| 1956 | for (int offset : { 32, 64, 96 } ) { |
| 1957 | info = SkImageInfo::MakeN32Premul(image->width() + offset, image->height()); |
| 1958 | rowBytes = info.width() * 4; |
| 1959 | std::vector<int32_t> dstPixels; |
| 1960 | dstPixels.resize(image->height() * rowBytes); |
| 1961 | SkPixmap dstmap(info, &dstPixels.front(), rowBytes); |
| 1962 | pixmap.scalePixels(dstmap, kMedium_SkFilterQuality); |
| 1963 | SkBitmap bitmap; |
| 1964 | bitmap.installPixels(dstmap); |
| 1965 | canvas->translate(32, 32); |
| 1966 | canvas->drawBitmap(bitmap, 0, 0); |
| 1967 | } |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1968 | } |
| 1969 | ## |
| 1970 | |
| 1971 | #SeeAlso SkCanvas::drawBitmap SkImage::scalePixels |
| 1972 | |
| 1973 | ## |
| 1974 | |
| 1975 | # ------------------------------------------------------------------------------ |
| 1976 | |
| 1977 | #Method bool erase(SkColor color, const SkIRect& subset) const |
| 1978 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1979 | #In Writer |
| 1980 | #Line # writes Color to pixels ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1981 | Writes color to pixels bounded by subset; returns true on success. |
| 1982 | Returns false if colorType is kUnknown_SkColorType, or if subset does |
| 1983 | not intersect bounds(). |
| 1984 | |
| 1985 | #Param color Unpremultiplied Color to write ## |
| 1986 | #Param subset bounding integer Rect of written pixels ## |
| 1987 | |
| 1988 | #Return true if pixels are changed ## |
| 1989 | |
| 1990 | #Example |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1991 | #Height 50 |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1992 | uint32_t storage[2]; |
| 1993 | SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2); |
| 1994 | SkPixmap pixmap(info, storage, info.minRowBytes()); |
| 1995 | pixmap.erase(SK_ColorBLUE, {0, 0, 1, 1}); |
| 1996 | pixmap.erase(SK_ColorRED, {0, 1, 1, 2}); |
| 1997 | SkBitmap bitmap; |
| 1998 | canvas->scale(20, 20); |
| 1999 | bitmap.installPixels(pixmap); |
| 2000 | canvas->drawBitmap(bitmap, 0, 0); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 2001 | ## |
| 2002 | |
| 2003 | #SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor |
| 2004 | |
| 2005 | ## |
| 2006 | |
| 2007 | # ------------------------------------------------------------------------------ |
| 2008 | |
| 2009 | #Method bool erase(SkColor color) const |
| 2010 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2011 | #In Writer |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 2012 | Writes color to pixels inside bounds(); returns true on success. |
| 2013 | Returns false if colorType is kUnknown_SkColorType, or if bounds() |
| 2014 | is empty. |
| 2015 | |
| 2016 | #Param color Unpremultiplied Color to write ## |
| 2017 | |
| 2018 | #Return true if pixels are changed ## |
| 2019 | |
| 2020 | #Example |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2021 | #Height 50 |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 2022 | uint32_t storage[2]; |
| 2023 | SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2); |
| 2024 | SkPixmap pixmap(info, storage, info.minRowBytes()); |
| 2025 | pixmap.erase(SK_ColorBLUE); |
| 2026 | SkBitmap bitmap; |
| 2027 | canvas->scale(20, 20); |
| 2028 | bitmap.installPixels(pixmap); |
| 2029 | canvas->drawBitmap(bitmap, 0, 0); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 2030 | ## |
| 2031 | |
| 2032 | #SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor |
| 2033 | |
| 2034 | ## |
| 2035 | |
| 2036 | # ------------------------------------------------------------------------------ |
| 2037 | |
| 2038 | #Method bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const |
| 2039 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2040 | #In Writer |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 2041 | Writes color to pixels bounded by subset; returns true on success. |
| 2042 | if subset is nullptr, writes colors pixels inside bounds(). Returns false if |
| 2043 | colorType is kUnknown_SkColorType, if subset is not nullptr and does |
| 2044 | not intersect bounds(), or if subset is nullptr and bounds() is empty. |
| 2045 | |
| 2046 | #Param color Unpremultiplied Color to write ## |
| 2047 | #Param subset bounding integer Rect of pixels to write; may be nullptr ## |
| 2048 | |
| 2049 | #Return true if pixels are changed ## |
| 2050 | |
| 2051 | #Example |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2052 | #Height 50 |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 2053 | uint32_t storage[2]; |
| 2054 | SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2); |
| 2055 | SkPixmap pixmap(info, storage, info.minRowBytes()); |
| 2056 | SkIRect topPixelBounds = {0, 0, 1, 1}; |
| 2057 | pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds); |
| 2058 | SkIRect bottomPixelBounds = {0, 1, 1, 2}; |
| 2059 | pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds); |
| 2060 | SkBitmap bitmap; |
| 2061 | canvas->scale(20, 20); |
| 2062 | bitmap.installPixels(pixmap); |
| 2063 | canvas->drawBitmap(bitmap, 0, 0); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 2064 | ## |
| 2065 | |
| 2066 | #SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor |
| 2067 | |
| 2068 | ## |
| 2069 | |
| 2070 | |
| 2071 | #Subtopic Writer ## |
| 2072 | |
| 2073 | #Class SkPixmap ## |
| 2074 | |
| 2075 | #Topic Pixmap ## |