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