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