blob: 74881545d073b4442fc29a5c9d416a51f1952597 [file] [log] [blame]
Cary Clarkd0530ba2017-09-14 11:25:39 -04001#Topic Pixmap
Cary Clarke4aa3712017-09-15 02:56:12 -04002#Alias Pixmap_Reference
3
Cary Clarkd0530ba2017-09-14 11:25:39 -04004#Class SkPixmap
5
6Pixmap provides a utility to pair SkImageInfo with pixels and row bytes.
7Pixmap is a low level class which provides convenience functions to access
8raster destinations. Canvas can not draw Pixmap, nor does Pixmap provide
9a direct drawing destination.
10
11Use Bitmap to draw pixels referenced by Pixmap; use Surface to draw into
12pixels referenced by Pixmap.
13
Cary Clarkbc5697d2017-10-04 14:31:33 -040014Pixmap does not try to manage the lifetime of the pixel memory. Use Pixel_Ref
15to manage pixel memory; Pixel_Ref is safe across threads.
Cary Clarkd0530ba2017-09-14 11:25:39 -040016
17#Topic Overview
18
19#Subtopic Subtopics
20#Table
21#Legend
Cary Clark5081eed2018-01-22 07:55:48 -050022# name # description ##
Cary Clarkd0530ba2017-09-14 11:25:39 -040023#Legend ##
Cary Clark5081eed2018-01-22 07:55:48 -050024# Constructors # list of functions that construct SkPath ##
25# Member_Functions # list of static functions and member methods ##
26# Related_Functions # similar methods grouped together ##
27#Table ##
28##
29
30#Subtopic Related_Functions
31#Table
32#Legend
33# name # description ##
34#Legend ##
35# Image_Info_Access # returns all or part of Image_Info ##
36# Initialization # sets fields for use ##
37# Readable_Address # returns read only pixels ##
38# Reader # examine pixel value ##
39# Writable_Address # returns writable pixels ##
40# Writer # copy to pixel values ##
Cary Clarkd0530ba2017-09-14 11:25:39 -040041#Table ##
42#Subtopic ##
43
44#Subtopic Constructors
45#Table
46#Legend
47# # description ##
48#Legend ##
Cary Clark5081eed2018-01-22 07:55:48 -050049# SkPixmap() # constructs with default values ##
50# SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) # constructs from Image_Info, pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -040051#Table ##
52#Subtopic ##
53
54#Subtopic Member_Functions
55#Table
56#Legend
Cary Clark5081eed2018-01-22 07:55:48 -050057# name # description ##
Cary Clarkd0530ba2017-09-14 11:25:39 -040058#Legend ##
Cary Clark5081eed2018-01-22 07:55:48 -050059# addr() # returns readable pixel address as void pointer ##
60# addr16 # returns readable pixel address as 16-bit pointer ##
61# addr32 # returns readable pixel address as 32-bit pointer ##
62# addr64 # returns readable pixel address as 64-bit pointer ##
63# addr8 # returns readable pixel address as 8-bit pointer ##
64# addrF16 # returns readable pixel component address as 16-bit pointer ##
65# alphaType # returns Image_Info Alpha_Type ##
66# bounds() # returns width and height as Rectangle ##
67# colorSpace # returns Image_Info Color_Space ##
68# colorType # returns Image_Info Color_Type ##
69# computeByteSize # returns size required for pixels ##
70# computeIsOpaque # returns true if all pixels are opaque ##
71# erase() # writes Color to pixels ##
72# extractSubset # sets pointer to portion of original ##
73# getColor # returns one pixel as Unpremultiplied Color ##
74# height() # returns pixel row count ##
75# info() # returns Image_Info ##
76# isOpaque # returns true if Image_Info describes opaque pixels ##
77# readPixels # copies and converts pixels ##
78# reset() # reuses existing Pixmap with replacement values ##
79# rowBytes # returns interval between rows in bytes ##
80# rowBytesAsPixels # returns interval between rows in pixels ##
81# scalePixels # scales and converts pixels ##
82# setColorSpace # sets Image_Info Color_Space ##
83# shiftPerPixel # returns bit shift from pixels to bytes ##
84# width() # returns pixel column count ##
85# writable_addr # returns writable pixel address as void pointer ##
86# writable_addr16 # returns writable pixel address as 16-bit pointer ##
87# writable_addr32 # returns writable pixel address as 32-bit pointer ##
88# writable_addr64 # returns writable pixel address as 64-bit pointer ##
89# writable_addr8 # returns writable pixel address as 8-bit pointer ##
90# writable_addrF16 # returns writable pixel component address as 16-bit pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -040091#Table ##
92#Subtopic ##
93
94#Topic Overview ##
95
96#Subtopic Initialization
97
98# ------------------------------------------------------------------------------
99
100#Method SkPixmap()
101
102Creates an empty Pixmap without pixels, with kUnknown_SkColorType, with
103kUnknown_SkAlphaType, and with a width and height of zero. Use
104reset() to associate pixels, SkColorType, SkAlphaType, width, and height
105after Pixmap has been created.
106
107#Return empty Pixmap ##
108
109#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400110void draw(SkCanvas* canvas) {
111 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
112 const char* colors[] = {"Unknown", "Alpha", "RGB_565", "ARGB_4444", "RGBA_8888", "BGRA_8888",
113 "Gray_8", "RGBA_F16"};
114 SkPixmap pixmap;
115 for (int i = 0; i < 2; ++i) {
116 SkDebugf("width: %2d height: %2d", pixmap.width(), pixmap.height());
117 SkDebugf(" color: k%s_SkColorType", colors[pixmap.colorType()]);
118 SkDebugf(" alpha: k%s_SkAlphaType\n", alphas[pixmap.alphaType()]);
119 pixmap.reset(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType),
120 nullptr, 0);
121 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400122}
123#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400124width: 0 height: 0 color: kUnknown_SkColorType alpha: kUnknown_SkAlphaType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400125width: 25 height: 35 color: kRGBA_8888_SkColorType alpha: kOpaque_SkAlphaType
126##
127##
128
129#SeeAlso SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) reset() SkAlphaType SkColorType
130
131##
132
133# ------------------------------------------------------------------------------
134
135#Method SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes)
136
137Creates Pixmap from info width, height, SkAlphaType, and SkColorType.
Cary Clark6fc50412017-09-21 12:31:06 -0400138addr points to pixels, or nullptr. rowBytes should be info.width() times
139info.bytesPerPixel(), or larger.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400140
141No parameter checking is performed; it is up to the caller to ensure that
142addr and rowBytes agree with info.
143
Cary Clark6fc50412017-09-21 12:31:06 -0400144The memory lifetime of pixels is managed by the caller. When Pixmap goes
Cary Clarkd0530ba2017-09-14 11:25:39 -0400145out of scope, addr is unaffected.
146
147Pixmap may be later modified by reset() to change its size, pixel type, or
148storage.
149
150#Param info width, height, SkAlphaType, SkColorType of Image_Info ##
151#Param addr pointer to pixels allocated by caller; may be nullptr ##
152#Param rowBytes size of one row of addr; width times pixel size, or larger ##
153
154#Return initialized Pixmap ##
155
156#Example
157#Image 3
158#Description
159SkImage::MakeRasterCopy takes const SkPixmap& as an argument. The example
160constructs a SkPixmap from the brace-delimited parameters.
161##
Cary Clark6fc50412017-09-21 12:31:06 -0400162 SkDebugf("image alpha only = %s\n", image->isAlphaOnly() ? "true" : "false");
163 SkPMColor pmColors = 0;
164 sk_sp<SkImage> copy = SkImage::MakeRasterCopy({SkImageInfo::MakeA8(1, 1),
165 (uint8_t*)&pmColors,
166 1});
Cary Clarkd0530ba2017-09-14 11:25:39 -0400167 SkDebugf("copy alpha only = %s\n", copy->isAlphaOnly() ? "true" : "false");
168#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400169image alpha only = false
Cary Clarkd0530ba2017-09-14 11:25:39 -0400170copy alpha only = true
171##
172##
173
174#SeeAlso SkPixmap() reset() SkAlphaType SkColorType
175
176##
177
178# ------------------------------------------------------------------------------
179
180#Method void reset()
181
182Sets width, height, row bytes to zero; pixel address to nullptr; SkColorType to
183kUnknown_SkColorType; and SkAlphaType to kUnknown_SkAlphaType.
184
185The prior pixels are unaffected; it is up to the caller to release pixels
186memory if desired.
187
188#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400189void draw(SkCanvas* canvas) {
190 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
191 const char* colors[] = {"Unknown", "Alpha", "RGB_565", "ARGB_4444", "RGBA_8888", "BGRA_8888",
192 "Gray_8", "RGBA_F16"};
193 SkPixmap pixmap(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType),
194 nullptr, 0);
195 for (int i = 0; i < 2; ++i) {
196 SkDebugf("width: %2d height: %2d", pixmap.width(), pixmap.height());
197 SkDebugf(" color: k%s_SkColorType", colors[pixmap.colorType()]);
198 SkDebugf(" alpha: k%s_SkAlphaType\n", alphas[pixmap.alphaType()]);
199 pixmap.reset();
200 }
201}
Cary Clarkd0530ba2017-09-14 11:25:39 -0400202#StdOut
203width: 25 height: 35 color: kRGBA_8888_SkColorType alpha: kOpaque_SkAlphaType
Cary Clark6fc50412017-09-21 12:31:06 -0400204width: 0 height: 0 color: kUnknown_SkColorType alpha: kUnknown_SkAlphaType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400205##
206##
207
208#SeeAlso SkPixmap() SkAlphaType SkColorType
209
210##
211
212# ------------------------------------------------------------------------------
213
214#Method void reset(const SkImageInfo& info, const void* addr, size_t rowBytes)
215
216Sets width, height, SkAlphaType, and SkColorType from info.
217Sets pixel address from addr, which may be nullptr.
Cary Clark6fc50412017-09-21 12:31:06 -0400218Sets row bytes from rowBytes, which should be info.width() times
219info.bytesPerPixel(), or larger.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400220
221Does not check addr. Asserts if built with SK_DEBUG defined and if rowBytes is
222too small to hold one row of pixels.
223
224The memory lifetime pixels are managed by the caller. When Pixmap goes
225out of scope, addr is unaffected.
226
227#Param info width, height, SkAlphaType, SkColorType of Image_Info ##
228#Param addr pointer to pixels allocated by caller; may be nullptr ##
229#Param rowBytes size of one row of addr; width times pixel size, or larger ##
230
231#Example
232#Image 4
Cary Clark2ade9972017-11-02 17:49:34 -0400233#Height 64
Cary Clark6fc50412017-09-21 12:31:06 -0400234void draw(SkCanvas* canvas) {
235 std::vector<int32_t> pixels;
236 pixels.resize(image->height() * image->width() * 4);
237 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
238 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
239 image->readPixels(pixmap, 0, 0);
240 int x = 0;
241 for (auto colorType : { kRGBA_8888_SkColorType, kBGRA_8888_SkColorType } ) {
242 pixmap.reset(SkImageInfo::Make(image->width(), image->height(), colorType,
243 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
244 SkBitmap bitmap;
245 bitmap.installPixels(pixmap);
246 canvas->drawBitmap(bitmap, x, 0);
247 x += 128;
248 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400249}
250##
251
252#SeeAlso SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) reset() SkAlphaType SkColorType
253
254##
255
256# ------------------------------------------------------------------------------
257
258#Method void setColorSpace(sk_sp<SkColorSpace> colorSpace)
259
260
261Changes Color_Space in Image_Info; preserves width, height, SkAlphaType, and
262SkColorType in Image, and leaves pixel address and row bytes unchanged.
Cary Clark6fc50412017-09-21 12:31:06 -0400263Color_Space reference count is incremented.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400264
265#Param colorSpace Color_Space moved to Image_Info ##
266
267#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400268void draw(SkCanvas* canvas) {
269 SkPixmap pixmap;
270 sk_sp<SkColorSpace> colorSpace1 = SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma,
271 SkColorSpace::kRec2020_Gamut);
272 SkDebugf("is %sunique\n", colorSpace1->unique() ? "" : "not ");
273 pixmap.setColorSpace(colorSpace1);
274 SkDebugf("is %sunique\n", colorSpace1->unique() ? "" : "not ");
Cary Clarkd0530ba2017-09-14 11:25:39 -0400275}
276#StdOut
277is unique
278is not unique
279##
280##
281
282#SeeAlso Color_Space SkImageInfo::makeColorSpace
283
284##
285
286# ------------------------------------------------------------------------------
287
288#Method bool SK_WARN_UNUSED_RESULT reset(const SkMask& mask)
289
290Sets width, height, pixel address, and row bytes to Mask properties, if Mask
291format is SkMask::kA8_Format; and returns true. Otherwise sets width, height,
292row bytes to zero; pixel address to nullptr; SkColorType to kUnknown_SkColorType;
293and SkAlphaType to kUnknown_SkAlphaType; and returns false.
294
295Failing to read the return value generates a compile time warning.
296
297#Param mask Mask containing pixels and dimensions ##
298
299#Return true if set to Mask properties ##
300
301#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400302 const int width = 2;
303 const int height = 2;
304 uint8_t bytes[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
305 SkMask mask;
306 mask.fFormat = SkMask::kA8_Format;
307 mask.fBounds = {0, 0, width, height};
308 mask.fImage = bytes;
309 mask.fRowBytes = (width + 7) >> 3;
310 SkPixmap pixmap;
311 bool success = pixmap.reset(mask);
312 SkDebugf("success: %s width: %d height: %d\n", success ? "true " : "false",
313 pixmap.width(), pixmap.height());
314 mask.fFormat = SkMask::kBW_Format;
315 success = pixmap.reset(mask);
316 SkDebugf("success: %s width: %d height: %d\n", success ? "true " : "false",
317 pixmap.width(), pixmap.height());
318#StdOut
319success: true width: 2 height: 2
320success: false width: 0 height: 0
321##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400322##
323
324#SeeAlso Mask reset()
325
326##
327
328# ------------------------------------------------------------------------------
329
330#Method bool SK_WARN_UNUSED_RESULT extractSubset(SkPixmap* subset, const SkIRect& area) const
331
332Sets subset width, height, pixel address to intersection of Pixmap with area,
333if intersection is not empty; and return true. Otherwise, leave subset unchanged
334and return false.
335
336Failing to read the return value generates a compile time warning.
337
338#Param subset storage for width, height, pixel address of intersection ##
339#Param area bounds to intersect with Pixmap ##
340
341#Return true if intersection of Pixmap and area is not empty ##
342
343#Example
344#Image 3
345#Height 128
Cary Clark6fc50412017-09-21 12:31:06 -0400346void draw(SkCanvas* canvas) {
347 std::vector<int32_t> pixels;
348 pixels.resize(image->height() * image->width() * 4);
349 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
350 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
351 image->readPixels(pixmap, 0, 0);
352 SkPixmap inset;
353 if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
354 SkBitmap bitmap;
355 bitmap.installPixels(inset);
356 canvas->drawBitmap(bitmap, 0, 0);
357 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400358}
359##
360
361#SeeAlso reset() SkIRect::intersect
362
363##
364
365#Subtopic Initialization ##
366
367#Subtopic Image_Info_Access
368
369# ------------------------------------------------------------------------------
370
371#Method const SkImageInfo& info() const
372
Cary Clark6fc50412017-09-21 12:31:06 -0400373Returns width, height, Alpha_Type, Color_Type, and Color_Space.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400374
375#Return reference to ImageInfo ##
376
377#Example
378#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -0400379 std::vector<int32_t> pixels;
380 pixels.resize(image->height() * image->width() * 4);
381 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
382 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
383 image->readPixels(pixmap, 0, 0);
384 SkPixmap inset;
385 if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
386 const SkImageInfo& info = inset.info();
387 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
388 const char* colors[] = {"Unknown", "Alpha", "RGB_565", "ARGB_4444",
389 "RGBA_8888", "BGRA_8888", "Gray_8", "RGBA_F16"};
390 SkDebugf("width: %d height: %d color: %s alpha: %s\n", info.width(), info.height(),
391 colors[info.colorType()], alphas[info.alphaType()]);
392 }
393#StdOut
394width: 384 height: 384 color: BGRA_8888 alpha: Opaque
395##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400396##
397
398#SeeAlso Image_Info
399
400##
401
402# ------------------------------------------------------------------------------
403
404#Method size_t rowBytes() const
405
406Returns row bytes, the interval from one pixel row to the next. Row bytes
Cary Clark154beea2017-10-26 07:58:48 -0400407is at least as large as:
Cary Clarkd0530ba2017-09-14 11:25:39 -0400408#Formula
409width() * info().bytesPerPixel()
410##
411.
412
Cary Clarkbc5697d2017-10-04 14:31:33 -0400413Returns zero if colorType is kUnknown_SkColorType.
414It is up to the Bitmap creator to ensure that row bytes is a useful value.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400415
416#Return byte length of pixel row ##
417
418#Example
419SkPixmap badPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 2};
420SkPixmap okPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 8};
421for (auto& pixmap : { badPixmap, okPixmap } ) {
422 SkDebugf("rowBytes: %d minRowBytes: %d\n", pixmap.rowBytes(),
423 pixmap.info().minRowBytes());
424}
425#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400426rowBytes: 2 minRowBytes: 4
Cary Clarkd0530ba2017-09-14 11:25:39 -0400427rowBytes: 8 minRowBytes: 4
428##
429##
430
431#SeeAlso addr() info() SkImageInfo::minRowBytes
432
433##
434
435# ------------------------------------------------------------------------------
436
437#Method const void* addr() const
438
Cary Clark6fc50412017-09-21 12:31:06 -0400439Returns pixel address, the base address corresponding to the pixel origin.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400440
441It is up to the Pixmap creator to ensure that pixel address is a useful value.
442
443#Return pixel address ##
444
445#Example
446#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -0400447 std::vector<int32_t> pixels;
448 pixels.resize(image->height() * image->width() * 4);
449 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
450 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
451 image->readPixels(pixmap, 0, 0);
452 SkDebugf("pixels address: 0x%llx\n", pixmap.addr());
453 SkPixmap inset;
454 if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
455 SkDebugf("inset address: 0x%llx\n", inset.addr());
456 }
457#StdOut
458#Volatile
459pixels address: 0x7f2a440bb010
460inset address: 0x7f2a440fb210
461##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400462##
463
464#SeeAlso addr(int x, int y) addr8 addr16 addr32 addr64 info() rowBytes()
465
466##
467
468# ------------------------------------------------------------------------------
469
470#Method int width() const
471
472Returns pixel count in each pixel row. Should be equal or less than:
Cary Clark154beea2017-10-26 07:58:48 -0400473
Cary Clarkd0530ba2017-09-14 11:25:39 -0400474#Formula
Cary Clarkbc5697d2017-10-04 14:31:33 -0400475rowBytes() / info().bytesPerPixel()
Cary Clarkd0530ba2017-09-14 11:25:39 -0400476##
477.
478
479#Return pixel width in Image_Info ##
480
481#Example
482 SkImageInfo info = SkImageInfo::MakeA8(16, 32);
Cary Clark6fc50412017-09-21 12:31:06 -0400483 SkPixmap pixmap(info, nullptr, 64);
484 SkDebugf("pixmap width: %d info width: %d\n", pixmap.width(), info.width());
485#StdOut
486pixmap width: 16 info width: 16
487##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400488##
489
Cary Clarkbc5697d2017-10-04 14:31:33 -0400490#SeeAlso height() SkImageInfo::width()
Cary Clarkd0530ba2017-09-14 11:25:39 -0400491
492##
493
494# ------------------------------------------------------------------------------
495
496#Method int height() const
497
498Returns pixel row count.
499
500#Return pixel height in Image_Info ##
501
502#Example
Cary Clarkbc5697d2017-10-04 14:31:33 -0400503 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
504 SkDebugf("pixmap height: %d info height: %d\n", pixmap.height(), pixmap.info().height());
Cary Clark6fc50412017-09-21 12:31:06 -0400505#StdOut
506pixmap height: 32 info height: 32
507##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400508##
509
Cary Clarkbc5697d2017-10-04 14:31:33 -0400510#SeeAlso width() ImageInfo::height()
Cary Clarkd0530ba2017-09-14 11:25:39 -0400511
512##
513
514# ------------------------------------------------------------------------------
515
516#Method SkColorType colorType() const
517
518Returns Color_Type, one of: kUnknown_SkColorType, kAlpha_8_SkColorType,
519kRGB_565_SkColorType, kARGB_4444_SkColorType, kRGBA_8888_SkColorType,
520kBGRA_8888_SkColorType, kGray_8_SkColorType, kRGBA_F16_SkColorType.
521
522#Return Color_Type in Image_Info ##
523
524#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400525 const char* colors[] = {"Unknown", "Alpha", "RGB_565", "ARGB_4444",
526 "RGBA_8888", "BGRA_8888", "Gray_8", "RGBA_F16"};
527 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
528 SkDebugf("color type: k" "%s" "_SkColorType\n", colors[pixmap.colorType()]);
529#StdOut
Cary Clarkd0530ba2017-09-14 11:25:39 -0400530color type: kAlpha_SkColorType
Cary Clark6fc50412017-09-21 12:31:06 -0400531##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400532##
533
Cary Clarkbc5697d2017-10-04 14:31:33 -0400534#SeeAlso alphaType() SkImageInfo::colorType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400535
536##
537
538# ------------------------------------------------------------------------------
539
540#Method SkAlphaType alphaType() const
541
542Returns Alpha_Type, one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType,
543kPremul_SkAlphaType, kUnpremul_SkAlphaType.
544
545#Return Alpha_Type in Image_Info ##
546
547#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400548 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
549 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
550 SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[pixmap.alphaType()]);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400551#StdOut
552alpha type: kPremul_SkAlphaType
553##
554##
555
Cary Clarkbc5697d2017-10-04 14:31:33 -0400556#SeeAlso colorType() SkImageInfo::alphaType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400557
558##
559
560# ------------------------------------------------------------------------------
561
562#Method SkColorSpace* colorSpace() const
563
Cary Clarkbc5697d2017-10-04 14:31:33 -0400564Returns Color_Space associated with Image_Info. The
565reference count of Color_Space is unchanged. The returned Color_Space is
566immutable.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400567
Cary Clarkbc5697d2017-10-04 14:31:33 -0400568#Return Color_Space, the range of colors, in Image_Info ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400569
570#Example
571#Description
572SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma
573and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma.
574##
Cary Clark6fc50412017-09-21 12:31:06 -0400575 SkPixmap pixmap(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
576 SkColorSpace::MakeSRGBLinear()), nullptr, 64);
577 SkColorSpace* colorSpace = pixmap.colorSpace();
578 SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
579 colorSpace->gammaCloseToSRGB() ? "true" : "false",
580 colorSpace->gammaIsLinear() ? "true" : "false",
581 colorSpace->isSRGB() ? "true" : "false");
582#StdOut
583gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
584##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400585##
586
Cary Clarkbc5697d2017-10-04 14:31:33 -0400587#SeeAlso Color_Space SkImageInfo::colorSpace
Cary Clarkd0530ba2017-09-14 11:25:39 -0400588
589##
590
591# ------------------------------------------------------------------------------
592
593#Method bool isOpaque() const
594
595Returns true if Alpha_Type is kOpaque_SkAlphaType.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400596Does not check if Color_Type allows Alpha, or if any pixel value has
597transparency.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400598
599#Return true if Image_Info has opaque Alpha_Type ##
600
601#Example
602#Description
603 isOpaque ignores whether all pixels are opaque or not.
604##
Cary Clark6fc50412017-09-21 12:31:06 -0400605 std::vector<uint32_t> pixels;
606 const int height = 2;
607 const int width = 2;
608 pixels.resize(height * width * 4);
609 SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType,
610 kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4);
611 for (int index = 0; index < 2; ++index) {
612 pixmap.erase(0x00000000);
613 SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false");
614 pixmap.erase(0xFFFFFFFF);
615 SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false");
616 pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType),
617 (const void*) &pixels.front(), width * 4);
618 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400619#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400620isOpaque: false
621isOpaque: false
622isOpaque: true
Cary Clarkd0530ba2017-09-14 11:25:39 -0400623isOpaque: true
624##
625##
626
627#SeeAlso computeIsOpaque SkImageInfo::isOpaque
628
629##
630
631# ------------------------------------------------------------------------------
632
633#Method SkIRect bounds() const
634
Cary Clark154beea2017-10-26 07:58:48 -0400635Returns IRect { 0, 0, width(), height() }.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400636
637#Return integral rectangle from origin to width() and height() ##
638
639#Example
640 for (int width : { 0, 2 } ) {
641 for (int height : { 0, 2 } ) {
Cary Clark6fc50412017-09-21 12:31:06 -0400642 SkPixmap pixmap(SkImageInfo::MakeA8(width, height), nullptr, width);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400643 SkDebugf("width: %d height: %d empty: %s\n", width, height,
644 pixmap.bounds().isEmpty() ? "true" : "false");
645 }
646 }
647#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400648width: 0 height: 0 empty: true
649width: 0 height: 2 empty: true
650width: 2 height: 0 empty: true
Cary Clarkd0530ba2017-09-14 11:25:39 -0400651width: 2 height: 2 empty: false
652##
653##
654
655#SeeAlso height() width() IRect
656
657##
658
659# ------------------------------------------------------------------------------
660
661#Method int rowBytesAsPixels() const
662
663
664Returns number of pixels that fit on row. Should be greater than or equal to
665width().
666
667#Return maximum pixels per row ##
668
669#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400670 for (int rowBytes : { 4, 5, 6, 7, 8} ) {
671 SkPixmap pixmap(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), nullptr, rowBytes);
672 SkDebugf("rowBytes: %d rowBytesAsPixels: %d\n", rowBytes, pixmap.rowBytesAsPixels());
673 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400674#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400675rowBytes: 4 rowBytesAsPixels: 1
676rowBytes: 5 rowBytesAsPixels: 1
677rowBytes: 6 rowBytesAsPixels: 1
678rowBytes: 7 rowBytesAsPixels: 1
Cary Clarkd0530ba2017-09-14 11:25:39 -0400679rowBytes: 8 rowBytesAsPixels: 2
680##
681##
682
683#SeeAlso rowBytes shiftPerPixel width SkImageInfo::bytesPerPixel
684
685##
686
687# ------------------------------------------------------------------------------
688
689#Method int shiftPerPixel() const
690
691Returns bit shift converting row bytes to row pixels.
692Returns zero for kUnknown_SkColorType.
693
694#Return one of: 0, 1, 2, 3; left shift to convert pixels to bytes ##
695
696#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400697 const char* colors[] = {"Unknown", "Alpha", "RGB_565", "ARGB_4444",
698 "RGBA_8888", "BGRA_8888", "Gray_8", "RGBA_F16"};
699 SkImageInfo info = SkImageInfo::MakeA8(1, 1);
700 for (SkColorType colorType : { kUnknown_SkColorType, kAlpha_8_SkColorType,
701 kRGB_565_SkColorType, kARGB_4444_SkColorType,
702 kRGBA_8888_SkColorType, kBGRA_8888_SkColorType,
703 kGray_8_SkColorType, kRGBA_F16_SkColorType } ) {
704 SkPixmap pixmap(info.makeColorType(colorType), nullptr, 4);
705 SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d shiftPerPixel: %d\n",
706 colors[colorType], 10 - strlen(colors[colorType]), " ",
707 pixmap.info().bytesPerPixel(), pixmap.shiftPerPixel());
708 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400709#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400710color: kUnknown_SkColorType bytesPerPixel: 0 shiftPerPixel: 0
711color: kAlpha_SkColorType bytesPerPixel: 1 shiftPerPixel: 0
712color: kRGB_565_SkColorType bytesPerPixel: 2 shiftPerPixel: 1
713color: kARGB_4444_SkColorType bytesPerPixel: 2 shiftPerPixel: 1
714color: kRGBA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2
715color: kBGRA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2
716color: kGray_8_SkColorType bytesPerPixel: 1 shiftPerPixel: 0
Cary Clarkd0530ba2017-09-14 11:25:39 -0400717color: kRGBA_F16_SkColorType bytesPerPixel: 8 shiftPerPixel: 3
718##
719##
720
721#SeeAlso rowBytes rowBytesAsPixels width SkImageInfo::bytesPerPixel
722
723##
724
725# ------------------------------------------------------------------------------
726
Cary Clarkbc5697d2017-10-04 14:31:33 -0400727#Method size_t computeByteSize() const
728
729Returns minimum memory required for pixel storage.
730Does not include unused memory on last row when rowBytesAsPixels exceeds width().
731Returns zero if result does not fit in size_t.
732Returns zero if height() or width() is 0.
733Returns height() times rowBytes if colorType is kUnknown_SkColorType.
734
735#Return size in bytes of image buffer ##
736
Cary Clarkd0530ba2017-09-14 11:25:39 -0400737#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400738 SkPixmap pixmap;
739 for (int width : { 1, 1000, 1000000 } ) {
740 for (int height: { 1, 1000, 1000000 } ) {
741 SkImageInfo imageInfo = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType);
Cary Clarkbc5697d2017-10-04 14:31:33 -0400742 pixmap.reset(imageInfo, nullptr, width * 5);
743 SkDebugf("width: %7d height: %7d computeByteSize: %13lld\n", width, height,
744 pixmap.computeByteSize());
Cary Clark6fc50412017-09-21 12:31:06 -0400745 }
746 }
Cary Clark6fc50412017-09-21 12:31:06 -0400747#StdOut
Ben Wagner29380bd2017-10-09 14:43:00 -0400748width: 1 height: 1 computeByteSize: 4
749width: 1 height: 1000 computeByteSize: 4999
750width: 1 height: 1000000 computeByteSize: 4999999
751width: 1000 height: 1 computeByteSize: 4000
752width: 1000 height: 1000 computeByteSize: 4999000
753width: 1000 height: 1000000 computeByteSize: 4999999000
754width: 1000000 height: 1 computeByteSize: 4000000
755width: 1000000 height: 1000 computeByteSize: 4999000000
Cary Clarkbc5697d2017-10-04 14:31:33 -0400756width: 1000000 height: 1000000 computeByteSize: 4999999000000
Cary Clarkd0530ba2017-09-14 11:25:39 -0400757##
758##
759
Cary Clarkbc5697d2017-10-04 14:31:33 -0400760#SeeAlso SkImageInfo::computeByteSize
Cary Clarkd0530ba2017-09-14 11:25:39 -0400761
762##
763
764#Subtopic Image_Info_Access ##
765
766#Subtopic Reader
767
768# ------------------------------------------------------------------------------
769
770#Method bool computeIsOpaque() const
771
772Returns true if all pixels are opaque. Color_Type determines how pixels
773are encoded, and whether pixel describes Alpha. Returns true for Color_Types
Cary Clark6fc50412017-09-21 12:31:06 -0400774without alpha in each pixel; for other Color_Types, returns true if all
Cary Clarkd0530ba2017-09-14 11:25:39 -0400775pixels have alpha values equivalent to 1.0 or greater.
776
777For Color_Types kRGB_565_SkColorType or kGray_8_SkColorType: always
778returns true. For Color_Types kAlpha_8_SkColorType, kBGRA_8888_SkColorType,
779kRGBA_8888_SkColorType: returns true if all pixel Alpha values are 255.
780For Color_Type kARGB_4444_SkColorType: returns true if all pixel Alpha values are 15.
781For kRGBA_F16_SkColorType: returns true if all pixel Alpha values are 1.0 or
782greater.
783
Cary Clark6fc50412017-09-21 12:31:06 -0400784Returns false for kUnknown_SkColorType.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400785
Cary Clarkbc5697d2017-10-04 14:31:33 -0400786#Return true if all pixels have opaque values or Color_Type is opaque ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400787
788#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400789 std::vector<uint32_t> pixels;
790 const int height = 2;
791 const int width = 2;
792 pixels.resize(height * width * 4);
793 SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType,
794 kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4);
795 for (int index = 0; index < 2; ++index) {
796 pixmap.erase(0x00000000);
797 SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false");
798 pixmap.erase(0xFFFFFFFF);
799 SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false");
800 pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType),
801 (const void*) &pixels.front(), width * 4);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400802 }
803#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400804computeIsOpaque: false
805computeIsOpaque: true
806computeIsOpaque: false
Cary Clarkd0530ba2017-09-14 11:25:39 -0400807computeIsOpaque: true
808##
809##
810
811#SeeAlso isOpaque Color_Type Alpha
812
813##
814
815# ------------------------------------------------------------------------------
816
817#Method SkColor getColor(int x, int y) const
818
819Returns pixel at (x, y) as Unpremultiplied Color.
820Returns black with Alpha if Color_Type is kAlpha_8_SkColorType.
821
822Input is not validated: out of bounds values of x or y trigger an assert() if
823built with SK_DEBUG defined; and returns undefined values or may crash if
824SK_RELEASE is defined. Fails if Color_Type is kUnknown_SkColorType or
825pixel address is nullptr.
826
827Color_Space in Image_Info is ignored. Some Color precision may be lost in the
828conversion to Unpremultiplied Color; original pixel data may have additional
829precision.
830
Cary Clark6fc50412017-09-21 12:31:06 -0400831#Param x column index, zero or greater, and less than width() ##
832#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400833
834#Return pixel converted to Unpremultiplied Color ##
835
836#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400837 const int w = 4;
838 const int h = 4;
839 std::vector<SkPMColor> storage;
840 storage.resize(w * h);
841 SkDebugf("Premultiplied:\n");
842 for (int y = 0; y < h; ++y) {
843 SkDebugf("(0, %d) ", y);
844 for (int x = 0; x < w; ++x) {
845 int a = 0xFF * (x + y) / (w - 1 + h - 1);
846 storage[x + y * w] = SkPackARGB32(a, a * x / (w - 1), a * y / (h - 1), a);
847 SkDebugf("0x%08x%c", storage[x + y * w], x == w - 1 ? '\n' : ' ');
848 }
849 }
850 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4);
851 SkDebugf("Unpremultiplied:\n");
852 for (int y = 0; y < h; ++y) {
853 SkDebugf("(0, %d) ", y);
854 for (int x = 0; x < w; ++x) {
855 SkDebugf("0x%08x%c", pixmap.getColor(x, y), x == w - 1 ? '\n' : ' ');
856 }
857 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400858#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400859Premultiplied:
860(0, 0) 0x00000000 0x2a0e002a 0x55380055 0x7f7f007f
861(0, 1) 0x2a000e2a 0x551c1c55 0x7f542a7f 0xaaaa38aa
862(0, 2) 0x55003855 0x7f2a547f 0xaa7171aa 0xd4d48dd4
863(0, 3) 0x7f007f7f 0xaa38aaaa 0xd48dd4d4 0xffffffff
864Unpremultiplied:
865(0, 0) 0x00000000 0x2a5500ff 0x55a800ff 0x7fff00ff
866(0, 1) 0x2a0055ff 0x555454ff 0x7fa954ff 0xaaff54ff
867(0, 2) 0x5500a8ff 0x7f54a9ff 0xaaaaaaff 0xd4ffaaff
Cary Clarkd0530ba2017-09-14 11:25:39 -0400868(0, 3) 0x7f00ffff 0xaa54ffff 0xd4aaffff 0xffffffff
869##
870##
871
872#SeeAlso addr() readPixels
873
874##
875
876#Subtopic Reader ##
877
878#Subtopic Readable_Address
879
880# ------------------------------------------------------------------------------
881
882#Method const void* addr(int x, int y) const
883
Cary Clarkbc5697d2017-10-04 14:31:33 -0400884Returns readable pixel address at (x, y). Returns nullptr if Pixel_Ref is nullptr.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400885
886Input is not validated: out of bounds values of x or y trigger an assert() if
Cary Clarkbc5697d2017-10-04 14:31:33 -0400887built with SK_DEBUG defined. Returns nullptr if Color_Type is kUnknown_SkColorType.
888
889Performs a lookup of pixel size; for better performance, call
890one of: addr8, addr16, addr32, addr64, or addrF16.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400891
Cary Clark6fc50412017-09-21 12:31:06 -0400892#Param x column index, zero or greater, and less than width() ##
893#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400894
895#Return readable generic pointer to pixel ##
896
897#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400898 const int w = 4;
899 const int h = 4;
900 std::vector<SkPMColor> storage;
901 storage.resize(w * h);
902 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400903 SkDebugf("pixmap.addr(1, 2) %c= &storage[1 + 2 * w]\n",
904 pixmap.addr(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
905#StdOut
906pixmap.addr(1, 2) == &storage[1 + 2 * w]
907##
908##
909
Cary Clarkbc5697d2017-10-04 14:31:33 -0400910#SeeAlso addr8 addr16 addr32 addr64 addrF16 getColor writable_addr SkBitmap::getAddr
Cary Clarkd0530ba2017-09-14 11:25:39 -0400911
912##
913
914# ------------------------------------------------------------------------------
915
916#Method const uint8_t* addr8() const
917
918Returns readable base pixel address. Result is addressable as unsigned 8-bit bytes.
919Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType or
920kGray_8_SkColorType, and is built with SK_DEBUG defined.
921
922One byte corresponds to one pixel.
923
924#Return readable unsigned 8-bit pointer to pixels ##
925
926#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400927 const int w = 4;
928 const int h = 4;
929 uint8_t storage[w * h];
930 SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType),
931 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400932 SkDebugf("pixmap.addr8() %c= storage\n",
933 pixmap.addr8() == storage ? '=' : '!');
934#StdOut
935pixmap.addr8() == storage
936##
937##
938
939#SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8
940
941##
942
943# ------------------------------------------------------------------------------
944
945#Method const uint16_t* addr16() const
946
947Returns readable base pixel address. Result is addressable as unsigned 16-bit words.
948Will trigger an assert() if Color_Type is not kRGB_565_SkColorType or
949kARGB_4444_SkColorType, and is built with SK_DEBUG defined.
950
951One word corresponds to one pixel.
952
953#Return readable unsigned 16-bit pointer to pixels ##
954
955#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400956 const int w = 4;
957 const int h = 4;
958 uint16_t storage[w * h];
959 SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType),
960 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400961 SkDebugf("pixmap.addr16() %c= storage\n",
962 pixmap.addr16() == storage ? '=' : '!');
963#StdOut
964pixmap.addr16() == storage
965##
966##
967
968#SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16
969
970##
971
972# ------------------------------------------------------------------------------
973
974#Method const uint32_t* addr32() const
975
976Returns readable base pixel address. Result is addressable as unsigned 32-bit words.
977Will trigger an assert() if Color_Type is not kRGBA_8888_SkColorType or
978kBGRA_8888_SkColorType, and is built with SK_DEBUG defined.
979
980One word corresponds to one pixel.
981
982#Return readable unsigned 32-bit pointer to pixels ##
983
984#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400985 const int w = 4;
986 const int h = 4;
987 uint32_t storage[w * h];
988 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType),
989 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400990 SkDebugf("pixmap.addr32() %c= storage\n",
991 pixmap.addr32() == storage ? '=' : '!');
992#StdOut
993pixmap.addr32() == storage
994##
995##
996
997#SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr32
998
999##
1000
1001# ------------------------------------------------------------------------------
1002
1003#Method const uint64_t* addr64() const
1004
1005Returns readable base pixel address. Result is addressable as unsigned 64-bit words.
1006Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
1007with SK_DEBUG defined.
1008
1009One word corresponds to one pixel.
1010
1011#Return readable unsigned 64-bit pointer to pixels ##
1012
1013#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001014 const int w = 4;
1015 const int h = 4;
1016 uint64_t storage[w * h];
1017 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
1018 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001019 SkDebugf("pixmap.addr64() %c= storage\n",
1020 pixmap.addr64() == storage ? '=' : '!');
1021#StdOut
1022pixmap.addr64() == storage
1023##
1024##
1025
1026#SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64
1027
1028##
1029
1030# ------------------------------------------------------------------------------
1031
1032#Method const uint16_t* addrF16() const
1033
1034Returns readable base pixel address. Result is addressable as unsigned 16-bit words.
1035Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
1036with SK_DEBUG defined.
1037
1038Each word represents one color component encoded as a half float.
1039Four words correspond to one pixel.
1040
1041#Return readable unsigned 16-bit pointer to first component of pixels ##
1042
1043#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001044 const int w = 4;
1045 const int h = 4;
1046 uint16_t storage[w * h * 4];
1047 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
1048 storage, w * 4 * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001049 SkDebugf("pixmap.addrF16() %c= storage\n",
1050 pixmap.addrF16() == storage ? '=' : '!');
1051#StdOut
1052pixmap.addrF16() == storage
1053##
1054##
1055
1056#SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16
1057
1058##
1059
1060# ------------------------------------------------------------------------------
1061
1062#Method const uint8_t* addr8(int x, int y) const
1063
1064Returns readable pixel address at (x, y).
1065
1066Input is not validated: out of bounds values of x or y trigger an assert() if
1067built with SK_DEBUG defined.
1068
1069Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType or
1070kGray_8_SkColorType, and is built with SK_DEBUG defined.
1071
Cary Clark6fc50412017-09-21 12:31:06 -04001072#Param x column index, zero or greater, and less than width() ##
1073#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001074
1075#Return readable unsigned 8-bit pointer to pixel at (x, y) ##
1076
1077#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001078 const int w = 4;
1079 const int h = 4;
1080 uint8_t storage[w * h];
1081 SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType),
1082 storage, w * sizeof(storage[0]));
1083 SkDebugf("pixmap.addr8(1, 2) %c= &storage[1 + 2 * w]\n",
1084 pixmap.addr8(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
Cary Clarkd0530ba2017-09-14 11:25:39 -04001085#StdOut
1086pixmap.addr8(1, 2) == &storage[1 + 2 * w]
1087##
1088##
1089
1090#SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8
1091
1092##
1093
1094# ------------------------------------------------------------------------------
1095
1096#Method const uint16_t* addr16(int x, int y) const
1097
1098Returns readable pixel address at (x, y).
1099
1100Input is not validated: out of bounds values of x or y trigger an assert() if
1101built with SK_DEBUG defined.
1102
1103Will trigger an assert() if Color_Type is not kRGB_565_SkColorType or
1104kARGB_4444_SkColorType, and is built with SK_DEBUG defined.
1105
Cary Clark6fc50412017-09-21 12:31:06 -04001106#Param x column index, zero or greater, and less than width() ##
1107#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001108
1109#Return readable unsigned 16-bit pointer to pixel at (x, y) ##
1110
1111#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001112 const int w = 4;
1113 const int h = 4;
1114 uint16_t storage[w * h];
1115 SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType),
1116 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001117 SkDebugf("pixmap.addr16(1, 2) %c= &storage[1 + 2 * w]\n",
1118 pixmap.addr16(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
1119#StdOut
1120pixmap.addr16(1, 2) == &storage[1 + 2 * w]
1121##
1122##
1123
1124#SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16
1125
1126##
1127
1128# ------------------------------------------------------------------------------
1129
1130#Method const uint32_t* addr32(int x, int y) const
1131
1132Returns readable pixel address at (x, y).
1133
1134Input is not validated: out of bounds values of x or y trigger an assert() if
1135built with SK_DEBUG defined.
1136
1137Will trigger an assert() if Color_Type is not kRGBA_8888_SkColorType or
1138kBGRA_8888_SkColorType, and is built with SK_DEBUG defined.
1139
Cary Clark6fc50412017-09-21 12:31:06 -04001140#Param x column index, zero or greater, and less than width() ##
1141#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001142
1143#Return readable unsigned 32-bit pointer to pixel at (x, y) ##
1144
1145#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001146 const int w = 4;
1147 const int h = 4;
1148 uint32_t storage[w * h];
1149 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_8888_SkColorType, kPremul_SkAlphaType),
1150 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001151 SkDebugf("pixmap.addr32(1, 2) %c= &storage[1 + 2 * w]\n",
1152 pixmap.addr32(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
1153#StdOut
1154pixmap.addr32(1, 2) == &storage[1 + 2 * w]
1155##
1156##
1157
Cary Clark2ade9972017-11-02 17:49:34 -04001158#SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr64
Cary Clarkd0530ba2017-09-14 11:25:39 -04001159
1160##
1161
1162# ------------------------------------------------------------------------------
1163
1164#Method const uint64_t* addr64(int x, int y) const
1165
1166Returns readable pixel address at (x, y).
1167
1168Input is not validated: out of bounds values of x or y trigger an assert() if
1169built with SK_DEBUG defined.
1170
1171Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
1172with SK_DEBUG defined.
1173
Cary Clark6fc50412017-09-21 12:31:06 -04001174#Param x column index, zero or greater, and less than width() ##
1175#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001176
1177#Return readable unsigned 64-bit pointer to pixel at (x, y) ##
1178
1179#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001180 const int w = 4;
1181 const int h = 4;
1182 uint64_t storage[w * h];
1183 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
1184 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001185 SkDebugf("pixmap.addr64(1, 2) %c= &storage[1 + 2 * w]\n",
1186 pixmap.addr64(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
1187#StdOut
1188pixmap.addr64(1, 2) == &storage[1 + 2 * w]
1189##
1190##
1191
1192#SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64
1193
1194##
1195
1196# ------------------------------------------------------------------------------
1197
1198#Method const uint16_t* addrF16(int x, int y) const
1199
1200Returns readable pixel address at (x, y).
1201
1202Input is not validated: out of bounds values of x or y trigger an assert() if
1203built with SK_DEBUG defined.
1204
1205Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
1206with SK_DEBUG defined.
1207
1208Each unsigned 16-bit word represents one color component encoded as a half float.
1209Four words correspond to one pixel.
1210
Cary Clark6fc50412017-09-21 12:31:06 -04001211#Param x column index, zero or greater, and less than width() ##
1212#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001213
1214#Return readable unsigned 16-bit pointer to pixel component at (x, y) ##
1215
1216#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001217 const int w = 4;
1218 const int h = 4;
1219 const int wordsPerPixel = 4;
1220 const int rowWords = w * wordsPerPixel;
1221 uint16_t storage[rowWords * h];
1222 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
1223 storage, rowWords * sizeof(storage[0]));
1224 SkDebugf("pixmap.addrF16(1, 2) %c= &storage[1 * wordsPerPixel + 2 * rowWords]\n",
1225 pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords] ? '=' : '!');
Cary Clarkd0530ba2017-09-14 11:25:39 -04001226#StdOut
1227pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords]
1228##
1229##
1230
1231#SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16
1232
1233##
1234
1235#Subtopic Readable_Address ##
1236
1237#Subtopic Writable_Address
1238
1239# ------------------------------------------------------------------------------
1240
1241#Method void* writable_addr() const
1242
1243Returns writable base pixel address.
1244
1245#Return writable generic base pointer to pixels ##
1246
1247#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001248 const int w = 4;
1249 const int h = 4;
1250 SkPMColor storage[w * h * 4];
1251 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4);
1252 SkDebugf("pixmap.writable_addr() %c= (void *)storage\n",
1253 pixmap.writable_addr() == (void *)storage ? '=' : '!');
1254 pixmap.erase(0x00000000);
1255 *(SkPMColor*)pixmap.writable_addr() = 0xFFFFFFFF;
1256 SkDebugf("pixmap.getColor(0, 1) %c= 0x00000000\n",
1257 pixmap.getColor(0, 1) == 0x00000000 ? '=' : '!');
1258 SkDebugf("pixmap.getColor(0, 0) %c= 0xFFFFFFFF\n",
Cary Clarkd0530ba2017-09-14 11:25:39 -04001259 pixmap.getColor(0, 0) == 0xFFFFFFFF ? '=' : '!');
1260#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -04001261pixmap.writable_addr() == (void *)storage
1262pixmap.getColor(0, 1) == 0x00000000
Cary Clarkd0530ba2017-09-14 11:25:39 -04001263pixmap.getColor(0, 0) == 0xFFFFFFFF
1264##
1265##
1266
1267#SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr()
1268
1269##
1270
1271# ------------------------------------------------------------------------------
1272
1273#Method void* writable_addr(int x, int y) const
1274
1275Returns writable pixel address at (x, y).
1276
1277Input is not validated: out of bounds values of x or y trigger an assert() if
1278built with SK_DEBUG defined. Returns zero if Color_Type is kUnknown_SkColorType.
1279
Cary Clark6fc50412017-09-21 12:31:06 -04001280#Param x column index, zero or greater, and less than width() ##
1281#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001282
1283#Return writable generic pointer to pixel ##
1284
1285#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001286 const int w = 4;
1287 const int h = 4;
1288 SkPMColor storage[w * h * 4];
1289 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4);
1290 SkDebugf("pixmap.writable_addr() %c= (void *)storage\n",
1291 pixmap.writable_addr() == (void *)storage ? '=' : '!');
1292 pixmap.erase(0x00000000);
1293 *(SkPMColor*)pixmap.writable_addr(1, 2) = 0xFFFFFFFF;
1294 SkDebugf("pixmap.getColor(0, 0) %c= 0x00000000\n",
1295 pixmap.getColor(0, 0) == 0x00000000 ? '=' : '!');
1296 SkDebugf("pixmap.getColor(1, 2) %c= 0xFFFFFFFF\n",
Cary Clarkd0530ba2017-09-14 11:25:39 -04001297 pixmap.getColor(1, 2) == 0xFFFFFFFF ? '=' : '!');
1298#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -04001299pixmap.writable_addr() == (void *)storage
1300pixmap.getColor(0, 0) == 0x00000000
Cary Clarkd0530ba2017-09-14 11:25:39 -04001301pixmap.getColor(1, 2) == 0xFFFFFFFF
1302##
1303##
1304
1305#SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr()
1306
1307##
1308
1309# ------------------------------------------------------------------------------
1310
1311#Method uint8_t* writable_addr8(int x, int y) const
1312
Cary Clark6fc50412017-09-21 12:31:06 -04001313Returns writable pixel address at (x, y). Result is addressable as unsigned
13148-bit bytes. Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType
1315or kGray_8_SkColorType, and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001316
1317One byte corresponds to one pixel.
1318
Cary Clark6fc50412017-09-21 12:31:06 -04001319#Param x column index, zero or greater, and less than width() ##
1320#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001321
1322#Return writable unsigned 8-bit pointer to pixels ##
1323
1324#Example
1325#Height 64
1326#Description
1327Altering pixels after drawing Bitmap is not guaranteed to affect subsequent
1328drawing on all platforms. Adding a second SkBitmap::installPixels after editing
1329pixel memory is safer.
1330##
Cary Clark6fc50412017-09-21 12:31:06 -04001331void draw(SkCanvas* canvas) {
1332 uint8_t storage[][5] = {{ 0, 0, 64, 0, 0},
1333 { 0, 128, 255, 128, 0},
1334 {64, 255, 255, 255, 64},
1335 { 0, 128, 255, 128, 0},
1336 { 0, 0, 64, 0, 0}};
1337 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kPremul_SkAlphaType);
1338 SkPixmap pixmap(imageInfo, storage[0], 5);
1339 SkBitmap bitmap;
1340 bitmap.installPixels(pixmap);
1341 canvas->scale(10, 10);
1342 canvas->drawBitmap(bitmap, 0, 0);
1343 *pixmap.writable_addr8(2, 2) = 0;
1344// bitmap.installPixels(pixmap); // uncomment to fix on GPU
1345 canvas->drawBitmap(bitmap, 10, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001346}
1347##
1348
1349#SeeAlso writable_addr writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr() addr8
1350
1351##
1352
1353# ------------------------------------------------------------------------------
1354
1355#Method uint16_t* writable_addr16(int x, int y) const
1356
Cary Clark6fc50412017-09-21 12:31:06 -04001357Returns writable_addr pixel address at (x, y). Result is addressable as unsigned
135816-bit words. Will trigger an assert() if Color_Type is not kRGB_565_SkColorType
1359or kARGB_4444_SkColorType, and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001360
1361One word corresponds to one pixel.
1362
Cary Clark6fc50412017-09-21 12:31:06 -04001363#Param x column index, zero or greater, and less than width() ##
1364#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001365
1366#Return writable unsigned 16-bit pointer to pixel ##
1367
1368#Example
1369#Description
1370Draw a five by five bitmap, and draw it again with a center black pixel.
1371The low nibble of the 16-bit word is Alpha.
1372##
1373#Height 64
Cary Clark6fc50412017-09-21 12:31:06 -04001374 uint16_t storage[][5] = {{ 0xCABF, 0xDABE, 0xCA9D, 0xC96C, 0xA39B },
1375 { 0xACEE, 0xA87C, 0x893A, 0x4779, 0x8708 },
1376 { 0x4B7C, 0x255B, 0x2559, 0x2557, 0x4656 },
1377 { 0x9099, 0x8128, 0x2557, 0x4124, 0x3323 },
1378 { 0x7547, 0x5505, 0x4434, 0x2012, 0x0000 }};
1379 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kARGB_4444_SkColorType, kPremul_SkAlphaType);
1380 SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
1381 SkBitmap bitmap;
1382 bitmap.installPixels(pixmap);
1383 canvas->scale(10, 10);
1384 canvas->drawBitmap(bitmap, 0, 0);
1385 *pixmap.writable_addr16(2, 2) = 0x000F;
1386 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001387 canvas->drawBitmap(bitmap, 10, 0);
1388##
1389
1390#SeeAlso writable_addr writable_addr8 writable_addr32 writable_addr64 writable_addrF16 addr() addr16
1391
1392##
1393
1394# ------------------------------------------------------------------------------
1395
1396#Method uint32_t* writable_addr32(int x, int y) const
1397
Cary Clark6fc50412017-09-21 12:31:06 -04001398Returns writable pixel address at (x, y). Result is addressable as unsigned
139932-bit words. Will trigger an assert() if Color_Type is not
1400kRGBA_8888_SkColorType or kBGRA_8888_SkColorType, and is built with SK_DEBUG
1401defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001402
1403One word corresponds to one pixel.
1404
Cary Clark6fc50412017-09-21 12:31:06 -04001405#Param x column index, zero or greater, and less than width() ##
1406#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001407
1408#Return writable unsigned 32-bit pointer to pixel ##
1409
1410#Example
1411#Image 4
1412#Height 72
Cary Clark6fc50412017-09-21 12:31:06 -04001413 std::vector<int32_t> pixels;
1414 pixels.resize(image->height() * image->width() * 4);
1415 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
1416 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
1417 image->readPixels(pixmap, 0, 0);
1418 for (int y = 0; y < pixmap.height() / 2; ++y) {
1419 for (int x = 0; x < pixmap.width(); ++x) {
1420 if ((x & 4) == (y & 4)) {
1421 SkTSwap(*pixmap.writable_addr32(x, y),
1422 *pixmap.writable_addr32(pixmap.width() - x, pixmap.height() - y));
1423 }
1424 }
1425 }
1426 SkBitmap bitmap;
1427 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001428 canvas->drawBitmap(bitmap, 0, 0);
1429##
1430
1431#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr64 writable_addrF16 addr() addr32
1432
1433##
1434
1435# ------------------------------------------------------------------------------
1436
1437#Method uint64_t* writable_addr64(int x, int y) const
1438
Cary Clark6fc50412017-09-21 12:31:06 -04001439Returns writable pixel address at (x, y). Result is addressable as unsigned
144064-bit words. Will trigger an assert() if Color_Type is not
1441kRGBA_F16_SkColorType and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001442
1443One word corresponds to one pixel.
1444
Cary Clark6fc50412017-09-21 12:31:06 -04001445#Param x column index, zero or greater, and less than width() ##
1446#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001447
1448#Return writable unsigned 64-bit pointer to pixel ##
1449
1450#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001451#Height 40
Cary Clark6fc50412017-09-21 12:31:06 -04001452 SkImageInfo info = SkImageInfo::Make(3, 3, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
1453 uint64_t storage[9];
1454 SkPixmap pixmap(info, storage, 3 * sizeof(uint64_t));
1455 SkColor4f c4 { 1, 0.45f, 0.25f, 0.65f };
1456 pixmap.erase(c4);
1457 SkBitmap bitmap;
1458 canvas->scale(10, 10);
1459 bitmap.installPixels(pixmap);
1460 canvas->drawBitmap(bitmap, 0, 0);
1461 *pixmap.writable_addr64(1, 1) |= 0x00ff000000000000LL;
1462 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001463 canvas->drawBitmap(bitmap, 10, 0);
1464##
1465
1466#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addrF16 addr() addr64
1467
1468##
1469
1470# ------------------------------------------------------------------------------
1471
1472#Method uint16_t* writable_addrF16(int x, int y) const
1473
Cary Clark6fc50412017-09-21 12:31:06 -04001474Returns writable pixel address at (x, y). Result is addressable as unsigned
147516-bit words. Will trigger an assert() if Color_Type is not
1476kRGBA_F16_SkColorType and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001477
1478Each word represents one color component encoded as a half float.
1479Four words correspond to one pixel.
1480
Cary Clark6fc50412017-09-21 12:31:06 -04001481#Param x column index, zero or greater, and less than width() ##
1482#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001483
1484#Return writable unsigned 16-bit pointer to first component of pixel ##
1485
1486#Example
1487#Height 64
1488#Description
1489Left bitmap is drawn with two pixels defined in half float format. Right bitmap
1490is drawn after overwriting bottom half float color with top half float color.
1491##
Cary Clark6fc50412017-09-21 12:31:06 -04001492 SkImageInfo info = SkImageInfo::Make(1, 2, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
1493 uint16_t storage[2][4];
1494 SkPixmap pixmap(info, storage[0], sizeof(uint64_t));
1495 SkIRect topPixelBounds = {0, 0, 1, 1};
1496 pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds);
1497 SkIRect bottomPixelBounds = {0, 1, 1, 2};
1498 pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds);
1499 SkBitmap bitmap;
1500 canvas->scale(20, 20);
1501 bitmap.installPixels(pixmap);
1502 canvas->drawBitmap(bitmap, 0, 0);
1503 uint16_t* pixel2 = pixmap.writable_addrF16(0, 1);
1504 for (int i = 0; i < 4; ++i) {
1505 pixel2[i] = storage[0][i];
1506 }
1507 bitmap.installPixels(pixmap);
1508 canvas->drawBitmap(bitmap, 4, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001509##
1510
1511#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addr64 addr() addrF16
1512
1513##
1514
1515#Subtopic Writable_Address ##
1516
1517#Subtopic Writer
1518
1519# ------------------------------------------------------------------------------
1520
1521#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
1522 int srcX, int srcY, SkTransferFunctionBehavior behavior) const
1523
Cary Clark154beea2017-10-26 07:58:48 -04001524Copies a Rect of pixels to dstPixels. Copy starts at (srcX, srcY), and does not
Cary Clarkac47b882018-01-11 10:35:44 -05001525exceed Pixmap (width(), height()).
Cary Clark6fc50412017-09-21 12:31:06 -04001526
1527dstInfo specifies width, height, Color_Type, Alpha_Type, and
Cary Clarkd0530ba2017-09-14 11:25:39 -04001528Color_Space of destination. dstRowBytes specifics the gap from one destination
1529row to the next. Returns true if pixels are copied. Returns false if
1530dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes.
1531
Cary Clarkac47b882018-01-11 10:35:44 -05001532Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001533kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001534If Pixmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match.
1535If Pixmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must
1536match. If Pixmap colorSpace is nullptr, dstInfo.colorSpace must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001537false if pixel conversion is not possible.
1538
1539srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clark154beea2017-10-26 07:58:48 -04001540false if width() or height() is zero or negative. Returns false if:
1541
Cary Clarkd0530ba2017-09-14 11:25:39 -04001542#Formula
Cary Clarkac47b882018-01-11 10:35:44 -05001543abs(srcX) >= Pixmap width()
Cary Clark6fc50412017-09-21 12:31:06 -04001544##
1545, or if
1546#Formula
Cary Clarkac47b882018-01-11 10:35:44 -05001547abs(srcY) >= Pixmap height()
Cary Clarkd0530ba2017-09-14 11:25:39 -04001548##
1549.
1550
1551If behavior is SkTransferFunctionBehavior::kRespect: converts source
1552pixels to a linear space before converting to dstInfo.
1553If behavior is SkTransferFunctionBehavior::kIgnore: source
Cary Clarkbc5697d2017-10-04 14:31:33 -04001554pixels are treated as if they are linear, regardless of how they are encoded.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001555
1556#Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ##
1557#Param dstPixels destination pixel storage ##
1558#Param dstRowBytes destination row length ##
1559#Param srcX column index whose absolute value is less than width() ##
1560#Param srcY row index whose absolute value is less than height() ##
1561#Param behavior one of: SkTransferFunctionBehavior::kRespect,
1562 SkTransferFunctionBehavior::kIgnore
1563##
1564
1565#Return true if pixels are copied to dstPixels ##
1566
1567#Example
Cary Clarkbc5697d2017-10-04 14:31:33 -04001568#ToDo example doesn't do anything interesting since info colorSpace is nullptr ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001569#Image 3
1570void draw(SkCanvas* canvas) {
1571 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height(),
1572 canvas->imageInfo().colorSpace() ? SkColorSpace::MakeSRGB() : nullptr);
Cary Clark6fc50412017-09-21 12:31:06 -04001573 std::vector<int32_t> srcPixels;
1574 srcPixels.resize(image->height() * image->width() * 4);
1575 SkPixmap pixmap(info, (const void*) &srcPixels.front(), image->width() * 4);
1576 image->readPixels(pixmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001577 SkTransferFunctionBehavior behavior = canvas->imageInfo().colorSpace() ?
1578 SkTransferFunctionBehavior::kRespect : SkTransferFunctionBehavior::kIgnore;
Cary Clark6fc50412017-09-21 12:31:06 -04001579 std::vector<int32_t> dstPixels;
1580 dstPixels.resize(image->height() * image->width() * 4);
1581 int offset = 0;
1582 for (auto behavior : { SkTransferFunctionBehavior::kRespect,
1583 SkTransferFunctionBehavior::kIgnore} ) {
Cary Clarkd0530ba2017-09-14 11:25:39 -04001584 pixmap.readPixels(info, &dstPixels.front(), image->width() * 4, offset, 0, behavior);
1585 offset += 128;
1586 }
1587 SkBitmap bitmap;
1588 SkPixmap dstmap(info, &dstPixels.front(), image->width() * 4);
1589 bitmap.installPixels(dstmap);
1590 canvas->drawBitmap(bitmap, 0, 0);
1591}
1592##
1593
1594#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1595
1596##
1597
1598# ------------------------------------------------------------------------------
1599
1600#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes) const
1601
1602Copies a Rect of pixels to dstPixels. Copy starts at (0, 0), and does not
Cary Clarkac47b882018-01-11 10:35:44 -05001603exceed Pixmap (width(), height()).
Cary Clark6fc50412017-09-21 12:31:06 -04001604
1605dstInfo specifies width, height, Color_Type, Alpha_Type, and
Cary Clarkd0530ba2017-09-14 11:25:39 -04001606Color_Space of destination. dstRowBytes specifics the gap from one destination
1607row to the next. Returns true if pixels are copied. Returns false if
1608dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes.
1609
Cary Clarkac47b882018-01-11 10:35:44 -05001610Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001611kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001612If Pixmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match.
1613If Pixmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must
1614match. If Pixmap colorSpace is nullptr, dstInfo.colorSpace must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001615false if pixel conversion is not possible.
1616
Cary Clarkac47b882018-01-11 10:35:44 -05001617Returns false if Pixmap width() or height() is zero or negative.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001618
1619#Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ##
1620#Param dstPixels destination pixel storage ##
1621#Param dstRowBytes destination row length ##
1622
1623#Return true if pixels are copied to dstPixels ##
1624
1625#Example
1626#Height 128
1627#Description
1628Transferring the gradient from 8 bits per component to 4 bits per component
1629creates visible banding.
1630##
Cary Clark6fc50412017-09-21 12:31:06 -04001631 std::vector<int32_t> pixels;
1632 const int width = 256;
1633 const int height = 64;
1634 pixels.resize(height * width * 4);
1635 SkImageInfo srcInfo = SkImageInfo::MakeN32Premul(width, height);
1636 SkPixmap srcPixmap(srcInfo, (const void*) &pixels.front(), width * 4);
1637 SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 };
1638 SkPoint gradPoints[] = { { 0, 0 }, { 256, 0 } };
1639 SkPaint paint;
1640 paint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1641 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1642 SkBitmap bitmap;
1643 bitmap.installPixels(srcPixmap);
1644 SkCanvas srcCanvas(bitmap);
1645 srcCanvas.drawRect(SkRect::MakeWH(width, height), paint);
1646 canvas->drawBitmap(bitmap, 0, 0);
1647 std::vector<int32_t> dstPixels;
1648 dstPixels.resize(height * width * 2);
1649 SkImageInfo dstInfo = srcInfo.makeColorType(kARGB_4444_SkColorType);
1650 srcPixmap.readPixels(dstInfo, &dstPixels.front(), width * 2);
1651 SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2);
1652 bitmap.installPixels(dstPixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001653 canvas->drawBitmap(bitmap, 0, 128);
1654##
1655
1656#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1657
1658##
1659
1660# ------------------------------------------------------------------------------
1661
1662#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX,
1663 int srcY) const
1664
1665Copies a Rect of pixels to dstPixels. Copy starts at (srcX, srcY), and does not
Cary Clarkac47b882018-01-11 10:35:44 -05001666exceed Pixmap (width(), height()).
Cary Clark6fc50412017-09-21 12:31:06 -04001667
1668dstInfo specifies width, height, Color_Type, Alpha_Type, and
Cary Clarkd0530ba2017-09-14 11:25:39 -04001669Color_Space of destination. dstRowBytes specifics the gap from one destination
1670row to the next. Returns true if pixels are copied. Returns false if
1671dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes.
1672
Cary Clarkac47b882018-01-11 10:35:44 -05001673Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001674kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001675If Pixmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match.
1676If Pixmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must
1677match. If Pixmap colorSpace is nullptr, dstInfo.colorSpace must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001678false if pixel conversion is not possible.
1679
1680srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clarkac47b882018-01-11 10:35:44 -05001681false if Pixmap width() or height() is zero or negative. Returns false if:
Cary Clark154beea2017-10-26 07:58:48 -04001682
Cary Clarkd0530ba2017-09-14 11:25:39 -04001683#Formula
Cary Clarkac47b882018-01-11 10:35:44 -05001684abs(srcX) >= Pixmap width()
Cary Clark6fc50412017-09-21 12:31:06 -04001685##
1686, or if
1687#Formula
Cary Clarkac47b882018-01-11 10:35:44 -05001688abs(srcY) >= Pixmap height()
Cary Clarkd0530ba2017-09-14 11:25:39 -04001689##
1690.
1691
1692#Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ##
1693#Param dstPixels destination pixel storage ##
1694#Param dstRowBytes destination row length ##
1695#Param srcX column index whose absolute value is less than width() ##
1696#Param srcY row index whose absolute value is less than height() ##
1697
1698#Return true if pixels are copied to dstPixels ##
1699
1700#Example
1701#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001702void draw(SkCanvas* canvas) {
1703 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1704 std::vector<int32_t> srcPixels;
1705 const int rowBytes = image->width() * 4;
1706 srcPixels.resize(image->height() * rowBytes);
1707 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1708 image->readPixels(pixmap, 0, 0);
1709 for (int offset : { 32, 64, 96 } ) {
1710 std::vector<int32_t> dstPixels;
1711 dstPixels.resize(image->height() * rowBytes);
1712 pixmap.readPixels(info, &dstPixels.front(), rowBytes, offset, 0);
1713 SkBitmap bitmap;
1714 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1715 bitmap.installPixels(dstmap);
1716 canvas->translate(32, 32);
1717 canvas->drawBitmap(bitmap, 0, 0);
1718 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001719}
1720##
1721
1722#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1723
1724##
1725
1726# ------------------------------------------------------------------------------
1727
1728#Method bool readPixels(const SkPixmap& dst, int srcX, int srcY) const
1729
1730Copies a Rect of pixels to dst. Copy starts at (srcX, srcY), and does not
Cary Clarkac47b882018-01-11 10:35:44 -05001731exceed Pixmap (width(), height()). dst specifies width, height, Color_Type,
Cary Clarkd0530ba2017-09-14 11:25:39 -04001732Alpha_Type, and Color_Space of destination. Returns true if pixels are copied.
1733Returns false if dst.addr() equals nullptr, or dst.rowBytes is less than
1734dst SkImageInfo::minRowBytes.
1735
Cary Clarkac47b882018-01-11 10:35:44 -05001736Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001737kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.info().colorType must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001738If Pixmap colorType is kGray_8_SkColorType, dst.info().colorSpace must match.
1739If Pixmap alphaType is kOpaque_SkAlphaType, dst.info().alphaType must
1740match. If Pixmap colorSpace is nullptr, dst.info().colorSpace must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001741false if pixel conversion is not possible.
1742
1743srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clarkac47b882018-01-11 10:35:44 -05001744false Pixmap width() or height() is zero or negative. Returns false if:
Cary Clark154beea2017-10-26 07:58:48 -04001745
Cary Clarkd0530ba2017-09-14 11:25:39 -04001746#Formula
Cary Clarkac47b882018-01-11 10:35:44 -05001747abs(srcX) >= Pixmap width()
Cary Clark6fc50412017-09-21 12:31:06 -04001748##
1749, or if
1750#Formula
Cary Clarkac47b882018-01-11 10:35:44 -05001751abs(srcY) >= Pixmap height()
Cary Clarkd0530ba2017-09-14 11:25:39 -04001752##
1753.
1754
1755#Param dst Image_Info and pixel address to write to ##
1756#Param srcX column index whose absolute value is less than width() ##
1757#Param srcY row index whose absolute value is less than height() ##
1758
1759#Return true if pixels are copied to dst ##
1760
1761#Example
1762#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001763void draw(SkCanvas* canvas) {
1764 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1765 std::vector<int32_t> srcPixels;
1766 const int rowBytes = image->width() * 4;
1767 srcPixels.resize(image->height() * rowBytes);
1768 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1769 image->readPixels(pixmap, 0, 0);
1770 for (int offset : { 32, 64, 96 } ) {
1771 std::vector<int32_t> dstPixels;
1772 dstPixels.resize(image->height() * rowBytes);
1773 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1774 pixmap.readPixels(dstmap, offset, 0);
1775 SkBitmap bitmap;
1776 bitmap.installPixels(dstmap);
1777 canvas->translate(32, 32);
1778 canvas->drawBitmap(bitmap, 0, 0);
1779 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001780}
1781##
1782
1783#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1784
1785##
1786
1787# ------------------------------------------------------------------------------
1788
1789#Method bool readPixels(const SkPixmap& dst) const
1790
1791Copies pixels inside bounds() to dst. dst specifies width, height, Color_Type,
1792Alpha_Type, and Color_Space of destination. Returns true if pixels are copied.
1793Returns false if dst.addr() equals nullptr, or dst.rowBytes is less than
1794dst SkImageInfo::minRowBytes.
1795
Cary Clarkac47b882018-01-11 10:35:44 -05001796Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001797kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001798If Pixmap colorType is kGray_8_SkColorType, dst Color_Space must match.
1799If Pixmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must
1800match. If Pixmap colorSpace is nullptr, dst Color_Space must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001801false if pixel conversion is not possible.
1802
Cary Clarkac47b882018-01-11 10:35:44 -05001803Returns false if Pixmap width() or height() is zero or negative.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001804
1805#Param dst Image_Info and pixel address to write to ##
1806
1807#Return true if pixels are copied to dst ##
1808
1809#Example
1810#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001811void draw(SkCanvas* canvas) {
1812 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1813 std::vector<int32_t> srcPixels;
1814 const int rowBytes = image->width() * 4;
1815 srcPixels.resize(image->height() * rowBytes);
1816 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1817 image->readPixels(pixmap, 0, 0);
1818 for (int index = 0; index < 3; ++index ) {
1819 std::vector<int32_t> dstPixels;
1820 dstPixels.resize(image->height() * rowBytes);
1821 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1822 pixmap.readPixels(dstmap);
1823 SkBitmap bitmap;
1824 bitmap.installPixels(dstmap);
1825 canvas->translate(32, 32);
1826 canvas->drawBitmap(bitmap, 0, 0);
1827 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001828}
1829##
1830
1831#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1832
1833##
1834
1835# ------------------------------------------------------------------------------
1836
1837#Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality) const
1838
Cary Clarkac47b882018-01-11 10:35:44 -05001839Copies Bitmap to dst, scaling pixels to fit dst.width() and dst.height(), and
Cary Clarkd0530ba2017-09-14 11:25:39 -04001840converting pixels to match dst.colorType and dst.alphaType. Returns true if
1841pixels are copied. Returns false if dst.addr() is nullptr, or dst.rowBytes is
1842less than dst SkImageInfo::minRowBytes.
1843
Cary Clarkac47b882018-01-11 10:35:44 -05001844Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001845kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001846If Pixmap colorType is kGray_8_SkColorType, dst Color_Space must match.
1847If Pixmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must
1848match. If Pixmap colorSpace is nullptr, dst Color_Space must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001849false if pixel conversion is not possible.
1850
Cary Clarkac47b882018-01-11 10:35:44 -05001851Returns false if Bitmap width() or height() is zero or negative.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001852
1853Scales the image, with filterQuality, to match dst.width() and dst.height().
1854filterQuality kNone_SkFilterQuality is fastest, typically implemented with
1855Filter_Quality_Nearest_Neighbor. kLow_SkFilterQuality is typically implemented with
1856Filter_Quality_Bilerp. kMedium_SkFilterQuality is typically implemented with
1857Filter_Quality_Bilerp, and Filter_Quality_MipMap when size is reduced.
1858kHigh_SkFilterQuality is slowest, typically implemented with Filter_Quality_BiCubic.
1859
1860#Param dst Image_Info and pixel address to write to ##
1861#Param filterQuality one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
1862 kMedium_SkFilterQuality, kHigh_SkFilterQuality
1863##
1864
Cary Clarkac47b882018-01-11 10:35:44 -05001865#Return true if pixels are scaled to fit dst ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001866
1867#Example
1868#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001869void draw(SkCanvas* canvas) {
1870 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1871 std::vector<int32_t> srcPixels;
1872 int rowBytes = image->width() * 4;
1873 srcPixels.resize(image->height() * rowBytes);
1874 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1875 image->readPixels(pixmap, 0, 0);
1876 for (int offset : { 32, 64, 96 } ) {
1877 info = SkImageInfo::MakeN32Premul(image->width() + offset, image->height());
1878 rowBytes = info.width() * 4;
1879 std::vector<int32_t> dstPixels;
1880 dstPixels.resize(image->height() * rowBytes);
1881 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1882 pixmap.scalePixels(dstmap, kMedium_SkFilterQuality);
1883 SkBitmap bitmap;
1884 bitmap.installPixels(dstmap);
1885 canvas->translate(32, 32);
1886 canvas->drawBitmap(bitmap, 0, 0);
1887 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001888}
1889##
1890
1891#SeeAlso SkCanvas::drawBitmap SkImage::scalePixels
1892
1893##
1894
1895# ------------------------------------------------------------------------------
1896
1897#Method bool erase(SkColor color, const SkIRect& subset) const
1898
1899Writes color to pixels bounded by subset; returns true on success.
1900Returns false if colorType is kUnknown_SkColorType, or if subset does
1901not intersect bounds().
1902
1903#Param color Unpremultiplied Color to write ##
1904#Param subset bounding integer Rect of written pixels ##
1905
1906#Return true if pixels are changed ##
1907
1908#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001909#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001910 uint32_t storage[2];
1911 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1912 SkPixmap pixmap(info, storage, info.minRowBytes());
1913 pixmap.erase(SK_ColorBLUE, {0, 0, 1, 1});
1914 pixmap.erase(SK_ColorRED, {0, 1, 1, 2});
1915 SkBitmap bitmap;
1916 canvas->scale(20, 20);
1917 bitmap.installPixels(pixmap);
1918 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001919##
1920
1921#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1922
1923##
1924
1925# ------------------------------------------------------------------------------
1926
1927#Method bool erase(SkColor color) const
1928
1929Writes color to pixels inside bounds(); returns true on success.
1930Returns false if colorType is kUnknown_SkColorType, or if bounds()
1931is empty.
1932
1933#Param color Unpremultiplied Color to write ##
1934
1935#Return true if pixels are changed ##
1936
1937#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001938#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001939 uint32_t storage[2];
1940 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1941 SkPixmap pixmap(info, storage, info.minRowBytes());
1942 pixmap.erase(SK_ColorBLUE);
1943 SkBitmap bitmap;
1944 canvas->scale(20, 20);
1945 bitmap.installPixels(pixmap);
1946 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001947##
1948
1949#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1950
1951##
1952
1953# ------------------------------------------------------------------------------
1954
1955#Method bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const
1956
1957Writes color to pixels bounded by subset; returns true on success.
1958if subset is nullptr, writes colors pixels inside bounds(). Returns false if
1959colorType is kUnknown_SkColorType, if subset is not nullptr and does
1960not intersect bounds(), or if subset is nullptr and bounds() is empty.
1961
1962#Param color Unpremultiplied Color to write ##
1963#Param subset bounding integer Rect of pixels to write; may be nullptr ##
1964
1965#Return true if pixels are changed ##
1966
1967#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001968#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001969 uint32_t storage[2];
1970 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1971 SkPixmap pixmap(info, storage, info.minRowBytes());
1972 SkIRect topPixelBounds = {0, 0, 1, 1};
1973 pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds);
1974 SkIRect bottomPixelBounds = {0, 1, 1, 2};
1975 pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds);
1976 SkBitmap bitmap;
1977 canvas->scale(20, 20);
1978 bitmap.installPixels(pixmap);
1979 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001980##
1981
1982#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1983
1984##
1985
1986
1987#Subtopic Writer ##
1988
1989#Class SkPixmap ##
1990
1991#Topic Pixmap ##