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