blob: bf425d703ae1e9812a0582b36101a0949d02cb91 [file] [log] [blame]
Cary Clark2dc84ad2018-01-26 12:56:22 -05001#Topic Image_Info
Cary Clark137b8742018-05-30 09:21:49 -04002#Alias Image_Info_Reference ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05003
Cary Clark61313f32018-10-08 14:57:48 -04004#Code
5#Populate
6##
7
Cary Clarkf895a422018-02-27 09:54:21 -05008Image_Info specifies the dimensions and encoding of the pixels in a Bitmap.
9The dimensions are integral width and height. The encoding is how pixel
10bits describe Color_Alpha, transparency; Color components red, blue,
11and green; and Color_Space, the range and linearity of colors.
12
13Image_Info describes an uncompressed raster pixels. In contrast, Image
14additionally describes compressed pixels like PNG, and Surface describes
15destinations on the GPU. Image and Surface may be specified by Image_Info,
16but Image and Surface may not contain Image_Info.
17
Cary Clark2dc84ad2018-01-26 12:56:22 -050018# ------------------------------------------------------------------------------
Cary Clark08895c42018-02-01 09:37:32 -050019#Subtopic Alpha_Type
Cary Clarkf895a422018-02-27 09:54:21 -050020#Line # encoding for pixel transparency ##
Cary Clark137b8742018-05-30 09:21:49 -040021#Alias Alpha_Type ##
22#Alias Alpha_Types ##
Cary Clarkf895a422018-02-27 09:54:21 -050023
Cary Clark681287e2018-03-16 11:34:15 -040024#PhraseDef list_of_alpha_types
25kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
26kUnpremul_SkAlphaType
27##
28
Cary Clark2dc84ad2018-01-26 12:56:22 -050029#Enum SkAlphaType
Cary Clarkf895a422018-02-27 09:54:21 -050030#Line # encoding for pixel transparency ##
Cary Clark2dc84ad2018-01-26 12:56:22 -050031
32#Code
Cary Clark61313f32018-10-08 14:57:48 -040033#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -050034##
35
Cary Clarkf895a422018-02-27 09:54:21 -050036Describes how to interpret the alpha component of a pixel. A pixel may
37be opaque, or Color_Alpha, describing multiple levels of transparency.
38
39In simple blending, Color_Alpha weights the draw color and the destination
Cary Clark61313f32018-10-08 14:57:48 -040040color to create a new color. If alpha describes a weight from zero to one,
41new color is set to: #Formula # draw color * alpha + destination color * (1 - alpha) ##.
Cary Clarkf895a422018-02-27 09:54:21 -050042
43In practice alpha is encoded in two or more bits, where 1.0 equals all bits set.
44
Cary Clarkffb3d682018-05-17 12:17:28 -040045RGB may have Color_Alpha included in each component value; the stored
46value is the original RGB multiplied by Color_Alpha. Premultiplied color
Cary Clarkf895a422018-02-27 09:54:21 -050047components improve performance.
Cary Clark2dc84ad2018-01-26 12:56:22 -050048
49#Const kUnknown_SkAlphaType 0
Cary Clark682c58d2018-05-16 07:07:07 -040050#Line # uninitialized ##
51 Alpha_Type is uninitialized.
Cary Clark2dc84ad2018-01-26 12:56:22 -050052##
53#Const kOpaque_SkAlphaType 1
Cary Clark682c58d2018-05-16 07:07:07 -040054#Line # pixel is opaque ##
55#Details Opaque
56 Pixels are opaque. The Color_Type must have no explicit alpha
57 component, or all alpha components must be set to their maximum value.
Cary Clark2dc84ad2018-01-26 12:56:22 -050058##
59#Const kPremul_SkAlphaType 2
Cary Clark682c58d2018-05-16 07:07:07 -040060#Line # pixel components are Premultiplied by Alpha ##
61#Details Premul
62 Pixels have Alpha Premultiplied into color components.
63 Surface pixels must be Premultiplied.
Cary Clark2dc84ad2018-01-26 12:56:22 -050064##
65#Const kUnpremul_SkAlphaType 3
Cary Clark682c58d2018-05-16 07:07:07 -040066#Line # pixel components are independent of Alpha ##
67#Details Unpremul
68 Pixel color component values are independent of alpha value.
69 Images generated from encoded data like PNG do not Premultiply pixel color
70 components. kUnpremul_SkAlphaType is supported for Image pixels, but not for
71 Surface pixels.
72##
73#Const kLastEnum_SkAlphaType 3
74#Line # last valid value ##
75 Used by tests to iterate through all valid values.
Cary Clark2dc84ad2018-01-26 12:56:22 -050076##
77
Cary Clarkf895a422018-02-27 09:54:21 -050078#NoExample
Cary Clark2dc84ad2018-01-26 12:56:22 -050079##
80
Cary Clarkf895a422018-02-27 09:54:21 -050081#SeeAlso SkColorType SkColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -050082
83#Enum SkAlphaType ##
Cary Clarkf895a422018-02-27 09:54:21 -050084
85#Subtopic Opaque
Cary Clark682c58d2018-05-16 07:07:07 -040086#Line # hints all pixels are opaque ##
87Use kOpaque_SkAlphaType as a hint to optimize drawing when Alpha component
Cary Clarkf895a422018-02-27 09:54:21 -050088of all pixel is set to its maximum value of 1.0; all alpha component bits are set.
Cary Clark682c58d2018-05-16 07:07:07 -040089If Image_Info is set to kOpaque_SkAlphaType but all alpha values are not 1.0,
90results are undefined.
Cary Clarkf895a422018-02-27 09:54:21 -050091
92#Example
93#Height 64
94#Description
95SkPreMultiplyARGB parameter a is set to 255, its maximum value, and is interpreted
96as Color_Alpha of 1.0. kOpaque_SkAlphaType may be set to improve performance.
Cary Clark682c58d2018-05-16 07:07:07 -040097If SkPreMultiplyARGB parameter a is set to a value smaller than 255,
Cary Clarkf895a422018-02-27 09:54:21 -050098kPremul_SkAlphaType must be used instead to avoid undefined results.
99The four displayed values are the original component values, though not necessarily
100in the same order.
101##
102 SkPMColor color = SkPreMultiplyARGB(255, 50, 100, 150);
103 SkString s;
104 s.printf("%u %u %u %u", SkColorGetA(color), SkColorGetR(color),
105 SkColorGetG(color), SkColorGetB(color));
106 SkPaint paint;
107 paint.setAntiAlias(true);
108 canvas->drawString(s, 10, 62, paint);
109 canvas->scale(50, 50);
110 SkBitmap bitmap;
111 SkImageInfo imageInfo = SkImageInfo::Make(1, 1, kN32_SkColorType, kOpaque_SkAlphaType);
112 if (bitmap.installPixels(imageInfo, (void*) &color, imageInfo.minRowBytes())) {
113 canvas->drawBitmap(bitmap, 0, 0);
114 }
115##
116
117#Subtopic Opaque ##
118
119#Subtopic Premul
Cary Clark682c58d2018-05-16 07:07:07 -0400120#Line # stores components scaled by Alpha ##
121Use kPremul_SkAlphaType when stored color components are the original color
122multiplied by the alpha component. The alpha component range of 0.0 to 1.0 is
123achieved by dividing the integer bit value by the maximum bit value.
Cary Clarkf895a422018-02-27 09:54:21 -0500124
Cary Clark682c58d2018-05-16 07:07:07 -0400125#Code
Cary Clarkf895a422018-02-27 09:54:21 -0500126stored color = original color * alpha / max alpha
127##
128
129The color component must be equal to or smaller than the alpha component,
130or the results are undefined.
131
132#Example
133#Description
134SkPreMultiplyARGB parameter a is set to 150, less than its maximum value, and is
135interpreted as Color_Alpha of about 0.6. kPremul_SkAlphaType must be set, since
Cary Clark682c58d2018-05-16 07:07:07 -0400136SkPreMultiplyARGB parameter a is set to a value smaller than 255,
Cary Clarkf895a422018-02-27 09:54:21 -0500137to avoid undefined results.
138The four displayed values reflect that the alpha component has been multiplied
139by the original color.
140##
141#Height 64
142 SkPMColor color = SkPreMultiplyARGB(150, 50, 100, 150);
143 SkString s;
144 s.printf("%u %u %u %u", SkColorGetA(color), SkColorGetR(color),
145 SkColorGetG(color), SkColorGetB(color));
146 SkPaint paint;
147 paint.setAntiAlias(true);
148 canvas->drawString(s, 10, 62, paint);
149 canvas->scale(50, 50);
150 SkBitmap bitmap;
151 SkImageInfo imageInfo = SkImageInfo::Make(1, 1, kN32_SkColorType, kPremul_SkAlphaType);
152 if (bitmap.installPixels(imageInfo, (void*) &color, imageInfo.minRowBytes())) {
153 canvas->drawBitmap(bitmap, 0, 0);
154 }
155##
156
157#Subtopic Premul ##
158
159#Subtopic Unpremul
Cary Clark682c58d2018-05-16 07:07:07 -0400160#Line # stores components without Alpha scaling ##
161Use kUnpremul_SkAlphaType if stored color components are not divided by the
162alpha component. Some drawing destinations may not support
163kUnpremul_SkAlphaType.
Cary Clarkf895a422018-02-27 09:54:21 -0500164
165#Bug 7079
166#Example
Cary Clark681287e2018-03-16 11:34:15 -0400167#Height 64
Cary Clarkf895a422018-02-27 09:54:21 -0500168#Description
169SkColorSetARGB parameter a is set to 150, less than its maximum value, and is
Cary Clark682c58d2018-05-16 07:07:07 -0400170interpreted as Color_Alpha of about 0.6. color is not Premultiplied;
Cary Clarkf895a422018-02-27 09:54:21 -0500171color components may have values greater than color alpha.
172The four displayed values are the original component values, though not necessarily
173in the same order.
174##
175 SkColor color = SkColorSetARGB(150, 50, 100, 255);
176 SkString s;
177 s.printf("%u %u %u %u", SkColorGetA(color), SkColorGetR(color),
178 SkColorGetG(color), SkColorGetB(color));
179 SkPaint paint;
180 paint.setAntiAlias(true);
181 canvas->drawString(s, 10, 62, paint);
182 canvas->scale(50, 50);
183 SkBitmap bitmap;
184 SkImageInfo imageInfo = SkImageInfo::Make(1, 1, kN32_SkColorType, kUnpremul_SkAlphaType);
185 if (bitmap.installPixels(imageInfo, (void*) &color, imageInfo.minRowBytes())) {
186 canvas->drawBitmap(bitmap, 0, 0);
187 }
188##
189
190#Subtopic Unpremul ##
191
Cary Clark06c20f32018-03-20 15:53:27 -0400192#Method static inline bool SkAlphaTypeIsOpaque(SkAlphaType at)
193#In Property
194#Line # returns if Alpha_Type equals kOpaque_SkAlphaType ##
Cary Clark09d80c02018-10-31 12:14:03 -0400195#Populate
Cary Clark06c20f32018-03-20 15:53:27 -0400196
Cary Clark06c20f32018-03-20 15:53:27 -0400197#NoExample
198##
199##
200
Cary Clark08895c42018-02-01 09:37:32 -0500201#Subtopic Alpha_Type ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500202
203# ------------------------------------------------------------------------------
Cary Clark08895c42018-02-01 09:37:32 -0500204#Subtopic Color_Type
Cary Clarkf895a422018-02-27 09:54:21 -0500205#Line # encoding for pixel color ##
Cary Clark137b8742018-05-30 09:21:49 -0400206#Alias Color_Type ##
207#Alias Color_Types ##
Cary Clark2a8c48b2018-02-15 17:31:24 -0500208
Cary Clark1a8d7622018-03-05 13:26:16 -0500209#PhraseDef list_of_color_types
210kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType,
211kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType,
212kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType,
213kGray_8_SkColorType, kRGBA_F16_SkColorType
214##
215
Cary Clark2dc84ad2018-01-26 12:56:22 -0500216#Enum SkColorType
Cary Clarkf895a422018-02-27 09:54:21 -0500217#Line # encoding for pixel color ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500218
219#Code
Cary Clark61313f32018-10-08 14:57:48 -0400220#Populate
221##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500222
Cary Clarkf895a422018-02-27 09:54:21 -0500223Describes how pixel bits encode color. A pixel may be an alpha mask, a
Cary Clark09d80c02018-10-31 12:14:03 -0400224grayscale, RGB, or ARGB.
Cary Clark4855f782018-02-06 09:41:53 -0500225
Cary Clarkffb3d682018-05-17 12:17:28 -0400226kN32_SkColorType selects the native 32-bit ARGB format. On Little_Endian
227processors, pixels containing 8-bit ARGB components pack into 32-bit
Cary Clark4855f782018-02-06 09:41:53 -0500228kBGRA_8888_SkColorType. On Big_Endian processors, pixels pack into 32-bit
229kRGBA_8888_SkColorType.
Cary Clark2dc84ad2018-01-26 12:56:22 -0500230
231#Const kUnknown_SkColorType 0
Cary Clark682c58d2018-05-16 07:07:07 -0400232#Line # uninitialized ##
233 Color_Type is set to kUnknown_SkColorType by default. If set,
234 encoding format and size is unknown.
Cary Clarkab2621d2018-01-30 10:08:57 -0500235##
Cary Clarkf895a422018-02-27 09:54:21 -0500236
Cary Clark682c58d2018-05-16 07:07:07 -0400237#Const kAlpha_8_SkColorType 1
238#Line # pixel with Alpha in 8-bit byte ##
239#Details Alpha_8
240 Stores 8-bit byte pixel encoding that represents transparency. Value of zero
241 is completely transparent; a value of 255 is completely opaque.
242##
243
244#Const kRGB_565_SkColorType 2
245#Line # pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word ##
246#Details RGB_565
247 Stores 16-bit word pixel encoding that contains five bits of blue,
248 six bits of green, and five bits of red.
249##
250
251#Const kARGB_4444_SkColorType 3
252#Line # pixel with 4 bits for alpha, red, green, blue; in 16-bit word ##
253#Details ARGB_4444
254 Stores 16-bit word pixel encoding that contains four bits of alpha,
255 four bits of blue, four bits of green, and four bits of red.
256##
257
258#Const kRGBA_8888_SkColorType 4
259#Line # pixel with 8 bits for red, green, blue, alpha; in 32-bit word ##
260#Details RGBA_8888
261 Stores 32-bit word pixel encoding that contains eight bits of red,
262 eight bits of green, eight bits of blue, and eight bits of alpha.
263##
264
265#Const kRGB_888x_SkColorType 5
266#Line # pixel with 8 bits each for red, green, blue; in 32-bit word ##
267#Details RGB_888
268 Stores 32-bit word pixel encoding that contains eight bits of red,
269 eight bits of green, eight bits of blue, and eight unused bits.
270##
271
272#Const kBGRA_8888_SkColorType 6
273#Line # pixel with 8 bits for blue, green, red, alpha; in 32-bit word ##
274#Details BGRA_8888
275 Stores 32-bit word pixel encoding that contains eight bits of blue,
276 eight bits of green, eight bits of red, and eight bits of alpha.
277##
278
279#Const kRGBA_1010102_SkColorType 7
280#Line # 10 bits for red, green, blue; 2 bits for alpha; in 32-bit word ##
281#Details RGBA_1010102
282 Stores 32-bit word pixel encoding that contains ten bits of red,
283 ten bits of green, ten bits of blue, and two bits of alpha.
284##
285
286#Const kRGB_101010x_SkColorType 8
287#Line # pixel with 10 bits each for red, green, blue; in 32-bit word ##
288#Details RGB_101010
289 Stores 32-bit word pixel encoding that contains ten bits of red,
290 ten bits of green, ten bits of blue, and two unused bits.
291##
292
293#Const kGray_8_SkColorType 9
Cary Clark09d80c02018-10-31 12:14:03 -0400294#Line # pixel with grayscale level in 8-bit byte ##
Cary Clark682c58d2018-05-16 07:07:07 -0400295#Details Gray_8
296 Stores 8-bit byte pixel encoding that equivalent to equal values for red,
297 blue, and green, representing colors from black to white.
298##
299
300#Const kRGBA_F16_SkColorType 10
301#Line # pixel with half floats for red, green, blue, alpha; in 64-bit word ##
302#Details RGBA_F16
303 Stores 64-bit word pixel encoding that contains 16 bits of blue,
Cary Clark224c7002018-06-27 11:00:21 -0400304 16 bits of green, 16 bits of red, and 16 bits of alpha. Each component
305 is encoded as a half float.
Cary Clark682c58d2018-05-16 07:07:07 -0400306##
307
Cary Clark224c7002018-06-27 11:00:21 -0400308#Const kRGBA_F32_SkColorType 11
309#Line # pixel using C float for red, green, blue, alpha; in 128-bit word ##
310#Details RGBA_F32
311 Stores 128-bit word pixel encoding that contains 32 bits of blue,
312 32 bits of green, 32 bits of red, and 32 bits of alpha. Each component
313 is encoded as a single precision float.
314##
315
316#Const kLastEnum_SkColorType 11
Cary Clark682c58d2018-05-16 07:07:07 -0400317#NoJustify
318#Line # last valid value ##
319 Used by tests to iterate through all valid values.
320##
321
322#Const kN32_SkColorType 4 or 6
Cary Clark137b8742018-05-30 09:21:49 -0400323#Alias Native_Color_Type ##
Cary Clark682c58d2018-05-16 07:07:07 -0400324#NoJustify
Cary Clarkffb3d682018-05-17 12:17:28 -0400325#Line # native ARGB 32-bit encoding ##
326 Encodes ARGB as either kRGBA_8888_SkColorType or
Cary Clark682c58d2018-05-16 07:07:07 -0400327 kBGRA_8888_SkColorType, whichever is native to the platform.
Cary Clarkf895a422018-02-27 09:54:21 -0500328##
329
330#NoExample
331##
332
333#SeeAlso SkAlphaType SkColorSpace
334
335#Enum SkColorType ##
336
337#Subtopic Alpha_8
Cary Clark682c58d2018-05-16 07:07:07 -0400338#Line # encodes transparency only ##
339 Alpha pixels encode transparency without color information. Value of zero is
340 completely transparent; a value of 255 is completely opaque. Bitmap
341 pixels do not visibly draw, because its pixels have no color information.
342 When SkColorType is set to kAlpha_8_SkColorType, the paired SkAlphaType is
343 ignored.
Cary Clarkf895a422018-02-27 09:54:21 -0500344
Cary Clark682c58d2018-05-16 07:07:07 -0400345 #Example
346 #Description
347 Alpha pixels can modify another draw. orangePaint fills the bounds of bitmap,
348 with its transparency set to alpha8 pixel value.
349 ##
350 #Height 64
351 canvas->scale(16, 16);
352 SkBitmap bitmap;
353 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kAlpha_8_SkColorType, kOpaque_SkAlphaType);
354 bitmap.allocPixels(imageInfo);
355 SkCanvas offscreen(bitmap);
356 offscreen.clear(SK_ColorGREEN);
357 SkPaint orangePaint;
358 orangePaint.setARGB(0xFF, 0xFF, 0xA5, 0x00);
359 canvas->drawBitmap(bitmap, 0, 0, &orangePaint);
360 uint8_t alpha8[] = { 0xFF, 0xBB, 0x77, 0x33 };
361 SkPixmap alphaPixmap(imageInfo, &alpha8, imageInfo.minRowBytes());
362 if (bitmap.writePixels(alphaPixmap, 0, 0)) {
363 canvas->drawBitmap(bitmap, 2, 2, &orangePaint);
364 }
365 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400366 #SeeAlso Alpha Gray_8
Cary Clarkf895a422018-02-27 09:54:21 -0500367##
368
Cary Clark682c58d2018-05-16 07:07:07 -0400369#Subtopic RGB_565
Cary Clarkffb3d682018-05-17 12:17:28 -0400370#Line # encodes RGB in 16 bits ##
371 kRGB_565_SkColorType encodes RGB to fit in a 16-bit word. Red and blue
Cary Clark682c58d2018-05-16 07:07:07 -0400372 components use five bits describing 32 levels. Green components, more sensitive
373 to the eye, use six bits describing 64 levels. kRGB_565_SkColorType has no
374 bits for Alpha.
375
376 Pixels are fully opaque as if its Color_Alpha was set to one, and should
377 always be paired with kOpaque_SkAlphaType.
Cary Clarkf895a422018-02-27 09:54:21 -0500378
Cary Clark682c58d2018-05-16 07:07:07 -0400379 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500380
Cary Clark682c58d2018-05-16 07:07:07 -0400381 #Example
382 #Height 96
383 canvas->scale(16, 16);
384 SkBitmap bitmap;
385 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGB_565_SkColorType, kOpaque_SkAlphaType);
386 bitmap.allocPixels(imageInfo);
387 SkCanvas offscreen(bitmap);
388 offscreen.clear(SK_ColorGREEN);
389 canvas->drawBitmap(bitmap, 0, 0);
390 auto pack565 = [](unsigned r, unsigned g, unsigned b) -> uint16_t {
391 return (b << 0) | (g << 5) | (r << 11);
392 };
393 uint16_t red565[] = { pack565(0x1F, 0x00, 0x00), pack565(0x17, 0x00, 0x00),
394 pack565(0x0F, 0x00, 0x00), pack565(0x07, 0x00, 0x00) };
395 uint16_t blue565[] = { pack565(0x00, 0x00, 0x1F), pack565(0x00, 0x00, 0x17),
396 pack565(0x00, 0x00, 0x0F), pack565(0x00, 0x00, 0x07) };
397 SkPixmap redPixmap(imageInfo, &red565, imageInfo.minRowBytes());
398 if (bitmap.writePixels(redPixmap, 0, 0)) {
399 canvas->drawBitmap(bitmap, 2, 2);
400 }
401 SkPixmap bluePixmap(imageInfo, &blue565, imageInfo.minRowBytes());
402 if (bitmap.writePixels(bluePixmap, 0, 0)) {
403 canvas->drawBitmap(bitmap, 4, 4);
404 }
405 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400406 #SeeAlso ARGB_4444 RGBA_8888
Cary Clarkf895a422018-02-27 09:54:21 -0500407##
408
Cary Clark682c58d2018-05-16 07:07:07 -0400409#Subtopic ARGB_4444
Cary Clarkffb3d682018-05-17 12:17:28 -0400410#Line # encodes ARGB in 16 bits ##
411 kARGB_4444_SkColorType encodes ARGB to fit in 16-bit word. Each
Cary Clark682c58d2018-05-16 07:07:07 -0400412 component: alpha, blue, green, and red; use four bits, describing 16 levels.
413 Note that kARGB_4444_SkColorType is misnamed; the acronym does not
414 describe the actual component order.
Cary Clarkf895a422018-02-27 09:54:21 -0500415
Cary Clark682c58d2018-05-16 07:07:07 -0400416 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500417
Cary Clark682c58d2018-05-16 07:07:07 -0400418 If paired with kPremul_SkAlphaType: blue, green, and red components are
419 Premultiplied by the alpha value. If blue, green, or red is greater than alpha,
420 the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500421
Cary Clark682c58d2018-05-16 07:07:07 -0400422 If paired with kUnpremul_SkAlphaType: alpha, blue, green, and red components
Cary Clark77b3f3a2018-11-07 14:59:03 -0500423 may have any value. There may be a performance penalty with Unpremultiplied
Cary Clark682c58d2018-05-16 07:07:07 -0400424 pixels.
Cary Clarkf895a422018-02-27 09:54:21 -0500425
Cary Clark682c58d2018-05-16 07:07:07 -0400426 If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum;
427 blue, green, and red components are fully opaque. If any alpha component is
428 less than 15, the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500429
Cary Clark682c58d2018-05-16 07:07:07 -0400430 #Bug 7648
Cary Clarkf895a422018-02-27 09:54:21 -0500431
Cary Clark682c58d2018-05-16 07:07:07 -0400432 #Example
433 #Height 96
434 canvas->scale(16, 16);
435 SkBitmap bitmap;
436 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, kPremul_SkAlphaType);
437 bitmap.allocPixels(imageInfo);
438 SkCanvas offscreen(bitmap);
439 offscreen.clear(SK_ColorGREEN);
440 canvas->drawBitmap(bitmap, 0, 0);
441 auto pack4444 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint16_t {
442 return (a << 0) | (b << 4) | (g << 8) | (r << 12);
443 };
444 uint16_t red4444[] = { pack4444(0xF, 0xF, 0x0, 0x0), pack4444(0xF, 0xb, 0x0, 0x0),
445 pack4444(0xF, 0x7, 0x0, 0x0), pack4444(0xF, 0x3, 0x0, 0x0) };
446 uint16_t blue4444[] = { pack4444(0xF, 0x0, 0x0, 0xF), pack4444(0xF, 0x0, 0x0, 0xb),
447 pack4444(0xF, 0x0, 0x0, 0x7), pack4444(0xF, 0x0, 0x0, 0x3) };
448 SkPixmap redPixmap(imageInfo, &red4444, imageInfo.minRowBytes());
449 if (bitmap.writePixels(redPixmap, 0, 0)) {
450 canvas->drawBitmap(bitmap, 2, 2);
451 }
452 SkPixmap bluePixmap(imageInfo, &blue4444, imageInfo.minRowBytes());
453 if (bitmap.writePixels(bluePixmap, 0, 0)) {
454 canvas->drawBitmap(bitmap, 4, 4);
455 }
456 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400457 #SeeAlso RGBA_8888
Cary Clarkf895a422018-02-27 09:54:21 -0500458##
459
460#Subtopic RGBA_8888
Cary Clarkffb3d682018-05-17 12:17:28 -0400461#Line # encodes ARGB Big_Endian in 32 bits ##
462 kRGBA_8888_SkColorType encodes ARGB into a 32-bit word. Each component:
Cary Clark682c58d2018-05-16 07:07:07 -0400463 red, green, blue, alpha; use eight bits, describing 256 levels.
Cary Clarkf895a422018-02-27 09:54:21 -0500464
Cary Clark682c58d2018-05-16 07:07:07 -0400465 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500466
Cary Clark682c58d2018-05-16 07:07:07 -0400467 If paired with kPremul_SkAlphaType: red, green, and blue components are
468 Premultiplied by the alpha value. If red, green, or blue is greater than alpha,
469 the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500470
Cary Clark682c58d2018-05-16 07:07:07 -0400471 If paired with kUnpremul_SkAlphaType: alpha, red, green, and blue components
Cary Clark77b3f3a2018-11-07 14:59:03 -0500472 may have any value. There may be a performance penalty with Unpremultiplied
Cary Clark682c58d2018-05-16 07:07:07 -0400473 pixels.
Cary Clarkf895a422018-02-27 09:54:21 -0500474
Cary Clark682c58d2018-05-16 07:07:07 -0400475 If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum;
476 red, green, and blue components are fully opaque. If any alpha component is
477 less than 255, the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500478
Cary Clark682c58d2018-05-16 07:07:07 -0400479 On Big_Endian platforms, kRGBA_8888_SkColorType is the native Color_Type, and
480 will have the best performance. Use kN32_SkColorType to choose the best
481 Color_Type for the platform at compile time.
Cary Clarkf895a422018-02-27 09:54:21 -0500482
Cary Clark682c58d2018-05-16 07:07:07 -0400483 #Example
484 #Height 96
485 canvas->scale(16, 16);
486 SkBitmap bitmap;
487 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
488 bitmap.allocPixels(imageInfo);
489 SkCanvas offscreen(bitmap);
490 offscreen.clear(SK_ColorGREEN);
491 canvas->drawBitmap(bitmap, 0, 0);
492 auto pack8888 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint32_t {
493 return (r << 0) | (g << 8) | (b << 16) | (a << 24);
494 };
495 uint32_t red8888[] = { pack8888(0xFF, 0xFF, 0x0, 0x0), pack8888(0xFF, 0xbb, 0x0, 0x0),
496 pack8888(0xFF, 0x77, 0x0, 0x0), pack8888(0xFF, 0x33, 0x0, 0x0) };
497 uint32_t blue8888[] = { pack8888(0xFF, 0x0, 0x0, 0x0FF), pack8888(0xFF, 0x0, 0x0, 0x0bb),
498 pack8888(0xFF, 0x0, 0x0, 0x077), pack8888(0xFF, 0x0, 0x0, 0x033) };
499 SkPixmap redPixmap(imageInfo, &red8888, imageInfo.minRowBytes());
500 if (bitmap.writePixels(redPixmap, 0, 0)) {
501 canvas->drawBitmap(bitmap, 2, 2);
502 }
503 SkPixmap bluePixmap(imageInfo, &blue8888, imageInfo.minRowBytes());
504 if (bitmap.writePixels(bluePixmap, 0, 0)) {
505 canvas->drawBitmap(bitmap, 4, 4);
506 }
507 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400508 #SeeAlso RGB_888 BGRA_8888
Cary Clarkf895a422018-02-27 09:54:21 -0500509##
510
Cary Clark682c58d2018-05-16 07:07:07 -0400511#Subtopic RGB_888
Cary Clarkffb3d682018-05-17 12:17:28 -0400512#Line # encodes RGB in 32 bits ##
513 kRGB_888x_SkColorType encodes RGB into a 32-bit word. Each component:
Cary Clark682c58d2018-05-16 07:07:07 -0400514 red, green, blue; use eight bits, describing 256 levels. Eight bits are
515 unused. Pixels described by kRGB_888x_SkColorType are fully opaque as if
516 their Color_Alpha was set to one, and should always be paired with
517 kOpaque_SkAlphaType.
Cary Clarkf895a422018-02-27 09:54:21 -0500518
Cary Clark682c58d2018-05-16 07:07:07 -0400519 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500520
Cary Clark682c58d2018-05-16 07:07:07 -0400521 #Example
522 #Bug 7645
523 #Height 96
524 #Platform cpu
525 canvas->scale(16, 16);
526 SkBitmap bitmap;
527 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGB_888x_SkColorType, kOpaque_SkAlphaType);
528 bitmap.allocPixels(imageInfo);
529 SkCanvas offscreen(bitmap);
530 offscreen.clear(SK_ColorGREEN);
531 canvas->drawBitmap(bitmap, 0, 0);
532 auto pack888 = [](unsigned r, unsigned g, unsigned b) -> uint32_t {
533 return (r << 0) | (g << 8) | (b << 16);
534 };
535 uint32_t red888[] = { pack888(0xFF, 0x00, 0x00), pack888(0xbb, 0x00, 0x00),
536 pack888(0x77, 0x00, 0x00), pack888(0x33, 0x00, 0x00) };
537 uint32_t blue888[] = { pack888(0x00, 0x00, 0xFF), pack888(0x00, 0x00, 0xbb),
538 pack888(0x00, 0x00, 0x77), pack888(0x00, 0x00, 0x33) };
539 if (bitmap.installPixels(imageInfo, (void*) red888, imageInfo.minRowBytes())) {
540 canvas->drawBitmap(bitmap, 2, 2);
541 }
542 if (bitmap.installPixels(imageInfo, (void*) blue888, imageInfo.minRowBytes())) {
543 canvas->drawBitmap(bitmap, 4, 4);
544 }
545 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400546 #SeeAlso RGBA_8888 BGRA_8888
Cary Clarkf895a422018-02-27 09:54:21 -0500547##
548
549#Subtopic BGRA_8888
Cary Clarkffb3d682018-05-17 12:17:28 -0400550#Line # encodes ARGB Little_Endian in 32 bits ##
551 kBGRA_8888_SkColorType encodes ARGB into a 32-bit word. Each component:
Cary Clark682c58d2018-05-16 07:07:07 -0400552 blue, green, red, and alpha; use eight bits, describing 256 levels.
Cary Clarkf895a422018-02-27 09:54:21 -0500553
Cary Clark682c58d2018-05-16 07:07:07 -0400554 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500555
Cary Clark682c58d2018-05-16 07:07:07 -0400556 If paired with kPremul_SkAlphaType: blue, green, and red components are
557 Premultiplied by the alpha value. If blue, green, or red is greater than alpha,
558 the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500559
Cary Clark682c58d2018-05-16 07:07:07 -0400560 If paired with kUnpremul_SkAlphaType: blue, green, red, and alpha components
561 may have any value. There may be a performance penalty with Unpremultiplied
562 pixels.
Cary Clarkf895a422018-02-27 09:54:21 -0500563
Cary Clark682c58d2018-05-16 07:07:07 -0400564 If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum;
565 blue, green, and red components are fully opaque. If any alpha component is
566 less than 255, the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500567
Cary Clark682c58d2018-05-16 07:07:07 -0400568 On Little_Endian platforms, kBGRA_8888_SkColorType is the native Color_Type,
569 and will have the best performance. Use kN32_SkColorType to choose the best
570 Color_Type for the platform at compile time.
Cary Clarkf895a422018-02-27 09:54:21 -0500571
Cary Clark682c58d2018-05-16 07:07:07 -0400572 #Example
573 #Height 96
574 canvas->scale(16, 16);
575 SkBitmap bitmap;
576 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
577 bitmap.allocPixels(imageInfo);
578 SkCanvas offscreen(bitmap);
579 offscreen.clear(SK_ColorGREEN);
580 canvas->drawBitmap(bitmap, 0, 0);
581 auto pack8888 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint32_t {
582 return (b << 0) | (g << 8) | (r << 16) | (a << 24);
583 };
584 uint32_t red8888[] = { pack8888(0xFF, 0xFF, 0x0, 0x0), pack8888(0xFF, 0xbb, 0x0, 0x0),
585 pack8888(0xFF, 0x99, 0x0, 0x0), pack8888(0xFF, 0x55, 0x0, 0x0) };
586 uint32_t blue8888[] = { pack8888(0xFF, 0x0, 0x0, 0x0FF), pack8888(0xFF, 0x0, 0x0, 0x0bb),
587 pack8888(0xFF, 0x0, 0x0, 0x099), pack8888(0xFF, 0x0, 0x0, 0x055) };
588 SkPixmap redPixmap(imageInfo, &red8888, imageInfo.minRowBytes());
589 if (bitmap.writePixels(redPixmap, 0, 0)) {
590 canvas->drawBitmap(bitmap, 2, 2);
591 }
592 SkPixmap bluePixmap(imageInfo, &blue8888, imageInfo.minRowBytes());
593 if (bitmap.writePixels(bluePixmap, 0, 0)) {
594 canvas->drawBitmap(bitmap, 4, 4);
595 }
596 ##
597 #SeeAlso RGBA_8888
Cary Clarkf895a422018-02-27 09:54:21 -0500598##
599
600#Subtopic RGBA_1010102
Cary Clarkffb3d682018-05-17 12:17:28 -0400601#Line # encodes ARGB ten bits per color component ##
602 kRGBA_1010102_SkColorType encodes ARGB into a 32-bit word. Each
Cary Clark682c58d2018-05-16 07:07:07 -0400603 Color component: red, green, and blue; use ten bits, describing 1024 levels.
604 Two bits contain alpha, describing four levels. Possible alpha
605 values are zero: fully transparent; one: 33% opaque; two: 67% opaque;
606 three: fully opaque.
Cary Clarkf895a422018-02-27 09:54:21 -0500607
Cary Clark682c58d2018-05-16 07:07:07 -0400608 At present, Color in Paint does not provide enough precision to
609 draw all colors possible to a kRGBA_1010102_SkColorType Surface.
Cary Clarkf895a422018-02-27 09:54:21 -0500610
Cary Clark682c58d2018-05-16 07:07:07 -0400611 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500612
Cary Clark682c58d2018-05-16 07:07:07 -0400613 If paired with kPremul_SkAlphaType: red, green, and blue components are
614 Premultiplied by the alpha value. If red, green, or blue is greater than the
615 alpha replicated to ten bits, the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500616
Cary Clark682c58d2018-05-16 07:07:07 -0400617 If paired with kUnpremul_SkAlphaType: alpha, red, green, and blue components
618 may have any value. There may be a performance penalty with Unpremultiplied
619 pixels.
Cary Clarkf895a422018-02-27 09:54:21 -0500620
Cary Clark682c58d2018-05-16 07:07:07 -0400621 If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum;
622 red, green, and blue components are fully opaque. If any alpha component is
623 less than three, the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500624
Cary Clark682c58d2018-05-16 07:07:07 -0400625 #Example
626 #Bug 7645
627 #Height 96
628 #Platform cpu
629 canvas->scale(16, 16);
630 SkBitmap bitmap;
631 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGBA_1010102_SkColorType, kOpaque_SkAlphaType);
632 bitmap.allocPixels(imageInfo);
633 SkCanvas offscreen(bitmap);
634 offscreen.clear(SK_ColorGREEN);
635 canvas->drawBitmap(bitmap, 0, 0);
636 auto pack1010102 = [](unsigned r, unsigned g, unsigned b, unsigned a) -> uint32_t {
637 return (r << 0) | (g << 10) | (b << 20) | (a << 30);
638 };
639 uint32_t redBits[] = { pack1010102(0x3FF, 0x000, 0x000, 0x3),
640 pack1010102(0x2ff, 0x000, 0x000, 0x3),
641 pack1010102(0x1ff, 0x000, 0x000, 0x3),
642 pack1010102(0x0ff, 0x000, 0x000, 0x3) };
643 uint32_t blueBits[] = { pack1010102(0x000, 0x000, 0x3FF, 0x3),
644 pack1010102(0x000, 0x000, 0x2ff, 0x3),
645 pack1010102(0x000, 0x000, 0x1ff, 0x3),
646 pack1010102(0x000, 0x000, 0x0ff, 0x3) };
647 if (bitmap.installPixels(imageInfo, (void*) redBits, imageInfo.minRowBytes())) {
648 canvas->drawBitmap(bitmap, 2, 2);
649 }
650 SkPixmap bluePixmap(imageInfo, &blueBits, imageInfo.minRowBytes());
651 if (bitmap.installPixels(imageInfo, (void*) blueBits, imageInfo.minRowBytes())) {
652 canvas->drawBitmap(bitmap, 4, 4);
653 }
654 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400655 #SeeAlso RGB_101010 RGBA_8888
Cary Clarkf895a422018-02-27 09:54:21 -0500656##
657
Cary Clark682c58d2018-05-16 07:07:07 -0400658#Subtopic RGB_101010
Cary Clarkffb3d682018-05-17 12:17:28 -0400659#Line # encodes RGB ten bits per color component ##
660 kRGB_101010x_SkColorType encodes RGB into a 32-bit word. Each
Cary Clark682c58d2018-05-16 07:07:07 -0400661 Color component: red, green, and blue; use ten bits, describing 1024 levels.
662 Two bits are unused. Pixels described by kRGB_101010x_SkColorType are fully
663 opaque as if its Color_Alpha was set to one, and should always be paired
664 with kOpaque_SkAlphaType.
Cary Clarkf895a422018-02-27 09:54:21 -0500665
Cary Clark682c58d2018-05-16 07:07:07 -0400666 At present, Color in Paint does not provide enough precision to
667 draw all colors possible to a kRGB_101010x_SkColorType Surface.
Cary Clark681287e2018-03-16 11:34:15 -0400668
Cary Clark682c58d2018-05-16 07:07:07 -0400669 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500670
Cary Clark682c58d2018-05-16 07:07:07 -0400671 #Example
672 #Bug 7645
673 #Height 96
674 #Platform cpu
675 canvas->scale(16, 16);
676 SkBitmap bitmap;
677 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGB_101010x_SkColorType, kOpaque_SkAlphaType);
678 bitmap.allocPixels(imageInfo);
679 SkCanvas offscreen(bitmap);
680 offscreen.clear(SK_ColorGREEN);
681 canvas->drawBitmap(bitmap, 0, 0);
682 auto pack101010x = [](unsigned r, unsigned g, unsigned b) -> uint32_t {
683 return (r << 0) | (g << 10) | (b << 20);
684 };
685 uint32_t redBits[] = { pack101010x(0x3FF, 0x000, 0x000), pack101010x(0x2ff, 0x000, 0x000),
686 pack101010x(0x1ff, 0x000, 0x000), pack101010x(0x0ff, 0x000, 0x000) };
687 uint32_t blueBits[] = { pack101010x(0x000, 0x000, 0x3FF), pack101010x(0x000, 0x000, 0x2ff),
688 pack101010x(0x000, 0x000, 0x1ff), pack101010x(0x000, 0x000, 0x0ff) };
689 if (bitmap.installPixels(imageInfo, (void*) redBits, imageInfo.minRowBytes())) {
690 canvas->drawBitmap(bitmap, 2, 2);
691 }
692 SkPixmap bluePixmap(imageInfo, &blueBits, imageInfo.minRowBytes());
693 if (bitmap.installPixels(imageInfo, (void*) blueBits, imageInfo.minRowBytes())) {
694 canvas->drawBitmap(bitmap, 4, 4);
695 }
696 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400697 #SeeAlso RGBA_1010102
Cary Clarkf895a422018-02-27 09:54:21 -0500698##
699
700#Subtopic Gray_8
Cary Clark09d80c02018-10-31 12:14:03 -0400701#Line # encodes level of grayscale in 8 bits ##
702 kGray_8_SkColorType encodes grayscale level in eight bits that is equivalent
Cary Clark682c58d2018-05-16 07:07:07 -0400703 to equal values for red, blue, and green, representing colors from black to
704 white. Pixels described by kGray_8_SkColorType are fully
705 opaque as if its Color_Alpha was set to one, and should always be paired with
706 kOpaque_SkAlphaType.
Cary Clarkf895a422018-02-27 09:54:21 -0500707
Cary Clark682c58d2018-05-16 07:07:07 -0400708 #Example
709 #Height 64
710 canvas->scale(16, 16);
711 SkBitmap bitmap;
712 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kGray_8_SkColorType, kOpaque_SkAlphaType);
713 bitmap.allocPixels(imageInfo);
714 SkCanvas offscreen(bitmap);
715 offscreen.clear(SK_ColorGREEN);
716 canvas->drawBitmap(bitmap, 0, 0);
717 uint8_t gray8[] = { 0xFF, 0xBB, 0x77, 0x33 };
718 SkPixmap grayPixmap(imageInfo, &gray8, imageInfo.minRowBytes());
719 if (bitmap.writePixels(grayPixmap, 0, 0)) {
720 canvas->drawBitmap(bitmap, 2, 2);
721 }
722 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400723 #SeeAlso Alpha_8
Cary Clarkf895a422018-02-27 09:54:21 -0500724##
725
726#Subtopic RGBA_F16
Cary Clarkffb3d682018-05-17 12:17:28 -0400727#Line # encodes ARGB as half floats ##
728 kRGBA_F16_SkColorType encodes ARGB into a 64-bit word. Each component:
Cary Clark224c7002018-06-27 11:00:21 -0400729 blue, green, red, and alpha; use 16 bits, describing a floating point value,
Cary Clark929e4362018-06-19 09:07:28 -0400730 from -65500 to 65000 with 3.31 decimal digits of precision.
Cary Clarkf895a422018-02-27 09:54:21 -0500731
Cary Clark682c58d2018-05-16 07:07:07 -0400732 At present, Color in Paint does not provide enough precision or range to
733 draw all colors possible to a kRGBA_F16_SkColorType Surface.
Cary Clark681287e2018-03-16 11:34:15 -0400734
Cary Clark682c58d2018-05-16 07:07:07 -0400735 Each component encodes a floating point value using
736 #A Half floats # https://www.khronos.org/opengl/wiki/Small_Float_Formats ##
737 . Meaningful colors are represented by the range 0.0 to 1.0, although smaller
738 and larger values may be useful when used in combination with Transfer_Mode.
Cary Clark681287e2018-03-16 11:34:15 -0400739
Cary Clark682c58d2018-05-16 07:07:07 -0400740 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500741
Cary Clark682c58d2018-05-16 07:07:07 -0400742 If paired with kPremul_SkAlphaType: blue, green, and red components are
743 Premultiplied by the alpha value. If blue, green, or red is greater than alpha,
744 the drawn result is undefined.
Cary Clark681287e2018-03-16 11:34:15 -0400745
Cary Clark682c58d2018-05-16 07:07:07 -0400746 If paired with kUnpremul_SkAlphaType: blue, green, red, and alpha components
747 may have any value. There may be a performance penalty with Unpremultiplied
748 pixels.
Cary Clark681287e2018-03-16 11:34:15 -0400749
Cary Clark682c58d2018-05-16 07:07:07 -0400750 If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum;
751 blue, green, and red components are fully opaque. If any alpha component is
Cary Clark224c7002018-06-27 11:00:21 -0400752 less than one, the drawn result is undefined.
Cary Clark681287e2018-03-16 11:34:15 -0400753
Cary Clark682c58d2018-05-16 07:07:07 -0400754 #ToDo
755 FloatToHalf should be replaced with SkFloatToHalf if/when that's made public
756 ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500757
Cary Clark682c58d2018-05-16 07:07:07 -0400758 #Example
759 #Height 96
760 #Function
761 union FloatUIntUnion {
762 uint32_t fUInt;
763 float fFloat;
Cary Clarkf895a422018-02-27 09:54:21 -0500764 };
Cary Clark682c58d2018-05-16 07:07:07 -0400765
766 uint16_t FloatToHalf(float f) {
767 static const FloatUIntUnion magic = { 15 << 23 };
768 static const uint32_t round_mask = ~0xfffu;
769 FloatUIntUnion floatUnion;
770 floatUnion.fFloat = f;
771 uint32_t sign = floatUnion.fUInt & 0x80000000u;
772 floatUnion.fUInt ^= sign;
773 floatUnion.fUInt &= round_mask;
774 floatUnion.fFloat *= magic.fFloat;
775 floatUnion.fUInt -= round_mask;
776 return (floatUnion.fUInt >> 13) | (sign >> 16);
Cary Clarkf895a422018-02-27 09:54:21 -0500777 }
Cary Clark682c58d2018-05-16 07:07:07 -0400778 ##
779
780 void draw(SkCanvas* canvas) {
781 canvas->scale(16, 16);
782 SkBitmap bitmap;
783 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
784 bitmap.allocPixels(imageInfo);
785 SkCanvas offscreen(bitmap);
786 offscreen.clear(SK_ColorGREEN);
787 canvas->drawBitmap(bitmap, 0, 0);
788 auto H = [](float c) -> uint16_t {
789 return FloatToHalf(c);
790 };
791 // R G B A
Cary Clark224c7002018-06-27 11:00:21 -0400792 uint16_t red_f16[][4] = { { H(1.0), H(0.0), H(0.0), H(1.0) },
793 { H(.75), H(0.0), H(0.0), H(1.0) },
794 { H(.50), H(0.0), H(0.0), H(1.0) },
795 { H(.25), H(0.0), H(0.0), H(1.0) } };
796 uint16_t blue_f16[][4] = { { H(0.0), H(0.0), H(1.0), H(1.0) },
797 { H(0.0), H(0.0), H(.75), H(1.0) },
798 { H(0.0), H(0.0), H(.50), H(1.0) },
799 { H(0.0), H(0.0), H(.25), H(1.0) } };
Cary Clark682c58d2018-05-16 07:07:07 -0400800 SkPixmap redPixmap(imageInfo, red_f16, imageInfo.minRowBytes());
801 if (bitmap.writePixels(redPixmap, 0, 0)) {
802 canvas->drawBitmap(bitmap, 2, 2);
803 }
804 SkPixmap bluePixmap(imageInfo, blue_f16, imageInfo.minRowBytes());
805 if (bitmap.writePixels(bluePixmap, 0, 0)) {
806 canvas->drawBitmap(bitmap, 4, 4);
807 }
Cary Clarkf895a422018-02-27 09:54:21 -0500808 }
Cary Clark682c58d2018-05-16 07:07:07 -0400809 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400810 #SeeAlso SkColor4f
Cary Clarkf895a422018-02-27 09:54:21 -0500811##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500812
Cary Clark224c7002018-06-27 11:00:21 -0400813#Subtopic RGBA_F32
814#Line # encodes ARGB as single precision floats ##
815 kRGBA_F32_SkColorType encodes ARGB into a 128-bit word. Each component:
816 blue, green, red, and alpha; use 32 bits, describing a floating point value,
817 from -3.402823e+38 to 3.402823e+38 with 7.225 decimal digits of precision.
818
819 At present, Color in Paint does not provide enough precision or range to
820 draw all colors possible to a kRGBA_F32_SkColorType Surface.
821
822 Each component encodes a floating point value using
823 #A single-precision floats # https://en.wikipedia.org/wiki/Single-precision_floating-point_format ##
824 . Meaningful colors are represented by the range 0.0 to 1.0, although smaller
825 and larger values may be useful when used in combination with Transfer_Mode.
826
827 #Illustration
828
829 If paired with kPremul_SkAlphaType: blue, green, and red components are
830 Premultiplied by the alpha value. If blue, green, or red is greater than alpha,
831 the drawn result is undefined.
832
833 If paired with kUnpremul_SkAlphaType: blue, green, red, and alpha components
834 may have any value. There may be a performance penalty with Unpremultiplied
835 pixels.
836
837 If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum;
838 blue, green, and red components are fully opaque. If any alpha component is
839 less than one, the drawn result is undefined.
840
841 #NoExample
Cary Clark61313f32018-10-08 14:57:48 -0400842 canvas->scale(16, 16);
843 SkBitmap bitmap;
844 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGBA_F32_SkColorType, kPremul_SkAlphaType);
845 bitmap.allocPixels(imageInfo);
846 SkCanvas offscreen(bitmap);
847 offscreen.clear(SK_ColorGREEN);
848 canvas->drawBitmap(bitmap, 0, 0);
849 // R G B A
850 float red_f32[][4] = { { 1.0, 0.0, 0.0, 1.0 },
851 { .75, 0.0, 0.0, 1.0 },
852 { .50, 0.0, 0.0, 1.0 },
853 { .25, 0.0, 0.0, 1.0 } };
854 float blue_f32[][4] = { { 0.0, 0.0, 1.0, 1.0 },
855 { 0.0, 0.0, .75, 1.0 },
856 { 0.0, 0.0, .50, 1.0 },
857 { 0.0, 0.0, .25, 1.0 } };
858 SkPixmap redPixmap(imageInfo, red_f32, imageInfo.minRowBytes());
859 if (bitmap.writePixels(redPixmap, 0, 0)) {
860 canvas->drawBitmap(bitmap, 2, 2);
861 }
862 SkPixmap bluePixmap(imageInfo, blue_f32, imageInfo.minRowBytes());
863 if (bitmap.writePixels(bluePixmap, 0, 0)) {
864 canvas->drawBitmap(bitmap, 4, 4);
Cary Clark224c7002018-06-27 11:00:21 -0400865 }
866 ##
867 #SeeAlso SkColor4f
868##
869
870
Cary Clark08895c42018-02-01 09:37:32 -0500871#Subtopic Color_Type ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500872
873# ------------------------------------------------------------------------------
Cary Clark681287e2018-03-16 11:34:15 -0400874
875#Method int SkColorTypeBytesPerPixel(SkColorType ct)
876#In Property
877#Line # returns Color_Type byte size ##
Cary Clark09d80c02018-10-31 12:14:03 -0400878#Populate
Cary Clark681287e2018-03-16 11:34:15 -0400879
880#Example
881#Height 192
882 const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
883 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" };
884 SkPaint paint;
885 paint.setTypeface(SkTypeface::MakeFromName("monospace", SkFontStyle()));
886 paint.setAntiAlias(true);
887 paint.setTextSize(10);
888 int y = 15;
889 canvas->drawString(" colorType bytes", 10, y, paint);
890 for (SkColorType colorType : { #list_of_color_types#
891 } ) {
892 int result = SkColorTypeBytesPerPixel(colorType);
893 SkString string;
894 string.printf("%13s %4d", colors[(int) colorType], result);
895 canvas->drawString(string, 10, y += 14, paint);
896 }
897##
898#SeeAlso SkImageInfo::bytesPerPixel
899##
900
901# ------------------------------------------------------------------------------
902
903#Method bool SkColorTypeIsAlwaysOpaque(SkColorType ct)
904#In Property
905#Line # returns if Color_Type includes Color_Alpha ##
Cary Clark09d80c02018-10-31 12:14:03 -0400906#Populate
Cary Clark681287e2018-03-16 11:34:15 -0400907
908#Example
909#Height 192
910 const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
911 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" };
912 SkPaint paint;
913 paint.setTypeface(SkTypeface::MakeFromName("monospace", SkFontStyle()));
914 paint.setAntiAlias(true);
915 paint.setTextSize(10);
916 int y = 15;
917 canvas->drawString(" colorType bytes", 10, y, paint);
918 for (SkColorType colorType : { #list_of_color_types#
919 } ) {
920 bool result = SkColorTypeIsAlwaysOpaque(colorType);
921 SkString string;
922 string.printf("%13s %6s", colors[(int) colorType], result ? "true" : "false");
923 canvas->drawString(string, 10, y += 14, paint);
924 }
925##
926#SeeAlso SkColorTypeValidateAlphaType
927##
928
929# ------------------------------------------------------------------------------
930
931#Method bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType,
932 SkAlphaType* canonical = nullptr)
933#In Property
934#Line # returns if Alpha_Type is valid ##
Cary Clark09d80c02018-10-31 12:14:03 -0400935#Populate
Cary Clark681287e2018-03-16 11:34:15 -0400936
937#Example
938#Height 640
939 const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
940 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" };
941 const char* alphas[] = {"Unknown ", "Opaque ", "Premul ", "Unpremul"};
942 SkAlphaType alphaTypes[] = { #list_of_alpha_types#
943 };
944 SkPaint paint;
945 paint.setTypeface(SkTypeface::MakeFromName("monospace", SkFontStyle()));
946 paint.setAntiAlias(true);
947 paint.setTextSize(10);
948 int y = 15;
949 canvas->drawString(" colorType alphaType canonical", 10, y, paint);
950 for (SkColorType colorType : { #list_of_color_types#
951 } ) {
952 for (SkAlphaType alphaType : alphaTypes) {
953 SkAlphaType canonicalAlphaType = kUnknown_SkAlphaType;
954 bool result = SkColorTypeValidateAlphaType(colorType, alphaType, &canonicalAlphaType);
955 SkString string;
956 string.printf("%13s %10s %10s", colors[(int) colorType], alphas[(int) alphaType],
957 result ? alphas[(int) canonicalAlphaType] : "------ ");
958 canvas->drawString(string, 10, y += 14, paint);
959 }
960 }
961##
962#SeeAlso SkColorTypeIsAlwaysOpaque
963##
964
965# ------------------------------------------------------------------------------
Cary Clark772953472018-02-12 09:38:08 -0500966#Subtopic YUV_ColorSpace
Cary Clark682c58d2018-05-16 07:07:07 -0400967#Line # color range of YUV pixels ##
Cary Clark137b8742018-05-30 09:21:49 -0400968#Alias YUV_ColorSpace ##
969
Cary Clark2dc84ad2018-01-26 12:56:22 -0500970#Enum SkYUVColorSpace
Cary Clark06c20f32018-03-20 15:53:27 -0400971#Line # color range of YUV pixels ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500972
973#Code
Cary Clark61313f32018-10-08 14:57:48 -0400974#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -0500975##
976
Cary Clark06c20f32018-03-20 15:53:27 -0400977Describes color range of YUV pixels. The color mapping from YUV to RGB varies
978depending on the source. YUV pixels may be generated by JPEG images, standard
979video streams, or high definition video streams. Each has its own mapping from
980YUV and RGB.
981
982JPEG YUV values encode the full range of 0 to 255 for all three components.
983Video YUV values range from 16 to 235 for all three components. Details of
Cary Clark682c58d2018-05-16 07:07:07 -0400984encoding and conversion to RGB are described in
Cary Clark06c20f32018-03-20 15:53:27 -0400985#A YCbCr color space # https://en.wikipedia.org/wiki/YCbCr ##
986.
Cary Clark2dc84ad2018-01-26 12:56:22 -0500987
988#Const kJPEG_SkYUVColorSpace 0
Cary Clark682c58d2018-05-16 07:07:07 -0400989#Line # describes full range ##
990Describes standard JPEG color space;
Cary Clark06c20f32018-03-20 15:53:27 -0400991#A CCIR 601 # https://en.wikipedia.org/wiki/Rec._601 ##
992with full range of 0 to 255 for components.
Cary Clark2dc84ad2018-01-26 12:56:22 -0500993##
994#Const kRec601_SkYUVColorSpace 1
Cary Clark682c58d2018-05-16 07:07:07 -0400995#Line # describes SDTV range ##
996Describes standard used by standard definition television;
Cary Clark06c20f32018-03-20 15:53:27 -0400997#A CCIR 601 # https://en.wikipedia.org/wiki/Rec._601 ##
998with studio range of 16 to 235 range for components.
Cary Clark2dc84ad2018-01-26 12:56:22 -0500999##
1000#Const kRec709_SkYUVColorSpace 2
Cary Clark682c58d2018-05-16 07:07:07 -04001001#Line # describes HDTV range ##
1002Describes standard used by high definition television;
1003#A Rec. 709 # https://en.wikipedia.org/wiki/Rec._709 ##
Cary Clark06c20f32018-03-20 15:53:27 -04001004with studio range of 16 to 235 range for components.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001005##
Cary Clark682c58d2018-05-16 07:07:07 -04001006#Const kLastEnum_SkYUVColorSpace 2
1007#Line # last valid value ##
1008 Used by tests to iterate through all valid values.
1009##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001010
Cary Clark06c20f32018-03-20 15:53:27 -04001011#NoExample
Cary Clark2dc84ad2018-01-26 12:56:22 -05001012##
1013
Cary Clark06c20f32018-03-20 15:53:27 -04001014#SeeAlso SkImage::MakeFromYUVTexturesCopy SkImage::MakeFromNV12TexturesCopy
Cary Clark2dc84ad2018-01-26 12:56:22 -05001015
1016#Enum SkYUVColorSpace ##
Cary Clark772953472018-02-12 09:38:08 -05001017#Subtopic YUV_ColorSpace ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001018
1019# ------------------------------------------------------------------------------
Cary Clark2dc84ad2018-01-26 12:56:22 -05001020
1021#Struct SkImageInfo
1022
Cary Clark61313f32018-10-08 14:57:48 -04001023#Code
1024#Populate
1025##
1026
Cary Clark77b3f3a2018-11-07 14:59:03 -05001027Describes pixel dimensions and encoding. Bitmap, Image, Pixmap, and Surface
Cary Clark1a8d7622018-03-05 13:26:16 -05001028can be created from Image_Info. Image_Info can be retrieved from Bitmap and
1029Pixmap, but not from Image and Surface. For example, Image and Surface
1030implementations may defer pixel depth, so may not completely specify Image_Info.
1031
1032Image_Info contains dimensions, the pixel integral width and height. It encodes
1033how pixel bits describe Color_Alpha, transparency; Color components red, blue,
1034and green; and Color_Space, the range and linearity of colors.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001035
Cary Clark2dc84ad2018-01-26 12:56:22 -05001036# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05001037
Cary Clark2dc84ad2018-01-26 12:56:22 -05001038#Method SkImageInfo()
1039
Cary Clark61313f32018-10-08 14:57:48 -04001040#In Constructors
Cary Clark82f1f742018-06-28 08:50:35 -04001041#Line # creates with zeroed dimensions, kUnknown_SkColorType, kUnknown_SkAlphaType ##
Cary Clark09d80c02018-10-31 12:14:03 -04001042#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001043
1044#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001045#Height 32
1046#Description
1047An empty Image_Info may be passed to SkCanvas::accessTopLayerPixels as storage
1048for the Canvas actual Image_Info.
1049##
1050 SkImageInfo imageInfo;
1051 size_t rowBytes;
1052 SkIPoint origin;
Cary Clark681287e2018-03-16 11:34:15 -04001053 (void) canvas->accessTopLayerPixels(&imageInfo, &rowBytes, &origin);
Cary Clark1a8d7622018-03-05 13:26:16 -05001054 const char* alphaType[] = { "Unknown", "Opaque", "Premul", "Unpremul" };
1055 SkString string;
1056 string.printf("k%s_SkAlphaType", alphaType[(int) imageInfo.alphaType()]);
1057 SkPaint paint;
1058 canvas->drawString(string, 20, 20, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001059##
1060
Cary Clark1a8d7622018-03-05 13:26:16 -05001061#SeeAlso Make MakeN32 MakeS32 MakeA8
Cary Clark2dc84ad2018-01-26 12:56:22 -05001062
1063#Method ##
1064
1065# ------------------------------------------------------------------------------
1066
1067#Method static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at,
1068 sk_sp<SkColorSpace> cs = nullptr)
Cary Clark61313f32018-10-08 14:57:48 -04001069#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001070#Line # creates Image_Info from dimensions, Color_Type, Alpha_Type, Color_Space ##
Cary Clark09d80c02018-10-31 12:14:03 -04001071#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001072
1073#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001074#Height 48
1075 uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 },
1076 { 0xAC, 0xA8, 0x89, 0xA7, 0x87 },
1077 { 0x9B, 0xB5, 0xE5, 0x95, 0x46 },
1078 { 0x90, 0x81, 0xC5, 0x71, 0x33 },
1079 { 0x75, 0x55, 0x44, 0x40, 0x30 }};
1080 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType);
1081 SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
1082 SkBitmap bitmap;
1083 bitmap.installPixels(pixmap);
1084 canvas->scale(8, 8);
1085 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001086##
1087
Cary Clark1a8d7622018-03-05 13:26:16 -05001088#SeeAlso MakeN32 MakeN32Premul MakeS32 MakeA8
Cary Clark2dc84ad2018-01-26 12:56:22 -05001089
1090#Method ##
1091
1092# ------------------------------------------------------------------------------
1093
1094#Method static SkImageInfo MakeN32(int width, int height, SkAlphaType at,
1095 sk_sp<SkColorSpace> cs = nullptr)
Cary Clark61313f32018-10-08 14:57:48 -04001096#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001097#Line # creates Image_Info with Native_Color_Type ##
Cary Clark09d80c02018-10-31 12:14:03 -04001098#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001099
1100#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001101#Height 128
1102 SkBitmap bitmap;
1103 bitmap.allocPixels(SkImageInfo::MakeN32(16, 16, kPremul_SkAlphaType));
1104 SkCanvas offscreen(bitmap);
1105 offscreen.clear(SK_ColorWHITE);
1106 SkPaint paint;
1107 offscreen.drawString("g", 0, 10, paint);
1108 canvas->scale(8, 8);
1109 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001110##
1111
Cary Clark1a8d7622018-03-05 13:26:16 -05001112#SeeAlso Make MakeN32Premul MakeS32 MakeA8
Cary Clark2dc84ad2018-01-26 12:56:22 -05001113
1114#Method ##
1115
1116# ------------------------------------------------------------------------------
1117
1118#Method static SkImageInfo MakeS32(int width, int height, SkAlphaType at)
1119
Cary Clark61313f32018-10-08 14:57:48 -04001120#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001121#Line # creates Image_Info with Native_Color_Type, sRGB Color_Space ##
Cary Clark09d80c02018-10-31 12:14:03 -04001122#Populate
Cary Clark1a8d7622018-03-05 13:26:16 -05001123
1124#Example
1125#Set sRGB
1126#Height 128
1127#Description
Cary Clark682c58d2018-05-16 07:07:07 -04001128Top gradient is drawn to offScreen without Color_Space. It is darker than middle
1129gradient, drawn to offScreen with sRGB Color_Space. Bottom gradient shares bits
Cary Clark1a8d7622018-03-05 13:26:16 -05001130with middle, but does not specify the Color_Space in noColorSpaceBitmap. A source
1131without Color_Space is treated as sRGB; the bottom gradient is identical to the
1132middle gradient.
1133##
1134 const int width = 256;
1135 const int height = 32;
1136 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
1137 SkColor gradColors[] = { 0xFFAA0055, 0xFF11CC88 };
1138 SkPoint gradPoints[] = { { 0, 0 }, { width, 0 } };
1139 SkPaint gradPaint;
1140 gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1141 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1142 SkBitmap bitmap;
1143 bitmap.allocPixels(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType));
Cary Clark682c58d2018-05-16 07:07:07 -04001144 SkCanvas offScreen(bitmap);
1145 offScreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
Cary Clark1a8d7622018-03-05 13:26:16 -05001146 canvas->drawBitmap(bitmap, 0, 0);
1147 bitmap.allocPixels(SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType));
1148 SkCanvas sRGBOffscreen(bitmap);
1149 sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1150 canvas->drawBitmap(bitmap, 0, 48);
1151 SkBitmap noColorSpaceBitmap;
1152 noColorSpaceBitmap.setInfo(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType));
1153 noColorSpaceBitmap.setPixels(bitmap.getAddr(0, 0));
1154 canvas->drawBitmap(noColorSpaceBitmap, 0, 96);
1155##
1156
1157#SeeAlso Make MakeN32 MakeN32Premul MakeA8
Cary Clark2dc84ad2018-01-26 12:56:22 -05001158
1159#Method ##
1160
1161# ------------------------------------------------------------------------------
1162
1163#Method static SkImageInfo MakeN32Premul(int width, int height, sk_sp<SkColorSpace> cs = nullptr)
1164
Cary Clark61313f32018-10-08 14:57:48 -04001165#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001166#Line # creates Image_Info with Native_Color_Type, kPremul_SkAlphaType ##
Cary Clark09d80c02018-10-31 12:14:03 -04001167#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001168
1169#Example
Cary Clark06c20f32018-03-20 15:53:27 -04001170#Height 128
Cary Clark1a8d7622018-03-05 13:26:16 -05001171 SkBitmap bitmap;
1172 bitmap.allocPixels(SkImageInfo::MakeN32Premul(18, 18));
1173 SkCanvas offscreen(bitmap);
1174 offscreen.clear(SK_ColorWHITE);
1175 SkPaint paint;
1176 paint.setAntiAlias(true);
1177 paint.setTextSize(15);
1178 offscreen.drawString("\xF0\x9F\x98\xB8", 1, 15, paint);
1179 canvas->scale(6, 6);
1180 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001181##
1182
Cary Clark1a8d7622018-03-05 13:26:16 -05001183#SeeAlso MakeN32 MakeS32 MakeA8 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001184
1185#Method ##
1186
1187# ------------------------------------------------------------------------------
1188
1189#Method static SkImageInfo MakeN32Premul(const SkISize& size)
1190
Cary Clark61313f32018-10-08 14:57:48 -04001191#In Constructors
Cary Clark09d80c02018-10-31 12:14:03 -04001192#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001193
1194#Example
Cary Clark06c20f32018-03-20 15:53:27 -04001195#Height 128
Cary Clark1a8d7622018-03-05 13:26:16 -05001196 SkBitmap bitmap;
1197 bitmap.allocPixels(SkImageInfo::MakeN32Premul({18, 18}));
1198 SkCanvas offscreen(bitmap);
1199 offscreen.clear(SK_ColorWHITE);
1200 SkPaint paint;
1201 paint.setAntiAlias(true);
1202 paint.setTextSize(15);
1203 offscreen.drawString("\xF0\x9F\x98\xB9", 1, 15, paint);
1204 canvas->scale(6, 6);
1205 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001206##
1207
Cary Clark682c58d2018-05-16 07:07:07 -04001208#SeeAlso MakeN32 MakeS32 MakeA8 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001209
1210#Method ##
1211
1212# ------------------------------------------------------------------------------
1213
1214#Method static SkImageInfo MakeA8(int width, int height)
1215
Cary Clark61313f32018-10-08 14:57:48 -04001216#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001217#Line # creates Image_Info with kAlpha_8_SkColorType, kPremul_SkAlphaType ##
Cary Clark09d80c02018-10-31 12:14:03 -04001218#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001219
1220#Example
Cary Clark681287e2018-03-16 11:34:15 -04001221#Height 64
1222 uint8_t pixels[][8] = { { 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00},
1223 { 0x00, 0x7f, 0xff, 0x3f, 0x3f, 0x7f, 0x3f, 0x00},
1224 { 0x3f, 0xff, 0x7f, 0x00, 0x7f, 0xff, 0x7f, 0x00},
1225 { 0x00, 0x3f, 0x00, 0x00, 0x3f, 0x7f, 0x3f, 0x00},
1226 { 0x3f, 0x7f, 0x7f, 0x3f, 0x00, 0x00, 0x00, 0x00},
1227 { 0x7f, 0xff, 0xff, 0x7f, 0x00, 0x3f, 0x7f, 0x3f},
1228 { 0x7f, 0xff, 0xff, 0x7f, 0x00, 0x7f, 0xff, 0x7f},
1229 { 0x3f, 0x7f, 0x7f, 0x3f, 0x00, 0x3f, 0x7f, 0x3f} };
1230 SkBitmap bitmap;
1231 bitmap.installPixels(SkImageInfo::MakeA8(8, 8),
1232 (void*) pixels, sizeof(pixels[0]));
1233 SkPaint paint;
1234 canvas->scale(4, 4);
1235 for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) {
1236 paint.setColor(color);
1237 canvas->drawBitmap(bitmap, 0, 0, &paint);
1238 canvas->translate(12, 0);
1239 }
Cary Clark2dc84ad2018-01-26 12:56:22 -05001240##
1241
Cary Clark1a8d7622018-03-05 13:26:16 -05001242#SeeAlso MakeN32 MakeS32 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001243
1244#Method ##
1245
1246# ------------------------------------------------------------------------------
1247
1248#Method static SkImageInfo MakeUnknown(int width, int height)
1249
Cary Clark61313f32018-10-08 14:57:48 -04001250#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001251#Line # creates Image_Info with kUnknown_SkColorType, kUnknown_SkAlphaType ##
Cary Clark09d80c02018-10-31 12:14:03 -04001252#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001253
1254#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001255#Height 32
1256#Width 384
1257SkImageInfo info; // default constructor
1258SkString string;
1259string.printf("SkImageInfo() %c= SkImageInfo::MakeUnknown(0, 0)",
1260 info == SkImageInfo::MakeUnknown(0, 0) ? '=' : '!');
1261SkPaint paint;
1262canvas->drawString(string, 0, 12, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001263##
1264
Cary Clark1a8d7622018-03-05 13:26:16 -05001265#SeeAlso SkImageInfo() MakeN32 MakeS32 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001266
1267#Method ##
1268
1269# ------------------------------------------------------------------------------
1270
1271#Method static SkImageInfo MakeUnknown()
1272
Cary Clark61313f32018-10-08 14:57:48 -04001273#In Constructors
Cary Clark09d80c02018-10-31 12:14:03 -04001274#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001275
1276#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001277#Height 32
1278#Width 384
1279SkImageInfo info; // default constructor
1280SkString string;
1281string.printf("SkImageInfo() %c= SkImageInfo::MakeUnknown()",
1282 info == SkImageInfo::MakeUnknown() ? '=' : '!');
1283SkPaint paint;
1284canvas->drawString(string, 0, 12, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001285##
1286
Cary Clark1a8d7622018-03-05 13:26:16 -05001287#SeeAlso SkImageInfo() MakeN32 MakeS32 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001288
1289#Method ##
1290
Cary Clark2dc84ad2018-01-26 12:56:22 -05001291
1292# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05001293#Subtopic Property
Cary Clark78de7512018-02-07 07:27:09 -05001294#Line # metrics and attributes ##
1295##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001296
1297#Method int width() const
Cary Clark78de7512018-02-07 07:27:09 -05001298#In Property
Cary Clark1a8d7622018-03-05 13:26:16 -05001299#Line # returns pixel column count ##
Cary Clark09d80c02018-10-31 12:14:03 -04001300#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001301
1302#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001303#Image 4
1304#Height 96
1305 canvas->translate(10, 10);
1306 canvas->drawBitmap(source, 0, 0);
1307 SkImageInfo imageInfo = source.info();
1308 canvas->translate(0, imageInfo.height());
1309 SkPaint paint;
Cary Clark1a8d7622018-03-05 13:26:16 -05001310 canvas->drawLine(0, 10, imageInfo.width(), 10, paint);
Cary Clark14768f62018-10-29 20:33:51 -04001311 canvas->drawString("width", imageInfo.width() / 2 - 15, 25, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001312##
1313
Cary Clark1a8d7622018-03-05 13:26:16 -05001314#SeeAlso height SkBitmap::width SkPixelRef::width SkImage::width SkSurface::width
Cary Clark2dc84ad2018-01-26 12:56:22 -05001315
1316#Method ##
1317
1318# ------------------------------------------------------------------------------
1319
1320#Method int height() const
Cary Clark78de7512018-02-07 07:27:09 -05001321#In Property
Cary Clark1a8d7622018-03-05 13:26:16 -05001322#Line # returns pixel row count ##
Cary Clark09d80c02018-10-31 12:14:03 -04001323#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001324
1325#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001326#Image 4
1327#Height 96
1328 canvas->translate(10, 20);
1329 canvas->drawBitmap(source, 0, 0);
1330 SkImageInfo imageInfo = source.info();
1331 SkPaint paint;
Cary Clark1a8d7622018-03-05 13:26:16 -05001332 canvas->drawLine(imageInfo.width() + 10, 0, imageInfo.width() + 10, imageInfo.height(), paint);
Cary Clark14768f62018-10-29 20:33:51 -04001333 canvas->drawString("height", imageInfo.width() + 15, imageInfo.height() / 2, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001334##
1335
Cary Clark1a8d7622018-03-05 13:26:16 -05001336#SeeAlso width SkBitmap::height SkPixelRef::height SkImage::height SkSurface::height
Cary Clark2dc84ad2018-01-26 12:56:22 -05001337
1338#Method ##
1339
1340# ------------------------------------------------------------------------------
1341
1342#Method SkColorType colorType() const
Cary Clark78de7512018-02-07 07:27:09 -05001343#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001344#Line # returns Color_Type ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001345Returns Color_Type, one of: #list_of_color_types#.
1346
1347#Return Color_Type ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001348
1349#Example
Cary Clark681287e2018-03-16 11:34:15 -04001350 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
1351 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
1352 SkImageInfo info = SkImageInfo::MakeA8(16, 32);
1353 SkDebugf("color type: k" "%s" "_SkColorType\n", colors[info.colorType()]);
1354#StdOut
1355color type: kAlpha_8_SkColorType
1356##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001357##
1358
Cary Clark681287e2018-03-16 11:34:15 -04001359#SeeAlso alphaType SkPixmap::colorType SkBitmap::colorType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001360
1361#Method ##
1362
1363# ------------------------------------------------------------------------------
1364
1365#Method SkAlphaType alphaType() const
Cary Clark78de7512018-02-07 07:27:09 -05001366#In Property
Cary Clark682c58d2018-05-16 07:07:07 -04001367#Line # returns Alpha_Type ##
Cary Clark681287e2018-03-16 11:34:15 -04001368Returns Alpha_Type, one of: #list_of_alpha_types#.
1369
1370#Return Alpha_Type ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001371
1372#Example
Cary Clark681287e2018-03-16 11:34:15 -04001373 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
1374 SkImageInfo info = SkImageInfo::MakeA8(16, 32);
1375 SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[info.alphaType()]);
1376#StdOut
1377alpha type: kPremul_SkAlphaType
1378##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001379##
1380
Cary Clark681287e2018-03-16 11:34:15 -04001381#SeeAlso colorType SkPixmap::alphaType SkBitmap::alphaType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001382
1383#Method ##
1384
1385# ------------------------------------------------------------------------------
1386
1387#Method SkColorSpace* colorSpace() const
Cary Clark78de7512018-02-07 07:27:09 -05001388#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001389#Line # returns Color_Space ##
Cary Clark09d80c02018-10-31 12:14:03 -04001390#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001391
1392#Example
Cary Clark681287e2018-03-16 11:34:15 -04001393#Description
1394SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma
1395and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma.
1396##
Cary Clark682c58d2018-05-16 07:07:07 -04001397 SkImageInfo info = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
Cary Clark681287e2018-03-16 11:34:15 -04001398 SkColorSpace::MakeSRGBLinear());
1399 SkColorSpace* colorSpace = info.colorSpace();
1400 SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
1401 colorSpace->gammaCloseToSRGB() ? "true" : "false",
1402 colorSpace->gammaIsLinear() ? "true" : "false",
1403 colorSpace->isSRGB() ? "true" : "false");
1404#StdOut
1405gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
1406##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001407##
1408
Cary Clark681287e2018-03-16 11:34:15 -04001409#SeeAlso Color_Space SkPixmap::colorSpace SkBitmap::colorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001410
1411#Method ##
1412
1413# ------------------------------------------------------------------------------
1414
1415#Method sk_sp<SkColorSpace> refColorSpace() const
Cary Clark78de7512018-02-07 07:27:09 -05001416#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001417#Line # returns Color_Space ##
Cary Clark09d80c02018-10-31 12:14:03 -04001418#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001419
1420#Example
Cary Clark682c58d2018-05-16 07:07:07 -04001421 SkImageInfo info1 = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
Cary Clark681287e2018-03-16 11:34:15 -04001422 SkColorSpace::MakeSRGBLinear());
1423 SkImageInfo info2 = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
1424 info1.refColorSpace());
1425 SkColorSpace* colorSpace = info2.colorSpace();
1426 SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
1427 colorSpace->gammaCloseToSRGB() ? "true" : "false",
1428 colorSpace->gammaIsLinear() ? "true" : "false",
1429 colorSpace->isSRGB() ? "true" : "false");
Cary Clark2dc84ad2018-01-26 12:56:22 -05001430##
1431
Cary Clark681287e2018-03-16 11:34:15 -04001432#SeeAlso Color_Space SkBitmap::refColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001433
1434#Method ##
1435
1436# ------------------------------------------------------------------------------
1437
1438#Method bool isEmpty() const
Cary Clark78de7512018-02-07 07:27:09 -05001439#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001440#Line # returns if dimensions contain pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -04001441#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001442
1443#Example
Cary Clark681287e2018-03-16 11:34:15 -04001444 for (int width : { 0, 2 } ) {
1445 for (int height : { 0, 2 } ) {
1446 SkImageInfo imageInfo= SkImageInfo::MakeA8(width, height);
1447 SkDebugf("width: %d height: %d empty: %s\n", width, height,
1448 imageInfo.isEmpty() ? "true" : "false");
1449 }
1450 }
1451#StdOut
1452width: 0 height: 0 empty: true
1453width: 0 height: 2 empty: true
1454width: 2 height: 0 empty: true
1455width: 2 height: 2 empty: false
1456##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001457##
1458
Cary Clark681287e2018-03-16 11:34:15 -04001459#SeeAlso dimensions bounds SkBitmap::empty SkPixmap::bounds
Cary Clark2dc84ad2018-01-26 12:56:22 -05001460
1461#Method ##
1462
1463# ------------------------------------------------------------------------------
1464
1465#Method bool isOpaque() const
Cary Clark78de7512018-02-07 07:27:09 -05001466#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001467#Line # returns if Alpha_Type is kOpaque_SkAlphaType ##
Cary Clark09d80c02018-10-31 12:14:03 -04001468#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001469
1470#Example
Cary Clark681287e2018-03-16 11:34:15 -04001471 const int height = 2;
1472 const int width = 2;
1473 SkBitmap bitmap;
1474 SkImageInfo imageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType);
1475 bitmap.setInfo(imageInfo);
1476 for (int index = 0; index < 2; ++index) {
1477 bitmap.allocPixels();
1478 bitmap.eraseColor(0x00000000);
1479 SkDebugf("isOpaque: %s\n", imageInfo.isOpaque() ? "true" : "false");
1480 bitmap.eraseColor(0xFFFFFFFF);
1481 SkDebugf("isOpaque: %s\n", imageInfo.isOpaque() ? "true" : "false");
1482 imageInfo = imageInfo.makeAlphaType(kOpaque_SkAlphaType);
1483 bitmap.setInfo(imageInfo);
1484 }
1485#StdOut
1486isOpaque: false
1487isOpaque: false
1488isOpaque: true
1489isOpaque: true
1490##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001491##
1492
Cary Clark681287e2018-03-16 11:34:15 -04001493#SeeAlso Color_Alpha SkColorTypeValidateAlphaType SkBitmap::isOpaque SkImage::isOpaque SkPixmap::isOpaque
Cary Clark2dc84ad2018-01-26 12:56:22 -05001494
1495#Method ##
1496
1497# ------------------------------------------------------------------------------
1498
1499#Method SkISize dimensions() const
Cary Clark78de7512018-02-07 07:27:09 -05001500#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001501#Line # returns width() and height() ##
Cary Clark09d80c02018-10-31 12:14:03 -04001502#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001503
1504#Example
Cary Clark681287e2018-03-16 11:34:15 -04001505 const int height = 2;
1506 const int width = 2;
1507 SkImageInfo imageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType);
1508 SkISize dimensions = imageInfo.dimensions();
1509 SkIRect bounds = imageInfo.bounds();
1510 SkIRect dimensionsAsBounds = SkIRect::MakeSize(dimensions);
1511 SkDebugf("dimensionsAsBounds %c= bounds\n", dimensionsAsBounds == bounds ? '=' : '!');
1512#StdOut
1513dimensionsAsBounds == bounds
1514##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001515##
1516
Cary Clark681287e2018-03-16 11:34:15 -04001517#SeeAlso width height bounds SkBitmap::dimensions
Cary Clark2dc84ad2018-01-26 12:56:22 -05001518
1519#Method ##
1520
1521# ------------------------------------------------------------------------------
1522
1523#Method SkIRect bounds() const
Cary Clark78de7512018-02-07 07:27:09 -05001524#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001525#Line # returns width() and height() as Rectangle ##
Cary Clark09d80c02018-10-31 12:14:03 -04001526#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001527
1528#Example
Cary Clark681287e2018-03-16 11:34:15 -04001529#Height 64
1530#Image 4
1531 canvas->scale(.5f, .5f);
1532 SkImageInfo imageInfo = source.info();
1533 SkIRect bounds = imageInfo.bounds();
1534 for (int x : { 0, bounds.width() } ) {
1535 for (int y : { 0, bounds.height() } ) {
1536 canvas->drawBitmap(source, x, y);
1537 }
1538 }
Cary Clark2dc84ad2018-01-26 12:56:22 -05001539##
1540
Cary Clark681287e2018-03-16 11:34:15 -04001541#SeeAlso width height dimensions
Cary Clark2dc84ad2018-01-26 12:56:22 -05001542
1543#Method ##
1544
1545# ------------------------------------------------------------------------------
1546
1547#Method bool gammaCloseToSRGB() const
Cary Clark78de7512018-02-07 07:27:09 -05001548#In Property
Cary Clark682c58d2018-05-16 07:07:07 -04001549#Line # returns if Color_Space gamma is approximately the same as sRGB ##
Cary Clark681287e2018-03-16 11:34:15 -04001550
1551Returns true if associated Color_Space is not nullptr, and Color_Space gamma
Cary Clark682c58d2018-05-16 07:07:07 -04001552is approximately the same as sRGB.
1553This includes the
Cary Clark681287e2018-03-16 11:34:15 -04001554###$
1555$A sRGB transfer function $ https://en.wikipedia.org/wiki/SRGB#The_sRGB_transfer_function_(%22gamma%22) $$
1556$$$#
1557as well as a gamma curve described by a 2.2 exponent.
1558
1559#Return true if Color_Space gamma is approximately the same as sRGB ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001560
1561#Example
Cary Clark681287e2018-03-16 11:34:15 -04001562#Height 144
1563 const int width = 256;
1564 const int height = 64;
1565 auto drawLabel = [=](const char* what, bool closeToSRGB) -> void {
1566 SkString string;
1567 string.printf("%s gamma is %s" "close to sRGB", what, closeToSRGB ? "" : "not ");
1568 SkPaint paint;
1569 paint.setAntiAlias(true);
Cary Clark14768f62018-10-29 20:33:51 -04001570 canvas->drawString(string, 20, 56, paint);
Cary Clark681287e2018-03-16 11:34:15 -04001571 };
1572 SkColor gradColors[] = { 0xFFFF7F00, 0xFF00FF7F, 0xFF0000FF, 0xFF7F7FFF };
1573 SkPoint gradPoints[] = { { 0, 0 }, { width, 0 }, { width * 2, 0 }, { width * 3, 0 } };
1574 SkPaint gradPaint;
1575 gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1576 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1577 canvas->drawRect(SkRect::MakeWH(width, height), gradPaint);
1578 drawLabel("canvas", canvas->imageInfo().gammaCloseToSRGB());
1579 SkBitmap bitmap;
1580 SkImageInfo offscreenInfo = SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType);
1581 bitmap.allocPixels(offscreenInfo);
1582 SkCanvas sRGBOffscreen(bitmap);
1583 sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1584 canvas->translate(0, 80);
1585 canvas->drawBitmap(bitmap, 0, 0);
1586 drawLabel("offscreen", offscreenInfo.gammaCloseToSRGB());
Cary Clark2dc84ad2018-01-26 12:56:22 -05001587##
1588
Cary Clark681287e2018-03-16 11:34:15 -04001589#SeeAlso SkColorSpace::gammaCloseToSRGB
Cary Clark2dc84ad2018-01-26 12:56:22 -05001590
1591#Method ##
1592
1593# ------------------------------------------------------------------------------
1594
1595#Method SkImageInfo makeWH(int newWidth, int newHeight) const
Cary Clark61313f32018-10-08 14:57:48 -04001596#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001597#Line # creates Image_Info with changed dimensions ##
Cary Clark09d80c02018-10-31 12:14:03 -04001598#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001599
1600#Example
Cary Clark681287e2018-03-16 11:34:15 -04001601#Height 144
1602#Image 3
1603 SkImageInfo canvasImageInfo = canvas->imageInfo();
1604 SkRect canvasBounds = SkRect::Make(canvasImageInfo.bounds());
1605 canvas->drawBitmapRect(source, source.bounds(), canvasBounds, nullptr);
Cary Clark682c58d2018-05-16 07:07:07 -04001606 SkImageInfo insetImageInfo =
Cary Clark681287e2018-03-16 11:34:15 -04001607 canvasImageInfo.makeWH(canvasBounds.width() / 2, canvasBounds.height() / 2);
1608 SkBitmap inset;
1609 inset.allocPixels(insetImageInfo);
1610 SkCanvas offscreen(inset);
1611 offscreen.drawBitmapRect(source, source.bounds(), SkRect::Make(inset.bounds()), nullptr);
1612 canvas->drawBitmap(inset, canvasBounds.width() / 4, canvasBounds.height() / 4);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001613##
1614
Cary Clark682c58d2018-05-16 07:07:07 -04001615#SeeAlso Make makeAlphaType makeColorSpace makeColorType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001616
1617#Method ##
1618
1619# ------------------------------------------------------------------------------
1620
1621#Method SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const
Cary Clark61313f32018-10-08 14:57:48 -04001622#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001623#Line # creates Image_Info with changed Alpha_Type ##
Cary Clark09d80c02018-10-31 12:14:03 -04001624#Populate
Cary Clark681287e2018-03-16 11:34:15 -04001625
1626#Example
1627#Image 3
1628 const int width = 256;
1629 const int height = 128;
1630 SkColor pixels[height][width];
1631 for (int y = 0; y < height; ++y) {
1632 for (int x = 0; x < width; ++x) {
Cary Clark682c58d2018-05-16 07:07:07 -04001633 int red = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 4 + y) * 0.03f)));
1634 int blue = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 3 + y) * 0.04f)));
Cary Clark681287e2018-03-16 11:34:15 -04001635 int green = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 2 + y) * 0.05f)));
1636 int alpha = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 1 + y) * 0.006f)));
Cary Clark682c58d2018-05-16 07:07:07 -04001637 pixels[y][x] =
Cary Clark681287e2018-03-16 11:34:15 -04001638 SkColorSetARGB(alpha, red * alpha / 255, green * alpha / 255, blue * alpha / 255);
1639 }
1640 }
1641 SkBitmap bitmap;
1642 SkImageInfo info = SkImageInfo::Make(width, height, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
1643 bitmap.installPixels(info, (void*) pixels, sizeof(SkColor) * width);
1644 canvas->drawBitmap(source, 0, 0);
1645 canvas->drawBitmap(bitmap, 0, 0);
1646 SkImageInfo unpremulInfo = info.makeAlphaType(kUnpremul_SkAlphaType);
1647 bitmap.installPixels(unpremulInfo, (void*) pixels, sizeof(SkColor) * width);
1648 canvas->drawBitmap(bitmap, 0, 128);
1649##
1650
1651#SeeAlso Make MakeA8 makeColorType makeColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001652
1653#Method ##
1654
1655# ------------------------------------------------------------------------------
1656
1657#Method SkImageInfo makeColorType(SkColorType newColorType) const
Cary Clark61313f32018-10-08 14:57:48 -04001658#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001659#Line # creates Image_Info with changed Color_Type ##
Cary Clark09d80c02018-10-31 12:14:03 -04001660#Populate
Cary Clark681287e2018-03-16 11:34:15 -04001661
1662#Example
1663 const int width = 256;
1664 const int height = 128;
1665 SkColor pixels[height][width];
1666 for (int y = 0; y < height; ++y) {
1667 for (int x = 0; x < width; ++x) {
Cary Clark682c58d2018-05-16 07:07:07 -04001668 int red = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 4 + y) * 0.03f)));
1669 int blue = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 3 + y) * 0.04f)));
Cary Clark681287e2018-03-16 11:34:15 -04001670 int green = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 2 + y) * 0.05f)));
1671 int alpha = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 1 + y) * 0.006f)));
Cary Clark682c58d2018-05-16 07:07:07 -04001672 pixels[y][x] =
Cary Clark681287e2018-03-16 11:34:15 -04001673 SkColorSetARGB(alpha, red * alpha / 255, green * alpha / 255, blue * alpha / 255);
1674 }
1675 }
1676 SkBitmap bitmap;
1677 SkImageInfo info = SkImageInfo::Make(width, height, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
1678 bitmap.installPixels(info, (void*) pixels, sizeof(SkColor) * width);
1679 canvas->drawBitmap(source, 0, 0);
1680 canvas->drawBitmap(bitmap, 0, 0);
1681 SkImageInfo rgbaInfo = info.makeColorType(kRGBA_8888_SkColorType);
1682 bitmap.installPixels(rgbaInfo, (void*) pixels, sizeof(SkColor) * width);
1683 canvas->drawBitmap(bitmap, 0, 128);
1684##
1685
1686#SeeAlso Make makeAlphaType makeColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001687
1688#Method ##
1689
1690# ------------------------------------------------------------------------------
1691
1692#Method SkImageInfo makeColorSpace(sk_sp<SkColorSpace> cs) const
Cary Clark61313f32018-10-08 14:57:48 -04001693#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001694#Line # creates Image_Info with changed Color_Space ##
Cary Clark09d80c02018-10-31 12:14:03 -04001695#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001696
1697#Example
Cary Clark681287e2018-03-16 11:34:15 -04001698#Height 224
1699 const int width = 256;
1700 const int height = 64;
1701 auto drawLabel = [=](const char* what, bool closeToSRGB) -> void {
1702 SkString string;
1703 string.printf("%s gamma is %s" "close to sRGB", what, closeToSRGB ? "" : "not ");
1704 SkPaint paint;
1705 paint.setAntiAlias(true);
Cary Clark14768f62018-10-29 20:33:51 -04001706 canvas->drawString(string, 20, 56, paint);
Cary Clark681287e2018-03-16 11:34:15 -04001707 };
1708 SkColor gradColors[] = { 0xFFFF7F00, 0xFF00FF7F, 0xFF0000FF, 0xFF7F7FFF };
1709 SkPoint gradPoints[] = { { 0, 0 }, { width, 0 }, { width * 2, 0 }, { width * 3, 0 } };
1710 SkPaint gradPaint;
1711 gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1712 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1713 canvas->drawRect(SkRect::MakeWH(width, height), gradPaint);
1714 drawLabel("canvas", canvas->imageInfo().gammaCloseToSRGB());
1715 SkBitmap bitmap;
1716 SkImageInfo offscreenInfo = SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType);
1717 bitmap.allocPixels(offscreenInfo);
1718 SkCanvas sRGBOffscreen(bitmap);
1719 sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1720 canvas->translate(0, 80);
1721 canvas->drawBitmap(bitmap, 0, 0);
1722 drawLabel("offscreen", offscreenInfo.gammaCloseToSRGB());
1723 SkImageInfo linearGamma =
1724 offscreenInfo.makeColorSpace(offscreenInfo.colorSpace()->makeLinearGamma());
1725 bitmap.allocPixels(linearGamma);
1726 SkCanvas lgOffscreen(bitmap);
1727 lgOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1728 canvas->translate(0, 80);
1729 canvas->drawBitmap(bitmap, 0, 0);
1730 drawLabel("linear", linearGamma.gammaCloseToSRGB());
Cary Clark2dc84ad2018-01-26 12:56:22 -05001731##
1732
Cary Clark681287e2018-03-16 11:34:15 -04001733#SeeAlso Make MakeS32 makeAlphaType makeColorType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001734
1735#Method ##
1736
1737# ------------------------------------------------------------------------------
1738
1739#Method int bytesPerPixel() const
Cary Clark78de7512018-02-07 07:27:09 -05001740#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001741#Line # returns number of bytes in pixel based on Color_Type ##
Cary Clark09d80c02018-10-31 12:14:03 -04001742#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001743
1744#Example
Cary Clark681287e2018-03-16 11:34:15 -04001745 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
1746 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
1747 for (SkColorType colorType : { #list_of_color_types#
1748 } ) {
1749 SkImageInfo info = SkImageInfo::Make(1, 1, colorType, kOpaque_SkAlphaType);
1750 SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d\n",
1751 colors[colorType], 13 - strlen(colors[colorType]), " ",
1752 info.bytesPerPixel());
1753 }
1754#StdOut
1755color: kUnknown_SkColorType bytesPerPixel: 0
1756color: kAlpha_8_SkColorType bytesPerPixel: 1
1757color: kRGB_565_SkColorType bytesPerPixel: 2
1758color: kARGB_4444_SkColorType bytesPerPixel: 2
1759color: kRGBA_8888_SkColorType bytesPerPixel: 4
1760color: kRGB_888x_SkColorType bytesPerPixel: 4
1761color: kBGRA_8888_SkColorType bytesPerPixel: 4
1762color: kRGBA_1010102_SkColorType bytesPerPixel: 4
1763color: kRGB_101010x_SkColorType bytesPerPixel: 4
1764color: kGray_8_SkColorType bytesPerPixel: 1
1765color: kRGBA_F16_SkColorType bytesPerPixel: 8
1766##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001767##
1768
Cary Clark681287e2018-03-16 11:34:15 -04001769#SeeAlso width shiftPerPixel SkBitmap::bytesPerPixel
Cary Clark2dc84ad2018-01-26 12:56:22 -05001770
1771#Method ##
1772
1773# ------------------------------------------------------------------------------
1774
1775#Method int shiftPerPixel() const
Cary Clark78de7512018-02-07 07:27:09 -05001776#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001777#Line # returns bit shift from pixels to bytes ##
Cary Clark09d80c02018-10-31 12:14:03 -04001778#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001779
1780#Example
Cary Clark681287e2018-03-16 11:34:15 -04001781 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
1782 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
1783 for (SkColorType colorType : { #list_of_color_types#
1784 } ) {
1785 SkImageInfo info = SkImageInfo::Make(1, 1, colorType, kOpaque_SkAlphaType);
1786 SkDebugf("color: k" "%s" "_SkColorType" "%*s" "shiftPerPixel: %d\n",
1787 colors[colorType], 14 - strlen(colors[colorType]), " ",
1788 info.shiftPerPixel());
1789 }
1790#StdOut
1791color: kUnknown_SkColorType shiftPerPixel: 0
1792color: kAlpha_8_SkColorType shiftPerPixel: 0
1793color: kRGB_565_SkColorType shiftPerPixel: 1
1794color: kARGB_4444_SkColorType shiftPerPixel: 1
1795color: kRGBA_8888_SkColorType shiftPerPixel: 2
1796color: kRGB_888x_SkColorType shiftPerPixel: 2
1797color: kBGRA_8888_SkColorType shiftPerPixel: 2
1798color: kRGBA_1010102_SkColorType shiftPerPixel: 2
1799color: kRGB_101010x_SkColorType shiftPerPixel: 2
1800color: kGray_8_SkColorType shiftPerPixel: 0
1801color: kRGBA_F16_SkColorType shiftPerPixel: 3
1802##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001803##
1804
Cary Clark06c20f32018-03-20 15:53:27 -04001805#SeeAlso bytesPerPixel minRowBytes SkBitmap::shiftPerPixel SkPixmap::shiftPerPixel
Cary Clark2dc84ad2018-01-26 12:56:22 -05001806
1807#Method ##
1808
1809# ------------------------------------------------------------------------------
1810
1811#Method uint64_t minRowBytes64() const
Cary Clark78de7512018-02-07 07:27:09 -05001812#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001813#Line # returns width() times bytesPerPixel in 64 bits ##
Cary Clark09d80c02018-10-31 12:14:03 -04001814#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001815
1816#Example
Cary Clark681287e2018-03-16 11:34:15 -04001817 for (int shift = 24; shift < 32; ++shift) {
1818 int width = 1 << shift;
Cary Clark682c58d2018-05-16 07:07:07 -04001819 SkImageInfo imageInfo =
Cary Clark681287e2018-03-16 11:34:15 -04001820 SkImageInfo::Make(width, 1, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
1821 uint64_t minRowBytes = imageInfo.minRowBytes64();
1822 bool widthTooLarge = (uint64_t) (int32_t) minRowBytes != minRowBytes;
1823 SkDebugf("RGBA_F16 width %d (0x%08x) %s\n",
Cary Clark682c58d2018-05-16 07:07:07 -04001824 width, width, widthTooLarge ? "too large" : "OK");
Cary Clark681287e2018-03-16 11:34:15 -04001825 }
1826#StdOut
1827RGBA_F16 width 16777216 (0x01000000) OK
1828RGBA_F16 width 33554432 (0x02000000) OK
1829RGBA_F16 width 67108864 (0x04000000) OK
1830RGBA_F16 width 134217728 (0x08000000) OK
1831RGBA_F16 width 268435456 (0x10000000) too large
1832RGBA_F16 width 536870912 (0x20000000) too large
1833RGBA_F16 width 1073741824 (0x40000000) too large
1834RGBA_F16 width -2147483648 (0x80000000) too large
1835##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001836##
1837
Cary Clark681287e2018-03-16 11:34:15 -04001838#SeeAlso minRowBytes computeByteSize computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05001839
1840#Method ##
1841
1842# ------------------------------------------------------------------------------
1843
1844#Method size_t minRowBytes() const
Cary Clark78de7512018-02-07 07:27:09 -05001845#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001846#Line # returns width() times bytesPerPixel in 32 bits ##
Cary Clark09d80c02018-10-31 12:14:03 -04001847#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001848
1849#Example
Cary Clark681287e2018-03-16 11:34:15 -04001850 for (int shift = 24; shift < 32; ++shift) {
1851 int width = 1 << shift;
Cary Clark682c58d2018-05-16 07:07:07 -04001852 SkImageInfo imageInfo =
Cary Clark681287e2018-03-16 11:34:15 -04001853 SkImageInfo::Make(width, 1, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
1854 size_t minRowBytes = imageInfo.minRowBytes();
1855 bool widthTooLarge = !minRowBytes;
1856 SkDebugf("RGBA_F16 width %d (0x%08x) %s\n",
Cary Clark682c58d2018-05-16 07:07:07 -04001857 width, width, widthTooLarge ? "too large" : "OK");
Cary Clark681287e2018-03-16 11:34:15 -04001858 }
1859#StdOut
1860RGBA_F16 width 16777216 (0x01000000) OK
1861RGBA_F16 width 33554432 (0x02000000) OK
1862RGBA_F16 width 67108864 (0x04000000) OK
1863RGBA_F16 width 134217728 (0x08000000) OK
1864RGBA_F16 width 268435456 (0x10000000) too large
1865RGBA_F16 width 536870912 (0x20000000) too large
1866RGBA_F16 width 1073741824 (0x40000000) too large
1867RGBA_F16 width -2147483648 (0x80000000) too large
1868##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001869##
1870
Cary Clark681287e2018-03-16 11:34:15 -04001871#SeeAlso minRowBytes64 computeByteSize computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05001872
1873#Method ##
1874
1875# ------------------------------------------------------------------------------
1876
1877#Method size_t computeOffset(int x, int y, size_t rowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05001878#In Utility
Cary Clark681287e2018-03-16 11:34:15 -04001879#Line # returns byte offset within pixel array ##
Cary Clark09d80c02018-10-31 12:14:03 -04001880#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001881
1882#Example
Cary Clark06c20f32018-03-20 15:53:27 -04001883#Height 128
Cary Clark681287e2018-03-16 11:34:15 -04001884 uint8_t pixels[][12] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00},
1885 { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00},
1886 { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00},
1887 { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF},
1888 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1889 { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00},
1890 { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00},
1891 { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00} };
1892 SkImageInfo imageInfo = SkImageInfo::MakeA8(8, 8);
1893 SkBitmap bitmap;
1894 bitmap.installPixels(imageInfo, (void*) pixels, sizeof(pixels[0]));
1895 SkPaint paint;
1896 paint.setColor(SK_ColorRED);
1897 canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint);
1898 size_t offset = imageInfo.computeOffset(2, 3, sizeof(pixels[0]));
1899 pixels[0][offset] = 0x7F;
1900 offset = imageInfo.computeOffset(5, 3, sizeof(pixels[0]));
1901 pixels[0][offset] = 0x7F;
1902 bitmap.installPixels(imageInfo, (void*) pixels, sizeof(pixels[0]));
1903 canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(128, 128), &paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001904##
1905
Cary Clark06c20f32018-03-20 15:53:27 -04001906#SeeAlso height width minRowBytes computeByteSize
Cary Clark2dc84ad2018-01-26 12:56:22 -05001907
1908#Method ##
1909
1910# ------------------------------------------------------------------------------
1911
1912#Method bool operator==(const SkImageInfo& other)_const
Cary Clark06c20f32018-03-20 15:53:27 -04001913#Line # compares Image_Info for equality ##
Cary Clark09d80c02018-10-31 12:14:03 -04001914#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001915
1916#Example
Cary Clark682c58d2018-05-16 07:07:07 -04001917 SkImageInfo info1 = SkImageInfo::Make(10, 20, kGray_8_SkColorType, kPremul_SkAlphaType);
1918 SkImageInfo info2 = SkImageInfo::Make(20, 10, kAlpha_8_SkColorType, kUnpremul_SkAlphaType);
1919 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
1920 info2 = info2.makeWH(10, 20);
1921 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
1922 info2 = info2.makeColorType(kGray_8_SkColorType);
1923 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
1924 info2 = info2.makeAlphaType(kPremul_SkAlphaType);
1925 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
1926#StdOut
1927info1 != info2
1928info1 != info2
1929info1 != info2
1930info1 == info2
1931##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001932##
1933
Cary Clark06c20f32018-03-20 15:53:27 -04001934#SeeAlso operator!=(const SkImageInfo& other)_const SkColorSpace::Equals
Cary Clark2dc84ad2018-01-26 12:56:22 -05001935
1936#Method ##
1937
1938# ------------------------------------------------------------------------------
1939
1940#Method bool operator!=(const SkImageInfo& other)_const
Cary Clark06c20f32018-03-20 15:53:27 -04001941#Line # compares Image_Info for inequality ##
Cary Clark09d80c02018-10-31 12:14:03 -04001942#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001943
1944#Example
Cary Clark682c58d2018-05-16 07:07:07 -04001945 SkImageInfo info1 = SkImageInfo::Make(10, 20, kGray_8_SkColorType, kPremul_SkAlphaType);
1946 SkImageInfo info2 = SkImageInfo::Make(20, 10, kAlpha_8_SkColorType, kUnpremul_SkAlphaType);
1947 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
1948 info2 = info2.makeWH(10, 20);
1949 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
1950 info2 = info2.makeColorType(kGray_8_SkColorType);
1951 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
1952 info2 = info2.makeAlphaType(kPremul_SkAlphaType);
1953 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
1954#StdOut
1955info1 != info2
1956info1 != info2
1957info1 != info2
1958info1 == info2
1959##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001960##
1961
Cary Clark06c20f32018-03-20 15:53:27 -04001962#SeeAlso operator==(const SkImageInfo& other)_const SkColorSpace::Equals
Cary Clark2dc84ad2018-01-26 12:56:22 -05001963
1964#Method ##
1965
1966# ------------------------------------------------------------------------------
1967
1968#Method size_t computeByteSize(size_t rowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05001969#In Utility
Cary Clark682c58d2018-05-16 07:07:07 -04001970#Line # returns memory required by pixel buffer with given row bytes ##
Cary Clark09d80c02018-10-31 12:14:03 -04001971#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001972
1973#Example
Cary Clark06c20f32018-03-20 15:53:27 -04001974#Height 130
Cary Clark682c58d2018-05-16 07:07:07 -04001975 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2);
1976 const size_t size = info.computeByteSize(100000);
1977 SkAutoTMalloc<SkPMColor> storage(size);
1978 SkPMColor* pixels = storage.get();
1979 SkBitmap bitmap;
1980 bitmap.setInfo(info);
1981 bitmap.setPixels(pixels);
1982 bitmap.eraseColor(SK_ColorRED);
1983 canvas->scale(50, 50);
1984 canvas->rotate(8);
Cary Clark06c20f32018-03-20 15:53:27 -04001985 canvas->drawBitmap(bitmap, 2, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001986##
1987
Cary Clark06c20f32018-03-20 15:53:27 -04001988#SeeAlso computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05001989
1990#Method ##
1991
1992# ------------------------------------------------------------------------------
1993
1994#Method size_t computeMinByteSize() const
Cary Clark78de7512018-02-07 07:27:09 -05001995#In Utility
Cary Clark682c58d2018-05-16 07:07:07 -04001996#Line # returns least memory required by pixel buffer ##
Cary Clark09d80c02018-10-31 12:14:03 -04001997#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001998
1999#Example
Cary Clark06c20f32018-03-20 15:53:27 -04002000#Height 130
Cary Clark682c58d2018-05-16 07:07:07 -04002001 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2);
2002 const size_t size = info.computeMinByteSize();
2003 SkAutoTMalloc<SkPMColor> storage(size);
2004 SkPMColor* pixels = storage.get();
2005 SkBitmap bitmap;
2006 bitmap.setInfo(info);
2007 bitmap.setPixels(pixels);
2008 bitmap.eraseColor(SK_ColorRED);
2009 canvas->scale(50, 50);
2010 canvas->rotate(8);
Cary Clark06c20f32018-03-20 15:53:27 -04002011 canvas->drawBitmap(bitmap, 2, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05002012##
2013
Cary Clark06c20f32018-03-20 15:53:27 -04002014#SeeAlso computeByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002015
2016#Method ##
2017
2018# ------------------------------------------------------------------------------
2019
2020#Method static bool ByteSizeOverflowed(size_t byteSize)
Cary Clark78de7512018-02-07 07:27:09 -05002021#In Utility
Cary Clark06c20f32018-03-20 15:53:27 -04002022#Line # checks result of computeByteSize and computeMinByteSize ##
Cary Clark09d80c02018-10-31 12:14:03 -04002023#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05002024
2025#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002026 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 1000000000);
2027 for (size_t rowBytes = 100000000; rowBytes < 10000000000000LL; rowBytes *= 10) {
2028 const size_t size = info.computeByteSize(rowBytes);
2029 SkDebugf("rowBytes:%llu size:%llu overflowed:%s\n", rowBytes, size,
2030 SkImageInfo::ByteSizeOverflowed(size) ? "true" : "false");
2031 }
2032#StdOut
2033rowBytes:100000000 size:99999999900000008 overflowed:false
2034rowBytes:1000000000 size:999999999000000008 overflowed:false
2035rowBytes:10000000000 size:9999999990000000008 overflowed:false
2036rowBytes:100000000000 size:18446744073709551615 overflowed:true
2037rowBytes:1000000000000 size:18446744073709551615 overflowed:true
2038##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002039##
2040
Cary Clark06c20f32018-03-20 15:53:27 -04002041#SeeAlso computeByteSize computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002042
2043#Method ##
2044
2045# ------------------------------------------------------------------------------
2046
2047#Method bool validRowBytes(size_t rowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05002048#In Utility
Cary Clark06c20f32018-03-20 15:53:27 -04002049#Line # checks if row bytes is large enough to contain pixel row ##
Cary Clark09d80c02018-10-31 12:14:03 -04002050#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05002051
2052#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002053 SkImageInfo info = SkImageInfo::MakeN32Premul(16, 8);
2054 for (size_t rowBytes = 60; rowBytes < 72; rowBytes += sizeof(SkPMColor)) {
2055 SkDebugf("validRowBytes(%llu): %s\n", rowBytes, info.validRowBytes(rowBytes) ?
2056 "true" : "false");
2057 }
2058#StdOut
2059validRowBytes(60): false
2060validRowBytes(64): true
2061validRowBytes(68): true
2062##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002063##
2064
Cary Clark06c20f32018-03-20 15:53:27 -04002065#SeeAlso ByteSizeOverflowed computeByteSize computeMinByteSize
Cary Clark2dc84ad2018-01-26 12:56:22 -05002066
2067#Method ##
2068
2069# ------------------------------------------------------------------------------
2070
2071#Method void reset()
Cary Clark61313f32018-10-08 14:57:48 -04002072#In Constructors
Cary Clark06c20f32018-03-20 15:53:27 -04002073#Line # sets zero dimensions, kUnknown_SkColorType, kUnknown_SkAlphaType ##
Cary Clark09d80c02018-10-31 12:14:03 -04002074#Populate
Cary Clark06c20f32018-03-20 15:53:27 -04002075
Cary Clark2dc84ad2018-01-26 12:56:22 -05002076#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002077 SkImageInfo info = SkImageInfo::MakeN32Premul(16, 8);
2078 SkImageInfo copy = info;
2079 SkDebugf("info %c= copy\n", info == copy ? '=' : '!');
2080 copy.reset();
2081 SkDebugf("info %c= reset copy\n", info == copy ? '=' : '!');
2082 SkDebugf("SkImageInfo() %c= reset copy\n", SkImageInfo() == copy ? '=' : '!');
2083#StdOut
2084info == copy
2085info != reset copy
2086SkImageInfo() == reset copy
2087##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002088##
2089
Cary Clark06c20f32018-03-20 15:53:27 -04002090#SeeAlso SkImageInfo()
Cary Clark2dc84ad2018-01-26 12:56:22 -05002091
2092#Method ##
2093
2094# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05002095#Subtopic Utility
Cary Clark78de7512018-02-07 07:27:09 -05002096#Line # rarely called management functions ##
2097##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002098
2099#Method void validate() const
Cary Clark78de7512018-02-07 07:27:09 -05002100#In Utility
Cary Clark06c20f32018-03-20 15:53:27 -04002101#Line # asserts if Image_Info is invalid (debug only) ##
Cary Clark09d80c02018-10-31 12:14:03 -04002102#Populate
Cary Clark06c20f32018-03-20 15:53:27 -04002103
2104#NoExample
Cary Clark2dc84ad2018-01-26 12:56:22 -05002105##
2106
Cary Clark06c20f32018-03-20 15:53:27 -04002107#SeeAlso validRowBytes SkBitmap::validate
Cary Clark2dc84ad2018-01-26 12:56:22 -05002108
2109#Method ##
2110
2111#Struct SkImageInfo ##
2112
Cary Clark08895c42018-02-01 09:37:32 -05002113#Topic Image_Info ##