blob: 86d89e53d1fd6f7b31bf4f554fac744b99339e3d [file] [log] [blame]
Cary Clarkd0530ba2017-09-14 11:25:39 -04001#Topic Pixmap
Cary Clarke4aa3712017-09-15 02:56:12 -04002#Alias Pixmap_Reference
3
Cary Clark08895c42018-02-01 09:37:32 -05004#Subtopic Overview
Cary Clark4855f782018-02-06 09:41:53 -05005 #Subtopic Subtopic
Cary Clark08895c42018-02-01 09:37:32 -05006 #Populate
7 ##
8##
9
Cary Clarkd0530ba2017-09-14 11:25:39 -040010#Class SkPixmap
11
12Pixmap provides a utility to pair SkImageInfo with pixels and row bytes.
13Pixmap is a low level class which provides convenience functions to access
14raster destinations. Canvas can not draw Pixmap, nor does Pixmap provide
15a direct drawing destination.
16
17Use Bitmap to draw pixels referenced by Pixmap; use Surface to draw into
18pixels referenced by Pixmap.
19
Cary Clarkbc5697d2017-10-04 14:31:33 -040020Pixmap does not try to manage the lifetime of the pixel memory. Use Pixel_Ref
21to manage pixel memory; Pixel_Ref is safe across threads.
Cary Clarkd0530ba2017-09-14 11:25:39 -040022
Cary Clark4855f782018-02-06 09:41:53 -050023#Subtopic Related_Function
Cary Clark08895c42018-02-01 09:37:32 -050024#Populate
Cary Clark5081eed2018-01-22 07:55:48 -050025##
26
Cary Clark4855f782018-02-06 09:41:53 -050027#Subtopic Constructor
Cary Clark08895c42018-02-01 09:37:32 -050028#Populate
29##
Cary Clarkd0530ba2017-09-14 11:25:39 -040030
Cary Clark4855f782018-02-06 09:41:53 -050031#Subtopic Member_Function
Cary Clark08895c42018-02-01 09:37:32 -050032#Populate
33##
Cary Clarkd0530ba2017-09-14 11:25:39 -040034
35#Subtopic Initialization
Cary Clark08895c42018-02-01 09:37:32 -050036#Line # sets fields for use ##
Cary Clarkd0530ba2017-09-14 11:25:39 -040037
38# ------------------------------------------------------------------------------
39
40#Method SkPixmap()
41
Cary Clarkab2621d2018-01-30 10:08:57 -050042#In Initialization
43#Line # constructs with default values ##
Cary Clarkd0530ba2017-09-14 11:25:39 -040044Creates an empty Pixmap without pixels, with kUnknown_SkColorType, with
45kUnknown_SkAlphaType, and with a width and height of zero. Use
46reset() to associate pixels, SkColorType, SkAlphaType, width, and height
47after Pixmap has been created.
48
49#Return empty Pixmap ##
50
51#Example
Cary Clark6fc50412017-09-21 12:31:06 -040052void draw(SkCanvas* canvas) {
53 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
Cary Clarkab2621d2018-01-30 10:08:57 -050054 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
55 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -040056 SkPixmap pixmap;
57 for (int i = 0; i < 2; ++i) {
58 SkDebugf("width: %2d height: %2d", pixmap.width(), pixmap.height());
59 SkDebugf(" color: k%s_SkColorType", colors[pixmap.colorType()]);
60 SkDebugf(" alpha: k%s_SkAlphaType\n", alphas[pixmap.alphaType()]);
61 pixmap.reset(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType),
62 nullptr, 0);
63 }
Cary Clarkd0530ba2017-09-14 11:25:39 -040064}
65#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -040066width: 0 height: 0 color: kUnknown_SkColorType alpha: kUnknown_SkAlphaType
Cary Clarkd0530ba2017-09-14 11:25:39 -040067width: 25 height: 35 color: kRGBA_8888_SkColorType alpha: kOpaque_SkAlphaType
68##
69##
70
71#SeeAlso SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) reset() SkAlphaType SkColorType
72
73##
74
75# ------------------------------------------------------------------------------
76
77#Method SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes)
78
Cary Clarkab2621d2018-01-30 10:08:57 -050079#In Initialization
80#Line # constructs from Image_Info, pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -040081Creates Pixmap from info width, height, SkAlphaType, and SkColorType.
Cary Clark6fc50412017-09-21 12:31:06 -040082addr points to pixels, or nullptr. rowBytes should be info.width() times
83info.bytesPerPixel(), or larger.
Cary Clarkd0530ba2017-09-14 11:25:39 -040084
85No parameter checking is performed; it is up to the caller to ensure that
86addr and rowBytes agree with info.
87
Cary Clark6fc50412017-09-21 12:31:06 -040088The memory lifetime of pixels is managed by the caller. When Pixmap goes
Cary Clarkd0530ba2017-09-14 11:25:39 -040089out of scope, addr is unaffected.
90
91Pixmap may be later modified by reset() to change its size, pixel type, or
92storage.
93
94#Param info width, height, SkAlphaType, SkColorType of Image_Info ##
95#Param addr pointer to pixels allocated by caller; may be nullptr ##
96#Param rowBytes size of one row of addr; width times pixel size, or larger ##
97
98#Return initialized Pixmap ##
99
100#Example
101#Image 3
102#Description
103SkImage::MakeRasterCopy takes const SkPixmap& as an argument. The example
104constructs a SkPixmap from the brace-delimited parameters.
105##
Cary Clark6fc50412017-09-21 12:31:06 -0400106 SkDebugf("image alpha only = %s\n", image->isAlphaOnly() ? "true" : "false");
107 SkPMColor pmColors = 0;
108 sk_sp<SkImage> copy = SkImage::MakeRasterCopy({SkImageInfo::MakeA8(1, 1),
109 (uint8_t*)&pmColors,
110 1});
Cary Clarkd0530ba2017-09-14 11:25:39 -0400111 SkDebugf("copy alpha only = %s\n", copy->isAlphaOnly() ? "true" : "false");
112#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400113image alpha only = false
Cary Clarkd0530ba2017-09-14 11:25:39 -0400114copy alpha only = true
115##
116##
117
118#SeeAlso SkPixmap() reset() SkAlphaType SkColorType
119
120##
121
122# ------------------------------------------------------------------------------
123
124#Method void reset()
125
Cary Clarkab2621d2018-01-30 10:08:57 -0500126#In Initialization
127#Line # reuses existing Pixmap with replacement values ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400128Sets width, height, row bytes to zero; pixel address to nullptr; SkColorType to
129kUnknown_SkColorType; and SkAlphaType to kUnknown_SkAlphaType.
130
131The prior pixels are unaffected; it is up to the caller to release pixels
132memory if desired.
133
134#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400135void draw(SkCanvas* canvas) {
136 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
Cary Clarkab2621d2018-01-30 10:08:57 -0500137 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
138 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -0400139 SkPixmap pixmap(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType),
140 nullptr, 0);
141 for (int i = 0; i < 2; ++i) {
142 SkDebugf("width: %2d height: %2d", pixmap.width(), pixmap.height());
143 SkDebugf(" color: k%s_SkColorType", colors[pixmap.colorType()]);
144 SkDebugf(" alpha: k%s_SkAlphaType\n", alphas[pixmap.alphaType()]);
145 pixmap.reset();
146 }
147}
Cary Clarkd0530ba2017-09-14 11:25:39 -0400148#StdOut
149width: 25 height: 35 color: kRGBA_8888_SkColorType alpha: kOpaque_SkAlphaType
Cary Clark6fc50412017-09-21 12:31:06 -0400150width: 0 height: 0 color: kUnknown_SkColorType alpha: kUnknown_SkAlphaType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400151##
152##
153
154#SeeAlso SkPixmap() SkAlphaType SkColorType
155
156##
157
158# ------------------------------------------------------------------------------
159
160#Method void reset(const SkImageInfo& info, const void* addr, size_t rowBytes)
161
Cary Clarkab2621d2018-01-30 10:08:57 -0500162#In Initialization
Cary Clarkd0530ba2017-09-14 11:25:39 -0400163Sets width, height, SkAlphaType, and SkColorType from info.
164Sets pixel address from addr, which may be nullptr.
Cary Clark6fc50412017-09-21 12:31:06 -0400165Sets row bytes from rowBytes, which should be info.width() times
166info.bytesPerPixel(), or larger.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400167
168Does not check addr. Asserts if built with SK_DEBUG defined and if rowBytes is
169too small to hold one row of pixels.
170
171The memory lifetime pixels are managed by the caller. When Pixmap goes
172out of scope, addr is unaffected.
173
174#Param info width, height, SkAlphaType, SkColorType of Image_Info ##
175#Param addr pointer to pixels allocated by caller; may be nullptr ##
176#Param rowBytes size of one row of addr; width times pixel size, or larger ##
177
178#Example
179#Image 4
Cary Clark2ade9972017-11-02 17:49:34 -0400180#Height 64
Cary Clark6fc50412017-09-21 12:31:06 -0400181void draw(SkCanvas* canvas) {
182 std::vector<int32_t> pixels;
183 pixels.resize(image->height() * image->width() * 4);
184 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
185 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
186 image->readPixels(pixmap, 0, 0);
187 int x = 0;
188 for (auto colorType : { kRGBA_8888_SkColorType, kBGRA_8888_SkColorType } ) {
189 pixmap.reset(SkImageInfo::Make(image->width(), image->height(), colorType,
190 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
191 SkBitmap bitmap;
192 bitmap.installPixels(pixmap);
193 canvas->drawBitmap(bitmap, x, 0);
194 x += 128;
195 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400196}
197##
198
199#SeeAlso SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) reset() SkAlphaType SkColorType
200
201##
202
203# ------------------------------------------------------------------------------
204
205#Method void setColorSpace(sk_sp<SkColorSpace> colorSpace)
206
Cary Clarkab2621d2018-01-30 10:08:57 -0500207#In Initialization
208#Line # sets Image_Info Color_Space ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400209
210Changes Color_Space in Image_Info; preserves width, height, SkAlphaType, and
211SkColorType in Image, and leaves pixel address and row bytes unchanged.
Cary Clark6fc50412017-09-21 12:31:06 -0400212Color_Space reference count is incremented.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400213
214#Param colorSpace Color_Space moved to Image_Info ##
215
216#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400217void draw(SkCanvas* canvas) {
218 SkPixmap pixmap;
219 sk_sp<SkColorSpace> colorSpace1 = SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma,
220 SkColorSpace::kRec2020_Gamut);
221 SkDebugf("is %sunique\n", colorSpace1->unique() ? "" : "not ");
222 pixmap.setColorSpace(colorSpace1);
223 SkDebugf("is %sunique\n", colorSpace1->unique() ? "" : "not ");
Cary Clarkd0530ba2017-09-14 11:25:39 -0400224}
225#StdOut
226is unique
227is not unique
228##
229##
230
231#SeeAlso Color_Space SkImageInfo::makeColorSpace
232
233##
234
235# ------------------------------------------------------------------------------
236
237#Method bool SK_WARN_UNUSED_RESULT reset(const SkMask& mask)
Cary Clark4855f782018-02-06 09:41:53 -0500238#Deprecated soon
Cary Clarkd0530ba2017-09-14 11:25:39 -0400239##
240
241# ------------------------------------------------------------------------------
242
243#Method bool SK_WARN_UNUSED_RESULT extractSubset(SkPixmap* subset, const SkIRect& area) const
244
Cary Clarkab2621d2018-01-30 10:08:57 -0500245#In Initialization
246#Line # sets pointer to portion of original ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400247Sets subset width, height, pixel address to intersection of Pixmap with area,
248if intersection is not empty; and return true. Otherwise, leave subset unchanged
249and return false.
250
251Failing to read the return value generates a compile time warning.
252
253#Param subset storage for width, height, pixel address of intersection ##
254#Param area bounds to intersect with Pixmap ##
255
256#Return true if intersection of Pixmap and area is not empty ##
257
258#Example
259#Image 3
260#Height 128
Cary Clark6fc50412017-09-21 12:31:06 -0400261void draw(SkCanvas* canvas) {
262 std::vector<int32_t> pixels;
263 pixels.resize(image->height() * image->width() * 4);
264 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
265 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
266 image->readPixels(pixmap, 0, 0);
267 SkPixmap inset;
268 if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
269 SkBitmap bitmap;
270 bitmap.installPixels(inset);
271 canvas->drawBitmap(bitmap, 0, 0);
272 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400273}
274##
275
276#SeeAlso reset() SkIRect::intersect
277
278##
279
280#Subtopic Initialization ##
281
282#Subtopic Image_Info_Access
Cary Clark08895c42018-02-01 09:37:32 -0500283#Line # returns all or part of Image_Info ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400284
285# ------------------------------------------------------------------------------
286
287#Method const SkImageInfo& info() const
288
Cary Clarkab2621d2018-01-30 10:08:57 -0500289#In Image_Info_Access
290#Line # returns Image_Info ##
Cary Clark6fc50412017-09-21 12:31:06 -0400291Returns width, height, Alpha_Type, Color_Type, and Color_Space.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400292
293#Return reference to ImageInfo ##
294
295#Example
296#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -0400297 std::vector<int32_t> pixels;
298 pixels.resize(image->height() * image->width() * 4);
299 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
300 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
301 image->readPixels(pixmap, 0, 0);
302 SkPixmap inset;
303 if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
304 const SkImageInfo& info = inset.info();
305 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
Cary Clarkab2621d2018-01-30 10:08:57 -0500306 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888",
307 "RGB_888x", "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -0400308 SkDebugf("width: %d height: %d color: %s alpha: %s\n", info.width(), info.height(),
309 colors[info.colorType()], alphas[info.alphaType()]);
310 }
311#StdOut
312width: 384 height: 384 color: BGRA_8888 alpha: Opaque
313##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400314##
315
316#SeeAlso Image_Info
317
318##
319
320# ------------------------------------------------------------------------------
321
322#Method size_t rowBytes() const
323
Cary Clarkab2621d2018-01-30 10:08:57 -0500324#In Image_Info_Access
325#Line # returns interval between rows in bytes ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400326Returns row bytes, the interval from one pixel row to the next. Row bytes
Cary Clark154beea2017-10-26 07:58:48 -0400327is at least as large as:
Cary Clarkd0530ba2017-09-14 11:25:39 -0400328#Formula
329width() * info().bytesPerPixel()
330##
331.
332
Cary Clarkbc5697d2017-10-04 14:31:33 -0400333Returns zero if colorType is kUnknown_SkColorType.
334It is up to the Bitmap creator to ensure that row bytes is a useful value.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400335
336#Return byte length of pixel row ##
337
338#Example
339SkPixmap badPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 2};
340SkPixmap okPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 8};
341for (auto& pixmap : { badPixmap, okPixmap } ) {
342 SkDebugf("rowBytes: %d minRowBytes: %d\n", pixmap.rowBytes(),
343 pixmap.info().minRowBytes());
344}
345#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400346rowBytes: 2 minRowBytes: 4
Cary Clarkd0530ba2017-09-14 11:25:39 -0400347rowBytes: 8 minRowBytes: 4
348##
349##
350
351#SeeAlso addr() info() SkImageInfo::minRowBytes
352
353##
354
355# ------------------------------------------------------------------------------
356
357#Method const void* addr() const
358
Cary Clarkab2621d2018-01-30 10:08:57 -0500359#In Image_Info_Access
360#Line # returns readable pixel address as void pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -0400361Returns pixel address, the base address corresponding to the pixel origin.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400362
363It is up to the Pixmap creator to ensure that pixel address is a useful value.
364
365#Return pixel address ##
366
367#Example
368#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -0400369 std::vector<int32_t> pixels;
370 pixels.resize(image->height() * image->width() * 4);
371 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
372 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
373 image->readPixels(pixmap, 0, 0);
374 SkDebugf("pixels address: 0x%llx\n", pixmap.addr());
375 SkPixmap inset;
376 if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
377 SkDebugf("inset address: 0x%llx\n", inset.addr());
378 }
379#StdOut
380#Volatile
381pixels address: 0x7f2a440bb010
382inset address: 0x7f2a440fb210
383##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400384##
385
386#SeeAlso addr(int x, int y) addr8 addr16 addr32 addr64 info() rowBytes()
387
388##
389
390# ------------------------------------------------------------------------------
391
392#Method int width() const
393
Cary Clarkab2621d2018-01-30 10:08:57 -0500394#In Image_Info_Access
395#Line # returns pixel column count ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400396Returns pixel count in each pixel row. Should be equal or less than:
Cary Clark154beea2017-10-26 07:58:48 -0400397
Cary Clarkd0530ba2017-09-14 11:25:39 -0400398#Formula
Cary Clarkbc5697d2017-10-04 14:31:33 -0400399rowBytes() / info().bytesPerPixel()
Cary Clarkd0530ba2017-09-14 11:25:39 -0400400##
401.
402
403#Return pixel width in Image_Info ##
404
405#Example
406 SkImageInfo info = SkImageInfo::MakeA8(16, 32);
Cary Clark6fc50412017-09-21 12:31:06 -0400407 SkPixmap pixmap(info, nullptr, 64);
408 SkDebugf("pixmap width: %d info width: %d\n", pixmap.width(), info.width());
409#StdOut
410pixmap width: 16 info width: 16
411##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400412##
413
Cary Clarkbc5697d2017-10-04 14:31:33 -0400414#SeeAlso height() SkImageInfo::width()
Cary Clarkd0530ba2017-09-14 11:25:39 -0400415
416##
417
418# ------------------------------------------------------------------------------
419
420#Method int height() const
421
Cary Clarkab2621d2018-01-30 10:08:57 -0500422#In Image_Info_Access
423#Line # returns pixel row count ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400424Returns pixel row count.
425
426#Return pixel height in Image_Info ##
427
428#Example
Cary Clarkbc5697d2017-10-04 14:31:33 -0400429 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
430 SkDebugf("pixmap height: %d info height: %d\n", pixmap.height(), pixmap.info().height());
Cary Clark6fc50412017-09-21 12:31:06 -0400431#StdOut
432pixmap height: 32 info height: 32
433##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400434##
435
Cary Clarkbc5697d2017-10-04 14:31:33 -0400436#SeeAlso width() ImageInfo::height()
Cary Clarkd0530ba2017-09-14 11:25:39 -0400437
438##
439
440# ------------------------------------------------------------------------------
441
442#Method SkColorType colorType() const
443
Cary Clarkab2621d2018-01-30 10:08:57 -0500444#In Image_Info_Access
445#Line # returns Image_Info Color_Type ##
Cary Clark1a8d7622018-03-05 13:26:16 -0500446Returns Color_Type, one of: #list_of_color_types#.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400447
448#Return Color_Type in Image_Info ##
449
450#Example
Cary Clarkab2621d2018-01-30 10:08:57 -0500451 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
452 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -0400453 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
454 SkDebugf("color type: k" "%s" "_SkColorType\n", colors[pixmap.colorType()]);
455#StdOut
Cary Clarkab2621d2018-01-30 10:08:57 -0500456color type: kAlpha_8_SkColorType
Cary Clark6fc50412017-09-21 12:31:06 -0400457##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400458##
459
Cary Clarkbc5697d2017-10-04 14:31:33 -0400460#SeeAlso alphaType() SkImageInfo::colorType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400461
462##
463
464# ------------------------------------------------------------------------------
465
466#Method SkAlphaType alphaType() const
467
Cary Clarkab2621d2018-01-30 10:08:57 -0500468#In Image_Info_Access
469#Line # returns Image_Info Alpha_Type ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400470Returns Alpha_Type, one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType,
471kPremul_SkAlphaType, kUnpremul_SkAlphaType.
472
473#Return Alpha_Type in Image_Info ##
474
475#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400476 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
477 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
478 SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[pixmap.alphaType()]);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400479#StdOut
480alpha type: kPremul_SkAlphaType
481##
482##
483
Cary Clarkbc5697d2017-10-04 14:31:33 -0400484#SeeAlso colorType() SkImageInfo::alphaType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400485
486##
487
488# ------------------------------------------------------------------------------
489
490#Method SkColorSpace* colorSpace() const
491
Cary Clarkab2621d2018-01-30 10:08:57 -0500492#In Image_Info_Access
493#Line # returns Image_Info Color_Space ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400494Returns Color_Space associated with Image_Info. The
495reference count of Color_Space is unchanged. The returned Color_Space is
496immutable.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400497
Cary Clarkbc5697d2017-10-04 14:31:33 -0400498#Return Color_Space, the range of colors, in Image_Info ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400499
500#Example
501#Description
502SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma
503and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma.
504##
Cary Clark6fc50412017-09-21 12:31:06 -0400505 SkPixmap pixmap(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
506 SkColorSpace::MakeSRGBLinear()), nullptr, 64);
507 SkColorSpace* colorSpace = pixmap.colorSpace();
508 SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
509 colorSpace->gammaCloseToSRGB() ? "true" : "false",
510 colorSpace->gammaIsLinear() ? "true" : "false",
511 colorSpace->isSRGB() ? "true" : "false");
512#StdOut
513gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
514##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400515##
516
Cary Clarkbc5697d2017-10-04 14:31:33 -0400517#SeeAlso Color_Space SkImageInfo::colorSpace
Cary Clarkd0530ba2017-09-14 11:25:39 -0400518
519##
520
521# ------------------------------------------------------------------------------
522
523#Method bool isOpaque() const
524
Cary Clarkab2621d2018-01-30 10:08:57 -0500525#In Image_Info_Access
526#Line # returns true if Image_Info describes opaque pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400527Returns true if Alpha_Type is kOpaque_SkAlphaType.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400528Does not check if Color_Type allows Alpha, or if any pixel value has
529transparency.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400530
531#Return true if Image_Info has opaque Alpha_Type ##
532
533#Example
534#Description
535 isOpaque ignores whether all pixels are opaque or not.
536##
Cary Clark6fc50412017-09-21 12:31:06 -0400537 std::vector<uint32_t> pixels;
538 const int height = 2;
539 const int width = 2;
540 pixels.resize(height * width * 4);
541 SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType,
542 kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4);
543 for (int index = 0; index < 2; ++index) {
544 pixmap.erase(0x00000000);
545 SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false");
546 pixmap.erase(0xFFFFFFFF);
547 SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false");
548 pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType),
549 (const void*) &pixels.front(), width * 4);
550 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400551#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400552isOpaque: false
553isOpaque: false
554isOpaque: true
Cary Clarkd0530ba2017-09-14 11:25:39 -0400555isOpaque: true
556##
557##
558
559#SeeAlso computeIsOpaque SkImageInfo::isOpaque
560
561##
562
563# ------------------------------------------------------------------------------
564
565#Method SkIRect bounds() const
566
Cary Clarkab2621d2018-01-30 10:08:57 -0500567#In Image_Info_Access
568#Line # returns width and height as Rectangle ##
Cary Clark154beea2017-10-26 07:58:48 -0400569Returns IRect { 0, 0, width(), height() }.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400570
571#Return integral rectangle from origin to width() and height() ##
572
573#Example
574 for (int width : { 0, 2 } ) {
575 for (int height : { 0, 2 } ) {
Cary Clark6fc50412017-09-21 12:31:06 -0400576 SkPixmap pixmap(SkImageInfo::MakeA8(width, height), nullptr, width);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400577 SkDebugf("width: %d height: %d empty: %s\n", width, height,
578 pixmap.bounds().isEmpty() ? "true" : "false");
579 }
580 }
581#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400582width: 0 height: 0 empty: true
583width: 0 height: 2 empty: true
584width: 2 height: 0 empty: true
Cary Clarkd0530ba2017-09-14 11:25:39 -0400585width: 2 height: 2 empty: false
586##
587##
588
589#SeeAlso height() width() IRect
590
591##
592
593# ------------------------------------------------------------------------------
594
595#Method int rowBytesAsPixels() const
596
Cary Clarkab2621d2018-01-30 10:08:57 -0500597#In Image_Info_Access
598#Line # returns interval between rows in pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400599
600Returns number of pixels that fit on row. Should be greater than or equal to
601width().
602
603#Return maximum pixels per row ##
604
605#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400606 for (int rowBytes : { 4, 5, 6, 7, 8} ) {
607 SkPixmap pixmap(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), nullptr, rowBytes);
608 SkDebugf("rowBytes: %d rowBytesAsPixels: %d\n", rowBytes, pixmap.rowBytesAsPixels());
609 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400610#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400611rowBytes: 4 rowBytesAsPixels: 1
612rowBytes: 5 rowBytesAsPixels: 1
613rowBytes: 6 rowBytesAsPixels: 1
614rowBytes: 7 rowBytesAsPixels: 1
Cary Clarkd0530ba2017-09-14 11:25:39 -0400615rowBytes: 8 rowBytesAsPixels: 2
616##
617##
618
619#SeeAlso rowBytes shiftPerPixel width SkImageInfo::bytesPerPixel
620
621##
622
623# ------------------------------------------------------------------------------
624
625#Method int shiftPerPixel() const
626
Cary Clarkab2621d2018-01-30 10:08:57 -0500627#In Image_Info_Access
628#Line # returns bit shift from pixels to bytes ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400629Returns bit shift converting row bytes to row pixels.
630Returns zero for kUnknown_SkColorType.
631
632#Return one of: 0, 1, 2, 3; left shift to convert pixels to bytes ##
633
634#Example
Cary Clarkab2621d2018-01-30 10:08:57 -0500635 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
636 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -0400637 SkImageInfo info = SkImageInfo::MakeA8(1, 1);
638 for (SkColorType colorType : { kUnknown_SkColorType, kAlpha_8_SkColorType,
639 kRGB_565_SkColorType, kARGB_4444_SkColorType,
640 kRGBA_8888_SkColorType, kBGRA_8888_SkColorType,
641 kGray_8_SkColorType, kRGBA_F16_SkColorType } ) {
642 SkPixmap pixmap(info.makeColorType(colorType), nullptr, 4);
643 SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d shiftPerPixel: %d\n",
644 colors[colorType], 10 - strlen(colors[colorType]), " ",
645 pixmap.info().bytesPerPixel(), pixmap.shiftPerPixel());
646 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400647#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400648color: kUnknown_SkColorType bytesPerPixel: 0 shiftPerPixel: 0
Cary Clarkab2621d2018-01-30 10:08:57 -0500649color: kAlpha_8_SkColorType bytesPerPixel: 1 shiftPerPixel: 0
Cary Clark6fc50412017-09-21 12:31:06 -0400650color: kRGB_565_SkColorType bytesPerPixel: 2 shiftPerPixel: 1
651color: kARGB_4444_SkColorType bytesPerPixel: 2 shiftPerPixel: 1
652color: kRGBA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2
653color: kBGRA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2
654color: kGray_8_SkColorType bytesPerPixel: 1 shiftPerPixel: 0
Cary Clarkd0530ba2017-09-14 11:25:39 -0400655color: kRGBA_F16_SkColorType bytesPerPixel: 8 shiftPerPixel: 3
656##
657##
658
659#SeeAlso rowBytes rowBytesAsPixels width SkImageInfo::bytesPerPixel
660
661##
662
663# ------------------------------------------------------------------------------
664
Cary Clarkbc5697d2017-10-04 14:31:33 -0400665#Method size_t computeByteSize() const
666
Cary Clarkab2621d2018-01-30 10:08:57 -0500667#In Image_Info_Access
668#Line # returns size required for pixels ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400669Returns minimum memory required for pixel storage.
670Does not include unused memory on last row when rowBytesAsPixels exceeds width().
671Returns zero if result does not fit in size_t.
672Returns zero if height() or width() is 0.
673Returns height() times rowBytes if colorType is kUnknown_SkColorType.
674
675#Return size in bytes of image buffer ##
676
Cary Clarkd0530ba2017-09-14 11:25:39 -0400677#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400678 SkPixmap pixmap;
679 for (int width : { 1, 1000, 1000000 } ) {
680 for (int height: { 1, 1000, 1000000 } ) {
681 SkImageInfo imageInfo = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType);
Cary Clarkbc5697d2017-10-04 14:31:33 -0400682 pixmap.reset(imageInfo, nullptr, width * 5);
683 SkDebugf("width: %7d height: %7d computeByteSize: %13lld\n", width, height,
684 pixmap.computeByteSize());
Cary Clark6fc50412017-09-21 12:31:06 -0400685 }
686 }
Cary Clark6fc50412017-09-21 12:31:06 -0400687#StdOut
Ben Wagner29380bd2017-10-09 14:43:00 -0400688width: 1 height: 1 computeByteSize: 4
689width: 1 height: 1000 computeByteSize: 4999
690width: 1 height: 1000000 computeByteSize: 4999999
691width: 1000 height: 1 computeByteSize: 4000
692width: 1000 height: 1000 computeByteSize: 4999000
693width: 1000 height: 1000000 computeByteSize: 4999999000
694width: 1000000 height: 1 computeByteSize: 4000000
695width: 1000000 height: 1000 computeByteSize: 4999000000
Cary Clarkbc5697d2017-10-04 14:31:33 -0400696width: 1000000 height: 1000000 computeByteSize: 4999999000000
Cary Clarkd0530ba2017-09-14 11:25:39 -0400697##
698##
699
Cary Clarkbc5697d2017-10-04 14:31:33 -0400700#SeeAlso SkImageInfo::computeByteSize
Cary Clarkd0530ba2017-09-14 11:25:39 -0400701
702##
703
704#Subtopic Image_Info_Access ##
705
706#Subtopic Reader
Cary Clark08895c42018-02-01 09:37:32 -0500707#Line # examine pixel value ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400708
709# ------------------------------------------------------------------------------
710
711#Method bool computeIsOpaque() const
712
Cary Clarkab2621d2018-01-30 10:08:57 -0500713#In Reader
714#Line # returns true if all pixels are opaque ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400715Returns true if all pixels are opaque. Color_Type determines how pixels
716are encoded, and whether pixel describes Alpha. Returns true for Color_Types
Cary Clark6fc50412017-09-21 12:31:06 -0400717without alpha in each pixel; for other Color_Types, returns true if all
Cary Clarkd0530ba2017-09-14 11:25:39 -0400718pixels have alpha values equivalent to 1.0 or greater.
719
720For Color_Types kRGB_565_SkColorType or kGray_8_SkColorType: always
721returns true. For Color_Types kAlpha_8_SkColorType, kBGRA_8888_SkColorType,
722kRGBA_8888_SkColorType: returns true if all pixel Alpha values are 255.
723For Color_Type kARGB_4444_SkColorType: returns true if all pixel Alpha values are 15.
724For kRGBA_F16_SkColorType: returns true if all pixel Alpha values are 1.0 or
725greater.
726
Cary Clark6fc50412017-09-21 12:31:06 -0400727Returns false for kUnknown_SkColorType.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400728
Cary Clarkbc5697d2017-10-04 14:31:33 -0400729#Return true if all pixels have opaque values or Color_Type is opaque ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400730
731#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400732 std::vector<uint32_t> pixels;
733 const int height = 2;
734 const int width = 2;
735 pixels.resize(height * width * 4);
736 SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType,
737 kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4);
738 for (int index = 0; index < 2; ++index) {
739 pixmap.erase(0x00000000);
740 SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false");
741 pixmap.erase(0xFFFFFFFF);
742 SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false");
743 pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType),
744 (const void*) &pixels.front(), width * 4);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400745 }
746#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400747computeIsOpaque: false
748computeIsOpaque: true
749computeIsOpaque: false
Cary Clarkd0530ba2017-09-14 11:25:39 -0400750computeIsOpaque: true
751##
752##
753
754#SeeAlso isOpaque Color_Type Alpha
755
756##
757
758# ------------------------------------------------------------------------------
759
760#Method SkColor getColor(int x, int y) const
761
Cary Clarkab2621d2018-01-30 10:08:57 -0500762#In Reader
763#Line # returns one pixel as Unpremultiplied Color ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400764Returns pixel at (x, y) as Unpremultiplied Color.
765Returns black with Alpha if Color_Type is kAlpha_8_SkColorType.
766
767Input is not validated: out of bounds values of x or y trigger an assert() if
768built with SK_DEBUG defined; and returns undefined values or may crash if
769SK_RELEASE is defined. Fails if Color_Type is kUnknown_SkColorType or
770pixel address is nullptr.
771
772Color_Space in Image_Info is ignored. Some Color precision may be lost in the
773conversion to Unpremultiplied Color; original pixel data may have additional
774precision.
775
Cary Clark6fc50412017-09-21 12:31:06 -0400776#Param x column index, zero or greater, and less than width() ##
777#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400778
779#Return pixel converted to Unpremultiplied Color ##
780
781#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400782 const int w = 4;
783 const int h = 4;
784 std::vector<SkPMColor> storage;
785 storage.resize(w * h);
786 SkDebugf("Premultiplied:\n");
787 for (int y = 0; y < h; ++y) {
788 SkDebugf("(0, %d) ", y);
789 for (int x = 0; x < w; ++x) {
790 int a = 0xFF * (x + y) / (w - 1 + h - 1);
791 storage[x + y * w] = SkPackARGB32(a, a * x / (w - 1), a * y / (h - 1), a);
792 SkDebugf("0x%08x%c", storage[x + y * w], x == w - 1 ? '\n' : ' ');
793 }
794 }
795 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4);
796 SkDebugf("Unpremultiplied:\n");
797 for (int y = 0; y < h; ++y) {
798 SkDebugf("(0, %d) ", y);
799 for (int x = 0; x < w; ++x) {
800 SkDebugf("0x%08x%c", pixmap.getColor(x, y), x == w - 1 ? '\n' : ' ');
801 }
802 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400803#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400804Premultiplied:
805(0, 0) 0x00000000 0x2a0e002a 0x55380055 0x7f7f007f
806(0, 1) 0x2a000e2a 0x551c1c55 0x7f542a7f 0xaaaa38aa
807(0, 2) 0x55003855 0x7f2a547f 0xaa7171aa 0xd4d48dd4
808(0, 3) 0x7f007f7f 0xaa38aaaa 0xd48dd4d4 0xffffffff
809Unpremultiplied:
810(0, 0) 0x00000000 0x2a5500ff 0x55a800ff 0x7fff00ff
811(0, 1) 0x2a0055ff 0x555454ff 0x7fa954ff 0xaaff54ff
812(0, 2) 0x5500a8ff 0x7f54a9ff 0xaaaaaaff 0xd4ffaaff
Cary Clarkd0530ba2017-09-14 11:25:39 -0400813(0, 3) 0x7f00ffff 0xaa54ffff 0xd4aaffff 0xffffffff
814##
815##
816
817#SeeAlso addr() readPixels
818
819##
820
821#Subtopic Reader ##
822
823#Subtopic Readable_Address
Cary Clark08895c42018-02-01 09:37:32 -0500824#Line # returns read only pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400825
826# ------------------------------------------------------------------------------
827
828#Method const void* addr(int x, int y) const
829
Cary Clarkab2621d2018-01-30 10:08:57 -0500830#In Readable_Address
Cary Clarkbc5697d2017-10-04 14:31:33 -0400831Returns readable pixel address at (x, y). Returns nullptr if Pixel_Ref is nullptr.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400832
833Input is not validated: out of bounds values of x or y trigger an assert() if
Cary Clarkbc5697d2017-10-04 14:31:33 -0400834built with SK_DEBUG defined. Returns nullptr if Color_Type is kUnknown_SkColorType.
835
836Performs a lookup of pixel size; for better performance, call
837one of: addr8, addr16, addr32, addr64, or addrF16.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400838
Cary Clark6fc50412017-09-21 12:31:06 -0400839#Param x column index, zero or greater, and less than width() ##
840#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400841
842#Return readable generic pointer to pixel ##
843
844#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400845 const int w = 4;
846 const int h = 4;
847 std::vector<SkPMColor> storage;
848 storage.resize(w * h);
849 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400850 SkDebugf("pixmap.addr(1, 2) %c= &storage[1 + 2 * w]\n",
851 pixmap.addr(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
852#StdOut
853pixmap.addr(1, 2) == &storage[1 + 2 * w]
854##
855##
856
Cary Clarkbc5697d2017-10-04 14:31:33 -0400857#SeeAlso addr8 addr16 addr32 addr64 addrF16 getColor writable_addr SkBitmap::getAddr
Cary Clarkd0530ba2017-09-14 11:25:39 -0400858
859##
860
861# ------------------------------------------------------------------------------
862
863#Method const uint8_t* addr8() const
864
Cary Clarkab2621d2018-01-30 10:08:57 -0500865#In Readable_Address
866#Line # returns readable pixel address as 8-bit pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400867Returns readable base pixel address. Result is addressable as unsigned 8-bit bytes.
868Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType or
869kGray_8_SkColorType, and is built with SK_DEBUG defined.
870
871One byte corresponds to one pixel.
872
873#Return readable unsigned 8-bit pointer to pixels ##
874
875#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400876 const int w = 4;
877 const int h = 4;
878 uint8_t storage[w * h];
879 SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType),
880 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400881 SkDebugf("pixmap.addr8() %c= storage\n",
882 pixmap.addr8() == storage ? '=' : '!');
883#StdOut
884pixmap.addr8() == storage
885##
886##
887
888#SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8
889
890##
891
892# ------------------------------------------------------------------------------
893
894#Method const uint16_t* addr16() const
895
Cary Clarkab2621d2018-01-30 10:08:57 -0500896#In Readable_Address
897#Line # returns readable pixel address as 16-bit pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400898Returns readable base pixel address. Result is addressable as unsigned 16-bit words.
899Will trigger an assert() if Color_Type is not kRGB_565_SkColorType or
900kARGB_4444_SkColorType, and is built with SK_DEBUG defined.
901
902One word corresponds to one pixel.
903
904#Return readable unsigned 16-bit pointer to pixels ##
905
906#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400907 const int w = 4;
908 const int h = 4;
909 uint16_t storage[w * h];
910 SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType),
911 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400912 SkDebugf("pixmap.addr16() %c= storage\n",
913 pixmap.addr16() == storage ? '=' : '!');
914#StdOut
915pixmap.addr16() == storage
916##
917##
918
919#SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16
920
921##
922
923# ------------------------------------------------------------------------------
924
925#Method const uint32_t* addr32() const
926
Cary Clarkab2621d2018-01-30 10:08:57 -0500927#In Readable_Address
928#Line # returns readable pixel address as 32-bit pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400929Returns readable base pixel address. Result is addressable as unsigned 32-bit words.
930Will trigger an assert() if Color_Type is not kRGBA_8888_SkColorType or
931kBGRA_8888_SkColorType, and is built with SK_DEBUG defined.
932
933One word corresponds to one pixel.
934
935#Return readable unsigned 32-bit pointer to pixels ##
936
937#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400938 const int w = 4;
939 const int h = 4;
940 uint32_t storage[w * h];
941 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType),
942 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400943 SkDebugf("pixmap.addr32() %c= storage\n",
944 pixmap.addr32() == storage ? '=' : '!');
945#StdOut
946pixmap.addr32() == storage
947##
948##
949
950#SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr32
951
952##
953
954# ------------------------------------------------------------------------------
955
956#Method const uint64_t* addr64() const
957
Cary Clarkab2621d2018-01-30 10:08:57 -0500958#In Readable_Address
959#Line # returns readable pixel address as 64-bit pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400960Returns readable base pixel address. Result is addressable as unsigned 64-bit words.
961Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
962with SK_DEBUG defined.
963
964One word corresponds to one pixel.
965
966#Return readable unsigned 64-bit pointer to pixels ##
967
968#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400969 const int w = 4;
970 const int h = 4;
971 uint64_t storage[w * h];
972 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
973 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400974 SkDebugf("pixmap.addr64() %c= storage\n",
975 pixmap.addr64() == storage ? '=' : '!');
976#StdOut
977pixmap.addr64() == storage
978##
979##
980
981#SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64
982
983##
984
985# ------------------------------------------------------------------------------
986
987#Method const uint16_t* addrF16() const
988
Cary Clarkab2621d2018-01-30 10:08:57 -0500989#In Readable_Address
990#Line # returns readable pixel component address as 16-bit pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400991Returns readable base pixel address. Result is addressable as unsigned 16-bit words.
992Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
993with SK_DEBUG defined.
994
995Each word represents one color component encoded as a half float.
996Four words correspond to one pixel.
997
998#Return readable unsigned 16-bit pointer to first component of pixels ##
999
1000#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001001 const int w = 4;
1002 const int h = 4;
1003 uint16_t storage[w * h * 4];
1004 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
1005 storage, w * 4 * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001006 SkDebugf("pixmap.addrF16() %c= storage\n",
1007 pixmap.addrF16() == storage ? '=' : '!');
1008#StdOut
1009pixmap.addrF16() == storage
1010##
1011##
1012
1013#SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16
1014
1015##
1016
1017# ------------------------------------------------------------------------------
1018
1019#Method const uint8_t* addr8(int x, int y) const
1020
Cary Clarkab2621d2018-01-30 10:08:57 -05001021#In Readable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001022Returns readable pixel address at (x, y).
1023
1024Input is not validated: out of bounds values of x or y trigger an assert() if
1025built with SK_DEBUG defined.
1026
1027Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType or
1028kGray_8_SkColorType, and is built with SK_DEBUG defined.
1029
Cary Clark6fc50412017-09-21 12:31:06 -04001030#Param x column index, zero or greater, and less than width() ##
1031#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001032
1033#Return readable unsigned 8-bit pointer to pixel at (x, y) ##
1034
1035#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001036 const int w = 4;
1037 const int h = 4;
1038 uint8_t storage[w * h];
1039 SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType),
1040 storage, w * sizeof(storage[0]));
1041 SkDebugf("pixmap.addr8(1, 2) %c= &storage[1 + 2 * w]\n",
1042 pixmap.addr8(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
Cary Clarkd0530ba2017-09-14 11:25:39 -04001043#StdOut
1044pixmap.addr8(1, 2) == &storage[1 + 2 * w]
1045##
1046##
1047
1048#SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8
1049
1050##
1051
1052# ------------------------------------------------------------------------------
1053
1054#Method const uint16_t* addr16(int x, int y) const
1055
Cary Clarkab2621d2018-01-30 10:08:57 -05001056#In Readable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001057Returns readable pixel address at (x, y).
1058
1059Input is not validated: out of bounds values of x or y trigger an assert() if
1060built with SK_DEBUG defined.
1061
1062Will trigger an assert() if Color_Type is not kRGB_565_SkColorType or
1063kARGB_4444_SkColorType, and is built with SK_DEBUG defined.
1064
Cary Clark6fc50412017-09-21 12:31:06 -04001065#Param x column index, zero or greater, and less than width() ##
1066#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001067
1068#Return readable unsigned 16-bit pointer to pixel at (x, y) ##
1069
1070#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001071 const int w = 4;
1072 const int h = 4;
1073 uint16_t storage[w * h];
1074 SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType),
1075 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001076 SkDebugf("pixmap.addr16(1, 2) %c= &storage[1 + 2 * w]\n",
1077 pixmap.addr16(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
1078#StdOut
1079pixmap.addr16(1, 2) == &storage[1 + 2 * w]
1080##
1081##
1082
1083#SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16
1084
1085##
1086
1087# ------------------------------------------------------------------------------
1088
1089#Method const uint32_t* addr32(int x, int y) const
1090
Cary Clarkab2621d2018-01-30 10:08:57 -05001091#In Readable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001092Returns readable pixel address at (x, y).
1093
1094Input is not validated: out of bounds values of x or y trigger an assert() if
1095built with SK_DEBUG defined.
1096
1097Will trigger an assert() if Color_Type is not kRGBA_8888_SkColorType or
1098kBGRA_8888_SkColorType, and is built with SK_DEBUG defined.
1099
Cary Clark6fc50412017-09-21 12:31:06 -04001100#Param x column index, zero or greater, and less than width() ##
1101#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001102
1103#Return readable unsigned 32-bit pointer to pixel at (x, y) ##
1104
1105#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001106 const int w = 4;
1107 const int h = 4;
1108 uint32_t storage[w * h];
1109 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_8888_SkColorType, kPremul_SkAlphaType),
1110 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001111 SkDebugf("pixmap.addr32(1, 2) %c= &storage[1 + 2 * w]\n",
1112 pixmap.addr32(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
1113#StdOut
1114pixmap.addr32(1, 2) == &storage[1 + 2 * w]
1115##
1116##
1117
Cary Clark2ade9972017-11-02 17:49:34 -04001118#SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr64
Cary Clarkd0530ba2017-09-14 11:25:39 -04001119
1120##
1121
1122# ------------------------------------------------------------------------------
1123
1124#Method const uint64_t* addr64(int x, int y) const
1125
Cary Clarkab2621d2018-01-30 10:08:57 -05001126#In Readable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001127Returns readable pixel address at (x, y).
1128
1129Input is not validated: out of bounds values of x or y trigger an assert() if
1130built with SK_DEBUG defined.
1131
1132Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
1133with SK_DEBUG defined.
1134
Cary Clark6fc50412017-09-21 12:31:06 -04001135#Param x column index, zero or greater, and less than width() ##
1136#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001137
1138#Return readable unsigned 64-bit pointer to pixel at (x, y) ##
1139
1140#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001141 const int w = 4;
1142 const int h = 4;
1143 uint64_t storage[w * h];
1144 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
1145 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001146 SkDebugf("pixmap.addr64(1, 2) %c= &storage[1 + 2 * w]\n",
1147 pixmap.addr64(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
1148#StdOut
1149pixmap.addr64(1, 2) == &storage[1 + 2 * w]
1150##
1151##
1152
1153#SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64
1154
1155##
1156
1157# ------------------------------------------------------------------------------
1158
1159#Method const uint16_t* addrF16(int x, int y) const
1160
Cary Clarkab2621d2018-01-30 10:08:57 -05001161#In Readable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001162Returns readable pixel address at (x, y).
1163
1164Input is not validated: out of bounds values of x or y trigger an assert() if
1165built with SK_DEBUG defined.
1166
1167Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
1168with SK_DEBUG defined.
1169
1170Each unsigned 16-bit word represents one color component encoded as a half float.
1171Four words correspond to one pixel.
1172
Cary Clark6fc50412017-09-21 12:31:06 -04001173#Param x column index, zero or greater, and less than width() ##
1174#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001175
1176#Return readable unsigned 16-bit pointer to pixel component at (x, y) ##
1177
1178#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001179 const int w = 4;
1180 const int h = 4;
1181 const int wordsPerPixel = 4;
1182 const int rowWords = w * wordsPerPixel;
1183 uint16_t storage[rowWords * h];
1184 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
1185 storage, rowWords * sizeof(storage[0]));
1186 SkDebugf("pixmap.addrF16(1, 2) %c= &storage[1 * wordsPerPixel + 2 * rowWords]\n",
1187 pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords] ? '=' : '!');
Cary Clarkd0530ba2017-09-14 11:25:39 -04001188#StdOut
1189pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords]
1190##
1191##
1192
1193#SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16
1194
1195##
1196
1197#Subtopic Readable_Address ##
1198
1199#Subtopic Writable_Address
Cary Clark08895c42018-02-01 09:37:32 -05001200#Line # returns writable pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001201
1202# ------------------------------------------------------------------------------
1203
1204#Method void* writable_addr() const
1205
Cary Clarkab2621d2018-01-30 10:08:57 -05001206#In Writable_Address
1207#Line # returns writable pixel address as void pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001208Returns writable base pixel address.
1209
1210#Return writable generic base pointer to pixels ##
1211
1212#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001213 const int w = 4;
1214 const int h = 4;
1215 SkPMColor storage[w * h * 4];
1216 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4);
1217 SkDebugf("pixmap.writable_addr() %c= (void *)storage\n",
1218 pixmap.writable_addr() == (void *)storage ? '=' : '!');
1219 pixmap.erase(0x00000000);
1220 *(SkPMColor*)pixmap.writable_addr() = 0xFFFFFFFF;
1221 SkDebugf("pixmap.getColor(0, 1) %c= 0x00000000\n",
1222 pixmap.getColor(0, 1) == 0x00000000 ? '=' : '!');
1223 SkDebugf("pixmap.getColor(0, 0) %c= 0xFFFFFFFF\n",
Cary Clarkd0530ba2017-09-14 11:25:39 -04001224 pixmap.getColor(0, 0) == 0xFFFFFFFF ? '=' : '!');
1225#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -04001226pixmap.writable_addr() == (void *)storage
1227pixmap.getColor(0, 1) == 0x00000000
Cary Clarkd0530ba2017-09-14 11:25:39 -04001228pixmap.getColor(0, 0) == 0xFFFFFFFF
1229##
1230##
1231
1232#SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr()
1233
1234##
1235
1236# ------------------------------------------------------------------------------
1237
1238#Method void* writable_addr(int x, int y) const
1239
Cary Clarkab2621d2018-01-30 10:08:57 -05001240#In Writable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001241Returns writable pixel address at (x, y).
1242
1243Input is not validated: out of bounds values of x or y trigger an assert() if
1244built with SK_DEBUG defined. Returns zero if Color_Type is kUnknown_SkColorType.
1245
Cary Clark6fc50412017-09-21 12:31:06 -04001246#Param x column index, zero or greater, and less than width() ##
1247#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001248
1249#Return writable generic pointer to pixel ##
1250
1251#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001252 const int w = 4;
1253 const int h = 4;
1254 SkPMColor storage[w * h * 4];
1255 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4);
1256 SkDebugf("pixmap.writable_addr() %c= (void *)storage\n",
1257 pixmap.writable_addr() == (void *)storage ? '=' : '!');
1258 pixmap.erase(0x00000000);
1259 *(SkPMColor*)pixmap.writable_addr(1, 2) = 0xFFFFFFFF;
1260 SkDebugf("pixmap.getColor(0, 0) %c= 0x00000000\n",
1261 pixmap.getColor(0, 0) == 0x00000000 ? '=' : '!');
1262 SkDebugf("pixmap.getColor(1, 2) %c= 0xFFFFFFFF\n",
Cary Clarkd0530ba2017-09-14 11:25:39 -04001263 pixmap.getColor(1, 2) == 0xFFFFFFFF ? '=' : '!');
1264#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -04001265pixmap.writable_addr() == (void *)storage
1266pixmap.getColor(0, 0) == 0x00000000
Cary Clarkd0530ba2017-09-14 11:25:39 -04001267pixmap.getColor(1, 2) == 0xFFFFFFFF
1268##
1269##
1270
1271#SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr()
1272
1273##
1274
1275# ------------------------------------------------------------------------------
1276
1277#Method uint8_t* writable_addr8(int x, int y) const
1278
Cary Clarkab2621d2018-01-30 10:08:57 -05001279#In Writable_Address
1280#Line # returns writable pixel address as 8-bit pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -04001281Returns writable pixel address at (x, y). Result is addressable as unsigned
12828-bit bytes. Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType
1283or kGray_8_SkColorType, and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001284
1285One byte corresponds to one pixel.
1286
Cary Clark6fc50412017-09-21 12:31:06 -04001287#Param x column index, zero or greater, and less than width() ##
1288#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001289
1290#Return writable unsigned 8-bit pointer to pixels ##
1291
1292#Example
1293#Height 64
1294#Description
1295Altering pixels after drawing Bitmap is not guaranteed to affect subsequent
1296drawing on all platforms. Adding a second SkBitmap::installPixels after editing
1297pixel memory is safer.
1298##
Cary Clark6fc50412017-09-21 12:31:06 -04001299void draw(SkCanvas* canvas) {
1300 uint8_t storage[][5] = {{ 0, 0, 64, 0, 0},
1301 { 0, 128, 255, 128, 0},
1302 {64, 255, 255, 255, 64},
1303 { 0, 128, 255, 128, 0},
1304 { 0, 0, 64, 0, 0}};
1305 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kPremul_SkAlphaType);
1306 SkPixmap pixmap(imageInfo, storage[0], 5);
1307 SkBitmap bitmap;
1308 bitmap.installPixels(pixmap);
1309 canvas->scale(10, 10);
1310 canvas->drawBitmap(bitmap, 0, 0);
1311 *pixmap.writable_addr8(2, 2) = 0;
1312// bitmap.installPixels(pixmap); // uncomment to fix on GPU
1313 canvas->drawBitmap(bitmap, 10, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001314}
1315##
1316
1317#SeeAlso writable_addr writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr() addr8
1318
1319##
1320
1321# ------------------------------------------------------------------------------
1322
1323#Method uint16_t* writable_addr16(int x, int y) const
1324
Cary Clarkab2621d2018-01-30 10:08:57 -05001325#In Writable_Address
1326#Line # returns writable pixel address as 16-bit pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -04001327Returns writable_addr pixel address at (x, y). Result is addressable as unsigned
132816-bit words. Will trigger an assert() if Color_Type is not kRGB_565_SkColorType
1329or kARGB_4444_SkColorType, and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001330
1331One word corresponds to one pixel.
1332
Cary Clark6fc50412017-09-21 12:31:06 -04001333#Param x column index, zero or greater, and less than width() ##
1334#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001335
1336#Return writable unsigned 16-bit pointer to pixel ##
1337
1338#Example
1339#Description
1340Draw a five by five bitmap, and draw it again with a center black pixel.
1341The low nibble of the 16-bit word is Alpha.
1342##
1343#Height 64
Cary Clark6fc50412017-09-21 12:31:06 -04001344 uint16_t storage[][5] = {{ 0xCABF, 0xDABE, 0xCA9D, 0xC96C, 0xA39B },
1345 { 0xACEE, 0xA87C, 0x893A, 0x4779, 0x8708 },
1346 { 0x4B7C, 0x255B, 0x2559, 0x2557, 0x4656 },
1347 { 0x9099, 0x8128, 0x2557, 0x4124, 0x3323 },
1348 { 0x7547, 0x5505, 0x4434, 0x2012, 0x0000 }};
1349 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kARGB_4444_SkColorType, kPremul_SkAlphaType);
1350 SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
1351 SkBitmap bitmap;
1352 bitmap.installPixels(pixmap);
1353 canvas->scale(10, 10);
1354 canvas->drawBitmap(bitmap, 0, 0);
1355 *pixmap.writable_addr16(2, 2) = 0x000F;
1356 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001357 canvas->drawBitmap(bitmap, 10, 0);
1358##
1359
1360#SeeAlso writable_addr writable_addr8 writable_addr32 writable_addr64 writable_addrF16 addr() addr16
1361
1362##
1363
1364# ------------------------------------------------------------------------------
1365
1366#Method uint32_t* writable_addr32(int x, int y) const
1367
Cary Clarkab2621d2018-01-30 10:08:57 -05001368#In Writable_Address
1369#Line # returns writable pixel address as 32-bit pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -04001370Returns writable pixel address at (x, y). Result is addressable as unsigned
137132-bit words. Will trigger an assert() if Color_Type is not
1372kRGBA_8888_SkColorType or kBGRA_8888_SkColorType, and is built with SK_DEBUG
1373defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001374
1375One word corresponds to one pixel.
1376
Cary Clark6fc50412017-09-21 12:31:06 -04001377#Param x column index, zero or greater, and less than width() ##
1378#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001379
1380#Return writable unsigned 32-bit pointer to pixel ##
1381
1382#Example
1383#Image 4
1384#Height 72
Cary Clark6fc50412017-09-21 12:31:06 -04001385 std::vector<int32_t> pixels;
1386 pixels.resize(image->height() * image->width() * 4);
1387 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
1388 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
1389 image->readPixels(pixmap, 0, 0);
1390 for (int y = 0; y < pixmap.height() / 2; ++y) {
1391 for (int x = 0; x < pixmap.width(); ++x) {
1392 if ((x & 4) == (y & 4)) {
1393 SkTSwap(*pixmap.writable_addr32(x, y),
1394 *pixmap.writable_addr32(pixmap.width() - x, pixmap.height() - y));
1395 }
1396 }
1397 }
1398 SkBitmap bitmap;
1399 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001400 canvas->drawBitmap(bitmap, 0, 0);
1401##
1402
1403#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr64 writable_addrF16 addr() addr32
1404
1405##
1406
1407# ------------------------------------------------------------------------------
1408
1409#Method uint64_t* writable_addr64(int x, int y) const
1410
Cary Clarkab2621d2018-01-30 10:08:57 -05001411#In Writable_Address
1412#Line # returns writable pixel address as 64-bit pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -04001413Returns writable pixel address at (x, y). Result is addressable as unsigned
141464-bit words. Will trigger an assert() if Color_Type is not
1415kRGBA_F16_SkColorType and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001416
1417One word corresponds to one pixel.
1418
Cary Clark6fc50412017-09-21 12:31:06 -04001419#Param x column index, zero or greater, and less than width() ##
1420#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001421
1422#Return writable unsigned 64-bit pointer to pixel ##
1423
1424#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001425#Height 40
Cary Clark6fc50412017-09-21 12:31:06 -04001426 SkImageInfo info = SkImageInfo::Make(3, 3, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
1427 uint64_t storage[9];
1428 SkPixmap pixmap(info, storage, 3 * sizeof(uint64_t));
1429 SkColor4f c4 { 1, 0.45f, 0.25f, 0.65f };
1430 pixmap.erase(c4);
1431 SkBitmap bitmap;
1432 canvas->scale(10, 10);
1433 bitmap.installPixels(pixmap);
1434 canvas->drawBitmap(bitmap, 0, 0);
1435 *pixmap.writable_addr64(1, 1) |= 0x00ff000000000000LL;
1436 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001437 canvas->drawBitmap(bitmap, 10, 0);
1438##
1439
1440#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addrF16 addr() addr64
1441
1442##
1443
1444# ------------------------------------------------------------------------------
1445
1446#Method uint16_t* writable_addrF16(int x, int y) const
1447
Cary Clarkab2621d2018-01-30 10:08:57 -05001448#In Writable_Address
1449#Line # returns writable pixel component address as 16-bit pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -04001450Returns writable pixel address at (x, y). Result is addressable as unsigned
145116-bit words. Will trigger an assert() if Color_Type is not
1452kRGBA_F16_SkColorType and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001453
1454Each word represents one color component encoded as a half float.
1455Four words correspond to one pixel.
1456
Cary Clark6fc50412017-09-21 12:31:06 -04001457#Param x column index, zero or greater, and less than width() ##
1458#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001459
1460#Return writable unsigned 16-bit pointer to first component of pixel ##
1461
1462#Example
1463#Height 64
1464#Description
1465Left bitmap is drawn with two pixels defined in half float format. Right bitmap
1466is drawn after overwriting bottom half float color with top half float color.
1467##
Cary Clark6fc50412017-09-21 12:31:06 -04001468 SkImageInfo info = SkImageInfo::Make(1, 2, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
1469 uint16_t storage[2][4];
1470 SkPixmap pixmap(info, storage[0], sizeof(uint64_t));
1471 SkIRect topPixelBounds = {0, 0, 1, 1};
1472 pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds);
1473 SkIRect bottomPixelBounds = {0, 1, 1, 2};
1474 pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds);
1475 SkBitmap bitmap;
1476 canvas->scale(20, 20);
1477 bitmap.installPixels(pixmap);
1478 canvas->drawBitmap(bitmap, 0, 0);
1479 uint16_t* pixel2 = pixmap.writable_addrF16(0, 1);
1480 for (int i = 0; i < 4; ++i) {
1481 pixel2[i] = storage[0][i];
1482 }
1483 bitmap.installPixels(pixmap);
1484 canvas->drawBitmap(bitmap, 4, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001485##
1486
1487#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addr64 addr() addrF16
1488
1489##
1490
1491#Subtopic Writable_Address ##
1492
Cary Clark78de7512018-02-07 07:27:09 -05001493#Subtopic Pixels
1494#Populate
1495#Line # read and write pixel values ##
1496##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001497
1498# ------------------------------------------------------------------------------
1499
1500#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
1501 int srcX, int srcY, SkTransferFunctionBehavior behavior) const
Cary Clark78de7512018-02-07 07:27:09 -05001502#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001503#Line # copies and converts pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001504
Cary Clark154beea2017-10-26 07:58:48 -04001505Copies a Rect of pixels to dstPixels. Copy starts at (srcX, srcY), and does not
Cary Clarkac47b882018-01-11 10:35:44 -05001506exceed Pixmap (width(), height()).
Cary Clark6fc50412017-09-21 12:31:06 -04001507
1508dstInfo specifies width, height, Color_Type, Alpha_Type, and
Cary Clarkd0530ba2017-09-14 11:25:39 -04001509Color_Space of destination. dstRowBytes specifics the gap from one destination
1510row to the next. Returns true if pixels are copied. Returns false if
1511dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes.
1512
Cary Clarkac47b882018-01-11 10:35:44 -05001513Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001514kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001515If Pixmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match.
1516If Pixmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must
1517match. If Pixmap colorSpace is nullptr, dstInfo.colorSpace must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001518false if pixel conversion is not possible.
1519
1520srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clark154beea2017-10-26 07:58:48 -04001521false if width() or height() is zero or negative. Returns false if:
1522
Cary Clarkd0530ba2017-09-14 11:25:39 -04001523#Formula
Cary Clarkac47b882018-01-11 10:35:44 -05001524abs(srcX) >= Pixmap width()
Cary Clark6fc50412017-09-21 12:31:06 -04001525##
1526, or if
1527#Formula
Cary Clarkac47b882018-01-11 10:35:44 -05001528abs(srcY) >= Pixmap height()
Cary Clarkd0530ba2017-09-14 11:25:39 -04001529##
1530.
1531
1532If behavior is SkTransferFunctionBehavior::kRespect: converts source
1533pixels to a linear space before converting to dstInfo.
1534If behavior is SkTransferFunctionBehavior::kIgnore: source
Cary Clarkbc5697d2017-10-04 14:31:33 -04001535pixels are treated as if they are linear, regardless of how they are encoded.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001536
1537#Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ##
1538#Param dstPixels destination pixel storage ##
1539#Param dstRowBytes destination row length ##
1540#Param srcX column index whose absolute value is less than width() ##
1541#Param srcY row index whose absolute value is less than height() ##
1542#Param behavior one of: SkTransferFunctionBehavior::kRespect,
1543 SkTransferFunctionBehavior::kIgnore
1544##
1545
1546#Return true if pixels are copied to dstPixels ##
1547
1548#Example
Cary Clarkbc5697d2017-10-04 14:31:33 -04001549#ToDo example doesn't do anything interesting since info colorSpace is nullptr ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001550#Image 3
1551void draw(SkCanvas* canvas) {
1552 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height(),
1553 canvas->imageInfo().colorSpace() ? SkColorSpace::MakeSRGB() : nullptr);
Cary Clark6fc50412017-09-21 12:31:06 -04001554 std::vector<int32_t> srcPixels;
1555 srcPixels.resize(image->height() * image->width() * 4);
1556 SkPixmap pixmap(info, (const void*) &srcPixels.front(), image->width() * 4);
1557 image->readPixels(pixmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001558 SkTransferFunctionBehavior behavior = canvas->imageInfo().colorSpace() ?
1559 SkTransferFunctionBehavior::kRespect : SkTransferFunctionBehavior::kIgnore;
Cary Clark6fc50412017-09-21 12:31:06 -04001560 std::vector<int32_t> dstPixels;
1561 dstPixels.resize(image->height() * image->width() * 4);
1562 int offset = 0;
1563 for (auto behavior : { SkTransferFunctionBehavior::kRespect,
1564 SkTransferFunctionBehavior::kIgnore} ) {
Cary Clarkd0530ba2017-09-14 11:25:39 -04001565 pixmap.readPixels(info, &dstPixels.front(), image->width() * 4, offset, 0, behavior);
1566 offset += 128;
1567 }
1568 SkBitmap bitmap;
1569 SkPixmap dstmap(info, &dstPixels.front(), image->width() * 4);
1570 bitmap.installPixels(dstmap);
1571 canvas->drawBitmap(bitmap, 0, 0);
1572}
1573##
1574
1575#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1576
1577##
1578
1579# ------------------------------------------------------------------------------
1580
1581#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes) const
1582
Cary Clark78de7512018-02-07 07:27:09 -05001583#In Pixels
Cary Clarkd0530ba2017-09-14 11:25:39 -04001584Copies a Rect of pixels to dstPixels. Copy starts at (0, 0), and does not
Cary Clarkac47b882018-01-11 10:35:44 -05001585exceed Pixmap (width(), height()).
Cary Clark6fc50412017-09-21 12:31:06 -04001586
1587dstInfo specifies width, height, Color_Type, Alpha_Type, and
Cary Clarkd0530ba2017-09-14 11:25:39 -04001588Color_Space of destination. dstRowBytes specifics the gap from one destination
1589row to the next. Returns true if pixels are copied. Returns false if
1590dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes.
1591
Cary Clarkac47b882018-01-11 10:35:44 -05001592Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001593kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001594If Pixmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match.
1595If Pixmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must
1596match. If Pixmap colorSpace is nullptr, dstInfo.colorSpace must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001597false if pixel conversion is not possible.
1598
Cary Clarkac47b882018-01-11 10:35:44 -05001599Returns false if Pixmap width() or height() is zero or negative.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001600
1601#Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ##
1602#Param dstPixels destination pixel storage ##
1603#Param dstRowBytes destination row length ##
1604
1605#Return true if pixels are copied to dstPixels ##
1606
1607#Example
1608#Height 128
1609#Description
1610Transferring the gradient from 8 bits per component to 4 bits per component
1611creates visible banding.
1612##
Cary Clark6fc50412017-09-21 12:31:06 -04001613 std::vector<int32_t> pixels;
1614 const int width = 256;
1615 const int height = 64;
1616 pixels.resize(height * width * 4);
1617 SkImageInfo srcInfo = SkImageInfo::MakeN32Premul(width, height);
1618 SkPixmap srcPixmap(srcInfo, (const void*) &pixels.front(), width * 4);
1619 SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 };
1620 SkPoint gradPoints[] = { { 0, 0 }, { 256, 0 } };
1621 SkPaint paint;
1622 paint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1623 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1624 SkBitmap bitmap;
1625 bitmap.installPixels(srcPixmap);
1626 SkCanvas srcCanvas(bitmap);
1627 srcCanvas.drawRect(SkRect::MakeWH(width, height), paint);
1628 canvas->drawBitmap(bitmap, 0, 0);
1629 std::vector<int32_t> dstPixels;
1630 dstPixels.resize(height * width * 2);
1631 SkImageInfo dstInfo = srcInfo.makeColorType(kARGB_4444_SkColorType);
1632 srcPixmap.readPixels(dstInfo, &dstPixels.front(), width * 2);
1633 SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2);
1634 bitmap.installPixels(dstPixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001635 canvas->drawBitmap(bitmap, 0, 128);
1636##
1637
1638#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1639
1640##
1641
1642# ------------------------------------------------------------------------------
1643
1644#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX,
1645 int srcY) const
1646
1647Copies a Rect of pixels to dstPixels. Copy starts at (srcX, srcY), and does not
Cary Clarkac47b882018-01-11 10:35:44 -05001648exceed Pixmap (width(), height()).
Cary Clark6fc50412017-09-21 12:31:06 -04001649
1650dstInfo specifies width, height, Color_Type, Alpha_Type, and
Cary Clarkd0530ba2017-09-14 11:25:39 -04001651Color_Space of destination. dstRowBytes specifics the gap from one destination
1652row to the next. Returns true if pixels are copied. Returns false if
1653dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes.
1654
Cary Clarkac47b882018-01-11 10:35:44 -05001655Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001656kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001657If Pixmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match.
1658If Pixmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must
1659match. If Pixmap colorSpace is nullptr, dstInfo.colorSpace must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001660false if pixel conversion is not possible.
1661
1662srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clarkac47b882018-01-11 10:35:44 -05001663false if Pixmap width() or height() is zero or negative. Returns false if:
Cary Clark154beea2017-10-26 07:58:48 -04001664
Cary Clarkd0530ba2017-09-14 11:25:39 -04001665#Formula
Cary Clarkac47b882018-01-11 10:35:44 -05001666abs(srcX) >= Pixmap width()
Cary Clark6fc50412017-09-21 12:31:06 -04001667##
1668, or if
1669#Formula
Cary Clarkac47b882018-01-11 10:35:44 -05001670abs(srcY) >= Pixmap height()
Cary Clarkd0530ba2017-09-14 11:25:39 -04001671##
1672.
1673
1674#Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ##
1675#Param dstPixels destination pixel storage ##
1676#Param dstRowBytes destination row length ##
1677#Param srcX column index whose absolute value is less than width() ##
1678#Param srcY row index whose absolute value is less than height() ##
1679
1680#Return true if pixels are copied to dstPixels ##
1681
1682#Example
1683#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001684void draw(SkCanvas* canvas) {
1685 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1686 std::vector<int32_t> srcPixels;
1687 const int rowBytes = image->width() * 4;
1688 srcPixels.resize(image->height() * rowBytes);
1689 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1690 image->readPixels(pixmap, 0, 0);
1691 for (int offset : { 32, 64, 96 } ) {
1692 std::vector<int32_t> dstPixels;
1693 dstPixels.resize(image->height() * rowBytes);
1694 pixmap.readPixels(info, &dstPixels.front(), rowBytes, offset, 0);
1695 SkBitmap bitmap;
1696 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1697 bitmap.installPixels(dstmap);
1698 canvas->translate(32, 32);
1699 canvas->drawBitmap(bitmap, 0, 0);
1700 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001701}
1702##
1703
1704#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1705
1706##
1707
1708# ------------------------------------------------------------------------------
1709
1710#Method bool readPixels(const SkPixmap& dst, int srcX, int srcY) const
1711
1712Copies a Rect of pixels to dst. Copy starts at (srcX, srcY), and does not
Cary Clarkac47b882018-01-11 10:35:44 -05001713exceed Pixmap (width(), height()). dst specifies width, height, Color_Type,
Cary Clarkd0530ba2017-09-14 11:25:39 -04001714Alpha_Type, and Color_Space of destination. Returns true if pixels are copied.
1715Returns false if dst.addr() equals nullptr, or dst.rowBytes is less than
1716dst SkImageInfo::minRowBytes.
1717
Cary Clarkac47b882018-01-11 10:35:44 -05001718Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001719kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.info().colorType must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001720If Pixmap colorType is kGray_8_SkColorType, dst.info().colorSpace must match.
1721If Pixmap alphaType is kOpaque_SkAlphaType, dst.info().alphaType must
1722match. If Pixmap colorSpace is nullptr, dst.info().colorSpace must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001723false if pixel conversion is not possible.
1724
1725srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clarkac47b882018-01-11 10:35:44 -05001726false Pixmap width() or height() is zero or negative. Returns false if:
Cary Clark154beea2017-10-26 07:58:48 -04001727
Cary Clarkd0530ba2017-09-14 11:25:39 -04001728#Formula
Cary Clarkac47b882018-01-11 10:35:44 -05001729abs(srcX) >= Pixmap width()
Cary Clark6fc50412017-09-21 12:31:06 -04001730##
1731, or if
1732#Formula
Cary Clarkac47b882018-01-11 10:35:44 -05001733abs(srcY) >= Pixmap height()
Cary Clarkd0530ba2017-09-14 11:25:39 -04001734##
1735.
1736
1737#Param dst Image_Info and pixel address to write to ##
1738#Param srcX column index whose absolute value is less than width() ##
1739#Param srcY row index whose absolute value is less than height() ##
1740
1741#Return true if pixels are copied to dst ##
1742
1743#Example
1744#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001745void draw(SkCanvas* canvas) {
1746 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1747 std::vector<int32_t> srcPixels;
1748 const int rowBytes = image->width() * 4;
1749 srcPixels.resize(image->height() * rowBytes);
1750 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1751 image->readPixels(pixmap, 0, 0);
1752 for (int offset : { 32, 64, 96 } ) {
1753 std::vector<int32_t> dstPixels;
1754 dstPixels.resize(image->height() * rowBytes);
1755 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1756 pixmap.readPixels(dstmap, offset, 0);
1757 SkBitmap bitmap;
1758 bitmap.installPixels(dstmap);
1759 canvas->translate(32, 32);
1760 canvas->drawBitmap(bitmap, 0, 0);
1761 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001762}
1763##
1764
1765#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1766
1767##
1768
1769# ------------------------------------------------------------------------------
1770
1771#Method bool readPixels(const SkPixmap& dst) const
1772
1773Copies pixels inside bounds() to dst. dst specifies width, height, Color_Type,
1774Alpha_Type, and Color_Space of destination. Returns true if pixels are copied.
1775Returns false if dst.addr() equals nullptr, or dst.rowBytes is less than
1776dst SkImageInfo::minRowBytes.
1777
Cary Clarkac47b882018-01-11 10:35:44 -05001778Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001779kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001780If Pixmap colorType is kGray_8_SkColorType, dst Color_Space must match.
1781If Pixmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must
1782match. If Pixmap colorSpace is nullptr, dst Color_Space must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001783false if pixel conversion is not possible.
1784
Cary Clarkac47b882018-01-11 10:35:44 -05001785Returns false if Pixmap width() or height() is zero or negative.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001786
1787#Param dst Image_Info and pixel address to write to ##
1788
1789#Return true if pixels are copied to dst ##
1790
1791#Example
1792#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001793void draw(SkCanvas* canvas) {
1794 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1795 std::vector<int32_t> srcPixels;
1796 const int rowBytes = image->width() * 4;
1797 srcPixels.resize(image->height() * rowBytes);
1798 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1799 image->readPixels(pixmap, 0, 0);
1800 for (int index = 0; index < 3; ++index ) {
1801 std::vector<int32_t> dstPixels;
1802 dstPixels.resize(image->height() * rowBytes);
1803 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1804 pixmap.readPixels(dstmap);
1805 SkBitmap bitmap;
1806 bitmap.installPixels(dstmap);
1807 canvas->translate(32, 32);
1808 canvas->drawBitmap(bitmap, 0, 0);
1809 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001810}
1811##
1812
1813#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1814
1815##
1816
1817# ------------------------------------------------------------------------------
1818
1819#Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality) const
1820
Cary Clark78de7512018-02-07 07:27:09 -05001821#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001822#Line # scales and converts pixels ##
Cary Clarkac47b882018-01-11 10:35:44 -05001823Copies Bitmap to dst, scaling pixels to fit dst.width() and dst.height(), and
Cary Clarkd0530ba2017-09-14 11:25:39 -04001824converting pixels to match dst.colorType and dst.alphaType. Returns true if
1825pixels are copied. Returns false if dst.addr() is nullptr, or dst.rowBytes is
1826less than dst SkImageInfo::minRowBytes.
1827
Cary Clarkac47b882018-01-11 10:35:44 -05001828Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001829kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001830If Pixmap colorType is kGray_8_SkColorType, dst Color_Space must match.
1831If Pixmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must
1832match. If Pixmap colorSpace is nullptr, dst Color_Space must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001833false if pixel conversion is not possible.
1834
Cary Clarkac47b882018-01-11 10:35:44 -05001835Returns false if Bitmap width() or height() is zero or negative.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001836
1837Scales the image, with filterQuality, to match dst.width() and dst.height().
1838filterQuality kNone_SkFilterQuality is fastest, typically implemented with
1839Filter_Quality_Nearest_Neighbor. kLow_SkFilterQuality is typically implemented with
1840Filter_Quality_Bilerp. kMedium_SkFilterQuality is typically implemented with
1841Filter_Quality_Bilerp, and Filter_Quality_MipMap when size is reduced.
1842kHigh_SkFilterQuality is slowest, typically implemented with Filter_Quality_BiCubic.
1843
1844#Param dst Image_Info and pixel address to write to ##
1845#Param filterQuality one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
1846 kMedium_SkFilterQuality, kHigh_SkFilterQuality
1847##
1848
Cary Clarkac47b882018-01-11 10:35:44 -05001849#Return true if pixels are scaled to fit dst ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001850
1851#Example
1852#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001853void draw(SkCanvas* canvas) {
1854 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1855 std::vector<int32_t> srcPixels;
1856 int rowBytes = image->width() * 4;
1857 srcPixels.resize(image->height() * rowBytes);
1858 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1859 image->readPixels(pixmap, 0, 0);
1860 for (int offset : { 32, 64, 96 } ) {
1861 info = SkImageInfo::MakeN32Premul(image->width() + offset, image->height());
1862 rowBytes = info.width() * 4;
1863 std::vector<int32_t> dstPixels;
1864 dstPixels.resize(image->height() * rowBytes);
1865 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1866 pixmap.scalePixels(dstmap, kMedium_SkFilterQuality);
1867 SkBitmap bitmap;
1868 bitmap.installPixels(dstmap);
1869 canvas->translate(32, 32);
1870 canvas->drawBitmap(bitmap, 0, 0);
1871 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001872}
1873##
1874
1875#SeeAlso SkCanvas::drawBitmap SkImage::scalePixels
1876
1877##
1878
1879# ------------------------------------------------------------------------------
1880
1881#Method bool erase(SkColor color, const SkIRect& subset) const
1882
Cary Clark78de7512018-02-07 07:27:09 -05001883#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001884#Line # writes Color to pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001885Writes color to pixels bounded by subset; returns true on success.
1886Returns false if colorType is kUnknown_SkColorType, or if subset does
1887not intersect bounds().
1888
1889#Param color Unpremultiplied Color to write ##
1890#Param subset bounding integer Rect of written pixels ##
1891
1892#Return true if pixels are changed ##
1893
1894#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001895#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001896 uint32_t storage[2];
1897 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1898 SkPixmap pixmap(info, storage, info.minRowBytes());
1899 pixmap.erase(SK_ColorBLUE, {0, 0, 1, 1});
1900 pixmap.erase(SK_ColorRED, {0, 1, 1, 2});
1901 SkBitmap bitmap;
1902 canvas->scale(20, 20);
1903 bitmap.installPixels(pixmap);
1904 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001905##
1906
1907#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1908
1909##
1910
1911# ------------------------------------------------------------------------------
1912
1913#Method bool erase(SkColor color) const
1914
1915Writes color to pixels inside bounds(); returns true on success.
1916Returns false if colorType is kUnknown_SkColorType, or if bounds()
1917is empty.
1918
1919#Param color Unpremultiplied Color to write ##
1920
1921#Return true if pixels are changed ##
1922
1923#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001924#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001925 uint32_t storage[2];
1926 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1927 SkPixmap pixmap(info, storage, info.minRowBytes());
1928 pixmap.erase(SK_ColorBLUE);
1929 SkBitmap bitmap;
1930 canvas->scale(20, 20);
1931 bitmap.installPixels(pixmap);
1932 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001933##
1934
1935#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1936
1937##
1938
1939# ------------------------------------------------------------------------------
1940
1941#Method bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const
1942
1943Writes color to pixels bounded by subset; returns true on success.
1944if subset is nullptr, writes colors pixels inside bounds(). Returns false if
1945colorType is kUnknown_SkColorType, if subset is not nullptr and does
1946not intersect bounds(), or if subset is nullptr and bounds() is empty.
1947
1948#Param color Unpremultiplied Color to write ##
1949#Param subset bounding integer Rect of pixels to write; may be nullptr ##
1950
1951#Return true if pixels are changed ##
1952
1953#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001954#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001955 uint32_t storage[2];
1956 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1957 SkPixmap pixmap(info, storage, info.minRowBytes());
1958 SkIRect topPixelBounds = {0, 0, 1, 1};
1959 pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds);
1960 SkIRect bottomPixelBounds = {0, 1, 1, 2};
1961 pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds);
1962 SkBitmap bitmap;
1963 canvas->scale(20, 20);
1964 bitmap.installPixels(pixmap);
1965 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001966##
1967
1968#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1969
1970##
1971
Cary Clarkd0530ba2017-09-14 11:25:39 -04001972#Class SkPixmap ##
1973
1974#Topic Pixmap ##