blob: 7a44af50359c7e86e588e7dbfda06f47273af2bb [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# ------------------------------------------------------------------------------
1542
1543#Method bool installMaskPixels(const SkMask& mask)
Cary Clark4855f782018-02-06 09:41:53 -05001544#Deprecated soon
Cary Clarkbc5697d2017-10-04 14:31:33 -04001545##
1546
1547# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05001548#Subtopic Pixels
Cary Clark78de7512018-02-07 07:27:09 -05001549#Line # read and write pixel values ##
1550##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001551
1552#Method void setPixels(void* pixels)
Cary Clark78de7512018-02-07 07:27:09 -05001553#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001554#Line # sets Pixel_Ref without an offset ##
Cary Clark09d80c02018-10-31 12:14:03 -04001555#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001556
1557#Example
1558#Height 50
Ben Wagner29380bd2017-10-09 14:43:00 -04001559 uint8_t set1[5] = { 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 };
1560 uint8_t set2[5] = { 0xAC, 0xA8, 0x89, 0x47, 0x87 };
1561 SkBitmap bitmap;
1562 bitmap.installPixels(SkImageInfo::Make(5, 1, kGray_8_SkColorType, kOpaque_SkAlphaType), set1, 5);
1563 canvas->scale(10, 50);
1564 canvas->drawBitmap(bitmap, 0, 0);
1565 bitmap.setPixels(set2);
1566 canvas->drawBitmap(bitmap, 10, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001567##
1568
1569#SeeAlso installPixels allocPixels
1570
1571##
1572
1573# ------------------------------------------------------------------------------
1574
Cary Clark61313f32018-10-08 14:57:48 -04001575#Method bool tryAllocPixels()
Cary Clark78de7512018-02-07 07:27:09 -05001576#In Allocate
Cary Clark09d80c02018-10-31 12:14:03 -04001577#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001578
1579#Example
1580#Height 50
Cary Clark682c58d2018-05-16 07:07:07 -04001581#Description
Cary Clarkbc5697d2017-10-04 14:31:33 -04001582Bitmap hosts and draws gray values in set1. tryAllocPixels replaces Pixel_Ref
1583and erases it to black, but does not alter set1. setPixels replaces black
Cary Clark682c58d2018-05-16 07:07:07 -04001584Pixel_Ref with set1.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001585##
Ben Wagner29380bd2017-10-09 14:43:00 -04001586 uint8_t set1[5] = { 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 };
1587 SkBitmap bitmap;
1588 bitmap.installPixels(SkImageInfo::Make(5, 1, kGray_8_SkColorType, kOpaque_SkAlphaType), set1, 5);
1589 canvas->scale(10, 50);
1590 canvas->drawBitmap(bitmap, 0, 0);
1591 if (bitmap.tryAllocPixels()) {
1592 bitmap.eraseColor(SK_ColorBLACK);
1593 canvas->drawBitmap(bitmap, 8, 0);
1594 bitmap.setPixels(set1);
1595 canvas->drawBitmap(bitmap, 16, 0);
1596 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04001597##
1598
1599#SeeAlso allocPixels installPixels setPixels
1600
1601##
1602
1603# ------------------------------------------------------------------------------
1604
1605#Method void allocPixels()
Cary Clark78de7512018-02-07 07:27:09 -05001606#In Allocate
Cary Clark09d80c02018-10-31 12:14:03 -04001607#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001608
1609#Example
1610#Height 50
Cary Clark682c58d2018-05-16 07:07:07 -04001611#Description
Cary Clarkbc5697d2017-10-04 14:31:33 -04001612Bitmap hosts and draws gray values in set1. allocPixels replaces Pixel_Ref
1613and erases it to black, but does not alter set1. setPixels replaces black
Cary Clark682c58d2018-05-16 07:07:07 -04001614Pixel_Ref with set2.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001615##
Ben Wagner29380bd2017-10-09 14:43:00 -04001616 uint8_t set1[5] = { 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 };
1617 uint8_t set2[5] = { 0xAC, 0xA8, 0x89, 0x47, 0x87 };
1618 SkBitmap bitmap;
1619 bitmap.installPixels(SkImageInfo::Make(5, 1, kGray_8_SkColorType, kOpaque_SkAlphaType), set1, 5);
1620 canvas->scale(10, 50);
1621 canvas->drawBitmap(bitmap, 0, 0);
1622 bitmap.allocPixels();
1623 bitmap.eraseColor(SK_ColorBLACK);
1624 canvas->drawBitmap(bitmap, 8, 0);
1625 bitmap.setPixels(set2);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001626 canvas->drawBitmap(bitmap, 16, 0);
1627##
1628
1629#SeeAlso tryAllocPixels installPixels setPixels
1630
1631##
1632
1633# ------------------------------------------------------------------------------
1634
Cary Clark61313f32018-10-08 14:57:48 -04001635#Method bool tryAllocPixels(Allocator* allocator)
Cary Clark09d80c02018-10-31 12:14:03 -04001636#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001637
1638#Example
1639#Height 100
1640#Description
1641HeapAllocator limits the maximum size of Bitmap to two gigabytes. Using
1642a custom allocator, this limitation may be relaxed. This example can be
Cary Clark682c58d2018-05-16 07:07:07 -04001643modified to allocate an eight gigabyte Bitmap on a 64-bit platform with
Cary Clarkbc5697d2017-10-04 14:31:33 -04001644sufficient memory.
1645##
1646#Function
1647class LargePixelRef : public SkPixelRef {
1648public:
1649 LargePixelRef(const SkImageInfo& info, char* storage, size_t rowBytes)
1650 : SkPixelRef(info.width(), info.height(), storage, rowBytes) {
1651 }
1652
1653 ~LargePixelRef() override {
1654 delete[] (char* ) this->pixels();
1655 }
1656};
1657
1658class LargeAllocator : public SkBitmap::Allocator {
1659public:
1660 bool allocPixelRef(SkBitmap* bitmap) override {
1661 const SkImageInfo& info = bitmap->info();
1662 uint64_t rowBytes = info.minRowBytes64();
1663 uint64_t size = info.height() * rowBytes;
1664 char* addr = new char[size];
1665 if (nullptr == addr) {
1666 return false;
1667 }
1668 sk_sp<SkPixelRef> pr = sk_sp<SkPixelRef>(new LargePixelRef(info, addr, rowBytes));
1669 if (!pr) {
1670 return false;
1671 }
1672 bitmap->setPixelRef(std::move(pr), 0, 0);
1673 return true;
1674 }
1675};
1676
1677##
1678
1679void draw(SkCanvas* canvas) {
1680 LargeAllocator largeAllocator;
1681 SkBitmap bitmap;
Ben Wagner29380bd2017-10-09 14:43:00 -04001682 int width = 100; // make this 20000
1683 int height = 100; // and this 100000 to allocate 8 gigs on a 64-bit platform
1684 bitmap.setInfo(SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType));
1685 if (bitmap.tryAllocPixels(&largeAllocator)) {
1686 bitmap.eraseColor(0xff55aa33);
1687 canvas->drawBitmap(bitmap, 0, 0);
1688 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04001689}
1690
1691##
1692
1693#SeeAlso allocPixels Allocator Pixel_Ref
1694
1695##
1696
1697# ------------------------------------------------------------------------------
1698
1699#Method void allocPixels(Allocator* allocator)
Cary Clark09d80c02018-10-31 12:14:03 -04001700#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001701
1702#Example
1703#Height 32
1704#Function
1705class TinyAllocator : public SkBitmap::Allocator {
1706public:
1707 bool allocPixelRef(SkBitmap* bitmap) override {
1708 const SkImageInfo& info = bitmap->info();
1709 if (info.height() * info.minRowBytes() > sizeof(storage)) {
1710 return false;
1711 }
1712 sk_sp<SkPixelRef> pr = sk_sp<SkPixelRef>(
1713 new SkPixelRef(info.width(), info.height(), storage, info.minRowBytes()));
1714 bitmap->setPixelRef(std::move(pr), 0, 0);
1715 return true;
1716 }
1717
1718 char storage[16];
1719};
1720
1721##
1722
1723void draw(SkCanvas* canvas) {
1724 TinyAllocator tinyAllocator;
1725 SkBitmap bitmap;
Ben Wagner29380bd2017-10-09 14:43:00 -04001726 bitmap.setInfo(SkImageInfo::MakeN32(2, 2, kOpaque_SkAlphaType));
1727 if (bitmap.tryAllocPixels(&tinyAllocator)) {
1728 bitmap.eraseColor(0xff55aa33);
1729 bitmap.erase(0xffaa3355, SkIRect::MakeXYWH(1, 1, 1, 1));
1730 canvas->scale(16, 16);
1731 canvas->drawBitmap(bitmap, 0, 0);
1732 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04001733}
1734##
1735
1736#SeeAlso allocPixels Allocator Pixel_Ref
1737
1738##
1739
1740# ------------------------------------------------------------------------------
1741
1742#Method SkPixelRef* pixelRef() const
Cary Clark78de7512018-02-07 07:27:09 -05001743#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05001744#Line # returns Pixel_Ref, or nullptr ##
Cary Clark09d80c02018-10-31 12:14:03 -04001745#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001746
1747#Example
1748#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04001749 SkBitmap subset;
1750 source.extractSubset(&subset, SkIRect::MakeXYWH(32, 64, 128, 256));
1751 SkDebugf("src ref %c= sub ref\n", source.pixelRef() == subset.pixelRef() ? '=' : '!');
1752 SkDebugf("src pixels %c= sub pixels\n", source.getPixels() == subset.getPixels() ? '=' : '!');
1753 SkDebugf("src addr %c= sub addr\n", source.getAddr(32, 64) == subset.getAddr(0, 0) ? '=' : '!');
Cary Clarkbc5697d2017-10-04 14:31:33 -04001754##
1755
1756#SeeAlso getPixels getAddr
1757
1758##
1759
1760# ------------------------------------------------------------------------------
1761
1762#Method SkIPoint pixelRefOrigin() const
Cary Clark78de7512018-02-07 07:27:09 -05001763#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05001764#Line # returns offset within Pixel_Ref ##
Cary Clark09d80c02018-10-31 12:14:03 -04001765#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001766
1767#Example
1768#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04001769 SkBitmap subset;
1770 source.extractSubset(&subset, SkIRect::MakeXYWH(32, 64, 128, 256));
1771 SkIPoint sourceOrigin = source.pixelRefOrigin();
1772 SkIPoint subsetOrigin = subset.pixelRefOrigin();
1773 SkDebugf("source origin: %d, %d\n", sourceOrigin.fX, sourceOrigin.fY);
1774 SkDebugf("subset origin: %d, %d\n", subsetOrigin.fX, subsetOrigin.fY);
1775#StdOut
1776source origin: 0, 0
1777subset origin: 32, 64
1778##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001779##
1780
Cary Clark2ade9972017-11-02 17:49:34 -04001781#SeeAlso SkPixelRef getSubset setPixelRef
Cary Clarkbc5697d2017-10-04 14:31:33 -04001782
1783##
1784
1785# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05001786#Subtopic Set
1787#Line # updates values and attributes ##
Cary Clark78de7512018-02-07 07:27:09 -05001788##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001789
1790#Method void setPixelRef(sk_sp<SkPixelRef> pixelRef, int dx, int dy)
Cary Clark78de7512018-02-07 07:27:09 -05001791#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -05001792#Line # sets Pixel_Ref and offset ##
Cary Clark09d80c02018-10-31 12:14:03 -04001793#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001794
1795#Example
1796#Height 140
1797#Image 5
1798#Description
Cary Clark682c58d2018-05-16 07:07:07 -04001799Treating 32-bit data as 8-bit data is unlikely to produce useful results.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001800##
Ben Wagner29380bd2017-10-09 14:43:00 -04001801 SkBitmap bitmap;
Cary Clark682c58d2018-05-16 07:07:07 -04001802 bitmap.setInfo(SkImageInfo::Make(source.width() - 5, source.height() - 5,
Ben Wagner29380bd2017-10-09 14:43:00 -04001803 kGray_8_SkColorType, kOpaque_SkAlphaType), source.rowBytes());
1804 bitmap.setPixelRef(sk_ref_sp(source.pixelRef()), 5, 5);
1805 canvas->drawBitmap(bitmap, 10, 10);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001806##
1807
1808#SeeAlso setInfo
1809
1810##
1811
1812# ------------------------------------------------------------------------------
1813
1814#Method bool readyToDraw() const
Cary Clark78de7512018-02-07 07:27:09 -05001815#In Utility
Cary Clarkab2621d2018-01-30 10:08:57 -05001816#Line # returns true if address of pixels is not nullptr ##
Cary Clark09d80c02018-10-31 12:14:03 -04001817#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001818
1819#Example
1820#Image 5
1821#Height 160
Ben Wagner29380bd2017-10-09 14:43:00 -04001822 if (source.readyToDraw()) {
1823 canvas->drawBitmap(source, 10, 10);
1824 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04001825##
1826
1827#SeeAlso getPixels drawsNothing
1828
1829##
1830
1831# ------------------------------------------------------------------------------
1832
1833#Method uint32_t getGenerationID() const
Cary Clark78de7512018-02-07 07:27:09 -05001834#In Utility
Cary Clarkab2621d2018-01-30 10:08:57 -05001835#Line # returns unique ID ##
Cary Clark09d80c02018-10-31 12:14:03 -04001836#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001837
1838#Example
Ben Wagner29380bd2017-10-09 14:43:00 -04001839 SkBitmap bitmap;
1840 SkDebugf("empty id %u\n", bitmap.getGenerationID());
1841 bitmap.allocPixels(SkImageInfo::MakeN32(64, 64, kOpaque_SkAlphaType));
1842 SkDebugf("alloc id %u\n", bitmap.getGenerationID());
1843 bitmap.eraseColor(SK_ColorRED);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001844 SkDebugf("erase id %u\n", bitmap.getGenerationID());
1845#StdOut
1846#Volatile
Ben Wagner29380bd2017-10-09 14:43:00 -04001847empty id 0
1848alloc id 4
Cary Clarkbc5697d2017-10-04 14:31:33 -04001849erase id 6
Cary Clark682c58d2018-05-16 07:07:07 -04001850##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001851##
1852
1853#SeeAlso notifyPixelsChanged Pixel_Ref
1854
1855##
1856
1857# ------------------------------------------------------------------------------
1858
1859#Method void notifyPixelsChanged() const
Cary Clark78de7512018-02-07 07:27:09 -05001860#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001861#Line # marks pixels as changed, altering the unique ID ##
Cary Clark09d80c02018-10-31 12:14:03 -04001862#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001863
1864#Example
1865#Height 20
Cary Clark682c58d2018-05-16 07:07:07 -04001866 SkBitmap bitmap;
Ben Wagner29380bd2017-10-09 14:43:00 -04001867 bitmap.setInfo(SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType));
1868 bitmap.allocPixels();
1869 bitmap.eraseColor(SK_ColorRED);
1870 canvas->scale(16, 16);
1871 canvas->drawBitmap(bitmap, 0, 0);
1872 *(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorBLUE);
1873 canvas->drawBitmap(bitmap, 2, 0);
1874 bitmap.notifyPixelsChanged();
1875 *(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorGREEN);
1876 canvas->drawBitmap(bitmap, 4, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001877##
1878
1879#SeeAlso getGenerationID isVolatile Pixel_Ref
1880
1881##
1882
1883# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05001884#Subtopic Draw
Cary Clark682c58d2018-05-16 07:07:07 -04001885#Line # sets pixels to Color ##
Cary Clark78de7512018-02-07 07:27:09 -05001886##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001887
1888#Method void eraseColor(SkColor c) const
Cary Clark78de7512018-02-07 07:27:09 -05001889#In Draw
Cary Clarkab2621d2018-01-30 10:08:57 -05001890#Line # writes Color to pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -04001891#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001892
1893#Example
1894#Height 20
Cary Clark682c58d2018-05-16 07:07:07 -04001895 SkBitmap bitmap;
Ben Wagner29380bd2017-10-09 14:43:00 -04001896 bitmap.allocPixels(SkImageInfo::MakeN32(1, 1, kOpaque_SkAlphaType));
1897 bitmap.eraseColor(SK_ColorRED);
1898 canvas->scale(16, 16);
1899 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001900##
1901
Cary Clark154beea2017-10-26 07:58:48 -04001902#SeeAlso eraseARGB erase
Cary Clarkbc5697d2017-10-04 14:31:33 -04001903
1904##
1905
1906# ------------------------------------------------------------------------------
1907
1908#Method void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const
Cary Clark78de7512018-02-07 07:27:09 -05001909#In Draw
Cary Clarkab2621d2018-01-30 10:08:57 -05001910#Line # writes Color to pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -04001911#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001912
1913#Example
1914#Height 80
Cary Clark682c58d2018-05-16 07:07:07 -04001915 SkBitmap bitmap;
Ben Wagner29380bd2017-10-09 14:43:00 -04001916 bitmap.allocPixels(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType));
1917 bitmap.eraseARGB(0x7f, 0xff, 0x7f, 0x3f);
1918 canvas->scale(50, 50);
1919 canvas->drawBitmap(bitmap, 0, 0);
1920 canvas->drawBitmap(bitmap, .5f, .5f);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001921##
1922
Cary Clark154beea2017-10-26 07:58:48 -04001923#SeeAlso eraseColor erase
Cary Clarkbc5697d2017-10-04 14:31:33 -04001924
1925##
1926
1927# ------------------------------------------------------------------------------
1928
Cary Clarkbc5697d2017-10-04 14:31:33 -04001929#Method void erase(SkColor c, const SkIRect& area) const
Cary Clark78de7512018-02-07 07:27:09 -05001930#In Draw
Cary Clarkab2621d2018-01-30 10:08:57 -05001931#Line # writes Color to rectangle of pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -04001932#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001933
1934#Example
1935#Height 70
Cary Clark682c58d2018-05-16 07:07:07 -04001936 SkBitmap bitmap;
Ben Wagner29380bd2017-10-09 14:43:00 -04001937 bitmap.allocPixels(SkImageInfo::MakeN32(2, 2, kPremul_SkAlphaType));
1938 bitmap.erase(0x7fff7f3f, SkIRect::MakeWH(1, 1));
1939 bitmap.erase(0x7f7f3fff, SkIRect::MakeXYWH(0, 1, 1, 1));
1940 bitmap.erase(0x7f3fff7f, SkIRect::MakeXYWH(1, 0, 1, 1));
1941 bitmap.erase(0x7f1fbf5f, SkIRect::MakeXYWH(1, 1, 1, 1));
1942 canvas->scale(25, 25);
1943 canvas->drawBitmap(bitmap, 0, 0);
1944 canvas->drawBitmap(bitmap, .5f, .5f);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001945
1946##
1947
Mike Kleinfe5ad672018-10-04 10:18:13 -04001948#SeeAlso eraseColor eraseARGB SkCanvas::drawRect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001949
1950##
1951
1952# ------------------------------------------------------------------------------
1953
1954#Method void eraseArea(const SkIRect& area, SkColor c) const
Cary Clark682c58d2018-05-16 07:07:07 -04001955#Deprecated
Cary Clarkbc5697d2017-10-04 14:31:33 -04001956##
1957
Cary Clarkbc5697d2017-10-04 14:31:33 -04001958# ------------------------------------------------------------------------------
1959
1960#Method SkColor getColor(int x, int y) const
Cary Clark78de7512018-02-07 07:27:09 -05001961#In Property
1962#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001963#Line # returns one pixel as Unpremultiplied Color ##
Cary Clark09d80c02018-10-31 12:14:03 -04001964#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001965
1966#Example
1967 const int w = 4;
1968 const int h = 4;
1969 SkColor colors[][w] = {
Cary Clark75fd4492018-06-20 12:45:16 -04001970 { 0x00000000, 0x2a0e002a, 0x55380055, 0x7f7f007f },
1971 { 0x2a000e2a, 0x551c1c55, 0x7f542a7f, 0xaaaa38aa },
1972 { 0x55003855, 0x7f2a547f, 0xaa7171aa, 0xd4d48dd4 },
1973 { 0x7f007f7f, 0xaa38aaaa, 0xd48dd4d4, 0xffffffff }
Cary Clarkbc5697d2017-10-04 14:31:33 -04001974 };
1975 SkDebugf("Premultiplied:\n");
1976 for (int y = 0; y < h; ++y) {
1977 SkDebugf("(0, %d) ", y);
1978 for (int x = 0; x < w; ++x) {
1979 SkDebugf("0x%08x%c", colors[y][x], x == w - 1 ? '\n' : ' ');
1980 }
1981 }
1982 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), colors, w * 4);
1983 SkBitmap bitmap;
1984 bitmap.installPixels(pixmap);
1985 SkDebugf("Unpremultiplied:\n");
1986 for (int y = 0; y < h; ++y) {
1987 SkDebugf("(0, %d) ", y);
1988 for (int x = 0; x < w; ++x) {
1989 SkDebugf("0x%08x%c", bitmap.getColor(x, y), x == w - 1 ? '\n' : ' ');
1990 }
1991 }
1992#StdOut
1993Premultiplied:
Cary Clark682c58d2018-05-16 07:07:07 -04001994(0, 0) 0x00000000 0x2a0e002a 0x55380055 0x7f7f007f
1995(0, 1) 0x2a000e2a 0x551c1c55 0x7f542a7f 0xaaaa38aa
1996(0, 2) 0x55003855 0x7f2a547f 0xaa7171aa 0xd4d48dd4
1997(0, 3) 0x7f007f7f 0xaa38aaaa 0xd48dd4d4 0xffffffff
Cary Clarkbc5697d2017-10-04 14:31:33 -04001998Unpremultiplied:
Cary Clark682c58d2018-05-16 07:07:07 -04001999(0, 0) 0x00000000 0x2a5500ff 0x55a800ff 0x7fff00ff
2000(0, 1) 0x2a0055ff 0x555454ff 0x7fa954ff 0xaaff54ff
2001(0, 2) 0x5500a8ff 0x7f54a9ff 0xaaaaaaff 0xd4ffaaff
2002(0, 3) 0x7f00ffff 0xaa54ffff 0xd4aaffff 0xffffffff
Cary Clarkbc5697d2017-10-04 14:31:33 -04002003##
2004##
2005
Cary Clark8fe29402018-09-20 17:31:43 -04002006#SeeAlso getAlphaf getAddr readPixels
Cary Clarkbc5697d2017-10-04 14:31:33 -04002007
2008##
2009
Cary Clark8fe29402018-09-20 17:31:43 -04002010#Method float getAlphaf(int x, int y) const
2011#In Property
2012#Line # returns Alpha normalized from zero to one ##
2013
2014Looks up the pixel at (x,y) and return its alpha component, normalized to [0..1].
Cary Clark77b3f3a2018-11-07 14:59:03 -05002015This is roughly equivalent to #Formula # SkGetColorA(getColor()) ##, but can be more efficient
Cary Clark8fe29402018-09-20 17:31:43 -04002016(and more precise if the pixels store more than 8 bits per component).
2017
2018#Param x column index, zero or greater, and less than width() ##
2019#Param y row index, zero or greater, and less than height() ##
2020
2021#Return alpha converted to normalized float ##
2022
2023#NoExample
2024##
2025
2026#SeeAlso getColor
2027
2028##
2029
2030
Cary Clarkbc5697d2017-10-04 14:31:33 -04002031# ------------------------------------------------------------------------------
2032
2033#Method void* getAddr(int x, int y) const
Cary Clark78de7512018-02-07 07:27:09 -05002034#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002035#Line # returns readable pixel address as void pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -04002036#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04002037
2038#Example
2039#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04002040 char* row0 = (char* ) source.getAddr(0, 0);
2041 char* row1 = (char* ) source.getAddr(0, 1);
Cary Clark681287e2018-03-16 11:34:15 -04002042 SkDebugf("addr interval %c= rowBytes\n",
2043 (size_t) (row1 - row0) == source.rowBytes() ? '=' : '!');
Ben Wagner29380bd2017-10-09 14:43:00 -04002044#StdOut
2045addr interval == rowBytes
2046##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002047##
2048
2049#SeeAlso getAddr8 getAddr16 getAddr32 readPixels SkPixmap::addr
2050
2051##
2052
2053# ------------------------------------------------------------------------------
2054
Cary Clark61313f32018-10-08 14:57:48 -04002055#Method uint32_t* getAddr32(int x, int y) const
Cary Clark78de7512018-02-07 07:27:09 -05002056#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002057#Line # returns readable pixel address as 32-bit pointer ##
Cary Clark682c58d2018-05-16 07:07:07 -04002058Returns address at (x, y).
Cary Clarkbc5697d2017-10-04 14:31:33 -04002059
2060Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:
2061#List
2062# Pixel_Ref is nullptr ##
2063# bytesPerPixel() is not four ##
2064# x is negative, or not less than width() ##
2065# y is negative, or not less than height() ##
2066##
2067
2068#Param x column index, zero or greater, and less than width() ##
2069#Param y row index, zero or greater, and less than height() ##
2070
2071#Return unsigned 32-bit pointer to pixel at (x, y) ##
2072
2073#Example
2074#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04002075 uint32_t* row0 = source.getAddr32(0, 0);
2076 uint32_t* row1 = source.getAddr32(0, 1);
2077 size_t interval = (row1 - row0) * source.bytesPerPixel();
2078 SkDebugf("addr interval %c= rowBytes\n", interval == source.rowBytes() ? '=' : '!');
2079#StdOut
2080addr interval == rowBytes
2081##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002082##
2083
2084#SeeAlso getAddr8 getAddr16 getAddr readPixels SkPixmap::addr32
2085
2086##
2087
2088# ------------------------------------------------------------------------------
2089
Cary Clark61313f32018-10-08 14:57:48 -04002090#Method uint16_t* getAddr16(int x, int y) const
Cary Clark78de7512018-02-07 07:27:09 -05002091#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002092#Line # returns readable pixel address as 16-bit pointer ##
Cary Clark682c58d2018-05-16 07:07:07 -04002093Returns address at (x, y).
Cary Clarkbc5697d2017-10-04 14:31:33 -04002094
2095Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:
2096#List
2097# Pixel_Ref is nullptr ##
2098# bytesPerPixel() is not two ##
2099# x is negative, or not less than width() ##
2100# y is negative, or not less than height() ##
2101##
2102
2103#Param x column index, zero or greater, and less than width() ##
2104#Param y row index, zero or greater, and less than height() ##
2105
2106#Return unsigned 16-bit pointer to pixel at (x, y)##
2107
2108#Example
2109#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04002110 SkBitmap bitmap16;
Cary Clark682c58d2018-05-16 07:07:07 -04002111 SkImageInfo dstInfo = SkImageInfo::Make(source.width(), source.height(), kARGB_4444_SkColorType,
Ben Wagner29380bd2017-10-09 14:43:00 -04002112 kPremul_SkAlphaType);
2113 bitmap16.allocPixels(dstInfo);
2114 if (source.readPixels(dstInfo, bitmap16.getPixels(), bitmap16.rowBytes(), 0, 0)) {
2115 uint16_t* row0 = bitmap16.getAddr16(0, 0);
2116 uint16_t* row1 = bitmap16.getAddr16(0, 1);
2117 size_t interval = (row1 - row0) * bitmap16.bytesPerPixel();
2118 SkDebugf("addr interval %c= rowBytes\n", interval == bitmap16.rowBytes() ? '=' : '!');
2119 }
2120#StdOut
2121addr interval == rowBytes
2122##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002123##
2124
2125#SeeAlso getAddr8 getAddr getAddr32 readPixels SkPixmap::addr16
2126
2127##
2128
2129# ------------------------------------------------------------------------------
2130
Cary Clark61313f32018-10-08 14:57:48 -04002131#Method uint8_t* getAddr8(int x, int y) const
Cary Clark78de7512018-02-07 07:27:09 -05002132#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002133#Line # returns readable pixel address as 8-bit pointer ##
Cary Clark682c58d2018-05-16 07:07:07 -04002134Returns address at (x, y).
Cary Clarkbc5697d2017-10-04 14:31:33 -04002135
2136Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:
2137#List
2138# Pixel_Ref is nullptr ##
2139# bytesPerPixel() is not one ##
2140# x is negative, or not less than width() ##
2141# y is negative, or not less than height() ##
2142##
2143
2144#Param x column index, zero or greater, and less than width() ##
2145#Param y row index, zero or greater, and less than height() ##
2146
2147#Return unsigned 8-bit pointer to pixel at (x, y) ##
2148
2149#Example
Ben Wagner29380bd2017-10-09 14:43:00 -04002150 SkBitmap bitmap;
2151 const int width = 8;
2152 const int height = 8;
2153 uint8_t pixels[height][width];
2154 SkImageInfo info = SkImageInfo::Make(width, height, kGray_8_SkColorType, kOpaque_SkAlphaType);
2155 if (bitmap.installPixels(info, pixels, info.minRowBytes())) {
2156 SkDebugf("&pixels[4][2] %c= bitmap.getAddr8(2, 4)\n",
2157 &pixels[4][2] == bitmap.getAddr8(2, 4) ? '=' : '!');
2158 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04002159#StdOut
2160&pixels[4][2] == bitmap.getAddr8(2, 4)
2161##
2162##
2163
2164#SeeAlso getAddr getAddr16 getAddr32 readPixels SkPixmap::addr8
2165
2166##
2167
2168# ------------------------------------------------------------------------------
2169
2170#Method bool extractSubset(SkBitmap* dst, const SkIRect& subset) const
Cary Clark61313f32018-10-08 14:57:48 -04002171#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05002172#Line # creates Bitmap, sharing pixels if possible ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002173Shares Pixel_Ref with dst. Pixels are not copied; Bitmap and dst point
2174to the same pixels; dst bounds() are set to the intersection of subset
2175and the original bounds().
2176
2177subset may be larger than bounds(). Any area outside of bounds() is ignored.
2178
2179Any contents of dst are discarded. isVolatile setting is copied to dst.
2180dst is set to colorType, alphaType, and colorSpace.
2181
2182Return false if:
2183#List
2184# dst is nullptr ##
2185# Pixel_Ref is nullptr ##
2186# subset does not intersect bounds() ##
Cary Clark682c58d2018-05-16 07:07:07 -04002187##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002188
2189#Param dst Bitmap set to subset ##
2190#Param subset rectangle of pixels to reference ##
2191
2192#Return true if dst is replaced by subset
2193##
2194
2195#Example
2196#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04002197 SkIRect bounds, s;
2198 source.getBounds(&bounds);
2199 SkDebugf("bounds: %d, %d, %d, %d\n", bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
2200 SkBitmap subset;
2201 for (int left: { -100, 0, 100, 1000 } ) {
2202 for (int right: { 0, 100, 1000 } ) {
2203 SkIRect b = SkIRect::MakeLTRB(left, 100, right, 200);
2204 bool success = source.extractSubset(&subset, b);
2205 SkDebugf("subset: %4d, %4d, %4d, %4d ", b.fLeft, b.fTop, b.fRight, b.fBottom);
2206 SkDebugf("success; %s", success ? "true" : "false");
2207 if (success) {
Cary Clark682c58d2018-05-16 07:07:07 -04002208 subset.getBounds(&s);
Ben Wagner29380bd2017-10-09 14:43:00 -04002209 SkDebugf(" subset: %d, %d, %d, %d", s.fLeft, s.fTop, s.fRight, s.fBottom);
2210 }
2211 SkDebugf("\n");
Cary Clark682c58d2018-05-16 07:07:07 -04002212 }
Ben Wagner29380bd2017-10-09 14:43:00 -04002213 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04002214#StdOut
Ben Wagner29380bd2017-10-09 14:43:00 -04002215bounds: 0, 0, 512, 512
2216subset: -100, 100, 0, 200 success; false
2217subset: -100, 100, 100, 200 success; true subset: 0, 0, 100, 100
2218subset: -100, 100, 1000, 200 success; true subset: 0, 0, 512, 100
2219subset: 0, 100, 0, 200 success; false
2220subset: 0, 100, 100, 200 success; true subset: 0, 0, 100, 100
2221subset: 0, 100, 1000, 200 success; true subset: 0, 0, 512, 100
2222subset: 100, 100, 0, 200 success; false
2223subset: 100, 100, 100, 200 success; false
2224subset: 100, 100, 1000, 200 success; true subset: 0, 0, 412, 100
2225subset: 1000, 100, 0, 200 success; false
2226subset: 1000, 100, 100, 200 success; false
Cary Clarkbc5697d2017-10-04 14:31:33 -04002227subset: 1000, 100, 1000, 200 success; false
2228##
2229##
2230
2231#SeeAlso readPixels writePixels SkCanvas::drawBitmap
2232
2233##
2234
2235# ------------------------------------------------------------------------------
2236
2237#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
Cary Clarkbc5697d2017-10-04 14:31:33 -04002238 int srcX, int srcY) const
Cary Clarke80cd442018-07-17 13:19:56 -04002239#In Pixels
Cary Clark09d80c02018-10-31 12:14:03 -04002240#Line # copies and converts pixels ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002241
Cary Clarkac47b882018-01-11 10:35:44 -05002242Copies a Rect of pixels from Bitmap to dstPixels. Copy starts at (srcX, srcY),
Cary Clark682c58d2018-05-16 07:07:07 -04002243and does not exceed Bitmap (width(), height()).
Cary Clarkbc5697d2017-10-04 14:31:33 -04002244
Cary Clarkac47b882018-01-11 10:35:44 -05002245dstInfo specifies width, height, Color_Type, Alpha_Type, and Color_Space of
2246destination. dstRowBytes specifics the gap from one destination row to the next.
2247Returns true if pixels are copied. Returns false if:
Cary Clarkbc5697d2017-10-04 14:31:33 -04002248#List
Cary Clark09d80c02018-10-31 12:14:03 -04002249# dstInfo has no address ##
Cary Clark77b3f3a2018-11-07 14:59:03 -05002250# dstRowBytes is less than dstInfo.minRowBytes() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002251# Pixel_Ref is nullptr ##
2252##
2253
Cary Clarkac47b882018-01-11 10:35:44 -05002254Pixels are copied only if pixel conversion is possible. If Bitmap colorType is
Cary Clark77b3f3a2018-11-07 14:59:03 -05002255kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match.
2256If Bitmap colorType is kGray_8_SkColorType, dstInfo.colorSpace() must match.
2257If Bitmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType() must
2258match. If Bitmap colorSpace is nullptr, dstInfo.colorSpace() must match. Returns
Cary Clarkbc5697d2017-10-04 14:31:33 -04002259false if pixel conversion is not possible.
Cary Clark682c58d2018-05-16 07:07:07 -04002260
Cary Clarkbc5697d2017-10-04 14:31:33 -04002261srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clark154beea2017-10-26 07:58:48 -04002262false if width() or height() is zero or negative.
Cary Clark2be81cf2018-09-13 12:04:30 -04002263Returns false if #Formula # abs(srcX) >= Bitmap width() ##, or if #Formula # abs(srcY) >= Bitmap height() ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002264
2265#Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ##
2266#Param dstPixels destination pixel storage ##
2267#Param dstRowBytes destination row length ##
2268#Param srcX column index whose absolute value is less than width() ##
2269#Param srcY row index whose absolute value is less than height() ##
2270
2271#Return true if pixels are copied to dstPixels ##
2272
2273#Example
2274#Height 128
2275#Description
2276Transferring the gradient from 8 bits per component to 4 bits per component
2277creates visible banding.
2278##
Ben Wagner29380bd2017-10-09 14:43:00 -04002279 const int width = 256;
2280 const int height = 64;
2281 SkImageInfo srcInfo = SkImageInfo::MakeN32Premul(width, height);
2282 SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 };
2283 SkPoint gradPoints[] = { { 0, 0 }, { 256, 0 } };
2284 SkPaint paint;
2285 paint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
2286 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
2287 SkBitmap bitmap;
2288 bitmap.allocPixels(srcInfo);
2289 SkCanvas srcCanvas(bitmap);
2290 srcCanvas.drawRect(SkRect::MakeWH(width, height), paint);
2291 canvas->drawBitmap(bitmap, 0, 0);
2292 SkImageInfo dstInfo = srcInfo.makeColorType(kARGB_4444_SkColorType);
2293 std::vector<int16_t> dstPixels;
2294 dstPixels.resize(height * width);
2295 bitmap.readPixels(dstInfo, &dstPixels.front(), width * 2, 0, 0);
2296 SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2);
2297 bitmap.installPixels(dstPixmap);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002298 canvas->drawBitmap(bitmap, 0, 64);
2299##
2300
2301#SeeAlso writePixels SkPixmap::readPixels SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
2302
2303##
2304
2305# ------------------------------------------------------------------------------
2306
2307#Method bool readPixels(const SkPixmap& dst, int srcX, int srcY) const
2308
Cary Clarkac47b882018-01-11 10:35:44 -05002309Copies a Rect of pixels from Bitmap to dst. Copy starts at (srcX, srcY), and
Cary Clark682c58d2018-05-16 07:07:07 -04002310does not exceed Bitmap (width(), height()).
Cary Clarkbc5697d2017-10-04 14:31:33 -04002311
2312dst specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage,
Cary Clark77b3f3a2018-11-07 14:59:03 -05002313and row bytes of destination. dst.rowBytes() specifics the gap from one destination
Cary Clarkbc5697d2017-10-04 14:31:33 -04002314row to the next. Returns true if pixels are copied. Returns false if:
2315#List
2316# dst pixel storage equals nullptr ##
Cary Clark77b3f3a2018-11-07 14:59:03 -05002317# dst.rowBytes() is less than SkImageInfo::minRowBytes() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002318# Pixel_Ref is nullptr ##
2319##
2320
Cary Clarkac47b882018-01-11 10:35:44 -05002321Pixels are copied only if pixel conversion is possible. If Bitmap colorType is
Cary Clarkbc5697d2017-10-04 14:31:33 -04002322kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match.
Cary Clarkac47b882018-01-11 10:35:44 -05002323If Bitmap colorType is kGray_8_SkColorType, dst Color_Space must match.
2324If Bitmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must
2325match. If Bitmap colorSpace is nullptr, dst Color_Space must match. Returns
Cary Clarkbc5697d2017-10-04 14:31:33 -04002326false if pixel conversion is not possible.
Cary Clark682c58d2018-05-16 07:07:07 -04002327
Cary Clarkbc5697d2017-10-04 14:31:33 -04002328srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clark682c58d2018-05-16 07:07:07 -04002329false if width() or height() is zero or negative.
Cary Clark2be81cf2018-09-13 12:04:30 -04002330Returns false if #Formula # abs(srcX) >= Bitmap width() ##, or if #Formula # abs(srcY) >= Bitmap height() ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002331
2332#Param dst destination Pixmap: Image_Info, pixels, row bytes ##
2333#Param srcX column index whose absolute value is less than width() ##
2334#Param srcY row index whose absolute value is less than height() ##
2335
2336#Return true if pixels are copied to dst ##
2337
2338#Example
2339#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04002340 std::vector<int32_t> srcPixels;
2341 srcPixels.resize(source.height() * source.rowBytes());
2342 for (int y = 0; y < 4; ++y) {
2343 for (int x = 0; x < 4; ++x) {
2344 SkPixmap pixmap(SkImageInfo::MakeN32Premul(source.width() / 4, source.height() / 4),
2345 &srcPixels.front() + x * source.height() * source.width() / 4 +
2346 y * source.width() / 4, source.rowBytes());
2347 source.readPixels(pixmap, x * source.width() / 4, y * source.height() / 4);
2348 }
2349 }
2350 canvas->scale(.5f, .5f);
2351 SkBitmap bitmap;
2352 bitmap.installPixels(SkImageInfo::MakeN32Premul(source.width(), source.height()),
2353 &srcPixels.front(), source.rowBytes());
Cary Clarkbc5697d2017-10-04 14:31:33 -04002354 canvas->drawBitmap(bitmap, 0, 0);
2355##
2356
2357#SeeAlso writePixels SkPixmap::readPixels SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
2358
2359##
2360
2361# ------------------------------------------------------------------------------
2362
2363#Method bool readPixels(const SkPixmap& dst) const
2364
Cary Clarkac47b882018-01-11 10:35:44 -05002365Copies a Rect of pixels from Bitmap to dst. Copy starts at (0, 0), and
Cary Clark682c58d2018-05-16 07:07:07 -04002366does not exceed Bitmap (width(), height()).
Cary Clarkbc5697d2017-10-04 14:31:33 -04002367
2368dst specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage,
Cary Clark77b3f3a2018-11-07 14:59:03 -05002369and row bytes of destination. dst.rowBytes() specifics the gap from one destination
Cary Clarkbc5697d2017-10-04 14:31:33 -04002370row to the next. Returns true if pixels are copied. Returns false if:
2371#List
2372# dst pixel storage equals nullptr ##
Cary Clark77b3f3a2018-11-07 14:59:03 -05002373# dst.rowBytes() is less than SkImageInfo::minRowBytes() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002374# Pixel_Ref is nullptr ##
2375##
2376
Cary Clarkac47b882018-01-11 10:35:44 -05002377Pixels are copied only if pixel conversion is possible. If Bitmap colorType is
Cary Clarkbc5697d2017-10-04 14:31:33 -04002378kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match.
Cary Clarkac47b882018-01-11 10:35:44 -05002379If Bitmap colorType is kGray_8_SkColorType, dst Color_Space must match.
2380If Bitmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must
2381match. If Bitmap colorSpace is nullptr, dst Color_Space must match. Returns
Cary Clarkbc5697d2017-10-04 14:31:33 -04002382false if pixel conversion is not possible.
Cary Clark682c58d2018-05-16 07:07:07 -04002383
Cary Clarkbc5697d2017-10-04 14:31:33 -04002384#Param dst destination Pixmap: Image_Info, pixels, row bytes ##
2385
2386#Return true if pixels are copied to dst ##
2387
2388#Example
2389#Height 128
2390#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04002391 std::vector<int32_t> srcPixels;
2392 srcPixels.resize(source.height() * source.width() * 8);
2393 for (int i = 0; i < 2; ++i) {
Cary Clark682c58d2018-05-16 07:07:07 -04002394 SkPixmap pixmap(SkImageInfo::Make(source.width() * 2, source.height(),
Ben Wagner29380bd2017-10-09 14:43:00 -04002395 i ? kRGBA_8888_SkColorType : kBGRA_8888_SkColorType, kPremul_SkAlphaType),
2396 &srcPixels.front() + i * source.width(), source.rowBytes() * 2);
2397 source.readPixels(pixmap);
2398 }
2399 canvas->scale(.25f, .25f);
2400 SkBitmap bitmap;
2401 bitmap.installPixels(SkImageInfo::MakeN32Premul(source.width() * 2, source.height()),
2402 &srcPixels.front(), source.rowBytes() * 2);
2403 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002404##
2405
2406#SeeAlso writePixels SkPixmap::readPixels SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
2407
2408##
2409
2410# ------------------------------------------------------------------------------
2411
2412#Method bool writePixels(const SkPixmap& src, int dstX, int dstY)
Cary Clark78de7512018-02-07 07:27:09 -05002413#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05002414#Line # copies and converts pixels ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002415Copies a Rect of pixels from src. Copy starts at (dstX, dstY), and does not exceed
Cary Clark682c58d2018-05-16 07:07:07 -04002416(src.width(), src.height()).
Cary Clarkbc5697d2017-10-04 14:31:33 -04002417
2418src specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage,
Cary Clark77b3f3a2018-11-07 14:59:03 -05002419and row bytes of source. src.rowBytes() specifics the gap from one source
Cary Clarkbc5697d2017-10-04 14:31:33 -04002420row to the next. Returns true if pixels are copied. Returns false if:
2421#List
2422# src pixel storage equals nullptr ##
Cary Clark77b3f3a2018-11-07 14:59:03 -05002423# src.rowBytes() is less than SkImageInfo::minRowBytes() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002424# Pixel_Ref is nullptr ##
2425##
2426
Cary Clarkac47b882018-01-11 10:35:44 -05002427Pixels are copied only if pixel conversion is possible. If Bitmap colorType is
Cary Clarkbc5697d2017-10-04 14:31:33 -04002428kGray_8_SkColorType, or kAlpha_8_SkColorType; src Color_Type must match.
Cary Clarkac47b882018-01-11 10:35:44 -05002429If Bitmap colorType is kGray_8_SkColorType, src Color_Space must match.
2430If Bitmap alphaType is kOpaque_SkAlphaType, src Alpha_Type must
2431match. If Bitmap colorSpace is nullptr, src Color_Space must match. Returns
Cary Clarkbc5697d2017-10-04 14:31:33 -04002432false if pixel conversion is not possible.
Cary Clark682c58d2018-05-16 07:07:07 -04002433
Cary Clarkbc5697d2017-10-04 14:31:33 -04002434dstX and dstY may be negative to copy only top or left of source. Returns
Cary Clark154beea2017-10-26 07:58:48 -04002435false if width() or height() is zero or negative.
Cary Clark2be81cf2018-09-13 12:04:30 -04002436Returns false if #Formula # abs(dstX) >= Bitmap width() ##, or if #Formula # abs(dstY) >= Bitmap height() ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002437
2438#Param src source Pixmap: Image_Info, pixels, row bytes ##
2439#Param dstX column index whose absolute value is less than width() ##
2440#Param dstY row index whose absolute value is less than height() ##
2441
2442#Return true if src pixels are copied to Bitmap ##
2443
2444#Example
2445#Image 3
Ben Wagner29380bd2017-10-09 14:43:00 -04002446 std::vector<int32_t> srcPixels;
2447 int width = image->width();
2448 int height = image->height();
2449 srcPixels.resize(height * width * 4);
2450 SkPixmap pixmap(SkImageInfo::MakeN32Premul(width, height), (const void*) &srcPixels.front(),
2451 width * 4);
2452 image->readPixels(pixmap, 0, 0);
2453 canvas->scale(.5f, .5f);
2454 width /= 4;
2455 height /= 4;
2456 for (int y = 0; y < 4; ++y) {
2457 for (int x = 0; x < 4; ++x) {
2458 SkBitmap bitmap;
2459 bitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height));
2460 bitmap.writePixels(pixmap, -y * width, -x * height);
2461 canvas->drawBitmap(bitmap, x * width, y * height);
2462 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04002463 }
2464##
2465
Cary Clark682c58d2018-05-16 07:07:07 -04002466#SeeAlso readPixels
Cary Clarkbc5697d2017-10-04 14:31:33 -04002467
2468##
2469
2470# ------------------------------------------------------------------------------
2471
2472#Method bool writePixels(const SkPixmap& src)
2473
2474Copies a Rect of pixels from src. Copy starts at (0, 0), and does not exceed
Cary Clark682c58d2018-05-16 07:07:07 -04002475(src.width(), src.height()).
Cary Clarkbc5697d2017-10-04 14:31:33 -04002476
2477src specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage,
Cary Clark77b3f3a2018-11-07 14:59:03 -05002478and row bytes of source. src.rowBytes() specifics the gap from one source
Cary Clarkbc5697d2017-10-04 14:31:33 -04002479row to the next. Returns true if pixels are copied. Returns false if:
2480#List
2481# src pixel storage equals nullptr ##
Cary Clark77b3f3a2018-11-07 14:59:03 -05002482# src.rowBytes() is less than SkImageInfo::minRowBytes() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002483# Pixel_Ref is nullptr ##
2484##
2485
Cary Clarkac47b882018-01-11 10:35:44 -05002486Pixels are copied only if pixel conversion is possible. If Bitmap colorType is
Cary Clarkbc5697d2017-10-04 14:31:33 -04002487kGray_8_SkColorType, or kAlpha_8_SkColorType; src Color_Type must match.
Cary Clarkac47b882018-01-11 10:35:44 -05002488If Bitmap colorType is kGray_8_SkColorType, src Color_Space must match.
2489If Bitmap alphaType is kOpaque_SkAlphaType, src Alpha_Type must
2490match. If Bitmap colorSpace is nullptr, src Color_Space must match. Returns
Cary Clarkbc5697d2017-10-04 14:31:33 -04002491false if pixel conversion is not possible.
2492
2493#Param src source Pixmap: Image_Info, pixels, row bytes ##
2494
2495#Return true if src pixels are copied to Bitmap ##
2496
2497#Example
2498#Height 80
Ben Wagner29380bd2017-10-09 14:43:00 -04002499 SkBitmap bitmap;
2500 bitmap.allocPixels(SkImageInfo::MakeN32Premul(2, 2));
2501 bitmap.eraseColor(SK_ColorGREEN);
2502 SkPMColor color = 0xFF5599BB;
2503 SkPixmap src(SkImageInfo::MakeN32Premul(1, 1), &color, 4);
2504 bitmap.writePixels(src);
2505 canvas->scale(40, 40);
2506 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002507##
2508
2509#SeeAlso readPixels
2510
2511##
2512
2513# ------------------------------------------------------------------------------
2514
Cary Clarkbc5697d2017-10-04 14:31:33 -04002515#Method bool extractAlpha(SkBitmap* dst) const
Cary Clark61313f32018-10-08 14:57:48 -04002516#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05002517#Line # creates Bitmap containing Alpha of pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -04002518#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04002519
2520#Example
2521#Height 100
Ben Wagner29380bd2017-10-09 14:43:00 -04002522 SkBitmap alpha, bitmap;
2523 bitmap.allocN32Pixels(100, 100);
2524 SkCanvas offscreen(bitmap);
2525 offscreen.clear(0);
2526 SkPaint paint;
2527 paint.setAntiAlias(true);
2528 paint.setColor(SK_ColorBLUE);
2529 paint.setStyle(SkPaint::kStroke_Style);
2530 paint.setStrokeWidth(20);
2531 offscreen.drawCircle(50, 50, 39, paint);
2532 offscreen.flush();
2533 bitmap.extractAlpha(&alpha);
2534 paint.setColor(SK_ColorRED);
2535 canvas->drawBitmap(bitmap, 0, 0, &paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002536 canvas->drawBitmap(alpha, 100, 0, &paint);
2537##
2538
2539#SeeAlso extractSubset
2540
2541##
2542
2543# ------------------------------------------------------------------------------
2544
2545#Method bool extractAlpha(SkBitmap* dst, const SkPaint* paint,
2546 SkIPoint* offset) const
Cary Clark09d80c02018-10-31 12:14:03 -04002547#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04002548
Cary Clarkbc5697d2017-10-04 14:31:33 -04002549#Example
2550#Height 160
Cary Clark681287e2018-03-16 11:34:15 -04002551 auto radiusToSigma = [](SkScalar radius) -> SkScalar {
2552 static const SkScalar kBLUR_SIGMA_SCALE = 0.57735f;
2553 return radius > 0 ? kBLUR_SIGMA_SCALE * radius + 0.5f : 0.0f;
2554 };
2555 SkBitmap alpha, bitmap;
2556 bitmap.allocN32Pixels(100, 100);
2557 SkCanvas offscreen(bitmap);
2558 offscreen.clear(0);
2559 SkPaint paint;
2560 paint.setAntiAlias(true);
2561 paint.setColor(SK_ColorBLUE);
2562 paint.setStyle(SkPaint::kStroke_Style);
2563 paint.setStrokeWidth(20);
2564 offscreen.drawCircle(50, 50, 39, paint);
2565 offscreen.flush();
2566 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, radiusToSigma(25)));
2567 SkIPoint offset;
2568 bitmap.extractAlpha(&alpha, &paint, &offset);
2569 paint.setColor(SK_ColorRED);
2570 canvas->drawBitmap(bitmap, 0, -offset.fY, &paint);
2571 canvas->drawBitmap(alpha, 100 + offset.fX, 0, &paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002572##
2573
2574#SeeAlso extractSubset
2575
2576##
2577
2578# ------------------------------------------------------------------------------
2579
2580#Method bool extractAlpha(SkBitmap* dst, const SkPaint* paint, Allocator* allocator,
2581 SkIPoint* offset) const
Cary Clark09d80c02018-10-31 12:14:03 -04002582#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04002583
Cary Clarkbc5697d2017-10-04 14:31:33 -04002584#Example
2585#Height 128
Ben Wagner29380bd2017-10-09 14:43:00 -04002586 SkBitmap alpha, bitmap;
2587 bitmap.allocN32Pixels(100, 100);
2588 SkCanvas offscreen(bitmap);
2589 offscreen.clear(0);
2590 SkPaint paint;
2591 paint.setAntiAlias(true);
2592 paint.setColor(SK_ColorBLUE);
2593 paint.setStyle(SkPaint::kStroke_Style);
2594 paint.setStrokeWidth(20);
2595 offscreen.drawCircle(50, 50, 39, paint);
2596 offscreen.flush();
Cary Clark681287e2018-03-16 11:34:15 -04002597 paint.setMaskFilter(SkMaskFilter::MakeBlur(kOuter_SkBlurStyle, 3));
Ben Wagner29380bd2017-10-09 14:43:00 -04002598 SkIPoint offset;
2599 bitmap.extractAlpha(&alpha, &paint, nullptr, &offset);
2600 paint.setColor(SK_ColorRED);
2601 canvas->drawBitmap(bitmap, 0, -offset.fY, &paint);
2602 canvas->drawBitmap(alpha, 100 + offset.fX, 0, &paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002603##
2604
2605#SeeAlso extractSubset
2606
2607##
2608
2609# ------------------------------------------------------------------------------
2610
2611#Method bool peekPixels(SkPixmap* pixmap) const
Cary Clark78de7512018-02-07 07:27:09 -05002612#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05002613#Line # returns Pixmap if possible ##
Cary Clark09d80c02018-10-31 12:14:03 -04002614#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04002615
2616#Example
Ben Wagner29380bd2017-10-09 14:43:00 -04002617 SkBitmap bitmap;
2618 bitmap.allocPixels(SkImageInfo::MakeN32Premul(6, 11));
2619 SkCanvas offscreen(bitmap);
2620 offscreen.clear(SK_ColorWHITE);
2621 SkPaint paint;
2622 offscreen.drawString("?", 0, 10, paint);
2623 SkPixmap pixmap;
2624 if (bitmap.peekPixels(&pixmap)) {
2625 const SkPMColor* pixels = pixmap.addr32();
2626 SkPMColor pmWhite = pixels[0];
2627 for (int y = 0; y < bitmap.height(); ++y) {
2628 for (int x = 0; x < bitmap.width(); ++x) {
2629 SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x');
2630 }
2631 SkDebugf("\n");
2632 }
2633 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04002634 #StdOut
Cary Clark2f466242017-12-11 16:03:17 -05002635------
2636-xxx--
2637x---x-
2638----x-
2639---x--
2640--x---
2641--x---
2642------
2643--x---
2644--x---
Cary Clarka560c472017-11-27 10:44:06 -05002645------
Cary Clarkbc5697d2017-10-04 14:31:33 -04002646 #StdOut ##
2647##
2648
Cary Clarka90ea222018-10-16 10:30:28 -04002649#SeeAlso pixmap installPixels readPixels writePixels
Cary Clarkbc5697d2017-10-04 14:31:33 -04002650
2651##
2652
2653# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05002654#Subtopic Utility
Cary Clark78de7512018-02-07 07:27:09 -05002655#Line # rarely called management functions ##
2656##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002657
Cary Clark154beea2017-10-26 07:58:48 -04002658#Method void validate() const;
Cary Clark78de7512018-02-07 07:27:09 -05002659#In Utility
Cary Clarkab2621d2018-01-30 10:08:57 -05002660#Line # asserts if Bitmap is invalid (debug only) ##
Cary Clark09d80c02018-10-31 12:14:03 -04002661#Populate
Cary Clark154beea2017-10-26 07:58:48 -04002662
2663#NoExample
2664##
2665
Cary Clark06c20f32018-03-20 15:53:27 -04002666#SeeAlso SkImageInfo::validate
Cary Clark154beea2017-10-26 07:58:48 -04002667
2668##
2669
2670# ------------------------------------------------------------------------------
2671
Cary Clarkbc5697d2017-10-04 14:31:33 -04002672#Class SkBitmap ##
2673
2674#Topic Bitmap ##