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