blob: f0b50f9f88f5973ed6141794ede6fddef3c4a911 [file] [log] [blame]
Cary Clarkbc5697d2017-10-04 14:31:33 -04001#Topic Bitmap
Cary Clark137b8742018-05-30 09:21:49 -04002#Alias Bitmaps ##
3#Alias Bitmap_Reference ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004
5#Class SkBitmap
Cary Clark61313f32018-10-08 14:57:48 -04006#Line # two-dimensional raster pixel array ##
7
8#Code
9#Populate
10##
Cary Clarkbc5697d2017-10-04 14:31:33 -040011
12Bitmap describes a two-dimensional raster pixel array. Bitmap is built on
13Image_Info, containing integer width and height, Color_Type and Alpha_Type
14describing the pixel format, and Color_Space describing the range of colors.
15Bitmap points to Pixel_Ref, which describes the physical array of pixels.
16Image_Info bounds may be located anywhere fully inside Pixel_Ref bounds.
17
18Bitmap can be drawn using Canvas. Bitmap can be a drawing destination for Canvas
Cary Clark137b8742018-05-30 09:21:49 -040019draw member functions. Bitmap flexibility as a pixel container limits some
Cary Clark682c58d2018-05-16 07:07:07 -040020optimizations available to the target platform.
Cary Clarkbc5697d2017-10-04 14:31:33 -040021
22If pixel array is primarily read-only, use Image for better performance.
23If pixel array is primarily written to, use Surface for better performance.
24
25Declaring SkBitmap const prevents altering Image_Info: the Bitmap height, width,
26and so on cannot change. It does not affect Pixel_Ref: a caller may write its
27pixels. Declaring SkBitmap const affects Bitmap configuration, not its contents.
28
Cary Clarkbef063a2017-10-31 15:44:45 -040029Bitmap is not thread safe. Each thread must have its own copy of Bitmap fields,
Cary Clarkbc5697d2017-10-04 14:31:33 -040030although threads may share the underlying pixel array.
31
Cary Clark08895c42018-02-01 09:37:32 -050032#Subtopic Row_Bytes
33#Line # interval from one row to the next ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040034Bitmap pixels may be contiguous, or may have a gap at the end of each row.
35Row_Bytes is the interval from one row to the next. Row_Bytes may be specified;
36sometimes passing zero will compute the Row_Bytes from the row width and the
37number of bytes in a pixel. Row_Bytes may be larger than the row requires. This
38is useful to position one or more Bitmaps within a shared pixel array.
39##
40
Cary Clarkbc5697d2017-10-04 14:31:33 -040041# ------------------------------------------------------------------------------
42
43#Class Allocator
Cary Clark08895c42018-02-01 09:37:32 -050044#Line # abstract subclass of HeapAllocator ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040045#Code
Cary Clarka90ea222018-10-16 10:30:28 -040046#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -040047##
48
49Abstract subclass of HeapAllocator.
50
51# ------------------------------------------------------------------------------
52
53#Method virtual bool allocPixelRef(SkBitmap* bitmap) = 0
Cary Clarkd2ca79c2018-08-10 13:09:13 -040054#Line # allocates pixel memory ##
Cary Clark09d80c02018-10-31 12:14:03 -040055#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -040056
57#NoExample
58##
59
60#SeeAlso HeapAllocator
61
62##
63
64#Class Allocator ##
65
66# ------------------------------------------------------------------------------
67
68#Class HeapAllocator
Cary Clark08895c42018-02-01 09:37:32 -050069#Line # allocates pixel memory from heap ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040070
71#Code
Cary Clarka90ea222018-10-16 10:30:28 -040072#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -040073##
74
Cary Clark78c110e2018-02-09 16:49:09 -050075Subclass of SkBitmap::Allocator that returns a Pixel_Ref that allocates its pixel
76memory from the heap. This is the default SkBitmap::Allocator invoked by
Cary Clarkbc5697d2017-10-04 14:31:33 -040077allocPixels.
78
79# ------------------------------------------------------------------------------
80
81#Method bool allocPixelRef(SkBitmap* bitmap) override
Cary Clark682c58d2018-05-16 07:07:07 -040082#Line # allocates pixel memory ##
Cary Clark09d80c02018-10-31 12:14:03 -040083#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -040084
85#Example
Ben Wagner29380bd2017-10-09 14:43:00 -040086 SkBitmap bitmap;
87 bitmap.setInfo(SkImageInfo::MakeN32(16, 16, kPremul_SkAlphaType));
88 SkDebugf("pixel address = %p\n", bitmap.getPixels());
89 SkBitmap::HeapAllocator stdalloc;
90 if (!stdalloc.allocPixelRef(&bitmap)) {
91 SkDebugf("pixel allocation failed\n");
92 } else {
93 SkDebugf("pixel address = %p\n", bitmap.getPixels());
94 }
95#StdOut
Cary Clark884dd7d2017-10-11 10:37:52 -040096#Volatile
Ben Wagner29380bd2017-10-09 14:43:00 -040097pixel address = (nil)
98pixel address = 0x560ddd0ac670
99##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400100##
101
Cary Clark78c110e2018-02-09 16:49:09 -0500102#SeeAlso SkBitmap::Allocator tryAllocPixels
Cary Clarkbc5697d2017-10-04 14:31:33 -0400103
104##
105
Cary Clark08895c42018-02-01 09:37:32 -0500106#Class HeapAllocator ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400107
108# ------------------------------------------------------------------------------
109
110#Method SkBitmap()
111
Cary Clarkab2621d2018-01-30 10:08:57 -0500112#Line # constructs with default values ##
Cary Clark09d80c02018-10-31 12:14:03 -0400113#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400114
115#Example
116void draw(SkCanvas* canvas) {
117 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
Cary Clarkab2621d2018-01-30 10:08:57 -0500118 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
119 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clarkbc5697d2017-10-04 14:31:33 -0400120 SkBitmap bitmap;
121 for (int i = 0; i < 2; ++i) {
122 SkDebugf("width: %2d height: %2d", bitmap.width(), bitmap.height());
123 SkDebugf(" color: k%s_SkColorType", colors[bitmap.colorType()]);
124 SkDebugf(" alpha: k%s_SkAlphaType\n", alphas[bitmap.alphaType()]);
125 bitmap.setInfo(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType),
126 0);
127 }
128}
129#StdOut
Ben Wagner29380bd2017-10-09 14:43:00 -0400130width: 0 height: 0 color: kUnknown_SkColorType alpha: kUnknown_SkAlphaType
Cary Clarkbc5697d2017-10-04 14:31:33 -0400131width: 25 height: 35 color: kRGBA_8888_SkColorType alpha: kOpaque_SkAlphaType
132##
133##
134
135#SeeAlso setInfo
136
137##
138
139# ------------------------------------------------------------------------------
140
141#Method SkBitmap(const SkBitmap& src)
142
Cary Clarkab2621d2018-01-30 10:08:57 -0500143#Line # shares ownership of pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -0400144#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400145
146#Example
Ben Wagner29380bd2017-10-09 14:43:00 -0400147void draw(SkCanvas* canvas) {
148 SkBitmap original;
Cary Clark681287e2018-03-16 11:34:15 -0400149 if (original.tryAllocPixels(
150 SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType))) {
151 SkDebugf("original has pixels before copy: %s\n", original.getPixels() ? "true" : "false");
Cary Clark682c58d2018-05-16 07:07:07 -0400152 SkBitmap copy(original);
Cary Clark681287e2018-03-16 11:34:15 -0400153 SkDebugf("original has pixels after copy: %s\n", original.getPixels() ? "true" : "false");
154 SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false");
155 }
Cary Clarkbc5697d2017-10-04 14:31:33 -0400156}
157#StdOut
Ben Wagner29380bd2017-10-09 14:43:00 -0400158original has pixels before copy: true
159original has pixels after copy: true
Cary Clarkbc5697d2017-10-04 14:31:33 -0400160copy has pixels: true
161##
162##
163
164#SeeAlso setInfo setPixelRef setPixels swap
165
166##
167
168# ------------------------------------------------------------------------------
169
170#Method SkBitmap(SkBitmap&& src)
171
Cary Clarkab2621d2018-01-30 10:08:57 -0500172#Line # takes ownership of pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -0400173#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400174
175#Example
Ben Wagner29380bd2017-10-09 14:43:00 -0400176void draw(SkCanvas* canvas) {
177 SkBitmap original;
Cary Clark681287e2018-03-16 11:34:15 -0400178 if (original.tryAllocPixels(
179 SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType))) {
180 SkDebugf("original has pixels before move: %s\n", original.getPixels() ? "true" : "false");
Cary Clark682c58d2018-05-16 07:07:07 -0400181 SkBitmap copy(std::move(original));
Cary Clark681287e2018-03-16 11:34:15 -0400182 SkDebugf("original has pixels after move: %s\n", original.getPixels() ? "true" : "false");
183 SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false");
184 }
Ben Wagner29380bd2017-10-09 14:43:00 -0400185}
Cary Clarkbc5697d2017-10-04 14:31:33 -0400186#StdOut
Ben Wagner29380bd2017-10-09 14:43:00 -0400187original has pixels before move: true
188original has pixels after move: false
Cary Clarkbc5697d2017-10-04 14:31:33 -0400189copy has pixels: true
190##
191##
192
193#SeeAlso setInfo setPixelRef setPixels swap
194
195##
196
197# ------------------------------------------------------------------------------
198
199#Method ~SkBitmap()
200
Cary Clarkab2621d2018-01-30 10:08:57 -0500201#Line # releases ownership of pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -0400202#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400203
204#NoExample
205##
206
207#SeeAlso Pixel_Ref
208
209##
210
211# ------------------------------------------------------------------------------
212
213#Method SkBitmap& operator=(const SkBitmap& src)
214
Cary Clarkab2621d2018-01-30 10:08:57 -0500215#Line # shares ownership of pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -0400216#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400217
218#Example
Ben Wagner29380bd2017-10-09 14:43:00 -0400219void draw(SkCanvas* canvas) {
220 SkBitmap original;
Cary Clark681287e2018-03-16 11:34:15 -0400221 if (original.tryAllocPixels(
222 SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType))) {
223 SkDebugf("original has pixels before copy: %s\n", original.getPixels() ? "true" : "false");
Cary Clark682c58d2018-05-16 07:07:07 -0400224 SkBitmap copy = original;
Cary Clark681287e2018-03-16 11:34:15 -0400225 SkDebugf("original has pixels after copy: %s\n", original.getPixels() ? "true" : "false");
226 SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false");
227 }
Cary Clarkbc5697d2017-10-04 14:31:33 -0400228}
229#StdOut
Ben Wagner29380bd2017-10-09 14:43:00 -0400230original has pixels before copy: true
231original has pixels after copy: true
Cary Clarkbc5697d2017-10-04 14:31:33 -0400232copy has pixels: true
233##
234##
235
236#SeeAlso setInfo setPixelRef setPixels swap
237
238##
239
240# ------------------------------------------------------------------------------
241
242#Method SkBitmap& operator=(SkBitmap&& src)
243
Cary Clarkab2621d2018-01-30 10:08:57 -0500244#Line # takes ownership of pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -0400245#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400246
247#Example
Ben Wagner29380bd2017-10-09 14:43:00 -0400248void draw(SkCanvas* canvas) {
249 SkBitmap original;
Cary Clark681287e2018-03-16 11:34:15 -0400250 if (original.tryAllocPixels(
251 SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType))) {
252 SkDebugf("original has pixels before move: %s\n", original.getPixels() ? "true" : "false");
Cary Clark682c58d2018-05-16 07:07:07 -0400253 SkBitmap copy = std::move(original);
Cary Clark681287e2018-03-16 11:34:15 -0400254 SkDebugf("original has pixels after move: %s\n", original.getPixels() ? "true" : "false");
255 SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false");
256 }
Ben Wagner29380bd2017-10-09 14:43:00 -0400257}
Cary Clarkbc5697d2017-10-04 14:31:33 -0400258#StdOut
Ben Wagner29380bd2017-10-09 14:43:00 -0400259original has pixels before move: true
260original has pixels after move: false
Cary Clarkbc5697d2017-10-04 14:31:33 -0400261copy has pixels: true
262##
263##
264
265#SeeAlso setInfo setPixelRef setPixels swap
266
267##
268
269# ------------------------------------------------------------------------------
270
271#Method void swap(SkBitmap& other)
Cary Clark78de7512018-02-07 07:27:09 -0500272#In Utility
Cary Clarkab2621d2018-01-30 10:08:57 -0500273#Line # exchanges Bitmap pair ##
Cary Clark09d80c02018-10-31 12:14:03 -0400274#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400275
276#Example
Ben Wagner29380bd2017-10-09 14:43:00 -0400277void draw(SkCanvas* canvas) {
278 auto debugster = [](const char* prefix, const SkBitmap& b) -> void {
279 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
Cary Clarkab2621d2018-01-30 10:08:57 -0500280 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
281 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Ben Wagner29380bd2017-10-09 14:43:00 -0400282 SkDebugf("%s width:%d height:%d colorType:k%s_SkColorType alphaType:k%s_SkAlphaType\n",
283 prefix, b.width(), b.height(), colors[b.colorType()], alphas[b.alphaType()]);
284 };
285 SkBitmap one, two;
Cary Clark681287e2018-03-16 11:34:15 -0400286 if (!one.tryAllocPixels(
287 SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType))) {
288 return;
289 }
290 if (!two.tryAllocPixels(
291 SkImageInfo::Make(2, 2, kBGRA_8888_SkColorType, kPremul_SkAlphaType))) {
292 return;
293 }
Ben Wagner29380bd2017-10-09 14:43:00 -0400294 for (int index = 0; index < 2; ++index) {
295 debugster("one", one);
296 debugster("two", two);
297 one.swap(two);
298 }
Cary Clarkbc5697d2017-10-04 14:31:33 -0400299}
300#StdOut
Ben Wagner29380bd2017-10-09 14:43:00 -0400301one width:1 height:1 colorType:kRGBA_8888_SkColorType alphaType:kOpaque_SkAlphaType
302two width:2 height:2 colorType:kBGRA_8888_SkColorType alphaType:kPremul_SkAlphaType
303one width:2 height:2 colorType:kBGRA_8888_SkColorType alphaType:kPremul_SkAlphaType
Cary Clarkbc5697d2017-10-04 14:31:33 -0400304two width:1 height:1 colorType:kRGBA_8888_SkColorType alphaType:kOpaque_SkAlphaType
305##
306##
307
308#SeeAlso SkBitmap(SkBitmap&& src) operator=(SkBitmap&& src)
309
310##
311
312# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -0500313#Subtopic Property
Cary Clark78de7512018-02-07 07:27:09 -0500314#Line # metrics and attributes ##
315##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400316
Hal Canary99578d22017-12-14 21:13:47 -0500317#Method const SkPixmap& pixmap() const
Cary Clark78de7512018-02-07 07:27:09 -0500318#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500319#Line # returns Pixmap ##
Cary Clark09d80c02018-10-31 12:14:03 -0400320#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500321
322#Example
323 SkBitmap bitmap;
324 bitmap.allocPixels(SkImageInfo::MakeN32Premul(10, 11));
325 SkCanvas offscreen(bitmap);
326 offscreen.clear(SK_ColorWHITE);
327 SkPaint paint;
328 offscreen.drawString("&", 0, 10, paint);
Hal Canary99578d22017-12-14 21:13:47 -0500329 const SkPixmap& pixmap = bitmap.pixmap();
Cary Clark0c5f5462017-12-15 11:21:51 -0500330 if (pixmap.addr()) {
Hal Canary99578d22017-12-14 21:13:47 -0500331 SkPMColor pmWhite = *pixmap.addr32(0, 0);
332 for (int y = 0; y < pixmap.height(); ++y) {
333 for (int x = 0; x < pixmap.width(); ++x) {
334 SkDebugf("%c", *pixmap.addr32(x, y) == pmWhite ? '-' : 'x');
Cary Clark0c5f5462017-12-15 11:21:51 -0500335 }
336 SkDebugf("\n");
337 }
338 }
339 #StdOut
340----------
341---xx-----
342--x--x----
343--x-------
344--xx------
345--x-x---x-
346-x---x--x-
347-x----xx--
348-xx---x---
349--xxxx-xx-
350----------
351 #StdOut ##
352
353##
354
355#SeeAlso peekPixels installPixels readPixels writePixels
356
357##
358
359# ------------------------------------------------------------------------------
360
Cary Clarkbc5697d2017-10-04 14:31:33 -0400361#Method const SkImageInfo& info() const
Cary Clark78de7512018-02-07 07:27:09 -0500362#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500363#Line # returns Image_Info ##
Cary Clark09d80c02018-10-31 12:14:03 -0400364#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400365
366#Example
367#Image 4
Ben Wagner29380bd2017-10-09 14:43:00 -0400368void draw(SkCanvas* canvas) {
369 // SkBitmap source; // pre-populated with soccer ball by fiddle.skia.org
370 const SkImageInfo& info = source.info();
371 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
Cary Clarkab2621d2018-01-30 10:08:57 -0500372 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
373 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Ben Wagner29380bd2017-10-09 14:43:00 -0400374 SkDebugf("width: %d height: %d color: %s alpha: %s\n", info.width(), info.height(),
375 colors[info.colorType()], alphas[info.alphaType()]);
376#StdOut
377width: 56 height: 56 color: BGRA_8888 alpha: Opaque
378##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400379}
380##
381
382#SeeAlso Image_Info
383
384##
385
386# ------------------------------------------------------------------------------
387
388#Method int width() const
Cary Clark78de7512018-02-07 07:27:09 -0500389#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500390#Line # returns pixel column count ##
Cary Clark2be81cf2018-09-13 12:04:30 -0400391Returns pixel count in each row. Should be equal or less than
392#Formula # rowBytes() / info().bytesPerPixel() ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400393
Cary Clark80247e52018-07-11 16:18:41 -0400394May be less than pixelRef().width(). Will not exceed pixelRef().width() less
Cary Clarkbc5697d2017-10-04 14:31:33 -0400395pixelRefOrigin().fX.
396
397#Return pixel width in Image_Info ##
398
399#Example
400 SkImageInfo info = SkImageInfo::MakeA8(16, 32);
401 SkBitmap bitmap;
402 bitmap.setInfo(info);
403 SkDebugf("bitmap width: %d info width: %d\n", bitmap.width(), info.width());
404#StdOut
405bitmap width: 16 info width: 16
406##
407##
408
409#SeeAlso height() SkPixelRef::width() SkImageInfo::width()
410
411##
412
413# ------------------------------------------------------------------------------
414
415#Method int height() const
Cary Clark78de7512018-02-07 07:27:09 -0500416#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500417#Line # returns pixel row count ##
Cary Clark09d80c02018-10-31 12:14:03 -0400418#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400419
420#Example
421 SkImageInfo info = SkImageInfo::MakeA8(16, 32);
422 SkBitmap bitmap;
423 bitmap.setInfo(info);
424 SkDebugf("bitmap height: %d info height: %d\n", bitmap.height(), info.height());
425#StdOut
426bitmap height: 32 info height: 32
427##
428##
429
430#SeeAlso width() SkPixelRef::height() SkImageInfo::height()
431
432##
433
434# ------------------------------------------------------------------------------
435
436#Method SkColorType colorType() const
Cary Clark78de7512018-02-07 07:27:09 -0500437#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500438#Line # returns Image_Info Color_Type ##
Cary Clark1a8d7622018-03-05 13:26:16 -0500439Returns Color_Type, one of: #list_of_color_types#.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400440
441#Return Color_Type in Image_Info ##
442
443#Example
Cary Clarkab2621d2018-01-30 10:08:57 -0500444 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
445 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Ben Wagner29380bd2017-10-09 14:43:00 -0400446 SkBitmap bitmap;
447 bitmap.setInfo(SkImageInfo::MakeA8(16, 32));
448 SkDebugf("color type: k" "%s" "_SkColorType\n", colors[bitmap.colorType()]);
Cary Clarkbc5697d2017-10-04 14:31:33 -0400449#StdOut
Cary Clarkab2621d2018-01-30 10:08:57 -0500450color type: kAlpha_8_SkColorType
Cary Clarkbc5697d2017-10-04 14:31:33 -0400451##
452##
453
454#SeeAlso alphaType() SkImageInfo::colorType
455
456##
457
458# ------------------------------------------------------------------------------
459
460#Method SkAlphaType alphaType() const
Cary Clark78de7512018-02-07 07:27:09 -0500461#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500462#Line # returns Image_Info Alpha_Type ##
Cary Clark681287e2018-03-16 11:34:15 -0400463Returns Alpha_Type, one of: #list_of_alpha_types#.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400464
465#Return Alpha_Type in Image_Info ##
466
467#Example
468 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
469 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
470 SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[pixmap.alphaType()]);
471#StdOut
472alpha type: kPremul_SkAlphaType
473##
474##
475
476#SeeAlso colorType() SkImageInfo::alphaType
477
478##
479
480# ------------------------------------------------------------------------------
481
482#Method SkColorSpace* colorSpace() const
Cary Clark78de7512018-02-07 07:27:09 -0500483#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500484#Line # returns Image_Info Color_Space ##
Cary Clark09d80c02018-10-31 12:14:03 -0400485#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400486
487#Example
488#Description
489SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma
490and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma.
491##
Ben Wagner29380bd2017-10-09 14:43:00 -0400492 SkBitmap bitmap;
Cary Clark682c58d2018-05-16 07:07:07 -0400493 bitmap.setInfo(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
Cary Clarkbc5697d2017-10-04 14:31:33 -0400494 SkColorSpace::MakeSRGBLinear()));
495 SkColorSpace* colorSpace = bitmap.colorSpace();
496 SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
497 colorSpace->gammaCloseToSRGB() ? "true" : "false",
498 colorSpace->gammaIsLinear() ? "true" : "false",
499 colorSpace->isSRGB() ? "true" : "false");
500#StdOut
501gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
502##
503##
504
505#SeeAlso Color_Space SkImageInfo::colorSpace
506
507##
508
509# ------------------------------------------------------------------------------
510
511#Method sk_sp<SkColorSpace> refColorSpace() const
Cary Clark78de7512018-02-07 07:27:09 -0500512#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500513#Line # returns Image_Info Color_Space ##
Cary Clark09d80c02018-10-31 12:14:03 -0400514#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400515
516#Example
Ben Wagner29380bd2017-10-09 14:43:00 -0400517 SkBitmap bitmap1, bitmap2;
Cary Clark682c58d2018-05-16 07:07:07 -0400518 bitmap1.setInfo(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
Cary Clarkbc5697d2017-10-04 14:31:33 -0400519 SkColorSpace::MakeSRGBLinear()));
520 bitmap2.setInfo(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
521 bitmap1.refColorSpace()));
522 SkColorSpace* colorSpace = bitmap2.colorSpace();
523 SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
524 colorSpace->gammaCloseToSRGB() ? "true" : "false",
525 colorSpace->gammaIsLinear() ? "true" : "false",
526 colorSpace->isSRGB() ? "true" : "false");
527#StdOut
528gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
529##
530##
531
532#SeeAlso Color_Space SkImageInfo::colorSpace
533
534##
535
536# ------------------------------------------------------------------------------
537
538#Method int bytesPerPixel() const
Cary Clark78de7512018-02-07 07:27:09 -0500539#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500540#Line # returns number of bytes in pixel based on Color_Type ##
Cary Clark09d80c02018-10-31 12:14:03 -0400541#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400542
543#Example
Cary Clarkab2621d2018-01-30 10:08:57 -0500544 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
545 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clarkbc5697d2017-10-04 14:31:33 -0400546 SkImageInfo info = SkImageInfo::MakeA8(1, 1);
547 SkBitmap bitmap;
Cary Clark1a8d7622018-03-05 13:26:16 -0500548 for (SkColorType colorType : { #list_of_color_types#
549 } ) {
Cary Clarkbc5697d2017-10-04 14:31:33 -0400550 bitmap.setInfo(info.makeColorType(colorType));
551 SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d\n",
Cary Clarkab2621d2018-01-30 10:08:57 -0500552 colors[colorType], 13 - strlen(colors[colorType]), " ",
Cary Clarkbc5697d2017-10-04 14:31:33 -0400553 bitmap.bytesPerPixel());
554 }
555#StdOut
Cary Clark98aebac2018-03-13 09:02:35 -0400556color: kUnknown_SkColorType bytesPerPixel: 0
557color: kAlpha_8_SkColorType bytesPerPixel: 1
558color: kRGB_565_SkColorType bytesPerPixel: 2
559color: kARGB_4444_SkColorType bytesPerPixel: 2
560color: kRGBA_8888_SkColorType bytesPerPixel: 4
561color: kRGB_888x_SkColorType bytesPerPixel: 4
562color: kBGRA_8888_SkColorType bytesPerPixel: 4
563color: kRGBA_1010102_SkColorType bytesPerPixel: 4
564color: kRGB_101010x_SkColorType bytesPerPixel: 4
565color: kGray_8_SkColorType bytesPerPixel: 1
Cary Clarkab2621d2018-01-30 10:08:57 -0500566color: kRGBA_F16_SkColorType bytesPerPixel: 8
Cary Clarkbc5697d2017-10-04 14:31:33 -0400567##
568##
569
Cary Clark681287e2018-03-16 11:34:15 -0400570#SeeAlso rowBytes rowBytesAsPixels width shiftPerPixel SkImageInfo::bytesPerPixel
Cary Clarkbc5697d2017-10-04 14:31:33 -0400571
572##
573
574# ------------------------------------------------------------------------------
575
576#Method int rowBytesAsPixels() const
Cary Clark78de7512018-02-07 07:27:09 -0500577#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500578#Line # returns interval between rows in pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -0400579#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400580
581#Example
582 SkBitmap bitmap;
583 for (int rowBytes : { 4, 5, 6, 7, 8} ) {
584 bitmap.setInfo(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), rowBytes);
585 SkDebugf("rowBytes: %d rowBytesAsPixels: %d\n", rowBytes, bitmap.rowBytesAsPixels());
586 }
587#StdOut
588rowBytes: 4 rowBytesAsPixels: 1
589rowBytes: 5 rowBytesAsPixels: 1
590rowBytes: 6 rowBytesAsPixels: 1
591rowBytes: 7 rowBytesAsPixels: 1
592rowBytes: 8 rowBytesAsPixels: 2
593##
594##
595
596#SeeAlso rowBytes shiftPerPixel width bytesPerPixel
597
598##
599
600# ------------------------------------------------------------------------------
601
602#Method int shiftPerPixel() const
Cary Clark78de7512018-02-07 07:27:09 -0500603#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500604#Line # returns bit shift from pixels to bytes ##
Cary Clark09d80c02018-10-31 12:14:03 -0400605#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400606
607#Example
Cary Clarkab2621d2018-01-30 10:08:57 -0500608 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
609 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clarkbc5697d2017-10-04 14:31:33 -0400610 SkImageInfo info = SkImageInfo::MakeA8(1, 1);
611 SkBitmap bitmap;
Cary Clark1a8d7622018-03-05 13:26:16 -0500612 for (SkColorType colorType : { #list_of_color_types#
613 } ) {
Cary Clarkbc5697d2017-10-04 14:31:33 -0400614 bitmap.setInfo(info.makeColorType(colorType));
615 SkDebugf("color: k" "%s" "_SkColorType" "%*s" "shiftPerPixel: %d\n",
Cary Clark1a8d7622018-03-05 13:26:16 -0500616 colors[colorType], 14 - strlen(colors[colorType]), " ",
Cary Clarkbc5697d2017-10-04 14:31:33 -0400617 bitmap.shiftPerPixel());
618 }
619#StdOut
Cary Clark98aebac2018-03-13 09:02:35 -0400620color: kUnknown_SkColorType shiftPerPixel: 0
621color: kAlpha_8_SkColorType shiftPerPixel: 0
622color: kRGB_565_SkColorType shiftPerPixel: 1
623color: kARGB_4444_SkColorType shiftPerPixel: 1
624color: kRGBA_8888_SkColorType shiftPerPixel: 2
625color: kRGB_888x_SkColorType shiftPerPixel: 2
626color: kBGRA_8888_SkColorType shiftPerPixel: 2
627color: kRGBA_1010102_SkColorType shiftPerPixel: 2
628color: kRGB_101010x_SkColorType shiftPerPixel: 2
629color: kGray_8_SkColorType shiftPerPixel: 0
Cary Clark1a8d7622018-03-05 13:26:16 -0500630color: kRGBA_F16_SkColorType shiftPerPixel: 3
Cary Clarkbc5697d2017-10-04 14:31:33 -0400631##
632##
633
634#SeeAlso rowBytes rowBytesAsPixels width bytesPerPixel
635
636##
637
638# ------------------------------------------------------------------------------
639
640#Method bool empty() const
Cary Clark78de7512018-02-07 07:27:09 -0500641#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500642#Line # returns true if Image_Info has zero width() or height() ##
Cary Clark09d80c02018-10-31 12:14:03 -0400643#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400644
645#Example
646 SkBitmap bitmap;
647 for (int width : { 0, 2 } ) {
648 for (int height : { 0, 2 } ) {
649 bitmap.setInfo(SkImageInfo::MakeA8(width, height));
650 SkDebugf("width: %d height: %d empty: %s\n", width, height,
651 bitmap.empty() ? "true" : "false");
652 }
653 }
654#StdOut
655width: 0 height: 0 empty: true
656width: 0 height: 2 empty: true
657width: 2 height: 0 empty: true
658width: 2 height: 2 empty: false
659##
660##
661
Cary Clark682c58d2018-05-16 07:07:07 -0400662#SeeAlso height() width() drawsNothing
Cary Clarkbc5697d2017-10-04 14:31:33 -0400663
664##
665
666# ------------------------------------------------------------------------------
667
668#Method bool isNull() const
Cary Clark78de7512018-02-07 07:27:09 -0500669#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500670#Line # returns true if Pixel_Ref is nullptr ##
Cary Clark09d80c02018-10-31 12:14:03 -0400671#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400672
673#Example
Ben Wagner29380bd2017-10-09 14:43:00 -0400674 SkBitmap bitmap;
675 SkDebugf("empty bitmap does %shave pixels\n", bitmap.isNull() ? "not " : "");
676 bitmap.setInfo(SkImageInfo::MakeA8(8, 8));
677 SkDebugf("bitmap with dimensions does %shave pixels\n", bitmap.isNull() ? "not " : "");
678 bitmap.allocPixels();
679 SkDebugf("allocated bitmap does %shave pixels\n", bitmap.isNull() ? "not " : "");
Cary Clarkbc5697d2017-10-04 14:31:33 -0400680#StdOut
Ben Wagner29380bd2017-10-09 14:43:00 -0400681empty bitmap does not have pixels
682bitmap with dimensions does not have pixels
Cary Clarkbc5697d2017-10-04 14:31:33 -0400683allocated bitmap does have pixels
684##
685##
686
687#SeeAlso empty() drawsNothing pixelRef
688
689##
690
691# ------------------------------------------------------------------------------
692
693#Method bool drawsNothing() const
Cary Clark78de7512018-02-07 07:27:09 -0500694#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500695#Line # returns true if no width(), no height(), or no Pixel_Ref ##
Cary Clark09d80c02018-10-31 12:14:03 -0400696#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400697
698#Example
Ben Wagner29380bd2017-10-09 14:43:00 -0400699 SkBitmap bitmap;
700 for (int w : { 0, 8 } ) {
701 for (bool allocate : { false, true} ) {
702 bitmap.setInfo(SkImageInfo::MakeA8(w, 8));
703 allocate ? bitmap.allocPixels() : (void) 0 ;
704 SkDebugf("empty:%s isNull:%s drawsNothing:%s\n", bitmap.empty() ? "true " : "false",
705 bitmap.isNull() ? "true " : "false", bitmap.drawsNothing() ? "true" : "false");
706 }
707 }
708#StdOut
709empty:true isNull:true drawsNothing:true
710empty:true isNull:false drawsNothing:true
711empty:false isNull:true drawsNothing:true
712empty:false isNull:false drawsNothing:false
713##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400714##
715
716#SeeAlso empty() isNull pixelRef
717
718##
719
720# ------------------------------------------------------------------------------
721
722#Method size_t rowBytes() const
Cary Clark78de7512018-02-07 07:27:09 -0500723#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500724#Line # returns interval between rows in bytes ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400725Returns row bytes, the interval from one pixel row to the next. Row bytes
Cary Clark2be81cf2018-09-13 12:04:30 -0400726is at least as large as: #Formula # width() * info().bytesPerPixel() ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400727
728Returns zero if colorType is kUnknown_SkColorType, or if row bytes supplied to
729setInfo is not large enough to hold a row of pixels.
730
731#Return byte length of pixel row ##
732
733#Example
Ben Wagner29380bd2017-10-09 14:43:00 -0400734 SkBitmap bitmap;
735 for (int rowBytes : { 2, 8 } ) {
736 bool result = bitmap.setInfo(SkImageInfo::MakeA8(4, 4), rowBytes);
737 SkDebugf("setInfo returned:%s rowBytes:%d\n", result ? "true " : "false", bitmap.rowBytes());
738 }
739#StdOut
740setInfo returned:false rowBytes:0
741setInfo returned:true rowBytes:8
742##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400743##
744
745#SeeAlso info() setInfo SkImageInfo::minRowBytes
746
747##
748
749# ------------------------------------------------------------------------------
750
751#Method bool setAlphaType(SkAlphaType alphaType)
Cary Clark78de7512018-02-07 07:27:09 -0500752#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500753#Line # sets Alpha_Type of shared pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -0400754#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400755
756#Example
Ben Wagner29380bd2017-10-09 14:43:00 -0400757void draw(SkCanvas* canvas) {
Cary Clarkab2621d2018-01-30 10:08:57 -0500758 const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
759 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" };
Cary Clark682c58d2018-05-16 07:07:07 -0400760 const char* alphas[] = {"Unknown ", "Opaque ", "Premul ", "Unpremul"};
Cary Clarkab2621d2018-01-30 10:08:57 -0500761 SkBitmap bitmap;
Cary Clark681287e2018-03-16 11:34:15 -0400762 SkAlphaType alphaTypes[] = { #list_of_alpha_types#
763 };
Cary Clarka90ea222018-10-16 10:30:28 -0400764 SkDebugf("%18s%15s%17s%18s%19s\n", "Canonical", "Unknown", "Opaque", "Premul", "Unpremul");
Cary Clark1a8d7622018-03-05 13:26:16 -0500765 for (SkColorType colorType : { #list_of_color_types#
766 } ) {
Ben Wagner29380bd2017-10-09 14:43:00 -0400767 for (SkAlphaType canonicalAlphaType : alphaTypes) {
768 SkColorTypeValidateAlphaType(colorType, kUnknown_SkAlphaType, &canonicalAlphaType );
Cary Clarka90ea222018-10-16 10:30:28 -0400769 SkDebugf("%12s %9s ", colors[(int) colorType], alphas[(int) canonicalAlphaType ]);
Ben Wagner29380bd2017-10-09 14:43:00 -0400770 for (SkAlphaType alphaType : alphaTypes) {
771 bitmap.setInfo(SkImageInfo::Make(4, 4, colorType, canonicalAlphaType));
772 bool result = bitmap.setAlphaType(alphaType);
773 SkDebugf("%s %s ", result ? "true " : "false", alphas[(int) bitmap.alphaType()]);
774 }
775 SkDebugf("\n");
776 }
777 }
Cary Clarkbc5697d2017-10-04 14:31:33 -0400778}
779##
780
781#SeeAlso Alpha_Type Color_Type Image_Info setInfo
782
783##
784
785# ------------------------------------------------------------------------------
786
787#Method void* getPixels() const
Cary Clark78de7512018-02-07 07:27:09 -0500788#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500789#Line # returns address of pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -0400790#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400791
792#Example
Ben Wagner29380bd2017-10-09 14:43:00 -0400793 SkBitmap bitmap;
794 bitmap.setInfo(SkImageInfo::MakeN32(4, 4, kPremul_SkAlphaType));
795 bitmap.allocPixels();
796 bitmap.eraseColor(0x00000000);
797 void* baseAddr = bitmap.getPixels();
798 *(SkPMColor*)baseAddr = 0xFFFFFFFF;
799 SkDebugf("bitmap.getColor(0, 1) %c= 0x00000000\n",
800 bitmap.getColor(0, 1) == 0x00000000 ? '=' : '!');
801 SkDebugf("bitmap.getColor(0, 0) %c= 0xFFFFFFFF\n",
802 bitmap.getColor(0, 0) == 0xFFFFFFFF ? '=' : '!');
Cary Clarkbc5697d2017-10-04 14:31:33 -0400803#StdOut
Ben Wagner29380bd2017-10-09 14:43:00 -0400804bitmap.getColor(0, 1) == 0x00000000
Cary Clarkbc5697d2017-10-04 14:31:33 -0400805bitmap.getColor(0, 0) == 0xFFFFFFFF
806##
807##
808
809#SeeAlso isNull drawsNothing
810
811##
812
813# ------------------------------------------------------------------------------
814
815#Method size_t computeByteSize() const
Cary Clark78de7512018-02-07 07:27:09 -0500816#In Utility
Cary Clarkab2621d2018-01-30 10:08:57 -0500817#Line # returns size required for pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -0400818#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400819
820#Example
Ben Wagner29380bd2017-10-09 14:43:00 -0400821 SkBitmap bitmap;
Cary Clarkbc5697d2017-10-04 14:31:33 -0400822 for (int width : { 1, 1000, 1000000 } ) {
823 for (int height: { 1, 1000, 1000000 } ) {
824 SkImageInfo imageInfo = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType);
825 bitmap.setInfo(imageInfo, width * 5);
826 SkDebugf("width: %7d height: %7d computeByteSize: %13lld\n", width, height,
827 bitmap.computeByteSize());
828 }
829 }
830#StdOut
Ben Wagner29380bd2017-10-09 14:43:00 -0400831width: 1 height: 1 computeByteSize: 4
832width: 1 height: 1000 computeByteSize: 4999
833width: 1 height: 1000000 computeByteSize: 4999999
834width: 1000 height: 1 computeByteSize: 4000
835width: 1000 height: 1000 computeByteSize: 4999000
836width: 1000 height: 1000000 computeByteSize: 4999999000
837width: 1000000 height: 1 computeByteSize: 4000000
838width: 1000000 height: 1000 computeByteSize: 4999000000
Cary Clarkbc5697d2017-10-04 14:31:33 -0400839width: 1000000 height: 1000000 computeByteSize: 4999999000000
840##
841##
842
843#SeeAlso SkImageInfo::computeByteSize
844
845##
846
847# ------------------------------------------------------------------------------
848
Cary Clarkbc5697d2017-10-04 14:31:33 -0400849#Method bool isImmutable() const
Cary Clark78de7512018-02-07 07:27:09 -0500850#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500851#Line # returns true if pixels will not change ##
Cary Clark09d80c02018-10-31 12:14:03 -0400852#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400853
854#Example
Cary Clark682c58d2018-05-16 07:07:07 -0400855 SkBitmap original;
Ben Wagner29380bd2017-10-09 14:43:00 -0400856 SkImageInfo info = SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
857 if (original.tryAllocPixels(info)) {
858 original.setImmutable();
859 SkBitmap copy;
Cary Clark682c58d2018-05-16 07:07:07 -0400860 original.extractSubset(&copy, {5, 10, 15, 20});
Ben Wagner29380bd2017-10-09 14:43:00 -0400861 SkDebugf("original is " "%s" "immutable\n", original.isImmutable() ? "" : "not ");
862 SkDebugf("copy is " "%s" "immutable\n", copy.isImmutable() ? "" : "not ");
Cary Clarkbc5697d2017-10-04 14:31:33 -0400863 }
864#StdOut
Ben Wagner29380bd2017-10-09 14:43:00 -0400865original is immutable
Cary Clarkbc5697d2017-10-04 14:31:33 -0400866copy is immutable
867##
868##
869
870#SeeAlso setImmutable SkPixelRef::isImmutable SkImage
871
872##
873
874# ------------------------------------------------------------------------------
875
876#Method void setImmutable()
Cary Clark78de7512018-02-07 07:27:09 -0500877#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500878#Line # marks that pixels will not change ##
Cary Clark09d80c02018-10-31 12:14:03 -0400879#Populate
Cary Clark682c58d2018-05-16 07:07:07 -0400880
Cary Clarkbc5697d2017-10-04 14:31:33 -0400881#Example
882#Description
883Triggers assert if SK_DEBUG is true, runs fine otherwise.
884##
Ben Wagner29380bd2017-10-09 14:43:00 -0400885 SkBitmap bitmap;
886 bitmap.setInfo(SkImageInfo::MakeN32(4, 4, kPremul_SkAlphaType));
887 bitmap.allocPixels();
888 SkCanvas offscreen(bitmap);
889 SkDebugf("draw white\n");
890 offscreen.clear(SK_ColorWHITE);
891 bitmap.setImmutable();
892 SkDebugf("draw black\n");
Cary Clarkbc5697d2017-10-04 14:31:33 -0400893 offscreen.clear(SK_ColorBLACK);
894##
895
896#SeeAlso isImmutable SkPixelRef::setImmutable SkImage
897
898##
899
900# ------------------------------------------------------------------------------
901
902#Method bool isOpaque() const
Cary Clark78de7512018-02-07 07:27:09 -0500903#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500904#Line # returns true if Image_Info describes opaque pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -0400905#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400906
907#Example
908#Description
909 isOpaque ignores whether all pixels are opaque or not.
910##
Ben Wagner29380bd2017-10-09 14:43:00 -0400911 const int height = 2;
912 const int width = 2;
913 SkBitmap bitmap;
914 bitmap.setInfo(SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType));
915 for (int index = 0; index < 2; ++index) {
916 bitmap.allocPixels();
917 bitmap.eraseColor(0x00000000);
918 SkDebugf("isOpaque: %s\n", bitmap.isOpaque() ? "true" : "false");
919 bitmap.eraseColor(0xFFFFFFFF);
920 SkDebugf("isOpaque: %s\n", bitmap.isOpaque() ? "true" : "false");
921 bitmap.setInfo(bitmap.info().makeAlphaType(kOpaque_SkAlphaType));
922 }
Cary Clarkbc5697d2017-10-04 14:31:33 -0400923#StdOut
924isOpaque: false
925isOpaque: false
926isOpaque: true
927isOpaque: true
928##
929##
930
931#SeeAlso ComputeIsOpaque SkImageInfo::isOpaque
932
933##
934
935# ------------------------------------------------------------------------------
936
937#Method bool isVolatile() const
Cary Clark78de7512018-02-07 07:27:09 -0500938#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500939#Line # returns true if pixels should not be cached ##
Cary Clark09d80c02018-10-31 12:14:03 -0400940#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400941
942#Example
Cary Clark682c58d2018-05-16 07:07:07 -0400943 SkBitmap original;
Ben Wagner29380bd2017-10-09 14:43:00 -0400944 SkImageInfo info = SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
945 if (original.tryAllocPixels(info)) {
946 original.setIsVolatile(true);
947 SkBitmap copy;
Cary Clark682c58d2018-05-16 07:07:07 -0400948 original.extractSubset(&copy, {5, 10, 15, 20});
Ben Wagner29380bd2017-10-09 14:43:00 -0400949 SkDebugf("original is " "%s" "volatile\n", original.isVolatile() ? "" : "not ");
950 SkDebugf("copy is " "%s" "volatile\n", copy.isImmutable() ? "" : "not ");
951 }
Cary Clarkbc5697d2017-10-04 14:31:33 -0400952#StdOut
Ben Wagner29380bd2017-10-09 14:43:00 -0400953original is volatile
Cary Clarkbc5697d2017-10-04 14:31:33 -0400954copy is not volatile
955##
956##
957
958#SeeAlso setIsVolatile
959
960##
961
962# ------------------------------------------------------------------------------
963
964#Method void setIsVolatile(bool isVolatile)
Cary Clark78de7512018-02-07 07:27:09 -0500965#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500966#Line # marks if pixels should not be cached ##
Cary Clark09d80c02018-10-31 12:14:03 -0400967#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400968
969#Example
970#Height 20
Cary Clark682c58d2018-05-16 07:07:07 -0400971 SkBitmap bitmap;
Ben Wagner29380bd2017-10-09 14:43:00 -0400972 bitmap.setInfo(SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType));
973 bitmap.allocPixels();
974 bitmap.eraseColor(SK_ColorRED);
975 canvas->scale(16, 16);
976 canvas->drawBitmap(bitmap, 0, 0);
977 *(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorBLUE);
978 canvas->drawBitmap(bitmap, 2, 0);
979 bitmap.setIsVolatile(true);
980 *(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorGREEN);
981 canvas->drawBitmap(bitmap, 4, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -0400982##
983
984#SeeAlso isVolatile
985
986##
987
988# ------------------------------------------------------------------------------
989
990#Method void reset()
Cary Clark61313f32018-10-08 14:57:48 -0400991#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -0500992#Line # sets to default values, releases pixel ownership ##
Cary Clark09d80c02018-10-31 12:14:03 -0400993#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400994
995#Example
Cary Clark682c58d2018-05-16 07:07:07 -0400996 SkBitmap bitmap;
Ben Wagner29380bd2017-10-09 14:43:00 -0400997 bitmap.setInfo(SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType));
998 bitmap.allocPixels();
999 SkDebugf("width:%d height:%d isNull:%s\n", bitmap.width(), bitmap.height(),
1000 bitmap.isNull() ? "true" : "false");
1001 bitmap.reset();
1002 SkDebugf("width:%d height:%d isNull:%s\n", bitmap.width(), bitmap.height(),
1003 bitmap.isNull() ? "true" : "false");
1004#StdOut
1005width:1 height:1 isNull:false
1006width:0 height:0 isNull:true
1007##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001008##
1009
1010#SeeAlso SkBitmap() SkAlphaType SkColorType
1011
1012##
1013
1014# ------------------------------------------------------------------------------
1015
1016#Method static bool ComputeIsOpaque(const SkBitmap& bm)
Cary Clark78de7512018-02-07 07:27:09 -05001017#In Utility
Cary Clarkab2621d2018-01-30 10:08:57 -05001018#Line # returns true if all pixels are opaque ##
Cary Clark09d80c02018-10-31 12:14:03 -04001019#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001020
1021#Example
Ben Wagner29380bd2017-10-09 14:43:00 -04001022 SkBitmap bitmap;
1023 bitmap.setInfo(SkImageInfo::Make(2, 2, kN32_SkColorType, kPremul_SkAlphaType));
1024 for (int index = 0; index < 2; ++index) {
1025 bitmap.allocPixels();
1026 bitmap.eraseColor(0x00000000);
1027 SkDebugf("computeIsOpaque: %s\n", SkBitmap::ComputeIsOpaque(bitmap) ? "true" : "false");
1028 bitmap.eraseColor(0xFFFFFFFF);
1029 SkDebugf("computeIsOpaque: %s\n", SkBitmap::ComputeIsOpaque(bitmap) ? "true" : "false");
1030 bitmap.setInfo(bitmap.info().makeAlphaType(kOpaque_SkAlphaType));
Cary Clarkbc5697d2017-10-04 14:31:33 -04001031 }
1032#StdOut
1033computeIsOpaque: false
1034computeIsOpaque: true
1035computeIsOpaque: false
1036computeIsOpaque: true
1037##
1038##
1039
1040#SeeAlso isOpaque Color_Type Alpha
1041
1042##
1043
1044# ------------------------------------------------------------------------------
1045
1046#Method void getBounds(SkRect* bounds) const
Cary Clark78de7512018-02-07 07:27:09 -05001047#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05001048#Line # returns width() and height() as Rectangle ##
Cary Clark09d80c02018-10-31 12:14:03 -04001049#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001050
1051#Example
1052#Height 160
1053#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04001054 SkRect bounds;
1055 source.getBounds(&bounds);
1056 bounds.offset(100, 100);
1057 SkPaint paint;
1058 paint.setColor(SK_ColorGRAY);
1059 canvas->scale(.25f, .25f);
1060 canvas->drawRect(bounds, paint);
1061 canvas->drawBitmap(source, 40, 40);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001062##
1063
Cary Clark682c58d2018-05-16 07:07:07 -04001064#SeeAlso bounds()
Cary Clarkbc5697d2017-10-04 14:31:33 -04001065
1066##
1067
1068# ------------------------------------------------------------------------------
1069
1070#Method void getBounds(SkIRect* bounds) const
Cary Clark09d80c02018-10-31 12:14:03 -04001071#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001072
1073#Example
1074#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04001075 SkIRect bounds;
1076 source.getBounds(&bounds);
1077 bounds.inset(100, 100);
1078 SkBitmap bitmap;
1079 source.extractSubset(&bitmap, bounds);
1080 canvas->scale(.5f, .5f);
1081 canvas->drawBitmap(bitmap, 10, 10);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001082##
1083
Cary Clark682c58d2018-05-16 07:07:07 -04001084#SeeAlso bounds()
Cary Clarkbc5697d2017-10-04 14:31:33 -04001085
1086##
1087
1088# ------------------------------------------------------------------------------
1089
1090#Method SkIRect bounds() const
Cary Clark78de7512018-02-07 07:27:09 -05001091#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05001092#Line # returns width() and height() as Rectangle ##
Cary Clark09d80c02018-10-31 12:14:03 -04001093#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001094
1095#Example
Cary Clark681287e2018-03-16 11:34:15 -04001096#Height 64
Cary Clarkbc5697d2017-10-04 14:31:33 -04001097#Image 4
Cary Clark61ca7c52018-01-02 11:34:14 -05001098 canvas->scale(.5f, .5f);
Ben Wagner29380bd2017-10-09 14:43:00 -04001099 SkIRect bounds = source.bounds();
1100 for (int x : { 0, bounds.width() } ) {
1101 for (int y : { 0, bounds.height() } ) {
1102 canvas->drawBitmap(source, x, y);
1103 }
1104 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04001105##
1106
Cary Clark682c58d2018-05-16 07:07:07 -04001107#SeeAlso getBounds
Cary Clarkbc5697d2017-10-04 14:31:33 -04001108
1109##
1110
1111# ------------------------------------------------------------------------------
1112
1113#Method SkISize dimensions() const
Cary Clark78de7512018-02-07 07:27:09 -05001114#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05001115#Line # returns width() and height() ##
Cary Clark09d80c02018-10-31 12:14:03 -04001116#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001117
1118#Example
Ben Wagner29380bd2017-10-09 14:43:00 -04001119 SkBitmap bitmap;
1120 bitmap.setInfo(SkImageInfo::MakeN32(33, 55, kOpaque_SkAlphaType));
1121 SkISize dimensions = bitmap.dimensions();
1122 SkRect bounds;
1123 bitmap.getBounds(&bounds);
1124 SkRect dimensionsAsBounds = SkRect::Make(dimensions);
1125 SkDebugf("dimensionsAsBounds %c= bounds\n", dimensionsAsBounds == bounds ? '=' : '!');
Cary Clarkbc5697d2017-10-04 14:31:33 -04001126##
1127
Cary Clarka90ea222018-10-16 10:30:28 -04001128#SeeAlso height width
Cary Clarkbc5697d2017-10-04 14:31:33 -04001129
1130##
1131
1132# ------------------------------------------------------------------------------
1133
1134#Method SkIRect getSubset() const
Cary Clark78de7512018-02-07 07:27:09 -05001135#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05001136#Line # returns bounds offset by origin ##
Cary Clark09d80c02018-10-31 12:14:03 -04001137#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001138
1139#Example
1140#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04001141 SkIRect bounds;
1142 source.getBounds(&bounds);
1143 bounds.inset(100, 100);
1144 SkBitmap subset;
1145 source.extractSubset(&subset, bounds);
1146 SkIRect r = source.getSubset();
1147 SkDebugf("source: %d, %d, %d, %d\n", r.fLeft, r.fTop, r.fRight, r.fBottom);
1148 r = subset.getSubset();
1149 SkDebugf("subset: %d, %d, %d, %d\n", r.fLeft, r.fTop, r.fRight, r.fBottom);
1150#StdOut
1151source: 0, 0, 512, 512
1152subset: 100, 100, 412, 412
1153##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001154##
1155
1156#SeeAlso extractSubset getBounds
1157
1158##
1159
1160# ------------------------------------------------------------------------------
1161
1162#Method bool setInfo(const SkImageInfo& imageInfo, size_t rowBytes = 0)
Cary Clark78de7512018-02-07 07:27:09 -05001163#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -05001164#Line # sets height, width, Color_Type, and so on, releasing pixels ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001165Sets width, height, Alpha_Type, Color_Type, Color_Space, and optional
1166rowBytes. Frees pixels, and returns true if successful.
1167
Cary Clark77b3f3a2018-11-07 14:59:03 -05001168imageInfo.alphaType() may be altered to a value permitted by imageInfo.colorSpace().
1169If imageInfo.colorType() is kUnknown_SkColorType, imageInfo.alphaType() is
Cary Clarkbc5697d2017-10-04 14:31:33 -04001170set to kUnknown_SkAlphaType.
Cary Clark77b3f3a2018-11-07 14:59:03 -05001171If imageInfo.colorType() is kAlpha_8_SkColorType and imageInfo.alphaType() is
1172kUnpremul_SkAlphaType, imageInfo.alphaType() is replaced by kPremul_SkAlphaType.
1173If imageInfo.colorType() is kRGB_565_SkColorType or kGray_8_SkColorType,
1174imageInfo.alphaType() is set to kOpaque_SkAlphaType.
1175If imageInfo.colorType() is kARGB_4444_SkColorType, kRGBA_8888_SkColorType,
1176kBGRA_8888_SkColorType, or kRGBA_F16_SkColorType: imageInfo.alphaType() remains
Cary Clarkbc5697d2017-10-04 14:31:33 -04001177unchanged.
1178
Cary Clark77b3f3a2018-11-07 14:59:03 -05001179rowBytes must equal or exceed imageInfo.minRowBytes(). If imageInfo.colorSpace() is
Cary Clarkbc5697d2017-10-04 14:31:33 -04001180kUnknown_SkColorType, rowBytes is ignored and treated as zero; for all other
Cary Clark77b3f3a2018-11-07 14:59:03 -05001181Color_Space values, rowBytes of zero is treated as imageInfo.minRowBytes().
Cary Clarkbc5697d2017-10-04 14:31:33 -04001182
1183Calls reset() and returns false if:
1184#List
1185# rowBytes exceeds 31 bits ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001186# imageInfo.width() is negative ##
1187# imageInfo.height() is negative ##
Cary Clark77b3f3a2018-11-07 14:59:03 -05001188# rowBytes is positive and less than imageInfo.width() times imageInfo.bytesPerPixel() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001189##
1190
1191#Param imageInfo contains width, height, Alpha_Type, Color_Type, Color_Space ##
Cary Clark77b3f3a2018-11-07 14:59:03 -05001192#Param rowBytes imageInfo.minRowBytes() or larger; or zero ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001193
1194#Return true if Image_Info set successfully ##
1195
1196#Example
1197#Height 96
1198###^
Ben Wagner29380bd2017-10-09 14:43:00 -04001199SkBitmap bitmap;
1200bitmap.setInfo(SkImageInfo::MakeN32(44, 16, kOpaque_SkAlphaType));
1201bitmap.allocPixels();
1202bitmap.eraseColor(SK_ColorGREEN);
1203SkCanvas offscreen(bitmap);
1204SkPaint paint;
1205offscreen.drawString("!@#$%", 0, 12, paint);
1206canvas->scale(6, 6);
1207canvas->drawBitmap(bitmap, 0, 0);
1208^^^#
Cary Clarkbc5697d2017-10-04 14:31:33 -04001209##
1210
1211#SeeAlso Alpha_Type Color_Type Color_Space height rowBytes width
1212
1213##
1214
1215# ------------------------------------------------------------------------------
1216
1217#Enum AllocFlags
Cary Clark4855f782018-02-06 09:41:53 -05001218#Line # zero pixel memory ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001219#Code
Cary Clarka90ea222018-10-16 10:30:28 -04001220#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001221##
1222
1223AllocFlags provides the option to zero pixel memory when allocated.
1224
1225#Const kZeroPixels_AllocFlag 1
Cary Clark682c58d2018-05-16 07:07:07 -04001226#Line # zero pixel memory ##
1227 Instructs tryAllocPixelsFlags and allocPixelsFlags to zero pixel memory.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001228##
1229
1230#NoExample
1231##
1232
Cary Clarka90ea222018-10-16 10:30:28 -04001233#SeeAlso tryAllocPixelsFlags allocPixelsFlags erase eraseColor
Cary Clarkbc5697d2017-10-04 14:31:33 -04001234
1235##
1236
1237# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05001238#Subtopic Allocate
Cary Clark78de7512018-02-07 07:27:09 -05001239#Line # allocates storage for pixels ##
1240##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001241
Cary Clark61313f32018-10-08 14:57:48 -04001242#Method bool tryAllocPixelsFlags(const SkImageInfo& info, uint32_t flags)
Cary Clark78de7512018-02-07 07:27:09 -05001243#In Allocate
Cary Clarkab2621d2018-01-30 10:08:57 -05001244#Line # allocates pixels from Image_Info with options if possible ##
Cary Clark09d80c02018-10-31 12:14:03 -04001245#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001246
1247#Example
Ben Wagner29380bd2017-10-09 14:43:00 -04001248 SkBitmap bitmap;
Cary Clark682c58d2018-05-16 07:07:07 -04001249 if (!bitmap.tryAllocPixelsFlags(SkImageInfo::MakeN32(10000, 10000, kOpaque_SkAlphaType),
Cary Clarka560c472017-11-27 10:44:06 -05001250 SkBitmap::kZeroPixels_AllocFlag)) {
1251 SkDebugf("bitmap allocation failed!\n");
1252 } else {
1253 SkDebugf("bitmap allocation succeeded!\n");
Cary Clarkbc5697d2017-10-04 14:31:33 -04001254 }
1255#StdOut
Cary Clarka560c472017-11-27 10:44:06 -05001256bitmap allocation succeeded!
Cary Clarkbc5697d2017-10-04 14:31:33 -04001257##
1258##
1259
1260#SeeAlso allocPixelsFlags tryAllocPixels SkMallocPixelRef::MakeZeroed
1261
1262##
1263
1264# ------------------------------------------------------------------------------
1265
1266#Method void allocPixelsFlags(const SkImageInfo& info, uint32_t flags)
Cary Clark78de7512018-02-07 07:27:09 -05001267#In Allocate
Cary Clarkab2621d2018-01-30 10:08:57 -05001268#Line # allocates pixels from Image_Info with options, or aborts ##
Cary Clark09d80c02018-10-31 12:14:03 -04001269#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001270
1271#Example
1272#Height 128
1273#Description
1274Text is drawn on a transparent background; drawing the bitmap a second time
1275lets the first draw show through.
1276##
1277###^
Ben Wagner29380bd2017-10-09 14:43:00 -04001278SkBitmap bitmap;
Cary Clark682c58d2018-05-16 07:07:07 -04001279bitmap.allocPixelsFlags(SkImageInfo::MakeN32(44, 16, kPremul_SkAlphaType),
Ben Wagner29380bd2017-10-09 14:43:00 -04001280 SkBitmap::kZeroPixels_AllocFlag);
1281SkCanvas offscreen(bitmap);
1282SkPaint paint;
1283offscreen.drawString("!@#$%", 0, 12, paint);
1284canvas->scale(6, 6);
1285canvas->drawBitmap(bitmap, 0, 0);
1286canvas->drawBitmap(bitmap, 8, 8);
1287^^^#
Cary Clarkbc5697d2017-10-04 14:31:33 -04001288##
1289
1290#SeeAlso tryAllocPixelsFlags allocPixels SkMallocPixelRef::MakeZeroed
1291
1292##
1293
1294# ------------------------------------------------------------------------------
1295
Cary Clark61313f32018-10-08 14:57:48 -04001296#Method bool tryAllocPixels(const SkImageInfo& info, size_t rowBytes)
Cary Clark78de7512018-02-07 07:27:09 -05001297#In Allocate
Cary Clarkab2621d2018-01-30 10:08:57 -05001298#Line # allocates pixels from Image_Info if possible ##
Cary Clark09d80c02018-10-31 12:14:03 -04001299#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001300
1301#Example
1302#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04001303SkBitmap bitmap;
1304SkImageInfo info = SkImageInfo::Make(64, 256, kGray_8_SkColorType, kOpaque_SkAlphaType);
1305if (bitmap.tryAllocPixels(info, 0)) {
1306 SkCanvas offscreen(bitmap);
1307 offscreen.scale(.5f, .5f);
1308 for (int x : { 0, 64, 128, 192 } ) {
1309 offscreen.drawBitmap(source, -x, 0);
1310 canvas->drawBitmap(bitmap, x, 0);
1311 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04001312}
1313##
1314
1315#SeeAlso tryAllocPixelsFlags allocPixels SkMallocPixelRef::MakeAllocate
1316
1317##
1318
1319# ------------------------------------------------------------------------------
1320
1321#Method void allocPixels(const SkImageInfo& info, size_t rowBytes)
Cary Clark78de7512018-02-07 07:27:09 -05001322#In Allocate
Cary Clarkab2621d2018-01-30 10:08:57 -05001323#Line # allocates pixels from Image_Info, or aborts ##
Cary Clark09d80c02018-10-31 12:14:03 -04001324#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001325
1326#Example
1327#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04001328SkBitmap bitmap;
1329SkImageInfo info = SkImageInfo::Make(256, 64, kGray_8_SkColorType, kOpaque_SkAlphaType);
1330bitmap.allocPixels(info, info.width() * info.bytesPerPixel() + 64);
1331SkCanvas offscreen(bitmap);
1332offscreen.scale(.5f, .5f);
1333for (int y : { 0, 64, 128, 192 } ) {
1334 offscreen.drawBitmap(source, 0, -y);
1335 canvas->drawBitmap(bitmap, 0, y);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001336}
1337##
1338
1339#SeeAlso tryAllocPixels allocPixelsFlags SkMallocPixelRef::MakeAllocate
1340
1341##
1342
1343# ------------------------------------------------------------------------------
1344
Cary Clark61313f32018-10-08 14:57:48 -04001345#Method bool tryAllocPixels(const SkImageInfo& info)
Cary Clark09d80c02018-10-31 12:14:03 -04001346#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001347
1348#Example
1349#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04001350SkBitmap bitmap;
1351if (bitmap.tryAllocPixels(SkImageInfo::Make(64, 64, kGray_8_SkColorType, kOpaque_SkAlphaType))) {
1352 SkCanvas offscreen(bitmap);
1353 offscreen.scale(.25f, .5f);
1354 for (int y : { 0, 64, 128, 192 } ) {
1355 offscreen.drawBitmap(source, -y, -y);
1356 canvas->drawBitmap(bitmap, y, y);
1357 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04001358}
1359##
1360
1361#SeeAlso tryAllocPixelsFlags allocPixels SkMallocPixelRef::MakeAllocate
1362
1363##
1364
1365# ------------------------------------------------------------------------------
1366
1367#Method void allocPixels(const SkImageInfo& info)
Cary Clark09d80c02018-10-31 12:14:03 -04001368#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001369
1370#Example
1371#Image 4
Ben Wagner29380bd2017-10-09 14:43:00 -04001372SkBitmap bitmap;
1373bitmap.allocPixels(SkImageInfo::Make(64, 64, kGray_8_SkColorType, kOpaque_SkAlphaType));
1374SkCanvas offscreen(bitmap);
1375offscreen.scale(.5f, .5f);
1376for (int y : { 0, 64, 128, 192 } ) {
1377 offscreen.drawBitmap(source, -y, -y);
1378 canvas->drawBitmap(bitmap, y, y);
1379}
Cary Clarkbc5697d2017-10-04 14:31:33 -04001380##
1381
1382#SeeAlso tryAllocPixels allocPixelsFlags SkMallocPixelRef::MakeAllocate
1383
1384##
1385
1386# ------------------------------------------------------------------------------
1387
Cary Clark61313f32018-10-08 14:57:48 -04001388#Method bool tryAllocN32Pixels(int width, int height, bool isOpaque = false)
Cary Clark78de7512018-02-07 07:27:09 -05001389#In Allocate
Cary Clarkffb3d682018-05-17 12:17:28 -04001390#Line # allocates compatible ARGB pixels if possible ##
Cary Clark09d80c02018-10-31 12:14:03 -04001391#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001392
1393#Example
1394#Height 160
Ben Wagner29380bd2017-10-09 14:43:00 -04001395 SkBitmap bitmap;
1396 if (bitmap.tryAllocN32Pixels(80, 80)) {
1397 bitmap.eraseColor(SK_ColorTRANSPARENT);
1398 bitmap.erase(0x7f3f7fff, SkIRect::MakeWH(50, 30));
1399 bitmap.erase(0x3f7fff3f, SkIRect::MakeXYWH(20, 10, 50, 30));
1400 bitmap.erase(0x5fff3f7f, SkIRect::MakeXYWH(40, 20, 50, 30));
1401 canvas->drawBitmap(bitmap, 0, 0);
1402 for (int x : { 0, 30, 60, 90 } ) {
1403 canvas->drawBitmap(bitmap, x, 70);
1404 }
1405 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04001406##
1407
1408#SeeAlso tryAllocPixels allocN32Pixels SkMallocPixelRef::MakeAllocate
1409
1410##
1411
1412# ------------------------------------------------------------------------------
1413
1414#Method void allocN32Pixels(int width, int height, bool isOpaque = false)
Cary Clark78de7512018-02-07 07:27:09 -05001415#In Allocate
Cary Clarkffb3d682018-05-17 12:17:28 -04001416#Line # allocates compatible ARGB pixels, or aborts ##
Cary Clark09d80c02018-10-31 12:14:03 -04001417#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001418
1419#Example
Ben Wagner29380bd2017-10-09 14:43:00 -04001420 SkRandom random;
1421 SkBitmap bitmap;
1422 bitmap.allocN32Pixels(64, 64);
1423 bitmap.eraseColor(SK_ColorTRANSPARENT);
1424 for (int y = 0; y < 256; y += 64) {
1425 for (int x = 0; x < 256; x += 64) {
1426 SkColor color = random.nextU();
1427 uint32_t w = random.nextRangeU(4, 32);
1428 uint32_t cx = random.nextRangeU(0, 64 - w);
1429 uint32_t h = random.nextRangeU(4, 32);
1430 uint32_t cy = random.nextRangeU(0, 64 - h);
1431 bitmap.erase(color, SkIRect::MakeXYWH(cx, cy, w, h));
1432 canvas->drawBitmap(bitmap, x, y);
1433 }
1434 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04001435##
1436
1437#SeeAlso allocPixels tryAllocN32Pixels SkMallocPixelRef::MakeAllocate
1438
1439##
1440
1441# ------------------------------------------------------------------------------
1442
1443#Method bool installPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
1444 void (*releaseProc)(void* addr, void* context), void* context)
Cary Clark78de7512018-02-07 07:27:09 -05001445#In Allocate
Cary Clarkab2621d2018-01-30 10:08:57 -05001446#Line # creates Pixel_Ref, with optional release function ##
Cary Clark09d80c02018-10-31 12:14:03 -04001447#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001448
1449#Example
1450#Description
1451releaseProc is called immediately because rowBytes is too small for Pixel_Ref.
1452##
1453#Function
Ben Wagner29380bd2017-10-09 14:43:00 -04001454static void releaseProc(void* addr, void* ) {
1455 SkDebugf("releaseProc called\n");
Cary Clark682c58d2018-05-16 07:07:07 -04001456 delete[] (uint32_t*) addr;
Ben Wagner29380bd2017-10-09 14:43:00 -04001457}
1458
1459##
1460
1461void draw(SkCanvas* canvas) {
1462 SkBitmap bitmap;
1463 void* pixels = new uint32_t[8 * 8];
1464 SkImageInfo info = SkImageInfo::MakeN32(8, 8, kOpaque_SkAlphaType);
1465 SkDebugf("before installPixels\n");
1466 bool installed = bitmap.installPixels(info, pixels, 16, releaseProc, nullptr);
1467 SkDebugf("install " "%s" "successful\n", installed ? "" : "not ");
Cary Clarkbc5697d2017-10-04 14:31:33 -04001468}
1469#StdOut
Ben Wagner29380bd2017-10-09 14:43:00 -04001470before installPixels
1471releaseProc called
Cary Clarkbc5697d2017-10-04 14:31:33 -04001472install not successful
1473##
1474##
1475
1476#SeeAlso allocPixels
1477
1478##
1479
1480# ------------------------------------------------------------------------------
1481
1482#Method bool installPixels(const SkImageInfo& info, void* pixels, size_t rowBytes)
Cary Clark09d80c02018-10-31 12:14:03 -04001483#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001484
1485#Example
Cary Clark4855f782018-02-06 09:41:53 -05001486#Bug 7079
Cary Clarkbc5697d2017-10-04 14:31:33 -04001487#Description
Cary Clarkbc5697d2017-10-04 14:31:33 -04001488GPU does not support kUnpremul_SkAlphaType, does not assert that it does not.
1489##
Ben Wagner29380bd2017-10-09 14:43:00 -04001490void draw(SkCanvas* canvas) {
1491 SkRandom random;
1492 SkBitmap bitmap;
1493 const int width = 8;
1494 const int height = 8;
1495 uint32_t pixels[width * height];
1496 for (unsigned x = 0; x < width * height; ++x) {
1497 pixels[x] = random.nextU();
1498 }
1499 SkImageInfo info = SkImageInfo::MakeN32(width, height, kUnpremul_SkAlphaType);
1500 if (bitmap.installPixels(info, pixels, info.minRowBytes())) {
1501 canvas->scale(32, 32);
1502 canvas->drawBitmap(bitmap, 0, 0);
1503 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04001504}
1505##
1506
1507#SeeAlso allocPixels
1508
1509##
1510
1511# ------------------------------------------------------------------------------
1512
1513#Method bool installPixels(const SkPixmap& pixmap)
Cary Clark09d80c02018-10-31 12:14:03 -04001514#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001515
1516#Example
1517#Description
1518Draw a five by five bitmap, and draw it again with a center white pixel.
1519##
1520#Height 64
1521 uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 },
1522 { 0xAC, 0xA8, 0x89, 0x47, 0x87 },
1523 { 0x4B, 0x25, 0x25, 0x25, 0x46 },
1524 { 0x90, 0x81, 0x25, 0x41, 0x33 },
1525 { 0x75, 0x55, 0x44, 0x20, 0x00 }};
1526 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType);
1527 SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
1528 SkBitmap bitmap;
1529 bitmap.installPixels(pixmap);
1530 canvas->scale(10, 10);
1531 canvas->drawBitmap(bitmap, 0, 0);
1532 *pixmap.writable_addr8(2, 2) = 0xFF;
1533 bitmap.installPixels(pixmap);
1534 canvas->drawBitmap(bitmap, 10, 0);
1535##
1536
1537#SeeAlso allocPixels
1538
1539##
1540
1541# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05001542#Subtopic Pixels
Cary Clark78de7512018-02-07 07:27:09 -05001543#Line # read and write pixel values ##
1544##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001545
1546#Method void setPixels(void* pixels)
Cary Clark78de7512018-02-07 07:27:09 -05001547#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001548#Line # sets Pixel_Ref without an offset ##
Cary Clark09d80c02018-10-31 12:14:03 -04001549#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001550
1551#Example
1552#Height 50
Ben Wagner29380bd2017-10-09 14:43:00 -04001553 uint8_t set1[5] = { 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 };
1554 uint8_t set2[5] = { 0xAC, 0xA8, 0x89, 0x47, 0x87 };
1555 SkBitmap bitmap;
1556 bitmap.installPixels(SkImageInfo::Make(5, 1, kGray_8_SkColorType, kOpaque_SkAlphaType), set1, 5);
1557 canvas->scale(10, 50);
1558 canvas->drawBitmap(bitmap, 0, 0);
1559 bitmap.setPixels(set2);
1560 canvas->drawBitmap(bitmap, 10, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001561##
1562
1563#SeeAlso installPixels allocPixels
1564
1565##
1566
1567# ------------------------------------------------------------------------------
1568
Cary Clark61313f32018-10-08 14:57:48 -04001569#Method bool tryAllocPixels()
Cary Clark78de7512018-02-07 07:27:09 -05001570#In Allocate
Cary Clark09d80c02018-10-31 12:14:03 -04001571#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001572
1573#Example
1574#Height 50
Cary Clark682c58d2018-05-16 07:07:07 -04001575#Description
Cary Clarkbc5697d2017-10-04 14:31:33 -04001576Bitmap hosts and draws gray values in set1. tryAllocPixels replaces Pixel_Ref
1577and erases it to black, but does not alter set1. setPixels replaces black
Cary Clark682c58d2018-05-16 07:07:07 -04001578Pixel_Ref with set1.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001579##
Ben Wagner29380bd2017-10-09 14:43:00 -04001580 uint8_t set1[5] = { 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 };
1581 SkBitmap bitmap;
1582 bitmap.installPixels(SkImageInfo::Make(5, 1, kGray_8_SkColorType, kOpaque_SkAlphaType), set1, 5);
1583 canvas->scale(10, 50);
1584 canvas->drawBitmap(bitmap, 0, 0);
1585 if (bitmap.tryAllocPixels()) {
1586 bitmap.eraseColor(SK_ColorBLACK);
1587 canvas->drawBitmap(bitmap, 8, 0);
1588 bitmap.setPixels(set1);
1589 canvas->drawBitmap(bitmap, 16, 0);
1590 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04001591##
1592
1593#SeeAlso allocPixels installPixels setPixels
1594
1595##
1596
1597# ------------------------------------------------------------------------------
1598
1599#Method void allocPixels()
Cary Clark78de7512018-02-07 07:27:09 -05001600#In Allocate
Cary Clark09d80c02018-10-31 12:14:03 -04001601#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001602
1603#Example
1604#Height 50
Cary Clark682c58d2018-05-16 07:07:07 -04001605#Description
Cary Clarkbc5697d2017-10-04 14:31:33 -04001606Bitmap hosts and draws gray values in set1. allocPixels replaces Pixel_Ref
1607and erases it to black, but does not alter set1. setPixels replaces black
Cary Clark682c58d2018-05-16 07:07:07 -04001608Pixel_Ref with set2.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001609##
Ben Wagner29380bd2017-10-09 14:43:00 -04001610 uint8_t set1[5] = { 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 };
1611 uint8_t set2[5] = { 0xAC, 0xA8, 0x89, 0x47, 0x87 };
1612 SkBitmap bitmap;
1613 bitmap.installPixels(SkImageInfo::Make(5, 1, kGray_8_SkColorType, kOpaque_SkAlphaType), set1, 5);
1614 canvas->scale(10, 50);
1615 canvas->drawBitmap(bitmap, 0, 0);
1616 bitmap.allocPixels();
1617 bitmap.eraseColor(SK_ColorBLACK);
1618 canvas->drawBitmap(bitmap, 8, 0);
1619 bitmap.setPixels(set2);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001620 canvas->drawBitmap(bitmap, 16, 0);
1621##
1622
1623#SeeAlso tryAllocPixels installPixels setPixels
1624
1625##
1626
1627# ------------------------------------------------------------------------------
1628
Cary Clark61313f32018-10-08 14:57:48 -04001629#Method bool tryAllocPixels(Allocator* allocator)
Cary Clark09d80c02018-10-31 12:14:03 -04001630#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001631
1632#Example
1633#Height 100
1634#Description
1635HeapAllocator limits the maximum size of Bitmap to two gigabytes. Using
1636a custom allocator, this limitation may be relaxed. This example can be
Cary Clark682c58d2018-05-16 07:07:07 -04001637modified to allocate an eight gigabyte Bitmap on a 64-bit platform with
Cary Clarkbc5697d2017-10-04 14:31:33 -04001638sufficient memory.
1639##
1640#Function
1641class LargePixelRef : public SkPixelRef {
1642public:
1643 LargePixelRef(const SkImageInfo& info, char* storage, size_t rowBytes)
1644 : SkPixelRef(info.width(), info.height(), storage, rowBytes) {
1645 }
1646
1647 ~LargePixelRef() override {
1648 delete[] (char* ) this->pixels();
1649 }
1650};
1651
1652class LargeAllocator : public SkBitmap::Allocator {
1653public:
1654 bool allocPixelRef(SkBitmap* bitmap) override {
1655 const SkImageInfo& info = bitmap->info();
1656 uint64_t rowBytes = info.minRowBytes64();
1657 uint64_t size = info.height() * rowBytes;
1658 char* addr = new char[size];
1659 if (nullptr == addr) {
1660 return false;
1661 }
1662 sk_sp<SkPixelRef> pr = sk_sp<SkPixelRef>(new LargePixelRef(info, addr, rowBytes));
1663 if (!pr) {
1664 return false;
1665 }
1666 bitmap->setPixelRef(std::move(pr), 0, 0);
1667 return true;
1668 }
1669};
1670
1671##
1672
1673void draw(SkCanvas* canvas) {
1674 LargeAllocator largeAllocator;
1675 SkBitmap bitmap;
Ben Wagner29380bd2017-10-09 14:43:00 -04001676 int width = 100; // make this 20000
1677 int height = 100; // and this 100000 to allocate 8 gigs on a 64-bit platform
1678 bitmap.setInfo(SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType));
1679 if (bitmap.tryAllocPixels(&largeAllocator)) {
1680 bitmap.eraseColor(0xff55aa33);
1681 canvas->drawBitmap(bitmap, 0, 0);
1682 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04001683}
1684
1685##
1686
1687#SeeAlso allocPixels Allocator Pixel_Ref
1688
1689##
1690
1691# ------------------------------------------------------------------------------
1692
1693#Method void allocPixels(Allocator* allocator)
Cary Clark09d80c02018-10-31 12:14:03 -04001694#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001695
1696#Example
1697#Height 32
1698#Function
1699class TinyAllocator : public SkBitmap::Allocator {
1700public:
1701 bool allocPixelRef(SkBitmap* bitmap) override {
1702 const SkImageInfo& info = bitmap->info();
1703 if (info.height() * info.minRowBytes() > sizeof(storage)) {
1704 return false;
1705 }
1706 sk_sp<SkPixelRef> pr = sk_sp<SkPixelRef>(
1707 new SkPixelRef(info.width(), info.height(), storage, info.minRowBytes()));
1708 bitmap->setPixelRef(std::move(pr), 0, 0);
1709 return true;
1710 }
1711
1712 char storage[16];
1713};
1714
1715##
1716
1717void draw(SkCanvas* canvas) {
1718 TinyAllocator tinyAllocator;
1719 SkBitmap bitmap;
Ben Wagner29380bd2017-10-09 14:43:00 -04001720 bitmap.setInfo(SkImageInfo::MakeN32(2, 2, kOpaque_SkAlphaType));
1721 if (bitmap.tryAllocPixels(&tinyAllocator)) {
1722 bitmap.eraseColor(0xff55aa33);
1723 bitmap.erase(0xffaa3355, SkIRect::MakeXYWH(1, 1, 1, 1));
1724 canvas->scale(16, 16);
1725 canvas->drawBitmap(bitmap, 0, 0);
1726 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04001727}
1728##
1729
1730#SeeAlso allocPixels Allocator Pixel_Ref
1731
1732##
1733
1734# ------------------------------------------------------------------------------
1735
1736#Method SkPixelRef* pixelRef() const
Cary Clark78de7512018-02-07 07:27:09 -05001737#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05001738#Line # returns Pixel_Ref, or nullptr ##
Cary Clark09d80c02018-10-31 12:14:03 -04001739#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001740
1741#Example
1742#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04001743 SkBitmap subset;
1744 source.extractSubset(&subset, SkIRect::MakeXYWH(32, 64, 128, 256));
1745 SkDebugf("src ref %c= sub ref\n", source.pixelRef() == subset.pixelRef() ? '=' : '!');
1746 SkDebugf("src pixels %c= sub pixels\n", source.getPixels() == subset.getPixels() ? '=' : '!');
1747 SkDebugf("src addr %c= sub addr\n", source.getAddr(32, 64) == subset.getAddr(0, 0) ? '=' : '!');
Cary Clarkbc5697d2017-10-04 14:31:33 -04001748##
1749
1750#SeeAlso getPixels getAddr
1751
1752##
1753
1754# ------------------------------------------------------------------------------
1755
1756#Method SkIPoint pixelRefOrigin() const
Cary Clark78de7512018-02-07 07:27:09 -05001757#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05001758#Line # returns offset within Pixel_Ref ##
Cary Clark09d80c02018-10-31 12:14:03 -04001759#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001760
1761#Example
1762#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04001763 SkBitmap subset;
1764 source.extractSubset(&subset, SkIRect::MakeXYWH(32, 64, 128, 256));
1765 SkIPoint sourceOrigin = source.pixelRefOrigin();
1766 SkIPoint subsetOrigin = subset.pixelRefOrigin();
1767 SkDebugf("source origin: %d, %d\n", sourceOrigin.fX, sourceOrigin.fY);
1768 SkDebugf("subset origin: %d, %d\n", subsetOrigin.fX, subsetOrigin.fY);
1769#StdOut
1770source origin: 0, 0
1771subset origin: 32, 64
1772##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001773##
1774
Cary Clark2ade9972017-11-02 17:49:34 -04001775#SeeAlso SkPixelRef getSubset setPixelRef
Cary Clarkbc5697d2017-10-04 14:31:33 -04001776
1777##
1778
1779# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05001780#Subtopic Set
1781#Line # updates values and attributes ##
Cary Clark78de7512018-02-07 07:27:09 -05001782##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001783
1784#Method void setPixelRef(sk_sp<SkPixelRef> pixelRef, int dx, int dy)
Cary Clark78de7512018-02-07 07:27:09 -05001785#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -05001786#Line # sets Pixel_Ref and offset ##
Cary Clark09d80c02018-10-31 12:14:03 -04001787#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001788
1789#Example
1790#Height 140
1791#Image 5
1792#Description
Cary Clark682c58d2018-05-16 07:07:07 -04001793Treating 32-bit data as 8-bit data is unlikely to produce useful results.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001794##
Ben Wagner29380bd2017-10-09 14:43:00 -04001795 SkBitmap bitmap;
Cary Clark682c58d2018-05-16 07:07:07 -04001796 bitmap.setInfo(SkImageInfo::Make(source.width() - 5, source.height() - 5,
Ben Wagner29380bd2017-10-09 14:43:00 -04001797 kGray_8_SkColorType, kOpaque_SkAlphaType), source.rowBytes());
1798 bitmap.setPixelRef(sk_ref_sp(source.pixelRef()), 5, 5);
1799 canvas->drawBitmap(bitmap, 10, 10);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001800##
1801
1802#SeeAlso setInfo
1803
1804##
1805
1806# ------------------------------------------------------------------------------
1807
1808#Method bool readyToDraw() const
Cary Clark78de7512018-02-07 07:27:09 -05001809#In Utility
Cary Clarkab2621d2018-01-30 10:08:57 -05001810#Line # returns true if address of pixels is not nullptr ##
Cary Clark09d80c02018-10-31 12:14:03 -04001811#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001812
1813#Example
1814#Image 5
1815#Height 160
Ben Wagner29380bd2017-10-09 14:43:00 -04001816 if (source.readyToDraw()) {
1817 canvas->drawBitmap(source, 10, 10);
1818 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04001819##
1820
1821#SeeAlso getPixels drawsNothing
1822
1823##
1824
1825# ------------------------------------------------------------------------------
1826
1827#Method uint32_t getGenerationID() const
Cary Clark78de7512018-02-07 07:27:09 -05001828#In Utility
Cary Clarkab2621d2018-01-30 10:08:57 -05001829#Line # returns unique ID ##
Cary Clark09d80c02018-10-31 12:14:03 -04001830#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001831
1832#Example
Ben Wagner29380bd2017-10-09 14:43:00 -04001833 SkBitmap bitmap;
1834 SkDebugf("empty id %u\n", bitmap.getGenerationID());
1835 bitmap.allocPixels(SkImageInfo::MakeN32(64, 64, kOpaque_SkAlphaType));
1836 SkDebugf("alloc id %u\n", bitmap.getGenerationID());
1837 bitmap.eraseColor(SK_ColorRED);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001838 SkDebugf("erase id %u\n", bitmap.getGenerationID());
1839#StdOut
1840#Volatile
Ben Wagner29380bd2017-10-09 14:43:00 -04001841empty id 0
1842alloc id 4
Cary Clarkbc5697d2017-10-04 14:31:33 -04001843erase id 6
Cary Clark682c58d2018-05-16 07:07:07 -04001844##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001845##
1846
1847#SeeAlso notifyPixelsChanged Pixel_Ref
1848
1849##
1850
1851# ------------------------------------------------------------------------------
1852
1853#Method void notifyPixelsChanged() const
Cary Clark78de7512018-02-07 07:27:09 -05001854#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001855#Line # marks pixels as changed, altering the unique ID ##
Cary Clark09d80c02018-10-31 12:14:03 -04001856#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001857
1858#Example
1859#Height 20
Cary Clark682c58d2018-05-16 07:07:07 -04001860 SkBitmap bitmap;
Ben Wagner29380bd2017-10-09 14:43:00 -04001861 bitmap.setInfo(SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType));
1862 bitmap.allocPixels();
1863 bitmap.eraseColor(SK_ColorRED);
1864 canvas->scale(16, 16);
1865 canvas->drawBitmap(bitmap, 0, 0);
1866 *(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorBLUE);
1867 canvas->drawBitmap(bitmap, 2, 0);
1868 bitmap.notifyPixelsChanged();
1869 *(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorGREEN);
1870 canvas->drawBitmap(bitmap, 4, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001871##
1872
1873#SeeAlso getGenerationID isVolatile Pixel_Ref
1874
1875##
1876
1877# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05001878#Subtopic Draw
Cary Clark682c58d2018-05-16 07:07:07 -04001879#Line # sets pixels to Color ##
Cary Clark78de7512018-02-07 07:27:09 -05001880##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001881
1882#Method void eraseColor(SkColor c) const
Cary Clark78de7512018-02-07 07:27:09 -05001883#In Draw
Cary Clarkab2621d2018-01-30 10:08:57 -05001884#Line # writes Color to pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -04001885#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001886
1887#Example
1888#Height 20
Cary Clark682c58d2018-05-16 07:07:07 -04001889 SkBitmap bitmap;
Ben Wagner29380bd2017-10-09 14:43:00 -04001890 bitmap.allocPixels(SkImageInfo::MakeN32(1, 1, kOpaque_SkAlphaType));
1891 bitmap.eraseColor(SK_ColorRED);
1892 canvas->scale(16, 16);
1893 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001894##
1895
Cary Clark154beea2017-10-26 07:58:48 -04001896#SeeAlso eraseARGB erase
Cary Clarkbc5697d2017-10-04 14:31:33 -04001897
1898##
1899
1900# ------------------------------------------------------------------------------
1901
1902#Method void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const
Cary Clark78de7512018-02-07 07:27:09 -05001903#In Draw
Cary Clarkab2621d2018-01-30 10:08:57 -05001904#Line # writes Color to pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -04001905#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001906
1907#Example
1908#Height 80
Cary Clark682c58d2018-05-16 07:07:07 -04001909 SkBitmap bitmap;
Ben Wagner29380bd2017-10-09 14:43:00 -04001910 bitmap.allocPixels(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType));
1911 bitmap.eraseARGB(0x7f, 0xff, 0x7f, 0x3f);
1912 canvas->scale(50, 50);
1913 canvas->drawBitmap(bitmap, 0, 0);
1914 canvas->drawBitmap(bitmap, .5f, .5f);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001915##
1916
Cary Clark154beea2017-10-26 07:58:48 -04001917#SeeAlso eraseColor erase
Cary Clarkbc5697d2017-10-04 14:31:33 -04001918
1919##
1920
1921# ------------------------------------------------------------------------------
1922
Cary Clarkbc5697d2017-10-04 14:31:33 -04001923#Method void erase(SkColor c, const SkIRect& area) const
Cary Clark78de7512018-02-07 07:27:09 -05001924#In Draw
Cary Clarkab2621d2018-01-30 10:08:57 -05001925#Line # writes Color to rectangle of pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -04001926#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001927
1928#Example
1929#Height 70
Cary Clark682c58d2018-05-16 07:07:07 -04001930 SkBitmap bitmap;
Ben Wagner29380bd2017-10-09 14:43:00 -04001931 bitmap.allocPixels(SkImageInfo::MakeN32(2, 2, kPremul_SkAlphaType));
1932 bitmap.erase(0x7fff7f3f, SkIRect::MakeWH(1, 1));
1933 bitmap.erase(0x7f7f3fff, SkIRect::MakeXYWH(0, 1, 1, 1));
1934 bitmap.erase(0x7f3fff7f, SkIRect::MakeXYWH(1, 0, 1, 1));
1935 bitmap.erase(0x7f1fbf5f, SkIRect::MakeXYWH(1, 1, 1, 1));
1936 canvas->scale(25, 25);
1937 canvas->drawBitmap(bitmap, 0, 0);
1938 canvas->drawBitmap(bitmap, .5f, .5f);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001939
1940##
1941
Mike Kleinfe5ad672018-10-04 10:18:13 -04001942#SeeAlso eraseColor eraseARGB SkCanvas::drawRect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001943
1944##
1945
1946# ------------------------------------------------------------------------------
1947
Cary Clarkbc5697d2017-10-04 14:31:33 -04001948#Method SkColor getColor(int x, int y) const
Cary Clark78de7512018-02-07 07:27:09 -05001949#In Property
1950#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001951#Line # returns one pixel as Unpremultiplied Color ##
Cary Clark09d80c02018-10-31 12:14:03 -04001952#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001953
1954#Example
1955 const int w = 4;
1956 const int h = 4;
1957 SkColor colors[][w] = {
Cary Clark75fd4492018-06-20 12:45:16 -04001958 { 0x00000000, 0x2a0e002a, 0x55380055, 0x7f7f007f },
1959 { 0x2a000e2a, 0x551c1c55, 0x7f542a7f, 0xaaaa38aa },
1960 { 0x55003855, 0x7f2a547f, 0xaa7171aa, 0xd4d48dd4 },
1961 { 0x7f007f7f, 0xaa38aaaa, 0xd48dd4d4, 0xffffffff }
Cary Clarkbc5697d2017-10-04 14:31:33 -04001962 };
1963 SkDebugf("Premultiplied:\n");
1964 for (int y = 0; y < h; ++y) {
1965 SkDebugf("(0, %d) ", y);
1966 for (int x = 0; x < w; ++x) {
1967 SkDebugf("0x%08x%c", colors[y][x], x == w - 1 ? '\n' : ' ');
1968 }
1969 }
1970 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), colors, w * 4);
1971 SkBitmap bitmap;
1972 bitmap.installPixels(pixmap);
1973 SkDebugf("Unpremultiplied:\n");
1974 for (int y = 0; y < h; ++y) {
1975 SkDebugf("(0, %d) ", y);
1976 for (int x = 0; x < w; ++x) {
1977 SkDebugf("0x%08x%c", bitmap.getColor(x, y), x == w - 1 ? '\n' : ' ');
1978 }
1979 }
1980#StdOut
1981Premultiplied:
Cary Clark682c58d2018-05-16 07:07:07 -04001982(0, 0) 0x00000000 0x2a0e002a 0x55380055 0x7f7f007f
1983(0, 1) 0x2a000e2a 0x551c1c55 0x7f542a7f 0xaaaa38aa
1984(0, 2) 0x55003855 0x7f2a547f 0xaa7171aa 0xd4d48dd4
1985(0, 3) 0x7f007f7f 0xaa38aaaa 0xd48dd4d4 0xffffffff
Cary Clarkbc5697d2017-10-04 14:31:33 -04001986Unpremultiplied:
Cary Clark682c58d2018-05-16 07:07:07 -04001987(0, 0) 0x00000000 0x2a5500ff 0x55a800ff 0x7fff00ff
1988(0, 1) 0x2a0055ff 0x555454ff 0x7fa954ff 0xaaff54ff
1989(0, 2) 0x5500a8ff 0x7f54a9ff 0xaaaaaaff 0xd4ffaaff
1990(0, 3) 0x7f00ffff 0xaa54ffff 0xd4aaffff 0xffffffff
Cary Clarkbc5697d2017-10-04 14:31:33 -04001991##
1992##
1993
Cary Clark8fe29402018-09-20 17:31:43 -04001994#SeeAlso getAlphaf getAddr readPixels
Cary Clarkbc5697d2017-10-04 14:31:33 -04001995
1996##
1997
Cary Clark8fe29402018-09-20 17:31:43 -04001998#Method float getAlphaf(int x, int y) const
1999#In Property
2000#Line # returns Alpha normalized from zero to one ##
2001
2002Looks up the pixel at (x,y) and return its alpha component, normalized to [0..1].
Cary Clark77b3f3a2018-11-07 14:59:03 -05002003This is roughly equivalent to #Formula # SkGetColorA(getColor()) ##, but can be more efficient
Cary Clark8fe29402018-09-20 17:31:43 -04002004(and more precise if the pixels store more than 8 bits per component).
2005
2006#Param x column index, zero or greater, and less than width() ##
2007#Param y row index, zero or greater, and less than height() ##
2008
2009#Return alpha converted to normalized float ##
2010
2011#NoExample
2012##
2013
2014#SeeAlso getColor
2015
2016##
2017
2018
Cary Clarkbc5697d2017-10-04 14:31:33 -04002019# ------------------------------------------------------------------------------
2020
2021#Method void* getAddr(int x, int y) const
Cary Clark78de7512018-02-07 07:27:09 -05002022#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002023#Line # returns readable pixel address as void pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -04002024#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04002025
2026#Example
2027#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04002028 char* row0 = (char* ) source.getAddr(0, 0);
2029 char* row1 = (char* ) source.getAddr(0, 1);
Cary Clark681287e2018-03-16 11:34:15 -04002030 SkDebugf("addr interval %c= rowBytes\n",
2031 (size_t) (row1 - row0) == source.rowBytes() ? '=' : '!');
Ben Wagner29380bd2017-10-09 14:43:00 -04002032#StdOut
2033addr interval == rowBytes
2034##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002035##
2036
2037#SeeAlso getAddr8 getAddr16 getAddr32 readPixels SkPixmap::addr
2038
2039##
2040
2041# ------------------------------------------------------------------------------
2042
Cary Clark61313f32018-10-08 14:57:48 -04002043#Method uint32_t* getAddr32(int x, int y) const
Cary Clark78de7512018-02-07 07:27:09 -05002044#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002045#Line # returns readable pixel address as 32-bit pointer ##
Cary Clark682c58d2018-05-16 07:07:07 -04002046Returns address at (x, y).
Cary Clarkbc5697d2017-10-04 14:31:33 -04002047
2048Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:
2049#List
2050# Pixel_Ref is nullptr ##
2051# bytesPerPixel() is not four ##
2052# x is negative, or not less than width() ##
2053# y is negative, or not less than height() ##
2054##
2055
2056#Param x column index, zero or greater, and less than width() ##
2057#Param y row index, zero or greater, and less than height() ##
2058
2059#Return unsigned 32-bit pointer to pixel at (x, y) ##
2060
2061#Example
2062#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04002063 uint32_t* row0 = source.getAddr32(0, 0);
2064 uint32_t* row1 = source.getAddr32(0, 1);
2065 size_t interval = (row1 - row0) * source.bytesPerPixel();
2066 SkDebugf("addr interval %c= rowBytes\n", interval == source.rowBytes() ? '=' : '!');
2067#StdOut
2068addr interval == rowBytes
2069##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002070##
2071
2072#SeeAlso getAddr8 getAddr16 getAddr readPixels SkPixmap::addr32
2073
2074##
2075
2076# ------------------------------------------------------------------------------
2077
Cary Clark61313f32018-10-08 14:57:48 -04002078#Method uint16_t* getAddr16(int x, int y) const
Cary Clark78de7512018-02-07 07:27:09 -05002079#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002080#Line # returns readable pixel address as 16-bit pointer ##
Cary Clark682c58d2018-05-16 07:07:07 -04002081Returns address at (x, y).
Cary Clarkbc5697d2017-10-04 14:31:33 -04002082
2083Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:
2084#List
2085# Pixel_Ref is nullptr ##
2086# bytesPerPixel() is not two ##
2087# x is negative, or not less than width() ##
2088# y is negative, or not less than height() ##
2089##
2090
2091#Param x column index, zero or greater, and less than width() ##
2092#Param y row index, zero or greater, and less than height() ##
2093
2094#Return unsigned 16-bit pointer to pixel at (x, y)##
2095
2096#Example
2097#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04002098 SkBitmap bitmap16;
Cary Clark682c58d2018-05-16 07:07:07 -04002099 SkImageInfo dstInfo = SkImageInfo::Make(source.width(), source.height(), kARGB_4444_SkColorType,
Ben Wagner29380bd2017-10-09 14:43:00 -04002100 kPremul_SkAlphaType);
2101 bitmap16.allocPixels(dstInfo);
2102 if (source.readPixels(dstInfo, bitmap16.getPixels(), bitmap16.rowBytes(), 0, 0)) {
2103 uint16_t* row0 = bitmap16.getAddr16(0, 0);
2104 uint16_t* row1 = bitmap16.getAddr16(0, 1);
2105 size_t interval = (row1 - row0) * bitmap16.bytesPerPixel();
2106 SkDebugf("addr interval %c= rowBytes\n", interval == bitmap16.rowBytes() ? '=' : '!');
2107 }
2108#StdOut
2109addr interval == rowBytes
2110##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002111##
2112
2113#SeeAlso getAddr8 getAddr getAddr32 readPixels SkPixmap::addr16
2114
2115##
2116
2117# ------------------------------------------------------------------------------
2118
Cary Clark61313f32018-10-08 14:57:48 -04002119#Method uint8_t* getAddr8(int x, int y) const
Cary Clark78de7512018-02-07 07:27:09 -05002120#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002121#Line # returns readable pixel address as 8-bit pointer ##
Cary Clark682c58d2018-05-16 07:07:07 -04002122Returns address at (x, y).
Cary Clarkbc5697d2017-10-04 14:31:33 -04002123
2124Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:
2125#List
2126# Pixel_Ref is nullptr ##
2127# bytesPerPixel() is not one ##
2128# x is negative, or not less than width() ##
2129# y is negative, or not less than height() ##
2130##
2131
2132#Param x column index, zero or greater, and less than width() ##
2133#Param y row index, zero or greater, and less than height() ##
2134
2135#Return unsigned 8-bit pointer to pixel at (x, y) ##
2136
2137#Example
Ben Wagner29380bd2017-10-09 14:43:00 -04002138 SkBitmap bitmap;
2139 const int width = 8;
2140 const int height = 8;
2141 uint8_t pixels[height][width];
2142 SkImageInfo info = SkImageInfo::Make(width, height, kGray_8_SkColorType, kOpaque_SkAlphaType);
2143 if (bitmap.installPixels(info, pixels, info.minRowBytes())) {
2144 SkDebugf("&pixels[4][2] %c= bitmap.getAddr8(2, 4)\n",
2145 &pixels[4][2] == bitmap.getAddr8(2, 4) ? '=' : '!');
2146 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04002147#StdOut
2148&pixels[4][2] == bitmap.getAddr8(2, 4)
2149##
2150##
2151
2152#SeeAlso getAddr getAddr16 getAddr32 readPixels SkPixmap::addr8
2153
2154##
2155
2156# ------------------------------------------------------------------------------
2157
2158#Method bool extractSubset(SkBitmap* dst, const SkIRect& subset) const
Cary Clark61313f32018-10-08 14:57:48 -04002159#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05002160#Line # creates Bitmap, sharing pixels if possible ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002161Shares Pixel_Ref with dst. Pixels are not copied; Bitmap and dst point
2162to the same pixels; dst bounds() are set to the intersection of subset
2163and the original bounds().
2164
2165subset may be larger than bounds(). Any area outside of bounds() is ignored.
2166
2167Any contents of dst are discarded. isVolatile setting is copied to dst.
2168dst is set to colorType, alphaType, and colorSpace.
2169
2170Return false if:
2171#List
2172# dst is nullptr ##
2173# Pixel_Ref is nullptr ##
2174# subset does not intersect bounds() ##
Cary Clark682c58d2018-05-16 07:07:07 -04002175##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002176
2177#Param dst Bitmap set to subset ##
2178#Param subset rectangle of pixels to reference ##
2179
2180#Return true if dst is replaced by subset
2181##
2182
2183#Example
2184#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04002185 SkIRect bounds, s;
2186 source.getBounds(&bounds);
2187 SkDebugf("bounds: %d, %d, %d, %d\n", bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
2188 SkBitmap subset;
2189 for (int left: { -100, 0, 100, 1000 } ) {
2190 for (int right: { 0, 100, 1000 } ) {
2191 SkIRect b = SkIRect::MakeLTRB(left, 100, right, 200);
2192 bool success = source.extractSubset(&subset, b);
2193 SkDebugf("subset: %4d, %4d, %4d, %4d ", b.fLeft, b.fTop, b.fRight, b.fBottom);
2194 SkDebugf("success; %s", success ? "true" : "false");
2195 if (success) {
Cary Clark682c58d2018-05-16 07:07:07 -04002196 subset.getBounds(&s);
Ben Wagner29380bd2017-10-09 14:43:00 -04002197 SkDebugf(" subset: %d, %d, %d, %d", s.fLeft, s.fTop, s.fRight, s.fBottom);
2198 }
2199 SkDebugf("\n");
Cary Clark682c58d2018-05-16 07:07:07 -04002200 }
Ben Wagner29380bd2017-10-09 14:43:00 -04002201 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04002202#StdOut
Ben Wagner29380bd2017-10-09 14:43:00 -04002203bounds: 0, 0, 512, 512
2204subset: -100, 100, 0, 200 success; false
2205subset: -100, 100, 100, 200 success; true subset: 0, 0, 100, 100
2206subset: -100, 100, 1000, 200 success; true subset: 0, 0, 512, 100
2207subset: 0, 100, 0, 200 success; false
2208subset: 0, 100, 100, 200 success; true subset: 0, 0, 100, 100
2209subset: 0, 100, 1000, 200 success; true subset: 0, 0, 512, 100
2210subset: 100, 100, 0, 200 success; false
2211subset: 100, 100, 100, 200 success; false
2212subset: 100, 100, 1000, 200 success; true subset: 0, 0, 412, 100
2213subset: 1000, 100, 0, 200 success; false
2214subset: 1000, 100, 100, 200 success; false
Cary Clarkbc5697d2017-10-04 14:31:33 -04002215subset: 1000, 100, 1000, 200 success; false
2216##
2217##
2218
2219#SeeAlso readPixels writePixels SkCanvas::drawBitmap
2220
2221##
2222
2223# ------------------------------------------------------------------------------
2224
2225#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
Cary Clarkbc5697d2017-10-04 14:31:33 -04002226 int srcX, int srcY) const
Cary Clarke80cd442018-07-17 13:19:56 -04002227#In Pixels
Cary Clark09d80c02018-10-31 12:14:03 -04002228#Line # copies and converts pixels ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002229
Cary Clarkac47b882018-01-11 10:35:44 -05002230Copies a Rect of pixels from Bitmap to dstPixels. Copy starts at (srcX, srcY),
Cary Clark682c58d2018-05-16 07:07:07 -04002231and does not exceed Bitmap (width(), height()).
Cary Clarkbc5697d2017-10-04 14:31:33 -04002232
Cary Clarkac47b882018-01-11 10:35:44 -05002233dstInfo specifies width, height, Color_Type, Alpha_Type, and Color_Space of
2234destination. dstRowBytes specifics the gap from one destination row to the next.
2235Returns true if pixels are copied. Returns false if:
Cary Clarkbc5697d2017-10-04 14:31:33 -04002236#List
Cary Clark09d80c02018-10-31 12:14:03 -04002237# dstInfo has no address ##
Cary Clark77b3f3a2018-11-07 14:59:03 -05002238# dstRowBytes is less than dstInfo.minRowBytes() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002239# Pixel_Ref is nullptr ##
2240##
2241
Cary Clarkac47b882018-01-11 10:35:44 -05002242Pixels are copied only if pixel conversion is possible. If Bitmap colorType is
Cary Clark77b3f3a2018-11-07 14:59:03 -05002243kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match.
2244If Bitmap colorType is kGray_8_SkColorType, dstInfo.colorSpace() must match.
2245If Bitmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType() must
2246match. If Bitmap colorSpace is nullptr, dstInfo.colorSpace() must match. Returns
Cary Clarkbc5697d2017-10-04 14:31:33 -04002247false if pixel conversion is not possible.
Cary Clark682c58d2018-05-16 07:07:07 -04002248
Cary Clarkbc5697d2017-10-04 14:31:33 -04002249srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clark154beea2017-10-26 07:58:48 -04002250false if width() or height() is zero or negative.
Cary Clark2be81cf2018-09-13 12:04:30 -04002251Returns false if #Formula # abs(srcX) >= Bitmap width() ##, or if #Formula # abs(srcY) >= Bitmap height() ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002252
2253#Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ##
2254#Param dstPixels destination pixel storage ##
2255#Param dstRowBytes destination row length ##
2256#Param srcX column index whose absolute value is less than width() ##
2257#Param srcY row index whose absolute value is less than height() ##
2258
2259#Return true if pixels are copied to dstPixels ##
2260
2261#Example
2262#Height 128
2263#Description
2264Transferring the gradient from 8 bits per component to 4 bits per component
2265creates visible banding.
2266##
Ben Wagner29380bd2017-10-09 14:43:00 -04002267 const int width = 256;
2268 const int height = 64;
2269 SkImageInfo srcInfo = SkImageInfo::MakeN32Premul(width, height);
2270 SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 };
2271 SkPoint gradPoints[] = { { 0, 0 }, { 256, 0 } };
2272 SkPaint paint;
2273 paint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
2274 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
2275 SkBitmap bitmap;
2276 bitmap.allocPixels(srcInfo);
2277 SkCanvas srcCanvas(bitmap);
2278 srcCanvas.drawRect(SkRect::MakeWH(width, height), paint);
2279 canvas->drawBitmap(bitmap, 0, 0);
2280 SkImageInfo dstInfo = srcInfo.makeColorType(kARGB_4444_SkColorType);
2281 std::vector<int16_t> dstPixels;
2282 dstPixels.resize(height * width);
2283 bitmap.readPixels(dstInfo, &dstPixels.front(), width * 2, 0, 0);
2284 SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2);
2285 bitmap.installPixels(dstPixmap);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002286 canvas->drawBitmap(bitmap, 0, 64);
2287##
2288
2289#SeeAlso writePixels SkPixmap::readPixels SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
2290
2291##
2292
2293# ------------------------------------------------------------------------------
2294
2295#Method bool readPixels(const SkPixmap& dst, int srcX, int srcY) const
2296
Cary Clarkac47b882018-01-11 10:35:44 -05002297Copies a Rect of pixels from Bitmap to dst. Copy starts at (srcX, srcY), and
Cary Clark682c58d2018-05-16 07:07:07 -04002298does not exceed Bitmap (width(), height()).
Cary Clarkbc5697d2017-10-04 14:31:33 -04002299
2300dst specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage,
Cary Clark77b3f3a2018-11-07 14:59:03 -05002301and row bytes of destination. dst.rowBytes() specifics the gap from one destination
Cary Clarkbc5697d2017-10-04 14:31:33 -04002302row to the next. Returns true if pixels are copied. Returns false if:
2303#List
2304# dst pixel storage equals nullptr ##
Cary Clark77b3f3a2018-11-07 14:59:03 -05002305# dst.rowBytes() is less than SkImageInfo::minRowBytes() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002306# Pixel_Ref is nullptr ##
2307##
2308
Cary Clarkac47b882018-01-11 10:35:44 -05002309Pixels are copied only if pixel conversion is possible. If Bitmap colorType is
Cary Clarkbc5697d2017-10-04 14:31:33 -04002310kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match.
Cary Clarkac47b882018-01-11 10:35:44 -05002311If Bitmap colorType is kGray_8_SkColorType, dst Color_Space must match.
2312If Bitmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must
2313match. If Bitmap colorSpace is nullptr, dst Color_Space must match. Returns
Cary Clarkbc5697d2017-10-04 14:31:33 -04002314false if pixel conversion is not possible.
Cary Clark682c58d2018-05-16 07:07:07 -04002315
Cary Clarkbc5697d2017-10-04 14:31:33 -04002316srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clark682c58d2018-05-16 07:07:07 -04002317false if width() or height() is zero or negative.
Cary Clark2be81cf2018-09-13 12:04:30 -04002318Returns false if #Formula # abs(srcX) >= Bitmap width() ##, or if #Formula # abs(srcY) >= Bitmap height() ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002319
2320#Param dst destination Pixmap: Image_Info, pixels, row bytes ##
2321#Param srcX column index whose absolute value is less than width() ##
2322#Param srcY row index whose absolute value is less than height() ##
2323
2324#Return true if pixels are copied to dst ##
2325
2326#Example
2327#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04002328 std::vector<int32_t> srcPixels;
2329 srcPixels.resize(source.height() * source.rowBytes());
2330 for (int y = 0; y < 4; ++y) {
2331 for (int x = 0; x < 4; ++x) {
2332 SkPixmap pixmap(SkImageInfo::MakeN32Premul(source.width() / 4, source.height() / 4),
2333 &srcPixels.front() + x * source.height() * source.width() / 4 +
2334 y * source.width() / 4, source.rowBytes());
2335 source.readPixels(pixmap, x * source.width() / 4, y * source.height() / 4);
2336 }
2337 }
2338 canvas->scale(.5f, .5f);
2339 SkBitmap bitmap;
2340 bitmap.installPixels(SkImageInfo::MakeN32Premul(source.width(), source.height()),
2341 &srcPixels.front(), source.rowBytes());
Cary Clarkbc5697d2017-10-04 14:31:33 -04002342 canvas->drawBitmap(bitmap, 0, 0);
2343##
2344
2345#SeeAlso writePixels SkPixmap::readPixels SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
2346
2347##
2348
2349# ------------------------------------------------------------------------------
2350
2351#Method bool readPixels(const SkPixmap& dst) const
2352
Cary Clarkac47b882018-01-11 10:35:44 -05002353Copies a Rect of pixels from Bitmap to dst. Copy starts at (0, 0), and
Cary Clark682c58d2018-05-16 07:07:07 -04002354does not exceed Bitmap (width(), height()).
Cary Clarkbc5697d2017-10-04 14:31:33 -04002355
2356dst specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage,
Cary Clark77b3f3a2018-11-07 14:59:03 -05002357and row bytes of destination. dst.rowBytes() specifics the gap from one destination
Cary Clarkbc5697d2017-10-04 14:31:33 -04002358row to the next. Returns true if pixels are copied. Returns false if:
2359#List
2360# dst pixel storage equals nullptr ##
Cary Clark77b3f3a2018-11-07 14:59:03 -05002361# dst.rowBytes() is less than SkImageInfo::minRowBytes() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002362# Pixel_Ref is nullptr ##
2363##
2364
Cary Clarkac47b882018-01-11 10:35:44 -05002365Pixels are copied only if pixel conversion is possible. If Bitmap colorType is
Cary Clarkbc5697d2017-10-04 14:31:33 -04002366kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match.
Cary Clarkac47b882018-01-11 10:35:44 -05002367If Bitmap colorType is kGray_8_SkColorType, dst Color_Space must match.
2368If Bitmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must
2369match. If Bitmap colorSpace is nullptr, dst Color_Space must match. Returns
Cary Clarkbc5697d2017-10-04 14:31:33 -04002370false if pixel conversion is not possible.
Cary Clark682c58d2018-05-16 07:07:07 -04002371
Cary Clarkbc5697d2017-10-04 14:31:33 -04002372#Param dst destination Pixmap: Image_Info, pixels, row bytes ##
2373
2374#Return true if pixels are copied to dst ##
2375
2376#Example
2377#Height 128
2378#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04002379 std::vector<int32_t> srcPixels;
2380 srcPixels.resize(source.height() * source.width() * 8);
2381 for (int i = 0; i < 2; ++i) {
Cary Clark682c58d2018-05-16 07:07:07 -04002382 SkPixmap pixmap(SkImageInfo::Make(source.width() * 2, source.height(),
Ben Wagner29380bd2017-10-09 14:43:00 -04002383 i ? kRGBA_8888_SkColorType : kBGRA_8888_SkColorType, kPremul_SkAlphaType),
2384 &srcPixels.front() + i * source.width(), source.rowBytes() * 2);
2385 source.readPixels(pixmap);
2386 }
2387 canvas->scale(.25f, .25f);
2388 SkBitmap bitmap;
2389 bitmap.installPixels(SkImageInfo::MakeN32Premul(source.width() * 2, source.height()),
2390 &srcPixels.front(), source.rowBytes() * 2);
2391 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002392##
2393
2394#SeeAlso writePixels SkPixmap::readPixels SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
2395
2396##
2397
2398# ------------------------------------------------------------------------------
2399
2400#Method bool writePixels(const SkPixmap& src, int dstX, int dstY)
Cary Clark78de7512018-02-07 07:27:09 -05002401#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05002402#Line # copies and converts pixels ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002403Copies a Rect of pixels from src. Copy starts at (dstX, dstY), and does not exceed
Cary Clark682c58d2018-05-16 07:07:07 -04002404(src.width(), src.height()).
Cary Clarkbc5697d2017-10-04 14:31:33 -04002405
2406src specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage,
Cary Clark77b3f3a2018-11-07 14:59:03 -05002407and row bytes of source. src.rowBytes() specifics the gap from one source
Cary Clarkbc5697d2017-10-04 14:31:33 -04002408row to the next. Returns true if pixels are copied. Returns false if:
2409#List
2410# src pixel storage equals nullptr ##
Cary Clark77b3f3a2018-11-07 14:59:03 -05002411# src.rowBytes() is less than SkImageInfo::minRowBytes() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002412# Pixel_Ref is nullptr ##
2413##
2414
Cary Clarkac47b882018-01-11 10:35:44 -05002415Pixels are copied only if pixel conversion is possible. If Bitmap colorType is
Cary Clarkbc5697d2017-10-04 14:31:33 -04002416kGray_8_SkColorType, or kAlpha_8_SkColorType; src Color_Type must match.
Cary Clarkac47b882018-01-11 10:35:44 -05002417If Bitmap colorType is kGray_8_SkColorType, src Color_Space must match.
2418If Bitmap alphaType is kOpaque_SkAlphaType, src Alpha_Type must
2419match. If Bitmap colorSpace is nullptr, src Color_Space must match. Returns
Cary Clarkbc5697d2017-10-04 14:31:33 -04002420false if pixel conversion is not possible.
Cary Clark682c58d2018-05-16 07:07:07 -04002421
Cary Clarkbc5697d2017-10-04 14:31:33 -04002422dstX and dstY may be negative to copy only top or left of source. Returns
Cary Clark154beea2017-10-26 07:58:48 -04002423false if width() or height() is zero or negative.
Cary Clark2be81cf2018-09-13 12:04:30 -04002424Returns false if #Formula # abs(dstX) >= Bitmap width() ##, or if #Formula # abs(dstY) >= Bitmap height() ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002425
2426#Param src source Pixmap: Image_Info, pixels, row bytes ##
2427#Param dstX column index whose absolute value is less than width() ##
2428#Param dstY row index whose absolute value is less than height() ##
2429
2430#Return true if src pixels are copied to Bitmap ##
2431
2432#Example
2433#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04002434 std::vector<int32_t> srcPixels;
2435 int width = image->width();
2436 int height = image->height();
2437 srcPixels.resize(height * width * 4);
2438 SkPixmap pixmap(SkImageInfo::MakeN32Premul(width, height), (const void*) &srcPixels.front(),
2439 width * 4);
2440 image->readPixels(pixmap, 0, 0);
2441 canvas->scale(.5f, .5f);
2442 width /= 4;
2443 height /= 4;
2444 for (int y = 0; y < 4; ++y) {
2445 for (int x = 0; x < 4; ++x) {
2446 SkBitmap bitmap;
2447 bitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height));
2448 bitmap.writePixels(pixmap, -y * width, -x * height);
2449 canvas->drawBitmap(bitmap, x * width, y * height);
2450 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04002451 }
2452##
2453
Cary Clark682c58d2018-05-16 07:07:07 -04002454#SeeAlso readPixels
Cary Clarkbc5697d2017-10-04 14:31:33 -04002455
2456##
2457
2458# ------------------------------------------------------------------------------
2459
2460#Method bool writePixels(const SkPixmap& src)
2461
2462Copies a Rect of pixels from src. Copy starts at (0, 0), and does not exceed
Cary Clark682c58d2018-05-16 07:07:07 -04002463(src.width(), src.height()).
Cary Clarkbc5697d2017-10-04 14:31:33 -04002464
2465src specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage,
Cary Clark77b3f3a2018-11-07 14:59:03 -05002466and row bytes of source. src.rowBytes() specifics the gap from one source
Cary Clarkbc5697d2017-10-04 14:31:33 -04002467row to the next. Returns true if pixels are copied. Returns false if:
2468#List
2469# src pixel storage equals nullptr ##
Cary Clark77b3f3a2018-11-07 14:59:03 -05002470# src.rowBytes() is less than SkImageInfo::minRowBytes() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002471# Pixel_Ref is nullptr ##
2472##
2473
Cary Clarkac47b882018-01-11 10:35:44 -05002474Pixels are copied only if pixel conversion is possible. If Bitmap colorType is
Cary Clarkbc5697d2017-10-04 14:31:33 -04002475kGray_8_SkColorType, or kAlpha_8_SkColorType; src Color_Type must match.
Cary Clarkac47b882018-01-11 10:35:44 -05002476If Bitmap colorType is kGray_8_SkColorType, src Color_Space must match.
2477If Bitmap alphaType is kOpaque_SkAlphaType, src Alpha_Type must
2478match. If Bitmap colorSpace is nullptr, src Color_Space must match. Returns
Cary Clarkbc5697d2017-10-04 14:31:33 -04002479false if pixel conversion is not possible.
2480
2481#Param src source Pixmap: Image_Info, pixels, row bytes ##
2482
2483#Return true if src pixels are copied to Bitmap ##
2484
2485#Example
2486#Height 80
Ben Wagner29380bd2017-10-09 14:43:00 -04002487 SkBitmap bitmap;
2488 bitmap.allocPixels(SkImageInfo::MakeN32Premul(2, 2));
2489 bitmap.eraseColor(SK_ColorGREEN);
2490 SkPMColor color = 0xFF5599BB;
2491 SkPixmap src(SkImageInfo::MakeN32Premul(1, 1), &color, 4);
2492 bitmap.writePixels(src);
2493 canvas->scale(40, 40);
2494 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002495##
2496
2497#SeeAlso readPixels
2498
2499##
2500
2501# ------------------------------------------------------------------------------
2502
Cary Clarkbc5697d2017-10-04 14:31:33 -04002503#Method bool extractAlpha(SkBitmap* dst) const
Cary Clark61313f32018-10-08 14:57:48 -04002504#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05002505#Line # creates Bitmap containing Alpha of pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -04002506#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04002507
2508#Example
2509#Height 100
Ben Wagner29380bd2017-10-09 14:43:00 -04002510 SkBitmap alpha, bitmap;
2511 bitmap.allocN32Pixels(100, 100);
2512 SkCanvas offscreen(bitmap);
2513 offscreen.clear(0);
2514 SkPaint paint;
2515 paint.setAntiAlias(true);
2516 paint.setColor(SK_ColorBLUE);
2517 paint.setStyle(SkPaint::kStroke_Style);
2518 paint.setStrokeWidth(20);
2519 offscreen.drawCircle(50, 50, 39, paint);
2520 offscreen.flush();
2521 bitmap.extractAlpha(&alpha);
2522 paint.setColor(SK_ColorRED);
2523 canvas->drawBitmap(bitmap, 0, 0, &paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002524 canvas->drawBitmap(alpha, 100, 0, &paint);
2525##
2526
2527#SeeAlso extractSubset
2528
2529##
2530
2531# ------------------------------------------------------------------------------
2532
2533#Method bool extractAlpha(SkBitmap* dst, const SkPaint* paint,
2534 SkIPoint* offset) const
Cary Clark09d80c02018-10-31 12:14:03 -04002535#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04002536
Cary Clarkbc5697d2017-10-04 14:31:33 -04002537#Example
2538#Height 160
Cary Clark681287e2018-03-16 11:34:15 -04002539 auto radiusToSigma = [](SkScalar radius) -> SkScalar {
2540 static const SkScalar kBLUR_SIGMA_SCALE = 0.57735f;
2541 return radius > 0 ? kBLUR_SIGMA_SCALE * radius + 0.5f : 0.0f;
2542 };
2543 SkBitmap alpha, bitmap;
2544 bitmap.allocN32Pixels(100, 100);
2545 SkCanvas offscreen(bitmap);
2546 offscreen.clear(0);
2547 SkPaint paint;
2548 paint.setAntiAlias(true);
2549 paint.setColor(SK_ColorBLUE);
2550 paint.setStyle(SkPaint::kStroke_Style);
2551 paint.setStrokeWidth(20);
2552 offscreen.drawCircle(50, 50, 39, paint);
2553 offscreen.flush();
2554 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, radiusToSigma(25)));
2555 SkIPoint offset;
2556 bitmap.extractAlpha(&alpha, &paint, &offset);
2557 paint.setColor(SK_ColorRED);
2558 canvas->drawBitmap(bitmap, 0, -offset.fY, &paint);
2559 canvas->drawBitmap(alpha, 100 + offset.fX, 0, &paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002560##
2561
2562#SeeAlso extractSubset
2563
2564##
2565
2566# ------------------------------------------------------------------------------
2567
2568#Method bool extractAlpha(SkBitmap* dst, const SkPaint* paint, Allocator* allocator,
2569 SkIPoint* offset) const
Cary Clark09d80c02018-10-31 12:14:03 -04002570#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04002571
Cary Clarkbc5697d2017-10-04 14:31:33 -04002572#Example
2573#Height 128
Ben Wagner29380bd2017-10-09 14:43:00 -04002574 SkBitmap alpha, bitmap;
2575 bitmap.allocN32Pixels(100, 100);
2576 SkCanvas offscreen(bitmap);
2577 offscreen.clear(0);
2578 SkPaint paint;
2579 paint.setAntiAlias(true);
2580 paint.setColor(SK_ColorBLUE);
2581 paint.setStyle(SkPaint::kStroke_Style);
2582 paint.setStrokeWidth(20);
2583 offscreen.drawCircle(50, 50, 39, paint);
2584 offscreen.flush();
Cary Clark681287e2018-03-16 11:34:15 -04002585 paint.setMaskFilter(SkMaskFilter::MakeBlur(kOuter_SkBlurStyle, 3));
Ben Wagner29380bd2017-10-09 14:43:00 -04002586 SkIPoint offset;
2587 bitmap.extractAlpha(&alpha, &paint, nullptr, &offset);
2588 paint.setColor(SK_ColorRED);
2589 canvas->drawBitmap(bitmap, 0, -offset.fY, &paint);
2590 canvas->drawBitmap(alpha, 100 + offset.fX, 0, &paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002591##
2592
2593#SeeAlso extractSubset
2594
2595##
2596
2597# ------------------------------------------------------------------------------
2598
2599#Method bool peekPixels(SkPixmap* pixmap) const
Cary Clark78de7512018-02-07 07:27:09 -05002600#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05002601#Line # returns Pixmap if possible ##
Cary Clark09d80c02018-10-31 12:14:03 -04002602#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04002603
2604#Example
Ben Wagner29380bd2017-10-09 14:43:00 -04002605 SkBitmap bitmap;
2606 bitmap.allocPixels(SkImageInfo::MakeN32Premul(6, 11));
2607 SkCanvas offscreen(bitmap);
2608 offscreen.clear(SK_ColorWHITE);
2609 SkPaint paint;
2610 offscreen.drawString("?", 0, 10, paint);
2611 SkPixmap pixmap;
2612 if (bitmap.peekPixels(&pixmap)) {
2613 const SkPMColor* pixels = pixmap.addr32();
2614 SkPMColor pmWhite = pixels[0];
2615 for (int y = 0; y < bitmap.height(); ++y) {
2616 for (int x = 0; x < bitmap.width(); ++x) {
2617 SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x');
2618 }
2619 SkDebugf("\n");
2620 }
2621 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04002622 #StdOut
Cary Clark2f466242017-12-11 16:03:17 -05002623------
2624-xxx--
2625x---x-
2626----x-
2627---x--
2628--x---
2629--x---
2630------
2631--x---
2632--x---
Cary Clarka560c472017-11-27 10:44:06 -05002633------
Cary Clarkbc5697d2017-10-04 14:31:33 -04002634 #StdOut ##
2635##
2636
Cary Clarka90ea222018-10-16 10:30:28 -04002637#SeeAlso pixmap installPixels readPixels writePixels
Cary Clarkbc5697d2017-10-04 14:31:33 -04002638
2639##
2640
2641# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05002642#Subtopic Utility
Cary Clark78de7512018-02-07 07:27:09 -05002643#Line # rarely called management functions ##
2644##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002645
Cary Clark154beea2017-10-26 07:58:48 -04002646#Method void validate() const;
Cary Clark78de7512018-02-07 07:27:09 -05002647#In Utility
Cary Clarkab2621d2018-01-30 10:08:57 -05002648#Line # asserts if Bitmap is invalid (debug only) ##
Cary Clark09d80c02018-10-31 12:14:03 -04002649#Populate
Cary Clark154beea2017-10-26 07:58:48 -04002650
2651#NoExample
2652##
2653
Cary Clark06c20f32018-03-20 15:53:27 -04002654#SeeAlso SkImageInfo::validate
Cary Clark154beea2017-10-26 07:58:48 -04002655
2656##
2657
2658# ------------------------------------------------------------------------------
2659
Cary Clarkbc5697d2017-10-04 14:31:33 -04002660#Class SkBitmap ##
2661
2662#Topic Bitmap ##