blob: 051a6a1f83f5d98c183df670941824ccdb087ead [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 Clark682c58d2018-05-16 07:07:07 -0400325is at least as large as:
Cary Clarkd0530ba2017-09-14 11:25:39 -0400326#Formula
327width() * info().bytesPerPixel()
328##
329.
330
Cary Clarkbc5697d2017-10-04 14:31:33 -0400331Returns zero if colorType is kUnknown_SkColorType.
332It is up to the Bitmap creator to ensure that row bytes is a useful value.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400333
334#Return byte length of pixel row ##
335
336#Example
337SkPixmap badPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 2};
338SkPixmap okPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 8};
339for (auto& pixmap : { badPixmap, okPixmap } ) {
Cary Clark682c58d2018-05-16 07:07:07 -0400340 SkDebugf("rowBytes: %d minRowBytes: %d\n", pixmap.rowBytes(),
Cary Clarkd0530ba2017-09-14 11:25:39 -0400341 pixmap.info().minRowBytes());
342}
343#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400344rowBytes: 2 minRowBytes: 4
Cary Clarkd0530ba2017-09-14 11:25:39 -0400345rowBytes: 8 minRowBytes: 4
346##
347##
348
349#SeeAlso addr() info() SkImageInfo::minRowBytes
350
351##
352
353# ------------------------------------------------------------------------------
354
Cary Clark682c58d2018-05-16 07:07:07 -0400355#Method const void* addr() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400356
Cary Clarkab2621d2018-01-30 10:08:57 -0500357#In Image_Info_Access
358#Line # returns readable pixel address as void pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -0400359Returns pixel address, the base address corresponding to the pixel origin.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400360
361It is up to the Pixmap creator to ensure that pixel address is a useful value.
362
363#Return pixel address ##
364
365#Example
366#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -0400367 std::vector<int32_t> pixels;
368 pixels.resize(image->height() * image->width() * 4);
369 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
370 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
371 image->readPixels(pixmap, 0, 0);
372 SkDebugf("pixels address: 0x%llx\n", pixmap.addr());
373 SkPixmap inset;
374 if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) {
375 SkDebugf("inset address: 0x%llx\n", inset.addr());
376 }
377#StdOut
378#Volatile
379pixels address: 0x7f2a440bb010
380inset address: 0x7f2a440fb210
381##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400382##
383
384#SeeAlso addr(int x, int y) addr8 addr16 addr32 addr64 info() rowBytes()
385
386##
387
388# ------------------------------------------------------------------------------
389
Cary Clark682c58d2018-05-16 07:07:07 -0400390#Method int width() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400391
Cary Clarkab2621d2018-01-30 10:08:57 -0500392#In Image_Info_Access
393#Line # returns pixel column count ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400394Returns pixel count in each pixel row. Should be equal or less than:
Cary Clark154beea2017-10-26 07:58:48 -0400395
Cary Clarkd0530ba2017-09-14 11:25:39 -0400396#Formula
Cary Clarkbc5697d2017-10-04 14:31:33 -0400397rowBytes() / info().bytesPerPixel()
Cary Clarkd0530ba2017-09-14 11:25:39 -0400398##
Cary Clark682c58d2018-05-16 07:07:07 -0400399.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400400
401#Return pixel width in Image_Info ##
402
403#Example
404 SkImageInfo info = SkImageInfo::MakeA8(16, 32);
Cary Clark6fc50412017-09-21 12:31:06 -0400405 SkPixmap pixmap(info, nullptr, 64);
406 SkDebugf("pixmap width: %d info width: %d\n", pixmap.width(), info.width());
407#StdOut
408pixmap width: 16 info width: 16
409##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400410##
411
Cary Clarkbc5697d2017-10-04 14:31:33 -0400412#SeeAlso height() SkImageInfo::width()
Cary Clarkd0530ba2017-09-14 11:25:39 -0400413
414##
415
416# ------------------------------------------------------------------------------
417
Cary Clark682c58d2018-05-16 07:07:07 -0400418#Method int height() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400419
Cary Clarkab2621d2018-01-30 10:08:57 -0500420#In Image_Info_Access
421#Line # returns pixel row count ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400422Returns pixel row count.
423
424#Return pixel height in Image_Info ##
425
426#Example
Cary Clarkbc5697d2017-10-04 14:31:33 -0400427 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
428 SkDebugf("pixmap height: %d info height: %d\n", pixmap.height(), pixmap.info().height());
Cary Clark6fc50412017-09-21 12:31:06 -0400429#StdOut
430pixmap height: 32 info height: 32
431##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400432##
433
Cary Clarkbc5697d2017-10-04 14:31:33 -0400434#SeeAlso width() ImageInfo::height()
Cary Clarkd0530ba2017-09-14 11:25:39 -0400435
436##
437
438# ------------------------------------------------------------------------------
439
Cary Clark682c58d2018-05-16 07:07:07 -0400440#Method SkColorType colorType() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400441
Cary Clarkab2621d2018-01-30 10:08:57 -0500442#In Image_Info_Access
443#Line # returns Image_Info Color_Type ##
Cary Clark1a8d7622018-03-05 13:26:16 -0500444Returns Color_Type, one of: #list_of_color_types#.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400445
446#Return Color_Type in Image_Info ##
447
448#Example
Cary Clarkab2621d2018-01-30 10:08:57 -0500449 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
450 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -0400451 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
452 SkDebugf("color type: k" "%s" "_SkColorType\n", colors[pixmap.colorType()]);
453#StdOut
Cary Clarkab2621d2018-01-30 10:08:57 -0500454color type: kAlpha_8_SkColorType
Cary Clark6fc50412017-09-21 12:31:06 -0400455##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400456##
457
Cary Clarkbc5697d2017-10-04 14:31:33 -0400458#SeeAlso alphaType() SkImageInfo::colorType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400459
460##
461
462# ------------------------------------------------------------------------------
463
Cary Clark682c58d2018-05-16 07:07:07 -0400464#Method SkAlphaType alphaType() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400465
Cary Clarkab2621d2018-01-30 10:08:57 -0500466#In Image_Info_Access
467#Line # returns Image_Info Alpha_Type ##
Cary Clark681287e2018-03-16 11:34:15 -0400468Returns Alpha_Type, one of: #list_of_alpha_types#.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400469
470#Return Alpha_Type in Image_Info ##
471
472#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400473 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
474 SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
475 SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[pixmap.alphaType()]);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400476#StdOut
477alpha type: kPremul_SkAlphaType
478##
479##
480
Cary Clarkbc5697d2017-10-04 14:31:33 -0400481#SeeAlso colorType() SkImageInfo::alphaType
Cary Clarkd0530ba2017-09-14 11:25:39 -0400482
483##
484
485# ------------------------------------------------------------------------------
486
Cary Clark682c58d2018-05-16 07:07:07 -0400487#Method SkColorSpace* colorSpace() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400488
Cary Clarkab2621d2018-01-30 10:08:57 -0500489#In Image_Info_Access
490#Line # returns Image_Info Color_Space ##
Cary Clark681287e2018-03-16 11:34:15 -0400491Returns Color_Space, the range of colors, associated with Image_Info. The
Cary Clarkbc5697d2017-10-04 14:31:33 -0400492reference count of Color_Space is unchanged. The returned Color_Space is
493immutable.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400494
Cary Clark681287e2018-03-16 11:34:15 -0400495#Return Color_Space in Image_Info, or nullptr ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400496
497#Example
498#Description
499SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma
500and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma.
501##
Cary Clark682c58d2018-05-16 07:07:07 -0400502 SkPixmap pixmap(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
Cary Clark6fc50412017-09-21 12:31:06 -0400503 SkColorSpace::MakeSRGBLinear()), nullptr, 64);
504 SkColorSpace* colorSpace = pixmap.colorSpace();
505 SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
506 colorSpace->gammaCloseToSRGB() ? "true" : "false",
507 colorSpace->gammaIsLinear() ? "true" : "false",
508 colorSpace->isSRGB() ? "true" : "false");
509#StdOut
510gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
511##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400512##
513
Cary Clarkbc5697d2017-10-04 14:31:33 -0400514#SeeAlso Color_Space SkImageInfo::colorSpace
Cary Clarkd0530ba2017-09-14 11:25:39 -0400515
516##
517
518# ------------------------------------------------------------------------------
519
Cary Clark682c58d2018-05-16 07:07:07 -0400520#Method bool isOpaque() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400521
Cary Clarkab2621d2018-01-30 10:08:57 -0500522#In Image_Info_Access
523#Line # returns true if Image_Info describes opaque pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400524Returns true if Alpha_Type is kOpaque_SkAlphaType.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400525Does not check if Color_Type allows Alpha, or if any pixel value has
526transparency.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400527
528#Return true if Image_Info has opaque Alpha_Type ##
529
530#Example
531#Description
532 isOpaque ignores whether all pixels are opaque or not.
533##
Cary Clark6fc50412017-09-21 12:31:06 -0400534 std::vector<uint32_t> pixels;
535 const int height = 2;
536 const int width = 2;
537 pixels.resize(height * width * 4);
538 SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType,
539 kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4);
540 for (int index = 0; index < 2; ++index) {
541 pixmap.erase(0x00000000);
542 SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false");
543 pixmap.erase(0xFFFFFFFF);
544 SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false");
545 pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType),
546 (const void*) &pixels.front(), width * 4);
547 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400548#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400549isOpaque: false
550isOpaque: false
551isOpaque: true
Cary Clarkd0530ba2017-09-14 11:25:39 -0400552isOpaque: true
553##
554##
555
556#SeeAlso computeIsOpaque SkImageInfo::isOpaque
557
558##
559
560# ------------------------------------------------------------------------------
561
Cary Clark682c58d2018-05-16 07:07:07 -0400562#Method SkIRect bounds() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400563
Cary Clarkab2621d2018-01-30 10:08:57 -0500564#In Image_Info_Access
565#Line # returns width and height as Rectangle ##
Cary Clark154beea2017-10-26 07:58:48 -0400566Returns IRect { 0, 0, width(), height() }.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400567
568#Return integral rectangle from origin to width() and height() ##
569
570#Example
571 for (int width : { 0, 2 } ) {
572 for (int height : { 0, 2 } ) {
Cary Clark6fc50412017-09-21 12:31:06 -0400573 SkPixmap pixmap(SkImageInfo::MakeA8(width, height), nullptr, width);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400574 SkDebugf("width: %d height: %d empty: %s\n", width, height,
575 pixmap.bounds().isEmpty() ? "true" : "false");
576 }
577 }
578#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400579width: 0 height: 0 empty: true
580width: 0 height: 2 empty: true
581width: 2 height: 0 empty: true
Cary Clarkd0530ba2017-09-14 11:25:39 -0400582width: 2 height: 2 empty: false
583##
584##
585
Cary Clark682c58d2018-05-16 07:07:07 -0400586#SeeAlso height() width() IRect
Cary Clarkd0530ba2017-09-14 11:25:39 -0400587
588##
589
590# ------------------------------------------------------------------------------
591
Cary Clark682c58d2018-05-16 07:07:07 -0400592#Method int rowBytesAsPixels() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400593
Cary Clarkab2621d2018-01-30 10:08:57 -0500594#In Image_Info_Access
595#Line # returns interval between rows in pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400596
597Returns number of pixels that fit on row. Should be greater than or equal to
598width().
599
600#Return maximum pixels per row ##
601
602#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400603 for (int rowBytes : { 4, 5, 6, 7, 8} ) {
604 SkPixmap pixmap(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), nullptr, rowBytes);
605 SkDebugf("rowBytes: %d rowBytesAsPixels: %d\n", rowBytes, pixmap.rowBytesAsPixels());
606 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400607#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400608rowBytes: 4 rowBytesAsPixels: 1
609rowBytes: 5 rowBytesAsPixels: 1
610rowBytes: 6 rowBytesAsPixels: 1
611rowBytes: 7 rowBytesAsPixels: 1
Cary Clarkd0530ba2017-09-14 11:25:39 -0400612rowBytes: 8 rowBytesAsPixels: 2
613##
614##
615
616#SeeAlso rowBytes shiftPerPixel width SkImageInfo::bytesPerPixel
617
618##
619
620# ------------------------------------------------------------------------------
621
Cary Clark682c58d2018-05-16 07:07:07 -0400622#Method int shiftPerPixel() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400623
Cary Clarkab2621d2018-01-30 10:08:57 -0500624#In Image_Info_Access
625#Line # returns bit shift from pixels to bytes ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400626Returns bit shift converting row bytes to row pixels.
627Returns zero for kUnknown_SkColorType.
628
629#Return one of: 0, 1, 2, 3; left shift to convert pixels to bytes ##
630
631#Example
Cary Clarkab2621d2018-01-30 10:08:57 -0500632 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
633 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
Cary Clark6fc50412017-09-21 12:31:06 -0400634 SkImageInfo info = SkImageInfo::MakeA8(1, 1);
635 for (SkColorType colorType : { kUnknown_SkColorType, kAlpha_8_SkColorType,
Cary Clark682c58d2018-05-16 07:07:07 -0400636 kRGB_565_SkColorType, kARGB_4444_SkColorType,
Cary Clark6fc50412017-09-21 12:31:06 -0400637 kRGBA_8888_SkColorType, kBGRA_8888_SkColorType,
638 kGray_8_SkColorType, kRGBA_F16_SkColorType } ) {
639 SkPixmap pixmap(info.makeColorType(colorType), nullptr, 4);
640 SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d shiftPerPixel: %d\n",
641 colors[colorType], 10 - strlen(colors[colorType]), " ",
642 pixmap.info().bytesPerPixel(), pixmap.shiftPerPixel());
643 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400644#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400645color: kUnknown_SkColorType bytesPerPixel: 0 shiftPerPixel: 0
Cary Clarkab2621d2018-01-30 10:08:57 -0500646color: kAlpha_8_SkColorType bytesPerPixel: 1 shiftPerPixel: 0
Cary Clark6fc50412017-09-21 12:31:06 -0400647color: kRGB_565_SkColorType bytesPerPixel: 2 shiftPerPixel: 1
648color: kARGB_4444_SkColorType bytesPerPixel: 2 shiftPerPixel: 1
649color: kRGBA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2
650color: kBGRA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2
651color: kGray_8_SkColorType bytesPerPixel: 1 shiftPerPixel: 0
Cary Clarkd0530ba2017-09-14 11:25:39 -0400652color: kRGBA_F16_SkColorType bytesPerPixel: 8 shiftPerPixel: 3
653##
654##
655
656#SeeAlso rowBytes rowBytesAsPixels width SkImageInfo::bytesPerPixel
657
658##
659
660# ------------------------------------------------------------------------------
661
Cary Clarkbc5697d2017-10-04 14:31:33 -0400662#Method size_t computeByteSize() const
663
Cary Clarkab2621d2018-01-30 10:08:57 -0500664#In Image_Info_Access
665#Line # returns size required for pixels ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400666Returns minimum memory required for pixel storage.
667Does not include unused memory on last row when rowBytesAsPixels exceeds width().
668Returns zero if result does not fit in size_t.
669Returns zero if height() or width() is 0.
670Returns height() times rowBytes if colorType is kUnknown_SkColorType.
671
672#Return size in bytes of image buffer ##
673
Cary Clarkd0530ba2017-09-14 11:25:39 -0400674#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400675 SkPixmap pixmap;
676 for (int width : { 1, 1000, 1000000 } ) {
677 for (int height: { 1, 1000, 1000000 } ) {
678 SkImageInfo imageInfo = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType);
Cary Clarkbc5697d2017-10-04 14:31:33 -0400679 pixmap.reset(imageInfo, nullptr, width * 5);
680 SkDebugf("width: %7d height: %7d computeByteSize: %13lld\n", width, height,
681 pixmap.computeByteSize());
Cary Clark6fc50412017-09-21 12:31:06 -0400682 }
683 }
Cary Clark6fc50412017-09-21 12:31:06 -0400684#StdOut
Ben Wagner29380bd2017-10-09 14:43:00 -0400685width: 1 height: 1 computeByteSize: 4
686width: 1 height: 1000 computeByteSize: 4999
687width: 1 height: 1000000 computeByteSize: 4999999
688width: 1000 height: 1 computeByteSize: 4000
689width: 1000 height: 1000 computeByteSize: 4999000
690width: 1000 height: 1000000 computeByteSize: 4999999000
691width: 1000000 height: 1 computeByteSize: 4000000
692width: 1000000 height: 1000 computeByteSize: 4999000000
Cary Clarkbc5697d2017-10-04 14:31:33 -0400693width: 1000000 height: 1000000 computeByteSize: 4999999000000
Cary Clarkd0530ba2017-09-14 11:25:39 -0400694##
695##
696
Cary Clarkbc5697d2017-10-04 14:31:33 -0400697#SeeAlso SkImageInfo::computeByteSize
Cary Clarkd0530ba2017-09-14 11:25:39 -0400698
699##
700
701#Subtopic Image_Info_Access ##
702
703#Subtopic Reader
Cary Clark08895c42018-02-01 09:37:32 -0500704#Line # examine pixel value ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400705
706# ------------------------------------------------------------------------------
707
708#Method bool computeIsOpaque() const
709
Cary Clarkab2621d2018-01-30 10:08:57 -0500710#In Reader
711#Line # returns true if all pixels are opaque ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400712Returns true if all pixels are opaque. Color_Type determines how pixels
713are encoded, and whether pixel describes Alpha. Returns true for Color_Types
Cary Clark6fc50412017-09-21 12:31:06 -0400714without alpha in each pixel; for other Color_Types, returns true if all
Cary Clarkd0530ba2017-09-14 11:25:39 -0400715pixels have alpha values equivalent to 1.0 or greater.
716
717For Color_Types kRGB_565_SkColorType or kGray_8_SkColorType: always
718returns true. For Color_Types kAlpha_8_SkColorType, kBGRA_8888_SkColorType,
719kRGBA_8888_SkColorType: returns true if all pixel Alpha values are 255.
720For Color_Type kARGB_4444_SkColorType: returns true if all pixel Alpha values are 15.
721For kRGBA_F16_SkColorType: returns true if all pixel Alpha values are 1.0 or
722greater.
723
Cary Clark682c58d2018-05-16 07:07:07 -0400724Returns false for kUnknown_SkColorType.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400725
Cary Clarkbc5697d2017-10-04 14:31:33 -0400726#Return true if all pixels have opaque values or Color_Type is opaque ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400727
728#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400729 std::vector<uint32_t> pixels;
730 const int height = 2;
731 const int width = 2;
732 pixels.resize(height * width * 4);
733 SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType,
734 kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4);
735 for (int index = 0; index < 2; ++index) {
736 pixmap.erase(0x00000000);
737 SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false");
738 pixmap.erase(0xFFFFFFFF);
739 SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false");
740 pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType),
741 (const void*) &pixels.front(), width * 4);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400742 }
743#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400744computeIsOpaque: false
745computeIsOpaque: true
746computeIsOpaque: false
Cary Clarkd0530ba2017-09-14 11:25:39 -0400747computeIsOpaque: true
748##
749##
750
751#SeeAlso isOpaque Color_Type Alpha
752
753##
754
755# ------------------------------------------------------------------------------
756
757#Method SkColor getColor(int x, int y) const
758
Cary Clarkab2621d2018-01-30 10:08:57 -0500759#In Reader
760#Line # returns one pixel as Unpremultiplied Color ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400761Returns pixel at (x, y) as Unpremultiplied Color.
762Returns black with Alpha if Color_Type is kAlpha_8_SkColorType.
763
764Input is not validated: out of bounds values of x or y trigger an assert() if
765built with SK_DEBUG defined; and returns undefined values or may crash if
766SK_RELEASE is defined. Fails if Color_Type is kUnknown_SkColorType or
767pixel address is nullptr.
768
769Color_Space in Image_Info is ignored. Some Color precision may be lost in the
Cary Clark682c58d2018-05-16 07:07:07 -0400770conversion to Unpremultiplied Color; original pixel data may have additional
Cary Clarkd0530ba2017-09-14 11:25:39 -0400771precision.
772
Cary Clark6fc50412017-09-21 12:31:06 -0400773#Param x column index, zero or greater, and less than width() ##
774#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400775
776#Return pixel converted to Unpremultiplied Color ##
777
778#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400779 const int w = 4;
780 const int h = 4;
781 std::vector<SkPMColor> storage;
782 storage.resize(w * h);
783 SkDebugf("Premultiplied:\n");
784 for (int y = 0; y < h; ++y) {
785 SkDebugf("(0, %d) ", y);
786 for (int x = 0; x < w; ++x) {
787 int a = 0xFF * (x + y) / (w - 1 + h - 1);
788 storage[x + y * w] = SkPackARGB32(a, a * x / (w - 1), a * y / (h - 1), a);
789 SkDebugf("0x%08x%c", storage[x + y * w], x == w - 1 ? '\n' : ' ');
790 }
791 }
792 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4);
793 SkDebugf("Unpremultiplied:\n");
794 for (int y = 0; y < h; ++y) {
795 SkDebugf("(0, %d) ", y);
796 for (int x = 0; x < w; ++x) {
797 SkDebugf("0x%08x%c", pixmap.getColor(x, y), x == w - 1 ? '\n' : ' ');
798 }
799 }
Cary Clarkd0530ba2017-09-14 11:25:39 -0400800#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -0400801Premultiplied:
Cary Clark682c58d2018-05-16 07:07:07 -0400802(0, 0) 0x00000000 0x2a0e002a 0x55380055 0x7f7f007f
803(0, 1) 0x2a000e2a 0x551c1c55 0x7f542a7f 0xaaaa38aa
804(0, 2) 0x55003855 0x7f2a547f 0xaa7171aa 0xd4d48dd4
805(0, 3) 0x7f007f7f 0xaa38aaaa 0xd48dd4d4 0xffffffff
Cary Clark6fc50412017-09-21 12:31:06 -0400806Unpremultiplied:
Cary Clark682c58d2018-05-16 07:07:07 -0400807(0, 0) 0x00000000 0x2a5500ff 0x55a800ff 0x7fff00ff
808(0, 1) 0x2a0055ff 0x555454ff 0x7fa954ff 0xaaff54ff
809(0, 2) 0x5500a8ff 0x7f54a9ff 0xaaaaaaff 0xd4ffaaff
810(0, 3) 0x7f00ffff 0xaa54ffff 0xd4aaffff 0xffffffff
Cary Clarkd0530ba2017-09-14 11:25:39 -0400811##
812##
813
814#SeeAlso addr() readPixels
815
816##
817
818#Subtopic Reader ##
819
820#Subtopic Readable_Address
Cary Clark08895c42018-02-01 09:37:32 -0500821#Line # returns read only pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400822
823# ------------------------------------------------------------------------------
824
825#Method const void* addr(int x, int y) const
826
Cary Clarkab2621d2018-01-30 10:08:57 -0500827#In Readable_Address
Cary Clarkbc5697d2017-10-04 14:31:33 -0400828Returns readable pixel address at (x, y). Returns nullptr if Pixel_Ref is nullptr.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400829
830Input is not validated: out of bounds values of x or y trigger an assert() if
Cary Clarkbc5697d2017-10-04 14:31:33 -0400831built with SK_DEBUG defined. Returns nullptr if Color_Type is kUnknown_SkColorType.
832
Cary Clark682c58d2018-05-16 07:07:07 -0400833Performs a lookup of pixel size; for better performance, call
Cary Clarkbc5697d2017-10-04 14:31:33 -0400834one of: addr8, addr16, addr32, addr64, or addrF16.
Cary Clarkd0530ba2017-09-14 11:25:39 -0400835
Cary Clark6fc50412017-09-21 12:31:06 -0400836#Param x column index, zero or greater, and less than width() ##
837#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400838
839#Return readable generic pointer to pixel ##
840
841#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400842 const int w = 4;
843 const int h = 4;
844 std::vector<SkPMColor> storage;
845 storage.resize(w * h);
846 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4);
Cary Clarkd0530ba2017-09-14 11:25:39 -0400847 SkDebugf("pixmap.addr(1, 2) %c= &storage[1 + 2 * w]\n",
848 pixmap.addr(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
849#StdOut
850pixmap.addr(1, 2) == &storage[1 + 2 * w]
851##
852##
853
Cary Clarkbc5697d2017-10-04 14:31:33 -0400854#SeeAlso addr8 addr16 addr32 addr64 addrF16 getColor writable_addr SkBitmap::getAddr
Cary Clarkd0530ba2017-09-14 11:25:39 -0400855
856##
857
858# ------------------------------------------------------------------------------
859
Cary Clark682c58d2018-05-16 07:07:07 -0400860#Method const uint8_t* addr8() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400861
Cary Clarkab2621d2018-01-30 10:08:57 -0500862#In Readable_Address
863#Line # returns readable pixel address as 8-bit pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400864Returns readable base pixel address. Result is addressable as unsigned 8-bit bytes.
865Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType or
866kGray_8_SkColorType, and is built with SK_DEBUG defined.
867
868One byte corresponds to one pixel.
869
870#Return readable unsigned 8-bit pointer to pixels ##
871
872#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400873 const int w = 4;
874 const int h = 4;
875 uint8_t storage[w * h];
876 SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType),
877 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400878 SkDebugf("pixmap.addr8() %c= storage\n",
879 pixmap.addr8() == storage ? '=' : '!');
880#StdOut
881pixmap.addr8() == storage
882##
883##
884
885#SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8
886
887##
888
889# ------------------------------------------------------------------------------
890
Cary Clark682c58d2018-05-16 07:07:07 -0400891#Method const uint16_t* addr16() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400892
Cary Clarkab2621d2018-01-30 10:08:57 -0500893#In Readable_Address
894#Line # returns readable pixel address as 16-bit pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400895Returns readable base pixel address. Result is addressable as unsigned 16-bit words.
896Will trigger an assert() if Color_Type is not kRGB_565_SkColorType or
897kARGB_4444_SkColorType, and is built with SK_DEBUG defined.
898
899One word corresponds to one pixel.
900
901#Return readable unsigned 16-bit pointer to pixels ##
902
903#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400904 const int w = 4;
905 const int h = 4;
906 uint16_t storage[w * h];
907 SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType),
908 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400909 SkDebugf("pixmap.addr16() %c= storage\n",
910 pixmap.addr16() == storage ? '=' : '!');
911#StdOut
912pixmap.addr16() == storage
913##
914##
915
916#SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16
917
918##
919
920# ------------------------------------------------------------------------------
921
Cary Clark682c58d2018-05-16 07:07:07 -0400922#Method const uint32_t* addr32() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400923
Cary Clarkab2621d2018-01-30 10:08:57 -0500924#In Readable_Address
925#Line # returns readable pixel address as 32-bit pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400926Returns readable base pixel address. Result is addressable as unsigned 32-bit words.
927Will trigger an assert() if Color_Type is not kRGBA_8888_SkColorType or
928kBGRA_8888_SkColorType, and is built with SK_DEBUG defined.
929
930One word corresponds to one pixel.
931
932#Return readable unsigned 32-bit pointer to pixels ##
933
934#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400935 const int w = 4;
936 const int h = 4;
937 uint32_t storage[w * h];
938 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType),
939 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400940 SkDebugf("pixmap.addr32() %c= storage\n",
941 pixmap.addr32() == storage ? '=' : '!');
942#StdOut
943pixmap.addr32() == storage
944##
945##
946
947#SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr32
948
949##
950
951# ------------------------------------------------------------------------------
952
Cary Clark682c58d2018-05-16 07:07:07 -0400953#Method const uint64_t* addr64() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400954
Cary Clarkab2621d2018-01-30 10:08:57 -0500955#In Readable_Address
956#Line # returns readable pixel address as 64-bit pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400957Returns readable base pixel address. Result is addressable as unsigned 64-bit words.
958Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
959with SK_DEBUG defined.
960
961One word corresponds to one pixel.
962
963#Return readable unsigned 64-bit pointer to pixels ##
964
965#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400966 const int w = 4;
967 const int h = 4;
968 uint64_t storage[w * h];
969 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
970 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -0400971 SkDebugf("pixmap.addr64() %c= storage\n",
972 pixmap.addr64() == storage ? '=' : '!');
973#StdOut
974pixmap.addr64() == storage
975##
976##
977
978#SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64
979
980##
981
982# ------------------------------------------------------------------------------
983
Cary Clark682c58d2018-05-16 07:07:07 -0400984#Method const uint16_t* addrF16() const
Cary Clarkd0530ba2017-09-14 11:25:39 -0400985
Cary Clarkab2621d2018-01-30 10:08:57 -0500986#In Readable_Address
987#Line # returns readable pixel component address as 16-bit pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -0400988Returns readable base pixel address. Result is addressable as unsigned 16-bit words.
989Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
990with SK_DEBUG defined.
991
992Each word represents one color component encoded as a half float.
993Four words correspond to one pixel.
994
995#Return readable unsigned 16-bit pointer to first component of pixels ##
996
997#Example
Cary Clark6fc50412017-09-21 12:31:06 -0400998 const int w = 4;
999 const int h = 4;
1000 uint16_t storage[w * h * 4];
1001 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
1002 storage, w * 4 * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001003 SkDebugf("pixmap.addrF16() %c= storage\n",
1004 pixmap.addrF16() == storage ? '=' : '!');
1005#StdOut
1006pixmap.addrF16() == storage
1007##
1008##
1009
1010#SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16
1011
1012##
1013
1014# ------------------------------------------------------------------------------
1015
Cary Clark682c58d2018-05-16 07:07:07 -04001016#Method const uint8_t* addr8(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001017
Cary Clarkab2621d2018-01-30 10:08:57 -05001018#In Readable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001019Returns readable pixel address at (x, y).
1020
1021Input is not validated: out of bounds values of x or y trigger an assert() if
1022built with SK_DEBUG defined.
1023
1024Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType or
1025kGray_8_SkColorType, and is built with SK_DEBUG defined.
1026
Cary Clark6fc50412017-09-21 12:31:06 -04001027#Param x column index, zero or greater, and less than width() ##
1028#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001029
1030#Return readable unsigned 8-bit pointer to pixel at (x, y) ##
1031
1032#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001033 const int w = 4;
1034 const int h = 4;
1035 uint8_t storage[w * h];
1036 SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType),
1037 storage, w * sizeof(storage[0]));
1038 SkDebugf("pixmap.addr8(1, 2) %c= &storage[1 + 2 * w]\n",
1039 pixmap.addr8(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
Cary Clarkd0530ba2017-09-14 11:25:39 -04001040#StdOut
1041pixmap.addr8(1, 2) == &storage[1 + 2 * w]
1042##
1043##
1044
1045#SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8
1046
1047##
1048
1049# ------------------------------------------------------------------------------
1050
Cary Clark682c58d2018-05-16 07:07:07 -04001051#Method const uint16_t* addr16(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001052
Cary Clarkab2621d2018-01-30 10:08:57 -05001053#In Readable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001054Returns readable pixel address at (x, y).
1055
1056Input is not validated: out of bounds values of x or y trigger an assert() if
1057built with SK_DEBUG defined.
1058
1059Will trigger an assert() if Color_Type is not kRGB_565_SkColorType or
1060kARGB_4444_SkColorType, and is built with SK_DEBUG defined.
1061
Cary Clark6fc50412017-09-21 12:31:06 -04001062#Param x column index, zero or greater, and less than width() ##
1063#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001064
1065#Return readable unsigned 16-bit pointer to pixel at (x, y) ##
1066
1067#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001068 const int w = 4;
1069 const int h = 4;
1070 uint16_t storage[w * h];
1071 SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType),
1072 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001073 SkDebugf("pixmap.addr16(1, 2) %c= &storage[1 + 2 * w]\n",
1074 pixmap.addr16(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
1075#StdOut
1076pixmap.addr16(1, 2) == &storage[1 + 2 * w]
1077##
1078##
1079
1080#SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16
1081
1082##
1083
1084# ------------------------------------------------------------------------------
1085
Cary Clark682c58d2018-05-16 07:07:07 -04001086#Method const uint32_t* addr32(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001087
Cary Clarkab2621d2018-01-30 10:08:57 -05001088#In Readable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001089Returns readable pixel address at (x, y).
1090
1091Input is not validated: out of bounds values of x or y trigger an assert() if
1092built with SK_DEBUG defined.
1093
1094Will trigger an assert() if Color_Type is not kRGBA_8888_SkColorType or
1095kBGRA_8888_SkColorType, and is built with SK_DEBUG defined.
1096
Cary Clark6fc50412017-09-21 12:31:06 -04001097#Param x column index, zero or greater, and less than width() ##
1098#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001099
1100#Return readable unsigned 32-bit pointer to pixel at (x, y) ##
1101
1102#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001103 const int w = 4;
1104 const int h = 4;
1105 uint32_t storage[w * h];
1106 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_8888_SkColorType, kPremul_SkAlphaType),
1107 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001108 SkDebugf("pixmap.addr32(1, 2) %c= &storage[1 + 2 * w]\n",
1109 pixmap.addr32(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
1110#StdOut
1111pixmap.addr32(1, 2) == &storage[1 + 2 * w]
1112##
1113##
1114
Cary Clark2ade9972017-11-02 17:49:34 -04001115#SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr64
Cary Clarkd0530ba2017-09-14 11:25:39 -04001116
1117##
1118
1119# ------------------------------------------------------------------------------
1120
Cary Clark682c58d2018-05-16 07:07:07 -04001121#Method const uint64_t* addr64(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001122
Cary Clarkab2621d2018-01-30 10:08:57 -05001123#In Readable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001124Returns readable pixel address at (x, y).
1125
1126Input is not validated: out of bounds values of x or y trigger an assert() if
1127built with SK_DEBUG defined.
1128
1129Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
1130with SK_DEBUG defined.
1131
Cary Clark6fc50412017-09-21 12:31:06 -04001132#Param x column index, zero or greater, and less than width() ##
1133#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001134
1135#Return readable unsigned 64-bit pointer to pixel at (x, y) ##
1136
1137#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001138 const int w = 4;
1139 const int h = 4;
1140 uint64_t storage[w * h];
1141 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
1142 storage, w * sizeof(storage[0]));
Cary Clarkd0530ba2017-09-14 11:25:39 -04001143 SkDebugf("pixmap.addr64(1, 2) %c= &storage[1 + 2 * w]\n",
1144 pixmap.addr64(1, 2) == &storage[1 + 2 * w] ? '=' : '!');
1145#StdOut
1146pixmap.addr64(1, 2) == &storage[1 + 2 * w]
1147##
1148##
1149
1150#SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64
1151
1152##
1153
1154# ------------------------------------------------------------------------------
1155
Cary Clark682c58d2018-05-16 07:07:07 -04001156#Method const uint16_t* addrF16(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001157
Cary Clarkab2621d2018-01-30 10:08:57 -05001158#In Readable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001159Returns readable pixel address at (x, y).
1160
1161Input is not validated: out of bounds values of x or y trigger an assert() if
1162built with SK_DEBUG defined.
1163
1164Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built
1165with SK_DEBUG defined.
1166
1167Each unsigned 16-bit word represents one color component encoded as a half float.
1168Four words correspond to one pixel.
1169
Cary Clark6fc50412017-09-21 12:31:06 -04001170#Param x column index, zero or greater, and less than width() ##
1171#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001172
1173#Return readable unsigned 16-bit pointer to pixel component at (x, y) ##
1174
1175#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001176 const int w = 4;
1177 const int h = 4;
1178 const int wordsPerPixel = 4;
1179 const int rowWords = w * wordsPerPixel;
1180 uint16_t storage[rowWords * h];
1181 SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),
1182 storage, rowWords * sizeof(storage[0]));
1183 SkDebugf("pixmap.addrF16(1, 2) %c= &storage[1 * wordsPerPixel + 2 * rowWords]\n",
1184 pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords] ? '=' : '!');
Cary Clarkd0530ba2017-09-14 11:25:39 -04001185#StdOut
1186pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords]
1187##
1188##
1189
1190#SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16
1191
1192##
1193
1194#Subtopic Readable_Address ##
1195
1196#Subtopic Writable_Address
Cary Clark08895c42018-02-01 09:37:32 -05001197#Line # returns writable pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001198
1199# ------------------------------------------------------------------------------
1200
Cary Clark682c58d2018-05-16 07:07:07 -04001201#Method void* writable_addr() const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001202
Cary Clarkab2621d2018-01-30 10:08:57 -05001203#In Writable_Address
1204#Line # returns writable pixel address as void pointer ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001205Returns writable base pixel address.
1206
1207#Return writable generic base pointer to pixels ##
1208
1209#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001210 const int w = 4;
1211 const int h = 4;
1212 SkPMColor storage[w * h * 4];
1213 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4);
1214 SkDebugf("pixmap.writable_addr() %c= (void *)storage\n",
1215 pixmap.writable_addr() == (void *)storage ? '=' : '!');
1216 pixmap.erase(0x00000000);
1217 *(SkPMColor*)pixmap.writable_addr() = 0xFFFFFFFF;
1218 SkDebugf("pixmap.getColor(0, 1) %c= 0x00000000\n",
1219 pixmap.getColor(0, 1) == 0x00000000 ? '=' : '!');
1220 SkDebugf("pixmap.getColor(0, 0) %c= 0xFFFFFFFF\n",
Cary Clarkd0530ba2017-09-14 11:25:39 -04001221 pixmap.getColor(0, 0) == 0xFFFFFFFF ? '=' : '!');
1222#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -04001223pixmap.writable_addr() == (void *)storage
1224pixmap.getColor(0, 1) == 0x00000000
Cary Clarkd0530ba2017-09-14 11:25:39 -04001225pixmap.getColor(0, 0) == 0xFFFFFFFF
1226##
1227##
1228
1229#SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr()
1230
1231##
1232
1233# ------------------------------------------------------------------------------
1234
Cary Clark682c58d2018-05-16 07:07:07 -04001235#Method void* writable_addr(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001236
Cary Clarkab2621d2018-01-30 10:08:57 -05001237#In Writable_Address
Cary Clarkd0530ba2017-09-14 11:25:39 -04001238Returns writable pixel address at (x, y).
1239
1240Input is not validated: out of bounds values of x or y trigger an assert() if
1241built with SK_DEBUG defined. Returns zero if Color_Type is kUnknown_SkColorType.
1242
Cary Clark6fc50412017-09-21 12:31:06 -04001243#Param x column index, zero or greater, and less than width() ##
1244#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001245
1246#Return writable generic pointer to pixel ##
1247
1248#Example
Cary Clark6fc50412017-09-21 12:31:06 -04001249 const int w = 4;
1250 const int h = 4;
1251 SkPMColor storage[w * h * 4];
1252 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4);
1253 SkDebugf("pixmap.writable_addr() %c= (void *)storage\n",
1254 pixmap.writable_addr() == (void *)storage ? '=' : '!');
1255 pixmap.erase(0x00000000);
1256 *(SkPMColor*)pixmap.writable_addr(1, 2) = 0xFFFFFFFF;
1257 SkDebugf("pixmap.getColor(0, 0) %c= 0x00000000\n",
1258 pixmap.getColor(0, 0) == 0x00000000 ? '=' : '!');
1259 SkDebugf("pixmap.getColor(1, 2) %c= 0xFFFFFFFF\n",
Cary Clarkd0530ba2017-09-14 11:25:39 -04001260 pixmap.getColor(1, 2) == 0xFFFFFFFF ? '=' : '!');
1261#StdOut
Cary Clark6fc50412017-09-21 12:31:06 -04001262pixmap.writable_addr() == (void *)storage
1263pixmap.getColor(0, 0) == 0x00000000
Cary Clarkd0530ba2017-09-14 11:25:39 -04001264pixmap.getColor(1, 2) == 0xFFFFFFFF
1265##
1266##
1267
1268#SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr()
1269
1270##
1271
1272# ------------------------------------------------------------------------------
1273
Cary Clark682c58d2018-05-16 07:07:07 -04001274#Method uint8_t* writable_addr8(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001275
Cary Clarkab2621d2018-01-30 10:08:57 -05001276#In Writable_Address
1277#Line # returns writable pixel address as 8-bit pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -04001278Returns writable pixel address at (x, y). Result is addressable as unsigned
12798-bit bytes. Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType
1280or kGray_8_SkColorType, and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001281
1282One byte corresponds to one pixel.
1283
Cary Clark6fc50412017-09-21 12:31:06 -04001284#Param x column index, zero or greater, and less than width() ##
1285#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001286
1287#Return writable unsigned 8-bit pointer to pixels ##
1288
1289#Example
1290#Height 64
1291#Description
1292Altering pixels after drawing Bitmap is not guaranteed to affect subsequent
1293drawing on all platforms. Adding a second SkBitmap::installPixels after editing
1294pixel memory is safer.
1295##
Cary Clark6fc50412017-09-21 12:31:06 -04001296void draw(SkCanvas* canvas) {
1297 uint8_t storage[][5] = {{ 0, 0, 64, 0, 0},
1298 { 0, 128, 255, 128, 0},
1299 {64, 255, 255, 255, 64},
1300 { 0, 128, 255, 128, 0},
1301 { 0, 0, 64, 0, 0}};
1302 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kPremul_SkAlphaType);
1303 SkPixmap pixmap(imageInfo, storage[0], 5);
1304 SkBitmap bitmap;
1305 bitmap.installPixels(pixmap);
1306 canvas->scale(10, 10);
1307 canvas->drawBitmap(bitmap, 0, 0);
1308 *pixmap.writable_addr8(2, 2) = 0;
1309// bitmap.installPixels(pixmap); // uncomment to fix on GPU
1310 canvas->drawBitmap(bitmap, 10, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001311}
1312##
1313
1314#SeeAlso writable_addr writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr() addr8
1315
1316##
1317
1318# ------------------------------------------------------------------------------
1319
Cary Clark682c58d2018-05-16 07:07:07 -04001320#Method uint16_t* writable_addr16(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001321
Cary Clarkab2621d2018-01-30 10:08:57 -05001322#In Writable_Address
1323#Line # returns writable pixel address as 16-bit pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -04001324Returns writable_addr pixel address at (x, y). Result is addressable as unsigned
132516-bit words. Will trigger an assert() if Color_Type is not kRGB_565_SkColorType
1326or kARGB_4444_SkColorType, and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001327
1328One word corresponds to one pixel.
1329
Cary Clark6fc50412017-09-21 12:31:06 -04001330#Param x column index, zero or greater, and less than width() ##
1331#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001332
1333#Return writable unsigned 16-bit pointer to pixel ##
1334
1335#Example
1336#Description
1337Draw a five by five bitmap, and draw it again with a center black pixel.
1338The low nibble of the 16-bit word is Alpha.
1339##
1340#Height 64
Cary Clark6fc50412017-09-21 12:31:06 -04001341 uint16_t storage[][5] = {{ 0xCABF, 0xDABE, 0xCA9D, 0xC96C, 0xA39B },
1342 { 0xACEE, 0xA87C, 0x893A, 0x4779, 0x8708 },
1343 { 0x4B7C, 0x255B, 0x2559, 0x2557, 0x4656 },
1344 { 0x9099, 0x8128, 0x2557, 0x4124, 0x3323 },
1345 { 0x7547, 0x5505, 0x4434, 0x2012, 0x0000 }};
1346 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kARGB_4444_SkColorType, kPremul_SkAlphaType);
1347 SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
1348 SkBitmap bitmap;
1349 bitmap.installPixels(pixmap);
1350 canvas->scale(10, 10);
1351 canvas->drawBitmap(bitmap, 0, 0);
1352 *pixmap.writable_addr16(2, 2) = 0x000F;
1353 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001354 canvas->drawBitmap(bitmap, 10, 0);
1355##
1356
1357#SeeAlso writable_addr writable_addr8 writable_addr32 writable_addr64 writable_addrF16 addr() addr16
1358
1359##
1360
1361# ------------------------------------------------------------------------------
1362
Cary Clark682c58d2018-05-16 07:07:07 -04001363#Method uint32_t* writable_addr32(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001364
Cary Clarkab2621d2018-01-30 10:08:57 -05001365#In Writable_Address
1366#Line # returns writable pixel address as 32-bit pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -04001367Returns writable pixel address at (x, y). Result is addressable as unsigned
136832-bit words. Will trigger an assert() if Color_Type is not
1369kRGBA_8888_SkColorType or kBGRA_8888_SkColorType, and is built with SK_DEBUG
1370defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001371
1372One word corresponds to one pixel.
1373
Cary Clark6fc50412017-09-21 12:31:06 -04001374#Param x column index, zero or greater, and less than width() ##
1375#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001376
1377#Return writable unsigned 32-bit pointer to pixel ##
1378
1379#Example
1380#Image 4
1381#Height 72
Cary Clark6fc50412017-09-21 12:31:06 -04001382 std::vector<int32_t> pixels;
1383 pixels.resize(image->height() * image->width() * 4);
1384 SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
1385 image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
1386 image->readPixels(pixmap, 0, 0);
1387 for (int y = 0; y < pixmap.height() / 2; ++y) {
1388 for (int x = 0; x < pixmap.width(); ++x) {
1389 if ((x & 4) == (y & 4)) {
Cary Clark4d759752018-06-19 12:57:43 -04001390 *pixmap.writable_addr32(x, y) =
1391 *pixmap.writable_addr32(pixmap.width() - x, pixmap.height() - y);
Cary Clark6fc50412017-09-21 12:31:06 -04001392 }
1393 }
1394 }
1395 SkBitmap bitmap;
1396 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001397 canvas->drawBitmap(bitmap, 0, 0);
1398##
1399
1400#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr64 writable_addrF16 addr() addr32
1401
1402##
1403
1404# ------------------------------------------------------------------------------
1405
Cary Clark682c58d2018-05-16 07:07:07 -04001406#Method uint64_t* writable_addr64(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001407
Cary Clarkab2621d2018-01-30 10:08:57 -05001408#In Writable_Address
1409#Line # returns writable pixel address as 64-bit pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -04001410Returns writable pixel address at (x, y). Result is addressable as unsigned
141164-bit words. Will trigger an assert() if Color_Type is not
1412kRGBA_F16_SkColorType and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001413
1414One word corresponds to one pixel.
1415
Cary Clark6fc50412017-09-21 12:31:06 -04001416#Param x column index, zero or greater, and less than width() ##
1417#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001418
1419#Return writable unsigned 64-bit pointer to pixel ##
1420
1421#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001422#Height 40
Cary Clark6fc50412017-09-21 12:31:06 -04001423 SkImageInfo info = SkImageInfo::Make(3, 3, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
1424 uint64_t storage[9];
1425 SkPixmap pixmap(info, storage, 3 * sizeof(uint64_t));
1426 SkColor4f c4 { 1, 0.45f, 0.25f, 0.65f };
1427 pixmap.erase(c4);
1428 SkBitmap bitmap;
1429 canvas->scale(10, 10);
1430 bitmap.installPixels(pixmap);
1431 canvas->drawBitmap(bitmap, 0, 0);
1432 *pixmap.writable_addr64(1, 1) |= 0x00ff000000000000LL;
1433 bitmap.installPixels(pixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001434 canvas->drawBitmap(bitmap, 10, 0);
1435##
1436
1437#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addrF16 addr() addr64
1438
1439##
1440
1441# ------------------------------------------------------------------------------
1442
Cary Clark682c58d2018-05-16 07:07:07 -04001443#Method uint16_t* writable_addrF16(int x, int y) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001444
Cary Clarkab2621d2018-01-30 10:08:57 -05001445#In Writable_Address
1446#Line # returns writable pixel component address as 16-bit pointer ##
Cary Clark6fc50412017-09-21 12:31:06 -04001447Returns writable pixel address at (x, y). Result is addressable as unsigned
144816-bit words. Will trigger an assert() if Color_Type is not
1449kRGBA_F16_SkColorType and is built with SK_DEBUG defined.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001450
1451Each word represents one color component encoded as a half float.
1452Four words correspond to one pixel.
1453
Cary Clark6fc50412017-09-21 12:31:06 -04001454#Param x column index, zero or greater, and less than width() ##
1455#Param y row index, zero or greater, and less than height() ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001456
1457#Return writable unsigned 16-bit pointer to first component of pixel ##
1458
1459#Example
1460#Height 64
1461#Description
1462Left bitmap is drawn with two pixels defined in half float format. Right bitmap
Cary Clark682c58d2018-05-16 07:07:07 -04001463is drawn after overwriting bottom half float color with top half float color.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001464##
Cary Clark6fc50412017-09-21 12:31:06 -04001465 SkImageInfo info = SkImageInfo::Make(1, 2, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
1466 uint16_t storage[2][4];
1467 SkPixmap pixmap(info, storage[0], sizeof(uint64_t));
1468 SkIRect topPixelBounds = {0, 0, 1, 1};
1469 pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds);
1470 SkIRect bottomPixelBounds = {0, 1, 1, 2};
1471 pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds);
1472 SkBitmap bitmap;
1473 canvas->scale(20, 20);
1474 bitmap.installPixels(pixmap);
1475 canvas->drawBitmap(bitmap, 0, 0);
1476 uint16_t* pixel2 = pixmap.writable_addrF16(0, 1);
1477 for (int i = 0; i < 4; ++i) {
1478 pixel2[i] = storage[0][i];
1479 }
1480 bitmap.installPixels(pixmap);
1481 canvas->drawBitmap(bitmap, 4, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001482##
1483
1484#SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addr64 addr() addrF16
1485
1486##
1487
1488#Subtopic Writable_Address ##
1489
Cary Clark78de7512018-02-07 07:27:09 -05001490#Subtopic Pixels
1491#Populate
1492#Line # read and write pixel values ##
1493##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001494
1495# ------------------------------------------------------------------------------
1496
Cary Clarke80cd442018-07-17 13:19:56 -04001497#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05001498#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001499#Line # copies and converts pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001500
Cary Clarkd0530ba2017-09-14 11:25:39 -04001501Copies a Rect of pixels to dstPixels. Copy starts at (0, 0), and does not
Cary Clarkac47b882018-01-11 10:35:44 -05001502exceed Pixmap (width(), height()).
Cary Clark6fc50412017-09-21 12:31:06 -04001503
Cary Clark682c58d2018-05-16 07:07:07 -04001504dstInfo specifies width, height, Color_Type, Alpha_Type, and
Cary Clarkd0530ba2017-09-14 11:25:39 -04001505Color_Space of destination. dstRowBytes specifics the gap from one destination
1506row to the next. Returns true if pixels are copied. Returns false if
1507dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes.
1508
Cary Clarkac47b882018-01-11 10:35:44 -05001509Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001510kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001511If Pixmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match.
1512If Pixmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must
1513match. If Pixmap colorSpace is nullptr, dstInfo.colorSpace must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001514false if pixel conversion is not possible.
1515
Cary Clarkac47b882018-01-11 10:35:44 -05001516Returns false if Pixmap width() or height() is zero or negative.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001517
1518#Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ##
1519#Param dstPixels destination pixel storage ##
1520#Param dstRowBytes destination row length ##
1521
1522#Return true if pixels are copied to dstPixels ##
1523
1524#Example
1525#Height 128
1526#Description
1527Transferring the gradient from 8 bits per component to 4 bits per component
1528creates visible banding.
1529##
Cary Clark6fc50412017-09-21 12:31:06 -04001530 std::vector<int32_t> pixels;
1531 const int width = 256;
1532 const int height = 64;
1533 pixels.resize(height * width * 4);
1534 SkImageInfo srcInfo = SkImageInfo::MakeN32Premul(width, height);
1535 SkPixmap srcPixmap(srcInfo, (const void*) &pixels.front(), width * 4);
1536 SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 };
1537 SkPoint gradPoints[] = { { 0, 0 }, { 256, 0 } };
1538 SkPaint paint;
1539 paint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1540 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1541 SkBitmap bitmap;
1542 bitmap.installPixels(srcPixmap);
1543 SkCanvas srcCanvas(bitmap);
1544 srcCanvas.drawRect(SkRect::MakeWH(width, height), paint);
1545 canvas->drawBitmap(bitmap, 0, 0);
1546 std::vector<int32_t> dstPixels;
1547 dstPixels.resize(height * width * 2);
1548 SkImageInfo dstInfo = srcInfo.makeColorType(kARGB_4444_SkColorType);
1549 srcPixmap.readPixels(dstInfo, &dstPixels.front(), width * 2);
1550 SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2);
1551 bitmap.installPixels(dstPixmap);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001552 canvas->drawBitmap(bitmap, 0, 128);
1553##
1554
1555#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1556
1557##
1558
1559# ------------------------------------------------------------------------------
1560
1561#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX,
Cary Clark682c58d2018-05-16 07:07:07 -04001562 int srcY) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001563
1564Copies a Rect of pixels to dstPixels. Copy starts at (srcX, srcY), and does not
Cary Clarkac47b882018-01-11 10:35:44 -05001565exceed Pixmap (width(), height()).
Cary Clark6fc50412017-09-21 12:31:06 -04001566
Cary Clark682c58d2018-05-16 07:07:07 -04001567dstInfo specifies width, height, Color_Type, Alpha_Type, and
Cary Clarkd0530ba2017-09-14 11:25:39 -04001568Color_Space of destination. dstRowBytes specifics the gap from one destination
1569row to the next. Returns true if pixels are copied. Returns false if
1570dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes.
1571
Cary Clarkac47b882018-01-11 10:35:44 -05001572Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001573kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001574If Pixmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match.
1575If Pixmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must
1576match. If Pixmap colorSpace is nullptr, dstInfo.colorSpace must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001577false if pixel conversion is not possible.
Cary Clark682c58d2018-05-16 07:07:07 -04001578
Cary Clarkd0530ba2017-09-14 11:25:39 -04001579srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clarkac47b882018-01-11 10:35:44 -05001580false if Pixmap width() or height() is zero or negative. Returns false if:
Cary Clark154beea2017-10-26 07:58:48 -04001581
Cary Clarkd0530ba2017-09-14 11:25:39 -04001582#Formula
Cary Clarkac47b882018-01-11 10:35:44 -05001583abs(srcX) >= Pixmap width()
Cary Clark6fc50412017-09-21 12:31:06 -04001584##
1585, or if
1586#Formula
Cary Clarkac47b882018-01-11 10:35:44 -05001587abs(srcY) >= Pixmap height()
Cary Clarkd0530ba2017-09-14 11:25:39 -04001588##
1589.
1590
1591#Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ##
1592#Param dstPixels destination pixel storage ##
1593#Param dstRowBytes destination row length ##
1594#Param srcX column index whose absolute value is less than width() ##
1595#Param srcY row index whose absolute value is less than height() ##
1596
1597#Return true if pixels are copied to dstPixels ##
1598
1599#Example
1600#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001601void draw(SkCanvas* canvas) {
1602 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1603 std::vector<int32_t> srcPixels;
1604 const int rowBytes = image->width() * 4;
1605 srcPixels.resize(image->height() * rowBytes);
1606 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1607 image->readPixels(pixmap, 0, 0);
1608 for (int offset : { 32, 64, 96 } ) {
1609 std::vector<int32_t> dstPixels;
1610 dstPixels.resize(image->height() * rowBytes);
1611 pixmap.readPixels(info, &dstPixels.front(), rowBytes, offset, 0);
1612 SkBitmap bitmap;
1613 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1614 bitmap.installPixels(dstmap);
1615 canvas->translate(32, 32);
1616 canvas->drawBitmap(bitmap, 0, 0);
1617 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001618}
1619##
1620
1621#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1622
1623##
1624
1625# ------------------------------------------------------------------------------
1626
Cary Clark682c58d2018-05-16 07:07:07 -04001627#Method bool readPixels(const SkPixmap& dst, int srcX, int srcY) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001628
1629Copies a Rect of pixels to dst. Copy starts at (srcX, srcY), and does not
Cary Clarkac47b882018-01-11 10:35:44 -05001630exceed Pixmap (width(), height()). dst specifies width, height, Color_Type,
Cary Clarkd0530ba2017-09-14 11:25:39 -04001631Alpha_Type, and Color_Space of destination. Returns true if pixels are copied.
1632Returns false if dst.addr() equals nullptr, or dst.rowBytes is less than
1633dst SkImageInfo::minRowBytes.
1634
Cary Clarkac47b882018-01-11 10:35:44 -05001635Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001636kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.info().colorType must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001637If Pixmap colorType is kGray_8_SkColorType, dst.info().colorSpace must match.
1638If Pixmap alphaType is kOpaque_SkAlphaType, dst.info().alphaType must
1639match. If Pixmap colorSpace is nullptr, dst.info().colorSpace must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001640false if pixel conversion is not possible.
Cary Clark682c58d2018-05-16 07:07:07 -04001641
Cary Clarkd0530ba2017-09-14 11:25:39 -04001642srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clarkac47b882018-01-11 10:35:44 -05001643false Pixmap width() or height() is zero or negative. Returns false if:
Cary Clark154beea2017-10-26 07:58:48 -04001644
Cary Clarkd0530ba2017-09-14 11:25:39 -04001645#Formula
Cary Clarkac47b882018-01-11 10:35:44 -05001646abs(srcX) >= Pixmap width()
Cary Clark6fc50412017-09-21 12:31:06 -04001647##
1648, or if
1649#Formula
Cary Clarkac47b882018-01-11 10:35:44 -05001650abs(srcY) >= Pixmap height()
Cary Clarkd0530ba2017-09-14 11:25:39 -04001651##
1652.
1653
1654#Param dst Image_Info and pixel address to write to ##
1655#Param srcX column index whose absolute value is less than width() ##
1656#Param srcY row index whose absolute value is less than height() ##
1657
1658#Return true if pixels are copied to dst ##
1659
1660#Example
1661#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001662void draw(SkCanvas* canvas) {
1663 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1664 std::vector<int32_t> srcPixels;
1665 const int rowBytes = image->width() * 4;
1666 srcPixels.resize(image->height() * rowBytes);
1667 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1668 image->readPixels(pixmap, 0, 0);
1669 for (int offset : { 32, 64, 96 } ) {
1670 std::vector<int32_t> dstPixels;
1671 dstPixels.resize(image->height() * rowBytes);
1672 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1673 pixmap.readPixels(dstmap, offset, 0);
1674 SkBitmap bitmap;
1675 bitmap.installPixels(dstmap);
1676 canvas->translate(32, 32);
1677 canvas->drawBitmap(bitmap, 0, 0);
1678 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001679}
1680##
1681
1682#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1683
1684##
1685
1686# ------------------------------------------------------------------------------
1687
Cary Clark682c58d2018-05-16 07:07:07 -04001688#Method bool readPixels(const SkPixmap& dst) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001689
1690Copies pixels inside bounds() to dst. dst specifies width, height, Color_Type,
1691Alpha_Type, and Color_Space of destination. Returns true if pixels are copied.
1692Returns false if dst.addr() equals nullptr, or dst.rowBytes is less than
1693dst SkImageInfo::minRowBytes.
1694
Cary Clarkac47b882018-01-11 10:35:44 -05001695Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001696kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001697If Pixmap colorType is kGray_8_SkColorType, dst Color_Space must match.
1698If Pixmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must
1699match. If Pixmap colorSpace is nullptr, dst Color_Space must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001700false if pixel conversion is not possible.
Cary Clark682c58d2018-05-16 07:07:07 -04001701
Cary Clarkac47b882018-01-11 10:35:44 -05001702Returns false if Pixmap width() or height() is zero or negative.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001703
1704#Param dst Image_Info and pixel address to write to ##
1705
1706#Return true if pixels are copied to dst ##
1707
1708#Example
1709#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001710void draw(SkCanvas* canvas) {
1711 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1712 std::vector<int32_t> srcPixels;
1713 const int rowBytes = image->width() * 4;
1714 srcPixels.resize(image->height() * rowBytes);
1715 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1716 image->readPixels(pixmap, 0, 0);
1717 for (int index = 0; index < 3; ++index ) {
1718 std::vector<int32_t> dstPixels;
1719 dstPixels.resize(image->height() * rowBytes);
1720 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1721 pixmap.readPixels(dstmap);
1722 SkBitmap bitmap;
1723 bitmap.installPixels(dstmap);
1724 canvas->translate(32, 32);
1725 canvas->drawBitmap(bitmap, 0, 0);
1726 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001727}
1728##
1729
1730#SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
1731
1732##
1733
1734# ------------------------------------------------------------------------------
1735
1736#Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality) const
1737
Cary Clark78de7512018-02-07 07:27:09 -05001738#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001739#Line # scales and converts pixels ##
Cary Clarkac47b882018-01-11 10:35:44 -05001740Copies Bitmap to dst, scaling pixels to fit dst.width() and dst.height(), and
Cary Clarkd0530ba2017-09-14 11:25:39 -04001741converting pixels to match dst.colorType and dst.alphaType. Returns true if
1742pixels are copied. Returns false if dst.addr() is nullptr, or dst.rowBytes is
1743less than dst SkImageInfo::minRowBytes.
1744
Cary Clarkac47b882018-01-11 10:35:44 -05001745Pixels are copied only if pixel conversion is possible. If Pixmap colorType is
Cary Clarkd0530ba2017-09-14 11:25:39 -04001746kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match.
Cary Clarkac47b882018-01-11 10:35:44 -05001747If Pixmap colorType is kGray_8_SkColorType, dst Color_Space must match.
1748If Pixmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must
1749match. If Pixmap colorSpace is nullptr, dst Color_Space must match. Returns
Cary Clarkd0530ba2017-09-14 11:25:39 -04001750false if pixel conversion is not possible.
1751
Cary Clarkac47b882018-01-11 10:35:44 -05001752Returns false if Bitmap width() or height() is zero or negative.
Cary Clarkd0530ba2017-09-14 11:25:39 -04001753
1754Scales the image, with filterQuality, to match dst.width() and dst.height().
1755filterQuality kNone_SkFilterQuality is fastest, typically implemented with
1756Filter_Quality_Nearest_Neighbor. kLow_SkFilterQuality is typically implemented with
1757Filter_Quality_Bilerp. kMedium_SkFilterQuality is typically implemented with
1758Filter_Quality_Bilerp, and Filter_Quality_MipMap when size is reduced.
1759kHigh_SkFilterQuality is slowest, typically implemented with Filter_Quality_BiCubic.
1760
1761#Param dst Image_Info and pixel address to write to ##
Cary Clark682c58d2018-05-16 07:07:07 -04001762#Param filterQuality one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
Cary Clarkd0530ba2017-09-14 11:25:39 -04001763 kMedium_SkFilterQuality, kHigh_SkFilterQuality
1764##
1765
Cary Clarkac47b882018-01-11 10:35:44 -05001766#Return true if pixels are scaled to fit dst ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001767
1768#Example
1769#Image 3
Cary Clark6fc50412017-09-21 12:31:06 -04001770void draw(SkCanvas* canvas) {
1771 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
1772 std::vector<int32_t> srcPixels;
1773 int rowBytes = image->width() * 4;
1774 srcPixels.resize(image->height() * rowBytes);
1775 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
1776 image->readPixels(pixmap, 0, 0);
1777 for (int offset : { 32, 64, 96 } ) {
1778 info = SkImageInfo::MakeN32Premul(image->width() + offset, image->height());
1779 rowBytes = info.width() * 4;
1780 std::vector<int32_t> dstPixels;
1781 dstPixels.resize(image->height() * rowBytes);
1782 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
1783 pixmap.scalePixels(dstmap, kMedium_SkFilterQuality);
1784 SkBitmap bitmap;
1785 bitmap.installPixels(dstmap);
1786 canvas->translate(32, 32);
1787 canvas->drawBitmap(bitmap, 0, 0);
1788 }
Cary Clarkd0530ba2017-09-14 11:25:39 -04001789}
1790##
1791
1792#SeeAlso SkCanvas::drawBitmap SkImage::scalePixels
1793
1794##
1795
1796# ------------------------------------------------------------------------------
1797
1798#Method bool erase(SkColor color, const SkIRect& subset) const
1799
Cary Clark78de7512018-02-07 07:27:09 -05001800#In Pixels
Cary Clarkab2621d2018-01-30 10:08:57 -05001801#Line # writes Color to pixels ##
Cary Clarkd0530ba2017-09-14 11:25:39 -04001802Writes color to pixels bounded by subset; returns true on success.
1803Returns false if colorType is kUnknown_SkColorType, or if subset does
1804not intersect bounds().
Cary Clark682c58d2018-05-16 07:07:07 -04001805
Cary Clarkd0530ba2017-09-14 11:25:39 -04001806#Param color Unpremultiplied Color to write ##
1807#Param subset bounding integer Rect of written pixels ##
1808
1809#Return true if pixels are changed ##
1810
1811#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001812#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001813 uint32_t storage[2];
1814 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1815 SkPixmap pixmap(info, storage, info.minRowBytes());
1816 pixmap.erase(SK_ColorBLUE, {0, 0, 1, 1});
1817 pixmap.erase(SK_ColorRED, {0, 1, 1, 2});
1818 SkBitmap bitmap;
1819 canvas->scale(20, 20);
1820 bitmap.installPixels(pixmap);
1821 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001822##
1823
1824#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1825
1826##
1827
1828# ------------------------------------------------------------------------------
1829
Cary Clark682c58d2018-05-16 07:07:07 -04001830#Method bool erase(SkColor color) const
Cary Clarkd0530ba2017-09-14 11:25:39 -04001831
1832Writes color to pixels inside bounds(); returns true on success.
1833Returns false if colorType is kUnknown_SkColorType, or if bounds()
1834is empty.
1835
1836#Param color Unpremultiplied Color to write ##
1837
1838#Return true if pixels are changed ##
1839
1840#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001841#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001842 uint32_t storage[2];
1843 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1844 SkPixmap pixmap(info, storage, info.minRowBytes());
1845 pixmap.erase(SK_ColorBLUE);
1846 SkBitmap bitmap;
1847 canvas->scale(20, 20);
1848 bitmap.installPixels(pixmap);
1849 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001850##
1851
1852#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1853
1854##
1855
1856# ------------------------------------------------------------------------------
1857
1858#Method bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const
1859
1860Writes color to pixels bounded by subset; returns true on success.
1861if subset is nullptr, writes colors pixels inside bounds(). Returns false if
1862colorType is kUnknown_SkColorType, if subset is not nullptr and does
1863not intersect bounds(), or if subset is nullptr and bounds() is empty.
1864
1865#Param color Unpremultiplied Color to write ##
1866#Param subset bounding integer Rect of pixels to write; may be nullptr ##
1867
1868#Return true if pixels are changed ##
1869
1870#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001871#Height 50
Cary Clark6fc50412017-09-21 12:31:06 -04001872 uint32_t storage[2];
1873 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2);
1874 SkPixmap pixmap(info, storage, info.minRowBytes());
1875 SkIRect topPixelBounds = {0, 0, 1, 1};
1876 pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds);
1877 SkIRect bottomPixelBounds = {0, 1, 1, 2};
1878 pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds);
1879 SkBitmap bitmap;
1880 canvas->scale(20, 20);
1881 bitmap.installPixels(pixmap);
1882 canvas->drawBitmap(bitmap, 0, 0);
Cary Clarkd0530ba2017-09-14 11:25:39 -04001883##
1884
1885#SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
1886
1887##
1888
Cary Clarkd0530ba2017-09-14 11:25:39 -04001889#Class SkPixmap ##
1890
1891#Topic Pixmap ##