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