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