blob: 1b38cc37f62b065879a15f5b387955b60aed474d [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 Clark09d80c02018-10-31 12:14:03 -040031#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -040032
33#Example
Cary Clark6fc50412017-09-21 12:31:06 -040034void draw(SkCanvas* canvas) {
35 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
Cary Clarkab2621d2018-01-30 10:08:57 -050036 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
37 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -040038 SkPixmap pixmap;
39 for (int i = 0; i < 2; ++i) {
40 SkDebugf("width: %2d height: %2d", pixmap.width(), pixmap.height());
41 SkDebugf(" color: k%s_SkColorType", colors[pixmap.colorType()]);
42 SkDebugf(" alpha: k%s_SkAlphaType\n", alphas[pixmap.alphaType()]);
43 pixmap.reset(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType),
44 nullptr, 0);
45 }
Cary Clarkd0530ba2017-09-14 11:25:39 -040046}
47#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -040048width: 0 height: 0 color: kUnknown_SkColorType alpha: kUnknown_SkAlphaType
Cary Clarkd0530ba2017-09-14 11:25:39 -040049width: 25 height: 35 color: kRGBA_8888_SkColorType alpha: kOpaque_SkAlphaType
50##
51##
52
53#SeeAlso SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) reset() SkAlphaType SkColorType
54
55##
56
57# ------------------------------------------------------------------------------
58
59#Method SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes)
Cary Clark682c58d2018-05-16 07:07:07 -040060
Cary Clarkab2621d2018-01-30 10:08:57 -050061#In Initialization
62#Line # constructs from Image_Info, pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -040063#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -040064
65#Example
66#Image 3
67#Description
Cary Clark682c58d2018-05-16 07:07:07 -040068SkImage::MakeRasterCopy takes const SkPixmap& as an argument. The example
Cary Clarkd0530ba2017-09-14 11:25:39 -040069constructs a SkPixmap from the brace-delimited parameters.
70##
Cary Clark6fc50412017-09-21 12:31:06 -040071 SkDebugf("image alpha only = %s\n", image->isAlphaOnly() ? "true" : "false");
72 SkPMColor pmColors = 0;
73 sk_sp<SkImage> copy = SkImage::MakeRasterCopy({SkImageInfo::MakeA8(1, 1),
74 (uint8_t*)&pmColors,
75 1});
Cary Clarkd0530ba2017-09-14 11:25:39 -040076 SkDebugf("copy alpha only = %s\n", copy->isAlphaOnly() ? "true" : "false");
77#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -040078image alpha only = false
Cary Clarkd0530ba2017-09-14 11:25:39 -040079copy alpha only = true
80##
81##
82
83#SeeAlso SkPixmap() reset() SkAlphaType SkColorType
84
85##
86
87# ------------------------------------------------------------------------------
88
89#Method void reset()
90
Cary Clarkab2621d2018-01-30 10:08:57 -050091#In Initialization
92#Line # reuses existing Pixmap with replacement values ##
Cary Clark09d80c02018-10-31 12:14:03 -040093#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -040094
95#Example
Cary Clark6fc50412017-09-21 12:31:06 -040096void draw(SkCanvas* canvas) {
97 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
Cary Clarkab2621d2018-01-30 10:08:57 -050098 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
99 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -0400100 SkPixmap pixmap(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType),
101 nullptr, 0);
102 for (int i = 0; i < 2; ++i) {
103 SkDebugf("width: %2d height: %2d", pixmap.width(), pixmap.height());
104 SkDebugf(" color: k%s_SkColorType", colors[pixmap.colorType()]);
105 SkDebugf(" alpha: k%s_SkAlphaType\n", alphas[pixmap.alphaType()]);
106 pixmap.reset();
107 }
108}
Cary Clarkd0530ba2017-09-14 11:25:39 -0400109#StdOut
110width: 25 height: 35 color: kRGBA_8888_SkColorType alpha: kOpaque_SkAlphaType
Cary Clark6fc50412017-09-21 12:31:06 -0400111width: 0 height: 0 color: kUnknown_SkColorType alpha: kUnknown_SkAlphaType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400112##
113##
114
115#SeeAlso SkPixmap() SkAlphaType SkColorType
116
117##
118
119# ------------------------------------------------------------------------------
120
121#Method void reset(const SkImageInfo& info, const void* addr, size_t rowBytes)
122
Cary Clarkab2621d2018-01-30 10:08:57 -0500123#In Initialization
Cary Clark09d80c02018-10-31 12:14:03 -0400124#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400125
126#Example
127#Image 4
Cary Clark2ade9972017-11-02 17:49:34 -0400128#Height 64
Cary Clark6fc50412017-09-21 12:31:06 -0400129void draw(SkCanvas* canvas) {
130 std::vector<int32_t> pixels;
131 pixels.resize(image->height() * image->width() * 4);
132 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
133 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
134 image->readPixels(pixmap, 0, 0);
135 int x = 0;
136 for (auto colorType : { kRGBA_8888_SkColorType, kBGRA_8888_SkColorType } ) {
Cary Clark682c58d2018-05-16 07:07:07 -0400137 pixmap.reset(SkImageInfo::Make(image->width(), image->height(), colorType,
Cary Clark6fc50412017-09-21 12:31:06 -0400138 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
139 SkBitmap bitmap;
140 bitmap.installPixels(pixmap);
141 canvas->drawBitmap(bitmap, x, 0);
142 x += 128;
143 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400144}
145##
146
147#SeeAlso SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) reset() SkAlphaType SkColorType
148
149##
150
151# ------------------------------------------------------------------------------
152
153#Method void setColorSpace(sk_sp<SkColorSpace> colorSpace)
154
Cary Clarkab2621d2018-01-30 10:08:57 -0500155#In Initialization
156#Line # sets Image_Info Color_Space ##
Cary Clark09d80c02018-10-31 12:14:03 -0400157#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400158
159#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400160void draw(SkCanvas* canvas) {
161 SkPixmap pixmap;
162 sk_sp<SkColorSpace> colorSpace1 = SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma,
163 SkColorSpace::kRec2020_Gamut);
Cary Clark682c58d2018-05-16 07:07:07 -0400164 SkDebugf("is %sunique\n", colorSpace1->unique() ? "" : "not ");
Cary Clark6fc50412017-09-21 12:31:06 -0400165 pixmap.setColorSpace(colorSpace1);
Cary Clark682c58d2018-05-16 07:07:07 -0400166 SkDebugf("is %sunique\n", colorSpace1->unique() ? "" : "not ");
Cary Clarkd0530ba2017-09-14 11:25:39 -0400167}
168#StdOut
169is unique
170is not unique
171##
172##
173
174#SeeAlso Color_Space SkImageInfo::makeColorSpace
175
176##
177
178# ------------------------------------------------------------------------------
179
Cary Clark61313f32018-10-08 14:57:48 -0400180#Method bool reset(const SkMask& mask)
Cary Clark4855f782018-02-06 09:41:53 -0500181#Deprecated soon
Cary Clarkd0530ba2017-09-14 11:25:39 -0400182##
183
184# ------------------------------------------------------------------------------
185
Cary Clark61313f32018-10-08 14:57:48 -0400186#Method bool extractSubset(SkPixmap* subset, const SkIRect& area) const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400187
Cary Clarkab2621d2018-01-30 10:08:57 -0500188#In Initialization
189#Line # sets pointer to portion of original ##
Cary Clark09d80c02018-10-31 12:14:03 -0400190#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400191
192#Example
193#Image 3
194#Height 128
Cary Clark6fc50412017-09-21 12:31:06 -0400195void draw(SkCanvas* canvas) {
196 std::vector<int32_t> pixels;
197 pixels.resize(image->height() * image->width() * 4);
198 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
199 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
200 image->readPixels(pixmap, 0, 0);
201 SkPixmap inset;
202 if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
203 SkBitmap bitmap;
204 bitmap.installPixels(inset);
205 canvas->drawBitmap(bitmap, 0, 0);
206 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400207}
208##
209
210#SeeAlso reset() SkIRect::intersect
211
212##
213
214#Subtopic Initialization ##
215
216#Subtopic Image_Info_Access
Cary Clark08895c42018-02-01 09:37:32 -0500217#Line # returns all or part of Image_Info ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400218
219# ------------------------------------------------------------------------------
220
Cary Clark682c58d2018-05-16 07:07:07 -0400221#Method const SkImageInfo& info() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400222
Cary Clarkab2621d2018-01-30 10:08:57 -0500223#In Image_Info_Access
224#Line # returns Image_Info ##
Cary Clark09d80c02018-10-31 12:14:03 -0400225#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400226
227#Example
228#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -0400229 std::vector<int32_t> pixels;
230 pixels.resize(image->height() * image->width() * 4);
231 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
232 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
233 image->readPixels(pixmap, 0, 0);
234 SkPixmap inset;
235 if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
236 const SkImageInfo& info = inset.info();
237 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
Cary Clarkab2621d2018-01-30 10:08:57 -0500238 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888",
239 "RGB_888x", "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -0400240 SkDebugf("width: %d height: %d color: %s alpha: %s\n", info.width(), info.height(),
241 colors[info.colorType()], alphas[info.alphaType()]);
242 }
243#StdOut
244width: 384 height: 384 color: BGRA_8888 alpha: Opaque
245##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400246##
247
248#SeeAlso Image_Info
249
250##
251
252# ------------------------------------------------------------------------------
253
Cary Clark682c58d2018-05-16 07:07:07 -0400254#Method size_t rowBytes() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400255
Cary Clarkab2621d2018-01-30 10:08:57 -0500256#In Image_Info_Access
257#Line # returns interval between rows in bytes ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400258Returns row bytes, the interval from one pixel row to the next. Row bytes
Cary Clark2be81cf2018-09-13 12:04:30 -0400259is at least as large as: #Formula # width() * info().bytesPerPixel() ##.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400260
Cary Clarkbc5697d2017-10-04 14:31:33 -0400261Returns zero if colorType is kUnknown_SkColorType.
262It is up to the Bitmap creator to ensure that row bytes is a useful value.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400263
264#Return byte length of pixel row ##
265
266#Example
267SkPixmap badPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 2};
268SkPixmap okPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 8};
269for (auto& pixmap : { badPixmap, okPixmap } ) {
Cary Clark682c58d2018-05-16 07:07:07 -0400270 SkDebugf("rowBytes: %d minRowBytes: %d\n", pixmap.rowBytes(),
Cary Clarkd0530ba2017-09-14 11:25:39 -0400271 pixmap.info().minRowBytes());
272}
273#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400274rowBytes: 2 minRowBytes: 4
Cary Clarkd0530ba2017-09-14 11:25:39 -0400275rowBytes: 8 minRowBytes: 4
276##
277##
278
279#SeeAlso addr() info() SkImageInfo::minRowBytes
280
281##
282
283# ------------------------------------------------------------------------------
284
Cary Clark682c58d2018-05-16 07:07:07 -0400285#Method const void* addr() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400286
Cary Clarkab2621d2018-01-30 10:08:57 -0500287#In Image_Info_Access
288#Line # returns readable pixel address as void pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -0400289#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400290
291#Example
292#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -0400293 std::vector<int32_t> pixels;
294 pixels.resize(image->height() * image->width() * 4);
295 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
296 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
297 image->readPixels(pixmap, 0, 0);
298 SkDebugf("pixels address: 0x%llx\n", pixmap.addr());
299 SkPixmap inset;
300 if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
301 SkDebugf("inset address: 0x%llx\n", inset.addr());
302 }
303#StdOut
304#Volatile
305pixels address: 0x7f2a440bb010
306inset address: 0x7f2a440fb210
307##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400308##
309
310#SeeAlso addr(int x, int y) addr8 addr16 addr32 addr64 info() rowBytes()
311
312##
313
314# ------------------------------------------------------------------------------
315
Cary Clark682c58d2018-05-16 07:07:07 -0400316#Method int width() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400317
Cary Clarkab2621d2018-01-30 10:08:57 -0500318#In Image_Info_Access
319#Line # returns pixel column count ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400320Returns pixel count in each pixel row. Should be equal or less than:
Cary Clark154beea2017-10-26 07:58:48 -0400321
Cary Clark2be81cf2018-09-13 12:04:30 -0400322#Formula # rowBytes() / info().bytesPerPixel() ##.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400323
324#Return pixel width in Image_Info ##
325
326#Example
327 SkImageInfo info = SkImageInfo::MakeA8(16, 32);
Cary Clark6fc50412017-09-21 12:31:06 -0400328 SkPixmap pixmap(info, nullptr, 64);
329 SkDebugf("pixmap width: %d info width: %d\n", pixmap.width(), info.width());
330#StdOut
331pixmap width: 16 info width: 16
332##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400333##
334
Cary Clarkbc5697d2017-10-04 14:31:33 -0400335#SeeAlso height() SkImageInfo::width()
Cary Clarkd0530ba2017-09-14 11:25:39 -0400336
337##
338
339# ------------------------------------------------------------------------------
340
Cary Clark682c58d2018-05-16 07:07:07 -0400341#Method int height() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400342
Cary Clarkab2621d2018-01-30 10:08:57 -0500343#In Image_Info_Access
344#Line # returns pixel row count ##
Cary Clark09d80c02018-10-31 12:14:03 -0400345#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400346
347#Example
Cary Clarkbc5697d2017-10-04 14:31:33 -0400348 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
349 SkDebugf("pixmap height: %d info height: %d\n", pixmap.height(), pixmap.info().height());
Cary Clark6fc50412017-09-21 12:31:06 -0400350#StdOut
351pixmap height: 32 info height: 32
352##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400353##
354
Cary Clark77b3f3a2018-11-07 14:59:03 -0500355#SeeAlso width SkImageInfo::height
Cary Clarkd0530ba2017-09-14 11:25:39 -0400356
357##
358
359# ------------------------------------------------------------------------------
360
Cary Clark682c58d2018-05-16 07:07:07 -0400361#Method SkColorType colorType() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400362
Cary Clarkab2621d2018-01-30 10:08:57 -0500363#In Image_Info_Access
364#Line # returns Image_Info Color_Type ##
Cary Clark1a8d7622018-03-05 13:26:16 -0500365Returns Color_Type, one of: #list_of_color_types#.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400366
367#Return Color_Type in Image_Info ##
368
369#Example
Cary Clarkab2621d2018-01-30 10:08:57 -0500370 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
371 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -0400372 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
373 SkDebugf("color type: k" "%s" "_SkColorType\n", colors[pixmap.colorType()]);
374#StdOut
Cary Clarkab2621d2018-01-30 10:08:57 -0500375color type: kAlpha_8_SkColorType
Cary Clark6fc50412017-09-21 12:31:06 -0400376##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400377##
378
Cary Clarkbc5697d2017-10-04 14:31:33 -0400379#SeeAlso alphaType() SkImageInfo::colorType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400380
381##
382
383# ------------------------------------------------------------------------------
384
Cary Clark682c58d2018-05-16 07:07:07 -0400385#Method SkAlphaType alphaType() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400386
Cary Clarkab2621d2018-01-30 10:08:57 -0500387#In Image_Info_Access
388#Line # returns Image_Info Alpha_Type ##
Cary Clark681287e2018-03-16 11:34:15 -0400389Returns Alpha_Type, one of: #list_of_alpha_types#.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400390
391#Return Alpha_Type in Image_Info ##
392
393#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400394 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
395 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
396 SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[pixmap.alphaType()]);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400397#StdOut
398alpha type: kPremul_SkAlphaType
399##
400##
401
Cary Clarkbc5697d2017-10-04 14:31:33 -0400402#SeeAlso colorType() SkImageInfo::alphaType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400403
404##
405
406# ------------------------------------------------------------------------------
407
Cary Clark682c58d2018-05-16 07:07:07 -0400408#Method SkColorSpace* colorSpace() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400409
Cary Clarkab2621d2018-01-30 10:08:57 -0500410#In Image_Info_Access
411#Line # returns Image_Info Color_Space ##
Cary Clark09d80c02018-10-31 12:14:03 -0400412#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400413
414#Example
415#Description
416SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma
417and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma.
418##
Cary Clark682c58d2018-05-16 07:07:07 -0400419 SkPixmap pixmap(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
Cary Clark6fc50412017-09-21 12:31:06 -0400420 SkColorSpace::MakeSRGBLinear()), nullptr, 64);
421 SkColorSpace* colorSpace = pixmap.colorSpace();
422 SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
423 colorSpace->gammaCloseToSRGB() ? "true" : "false",
424 colorSpace->gammaIsLinear() ? "true" : "false",
425 colorSpace->isSRGB() ? "true" : "false");
426#StdOut
427gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
428##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400429##
430
Cary Clarkbc5697d2017-10-04 14:31:33 -0400431#SeeAlso Color_Space SkImageInfo::colorSpace
Cary Clarkd0530ba2017-09-14 11:25:39 -0400432
433##
434
435# ------------------------------------------------------------------------------
436
Cary Clark682c58d2018-05-16 07:07:07 -0400437#Method bool isOpaque() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400438
Cary Clarkab2621d2018-01-30 10:08:57 -0500439#In Image_Info_Access
440#Line # returns true if Image_Info describes opaque pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -0400441#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400442
443#Example
444#Description
445 isOpaque ignores whether all pixels are opaque or not.
446##
Cary Clark6fc50412017-09-21 12:31:06 -0400447 std::vector<uint32_t> pixels;
448 const int height = 2;
449 const int width = 2;
450 pixels.resize(height * width * 4);
451 SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType,
452 kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4);
453 for (int index = 0; index < 2; ++index) {
454 pixmap.erase(0x00000000);
455 SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false");
456 pixmap.erase(0xFFFFFFFF);
457 SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false");
458 pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType),
459 (const void*) &pixels.front(), width * 4);
460 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400461#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400462isOpaque: false
463isOpaque: false
464isOpaque: true
Cary Clarkd0530ba2017-09-14 11:25:39 -0400465isOpaque: true
466##
467##
468
469#SeeAlso computeIsOpaque SkImageInfo::isOpaque
470
471##
472
473# ------------------------------------------------------------------------------
474
Cary Clark682c58d2018-05-16 07:07:07 -0400475#Method SkIRect bounds() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400476
Cary Clarkab2621d2018-01-30 10:08:57 -0500477#In Image_Info_Access
478#Line # returns width and height as Rectangle ##
Cary Clark09d80c02018-10-31 12:14:03 -0400479#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400480
481#Example
482 for (int width : { 0, 2 } ) {
483 for (int height : { 0, 2 } ) {
Cary Clark6fc50412017-09-21 12:31:06 -0400484 SkPixmap pixmap(SkImageInfo::MakeA8(width, height), nullptr, width);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400485 SkDebugf("width: %d height: %d empty: %s\n", width, height,
486 pixmap.bounds().isEmpty() ? "true" : "false");
487 }
488 }
489#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400490width: 0 height: 0 empty: true
491width: 0 height: 2 empty: true
492width: 2 height: 0 empty: true
Cary Clarkd0530ba2017-09-14 11:25:39 -0400493width: 2 height: 2 empty: false
494##
495##
496
Cary Clark682c58d2018-05-16 07:07:07 -0400497#SeeAlso height() width() IRect
Cary Clarkd0530ba2017-09-14 11:25:39 -0400498
499##
500
501# ------------------------------------------------------------------------------
502
Cary Clark682c58d2018-05-16 07:07:07 -0400503#Method int rowBytesAsPixels() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400504
Cary Clarkab2621d2018-01-30 10:08:57 -0500505#In Image_Info_Access
506#Line # returns interval between rows in pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -0400507#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400508
509#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400510 for (int rowBytes : { 4, 5, 6, 7, 8} ) {
511 SkPixmap pixmap(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), nullptr, rowBytes);
512 SkDebugf("rowBytes: %d rowBytesAsPixels: %d\n", rowBytes, pixmap.rowBytesAsPixels());
513 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400514#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400515rowBytes: 4 rowBytesAsPixels: 1
516rowBytes: 5 rowBytesAsPixels: 1
517rowBytes: 6 rowBytesAsPixels: 1
518rowBytes: 7 rowBytesAsPixels: 1
Cary Clarkd0530ba2017-09-14 11:25:39 -0400519rowBytes: 8 rowBytesAsPixels: 2
520##
521##
522
523#SeeAlso rowBytes shiftPerPixel width SkImageInfo::bytesPerPixel
524
525##
526
527# ------------------------------------------------------------------------------
528
Cary Clark682c58d2018-05-16 07:07:07 -0400529#Method int shiftPerPixel() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400530
Cary Clarkab2621d2018-01-30 10:08:57 -0500531#In Image_Info_Access
532#Line # returns bit shift from pixels to bytes ##
Cary Clark09d80c02018-10-31 12:14:03 -0400533#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400534
535#Example
Cary Clarkab2621d2018-01-30 10:08:57 -0500536 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
537 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -0400538 SkImageInfo info = SkImageInfo::MakeA8(1, 1);
539 for (SkColorType colorType : { kUnknown_SkColorType, kAlpha_8_SkColorType,
Cary Clark682c58d2018-05-16 07:07:07 -0400540 kRGB_565_SkColorType, kARGB_4444_SkColorType,
Cary Clark6fc50412017-09-21 12:31:06 -0400541 kRGBA_8888_SkColorType, kBGRA_8888_SkColorType,
542 kGray_8_SkColorType, kRGBA_F16_SkColorType } ) {
543 SkPixmap pixmap(info.makeColorType(colorType), nullptr, 4);
544 SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d shiftPerPixel: %d\n",
545 colors[colorType], 10 - strlen(colors[colorType]), " ",
546 pixmap.info().bytesPerPixel(), pixmap.shiftPerPixel());
547 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400548#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400549color: kUnknown_SkColorType bytesPerPixel: 0 shiftPerPixel: 0
Cary Clarkab2621d2018-01-30 10:08:57 -0500550color: kAlpha_8_SkColorType bytesPerPixel: 1 shiftPerPixel: 0
Cary Clark6fc50412017-09-21 12:31:06 -0400551color: kRGB_565_SkColorType bytesPerPixel: 2 shiftPerPixel: 1
552color: kARGB_4444_SkColorType bytesPerPixel: 2 shiftPerPixel: 1
553color: kRGBA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2
554color: kBGRA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2
555color: kGray_8_SkColorType bytesPerPixel: 1 shiftPerPixel: 0
Cary Clarkd0530ba2017-09-14 11:25:39 -0400556color: kRGBA_F16_SkColorType bytesPerPixel: 8 shiftPerPixel: 3
557##
558##
559
560#SeeAlso rowBytes rowBytesAsPixels width SkImageInfo::bytesPerPixel
561
562##
563
564# ------------------------------------------------------------------------------
565
Cary Clarkbc5697d2017-10-04 14:31:33 -0400566#Method size_t computeByteSize() const
567
Cary Clarkab2621d2018-01-30 10:08:57 -0500568#In Image_Info_Access
569#Line # returns size required for pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -0400570#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400571
Cary Clarkd0530ba2017-09-14 11:25:39 -0400572#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400573 SkPixmap pixmap;
574 for (int width : { 1, 1000, 1000000 } ) {
575 for (int height: { 1, 1000, 1000000 } ) {
576 SkImageInfo imageInfo = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType);
Cary Clarkbc5697d2017-10-04 14:31:33 -0400577 pixmap.reset(imageInfo, nullptr, width * 5);
578 SkDebugf("width: %7d height: %7d computeByteSize: %13lld\n", width, height,
579 pixmap.computeByteSize());
Cary Clark6fc50412017-09-21 12:31:06 -0400580 }
581 }
Cary Clark6fc50412017-09-21 12:31:06 -0400582#StdOut
Ben Wagner29380bd2017-10-09 14:43:00 -0400583width: 1 height: 1 computeByteSize: 4
584width: 1 height: 1000 computeByteSize: 4999
585width: 1 height: 1000000 computeByteSize: 4999999
586width: 1000 height: 1 computeByteSize: 4000
587width: 1000 height: 1000 computeByteSize: 4999000
588width: 1000 height: 1000000 computeByteSize: 4999999000
589width: 1000000 height: 1 computeByteSize: 4000000
590width: 1000000 height: 1000 computeByteSize: 4999000000
Cary Clarkbc5697d2017-10-04 14:31:33 -0400591width: 1000000 height: 1000000 computeByteSize: 4999999000000
Cary Clarkd0530ba2017-09-14 11:25:39 -0400592##
593##
594
Cary Clarkbc5697d2017-10-04 14:31:33 -0400595#SeeAlso SkImageInfo::computeByteSize
Cary Clarkd0530ba2017-09-14 11:25:39 -0400596
597##
598
599#Subtopic Image_Info_Access ##
600
601#Subtopic Reader
Cary Clark08895c42018-02-01 09:37:32 -0500602#Line # examine pixel value ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400603
604# ------------------------------------------------------------------------------
605
606#Method bool computeIsOpaque() const
607
Cary Clarkab2621d2018-01-30 10:08:57 -0500608#In Reader
609#Line # returns true if all pixels are opaque ##
Cary Clark09d80c02018-10-31 12:14:03 -0400610#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400611
612#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400613 std::vector<uint32_t> pixels;
614 const int height = 2;
615 const int width = 2;
616 pixels.resize(height * width * 4);
617 SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType,
618 kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4);
619 for (int index = 0; index < 2; ++index) {
620 pixmap.erase(0x00000000);
621 SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false");
622 pixmap.erase(0xFFFFFFFF);
623 SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false");
624 pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType),
625 (const void*) &pixels.front(), width * 4);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400626 }
627#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400628computeIsOpaque: false
629computeIsOpaque: true
630computeIsOpaque: false
Cary Clarkd0530ba2017-09-14 11:25:39 -0400631computeIsOpaque: true
632##
633##
634
635#SeeAlso isOpaque Color_Type Alpha
636
637##
638
639# ------------------------------------------------------------------------------
640
641#Method SkColor getColor(int x, int y) const
642
Cary Clarkab2621d2018-01-30 10:08:57 -0500643#In Reader
644#Line # returns one pixel as Unpremultiplied Color ##
Cary Clark09d80c02018-10-31 12:14:03 -0400645#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400646
647#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400648 const int w = 4;
649 const int h = 4;
650 std::vector<SkPMColor> storage;
651 storage.resize(w * h);
652 SkDebugf("Premultiplied:\n");
653 for (int y = 0; y < h; ++y) {
654 SkDebugf("(0, %d) ", y);
655 for (int x = 0; x < w; ++x) {
656 int a = 0xFF * (x + y) / (w - 1 + h - 1);
657 storage[x + y * w] = SkPackARGB32(a, a * x / (w - 1), a * y / (h - 1), a);
658 SkDebugf("0x%08x%c", storage[x + y * w], x == w - 1 ? '\n' : ' ');
659 }
660 }
661 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4);
662 SkDebugf("Unpremultiplied:\n");
663 for (int y = 0; y < h; ++y) {
664 SkDebugf("(0, %d) ", y);
665 for (int x = 0; x < w; ++x) {
666 SkDebugf("0x%08x%c", pixmap.getColor(x, y), x == w - 1 ? '\n' : ' ');
667 }
668 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400669#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400670Premultiplied:
Cary Clark682c58d2018-05-16 07:07:07 -0400671(0, 0) 0x00000000 0x2a0e002a 0x55380055 0x7f7f007f
672(0, 1) 0x2a000e2a 0x551c1c55 0x7f542a7f 0xaaaa38aa
673(0, 2) 0x55003855 0x7f2a547f 0xaa7171aa 0xd4d48dd4
674(0, 3) 0x7f007f7f 0xaa38aaaa 0xd48dd4d4 0xffffffff
Cary Clark6fc50412017-09-21 12:31:06 -0400675Unpremultiplied:
Cary Clark682c58d2018-05-16 07:07:07 -0400676(0, 0) 0x00000000 0x2a5500ff 0x55a800ff 0x7fff00ff
677(0, 1) 0x2a0055ff 0x555454ff 0x7fa954ff 0xaaff54ff
678(0, 2) 0x5500a8ff 0x7f54a9ff 0xaaaaaaff 0xd4ffaaff
679(0, 3) 0x7f00ffff 0xaa54ffff 0xd4aaffff 0xffffffff
Cary Clarkd0530ba2017-09-14 11:25:39 -0400680##
681##
682
Cary Clark8fe29402018-09-20 17:31:43 -0400683#SeeAlso getAlphaf addr() readPixels
684
685##
686
687#Method float getAlphaf(int x, int y) const
688#In Property
689#Line # returns Alpha normalized from zero to one ##
690
691Looks up the pixel at (x,y) and return its alpha component, normalized to [0..1].
Cary Clark77b3f3a2018-11-07 14:59:03 -0500692This is roughly equivalent to #Formula # SkGetColorA(getColor()) ##, but can be more efficient
Cary Clark8fe29402018-09-20 17:31:43 -0400693(and more precise if the pixels store more than 8 bits per component).
694
695#Param x column index, zero or greater, and less than width() ##
696#Param y row index, zero or greater, and less than height() ##
697
698#Return alpha converted to normalized float ##
699
700#NoExample
701##
702
703#SeeAlso getColor
Cary Clarkd0530ba2017-09-14 11:25:39 -0400704
705##
706
707#Subtopic Reader ##
708
709#Subtopic Readable_Address
Cary Clark08895c42018-02-01 09:37:32 -0500710#Line # returns read only pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400711
712# ------------------------------------------------------------------------------
713
714#Method const void* addr(int x, int y) const
715
Cary Clarkab2621d2018-01-30 10:08:57 -0500716#In Readable_Address
Cary Clark09d80c02018-10-31 12:14:03 -0400717#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400718
719#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400720 const int w = 4;
721 const int h = 4;
722 std::vector<SkPMColor> storage;
723 storage.resize(w * h);
724 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400725 SkDebugf("pixmap.addr(1, 2) %c= &storage[1 + 2 * w]\n",
726 pixmap.addr(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
727#StdOut
728pixmap.addr(1, 2) == &storage[1 + 2 * w]
729##
730##
731
Cary Clarkbc5697d2017-10-04 14:31:33 -0400732#SeeAlso addr8 addr16 addr32 addr64 addrF16 getColor writable_addr SkBitmap::getAddr
Cary Clarkd0530ba2017-09-14 11:25:39 -0400733
734##
735
736# ------------------------------------------------------------------------------
737
Cary Clark682c58d2018-05-16 07:07:07 -0400738#Method const uint8_t* addr8() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400739
Cary Clarkab2621d2018-01-30 10:08:57 -0500740#In Readable_Address
741#Line # returns readable pixel address as 8-bit pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -0400742#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400743
744#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400745 const int w = 4;
746 const int h = 4;
747 uint8_t storage[w * h];
748 SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType),
749 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400750 SkDebugf("pixmap.addr8() %c= storage\n",
751 pixmap.addr8() == storage ? '=' : '!');
752#StdOut
753pixmap.addr8() == storage
754##
755##
756
757#SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8
758
759##
760
761# ------------------------------------------------------------------------------
762
Cary Clark682c58d2018-05-16 07:07:07 -0400763#Method const uint16_t* addr16() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400764
Cary Clarkab2621d2018-01-30 10:08:57 -0500765#In Readable_Address
766#Line # returns readable pixel address as 16-bit pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -0400767#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400768
769#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400770 const int w = 4;
771 const int h = 4;
772 uint16_t storage[w * h];
773 SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType),
774 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400775 SkDebugf("pixmap.addr16() %c= storage\n",
776 pixmap.addr16() == storage ? '=' : '!');
777#StdOut
778pixmap.addr16() == storage
779##
780##
781
782#SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16
783
784##
785
786# ------------------------------------------------------------------------------
787
Cary Clark682c58d2018-05-16 07:07:07 -0400788#Method const uint32_t* addr32() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400789
Cary Clarkab2621d2018-01-30 10:08:57 -0500790#In Readable_Address
791#Line # returns readable pixel address as 32-bit pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -0400792#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400793
794#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400795 const int w = 4;
796 const int h = 4;
797 uint32_t storage[w * h];
798 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType),
799 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400800 SkDebugf("pixmap.addr32() %c= storage\n",
801 pixmap.addr32() == storage ? '=' : '!');
802#StdOut
803pixmap.addr32() == storage
804##
805##
806
807#SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr32
808
809##
810
811# ------------------------------------------------------------------------------
812
Cary Clark682c58d2018-05-16 07:07:07 -0400813#Method const uint64_t* addr64() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400814
Cary Clarkab2621d2018-01-30 10:08:57 -0500815#In Readable_Address
816#Line # returns readable pixel address as 64-bit pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -0400817#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400818
819#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400820 const int w = 4;
821 const int h = 4;
822 uint64_t storage[w * h];
823 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
824 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400825 SkDebugf("pixmap.addr64() %c= storage\n",
826 pixmap.addr64() == storage ? '=' : '!');
827#StdOut
828pixmap.addr64() == storage
829##
830##
831
832#SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64
833
834##
835
836# ------------------------------------------------------------------------------
837
Cary Clark682c58d2018-05-16 07:07:07 -0400838#Method const uint16_t* addrF16() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400839
Cary Clarkab2621d2018-01-30 10:08:57 -0500840#In Readable_Address
841#Line # returns readable pixel component address as 16-bit pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -0400842#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400843
844#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400845 const int w = 4;
846 const int h = 4;
847 uint16_t storage[w * h * 4];
848 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
849 storage, w * 4 * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400850 SkDebugf("pixmap.addrF16() %c= storage\n",
851 pixmap.addrF16() == storage ? '=' : '!');
852#StdOut
853pixmap.addrF16() == storage
854##
855##
856
857#SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16
858
859##
860
861# ------------------------------------------------------------------------------
862
Cary Clark682c58d2018-05-16 07:07:07 -0400863#Method const uint8_t* addr8(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400864
Cary Clarkab2621d2018-01-30 10:08:57 -0500865#In Readable_Address
Cary Clark09d80c02018-10-31 12:14:03 -0400866#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400867
868#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400869 const int w = 4;
870 const int h = 4;
871 uint8_t storage[w * h];
872 SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType),
873 storage, w * sizeof(storage[0]));
874 SkDebugf("pixmap.addr8(1, 2) %c= &storage[1 + 2 * w]\n",
875 pixmap.addr8(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
Cary Clarkd0530ba2017-09-14 11:25:39 -0400876#StdOut
877pixmap.addr8(1, 2) == &storage[1 + 2 * w]
878##
879##
880
881#SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8
882
883##
884
885# ------------------------------------------------------------------------------
886
Cary Clark682c58d2018-05-16 07:07:07 -0400887#Method const uint16_t* addr16(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400888
Cary Clarkab2621d2018-01-30 10:08:57 -0500889#In Readable_Address
Cary Clark09d80c02018-10-31 12:14:03 -0400890#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400891
892#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400893 const int w = 4;
894 const int h = 4;
895 uint16_t storage[w * h];
896 SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType),
897 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400898 SkDebugf("pixmap.addr16(1, 2) %c= &storage[1 + 2 * w]\n",
899 pixmap.addr16(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
900#StdOut
901pixmap.addr16(1, 2) == &storage[1 + 2 * w]
902##
903##
904
905#SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16
906
907##
908
909# ------------------------------------------------------------------------------
910
Cary Clark682c58d2018-05-16 07:07:07 -0400911#Method const uint32_t* addr32(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400912
Cary Clarkab2621d2018-01-30 10:08:57 -0500913#In Readable_Address
Cary Clark09d80c02018-10-31 12:14:03 -0400914#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400915
916#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400917 const int w = 4;
918 const int h = 4;
919 uint32_t storage[w * h];
920 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_8888_SkColorType, kPremul_SkAlphaType),
921 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400922 SkDebugf("pixmap.addr32(1, 2) %c= &storage[1 + 2 * w]\n",
923 pixmap.addr32(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
924#StdOut
925pixmap.addr32(1, 2) == &storage[1 + 2 * w]
926##
927##
928
Cary Clark2ade9972017-11-02 17:49:34 -0400929#SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr64
Cary Clarkd0530ba2017-09-14 11:25:39 -0400930
931##
932
933# ------------------------------------------------------------------------------
934
Cary Clark682c58d2018-05-16 07:07:07 -0400935#Method const uint64_t* addr64(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400936
Cary Clarkab2621d2018-01-30 10:08:57 -0500937#In Readable_Address
Cary Clark09d80c02018-10-31 12:14:03 -0400938#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400939
940#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400941 const int w = 4;
942 const int h = 4;
943 uint64_t storage[w * h];
944 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
945 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400946 SkDebugf("pixmap.addr64(1, 2) %c= &storage[1 + 2 * w]\n",
947 pixmap.addr64(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
948#StdOut
949pixmap.addr64(1, 2) == &storage[1 + 2 * w]
950##
951##
952
953#SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64
954
955##
956
957# ------------------------------------------------------------------------------
958
Cary Clark682c58d2018-05-16 07:07:07 -0400959#Method const uint16_t* addrF16(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400960
Cary Clarkab2621d2018-01-30 10:08:57 -0500961#In Readable_Address
Cary Clark09d80c02018-10-31 12:14:03 -0400962#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400963
964#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400965 const int w = 4;
966 const int h = 4;
967 const int wordsPerPixel = 4;
968 const int rowWords = w * wordsPerPixel;
969 uint16_t storage[rowWords * h];
970 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
971 storage, rowWords * sizeof(storage[0]));
972 SkDebugf("pixmap.addrF16(1, 2) %c= &storage[1 * wordsPerPixel + 2 * rowWords]\n",
973 pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords] ? '=' : '!');
Cary Clarkd0530ba2017-09-14 11:25:39 -0400974#StdOut
975pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords]
976##
977##
978
979#SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16
980
981##
982
983#Subtopic Readable_Address ##
984
985#Subtopic Writable_Address
Cary Clark08895c42018-02-01 09:37:32 -0500986#Line # returns writable pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400987
988# ------------------------------------------------------------------------------
989
Cary Clark682c58d2018-05-16 07:07:07 -0400990#Method void* writable_addr() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400991
Cary Clarkab2621d2018-01-30 10:08:57 -0500992#In Writable_Address
993#Line # returns writable pixel address as void pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -0400994#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400995
996#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400997 const int w = 4;
998 const int h = 4;
999 SkPMColor storage[w * h * 4];
1000 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4);
1001 SkDebugf("pixmap.writable_addr() %c= (void *)storage\n",
1002 pixmap.writable_addr() == (void *)storage ? '=' : '!');
1003 pixmap.erase(0x00000000);
1004 *(SkPMColor*)pixmap.writable_addr() = 0xFFFFFFFF;
1005 SkDebugf("pixmap.getColor(0, 1) %c= 0x00000000\n",
1006 pixmap.getColor(0, 1) == 0x00000000 ? '=' : '!');
1007 SkDebugf("pixmap.getColor(0, 0) %c= 0xFFFFFFFF\n",
Cary Clarkd0530ba2017-09-14 11:25:39 -04001008 pixmap.getColor(0, 0) == 0xFFFFFFFF ? '=' : '!');
1009#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -04001010pixmap.writable_addr() == (void *)storage
1011pixmap.getColor(0, 1) == 0x00000000
Cary Clarkd0530ba2017-09-14 11:25:39 -04001012pixmap.getColor(0, 0) == 0xFFFFFFFF
1013##
1014##
1015
1016#SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr()
1017
1018##
1019
1020# ------------------------------------------------------------------------------
1021
Cary Clark682c58d2018-05-16 07:07:07 -04001022#Method void* writable_addr(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001023
Cary Clarkab2621d2018-01-30 10:08:57 -05001024#In Writable_Address
Cary Clark09d80c02018-10-31 12:14:03 -04001025#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001026
1027#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001028 const int w = 4;
1029 const int h = 4;
1030 SkPMColor storage[w * h * 4];
1031 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4);
1032 SkDebugf("pixmap.writable_addr() %c= (void *)storage\n",
1033 pixmap.writable_addr() == (void *)storage ? '=' : '!');
1034 pixmap.erase(0x00000000);
1035 *(SkPMColor*)pixmap.writable_addr(1, 2) = 0xFFFFFFFF;
1036 SkDebugf("pixmap.getColor(0, 0) %c= 0x00000000\n",
1037 pixmap.getColor(0, 0) == 0x00000000 ? '=' : '!');
1038 SkDebugf("pixmap.getColor(1, 2) %c= 0xFFFFFFFF\n",
Cary Clarkd0530ba2017-09-14 11:25:39 -04001039 pixmap.getColor(1, 2) == 0xFFFFFFFF ? '=' : '!');
1040#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -04001041pixmap.writable_addr() == (void *)storage
1042pixmap.getColor(0, 0) == 0x00000000
Cary Clarkd0530ba2017-09-14 11:25:39 -04001043pixmap.getColor(1, 2) == 0xFFFFFFFF
1044##
1045##
1046
1047#SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr()
1048
1049##
1050
1051# ------------------------------------------------------------------------------
1052
Cary Clark682c58d2018-05-16 07:07:07 -04001053#Method uint8_t* writable_addr8(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001054
Cary Clarkab2621d2018-01-30 10:08:57 -05001055#In Writable_Address
1056#Line # returns writable pixel address as 8-bit pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -04001057#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001058
1059#Example
1060#Height 64
1061#Description
1062Altering pixels after drawing Bitmap is not guaranteed to affect subsequent
1063drawing on all platforms. Adding a second SkBitmap::installPixels after editing
1064pixel memory is safer.
1065##
Cary Clark6fc50412017-09-21 12:31:06 -04001066void draw(SkCanvas* canvas) {
1067 uint8_t storage[][5] = {{ 0, 0, 64, 0, 0},
1068 { 0, 128, 255, 128, 0},
1069 {64, 255, 255, 255, 64},
1070 { 0, 128, 255, 128, 0},
1071 { 0, 0, 64, 0, 0}};
1072 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kPremul_SkAlphaType);
1073 SkPixmap pixmap(imageInfo, storage[0], 5);
1074 SkBitmap bitmap;
1075 bitmap.installPixels(pixmap);
1076 canvas->scale(10, 10);
1077 canvas->drawBitmap(bitmap, 0, 0);
1078 *pixmap.writable_addr8(2, 2) = 0;
1079// bitmap.installPixels(pixmap); // uncomment to fix on GPU
1080 canvas->drawBitmap(bitmap, 10, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001081}
1082##
1083
1084#SeeAlso writable_addr writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr() addr8
1085
1086##
1087
1088# ------------------------------------------------------------------------------
1089
Cary Clark682c58d2018-05-16 07:07:07 -04001090#Method uint16_t* writable_addr16(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001091
Cary Clarkab2621d2018-01-30 10:08:57 -05001092#In Writable_Address
1093#Line # returns writable pixel address as 16-bit pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -04001094#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001095
1096#Example
1097#Description
1098Draw a five by five bitmap, and draw it again with a center black pixel.
1099The low nibble of the 16-bit word is Alpha.
1100##
1101#Height 64
Cary Clark6fc50412017-09-21 12:31:06 -04001102 uint16_t storage[][5] = {{ 0xCABF, 0xDABE, 0xCA9D, 0xC96C, 0xA39B },
1103 { 0xACEE, 0xA87C, 0x893A, 0x4779, 0x8708 },
1104 { 0x4B7C, 0x255B, 0x2559, 0x2557, 0x4656 },
1105 { 0x9099, 0x8128, 0x2557, 0x4124, 0x3323 },
1106 { 0x7547, 0x5505, 0x4434, 0x2012, 0x0000 }};
1107 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kARGB_4444_SkColorType, kPremul_SkAlphaType);
1108 SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
1109 SkBitmap bitmap;
1110 bitmap.installPixels(pixmap);
1111 canvas->scale(10, 10);
1112 canvas->drawBitmap(bitmap, 0, 0);
1113 *pixmap.writable_addr16(2, 2) = 0x000F;
1114 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001115 canvas->drawBitmap(bitmap, 10, 0);
1116##
1117
1118#SeeAlso writable_addr writable_addr8 writable_addr32 writable_addr64 writable_addrF16 addr() addr16
1119
1120##
1121
1122# ------------------------------------------------------------------------------
1123
Cary Clark682c58d2018-05-16 07:07:07 -04001124#Method uint32_t* writable_addr32(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001125
Cary Clarkab2621d2018-01-30 10:08:57 -05001126#In Writable_Address
1127#Line # returns writable pixel address as 32-bit pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -04001128#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001129
1130#Example
1131#Image 4
1132#Height 72
Cary Clark6fc50412017-09-21 12:31:06 -04001133 std::vector<int32_t> pixels;
1134 pixels.resize(image->height() * image->width() * 4);
1135 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
1136 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
1137 image->readPixels(pixmap, 0, 0);
1138 for (int y = 0; y < pixmap.height() / 2; ++y) {
1139 for (int x = 0; x < pixmap.width(); ++x) {
1140 if ((x & 4) == (y & 4)) {
Cary Clark4d759752018-06-19 12:57:43 -04001141 *pixmap.writable_addr32(x, y) =
1142 *pixmap.writable_addr32(pixmap.width() - x, pixmap.height() - y);
Cary Clark6fc50412017-09-21 12:31:06 -04001143 }
1144 }
1145 }
1146 SkBitmap bitmap;
1147 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001148 canvas->drawBitmap(bitmap, 0, 0);
1149##
1150
1151#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr64 writable_addrF16 addr() addr32
1152
1153##
1154
1155# ------------------------------------------------------------------------------
1156
Cary Clark682c58d2018-05-16 07:07:07 -04001157#Method uint64_t* writable_addr64(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001158
Cary Clarkab2621d2018-01-30 10:08:57 -05001159#In Writable_Address
1160#Line # returns writable pixel address as 64-bit pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -04001161#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001162
1163#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001164#Height 40
Cary Clark6fc50412017-09-21 12:31:06 -04001165 SkImageInfo info = SkImageInfo::Make(3, 3, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
1166 uint64_t storage[9];
1167 SkPixmap pixmap(info, storage, 3 * sizeof(uint64_t));
1168 SkColor4f c4 { 1, 0.45f, 0.25f, 0.65f };
1169 pixmap.erase(c4);
1170 SkBitmap bitmap;
1171 canvas->scale(10, 10);
1172 bitmap.installPixels(pixmap);
1173 canvas->drawBitmap(bitmap, 0, 0);
1174 *pixmap.writable_addr64(1, 1) |= 0x00ff000000000000LL;
1175 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001176 canvas->drawBitmap(bitmap, 10, 0);
1177##
1178
1179#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addrF16 addr() addr64
1180
1181##
1182
1183# ------------------------------------------------------------------------------
1184
Cary Clark682c58d2018-05-16 07:07:07 -04001185#Method uint16_t* writable_addrF16(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001186
Cary Clarkab2621d2018-01-30 10:08:57 -05001187#In Writable_Address
1188#Line # returns writable pixel component address as 16-bit pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -04001189#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001190
1191#Example
1192#Height 64
1193#Description
1194Left bitmap is drawn with two pixels defined in half float format. Right bitmap
Cary Clark682c58d2018-05-16 07:07:07 -04001195is drawn after overwriting bottom half float color with top half float color.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001196##
Cary Clark6fc50412017-09-21 12:31:06 -04001197 SkImageInfo info = SkImageInfo::Make(1, 2, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
1198 uint16_t storage[2][4];
1199 SkPixmap pixmap(info, storage[0], sizeof(uint64_t));
1200 SkIRect topPixelBounds = {0, 0, 1, 1};
1201 pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds);
1202 SkIRect bottomPixelBounds = {0, 1, 1, 2};
1203 pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds);
1204 SkBitmap bitmap;
1205 canvas->scale(20, 20);
1206 bitmap.installPixels(pixmap);
1207 canvas->drawBitmap(bitmap, 0, 0);
1208 uint16_t* pixel2 = pixmap.writable_addrF16(0, 1);
1209 for (int i = 0; i < 4; ++i) {
1210 pixel2[i] = storage[0][i];
1211 }
1212 bitmap.installPixels(pixmap);
1213 canvas->drawBitmap(bitmap, 4, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001214##
1215
1216#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addr64 addr() addrF16
1217
1218##
1219
1220#Subtopic Writable_Address ##
1221
Cary Clark78de7512018-02-07 07:27:09 -05001222#Subtopic Pixels
Cary Clark78de7512018-02-07 07:27:09 -05001223#Line # read and write pixel values ##
1224##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001225
1226# ------------------------------------------------------------------------------
1227
Cary Clarke80cd442018-07-17 13:19:56 -04001228#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05001229#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001230#Line # copies and converts pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -04001231#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001232
1233#Example
1234#Height 128
1235#Description
1236Transferring the gradient from 8 bits per component to 4 bits per component
1237creates visible banding.
1238##
Cary Clark6fc50412017-09-21 12:31:06 -04001239 std::vector<int32_t> pixels;
1240 const int width = 256;
1241 const int height = 64;
1242 pixels.resize(height * width * 4);
1243 SkImageInfo srcInfo = SkImageInfo::MakeN32Premul(width, height);
1244 SkPixmap srcPixmap(srcInfo, (const void*) &pixels.front(), width * 4);
1245 SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 };
1246 SkPoint gradPoints[] = { { 0, 0 }, { 256, 0 } };
1247 SkPaint paint;
1248 paint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1249 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1250 SkBitmap bitmap;
1251 bitmap.installPixels(srcPixmap);
1252 SkCanvas srcCanvas(bitmap);
1253 srcCanvas.drawRect(SkRect::MakeWH(width, height), paint);
1254 canvas->drawBitmap(bitmap, 0, 0);
1255 std::vector<int32_t> dstPixels;
1256 dstPixels.resize(height * width * 2);
1257 SkImageInfo dstInfo = srcInfo.makeColorType(kARGB_4444_SkColorType);
1258 srcPixmap.readPixels(dstInfo, &dstPixels.front(), width * 2);
1259 SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2);
1260 bitmap.installPixels(dstPixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001261 canvas->drawBitmap(bitmap, 0, 128);
1262##
1263
1264#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1265
1266##
1267
1268# ------------------------------------------------------------------------------
1269
1270#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX,
Cary Clark682c58d2018-05-16 07:07:07 -04001271 int srcY) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001272
1273Copies a Rect of pixels to dstPixels. Copy starts at (srcX, srcY), and does not
Cary Clarkac47b882018-01-11 10:35:44 -05001274exceed Pixmap (width(), height()).
Cary Clark6fc50412017-09-21 12:31:06 -04001275
Cary Clark682c58d2018-05-16 07:07:07 -04001276dstInfo specifies width, height, Color_Type, Alpha_Type, and
Cary Clarkd0530ba2017-09-14 11:25:39 -04001277Color_Space of destination. dstRowBytes specifics the gap from one destination
1278row to the next. Returns true if pixels are copied. Returns false if
Cary Clark77b3f3a2018-11-07 14:59:03 -05001279dstInfo has no address, or dstRowBytes is less than dstInfo.minRowBytes().
Cary Clarkd0530ba2017-09-14 11:25:39 -04001280
Cary Clarkac47b882018-01-11 10:35:44 -05001281Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clark77b3f3a2018-11-07 14:59:03 -05001282kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match.
1283If Pixmap colorType is kGray_8_SkColorType, dstInfo.colorSpace() must match.
1284If Pixmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType() must
1285match. If Pixmap colorSpace is nullptr, dstInfo.colorSpace() must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001286false if pixel conversion is not possible.
Cary Clark682c58d2018-05-16 07:07:07 -04001287
Cary Clarkd0530ba2017-09-14 11:25:39 -04001288srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clarkac47b882018-01-11 10:35:44 -05001289false if Pixmap width() or height() is zero or negative. Returns false if:
Cary Clark154beea2017-10-26 07:58:48 -04001290
Cary Clark2be81cf2018-09-13 12:04:30 -04001291#Formula # abs(srcX) >= Pixmap width() ##, or if #Formula # abs(srcY) >= Pixmap height() ##.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001292
1293#Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ##
1294#Param dstPixels destination pixel storage ##
1295#Param dstRowBytes destination row length ##
1296#Param srcX column index whose absolute value is less than width() ##
1297#Param srcY row index whose absolute value is less than height() ##
1298
1299#Return true if pixels are copied to dstPixels ##
1300
1301#Example
1302#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001303void draw(SkCanvas* canvas) {
1304 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1305 std::vector<int32_t> srcPixels;
1306 const int rowBytes = image->width() * 4;
1307 srcPixels.resize(image->height() * rowBytes);
1308 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1309 image->readPixels(pixmap, 0, 0);
1310 for (int offset : { 32, 64, 96 } ) {
1311 std::vector<int32_t> dstPixels;
1312 dstPixels.resize(image->height() * rowBytes);
1313 pixmap.readPixels(info, &dstPixels.front(), rowBytes, offset, 0);
1314 SkBitmap bitmap;
1315 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1316 bitmap.installPixels(dstmap);
1317 canvas->translate(32, 32);
1318 canvas->drawBitmap(bitmap, 0, 0);
1319 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001320}
1321##
1322
1323#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1324
1325##
1326
1327# ------------------------------------------------------------------------------
1328
Cary Clark682c58d2018-05-16 07:07:07 -04001329#Method bool readPixels(const SkPixmap& dst, int srcX, int srcY) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001330
1331Copies a Rect of pixels to dst. Copy starts at (srcX, srcY), and does not
Cary Clarkac47b882018-01-11 10:35:44 -05001332exceed Pixmap (width(), height()). dst specifies width, height, Color_Type,
Cary Clarkd0530ba2017-09-14 11:25:39 -04001333Alpha_Type, and Color_Space of destination. Returns true if pixels are copied.
Cary Clark77b3f3a2018-11-07 14:59:03 -05001334Returns false if dst.addr() equals nullptr, or dst.rowBytes() is less than
Cary Clarkd0530ba2017-09-14 11:25:39 -04001335dst SkImageInfo::minRowBytes.
1336
Cary Clarkac47b882018-01-11 10:35:44 -05001337Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clark77b3f3a2018-11-07 14:59:03 -05001338kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.info().colorType() must match.
1339If Pixmap colorType is kGray_8_SkColorType, dst.info().colorSpace() must match.
1340If Pixmap alphaType is kOpaque_SkAlphaType, dst.info().alphaType() must
1341match. If Pixmap colorSpace is nullptr, dst.info().colorSpace() must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001342false if pixel conversion is not possible.
Cary Clark682c58d2018-05-16 07:07:07 -04001343
Cary Clarkd0530ba2017-09-14 11:25:39 -04001344srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clarkac47b882018-01-11 10:35:44 -05001345false Pixmap width() or height() is zero or negative. Returns false if:
Cary Clark154beea2017-10-26 07:58:48 -04001346
Cary Clark2be81cf2018-09-13 12:04:30 -04001347#Formula # abs(srcX) >= Pixmap width() ##, or if #Formula # abs(srcY) >= Pixmap height() ##.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001348
1349#Param dst Image_Info and pixel address to write to ##
1350#Param srcX column index whose absolute value is less than width() ##
1351#Param srcY row index whose absolute value is less than height() ##
1352
1353#Return true if pixels are copied to dst ##
1354
1355#Example
1356#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001357void draw(SkCanvas* canvas) {
1358 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1359 std::vector<int32_t> srcPixels;
1360 const int rowBytes = image->width() * 4;
1361 srcPixels.resize(image->height() * rowBytes);
1362 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1363 image->readPixels(pixmap, 0, 0);
1364 for (int offset : { 32, 64, 96 } ) {
1365 std::vector<int32_t> dstPixels;
1366 dstPixels.resize(image->height() * rowBytes);
1367 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1368 pixmap.readPixels(dstmap, offset, 0);
1369 SkBitmap bitmap;
1370 bitmap.installPixels(dstmap);
1371 canvas->translate(32, 32);
1372 canvas->drawBitmap(bitmap, 0, 0);
1373 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001374}
1375##
1376
1377#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1378
1379##
1380
1381# ------------------------------------------------------------------------------
1382
Cary Clark682c58d2018-05-16 07:07:07 -04001383#Method bool readPixels(const SkPixmap& dst) const
Cary Clark09d80c02018-10-31 12:14:03 -04001384#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001385
1386#Example
1387#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001388void draw(SkCanvas* canvas) {
1389 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1390 std::vector<int32_t> srcPixels;
1391 const int rowBytes = image->width() * 4;
1392 srcPixels.resize(image->height() * rowBytes);
1393 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1394 image->readPixels(pixmap, 0, 0);
1395 for (int index = 0; index < 3; ++index ) {
1396 std::vector<int32_t> dstPixels;
1397 dstPixels.resize(image->height() * rowBytes);
1398 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1399 pixmap.readPixels(dstmap);
1400 SkBitmap bitmap;
1401 bitmap.installPixels(dstmap);
1402 canvas->translate(32, 32);
1403 canvas->drawBitmap(bitmap, 0, 0);
1404 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001405}
1406##
1407
1408#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1409
1410##
1411
1412# ------------------------------------------------------------------------------
1413
1414#Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality) const
1415
Cary Clark78de7512018-02-07 07:27:09 -05001416#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001417#Line # scales and converts pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -04001418#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001419
1420#Example
1421#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001422void draw(SkCanvas* canvas) {
1423 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1424 std::vector<int32_t> srcPixels;
1425 int rowBytes = image->width() * 4;
1426 srcPixels.resize(image->height() * rowBytes);
1427 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1428 image->readPixels(pixmap, 0, 0);
1429 for (int offset : { 32, 64, 96 } ) {
1430 info = SkImageInfo::MakeN32Premul(image->width() + offset, image->height());
1431 rowBytes = info.width() * 4;
1432 std::vector<int32_t> dstPixels;
1433 dstPixels.resize(image->height() * rowBytes);
1434 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1435 pixmap.scalePixels(dstmap, kMedium_SkFilterQuality);
1436 SkBitmap bitmap;
1437 bitmap.installPixels(dstmap);
1438 canvas->translate(32, 32);
1439 canvas->drawBitmap(bitmap, 0, 0);
1440 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001441}
1442##
1443
1444#SeeAlso SkCanvas::drawBitmap SkImage::scalePixels
1445
1446##
1447
1448# ------------------------------------------------------------------------------
1449
1450#Method bool erase(SkColor color, const SkIRect& subset) const
1451
Cary Clark78de7512018-02-07 07:27:09 -05001452#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001453#Line # writes Color to pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -04001454#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001455
1456#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001457#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001458 uint32_t storage[2];
1459 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1460 SkPixmap pixmap(info, storage, info.minRowBytes());
1461 pixmap.erase(SK_ColorBLUE, {0, 0, 1, 1});
1462 pixmap.erase(SK_ColorRED, {0, 1, 1, 2});
1463 SkBitmap bitmap;
1464 canvas->scale(20, 20);
1465 bitmap.installPixels(pixmap);
1466 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001467##
1468
1469#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1470
1471##
1472
1473# ------------------------------------------------------------------------------
1474
Cary Clark682c58d2018-05-16 07:07:07 -04001475#Method bool erase(SkColor color) const
Cary Clark09d80c02018-10-31 12:14:03 -04001476#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001477
1478#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001479#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001480 uint32_t storage[2];
1481 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1482 SkPixmap pixmap(info, storage, info.minRowBytes());
1483 pixmap.erase(SK_ColorBLUE);
1484 SkBitmap bitmap;
1485 canvas->scale(20, 20);
1486 bitmap.installPixels(pixmap);
1487 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001488##
1489
1490#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1491
1492##
1493
1494# ------------------------------------------------------------------------------
1495
1496#Method bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const
Cary Clark09d80c02018-10-31 12:14:03 -04001497#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001498
1499#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001500#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001501 uint32_t storage[2];
1502 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1503 SkPixmap pixmap(info, storage, info.minRowBytes());
1504 SkIRect topPixelBounds = {0, 0, 1, 1};
1505 pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds);
1506 SkIRect bottomPixelBounds = {0, 1, 1, 2};
1507 pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds);
1508 SkBitmap bitmap;
1509 canvas->scale(20, 20);
1510 bitmap.installPixels(pixmap);
1511 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001512##
1513
1514#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1515
1516##
1517
Cary Clarkd0530ba2017-09-14 11:25:39 -04001518#Class SkPixmap ##
1519
1520#Topic Pixmap ##