blob: e06f70909abb38bac7928ddfbd1bd8baadef0775 [file] [log] [blame]
Cary Clarkd0530ba2017-09-14 11:25:39 -04001#Topic Pixmap
Cary Clarke4aa3712017-09-15 02:56:12 -04002#Alias Pixmap_Reference
3
Cary Clarkd0530ba2017-09-14 11:25:39 -04004#Class SkPixmap
5
6Pixmap provides a utility to pair SkImageInfo with pixels and row bytes.
7Pixmap is a low level class which provides convenience functions to access
8raster destinations. Canvas can not draw Pixmap, nor does Pixmap provide
9a direct drawing destination.
10
11Use Bitmap to draw pixels referenced by Pixmap; use Surface to draw into
12pixels referenced by Pixmap.
13
Cary Clarkbc5697d2017-10-04 14:31:33 -040014Pixmap does not try to manage the lifetime of the pixel memory. Use Pixel_Ref
15to manage pixel memory; Pixel_Ref is safe across threads.
Cary Clarkd0530ba2017-09-14 11:25:39 -040016
17#Topic Overview
18
19#Subtopic Subtopics
20#Table
21#Legend
22# topics # description ##
23#Legend ##
24# Image_Info_Access # Returns all or part of Image_Info. ##
25# Initialization # Sets fields for use. ##
26# Reader # Examine pixel value. ##
27# Writer # Copy to pixel values. ##
28# Readable_Address # Returns read only pixels. ##
29# Writable_Address # Returns writable pixels. ##
30#Table ##
31#Subtopic ##
32
33#Subtopic Constructors
34#Table
35#Legend
36# # description ##
37#Legend ##
38# SkPixmap() # Constructs with default values. ##
39# SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) # Constructs from Image_Info, pixels. ##
40#Table ##
41#Subtopic ##
42
43#Subtopic Member_Functions
44#Table
45#Legend
46# function # description ##
47#Legend ##
48# addr() # Returns readable pixel address as void pointer. ##
49# addr16 # Returns readable pixel address as 16-bit pointer. ##
50# addr32 # Returns readable pixel address as 32-bit pointer. ##
51# addr64 # Returns readable pixel address as 64-bit pointer. ##
52# addr8 # Returns readable pixel address as 8-bit pointer. ##
53# addrF16 # Returns readable pixel component address as 16-bit pointer. ##
54# alphaType # Returns Image_Info Alpha_Type. ##
55# bounds() # Returns width and height as Rectangle. ##
56# colorSpace # Returns Image_Info Color_Space. ##
57# colorType # Returns Image_Info Color_Type. ##
Cary Clark154beea2017-10-26 07:58:48 -040058# computeByteSize # Returns size required for pixels. ##
Cary Clarkd0530ba2017-09-14 11:25:39 -040059# computeIsOpaque # Returns true if all pixels are opaque. ##
60# erase() # Writes Color to pixels. ##
61# extractSubset # Sets pointer to portion of original. ##
62# getColor # Returns one pixel as Unpremultiplied Color. ##
Cary Clarkd0530ba2017-09-14 11:25:39 -040063# height() # Returns pixel row count. ##
64# info() # Returns Image_Info. ##
65# isOpaque # Returns true if Image_Info describes opaque pixels. ##
66# readPixels # Copies and converts pixels. ##
67# reset() # Reuses existing Pixmap with replacement values. ##
68# rowBytes # Returns interval between rows in bytes. ##
69# rowBytesAsPixels # Returns interval between rows in pixels. ##
70# scalePixels # Scales and converts pixels. ##
71# setColorSpace # Sets Image_Info Color_Space. ##
72# shiftPerPixel # Returns bit shift from pixels to bytes. ##
73# width() # Returns pixel column count. ##
74# writable_addr # Returns writable pixel address as void pointer. ##
75# writable_addr16 # Returns writable pixel address as 16-bit pointer. ##
76# writable_addr32 # Returns writable pixel address as 32-bit pointer. ##
77# writable_addr64 # Returns writable pixel address as 64-bit pointer. ##
78# writable_addr8 # Returns writable pixel address as 8-bit pointer. ##
79# writable_addrF16 # Returns writable pixel component address as 16-bit pointer. ##
80#Table ##
81#Subtopic ##
82
83#Topic Overview ##
84
85#Subtopic Initialization
86
87# ------------------------------------------------------------------------------
88
89#Method SkPixmap()
90
91Creates an empty Pixmap without pixels, with kUnknown_SkColorType, with
92kUnknown_SkAlphaType, and with a width and height of zero. Use
93reset() to associate pixels, SkColorType, SkAlphaType, width, and height
94after Pixmap has been created.
95
96#Return empty Pixmap ##
97
98#Example
Cary Clark6fc50412017-09-21 12:31:06 -040099void draw(SkCanvas* canvas) {
100 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
101 const char* colors[] = {"Unknown", "Alpha", "RGB_565", "ARGB_4444", "RGBA_8888", "BGRA_8888",
102 "Gray_8", "RGBA_F16"};
103 SkPixmap pixmap;
104 for (int i = 0; i < 2; ++i) {
105 SkDebugf("width: %2d height: %2d", pixmap.width(), pixmap.height());
106 SkDebugf(" color: k%s_SkColorType", colors[pixmap.colorType()]);
107 SkDebugf(" alpha: k%s_SkAlphaType\n", alphas[pixmap.alphaType()]);
108 pixmap.reset(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType),
109 nullptr, 0);
110 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400111}
112#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400113width: 0 height: 0 color: kUnknown_SkColorType alpha: kUnknown_SkAlphaType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400114width: 25 height: 35 color: kRGBA_8888_SkColorType alpha: kOpaque_SkAlphaType
115##
116##
117
118#SeeAlso SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) reset() SkAlphaType SkColorType
119
120##
121
122# ------------------------------------------------------------------------------
123
124#Method SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes)
125
126Creates Pixmap from info width, height, SkAlphaType, and SkColorType.
Cary Clark6fc50412017-09-21 12:31:06 -0400127addr points to pixels, or nullptr. rowBytes should be info.width() times
128info.bytesPerPixel(), or larger.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400129
130No parameter checking is performed; it is up to the caller to ensure that
131addr and rowBytes agree with info.
132
Cary Clark6fc50412017-09-21 12:31:06 -0400133The memory lifetime of pixels is managed by the caller. When Pixmap goes
Cary Clarkd0530ba2017-09-14 11:25:39 -0400134out of scope, addr is unaffected.
135
136Pixmap may be later modified by reset() to change its size, pixel type, or
137storage.
138
139#Param info width, height, SkAlphaType, SkColorType of Image_Info ##
140#Param addr pointer to pixels allocated by caller; may be nullptr ##
141#Param rowBytes size of one row of addr; width times pixel size, or larger ##
142
143#Return initialized Pixmap ##
144
145#Example
146#Image 3
147#Description
148SkImage::MakeRasterCopy takes const SkPixmap& as an argument. The example
149constructs a SkPixmap from the brace-delimited parameters.
150##
Cary Clark6fc50412017-09-21 12:31:06 -0400151 SkDebugf("image alpha only = %s\n", image->isAlphaOnly() ? "true" : "false");
152 SkPMColor pmColors = 0;
153 sk_sp<SkImage> copy = SkImage::MakeRasterCopy({SkImageInfo::MakeA8(1, 1),
154 (uint8_t*)&pmColors,
155 1});
Cary Clarkd0530ba2017-09-14 11:25:39 -0400156 SkDebugf("copy alpha only = %s\n", copy->isAlphaOnly() ? "true" : "false");
157#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400158image alpha only = false
Cary Clarkd0530ba2017-09-14 11:25:39 -0400159copy alpha only = true
160##
161##
162
163#SeeAlso SkPixmap() reset() SkAlphaType SkColorType
164
165##
166
167# ------------------------------------------------------------------------------
168
169#Method void reset()
170
171Sets width, height, row bytes to zero; pixel address to nullptr; SkColorType to
172kUnknown_SkColorType; and SkAlphaType to kUnknown_SkAlphaType.
173
174The prior pixels are unaffected; it is up to the caller to release pixels
175memory if desired.
176
177#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400178void draw(SkCanvas* canvas) {
179 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
180 const char* colors[] = {"Unknown", "Alpha", "RGB_565", "ARGB_4444", "RGBA_8888", "BGRA_8888",
181 "Gray_8", "RGBA_F16"};
182 SkPixmap pixmap(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType),
183 nullptr, 0);
184 for (int i = 0; i < 2; ++i) {
185 SkDebugf("width: %2d height: %2d", pixmap.width(), pixmap.height());
186 SkDebugf(" color: k%s_SkColorType", colors[pixmap.colorType()]);
187 SkDebugf(" alpha: k%s_SkAlphaType\n", alphas[pixmap.alphaType()]);
188 pixmap.reset();
189 }
190}
Cary Clarkd0530ba2017-09-14 11:25:39 -0400191#StdOut
192width: 25 height: 35 color: kRGBA_8888_SkColorType alpha: kOpaque_SkAlphaType
Cary Clark6fc50412017-09-21 12:31:06 -0400193width: 0 height: 0 color: kUnknown_SkColorType alpha: kUnknown_SkAlphaType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400194##
195##
196
197#SeeAlso SkPixmap() SkAlphaType SkColorType
198
199##
200
201# ------------------------------------------------------------------------------
202
203#Method void reset(const SkImageInfo& info, const void* addr, size_t rowBytes)
204
205Sets width, height, SkAlphaType, and SkColorType from info.
206Sets pixel address from addr, which may be nullptr.
Cary Clark6fc50412017-09-21 12:31:06 -0400207Sets row bytes from rowBytes, which should be info.width() times
208info.bytesPerPixel(), or larger.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400209
210Does not check addr. Asserts if built with SK_DEBUG defined and if rowBytes is
211too small to hold one row of pixels.
212
213The memory lifetime pixels are managed by the caller. When Pixmap goes
214out of scope, addr is unaffected.
215
216#Param info width, height, SkAlphaType, SkColorType of Image_Info ##
217#Param addr pointer to pixels allocated by caller; may be nullptr ##
218#Param rowBytes size of one row of addr; width times pixel size, or larger ##
219
220#Example
221#Image 4
Cary Clark2ade9972017-11-02 17:49:34 -0400222#Height 64
Cary Clark6fc50412017-09-21 12:31:06 -0400223void draw(SkCanvas* canvas) {
224 std::vector<int32_t> pixels;
225 pixels.resize(image->height() * image->width() * 4);
226 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
227 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
228 image->readPixels(pixmap, 0, 0);
229 int x = 0;
230 for (auto colorType : { kRGBA_8888_SkColorType, kBGRA_8888_SkColorType } ) {
231 pixmap.reset(SkImageInfo::Make(image->width(), image->height(), colorType,
232 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
233 SkBitmap bitmap;
234 bitmap.installPixels(pixmap);
235 canvas->drawBitmap(bitmap, x, 0);
236 x += 128;
237 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400238}
239##
240
241#SeeAlso SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) reset() SkAlphaType SkColorType
242
243##
244
245# ------------------------------------------------------------------------------
246
247#Method void setColorSpace(sk_sp<SkColorSpace> colorSpace)
248
249
250Changes Color_Space in Image_Info; preserves width, height, SkAlphaType, and
251SkColorType in Image, and leaves pixel address and row bytes unchanged.
Cary Clark6fc50412017-09-21 12:31:06 -0400252Color_Space reference count is incremented.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400253
254#Param colorSpace Color_Space moved to Image_Info ##
255
256#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400257void draw(SkCanvas* canvas) {
258 SkPixmap pixmap;
259 sk_sp<SkColorSpace> colorSpace1 = SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma,
260 SkColorSpace::kRec2020_Gamut);
261 SkDebugf("is %sunique\n", colorSpace1->unique() ? "" : "not ");
262 pixmap.setColorSpace(colorSpace1);
263 SkDebugf("is %sunique\n", colorSpace1->unique() ? "" : "not ");
Cary Clarkd0530ba2017-09-14 11:25:39 -0400264}
265#StdOut
266is unique
267is not unique
268##
269##
270
271#SeeAlso Color_Space SkImageInfo::makeColorSpace
272
273##
274
275# ------------------------------------------------------------------------------
276
277#Method bool SK_WARN_UNUSED_RESULT reset(const SkMask& mask)
278
279Sets width, height, pixel address, and row bytes to Mask properties, if Mask
280format is SkMask::kA8_Format; and returns true. Otherwise sets width, height,
281row bytes to zero; pixel address to nullptr; SkColorType to kUnknown_SkColorType;
282and SkAlphaType to kUnknown_SkAlphaType; and returns false.
283
284Failing to read the return value generates a compile time warning.
285
286#Param mask Mask containing pixels and dimensions ##
287
288#Return true if set to Mask properties ##
289
290#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400291 const int width = 2;
292 const int height = 2;
293 uint8_t bytes[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
294 SkMask mask;
295 mask.fFormat = SkMask::kA8_Format;
296 mask.fBounds = {0, 0, width, height};
297 mask.fImage = bytes;
298 mask.fRowBytes = (width + 7) >> 3;
299 SkPixmap pixmap;
300 bool success = pixmap.reset(mask);
301 SkDebugf("success: %s width: %d height: %d\n", success ? "true " : "false",
302 pixmap.width(), pixmap.height());
303 mask.fFormat = SkMask::kBW_Format;
304 success = pixmap.reset(mask);
305 SkDebugf("success: %s width: %d height: %d\n", success ? "true " : "false",
306 pixmap.width(), pixmap.height());
307#StdOut
308success: true width: 2 height: 2
309success: false width: 0 height: 0
310##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400311##
312
313#SeeAlso Mask reset()
314
315##
316
317# ------------------------------------------------------------------------------
318
319#Method bool SK_WARN_UNUSED_RESULT extractSubset(SkPixmap* subset, const SkIRect& area) const
320
321Sets subset width, height, pixel address to intersection of Pixmap with area,
322if intersection is not empty; and return true. Otherwise, leave subset unchanged
323and return false.
324
325Failing to read the return value generates a compile time warning.
326
327#Param subset storage for width, height, pixel address of intersection ##
328#Param area bounds to intersect with Pixmap ##
329
330#Return true if intersection of Pixmap and area is not empty ##
331
332#Example
333#Image 3
334#Height 128
Cary Clark6fc50412017-09-21 12:31:06 -0400335void draw(SkCanvas* canvas) {
336 std::vector<int32_t> pixels;
337 pixels.resize(image->height() * image->width() * 4);
338 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
339 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
340 image->readPixels(pixmap, 0, 0);
341 SkPixmap inset;
342 if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
343 SkBitmap bitmap;
344 bitmap.installPixels(inset);
345 canvas->drawBitmap(bitmap, 0, 0);
346 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400347}
348##
349
350#SeeAlso reset() SkIRect::intersect
351
352##
353
354#Subtopic Initialization ##
355
356#Subtopic Image_Info_Access
357
358# ------------------------------------------------------------------------------
359
360#Method const SkImageInfo& info() const
361
Cary Clark6fc50412017-09-21 12:31:06 -0400362Returns width, height, Alpha_Type, Color_Type, and Color_Space.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400363
364#Return reference to ImageInfo ##
365
366#Example
367#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -0400368 std::vector<int32_t> pixels;
369 pixels.resize(image->height() * image->width() * 4);
370 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
371 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
372 image->readPixels(pixmap, 0, 0);
373 SkPixmap inset;
374 if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
375 const SkImageInfo& info = inset.info();
376 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
377 const char* colors[] = {"Unknown", "Alpha", "RGB_565", "ARGB_4444",
378 "RGBA_8888", "BGRA_8888", "Gray_8", "RGBA_F16"};
379 SkDebugf("width: %d height: %d color: %s alpha: %s\n", info.width(), info.height(),
380 colors[info.colorType()], alphas[info.alphaType()]);
381 }
382#StdOut
383width: 384 height: 384 color: BGRA_8888 alpha: Opaque
384##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400385##
386
387#SeeAlso Image_Info
388
389##
390
391# ------------------------------------------------------------------------------
392
393#Method size_t rowBytes() const
394
395Returns row bytes, the interval from one pixel row to the next. Row bytes
Cary Clark154beea2017-10-26 07:58:48 -0400396is at least as large as:
Cary Clarkd0530ba2017-09-14 11:25:39 -0400397#Formula
398width() * info().bytesPerPixel()
399##
400.
401
Cary Clarkbc5697d2017-10-04 14:31:33 -0400402Returns zero if colorType is kUnknown_SkColorType.
403It is up to the Bitmap creator to ensure that row bytes is a useful value.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400404
405#Return byte length of pixel row ##
406
407#Example
408SkPixmap badPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 2};
409SkPixmap okPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 8};
410for (auto& pixmap : { badPixmap, okPixmap } ) {
411 SkDebugf("rowBytes: %d minRowBytes: %d\n", pixmap.rowBytes(),
412 pixmap.info().minRowBytes());
413}
414#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400415rowBytes: 2 minRowBytes: 4
Cary Clarkd0530ba2017-09-14 11:25:39 -0400416rowBytes: 8 minRowBytes: 4
417##
418##
419
420#SeeAlso addr() info() SkImageInfo::minRowBytes
421
422##
423
424# ------------------------------------------------------------------------------
425
426#Method const void* addr() const
427
Cary Clark6fc50412017-09-21 12:31:06 -0400428Returns pixel address, the base address corresponding to the pixel origin.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400429
430It is up to the Pixmap creator to ensure that pixel address is a useful value.
431
432#Return pixel address ##
433
434#Example
435#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -0400436 std::vector<int32_t> pixels;
437 pixels.resize(image->height() * image->width() * 4);
438 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
439 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
440 image->readPixels(pixmap, 0, 0);
441 SkDebugf("pixels address: 0x%llx\n", pixmap.addr());
442 SkPixmap inset;
443 if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
444 SkDebugf("inset address: 0x%llx\n", inset.addr());
445 }
446#StdOut
447#Volatile
448pixels address: 0x7f2a440bb010
449inset address: 0x7f2a440fb210
450##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400451##
452
453#SeeAlso addr(int x, int y) addr8 addr16 addr32 addr64 info() rowBytes()
454
455##
456
457# ------------------------------------------------------------------------------
458
459#Method int width() const
460
461Returns pixel count in each pixel row. Should be equal or less than:
Cary Clark154beea2017-10-26 07:58:48 -0400462
Cary Clarkd0530ba2017-09-14 11:25:39 -0400463#Formula
Cary Clarkbc5697d2017-10-04 14:31:33 -0400464rowBytes() / info().bytesPerPixel()
Cary Clarkd0530ba2017-09-14 11:25:39 -0400465##
466.
467
468#Return pixel width in Image_Info ##
469
470#Example
471 SkImageInfo info = SkImageInfo::MakeA8(16, 32);
Cary Clark6fc50412017-09-21 12:31:06 -0400472 SkPixmap pixmap(info, nullptr, 64);
473 SkDebugf("pixmap width: %d info width: %d\n", pixmap.width(), info.width());
474#StdOut
475pixmap width: 16 info width: 16
476##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400477##
478
Cary Clarkbc5697d2017-10-04 14:31:33 -0400479#SeeAlso height() SkImageInfo::width()
Cary Clarkd0530ba2017-09-14 11:25:39 -0400480
481##
482
483# ------------------------------------------------------------------------------
484
485#Method int height() const
486
487Returns pixel row count.
488
489#Return pixel height in Image_Info ##
490
491#Example
Cary Clarkbc5697d2017-10-04 14:31:33 -0400492 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
493 SkDebugf("pixmap height: %d info height: %d\n", pixmap.height(), pixmap.info().height());
Cary Clark6fc50412017-09-21 12:31:06 -0400494#StdOut
495pixmap height: 32 info height: 32
496##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400497##
498
Cary Clarkbc5697d2017-10-04 14:31:33 -0400499#SeeAlso width() ImageInfo::height()
Cary Clarkd0530ba2017-09-14 11:25:39 -0400500
501##
502
503# ------------------------------------------------------------------------------
504
505#Method SkColorType colorType() const
506
507Returns Color_Type, one of: kUnknown_SkColorType, kAlpha_8_SkColorType,
508kRGB_565_SkColorType, kARGB_4444_SkColorType, kRGBA_8888_SkColorType,
509kBGRA_8888_SkColorType, kGray_8_SkColorType, kRGBA_F16_SkColorType.
510
511#Return Color_Type in Image_Info ##
512
513#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400514 const char* colors[] = {"Unknown", "Alpha", "RGB_565", "ARGB_4444",
515 "RGBA_8888", "BGRA_8888", "Gray_8", "RGBA_F16"};
516 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
517 SkDebugf("color type: k" "%s" "_SkColorType\n", colors[pixmap.colorType()]);
518#StdOut
Cary Clarkd0530ba2017-09-14 11:25:39 -0400519color type: kAlpha_SkColorType
Cary Clark6fc50412017-09-21 12:31:06 -0400520##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400521##
522
Cary Clarkbc5697d2017-10-04 14:31:33 -0400523#SeeAlso alphaType() SkImageInfo::colorType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400524
525##
526
527# ------------------------------------------------------------------------------
528
529#Method SkAlphaType alphaType() const
530
531Returns Alpha_Type, one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType,
532kPremul_SkAlphaType, kUnpremul_SkAlphaType.
533
534#Return Alpha_Type in Image_Info ##
535
536#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400537 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
538 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
539 SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[pixmap.alphaType()]);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400540#StdOut
541alpha type: kPremul_SkAlphaType
542##
543##
544
Cary Clarkbc5697d2017-10-04 14:31:33 -0400545#SeeAlso colorType() SkImageInfo::alphaType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400546
547##
548
549# ------------------------------------------------------------------------------
550
551#Method SkColorSpace* colorSpace() const
552
Cary Clarkbc5697d2017-10-04 14:31:33 -0400553Returns Color_Space associated with Image_Info. The
554reference count of Color_Space is unchanged. The returned Color_Space is
555immutable.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400556
Cary Clarkbc5697d2017-10-04 14:31:33 -0400557#Return Color_Space, the range of colors, in Image_Info ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400558
559#Example
560#Description
561SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma
562and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma.
563##
Cary Clark6fc50412017-09-21 12:31:06 -0400564 SkPixmap pixmap(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
565 SkColorSpace::MakeSRGBLinear()), nullptr, 64);
566 SkColorSpace* colorSpace = pixmap.colorSpace();
567 SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
568 colorSpace->gammaCloseToSRGB() ? "true" : "false",
569 colorSpace->gammaIsLinear() ? "true" : "false",
570 colorSpace->isSRGB() ? "true" : "false");
571#StdOut
572gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
573##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400574##
575
Cary Clarkbc5697d2017-10-04 14:31:33 -0400576#SeeAlso Color_Space SkImageInfo::colorSpace
Cary Clarkd0530ba2017-09-14 11:25:39 -0400577
578##
579
580# ------------------------------------------------------------------------------
581
582#Method bool isOpaque() const
583
584Returns true if Alpha_Type is kOpaque_SkAlphaType.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400585Does not check if Color_Type allows Alpha, or if any pixel value has
586transparency.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400587
588#Return true if Image_Info has opaque Alpha_Type ##
589
590#Example
591#Description
592 isOpaque ignores whether all pixels are opaque or not.
593##
Cary Clark6fc50412017-09-21 12:31:06 -0400594 std::vector<uint32_t> pixels;
595 const int height = 2;
596 const int width = 2;
597 pixels.resize(height * width * 4);
598 SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType,
599 kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4);
600 for (int index = 0; index < 2; ++index) {
601 pixmap.erase(0x00000000);
602 SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false");
603 pixmap.erase(0xFFFFFFFF);
604 SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false");
605 pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType),
606 (const void*) &pixels.front(), width * 4);
607 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400608#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400609isOpaque: false
610isOpaque: false
611isOpaque: true
Cary Clarkd0530ba2017-09-14 11:25:39 -0400612isOpaque: true
613##
614##
615
616#SeeAlso computeIsOpaque SkImageInfo::isOpaque
617
618##
619
620# ------------------------------------------------------------------------------
621
622#Method SkIRect bounds() const
623
Cary Clark154beea2017-10-26 07:58:48 -0400624Returns IRect { 0, 0, width(), height() }.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400625
626#Return integral rectangle from origin to width() and height() ##
627
628#Example
629 for (int width : { 0, 2 } ) {
630 for (int height : { 0, 2 } ) {
Cary Clark6fc50412017-09-21 12:31:06 -0400631 SkPixmap pixmap(SkImageInfo::MakeA8(width, height), nullptr, width);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400632 SkDebugf("width: %d height: %d empty: %s\n", width, height,
633 pixmap.bounds().isEmpty() ? "true" : "false");
634 }
635 }
636#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400637width: 0 height: 0 empty: true
638width: 0 height: 2 empty: true
639width: 2 height: 0 empty: true
Cary Clarkd0530ba2017-09-14 11:25:39 -0400640width: 2 height: 2 empty: false
641##
642##
643
644#SeeAlso height() width() IRect
645
646##
647
648# ------------------------------------------------------------------------------
649
650#Method int rowBytesAsPixels() const
651
652
653Returns number of pixels that fit on row. Should be greater than or equal to
654width().
655
656#Return maximum pixels per row ##
657
658#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400659 for (int rowBytes : { 4, 5, 6, 7, 8} ) {
660 SkPixmap pixmap(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), nullptr, rowBytes);
661 SkDebugf("rowBytes: %d rowBytesAsPixels: %d\n", rowBytes, pixmap.rowBytesAsPixels());
662 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400663#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400664rowBytes: 4 rowBytesAsPixels: 1
665rowBytes: 5 rowBytesAsPixels: 1
666rowBytes: 6 rowBytesAsPixels: 1
667rowBytes: 7 rowBytesAsPixels: 1
Cary Clarkd0530ba2017-09-14 11:25:39 -0400668rowBytes: 8 rowBytesAsPixels: 2
669##
670##
671
672#SeeAlso rowBytes shiftPerPixel width SkImageInfo::bytesPerPixel
673
674##
675
676# ------------------------------------------------------------------------------
677
678#Method int shiftPerPixel() const
679
680Returns bit shift converting row bytes to row pixels.
681Returns zero for kUnknown_SkColorType.
682
683#Return one of: 0, 1, 2, 3; left shift to convert pixels to bytes ##
684
685#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400686 const char* colors[] = {"Unknown", "Alpha", "RGB_565", "ARGB_4444",
687 "RGBA_8888", "BGRA_8888", "Gray_8", "RGBA_F16"};
688 SkImageInfo info = SkImageInfo::MakeA8(1, 1);
689 for (SkColorType colorType : { kUnknown_SkColorType, kAlpha_8_SkColorType,
690 kRGB_565_SkColorType, kARGB_4444_SkColorType,
691 kRGBA_8888_SkColorType, kBGRA_8888_SkColorType,
692 kGray_8_SkColorType, kRGBA_F16_SkColorType } ) {
693 SkPixmap pixmap(info.makeColorType(colorType), nullptr, 4);
694 SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d shiftPerPixel: %d\n",
695 colors[colorType], 10 - strlen(colors[colorType]), " ",
696 pixmap.info().bytesPerPixel(), pixmap.shiftPerPixel());
697 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400698#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400699color: kUnknown_SkColorType bytesPerPixel: 0 shiftPerPixel: 0
700color: kAlpha_SkColorType bytesPerPixel: 1 shiftPerPixel: 0
701color: kRGB_565_SkColorType bytesPerPixel: 2 shiftPerPixel: 1
702color: kARGB_4444_SkColorType bytesPerPixel: 2 shiftPerPixel: 1
703color: kRGBA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2
704color: kBGRA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2
705color: kGray_8_SkColorType bytesPerPixel: 1 shiftPerPixel: 0
Cary Clarkd0530ba2017-09-14 11:25:39 -0400706color: kRGBA_F16_SkColorType bytesPerPixel: 8 shiftPerPixel: 3
707##
708##
709
710#SeeAlso rowBytes rowBytesAsPixels width SkImageInfo::bytesPerPixel
711
712##
713
714# ------------------------------------------------------------------------------
715
Cary Clarkbc5697d2017-10-04 14:31:33 -0400716#Method size_t computeByteSize() const
717
718Returns minimum memory required for pixel storage.
719Does not include unused memory on last row when rowBytesAsPixels exceeds width().
720Returns zero if result does not fit in size_t.
721Returns zero if height() or width() is 0.
722Returns height() times rowBytes if colorType is kUnknown_SkColorType.
723
724#Return size in bytes of image buffer ##
725
Cary Clarkd0530ba2017-09-14 11:25:39 -0400726#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400727 SkPixmap pixmap;
728 for (int width : { 1, 1000, 1000000 } ) {
729 for (int height: { 1, 1000, 1000000 } ) {
730 SkImageInfo imageInfo = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType);
Cary Clarkbc5697d2017-10-04 14:31:33 -0400731 pixmap.reset(imageInfo, nullptr, width * 5);
732 SkDebugf("width: %7d height: %7d computeByteSize: %13lld\n", width, height,
733 pixmap.computeByteSize());
Cary Clark6fc50412017-09-21 12:31:06 -0400734 }
735 }
Cary Clark6fc50412017-09-21 12:31:06 -0400736#StdOut
Ben Wagner29380bd2017-10-09 14:43:00 -0400737width: 1 height: 1 computeByteSize: 4
738width: 1 height: 1000 computeByteSize: 4999
739width: 1 height: 1000000 computeByteSize: 4999999
740width: 1000 height: 1 computeByteSize: 4000
741width: 1000 height: 1000 computeByteSize: 4999000
742width: 1000 height: 1000000 computeByteSize: 4999999000
743width: 1000000 height: 1 computeByteSize: 4000000
744width: 1000000 height: 1000 computeByteSize: 4999000000
Cary Clarkbc5697d2017-10-04 14:31:33 -0400745width: 1000000 height: 1000000 computeByteSize: 4999999000000
Cary Clarkd0530ba2017-09-14 11:25:39 -0400746##
747##
748
Cary Clarkbc5697d2017-10-04 14:31:33 -0400749#SeeAlso SkImageInfo::computeByteSize
Cary Clarkd0530ba2017-09-14 11:25:39 -0400750
751##
752
753#Subtopic Image_Info_Access ##
754
755#Subtopic Reader
756
757# ------------------------------------------------------------------------------
758
759#Method bool computeIsOpaque() const
760
761Returns true if all pixels are opaque. Color_Type determines how pixels
762are encoded, and whether pixel describes Alpha. Returns true for Color_Types
Cary Clark6fc50412017-09-21 12:31:06 -0400763without alpha in each pixel; for other Color_Types, returns true if all
Cary Clarkd0530ba2017-09-14 11:25:39 -0400764pixels have alpha values equivalent to 1.0 or greater.
765
766For Color_Types kRGB_565_SkColorType or kGray_8_SkColorType: always
767returns true. For Color_Types kAlpha_8_SkColorType, kBGRA_8888_SkColorType,
768kRGBA_8888_SkColorType: returns true if all pixel Alpha values are 255.
769For Color_Type kARGB_4444_SkColorType: returns true if all pixel Alpha values are 15.
770For kRGBA_F16_SkColorType: returns true if all pixel Alpha values are 1.0 or
771greater.
772
Cary Clark6fc50412017-09-21 12:31:06 -0400773Returns false for kUnknown_SkColorType.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400774
Cary Clarkbc5697d2017-10-04 14:31:33 -0400775#Return true if all pixels have opaque values or Color_Type is opaque ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400776
777#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400778 std::vector<uint32_t> pixels;
779 const int height = 2;
780 const int width = 2;
781 pixels.resize(height * width * 4);
782 SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType,
783 kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4);
784 for (int index = 0; index < 2; ++index) {
785 pixmap.erase(0x00000000);
786 SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false");
787 pixmap.erase(0xFFFFFFFF);
788 SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false");
789 pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType),
790 (const void*) &pixels.front(), width * 4);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400791 }
792#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400793computeIsOpaque: false
794computeIsOpaque: true
795computeIsOpaque: false
Cary Clarkd0530ba2017-09-14 11:25:39 -0400796computeIsOpaque: true
797##
798##
799
800#SeeAlso isOpaque Color_Type Alpha
801
802##
803
804# ------------------------------------------------------------------------------
805
806#Method SkColor getColor(int x, int y) const
807
808Returns pixel at (x, y) as Unpremultiplied Color.
809Returns black with Alpha if Color_Type is kAlpha_8_SkColorType.
810
811Input is not validated: out of bounds values of x or y trigger an assert() if
812built with SK_DEBUG defined; and returns undefined values or may crash if
813SK_RELEASE is defined. Fails if Color_Type is kUnknown_SkColorType or
814pixel address is nullptr.
815
816Color_Space in Image_Info is ignored. Some Color precision may be lost in the
817conversion to Unpremultiplied Color; original pixel data may have additional
818precision.
819
Cary Clark6fc50412017-09-21 12:31:06 -0400820#Param x column index, zero or greater, and less than width() ##
821#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400822
823#Return pixel converted to Unpremultiplied Color ##
824
825#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400826 const int w = 4;
827 const int h = 4;
828 std::vector<SkPMColor> storage;
829 storage.resize(w * h);
830 SkDebugf("Premultiplied:\n");
831 for (int y = 0; y < h; ++y) {
832 SkDebugf("(0, %d) ", y);
833 for (int x = 0; x < w; ++x) {
834 int a = 0xFF * (x + y) / (w - 1 + h - 1);
835 storage[x + y * w] = SkPackARGB32(a, a * x / (w - 1), a * y / (h - 1), a);
836 SkDebugf("0x%08x%c", storage[x + y * w], x == w - 1 ? '\n' : ' ');
837 }
838 }
839 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4);
840 SkDebugf("Unpremultiplied:\n");
841 for (int y = 0; y < h; ++y) {
842 SkDebugf("(0, %d) ", y);
843 for (int x = 0; x < w; ++x) {
844 SkDebugf("0x%08x%c", pixmap.getColor(x, y), x == w - 1 ? '\n' : ' ');
845 }
846 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400847#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400848Premultiplied:
849(0, 0) 0x00000000 0x2a0e002a 0x55380055 0x7f7f007f
850(0, 1) 0x2a000e2a 0x551c1c55 0x7f542a7f 0xaaaa38aa
851(0, 2) 0x55003855 0x7f2a547f 0xaa7171aa 0xd4d48dd4
852(0, 3) 0x7f007f7f 0xaa38aaaa 0xd48dd4d4 0xffffffff
853Unpremultiplied:
854(0, 0) 0x00000000 0x2a5500ff 0x55a800ff 0x7fff00ff
855(0, 1) 0x2a0055ff 0x555454ff 0x7fa954ff 0xaaff54ff
856(0, 2) 0x5500a8ff 0x7f54a9ff 0xaaaaaaff 0xd4ffaaff
Cary Clarkd0530ba2017-09-14 11:25:39 -0400857(0, 3) 0x7f00ffff 0xaa54ffff 0xd4aaffff 0xffffffff
858##
859##
860
861#SeeAlso addr() readPixels
862
863##
864
865#Subtopic Reader ##
866
867#Subtopic Readable_Address
868
869# ------------------------------------------------------------------------------
870
871#Method const void* addr(int x, int y) const
872
Cary Clarkbc5697d2017-10-04 14:31:33 -0400873Returns readable pixel address at (x, y). Returns nullptr if Pixel_Ref is nullptr.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400874
875Input is not validated: out of bounds values of x or y trigger an assert() if
Cary Clarkbc5697d2017-10-04 14:31:33 -0400876built with SK_DEBUG defined. Returns nullptr if Color_Type is kUnknown_SkColorType.
877
878Performs a lookup of pixel size; for better performance, call
879one of: addr8, addr16, addr32, addr64, or addrF16.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400880
Cary Clark6fc50412017-09-21 12:31:06 -0400881#Param x column index, zero or greater, and less than width() ##
882#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400883
884#Return readable generic pointer to pixel ##
885
886#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400887 const int w = 4;
888 const int h = 4;
889 std::vector<SkPMColor> storage;
890 storage.resize(w * h);
891 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400892 SkDebugf("pixmap.addr(1, 2) %c= &storage[1 + 2 * w]\n",
893 pixmap.addr(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
894#StdOut
895pixmap.addr(1, 2) == &storage[1 + 2 * w]
896##
897##
898
Cary Clarkbc5697d2017-10-04 14:31:33 -0400899#SeeAlso addr8 addr16 addr32 addr64 addrF16 getColor writable_addr SkBitmap::getAddr
Cary Clarkd0530ba2017-09-14 11:25:39 -0400900
901##
902
903# ------------------------------------------------------------------------------
904
905#Method const uint8_t* addr8() const
906
907Returns readable base pixel address. Result is addressable as unsigned 8-bit bytes.
908Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType or
909kGray_8_SkColorType, and is built with SK_DEBUG defined.
910
911One byte corresponds to one pixel.
912
913#Return readable unsigned 8-bit pointer to pixels ##
914
915#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400916 const int w = 4;
917 const int h = 4;
918 uint8_t storage[w * h];
919 SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType),
920 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400921 SkDebugf("pixmap.addr8() %c= storage\n",
922 pixmap.addr8() == storage ? '=' : '!');
923#StdOut
924pixmap.addr8() == storage
925##
926##
927
928#SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8
929
930##
931
932# ------------------------------------------------------------------------------
933
934#Method const uint16_t* addr16() const
935
936Returns readable base pixel address. Result is addressable as unsigned 16-bit words.
937Will trigger an assert() if Color_Type is not kRGB_565_SkColorType or
938kARGB_4444_SkColorType, and is built with SK_DEBUG defined.
939
940One word corresponds to one pixel.
941
942#Return readable unsigned 16-bit pointer to pixels ##
943
944#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400945 const int w = 4;
946 const int h = 4;
947 uint16_t storage[w * h];
948 SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType),
949 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400950 SkDebugf("pixmap.addr16() %c= storage\n",
951 pixmap.addr16() == storage ? '=' : '!');
952#StdOut
953pixmap.addr16() == storage
954##
955##
956
957#SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16
958
959##
960
961# ------------------------------------------------------------------------------
962
963#Method const uint32_t* addr32() const
964
965Returns readable base pixel address. Result is addressable as unsigned 32-bit words.
966Will trigger an assert() if Color_Type is not kRGBA_8888_SkColorType or
967kBGRA_8888_SkColorType, and is built with SK_DEBUG defined.
968
969One word corresponds to one pixel.
970
971#Return readable unsigned 32-bit pointer to pixels ##
972
973#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400974 const int w = 4;
975 const int h = 4;
976 uint32_t storage[w * h];
977 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType),
978 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400979 SkDebugf("pixmap.addr32() %c= storage\n",
980 pixmap.addr32() == storage ? '=' : '!');
981#StdOut
982pixmap.addr32() == storage
983##
984##
985
986#SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr32
987
988##
989
990# ------------------------------------------------------------------------------
991
992#Method const uint64_t* addr64() const
993
994Returns readable base pixel address. Result is addressable as unsigned 64-bit words.
995Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
996with SK_DEBUG defined.
997
998One word corresponds to one pixel.
999
1000#Return readable unsigned 64-bit pointer to pixels ##
1001
1002#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001003 const int w = 4;
1004 const int h = 4;
1005 uint64_t storage[w * h];
1006 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
1007 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001008 SkDebugf("pixmap.addr64() %c= storage\n",
1009 pixmap.addr64() == storage ? '=' : '!');
1010#StdOut
1011pixmap.addr64() == storage
1012##
1013##
1014
1015#SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64
1016
1017##
1018
1019# ------------------------------------------------------------------------------
1020
1021#Method const uint16_t* addrF16() const
1022
1023Returns readable base pixel address. Result is addressable as unsigned 16-bit words.
1024Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
1025with SK_DEBUG defined.
1026
1027Each word represents one color component encoded as a half float.
1028Four words correspond to one pixel.
1029
1030#Return readable unsigned 16-bit pointer to first component of pixels ##
1031
1032#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001033 const int w = 4;
1034 const int h = 4;
1035 uint16_t storage[w * h * 4];
1036 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
1037 storage, w * 4 * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001038 SkDebugf("pixmap.addrF16() %c= storage\n",
1039 pixmap.addrF16() == storage ? '=' : '!');
1040#StdOut
1041pixmap.addrF16() == storage
1042##
1043##
1044
1045#SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16
1046
1047##
1048
1049# ------------------------------------------------------------------------------
1050
1051#Method const uint8_t* addr8(int x, int y) const
1052
1053Returns readable pixel address at (x, y).
1054
1055Input is not validated: out of bounds values of x or y trigger an assert() if
1056built with SK_DEBUG defined.
1057
1058Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType or
1059kGray_8_SkColorType, and is built with SK_DEBUG defined.
1060
Cary Clark6fc50412017-09-21 12:31:06 -04001061#Param x column index, zero or greater, and less than width() ##
1062#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001063
1064#Return readable unsigned 8-bit pointer to pixel at (x, y) ##
1065
1066#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001067 const int w = 4;
1068 const int h = 4;
1069 uint8_t storage[w * h];
1070 SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType),
1071 storage, w * sizeof(storage[0]));
1072 SkDebugf("pixmap.addr8(1, 2) %c= &storage[1 + 2 * w]\n",
1073 pixmap.addr8(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
Cary Clarkd0530ba2017-09-14 11:25:39 -04001074#StdOut
1075pixmap.addr8(1, 2) == &storage[1 + 2 * w]
1076##
1077##
1078
1079#SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8
1080
1081##
1082
1083# ------------------------------------------------------------------------------
1084
1085#Method const uint16_t* addr16(int x, int y) const
1086
1087Returns readable pixel address at (x, y).
1088
1089Input is not validated: out of bounds values of x or y trigger an assert() if
1090built with SK_DEBUG defined.
1091
1092Will trigger an assert() if Color_Type is not kRGB_565_SkColorType or
1093kARGB_4444_SkColorType, and is built with SK_DEBUG defined.
1094
Cary Clark6fc50412017-09-21 12:31:06 -04001095#Param x column index, zero or greater, and less than width() ##
1096#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001097
1098#Return readable unsigned 16-bit pointer to pixel at (x, y) ##
1099
1100#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001101 const int w = 4;
1102 const int h = 4;
1103 uint16_t storage[w * h];
1104 SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType),
1105 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001106 SkDebugf("pixmap.addr16(1, 2) %c= &storage[1 + 2 * w]\n",
1107 pixmap.addr16(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
1108#StdOut
1109pixmap.addr16(1, 2) == &storage[1 + 2 * w]
1110##
1111##
1112
1113#SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16
1114
1115##
1116
1117# ------------------------------------------------------------------------------
1118
1119#Method const uint32_t* addr32(int x, int y) const
1120
1121Returns readable pixel address at (x, y).
1122
1123Input is not validated: out of bounds values of x or y trigger an assert() if
1124built with SK_DEBUG defined.
1125
1126Will trigger an assert() if Color_Type is not kRGBA_8888_SkColorType or
1127kBGRA_8888_SkColorType, and is built with SK_DEBUG defined.
1128
Cary Clark6fc50412017-09-21 12:31:06 -04001129#Param x column index, zero or greater, and less than width() ##
1130#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001131
1132#Return readable unsigned 32-bit pointer to pixel at (x, y) ##
1133
1134#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001135 const int w = 4;
1136 const int h = 4;
1137 uint32_t storage[w * h];
1138 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_8888_SkColorType, kPremul_SkAlphaType),
1139 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001140 SkDebugf("pixmap.addr32(1, 2) %c= &storage[1 + 2 * w]\n",
1141 pixmap.addr32(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
1142#StdOut
1143pixmap.addr32(1, 2) == &storage[1 + 2 * w]
1144##
1145##
1146
Cary Clark2ade9972017-11-02 17:49:34 -04001147#SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr64
Cary Clarkd0530ba2017-09-14 11:25:39 -04001148
1149##
1150
1151# ------------------------------------------------------------------------------
1152
1153#Method const uint64_t* addr64(int x, int y) const
1154
1155Returns readable pixel address at (x, y).
1156
1157Input is not validated: out of bounds values of x or y trigger an assert() if
1158built with SK_DEBUG defined.
1159
1160Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
1161with SK_DEBUG defined.
1162
Cary Clark6fc50412017-09-21 12:31:06 -04001163#Param x column index, zero or greater, and less than width() ##
1164#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001165
1166#Return readable unsigned 64-bit pointer to pixel at (x, y) ##
1167
1168#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001169 const int w = 4;
1170 const int h = 4;
1171 uint64_t storage[w * h];
1172 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
1173 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001174 SkDebugf("pixmap.addr64(1, 2) %c= &storage[1 + 2 * w]\n",
1175 pixmap.addr64(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
1176#StdOut
1177pixmap.addr64(1, 2) == &storage[1 + 2 * w]
1178##
1179##
1180
1181#SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64
1182
1183##
1184
1185# ------------------------------------------------------------------------------
1186
1187#Method const uint16_t* addrF16(int x, int y) const
1188
1189Returns readable pixel address at (x, y).
1190
1191Input is not validated: out of bounds values of x or y trigger an assert() if
1192built with SK_DEBUG defined.
1193
1194Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
1195with SK_DEBUG defined.
1196
1197Each unsigned 16-bit word represents one color component encoded as a half float.
1198Four words correspond to one pixel.
1199
Cary Clark6fc50412017-09-21 12:31:06 -04001200#Param x column index, zero or greater, and less than width() ##
1201#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001202
1203#Return readable unsigned 16-bit pointer to pixel component at (x, y) ##
1204
1205#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001206 const int w = 4;
1207 const int h = 4;
1208 const int wordsPerPixel = 4;
1209 const int rowWords = w * wordsPerPixel;
1210 uint16_t storage[rowWords * h];
1211 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
1212 storage, rowWords * sizeof(storage[0]));
1213 SkDebugf("pixmap.addrF16(1, 2) %c= &storage[1 * wordsPerPixel + 2 * rowWords]\n",
1214 pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords] ? '=' : '!');
Cary Clarkd0530ba2017-09-14 11:25:39 -04001215#StdOut
1216pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords]
1217##
1218##
1219
1220#SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16
1221
1222##
1223
1224#Subtopic Readable_Address ##
1225
1226#Subtopic Writable_Address
1227
1228# ------------------------------------------------------------------------------
1229
1230#Method void* writable_addr() const
1231
1232Returns writable base pixel address.
1233
1234#Return writable generic base pointer to pixels ##
1235
1236#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001237 const int w = 4;
1238 const int h = 4;
1239 SkPMColor storage[w * h * 4];
1240 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4);
1241 SkDebugf("pixmap.writable_addr() %c= (void *)storage\n",
1242 pixmap.writable_addr() == (void *)storage ? '=' : '!');
1243 pixmap.erase(0x00000000);
1244 *(SkPMColor*)pixmap.writable_addr() = 0xFFFFFFFF;
1245 SkDebugf("pixmap.getColor(0, 1) %c= 0x00000000\n",
1246 pixmap.getColor(0, 1) == 0x00000000 ? '=' : '!');
1247 SkDebugf("pixmap.getColor(0, 0) %c= 0xFFFFFFFF\n",
Cary Clarkd0530ba2017-09-14 11:25:39 -04001248 pixmap.getColor(0, 0) == 0xFFFFFFFF ? '=' : '!');
1249#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -04001250pixmap.writable_addr() == (void *)storage
1251pixmap.getColor(0, 1) == 0x00000000
Cary Clarkd0530ba2017-09-14 11:25:39 -04001252pixmap.getColor(0, 0) == 0xFFFFFFFF
1253##
1254##
1255
1256#SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr()
1257
1258##
1259
1260# ------------------------------------------------------------------------------
1261
1262#Method void* writable_addr(int x, int y) const
1263
1264Returns writable pixel address at (x, y).
1265
1266Input is not validated: out of bounds values of x or y trigger an assert() if
1267built with SK_DEBUG defined. Returns zero if Color_Type is kUnknown_SkColorType.
1268
Cary Clark6fc50412017-09-21 12:31:06 -04001269#Param x column index, zero or greater, and less than width() ##
1270#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001271
1272#Return writable generic pointer to pixel ##
1273
1274#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001275 const int w = 4;
1276 const int h = 4;
1277 SkPMColor storage[w * h * 4];
1278 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4);
1279 SkDebugf("pixmap.writable_addr() %c= (void *)storage\n",
1280 pixmap.writable_addr() == (void *)storage ? '=' : '!');
1281 pixmap.erase(0x00000000);
1282 *(SkPMColor*)pixmap.writable_addr(1, 2) = 0xFFFFFFFF;
1283 SkDebugf("pixmap.getColor(0, 0) %c= 0x00000000\n",
1284 pixmap.getColor(0, 0) == 0x00000000 ? '=' : '!');
1285 SkDebugf("pixmap.getColor(1, 2) %c= 0xFFFFFFFF\n",
Cary Clarkd0530ba2017-09-14 11:25:39 -04001286 pixmap.getColor(1, 2) == 0xFFFFFFFF ? '=' : '!');
1287#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -04001288pixmap.writable_addr() == (void *)storage
1289pixmap.getColor(0, 0) == 0x00000000
Cary Clarkd0530ba2017-09-14 11:25:39 -04001290pixmap.getColor(1, 2) == 0xFFFFFFFF
1291##
1292##
1293
1294#SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr()
1295
1296##
1297
1298# ------------------------------------------------------------------------------
1299
1300#Method uint8_t* writable_addr8(int x, int y) const
1301
Cary Clark6fc50412017-09-21 12:31:06 -04001302Returns writable pixel address at (x, y). Result is addressable as unsigned
13038-bit bytes. Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType
1304or kGray_8_SkColorType, and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001305
1306One byte corresponds to one pixel.
1307
Cary Clark6fc50412017-09-21 12:31:06 -04001308#Param x column index, zero or greater, and less than width() ##
1309#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001310
1311#Return writable unsigned 8-bit pointer to pixels ##
1312
1313#Example
1314#Height 64
1315#Description
1316Altering pixels after drawing Bitmap is not guaranteed to affect subsequent
1317drawing on all platforms. Adding a second SkBitmap::installPixels after editing
1318pixel memory is safer.
1319##
Cary Clark6fc50412017-09-21 12:31:06 -04001320void draw(SkCanvas* canvas) {
1321 uint8_t storage[][5] = {{ 0, 0, 64, 0, 0},
1322 { 0, 128, 255, 128, 0},
1323 {64, 255, 255, 255, 64},
1324 { 0, 128, 255, 128, 0},
1325 { 0, 0, 64, 0, 0}};
1326 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kPremul_SkAlphaType);
1327 SkPixmap pixmap(imageInfo, storage[0], 5);
1328 SkBitmap bitmap;
1329 bitmap.installPixels(pixmap);
1330 canvas->scale(10, 10);
1331 canvas->drawBitmap(bitmap, 0, 0);
1332 *pixmap.writable_addr8(2, 2) = 0;
1333// bitmap.installPixels(pixmap); // uncomment to fix on GPU
1334 canvas->drawBitmap(bitmap, 10, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001335}
1336##
1337
1338#SeeAlso writable_addr writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr() addr8
1339
1340##
1341
1342# ------------------------------------------------------------------------------
1343
1344#Method uint16_t* writable_addr16(int x, int y) const
1345
Cary Clark6fc50412017-09-21 12:31:06 -04001346Returns writable_addr pixel address at (x, y). Result is addressable as unsigned
134716-bit words. Will trigger an assert() if Color_Type is not kRGB_565_SkColorType
1348or kARGB_4444_SkColorType, and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001349
1350One word corresponds to one pixel.
1351
Cary Clark6fc50412017-09-21 12:31:06 -04001352#Param x column index, zero or greater, and less than width() ##
1353#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001354
1355#Return writable unsigned 16-bit pointer to pixel ##
1356
1357#Example
1358#Description
1359Draw a five by five bitmap, and draw it again with a center black pixel.
1360The low nibble of the 16-bit word is Alpha.
1361##
1362#Height 64
Cary Clark6fc50412017-09-21 12:31:06 -04001363 uint16_t storage[][5] = {{ 0xCABF, 0xDABE, 0xCA9D, 0xC96C, 0xA39B },
1364 { 0xACEE, 0xA87C, 0x893A, 0x4779, 0x8708 },
1365 { 0x4B7C, 0x255B, 0x2559, 0x2557, 0x4656 },
1366 { 0x9099, 0x8128, 0x2557, 0x4124, 0x3323 },
1367 { 0x7547, 0x5505, 0x4434, 0x2012, 0x0000 }};
1368 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kARGB_4444_SkColorType, kPremul_SkAlphaType);
1369 SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
1370 SkBitmap bitmap;
1371 bitmap.installPixels(pixmap);
1372 canvas->scale(10, 10);
1373 canvas->drawBitmap(bitmap, 0, 0);
1374 *pixmap.writable_addr16(2, 2) = 0x000F;
1375 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001376 canvas->drawBitmap(bitmap, 10, 0);
1377##
1378
1379#SeeAlso writable_addr writable_addr8 writable_addr32 writable_addr64 writable_addrF16 addr() addr16
1380
1381##
1382
1383# ------------------------------------------------------------------------------
1384
1385#Method uint32_t* writable_addr32(int x, int y) const
1386
Cary Clark6fc50412017-09-21 12:31:06 -04001387Returns writable pixel address at (x, y). Result is addressable as unsigned
138832-bit words. Will trigger an assert() if Color_Type is not
1389kRGBA_8888_SkColorType or kBGRA_8888_SkColorType, and is built with SK_DEBUG
1390defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001391
1392One word corresponds to one pixel.
1393
Cary Clark6fc50412017-09-21 12:31:06 -04001394#Param x column index, zero or greater, and less than width() ##
1395#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001396
1397#Return writable unsigned 32-bit pointer to pixel ##
1398
1399#Example
1400#Image 4
1401#Height 72
Cary Clark6fc50412017-09-21 12:31:06 -04001402 std::vector<int32_t> pixels;
1403 pixels.resize(image->height() * image->width() * 4);
1404 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
1405 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
1406 image->readPixels(pixmap, 0, 0);
1407 for (int y = 0; y < pixmap.height() / 2; ++y) {
1408 for (int x = 0; x < pixmap.width(); ++x) {
1409 if ((x & 4) == (y & 4)) {
1410 SkTSwap(*pixmap.writable_addr32(x, y),
1411 *pixmap.writable_addr32(pixmap.width() - x, pixmap.height() - y));
1412 }
1413 }
1414 }
1415 SkBitmap bitmap;
1416 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001417 canvas->drawBitmap(bitmap, 0, 0);
1418##
1419
1420#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr64 writable_addrF16 addr() addr32
1421
1422##
1423
1424# ------------------------------------------------------------------------------
1425
1426#Method uint64_t* writable_addr64(int x, int y) const
1427
Cary Clark6fc50412017-09-21 12:31:06 -04001428Returns writable pixel address at (x, y). Result is addressable as unsigned
142964-bit words. Will trigger an assert() if Color_Type is not
1430kRGBA_F16_SkColorType and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001431
1432One word corresponds to one pixel.
1433
Cary Clark6fc50412017-09-21 12:31:06 -04001434#Param x column index, zero or greater, and less than width() ##
1435#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001436
1437#Return writable unsigned 64-bit pointer to pixel ##
1438
1439#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001440#Height 40
Cary Clark6fc50412017-09-21 12:31:06 -04001441 SkImageInfo info = SkImageInfo::Make(3, 3, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
1442 uint64_t storage[9];
1443 SkPixmap pixmap(info, storage, 3 * sizeof(uint64_t));
1444 SkColor4f c4 { 1, 0.45f, 0.25f, 0.65f };
1445 pixmap.erase(c4);
1446 SkBitmap bitmap;
1447 canvas->scale(10, 10);
1448 bitmap.installPixels(pixmap);
1449 canvas->drawBitmap(bitmap, 0, 0);
1450 *pixmap.writable_addr64(1, 1) |= 0x00ff000000000000LL;
1451 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001452 canvas->drawBitmap(bitmap, 10, 0);
1453##
1454
1455#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addrF16 addr() addr64
1456
1457##
1458
1459# ------------------------------------------------------------------------------
1460
1461#Method uint16_t* writable_addrF16(int x, int y) const
1462
Cary Clark6fc50412017-09-21 12:31:06 -04001463Returns writable pixel address at (x, y). Result is addressable as unsigned
146416-bit words. Will trigger an assert() if Color_Type is not
1465kRGBA_F16_SkColorType and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001466
1467Each word represents one color component encoded as a half float.
1468Four words correspond to one pixel.
1469
Cary Clark6fc50412017-09-21 12:31:06 -04001470#Param x column index, zero or greater, and less than width() ##
1471#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001472
1473#Return writable unsigned 16-bit pointer to first component of pixel ##
1474
1475#Example
1476#Height 64
1477#Description
1478Left bitmap is drawn with two pixels defined in half float format. Right bitmap
1479is drawn after overwriting bottom half float color with top half float color.
1480##
Cary Clark6fc50412017-09-21 12:31:06 -04001481 SkImageInfo info = SkImageInfo::Make(1, 2, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
1482 uint16_t storage[2][4];
1483 SkPixmap pixmap(info, storage[0], sizeof(uint64_t));
1484 SkIRect topPixelBounds = {0, 0, 1, 1};
1485 pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds);
1486 SkIRect bottomPixelBounds = {0, 1, 1, 2};
1487 pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds);
1488 SkBitmap bitmap;
1489 canvas->scale(20, 20);
1490 bitmap.installPixels(pixmap);
1491 canvas->drawBitmap(bitmap, 0, 0);
1492 uint16_t* pixel2 = pixmap.writable_addrF16(0, 1);
1493 for (int i = 0; i < 4; ++i) {
1494 pixel2[i] = storage[0][i];
1495 }
1496 bitmap.installPixels(pixmap);
1497 canvas->drawBitmap(bitmap, 4, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001498##
1499
1500#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addr64 addr() addrF16
1501
1502##
1503
1504#Subtopic Writable_Address ##
1505
1506#Subtopic Writer
1507
1508# ------------------------------------------------------------------------------
1509
1510#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
1511 int srcX, int srcY, SkTransferFunctionBehavior behavior) const
1512
Cary Clark154beea2017-10-26 07:58:48 -04001513Copies a Rect of pixels to dstPixels. Copy starts at (srcX, srcY), and does not
1514exceed (this->width(), this->height()).
Cary Clark6fc50412017-09-21 12:31:06 -04001515
1516dstInfo specifies width, height, Color_Type, Alpha_Type, and
Cary Clarkd0530ba2017-09-14 11:25:39 -04001517Color_Space of destination. dstRowBytes specifics the gap from one destination
1518row to the next. Returns true if pixels are copied. Returns false if
1519dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes.
1520
1521Pixels are copied only if pixel conversion is possible. If this->colorType is
1522kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match.
1523If this->colorType is kGray_8_SkColorType, dstInfo.colorSpace must match.
1524If this->alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must
1525match. If this->colorSpace is nullptr, dstInfo.colorSpace must match. Returns
1526false if pixel conversion is not possible.
1527
1528srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clark154beea2017-10-26 07:58:48 -04001529false if width() or height() is zero or negative. Returns false if:
1530
Cary Clarkd0530ba2017-09-14 11:25:39 -04001531#Formula
Cary Clark6fc50412017-09-21 12:31:06 -04001532abs(srcX) >= this->width()
1533##
1534, or if
1535#Formula
1536abs(srcY) >= this->height()
Cary Clarkd0530ba2017-09-14 11:25:39 -04001537##
1538.
1539
1540If behavior is SkTransferFunctionBehavior::kRespect: converts source
1541pixels to a linear space before converting to dstInfo.
1542If behavior is SkTransferFunctionBehavior::kIgnore: source
Cary Clarkbc5697d2017-10-04 14:31:33 -04001543pixels are treated as if they are linear, regardless of how they are encoded.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001544
1545#Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ##
1546#Param dstPixels destination pixel storage ##
1547#Param dstRowBytes destination row length ##
1548#Param srcX column index whose absolute value is less than width() ##
1549#Param srcY row index whose absolute value is less than height() ##
1550#Param behavior one of: SkTransferFunctionBehavior::kRespect,
1551 SkTransferFunctionBehavior::kIgnore
1552##
1553
1554#Return true if pixels are copied to dstPixels ##
1555
1556#Example
Cary Clarkbc5697d2017-10-04 14:31:33 -04001557#ToDo example doesn't do anything interesting since info colorSpace is nullptr ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001558#Image 3
1559void draw(SkCanvas* canvas) {
1560 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height(),
1561 canvas->imageInfo().colorSpace() ? SkColorSpace::MakeSRGB() : nullptr);
Cary Clark6fc50412017-09-21 12:31:06 -04001562 std::vector<int32_t> srcPixels;
1563 srcPixels.resize(image->height() * image->width() * 4);
1564 SkPixmap pixmap(info, (const void*) &srcPixels.front(), image->width() * 4);
1565 image->readPixels(pixmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001566 SkTransferFunctionBehavior behavior = canvas->imageInfo().colorSpace() ?
1567 SkTransferFunctionBehavior::kRespect : SkTransferFunctionBehavior::kIgnore;
Cary Clark6fc50412017-09-21 12:31:06 -04001568 std::vector<int32_t> dstPixels;
1569 dstPixels.resize(image->height() * image->width() * 4);
1570 int offset = 0;
1571 for (auto behavior : { SkTransferFunctionBehavior::kRespect,
1572 SkTransferFunctionBehavior::kIgnore} ) {
Cary Clarkd0530ba2017-09-14 11:25:39 -04001573 pixmap.readPixels(info, &dstPixels.front(), image->width() * 4, offset, 0, behavior);
1574 offset += 128;
1575 }
1576 SkBitmap bitmap;
1577 SkPixmap dstmap(info, &dstPixels.front(), image->width() * 4);
1578 bitmap.installPixels(dstmap);
1579 canvas->drawBitmap(bitmap, 0, 0);
1580}
1581##
1582
1583#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1584
1585##
1586
1587# ------------------------------------------------------------------------------
1588
1589#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes) const
1590
1591Copies a Rect of pixels to dstPixels. Copy starts at (0, 0), and does not
Cary Clark154beea2017-10-26 07:58:48 -04001592exceed (this->width(), this->height()).
Cary Clark6fc50412017-09-21 12:31:06 -04001593
1594dstInfo specifies width, height, Color_Type, Alpha_Type, and
Cary Clarkd0530ba2017-09-14 11:25:39 -04001595Color_Space of destination. dstRowBytes specifics the gap from one destination
1596row to the next. Returns true if pixels are copied. Returns false if
1597dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes.
1598
1599Pixels are copied only if pixel conversion is possible. If this->colorType is
1600kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match.
1601If this->colorType is kGray_8_SkColorType, dstInfo.colorSpace must match.
1602If this->alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must
1603match. If this->colorSpace is nullptr, dstInfo.colorSpace must match. Returns
1604false if pixel conversion is not possible.
1605
1606Returns false if this->width() or this->height() is zero or negative.
1607
1608#Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ##
1609#Param dstPixels destination pixel storage ##
1610#Param dstRowBytes destination row length ##
1611
1612#Return true if pixels are copied to dstPixels ##
1613
1614#Example
1615#Height 128
1616#Description
1617Transferring the gradient from 8 bits per component to 4 bits per component
1618creates visible banding.
1619##
Cary Clark6fc50412017-09-21 12:31:06 -04001620 std::vector<int32_t> pixels;
1621 const int width = 256;
1622 const int height = 64;
1623 pixels.resize(height * width * 4);
1624 SkImageInfo srcInfo = SkImageInfo::MakeN32Premul(width, height);
1625 SkPixmap srcPixmap(srcInfo, (const void*) &pixels.front(), width * 4);
1626 SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 };
1627 SkPoint gradPoints[] = { { 0, 0 }, { 256, 0 } };
1628 SkPaint paint;
1629 paint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1630 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1631 SkBitmap bitmap;
1632 bitmap.installPixels(srcPixmap);
1633 SkCanvas srcCanvas(bitmap);
1634 srcCanvas.drawRect(SkRect::MakeWH(width, height), paint);
1635 canvas->drawBitmap(bitmap, 0, 0);
1636 std::vector<int32_t> dstPixels;
1637 dstPixels.resize(height * width * 2);
1638 SkImageInfo dstInfo = srcInfo.makeColorType(kARGB_4444_SkColorType);
1639 srcPixmap.readPixels(dstInfo, &dstPixels.front(), width * 2);
1640 SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2);
1641 bitmap.installPixels(dstPixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001642 canvas->drawBitmap(bitmap, 0, 128);
1643##
1644
1645#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1646
1647##
1648
1649# ------------------------------------------------------------------------------
1650
1651#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX,
1652 int srcY) const
1653
1654Copies a Rect of pixels to dstPixels. Copy starts at (srcX, srcY), and does not
Cary Clark154beea2017-10-26 07:58:48 -04001655exceed (this->width(), this->height()).
Cary Clark6fc50412017-09-21 12:31:06 -04001656
1657dstInfo specifies width, height, Color_Type, Alpha_Type, and
Cary Clarkd0530ba2017-09-14 11:25:39 -04001658Color_Space of destination. dstRowBytes specifics the gap from one destination
1659row to the next. Returns true if pixels are copied. Returns false if
1660dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes.
1661
1662Pixels are copied only if pixel conversion is possible. If this->colorType is
1663kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match.
1664If this->colorType is kGray_8_SkColorType, dstInfo.colorSpace must match.
1665If this->alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must
1666match. If this->colorSpace is nullptr, dstInfo.colorSpace must match. Returns
1667false if pixel conversion is not possible.
1668
1669srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clark154beea2017-10-26 07:58:48 -04001670false if this->width() or this->height() is zero or negative. Returns false if:
1671
Cary Clarkd0530ba2017-09-14 11:25:39 -04001672#Formula
Cary Clark6fc50412017-09-21 12:31:06 -04001673abs(srcX) >= this->width()
1674##
1675, or if
1676#Formula
1677abs(srcY) >= this->height()
Cary Clarkd0530ba2017-09-14 11:25:39 -04001678##
1679.
1680
1681#Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ##
1682#Param dstPixels destination pixel storage ##
1683#Param dstRowBytes destination row length ##
1684#Param srcX column index whose absolute value is less than width() ##
1685#Param srcY row index whose absolute value is less than height() ##
1686
1687#Return true if pixels are copied to dstPixels ##
1688
1689#Example
1690#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001691void draw(SkCanvas* canvas) {
1692 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1693 std::vector<int32_t> srcPixels;
1694 const int rowBytes = image->width() * 4;
1695 srcPixels.resize(image->height() * rowBytes);
1696 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1697 image->readPixels(pixmap, 0, 0);
1698 for (int offset : { 32, 64, 96 } ) {
1699 std::vector<int32_t> dstPixels;
1700 dstPixels.resize(image->height() * rowBytes);
1701 pixmap.readPixels(info, &dstPixels.front(), rowBytes, offset, 0);
1702 SkBitmap bitmap;
1703 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1704 bitmap.installPixels(dstmap);
1705 canvas->translate(32, 32);
1706 canvas->drawBitmap(bitmap, 0, 0);
1707 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001708}
1709##
1710
1711#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1712
1713##
1714
1715# ------------------------------------------------------------------------------
1716
1717#Method bool readPixels(const SkPixmap& dst, int srcX, int srcY) const
1718
1719Copies a Rect of pixels to dst. Copy starts at (srcX, srcY), and does not
1720exceed (this->width(), this->height()). dst specifies width, height, Color_Type,
1721Alpha_Type, and Color_Space of destination. Returns true if pixels are copied.
1722Returns false if dst.addr() equals nullptr, or dst.rowBytes is less than
1723dst SkImageInfo::minRowBytes.
1724
1725Pixels are copied only if pixel conversion is possible. If this->colorType is
1726kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.info().colorType must match.
1727If this->colorType is kGray_8_SkColorType, dst.info().colorSpace must match.
1728If this->alphaType is kOpaque_SkAlphaType, dst.info().alphaType must
1729match. If this->colorSpace is nullptr, dst.info().colorSpace must match. Returns
1730false if pixel conversion is not possible.
1731
1732srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clark154beea2017-10-26 07:58:48 -04001733false this->width() or this->height() is zero or negative. Returns false if:
1734
Cary Clarkd0530ba2017-09-14 11:25:39 -04001735#Formula
Cary Clark6fc50412017-09-21 12:31:06 -04001736abs(srcX) >= this->width()
1737##
1738, or if
1739#Formula
1740abs(srcY) >= this->height()
Cary Clarkd0530ba2017-09-14 11:25:39 -04001741##
1742.
1743
1744#Param dst Image_Info and pixel address to write to ##
1745#Param srcX column index whose absolute value is less than width() ##
1746#Param srcY row index whose absolute value is less than height() ##
1747
1748#Return true if pixels are copied to dst ##
1749
1750#Example
1751#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001752void draw(SkCanvas* canvas) {
1753 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1754 std::vector<int32_t> srcPixels;
1755 const int rowBytes = image->width() * 4;
1756 srcPixels.resize(image->height() * rowBytes);
1757 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1758 image->readPixels(pixmap, 0, 0);
1759 for (int offset : { 32, 64, 96 } ) {
1760 std::vector<int32_t> dstPixels;
1761 dstPixels.resize(image->height() * rowBytes);
1762 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1763 pixmap.readPixels(dstmap, offset, 0);
1764 SkBitmap bitmap;
1765 bitmap.installPixels(dstmap);
1766 canvas->translate(32, 32);
1767 canvas->drawBitmap(bitmap, 0, 0);
1768 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001769}
1770##
1771
1772#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1773
1774##
1775
1776# ------------------------------------------------------------------------------
1777
1778#Method bool readPixels(const SkPixmap& dst) const
1779
1780Copies pixels inside bounds() to dst. dst specifies width, height, Color_Type,
1781Alpha_Type, and Color_Space of destination. Returns true if pixels are copied.
1782Returns false if dst.addr() equals nullptr, or dst.rowBytes is less than
1783dst SkImageInfo::minRowBytes.
1784
1785Pixels are copied only if pixel conversion is possible. If this->colorType is
1786kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match.
1787If this->colorType is kGray_8_SkColorType, dst Color_Space must match.
1788If this->alphaType is kOpaque_SkAlphaType, dst Alpha_Type must
1789match. If this->colorSpace is nullptr, dst Color_Space must match. Returns
1790false if pixel conversion is not possible.
1791
1792Returns false if this->width() or this->height() is zero or negative.
1793
1794#Param dst Image_Info and pixel address to write to ##
1795
1796#Return true if pixels are copied to dst ##
1797
1798#Example
1799#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001800void draw(SkCanvas* canvas) {
1801 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1802 std::vector<int32_t> srcPixels;
1803 const int rowBytes = image->width() * 4;
1804 srcPixels.resize(image->height() * rowBytes);
1805 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1806 image->readPixels(pixmap, 0, 0);
1807 for (int index = 0; index < 3; ++index ) {
1808 std::vector<int32_t> dstPixels;
1809 dstPixels.resize(image->height() * rowBytes);
1810 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1811 pixmap.readPixels(dstmap);
1812 SkBitmap bitmap;
1813 bitmap.installPixels(dstmap);
1814 canvas->translate(32, 32);
1815 canvas->drawBitmap(bitmap, 0, 0);
1816 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001817}
1818##
1819
1820#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1821
1822##
1823
1824# ------------------------------------------------------------------------------
1825
1826#Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality) const
1827
1828Copies this to dst, scaling pixels to fit dst.width() and dst.height(), and
1829converting pixels to match dst.colorType and dst.alphaType. Returns true if
1830pixels are copied. Returns false if dst.addr() is nullptr, or dst.rowBytes is
1831less than dst SkImageInfo::minRowBytes.
1832
1833Pixels are copied only if pixel conversion is possible. If this->colorType is
1834kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match.
1835If this->colorType is kGray_8_SkColorType, dst Color_Space must match.
1836If this->alphaType is kOpaque_SkAlphaType, dst Alpha_Type must
1837match. If this->colorSpace is nullptr, dst Color_Space must match. Returns
1838false if pixel conversion is not possible.
1839
1840Returns false if this->width() or this->height() is zero or negative.
1841
1842Scales the image, with filterQuality, to match dst.width() and dst.height().
1843filterQuality kNone_SkFilterQuality is fastest, typically implemented with
1844Filter_Quality_Nearest_Neighbor. kLow_SkFilterQuality is typically implemented with
1845Filter_Quality_Bilerp. kMedium_SkFilterQuality is typically implemented with
1846Filter_Quality_Bilerp, and Filter_Quality_MipMap when size is reduced.
1847kHigh_SkFilterQuality is slowest, typically implemented with Filter_Quality_BiCubic.
1848
1849#Param dst Image_Info and pixel address to write to ##
1850#Param filterQuality one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
1851 kMedium_SkFilterQuality, kHigh_SkFilterQuality
1852##
1853
1854#Return true if pixels are copied to dst ##
1855
1856#Example
1857#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001858void draw(SkCanvas* canvas) {
1859 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1860 std::vector<int32_t> srcPixels;
1861 int rowBytes = image->width() * 4;
1862 srcPixels.resize(image->height() * rowBytes);
1863 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1864 image->readPixels(pixmap, 0, 0);
1865 for (int offset : { 32, 64, 96 } ) {
1866 info = SkImageInfo::MakeN32Premul(image->width() + offset, image->height());
1867 rowBytes = info.width() * 4;
1868 std::vector<int32_t> dstPixels;
1869 dstPixels.resize(image->height() * rowBytes);
1870 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1871 pixmap.scalePixels(dstmap, kMedium_SkFilterQuality);
1872 SkBitmap bitmap;
1873 bitmap.installPixels(dstmap);
1874 canvas->translate(32, 32);
1875 canvas->drawBitmap(bitmap, 0, 0);
1876 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001877}
1878##
1879
1880#SeeAlso SkCanvas::drawBitmap SkImage::scalePixels
1881
1882##
1883
1884# ------------------------------------------------------------------------------
1885
1886#Method bool erase(SkColor color, const SkIRect& subset) const
1887
1888Writes color to pixels bounded by subset; returns true on success.
1889Returns false if colorType is kUnknown_SkColorType, or if subset does
1890not intersect bounds().
1891
1892#Param color Unpremultiplied Color to write ##
1893#Param subset bounding integer Rect of written pixels ##
1894
1895#Return true if pixels are changed ##
1896
1897#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001898#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001899 uint32_t storage[2];
1900 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1901 SkPixmap pixmap(info, storage, info.minRowBytes());
1902 pixmap.erase(SK_ColorBLUE, {0, 0, 1, 1});
1903 pixmap.erase(SK_ColorRED, {0, 1, 1, 2});
1904 SkBitmap bitmap;
1905 canvas->scale(20, 20);
1906 bitmap.installPixels(pixmap);
1907 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001908##
1909
1910#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1911
1912##
1913
1914# ------------------------------------------------------------------------------
1915
1916#Method bool erase(SkColor color) const
1917
1918Writes color to pixels inside bounds(); returns true on success.
1919Returns false if colorType is kUnknown_SkColorType, or if bounds()
1920is empty.
1921
1922#Param color Unpremultiplied Color to write ##
1923
1924#Return true if pixels are changed ##
1925
1926#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001927#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001928 uint32_t storage[2];
1929 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1930 SkPixmap pixmap(info, storage, info.minRowBytes());
1931 pixmap.erase(SK_ColorBLUE);
1932 SkBitmap bitmap;
1933 canvas->scale(20, 20);
1934 bitmap.installPixels(pixmap);
1935 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001936##
1937
1938#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1939
1940##
1941
1942# ------------------------------------------------------------------------------
1943
1944#Method bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const
1945
1946Writes color to pixels bounded by subset; returns true on success.
1947if subset is nullptr, writes colors pixels inside bounds(). Returns false if
1948colorType is kUnknown_SkColorType, if subset is not nullptr and does
1949not intersect bounds(), or if subset is nullptr and bounds() is empty.
1950
1951#Param color Unpremultiplied Color to write ##
1952#Param subset bounding integer Rect of pixels to write; may be nullptr ##
1953
1954#Return true if pixels are changed ##
1955
1956#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001957#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001958 uint32_t storage[2];
1959 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1960 SkPixmap pixmap(info, storage, info.minRowBytes());
1961 SkIRect topPixelBounds = {0, 0, 1, 1};
1962 pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds);
1963 SkIRect bottomPixelBounds = {0, 1, 1, 2};
1964 pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds);
1965 SkBitmap bitmap;
1966 canvas->scale(20, 20);
1967 bitmap.installPixels(pixmap);
1968 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001969##
1970
1971#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1972
1973##
1974
1975
1976#Subtopic Writer ##
1977
1978#Class SkPixmap ##
1979
1980#Topic Pixmap ##