blob: 9dbb1a5c375921910e2d5691769b837d00f4a705 [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 Clark682c58d2018-05-16 07:07:07 -04006Pixmap provides a utility to pair SkImageInfo with pixels and row bytes.
Cary Clarkd0530ba2017-09-14 11:25:39 -04007Pixmap is a low level class which provides convenience functions to access
8raster destinations. Canvas can not draw Pixmap, nor does Pixmap provide
9a direct drawing destination.
10
11Use Bitmap to draw pixels referenced by Pixmap; use Surface to draw into
12pixels referenced by Pixmap.
13
Cary Clarkbc5697d2017-10-04 14:31:33 -040014Pixmap does not try to manage the lifetime of the pixel memory. Use Pixel_Ref
15to manage pixel memory; Pixel_Ref is safe across threads.
Cary Clarkd0530ba2017-09-14 11:25:39 -040016
Cary Clark682c58d2018-05-16 07:07:07 -040017#Subtopic Overview
18#Populate
19##
20
Cary Clark4855f782018-02-06 09:41:53 -050021#Subtopic Related_Function
Cary Clark08895c42018-02-01 09:37:32 -050022#Populate
Cary Clark5081eed2018-01-22 07:55:48 -050023##
24
Cary Clark4855f782018-02-06 09:41:53 -050025#Subtopic Constructor
Cary Clark08895c42018-02-01 09:37:32 -050026#Populate
27##
Cary Clarkd0530ba2017-09-14 11:25:39 -040028
Cary Clark4855f782018-02-06 09:41:53 -050029#Subtopic Member_Function
Cary Clark08895c42018-02-01 09:37:32 -050030#Populate
31##
Cary Clarkd0530ba2017-09-14 11:25:39 -040032
33#Subtopic Initialization
Cary Clark08895c42018-02-01 09:37:32 -050034#Line # sets fields for use ##
Cary Clarkd0530ba2017-09-14 11:25:39 -040035
36# ------------------------------------------------------------------------------
37
38#Method SkPixmap()
39
Cary Clarkab2621d2018-01-30 10:08:57 -050040#In Initialization
41#Line # constructs with default values ##
Cary Clarkd0530ba2017-09-14 11:25:39 -040042Creates an empty Pixmap without pixels, with kUnknown_SkColorType, with
43kUnknown_SkAlphaType, and with a width and height of zero. Use
44reset() to associate pixels, SkColorType, SkAlphaType, width, and height
45after Pixmap has been created.
46
47#Return empty Pixmap ##
48
49#Example
Cary Clark6fc50412017-09-21 12:31:06 -040050void draw(SkCanvas* canvas) {
51 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
Cary Clarkab2621d2018-01-30 10:08:57 -050052 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
53 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -040054 SkPixmap pixmap;
55 for (int i = 0; i < 2; ++i) {
56 SkDebugf("width: %2d height: %2d", pixmap.width(), pixmap.height());
57 SkDebugf(" color: k%s_SkColorType", colors[pixmap.colorType()]);
58 SkDebugf(" alpha: k%s_SkAlphaType\n", alphas[pixmap.alphaType()]);
59 pixmap.reset(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType),
60 nullptr, 0);
61 }
Cary Clarkd0530ba2017-09-14 11:25:39 -040062}
63#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -040064width: 0 height: 0 color: kUnknown_SkColorType alpha: kUnknown_SkAlphaType
Cary Clarkd0530ba2017-09-14 11:25:39 -040065width: 25 height: 35 color: kRGBA_8888_SkColorType alpha: kOpaque_SkAlphaType
66##
67##
68
69#SeeAlso SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) reset() SkAlphaType SkColorType
70
71##
72
73# ------------------------------------------------------------------------------
74
75#Method SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes)
Cary Clark682c58d2018-05-16 07:07:07 -040076
Cary Clarkab2621d2018-01-30 10:08:57 -050077#In Initialization
78#Line # constructs from Image_Info, pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -040079Creates Pixmap from info width, height, SkAlphaType, and SkColorType.
Cary Clark6fc50412017-09-21 12:31:06 -040080addr points to pixels, or nullptr. rowBytes should be info.width() times
81info.bytesPerPixel(), or larger.
Cary Clarkd0530ba2017-09-14 11:25:39 -040082
83No parameter checking is performed; it is up to the caller to ensure that
Cary Clark682c58d2018-05-16 07:07:07 -040084addr and rowBytes agree with info.
Cary Clarkd0530ba2017-09-14 11:25:39 -040085
Cary Clark6fc50412017-09-21 12:31:06 -040086The memory lifetime of pixels is managed by the caller. When Pixmap goes
Cary Clarkd0530ba2017-09-14 11:25:39 -040087out of scope, addr is unaffected.
88
89Pixmap may be later modified by reset() to change its size, pixel type, or
90storage.
91
92#Param info width, height, SkAlphaType, SkColorType of Image_Info ##
93#Param addr pointer to pixels allocated by caller; may be nullptr ##
94#Param rowBytes size of one row of addr; width times pixel size, or larger ##
95
96#Return initialized Pixmap ##
97
98#Example
99#Image 3
100#Description
Cary Clark682c58d2018-05-16 07:07:07 -0400101SkImage::MakeRasterCopy takes const SkPixmap& as an argument. The example
Cary Clarkd0530ba2017-09-14 11:25:39 -0400102constructs a SkPixmap from the brace-delimited parameters.
103##
Cary Clark6fc50412017-09-21 12:31:06 -0400104 SkDebugf("image alpha only = %s\n", image->isAlphaOnly() ? "true" : "false");
105 SkPMColor pmColors = 0;
106 sk_sp<SkImage> copy = SkImage::MakeRasterCopy({SkImageInfo::MakeA8(1, 1),
107 (uint8_t*)&pmColors,
108 1});
Cary Clarkd0530ba2017-09-14 11:25:39 -0400109 SkDebugf("copy alpha only = %s\n", copy->isAlphaOnly() ? "true" : "false");
110#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400111image alpha only = false
Cary Clarkd0530ba2017-09-14 11:25:39 -0400112copy alpha only = true
113##
114##
115
116#SeeAlso SkPixmap() reset() SkAlphaType SkColorType
117
118##
119
120# ------------------------------------------------------------------------------
121
122#Method void reset()
123
Cary Clarkab2621d2018-01-30 10:08:57 -0500124#In Initialization
125#Line # reuses existing Pixmap with replacement values ##
Cary Clark682c58d2018-05-16 07:07:07 -0400126Sets width, height, row bytes to zero; pixel address to nullptr; SkColorType to
Cary Clarkd0530ba2017-09-14 11:25:39 -0400127kUnknown_SkColorType; and SkAlphaType to kUnknown_SkAlphaType.
128
129The prior pixels are unaffected; it is up to the caller to release pixels
130memory if desired.
131
132#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400133void draw(SkCanvas* canvas) {
134 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
Cary Clarkab2621d2018-01-30 10:08:57 -0500135 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
136 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -0400137 SkPixmap pixmap(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType),
138 nullptr, 0);
139 for (int i = 0; i < 2; ++i) {
140 SkDebugf("width: %2d height: %2d", pixmap.width(), pixmap.height());
141 SkDebugf(" color: k%s_SkColorType", colors[pixmap.colorType()]);
142 SkDebugf(" alpha: k%s_SkAlphaType\n", alphas[pixmap.alphaType()]);
143 pixmap.reset();
144 }
145}
Cary Clarkd0530ba2017-09-14 11:25:39 -0400146#StdOut
147width: 25 height: 35 color: kRGBA_8888_SkColorType alpha: kOpaque_SkAlphaType
Cary Clark6fc50412017-09-21 12:31:06 -0400148width: 0 height: 0 color: kUnknown_SkColorType alpha: kUnknown_SkAlphaType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400149##
150##
151
152#SeeAlso SkPixmap() SkAlphaType SkColorType
153
154##
155
156# ------------------------------------------------------------------------------
157
158#Method void reset(const SkImageInfo& info, const void* addr, size_t rowBytes)
159
Cary Clarkab2621d2018-01-30 10:08:57 -0500160#In Initialization
Cary Clarkd0530ba2017-09-14 11:25:39 -0400161Sets width, height, SkAlphaType, and SkColorType from info.
Cary Clark682c58d2018-05-16 07:07:07 -0400162Sets pixel address from addr, which may be nullptr.
Cary Clark6fc50412017-09-21 12:31:06 -0400163Sets row bytes from rowBytes, which should be info.width() times
164info.bytesPerPixel(), or larger.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400165
166Does not check addr. Asserts if built with SK_DEBUG defined and if rowBytes is
Cary Clark682c58d2018-05-16 07:07:07 -0400167too small to hold one row of pixels.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400168
169The memory lifetime pixels are managed by the caller. When Pixmap goes
170out of scope, addr is unaffected.
171
172#Param info width, height, SkAlphaType, SkColorType of Image_Info ##
173#Param addr pointer to pixels allocated by caller; may be nullptr ##
174#Param rowBytes size of one row of addr; width times pixel size, or larger ##
175
176#Example
177#Image 4
Cary Clark2ade9972017-11-02 17:49:34 -0400178#Height 64
Cary Clark6fc50412017-09-21 12:31:06 -0400179void draw(SkCanvas* canvas) {
180 std::vector<int32_t> pixels;
181 pixels.resize(image->height() * image->width() * 4);
182 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
183 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
184 image->readPixels(pixmap, 0, 0);
185 int x = 0;
186 for (auto colorType : { kRGBA_8888_SkColorType, kBGRA_8888_SkColorType } ) {
Cary Clark682c58d2018-05-16 07:07:07 -0400187 pixmap.reset(SkImageInfo::Make(image->width(), image->height(), colorType,
Cary Clark6fc50412017-09-21 12:31:06 -0400188 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
189 SkBitmap bitmap;
190 bitmap.installPixels(pixmap);
191 canvas->drawBitmap(bitmap, x, 0);
192 x += 128;
193 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400194}
195##
196
197#SeeAlso SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) reset() SkAlphaType SkColorType
198
199##
200
201# ------------------------------------------------------------------------------
202
203#Method void setColorSpace(sk_sp<SkColorSpace> colorSpace)
204
Cary Clarkab2621d2018-01-30 10:08:57 -0500205#In Initialization
206#Line # sets Image_Info Color_Space ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400207
208Changes Color_Space in Image_Info; preserves width, height, SkAlphaType, and
209SkColorType in Image, and leaves pixel address and row bytes unchanged.
Cary Clark6fc50412017-09-21 12:31:06 -0400210Color_Space reference count is incremented.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400211
212#Param colorSpace Color_Space moved to Image_Info ##
213
214#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400215void draw(SkCanvas* canvas) {
216 SkPixmap pixmap;
217 sk_sp<SkColorSpace> colorSpace1 = SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma,
218 SkColorSpace::kRec2020_Gamut);
Cary Clark682c58d2018-05-16 07:07:07 -0400219 SkDebugf("is %sunique\n", colorSpace1->unique() ? "" : "not ");
Cary Clark6fc50412017-09-21 12:31:06 -0400220 pixmap.setColorSpace(colorSpace1);
Cary Clark682c58d2018-05-16 07:07:07 -0400221 SkDebugf("is %sunique\n", colorSpace1->unique() ? "" : "not ");
Cary Clarkd0530ba2017-09-14 11:25:39 -0400222}
223#StdOut
224is unique
225is not unique
226##
227##
228
229#SeeAlso Color_Space SkImageInfo::makeColorSpace
230
231##
232
233# ------------------------------------------------------------------------------
234
235#Method bool SK_WARN_UNUSED_RESULT reset(const SkMask& mask)
Cary Clark4855f782018-02-06 09:41:53 -0500236#Deprecated soon
Cary Clarkd0530ba2017-09-14 11:25:39 -0400237##
238
239# ------------------------------------------------------------------------------
240
241#Method bool SK_WARN_UNUSED_RESULT extractSubset(SkPixmap* subset, const SkIRect& area) const
242
Cary Clarkab2621d2018-01-30 10:08:57 -0500243#In Initialization
244#Line # sets pointer to portion of original ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400245Sets subset width, height, pixel address to intersection of Pixmap with area,
246if intersection is not empty; and return true. Otherwise, leave subset unchanged
Cary Clark682c58d2018-05-16 07:07:07 -0400247and return false.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400248
249Failing to read the return value generates a compile time warning.
250
251#Param subset storage for width, height, pixel address of intersection ##
252#Param area bounds to intersect with Pixmap ##
253
254#Return true if intersection of Pixmap and area is not empty ##
255
256#Example
257#Image 3
258#Height 128
Cary Clark6fc50412017-09-21 12:31:06 -0400259void draw(SkCanvas* canvas) {
260 std::vector<int32_t> pixels;
261 pixels.resize(image->height() * image->width() * 4);
262 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
263 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
264 image->readPixels(pixmap, 0, 0);
265 SkPixmap inset;
266 if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
267 SkBitmap bitmap;
268 bitmap.installPixels(inset);
269 canvas->drawBitmap(bitmap, 0, 0);
270 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400271}
272##
273
274#SeeAlso reset() SkIRect::intersect
275
276##
277
278#Subtopic Initialization ##
279
280#Subtopic Image_Info_Access
Cary Clark08895c42018-02-01 09:37:32 -0500281#Line # returns all or part of Image_Info ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400282
283# ------------------------------------------------------------------------------
284
Cary Clark682c58d2018-05-16 07:07:07 -0400285#Method const SkImageInfo& info() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400286
Cary Clarkab2621d2018-01-30 10:08:57 -0500287#In Image_Info_Access
288#Line # returns Image_Info ##
Cary Clark6fc50412017-09-21 12:31:06 -0400289Returns width, height, Alpha_Type, Color_Type, and Color_Space.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400290
291#Return reference to ImageInfo ##
292
293#Example
294#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -0400295 std::vector<int32_t> pixels;
296 pixels.resize(image->height() * image->width() * 4);
297 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
298 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
299 image->readPixels(pixmap, 0, 0);
300 SkPixmap inset;
301 if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
302 const SkImageInfo& info = inset.info();
303 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
Cary Clarkab2621d2018-01-30 10:08:57 -0500304 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888",
305 "RGB_888x", "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -0400306 SkDebugf("width: %d height: %d color: %s alpha: %s\n", info.width(), info.height(),
307 colors[info.colorType()], alphas[info.alphaType()]);
308 }
309#StdOut
310width: 384 height: 384 color: BGRA_8888 alpha: Opaque
311##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400312##
313
314#SeeAlso Image_Info
315
316##
317
318# ------------------------------------------------------------------------------
319
Cary Clark682c58d2018-05-16 07:07:07 -0400320#Method size_t rowBytes() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400321
Cary Clarkab2621d2018-01-30 10:08:57 -0500322#In Image_Info_Access
323#Line # returns interval between rows in bytes ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400324Returns row bytes, the interval from one pixel row to the next. Row bytes
Cary Clark2be81cf2018-09-13 12:04:30 -0400325is at least as large as: #Formula # width() * info().bytesPerPixel() ##.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400326
Cary Clarkbc5697d2017-10-04 14:31:33 -0400327Returns zero if colorType is kUnknown_SkColorType.
328It is up to the Bitmap creator to ensure that row bytes is a useful value.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400329
330#Return byte length of pixel row ##
331
332#Example
333SkPixmap badPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 2};
334SkPixmap okPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 8};
335for (auto& pixmap : { badPixmap, okPixmap } ) {
Cary Clark682c58d2018-05-16 07:07:07 -0400336 SkDebugf("rowBytes: %d minRowBytes: %d\n", pixmap.rowBytes(),
Cary Clarkd0530ba2017-09-14 11:25:39 -0400337 pixmap.info().minRowBytes());
338}
339#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400340rowBytes: 2 minRowBytes: 4
Cary Clarkd0530ba2017-09-14 11:25:39 -0400341rowBytes: 8 minRowBytes: 4
342##
343##
344
345#SeeAlso addr() info() SkImageInfo::minRowBytes
346
347##
348
349# ------------------------------------------------------------------------------
350
Cary Clark682c58d2018-05-16 07:07:07 -0400351#Method const void* addr() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400352
Cary Clarkab2621d2018-01-30 10:08:57 -0500353#In Image_Info_Access
354#Line # returns readable pixel address as void pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -0400355Returns pixel address, the base address corresponding to the pixel origin.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400356
357It is up to the Pixmap creator to ensure that pixel address is a useful value.
358
359#Return pixel address ##
360
361#Example
362#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -0400363 std::vector<int32_t> pixels;
364 pixels.resize(image->height() * image->width() * 4);
365 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
366 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
367 image->readPixels(pixmap, 0, 0);
368 SkDebugf("pixels address: 0x%llx\n", pixmap.addr());
369 SkPixmap inset;
370 if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
371 SkDebugf("inset address: 0x%llx\n", inset.addr());
372 }
373#StdOut
374#Volatile
375pixels address: 0x7f2a440bb010
376inset address: 0x7f2a440fb210
377##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400378##
379
380#SeeAlso addr(int x, int y) addr8 addr16 addr32 addr64 info() rowBytes()
381
382##
383
384# ------------------------------------------------------------------------------
385
Cary Clark682c58d2018-05-16 07:07:07 -0400386#Method int width() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400387
Cary Clarkab2621d2018-01-30 10:08:57 -0500388#In Image_Info_Access
389#Line # returns pixel column count ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400390Returns pixel count in each pixel row. Should be equal or less than:
Cary Clark154beea2017-10-26 07:58:48 -0400391
Cary Clark2be81cf2018-09-13 12:04:30 -0400392#Formula # rowBytes() / info().bytesPerPixel() ##.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400393
394#Return pixel width in Image_Info ##
395
396#Example
397 SkImageInfo info = SkImageInfo::MakeA8(16, 32);
Cary Clark6fc50412017-09-21 12:31:06 -0400398 SkPixmap pixmap(info, nullptr, 64);
399 SkDebugf("pixmap width: %d info width: %d\n", pixmap.width(), info.width());
400#StdOut
401pixmap width: 16 info width: 16
402##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400403##
404
Cary Clarkbc5697d2017-10-04 14:31:33 -0400405#SeeAlso height() SkImageInfo::width()
Cary Clarkd0530ba2017-09-14 11:25:39 -0400406
407##
408
409# ------------------------------------------------------------------------------
410
Cary Clark682c58d2018-05-16 07:07:07 -0400411#Method int height() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400412
Cary Clarkab2621d2018-01-30 10:08:57 -0500413#In Image_Info_Access
414#Line # returns pixel row count ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400415Returns pixel row count.
416
417#Return pixel height in Image_Info ##
418
419#Example
Cary Clarkbc5697d2017-10-04 14:31:33 -0400420 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
421 SkDebugf("pixmap height: %d info height: %d\n", pixmap.height(), pixmap.info().height());
Cary Clark6fc50412017-09-21 12:31:06 -0400422#StdOut
423pixmap height: 32 info height: 32
424##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400425##
426
Cary Clarkbc5697d2017-10-04 14:31:33 -0400427#SeeAlso width() ImageInfo::height()
Cary Clarkd0530ba2017-09-14 11:25:39 -0400428
429##
430
431# ------------------------------------------------------------------------------
432
Cary Clark682c58d2018-05-16 07:07:07 -0400433#Method SkColorType colorType() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400434
Cary Clarkab2621d2018-01-30 10:08:57 -0500435#In Image_Info_Access
436#Line # returns Image_Info Color_Type ##
Cary Clark1a8d7622018-03-05 13:26:16 -0500437Returns Color_Type, one of: #list_of_color_types#.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400438
439#Return Color_Type in Image_Info ##
440
441#Example
Cary Clarkab2621d2018-01-30 10:08:57 -0500442 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
443 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -0400444 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
445 SkDebugf("color type: k" "%s" "_SkColorType\n", colors[pixmap.colorType()]);
446#StdOut
Cary Clarkab2621d2018-01-30 10:08:57 -0500447color type: kAlpha_8_SkColorType
Cary Clark6fc50412017-09-21 12:31:06 -0400448##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400449##
450
Cary Clarkbc5697d2017-10-04 14:31:33 -0400451#SeeAlso alphaType() SkImageInfo::colorType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400452
453##
454
455# ------------------------------------------------------------------------------
456
Cary Clark682c58d2018-05-16 07:07:07 -0400457#Method SkAlphaType alphaType() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400458
Cary Clarkab2621d2018-01-30 10:08:57 -0500459#In Image_Info_Access
460#Line # returns Image_Info Alpha_Type ##
Cary Clark681287e2018-03-16 11:34:15 -0400461Returns Alpha_Type, one of: #list_of_alpha_types#.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400462
463#Return Alpha_Type in Image_Info ##
464
465#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400466 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
467 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
468 SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[pixmap.alphaType()]);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400469#StdOut
470alpha type: kPremul_SkAlphaType
471##
472##
473
Cary Clarkbc5697d2017-10-04 14:31:33 -0400474#SeeAlso colorType() SkImageInfo::alphaType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400475
476##
477
478# ------------------------------------------------------------------------------
479
Cary Clark682c58d2018-05-16 07:07:07 -0400480#Method SkColorSpace* colorSpace() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400481
Cary Clarkab2621d2018-01-30 10:08:57 -0500482#In Image_Info_Access
483#Line # returns Image_Info Color_Space ##
Cary Clark681287e2018-03-16 11:34:15 -0400484Returns Color_Space, the range of colors, associated with Image_Info. The
Cary Clarkbc5697d2017-10-04 14:31:33 -0400485reference count of Color_Space is unchanged. The returned Color_Space is
486immutable.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400487
Cary Clark681287e2018-03-16 11:34:15 -0400488#Return Color_Space in Image_Info, or nullptr ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400489
490#Example
491#Description
492SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma
493and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma.
494##
Cary Clark682c58d2018-05-16 07:07:07 -0400495 SkPixmap pixmap(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
Cary Clark6fc50412017-09-21 12:31:06 -0400496 SkColorSpace::MakeSRGBLinear()), nullptr, 64);
497 SkColorSpace* colorSpace = pixmap.colorSpace();
498 SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
499 colorSpace->gammaCloseToSRGB() ? "true" : "false",
500 colorSpace->gammaIsLinear() ? "true" : "false",
501 colorSpace->isSRGB() ? "true" : "false");
502#StdOut
503gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
504##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400505##
506
Cary Clarkbc5697d2017-10-04 14:31:33 -0400507#SeeAlso Color_Space SkImageInfo::colorSpace
Cary Clarkd0530ba2017-09-14 11:25:39 -0400508
509##
510
511# ------------------------------------------------------------------------------
512
Cary Clark682c58d2018-05-16 07:07:07 -0400513#Method bool isOpaque() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400514
Cary Clarkab2621d2018-01-30 10:08:57 -0500515#In Image_Info_Access
516#Line # returns true if Image_Info describes opaque pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400517Returns true if Alpha_Type is kOpaque_SkAlphaType.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400518Does not check if Color_Type allows Alpha, or if any pixel value has
519transparency.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400520
521#Return true if Image_Info has opaque Alpha_Type ##
522
523#Example
524#Description
525 isOpaque ignores whether all pixels are opaque or not.
526##
Cary Clark6fc50412017-09-21 12:31:06 -0400527 std::vector<uint32_t> pixels;
528 const int height = 2;
529 const int width = 2;
530 pixels.resize(height * width * 4);
531 SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType,
532 kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4);
533 for (int index = 0; index < 2; ++index) {
534 pixmap.erase(0x00000000);
535 SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false");
536 pixmap.erase(0xFFFFFFFF);
537 SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false");
538 pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType),
539 (const void*) &pixels.front(), width * 4);
540 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400541#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400542isOpaque: false
543isOpaque: false
544isOpaque: true
Cary Clarkd0530ba2017-09-14 11:25:39 -0400545isOpaque: true
546##
547##
548
549#SeeAlso computeIsOpaque SkImageInfo::isOpaque
550
551##
552
553# ------------------------------------------------------------------------------
554
Cary Clark682c58d2018-05-16 07:07:07 -0400555#Method SkIRect bounds() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400556
Cary Clarkab2621d2018-01-30 10:08:57 -0500557#In Image_Info_Access
558#Line # returns width and height as Rectangle ##
Cary Clark154beea2017-10-26 07:58:48 -0400559Returns IRect { 0, 0, width(), height() }.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400560
561#Return integral rectangle from origin to width() and height() ##
562
563#Example
564 for (int width : { 0, 2 } ) {
565 for (int height : { 0, 2 } ) {
Cary Clark6fc50412017-09-21 12:31:06 -0400566 SkPixmap pixmap(SkImageInfo::MakeA8(width, height), nullptr, width);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400567 SkDebugf("width: %d height: %d empty: %s\n", width, height,
568 pixmap.bounds().isEmpty() ? "true" : "false");
569 }
570 }
571#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400572width: 0 height: 0 empty: true
573width: 0 height: 2 empty: true
574width: 2 height: 0 empty: true
Cary Clarkd0530ba2017-09-14 11:25:39 -0400575width: 2 height: 2 empty: false
576##
577##
578
Cary Clark682c58d2018-05-16 07:07:07 -0400579#SeeAlso height() width() IRect
Cary Clarkd0530ba2017-09-14 11:25:39 -0400580
581##
582
583# ------------------------------------------------------------------------------
584
Cary Clark682c58d2018-05-16 07:07:07 -0400585#Method int rowBytesAsPixels() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400586
Cary Clarkab2621d2018-01-30 10:08:57 -0500587#In Image_Info_Access
588#Line # returns interval between rows in pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400589
590Returns number of pixels that fit on row. Should be greater than or equal to
591width().
592
593#Return maximum pixels per row ##
594
595#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400596 for (int rowBytes : { 4, 5, 6, 7, 8} ) {
597 SkPixmap pixmap(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), nullptr, rowBytes);
598 SkDebugf("rowBytes: %d rowBytesAsPixels: %d\n", rowBytes, pixmap.rowBytesAsPixels());
599 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400600#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400601rowBytes: 4 rowBytesAsPixels: 1
602rowBytes: 5 rowBytesAsPixels: 1
603rowBytes: 6 rowBytesAsPixels: 1
604rowBytes: 7 rowBytesAsPixels: 1
Cary Clarkd0530ba2017-09-14 11:25:39 -0400605rowBytes: 8 rowBytesAsPixels: 2
606##
607##
608
609#SeeAlso rowBytes shiftPerPixel width SkImageInfo::bytesPerPixel
610
611##
612
613# ------------------------------------------------------------------------------
614
Cary Clark682c58d2018-05-16 07:07:07 -0400615#Method int shiftPerPixel() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400616
Cary Clarkab2621d2018-01-30 10:08:57 -0500617#In Image_Info_Access
618#Line # returns bit shift from pixels to bytes ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400619Returns bit shift converting row bytes to row pixels.
620Returns zero for kUnknown_SkColorType.
621
622#Return one of: 0, 1, 2, 3; left shift to convert pixels to bytes ##
623
624#Example
Cary Clarkab2621d2018-01-30 10:08:57 -0500625 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
626 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -0400627 SkImageInfo info = SkImageInfo::MakeA8(1, 1);
628 for (SkColorType colorType : { kUnknown_SkColorType, kAlpha_8_SkColorType,
Cary Clark682c58d2018-05-16 07:07:07 -0400629 kRGB_565_SkColorType, kARGB_4444_SkColorType,
Cary Clark6fc50412017-09-21 12:31:06 -0400630 kRGBA_8888_SkColorType, kBGRA_8888_SkColorType,
631 kGray_8_SkColorType, kRGBA_F16_SkColorType } ) {
632 SkPixmap pixmap(info.makeColorType(colorType), nullptr, 4);
633 SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d shiftPerPixel: %d\n",
634 colors[colorType], 10 - strlen(colors[colorType]), " ",
635 pixmap.info().bytesPerPixel(), pixmap.shiftPerPixel());
636 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400637#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400638color: kUnknown_SkColorType bytesPerPixel: 0 shiftPerPixel: 0
Cary Clarkab2621d2018-01-30 10:08:57 -0500639color: kAlpha_8_SkColorType bytesPerPixel: 1 shiftPerPixel: 0
Cary Clark6fc50412017-09-21 12:31:06 -0400640color: kRGB_565_SkColorType bytesPerPixel: 2 shiftPerPixel: 1
641color: kARGB_4444_SkColorType bytesPerPixel: 2 shiftPerPixel: 1
642color: kRGBA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2
643color: kBGRA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2
644color: kGray_8_SkColorType bytesPerPixel: 1 shiftPerPixel: 0
Cary Clarkd0530ba2017-09-14 11:25:39 -0400645color: kRGBA_F16_SkColorType bytesPerPixel: 8 shiftPerPixel: 3
646##
647##
648
649#SeeAlso rowBytes rowBytesAsPixels width SkImageInfo::bytesPerPixel
650
651##
652
653# ------------------------------------------------------------------------------
654
Cary Clarkbc5697d2017-10-04 14:31:33 -0400655#Method size_t computeByteSize() const
656
Cary Clarkab2621d2018-01-30 10:08:57 -0500657#In Image_Info_Access
658#Line # returns size required for pixels ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400659Returns minimum memory required for pixel storage.
660Does not include unused memory on last row when rowBytesAsPixels exceeds width().
661Returns zero if result does not fit in size_t.
662Returns zero if height() or width() is 0.
663Returns height() times rowBytes if colorType is kUnknown_SkColorType.
664
665#Return size in bytes of image buffer ##
666
Cary Clarkd0530ba2017-09-14 11:25:39 -0400667#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400668 SkPixmap pixmap;
669 for (int width : { 1, 1000, 1000000 } ) {
670 for (int height: { 1, 1000, 1000000 } ) {
671 SkImageInfo imageInfo = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType);
Cary Clarkbc5697d2017-10-04 14:31:33 -0400672 pixmap.reset(imageInfo, nullptr, width * 5);
673 SkDebugf("width: %7d height: %7d computeByteSize: %13lld\n", width, height,
674 pixmap.computeByteSize());
Cary Clark6fc50412017-09-21 12:31:06 -0400675 }
676 }
Cary Clark6fc50412017-09-21 12:31:06 -0400677#StdOut
Ben Wagner29380bd2017-10-09 14:43:00 -0400678width: 1 height: 1 computeByteSize: 4
679width: 1 height: 1000 computeByteSize: 4999
680width: 1 height: 1000000 computeByteSize: 4999999
681width: 1000 height: 1 computeByteSize: 4000
682width: 1000 height: 1000 computeByteSize: 4999000
683width: 1000 height: 1000000 computeByteSize: 4999999000
684width: 1000000 height: 1 computeByteSize: 4000000
685width: 1000000 height: 1000 computeByteSize: 4999000000
Cary Clarkbc5697d2017-10-04 14:31:33 -0400686width: 1000000 height: 1000000 computeByteSize: 4999999000000
Cary Clarkd0530ba2017-09-14 11:25:39 -0400687##
688##
689
Cary Clarkbc5697d2017-10-04 14:31:33 -0400690#SeeAlso SkImageInfo::computeByteSize
Cary Clarkd0530ba2017-09-14 11:25:39 -0400691
692##
693
694#Subtopic Image_Info_Access ##
695
696#Subtopic Reader
Cary Clark08895c42018-02-01 09:37:32 -0500697#Line # examine pixel value ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400698
699# ------------------------------------------------------------------------------
700
701#Method bool computeIsOpaque() const
702
Cary Clarkab2621d2018-01-30 10:08:57 -0500703#In Reader
704#Line # returns true if all pixels are opaque ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400705Returns true if all pixels are opaque. Color_Type determines how pixels
706are encoded, and whether pixel describes Alpha. Returns true for Color_Types
Cary Clark6fc50412017-09-21 12:31:06 -0400707without alpha in each pixel; for other Color_Types, returns true if all
Cary Clarkd0530ba2017-09-14 11:25:39 -0400708pixels have alpha values equivalent to 1.0 or greater.
709
710For Color_Types kRGB_565_SkColorType or kGray_8_SkColorType: always
711returns true. For Color_Types kAlpha_8_SkColorType, kBGRA_8888_SkColorType,
712kRGBA_8888_SkColorType: returns true if all pixel Alpha values are 255.
713For Color_Type kARGB_4444_SkColorType: returns true if all pixel Alpha values are 15.
714For kRGBA_F16_SkColorType: returns true if all pixel Alpha values are 1.0 or
715greater.
716
Cary Clark682c58d2018-05-16 07:07:07 -0400717Returns false for kUnknown_SkColorType.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400718
Cary Clarkbc5697d2017-10-04 14:31:33 -0400719#Return true if all pixels have opaque values or Color_Type is opaque ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400720
721#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400722 std::vector<uint32_t> pixels;
723 const int height = 2;
724 const int width = 2;
725 pixels.resize(height * width * 4);
726 SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType,
727 kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4);
728 for (int index = 0; index < 2; ++index) {
729 pixmap.erase(0x00000000);
730 SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false");
731 pixmap.erase(0xFFFFFFFF);
732 SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false");
733 pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType),
734 (const void*) &pixels.front(), width * 4);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400735 }
736#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400737computeIsOpaque: false
738computeIsOpaque: true
739computeIsOpaque: false
Cary Clarkd0530ba2017-09-14 11:25:39 -0400740computeIsOpaque: true
741##
742##
743
744#SeeAlso isOpaque Color_Type Alpha
745
746##
747
748# ------------------------------------------------------------------------------
749
750#Method SkColor getColor(int x, int y) const
751
Cary Clarkab2621d2018-01-30 10:08:57 -0500752#In Reader
753#Line # returns one pixel as Unpremultiplied Color ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400754Returns pixel at (x, y) as Unpremultiplied Color.
755Returns black with Alpha if Color_Type is kAlpha_8_SkColorType.
756
757Input is not validated: out of bounds values of x or y trigger an assert() if
758built with SK_DEBUG defined; and returns undefined values or may crash if
759SK_RELEASE is defined. Fails if Color_Type is kUnknown_SkColorType or
760pixel address is nullptr.
761
762Color_Space in Image_Info is ignored. Some Color precision may be lost in the
Cary Clark682c58d2018-05-16 07:07:07 -0400763conversion to Unpremultiplied Color; original pixel data may have additional
Cary Clarkd0530ba2017-09-14 11:25:39 -0400764precision.
765
Cary Clark6fc50412017-09-21 12:31:06 -0400766#Param x column index, zero or greater, and less than width() ##
767#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400768
769#Return pixel converted to Unpremultiplied Color ##
770
771#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400772 const int w = 4;
773 const int h = 4;
774 std::vector<SkPMColor> storage;
775 storage.resize(w * h);
776 SkDebugf("Premultiplied:\n");
777 for (int y = 0; y < h; ++y) {
778 SkDebugf("(0, %d) ", y);
779 for (int x = 0; x < w; ++x) {
780 int a = 0xFF * (x + y) / (w - 1 + h - 1);
781 storage[x + y * w] = SkPackARGB32(a, a * x / (w - 1), a * y / (h - 1), a);
782 SkDebugf("0x%08x%c", storage[x + y * w], x == w - 1 ? '\n' : ' ');
783 }
784 }
785 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4);
786 SkDebugf("Unpremultiplied:\n");
787 for (int y = 0; y < h; ++y) {
788 SkDebugf("(0, %d) ", y);
789 for (int x = 0; x < w; ++x) {
790 SkDebugf("0x%08x%c", pixmap.getColor(x, y), x == w - 1 ? '\n' : ' ');
791 }
792 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400793#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400794Premultiplied:
Cary Clark682c58d2018-05-16 07:07:07 -0400795(0, 0) 0x00000000 0x2a0e002a 0x55380055 0x7f7f007f
796(0, 1) 0x2a000e2a 0x551c1c55 0x7f542a7f 0xaaaa38aa
797(0, 2) 0x55003855 0x7f2a547f 0xaa7171aa 0xd4d48dd4
798(0, 3) 0x7f007f7f 0xaa38aaaa 0xd48dd4d4 0xffffffff
Cary Clark6fc50412017-09-21 12:31:06 -0400799Unpremultiplied:
Cary Clark682c58d2018-05-16 07:07:07 -0400800(0, 0) 0x00000000 0x2a5500ff 0x55a800ff 0x7fff00ff
801(0, 1) 0x2a0055ff 0x555454ff 0x7fa954ff 0xaaff54ff
802(0, 2) 0x5500a8ff 0x7f54a9ff 0xaaaaaaff 0xd4ffaaff
803(0, 3) 0x7f00ffff 0xaa54ffff 0xd4aaffff 0xffffffff
Cary Clarkd0530ba2017-09-14 11:25:39 -0400804##
805##
806
807#SeeAlso addr() readPixels
808
809##
810
811#Subtopic Reader ##
812
813#Subtopic Readable_Address
Cary Clark08895c42018-02-01 09:37:32 -0500814#Line # returns read only pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400815
816# ------------------------------------------------------------------------------
817
818#Method const void* addr(int x, int y) const
819
Cary Clarkab2621d2018-01-30 10:08:57 -0500820#In Readable_Address
Cary Clarkbc5697d2017-10-04 14:31:33 -0400821Returns readable pixel address at (x, y). Returns nullptr if Pixel_Ref is nullptr.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400822
823Input is not validated: out of bounds values of x or y trigger an assert() if
Cary Clarkbc5697d2017-10-04 14:31:33 -0400824built with SK_DEBUG defined. Returns nullptr if Color_Type is kUnknown_SkColorType.
825
Cary Clark682c58d2018-05-16 07:07:07 -0400826Performs a lookup of pixel size; for better performance, call
Cary Clarkbc5697d2017-10-04 14:31:33 -0400827one of: addr8, addr16, addr32, addr64, or addrF16.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400828
Cary Clark6fc50412017-09-21 12:31:06 -0400829#Param x column index, zero or greater, and less than width() ##
830#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400831
832#Return readable generic pointer to pixel ##
833
834#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400835 const int w = 4;
836 const int h = 4;
837 std::vector<SkPMColor> storage;
838 storage.resize(w * h);
839 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400840 SkDebugf("pixmap.addr(1, 2) %c= &storage[1 + 2 * w]\n",
841 pixmap.addr(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
842#StdOut
843pixmap.addr(1, 2) == &storage[1 + 2 * w]
844##
845##
846
Cary Clarkbc5697d2017-10-04 14:31:33 -0400847#SeeAlso addr8 addr16 addr32 addr64 addrF16 getColor writable_addr SkBitmap::getAddr
Cary Clarkd0530ba2017-09-14 11:25:39 -0400848
849##
850
851# ------------------------------------------------------------------------------
852
Cary Clark682c58d2018-05-16 07:07:07 -0400853#Method const uint8_t* addr8() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400854
Cary Clarkab2621d2018-01-30 10:08:57 -0500855#In Readable_Address
856#Line # returns readable pixel address as 8-bit pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400857Returns readable base pixel address. Result is addressable as unsigned 8-bit bytes.
858Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType or
859kGray_8_SkColorType, and is built with SK_DEBUG defined.
860
861One byte corresponds to one pixel.
862
863#Return readable unsigned 8-bit pointer to pixels ##
864
865#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400866 const int w = 4;
867 const int h = 4;
868 uint8_t storage[w * h];
869 SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType),
870 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400871 SkDebugf("pixmap.addr8() %c= storage\n",
872 pixmap.addr8() == storage ? '=' : '!');
873#StdOut
874pixmap.addr8() == storage
875##
876##
877
878#SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8
879
880##
881
882# ------------------------------------------------------------------------------
883
Cary Clark682c58d2018-05-16 07:07:07 -0400884#Method const uint16_t* addr16() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400885
Cary Clarkab2621d2018-01-30 10:08:57 -0500886#In Readable_Address
887#Line # returns readable pixel address as 16-bit pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400888Returns readable base pixel address. Result is addressable as unsigned 16-bit words.
889Will trigger an assert() if Color_Type is not kRGB_565_SkColorType or
890kARGB_4444_SkColorType, and is built with SK_DEBUG defined.
891
892One word corresponds to one pixel.
893
894#Return readable unsigned 16-bit pointer to pixels ##
895
896#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400897 const int w = 4;
898 const int h = 4;
899 uint16_t storage[w * h];
900 SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType),
901 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400902 SkDebugf("pixmap.addr16() %c= storage\n",
903 pixmap.addr16() == storage ? '=' : '!');
904#StdOut
905pixmap.addr16() == storage
906##
907##
908
909#SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16
910
911##
912
913# ------------------------------------------------------------------------------
914
Cary Clark682c58d2018-05-16 07:07:07 -0400915#Method const uint32_t* addr32() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400916
Cary Clarkab2621d2018-01-30 10:08:57 -0500917#In Readable_Address
918#Line # returns readable pixel address as 32-bit pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400919Returns readable base pixel address. Result is addressable as unsigned 32-bit words.
920Will trigger an assert() if Color_Type is not kRGBA_8888_SkColorType or
921kBGRA_8888_SkColorType, and is built with SK_DEBUG defined.
922
923One word corresponds to one pixel.
924
925#Return readable unsigned 32-bit pointer to pixels ##
926
927#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400928 const int w = 4;
929 const int h = 4;
930 uint32_t storage[w * h];
931 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType),
932 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400933 SkDebugf("pixmap.addr32() %c= storage\n",
934 pixmap.addr32() == storage ? '=' : '!');
935#StdOut
936pixmap.addr32() == storage
937##
938##
939
940#SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr32
941
942##
943
944# ------------------------------------------------------------------------------
945
Cary Clark682c58d2018-05-16 07:07:07 -0400946#Method const uint64_t* addr64() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400947
Cary Clarkab2621d2018-01-30 10:08:57 -0500948#In Readable_Address
949#Line # returns readable pixel address as 64-bit pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400950Returns readable base pixel address. Result is addressable as unsigned 64-bit words.
951Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
952with SK_DEBUG defined.
953
954One word corresponds to one pixel.
955
956#Return readable unsigned 64-bit pointer to pixels ##
957
958#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400959 const int w = 4;
960 const int h = 4;
961 uint64_t storage[w * h];
962 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
963 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400964 SkDebugf("pixmap.addr64() %c= storage\n",
965 pixmap.addr64() == storage ? '=' : '!');
966#StdOut
967pixmap.addr64() == storage
968##
969##
970
971#SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64
972
973##
974
975# ------------------------------------------------------------------------------
976
Cary Clark682c58d2018-05-16 07:07:07 -0400977#Method const uint16_t* addrF16() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400978
Cary Clarkab2621d2018-01-30 10:08:57 -0500979#In Readable_Address
980#Line # returns readable pixel component address as 16-bit pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400981Returns readable base pixel address. Result is addressable as unsigned 16-bit words.
982Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
983with SK_DEBUG defined.
984
985Each word represents one color component encoded as a half float.
986Four words correspond to one pixel.
987
988#Return readable unsigned 16-bit pointer to first component of pixels ##
989
990#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400991 const int w = 4;
992 const int h = 4;
993 uint16_t storage[w * h * 4];
994 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
995 storage, w * 4 * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400996 SkDebugf("pixmap.addrF16() %c= storage\n",
997 pixmap.addrF16() == storage ? '=' : '!');
998#StdOut
999pixmap.addrF16() == storage
1000##
1001##
1002
1003#SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16
1004
1005##
1006
1007# ------------------------------------------------------------------------------
1008
Cary Clark682c58d2018-05-16 07:07:07 -04001009#Method const uint8_t* addr8(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001010
Cary Clarkab2621d2018-01-30 10:08:57 -05001011#In Readable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001012Returns readable pixel address at (x, y).
1013
1014Input is not validated: out of bounds values of x or y trigger an assert() if
1015built with SK_DEBUG defined.
1016
1017Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType or
1018kGray_8_SkColorType, and is built with SK_DEBUG defined.
1019
Cary Clark6fc50412017-09-21 12:31:06 -04001020#Param x column index, zero or greater, and less than width() ##
1021#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001022
1023#Return readable unsigned 8-bit pointer to pixel at (x, y) ##
1024
1025#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001026 const int w = 4;
1027 const int h = 4;
1028 uint8_t storage[w * h];
1029 SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType),
1030 storage, w * sizeof(storage[0]));
1031 SkDebugf("pixmap.addr8(1, 2) %c= &storage[1 + 2 * w]\n",
1032 pixmap.addr8(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
Cary Clarkd0530ba2017-09-14 11:25:39 -04001033#StdOut
1034pixmap.addr8(1, 2) == &storage[1 + 2 * w]
1035##
1036##
1037
1038#SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8
1039
1040##
1041
1042# ------------------------------------------------------------------------------
1043
Cary Clark682c58d2018-05-16 07:07:07 -04001044#Method const uint16_t* addr16(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001045
Cary Clarkab2621d2018-01-30 10:08:57 -05001046#In Readable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001047Returns readable pixel address at (x, y).
1048
1049Input is not validated: out of bounds values of x or y trigger an assert() if
1050built with SK_DEBUG defined.
1051
1052Will trigger an assert() if Color_Type is not kRGB_565_SkColorType or
1053kARGB_4444_SkColorType, and is built with SK_DEBUG defined.
1054
Cary Clark6fc50412017-09-21 12:31:06 -04001055#Param x column index, zero or greater, and less than width() ##
1056#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001057
1058#Return readable unsigned 16-bit pointer to pixel at (x, y) ##
1059
1060#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001061 const int w = 4;
1062 const int h = 4;
1063 uint16_t storage[w * h];
1064 SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType),
1065 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001066 SkDebugf("pixmap.addr16(1, 2) %c= &storage[1 + 2 * w]\n",
1067 pixmap.addr16(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
1068#StdOut
1069pixmap.addr16(1, 2) == &storage[1 + 2 * w]
1070##
1071##
1072
1073#SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16
1074
1075##
1076
1077# ------------------------------------------------------------------------------
1078
Cary Clark682c58d2018-05-16 07:07:07 -04001079#Method const uint32_t* addr32(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001080
Cary Clarkab2621d2018-01-30 10:08:57 -05001081#In Readable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001082Returns readable pixel address at (x, y).
1083
1084Input is not validated: out of bounds values of x or y trigger an assert() if
1085built with SK_DEBUG defined.
1086
1087Will trigger an assert() if Color_Type is not kRGBA_8888_SkColorType or
1088kBGRA_8888_SkColorType, and is built with SK_DEBUG defined.
1089
Cary Clark6fc50412017-09-21 12:31:06 -04001090#Param x column index, zero or greater, and less than width() ##
1091#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001092
1093#Return readable unsigned 32-bit pointer to pixel at (x, y) ##
1094
1095#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001096 const int w = 4;
1097 const int h = 4;
1098 uint32_t storage[w * h];
1099 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_8888_SkColorType, kPremul_SkAlphaType),
1100 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001101 SkDebugf("pixmap.addr32(1, 2) %c= &storage[1 + 2 * w]\n",
1102 pixmap.addr32(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
1103#StdOut
1104pixmap.addr32(1, 2) == &storage[1 + 2 * w]
1105##
1106##
1107
Cary Clark2ade9972017-11-02 17:49:34 -04001108#SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr64
Cary Clarkd0530ba2017-09-14 11:25:39 -04001109
1110##
1111
1112# ------------------------------------------------------------------------------
1113
Cary Clark682c58d2018-05-16 07:07:07 -04001114#Method const uint64_t* addr64(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001115
Cary Clarkab2621d2018-01-30 10:08:57 -05001116#In Readable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001117Returns readable pixel address at (x, y).
1118
1119Input is not validated: out of bounds values of x or y trigger an assert() if
1120built with SK_DEBUG defined.
1121
1122Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
1123with SK_DEBUG defined.
1124
Cary Clark6fc50412017-09-21 12:31:06 -04001125#Param x column index, zero or greater, and less than width() ##
1126#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001127
1128#Return readable unsigned 64-bit pointer to pixel at (x, y) ##
1129
1130#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001131 const int w = 4;
1132 const int h = 4;
1133 uint64_t storage[w * h];
1134 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
1135 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001136 SkDebugf("pixmap.addr64(1, 2) %c= &storage[1 + 2 * w]\n",
1137 pixmap.addr64(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
1138#StdOut
1139pixmap.addr64(1, 2) == &storage[1 + 2 * w]
1140##
1141##
1142
1143#SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64
1144
1145##
1146
1147# ------------------------------------------------------------------------------
1148
Cary Clark682c58d2018-05-16 07:07:07 -04001149#Method const uint16_t* addrF16(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001150
Cary Clarkab2621d2018-01-30 10:08:57 -05001151#In Readable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001152Returns readable pixel address at (x, y).
1153
1154Input is not validated: out of bounds values of x or y trigger an assert() if
1155built with SK_DEBUG defined.
1156
1157Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
1158with SK_DEBUG defined.
1159
1160Each unsigned 16-bit word represents one color component encoded as a half float.
1161Four words correspond to one pixel.
1162
Cary Clark6fc50412017-09-21 12:31:06 -04001163#Param x column index, zero or greater, and less than width() ##
1164#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001165
1166#Return readable unsigned 16-bit pointer to pixel component at (x, y) ##
1167
1168#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001169 const int w = 4;
1170 const int h = 4;
1171 const int wordsPerPixel = 4;
1172 const int rowWords = w * wordsPerPixel;
1173 uint16_t storage[rowWords * h];
1174 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
1175 storage, rowWords * sizeof(storage[0]));
1176 SkDebugf("pixmap.addrF16(1, 2) %c= &storage[1 * wordsPerPixel + 2 * rowWords]\n",
1177 pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords] ? '=' : '!');
Cary Clarkd0530ba2017-09-14 11:25:39 -04001178#StdOut
1179pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords]
1180##
1181##
1182
1183#SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16
1184
1185##
1186
1187#Subtopic Readable_Address ##
1188
1189#Subtopic Writable_Address
Cary Clark08895c42018-02-01 09:37:32 -05001190#Line # returns writable pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001191
1192# ------------------------------------------------------------------------------
1193
Cary Clark682c58d2018-05-16 07:07:07 -04001194#Method void* writable_addr() const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001195
Cary Clarkab2621d2018-01-30 10:08:57 -05001196#In Writable_Address
1197#Line # returns writable pixel address as void pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001198Returns writable base pixel address.
1199
1200#Return writable generic base pointer to pixels ##
1201
1202#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001203 const int w = 4;
1204 const int h = 4;
1205 SkPMColor storage[w * h * 4];
1206 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4);
1207 SkDebugf("pixmap.writable_addr() %c= (void *)storage\n",
1208 pixmap.writable_addr() == (void *)storage ? '=' : '!');
1209 pixmap.erase(0x00000000);
1210 *(SkPMColor*)pixmap.writable_addr() = 0xFFFFFFFF;
1211 SkDebugf("pixmap.getColor(0, 1) %c= 0x00000000\n",
1212 pixmap.getColor(0, 1) == 0x00000000 ? '=' : '!');
1213 SkDebugf("pixmap.getColor(0, 0) %c= 0xFFFFFFFF\n",
Cary Clarkd0530ba2017-09-14 11:25:39 -04001214 pixmap.getColor(0, 0) == 0xFFFFFFFF ? '=' : '!');
1215#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -04001216pixmap.writable_addr() == (void *)storage
1217pixmap.getColor(0, 1) == 0x00000000
Cary Clarkd0530ba2017-09-14 11:25:39 -04001218pixmap.getColor(0, 0) == 0xFFFFFFFF
1219##
1220##
1221
1222#SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr()
1223
1224##
1225
1226# ------------------------------------------------------------------------------
1227
Cary Clark682c58d2018-05-16 07:07:07 -04001228#Method void* writable_addr(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001229
Cary Clarkab2621d2018-01-30 10:08:57 -05001230#In Writable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001231Returns writable pixel address at (x, y).
1232
1233Input is not validated: out of bounds values of x or y trigger an assert() if
1234built with SK_DEBUG defined. Returns zero if Color_Type is kUnknown_SkColorType.
1235
Cary Clark6fc50412017-09-21 12:31:06 -04001236#Param x column index, zero or greater, and less than width() ##
1237#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001238
1239#Return writable generic pointer to pixel ##
1240
1241#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001242 const int w = 4;
1243 const int h = 4;
1244 SkPMColor storage[w * h * 4];
1245 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4);
1246 SkDebugf("pixmap.writable_addr() %c= (void *)storage\n",
1247 pixmap.writable_addr() == (void *)storage ? '=' : '!');
1248 pixmap.erase(0x00000000);
1249 *(SkPMColor*)pixmap.writable_addr(1, 2) = 0xFFFFFFFF;
1250 SkDebugf("pixmap.getColor(0, 0) %c= 0x00000000\n",
1251 pixmap.getColor(0, 0) == 0x00000000 ? '=' : '!');
1252 SkDebugf("pixmap.getColor(1, 2) %c= 0xFFFFFFFF\n",
Cary Clarkd0530ba2017-09-14 11:25:39 -04001253 pixmap.getColor(1, 2) == 0xFFFFFFFF ? '=' : '!');
1254#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -04001255pixmap.writable_addr() == (void *)storage
1256pixmap.getColor(0, 0) == 0x00000000
Cary Clarkd0530ba2017-09-14 11:25:39 -04001257pixmap.getColor(1, 2) == 0xFFFFFFFF
1258##
1259##
1260
1261#SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr()
1262
1263##
1264
1265# ------------------------------------------------------------------------------
1266
Cary Clark682c58d2018-05-16 07:07:07 -04001267#Method uint8_t* writable_addr8(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001268
Cary Clarkab2621d2018-01-30 10:08:57 -05001269#In Writable_Address
1270#Line # returns writable pixel address as 8-bit pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -04001271Returns writable pixel address at (x, y). Result is addressable as unsigned
12728-bit bytes. Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType
1273or kGray_8_SkColorType, and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001274
1275One byte corresponds to one pixel.
1276
Cary Clark6fc50412017-09-21 12:31:06 -04001277#Param x column index, zero or greater, and less than width() ##
1278#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001279
1280#Return writable unsigned 8-bit pointer to pixels ##
1281
1282#Example
1283#Height 64
1284#Description
1285Altering pixels after drawing Bitmap is not guaranteed to affect subsequent
1286drawing on all platforms. Adding a second SkBitmap::installPixels after editing
1287pixel memory is safer.
1288##
Cary Clark6fc50412017-09-21 12:31:06 -04001289void draw(SkCanvas* canvas) {
1290 uint8_t storage[][5] = {{ 0, 0, 64, 0, 0},
1291 { 0, 128, 255, 128, 0},
1292 {64, 255, 255, 255, 64},
1293 { 0, 128, 255, 128, 0},
1294 { 0, 0, 64, 0, 0}};
1295 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kPremul_SkAlphaType);
1296 SkPixmap pixmap(imageInfo, storage[0], 5);
1297 SkBitmap bitmap;
1298 bitmap.installPixels(pixmap);
1299 canvas->scale(10, 10);
1300 canvas->drawBitmap(bitmap, 0, 0);
1301 *pixmap.writable_addr8(2, 2) = 0;
1302// bitmap.installPixels(pixmap); // uncomment to fix on GPU
1303 canvas->drawBitmap(bitmap, 10, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001304}
1305##
1306
1307#SeeAlso writable_addr writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr() addr8
1308
1309##
1310
1311# ------------------------------------------------------------------------------
1312
Cary Clark682c58d2018-05-16 07:07:07 -04001313#Method uint16_t* writable_addr16(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001314
Cary Clarkab2621d2018-01-30 10:08:57 -05001315#In Writable_Address
1316#Line # returns writable pixel address as 16-bit pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -04001317Returns writable_addr pixel address at (x, y). Result is addressable as unsigned
131816-bit words. Will trigger an assert() if Color_Type is not kRGB_565_SkColorType
1319or kARGB_4444_SkColorType, and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001320
1321One word corresponds to one pixel.
1322
Cary Clark6fc50412017-09-21 12:31:06 -04001323#Param x column index, zero or greater, and less than width() ##
1324#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001325
1326#Return writable unsigned 16-bit pointer to pixel ##
1327
1328#Example
1329#Description
1330Draw a five by five bitmap, and draw it again with a center black pixel.
1331The low nibble of the 16-bit word is Alpha.
1332##
1333#Height 64
Cary Clark6fc50412017-09-21 12:31:06 -04001334 uint16_t storage[][5] = {{ 0xCABF, 0xDABE, 0xCA9D, 0xC96C, 0xA39B },
1335 { 0xACEE, 0xA87C, 0x893A, 0x4779, 0x8708 },
1336 { 0x4B7C, 0x255B, 0x2559, 0x2557, 0x4656 },
1337 { 0x9099, 0x8128, 0x2557, 0x4124, 0x3323 },
1338 { 0x7547, 0x5505, 0x4434, 0x2012, 0x0000 }};
1339 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kARGB_4444_SkColorType, kPremul_SkAlphaType);
1340 SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
1341 SkBitmap bitmap;
1342 bitmap.installPixels(pixmap);
1343 canvas->scale(10, 10);
1344 canvas->drawBitmap(bitmap, 0, 0);
1345 *pixmap.writable_addr16(2, 2) = 0x000F;
1346 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001347 canvas->drawBitmap(bitmap, 10, 0);
1348##
1349
1350#SeeAlso writable_addr writable_addr8 writable_addr32 writable_addr64 writable_addrF16 addr() addr16
1351
1352##
1353
1354# ------------------------------------------------------------------------------
1355
Cary Clark682c58d2018-05-16 07:07:07 -04001356#Method uint32_t* writable_addr32(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001357
Cary Clarkab2621d2018-01-30 10:08:57 -05001358#In Writable_Address
1359#Line # returns writable pixel address as 32-bit pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -04001360Returns writable pixel address at (x, y). Result is addressable as unsigned
136132-bit words. Will trigger an assert() if Color_Type is not
1362kRGBA_8888_SkColorType or kBGRA_8888_SkColorType, and is built with SK_DEBUG
1363defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001364
1365One word corresponds to one pixel.
1366
Cary Clark6fc50412017-09-21 12:31:06 -04001367#Param x column index, zero or greater, and less than width() ##
1368#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001369
1370#Return writable unsigned 32-bit pointer to pixel ##
1371
1372#Example
1373#Image 4
1374#Height 72
Cary Clark6fc50412017-09-21 12:31:06 -04001375 std::vector<int32_t> pixels;
1376 pixels.resize(image->height() * image->width() * 4);
1377 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
1378 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
1379 image->readPixels(pixmap, 0, 0);
1380 for (int y = 0; y < pixmap.height() / 2; ++y) {
1381 for (int x = 0; x < pixmap.width(); ++x) {
1382 if ((x & 4) == (y & 4)) {
Cary Clark4d759752018-06-19 12:57:43 -04001383 *pixmap.writable_addr32(x, y) =
1384 *pixmap.writable_addr32(pixmap.width() - x, pixmap.height() - y);
Cary Clark6fc50412017-09-21 12:31:06 -04001385 }
1386 }
1387 }
1388 SkBitmap bitmap;
1389 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001390 canvas->drawBitmap(bitmap, 0, 0);
1391##
1392
1393#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr64 writable_addrF16 addr() addr32
1394
1395##
1396
1397# ------------------------------------------------------------------------------
1398
Cary Clark682c58d2018-05-16 07:07:07 -04001399#Method uint64_t* writable_addr64(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001400
Cary Clarkab2621d2018-01-30 10:08:57 -05001401#In Writable_Address
1402#Line # returns writable pixel address as 64-bit pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -04001403Returns writable pixel address at (x, y). Result is addressable as unsigned
140464-bit words. Will trigger an assert() if Color_Type is not
1405kRGBA_F16_SkColorType and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001406
1407One word corresponds to one pixel.
1408
Cary Clark6fc50412017-09-21 12:31:06 -04001409#Param x column index, zero or greater, and less than width() ##
1410#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001411
1412#Return writable unsigned 64-bit pointer to pixel ##
1413
1414#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001415#Height 40
Cary Clark6fc50412017-09-21 12:31:06 -04001416 SkImageInfo info = SkImageInfo::Make(3, 3, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
1417 uint64_t storage[9];
1418 SkPixmap pixmap(info, storage, 3 * sizeof(uint64_t));
1419 SkColor4f c4 { 1, 0.45f, 0.25f, 0.65f };
1420 pixmap.erase(c4);
1421 SkBitmap bitmap;
1422 canvas->scale(10, 10);
1423 bitmap.installPixels(pixmap);
1424 canvas->drawBitmap(bitmap, 0, 0);
1425 *pixmap.writable_addr64(1, 1) |= 0x00ff000000000000LL;
1426 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001427 canvas->drawBitmap(bitmap, 10, 0);
1428##
1429
1430#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addrF16 addr() addr64
1431
1432##
1433
1434# ------------------------------------------------------------------------------
1435
Cary Clark682c58d2018-05-16 07:07:07 -04001436#Method uint16_t* writable_addrF16(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001437
Cary Clarkab2621d2018-01-30 10:08:57 -05001438#In Writable_Address
1439#Line # returns writable pixel component address as 16-bit pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -04001440Returns writable pixel address at (x, y). Result is addressable as unsigned
144116-bit words. Will trigger an assert() if Color_Type is not
1442kRGBA_F16_SkColorType and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001443
1444Each word represents one color component encoded as a half float.
1445Four words correspond to one pixel.
1446
Cary Clark6fc50412017-09-21 12:31:06 -04001447#Param x column index, zero or greater, and less than width() ##
1448#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001449
1450#Return writable unsigned 16-bit pointer to first component of pixel ##
1451
1452#Example
1453#Height 64
1454#Description
1455Left bitmap is drawn with two pixels defined in half float format. Right bitmap
Cary Clark682c58d2018-05-16 07:07:07 -04001456is drawn after overwriting bottom half float color with top half float color.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001457##
Cary Clark6fc50412017-09-21 12:31:06 -04001458 SkImageInfo info = SkImageInfo::Make(1, 2, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
1459 uint16_t storage[2][4];
1460 SkPixmap pixmap(info, storage[0], sizeof(uint64_t));
1461 SkIRect topPixelBounds = {0, 0, 1, 1};
1462 pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds);
1463 SkIRect bottomPixelBounds = {0, 1, 1, 2};
1464 pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds);
1465 SkBitmap bitmap;
1466 canvas->scale(20, 20);
1467 bitmap.installPixels(pixmap);
1468 canvas->drawBitmap(bitmap, 0, 0);
1469 uint16_t* pixel2 = pixmap.writable_addrF16(0, 1);
1470 for (int i = 0; i < 4; ++i) {
1471 pixel2[i] = storage[0][i];
1472 }
1473 bitmap.installPixels(pixmap);
1474 canvas->drawBitmap(bitmap, 4, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001475##
1476
1477#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addr64 addr() addrF16
1478
1479##
1480
1481#Subtopic Writable_Address ##
1482
Cary Clark78de7512018-02-07 07:27:09 -05001483#Subtopic Pixels
1484#Populate
1485#Line # read and write pixel values ##
1486##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001487
1488# ------------------------------------------------------------------------------
1489
Cary Clarke80cd442018-07-17 13:19:56 -04001490#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05001491#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001492#Line # copies and converts pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001493
Cary Clarkd0530ba2017-09-14 11:25:39 -04001494Copies a Rect of pixels to dstPixels. Copy starts at (0, 0), and does not
Cary Clarkac47b882018-01-11 10:35:44 -05001495exceed Pixmap (width(), height()).
Cary Clark6fc50412017-09-21 12:31:06 -04001496
Cary Clark682c58d2018-05-16 07:07:07 -04001497dstInfo specifies width, height, Color_Type, Alpha_Type, and
Cary Clarkd0530ba2017-09-14 11:25:39 -04001498Color_Space of destination. dstRowBytes specifics the gap from one destination
1499row to the next. Returns true if pixels are copied. Returns false if
1500dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes.
1501
Cary Clarkac47b882018-01-11 10:35:44 -05001502Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001503kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001504If Pixmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match.
1505If Pixmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must
1506match. If Pixmap colorSpace is nullptr, dstInfo.colorSpace must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001507false if pixel conversion is not possible.
1508
Cary Clarkac47b882018-01-11 10:35:44 -05001509Returns false if Pixmap width() or height() is zero or negative.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001510
1511#Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ##
1512#Param dstPixels destination pixel storage ##
1513#Param dstRowBytes destination row length ##
1514
1515#Return true if pixels are copied to dstPixels ##
1516
1517#Example
1518#Height 128
1519#Description
1520Transferring the gradient from 8 bits per component to 4 bits per component
1521creates visible banding.
1522##
Cary Clark6fc50412017-09-21 12:31:06 -04001523 std::vector<int32_t> pixels;
1524 const int width = 256;
1525 const int height = 64;
1526 pixels.resize(height * width * 4);
1527 SkImageInfo srcInfo = SkImageInfo::MakeN32Premul(width, height);
1528 SkPixmap srcPixmap(srcInfo, (const void*) &pixels.front(), width * 4);
1529 SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 };
1530 SkPoint gradPoints[] = { { 0, 0 }, { 256, 0 } };
1531 SkPaint paint;
1532 paint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1533 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1534 SkBitmap bitmap;
1535 bitmap.installPixels(srcPixmap);
1536 SkCanvas srcCanvas(bitmap);
1537 srcCanvas.drawRect(SkRect::MakeWH(width, height), paint);
1538 canvas->drawBitmap(bitmap, 0, 0);
1539 std::vector<int32_t> dstPixels;
1540 dstPixels.resize(height * width * 2);
1541 SkImageInfo dstInfo = srcInfo.makeColorType(kARGB_4444_SkColorType);
1542 srcPixmap.readPixels(dstInfo, &dstPixels.front(), width * 2);
1543 SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2);
1544 bitmap.installPixels(dstPixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001545 canvas->drawBitmap(bitmap, 0, 128);
1546##
1547
1548#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1549
1550##
1551
1552# ------------------------------------------------------------------------------
1553
1554#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX,
Cary Clark682c58d2018-05-16 07:07:07 -04001555 int srcY) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001556
1557Copies a Rect of pixels to dstPixels. Copy starts at (srcX, srcY), and does not
Cary Clarkac47b882018-01-11 10:35:44 -05001558exceed Pixmap (width(), height()).
Cary Clark6fc50412017-09-21 12:31:06 -04001559
Cary Clark682c58d2018-05-16 07:07:07 -04001560dstInfo specifies width, height, Color_Type, Alpha_Type, and
Cary Clarkd0530ba2017-09-14 11:25:39 -04001561Color_Space of destination. dstRowBytes specifics the gap from one destination
1562row to the next. Returns true if pixels are copied. Returns false if
1563dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes.
1564
Cary Clarkac47b882018-01-11 10:35:44 -05001565Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001566kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001567If Pixmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match.
1568If Pixmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must
1569match. If Pixmap colorSpace is nullptr, dstInfo.colorSpace must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001570false if pixel conversion is not possible.
Cary Clark682c58d2018-05-16 07:07:07 -04001571
Cary Clarkd0530ba2017-09-14 11:25:39 -04001572srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clarkac47b882018-01-11 10:35:44 -05001573false if Pixmap width() or height() is zero or negative. Returns false if:
Cary Clark154beea2017-10-26 07:58:48 -04001574
Cary Clark2be81cf2018-09-13 12:04:30 -04001575#Formula # abs(srcX) >= Pixmap width() ##, or if #Formula # abs(srcY) >= Pixmap height() ##.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001576
1577#Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ##
1578#Param dstPixels destination pixel storage ##
1579#Param dstRowBytes destination row length ##
1580#Param srcX column index whose absolute value is less than width() ##
1581#Param srcY row index whose absolute value is less than height() ##
1582
1583#Return true if pixels are copied to dstPixels ##
1584
1585#Example
1586#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001587void draw(SkCanvas* canvas) {
1588 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1589 std::vector<int32_t> srcPixels;
1590 const int rowBytes = image->width() * 4;
1591 srcPixels.resize(image->height() * rowBytes);
1592 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1593 image->readPixels(pixmap, 0, 0);
1594 for (int offset : { 32, 64, 96 } ) {
1595 std::vector<int32_t> dstPixels;
1596 dstPixels.resize(image->height() * rowBytes);
1597 pixmap.readPixels(info, &dstPixels.front(), rowBytes, offset, 0);
1598 SkBitmap bitmap;
1599 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1600 bitmap.installPixels(dstmap);
1601 canvas->translate(32, 32);
1602 canvas->drawBitmap(bitmap, 0, 0);
1603 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001604}
1605##
1606
1607#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1608
1609##
1610
1611# ------------------------------------------------------------------------------
1612
Cary Clark682c58d2018-05-16 07:07:07 -04001613#Method bool readPixels(const SkPixmap& dst, int srcX, int srcY) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001614
1615Copies a Rect of pixels to dst. Copy starts at (srcX, srcY), and does not
Cary Clarkac47b882018-01-11 10:35:44 -05001616exceed Pixmap (width(), height()). dst specifies width, height, Color_Type,
Cary Clarkd0530ba2017-09-14 11:25:39 -04001617Alpha_Type, and Color_Space of destination. Returns true if pixels are copied.
1618Returns false if dst.addr() equals nullptr, or dst.rowBytes is less than
1619dst SkImageInfo::minRowBytes.
1620
Cary Clarkac47b882018-01-11 10:35:44 -05001621Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001622kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.info().colorType must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001623If Pixmap colorType is kGray_8_SkColorType, dst.info().colorSpace must match.
1624If Pixmap alphaType is kOpaque_SkAlphaType, dst.info().alphaType must
1625match. If Pixmap colorSpace is nullptr, dst.info().colorSpace must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001626false if pixel conversion is not possible.
Cary Clark682c58d2018-05-16 07:07:07 -04001627
Cary Clarkd0530ba2017-09-14 11:25:39 -04001628srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clarkac47b882018-01-11 10:35:44 -05001629false Pixmap width() or height() is zero or negative. Returns false if:
Cary Clark154beea2017-10-26 07:58:48 -04001630
Cary Clark2be81cf2018-09-13 12:04:30 -04001631#Formula # abs(srcX) >= Pixmap width() ##, or if #Formula # abs(srcY) >= Pixmap height() ##.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001632
1633#Param dst Image_Info and pixel address to write to ##
1634#Param srcX column index whose absolute value is less than width() ##
1635#Param srcY row index whose absolute value is less than height() ##
1636
1637#Return true if pixels are copied to dst ##
1638
1639#Example
1640#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001641void draw(SkCanvas* canvas) {
1642 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1643 std::vector<int32_t> srcPixels;
1644 const int rowBytes = image->width() * 4;
1645 srcPixels.resize(image->height() * rowBytes);
1646 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1647 image->readPixels(pixmap, 0, 0);
1648 for (int offset : { 32, 64, 96 } ) {
1649 std::vector<int32_t> dstPixels;
1650 dstPixels.resize(image->height() * rowBytes);
1651 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1652 pixmap.readPixels(dstmap, offset, 0);
1653 SkBitmap bitmap;
1654 bitmap.installPixels(dstmap);
1655 canvas->translate(32, 32);
1656 canvas->drawBitmap(bitmap, 0, 0);
1657 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001658}
1659##
1660
1661#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1662
1663##
1664
1665# ------------------------------------------------------------------------------
1666
Cary Clark682c58d2018-05-16 07:07:07 -04001667#Method bool readPixels(const SkPixmap& dst) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001668
1669Copies pixels inside bounds() to dst. dst specifies width, height, Color_Type,
1670Alpha_Type, and Color_Space of destination. Returns true if pixels are copied.
1671Returns false if dst.addr() equals nullptr, or dst.rowBytes is less than
1672dst SkImageInfo::minRowBytes.
1673
Cary Clarkac47b882018-01-11 10:35:44 -05001674Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001675kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001676If Pixmap colorType is kGray_8_SkColorType, dst Color_Space must match.
1677If Pixmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must
1678match. If Pixmap colorSpace is nullptr, dst Color_Space must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001679false if pixel conversion is not possible.
Cary Clark682c58d2018-05-16 07:07:07 -04001680
Cary Clarkac47b882018-01-11 10:35:44 -05001681Returns false if Pixmap width() or height() is zero or negative.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001682
1683#Param dst Image_Info and pixel address to write to ##
1684
1685#Return true if pixels are copied to dst ##
1686
1687#Example
1688#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001689void draw(SkCanvas* canvas) {
1690 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1691 std::vector<int32_t> srcPixels;
1692 const int rowBytes = image->width() * 4;
1693 srcPixels.resize(image->height() * rowBytes);
1694 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1695 image->readPixels(pixmap, 0, 0);
1696 for (int index = 0; index < 3; ++index ) {
1697 std::vector<int32_t> dstPixels;
1698 dstPixels.resize(image->height() * rowBytes);
1699 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1700 pixmap.readPixels(dstmap);
1701 SkBitmap bitmap;
1702 bitmap.installPixels(dstmap);
1703 canvas->translate(32, 32);
1704 canvas->drawBitmap(bitmap, 0, 0);
1705 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001706}
1707##
1708
1709#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1710
1711##
1712
1713# ------------------------------------------------------------------------------
1714
1715#Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality) const
1716
Cary Clark78de7512018-02-07 07:27:09 -05001717#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001718#Line # scales and converts pixels ##
Cary Clarkac47b882018-01-11 10:35:44 -05001719Copies Bitmap to dst, scaling pixels to fit dst.width() and dst.height(), and
Cary Clarkd0530ba2017-09-14 11:25:39 -04001720converting pixels to match dst.colorType and dst.alphaType. Returns true if
1721pixels are copied. Returns false if dst.addr() is nullptr, or dst.rowBytes is
1722less than dst SkImageInfo::minRowBytes.
1723
Cary Clarkac47b882018-01-11 10:35:44 -05001724Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001725kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001726If Pixmap colorType is kGray_8_SkColorType, dst Color_Space must match.
1727If Pixmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must
1728match. If Pixmap colorSpace is nullptr, dst Color_Space must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001729false if pixel conversion is not possible.
1730
Cary Clarkac47b882018-01-11 10:35:44 -05001731Returns false if Bitmap width() or height() is zero or negative.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001732
1733Scales the image, with filterQuality, to match dst.width() and dst.height().
1734filterQuality kNone_SkFilterQuality is fastest, typically implemented with
1735Filter_Quality_Nearest_Neighbor. kLow_SkFilterQuality is typically implemented with
1736Filter_Quality_Bilerp. kMedium_SkFilterQuality is typically implemented with
1737Filter_Quality_Bilerp, and Filter_Quality_MipMap when size is reduced.
1738kHigh_SkFilterQuality is slowest, typically implemented with Filter_Quality_BiCubic.
1739
1740#Param dst Image_Info and pixel address to write to ##
Cary Clark682c58d2018-05-16 07:07:07 -04001741#Param filterQuality one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
Cary Clarkd0530ba2017-09-14 11:25:39 -04001742 kMedium_SkFilterQuality, kHigh_SkFilterQuality
1743##
1744
Cary Clarkac47b882018-01-11 10:35:44 -05001745#Return true if pixels are scaled to fit dst ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001746
1747#Example
1748#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001749void draw(SkCanvas* canvas) {
1750 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1751 std::vector<int32_t> srcPixels;
1752 int rowBytes = image->width() * 4;
1753 srcPixels.resize(image->height() * rowBytes);
1754 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1755 image->readPixels(pixmap, 0, 0);
1756 for (int offset : { 32, 64, 96 } ) {
1757 info = SkImageInfo::MakeN32Premul(image->width() + offset, image->height());
1758 rowBytes = info.width() * 4;
1759 std::vector<int32_t> dstPixels;
1760 dstPixels.resize(image->height() * rowBytes);
1761 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1762 pixmap.scalePixels(dstmap, kMedium_SkFilterQuality);
1763 SkBitmap bitmap;
1764 bitmap.installPixels(dstmap);
1765 canvas->translate(32, 32);
1766 canvas->drawBitmap(bitmap, 0, 0);
1767 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001768}
1769##
1770
1771#SeeAlso SkCanvas::drawBitmap SkImage::scalePixels
1772
1773##
1774
1775# ------------------------------------------------------------------------------
1776
1777#Method bool erase(SkColor color, const SkIRect& subset) const
1778
Cary Clark78de7512018-02-07 07:27:09 -05001779#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001780#Line # writes Color to pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001781Writes color to pixels bounded by subset; returns true on success.
1782Returns false if colorType is kUnknown_SkColorType, or if subset does
1783not intersect bounds().
Cary Clark682c58d2018-05-16 07:07:07 -04001784
Cary Clarkd0530ba2017-09-14 11:25:39 -04001785#Param color Unpremultiplied Color to write ##
1786#Param subset bounding integer Rect of written pixels ##
1787
1788#Return true if pixels are changed ##
1789
1790#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001791#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001792 uint32_t storage[2];
1793 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1794 SkPixmap pixmap(info, storage, info.minRowBytes());
1795 pixmap.erase(SK_ColorBLUE, {0, 0, 1, 1});
1796 pixmap.erase(SK_ColorRED, {0, 1, 1, 2});
1797 SkBitmap bitmap;
1798 canvas->scale(20, 20);
1799 bitmap.installPixels(pixmap);
1800 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001801##
1802
1803#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1804
1805##
1806
1807# ------------------------------------------------------------------------------
1808
Cary Clark682c58d2018-05-16 07:07:07 -04001809#Method bool erase(SkColor color) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001810
1811Writes color to pixels inside bounds(); returns true on success.
1812Returns false if colorType is kUnknown_SkColorType, or if bounds()
1813is empty.
1814
1815#Param color Unpremultiplied Color to write ##
1816
1817#Return true if pixels are changed ##
1818
1819#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001820#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001821 uint32_t storage[2];
1822 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1823 SkPixmap pixmap(info, storage, info.minRowBytes());
1824 pixmap.erase(SK_ColorBLUE);
1825 SkBitmap bitmap;
1826 canvas->scale(20, 20);
1827 bitmap.installPixels(pixmap);
1828 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001829##
1830
1831#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1832
1833##
1834
1835# ------------------------------------------------------------------------------
1836
1837#Method bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const
1838
1839Writes color to pixels bounded by subset; returns true on success.
1840if subset is nullptr, writes colors pixels inside bounds(). Returns false if
1841colorType is kUnknown_SkColorType, if subset is not nullptr and does
1842not intersect bounds(), or if subset is nullptr and bounds() is empty.
1843
1844#Param color Unpremultiplied Color to write ##
1845#Param subset bounding integer Rect of pixels to write; may be nullptr ##
1846
1847#Return true if pixels are changed ##
1848
1849#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001850#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001851 uint32_t storage[2];
1852 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1853 SkPixmap pixmap(info, storage, info.minRowBytes());
1854 SkIRect topPixelBounds = {0, 0, 1, 1};
1855 pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds);
1856 SkIRect bottomPixelBounds = {0, 1, 1, 2};
1857 pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds);
1858 SkBitmap bitmap;
1859 canvas->scale(20, 20);
1860 bitmap.installPixels(pixmap);
1861 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001862##
1863
1864#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1865
1866##
1867
Cary Clarkd0530ba2017-09-14 11:25:39 -04001868#Class SkPixmap ##
1869
1870#Topic Pixmap ##