• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#Topic Pixmap
2#Alias Pixmap_Reference ##
3
4#Class SkPixmap
5
6#Code
7#Populate
8##
9
10Pixmap provides a utility to pair SkImageInfo with pixels and row bytes.
11Pixmap is a low level class which provides convenience functions to access
12raster destinations. Canvas can not draw Pixmap, nor does Pixmap provide
13a direct drawing destination.
14
15Use Bitmap to draw pixels referenced by Pixmap; use Surface to draw into
16pixels referenced by Pixmap.
17
18Pixmap does not try to manage the lifetime of the pixel memory. Use Pixel_Ref
19to manage pixel memory; Pixel_Ref is safe across threads.
20
21
22#Subtopic Initialization
23#Line # sets fields for use ##
24
25# ------------------------------------------------------------------------------
26
27#Method SkPixmap()
28
29#In Initialization
30#Line # constructs with default values ##
31#Populate
32
33#Example
34void draw(SkCanvas* canvas) {
35    const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
36    const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
37                            "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
38    SkPixmap pixmap;
39    for (int i = 0; i < 2; ++i) {
40       SkDebugf("width: %2d  height: %2d", pixmap.width(), pixmap.height());
41       SkDebugf("  color: k%s_SkColorType", colors[pixmap.colorType()]);
42       SkDebugf("  alpha: k%s_SkAlphaType\n", alphas[pixmap.alphaType()]);
43       pixmap.reset(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType),
44                    nullptr, 0);
45    }
46}
47#StdOut
48width:  0  height:  0  color: kUnknown_SkColorType  alpha: kUnknown_SkAlphaType
49width: 25  height: 35  color: kRGBA_8888_SkColorType  alpha: kOpaque_SkAlphaType
50##
51##
52
53#SeeAlso SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) reset() SkAlphaType SkColorType
54
55##
56
57# ------------------------------------------------------------------------------
58
59#Method SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes)
60
61#In Initialization
62#Line # constructs from Image_Info, pixels ##
63#Populate
64
65#Example
66#Image 3
67#Description
68SkImage::MakeRasterCopy takes const SkPixmap& as an argument. The example
69constructs a SkPixmap from the brace-delimited parameters.
70##
71    SkDebugf("image alpha only = %s\n", image->isAlphaOnly() ? "true" : "false");
72    SkPMColor pmColors = 0;
73    sk_sp<SkImage> copy = SkImage::MakeRasterCopy({SkImageInfo::MakeA8(1, 1),
74                                                  (uint8_t*)&pmColors,
75                                                  1});
76    SkDebugf("copy alpha only = %s\n", copy->isAlphaOnly() ? "true" : "false");
77#StdOut
78image alpha only = false
79copy alpha only = true
80##
81##
82
83#SeeAlso SkPixmap() reset() SkAlphaType SkColorType
84
85##
86
87# ------------------------------------------------------------------------------
88
89#Method void reset()
90
91#In Initialization
92#Line # reuses existing Pixmap with replacement values ##
93#Populate
94
95#Example
96void draw(SkCanvas* canvas) {
97    const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
98    const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
99                            "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
100    SkPixmap pixmap(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType),
101                    nullptr, 0);
102    for (int i = 0; i < 2; ++i) {
103       SkDebugf("width: %2d  height: %2d", pixmap.width(), pixmap.height());
104       SkDebugf("  color: k%s_SkColorType", colors[pixmap.colorType()]);
105       SkDebugf("  alpha: k%s_SkAlphaType\n", alphas[pixmap.alphaType()]);
106       pixmap.reset();
107    }
108}
109#StdOut
110width: 25  height: 35  color: kRGBA_8888_SkColorType  alpha: kOpaque_SkAlphaType
111width:  0  height:  0  color: kUnknown_SkColorType  alpha: kUnknown_SkAlphaType
112##
113##
114
115#SeeAlso SkPixmap() SkAlphaType SkColorType
116
117##
118
119# ------------------------------------------------------------------------------
120
121#Method void reset(const SkImageInfo& info, const void* addr, size_t rowBytes)
122
123#In Initialization
124#Populate
125
126#Example
127#Image 4
128#Height 64
129void draw(SkCanvas* canvas) {
130    std::vector<int32_t> pixels;
131    pixels.resize(image->height() * image->width() * 4);
132    SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
133            image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
134    image->readPixels(pixmap, 0, 0);
135    int x = 0;
136    for (auto colorType : { kRGBA_8888_SkColorType, kBGRA_8888_SkColorType } ) {
137        pixmap.reset(SkImageInfo::Make(image->width(), image->height(), colorType,
138                image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
139        SkBitmap bitmap;
140        bitmap.installPixels(pixmap);
141        canvas->drawBitmap(bitmap, x, 0);
142        x += 128;
143    }
144}
145##
146
147#SeeAlso SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) reset() SkAlphaType SkColorType
148
149##
150
151# ------------------------------------------------------------------------------
152
153#Method void setColorSpace(sk_sp<SkColorSpace> colorSpace)
154
155#In Initialization
156#Line # sets Image_Info Color_Space ##
157#Populate
158
159#Example
160void draw(SkCanvas* canvas) {
161    SkPixmap pixmap;
162    sk_sp<SkColorSpace> colorSpace1 = SkColorSpace::MakeRGB(SkNamedTransferFn::kLinear,
163                                                            SkNamedGamut::kRec2020);
164    SkDebugf("is %sunique\n", colorSpace1->unique() ? "" : "not ");
165    pixmap.setColorSpace(colorSpace1);
166    SkDebugf("is %sunique\n", colorSpace1->unique() ? "" : "not ");
167}
168#StdOut
169is unique
170is not unique
171##
172##
173
174#SeeAlso Color_Space SkImageInfo::makeColorSpace
175
176##
177
178# ------------------------------------------------------------------------------
179
180#Method bool extractSubset(SkPixmap* subset, const SkIRect& area) const
181
182#In Initialization
183#Line # sets pointer to portion of original ##
184#Populate
185
186#Example
187#Image 3
188#Height 128
189void draw(SkCanvas* canvas) {
190    std::vector<int32_t> pixels;
191    pixels.resize(image->height() * image->width() * 4);
192    SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
193            image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
194    image->readPixels(pixmap, 0, 0);
195    SkPixmap inset;
196    if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
197        SkBitmap bitmap;
198        bitmap.installPixels(inset);
199        canvas->drawBitmap(bitmap, 0, 0);
200    }
201}
202##
203
204#SeeAlso reset() SkIRect::intersect
205
206##
207
208#Subtopic Initialization ##
209
210#Subtopic Image_Info_Access
211#Line # returns all or part of Image_Info ##
212
213# ------------------------------------------------------------------------------
214
215#Method const SkImageInfo& info() const
216
217#In Image_Info_Access
218#Line # returns Image_Info ##
219#Populate
220
221#Example
222#Image 3
223    std::vector<int32_t> pixels;
224    pixels.resize(image->height() * image->width() * 4);
225    SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
226            image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
227    image->readPixels(pixmap, 0, 0);
228    SkPixmap inset;
229    if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
230        const SkImageInfo& info = inset.info();
231        const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
232        const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888",
233                "RGB_888x", "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
234        SkDebugf("width: %d height: %d color: %s alpha: %s\n", info.width(), info.height(),
235                 colors[info.colorType()], alphas[info.alphaType()]);
236    }
237#StdOut
238width: 384 height: 384 color: BGRA_8888 alpha: Opaque
239##
240##
241
242#SeeAlso Image_Info
243
244##
245
246# ------------------------------------------------------------------------------
247
248#Method size_t rowBytes() const
249
250#In Image_Info_Access
251#Line # returns interval between rows in bytes ##
252Returns row bytes, the interval from one pixel row to the next. Row bytes
253is at least as large as: #Formula # width() * info().bytesPerPixel() ##.
254
255Returns zero if colorType is kUnknown_SkColorType.
256It is up to the Bitmap creator to ensure that row bytes is a useful value.
257
258#Return  byte length of pixel row ##
259
260#Example
261SkPixmap badPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 2};
262SkPixmap okPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 8};
263for (auto& pixmap : { badPixmap, okPixmap } ) {
264    SkDebugf("rowBytes: %d minRowBytes: %d\n", pixmap.rowBytes(),
265       pixmap.info().minRowBytes());
266}
267#StdOut
268rowBytes: 2 minRowBytes: 4
269rowBytes: 8 minRowBytes: 4
270##
271##
272
273#SeeAlso addr() info() SkImageInfo::minRowBytes
274
275##
276
277# ------------------------------------------------------------------------------
278
279#Method const void* addr() const
280
281#In Image_Info_Access
282#Line # returns readable pixel address as void pointer ##
283#Populate
284
285#Example
286#Image 3
287    std::vector<int32_t> pixels;
288    pixels.resize(image->height() * image->width() * 4);
289    SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
290            image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
291    image->readPixels(pixmap, 0, 0);
292    SkDebugf("pixels address: 0x%llx\n", pixmap.addr());
293    SkPixmap inset;
294    if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
295         SkDebugf("inset address:  0x%llx\n", inset.addr());
296    }
297#StdOut
298#Volatile
299pixels address: 0x7f2a440bb010
300inset address:  0x7f2a440fb210
301##
302##
303
304#SeeAlso addr(int x, int y) addr8 addr16 addr32 addr64 info() rowBytes()
305
306##
307
308# ------------------------------------------------------------------------------
309
310#Method int width() const
311
312#In Image_Info_Access
313#Line # returns pixel column count ##
314Returns pixel count in each pixel row. Should be equal or less than:
315
316#Formula # rowBytes() / info().bytesPerPixel() ##.
317
318#Return  pixel width in Image_Info ##
319
320#Example
321    SkImageInfo info = SkImageInfo::MakeA8(16, 32);
322    SkPixmap pixmap(info, nullptr, 64);
323    SkDebugf("pixmap width: %d  info width: %d\n", pixmap.width(), info.width());
324#StdOut
325pixmap width: 16  info width: 16
326##
327##
328
329#SeeAlso height() SkImageInfo::width()
330
331##
332
333# ------------------------------------------------------------------------------
334
335#Method int height() const
336
337#In Image_Info_Access
338#Line # returns pixel row count ##
339#Populate
340
341#Example
342    SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
343    SkDebugf("pixmap height: %d  info height: %d\n", pixmap.height(), pixmap.info().height());
344#StdOut
345pixmap height: 32  info height: 32
346##
347##
348
349#SeeAlso width SkImageInfo::height
350
351##
352
353# ------------------------------------------------------------------------------
354
355#Method SkColorType colorType() const
356
357#In Image_Info_Access
358#Line # returns Image_Info Color_Type ##
359Returns Color_Type, one of: #list_of_color_types#.
360
361#Return  Color_Type in Image_Info ##
362
363#Example
364    const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
365                            "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
366    SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
367    SkDebugf("color type: k" "%s" "_SkColorType\n", colors[pixmap.colorType()]);
368#StdOut
369color type: kAlpha_8_SkColorType
370##
371##
372
373#SeeAlso alphaType() SkImageInfo::colorType
374
375##
376
377# ------------------------------------------------------------------------------
378
379#Method SkAlphaType alphaType() const
380
381#In Image_Info_Access
382#Line # returns Image_Info Alpha_Type ##
383Returns Alpha_Type, one of: #list_of_alpha_types#.
384
385#Return  Alpha_Type in Image_Info ##
386
387#Example
388    const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
389    SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
390    SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[pixmap.alphaType()]);
391#StdOut
392alpha type: kPremul_SkAlphaType
393##
394##
395
396#SeeAlso colorType() SkImageInfo::alphaType
397
398##
399
400# ------------------------------------------------------------------------------
401
402#Method SkColorSpace* colorSpace() const
403
404#In Image_Info_Access
405#Line # returns Image_Info Color_Space ##
406#Populate
407
408#Example
409#Description
410SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma
411and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma.
412##
413    SkPixmap pixmap(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
414            SkColorSpace::MakeSRGBLinear()), nullptr, 64);
415    SkColorSpace* colorSpace = pixmap.colorSpace();
416    SkDebugf("gammaCloseToSRGB: %s  gammaIsLinear: %s  isSRGB: %s\n",
417            colorSpace->gammaCloseToSRGB() ? "true" : "false",
418            colorSpace->gammaIsLinear() ? "true" : "false",
419            colorSpace->isSRGB() ? "true" : "false");
420#StdOut
421gammaCloseToSRGB: false  gammaIsLinear: true  isSRGB: false
422##
423##
424
425#SeeAlso Color_Space SkImageInfo::colorSpace
426
427##
428
429# ------------------------------------------------------------------------------
430
431#Method bool isOpaque() const
432
433#In Image_Info_Access
434#Line # returns true if Image_Info describes opaque pixels ##
435#Populate
436
437#Example
438#Description
439    isOpaque ignores whether all pixels are opaque or not.
440##
441    std::vector<uint32_t> pixels;
442    const int height = 2;
443    const int width = 2;
444    pixels.resize(height * width * 4);
445    SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType,
446            kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4);
447    for (int index = 0; index < 2; ++index) {
448        pixmap.erase(0x00000000);
449        SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false");
450        pixmap.erase(0xFFFFFFFF);
451        SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false");
452        pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType),
453                     (const void*) &pixels.front(), width * 4);
454    }
455#StdOut
456isOpaque: false
457isOpaque: false
458isOpaque: true
459isOpaque: true
460##
461##
462
463#SeeAlso computeIsOpaque SkImageInfo::isOpaque
464
465##
466
467# ------------------------------------------------------------------------------
468
469#Method SkIRect bounds() const
470
471#In Image_Info_Access
472#Line # returns width and height as Rectangle ##
473#Populate
474
475#Example
476    for (int width : { 0, 2 } ) {
477        for (int height : { 0, 2 } ) {
478             SkPixmap pixmap(SkImageInfo::MakeA8(width, height), nullptr, width);
479             SkDebugf("width: %d height: %d empty: %s\n", width, height,
480                      pixmap.bounds().isEmpty() ? "true" : "false");
481        }
482    }
483#StdOut
484width: 0 height: 0 empty: true
485width: 0 height: 2 empty: true
486width: 2 height: 0 empty: true
487width: 2 height: 2 empty: false
488##
489##
490
491#SeeAlso height() width() IRect
492
493##
494
495# ------------------------------------------------------------------------------
496
497#Method int rowBytesAsPixels() const
498
499#In Image_Info_Access
500#Line # returns interval between rows in pixels ##
501#Populate
502
503#Example
504    for (int rowBytes : { 4, 5, 6, 7, 8} ) {
505        SkPixmap pixmap(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), nullptr, rowBytes);
506        SkDebugf("rowBytes: %d rowBytesAsPixels: %d\n", rowBytes, pixmap.rowBytesAsPixels());
507    }
508#StdOut
509rowBytes: 4 rowBytesAsPixels: 1
510rowBytes: 5 rowBytesAsPixels: 1
511rowBytes: 6 rowBytesAsPixels: 1
512rowBytes: 7 rowBytesAsPixels: 1
513rowBytes: 8 rowBytesAsPixels: 2
514##
515##
516
517#SeeAlso rowBytes shiftPerPixel width SkImageInfo::bytesPerPixel
518
519##
520
521# ------------------------------------------------------------------------------
522
523#Method int shiftPerPixel() const
524
525#In Image_Info_Access
526#Line # returns bit shift from pixels to bytes ##
527#Populate
528
529#Example
530    const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
531                            "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
532    SkImageInfo info = SkImageInfo::MakeA8(1, 1);
533    for (SkColorType colorType : { kUnknown_SkColorType,   kAlpha_8_SkColorType,
534                                   kRGB_565_SkColorType,   kARGB_4444_SkColorType,
535                                   kRGBA_8888_SkColorType, kBGRA_8888_SkColorType,
536                                   kGray_8_SkColorType,    kRGBA_F16_SkColorType } ) {
537        SkPixmap pixmap(info.makeColorType(colorType), nullptr, 4);
538        SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d shiftPerPixel: %d\n",
539                colors[colorType], 10 - strlen(colors[colorType]), " ",
540                pixmap.info().bytesPerPixel(), pixmap.shiftPerPixel());
541    }
542#StdOut
543color: kUnknown_SkColorType   bytesPerPixel: 0 shiftPerPixel: 0
544color: kAlpha_8_SkColorType   bytesPerPixel: 1 shiftPerPixel: 0
545color: kRGB_565_SkColorType   bytesPerPixel: 2 shiftPerPixel: 1
546color: kARGB_4444_SkColorType bytesPerPixel: 2 shiftPerPixel: 1
547color: kRGBA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2
548color: kBGRA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2
549color: kGray_8_SkColorType    bytesPerPixel: 1 shiftPerPixel: 0
550color: kRGBA_F16_SkColorType  bytesPerPixel: 8 shiftPerPixel: 3
551##
552##
553
554#SeeAlso rowBytes rowBytesAsPixels width SkImageInfo::bytesPerPixel
555
556##
557
558# ------------------------------------------------------------------------------
559
560#Method size_t computeByteSize() const
561
562#In Image_Info_Access
563#Line # returns size required for pixels ##
564#Populate
565
566#Example
567    SkPixmap pixmap;
568    for (int width : { 1, 1000, 1000000 } ) {
569        for (int height: { 1, 1000, 1000000 } ) {
570            SkImageInfo imageInfo = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType);
571            pixmap.reset(imageInfo, nullptr, width * 5);
572            SkDebugf("width: %7d height: %7d computeByteSize: %13lld\n", width, height,
573                     pixmap.computeByteSize());
574        }
575    }
576#StdOut
577width:       1 height:       1 computeByteSize:             4
578width:       1 height:    1000 computeByteSize:          4999
579width:       1 height: 1000000 computeByteSize:       4999999
580width:    1000 height:       1 computeByteSize:          4000
581width:    1000 height:    1000 computeByteSize:       4999000
582width:    1000 height: 1000000 computeByteSize:    4999999000
583width: 1000000 height:       1 computeByteSize:       4000000
584width: 1000000 height:    1000 computeByteSize:    4999000000
585width: 1000000 height: 1000000 computeByteSize: 4999999000000
586##
587##
588
589#SeeAlso SkImageInfo::computeByteSize
590
591##
592
593#Subtopic Image_Info_Access ##
594
595#Subtopic Reader
596#Line # examine pixel value ##
597
598# ------------------------------------------------------------------------------
599
600#Method bool computeIsOpaque() const
601
602#In Reader
603#Line # returns true if all pixels are opaque ##
604#Populate
605
606#Example
607    std::vector<uint32_t> pixels;
608    const int height = 2;
609    const int width = 2;
610    pixels.resize(height * width * 4);
611    SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType,
612            kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4);
613    for (int index = 0; index < 2; ++index) {
614        pixmap.erase(0x00000000);
615        SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false");
616        pixmap.erase(0xFFFFFFFF);
617        SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false");
618        pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType),
619                     (const void*) &pixels.front(), width * 4);
620    }
621#StdOut
622computeIsOpaque: false
623computeIsOpaque: true
624computeIsOpaque: false
625computeIsOpaque: true
626##
627##
628
629#SeeAlso isOpaque Color_Type Alpha
630
631##
632
633# ------------------------------------------------------------------------------
634
635#Method SkColor getColor(int x, int y) const
636
637#In Reader
638#Line # returns one pixel as Unpremultiplied Color ##
639#Populate
640
641#Example
642    const int w = 4;
643    const int h = 4;
644    std::vector<SkPMColor> storage;
645    storage.resize(w * h);
646    SkDebugf("Premultiplied:\n");
647    for (int y = 0; y < h; ++y) {
648        SkDebugf("(0, %d) ", y);
649        for (int x = 0; x < w; ++x) {
650            int a = 0xFF * (x + y) / (w - 1 + h - 1);
651            storage[x + y * w] = SkPackARGB32(a, a * x / (w - 1), a * y / (h - 1), a);
652            SkDebugf("0x%08x%c", storage[x + y * w], x == w - 1 ? '\n' : ' ');
653        }
654    }
655    SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4);
656    SkDebugf("Unpremultiplied:\n");
657    for (int y = 0; y < h; ++y) {
658        SkDebugf("(0, %d) ", y);
659        for (int x = 0; x < w; ++x) {
660            SkDebugf("0x%08x%c", pixmap.getColor(x, y), x == w - 1 ? '\n' : ' ');
661        }
662    }
663#StdOut
664Premultiplied:
665(0, 0) 0x00000000 0x2a0e002a 0x55380055 0x7f7f007f
666(0, 1) 0x2a000e2a 0x551c1c55 0x7f542a7f 0xaaaa38aa
667(0, 2) 0x55003855 0x7f2a547f 0xaa7171aa 0xd4d48dd4
668(0, 3) 0x7f007f7f 0xaa38aaaa 0xd48dd4d4 0xffffffff
669Unpremultiplied:
670(0, 0) 0x00000000 0x2a5500ff 0x55a800ff 0x7fff00ff
671(0, 1) 0x2a0055ff 0x555454ff 0x7fa954ff 0xaaff54ff
672(0, 2) 0x5500a8ff 0x7f54a9ff 0xaaaaaaff 0xd4ffaaff
673(0, 3) 0x7f00ffff 0xaa54ffff 0xd4aaffff 0xffffffff
674##
675##
676
677#SeeAlso getAlphaf addr() readPixels
678
679##
680
681#Method float getAlphaf(int x, int y) const
682#In Property
683#Line # returns Alpha normalized from zero to one ##
684
685Looks up the pixel at (x,y) and return its alpha component, normalized to [0..1].
686This is roughly equivalent to #Formula # SkGetColorA(getColor()) ##, but can be more efficient
687(and more precise if the pixels store more than 8 bits per component).
688
689#Param x  column index, zero or greater, and less than width() ##
690#Param y  row index, zero or greater, and less than height() ##
691
692#Return   alpha converted to normalized float ##
693
694#NoExample
695##
696
697#SeeAlso getColor
698
699##
700
701#Subtopic Reader ##
702
703#Subtopic Readable_Address
704#Line # returns read only pixels ##
705
706# ------------------------------------------------------------------------------
707
708#Method const void* addr(int x, int y) const
709
710#In Readable_Address
711#Populate
712
713#Example
714    const int w = 4;
715    const int h = 4;
716    std::vector<SkPMColor> storage;
717    storage.resize(w * h);
718    SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4);
719    SkDebugf("pixmap.addr(1, 2) %c= &storage[1 + 2 * w]\n",
720              pixmap.addr(1, 2)  == &storage[1 + 2 * w] ? '=' : '!');
721#StdOut
722pixmap.addr(1, 2) == &storage[1 + 2 * w]
723##
724##
725
726#SeeAlso addr8 addr16 addr32 addr64 addrF16 getColor writable_addr SkBitmap::getAddr
727
728##
729
730# ------------------------------------------------------------------------------
731
732#Method const uint8_t* addr8() const
733
734#In Readable_Address
735#Line # returns readable pixel address as 8-bit pointer ##
736#Populate
737
738#Example
739    const int w = 4;
740    const int h = 4;
741    uint8_t storage[w * h];
742    SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType),
743                    storage, w * sizeof(storage[0]));
744    SkDebugf("pixmap.addr8() %c= storage\n",
745              pixmap.addr8()  == storage ? '=' : '!');
746#StdOut
747pixmap.addr8() == storage
748##
749##
750
751#SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8
752
753##
754
755# ------------------------------------------------------------------------------
756
757#Method const uint16_t* addr16() const
758
759#In Readable_Address
760#Line # returns readable pixel address as 16-bit pointer ##
761#Populate
762
763#Example
764    const int w = 4;
765    const int h = 4;
766    uint16_t storage[w * h];
767    SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType),
768                    storage, w * sizeof(storage[0]));
769    SkDebugf("pixmap.addr16() %c= storage\n",
770              pixmap.addr16()  == storage ? '=' : '!');
771#StdOut
772pixmap.addr16() == storage
773##
774##
775
776#SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16
777
778##
779
780# ------------------------------------------------------------------------------
781
782#Method const uint32_t* addr32() const
783
784#In Readable_Address
785#Line # returns readable pixel address as 32-bit pointer ##
786#Populate
787
788#Example
789    const int w = 4;
790    const int h = 4;
791    uint32_t storage[w * h];
792    SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType),
793                    storage, w * sizeof(storage[0]));
794    SkDebugf("pixmap.addr32() %c= storage\n",
795              pixmap.addr32()  == storage ? '=' : '!');
796#StdOut
797pixmap.addr32() == storage
798##
799##
800
801#SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr32
802
803##
804
805# ------------------------------------------------------------------------------
806
807#Method const uint64_t* addr64() const
808
809#In Readable_Address
810#Line # returns readable pixel address as 64-bit pointer ##
811#Populate
812
813#Example
814    const int w = 4;
815    const int h = 4;
816    uint64_t storage[w * h];
817    SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
818                    storage, w * sizeof(storage[0]));
819    SkDebugf("pixmap.addr64() %c= storage\n",
820              pixmap.addr64()  == storage ? '=' : '!');
821#StdOut
822pixmap.addr64() == storage
823##
824##
825
826#SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64
827
828##
829
830# ------------------------------------------------------------------------------
831
832#Method const uint16_t* addrF16() const
833
834#In Readable_Address
835#Line # returns readable pixel component address as 16-bit pointer ##
836#Populate
837
838#Example
839    const int w = 4;
840    const int h = 4;
841    uint16_t storage[w * h * 4];
842    SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
843                    storage, w * 4 * sizeof(storage[0]));
844    SkDebugf("pixmap.addrF16() %c= storage\n",
845              pixmap.addrF16()  == storage ? '=' : '!');
846#StdOut
847pixmap.addrF16() == storage
848##
849##
850
851#SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16
852
853##
854
855# ------------------------------------------------------------------------------
856
857#Method const uint8_t* addr8(int x, int y) const
858
859#In Readable_Address
860#Populate
861
862#Example
863    const int w = 4;
864    const int h = 4;
865    uint8_t storage[w * h];
866    SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType),
867                    storage, w * sizeof(storage[0]));
868    SkDebugf("pixmap.addr8(1, 2) %c= &storage[1 + 2 * w]\n",
869              pixmap.addr8(1, 2)  == &storage[1 + 2 * w] ? '=' : '!');
870#StdOut
871pixmap.addr8(1, 2) == &storage[1 + 2 * w]
872##
873##
874
875#SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8
876
877##
878
879# ------------------------------------------------------------------------------
880
881#Method const uint16_t* addr16(int x, int y) const
882
883#In Readable_Address
884#Populate
885
886#Example
887    const int w = 4;
888    const int h = 4;
889    uint16_t storage[w * h];
890    SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType),
891                    storage, w * sizeof(storage[0]));
892    SkDebugf("pixmap.addr16(1, 2) %c= &storage[1 + 2 * w]\n",
893              pixmap.addr16(1, 2)  == &storage[1 + 2 * w] ? '=' : '!');
894#StdOut
895pixmap.addr16(1, 2) == &storage[1 + 2 * w]
896##
897##
898
899#SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16
900
901##
902
903# ------------------------------------------------------------------------------
904
905#Method const uint32_t* addr32(int x, int y) const
906
907#In Readable_Address
908#Populate
909
910#Example
911    const int w = 4;
912    const int h = 4;
913    uint32_t storage[w * h];
914    SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_8888_SkColorType, kPremul_SkAlphaType),
915                    storage, w * sizeof(storage[0]));
916    SkDebugf("pixmap.addr32(1, 2) %c= &storage[1 + 2 * w]\n",
917              pixmap.addr32(1, 2)  == &storage[1 + 2 * w] ? '=' : '!');
918#StdOut
919pixmap.addr32(1, 2) == &storage[1 + 2 * w]
920##
921##
922
923#SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr64
924
925##
926
927# ------------------------------------------------------------------------------
928
929#Method const uint64_t* addr64(int x, int y) const
930
931#In Readable_Address
932#Populate
933
934#Example
935    const int w = 4;
936    const int h = 4;
937    uint64_t storage[w * h];
938    SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
939                    storage, w * sizeof(storage[0]));
940    SkDebugf("pixmap.addr64(1, 2) %c= &storage[1 + 2 * w]\n",
941              pixmap.addr64(1, 2)  == &storage[1 + 2 * w] ? '=' : '!');
942#StdOut
943pixmap.addr64(1, 2) == &storage[1 + 2 * w]
944##
945##
946
947#SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64
948
949##
950
951# ------------------------------------------------------------------------------
952
953#Method const uint16_t* addrF16(int x, int y) const
954
955#In Readable_Address
956#Populate
957
958#Example
959    const int w = 4;
960    const int h = 4;
961    const int wordsPerPixel = 4;
962    const int rowWords = w * wordsPerPixel;
963    uint16_t storage[rowWords * h];
964    SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
965                    storage, rowWords * sizeof(storage[0]));
966    SkDebugf("pixmap.addrF16(1, 2) %c= &storage[1 * wordsPerPixel + 2 * rowWords]\n",
967              pixmap.addrF16(1, 2)  == &storage[1 * wordsPerPixel + 2 * rowWords] ? '=' : '!');
968#StdOut
969pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords]
970##
971##
972
973#SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16
974
975##
976
977#Subtopic Readable_Address ##
978
979#Subtopic Writable_Address
980#Line # returns writable pixels ##
981
982# ------------------------------------------------------------------------------
983
984#Method void* writable_addr() const
985
986#In Writable_Address
987#Line # returns writable pixel address as void pointer ##
988#Populate
989
990#Example
991    const int w = 4;
992    const int h = 4;
993    SkPMColor storage[w * h * 4];
994    SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4);
995    SkDebugf("pixmap.writable_addr() %c= (void *)storage\n",
996              pixmap.writable_addr()  == (void *)storage ? '=' : '!');
997    pixmap.erase(0x00000000);
998    *(SkPMColor*)pixmap.writable_addr() = 0xFFFFFFFF;
999    SkDebugf("pixmap.getColor(0, 1) %c= 0x00000000\n",
1000              pixmap.getColor(0, 1)  == 0x00000000 ? '=' : '!');
1001    SkDebugf("pixmap.getColor(0, 0) %c= 0xFFFFFFFF\n",
1002              pixmap.getColor(0, 0)  == 0xFFFFFFFF ? '=' : '!');
1003#StdOut
1004pixmap.writable_addr() == (void *)storage
1005pixmap.getColor(0, 1) == 0x00000000
1006pixmap.getColor(0, 0) == 0xFFFFFFFF
1007##
1008##
1009
1010#SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr()
1011
1012##
1013
1014# ------------------------------------------------------------------------------
1015
1016#Method void* writable_addr(int x, int y) const
1017
1018#In Writable_Address
1019#Populate
1020
1021#Example
1022    const int w = 4;
1023    const int h = 4;
1024    SkPMColor storage[w * h * 4];
1025    SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4);
1026    SkDebugf("pixmap.writable_addr() %c= (void *)storage\n",
1027              pixmap.writable_addr()  == (void *)storage ? '=' : '!');
1028    pixmap.erase(0x00000000);
1029    *(SkPMColor*)pixmap.writable_addr(1, 2) = 0xFFFFFFFF;
1030    SkDebugf("pixmap.getColor(0, 0) %c= 0x00000000\n",
1031              pixmap.getColor(0, 0)  == 0x00000000 ? '=' : '!');
1032    SkDebugf("pixmap.getColor(1, 2) %c= 0xFFFFFFFF\n",
1033              pixmap.getColor(1, 2)  == 0xFFFFFFFF ? '=' : '!');
1034#StdOut
1035pixmap.writable_addr() == (void *)storage
1036pixmap.getColor(0, 0) == 0x00000000
1037pixmap.getColor(1, 2) == 0xFFFFFFFF
1038##
1039##
1040
1041#SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr()
1042
1043##
1044
1045# ------------------------------------------------------------------------------
1046
1047#Method uint8_t* writable_addr8(int x, int y) const
1048
1049#In Writable_Address
1050#Line # returns writable pixel address as 8-bit pointer ##
1051#Populate
1052
1053#Example
1054#Height 64
1055#Description
1056Altering pixels after drawing Bitmap is not guaranteed to affect subsequent
1057drawing on all platforms. Adding a second SkBitmap::installPixels after editing
1058pixel memory is safer.
1059##
1060void draw(SkCanvas* canvas) {
1061    uint8_t storage[][5] = {{ 0,   0,  64,   0,  0},
1062                            { 0, 128, 255, 128,  0},
1063                            {64, 255, 255, 255, 64},
1064                            { 0, 128, 255, 128,  0},
1065                            { 0,   0,  64,   0,  0}};
1066    SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kPremul_SkAlphaType);
1067    SkPixmap pixmap(imageInfo, storage[0], 5);
1068    SkBitmap bitmap;
1069    bitmap.installPixels(pixmap);
1070    canvas->scale(10, 10);
1071    canvas->drawBitmap(bitmap, 0, 0);
1072    *pixmap.writable_addr8(2, 2) = 0;
1073//  bitmap.installPixels(pixmap);      // uncomment to fix on GPU
1074    canvas->drawBitmap(bitmap, 10, 0);
1075}
1076##
1077
1078#SeeAlso writable_addr writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr() addr8
1079
1080##
1081
1082# ------------------------------------------------------------------------------
1083
1084#Method uint16_t* writable_addr16(int x, int y) const
1085
1086#In Writable_Address
1087#Line # returns writable pixel address as 16-bit pointer ##
1088#Populate
1089
1090#Example
1091#Description
1092Draw a five by five bitmap, and draw it again with a center black pixel.
1093The low nibble of the 16-bit word is Alpha.
1094##
1095#Height 64
1096    uint16_t storage[][5] = {{ 0xCABF, 0xDABE, 0xCA9D, 0xC96C, 0xA39B },
1097                             { 0xACEE, 0xA87C, 0x893A, 0x4779, 0x8708 },
1098                             { 0x4B7C, 0x255B, 0x2559, 0x2557, 0x4656 },
1099                             { 0x9099, 0x8128, 0x2557, 0x4124, 0x3323 },
1100                             { 0x7547, 0x5505, 0x4434, 0x2012, 0x0000 }};
1101    SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kARGB_4444_SkColorType, kPremul_SkAlphaType);
1102    SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
1103    SkBitmap bitmap;
1104    bitmap.installPixels(pixmap);
1105    canvas->scale(10, 10);
1106    canvas->drawBitmap(bitmap, 0, 0);
1107    *pixmap.writable_addr16(2, 2) = 0x000F;
1108    bitmap.installPixels(pixmap);
1109    canvas->drawBitmap(bitmap, 10, 0);
1110##
1111
1112#SeeAlso writable_addr writable_addr8 writable_addr32 writable_addr64 writable_addrF16 addr() addr16
1113
1114##
1115
1116# ------------------------------------------------------------------------------
1117
1118#Method uint32_t* writable_addr32(int x, int y) const
1119
1120#In Writable_Address
1121#Line # returns writable pixel address as 32-bit pointer ##
1122#Populate
1123
1124#Example
1125#Image 4
1126#Height 72
1127    std::vector<int32_t> pixels;
1128    pixels.resize(image->height() * image->width() * 4);
1129    SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
1130            image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
1131    image->readPixels(pixmap, 0, 0);
1132    for (int y = 0; y < pixmap.height() / 2; ++y) {
1133        for (int x = 0; x < pixmap.width(); ++x) {
1134            if ((x & 4) == (y & 4)) {
1135                *pixmap.writable_addr32(x, y) =
1136                        *pixmap.writable_addr32(pixmap.width() - x, pixmap.height() - y);
1137            }
1138        }
1139    }
1140    SkBitmap bitmap;
1141    bitmap.installPixels(pixmap);
1142    canvas->drawBitmap(bitmap, 0, 0);
1143##
1144
1145#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr64 writable_addrF16 addr() addr32
1146
1147##
1148
1149# ------------------------------------------------------------------------------
1150
1151#Method uint64_t* writable_addr64(int x, int y) const
1152
1153#In Writable_Address
1154#Line # returns writable pixel address as 64-bit pointer ##
1155#Populate
1156
1157#Example
1158#Height 40
1159    SkImageInfo info = SkImageInfo::Make(3, 3, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
1160    uint64_t storage[9];
1161    SkPixmap pixmap(info, storage, 3 * sizeof(uint64_t));
1162    SkColor4f c4 { 1, 0.45f, 0.25f, 0.65f };
1163    pixmap.erase(c4);
1164    SkBitmap bitmap;
1165    canvas->scale(10, 10);
1166    bitmap.installPixels(pixmap);
1167    canvas->drawBitmap(bitmap, 0, 0);
1168    *pixmap.writable_addr64(1, 1) |= 0x00ff000000000000LL;
1169    bitmap.installPixels(pixmap);
1170    canvas->drawBitmap(bitmap, 10, 0);
1171##
1172
1173#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addrF16 addr() addr64
1174
1175##
1176
1177# ------------------------------------------------------------------------------
1178
1179#Method uint16_t* writable_addrF16(int x, int y) const
1180
1181#In Writable_Address
1182#Line # returns writable pixel component address as 16-bit pointer ##
1183#Populate
1184
1185#Example
1186#Height 64
1187#Description
1188Left bitmap is drawn with two pixels defined in half float format. Right bitmap
1189is drawn after overwriting bottom half float color with top half float color.
1190##
1191    SkImageInfo info = SkImageInfo::Make(1, 2, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
1192    uint16_t storage[2][4];
1193    SkPixmap pixmap(info, storage[0], sizeof(uint64_t));
1194    SkIRect topPixelBounds = {0, 0, 1, 1};
1195    pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds);
1196    SkIRect bottomPixelBounds = {0, 1, 1, 2};
1197    pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds);
1198    SkBitmap bitmap;
1199    canvas->scale(20, 20);
1200    bitmap.installPixels(pixmap);
1201    canvas->drawBitmap(bitmap, 0, 0);
1202    uint16_t* pixel2 = pixmap.writable_addrF16(0, 1);
1203    for (int i = 0; i < 4; ++i) {
1204        pixel2[i] = storage[0][i];
1205    }
1206    bitmap.installPixels(pixmap);
1207    canvas->drawBitmap(bitmap, 4, 0);
1208##
1209
1210#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addr64 addr() addrF16
1211
1212##
1213
1214#Subtopic Writable_Address ##
1215
1216#Subtopic Pixels
1217#Line # read and write pixel values ##
1218##
1219
1220# ------------------------------------------------------------------------------
1221
1222#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes) const
1223#In Pixels
1224#Line # copies and converts pixels ##
1225#Populate
1226
1227#Example
1228#Height 128
1229#Description
1230Transferring the gradient from 8 bits per component to 4 bits per component
1231creates visible banding.
1232##
1233    std::vector<int32_t> pixels;
1234    const int width = 256;
1235    const int height = 64;
1236    pixels.resize(height * width * 4);
1237    SkImageInfo srcInfo = SkImageInfo::MakeN32Premul(width, height);
1238    SkPixmap srcPixmap(srcInfo, (const void*) &pixels.front(), width * 4);
1239    SkColor  gradColors[] = { 0xFFAA3300, 0x7F881122 };
1240    SkPoint  gradPoints[] = { { 0, 0 }, { 256, 0 } };
1241    SkPaint paint;
1242    paint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1243                    SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1244    SkBitmap bitmap;
1245    bitmap.installPixels(srcPixmap);
1246    SkCanvas srcCanvas(bitmap);
1247    srcCanvas.drawRect(SkRect::MakeWH(width, height), paint);
1248    canvas->drawBitmap(bitmap, 0, 0);
1249    std::vector<int32_t> dstPixels;
1250    dstPixels.resize(height * width * 2);
1251    SkImageInfo dstInfo = srcInfo.makeColorType(kARGB_4444_SkColorType);
1252    srcPixmap.readPixels(dstInfo, &dstPixels.front(), width * 2);
1253    SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2);
1254    bitmap.installPixels(dstPixmap);
1255    canvas->drawBitmap(bitmap, 0, 128);
1256##
1257
1258#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1259
1260##
1261
1262# ------------------------------------------------------------------------------
1263
1264#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX,
1265                    int srcY) const
1266
1267Copies a Rect of pixels to dstPixels. Copy starts at (srcX, srcY), and does not
1268exceed Pixmap (width(), height()).
1269
1270dstInfo specifies width, height, Color_Type, Alpha_Type, and
1271Color_Space of destination. dstRowBytes specifics the gap from one destination
1272row to the next. Returns true if pixels are copied. Returns false if
1273dstInfo has no address, or dstRowBytes is less than dstInfo.minRowBytes().
1274
1275Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
1276kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match.
1277If Pixmap colorType is kGray_8_SkColorType, dstInfo.colorSpace() must match.
1278If Pixmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType() must
1279match. If Pixmap colorSpace is nullptr, dstInfo.colorSpace() must match. Returns
1280false if pixel conversion is not possible.
1281
1282srcX and srcY may be negative to copy only top or left of source. Returns
1283false if Pixmap width() or height() is zero or negative. Returns false if:
1284
1285#Formula # abs(srcX) >= Pixmap width() ##, or if #Formula # abs(srcY) >= Pixmap height() ##.
1286
1287#Param dstInfo  destination width, height, Color_Type, Alpha_Type, Color_Space ##
1288#Param dstPixels  destination pixel storage ##
1289#Param dstRowBytes  destination row length ##
1290#Param srcX  column index whose absolute value is less than width() ##
1291#Param srcY  row index whose absolute value is less than height() ##
1292
1293#Return  true if pixels are copied to dstPixels ##
1294
1295#Example
1296#Image 3
1297void draw(SkCanvas* canvas) {
1298    SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1299    std::vector<int32_t> srcPixels;
1300    const int rowBytes = image->width() * 4;
1301    srcPixels.resize(image->height() * rowBytes);
1302    SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1303    image->readPixels(pixmap, 0, 0);
1304    for (int offset : { 32, 64, 96 } ) {
1305        std::vector<int32_t> dstPixels;
1306        dstPixels.resize(image->height() * rowBytes);
1307        pixmap.readPixels(info, &dstPixels.front(), rowBytes, offset, 0);
1308        SkBitmap bitmap;
1309        SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1310        bitmap.installPixels(dstmap);
1311        canvas->translate(32, 32);
1312        canvas->drawBitmap(bitmap, 0, 0);
1313    }
1314}
1315##
1316
1317#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1318
1319##
1320
1321# ------------------------------------------------------------------------------
1322
1323#Method bool readPixels(const SkPixmap& dst, int srcX, int srcY) const
1324
1325Copies a Rect of pixels to dst. Copy starts at (srcX, srcY), and does not
1326exceed Pixmap (width(), height()). dst specifies width, height, Color_Type,
1327Alpha_Type, and Color_Space of destination.  Returns true if pixels are copied.
1328Returns false if dst.addr() equals nullptr, or dst.rowBytes() is less than
1329dst SkImageInfo::minRowBytes.
1330
1331Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
1332kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.info().colorType() must match.
1333If Pixmap colorType is kGray_8_SkColorType, dst.info().colorSpace() must match.
1334If Pixmap alphaType is kOpaque_SkAlphaType, dst.info().alphaType() must
1335match. If Pixmap colorSpace is nullptr, dst.info().colorSpace() must match. Returns
1336false if pixel conversion is not possible.
1337
1338srcX and srcY may be negative to copy only top or left of source. Returns
1339false Pixmap width() or height() is zero or negative. Returns false if:
1340
1341#Formula # abs(srcX) >= Pixmap width() ##, or if #Formula # abs(srcY) >= Pixmap height() ##.
1342
1343#Param dst  Image_Info and pixel address to write to ##
1344#Param srcX  column index whose absolute value is less than width() ##
1345#Param srcY  row index whose absolute value is less than height() ##
1346
1347#Return  true if pixels are copied to dst ##
1348
1349#Example
1350#Image 3
1351void draw(SkCanvas* canvas) {
1352    SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1353    std::vector<int32_t> srcPixels;
1354    const int rowBytes = image->width() * 4;
1355    srcPixels.resize(image->height() * rowBytes);
1356    SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1357    image->readPixels(pixmap, 0, 0);
1358    for (int offset : { 32, 64, 96 } ) {
1359        std::vector<int32_t> dstPixels;
1360        dstPixels.resize(image->height() * rowBytes);
1361        SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1362        pixmap.readPixels(dstmap, offset, 0);
1363        SkBitmap bitmap;
1364        bitmap.installPixels(dstmap);
1365        canvas->translate(32, 32);
1366        canvas->drawBitmap(bitmap, 0, 0);
1367    }
1368}
1369##
1370
1371#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1372
1373##
1374
1375# ------------------------------------------------------------------------------
1376
1377#Method bool readPixels(const SkPixmap& dst) const
1378#Populate
1379
1380#Example
1381#Image 3
1382void draw(SkCanvas* canvas) {
1383    SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1384    std::vector<int32_t> srcPixels;
1385    const int rowBytes = image->width() * 4;
1386    srcPixels.resize(image->height() * rowBytes);
1387    SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1388    image->readPixels(pixmap, 0, 0);
1389    for (int index = 0; index < 3; ++index ) {
1390        std::vector<int32_t> dstPixels;
1391        dstPixels.resize(image->height() * rowBytes);
1392        SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1393        pixmap.readPixels(dstmap);
1394        SkBitmap bitmap;
1395        bitmap.installPixels(dstmap);
1396        canvas->translate(32, 32);
1397        canvas->drawBitmap(bitmap, 0, 0);
1398    }
1399}
1400##
1401
1402#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1403
1404##
1405
1406# ------------------------------------------------------------------------------
1407
1408#Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality) const
1409
1410#In Pixels
1411#Line # scales and converts pixels ##
1412#Populate
1413
1414#Example
1415#Image 3
1416void draw(SkCanvas* canvas) {
1417    SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1418    std::vector<int32_t> srcPixels;
1419    int rowBytes = image->width() * 4;
1420    srcPixels.resize(image->height() * rowBytes);
1421    SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1422    image->readPixels(pixmap, 0, 0);
1423    for (int offset : { 32, 64, 96 } ) {
1424        info = SkImageInfo::MakeN32Premul(image->width() + offset, image->height());
1425        rowBytes = info.width() * 4;
1426        std::vector<int32_t> dstPixels;
1427        dstPixels.resize(image->height() * rowBytes);
1428        SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1429        pixmap.scalePixels(dstmap, kMedium_SkFilterQuality);
1430        SkBitmap bitmap;
1431        bitmap.installPixels(dstmap);
1432        canvas->translate(32, 32);
1433        canvas->drawBitmap(bitmap, 0, 0);
1434    }
1435}
1436##
1437
1438#SeeAlso SkCanvas::drawBitmap SkImage::scalePixels
1439
1440##
1441
1442# ------------------------------------------------------------------------------
1443
1444#Method bool erase(SkColor color, const SkIRect& subset) const
1445
1446#In Pixels
1447#Line # writes Color to pixels ##
1448#Populate
1449
1450#Example
1451#Height 50
1452    uint32_t storage[2];
1453    SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1454    SkPixmap pixmap(info, storage, info.minRowBytes());
1455    pixmap.erase(SK_ColorBLUE, {0, 0, 1, 1});
1456    pixmap.erase(SK_ColorRED, {0, 1, 1, 2});
1457    SkBitmap bitmap;
1458    canvas->scale(20, 20);
1459    bitmap.installPixels(pixmap);
1460    canvas->drawBitmap(bitmap, 0, 0);
1461##
1462
1463#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1464
1465##
1466
1467# ------------------------------------------------------------------------------
1468
1469#Method bool erase(SkColor color) const
1470#Populate
1471
1472#Example
1473#Height 50
1474    uint32_t storage[2];
1475    SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1476    SkPixmap pixmap(info, storage, info.minRowBytes());
1477    pixmap.erase(SK_ColorBLUE);
1478    SkBitmap bitmap;
1479    canvas->scale(20, 20);
1480    bitmap.installPixels(pixmap);
1481    canvas->drawBitmap(bitmap, 0, 0);
1482##
1483
1484#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1485
1486##
1487
1488# ------------------------------------------------------------------------------
1489
1490#Method bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const
1491#Populate
1492
1493#Example
1494#Height 50
1495    uint32_t storage[2];
1496    SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1497    SkPixmap pixmap(info, storage, info.minRowBytes());
1498    SkIRect topPixelBounds = {0, 0, 1, 1};
1499    pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds);
1500    SkIRect bottomPixelBounds = {0, 1, 1, 2};
1501    pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds);
1502    SkBitmap bitmap;
1503    canvas->scale(20, 20);
1504    bitmap.installPixels(pixmap);
1505    canvas->drawBitmap(bitmap, 0, 0);
1506##
1507
1508#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1509
1510##
1511
1512#Class SkPixmap ##
1513
1514#Topic Pixmap ##
1515