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 | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 470 | Returns Alpha_Type, one of: #list_of_alpha_types#. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 471 | |
| 472 | #Return Alpha_Type in Image_Info ## |
| 473 | |
| 474 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 475 | const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; |
| 476 | SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64); |
| 477 | SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[pixmap.alphaType()]); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 478 | #StdOut |
| 479 | alpha type: kPremul_SkAlphaType |
| 480 | ## |
| 481 | ## |
| 482 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 483 | #SeeAlso colorType() SkImageInfo::alphaType |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 484 | |
| 485 | ## |
| 486 | |
| 487 | # ------------------------------------------------------------------------------ |
| 488 | |
| 489 | #Method SkColorSpace* colorSpace() const |
| 490 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 491 | #In Image_Info_Access |
| 492 | #Line # returns Image_Info Color_Space ## |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 493 | Returns Color_Space, the range of colors, associated with Image_Info. The |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 494 | reference count of Color_Space is unchanged. The returned Color_Space is |
| 495 | immutable. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 496 | |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 497 | #Return Color_Space in Image_Info, or nullptr ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 498 | |
| 499 | #Example |
| 500 | #Description |
| 501 | SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma |
| 502 | and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma. |
| 503 | ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 504 | SkPixmap pixmap(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType, |
| 505 | SkColorSpace::MakeSRGBLinear()), nullptr, 64); |
| 506 | SkColorSpace* colorSpace = pixmap.colorSpace(); |
| 507 | SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n", |
| 508 | colorSpace->gammaCloseToSRGB() ? "true" : "false", |
| 509 | colorSpace->gammaIsLinear() ? "true" : "false", |
| 510 | colorSpace->isSRGB() ? "true" : "false"); |
| 511 | #StdOut |
| 512 | gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false |
| 513 | ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 514 | ## |
| 515 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 516 | #SeeAlso Color_Space SkImageInfo::colorSpace |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 517 | |
| 518 | ## |
| 519 | |
| 520 | # ------------------------------------------------------------------------------ |
| 521 | |
| 522 | #Method bool isOpaque() const |
| 523 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 524 | #In Image_Info_Access |
| 525 | #Line # returns true if Image_Info describes opaque pixels ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 526 | Returns true if Alpha_Type is kOpaque_SkAlphaType. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 527 | Does not check if Color_Type allows Alpha, or if any pixel value has |
| 528 | transparency. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 529 | |
| 530 | #Return true if Image_Info has opaque Alpha_Type ## |
| 531 | |
| 532 | #Example |
| 533 | #Description |
| 534 | isOpaque ignores whether all pixels are opaque or not. |
| 535 | ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 536 | std::vector<uint32_t> pixels; |
| 537 | const int height = 2; |
| 538 | const int width = 2; |
| 539 | pixels.resize(height * width * 4); |
| 540 | SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType, |
| 541 | kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4); |
| 542 | for (int index = 0; index < 2; ++index) { |
| 543 | pixmap.erase(0x00000000); |
| 544 | SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false"); |
| 545 | pixmap.erase(0xFFFFFFFF); |
| 546 | SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false"); |
| 547 | pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType), |
| 548 | (const void*) &pixels.front(), width * 4); |
| 549 | } |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 550 | #StdOut |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 551 | isOpaque: false |
| 552 | isOpaque: false |
| 553 | isOpaque: true |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 554 | isOpaque: true |
| 555 | ## |
| 556 | ## |
| 557 | |
| 558 | #SeeAlso computeIsOpaque SkImageInfo::isOpaque |
| 559 | |
| 560 | ## |
| 561 | |
| 562 | # ------------------------------------------------------------------------------ |
| 563 | |
| 564 | #Method SkIRect bounds() const |
| 565 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 566 | #In Image_Info_Access |
| 567 | #Line # returns width and height as Rectangle ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 568 | Returns IRect { 0, 0, width(), height() }. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 569 | |
| 570 | #Return integral rectangle from origin to width() and height() ## |
| 571 | |
| 572 | #Example |
| 573 | for (int width : { 0, 2 } ) { |
| 574 | for (int height : { 0, 2 } ) { |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 575 | SkPixmap pixmap(SkImageInfo::MakeA8(width, height), nullptr, width); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 576 | SkDebugf("width: %d height: %d empty: %s\n", width, height, |
| 577 | pixmap.bounds().isEmpty() ? "true" : "false"); |
| 578 | } |
| 579 | } |
| 580 | #StdOut |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 581 | width: 0 height: 0 empty: true |
| 582 | width: 0 height: 2 empty: true |
| 583 | width: 2 height: 0 empty: true |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 584 | width: 2 height: 2 empty: false |
| 585 | ## |
| 586 | ## |
| 587 | |
| 588 | #SeeAlso height() width() IRect |
| 589 | |
| 590 | ## |
| 591 | |
| 592 | # ------------------------------------------------------------------------------ |
| 593 | |
| 594 | #Method int rowBytesAsPixels() const |
| 595 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 596 | #In Image_Info_Access |
| 597 | #Line # returns interval between rows in pixels ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 598 | |
| 599 | Returns number of pixels that fit on row. Should be greater than or equal to |
| 600 | width(). |
| 601 | |
| 602 | #Return maximum pixels per row ## |
| 603 | |
| 604 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 605 | for (int rowBytes : { 4, 5, 6, 7, 8} ) { |
| 606 | SkPixmap pixmap(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), nullptr, rowBytes); |
| 607 | SkDebugf("rowBytes: %d rowBytesAsPixels: %d\n", rowBytes, pixmap.rowBytesAsPixels()); |
| 608 | } |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 609 | #StdOut |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 610 | rowBytes: 4 rowBytesAsPixels: 1 |
| 611 | rowBytes: 5 rowBytesAsPixels: 1 |
| 612 | rowBytes: 6 rowBytesAsPixels: 1 |
| 613 | rowBytes: 7 rowBytesAsPixels: 1 |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 614 | rowBytes: 8 rowBytesAsPixels: 2 |
| 615 | ## |
| 616 | ## |
| 617 | |
| 618 | #SeeAlso rowBytes shiftPerPixel width SkImageInfo::bytesPerPixel |
| 619 | |
| 620 | ## |
| 621 | |
| 622 | # ------------------------------------------------------------------------------ |
| 623 | |
| 624 | #Method int shiftPerPixel() const |
| 625 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 626 | #In Image_Info_Access |
| 627 | #Line # returns bit shift from pixels to bytes ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 628 | Returns bit shift converting row bytes to row pixels. |
| 629 | Returns zero for kUnknown_SkColorType. |
| 630 | |
| 631 | #Return one of: 0, 1, 2, 3; left shift to convert pixels to bytes ## |
| 632 | |
| 633 | #Example |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 634 | const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", |
| 635 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"}; |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 636 | SkImageInfo info = SkImageInfo::MakeA8(1, 1); |
| 637 | for (SkColorType colorType : { kUnknown_SkColorType, kAlpha_8_SkColorType, |
| 638 | kRGB_565_SkColorType, kARGB_4444_SkColorType, |
| 639 | kRGBA_8888_SkColorType, kBGRA_8888_SkColorType, |
| 640 | kGray_8_SkColorType, kRGBA_F16_SkColorType } ) { |
| 641 | SkPixmap pixmap(info.makeColorType(colorType), nullptr, 4); |
| 642 | SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d shiftPerPixel: %d\n", |
| 643 | colors[colorType], 10 - strlen(colors[colorType]), " ", |
| 644 | pixmap.info().bytesPerPixel(), pixmap.shiftPerPixel()); |
| 645 | } |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 646 | #StdOut |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 647 | color: kUnknown_SkColorType bytesPerPixel: 0 shiftPerPixel: 0 |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 648 | color: kAlpha_8_SkColorType bytesPerPixel: 1 shiftPerPixel: 0 |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 649 | color: kRGB_565_SkColorType bytesPerPixel: 2 shiftPerPixel: 1 |
| 650 | color: kARGB_4444_SkColorType bytesPerPixel: 2 shiftPerPixel: 1 |
| 651 | color: kRGBA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2 |
| 652 | color: kBGRA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2 |
| 653 | color: kGray_8_SkColorType bytesPerPixel: 1 shiftPerPixel: 0 |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 654 | color: kRGBA_F16_SkColorType bytesPerPixel: 8 shiftPerPixel: 3 |
| 655 | ## |
| 656 | ## |
| 657 | |
| 658 | #SeeAlso rowBytes rowBytesAsPixels width SkImageInfo::bytesPerPixel |
| 659 | |
| 660 | ## |
| 661 | |
| 662 | # ------------------------------------------------------------------------------ |
| 663 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 664 | #Method size_t computeByteSize() const |
| 665 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 666 | #In Image_Info_Access |
| 667 | #Line # returns size required for pixels ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 668 | Returns minimum memory required for pixel storage. |
| 669 | Does not include unused memory on last row when rowBytesAsPixels exceeds width(). |
| 670 | Returns zero if result does not fit in size_t. |
| 671 | Returns zero if height() or width() is 0. |
| 672 | Returns height() times rowBytes if colorType is kUnknown_SkColorType. |
| 673 | |
| 674 | #Return size in bytes of image buffer ## |
| 675 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 676 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 677 | SkPixmap pixmap; |
| 678 | for (int width : { 1, 1000, 1000000 } ) { |
| 679 | for (int height: { 1, 1000, 1000000 } ) { |
| 680 | SkImageInfo imageInfo = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 681 | pixmap.reset(imageInfo, nullptr, width * 5); |
| 682 | SkDebugf("width: %7d height: %7d computeByteSize: %13lld\n", width, height, |
| 683 | pixmap.computeByteSize()); |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 684 | } |
| 685 | } |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 686 | #StdOut |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 687 | width: 1 height: 1 computeByteSize: 4 |
| 688 | width: 1 height: 1000 computeByteSize: 4999 |
| 689 | width: 1 height: 1000000 computeByteSize: 4999999 |
| 690 | width: 1000 height: 1 computeByteSize: 4000 |
| 691 | width: 1000 height: 1000 computeByteSize: 4999000 |
| 692 | width: 1000 height: 1000000 computeByteSize: 4999999000 |
| 693 | width: 1000000 height: 1 computeByteSize: 4000000 |
| 694 | width: 1000000 height: 1000 computeByteSize: 4999000000 |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 695 | width: 1000000 height: 1000000 computeByteSize: 4999999000000 |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 696 | ## |
| 697 | ## |
| 698 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 699 | #SeeAlso SkImageInfo::computeByteSize |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 700 | |
| 701 | ## |
| 702 | |
| 703 | #Subtopic Image_Info_Access ## |
| 704 | |
| 705 | #Subtopic Reader |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 706 | #Line # examine pixel value ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 707 | |
| 708 | # ------------------------------------------------------------------------------ |
| 709 | |
| 710 | #Method bool computeIsOpaque() const |
| 711 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 712 | #In Reader |
| 713 | #Line # returns true if all pixels are opaque ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 714 | Returns true if all pixels are opaque. Color_Type determines how pixels |
| 715 | are encoded, and whether pixel describes Alpha. Returns true for Color_Types |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 716 | 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] | 717 | pixels have alpha values equivalent to 1.0 or greater. |
| 718 | |
| 719 | For Color_Types kRGB_565_SkColorType or kGray_8_SkColorType: always |
| 720 | returns true. For Color_Types kAlpha_8_SkColorType, kBGRA_8888_SkColorType, |
| 721 | kRGBA_8888_SkColorType: returns true if all pixel Alpha values are 255. |
| 722 | For Color_Type kARGB_4444_SkColorType: returns true if all pixel Alpha values are 15. |
| 723 | For kRGBA_F16_SkColorType: returns true if all pixel Alpha values are 1.0 or |
| 724 | greater. |
| 725 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 726 | Returns false for kUnknown_SkColorType. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 727 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 728 | #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] | 729 | |
| 730 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 731 | std::vector<uint32_t> pixels; |
| 732 | const int height = 2; |
| 733 | const int width = 2; |
| 734 | pixels.resize(height * width * 4); |
| 735 | SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType, |
| 736 | kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4); |
| 737 | for (int index = 0; index < 2; ++index) { |
| 738 | pixmap.erase(0x00000000); |
| 739 | SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false"); |
| 740 | pixmap.erase(0xFFFFFFFF); |
| 741 | SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false"); |
| 742 | pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType), |
| 743 | (const void*) &pixels.front(), width * 4); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 744 | } |
| 745 | #StdOut |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 746 | computeIsOpaque: false |
| 747 | computeIsOpaque: true |
| 748 | computeIsOpaque: false |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 749 | computeIsOpaque: true |
| 750 | ## |
| 751 | ## |
| 752 | |
| 753 | #SeeAlso isOpaque Color_Type Alpha |
| 754 | |
| 755 | ## |
| 756 | |
| 757 | # ------------------------------------------------------------------------------ |
| 758 | |
| 759 | #Method SkColor getColor(int x, int y) const |
| 760 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 761 | #In Reader |
| 762 | #Line # returns one pixel as Unpremultiplied Color ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 763 | Returns pixel at (x, y) as Unpremultiplied Color. |
| 764 | Returns black with Alpha if Color_Type is kAlpha_8_SkColorType. |
| 765 | |
| 766 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 767 | built with SK_DEBUG defined; and returns undefined values or may crash if |
| 768 | SK_RELEASE is defined. Fails if Color_Type is kUnknown_SkColorType or |
| 769 | pixel address is nullptr. |
| 770 | |
| 771 | Color_Space in Image_Info is ignored. Some Color precision may be lost in the |
| 772 | conversion to Unpremultiplied Color; original pixel data may have additional |
| 773 | precision. |
| 774 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 775 | #Param x column index, zero or greater, and less than width() ## |
| 776 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 777 | |
| 778 | #Return pixel converted to Unpremultiplied Color ## |
| 779 | |
| 780 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 781 | const int w = 4; |
| 782 | const int h = 4; |
| 783 | std::vector<SkPMColor> storage; |
| 784 | storage.resize(w * h); |
| 785 | SkDebugf("Premultiplied:\n"); |
| 786 | for (int y = 0; y < h; ++y) { |
| 787 | SkDebugf("(0, %d) ", y); |
| 788 | for (int x = 0; x < w; ++x) { |
| 789 | int a = 0xFF * (x + y) / (w - 1 + h - 1); |
| 790 | storage[x + y * w] = SkPackARGB32(a, a * x / (w - 1), a * y / (h - 1), a); |
| 791 | SkDebugf("0x%08x%c", storage[x + y * w], x == w - 1 ? '\n' : ' '); |
| 792 | } |
| 793 | } |
| 794 | SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4); |
| 795 | SkDebugf("Unpremultiplied:\n"); |
| 796 | for (int y = 0; y < h; ++y) { |
| 797 | SkDebugf("(0, %d) ", y); |
| 798 | for (int x = 0; x < w; ++x) { |
| 799 | SkDebugf("0x%08x%c", pixmap.getColor(x, y), x == w - 1 ? '\n' : ' '); |
| 800 | } |
| 801 | } |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 802 | #StdOut |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 803 | Premultiplied: |
| 804 | (0, 0) 0x00000000 0x2a0e002a 0x55380055 0x7f7f007f |
| 805 | (0, 1) 0x2a000e2a 0x551c1c55 0x7f542a7f 0xaaaa38aa |
| 806 | (0, 2) 0x55003855 0x7f2a547f 0xaa7171aa 0xd4d48dd4 |
| 807 | (0, 3) 0x7f007f7f 0xaa38aaaa 0xd48dd4d4 0xffffffff |
| 808 | Unpremultiplied: |
| 809 | (0, 0) 0x00000000 0x2a5500ff 0x55a800ff 0x7fff00ff |
| 810 | (0, 1) 0x2a0055ff 0x555454ff 0x7fa954ff 0xaaff54ff |
| 811 | (0, 2) 0x5500a8ff 0x7f54a9ff 0xaaaaaaff 0xd4ffaaff |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 812 | (0, 3) 0x7f00ffff 0xaa54ffff 0xd4aaffff 0xffffffff |
| 813 | ## |
| 814 | ## |
| 815 | |
| 816 | #SeeAlso addr() readPixels |
| 817 | |
| 818 | ## |
| 819 | |
| 820 | #Subtopic Reader ## |
| 821 | |
| 822 | #Subtopic Readable_Address |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 823 | #Line # returns read only pixels ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 824 | |
| 825 | # ------------------------------------------------------------------------------ |
| 826 | |
| 827 | #Method const void* addr(int x, int y) const |
| 828 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 829 | #In Readable_Address |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 830 | 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] | 831 | |
| 832 | 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] | 833 | built with SK_DEBUG defined. Returns nullptr if Color_Type is kUnknown_SkColorType. |
| 834 | |
| 835 | Performs a lookup of pixel size; for better performance, call |
| 836 | one of: addr8, addr16, addr32, addr64, or addrF16. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 837 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 838 | #Param x column index, zero or greater, and less than width() ## |
| 839 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 840 | |
| 841 | #Return readable generic pointer to pixel ## |
| 842 | |
| 843 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 844 | const int w = 4; |
| 845 | const int h = 4; |
| 846 | std::vector<SkPMColor> storage; |
| 847 | storage.resize(w * h); |
| 848 | SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 849 | SkDebugf("pixmap.addr(1, 2) %c= &storage[1 + 2 * w]\n", |
| 850 | pixmap.addr(1, 2) == &storage[1 + 2 * w] ? '=' : '!'); |
| 851 | #StdOut |
| 852 | pixmap.addr(1, 2) == &storage[1 + 2 * w] |
| 853 | ## |
| 854 | ## |
| 855 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 856 | #SeeAlso addr8 addr16 addr32 addr64 addrF16 getColor writable_addr SkBitmap::getAddr |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 857 | |
| 858 | ## |
| 859 | |
| 860 | # ------------------------------------------------------------------------------ |
| 861 | |
| 862 | #Method const uint8_t* addr8() const |
| 863 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 864 | #In Readable_Address |
| 865 | #Line # returns readable pixel address as 8-bit pointer ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 866 | Returns readable base pixel address. Result is addressable as unsigned 8-bit bytes. |
| 867 | Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType or |
| 868 | kGray_8_SkColorType, and is built with SK_DEBUG defined. |
| 869 | |
| 870 | One byte corresponds to one pixel. |
| 871 | |
| 872 | #Return readable unsigned 8-bit pointer to pixels ## |
| 873 | |
| 874 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 875 | const int w = 4; |
| 876 | const int h = 4; |
| 877 | uint8_t storage[w * h]; |
| 878 | SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType), |
| 879 | storage, w * sizeof(storage[0])); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 880 | SkDebugf("pixmap.addr8() %c= storage\n", |
| 881 | pixmap.addr8() == storage ? '=' : '!'); |
| 882 | #StdOut |
| 883 | pixmap.addr8() == storage |
| 884 | ## |
| 885 | ## |
| 886 | |
| 887 | #SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8 |
| 888 | |
| 889 | ## |
| 890 | |
| 891 | # ------------------------------------------------------------------------------ |
| 892 | |
| 893 | #Method const uint16_t* addr16() const |
| 894 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 895 | #In Readable_Address |
| 896 | #Line # returns readable pixel address as 16-bit pointer ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 897 | Returns readable base pixel address. Result is addressable as unsigned 16-bit words. |
| 898 | Will trigger an assert() if Color_Type is not kRGB_565_SkColorType or |
| 899 | kARGB_4444_SkColorType, and is built with SK_DEBUG defined. |
| 900 | |
| 901 | One word corresponds to one pixel. |
| 902 | |
| 903 | #Return readable unsigned 16-bit pointer to pixels ## |
| 904 | |
| 905 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 906 | const int w = 4; |
| 907 | const int h = 4; |
| 908 | uint16_t storage[w * h]; |
| 909 | SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType), |
| 910 | storage, w * sizeof(storage[0])); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 911 | SkDebugf("pixmap.addr16() %c= storage\n", |
| 912 | pixmap.addr16() == storage ? '=' : '!'); |
| 913 | #StdOut |
| 914 | pixmap.addr16() == storage |
| 915 | ## |
| 916 | ## |
| 917 | |
| 918 | #SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16 |
| 919 | |
| 920 | ## |
| 921 | |
| 922 | # ------------------------------------------------------------------------------ |
| 923 | |
| 924 | #Method const uint32_t* addr32() const |
| 925 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 926 | #In Readable_Address |
| 927 | #Line # returns readable pixel address as 32-bit pointer ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 928 | Returns readable base pixel address. Result is addressable as unsigned 32-bit words. |
| 929 | Will trigger an assert() if Color_Type is not kRGBA_8888_SkColorType or |
| 930 | kBGRA_8888_SkColorType, and is built with SK_DEBUG defined. |
| 931 | |
| 932 | One word corresponds to one pixel. |
| 933 | |
| 934 | #Return readable unsigned 32-bit pointer to pixels ## |
| 935 | |
| 936 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 937 | const int w = 4; |
| 938 | const int h = 4; |
| 939 | uint32_t storage[w * h]; |
| 940 | SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), |
| 941 | storage, w * sizeof(storage[0])); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 942 | SkDebugf("pixmap.addr32() %c= storage\n", |
| 943 | pixmap.addr32() == storage ? '=' : '!'); |
| 944 | #StdOut |
| 945 | pixmap.addr32() == storage |
| 946 | ## |
| 947 | ## |
| 948 | |
| 949 | #SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr32 |
| 950 | |
| 951 | ## |
| 952 | |
| 953 | # ------------------------------------------------------------------------------ |
| 954 | |
| 955 | #Method const uint64_t* addr64() const |
| 956 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 957 | #In Readable_Address |
| 958 | #Line # returns readable pixel address as 64-bit pointer ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 959 | Returns readable base pixel address. Result is addressable as unsigned 64-bit words. |
| 960 | Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built |
| 961 | with SK_DEBUG defined. |
| 962 | |
| 963 | One word corresponds to one pixel. |
| 964 | |
| 965 | #Return readable unsigned 64-bit pointer to pixels ## |
| 966 | |
| 967 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 968 | const int w = 4; |
| 969 | const int h = 4; |
| 970 | uint64_t storage[w * h]; |
| 971 | SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType), |
| 972 | storage, w * sizeof(storage[0])); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 973 | SkDebugf("pixmap.addr64() %c= storage\n", |
| 974 | pixmap.addr64() == storage ? '=' : '!'); |
| 975 | #StdOut |
| 976 | pixmap.addr64() == storage |
| 977 | ## |
| 978 | ## |
| 979 | |
| 980 | #SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64 |
| 981 | |
| 982 | ## |
| 983 | |
| 984 | # ------------------------------------------------------------------------------ |
| 985 | |
| 986 | #Method const uint16_t* addrF16() const |
| 987 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 988 | #In Readable_Address |
| 989 | #Line # returns readable pixel component address as 16-bit pointer ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 990 | Returns readable base pixel address. Result is addressable as unsigned 16-bit words. |
| 991 | Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built |
| 992 | with SK_DEBUG defined. |
| 993 | |
| 994 | Each word represents one color component encoded as a half float. |
| 995 | Four words correspond to one pixel. |
| 996 | |
| 997 | #Return readable unsigned 16-bit pointer to first component of pixels ## |
| 998 | |
| 999 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1000 | const int w = 4; |
| 1001 | const int h = 4; |
| 1002 | uint16_t storage[w * h * 4]; |
| 1003 | SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType), |
| 1004 | storage, w * 4 * sizeof(storage[0])); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1005 | SkDebugf("pixmap.addrF16() %c= storage\n", |
| 1006 | pixmap.addrF16() == storage ? '=' : '!'); |
| 1007 | #StdOut |
| 1008 | pixmap.addrF16() == storage |
| 1009 | ## |
| 1010 | ## |
| 1011 | |
| 1012 | #SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16 |
| 1013 | |
| 1014 | ## |
| 1015 | |
| 1016 | # ------------------------------------------------------------------------------ |
| 1017 | |
| 1018 | #Method const uint8_t* addr8(int x, int y) const |
| 1019 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1020 | #In Readable_Address |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1021 | Returns readable pixel address at (x, y). |
| 1022 | |
| 1023 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 1024 | built with SK_DEBUG defined. |
| 1025 | |
| 1026 | Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType or |
| 1027 | kGray_8_SkColorType, and is built with SK_DEBUG defined. |
| 1028 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1029 | #Param x column index, zero or greater, and less than width() ## |
| 1030 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1031 | |
| 1032 | #Return readable unsigned 8-bit pointer to pixel at (x, y) ## |
| 1033 | |
| 1034 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1035 | const int w = 4; |
| 1036 | const int h = 4; |
| 1037 | uint8_t storage[w * h]; |
| 1038 | SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType), |
| 1039 | storage, w * sizeof(storage[0])); |
| 1040 | SkDebugf("pixmap.addr8(1, 2) %c= &storage[1 + 2 * w]\n", |
| 1041 | pixmap.addr8(1, 2) == &storage[1 + 2 * w] ? '=' : '!'); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1042 | #StdOut |
| 1043 | pixmap.addr8(1, 2) == &storage[1 + 2 * w] |
| 1044 | ## |
| 1045 | ## |
| 1046 | |
| 1047 | #SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8 |
| 1048 | |
| 1049 | ## |
| 1050 | |
| 1051 | # ------------------------------------------------------------------------------ |
| 1052 | |
| 1053 | #Method const uint16_t* addr16(int x, int y) const |
| 1054 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1055 | #In Readable_Address |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1056 | Returns readable pixel address at (x, y). |
| 1057 | |
| 1058 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 1059 | built with SK_DEBUG defined. |
| 1060 | |
| 1061 | Will trigger an assert() if Color_Type is not kRGB_565_SkColorType or |
| 1062 | kARGB_4444_SkColorType, and is built with SK_DEBUG defined. |
| 1063 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1064 | #Param x column index, zero or greater, and less than width() ## |
| 1065 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1066 | |
| 1067 | #Return readable unsigned 16-bit pointer to pixel at (x, y) ## |
| 1068 | |
| 1069 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1070 | const int w = 4; |
| 1071 | const int h = 4; |
| 1072 | uint16_t storage[w * h]; |
| 1073 | SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType), |
| 1074 | storage, w * sizeof(storage[0])); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1075 | SkDebugf("pixmap.addr16(1, 2) %c= &storage[1 + 2 * w]\n", |
| 1076 | pixmap.addr16(1, 2) == &storage[1 + 2 * w] ? '=' : '!'); |
| 1077 | #StdOut |
| 1078 | pixmap.addr16(1, 2) == &storage[1 + 2 * w] |
| 1079 | ## |
| 1080 | ## |
| 1081 | |
| 1082 | #SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16 |
| 1083 | |
| 1084 | ## |
| 1085 | |
| 1086 | # ------------------------------------------------------------------------------ |
| 1087 | |
| 1088 | #Method const uint32_t* addr32(int x, int y) const |
| 1089 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1090 | #In Readable_Address |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1091 | Returns readable pixel address at (x, y). |
| 1092 | |
| 1093 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 1094 | built with SK_DEBUG defined. |
| 1095 | |
| 1096 | Will trigger an assert() if Color_Type is not kRGBA_8888_SkColorType or |
| 1097 | kBGRA_8888_SkColorType, and is built with SK_DEBUG defined. |
| 1098 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1099 | #Param x column index, zero or greater, and less than width() ## |
| 1100 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1101 | |
| 1102 | #Return readable unsigned 32-bit pointer to pixel at (x, y) ## |
| 1103 | |
| 1104 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1105 | const int w = 4; |
| 1106 | const int h = 4; |
| 1107 | uint32_t storage[w * h]; |
| 1108 | SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_8888_SkColorType, kPremul_SkAlphaType), |
| 1109 | storage, w * sizeof(storage[0])); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1110 | SkDebugf("pixmap.addr32(1, 2) %c= &storage[1 + 2 * w]\n", |
| 1111 | pixmap.addr32(1, 2) == &storage[1 + 2 * w] ? '=' : '!'); |
| 1112 | #StdOut |
| 1113 | pixmap.addr32(1, 2) == &storage[1 + 2 * w] |
| 1114 | ## |
| 1115 | ## |
| 1116 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1117 | #SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr64 |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1118 | |
| 1119 | ## |
| 1120 | |
| 1121 | # ------------------------------------------------------------------------------ |
| 1122 | |
| 1123 | #Method const uint64_t* addr64(int x, int y) const |
| 1124 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1125 | #In Readable_Address |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1126 | Returns readable pixel address at (x, y). |
| 1127 | |
| 1128 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 1129 | built with SK_DEBUG defined. |
| 1130 | |
| 1131 | Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built |
| 1132 | with SK_DEBUG defined. |
| 1133 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1134 | #Param x column index, zero or greater, and less than width() ## |
| 1135 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1136 | |
| 1137 | #Return readable unsigned 64-bit pointer to pixel at (x, y) ## |
| 1138 | |
| 1139 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1140 | const int w = 4; |
| 1141 | const int h = 4; |
| 1142 | uint64_t storage[w * h]; |
| 1143 | SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType), |
| 1144 | storage, w * sizeof(storage[0])); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1145 | SkDebugf("pixmap.addr64(1, 2) %c= &storage[1 + 2 * w]\n", |
| 1146 | pixmap.addr64(1, 2) == &storage[1 + 2 * w] ? '=' : '!'); |
| 1147 | #StdOut |
| 1148 | pixmap.addr64(1, 2) == &storage[1 + 2 * w] |
| 1149 | ## |
| 1150 | ## |
| 1151 | |
| 1152 | #SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64 |
| 1153 | |
| 1154 | ## |
| 1155 | |
| 1156 | # ------------------------------------------------------------------------------ |
| 1157 | |
| 1158 | #Method const uint16_t* addrF16(int x, int y) const |
| 1159 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1160 | #In Readable_Address |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1161 | Returns readable pixel address at (x, y). |
| 1162 | |
| 1163 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 1164 | built with SK_DEBUG defined. |
| 1165 | |
| 1166 | Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built |
| 1167 | with SK_DEBUG defined. |
| 1168 | |
| 1169 | Each unsigned 16-bit word represents one color component encoded as a half float. |
| 1170 | Four words correspond to one pixel. |
| 1171 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1172 | #Param x column index, zero or greater, and less than width() ## |
| 1173 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1174 | |
| 1175 | #Return readable unsigned 16-bit pointer to pixel component at (x, y) ## |
| 1176 | |
| 1177 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1178 | const int w = 4; |
| 1179 | const int h = 4; |
| 1180 | const int wordsPerPixel = 4; |
| 1181 | const int rowWords = w * wordsPerPixel; |
| 1182 | uint16_t storage[rowWords * h]; |
| 1183 | SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType), |
| 1184 | storage, rowWords * sizeof(storage[0])); |
| 1185 | SkDebugf("pixmap.addrF16(1, 2) %c= &storage[1 * wordsPerPixel + 2 * rowWords]\n", |
| 1186 | pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords] ? '=' : '!'); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1187 | #StdOut |
| 1188 | pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords] |
| 1189 | ## |
| 1190 | ## |
| 1191 | |
| 1192 | #SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16 |
| 1193 | |
| 1194 | ## |
| 1195 | |
| 1196 | #Subtopic Readable_Address ## |
| 1197 | |
| 1198 | #Subtopic Writable_Address |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1199 | #Line # returns writable pixels ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1200 | |
| 1201 | # ------------------------------------------------------------------------------ |
| 1202 | |
| 1203 | #Method void* writable_addr() const |
| 1204 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1205 | #In Writable_Address |
| 1206 | #Line # returns writable pixel address as void pointer ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1207 | Returns writable base pixel address. |
| 1208 | |
| 1209 | #Return writable generic base pointer to pixels ## |
| 1210 | |
| 1211 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1212 | const int w = 4; |
| 1213 | const int h = 4; |
| 1214 | SkPMColor storage[w * h * 4]; |
| 1215 | SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4); |
| 1216 | SkDebugf("pixmap.writable_addr() %c= (void *)storage\n", |
| 1217 | pixmap.writable_addr() == (void *)storage ? '=' : '!'); |
| 1218 | pixmap.erase(0x00000000); |
| 1219 | *(SkPMColor*)pixmap.writable_addr() = 0xFFFFFFFF; |
| 1220 | SkDebugf("pixmap.getColor(0, 1) %c= 0x00000000\n", |
| 1221 | pixmap.getColor(0, 1) == 0x00000000 ? '=' : '!'); |
| 1222 | SkDebugf("pixmap.getColor(0, 0) %c= 0xFFFFFFFF\n", |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1223 | pixmap.getColor(0, 0) == 0xFFFFFFFF ? '=' : '!'); |
| 1224 | #StdOut |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1225 | pixmap.writable_addr() == (void *)storage |
| 1226 | pixmap.getColor(0, 1) == 0x00000000 |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1227 | pixmap.getColor(0, 0) == 0xFFFFFFFF |
| 1228 | ## |
| 1229 | ## |
| 1230 | |
| 1231 | #SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr() |
| 1232 | |
| 1233 | ## |
| 1234 | |
| 1235 | # ------------------------------------------------------------------------------ |
| 1236 | |
| 1237 | #Method void* writable_addr(int x, int y) const |
| 1238 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1239 | #In Writable_Address |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1240 | Returns writable pixel address at (x, y). |
| 1241 | |
| 1242 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 1243 | built with SK_DEBUG defined. Returns zero if Color_Type is kUnknown_SkColorType. |
| 1244 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1245 | #Param x column index, zero or greater, and less than width() ## |
| 1246 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1247 | |
| 1248 | #Return writable generic pointer to pixel ## |
| 1249 | |
| 1250 | #Example |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1251 | const int w = 4; |
| 1252 | const int h = 4; |
| 1253 | SkPMColor storage[w * h * 4]; |
| 1254 | SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4); |
| 1255 | SkDebugf("pixmap.writable_addr() %c= (void *)storage\n", |
| 1256 | pixmap.writable_addr() == (void *)storage ? '=' : '!'); |
| 1257 | pixmap.erase(0x00000000); |
| 1258 | *(SkPMColor*)pixmap.writable_addr(1, 2) = 0xFFFFFFFF; |
| 1259 | SkDebugf("pixmap.getColor(0, 0) %c= 0x00000000\n", |
| 1260 | pixmap.getColor(0, 0) == 0x00000000 ? '=' : '!'); |
| 1261 | SkDebugf("pixmap.getColor(1, 2) %c= 0xFFFFFFFF\n", |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1262 | pixmap.getColor(1, 2) == 0xFFFFFFFF ? '=' : '!'); |
| 1263 | #StdOut |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1264 | pixmap.writable_addr() == (void *)storage |
| 1265 | pixmap.getColor(0, 0) == 0x00000000 |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1266 | pixmap.getColor(1, 2) == 0xFFFFFFFF |
| 1267 | ## |
| 1268 | ## |
| 1269 | |
| 1270 | #SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr() |
| 1271 | |
| 1272 | ## |
| 1273 | |
| 1274 | # ------------------------------------------------------------------------------ |
| 1275 | |
| 1276 | #Method uint8_t* writable_addr8(int x, int y) const |
| 1277 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1278 | #In Writable_Address |
| 1279 | #Line # returns writable pixel address as 8-bit pointer ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1280 | Returns writable pixel address at (x, y). Result is addressable as unsigned |
| 1281 | 8-bit bytes. Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType |
| 1282 | or kGray_8_SkColorType, and is built with SK_DEBUG defined. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1283 | |
| 1284 | One byte corresponds to one pixel. |
| 1285 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1286 | #Param x column index, zero or greater, and less than width() ## |
| 1287 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1288 | |
| 1289 | #Return writable unsigned 8-bit pointer to pixels ## |
| 1290 | |
| 1291 | #Example |
| 1292 | #Height 64 |
| 1293 | #Description |
| 1294 | Altering pixels after drawing Bitmap is not guaranteed to affect subsequent |
| 1295 | drawing on all platforms. Adding a second SkBitmap::installPixels after editing |
| 1296 | pixel memory is safer. |
| 1297 | ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1298 | void draw(SkCanvas* canvas) { |
| 1299 | uint8_t storage[][5] = {{ 0, 0, 64, 0, 0}, |
| 1300 | { 0, 128, 255, 128, 0}, |
| 1301 | {64, 255, 255, 255, 64}, |
| 1302 | { 0, 128, 255, 128, 0}, |
| 1303 | { 0, 0, 64, 0, 0}}; |
| 1304 | SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kPremul_SkAlphaType); |
| 1305 | SkPixmap pixmap(imageInfo, storage[0], 5); |
| 1306 | SkBitmap bitmap; |
| 1307 | bitmap.installPixels(pixmap); |
| 1308 | canvas->scale(10, 10); |
| 1309 | canvas->drawBitmap(bitmap, 0, 0); |
| 1310 | *pixmap.writable_addr8(2, 2) = 0; |
| 1311 | // bitmap.installPixels(pixmap); // uncomment to fix on GPU |
| 1312 | canvas->drawBitmap(bitmap, 10, 0); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1313 | } |
| 1314 | ## |
| 1315 | |
| 1316 | #SeeAlso writable_addr writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr() addr8 |
| 1317 | |
| 1318 | ## |
| 1319 | |
| 1320 | # ------------------------------------------------------------------------------ |
| 1321 | |
| 1322 | #Method uint16_t* writable_addr16(int x, int y) const |
| 1323 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1324 | #In Writable_Address |
| 1325 | #Line # returns writable pixel address as 16-bit pointer ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1326 | Returns writable_addr pixel address at (x, y). Result is addressable as unsigned |
| 1327 | 16-bit words. Will trigger an assert() if Color_Type is not kRGB_565_SkColorType |
| 1328 | or kARGB_4444_SkColorType, and is built with SK_DEBUG defined. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1329 | |
| 1330 | One word corresponds to one pixel. |
| 1331 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1332 | #Param x column index, zero or greater, and less than width() ## |
| 1333 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1334 | |
| 1335 | #Return writable unsigned 16-bit pointer to pixel ## |
| 1336 | |
| 1337 | #Example |
| 1338 | #Description |
| 1339 | Draw a five by five bitmap, and draw it again with a center black pixel. |
| 1340 | The low nibble of the 16-bit word is Alpha. |
| 1341 | ## |
| 1342 | #Height 64 |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1343 | uint16_t storage[][5] = {{ 0xCABF, 0xDABE, 0xCA9D, 0xC96C, 0xA39B }, |
| 1344 | { 0xACEE, 0xA87C, 0x893A, 0x4779, 0x8708 }, |
| 1345 | { 0x4B7C, 0x255B, 0x2559, 0x2557, 0x4656 }, |
| 1346 | { 0x9099, 0x8128, 0x2557, 0x4124, 0x3323 }, |
| 1347 | { 0x7547, 0x5505, 0x4434, 0x2012, 0x0000 }}; |
| 1348 | SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kARGB_4444_SkColorType, kPremul_SkAlphaType); |
| 1349 | SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5); |
| 1350 | SkBitmap bitmap; |
| 1351 | bitmap.installPixels(pixmap); |
| 1352 | canvas->scale(10, 10); |
| 1353 | canvas->drawBitmap(bitmap, 0, 0); |
| 1354 | *pixmap.writable_addr16(2, 2) = 0x000F; |
| 1355 | bitmap.installPixels(pixmap); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1356 | canvas->drawBitmap(bitmap, 10, 0); |
| 1357 | ## |
| 1358 | |
| 1359 | #SeeAlso writable_addr writable_addr8 writable_addr32 writable_addr64 writable_addrF16 addr() addr16 |
| 1360 | |
| 1361 | ## |
| 1362 | |
| 1363 | # ------------------------------------------------------------------------------ |
| 1364 | |
| 1365 | #Method uint32_t* writable_addr32(int x, int y) const |
| 1366 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1367 | #In Writable_Address |
| 1368 | #Line # returns writable pixel address as 32-bit pointer ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1369 | Returns writable pixel address at (x, y). Result is addressable as unsigned |
| 1370 | 32-bit words. Will trigger an assert() if Color_Type is not |
| 1371 | kRGBA_8888_SkColorType or kBGRA_8888_SkColorType, and is built with SK_DEBUG |
| 1372 | defined. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1373 | |
| 1374 | One word corresponds to one pixel. |
| 1375 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1376 | #Param x column index, zero or greater, and less than width() ## |
| 1377 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1378 | |
| 1379 | #Return writable unsigned 32-bit pointer to pixel ## |
| 1380 | |
| 1381 | #Example |
| 1382 | #Image 4 |
| 1383 | #Height 72 |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1384 | std::vector<int32_t> pixels; |
| 1385 | pixels.resize(image->height() * image->width() * 4); |
| 1386 | SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType, |
| 1387 | image->alphaType()), (const void*) &pixels.front(), image->width() * 4); |
| 1388 | image->readPixels(pixmap, 0, 0); |
| 1389 | for (int y = 0; y < pixmap.height() / 2; ++y) { |
| 1390 | for (int x = 0; x < pixmap.width(); ++x) { |
| 1391 | if ((x & 4) == (y & 4)) { |
| 1392 | SkTSwap(*pixmap.writable_addr32(x, y), |
| 1393 | *pixmap.writable_addr32(pixmap.width() - x, pixmap.height() - y)); |
| 1394 | } |
| 1395 | } |
| 1396 | } |
| 1397 | SkBitmap bitmap; |
| 1398 | bitmap.installPixels(pixmap); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1399 | canvas->drawBitmap(bitmap, 0, 0); |
| 1400 | ## |
| 1401 | |
| 1402 | #SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr64 writable_addrF16 addr() addr32 |
| 1403 | |
| 1404 | ## |
| 1405 | |
| 1406 | # ------------------------------------------------------------------------------ |
| 1407 | |
| 1408 | #Method uint64_t* writable_addr64(int x, int y) const |
| 1409 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1410 | #In Writable_Address |
| 1411 | #Line # returns writable pixel address as 64-bit pointer ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1412 | Returns writable pixel address at (x, y). Result is addressable as unsigned |
| 1413 | 64-bit words. Will trigger an assert() if Color_Type is not |
| 1414 | kRGBA_F16_SkColorType and is built with SK_DEBUG defined. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1415 | |
| 1416 | One word corresponds to one pixel. |
| 1417 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1418 | #Param x column index, zero or greater, and less than width() ## |
| 1419 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1420 | |
| 1421 | #Return writable unsigned 64-bit pointer to pixel ## |
| 1422 | |
| 1423 | #Example |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1424 | #Height 40 |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1425 | SkImageInfo info = SkImageInfo::Make(3, 3, kRGBA_F16_SkColorType, kPremul_SkAlphaType); |
| 1426 | uint64_t storage[9]; |
| 1427 | SkPixmap pixmap(info, storage, 3 * sizeof(uint64_t)); |
| 1428 | SkColor4f c4 { 1, 0.45f, 0.25f, 0.65f }; |
| 1429 | pixmap.erase(c4); |
| 1430 | SkBitmap bitmap; |
| 1431 | canvas->scale(10, 10); |
| 1432 | bitmap.installPixels(pixmap); |
| 1433 | canvas->drawBitmap(bitmap, 0, 0); |
| 1434 | *pixmap.writable_addr64(1, 1) |= 0x00ff000000000000LL; |
| 1435 | bitmap.installPixels(pixmap); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1436 | canvas->drawBitmap(bitmap, 10, 0); |
| 1437 | ## |
| 1438 | |
| 1439 | #SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addrF16 addr() addr64 |
| 1440 | |
| 1441 | ## |
| 1442 | |
| 1443 | # ------------------------------------------------------------------------------ |
| 1444 | |
| 1445 | #Method uint16_t* writable_addrF16(int x, int y) const |
| 1446 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1447 | #In Writable_Address |
| 1448 | #Line # returns writable pixel component address as 16-bit pointer ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1449 | Returns writable pixel address at (x, y). Result is addressable as unsigned |
| 1450 | 16-bit words. Will trigger an assert() if Color_Type is not |
| 1451 | kRGBA_F16_SkColorType and is built with SK_DEBUG defined. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1452 | |
| 1453 | Each word represents one color component encoded as a half float. |
| 1454 | Four words correspond to one pixel. |
| 1455 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1456 | #Param x column index, zero or greater, and less than width() ## |
| 1457 | #Param y row index, zero or greater, and less than height() ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1458 | |
| 1459 | #Return writable unsigned 16-bit pointer to first component of pixel ## |
| 1460 | |
| 1461 | #Example |
| 1462 | #Height 64 |
| 1463 | #Description |
| 1464 | Left bitmap is drawn with two pixels defined in half float format. Right bitmap |
| 1465 | is drawn after overwriting bottom half float color with top half float color. |
| 1466 | ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1467 | SkImageInfo info = SkImageInfo::Make(1, 2, kRGBA_F16_SkColorType, kPremul_SkAlphaType); |
| 1468 | uint16_t storage[2][4]; |
| 1469 | SkPixmap pixmap(info, storage[0], sizeof(uint64_t)); |
| 1470 | SkIRect topPixelBounds = {0, 0, 1, 1}; |
| 1471 | pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds); |
| 1472 | SkIRect bottomPixelBounds = {0, 1, 1, 2}; |
| 1473 | pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds); |
| 1474 | SkBitmap bitmap; |
| 1475 | canvas->scale(20, 20); |
| 1476 | bitmap.installPixels(pixmap); |
| 1477 | canvas->drawBitmap(bitmap, 0, 0); |
| 1478 | uint16_t* pixel2 = pixmap.writable_addrF16(0, 1); |
| 1479 | for (int i = 0; i < 4; ++i) { |
| 1480 | pixel2[i] = storage[0][i]; |
| 1481 | } |
| 1482 | bitmap.installPixels(pixmap); |
| 1483 | canvas->drawBitmap(bitmap, 4, 0); |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1484 | ## |
| 1485 | |
| 1486 | #SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addr64 addr() addrF16 |
| 1487 | |
| 1488 | ## |
| 1489 | |
| 1490 | #Subtopic Writable_Address ## |
| 1491 | |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1492 | #Subtopic Pixels |
| 1493 | #Populate |
| 1494 | #Line # read and write pixel values ## |
| 1495 | ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1496 | |
| 1497 | # ------------------------------------------------------------------------------ |
| 1498 | |
| 1499 | #Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 1500 | int srcX, int srcY, SkTransferFunctionBehavior behavior) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1501 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1502 | #Line # copies and converts pixels ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1503 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1504 | 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] | 1505 | exceed Pixmap (width(), height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1506 | |
| 1507 | dstInfo specifies width, height, Color_Type, Alpha_Type, and |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1508 | Color_Space of destination. dstRowBytes specifics the gap from one destination |
| 1509 | row to the next. Returns true if pixels are copied. Returns false if |
| 1510 | dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes. |
| 1511 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1512 | 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] | 1513 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match. |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1514 | If Pixmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match. |
| 1515 | If Pixmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must |
| 1516 | match. If Pixmap colorSpace is nullptr, dstInfo.colorSpace must match. Returns |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1517 | false if pixel conversion is not possible. |
| 1518 | |
| 1519 | 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] | 1520 | false if width() or height() is zero or negative. Returns false if: |
| 1521 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1522 | #Formula |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1523 | abs(srcX) >= Pixmap width() |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1524 | ## |
| 1525 | , or if |
| 1526 | #Formula |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1527 | abs(srcY) >= Pixmap height() |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1528 | ## |
| 1529 | . |
| 1530 | |
| 1531 | If behavior is SkTransferFunctionBehavior::kRespect: converts source |
| 1532 | pixels to a linear space before converting to dstInfo. |
| 1533 | If behavior is SkTransferFunctionBehavior::kIgnore: source |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1534 | 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] | 1535 | |
| 1536 | #Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ## |
| 1537 | #Param dstPixels destination pixel storage ## |
| 1538 | #Param dstRowBytes destination row length ## |
| 1539 | #Param srcX column index whose absolute value is less than width() ## |
| 1540 | #Param srcY row index whose absolute value is less than height() ## |
| 1541 | #Param behavior one of: SkTransferFunctionBehavior::kRespect, |
| 1542 | SkTransferFunctionBehavior::kIgnore |
| 1543 | ## |
| 1544 | |
| 1545 | #Return true if pixels are copied to dstPixels ## |
| 1546 | |
| 1547 | #Example |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1548 | #ToDo example doesn't do anything interesting since image doesn't have alpha ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1549 | #Image 3 |
| 1550 | void draw(SkCanvas* canvas) { |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1551 | SkImageInfo srgb = SkImageInfo::MakeS32(image->width(), image->height(), |
| 1552 | kPremul_SkAlphaType); |
| 1553 | SkImageInfo linear = srgb.makeColorSpace(srgb.colorSpace()->makeLinearGamma()); |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1554 | std::vector<int32_t> srcPixels; |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1555 | size_t rowBytes = image->width() * 4; |
| 1556 | srcPixels.resize(image->height() * rowBytes); |
| 1557 | SkPixmap pixmap(srgb, (const void*) &srcPixels.front(), rowBytes); |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1558 | image->readPixels(pixmap, 0, 0); |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1559 | int offset = -64; |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1560 | std::vector<int32_t> dstPixels; |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1561 | dstPixels.resize(image->height() * rowBytes); |
| 1562 | for (const auto& info : { srgb, linear } ) { |
| 1563 | for (auto behavior : { SkTransferFunctionBehavior::kRespect, |
| 1564 | SkTransferFunctionBehavior::kIgnore} ) { |
| 1565 | pixmap.readPixels(info, &dstPixels.front(), rowBytes, 0, 0, behavior); |
| 1566 | SkBitmap bitmap; |
| 1567 | SkPixmap dstmap(info, &dstPixels.front(), rowBytes); |
| 1568 | bitmap.installPixels(dstmap); |
| 1569 | canvas->drawBitmap(bitmap, 0, offset += 64); |
| 1570 | } |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1571 | } |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 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 ## |