blob: 1515b8e20b1d782ff2840de49c7cba358944e320 [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;
Brian Osman410b3022019-01-28 15:42:55 -0500162 sk_sp<SkColorSpace> colorSpace1 = SkColorSpace::MakeRGB(SkNamedTransferFn::kLinear,
163 SkNamedGamut::kRec2020);
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 extractSubset(SkPixmap* subset, const SkIRect& area) const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400181
Cary Clarkab2621d2018-01-30 10:08:57 -0500182#In Initialization
183#Line # sets pointer to portion of original ##
Cary Clark09d80c02018-10-31 12:14:03 -0400184#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400185
186#Example
187#Image 3
188#Height 128
Cary Clark6fc50412017-09-21 12:31:06 -0400189void draw(SkCanvas* canvas) {
190 std::vector<int32_t> pixels;
191 pixels.resize(image->height() * image->width() * 4);
192 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
193 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
194 image->readPixels(pixmap, 0, 0);
195 SkPixmap inset;
196 if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
197 SkBitmap bitmap;
198 bitmap.installPixels(inset);
199 canvas->drawBitmap(bitmap, 0, 0);
200 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400201}
202##
203
204#SeeAlso reset() SkIRect::intersect
205
206##
207
208#Subtopic Initialization ##
209
210#Subtopic Image_Info_Access
Cary Clark08895c42018-02-01 09:37:32 -0500211#Line # returns all or part of Image_Info ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400212
213# ------------------------------------------------------------------------------
214
Cary Clark682c58d2018-05-16 07:07:07 -0400215#Method const SkImageInfo& info() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400216
Cary Clarkab2621d2018-01-30 10:08:57 -0500217#In Image_Info_Access
218#Line # returns Image_Info ##
Cary Clark09d80c02018-10-31 12:14:03 -0400219#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400220
221#Example
222#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -0400223 std::vector<int32_t> pixels;
224 pixels.resize(image->height() * image->width() * 4);
225 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
226 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
227 image->readPixels(pixmap, 0, 0);
228 SkPixmap inset;
229 if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
230 const SkImageInfo& info = inset.info();
231 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
Cary Clarkab2621d2018-01-30 10:08:57 -0500232 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888",
233 "RGB_888x", "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -0400234 SkDebugf("width: %d height: %d color: %s alpha: %s\n", info.width(), info.height(),
235 colors[info.colorType()], alphas[info.alphaType()]);
236 }
237#StdOut
238width: 384 height: 384 color: BGRA_8888 alpha: Opaque
239##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400240##
241
242#SeeAlso Image_Info
243
244##
245
246# ------------------------------------------------------------------------------
247
Cary Clark682c58d2018-05-16 07:07:07 -0400248#Method size_t rowBytes() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400249
Cary Clarkab2621d2018-01-30 10:08:57 -0500250#In Image_Info_Access
251#Line # returns interval between rows in bytes ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400252Returns row bytes, the interval from one pixel row to the next. Row bytes
Cary Clark2be81cf2018-09-13 12:04:30 -0400253is at least as large as: #Formula # width() * info().bytesPerPixel() ##.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400254
Cary Clarkbc5697d2017-10-04 14:31:33 -0400255Returns zero if colorType is kUnknown_SkColorType.
256It is up to the Bitmap creator to ensure that row bytes is a useful value.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400257
258#Return byte length of pixel row ##
259
260#Example
261SkPixmap badPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 2};
262SkPixmap okPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 8};
263for (auto& pixmap : { badPixmap, okPixmap } ) {
Cary Clark682c58d2018-05-16 07:07:07 -0400264 SkDebugf("rowBytes: %d minRowBytes: %d\n", pixmap.rowBytes(),
Cary Clarkd0530ba2017-09-14 11:25:39 -0400265 pixmap.info().minRowBytes());
266}
267#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400268rowBytes: 2 minRowBytes: 4
Cary Clarkd0530ba2017-09-14 11:25:39 -0400269rowBytes: 8 minRowBytes: 4
270##
271##
272
273#SeeAlso addr() info() SkImageInfo::minRowBytes
274
275##
276
277# ------------------------------------------------------------------------------
278
Cary Clark682c58d2018-05-16 07:07:07 -0400279#Method const void* addr() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400280
Cary Clarkab2621d2018-01-30 10:08:57 -0500281#In Image_Info_Access
282#Line # returns readable pixel address as void pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -0400283#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400284
285#Example
286#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -0400287 std::vector<int32_t> pixels;
288 pixels.resize(image->height() * image->width() * 4);
289 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
290 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
291 image->readPixels(pixmap, 0, 0);
292 SkDebugf("pixels address: 0x%llx\n", pixmap.addr());
293 SkPixmap inset;
294 if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
295 SkDebugf("inset address: 0x%llx\n", inset.addr());
296 }
297#StdOut
298#Volatile
299pixels address: 0x7f2a440bb010
300inset address: 0x7f2a440fb210
301##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400302##
303
304#SeeAlso addr(int x, int y) addr8 addr16 addr32 addr64 info() rowBytes()
305
306##
307
308# ------------------------------------------------------------------------------
309
Cary Clark682c58d2018-05-16 07:07:07 -0400310#Method int width() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400311
Cary Clarkab2621d2018-01-30 10:08:57 -0500312#In Image_Info_Access
313#Line # returns pixel column count ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400314Returns pixel count in each pixel row. Should be equal or less than:
Cary Clark154beea2017-10-26 07:58:48 -0400315
Cary Clark2be81cf2018-09-13 12:04:30 -0400316#Formula # rowBytes() / info().bytesPerPixel() ##.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400317
318#Return pixel width in Image_Info ##
319
320#Example
321 SkImageInfo info = SkImageInfo::MakeA8(16, 32);
Cary Clark6fc50412017-09-21 12:31:06 -0400322 SkPixmap pixmap(info, nullptr, 64);
323 SkDebugf("pixmap width: %d info width: %d\n", pixmap.width(), info.width());
324#StdOut
325pixmap width: 16 info width: 16
326##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400327##
328
Cary Clarkbc5697d2017-10-04 14:31:33 -0400329#SeeAlso height() SkImageInfo::width()
Cary Clarkd0530ba2017-09-14 11:25:39 -0400330
331##
332
333# ------------------------------------------------------------------------------
334
Cary Clark682c58d2018-05-16 07:07:07 -0400335#Method int height() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400336
Cary Clarkab2621d2018-01-30 10:08:57 -0500337#In Image_Info_Access
338#Line # returns pixel row count ##
Cary Clark09d80c02018-10-31 12:14:03 -0400339#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400340
341#Example
Cary Clarkbc5697d2017-10-04 14:31:33 -0400342 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
343 SkDebugf("pixmap height: %d info height: %d\n", pixmap.height(), pixmap.info().height());
Cary Clark6fc50412017-09-21 12:31:06 -0400344#StdOut
345pixmap height: 32 info height: 32
346##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400347##
348
Cary Clark77b3f3a2018-11-07 14:59:03 -0500349#SeeAlso width SkImageInfo::height
Cary Clarkd0530ba2017-09-14 11:25:39 -0400350
351##
352
353# ------------------------------------------------------------------------------
354
Cary Clark682c58d2018-05-16 07:07:07 -0400355#Method SkColorType colorType() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400356
Cary Clarkab2621d2018-01-30 10:08:57 -0500357#In Image_Info_Access
358#Line # returns Image_Info Color_Type ##
Cary Clark1a8d7622018-03-05 13:26:16 -0500359Returns Color_Type, one of: #list_of_color_types#.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400360
361#Return Color_Type in Image_Info ##
362
363#Example
Cary Clarkab2621d2018-01-30 10:08:57 -0500364 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
365 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -0400366 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
367 SkDebugf("color type: k" "%s" "_SkColorType\n", colors[pixmap.colorType()]);
368#StdOut
Cary Clarkab2621d2018-01-30 10:08:57 -0500369color type: kAlpha_8_SkColorType
Cary Clark6fc50412017-09-21 12:31:06 -0400370##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400371##
372
Cary Clarkbc5697d2017-10-04 14:31:33 -0400373#SeeAlso alphaType() SkImageInfo::colorType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400374
375##
376
377# ------------------------------------------------------------------------------
378
Cary Clark682c58d2018-05-16 07:07:07 -0400379#Method SkAlphaType alphaType() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400380
Cary Clarkab2621d2018-01-30 10:08:57 -0500381#In Image_Info_Access
382#Line # returns Image_Info Alpha_Type ##
Cary Clark681287e2018-03-16 11:34:15 -0400383Returns Alpha_Type, one of: #list_of_alpha_types#.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400384
385#Return Alpha_Type in Image_Info ##
386
387#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400388 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
389 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
390 SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[pixmap.alphaType()]);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400391#StdOut
392alpha type: kPremul_SkAlphaType
393##
394##
395
Cary Clarkbc5697d2017-10-04 14:31:33 -0400396#SeeAlso colorType() SkImageInfo::alphaType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400397
398##
399
400# ------------------------------------------------------------------------------
401
Cary Clark682c58d2018-05-16 07:07:07 -0400402#Method SkColorSpace* colorSpace() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400403
Cary Clarkab2621d2018-01-30 10:08:57 -0500404#In Image_Info_Access
405#Line # returns Image_Info Color_Space ##
Cary Clark09d80c02018-10-31 12:14:03 -0400406#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400407
408#Example
409#Description
410SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma
411and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma.
412##
Cary Clark682c58d2018-05-16 07:07:07 -0400413 SkPixmap pixmap(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
Cary Clark6fc50412017-09-21 12:31:06 -0400414 SkColorSpace::MakeSRGBLinear()), nullptr, 64);
415 SkColorSpace* colorSpace = pixmap.colorSpace();
416 SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
417 colorSpace->gammaCloseToSRGB() ? "true" : "false",
418 colorSpace->gammaIsLinear() ? "true" : "false",
419 colorSpace->isSRGB() ? "true" : "false");
420#StdOut
421gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
422##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400423##
424
Cary Clarkbc5697d2017-10-04 14:31:33 -0400425#SeeAlso Color_Space SkImageInfo::colorSpace
Cary Clarkd0530ba2017-09-14 11:25:39 -0400426
427##
428
429# ------------------------------------------------------------------------------
430
Cary Clark682c58d2018-05-16 07:07:07 -0400431#Method bool isOpaque() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400432
Cary Clarkab2621d2018-01-30 10:08:57 -0500433#In Image_Info_Access
434#Line # returns true if Image_Info describes opaque pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -0400435#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400436
437#Example
438#Description
439 isOpaque ignores whether all pixels are opaque or not.
440##
Cary Clark6fc50412017-09-21 12:31:06 -0400441 std::vector<uint32_t> pixels;
442 const int height = 2;
443 const int width = 2;
444 pixels.resize(height * width * 4);
445 SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType,
446 kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4);
447 for (int index = 0; index < 2; ++index) {
448 pixmap.erase(0x00000000);
449 SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false");
450 pixmap.erase(0xFFFFFFFF);
451 SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false");
452 pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType),
453 (const void*) &pixels.front(), width * 4);
454 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400455#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400456isOpaque: false
457isOpaque: false
458isOpaque: true
Cary Clarkd0530ba2017-09-14 11:25:39 -0400459isOpaque: true
460##
461##
462
463#SeeAlso computeIsOpaque SkImageInfo::isOpaque
464
465##
466
467# ------------------------------------------------------------------------------
468
Cary Clark682c58d2018-05-16 07:07:07 -0400469#Method SkIRect bounds() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400470
Cary Clarkab2621d2018-01-30 10:08:57 -0500471#In Image_Info_Access
472#Line # returns width and height as Rectangle ##
Cary Clark09d80c02018-10-31 12:14:03 -0400473#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400474
475#Example
476 for (int width : { 0, 2 } ) {
477 for (int height : { 0, 2 } ) {
Cary Clark6fc50412017-09-21 12:31:06 -0400478 SkPixmap pixmap(SkImageInfo::MakeA8(width, height), nullptr, width);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400479 SkDebugf("width: %d height: %d empty: %s\n", width, height,
480 pixmap.bounds().isEmpty() ? "true" : "false");
481 }
482 }
483#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400484width: 0 height: 0 empty: true
485width: 0 height: 2 empty: true
486width: 2 height: 0 empty: true
Cary Clarkd0530ba2017-09-14 11:25:39 -0400487width: 2 height: 2 empty: false
488##
489##
490
Cary Clark682c58d2018-05-16 07:07:07 -0400491#SeeAlso height() width() IRect
Cary Clarkd0530ba2017-09-14 11:25:39 -0400492
493##
494
495# ------------------------------------------------------------------------------
496
Cary Clark682c58d2018-05-16 07:07:07 -0400497#Method int rowBytesAsPixels() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400498
Cary Clarkab2621d2018-01-30 10:08:57 -0500499#In Image_Info_Access
500#Line # returns interval between rows in pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -0400501#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400502
503#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400504 for (int rowBytes : { 4, 5, 6, 7, 8} ) {
505 SkPixmap pixmap(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), nullptr, rowBytes);
506 SkDebugf("rowBytes: %d rowBytesAsPixels: %d\n", rowBytes, pixmap.rowBytesAsPixels());
507 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400508#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400509rowBytes: 4 rowBytesAsPixels: 1
510rowBytes: 5 rowBytesAsPixels: 1
511rowBytes: 6 rowBytesAsPixels: 1
512rowBytes: 7 rowBytesAsPixels: 1
Cary Clarkd0530ba2017-09-14 11:25:39 -0400513rowBytes: 8 rowBytesAsPixels: 2
514##
515##
516
517#SeeAlso rowBytes shiftPerPixel width SkImageInfo::bytesPerPixel
518
519##
520
521# ------------------------------------------------------------------------------
522
Cary Clark682c58d2018-05-16 07:07:07 -0400523#Method int shiftPerPixel() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400524
Cary Clarkab2621d2018-01-30 10:08:57 -0500525#In Image_Info_Access
526#Line # returns bit shift from pixels to bytes ##
Cary Clark09d80c02018-10-31 12:14:03 -0400527#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400528
529#Example
Cary Clarkab2621d2018-01-30 10:08:57 -0500530 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
531 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -0400532 SkImageInfo info = SkImageInfo::MakeA8(1, 1);
533 for (SkColorType colorType : { kUnknown_SkColorType, kAlpha_8_SkColorType,
Cary Clark682c58d2018-05-16 07:07:07 -0400534 kRGB_565_SkColorType, kARGB_4444_SkColorType,
Cary Clark6fc50412017-09-21 12:31:06 -0400535 kRGBA_8888_SkColorType, kBGRA_8888_SkColorType,
536 kGray_8_SkColorType, kRGBA_F16_SkColorType } ) {
537 SkPixmap pixmap(info.makeColorType(colorType), nullptr, 4);
538 SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d shiftPerPixel: %d\n",
539 colors[colorType], 10 - strlen(colors[colorType]), " ",
540 pixmap.info().bytesPerPixel(), pixmap.shiftPerPixel());
541 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400542#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400543color: kUnknown_SkColorType bytesPerPixel: 0 shiftPerPixel: 0
Cary Clarkab2621d2018-01-30 10:08:57 -0500544color: kAlpha_8_SkColorType bytesPerPixel: 1 shiftPerPixel: 0
Cary Clark6fc50412017-09-21 12:31:06 -0400545color: kRGB_565_SkColorType bytesPerPixel: 2 shiftPerPixel: 1
546color: kARGB_4444_SkColorType bytesPerPixel: 2 shiftPerPixel: 1
547color: kRGBA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2
548color: kBGRA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2
549color: kGray_8_SkColorType bytesPerPixel: 1 shiftPerPixel: 0
Cary Clarkd0530ba2017-09-14 11:25:39 -0400550color: kRGBA_F16_SkColorType bytesPerPixel: 8 shiftPerPixel: 3
551##
552##
553
554#SeeAlso rowBytes rowBytesAsPixels width SkImageInfo::bytesPerPixel
555
556##
557
558# ------------------------------------------------------------------------------
559
Cary Clarkbc5697d2017-10-04 14:31:33 -0400560#Method size_t computeByteSize() const
561
Cary Clarkab2621d2018-01-30 10:08:57 -0500562#In Image_Info_Access
563#Line # returns size required for pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -0400564#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400565
Cary Clarkd0530ba2017-09-14 11:25:39 -0400566#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400567 SkPixmap pixmap;
568 for (int width : { 1, 1000, 1000000 } ) {
569 for (int height: { 1, 1000, 1000000 } ) {
570 SkImageInfo imageInfo = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType);
Cary Clarkbc5697d2017-10-04 14:31:33 -0400571 pixmap.reset(imageInfo, nullptr, width * 5);
572 SkDebugf("width: %7d height: %7d computeByteSize: %13lld\n", width, height,
573 pixmap.computeByteSize());
Cary Clark6fc50412017-09-21 12:31:06 -0400574 }
575 }
Cary Clark6fc50412017-09-21 12:31:06 -0400576#StdOut
Ben Wagner29380bd2017-10-09 14:43:00 -0400577width: 1 height: 1 computeByteSize: 4
578width: 1 height: 1000 computeByteSize: 4999
579width: 1 height: 1000000 computeByteSize: 4999999
580width: 1000 height: 1 computeByteSize: 4000
581width: 1000 height: 1000 computeByteSize: 4999000
582width: 1000 height: 1000000 computeByteSize: 4999999000
583width: 1000000 height: 1 computeByteSize: 4000000
584width: 1000000 height: 1000 computeByteSize: 4999000000
Cary Clarkbc5697d2017-10-04 14:31:33 -0400585width: 1000000 height: 1000000 computeByteSize: 4999999000000
Cary Clarkd0530ba2017-09-14 11:25:39 -0400586##
587##
588
Cary Clarkbc5697d2017-10-04 14:31:33 -0400589#SeeAlso SkImageInfo::computeByteSize
Cary Clarkd0530ba2017-09-14 11:25:39 -0400590
591##
592
593#Subtopic Image_Info_Access ##
594
595#Subtopic Reader
Cary Clark08895c42018-02-01 09:37:32 -0500596#Line # examine pixel value ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400597
598# ------------------------------------------------------------------------------
599
600#Method bool computeIsOpaque() const
601
Cary Clarkab2621d2018-01-30 10:08:57 -0500602#In Reader
603#Line # returns true if all pixels are opaque ##
Cary Clark09d80c02018-10-31 12:14:03 -0400604#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400605
606#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400607 std::vector<uint32_t> pixels;
608 const int height = 2;
609 const int width = 2;
610 pixels.resize(height * width * 4);
611 SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType,
612 kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4);
613 for (int index = 0; index < 2; ++index) {
614 pixmap.erase(0x00000000);
615 SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false");
616 pixmap.erase(0xFFFFFFFF);
617 SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false");
618 pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType),
619 (const void*) &pixels.front(), width * 4);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400620 }
621#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400622computeIsOpaque: false
623computeIsOpaque: true
624computeIsOpaque: false
Cary Clarkd0530ba2017-09-14 11:25:39 -0400625computeIsOpaque: true
626##
627##
628
629#SeeAlso isOpaque Color_Type Alpha
630
631##
632
633# ------------------------------------------------------------------------------
634
635#Method SkColor getColor(int x, int y) const
636
Cary Clarkab2621d2018-01-30 10:08:57 -0500637#In Reader
638#Line # returns one pixel as Unpremultiplied Color ##
Cary Clark09d80c02018-10-31 12:14:03 -0400639#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400640
641#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400642 const int w = 4;
643 const int h = 4;
644 std::vector<SkPMColor> storage;
645 storage.resize(w * h);
646 SkDebugf("Premultiplied:\n");
647 for (int y = 0; y < h; ++y) {
648 SkDebugf("(0, %d) ", y);
649 for (int x = 0; x < w; ++x) {
650 int a = 0xFF * (x + y) / (w - 1 + h - 1);
651 storage[x + y * w] = SkPackARGB32(a, a * x / (w - 1), a * y / (h - 1), a);
652 SkDebugf("0x%08x%c", storage[x + y * w], x == w - 1 ? '\n' : ' ');
653 }
654 }
655 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4);
656 SkDebugf("Unpremultiplied:\n");
657 for (int y = 0; y < h; ++y) {
658 SkDebugf("(0, %d) ", y);
659 for (int x = 0; x < w; ++x) {
660 SkDebugf("0x%08x%c", pixmap.getColor(x, y), x == w - 1 ? '\n' : ' ');
661 }
662 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400663#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400664Premultiplied:
Cary Clark682c58d2018-05-16 07:07:07 -0400665(0, 0) 0x00000000 0x2a0e002a 0x55380055 0x7f7f007f
666(0, 1) 0x2a000e2a 0x551c1c55 0x7f542a7f 0xaaaa38aa
667(0, 2) 0x55003855 0x7f2a547f 0xaa7171aa 0xd4d48dd4
668(0, 3) 0x7f007f7f 0xaa38aaaa 0xd48dd4d4 0xffffffff
Cary Clark6fc50412017-09-21 12:31:06 -0400669Unpremultiplied:
Cary Clark682c58d2018-05-16 07:07:07 -0400670(0, 0) 0x00000000 0x2a5500ff 0x55a800ff 0x7fff00ff
671(0, 1) 0x2a0055ff 0x555454ff 0x7fa954ff 0xaaff54ff
672(0, 2) 0x5500a8ff 0x7f54a9ff 0xaaaaaaff 0xd4ffaaff
673(0, 3) 0x7f00ffff 0xaa54ffff 0xd4aaffff 0xffffffff
Cary Clarkd0530ba2017-09-14 11:25:39 -0400674##
675##
676
Cary Clark8fe29402018-09-20 17:31:43 -0400677#SeeAlso getAlphaf addr() readPixels
678
679##
680
681#Method float getAlphaf(int x, int y) const
682#In Property
683#Line # returns Alpha normalized from zero to one ##
684
685Looks up the pixel at (x,y) and return its alpha component, normalized to [0..1].
Cary Clark77b3f3a2018-11-07 14:59:03 -0500686This is roughly equivalent to #Formula # SkGetColorA(getColor()) ##, but can be more efficient
Cary Clark8fe29402018-09-20 17:31:43 -0400687(and more precise if the pixels store more than 8 bits per component).
688
689#Param x column index, zero or greater, and less than width() ##
690#Param y row index, zero or greater, and less than height() ##
691
692#Return alpha converted to normalized float ##
693
694#NoExample
695##
696
697#SeeAlso getColor
Cary Clarkd0530ba2017-09-14 11:25:39 -0400698
699##
700
701#Subtopic Reader ##
702
703#Subtopic Readable_Address
Cary Clark08895c42018-02-01 09:37:32 -0500704#Line # returns read only pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400705
706# ------------------------------------------------------------------------------
707
708#Method const void* addr(int x, int y) const
709
Cary Clarkab2621d2018-01-30 10:08:57 -0500710#In Readable_Address
Cary Clark09d80c02018-10-31 12:14:03 -0400711#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400712
713#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400714 const int w = 4;
715 const int h = 4;
716 std::vector<SkPMColor> storage;
717 storage.resize(w * h);
718 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400719 SkDebugf("pixmap.addr(1, 2) %c= &storage[1 + 2 * w]\n",
720 pixmap.addr(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
721#StdOut
722pixmap.addr(1, 2) == &storage[1 + 2 * w]
723##
724##
725
Cary Clarkbc5697d2017-10-04 14:31:33 -0400726#SeeAlso addr8 addr16 addr32 addr64 addrF16 getColor writable_addr SkBitmap::getAddr
Cary Clarkd0530ba2017-09-14 11:25:39 -0400727
728##
729
730# ------------------------------------------------------------------------------
731
Cary Clark682c58d2018-05-16 07:07:07 -0400732#Method const uint8_t* addr8() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400733
Cary Clarkab2621d2018-01-30 10:08:57 -0500734#In Readable_Address
735#Line # returns readable pixel address as 8-bit pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -0400736#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400737
738#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400739 const int w = 4;
740 const int h = 4;
741 uint8_t storage[w * h];
742 SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType),
743 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400744 SkDebugf("pixmap.addr8() %c= storage\n",
745 pixmap.addr8() == storage ? '=' : '!');
746#StdOut
747pixmap.addr8() == storage
748##
749##
750
751#SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8
752
753##
754
755# ------------------------------------------------------------------------------
756
Cary Clark682c58d2018-05-16 07:07:07 -0400757#Method const uint16_t* addr16() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400758
Cary Clarkab2621d2018-01-30 10:08:57 -0500759#In Readable_Address
760#Line # returns readable pixel address as 16-bit pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -0400761#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400762
763#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400764 const int w = 4;
765 const int h = 4;
766 uint16_t storage[w * h];
767 SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType),
768 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400769 SkDebugf("pixmap.addr16() %c= storage\n",
770 pixmap.addr16() == storage ? '=' : '!');
771#StdOut
772pixmap.addr16() == storage
773##
774##
775
776#SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16
777
778##
779
780# ------------------------------------------------------------------------------
781
Cary Clark682c58d2018-05-16 07:07:07 -0400782#Method const uint32_t* addr32() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400783
Cary Clarkab2621d2018-01-30 10:08:57 -0500784#In Readable_Address
785#Line # returns readable pixel address as 32-bit pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -0400786#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400787
788#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400789 const int w = 4;
790 const int h = 4;
791 uint32_t storage[w * h];
792 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType),
793 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400794 SkDebugf("pixmap.addr32() %c= storage\n",
795 pixmap.addr32() == storage ? '=' : '!');
796#StdOut
797pixmap.addr32() == storage
798##
799##
800
801#SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr32
802
803##
804
805# ------------------------------------------------------------------------------
806
Cary Clark682c58d2018-05-16 07:07:07 -0400807#Method const uint64_t* addr64() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400808
Cary Clarkab2621d2018-01-30 10:08:57 -0500809#In Readable_Address
810#Line # returns readable pixel address as 64-bit pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -0400811#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400812
813#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400814 const int w = 4;
815 const int h = 4;
816 uint64_t storage[w * h];
817 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
818 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400819 SkDebugf("pixmap.addr64() %c= storage\n",
820 pixmap.addr64() == storage ? '=' : '!');
821#StdOut
822pixmap.addr64() == storage
823##
824##
825
826#SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64
827
828##
829
830# ------------------------------------------------------------------------------
831
Cary Clark682c58d2018-05-16 07:07:07 -0400832#Method const uint16_t* addrF16() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400833
Cary Clarkab2621d2018-01-30 10:08:57 -0500834#In Readable_Address
835#Line # returns readable pixel component address as 16-bit pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -0400836#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400837
838#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400839 const int w = 4;
840 const int h = 4;
841 uint16_t storage[w * h * 4];
842 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
843 storage, w * 4 * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400844 SkDebugf("pixmap.addrF16() %c= storage\n",
845 pixmap.addrF16() == storage ? '=' : '!');
846#StdOut
847pixmap.addrF16() == storage
848##
849##
850
851#SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16
852
853##
854
855# ------------------------------------------------------------------------------
856
Cary Clark682c58d2018-05-16 07:07:07 -0400857#Method const uint8_t* addr8(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400858
Cary Clarkab2621d2018-01-30 10:08:57 -0500859#In Readable_Address
Cary Clark09d80c02018-10-31 12:14:03 -0400860#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400861
862#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400863 const int w = 4;
864 const int h = 4;
865 uint8_t storage[w * h];
866 SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType),
867 storage, w * sizeof(storage[0]));
868 SkDebugf("pixmap.addr8(1, 2) %c= &storage[1 + 2 * w]\n",
869 pixmap.addr8(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
Cary Clarkd0530ba2017-09-14 11:25:39 -0400870#StdOut
871pixmap.addr8(1, 2) == &storage[1 + 2 * w]
872##
873##
874
875#SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8
876
877##
878
879# ------------------------------------------------------------------------------
880
Cary Clark682c58d2018-05-16 07:07:07 -0400881#Method const uint16_t* addr16(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400882
Cary Clarkab2621d2018-01-30 10:08:57 -0500883#In Readable_Address
Cary Clark09d80c02018-10-31 12:14:03 -0400884#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400885
886#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400887 const int w = 4;
888 const int h = 4;
889 uint16_t storage[w * h];
890 SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType),
891 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400892 SkDebugf("pixmap.addr16(1, 2) %c= &storage[1 + 2 * w]\n",
893 pixmap.addr16(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
894#StdOut
895pixmap.addr16(1, 2) == &storage[1 + 2 * w]
896##
897##
898
899#SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16
900
901##
902
903# ------------------------------------------------------------------------------
904
Cary Clark682c58d2018-05-16 07:07:07 -0400905#Method const uint32_t* addr32(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400906
Cary Clarkab2621d2018-01-30 10:08:57 -0500907#In Readable_Address
Cary Clark09d80c02018-10-31 12:14:03 -0400908#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400909
910#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400911 const int w = 4;
912 const int h = 4;
913 uint32_t storage[w * h];
914 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_8888_SkColorType, kPremul_SkAlphaType),
915 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400916 SkDebugf("pixmap.addr32(1, 2) %c= &storage[1 + 2 * w]\n",
917 pixmap.addr32(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
918#StdOut
919pixmap.addr32(1, 2) == &storage[1 + 2 * w]
920##
921##
922
Cary Clark2ade9972017-11-02 17:49:34 -0400923#SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr64
Cary Clarkd0530ba2017-09-14 11:25:39 -0400924
925##
926
927# ------------------------------------------------------------------------------
928
Cary Clark682c58d2018-05-16 07:07:07 -0400929#Method const uint64_t* addr64(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400930
Cary Clarkab2621d2018-01-30 10:08:57 -0500931#In Readable_Address
Cary Clark09d80c02018-10-31 12:14:03 -0400932#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400933
934#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400935 const int w = 4;
936 const int h = 4;
937 uint64_t storage[w * h];
938 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
939 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400940 SkDebugf("pixmap.addr64(1, 2) %c= &storage[1 + 2 * w]\n",
941 pixmap.addr64(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
942#StdOut
943pixmap.addr64(1, 2) == &storage[1 + 2 * w]
944##
945##
946
947#SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64
948
949##
950
951# ------------------------------------------------------------------------------
952
Cary Clark682c58d2018-05-16 07:07:07 -0400953#Method const uint16_t* addrF16(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400954
Cary Clarkab2621d2018-01-30 10:08:57 -0500955#In Readable_Address
Cary Clark09d80c02018-10-31 12:14:03 -0400956#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400957
958#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400959 const int w = 4;
960 const int h = 4;
961 const int wordsPerPixel = 4;
962 const int rowWords = w * wordsPerPixel;
963 uint16_t storage[rowWords * h];
964 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
965 storage, rowWords * sizeof(storage[0]));
966 SkDebugf("pixmap.addrF16(1, 2) %c= &storage[1 * wordsPerPixel + 2 * rowWords]\n",
967 pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords] ? '=' : '!');
Cary Clarkd0530ba2017-09-14 11:25:39 -0400968#StdOut
969pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords]
970##
971##
972
973#SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16
974
975##
976
977#Subtopic Readable_Address ##
978
979#Subtopic Writable_Address
Cary Clark08895c42018-02-01 09:37:32 -0500980#Line # returns writable pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400981
982# ------------------------------------------------------------------------------
983
Cary Clark682c58d2018-05-16 07:07:07 -0400984#Method void* writable_addr() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400985
Cary Clarkab2621d2018-01-30 10:08:57 -0500986#In Writable_Address
987#Line # returns writable pixel address as void pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -0400988#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -0400989
990#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400991 const int w = 4;
992 const int h = 4;
993 SkPMColor storage[w * h * 4];
994 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4);
995 SkDebugf("pixmap.writable_addr() %c= (void *)storage\n",
996 pixmap.writable_addr() == (void *)storage ? '=' : '!');
997 pixmap.erase(0x00000000);
998 *(SkPMColor*)pixmap.writable_addr() = 0xFFFFFFFF;
999 SkDebugf("pixmap.getColor(0, 1) %c= 0x00000000\n",
1000 pixmap.getColor(0, 1) == 0x00000000 ? '=' : '!');
1001 SkDebugf("pixmap.getColor(0, 0) %c= 0xFFFFFFFF\n",
Cary Clarkd0530ba2017-09-14 11:25:39 -04001002 pixmap.getColor(0, 0) == 0xFFFFFFFF ? '=' : '!');
1003#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -04001004pixmap.writable_addr() == (void *)storage
1005pixmap.getColor(0, 1) == 0x00000000
Cary Clarkd0530ba2017-09-14 11:25:39 -04001006pixmap.getColor(0, 0) == 0xFFFFFFFF
1007##
1008##
1009
1010#SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr()
1011
1012##
1013
1014# ------------------------------------------------------------------------------
1015
Cary Clark682c58d2018-05-16 07:07:07 -04001016#Method void* writable_addr(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001017
Cary Clarkab2621d2018-01-30 10:08:57 -05001018#In Writable_Address
Cary Clark09d80c02018-10-31 12:14:03 -04001019#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001020
1021#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001022 const int w = 4;
1023 const int h = 4;
1024 SkPMColor storage[w * h * 4];
1025 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4);
1026 SkDebugf("pixmap.writable_addr() %c= (void *)storage\n",
1027 pixmap.writable_addr() == (void *)storage ? '=' : '!');
1028 pixmap.erase(0x00000000);
1029 *(SkPMColor*)pixmap.writable_addr(1, 2) = 0xFFFFFFFF;
1030 SkDebugf("pixmap.getColor(0, 0) %c= 0x00000000\n",
1031 pixmap.getColor(0, 0) == 0x00000000 ? '=' : '!');
1032 SkDebugf("pixmap.getColor(1, 2) %c= 0xFFFFFFFF\n",
Cary Clarkd0530ba2017-09-14 11:25:39 -04001033 pixmap.getColor(1, 2) == 0xFFFFFFFF ? '=' : '!');
1034#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -04001035pixmap.writable_addr() == (void *)storage
1036pixmap.getColor(0, 0) == 0x00000000
Cary Clarkd0530ba2017-09-14 11:25:39 -04001037pixmap.getColor(1, 2) == 0xFFFFFFFF
1038##
1039##
1040
1041#SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr()
1042
1043##
1044
1045# ------------------------------------------------------------------------------
1046
Cary Clark682c58d2018-05-16 07:07:07 -04001047#Method uint8_t* writable_addr8(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001048
Cary Clarkab2621d2018-01-30 10:08:57 -05001049#In Writable_Address
1050#Line # returns writable pixel address as 8-bit pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -04001051#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001052
1053#Example
1054#Height 64
1055#Description
1056Altering pixels after drawing Bitmap is not guaranteed to affect subsequent
1057drawing on all platforms. Adding a second SkBitmap::installPixels after editing
1058pixel memory is safer.
1059##
Cary Clark6fc50412017-09-21 12:31:06 -04001060void draw(SkCanvas* canvas) {
1061 uint8_t storage[][5] = {{ 0, 0, 64, 0, 0},
1062 { 0, 128, 255, 128, 0},
1063 {64, 255, 255, 255, 64},
1064 { 0, 128, 255, 128, 0},
1065 { 0, 0, 64, 0, 0}};
1066 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kPremul_SkAlphaType);
1067 SkPixmap pixmap(imageInfo, storage[0], 5);
1068 SkBitmap bitmap;
1069 bitmap.installPixels(pixmap);
1070 canvas->scale(10, 10);
1071 canvas->drawBitmap(bitmap, 0, 0);
1072 *pixmap.writable_addr8(2, 2) = 0;
1073// bitmap.installPixels(pixmap); // uncomment to fix on GPU
1074 canvas->drawBitmap(bitmap, 10, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001075}
1076##
1077
1078#SeeAlso writable_addr writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr() addr8
1079
1080##
1081
1082# ------------------------------------------------------------------------------
1083
Cary Clark682c58d2018-05-16 07:07:07 -04001084#Method uint16_t* writable_addr16(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001085
Cary Clarkab2621d2018-01-30 10:08:57 -05001086#In Writable_Address
1087#Line # returns writable pixel address as 16-bit pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -04001088#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001089
1090#Example
1091#Description
1092Draw a five by five bitmap, and draw it again with a center black pixel.
1093The low nibble of the 16-bit word is Alpha.
1094##
1095#Height 64
Cary Clark6fc50412017-09-21 12:31:06 -04001096 uint16_t storage[][5] = {{ 0xCABF, 0xDABE, 0xCA9D, 0xC96C, 0xA39B },
1097 { 0xACEE, 0xA87C, 0x893A, 0x4779, 0x8708 },
1098 { 0x4B7C, 0x255B, 0x2559, 0x2557, 0x4656 },
1099 { 0x9099, 0x8128, 0x2557, 0x4124, 0x3323 },
1100 { 0x7547, 0x5505, 0x4434, 0x2012, 0x0000 }};
1101 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kARGB_4444_SkColorType, kPremul_SkAlphaType);
1102 SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
1103 SkBitmap bitmap;
1104 bitmap.installPixels(pixmap);
1105 canvas->scale(10, 10);
1106 canvas->drawBitmap(bitmap, 0, 0);
1107 *pixmap.writable_addr16(2, 2) = 0x000F;
1108 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001109 canvas->drawBitmap(bitmap, 10, 0);
1110##
1111
1112#SeeAlso writable_addr writable_addr8 writable_addr32 writable_addr64 writable_addrF16 addr() addr16
1113
1114##
1115
1116# ------------------------------------------------------------------------------
1117
Cary Clark682c58d2018-05-16 07:07:07 -04001118#Method uint32_t* writable_addr32(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001119
Cary Clarkab2621d2018-01-30 10:08:57 -05001120#In Writable_Address
1121#Line # returns writable pixel address as 32-bit pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -04001122#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001123
1124#Example
1125#Image 4
1126#Height 72
Cary Clark6fc50412017-09-21 12:31:06 -04001127 std::vector<int32_t> pixels;
1128 pixels.resize(image->height() * image->width() * 4);
1129 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
1130 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
1131 image->readPixels(pixmap, 0, 0);
1132 for (int y = 0; y < pixmap.height() / 2; ++y) {
1133 for (int x = 0; x < pixmap.width(); ++x) {
1134 if ((x & 4) == (y & 4)) {
Cary Clark4d759752018-06-19 12:57:43 -04001135 *pixmap.writable_addr32(x, y) =
1136 *pixmap.writable_addr32(pixmap.width() - x, pixmap.height() - y);
Cary Clark6fc50412017-09-21 12:31:06 -04001137 }
1138 }
1139 }
1140 SkBitmap bitmap;
1141 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001142 canvas->drawBitmap(bitmap, 0, 0);
1143##
1144
1145#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr64 writable_addrF16 addr() addr32
1146
1147##
1148
1149# ------------------------------------------------------------------------------
1150
Cary Clark682c58d2018-05-16 07:07:07 -04001151#Method uint64_t* writable_addr64(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001152
Cary Clarkab2621d2018-01-30 10:08:57 -05001153#In Writable_Address
1154#Line # returns writable pixel address as 64-bit pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -04001155#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001156
1157#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001158#Height 40
Cary Clark6fc50412017-09-21 12:31:06 -04001159 SkImageInfo info = SkImageInfo::Make(3, 3, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
1160 uint64_t storage[9];
1161 SkPixmap pixmap(info, storage, 3 * sizeof(uint64_t));
1162 SkColor4f c4 { 1, 0.45f, 0.25f, 0.65f };
1163 pixmap.erase(c4);
1164 SkBitmap bitmap;
1165 canvas->scale(10, 10);
1166 bitmap.installPixels(pixmap);
1167 canvas->drawBitmap(bitmap, 0, 0);
1168 *pixmap.writable_addr64(1, 1) |= 0x00ff000000000000LL;
1169 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001170 canvas->drawBitmap(bitmap, 10, 0);
1171##
1172
1173#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addrF16 addr() addr64
1174
1175##
1176
1177# ------------------------------------------------------------------------------
1178
Cary Clark682c58d2018-05-16 07:07:07 -04001179#Method uint16_t* writable_addrF16(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001180
Cary Clarkab2621d2018-01-30 10:08:57 -05001181#In Writable_Address
1182#Line # returns writable pixel component address as 16-bit pointer ##
Cary Clark09d80c02018-10-31 12:14:03 -04001183#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001184
1185#Example
1186#Height 64
1187#Description
1188Left bitmap is drawn with two pixels defined in half float format. Right bitmap
Cary Clark682c58d2018-05-16 07:07:07 -04001189is drawn after overwriting bottom half float color with top half float color.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001190##
Cary Clark6fc50412017-09-21 12:31:06 -04001191 SkImageInfo info = SkImageInfo::Make(1, 2, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
1192 uint16_t storage[2][4];
1193 SkPixmap pixmap(info, storage[0], sizeof(uint64_t));
1194 SkIRect topPixelBounds = {0, 0, 1, 1};
1195 pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds);
1196 SkIRect bottomPixelBounds = {0, 1, 1, 2};
1197 pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds);
1198 SkBitmap bitmap;
1199 canvas->scale(20, 20);
1200 bitmap.installPixels(pixmap);
1201 canvas->drawBitmap(bitmap, 0, 0);
1202 uint16_t* pixel2 = pixmap.writable_addrF16(0, 1);
1203 for (int i = 0; i < 4; ++i) {
1204 pixel2[i] = storage[0][i];
1205 }
1206 bitmap.installPixels(pixmap);
1207 canvas->drawBitmap(bitmap, 4, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001208##
1209
1210#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addr64 addr() addrF16
1211
1212##
1213
1214#Subtopic Writable_Address ##
1215
Cary Clark78de7512018-02-07 07:27:09 -05001216#Subtopic Pixels
Cary Clark78de7512018-02-07 07:27:09 -05001217#Line # read and write pixel values ##
1218##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001219
1220# ------------------------------------------------------------------------------
1221
Cary Clarke80cd442018-07-17 13:19:56 -04001222#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05001223#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001224#Line # copies and converts pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -04001225#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001226
1227#Example
1228#Height 128
1229#Description
1230Transferring the gradient from 8 bits per component to 4 bits per component
1231creates visible banding.
1232##
Cary Clark6fc50412017-09-21 12:31:06 -04001233 std::vector<int32_t> pixels;
1234 const int width = 256;
1235 const int height = 64;
1236 pixels.resize(height * width * 4);
1237 SkImageInfo srcInfo = SkImageInfo::MakeN32Premul(width, height);
1238 SkPixmap srcPixmap(srcInfo, (const void*) &pixels.front(), width * 4);
1239 SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 };
1240 SkPoint gradPoints[] = { { 0, 0 }, { 256, 0 } };
1241 SkPaint paint;
1242 paint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1243 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1244 SkBitmap bitmap;
1245 bitmap.installPixels(srcPixmap);
1246 SkCanvas srcCanvas(bitmap);
1247 srcCanvas.drawRect(SkRect::MakeWH(width, height), paint);
1248 canvas->drawBitmap(bitmap, 0, 0);
1249 std::vector<int32_t> dstPixels;
1250 dstPixels.resize(height * width * 2);
1251 SkImageInfo dstInfo = srcInfo.makeColorType(kARGB_4444_SkColorType);
1252 srcPixmap.readPixels(dstInfo, &dstPixels.front(), width * 2);
1253 SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2);
1254 bitmap.installPixels(dstPixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001255 canvas->drawBitmap(bitmap, 0, 128);
1256##
1257
1258#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1259
1260##
1261
1262# ------------------------------------------------------------------------------
1263
1264#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX,
Cary Clark682c58d2018-05-16 07:07:07 -04001265 int srcY) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001266
1267Copies a Rect of pixels to dstPixels. Copy starts at (srcX, srcY), and does not
Cary Clarkac47b882018-01-11 10:35:44 -05001268exceed Pixmap (width(), height()).
Cary Clark6fc50412017-09-21 12:31:06 -04001269
Cary Clark682c58d2018-05-16 07:07:07 -04001270dstInfo specifies width, height, Color_Type, Alpha_Type, and
Cary Clarkd0530ba2017-09-14 11:25:39 -04001271Color_Space of destination. dstRowBytes specifics the gap from one destination
1272row to the next. Returns true if pixels are copied. Returns false if
Cary Clark77b3f3a2018-11-07 14:59:03 -05001273dstInfo has no address, or dstRowBytes is less than dstInfo.minRowBytes().
Cary Clarkd0530ba2017-09-14 11:25:39 -04001274
Cary Clarkac47b882018-01-11 10:35:44 -05001275Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clark77b3f3a2018-11-07 14:59:03 -05001276kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match.
1277If Pixmap colorType is kGray_8_SkColorType, dstInfo.colorSpace() must match.
1278If Pixmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType() must
1279match. If Pixmap colorSpace is nullptr, dstInfo.colorSpace() must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001280false if pixel conversion is not possible.
Cary Clark682c58d2018-05-16 07:07:07 -04001281
Cary Clarkd0530ba2017-09-14 11:25:39 -04001282srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clarkac47b882018-01-11 10:35:44 -05001283false if Pixmap width() or height() is zero or negative. Returns false if:
Cary Clark154beea2017-10-26 07:58:48 -04001284
Cary Clark2be81cf2018-09-13 12:04:30 -04001285#Formula # abs(srcX) >= Pixmap width() ##, or if #Formula # abs(srcY) >= Pixmap height() ##.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001286
1287#Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ##
1288#Param dstPixels destination pixel storage ##
1289#Param dstRowBytes destination row length ##
1290#Param srcX column index whose absolute value is less than width() ##
1291#Param srcY row index whose absolute value is less than height() ##
1292
1293#Return true if pixels are copied to dstPixels ##
1294
1295#Example
1296#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001297void draw(SkCanvas* canvas) {
1298 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1299 std::vector<int32_t> srcPixels;
1300 const int rowBytes = image->width() * 4;
1301 srcPixels.resize(image->height() * rowBytes);
1302 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1303 image->readPixels(pixmap, 0, 0);
1304 for (int offset : { 32, 64, 96 } ) {
1305 std::vector<int32_t> dstPixels;
1306 dstPixels.resize(image->height() * rowBytes);
1307 pixmap.readPixels(info, &dstPixels.front(), rowBytes, offset, 0);
1308 SkBitmap bitmap;
1309 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1310 bitmap.installPixels(dstmap);
1311 canvas->translate(32, 32);
1312 canvas->drawBitmap(bitmap, 0, 0);
1313 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001314}
1315##
1316
1317#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1318
1319##
1320
1321# ------------------------------------------------------------------------------
1322
Cary Clark682c58d2018-05-16 07:07:07 -04001323#Method bool readPixels(const SkPixmap& dst, int srcX, int srcY) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001324
1325Copies a Rect of pixels to dst. Copy starts at (srcX, srcY), and does not
Cary Clarkac47b882018-01-11 10:35:44 -05001326exceed Pixmap (width(), height()). dst specifies width, height, Color_Type,
Cary Clarkd0530ba2017-09-14 11:25:39 -04001327Alpha_Type, and Color_Space of destination. Returns true if pixels are copied.
Cary Clark77b3f3a2018-11-07 14:59:03 -05001328Returns false if dst.addr() equals nullptr, or dst.rowBytes() is less than
Cary Clarkd0530ba2017-09-14 11:25:39 -04001329dst SkImageInfo::minRowBytes.
1330
Cary Clarkac47b882018-01-11 10:35:44 -05001331Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clark77b3f3a2018-11-07 14:59:03 -05001332kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.info().colorType() must match.
1333If Pixmap colorType is kGray_8_SkColorType, dst.info().colorSpace() must match.
1334If Pixmap alphaType is kOpaque_SkAlphaType, dst.info().alphaType() must
1335match. If Pixmap colorSpace is nullptr, dst.info().colorSpace() must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001336false if pixel conversion is not possible.
Cary Clark682c58d2018-05-16 07:07:07 -04001337
Cary Clarkd0530ba2017-09-14 11:25:39 -04001338srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clarkac47b882018-01-11 10:35:44 -05001339false Pixmap width() or height() is zero or negative. Returns false if:
Cary Clark154beea2017-10-26 07:58:48 -04001340
Cary Clark2be81cf2018-09-13 12:04:30 -04001341#Formula # abs(srcX) >= Pixmap width() ##, or if #Formula # abs(srcY) >= Pixmap height() ##.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001342
1343#Param dst Image_Info and pixel address to write to ##
1344#Param srcX column index whose absolute value is less than width() ##
1345#Param srcY row index whose absolute value is less than height() ##
1346
1347#Return true if pixels are copied to dst ##
1348
1349#Example
1350#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001351void draw(SkCanvas* canvas) {
1352 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1353 std::vector<int32_t> srcPixels;
1354 const int rowBytes = image->width() * 4;
1355 srcPixels.resize(image->height() * rowBytes);
1356 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1357 image->readPixels(pixmap, 0, 0);
1358 for (int offset : { 32, 64, 96 } ) {
1359 std::vector<int32_t> dstPixels;
1360 dstPixels.resize(image->height() * rowBytes);
1361 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1362 pixmap.readPixels(dstmap, offset, 0);
1363 SkBitmap bitmap;
1364 bitmap.installPixels(dstmap);
1365 canvas->translate(32, 32);
1366 canvas->drawBitmap(bitmap, 0, 0);
1367 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001368}
1369##
1370
1371#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1372
1373##
1374
1375# ------------------------------------------------------------------------------
1376
Cary Clark682c58d2018-05-16 07:07:07 -04001377#Method bool readPixels(const SkPixmap& dst) const
Cary Clark09d80c02018-10-31 12:14:03 -04001378#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001379
1380#Example
1381#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001382void draw(SkCanvas* canvas) {
1383 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1384 std::vector<int32_t> srcPixels;
1385 const int rowBytes = image->width() * 4;
1386 srcPixels.resize(image->height() * rowBytes);
1387 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1388 image->readPixels(pixmap, 0, 0);
1389 for (int index = 0; index < 3; ++index ) {
1390 std::vector<int32_t> dstPixels;
1391 dstPixels.resize(image->height() * rowBytes);
1392 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1393 pixmap.readPixels(dstmap);
1394 SkBitmap bitmap;
1395 bitmap.installPixels(dstmap);
1396 canvas->translate(32, 32);
1397 canvas->drawBitmap(bitmap, 0, 0);
1398 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001399}
1400##
1401
1402#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1403
1404##
1405
1406# ------------------------------------------------------------------------------
1407
1408#Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality) const
1409
Cary Clark78de7512018-02-07 07:27:09 -05001410#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001411#Line # scales and converts pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -04001412#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001413
1414#Example
1415#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001416void draw(SkCanvas* canvas) {
1417 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1418 std::vector<int32_t> srcPixels;
1419 int rowBytes = image->width() * 4;
1420 srcPixels.resize(image->height() * rowBytes);
1421 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1422 image->readPixels(pixmap, 0, 0);
1423 for (int offset : { 32, 64, 96 } ) {
1424 info = SkImageInfo::MakeN32Premul(image->width() + offset, image->height());
1425 rowBytes = info.width() * 4;
1426 std::vector<int32_t> dstPixels;
1427 dstPixels.resize(image->height() * rowBytes);
1428 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1429 pixmap.scalePixels(dstmap, kMedium_SkFilterQuality);
1430 SkBitmap bitmap;
1431 bitmap.installPixels(dstmap);
1432 canvas->translate(32, 32);
1433 canvas->drawBitmap(bitmap, 0, 0);
1434 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001435}
1436##
1437
1438#SeeAlso SkCanvas::drawBitmap SkImage::scalePixels
1439
1440##
1441
1442# ------------------------------------------------------------------------------
1443
1444#Method bool erase(SkColor color, const SkIRect& subset) const
1445
Cary Clark78de7512018-02-07 07:27:09 -05001446#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001447#Line # writes Color to pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -04001448#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001449
1450#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001451#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001452 uint32_t storage[2];
1453 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1454 SkPixmap pixmap(info, storage, info.minRowBytes());
1455 pixmap.erase(SK_ColorBLUE, {0, 0, 1, 1});
1456 pixmap.erase(SK_ColorRED, {0, 1, 1, 2});
1457 SkBitmap bitmap;
1458 canvas->scale(20, 20);
1459 bitmap.installPixels(pixmap);
1460 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001461##
1462
1463#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1464
1465##
1466
1467# ------------------------------------------------------------------------------
1468
Cary Clark682c58d2018-05-16 07:07:07 -04001469#Method bool erase(SkColor color) const
Cary Clark09d80c02018-10-31 12:14:03 -04001470#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001471
1472#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001473#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001474 uint32_t storage[2];
1475 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1476 SkPixmap pixmap(info, storage, info.minRowBytes());
1477 pixmap.erase(SK_ColorBLUE);
1478 SkBitmap bitmap;
1479 canvas->scale(20, 20);
1480 bitmap.installPixels(pixmap);
1481 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001482##
1483
1484#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1485
1486##
1487
1488# ------------------------------------------------------------------------------
1489
1490#Method bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const
Cary Clark09d80c02018-10-31 12:14:03 -04001491#Populate
Cary Clarkd0530ba2017-09-14 11:25:39 -04001492
1493#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001494#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001495 uint32_t storage[2];
1496 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1497 SkPixmap pixmap(info, storage, info.minRowBytes());
1498 SkIRect topPixelBounds = {0, 0, 1, 1};
1499 pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds);
1500 SkIRect bottomPixelBounds = {0, 1, 1, 2};
1501 pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds);
1502 SkBitmap bitmap;
1503 canvas->scale(20, 20);
1504 bitmap.installPixels(pixmap);
1505 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001506##
1507
1508#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1509
1510##
1511
Cary Clarkd0530ba2017-09-14 11:25:39 -04001512#Class SkPixmap ##
1513
1514#Topic Pixmap ##