blob: 9c36642024bc975600e30211b2581007a5f9cb4c [file] [log] [blame]
Cary Clarkd0530ba2017-09-14 11:25:39 -04001#Topic Pixmap
Cary Clark137b8742018-05-30 09:21:49 -04002#Alias Pixmap_Reference ##
Cary Clarke4aa3712017-09-15 02:56:12 -04003
Cary Clarkd0530ba2017-09-14 11:25:39 -04004#Class SkPixmap
5
Cary Clark61313f32018-10-08 14:57:48 -04006#Code
7#Populate
8##
9
Cary Clark682c58d2018-05-16 07:07:07 -040010Pixmap provides a utility to pair SkImageInfo with pixels and row bytes.
Cary Clarkd0530ba2017-09-14 11:25:39 -040011Pixmap is a low level class which provides convenience functions to access
12raster destinations. Canvas can not draw Pixmap, nor does Pixmap provide
13a direct drawing destination.
14
15Use Bitmap to draw pixels referenced by Pixmap; use Surface to draw into
16pixels referenced by Pixmap.
17
Cary Clarkbc5697d2017-10-04 14:31:33 -040018Pixmap does not try to manage the lifetime of the pixel memory. Use Pixel_Ref
19to manage pixel memory; Pixel_Ref is safe across threads.
Cary Clarkd0530ba2017-09-14 11:25:39 -040020
Cary Clarkd0530ba2017-09-14 11:25:39 -040021
22#Subtopic Initialization
Cary Clark08895c42018-02-01 09:37:32 -050023#Line # sets fields for use ##
Cary Clarkd0530ba2017-09-14 11:25:39 -040024
25# ------------------------------------------------------------------------------
26
27#Method SkPixmap()
28
Cary Clarkab2621d2018-01-30 10:08:57 -050029#In Initialization
30#Line # constructs with default values ##
Cary Clarkd0530ba2017-09-14 11:25:39 -040031Creates an empty Pixmap without pixels, with kUnknown_SkColorType, with
32kUnknown_SkAlphaType, and with a width and height of zero. Use
33reset() to associate pixels, SkColorType, SkAlphaType, width, and height
34after Pixmap has been created.
35
36#Return empty Pixmap ##
37
38#Example
Cary Clark6fc50412017-09-21 12:31:06 -040039void draw(SkCanvas* canvas) {
40 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
Cary Clarkab2621d2018-01-30 10:08:57 -050041 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
42 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -040043 SkPixmap pixmap;
44 for (int i = 0; i < 2; ++i) {
45 SkDebugf("width: %2d height: %2d", pixmap.width(), pixmap.height());
46 SkDebugf(" color: k%s_SkColorType", colors[pixmap.colorType()]);
47 SkDebugf(" alpha: k%s_SkAlphaType\n", alphas[pixmap.alphaType()]);
48 pixmap.reset(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType),
49 nullptr, 0);
50 }
Cary Clarkd0530ba2017-09-14 11:25:39 -040051}
52#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -040053width: 0 height: 0 color: kUnknown_SkColorType alpha: kUnknown_SkAlphaType
Cary Clarkd0530ba2017-09-14 11:25:39 -040054width: 25 height: 35 color: kRGBA_8888_SkColorType alpha: kOpaque_SkAlphaType
55##
56##
57
58#SeeAlso SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) reset() SkAlphaType SkColorType
59
60##
61
62# ------------------------------------------------------------------------------
63
64#Method SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes)
Cary Clark682c58d2018-05-16 07:07:07 -040065
Cary Clarkab2621d2018-01-30 10:08:57 -050066#In Initialization
67#Line # constructs from Image_Info, pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -040068Creates Pixmap from info width, height, SkAlphaType, and SkColorType.
Cary Clark6fc50412017-09-21 12:31:06 -040069addr points to pixels, or nullptr. rowBytes should be info.width() times
70info.bytesPerPixel(), or larger.
Cary Clarkd0530ba2017-09-14 11:25:39 -040071
72No parameter checking is performed; it is up to the caller to ensure that
Cary Clark682c58d2018-05-16 07:07:07 -040073addr and rowBytes agree with info.
Cary Clarkd0530ba2017-09-14 11:25:39 -040074
Cary Clark6fc50412017-09-21 12:31:06 -040075The memory lifetime of pixels is managed by the caller. When Pixmap goes
Cary Clarkd0530ba2017-09-14 11:25:39 -040076out of scope, addr is unaffected.
77
78Pixmap may be later modified by reset() to change its size, pixel type, or
79storage.
80
81#Param info width, height, SkAlphaType, SkColorType of Image_Info ##
82#Param addr pointer to pixels allocated by caller; may be nullptr ##
83#Param rowBytes size of one row of addr; width times pixel size, or larger ##
84
85#Return initialized Pixmap ##
86
87#Example
88#Image 3
89#Description
Cary Clark682c58d2018-05-16 07:07:07 -040090SkImage::MakeRasterCopy takes const SkPixmap& as an argument. The example
Cary Clarkd0530ba2017-09-14 11:25:39 -040091constructs a SkPixmap from the brace-delimited parameters.
92##
Cary Clark6fc50412017-09-21 12:31:06 -040093 SkDebugf("image alpha only = %s\n", image->isAlphaOnly() ? "true" : "false");
94 SkPMColor pmColors = 0;
95 sk_sp<SkImage> copy = SkImage::MakeRasterCopy({SkImageInfo::MakeA8(1, 1),
96 (uint8_t*)&pmColors,
97 1});
Cary Clarkd0530ba2017-09-14 11:25:39 -040098 SkDebugf("copy alpha only = %s\n", copy->isAlphaOnly() ? "true" : "false");
99#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400100image alpha only = false
Cary Clarkd0530ba2017-09-14 11:25:39 -0400101copy alpha only = true
102##
103##
104
105#SeeAlso SkPixmap() reset() SkAlphaType SkColorType
106
107##
108
109# ------------------------------------------------------------------------------
110
111#Method void reset()
112
Cary Clarkab2621d2018-01-30 10:08:57 -0500113#In Initialization
114#Line # reuses existing Pixmap with replacement values ##
Cary Clark682c58d2018-05-16 07:07:07 -0400115Sets width, height, row bytes to zero; pixel address to nullptr; SkColorType to
Cary Clarkd0530ba2017-09-14 11:25:39 -0400116kUnknown_SkColorType; and SkAlphaType to kUnknown_SkAlphaType.
117
118The prior pixels are unaffected; it is up to the caller to release pixels
119memory if desired.
120
121#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400122void draw(SkCanvas* canvas) {
123 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
Cary Clarkab2621d2018-01-30 10:08:57 -0500124 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
125 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -0400126 SkPixmap pixmap(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType),
127 nullptr, 0);
128 for (int i = 0; i < 2; ++i) {
129 SkDebugf("width: %2d height: %2d", pixmap.width(), pixmap.height());
130 SkDebugf(" color: k%s_SkColorType", colors[pixmap.colorType()]);
131 SkDebugf(" alpha: k%s_SkAlphaType\n", alphas[pixmap.alphaType()]);
132 pixmap.reset();
133 }
134}
Cary Clarkd0530ba2017-09-14 11:25:39 -0400135#StdOut
136width: 25 height: 35 color: kRGBA_8888_SkColorType alpha: kOpaque_SkAlphaType
Cary Clark6fc50412017-09-21 12:31:06 -0400137width: 0 height: 0 color: kUnknown_SkColorType alpha: kUnknown_SkAlphaType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400138##
139##
140
141#SeeAlso SkPixmap() SkAlphaType SkColorType
142
143##
144
145# ------------------------------------------------------------------------------
146
147#Method void reset(const SkImageInfo& info, const void* addr, size_t rowBytes)
148
Cary Clarkab2621d2018-01-30 10:08:57 -0500149#In Initialization
Cary Clarkd0530ba2017-09-14 11:25:39 -0400150Sets width, height, SkAlphaType, and SkColorType from info.
Cary Clark682c58d2018-05-16 07:07:07 -0400151Sets pixel address from addr, which may be nullptr.
Cary Clark6fc50412017-09-21 12:31:06 -0400152Sets row bytes from rowBytes, which should be info.width() times
153info.bytesPerPixel(), or larger.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400154
155Does not check addr. Asserts if built with SK_DEBUG defined and if rowBytes is
Cary Clark682c58d2018-05-16 07:07:07 -0400156too small to hold one row of pixels.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400157
158The memory lifetime pixels are managed by the caller. When Pixmap goes
159out of scope, addr is unaffected.
160
161#Param info width, height, SkAlphaType, SkColorType of Image_Info ##
162#Param addr pointer to pixels allocated by caller; may be nullptr ##
163#Param rowBytes size of one row of addr; width times pixel size, or larger ##
164
165#Example
166#Image 4
Cary Clark2ade9972017-11-02 17:49:34 -0400167#Height 64
Cary Clark6fc50412017-09-21 12:31:06 -0400168void draw(SkCanvas* canvas) {
169 std::vector<int32_t> pixels;
170 pixels.resize(image->height() * image->width() * 4);
171 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
172 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
173 image->readPixels(pixmap, 0, 0);
174 int x = 0;
175 for (auto colorType : { kRGBA_8888_SkColorType, kBGRA_8888_SkColorType } ) {
Cary Clark682c58d2018-05-16 07:07:07 -0400176 pixmap.reset(SkImageInfo::Make(image->width(), image->height(), colorType,
Cary Clark6fc50412017-09-21 12:31:06 -0400177 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
178 SkBitmap bitmap;
179 bitmap.installPixels(pixmap);
180 canvas->drawBitmap(bitmap, x, 0);
181 x += 128;
182 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400183}
184##
185
186#SeeAlso SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) reset() SkAlphaType SkColorType
187
188##
189
190# ------------------------------------------------------------------------------
191
192#Method void setColorSpace(sk_sp<SkColorSpace> colorSpace)
193
Cary Clarkab2621d2018-01-30 10:08:57 -0500194#In Initialization
195#Line # sets Image_Info Color_Space ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400196
197Changes Color_Space in Image_Info; preserves width, height, SkAlphaType, and
198SkColorType in Image, and leaves pixel address and row bytes unchanged.
Cary Clark6fc50412017-09-21 12:31:06 -0400199Color_Space reference count is incremented.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400200
201#Param colorSpace Color_Space moved to Image_Info ##
202
203#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400204void draw(SkCanvas* canvas) {
205 SkPixmap pixmap;
206 sk_sp<SkColorSpace> colorSpace1 = SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma,
207 SkColorSpace::kRec2020_Gamut);
Cary Clark682c58d2018-05-16 07:07:07 -0400208 SkDebugf("is %sunique\n", colorSpace1->unique() ? "" : "not ");
Cary Clark6fc50412017-09-21 12:31:06 -0400209 pixmap.setColorSpace(colorSpace1);
Cary Clark682c58d2018-05-16 07:07:07 -0400210 SkDebugf("is %sunique\n", colorSpace1->unique() ? "" : "not ");
Cary Clarkd0530ba2017-09-14 11:25:39 -0400211}
212#StdOut
213is unique
214is not unique
215##
216##
217
218#SeeAlso Color_Space SkImageInfo::makeColorSpace
219
220##
221
222# ------------------------------------------------------------------------------
223
Cary Clark61313f32018-10-08 14:57:48 -0400224#Method bool reset(const SkMask& mask)
Cary Clark4855f782018-02-06 09:41:53 -0500225#Deprecated soon
Cary Clarkd0530ba2017-09-14 11:25:39 -0400226##
227
228# ------------------------------------------------------------------------------
229
Cary Clark61313f32018-10-08 14:57:48 -0400230#Method bool extractSubset(SkPixmap* subset, const SkIRect& area) const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400231
Cary Clarkab2621d2018-01-30 10:08:57 -0500232#In Initialization
233#Line # sets pointer to portion of original ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400234Sets subset width, height, pixel address to intersection of Pixmap with area,
235if intersection is not empty; and return true. Otherwise, leave subset unchanged
Cary Clark682c58d2018-05-16 07:07:07 -0400236and return false.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400237
238Failing to read the return value generates a compile time warning.
239
240#Param subset storage for width, height, pixel address of intersection ##
241#Param area bounds to intersect with Pixmap ##
242
243#Return true if intersection of Pixmap and area is not empty ##
244
245#Example
246#Image 3
247#Height 128
Cary Clark6fc50412017-09-21 12:31:06 -0400248void draw(SkCanvas* canvas) {
249 std::vector<int32_t> pixels;
250 pixels.resize(image->height() * image->width() * 4);
251 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
252 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
253 image->readPixels(pixmap, 0, 0);
254 SkPixmap inset;
255 if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
256 SkBitmap bitmap;
257 bitmap.installPixels(inset);
258 canvas->drawBitmap(bitmap, 0, 0);
259 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400260}
261##
262
263#SeeAlso reset() SkIRect::intersect
264
265##
266
267#Subtopic Initialization ##
268
269#Subtopic Image_Info_Access
Cary Clark08895c42018-02-01 09:37:32 -0500270#Line # returns all or part of Image_Info ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400271
272# ------------------------------------------------------------------------------
273
Cary Clark682c58d2018-05-16 07:07:07 -0400274#Method const SkImageInfo& info() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400275
Cary Clarkab2621d2018-01-30 10:08:57 -0500276#In Image_Info_Access
277#Line # returns Image_Info ##
Cary Clark6fc50412017-09-21 12:31:06 -0400278Returns width, height, Alpha_Type, Color_Type, and Color_Space.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400279
280#Return reference to ImageInfo ##
281
282#Example
283#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -0400284 std::vector<int32_t> pixels;
285 pixels.resize(image->height() * image->width() * 4);
286 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
287 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
288 image->readPixels(pixmap, 0, 0);
289 SkPixmap inset;
290 if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
291 const SkImageInfo& info = inset.info();
292 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
Cary Clarkab2621d2018-01-30 10:08:57 -0500293 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888",
294 "RGB_888x", "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -0400295 SkDebugf("width: %d height: %d color: %s alpha: %s\n", info.width(), info.height(),
296 colors[info.colorType()], alphas[info.alphaType()]);
297 }
298#StdOut
299width: 384 height: 384 color: BGRA_8888 alpha: Opaque
300##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400301##
302
303#SeeAlso Image_Info
304
305##
306
307# ------------------------------------------------------------------------------
308
Cary Clark682c58d2018-05-16 07:07:07 -0400309#Method size_t rowBytes() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400310
Cary Clarkab2621d2018-01-30 10:08:57 -0500311#In Image_Info_Access
312#Line # returns interval between rows in bytes ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400313Returns row bytes, the interval from one pixel row to the next. Row bytes
Cary Clark2be81cf2018-09-13 12:04:30 -0400314is at least as large as: #Formula # width() * info().bytesPerPixel() ##.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400315
Cary Clarkbc5697d2017-10-04 14:31:33 -0400316Returns zero if colorType is kUnknown_SkColorType.
317It is up to the Bitmap creator to ensure that row bytes is a useful value.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400318
319#Return byte length of pixel row ##
320
321#Example
322SkPixmap badPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 2};
323SkPixmap okPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 8};
324for (auto& pixmap : { badPixmap, okPixmap } ) {
Cary Clark682c58d2018-05-16 07:07:07 -0400325 SkDebugf("rowBytes: %d minRowBytes: %d\n", pixmap.rowBytes(),
Cary Clarkd0530ba2017-09-14 11:25:39 -0400326 pixmap.info().minRowBytes());
327}
328#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400329rowBytes: 2 minRowBytes: 4
Cary Clarkd0530ba2017-09-14 11:25:39 -0400330rowBytes: 8 minRowBytes: 4
331##
332##
333
334#SeeAlso addr() info() SkImageInfo::minRowBytes
335
336##
337
338# ------------------------------------------------------------------------------
339
Cary Clark682c58d2018-05-16 07:07:07 -0400340#Method const void* addr() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400341
Cary Clarkab2621d2018-01-30 10:08:57 -0500342#In Image_Info_Access
343#Line # returns readable pixel address as void pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -0400344Returns pixel address, the base address corresponding to the pixel origin.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400345
346It is up to the Pixmap creator to ensure that pixel address is a useful value.
347
348#Return pixel address ##
349
350#Example
351#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -0400352 std::vector<int32_t> pixels;
353 pixels.resize(image->height() * image->width() * 4);
354 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
355 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
356 image->readPixels(pixmap, 0, 0);
357 SkDebugf("pixels address: 0x%llx\n", pixmap.addr());
358 SkPixmap inset;
359 if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
360 SkDebugf("inset address: 0x%llx\n", inset.addr());
361 }
362#StdOut
363#Volatile
364pixels address: 0x7f2a440bb010
365inset address: 0x7f2a440fb210
366##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400367##
368
369#SeeAlso addr(int x, int y) addr8 addr16 addr32 addr64 info() rowBytes()
370
371##
372
373# ------------------------------------------------------------------------------
374
Cary Clark682c58d2018-05-16 07:07:07 -0400375#Method int width() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400376
Cary Clarkab2621d2018-01-30 10:08:57 -0500377#In Image_Info_Access
378#Line # returns pixel column count ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400379Returns pixel count in each pixel row. Should be equal or less than:
Cary Clark154beea2017-10-26 07:58:48 -0400380
Cary Clark2be81cf2018-09-13 12:04:30 -0400381#Formula # rowBytes() / info().bytesPerPixel() ##.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400382
383#Return pixel width in Image_Info ##
384
385#Example
386 SkImageInfo info = SkImageInfo::MakeA8(16, 32);
Cary Clark6fc50412017-09-21 12:31:06 -0400387 SkPixmap pixmap(info, nullptr, 64);
388 SkDebugf("pixmap width: %d info width: %d\n", pixmap.width(), info.width());
389#StdOut
390pixmap width: 16 info width: 16
391##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400392##
393
Cary Clarkbc5697d2017-10-04 14:31:33 -0400394#SeeAlso height() SkImageInfo::width()
Cary Clarkd0530ba2017-09-14 11:25:39 -0400395
396##
397
398# ------------------------------------------------------------------------------
399
Cary Clark682c58d2018-05-16 07:07:07 -0400400#Method int height() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400401
Cary Clarkab2621d2018-01-30 10:08:57 -0500402#In Image_Info_Access
403#Line # returns pixel row count ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400404Returns pixel row count.
405
406#Return pixel height in Image_Info ##
407
408#Example
Cary Clarkbc5697d2017-10-04 14:31:33 -0400409 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
410 SkDebugf("pixmap height: %d info height: %d\n", pixmap.height(), pixmap.info().height());
Cary Clark6fc50412017-09-21 12:31:06 -0400411#StdOut
412pixmap height: 32 info height: 32
413##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400414##
415
Cary Clarkbc5697d2017-10-04 14:31:33 -0400416#SeeAlso width() ImageInfo::height()
Cary Clarkd0530ba2017-09-14 11:25:39 -0400417
418##
419
420# ------------------------------------------------------------------------------
421
Cary Clark682c58d2018-05-16 07:07:07 -0400422#Method SkColorType colorType() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400423
Cary Clarkab2621d2018-01-30 10:08:57 -0500424#In Image_Info_Access
425#Line # returns Image_Info Color_Type ##
Cary Clark1a8d7622018-03-05 13:26:16 -0500426Returns Color_Type, one of: #list_of_color_types#.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400427
428#Return Color_Type in Image_Info ##
429
430#Example
Cary Clarkab2621d2018-01-30 10:08:57 -0500431 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
432 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -0400433 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
434 SkDebugf("color type: k" "%s" "_SkColorType\n", colors[pixmap.colorType()]);
435#StdOut
Cary Clarkab2621d2018-01-30 10:08:57 -0500436color type: kAlpha_8_SkColorType
Cary Clark6fc50412017-09-21 12:31:06 -0400437##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400438##
439
Cary Clarkbc5697d2017-10-04 14:31:33 -0400440#SeeAlso alphaType() SkImageInfo::colorType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400441
442##
443
444# ------------------------------------------------------------------------------
445
Cary Clark682c58d2018-05-16 07:07:07 -0400446#Method SkAlphaType alphaType() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400447
Cary Clarkab2621d2018-01-30 10:08:57 -0500448#In Image_Info_Access
449#Line # returns Image_Info Alpha_Type ##
Cary Clark681287e2018-03-16 11:34:15 -0400450Returns Alpha_Type, one of: #list_of_alpha_types#.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400451
452#Return Alpha_Type in Image_Info ##
453
454#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400455 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
456 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
457 SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[pixmap.alphaType()]);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400458#StdOut
459alpha type: kPremul_SkAlphaType
460##
461##
462
Cary Clarkbc5697d2017-10-04 14:31:33 -0400463#SeeAlso colorType() SkImageInfo::alphaType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400464
465##
466
467# ------------------------------------------------------------------------------
468
Cary Clark682c58d2018-05-16 07:07:07 -0400469#Method SkColorSpace* colorSpace() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400470
Cary Clarkab2621d2018-01-30 10:08:57 -0500471#In Image_Info_Access
472#Line # returns Image_Info Color_Space ##
Cary Clark681287e2018-03-16 11:34:15 -0400473Returns Color_Space, the range of colors, associated with Image_Info. The
Cary Clarkbc5697d2017-10-04 14:31:33 -0400474reference count of Color_Space is unchanged. The returned Color_Space is
475immutable.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400476
Cary Clark681287e2018-03-16 11:34:15 -0400477#Return Color_Space in Image_Info, or nullptr ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400478
479#Example
480#Description
481SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma
482and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma.
483##
Cary Clark682c58d2018-05-16 07:07:07 -0400484 SkPixmap pixmap(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
Cary Clark6fc50412017-09-21 12:31:06 -0400485 SkColorSpace::MakeSRGBLinear()), nullptr, 64);
486 SkColorSpace* colorSpace = pixmap.colorSpace();
487 SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
488 colorSpace->gammaCloseToSRGB() ? "true" : "false",
489 colorSpace->gammaIsLinear() ? "true" : "false",
490 colorSpace->isSRGB() ? "true" : "false");
491#StdOut
492gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
493##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400494##
495
Cary Clarkbc5697d2017-10-04 14:31:33 -0400496#SeeAlso Color_Space SkImageInfo::colorSpace
Cary Clarkd0530ba2017-09-14 11:25:39 -0400497
498##
499
500# ------------------------------------------------------------------------------
501
Cary Clark682c58d2018-05-16 07:07:07 -0400502#Method bool isOpaque() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400503
Cary Clarkab2621d2018-01-30 10:08:57 -0500504#In Image_Info_Access
505#Line # returns true if Image_Info describes opaque pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400506Returns true if Alpha_Type is kOpaque_SkAlphaType.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400507Does not check if Color_Type allows Alpha, or if any pixel value has
508transparency.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400509
510#Return true if Image_Info has opaque Alpha_Type ##
511
512#Example
513#Description
514 isOpaque ignores whether all pixels are opaque or not.
515##
Cary Clark6fc50412017-09-21 12:31:06 -0400516 std::vector<uint32_t> pixels;
517 const int height = 2;
518 const int width = 2;
519 pixels.resize(height * width * 4);
520 SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType,
521 kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4);
522 for (int index = 0; index < 2; ++index) {
523 pixmap.erase(0x00000000);
524 SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false");
525 pixmap.erase(0xFFFFFFFF);
526 SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false");
527 pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType),
528 (const void*) &pixels.front(), width * 4);
529 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400530#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400531isOpaque: false
532isOpaque: false
533isOpaque: true
Cary Clarkd0530ba2017-09-14 11:25:39 -0400534isOpaque: true
535##
536##
537
538#SeeAlso computeIsOpaque SkImageInfo::isOpaque
539
540##
541
542# ------------------------------------------------------------------------------
543
Cary Clark682c58d2018-05-16 07:07:07 -0400544#Method SkIRect bounds() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400545
Cary Clarkab2621d2018-01-30 10:08:57 -0500546#In Image_Info_Access
547#Line # returns width and height as Rectangle ##
Cary Clark154beea2017-10-26 07:58:48 -0400548Returns IRect { 0, 0, width(), height() }.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400549
550#Return integral rectangle from origin to width() and height() ##
551
552#Example
553 for (int width : { 0, 2 } ) {
554 for (int height : { 0, 2 } ) {
Cary Clark6fc50412017-09-21 12:31:06 -0400555 SkPixmap pixmap(SkImageInfo::MakeA8(width, height), nullptr, width);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400556 SkDebugf("width: %d height: %d empty: %s\n", width, height,
557 pixmap.bounds().isEmpty() ? "true" : "false");
558 }
559 }
560#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400561width: 0 height: 0 empty: true
562width: 0 height: 2 empty: true
563width: 2 height: 0 empty: true
Cary Clarkd0530ba2017-09-14 11:25:39 -0400564width: 2 height: 2 empty: false
565##
566##
567
Cary Clark682c58d2018-05-16 07:07:07 -0400568#SeeAlso height() width() IRect
Cary Clarkd0530ba2017-09-14 11:25:39 -0400569
570##
571
572# ------------------------------------------------------------------------------
573
Cary Clark682c58d2018-05-16 07:07:07 -0400574#Method int rowBytesAsPixels() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400575
Cary Clarkab2621d2018-01-30 10:08:57 -0500576#In Image_Info_Access
577#Line # returns interval between rows in pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400578
579Returns number of pixels that fit on row. Should be greater than or equal to
580width().
581
582#Return maximum pixels per row ##
583
584#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400585 for (int rowBytes : { 4, 5, 6, 7, 8} ) {
586 SkPixmap pixmap(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), nullptr, rowBytes);
587 SkDebugf("rowBytes: %d rowBytesAsPixels: %d\n", rowBytes, pixmap.rowBytesAsPixels());
588 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400589#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400590rowBytes: 4 rowBytesAsPixels: 1
591rowBytes: 5 rowBytesAsPixels: 1
592rowBytes: 6 rowBytesAsPixels: 1
593rowBytes: 7 rowBytesAsPixels: 1
Cary Clarkd0530ba2017-09-14 11:25:39 -0400594rowBytes: 8 rowBytesAsPixels: 2
595##
596##
597
598#SeeAlso rowBytes shiftPerPixel width SkImageInfo::bytesPerPixel
599
600##
601
602# ------------------------------------------------------------------------------
603
Cary Clark682c58d2018-05-16 07:07:07 -0400604#Method int shiftPerPixel() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400605
Cary Clarkab2621d2018-01-30 10:08:57 -0500606#In Image_Info_Access
607#Line # returns bit shift from pixels to bytes ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400608Returns bit shift converting row bytes to row pixels.
609Returns zero for kUnknown_SkColorType.
610
611#Return one of: 0, 1, 2, 3; left shift to convert pixels to bytes ##
612
613#Example
Cary Clarkab2621d2018-01-30 10:08:57 -0500614 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
615 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -0400616 SkImageInfo info = SkImageInfo::MakeA8(1, 1);
617 for (SkColorType colorType : { kUnknown_SkColorType, kAlpha_8_SkColorType,
Cary Clark682c58d2018-05-16 07:07:07 -0400618 kRGB_565_SkColorType, kARGB_4444_SkColorType,
Cary Clark6fc50412017-09-21 12:31:06 -0400619 kRGBA_8888_SkColorType, kBGRA_8888_SkColorType,
620 kGray_8_SkColorType, kRGBA_F16_SkColorType } ) {
621 SkPixmap pixmap(info.makeColorType(colorType), nullptr, 4);
622 SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d shiftPerPixel: %d\n",
623 colors[colorType], 10 - strlen(colors[colorType]), " ",
624 pixmap.info().bytesPerPixel(), pixmap.shiftPerPixel());
625 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400626#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400627color: kUnknown_SkColorType bytesPerPixel: 0 shiftPerPixel: 0
Cary Clarkab2621d2018-01-30 10:08:57 -0500628color: kAlpha_8_SkColorType bytesPerPixel: 1 shiftPerPixel: 0
Cary Clark6fc50412017-09-21 12:31:06 -0400629color: kRGB_565_SkColorType bytesPerPixel: 2 shiftPerPixel: 1
630color: kARGB_4444_SkColorType bytesPerPixel: 2 shiftPerPixel: 1
631color: kRGBA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2
632color: kBGRA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2
633color: kGray_8_SkColorType bytesPerPixel: 1 shiftPerPixel: 0
Cary Clarkd0530ba2017-09-14 11:25:39 -0400634color: kRGBA_F16_SkColorType bytesPerPixel: 8 shiftPerPixel: 3
635##
636##
637
638#SeeAlso rowBytes rowBytesAsPixels width SkImageInfo::bytesPerPixel
639
640##
641
642# ------------------------------------------------------------------------------
643
Cary Clarkbc5697d2017-10-04 14:31:33 -0400644#Method size_t computeByteSize() const
645
Cary Clarkab2621d2018-01-30 10:08:57 -0500646#In Image_Info_Access
647#Line # returns size required for pixels ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400648Returns minimum memory required for pixel storage.
649Does not include unused memory on last row when rowBytesAsPixels exceeds width().
650Returns zero if result does not fit in size_t.
651Returns zero if height() or width() is 0.
652Returns height() times rowBytes if colorType is kUnknown_SkColorType.
653
654#Return size in bytes of image buffer ##
655
Cary Clarkd0530ba2017-09-14 11:25:39 -0400656#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400657 SkPixmap pixmap;
658 for (int width : { 1, 1000, 1000000 } ) {
659 for (int height: { 1, 1000, 1000000 } ) {
660 SkImageInfo imageInfo = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType);
Cary Clarkbc5697d2017-10-04 14:31:33 -0400661 pixmap.reset(imageInfo, nullptr, width * 5);
662 SkDebugf("width: %7d height: %7d computeByteSize: %13lld\n", width, height,
663 pixmap.computeByteSize());
Cary Clark6fc50412017-09-21 12:31:06 -0400664 }
665 }
Cary Clark6fc50412017-09-21 12:31:06 -0400666#StdOut
Ben Wagner29380bd2017-10-09 14:43:00 -0400667width: 1 height: 1 computeByteSize: 4
668width: 1 height: 1000 computeByteSize: 4999
669width: 1 height: 1000000 computeByteSize: 4999999
670width: 1000 height: 1 computeByteSize: 4000
671width: 1000 height: 1000 computeByteSize: 4999000
672width: 1000 height: 1000000 computeByteSize: 4999999000
673width: 1000000 height: 1 computeByteSize: 4000000
674width: 1000000 height: 1000 computeByteSize: 4999000000
Cary Clarkbc5697d2017-10-04 14:31:33 -0400675width: 1000000 height: 1000000 computeByteSize: 4999999000000
Cary Clarkd0530ba2017-09-14 11:25:39 -0400676##
677##
678
Cary Clarkbc5697d2017-10-04 14:31:33 -0400679#SeeAlso SkImageInfo::computeByteSize
Cary Clarkd0530ba2017-09-14 11:25:39 -0400680
681##
682
683#Subtopic Image_Info_Access ##
684
685#Subtopic Reader
Cary Clark08895c42018-02-01 09:37:32 -0500686#Line # examine pixel value ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400687
688# ------------------------------------------------------------------------------
689
690#Method bool computeIsOpaque() const
691
Cary Clarkab2621d2018-01-30 10:08:57 -0500692#In Reader
693#Line # returns true if all pixels are opaque ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400694Returns true if all pixels are opaque. Color_Type determines how pixels
695are encoded, and whether pixel describes Alpha. Returns true for Color_Types
Cary Clark6fc50412017-09-21 12:31:06 -0400696without alpha in each pixel; for other Color_Types, returns true if all
Cary Clarkd0530ba2017-09-14 11:25:39 -0400697pixels have alpha values equivalent to 1.0 or greater.
698
699For Color_Types kRGB_565_SkColorType or kGray_8_SkColorType: always
700returns true. For Color_Types kAlpha_8_SkColorType, kBGRA_8888_SkColorType,
701kRGBA_8888_SkColorType: returns true if all pixel Alpha values are 255.
702For Color_Type kARGB_4444_SkColorType: returns true if all pixel Alpha values are 15.
703For kRGBA_F16_SkColorType: returns true if all pixel Alpha values are 1.0 or
704greater.
705
Cary Clark682c58d2018-05-16 07:07:07 -0400706Returns false for kUnknown_SkColorType.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400707
Cary Clarkbc5697d2017-10-04 14:31:33 -0400708#Return true if all pixels have opaque values or Color_Type is opaque ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400709
710#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400711 std::vector<uint32_t> pixels;
712 const int height = 2;
713 const int width = 2;
714 pixels.resize(height * width * 4);
715 SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType,
716 kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4);
717 for (int index = 0; index < 2; ++index) {
718 pixmap.erase(0x00000000);
719 SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false");
720 pixmap.erase(0xFFFFFFFF);
721 SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false");
722 pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType),
723 (const void*) &pixels.front(), width * 4);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400724 }
725#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400726computeIsOpaque: false
727computeIsOpaque: true
728computeIsOpaque: false
Cary Clarkd0530ba2017-09-14 11:25:39 -0400729computeIsOpaque: true
730##
731##
732
733#SeeAlso isOpaque Color_Type Alpha
734
735##
736
737# ------------------------------------------------------------------------------
738
739#Method SkColor getColor(int x, int y) const
740
Cary Clarkab2621d2018-01-30 10:08:57 -0500741#In Reader
742#Line # returns one pixel as Unpremultiplied Color ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400743Returns pixel at (x, y) as Unpremultiplied Color.
744Returns black with Alpha if Color_Type is kAlpha_8_SkColorType.
745
746Input is not validated: out of bounds values of x or y trigger an assert() if
747built with SK_DEBUG defined; and returns undefined values or may crash if
748SK_RELEASE is defined. Fails if Color_Type is kUnknown_SkColorType or
749pixel address is nullptr.
750
751Color_Space in Image_Info is ignored. Some Color precision may be lost in the
Cary Clark682c58d2018-05-16 07:07:07 -0400752conversion to Unpremultiplied Color; original pixel data may have additional
Cary Clarkd0530ba2017-09-14 11:25:39 -0400753precision.
754
Cary Clark6fc50412017-09-21 12:31:06 -0400755#Param x column index, zero or greater, and less than width() ##
756#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400757
758#Return pixel converted to Unpremultiplied Color ##
759
760#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400761 const int w = 4;
762 const int h = 4;
763 std::vector<SkPMColor> storage;
764 storage.resize(w * h);
765 SkDebugf("Premultiplied:\n");
766 for (int y = 0; y < h; ++y) {
767 SkDebugf("(0, %d) ", y);
768 for (int x = 0; x < w; ++x) {
769 int a = 0xFF * (x + y) / (w - 1 + h - 1);
770 storage[x + y * w] = SkPackARGB32(a, a * x / (w - 1), a * y / (h - 1), a);
771 SkDebugf("0x%08x%c", storage[x + y * w], x == w - 1 ? '\n' : ' ');
772 }
773 }
774 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4);
775 SkDebugf("Unpremultiplied:\n");
776 for (int y = 0; y < h; ++y) {
777 SkDebugf("(0, %d) ", y);
778 for (int x = 0; x < w; ++x) {
779 SkDebugf("0x%08x%c", pixmap.getColor(x, y), x == w - 1 ? '\n' : ' ');
780 }
781 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400782#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400783Premultiplied:
Cary Clark682c58d2018-05-16 07:07:07 -0400784(0, 0) 0x00000000 0x2a0e002a 0x55380055 0x7f7f007f
785(0, 1) 0x2a000e2a 0x551c1c55 0x7f542a7f 0xaaaa38aa
786(0, 2) 0x55003855 0x7f2a547f 0xaa7171aa 0xd4d48dd4
787(0, 3) 0x7f007f7f 0xaa38aaaa 0xd48dd4d4 0xffffffff
Cary Clark6fc50412017-09-21 12:31:06 -0400788Unpremultiplied:
Cary Clark682c58d2018-05-16 07:07:07 -0400789(0, 0) 0x00000000 0x2a5500ff 0x55a800ff 0x7fff00ff
790(0, 1) 0x2a0055ff 0x555454ff 0x7fa954ff 0xaaff54ff
791(0, 2) 0x5500a8ff 0x7f54a9ff 0xaaaaaaff 0xd4ffaaff
792(0, 3) 0x7f00ffff 0xaa54ffff 0xd4aaffff 0xffffffff
Cary Clarkd0530ba2017-09-14 11:25:39 -0400793##
794##
795
Cary Clark8fe29402018-09-20 17:31:43 -0400796#SeeAlso getAlphaf addr() readPixels
797
798##
799
800#Method float getAlphaf(int x, int y) const
801#In Property
802#Line # returns Alpha normalized from zero to one ##
803
804Looks up the pixel at (x,y) and return its alpha component, normalized to [0..1].
805This is roughly equivalent to #Formula # SkGetColorA(getColor()) ##, but can be more efficent
806(and more precise if the pixels store more than 8 bits per component).
807
808#Param x column index, zero or greater, and less than width() ##
809#Param y row index, zero or greater, and less than height() ##
810
811#Return alpha converted to normalized float ##
812
813#NoExample
814##
815
816#SeeAlso getColor
Cary Clarkd0530ba2017-09-14 11:25:39 -0400817
818##
819
820#Subtopic Reader ##
821
822#Subtopic Readable_Address
Cary Clark08895c42018-02-01 09:37:32 -0500823#Line # returns read only pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400824
825# ------------------------------------------------------------------------------
826
827#Method const void* addr(int x, int y) const
828
Cary Clarkab2621d2018-01-30 10:08:57 -0500829#In Readable_Address
Cary Clarkbc5697d2017-10-04 14:31:33 -0400830Returns readable pixel address at (x, y). Returns nullptr if Pixel_Ref is nullptr.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400831
832Input is not validated: out of bounds values of x or y trigger an assert() if
Cary Clarkbc5697d2017-10-04 14:31:33 -0400833built with SK_DEBUG defined. Returns nullptr if Color_Type is kUnknown_SkColorType.
834
Cary Clark682c58d2018-05-16 07:07:07 -0400835Performs a lookup of pixel size; for better performance, call
Cary Clarkbc5697d2017-10-04 14:31:33 -0400836one of: addr8, addr16, addr32, addr64, or addrF16.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400837
Cary Clark6fc50412017-09-21 12:31:06 -0400838#Param x column index, zero or greater, and less than width() ##
839#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400840
841#Return readable generic pointer to pixel ##
842
843#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400844 const int w = 4;
845 const int h = 4;
846 std::vector<SkPMColor> storage;
847 storage.resize(w * h);
848 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400849 SkDebugf("pixmap.addr(1, 2) %c= &storage[1 + 2 * w]\n",
850 pixmap.addr(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
851#StdOut
852pixmap.addr(1, 2) == &storage[1 + 2 * w]
853##
854##
855
Cary Clarkbc5697d2017-10-04 14:31:33 -0400856#SeeAlso addr8 addr16 addr32 addr64 addrF16 getColor writable_addr SkBitmap::getAddr
Cary Clarkd0530ba2017-09-14 11:25:39 -0400857
858##
859
860# ------------------------------------------------------------------------------
861
Cary Clark682c58d2018-05-16 07:07:07 -0400862#Method const uint8_t* addr8() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400863
Cary Clarkab2621d2018-01-30 10:08:57 -0500864#In Readable_Address
865#Line # returns readable pixel address as 8-bit pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400866Returns readable base pixel address. Result is addressable as unsigned 8-bit bytes.
867Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType or
868kGray_8_SkColorType, and is built with SK_DEBUG defined.
869
870One byte corresponds to one pixel.
871
872#Return readable unsigned 8-bit pointer to pixels ##
873
874#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400875 const int w = 4;
876 const int h = 4;
877 uint8_t storage[w * h];
878 SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType),
879 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400880 SkDebugf("pixmap.addr8() %c= storage\n",
881 pixmap.addr8() == storage ? '=' : '!');
882#StdOut
883pixmap.addr8() == storage
884##
885##
886
887#SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8
888
889##
890
891# ------------------------------------------------------------------------------
892
Cary Clark682c58d2018-05-16 07:07:07 -0400893#Method const uint16_t* addr16() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400894
Cary Clarkab2621d2018-01-30 10:08:57 -0500895#In Readable_Address
896#Line # returns readable pixel address as 16-bit pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400897Returns readable base pixel address. Result is addressable as unsigned 16-bit words.
898Will trigger an assert() if Color_Type is not kRGB_565_SkColorType or
899kARGB_4444_SkColorType, and is built with SK_DEBUG defined.
900
901One word corresponds to one pixel.
902
903#Return readable unsigned 16-bit pointer to pixels ##
904
905#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400906 const int w = 4;
907 const int h = 4;
908 uint16_t storage[w * h];
909 SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType),
910 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400911 SkDebugf("pixmap.addr16() %c= storage\n",
912 pixmap.addr16() == storage ? '=' : '!');
913#StdOut
914pixmap.addr16() == storage
915##
916##
917
918#SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16
919
920##
921
922# ------------------------------------------------------------------------------
923
Cary Clark682c58d2018-05-16 07:07:07 -0400924#Method const uint32_t* addr32() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400925
Cary Clarkab2621d2018-01-30 10:08:57 -0500926#In Readable_Address
927#Line # returns readable pixel address as 32-bit pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400928Returns readable base pixel address. Result is addressable as unsigned 32-bit words.
929Will trigger an assert() if Color_Type is not kRGBA_8888_SkColorType or
930kBGRA_8888_SkColorType, and is built with SK_DEBUG defined.
931
932One word corresponds to one pixel.
933
934#Return readable unsigned 32-bit pointer to pixels ##
935
936#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400937 const int w = 4;
938 const int h = 4;
939 uint32_t storage[w * h];
940 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType),
941 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400942 SkDebugf("pixmap.addr32() %c= storage\n",
943 pixmap.addr32() == storage ? '=' : '!');
944#StdOut
945pixmap.addr32() == storage
946##
947##
948
949#SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr32
950
951##
952
953# ------------------------------------------------------------------------------
954
Cary Clark682c58d2018-05-16 07:07:07 -0400955#Method const uint64_t* addr64() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400956
Cary Clarkab2621d2018-01-30 10:08:57 -0500957#In Readable_Address
958#Line # returns readable pixel address as 64-bit pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400959Returns readable base pixel address. Result is addressable as unsigned 64-bit words.
960Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
961with SK_DEBUG defined.
962
963One word corresponds to one pixel.
964
965#Return readable unsigned 64-bit pointer to pixels ##
966
967#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400968 const int w = 4;
969 const int h = 4;
970 uint64_t storage[w * h];
971 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
972 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400973 SkDebugf("pixmap.addr64() %c= storage\n",
974 pixmap.addr64() == storage ? '=' : '!');
975#StdOut
976pixmap.addr64() == storage
977##
978##
979
980#SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64
981
982##
983
984# ------------------------------------------------------------------------------
985
Cary Clark682c58d2018-05-16 07:07:07 -0400986#Method const uint16_t* addrF16() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400987
Cary Clarkab2621d2018-01-30 10:08:57 -0500988#In Readable_Address
989#Line # returns readable pixel component address as 16-bit pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400990Returns readable base pixel address. Result is addressable as unsigned 16-bit words.
991Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
992with SK_DEBUG defined.
993
994Each word represents one color component encoded as a half float.
995Four words correspond to one pixel.
996
997#Return readable unsigned 16-bit pointer to first component of pixels ##
998
999#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001000 const int w = 4;
1001 const int h = 4;
1002 uint16_t storage[w * h * 4];
1003 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
1004 storage, w * 4 * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001005 SkDebugf("pixmap.addrF16() %c= storage\n",
1006 pixmap.addrF16() == storage ? '=' : '!');
1007#StdOut
1008pixmap.addrF16() == storage
1009##
1010##
1011
1012#SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16
1013
1014##
1015
1016# ------------------------------------------------------------------------------
1017
Cary Clark682c58d2018-05-16 07:07:07 -04001018#Method const uint8_t* addr8(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001019
Cary Clarkab2621d2018-01-30 10:08:57 -05001020#In Readable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001021Returns readable pixel address at (x, y).
1022
1023Input is not validated: out of bounds values of x or y trigger an assert() if
1024built with SK_DEBUG defined.
1025
1026Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType or
1027kGray_8_SkColorType, and is built with SK_DEBUG defined.
1028
Cary Clark6fc50412017-09-21 12:31:06 -04001029#Param x column index, zero or greater, and less than width() ##
1030#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001031
1032#Return readable unsigned 8-bit pointer to pixel at (x, y) ##
1033
1034#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001035 const int w = 4;
1036 const int h = 4;
1037 uint8_t storage[w * h];
1038 SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType),
1039 storage, w * sizeof(storage[0]));
1040 SkDebugf("pixmap.addr8(1, 2) %c= &storage[1 + 2 * w]\n",
1041 pixmap.addr8(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
Cary Clarkd0530ba2017-09-14 11:25:39 -04001042#StdOut
1043pixmap.addr8(1, 2) == &storage[1 + 2 * w]
1044##
1045##
1046
1047#SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8
1048
1049##
1050
1051# ------------------------------------------------------------------------------
1052
Cary Clark682c58d2018-05-16 07:07:07 -04001053#Method const uint16_t* addr16(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001054
Cary Clarkab2621d2018-01-30 10:08:57 -05001055#In Readable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001056Returns readable pixel address at (x, y).
1057
1058Input is not validated: out of bounds values of x or y trigger an assert() if
1059built with SK_DEBUG defined.
1060
1061Will trigger an assert() if Color_Type is not kRGB_565_SkColorType or
1062kARGB_4444_SkColorType, and is built with SK_DEBUG defined.
1063
Cary Clark6fc50412017-09-21 12:31:06 -04001064#Param x column index, zero or greater, and less than width() ##
1065#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001066
1067#Return readable unsigned 16-bit pointer to pixel at (x, y) ##
1068
1069#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001070 const int w = 4;
1071 const int h = 4;
1072 uint16_t storage[w * h];
1073 SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType),
1074 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001075 SkDebugf("pixmap.addr16(1, 2) %c= &storage[1 + 2 * w]\n",
1076 pixmap.addr16(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
1077#StdOut
1078pixmap.addr16(1, 2) == &storage[1 + 2 * w]
1079##
1080##
1081
1082#SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16
1083
1084##
1085
1086# ------------------------------------------------------------------------------
1087
Cary Clark682c58d2018-05-16 07:07:07 -04001088#Method const uint32_t* addr32(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001089
Cary Clarkab2621d2018-01-30 10:08:57 -05001090#In Readable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001091Returns readable pixel address at (x, y).
1092
1093Input is not validated: out of bounds values of x or y trigger an assert() if
1094built with SK_DEBUG defined.
1095
1096Will trigger an assert() if Color_Type is not kRGBA_8888_SkColorType or
1097kBGRA_8888_SkColorType, and is built with SK_DEBUG defined.
1098
Cary Clark6fc50412017-09-21 12:31:06 -04001099#Param x column index, zero or greater, and less than width() ##
1100#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001101
1102#Return readable unsigned 32-bit pointer to pixel at (x, y) ##
1103
1104#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001105 const int w = 4;
1106 const int h = 4;
1107 uint32_t storage[w * h];
1108 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_8888_SkColorType, kPremul_SkAlphaType),
1109 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001110 SkDebugf("pixmap.addr32(1, 2) %c= &storage[1 + 2 * w]\n",
1111 pixmap.addr32(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
1112#StdOut
1113pixmap.addr32(1, 2) == &storage[1 + 2 * w]
1114##
1115##
1116
Cary Clark2ade9972017-11-02 17:49:34 -04001117#SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr64
Cary Clarkd0530ba2017-09-14 11:25:39 -04001118
1119##
1120
1121# ------------------------------------------------------------------------------
1122
Cary Clark682c58d2018-05-16 07:07:07 -04001123#Method const uint64_t* addr64(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001124
Cary Clarkab2621d2018-01-30 10:08:57 -05001125#In Readable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001126Returns readable pixel address at (x, y).
1127
1128Input is not validated: out of bounds values of x or y trigger an assert() if
1129built with SK_DEBUG defined.
1130
1131Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
1132with SK_DEBUG defined.
1133
Cary Clark6fc50412017-09-21 12:31:06 -04001134#Param x column index, zero or greater, and less than width() ##
1135#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001136
1137#Return readable unsigned 64-bit pointer to pixel at (x, y) ##
1138
1139#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001140 const int w = 4;
1141 const int h = 4;
1142 uint64_t storage[w * h];
1143 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
1144 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001145 SkDebugf("pixmap.addr64(1, 2) %c= &storage[1 + 2 * w]\n",
1146 pixmap.addr64(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
1147#StdOut
1148pixmap.addr64(1, 2) == &storage[1 + 2 * w]
1149##
1150##
1151
1152#SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64
1153
1154##
1155
1156# ------------------------------------------------------------------------------
1157
Cary Clark682c58d2018-05-16 07:07:07 -04001158#Method const uint16_t* addrF16(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001159
Cary Clarkab2621d2018-01-30 10:08:57 -05001160#In Readable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001161Returns readable pixel address at (x, y).
1162
1163Input is not validated: out of bounds values of x or y trigger an assert() if
1164built with SK_DEBUG defined.
1165
1166Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
1167with SK_DEBUG defined.
1168
1169Each unsigned 16-bit word represents one color component encoded as a half float.
1170Four words correspond to one pixel.
1171
Cary Clark6fc50412017-09-21 12:31:06 -04001172#Param x column index, zero or greater, and less than width() ##
1173#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001174
1175#Return readable unsigned 16-bit pointer to pixel component at (x, y) ##
1176
1177#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001178 const int w = 4;
1179 const int h = 4;
1180 const int wordsPerPixel = 4;
1181 const int rowWords = w * wordsPerPixel;
1182 uint16_t storage[rowWords * h];
1183 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
1184 storage, rowWords * sizeof(storage[0]));
1185 SkDebugf("pixmap.addrF16(1, 2) %c= &storage[1 * wordsPerPixel + 2 * rowWords]\n",
1186 pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords] ? '=' : '!');
Cary Clarkd0530ba2017-09-14 11:25:39 -04001187#StdOut
1188pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords]
1189##
1190##
1191
1192#SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16
1193
1194##
1195
1196#Subtopic Readable_Address ##
1197
1198#Subtopic Writable_Address
Cary Clark08895c42018-02-01 09:37:32 -05001199#Line # returns writable pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001200
1201# ------------------------------------------------------------------------------
1202
Cary Clark682c58d2018-05-16 07:07:07 -04001203#Method void* writable_addr() const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001204
Cary Clarkab2621d2018-01-30 10:08:57 -05001205#In Writable_Address
1206#Line # returns writable pixel address as void pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001207Returns writable base pixel address.
1208
1209#Return writable generic base pointer to pixels ##
1210
1211#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001212 const int w = 4;
1213 const int h = 4;
1214 SkPMColor storage[w * h * 4];
1215 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4);
1216 SkDebugf("pixmap.writable_addr() %c= (void *)storage\n",
1217 pixmap.writable_addr() == (void *)storage ? '=' : '!');
1218 pixmap.erase(0x00000000);
1219 *(SkPMColor*)pixmap.writable_addr() = 0xFFFFFFFF;
1220 SkDebugf("pixmap.getColor(0, 1) %c= 0x00000000\n",
1221 pixmap.getColor(0, 1) == 0x00000000 ? '=' : '!');
1222 SkDebugf("pixmap.getColor(0, 0) %c= 0xFFFFFFFF\n",
Cary Clarkd0530ba2017-09-14 11:25:39 -04001223 pixmap.getColor(0, 0) == 0xFFFFFFFF ? '=' : '!');
1224#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -04001225pixmap.writable_addr() == (void *)storage
1226pixmap.getColor(0, 1) == 0x00000000
Cary Clarkd0530ba2017-09-14 11:25:39 -04001227pixmap.getColor(0, 0) == 0xFFFFFFFF
1228##
1229##
1230
1231#SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr()
1232
1233##
1234
1235# ------------------------------------------------------------------------------
1236
Cary Clark682c58d2018-05-16 07:07:07 -04001237#Method void* writable_addr(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001238
Cary Clarkab2621d2018-01-30 10:08:57 -05001239#In Writable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001240Returns writable pixel address at (x, y).
1241
1242Input is not validated: out of bounds values of x or y trigger an assert() if
1243built with SK_DEBUG defined. Returns zero if Color_Type is kUnknown_SkColorType.
1244
Cary Clark6fc50412017-09-21 12:31:06 -04001245#Param x column index, zero or greater, and less than width() ##
1246#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001247
1248#Return writable generic pointer to pixel ##
1249
1250#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001251 const int w = 4;
1252 const int h = 4;
1253 SkPMColor storage[w * h * 4];
1254 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4);
1255 SkDebugf("pixmap.writable_addr() %c= (void *)storage\n",
1256 pixmap.writable_addr() == (void *)storage ? '=' : '!');
1257 pixmap.erase(0x00000000);
1258 *(SkPMColor*)pixmap.writable_addr(1, 2) = 0xFFFFFFFF;
1259 SkDebugf("pixmap.getColor(0, 0) %c= 0x00000000\n",
1260 pixmap.getColor(0, 0) == 0x00000000 ? '=' : '!');
1261 SkDebugf("pixmap.getColor(1, 2) %c= 0xFFFFFFFF\n",
Cary Clarkd0530ba2017-09-14 11:25:39 -04001262 pixmap.getColor(1, 2) == 0xFFFFFFFF ? '=' : '!');
1263#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -04001264pixmap.writable_addr() == (void *)storage
1265pixmap.getColor(0, 0) == 0x00000000
Cary Clarkd0530ba2017-09-14 11:25:39 -04001266pixmap.getColor(1, 2) == 0xFFFFFFFF
1267##
1268##
1269
1270#SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr()
1271
1272##
1273
1274# ------------------------------------------------------------------------------
1275
Cary Clark682c58d2018-05-16 07:07:07 -04001276#Method uint8_t* writable_addr8(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001277
Cary Clarkab2621d2018-01-30 10:08:57 -05001278#In Writable_Address
1279#Line # returns writable pixel address as 8-bit pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -04001280Returns writable pixel address at (x, y). Result is addressable as unsigned
12818-bit bytes. Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType
1282or kGray_8_SkColorType, and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001283
1284One byte corresponds to one pixel.
1285
Cary Clark6fc50412017-09-21 12:31:06 -04001286#Param x column index, zero or greater, and less than width() ##
1287#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001288
1289#Return writable unsigned 8-bit pointer to pixels ##
1290
1291#Example
1292#Height 64
1293#Description
1294Altering pixels after drawing Bitmap is not guaranteed to affect subsequent
1295drawing on all platforms. Adding a second SkBitmap::installPixels after editing
1296pixel memory is safer.
1297##
Cary Clark6fc50412017-09-21 12:31:06 -04001298void draw(SkCanvas* canvas) {
1299 uint8_t storage[][5] = {{ 0, 0, 64, 0, 0},
1300 { 0, 128, 255, 128, 0},
1301 {64, 255, 255, 255, 64},
1302 { 0, 128, 255, 128, 0},
1303 { 0, 0, 64, 0, 0}};
1304 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kPremul_SkAlphaType);
1305 SkPixmap pixmap(imageInfo, storage[0], 5);
1306 SkBitmap bitmap;
1307 bitmap.installPixels(pixmap);
1308 canvas->scale(10, 10);
1309 canvas->drawBitmap(bitmap, 0, 0);
1310 *pixmap.writable_addr8(2, 2) = 0;
1311// bitmap.installPixels(pixmap); // uncomment to fix on GPU
1312 canvas->drawBitmap(bitmap, 10, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001313}
1314##
1315
1316#SeeAlso writable_addr writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr() addr8
1317
1318##
1319
1320# ------------------------------------------------------------------------------
1321
Cary Clark682c58d2018-05-16 07:07:07 -04001322#Method uint16_t* writable_addr16(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001323
Cary Clarkab2621d2018-01-30 10:08:57 -05001324#In Writable_Address
1325#Line # returns writable pixel address as 16-bit pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -04001326Returns writable_addr pixel address at (x, y). Result is addressable as unsigned
132716-bit words. Will trigger an assert() if Color_Type is not kRGB_565_SkColorType
1328or kARGB_4444_SkColorType, and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001329
1330One word corresponds to one pixel.
1331
Cary Clark6fc50412017-09-21 12:31:06 -04001332#Param x column index, zero or greater, and less than width() ##
1333#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001334
1335#Return writable unsigned 16-bit pointer to pixel ##
1336
1337#Example
1338#Description
1339Draw a five by five bitmap, and draw it again with a center black pixel.
1340The low nibble of the 16-bit word is Alpha.
1341##
1342#Height 64
Cary Clark6fc50412017-09-21 12:31:06 -04001343 uint16_t storage[][5] = {{ 0xCABF, 0xDABE, 0xCA9D, 0xC96C, 0xA39B },
1344 { 0xACEE, 0xA87C, 0x893A, 0x4779, 0x8708 },
1345 { 0x4B7C, 0x255B, 0x2559, 0x2557, 0x4656 },
1346 { 0x9099, 0x8128, 0x2557, 0x4124, 0x3323 },
1347 { 0x7547, 0x5505, 0x4434, 0x2012, 0x0000 }};
1348 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kARGB_4444_SkColorType, kPremul_SkAlphaType);
1349 SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
1350 SkBitmap bitmap;
1351 bitmap.installPixels(pixmap);
1352 canvas->scale(10, 10);
1353 canvas->drawBitmap(bitmap, 0, 0);
1354 *pixmap.writable_addr16(2, 2) = 0x000F;
1355 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001356 canvas->drawBitmap(bitmap, 10, 0);
1357##
1358
1359#SeeAlso writable_addr writable_addr8 writable_addr32 writable_addr64 writable_addrF16 addr() addr16
1360
1361##
1362
1363# ------------------------------------------------------------------------------
1364
Cary Clark682c58d2018-05-16 07:07:07 -04001365#Method uint32_t* writable_addr32(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001366
Cary Clarkab2621d2018-01-30 10:08:57 -05001367#In Writable_Address
1368#Line # returns writable pixel address as 32-bit pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -04001369Returns writable pixel address at (x, y). Result is addressable as unsigned
137032-bit words. Will trigger an assert() if Color_Type is not
1371kRGBA_8888_SkColorType or kBGRA_8888_SkColorType, and is built with SK_DEBUG
1372defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001373
1374One word corresponds to one pixel.
1375
Cary Clark6fc50412017-09-21 12:31:06 -04001376#Param x column index, zero or greater, and less than width() ##
1377#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001378
1379#Return writable unsigned 32-bit pointer to pixel ##
1380
1381#Example
1382#Image 4
1383#Height 72
Cary Clark6fc50412017-09-21 12:31:06 -04001384 std::vector<int32_t> pixels;
1385 pixels.resize(image->height() * image->width() * 4);
1386 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
1387 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
1388 image->readPixels(pixmap, 0, 0);
1389 for (int y = 0; y < pixmap.height() / 2; ++y) {
1390 for (int x = 0; x < pixmap.width(); ++x) {
1391 if ((x & 4) == (y & 4)) {
Cary Clark4d759752018-06-19 12:57:43 -04001392 *pixmap.writable_addr32(x, y) =
1393 *pixmap.writable_addr32(pixmap.width() - x, pixmap.height() - y);
Cary Clark6fc50412017-09-21 12:31:06 -04001394 }
1395 }
1396 }
1397 SkBitmap bitmap;
1398 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001399 canvas->drawBitmap(bitmap, 0, 0);
1400##
1401
1402#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr64 writable_addrF16 addr() addr32
1403
1404##
1405
1406# ------------------------------------------------------------------------------
1407
Cary Clark682c58d2018-05-16 07:07:07 -04001408#Method uint64_t* writable_addr64(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001409
Cary Clarkab2621d2018-01-30 10:08:57 -05001410#In Writable_Address
1411#Line # returns writable pixel address as 64-bit pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -04001412Returns writable pixel address at (x, y). Result is addressable as unsigned
141364-bit words. Will trigger an assert() if Color_Type is not
1414kRGBA_F16_SkColorType and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001415
1416One word corresponds to one pixel.
1417
Cary Clark6fc50412017-09-21 12:31:06 -04001418#Param x column index, zero or greater, and less than width() ##
1419#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001420
1421#Return writable unsigned 64-bit pointer to pixel ##
1422
1423#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001424#Height 40
Cary Clark6fc50412017-09-21 12:31:06 -04001425 SkImageInfo info = SkImageInfo::Make(3, 3, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
1426 uint64_t storage[9];
1427 SkPixmap pixmap(info, storage, 3 * sizeof(uint64_t));
1428 SkColor4f c4 { 1, 0.45f, 0.25f, 0.65f };
1429 pixmap.erase(c4);
1430 SkBitmap bitmap;
1431 canvas->scale(10, 10);
1432 bitmap.installPixels(pixmap);
1433 canvas->drawBitmap(bitmap, 0, 0);
1434 *pixmap.writable_addr64(1, 1) |= 0x00ff000000000000LL;
1435 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001436 canvas->drawBitmap(bitmap, 10, 0);
1437##
1438
1439#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addrF16 addr() addr64
1440
1441##
1442
1443# ------------------------------------------------------------------------------
1444
Cary Clark682c58d2018-05-16 07:07:07 -04001445#Method uint16_t* writable_addrF16(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001446
Cary Clarkab2621d2018-01-30 10:08:57 -05001447#In Writable_Address
1448#Line # returns writable pixel component address as 16-bit pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -04001449Returns writable pixel address at (x, y). Result is addressable as unsigned
145016-bit words. Will trigger an assert() if Color_Type is not
1451kRGBA_F16_SkColorType and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001452
1453Each word represents one color component encoded as a half float.
1454Four words correspond to one pixel.
1455
Cary Clark6fc50412017-09-21 12:31:06 -04001456#Param x column index, zero or greater, and less than width() ##
1457#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001458
1459#Return writable unsigned 16-bit pointer to first component of pixel ##
1460
1461#Example
1462#Height 64
1463#Description
1464Left bitmap is drawn with two pixels defined in half float format. Right bitmap
Cary Clark682c58d2018-05-16 07:07:07 -04001465is drawn after overwriting bottom half float color with top half float color.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001466##
Cary Clark6fc50412017-09-21 12:31:06 -04001467 SkImageInfo info = SkImageInfo::Make(1, 2, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
1468 uint16_t storage[2][4];
1469 SkPixmap pixmap(info, storage[0], sizeof(uint64_t));
1470 SkIRect topPixelBounds = {0, 0, 1, 1};
1471 pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds);
1472 SkIRect bottomPixelBounds = {0, 1, 1, 2};
1473 pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds);
1474 SkBitmap bitmap;
1475 canvas->scale(20, 20);
1476 bitmap.installPixels(pixmap);
1477 canvas->drawBitmap(bitmap, 0, 0);
1478 uint16_t* pixel2 = pixmap.writable_addrF16(0, 1);
1479 for (int i = 0; i < 4; ++i) {
1480 pixel2[i] = storage[0][i];
1481 }
1482 bitmap.installPixels(pixmap);
1483 canvas->drawBitmap(bitmap, 4, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001484##
1485
1486#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addr64 addr() addrF16
1487
1488##
1489
1490#Subtopic Writable_Address ##
1491
Cary Clark78de7512018-02-07 07:27:09 -05001492#Subtopic Pixels
Cary Clark78de7512018-02-07 07:27:09 -05001493#Line # read and write pixel values ##
1494##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001495
1496# ------------------------------------------------------------------------------
1497
Cary Clarke80cd442018-07-17 13:19:56 -04001498#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05001499#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001500#Line # copies and converts pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001501
Cary Clarkd0530ba2017-09-14 11:25:39 -04001502Copies a Rect of pixels to dstPixels. Copy starts at (0, 0), and does not
Cary Clarkac47b882018-01-11 10:35:44 -05001503exceed Pixmap (width(), height()).
Cary Clark6fc50412017-09-21 12:31:06 -04001504
Cary Clark682c58d2018-05-16 07:07:07 -04001505dstInfo specifies width, height, Color_Type, Alpha_Type, and
Cary Clarkd0530ba2017-09-14 11:25:39 -04001506Color_Space of destination. dstRowBytes specifics the gap from one destination
1507row to the next. Returns true if pixels are copied. Returns false if
1508dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes.
1509
Cary Clarkac47b882018-01-11 10:35:44 -05001510Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001511kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001512If Pixmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match.
1513If Pixmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must
1514match. If Pixmap colorSpace is nullptr, dstInfo.colorSpace must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001515false if pixel conversion is not possible.
1516
Cary Clarkac47b882018-01-11 10:35:44 -05001517Returns false if Pixmap width() or height() is zero or negative.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001518
1519#Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ##
1520#Param dstPixels destination pixel storage ##
1521#Param dstRowBytes destination row length ##
1522
1523#Return true if pixels are copied to dstPixels ##
1524
1525#Example
1526#Height 128
1527#Description
1528Transferring the gradient from 8 bits per component to 4 bits per component
1529creates visible banding.
1530##
Cary Clark6fc50412017-09-21 12:31:06 -04001531 std::vector<int32_t> pixels;
1532 const int width = 256;
1533 const int height = 64;
1534 pixels.resize(height * width * 4);
1535 SkImageInfo srcInfo = SkImageInfo::MakeN32Premul(width, height);
1536 SkPixmap srcPixmap(srcInfo, (const void*) &pixels.front(), width * 4);
1537 SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 };
1538 SkPoint gradPoints[] = { { 0, 0 }, { 256, 0 } };
1539 SkPaint paint;
1540 paint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1541 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1542 SkBitmap bitmap;
1543 bitmap.installPixels(srcPixmap);
1544 SkCanvas srcCanvas(bitmap);
1545 srcCanvas.drawRect(SkRect::MakeWH(width, height), paint);
1546 canvas->drawBitmap(bitmap, 0, 0);
1547 std::vector<int32_t> dstPixels;
1548 dstPixels.resize(height * width * 2);
1549 SkImageInfo dstInfo = srcInfo.makeColorType(kARGB_4444_SkColorType);
1550 srcPixmap.readPixels(dstInfo, &dstPixels.front(), width * 2);
1551 SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2);
1552 bitmap.installPixels(dstPixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001553 canvas->drawBitmap(bitmap, 0, 128);
1554##
1555
1556#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1557
1558##
1559
1560# ------------------------------------------------------------------------------
1561
1562#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX,
Cary Clark682c58d2018-05-16 07:07:07 -04001563 int srcY) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001564
1565Copies a Rect of pixels to dstPixels. Copy starts at (srcX, srcY), and does not
Cary Clarkac47b882018-01-11 10:35:44 -05001566exceed Pixmap (width(), height()).
Cary Clark6fc50412017-09-21 12:31:06 -04001567
Cary Clark682c58d2018-05-16 07:07:07 -04001568dstInfo specifies width, height, Color_Type, Alpha_Type, and
Cary Clarkd0530ba2017-09-14 11:25:39 -04001569Color_Space of destination. dstRowBytes specifics the gap from one destination
1570row to the next. Returns true if pixels are copied. Returns false if
1571dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes.
1572
Cary Clarkac47b882018-01-11 10:35:44 -05001573Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001574kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001575If Pixmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match.
1576If Pixmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must
1577match. If Pixmap colorSpace is nullptr, dstInfo.colorSpace must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001578false if pixel conversion is not possible.
Cary Clark682c58d2018-05-16 07:07:07 -04001579
Cary Clarkd0530ba2017-09-14 11:25:39 -04001580srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clarkac47b882018-01-11 10:35:44 -05001581false if Pixmap width() or height() is zero or negative. Returns false if:
Cary Clark154beea2017-10-26 07:58:48 -04001582
Cary Clark2be81cf2018-09-13 12:04:30 -04001583#Formula # abs(srcX) >= Pixmap width() ##, or if #Formula # abs(srcY) >= Pixmap height() ##.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001584
1585#Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ##
1586#Param dstPixels destination pixel storage ##
1587#Param dstRowBytes destination row length ##
1588#Param srcX column index whose absolute value is less than width() ##
1589#Param srcY row index whose absolute value is less than height() ##
1590
1591#Return true if pixels are copied to dstPixels ##
1592
1593#Example
1594#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001595void draw(SkCanvas* canvas) {
1596 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1597 std::vector<int32_t> srcPixels;
1598 const int rowBytes = image->width() * 4;
1599 srcPixels.resize(image->height() * rowBytes);
1600 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1601 image->readPixels(pixmap, 0, 0);
1602 for (int offset : { 32, 64, 96 } ) {
1603 std::vector<int32_t> dstPixels;
1604 dstPixels.resize(image->height() * rowBytes);
1605 pixmap.readPixels(info, &dstPixels.front(), rowBytes, offset, 0);
1606 SkBitmap bitmap;
1607 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1608 bitmap.installPixels(dstmap);
1609 canvas->translate(32, 32);
1610 canvas->drawBitmap(bitmap, 0, 0);
1611 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001612}
1613##
1614
1615#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1616
1617##
1618
1619# ------------------------------------------------------------------------------
1620
Cary Clark682c58d2018-05-16 07:07:07 -04001621#Method bool readPixels(const SkPixmap& dst, int srcX, int srcY) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001622
1623Copies a Rect of pixels to dst. Copy starts at (srcX, srcY), and does not
Cary Clarkac47b882018-01-11 10:35:44 -05001624exceed Pixmap (width(), height()). dst specifies width, height, Color_Type,
Cary Clarkd0530ba2017-09-14 11:25:39 -04001625Alpha_Type, and Color_Space of destination. Returns true if pixels are copied.
1626Returns false if dst.addr() equals nullptr, or dst.rowBytes is less than
1627dst SkImageInfo::minRowBytes.
1628
Cary Clarkac47b882018-01-11 10:35:44 -05001629Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001630kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.info().colorType must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001631If Pixmap colorType is kGray_8_SkColorType, dst.info().colorSpace must match.
1632If Pixmap alphaType is kOpaque_SkAlphaType, dst.info().alphaType must
1633match. If Pixmap colorSpace is nullptr, dst.info().colorSpace must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001634false if pixel conversion is not possible.
Cary Clark682c58d2018-05-16 07:07:07 -04001635
Cary Clarkd0530ba2017-09-14 11:25:39 -04001636srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clarkac47b882018-01-11 10:35:44 -05001637false Pixmap width() or height() is zero or negative. Returns false if:
Cary Clark154beea2017-10-26 07:58:48 -04001638
Cary Clark2be81cf2018-09-13 12:04:30 -04001639#Formula # abs(srcX) >= Pixmap width() ##, or if #Formula # abs(srcY) >= Pixmap height() ##.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001640
1641#Param dst Image_Info and pixel address to write to ##
1642#Param srcX column index whose absolute value is less than width() ##
1643#Param srcY row index whose absolute value is less than height() ##
1644
1645#Return true if pixels are copied to dst ##
1646
1647#Example
1648#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001649void draw(SkCanvas* canvas) {
1650 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1651 std::vector<int32_t> srcPixels;
1652 const int rowBytes = image->width() * 4;
1653 srcPixels.resize(image->height() * rowBytes);
1654 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1655 image->readPixels(pixmap, 0, 0);
1656 for (int offset : { 32, 64, 96 } ) {
1657 std::vector<int32_t> dstPixels;
1658 dstPixels.resize(image->height() * rowBytes);
1659 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1660 pixmap.readPixels(dstmap, offset, 0);
1661 SkBitmap bitmap;
1662 bitmap.installPixels(dstmap);
1663 canvas->translate(32, 32);
1664 canvas->drawBitmap(bitmap, 0, 0);
1665 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001666}
1667##
1668
1669#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1670
1671##
1672
1673# ------------------------------------------------------------------------------
1674
Cary Clark682c58d2018-05-16 07:07:07 -04001675#Method bool readPixels(const SkPixmap& dst) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001676
1677Copies pixels inside bounds() to dst. dst specifies width, height, Color_Type,
1678Alpha_Type, and Color_Space of destination. Returns true if pixels are copied.
1679Returns false if dst.addr() equals nullptr, or dst.rowBytes is less than
1680dst SkImageInfo::minRowBytes.
1681
Cary Clarkac47b882018-01-11 10:35:44 -05001682Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001683kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001684If Pixmap colorType is kGray_8_SkColorType, dst Color_Space must match.
1685If Pixmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must
1686match. If Pixmap colorSpace is nullptr, dst Color_Space must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001687false if pixel conversion is not possible.
Cary Clark682c58d2018-05-16 07:07:07 -04001688
Cary Clarkac47b882018-01-11 10:35:44 -05001689Returns false if Pixmap width() or height() is zero or negative.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001690
1691#Param dst Image_Info and pixel address to write to ##
1692
1693#Return true if pixels are copied to dst ##
1694
1695#Example
1696#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001697void draw(SkCanvas* canvas) {
1698 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1699 std::vector<int32_t> srcPixels;
1700 const int rowBytes = image->width() * 4;
1701 srcPixels.resize(image->height() * rowBytes);
1702 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1703 image->readPixels(pixmap, 0, 0);
1704 for (int index = 0; index < 3; ++index ) {
1705 std::vector<int32_t> dstPixels;
1706 dstPixels.resize(image->height() * rowBytes);
1707 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1708 pixmap.readPixels(dstmap);
1709 SkBitmap bitmap;
1710 bitmap.installPixels(dstmap);
1711 canvas->translate(32, 32);
1712 canvas->drawBitmap(bitmap, 0, 0);
1713 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001714}
1715##
1716
1717#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1718
1719##
1720
1721# ------------------------------------------------------------------------------
1722
1723#Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality) const
1724
Cary Clark78de7512018-02-07 07:27:09 -05001725#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001726#Line # scales and converts pixels ##
Cary Clarkac47b882018-01-11 10:35:44 -05001727Copies Bitmap to dst, scaling pixels to fit dst.width() and dst.height(), and
Cary Clarkd0530ba2017-09-14 11:25:39 -04001728converting pixels to match dst.colorType and dst.alphaType. Returns true if
1729pixels are copied. Returns false if dst.addr() is nullptr, or dst.rowBytes is
1730less than dst SkImageInfo::minRowBytes.
1731
Cary Clarkac47b882018-01-11 10:35:44 -05001732Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001733kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001734If Pixmap colorType is kGray_8_SkColorType, dst Color_Space must match.
1735If Pixmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must
1736match. If Pixmap colorSpace is nullptr, dst Color_Space must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001737false if pixel conversion is not possible.
1738
Cary Clarkac47b882018-01-11 10:35:44 -05001739Returns false if Bitmap width() or height() is zero or negative.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001740
1741Scales the image, with filterQuality, to match dst.width() and dst.height().
1742filterQuality kNone_SkFilterQuality is fastest, typically implemented with
1743Filter_Quality_Nearest_Neighbor. kLow_SkFilterQuality is typically implemented with
1744Filter_Quality_Bilerp. kMedium_SkFilterQuality is typically implemented with
1745Filter_Quality_Bilerp, and Filter_Quality_MipMap when size is reduced.
1746kHigh_SkFilterQuality is slowest, typically implemented with Filter_Quality_BiCubic.
1747
1748#Param dst Image_Info and pixel address to write to ##
Cary Clark682c58d2018-05-16 07:07:07 -04001749#Param filterQuality one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
Cary Clarkd0530ba2017-09-14 11:25:39 -04001750 kMedium_SkFilterQuality, kHigh_SkFilterQuality
1751##
1752
Cary Clarkac47b882018-01-11 10:35:44 -05001753#Return true if pixels are scaled to fit dst ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001754
1755#Example
1756#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001757void draw(SkCanvas* canvas) {
1758 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1759 std::vector<int32_t> srcPixels;
1760 int rowBytes = image->width() * 4;
1761 srcPixels.resize(image->height() * rowBytes);
1762 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1763 image->readPixels(pixmap, 0, 0);
1764 for (int offset : { 32, 64, 96 } ) {
1765 info = SkImageInfo::MakeN32Premul(image->width() + offset, image->height());
1766 rowBytes = info.width() * 4;
1767 std::vector<int32_t> dstPixels;
1768 dstPixels.resize(image->height() * rowBytes);
1769 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1770 pixmap.scalePixels(dstmap, kMedium_SkFilterQuality);
1771 SkBitmap bitmap;
1772 bitmap.installPixels(dstmap);
1773 canvas->translate(32, 32);
1774 canvas->drawBitmap(bitmap, 0, 0);
1775 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001776}
1777##
1778
1779#SeeAlso SkCanvas::drawBitmap SkImage::scalePixels
1780
1781##
1782
1783# ------------------------------------------------------------------------------
1784
1785#Method bool erase(SkColor color, const SkIRect& subset) const
1786
Cary Clark78de7512018-02-07 07:27:09 -05001787#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001788#Line # writes Color to pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001789Writes color to pixels bounded by subset; returns true on success.
1790Returns false if colorType is kUnknown_SkColorType, or if subset does
1791not intersect bounds().
Cary Clark682c58d2018-05-16 07:07:07 -04001792
Cary Clarkd0530ba2017-09-14 11:25:39 -04001793#Param color Unpremultiplied Color to write ##
1794#Param subset bounding integer Rect of written pixels ##
1795
1796#Return true if pixels are changed ##
1797
1798#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001799#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001800 uint32_t storage[2];
1801 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1802 SkPixmap pixmap(info, storage, info.minRowBytes());
1803 pixmap.erase(SK_ColorBLUE, {0, 0, 1, 1});
1804 pixmap.erase(SK_ColorRED, {0, 1, 1, 2});
1805 SkBitmap bitmap;
1806 canvas->scale(20, 20);
1807 bitmap.installPixels(pixmap);
1808 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001809##
1810
1811#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1812
1813##
1814
1815# ------------------------------------------------------------------------------
1816
Cary Clark682c58d2018-05-16 07:07:07 -04001817#Method bool erase(SkColor color) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001818
1819Writes color to pixels inside bounds(); returns true on success.
1820Returns false if colorType is kUnknown_SkColorType, or if bounds()
1821is empty.
1822
1823#Param color Unpremultiplied Color to write ##
1824
1825#Return true if pixels are changed ##
1826
1827#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001828#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001829 uint32_t storage[2];
1830 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1831 SkPixmap pixmap(info, storage, info.minRowBytes());
1832 pixmap.erase(SK_ColorBLUE);
1833 SkBitmap bitmap;
1834 canvas->scale(20, 20);
1835 bitmap.installPixels(pixmap);
1836 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001837##
1838
1839#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1840
1841##
1842
1843# ------------------------------------------------------------------------------
1844
1845#Method bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const
1846
1847Writes color to pixels bounded by subset; returns true on success.
1848if subset is nullptr, writes colors pixels inside bounds(). Returns false if
1849colorType is kUnknown_SkColorType, if subset is not nullptr and does
1850not intersect bounds(), or if subset is nullptr and bounds() is empty.
1851
1852#Param color Unpremultiplied Color to write ##
1853#Param subset bounding integer Rect of pixels to write; may be nullptr ##
1854
1855#Return true if pixels are changed ##
1856
1857#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001858#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001859 uint32_t storage[2];
1860 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1861 SkPixmap pixmap(info, storage, info.minRowBytes());
1862 SkIRect topPixelBounds = {0, 0, 1, 1};
1863 pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds);
1864 SkIRect bottomPixelBounds = {0, 1, 1, 2};
1865 pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds);
1866 SkBitmap bitmap;
1867 canvas->scale(20, 20);
1868 bitmap.installPixels(pixmap);
1869 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001870##
1871
1872#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1873
1874##
1875
Cary Clarkd0530ba2017-09-14 11:25:39 -04001876#Class SkPixmap ##
1877
1878#Topic Pixmap ##