blob: 096695cecf9068b0c85e8c9c73ddc7b7bc234e9a [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 Clarkf895a422018-02-27 09:54:21 -05004Image_Info specifies the dimensions and encoding of the pixels in a Bitmap.
5The dimensions are integral width and height. The encoding is how pixel
6bits describe Color_Alpha, transparency; Color components red, blue,
7and green; and Color_Space, the range and linearity of colors.
8
9Image_Info describes an uncompressed raster pixels. In contrast, Image
10additionally describes compressed pixels like PNG, and Surface describes
11destinations on the GPU. Image and Surface may be specified by Image_Info,
12but Image and Surface may not contain Image_Info.
13
Cary Clark08895c42018-02-01 09:37:32 -050014#Subtopic Overview
Cary Clark682c58d2018-05-16 07:07:07 -040015#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -050016##
17
Cary Clark4855f782018-02-06 09:41:53 -050018#Subtopic Constant
Cary Clark08895c42018-02-01 09:37:32 -050019#Populate
20##
Cary Clark2dc84ad2018-01-26 12:56:22 -050021
22# ------------------------------------------------------------------------------
Cary Clark08895c42018-02-01 09:37:32 -050023#Subtopic Alpha_Type
Cary Clarkf895a422018-02-27 09:54:21 -050024#Line # encoding for pixel transparency ##
Cary Clark137b8742018-05-30 09:21:49 -040025#Alias Alpha_Type ##
26#Alias Alpha_Types ##
Cary Clarkf895a422018-02-27 09:54:21 -050027
Cary Clark681287e2018-03-16 11:34:15 -040028#PhraseDef list_of_alpha_types
29kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
30kUnpremul_SkAlphaType
31##
32
Cary Clark2dc84ad2018-01-26 12:56:22 -050033#Enum SkAlphaType
Cary Clarkf895a422018-02-27 09:54:21 -050034#Line # encoding for pixel transparency ##
Cary Clark2dc84ad2018-01-26 12:56:22 -050035
36#Code
37 enum SkAlphaType {
38 kUnknown_SkAlphaType,
39 kOpaque_SkAlphaType,
40 kPremul_SkAlphaType,
41 kUnpremul_SkAlphaType,
42 kLastEnum_SkAlphaType = kUnpremul_SkAlphaType,
43 };
44##
45
Cary Clarkf895a422018-02-27 09:54:21 -050046Describes how to interpret the alpha component of a pixel. A pixel may
47be opaque, or Color_Alpha, describing multiple levels of transparency.
48
49In simple blending, Color_Alpha weights the draw color and the destination
50color to create a new color. If alpha describes a weight from zero to one:
51
Cary Clark682c58d2018-05-16 07:07:07 -040052#Code
Cary Clarkf895a422018-02-27 09:54:21 -050053 new color = draw color * alpha + destination color * (1 - alpha)
54##
55
56In practice alpha is encoded in two or more bits, where 1.0 equals all bits set.
57
Cary Clarkffb3d682018-05-17 12:17:28 -040058RGB may have Color_Alpha included in each component value; the stored
59value is the original RGB multiplied by Color_Alpha. Premultiplied color
Cary Clarkf895a422018-02-27 09:54:21 -050060components improve performance.
Cary Clark2dc84ad2018-01-26 12:56:22 -050061
62#Const kUnknown_SkAlphaType 0
Cary Clark682c58d2018-05-16 07:07:07 -040063#Line # uninitialized ##
64 Alpha_Type is uninitialized.
Cary Clark2dc84ad2018-01-26 12:56:22 -050065##
66#Const kOpaque_SkAlphaType 1
Cary Clark682c58d2018-05-16 07:07:07 -040067#Line # pixel is opaque ##
68#Details Opaque
69 Pixels are opaque. The Color_Type must have no explicit alpha
70 component, or all alpha components must be set to their maximum value.
Cary Clark2dc84ad2018-01-26 12:56:22 -050071##
72#Const kPremul_SkAlphaType 2
Cary Clark682c58d2018-05-16 07:07:07 -040073#Line # pixel components are Premultiplied by Alpha ##
74#Details Premul
75 Pixels have Alpha Premultiplied into color components.
76 Surface pixels must be Premultiplied.
Cary Clark2dc84ad2018-01-26 12:56:22 -050077##
78#Const kUnpremul_SkAlphaType 3
Cary Clark682c58d2018-05-16 07:07:07 -040079#Line # pixel components are independent of Alpha ##
80#Details Unpremul
81 Pixel color component values are independent of alpha value.
82 Images generated from encoded data like PNG do not Premultiply pixel color
83 components. kUnpremul_SkAlphaType is supported for Image pixels, but not for
84 Surface pixels.
85##
86#Const kLastEnum_SkAlphaType 3
87#Line # last valid value ##
88 Used by tests to iterate through all valid values.
Cary Clark2dc84ad2018-01-26 12:56:22 -050089##
90
Cary Clarkf895a422018-02-27 09:54:21 -050091#NoExample
Cary Clark2dc84ad2018-01-26 12:56:22 -050092##
93
Cary Clarkf895a422018-02-27 09:54:21 -050094#SeeAlso SkColorType SkColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -050095
96#Enum SkAlphaType ##
Cary Clarkf895a422018-02-27 09:54:21 -050097
98#Subtopic Opaque
Cary Clark682c58d2018-05-16 07:07:07 -040099#Line # hints all pixels are opaque ##
100Use kOpaque_SkAlphaType as a hint to optimize drawing when Alpha component
Cary Clarkf895a422018-02-27 09:54:21 -0500101of all pixel is set to its maximum value of 1.0; all alpha component bits are set.
Cary Clark682c58d2018-05-16 07:07:07 -0400102If Image_Info is set to kOpaque_SkAlphaType but all alpha values are not 1.0,
103results are undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500104
105#Example
106#Height 64
107#Description
108SkPreMultiplyARGB parameter a is set to 255, its maximum value, and is interpreted
109as Color_Alpha of 1.0. kOpaque_SkAlphaType may be set to improve performance.
Cary Clark682c58d2018-05-16 07:07:07 -0400110If SkPreMultiplyARGB parameter a is set to a value smaller than 255,
Cary Clarkf895a422018-02-27 09:54:21 -0500111kPremul_SkAlphaType must be used instead to avoid undefined results.
112The four displayed values are the original component values, though not necessarily
113in the same order.
114##
115 SkPMColor color = SkPreMultiplyARGB(255, 50, 100, 150);
116 SkString s;
117 s.printf("%u %u %u %u", SkColorGetA(color), SkColorGetR(color),
118 SkColorGetG(color), SkColorGetB(color));
119 SkPaint paint;
120 paint.setAntiAlias(true);
121 canvas->drawString(s, 10, 62, paint);
122 canvas->scale(50, 50);
123 SkBitmap bitmap;
124 SkImageInfo imageInfo = SkImageInfo::Make(1, 1, kN32_SkColorType, kOpaque_SkAlphaType);
125 if (bitmap.installPixels(imageInfo, (void*) &color, imageInfo.minRowBytes())) {
126 canvas->drawBitmap(bitmap, 0, 0);
127 }
128##
129
130#Subtopic Opaque ##
131
132#Subtopic Premul
Cary Clark682c58d2018-05-16 07:07:07 -0400133#Line # stores components scaled by Alpha ##
134Use kPremul_SkAlphaType when stored color components are the original color
135multiplied by the alpha component. The alpha component range of 0.0 to 1.0 is
136achieved by dividing the integer bit value by the maximum bit value.
Cary Clarkf895a422018-02-27 09:54:21 -0500137
Cary Clark682c58d2018-05-16 07:07:07 -0400138#Code
Cary Clarkf895a422018-02-27 09:54:21 -0500139stored color = original color * alpha / max alpha
140##
141
142The color component must be equal to or smaller than the alpha component,
143or the results are undefined.
144
145#Example
146#Description
147SkPreMultiplyARGB parameter a is set to 150, less than its maximum value, and is
148interpreted as Color_Alpha of about 0.6. kPremul_SkAlphaType must be set, since
Cary Clark682c58d2018-05-16 07:07:07 -0400149SkPreMultiplyARGB parameter a is set to a value smaller than 255,
Cary Clarkf895a422018-02-27 09:54:21 -0500150to avoid undefined results.
151The four displayed values reflect that the alpha component has been multiplied
152by the original color.
153##
154#Height 64
155 SkPMColor color = SkPreMultiplyARGB(150, 50, 100, 150);
156 SkString s;
157 s.printf("%u %u %u %u", SkColorGetA(color), SkColorGetR(color),
158 SkColorGetG(color), SkColorGetB(color));
159 SkPaint paint;
160 paint.setAntiAlias(true);
161 canvas->drawString(s, 10, 62, paint);
162 canvas->scale(50, 50);
163 SkBitmap bitmap;
164 SkImageInfo imageInfo = SkImageInfo::Make(1, 1, kN32_SkColorType, kPremul_SkAlphaType);
165 if (bitmap.installPixels(imageInfo, (void*) &color, imageInfo.minRowBytes())) {
166 canvas->drawBitmap(bitmap, 0, 0);
167 }
168##
169
170#Subtopic Premul ##
171
172#Subtopic Unpremul
Cary Clark682c58d2018-05-16 07:07:07 -0400173#Line # stores components without Alpha scaling ##
174Use kUnpremul_SkAlphaType if stored color components are not divided by the
175alpha component. Some drawing destinations may not support
176kUnpremul_SkAlphaType.
Cary Clarkf895a422018-02-27 09:54:21 -0500177
178#Bug 7079
179#Example
Cary Clark681287e2018-03-16 11:34:15 -0400180#Height 64
Cary Clarkf895a422018-02-27 09:54:21 -0500181#Description
182SkColorSetARGB parameter a is set to 150, less than its maximum value, and is
Cary Clark682c58d2018-05-16 07:07:07 -0400183interpreted as Color_Alpha of about 0.6. color is not Premultiplied;
Cary Clarkf895a422018-02-27 09:54:21 -0500184color components may have values greater than color alpha.
185The four displayed values are the original component values, though not necessarily
186in the same order.
187##
188 SkColor color = SkColorSetARGB(150, 50, 100, 255);
189 SkString s;
190 s.printf("%u %u %u %u", SkColorGetA(color), SkColorGetR(color),
191 SkColorGetG(color), SkColorGetB(color));
192 SkPaint paint;
193 paint.setAntiAlias(true);
194 canvas->drawString(s, 10, 62, paint);
195 canvas->scale(50, 50);
196 SkBitmap bitmap;
197 SkImageInfo imageInfo = SkImageInfo::Make(1, 1, kN32_SkColorType, kUnpremul_SkAlphaType);
198 if (bitmap.installPixels(imageInfo, (void*) &color, imageInfo.minRowBytes())) {
199 canvas->drawBitmap(bitmap, 0, 0);
200 }
201##
202
203#Subtopic Unpremul ##
204
Cary Clark06c20f32018-03-20 15:53:27 -0400205#Method static inline bool SkAlphaTypeIsOpaque(SkAlphaType at)
206#In Property
207#Line # returns if Alpha_Type equals kOpaque_SkAlphaType ##
208
Cary Clarka4f581a2018-04-03 15:31:59 -0400209Returns true if Alpha_Type equals kOpaque_SkAlphaType. kOpaque_SkAlphaType is a
210hint that the Color_Type is opaque, or that all Color_Alpha values are set to
211their 1.0 equivalent. If Alpha_Type is kOpaque_SkAlphaType, and Color_Type is not
212opaque, then the result of drawing any pixel with a Color_Alpha value less than
2131.0 is undefined.
214
Cary Clark06c20f32018-03-20 15:53:27 -0400215#Param at one of: #list_of_alpha_types#
216##
217#Return true if at equals kOpaque_SkAlphaType ##
218#NoExample
219##
220##
221
Cary Clark08895c42018-02-01 09:37:32 -0500222#Subtopic Alpha_Type ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500223
224# ------------------------------------------------------------------------------
Cary Clark08895c42018-02-01 09:37:32 -0500225#Subtopic Color_Type
Cary Clarkf895a422018-02-27 09:54:21 -0500226#Line # encoding for pixel color ##
Cary Clark137b8742018-05-30 09:21:49 -0400227#Alias Color_Type ##
228#Alias Color_Types ##
Cary Clark2a8c48b2018-02-15 17:31:24 -0500229
Cary Clark1a8d7622018-03-05 13:26:16 -0500230#PhraseDef list_of_color_types
231kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType,
232kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType,
233kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType,
234kGray_8_SkColorType, kRGBA_F16_SkColorType
235##
236
Cary Clark2dc84ad2018-01-26 12:56:22 -0500237#Enum SkColorType
Cary Clarkf895a422018-02-27 09:54:21 -0500238#Line # encoding for pixel color ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500239
240#Code
241 enum SkColorType {
242 kUnknown_SkColorType,
243 kAlpha_8_SkColorType,
244 kRGB_565_SkColorType,
245 kARGB_4444_SkColorType,
246 kRGBA_8888_SkColorType,
Cary Clark4855f782018-02-06 09:41:53 -0500247 kRGB_888x_SkColorType,
Cary Clark2dc84ad2018-01-26 12:56:22 -0500248 kBGRA_8888_SkColorType,
Cary Clark4855f782018-02-06 09:41:53 -0500249 kRGBA_1010102_SkColorType,
250 kRGB_101010x_SkColorType,
Cary Clark2dc84ad2018-01-26 12:56:22 -0500251 kGray_8_SkColorType,
252 kRGBA_F16_SkColorType,
Cary Clark06c20f32018-03-20 15:53:27 -0400253
Cary Clark2dc84ad2018-01-26 12:56:22 -0500254 kLastEnum_SkColorType = kRGBA_F16_SkColorType,
Cary Clark186d08f2018-04-03 08:43:27 -0400255###$
Cary Clark06c20f32018-03-20 15:53:27 -0400256 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A)
Cary Clark2dc84ad2018-01-26 12:56:22 -0500257 kN32_SkColorType = kBGRA_8888_SkColorType,
Cary Clark06c20f32018-03-20 15:53:27 -0400258 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A)
Cary Clark2dc84ad2018-01-26 12:56:22 -0500259 kN32_SkColorType = kRGBA_8888_SkColorType,
Cary Clark06c20f32018-03-20 15:53:27 -0400260 #else
261 #error "SK_*32_SHIFT values must correspond to BGRA or RGBA byte order"
262 #endif
Cary Clark06c20f32018-03-20 15:53:27 -0400263$$$#
Cary Clark186d08f2018-04-03 08:43:27 -0400264 };
265#Code ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500266
Cary Clarkf895a422018-02-27 09:54:21 -0500267Describes how pixel bits encode color. A pixel may be an alpha mask, a
Cary Clark137b8742018-05-30 09:21:49 -0400268Grayscale, RGB, or ARGB.
Cary Clark4855f782018-02-06 09:41:53 -0500269
Cary Clarkffb3d682018-05-17 12:17:28 -0400270kN32_SkColorType selects the native 32-bit ARGB format. On Little_Endian
271processors, pixels containing 8-bit ARGB components pack into 32-bit
Cary Clark4855f782018-02-06 09:41:53 -0500272kBGRA_8888_SkColorType. On Big_Endian processors, pixels pack into 32-bit
273kRGBA_8888_SkColorType.
Cary Clark2dc84ad2018-01-26 12:56:22 -0500274
275#Const kUnknown_SkColorType 0
Cary Clark682c58d2018-05-16 07:07:07 -0400276#Line # uninitialized ##
277 Color_Type is set to kUnknown_SkColorType by default. If set,
278 encoding format and size is unknown.
Cary Clarkab2621d2018-01-30 10:08:57 -0500279##
Cary Clarkf895a422018-02-27 09:54:21 -0500280
Cary Clark682c58d2018-05-16 07:07:07 -0400281#Const kAlpha_8_SkColorType 1
282#Line # pixel with Alpha in 8-bit byte ##
283#Details Alpha_8
284 Stores 8-bit byte pixel encoding that represents transparency. Value of zero
285 is completely transparent; a value of 255 is completely opaque.
286##
287
288#Const kRGB_565_SkColorType 2
289#Line # pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word ##
290#Details RGB_565
291 Stores 16-bit word pixel encoding that contains five bits of blue,
292 six bits of green, and five bits of red.
293##
294
295#Const kARGB_4444_SkColorType 3
296#Line # pixel with 4 bits for alpha, red, green, blue; in 16-bit word ##
297#Details ARGB_4444
298 Stores 16-bit word pixel encoding that contains four bits of alpha,
299 four bits of blue, four bits of green, and four bits of red.
300##
301
302#Const kRGBA_8888_SkColorType 4
303#Line # pixel with 8 bits for red, green, blue, alpha; in 32-bit word ##
304#Details RGBA_8888
305 Stores 32-bit word pixel encoding that contains eight bits of red,
306 eight bits of green, eight bits of blue, and eight bits of alpha.
307##
308
309#Const kRGB_888x_SkColorType 5
310#Line # pixel with 8 bits each for red, green, blue; in 32-bit word ##
311#Details RGB_888
312 Stores 32-bit word pixel encoding that contains eight bits of red,
313 eight bits of green, eight bits of blue, and eight unused bits.
314##
315
316#Const kBGRA_8888_SkColorType 6
317#Line # pixel with 8 bits for blue, green, red, alpha; in 32-bit word ##
318#Details BGRA_8888
319 Stores 32-bit word pixel encoding that contains eight bits of blue,
320 eight bits of green, eight bits of red, and eight bits of alpha.
321##
322
323#Const kRGBA_1010102_SkColorType 7
324#Line # 10 bits for red, green, blue; 2 bits for alpha; in 32-bit word ##
325#Details RGBA_1010102
326 Stores 32-bit word pixel encoding that contains ten bits of red,
327 ten bits of green, ten bits of blue, and two bits of alpha.
328##
329
330#Const kRGB_101010x_SkColorType 8
331#Line # pixel with 10 bits each for red, green, blue; in 32-bit word ##
332#Details RGB_101010
333 Stores 32-bit word pixel encoding that contains ten bits of red,
334 ten bits of green, ten bits of blue, and two unused bits.
335##
336
337#Const kGray_8_SkColorType 9
Cary Clark137b8742018-05-30 09:21:49 -0400338#Line # pixel with Grayscale level in 8-bit byte ##
Cary Clark682c58d2018-05-16 07:07:07 -0400339#Details Gray_8
340 Stores 8-bit byte pixel encoding that equivalent to equal values for red,
341 blue, and green, representing colors from black to white.
342##
343
344#Const kRGBA_F16_SkColorType 10
345#Line # pixel with half floats for red, green, blue, alpha; in 64-bit word ##
346#Details RGBA_F16
347 Stores 64-bit word pixel encoding that contains 16 bits of blue,
348 16 bits of green, 16 bits of red, and 16 bits of alpha.
349##
350
351#Const kLastEnum_SkColorType 10
352#NoJustify
353#Line # last valid value ##
354 Used by tests to iterate through all valid values.
355##
356
357#Const kN32_SkColorType 4 or 6
Cary Clark137b8742018-05-30 09:21:49 -0400358#Alias Native_Color_Type ##
Cary Clark682c58d2018-05-16 07:07:07 -0400359#NoJustify
Cary Clarkffb3d682018-05-17 12:17:28 -0400360#Line # native ARGB 32-bit encoding ##
361 Encodes ARGB as either kRGBA_8888_SkColorType or
Cary Clark682c58d2018-05-16 07:07:07 -0400362 kBGRA_8888_SkColorType, whichever is native to the platform.
Cary Clarkf895a422018-02-27 09:54:21 -0500363##
364
365#NoExample
366##
367
368#SeeAlso SkAlphaType SkColorSpace
369
370#Enum SkColorType ##
371
372#Subtopic Alpha_8
Cary Clark682c58d2018-05-16 07:07:07 -0400373#Line # encodes transparency only ##
374 Alpha pixels encode transparency without color information. Value of zero is
375 completely transparent; a value of 255 is completely opaque. Bitmap
376 pixels do not visibly draw, because its pixels have no color information.
377 When SkColorType is set to kAlpha_8_SkColorType, the paired SkAlphaType is
378 ignored.
Cary Clarkf895a422018-02-27 09:54:21 -0500379
Cary Clark682c58d2018-05-16 07:07:07 -0400380 #Example
381 #Description
382 Alpha pixels can modify another draw. orangePaint fills the bounds of bitmap,
383 with its transparency set to alpha8 pixel value.
384 ##
385 #Height 64
386 canvas->scale(16, 16);
387 SkBitmap bitmap;
388 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kAlpha_8_SkColorType, kOpaque_SkAlphaType);
389 bitmap.allocPixels(imageInfo);
390 SkCanvas offscreen(bitmap);
391 offscreen.clear(SK_ColorGREEN);
392 SkPaint orangePaint;
393 orangePaint.setARGB(0xFF, 0xFF, 0xA5, 0x00);
394 canvas->drawBitmap(bitmap, 0, 0, &orangePaint);
395 uint8_t alpha8[] = { 0xFF, 0xBB, 0x77, 0x33 };
396 SkPixmap alphaPixmap(imageInfo, &alpha8, imageInfo.minRowBytes());
397 if (bitmap.writePixels(alphaPixmap, 0, 0)) {
398 canvas->drawBitmap(bitmap, 2, 2, &orangePaint);
399 }
400 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400401 #SeeAlso Alpha Gray_8
Cary Clarkf895a422018-02-27 09:54:21 -0500402##
403
Cary Clark682c58d2018-05-16 07:07:07 -0400404#Subtopic RGB_565
Cary Clarkffb3d682018-05-17 12:17:28 -0400405#Line # encodes RGB in 16 bits ##
406 kRGB_565_SkColorType encodes RGB to fit in a 16-bit word. Red and blue
Cary Clark682c58d2018-05-16 07:07:07 -0400407 components use five bits describing 32 levels. Green components, more sensitive
408 to the eye, use six bits describing 64 levels. kRGB_565_SkColorType has no
409 bits for Alpha.
410
411 Pixels are fully opaque as if its Color_Alpha was set to one, and should
412 always be paired with kOpaque_SkAlphaType.
Cary Clarkf895a422018-02-27 09:54:21 -0500413
Cary Clark682c58d2018-05-16 07:07:07 -0400414 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500415
Cary Clark682c58d2018-05-16 07:07:07 -0400416 #Example
417 #Height 96
418 canvas->scale(16, 16);
419 SkBitmap bitmap;
420 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGB_565_SkColorType, kOpaque_SkAlphaType);
421 bitmap.allocPixels(imageInfo);
422 SkCanvas offscreen(bitmap);
423 offscreen.clear(SK_ColorGREEN);
424 canvas->drawBitmap(bitmap, 0, 0);
425 auto pack565 = [](unsigned r, unsigned g, unsigned b) -> uint16_t {
426 return (b << 0) | (g << 5) | (r << 11);
427 };
428 uint16_t red565[] = { pack565(0x1F, 0x00, 0x00), pack565(0x17, 0x00, 0x00),
429 pack565(0x0F, 0x00, 0x00), pack565(0x07, 0x00, 0x00) };
430 uint16_t blue565[] = { pack565(0x00, 0x00, 0x1F), pack565(0x00, 0x00, 0x17),
431 pack565(0x00, 0x00, 0x0F), pack565(0x00, 0x00, 0x07) };
432 SkPixmap redPixmap(imageInfo, &red565, imageInfo.minRowBytes());
433 if (bitmap.writePixels(redPixmap, 0, 0)) {
434 canvas->drawBitmap(bitmap, 2, 2);
435 }
436 SkPixmap bluePixmap(imageInfo, &blue565, imageInfo.minRowBytes());
437 if (bitmap.writePixels(bluePixmap, 0, 0)) {
438 canvas->drawBitmap(bitmap, 4, 4);
439 }
440 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400441 #SeeAlso ARGB_4444 RGBA_8888
Cary Clarkf895a422018-02-27 09:54:21 -0500442##
443
Cary Clark682c58d2018-05-16 07:07:07 -0400444#Subtopic ARGB_4444
Cary Clarkffb3d682018-05-17 12:17:28 -0400445#Line # encodes ARGB in 16 bits ##
446 kARGB_4444_SkColorType encodes ARGB to fit in 16-bit word. Each
Cary Clark682c58d2018-05-16 07:07:07 -0400447 component: alpha, blue, green, and red; use four bits, describing 16 levels.
448 Note that kARGB_4444_SkColorType is misnamed; the acronym does not
449 describe the actual component order.
Cary Clarkf895a422018-02-27 09:54:21 -0500450
Cary Clark682c58d2018-05-16 07:07:07 -0400451 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500452
Cary Clark682c58d2018-05-16 07:07:07 -0400453 If paired with kPremul_SkAlphaType: blue, green, and red components are
454 Premultiplied by the alpha value. If blue, green, or red is greater than alpha,
455 the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500456
Cary Clark682c58d2018-05-16 07:07:07 -0400457 If paired with kUnpremul_SkAlphaType: alpha, blue, green, and red components
458 may have any value. There may be a performance penalty with Unpremultipled
459 pixels.
Cary Clarkf895a422018-02-27 09:54:21 -0500460
Cary Clark682c58d2018-05-16 07:07:07 -0400461 If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum;
462 blue, green, and red components are fully opaque. If any alpha component is
463 less than 15, the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500464
Cary Clark682c58d2018-05-16 07:07:07 -0400465 #Bug 7648
Cary Clarkf895a422018-02-27 09:54:21 -0500466
Cary Clark682c58d2018-05-16 07:07:07 -0400467 #Example
468 #Height 96
469 canvas->scale(16, 16);
470 SkBitmap bitmap;
471 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, kPremul_SkAlphaType);
472 bitmap.allocPixels(imageInfo);
473 SkCanvas offscreen(bitmap);
474 offscreen.clear(SK_ColorGREEN);
475 canvas->drawBitmap(bitmap, 0, 0);
476 auto pack4444 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint16_t {
477 return (a << 0) | (b << 4) | (g << 8) | (r << 12);
478 };
479 uint16_t red4444[] = { pack4444(0xF, 0xF, 0x0, 0x0), pack4444(0xF, 0xb, 0x0, 0x0),
480 pack4444(0xF, 0x7, 0x0, 0x0), pack4444(0xF, 0x3, 0x0, 0x0) };
481 uint16_t blue4444[] = { pack4444(0xF, 0x0, 0x0, 0xF), pack4444(0xF, 0x0, 0x0, 0xb),
482 pack4444(0xF, 0x0, 0x0, 0x7), pack4444(0xF, 0x0, 0x0, 0x3) };
483 SkPixmap redPixmap(imageInfo, &red4444, imageInfo.minRowBytes());
484 if (bitmap.writePixels(redPixmap, 0, 0)) {
485 canvas->drawBitmap(bitmap, 2, 2);
486 }
487 SkPixmap bluePixmap(imageInfo, &blue4444, imageInfo.minRowBytes());
488 if (bitmap.writePixels(bluePixmap, 0, 0)) {
489 canvas->drawBitmap(bitmap, 4, 4);
490 }
491 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400492 #SeeAlso RGBA_8888
Cary Clarkf895a422018-02-27 09:54:21 -0500493##
494
495#Subtopic RGBA_8888
Cary Clarkffb3d682018-05-17 12:17:28 -0400496#Line # encodes ARGB Big_Endian in 32 bits ##
497 kRGBA_8888_SkColorType encodes ARGB into a 32-bit word. Each component:
Cary Clark682c58d2018-05-16 07:07:07 -0400498 red, green, blue, alpha; use eight bits, describing 256 levels.
Cary Clarkf895a422018-02-27 09:54:21 -0500499
Cary Clark682c58d2018-05-16 07:07:07 -0400500 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500501
Cary Clark682c58d2018-05-16 07:07:07 -0400502 If paired with kPremul_SkAlphaType: red, green, and blue components are
503 Premultiplied by the alpha value. If red, green, or blue is greater than alpha,
504 the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500505
Cary Clark682c58d2018-05-16 07:07:07 -0400506 If paired with kUnpremul_SkAlphaType: alpha, red, green, and blue components
507 may have any value. There may be a performance penalty with Unpremultipled
508 pixels.
Cary Clarkf895a422018-02-27 09:54:21 -0500509
Cary Clark682c58d2018-05-16 07:07:07 -0400510 If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum;
511 red, green, and blue components are fully opaque. If any alpha component is
512 less than 255, the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500513
Cary Clark682c58d2018-05-16 07:07:07 -0400514 On Big_Endian platforms, kRGBA_8888_SkColorType is the native Color_Type, and
515 will have the best performance. Use kN32_SkColorType to choose the best
516 Color_Type for the platform at compile time.
Cary Clarkf895a422018-02-27 09:54:21 -0500517
Cary Clark682c58d2018-05-16 07:07:07 -0400518 #Example
519 #Height 96
520 canvas->scale(16, 16);
521 SkBitmap bitmap;
522 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
523 bitmap.allocPixels(imageInfo);
524 SkCanvas offscreen(bitmap);
525 offscreen.clear(SK_ColorGREEN);
526 canvas->drawBitmap(bitmap, 0, 0);
527 auto pack8888 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint32_t {
528 return (r << 0) | (g << 8) | (b << 16) | (a << 24);
529 };
530 uint32_t red8888[] = { pack8888(0xFF, 0xFF, 0x0, 0x0), pack8888(0xFF, 0xbb, 0x0, 0x0),
531 pack8888(0xFF, 0x77, 0x0, 0x0), pack8888(0xFF, 0x33, 0x0, 0x0) };
532 uint32_t blue8888[] = { pack8888(0xFF, 0x0, 0x0, 0x0FF), pack8888(0xFF, 0x0, 0x0, 0x0bb),
533 pack8888(0xFF, 0x0, 0x0, 0x077), pack8888(0xFF, 0x0, 0x0, 0x033) };
534 SkPixmap redPixmap(imageInfo, &red8888, imageInfo.minRowBytes());
535 if (bitmap.writePixels(redPixmap, 0, 0)) {
536 canvas->drawBitmap(bitmap, 2, 2);
537 }
538 SkPixmap bluePixmap(imageInfo, &blue8888, imageInfo.minRowBytes());
539 if (bitmap.writePixels(bluePixmap, 0, 0)) {
540 canvas->drawBitmap(bitmap, 4, 4);
541 }
542 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400543 #SeeAlso RGB_888 BGRA_8888
Cary Clarkf895a422018-02-27 09:54:21 -0500544##
545
Cary Clark682c58d2018-05-16 07:07:07 -0400546#Subtopic RGB_888
Cary Clarkffb3d682018-05-17 12:17:28 -0400547#Line # encodes RGB in 32 bits ##
548 kRGB_888x_SkColorType encodes RGB into a 32-bit word. Each component:
Cary Clark682c58d2018-05-16 07:07:07 -0400549 red, green, blue; use eight bits, describing 256 levels. Eight bits are
550 unused. Pixels described by kRGB_888x_SkColorType are fully opaque as if
551 their Color_Alpha was set to one, and should always be paired with
552 kOpaque_SkAlphaType.
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 #Example
557 #Bug 7645
558 #Height 96
559 #Platform cpu
560 canvas->scale(16, 16);
561 SkBitmap bitmap;
562 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGB_888x_SkColorType, kOpaque_SkAlphaType);
563 bitmap.allocPixels(imageInfo);
564 SkCanvas offscreen(bitmap);
565 offscreen.clear(SK_ColorGREEN);
566 canvas->drawBitmap(bitmap, 0, 0);
567 auto pack888 = [](unsigned r, unsigned g, unsigned b) -> uint32_t {
568 return (r << 0) | (g << 8) | (b << 16);
569 };
570 uint32_t red888[] = { pack888(0xFF, 0x00, 0x00), pack888(0xbb, 0x00, 0x00),
571 pack888(0x77, 0x00, 0x00), pack888(0x33, 0x00, 0x00) };
572 uint32_t blue888[] = { pack888(0x00, 0x00, 0xFF), pack888(0x00, 0x00, 0xbb),
573 pack888(0x00, 0x00, 0x77), pack888(0x00, 0x00, 0x33) };
574 if (bitmap.installPixels(imageInfo, (void*) red888, imageInfo.minRowBytes())) {
575 canvas->drawBitmap(bitmap, 2, 2);
576 }
577 if (bitmap.installPixels(imageInfo, (void*) blue888, imageInfo.minRowBytes())) {
578 canvas->drawBitmap(bitmap, 4, 4);
579 }
580 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400581 #SeeAlso RGBA_8888 BGRA_8888
Cary Clarkf895a422018-02-27 09:54:21 -0500582##
583
584#Subtopic BGRA_8888
Cary Clarkffb3d682018-05-17 12:17:28 -0400585#Line # encodes ARGB Little_Endian in 32 bits ##
586 kBGRA_8888_SkColorType encodes ARGB into a 32-bit word. Each component:
Cary Clark682c58d2018-05-16 07:07:07 -0400587 blue, green, red, and alpha; use eight bits, describing 256 levels.
Cary Clarkf895a422018-02-27 09:54:21 -0500588
Cary Clark682c58d2018-05-16 07:07:07 -0400589 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500590
Cary Clark682c58d2018-05-16 07:07:07 -0400591 If paired with kPremul_SkAlphaType: blue, green, and red components are
592 Premultiplied by the alpha value. If blue, green, or red is greater than alpha,
593 the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500594
Cary Clark682c58d2018-05-16 07:07:07 -0400595 If paired with kUnpremul_SkAlphaType: blue, green, red, and alpha components
596 may have any value. There may be a performance penalty with Unpremultiplied
597 pixels.
Cary Clarkf895a422018-02-27 09:54:21 -0500598
Cary Clark682c58d2018-05-16 07:07:07 -0400599 If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum;
600 blue, green, and red components are fully opaque. If any alpha component is
601 less than 255, the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500602
Cary Clark682c58d2018-05-16 07:07:07 -0400603 On Little_Endian platforms, kBGRA_8888_SkColorType is the native Color_Type,
604 and will have the best performance. Use kN32_SkColorType to choose the best
605 Color_Type for the platform at compile time.
Cary Clarkf895a422018-02-27 09:54:21 -0500606
Cary Clark682c58d2018-05-16 07:07:07 -0400607 #Example
608 #Height 96
609 canvas->scale(16, 16);
610 SkBitmap bitmap;
611 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
612 bitmap.allocPixels(imageInfo);
613 SkCanvas offscreen(bitmap);
614 offscreen.clear(SK_ColorGREEN);
615 canvas->drawBitmap(bitmap, 0, 0);
616 auto pack8888 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint32_t {
617 return (b << 0) | (g << 8) | (r << 16) | (a << 24);
618 };
619 uint32_t red8888[] = { pack8888(0xFF, 0xFF, 0x0, 0x0), pack8888(0xFF, 0xbb, 0x0, 0x0),
620 pack8888(0xFF, 0x99, 0x0, 0x0), pack8888(0xFF, 0x55, 0x0, 0x0) };
621 uint32_t blue8888[] = { pack8888(0xFF, 0x0, 0x0, 0x0FF), pack8888(0xFF, 0x0, 0x0, 0x0bb),
622 pack8888(0xFF, 0x0, 0x0, 0x099), pack8888(0xFF, 0x0, 0x0, 0x055) };
623 SkPixmap redPixmap(imageInfo, &red8888, imageInfo.minRowBytes());
624 if (bitmap.writePixels(redPixmap, 0, 0)) {
625 canvas->drawBitmap(bitmap, 2, 2);
626 }
627 SkPixmap bluePixmap(imageInfo, &blue8888, imageInfo.minRowBytes());
628 if (bitmap.writePixels(bluePixmap, 0, 0)) {
629 canvas->drawBitmap(bitmap, 4, 4);
630 }
631 ##
632 #SeeAlso RGBA_8888
Cary Clarkf895a422018-02-27 09:54:21 -0500633##
634
635#Subtopic RGBA_1010102
Cary Clarkffb3d682018-05-17 12:17:28 -0400636#Line # encodes ARGB ten bits per color component ##
637 kRGBA_1010102_SkColorType encodes ARGB into a 32-bit word. Each
Cary Clark682c58d2018-05-16 07:07:07 -0400638 Color component: red, green, and blue; use ten bits, describing 1024 levels.
639 Two bits contain alpha, describing four levels. Possible alpha
640 values are zero: fully transparent; one: 33% opaque; two: 67% opaque;
641 three: fully opaque.
Cary Clarkf895a422018-02-27 09:54:21 -0500642
Cary Clark682c58d2018-05-16 07:07:07 -0400643 At present, Color in Paint does not provide enough precision to
644 draw all colors possible to a kRGBA_1010102_SkColorType Surface.
Cary Clarkf895a422018-02-27 09:54:21 -0500645
Cary Clark682c58d2018-05-16 07:07:07 -0400646 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500647
Cary Clark682c58d2018-05-16 07:07:07 -0400648 If paired with kPremul_SkAlphaType: red, green, and blue components are
649 Premultiplied by the alpha value. If red, green, or blue is greater than the
650 alpha replicated to ten bits, the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500651
Cary Clark682c58d2018-05-16 07:07:07 -0400652 If paired with kUnpremul_SkAlphaType: alpha, red, green, and blue components
653 may have any value. There may be a performance penalty with Unpremultiplied
654 pixels.
Cary Clarkf895a422018-02-27 09:54:21 -0500655
Cary Clark682c58d2018-05-16 07:07:07 -0400656 If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum;
657 red, green, and blue components are fully opaque. If any alpha component is
658 less than three, the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500659
Cary Clark682c58d2018-05-16 07:07:07 -0400660 #Example
661 #Bug 7645
662 #Height 96
663 #Platform cpu
664 canvas->scale(16, 16);
665 SkBitmap bitmap;
666 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGBA_1010102_SkColorType, kOpaque_SkAlphaType);
667 bitmap.allocPixels(imageInfo);
668 SkCanvas offscreen(bitmap);
669 offscreen.clear(SK_ColorGREEN);
670 canvas->drawBitmap(bitmap, 0, 0);
671 auto pack1010102 = [](unsigned r, unsigned g, unsigned b, unsigned a) -> uint32_t {
672 return (r << 0) | (g << 10) | (b << 20) | (a << 30);
673 };
674 uint32_t redBits[] = { pack1010102(0x3FF, 0x000, 0x000, 0x3),
675 pack1010102(0x2ff, 0x000, 0x000, 0x3),
676 pack1010102(0x1ff, 0x000, 0x000, 0x3),
677 pack1010102(0x0ff, 0x000, 0x000, 0x3) };
678 uint32_t blueBits[] = { pack1010102(0x000, 0x000, 0x3FF, 0x3),
679 pack1010102(0x000, 0x000, 0x2ff, 0x3),
680 pack1010102(0x000, 0x000, 0x1ff, 0x3),
681 pack1010102(0x000, 0x000, 0x0ff, 0x3) };
682 if (bitmap.installPixels(imageInfo, (void*) redBits, imageInfo.minRowBytes())) {
683 canvas->drawBitmap(bitmap, 2, 2);
684 }
685 SkPixmap bluePixmap(imageInfo, &blueBits, imageInfo.minRowBytes());
686 if (bitmap.installPixels(imageInfo, (void*) blueBits, imageInfo.minRowBytes())) {
687 canvas->drawBitmap(bitmap, 4, 4);
688 }
689 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400690 #SeeAlso RGB_101010 RGBA_8888
Cary Clarkf895a422018-02-27 09:54:21 -0500691##
692
Cary Clark682c58d2018-05-16 07:07:07 -0400693#Subtopic RGB_101010
Cary Clarkffb3d682018-05-17 12:17:28 -0400694#Line # encodes RGB ten bits per color component ##
695 kRGB_101010x_SkColorType encodes RGB into a 32-bit word. Each
Cary Clark682c58d2018-05-16 07:07:07 -0400696 Color component: red, green, and blue; use ten bits, describing 1024 levels.
697 Two bits are unused. Pixels described by kRGB_101010x_SkColorType are fully
698 opaque as if its Color_Alpha was set to one, and should always be paired
699 with kOpaque_SkAlphaType.
Cary Clarkf895a422018-02-27 09:54:21 -0500700
Cary Clark682c58d2018-05-16 07:07:07 -0400701 At present, Color in Paint does not provide enough precision to
702 draw all colors possible to a kRGB_101010x_SkColorType Surface.
Cary Clark681287e2018-03-16 11:34:15 -0400703
Cary Clark682c58d2018-05-16 07:07:07 -0400704 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500705
Cary Clark682c58d2018-05-16 07:07:07 -0400706 #Example
707 #Bug 7645
708 #Height 96
709 #Platform cpu
710 canvas->scale(16, 16);
711 SkBitmap bitmap;
712 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGB_101010x_SkColorType, kOpaque_SkAlphaType);
713 bitmap.allocPixels(imageInfo);
714 SkCanvas offscreen(bitmap);
715 offscreen.clear(SK_ColorGREEN);
716 canvas->drawBitmap(bitmap, 0, 0);
717 auto pack101010x = [](unsigned r, unsigned g, unsigned b) -> uint32_t {
718 return (r << 0) | (g << 10) | (b << 20);
719 };
720 uint32_t redBits[] = { pack101010x(0x3FF, 0x000, 0x000), pack101010x(0x2ff, 0x000, 0x000),
721 pack101010x(0x1ff, 0x000, 0x000), pack101010x(0x0ff, 0x000, 0x000) };
722 uint32_t blueBits[] = { pack101010x(0x000, 0x000, 0x3FF), pack101010x(0x000, 0x000, 0x2ff),
723 pack101010x(0x000, 0x000, 0x1ff), pack101010x(0x000, 0x000, 0x0ff) };
724 if (bitmap.installPixels(imageInfo, (void*) redBits, imageInfo.minRowBytes())) {
725 canvas->drawBitmap(bitmap, 2, 2);
726 }
727 SkPixmap bluePixmap(imageInfo, &blueBits, imageInfo.minRowBytes());
728 if (bitmap.installPixels(imageInfo, (void*) blueBits, imageInfo.minRowBytes())) {
729 canvas->drawBitmap(bitmap, 4, 4);
730 }
731 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400732 #SeeAlso RGBA_1010102
Cary Clarkf895a422018-02-27 09:54:21 -0500733##
734
735#Subtopic Gray_8
Cary Clark137b8742018-05-30 09:21:49 -0400736#Line # encodes level of Grayscale in 8 bits ##
737 kGray_8_SkColorType encodes Grayscale level in eight bits that is equivalent
Cary Clark682c58d2018-05-16 07:07:07 -0400738 to equal values for red, blue, and green, representing colors from black to
739 white. Pixels described by kGray_8_SkColorType are fully
740 opaque as if its Color_Alpha was set to one, and should always be paired with
741 kOpaque_SkAlphaType.
Cary Clarkf895a422018-02-27 09:54:21 -0500742
Cary Clark682c58d2018-05-16 07:07:07 -0400743 #Example
744 #Height 64
745 canvas->scale(16, 16);
746 SkBitmap bitmap;
747 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kGray_8_SkColorType, kOpaque_SkAlphaType);
748 bitmap.allocPixels(imageInfo);
749 SkCanvas offscreen(bitmap);
750 offscreen.clear(SK_ColorGREEN);
751 canvas->drawBitmap(bitmap, 0, 0);
752 uint8_t gray8[] = { 0xFF, 0xBB, 0x77, 0x33 };
753 SkPixmap grayPixmap(imageInfo, &gray8, imageInfo.minRowBytes());
754 if (bitmap.writePixels(grayPixmap, 0, 0)) {
755 canvas->drawBitmap(bitmap, 2, 2);
756 }
757 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400758 #SeeAlso Alpha_8
Cary Clarkf895a422018-02-27 09:54:21 -0500759##
760
761#Subtopic RGBA_F16
Cary Clarkffb3d682018-05-17 12:17:28 -0400762#Line # encodes ARGB as half floats ##
763 kRGBA_F16_SkColorType encodes ARGB into a 64-bit word. Each component:
Cary Clark682c58d2018-05-16 07:07:07 -0400764 blue, green, red, and alpha; use 16 bits, describing a floating point value.
Cary Clark929e4362018-06-19 09:07:28 -0400765 from -65500 to 65000 with 3.31 decimal digits of precision.
Cary Clarkf895a422018-02-27 09:54:21 -0500766
Cary Clark682c58d2018-05-16 07:07:07 -0400767 At present, Color in Paint does not provide enough precision or range to
768 draw all colors possible to a kRGBA_F16_SkColorType Surface.
Cary Clark681287e2018-03-16 11:34:15 -0400769
Cary Clark682c58d2018-05-16 07:07:07 -0400770 Each component encodes a floating point value using
771 #A Half floats # https://www.khronos.org/opengl/wiki/Small_Float_Formats ##
772 . Meaningful colors are represented by the range 0.0 to 1.0, although smaller
773 and larger values may be useful when used in combination with Transfer_Mode.
Cary Clark681287e2018-03-16 11:34:15 -0400774
Cary Clark682c58d2018-05-16 07:07:07 -0400775 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500776
Cary Clark682c58d2018-05-16 07:07:07 -0400777 If paired with kPremul_SkAlphaType: blue, green, and red components are
778 Premultiplied by the alpha value. If blue, green, or red is greater than alpha,
779 the drawn result is undefined.
Cary Clark681287e2018-03-16 11:34:15 -0400780
Cary Clark682c58d2018-05-16 07:07:07 -0400781 If paired with kUnpremul_SkAlphaType: blue, green, red, and alpha components
782 may have any value. There may be a performance penalty with Unpremultiplied
783 pixels.
Cary Clark681287e2018-03-16 11:34:15 -0400784
Cary Clark682c58d2018-05-16 07:07:07 -0400785 If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum;
786 blue, green, and red components are fully opaque. If any alpha component is
787 less than 255, the drawn result is undefined.
Cary Clark681287e2018-03-16 11:34:15 -0400788
Cary Clark682c58d2018-05-16 07:07:07 -0400789 #ToDo
790 FloatToHalf should be replaced with SkFloatToHalf if/when that's made public
791 ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500792
Cary Clark682c58d2018-05-16 07:07:07 -0400793 #Example
794 #Height 96
795 #Function
796 union FloatUIntUnion {
797 uint32_t fUInt;
798 float fFloat;
Cary Clarkf895a422018-02-27 09:54:21 -0500799 };
Cary Clark682c58d2018-05-16 07:07:07 -0400800
801 uint16_t FloatToHalf(float f) {
802 static const FloatUIntUnion magic = { 15 << 23 };
803 static const uint32_t round_mask = ~0xfffu;
804 FloatUIntUnion floatUnion;
805 floatUnion.fFloat = f;
806 uint32_t sign = floatUnion.fUInt & 0x80000000u;
807 floatUnion.fUInt ^= sign;
808 floatUnion.fUInt &= round_mask;
809 floatUnion.fFloat *= magic.fFloat;
810 floatUnion.fUInt -= round_mask;
811 return (floatUnion.fUInt >> 13) | (sign >> 16);
Cary Clarkf895a422018-02-27 09:54:21 -0500812 }
Cary Clark682c58d2018-05-16 07:07:07 -0400813 ##
814
815 void draw(SkCanvas* canvas) {
816 canvas->scale(16, 16);
817 SkBitmap bitmap;
818 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
819 bitmap.allocPixels(imageInfo);
820 SkCanvas offscreen(bitmap);
821 offscreen.clear(SK_ColorGREEN);
822 canvas->drawBitmap(bitmap, 0, 0);
823 auto H = [](float c) -> uint16_t {
824 return FloatToHalf(c);
825 };
826 // R G B A
827 uint16_t red_f16[][4] = { { H(1.0f), H(0.0f), H(0.0f), H(1.0f) },
828 { H(.75f), H(0.0f), H(0.0f), H(1.0f) },
829 { H(.50f), H(0.0f), H(0.0f), H(1.0f) },
830 { H(.25f), H(0.0f), H(0.0f), H(1.0f) } };
831 uint16_t blue_f16[][4] = { { H(0.0f), H(0.0f), H(1.0f), H(1.0f) },
832 { H(0.0f), H(0.0f), H(.75f), H(1.0f) },
833 { H(0.0f), H(0.0f), H(.50f), H(1.0f) },
834 { H(0.0f), H(0.0f), H(.25f), H(1.0f) } };
835 SkPixmap redPixmap(imageInfo, red_f16, imageInfo.minRowBytes());
836 if (bitmap.writePixels(redPixmap, 0, 0)) {
837 canvas->drawBitmap(bitmap, 2, 2);
838 }
839 SkPixmap bluePixmap(imageInfo, blue_f16, imageInfo.minRowBytes());
840 if (bitmap.writePixels(bluePixmap, 0, 0)) {
841 canvas->drawBitmap(bitmap, 4, 4);
842 }
Cary Clarkf895a422018-02-27 09:54:21 -0500843 }
Cary Clark682c58d2018-05-16 07:07:07 -0400844 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400845 #SeeAlso SkColor4f
Cary Clarkf895a422018-02-27 09:54:21 -0500846##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500847
Cary Clark08895c42018-02-01 09:37:32 -0500848#Subtopic Color_Type ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500849
850# ------------------------------------------------------------------------------
Cary Clark681287e2018-03-16 11:34:15 -0400851
852#Method int SkColorTypeBytesPerPixel(SkColorType ct)
853#In Property
854#Line # returns Color_Type byte size ##
855
856Returns the number of bytes required to store a pixel, including unused padding.
857Returns zero if ct is kUnknown_SkColorType or invalid.
858
859#Param ct one of: #list_of_color_types#
860##
861
862#Return bytes per pixel ##
863
864#Example
865#Height 192
866 const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
867 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" };
868 SkPaint paint;
869 paint.setTypeface(SkTypeface::MakeFromName("monospace", SkFontStyle()));
870 paint.setAntiAlias(true);
871 paint.setTextSize(10);
872 int y = 15;
873 canvas->drawString(" colorType bytes", 10, y, paint);
874 for (SkColorType colorType : { #list_of_color_types#
875 } ) {
876 int result = SkColorTypeBytesPerPixel(colorType);
877 SkString string;
878 string.printf("%13s %4d", colors[(int) colorType], result);
879 canvas->drawString(string, 10, y += 14, paint);
880 }
881##
882#SeeAlso SkImageInfo::bytesPerPixel
883##
884
885# ------------------------------------------------------------------------------
886
887#Method bool SkColorTypeIsAlwaysOpaque(SkColorType ct)
888#In Property
889#Line # returns if Color_Type includes Color_Alpha ##
890
891Returns true if Color_Type always decodes Color_Alpha to 1.0, making the pixel
892fully opaque. If true, Color_Type does not reserve bits to encode Color_Alpha.
893
894#Param ct one of: #list_of_color_types#
895##
896
897#Return true if Color_Alpha is always set to 1.0 ##
898
899#Example
900#Height 192
901 const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
902 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" };
903 SkPaint paint;
904 paint.setTypeface(SkTypeface::MakeFromName("monospace", SkFontStyle()));
905 paint.setAntiAlias(true);
906 paint.setTextSize(10);
907 int y = 15;
908 canvas->drawString(" colorType bytes", 10, y, paint);
909 for (SkColorType colorType : { #list_of_color_types#
910 } ) {
911 bool result = SkColorTypeIsAlwaysOpaque(colorType);
912 SkString string;
913 string.printf("%13s %6s", colors[(int) colorType], result ? "true" : "false");
914 canvas->drawString(string, 10, y += 14, paint);
915 }
916##
917#SeeAlso SkColorTypeValidateAlphaType
918##
919
920# ------------------------------------------------------------------------------
921
922#Method bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType,
923 SkAlphaType* canonical = nullptr)
924#In Property
925#Line # returns if Alpha_Type is valid ##
926
927Returns true if canonical can be set to a valid Alpha_Type for colorType. If
928there is more than one valid canonical Alpha_Type, set to alphaType, if valid.
929If true is returned and canonical is not nullptr, store valid Alpha_Type.
930
931Returns false only if alphaType is kUnknown_SkAlphaType, color type is not
932kUnknown_SkColorType, and Color_Type is not always opaque. If false is returned,
933canonical is ignored.
934
935For kUnknown_SkColorType: set canonical to kUnknown_SkAlphaType and return true.
Cary Clark682c58d2018-05-16 07:07:07 -0400936For kAlpha_8_SkColorType: set canonical to kPremul_SkAlphaType or
Cary Clark681287e2018-03-16 11:34:15 -0400937kOpaque_SkAlphaType and return true if alphaType is not kUnknown_SkAlphaType.
938For kRGB_565_SkColorType, kRGB_888x_SkColorType, kRGB_101010x_SkColorType, and
939kGray_8_SkColorType: set canonical to kOpaque_SkAlphaType and return true.
940For kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kBGRA_8888_SkColorType,
941kRGBA_1010102_SkColorType, and kRGBA_F16_SkColorType: set canonical to alphaType
942and return true if alphaType is not kUnknown_SkAlphaType.
943
944#Param colorType one of: #list_of_color_types#
945##
946#Param alphaType one of: #list_of_alpha_types#
947##
948#Param canonical storage for Alpha_Type ##
949
950#Return true if valid Alpha_Type can be associated with colorType ##
951
952#Example
953#Height 640
954 const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
955 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" };
956 const char* alphas[] = {"Unknown ", "Opaque ", "Premul ", "Unpremul"};
957 SkAlphaType alphaTypes[] = { #list_of_alpha_types#
958 };
959 SkPaint paint;
960 paint.setTypeface(SkTypeface::MakeFromName("monospace", SkFontStyle()));
961 paint.setAntiAlias(true);
962 paint.setTextSize(10);
963 int y = 15;
964 canvas->drawString(" colorType alphaType canonical", 10, y, paint);
965 for (SkColorType colorType : { #list_of_color_types#
966 } ) {
967 for (SkAlphaType alphaType : alphaTypes) {
968 SkAlphaType canonicalAlphaType = kUnknown_SkAlphaType;
969 bool result = SkColorTypeValidateAlphaType(colorType, alphaType, &canonicalAlphaType);
970 SkString string;
971 string.printf("%13s %10s %10s", colors[(int) colorType], alphas[(int) alphaType],
972 result ? alphas[(int) canonicalAlphaType] : "------ ");
973 canvas->drawString(string, 10, y += 14, paint);
974 }
975 }
976##
977#SeeAlso SkColorTypeIsAlwaysOpaque
978##
979
980# ------------------------------------------------------------------------------
Cary Clark772953472018-02-12 09:38:08 -0500981#Subtopic YUV_ColorSpace
Cary Clark682c58d2018-05-16 07:07:07 -0400982#Line # color range of YUV pixels ##
Cary Clark137b8742018-05-30 09:21:49 -0400983#Alias YUV_ColorSpace ##
984
Cary Clark2dc84ad2018-01-26 12:56:22 -0500985#Enum SkYUVColorSpace
Cary Clark06c20f32018-03-20 15:53:27 -0400986#Line # color range of YUV pixels ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500987
988#Code
989 enum SkYUVColorSpace {
990 kJPEG_SkYUVColorSpace,
991 kRec601_SkYUVColorSpace,
992 kRec709_SkYUVColorSpace,
993 kLastEnum_SkYUVColorSpace = kRec709_SkYUVColorSpace,
994 };
995##
996
Cary Clark06c20f32018-03-20 15:53:27 -0400997Describes color range of YUV pixels. The color mapping from YUV to RGB varies
998depending on the source. YUV pixels may be generated by JPEG images, standard
999video streams, or high definition video streams. Each has its own mapping from
1000YUV and RGB.
1001
1002JPEG YUV values encode the full range of 0 to 255 for all three components.
1003Video YUV values range from 16 to 235 for all three components. Details of
Cary Clark682c58d2018-05-16 07:07:07 -04001004encoding and conversion to RGB are described in
Cary Clark06c20f32018-03-20 15:53:27 -04001005#A YCbCr color space # https://en.wikipedia.org/wiki/YCbCr ##
1006.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001007
1008#Const kJPEG_SkYUVColorSpace 0
Cary Clark682c58d2018-05-16 07:07:07 -04001009#Line # describes full range ##
1010Describes standard JPEG color space;
Cary Clark06c20f32018-03-20 15:53:27 -04001011#A CCIR 601 # https://en.wikipedia.org/wiki/Rec._601 ##
1012with full range of 0 to 255 for components.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001013##
1014#Const kRec601_SkYUVColorSpace 1
Cary Clark682c58d2018-05-16 07:07:07 -04001015#Line # describes SDTV range ##
1016Describes standard used by standard definition television;
Cary Clark06c20f32018-03-20 15:53:27 -04001017#A CCIR 601 # https://en.wikipedia.org/wiki/Rec._601 ##
1018with studio range of 16 to 235 range for components.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001019##
1020#Const kRec709_SkYUVColorSpace 2
Cary Clark682c58d2018-05-16 07:07:07 -04001021#Line # describes HDTV range ##
1022Describes standard used by high definition television;
1023#A Rec. 709 # https://en.wikipedia.org/wiki/Rec._709 ##
Cary Clark06c20f32018-03-20 15:53:27 -04001024with studio range of 16 to 235 range for components.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001025##
Cary Clark682c58d2018-05-16 07:07:07 -04001026#Const kLastEnum_SkYUVColorSpace 2
1027#Line # last valid value ##
1028 Used by tests to iterate through all valid values.
1029##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001030
Cary Clark06c20f32018-03-20 15:53:27 -04001031#NoExample
Cary Clark2dc84ad2018-01-26 12:56:22 -05001032##
1033
Cary Clark06c20f32018-03-20 15:53:27 -04001034#SeeAlso SkImage::MakeFromYUVTexturesCopy SkImage::MakeFromNV12TexturesCopy
Cary Clark2dc84ad2018-01-26 12:56:22 -05001035
1036#Enum SkYUVColorSpace ##
Cary Clark772953472018-02-12 09:38:08 -05001037#Subtopic YUV_ColorSpace ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001038
1039# ------------------------------------------------------------------------------
Cary Clark2dc84ad2018-01-26 12:56:22 -05001040
1041#Struct SkImageInfo
1042
Cary Clark682c58d2018-05-16 07:07:07 -04001043Describes pixel dimensions and encoding. Bitmap, Image, PixMap, and Surface
Cary Clark1a8d7622018-03-05 13:26:16 -05001044can be created from Image_Info. Image_Info can be retrieved from Bitmap and
1045Pixmap, but not from Image and Surface. For example, Image and Surface
1046implementations may defer pixel depth, so may not completely specify Image_Info.
1047
1048Image_Info contains dimensions, the pixel integral width and height. It encodes
1049how pixel bits describe Color_Alpha, transparency; Color components red, blue,
1050and green; and Color_Space, the range and linearity of colors.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001051
Cary Clark4855f782018-02-06 09:41:53 -05001052#Subtopic Member_Function
Cary Clark08895c42018-02-01 09:37:32 -05001053#Populate
1054##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001055
Cary Clark78de7512018-02-07 07:27:09 -05001056#Subtopic Related_Function
Cary Clark08895c42018-02-01 09:37:32 -05001057#Populate
1058##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001059
1060# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05001061#Subtopic Constructor
1062#Populate
1063##
1064
Cary Clark2dc84ad2018-01-26 12:56:22 -05001065#Method SkImageInfo()
1066
Cary Clark4855f782018-02-06 09:41:53 -05001067#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001068#Line # creates with zero dimensions, kUnknown_SkColorType, kUnknown_SkAlphaType ##
Cary Clark06c20f32018-03-20 15:53:27 -04001069Creates an empty Image_Info with kUnknown_SkColorType, kUnknown_SkAlphaType,
Cary Clark1a8d7622018-03-05 13:26:16 -05001070a width and height of zero, and no Color_Space.
1071
1072#Return empty Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001073
1074#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001075#Height 32
1076#Description
1077An empty Image_Info may be passed to SkCanvas::accessTopLayerPixels as storage
1078for the Canvas actual Image_Info.
1079##
1080 SkImageInfo imageInfo;
1081 size_t rowBytes;
1082 SkIPoint origin;
Cary Clark681287e2018-03-16 11:34:15 -04001083 (void) canvas->accessTopLayerPixels(&imageInfo, &rowBytes, &origin);
Cary Clark1a8d7622018-03-05 13:26:16 -05001084 const char* alphaType[] = { "Unknown", "Opaque", "Premul", "Unpremul" };
1085 SkString string;
1086 string.printf("k%s_SkAlphaType", alphaType[(int) imageInfo.alphaType()]);
1087 SkPaint paint;
1088 canvas->drawString(string, 20, 20, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001089##
1090
Cary Clark1a8d7622018-03-05 13:26:16 -05001091#SeeAlso Make MakeN32 MakeS32 MakeA8
Cary Clark2dc84ad2018-01-26 12:56:22 -05001092
1093#Method ##
1094
1095# ------------------------------------------------------------------------------
1096
1097#Method static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at,
1098 sk_sp<SkColorSpace> cs = nullptr)
Cary Clark4855f782018-02-06 09:41:53 -05001099#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001100#Line # creates Image_Info from dimensions, Color_Type, Alpha_Type, Color_Space ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001101Creates Image_Info from integral dimensions width and height, Color_Type ct,
1102Alpha_Type at, and optionally Color_Space cs.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001103
Cary Clark1a8d7622018-03-05 13:26:16 -05001104If Color_Space cs is nullptr and Image_Info is part of drawing source: Color_Space
1105defaults to sRGB, mapping into Surface Color_Space.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001106
Cary Clark1a8d7622018-03-05 13:26:16 -05001107Parameters are not validated to see if their values are legal, or that the
1108combination is supported.
1109
1110#Param width pixel column count; must be zero or greater ##
1111#Param height pixel row count; must be zero or greater ##
1112#Param ct one of: #list_of_color_types#
1113##
Cary Clark681287e2018-03-16 11:34:15 -04001114#Param at one of: #list_of_alpha_types#
Cary Clark1a8d7622018-03-05 13:26:16 -05001115##
1116#Param cs range of colors; may be nullptr ##
1117
1118#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001119
1120#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001121#Height 48
1122 uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 },
1123 { 0xAC, 0xA8, 0x89, 0xA7, 0x87 },
1124 { 0x9B, 0xB5, 0xE5, 0x95, 0x46 },
1125 { 0x90, 0x81, 0xC5, 0x71, 0x33 },
1126 { 0x75, 0x55, 0x44, 0x40, 0x30 }};
1127 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType);
1128 SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
1129 SkBitmap bitmap;
1130 bitmap.installPixels(pixmap);
1131 canvas->scale(8, 8);
1132 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001133##
1134
Cary Clark1a8d7622018-03-05 13:26:16 -05001135#SeeAlso MakeN32 MakeN32Premul MakeS32 MakeA8
Cary Clark2dc84ad2018-01-26 12:56:22 -05001136
1137#Method ##
1138
1139# ------------------------------------------------------------------------------
1140
1141#Method static SkImageInfo MakeN32(int width, int height, SkAlphaType at,
1142 sk_sp<SkColorSpace> cs = nullptr)
Cary Clark4855f782018-02-06 09:41:53 -05001143#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001144#Line # creates Image_Info with Native_Color_Type ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001145Creates Image_Info from integral dimensions width and height, kN32_SkColorType,
1146Alpha_Type at, and optionally Color_Space cs. kN32_SkColorType will equal either
1147kBGRA_8888_SkColorType or kRGBA_8888_SkColorType, whichever is optimal.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001148
Cary Clark1a8d7622018-03-05 13:26:16 -05001149If Color_Space cs is nullptr and Image_Info is part of drawing source: Color_Space
1150defaults to sRGB, mapping into Surface Color_Space.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001151
Cary Clark1a8d7622018-03-05 13:26:16 -05001152Parameters are not validated to see if their values are legal, or that the
1153combination is supported.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001154
Cary Clark1a8d7622018-03-05 13:26:16 -05001155#Param width pixel column count; must be zero or greater ##
1156#Param height pixel row count; must be zero or greater ##
Cary Clark681287e2018-03-16 11:34:15 -04001157#Param at one of: #list_of_alpha_types#
Cary Clark1a8d7622018-03-05 13:26:16 -05001158##
1159#Param cs range of colors; may be nullptr ##
1160
1161#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001162
1163#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001164#Height 128
1165 SkBitmap bitmap;
1166 bitmap.allocPixels(SkImageInfo::MakeN32(16, 16, kPremul_SkAlphaType));
1167 SkCanvas offscreen(bitmap);
1168 offscreen.clear(SK_ColorWHITE);
1169 SkPaint paint;
1170 offscreen.drawString("g", 0, 10, paint);
1171 canvas->scale(8, 8);
1172 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001173##
1174
Cary Clark1a8d7622018-03-05 13:26:16 -05001175#SeeAlso Make MakeN32Premul MakeS32 MakeA8
Cary Clark2dc84ad2018-01-26 12:56:22 -05001176
1177#Method ##
1178
1179# ------------------------------------------------------------------------------
1180
1181#Method static SkImageInfo MakeS32(int width, int height, SkAlphaType at)
1182
Cary Clark4855f782018-02-06 09:41:53 -05001183#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001184#Line # creates Image_Info with Native_Color_Type, sRGB Color_Space ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001185Creates Image_Info from integral dimensions width and height, kN32_SkColorType,
1186Alpha_Type at, with sRGB Color_Space.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001187
Cary Clark1a8d7622018-03-05 13:26:16 -05001188Parameters are not validated to see if their values are legal, or that the
1189combination is supported.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001190
Cary Clark1a8d7622018-03-05 13:26:16 -05001191#Param width pixel column count; must be zero or greater ##
1192#Param height pixel row count; must be zero or greater ##
Cary Clark681287e2018-03-16 11:34:15 -04001193#Param at one of: #list_of_alpha_types#
Cary Clark2dc84ad2018-01-26 12:56:22 -05001194##
1195
Cary Clark1a8d7622018-03-05 13:26:16 -05001196#Return created Image_Info ##
1197
1198#Example
1199#Set sRGB
1200#Height 128
1201#Description
Cary Clark682c58d2018-05-16 07:07:07 -04001202Top gradient is drawn to offScreen without Color_Space. It is darker than middle
1203gradient, drawn to offScreen with sRGB Color_Space. Bottom gradient shares bits
Cary Clark1a8d7622018-03-05 13:26:16 -05001204with middle, but does not specify the Color_Space in noColorSpaceBitmap. A source
1205without Color_Space is treated as sRGB; the bottom gradient is identical to the
1206middle gradient.
1207##
1208 const int width = 256;
1209 const int height = 32;
1210 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
1211 SkColor gradColors[] = { 0xFFAA0055, 0xFF11CC88 };
1212 SkPoint gradPoints[] = { { 0, 0 }, { width, 0 } };
1213 SkPaint gradPaint;
1214 gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1215 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1216 SkBitmap bitmap;
1217 bitmap.allocPixels(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType));
Cary Clark682c58d2018-05-16 07:07:07 -04001218 SkCanvas offScreen(bitmap);
1219 offScreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
Cary Clark1a8d7622018-03-05 13:26:16 -05001220 canvas->drawBitmap(bitmap, 0, 0);
1221 bitmap.allocPixels(SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType));
1222 SkCanvas sRGBOffscreen(bitmap);
1223 sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1224 canvas->drawBitmap(bitmap, 0, 48);
1225 SkBitmap noColorSpaceBitmap;
1226 noColorSpaceBitmap.setInfo(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType));
1227 noColorSpaceBitmap.setPixels(bitmap.getAddr(0, 0));
1228 canvas->drawBitmap(noColorSpaceBitmap, 0, 96);
1229##
1230
1231#SeeAlso Make MakeN32 MakeN32Premul MakeA8
Cary Clark2dc84ad2018-01-26 12:56:22 -05001232
1233#Method ##
1234
1235# ------------------------------------------------------------------------------
1236
1237#Method static SkImageInfo MakeN32Premul(int width, int height, sk_sp<SkColorSpace> cs = nullptr)
1238
Cary Clark4855f782018-02-06 09:41:53 -05001239#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001240#Line # creates Image_Info with Native_Color_Type, kPremul_SkAlphaType ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001241Creates Image_Info from integral dimensions width and height, kN32_SkColorType,
1242kPremul_SkAlphaType, with optional Color_Space.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001243
Cary Clark1a8d7622018-03-05 13:26:16 -05001244If Color_Space cs is nullptr and Image_Info is part of drawing source: Color_Space
1245defaults to sRGB, mapping into Surface Color_Space.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001246
Cary Clark1a8d7622018-03-05 13:26:16 -05001247Parameters are not validated to see if their values are legal, or that the
1248combination is supported.
1249
1250#Param width pixel column count; must be zero or greater ##
1251#Param height pixel row count; must be zero or greater ##
1252#Param cs range of colors; may be nullptr ##
1253
1254#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001255
1256#Example
Cary Clark06c20f32018-03-20 15:53:27 -04001257#Height 128
Cary Clark1a8d7622018-03-05 13:26:16 -05001258 SkBitmap bitmap;
1259 bitmap.allocPixels(SkImageInfo::MakeN32Premul(18, 18));
1260 SkCanvas offscreen(bitmap);
1261 offscreen.clear(SK_ColorWHITE);
1262 SkPaint paint;
1263 paint.setAntiAlias(true);
1264 paint.setTextSize(15);
1265 offscreen.drawString("\xF0\x9F\x98\xB8", 1, 15, paint);
1266 canvas->scale(6, 6);
1267 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001268##
1269
Cary Clark1a8d7622018-03-05 13:26:16 -05001270#SeeAlso MakeN32 MakeS32 MakeA8 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001271
1272#Method ##
1273
1274# ------------------------------------------------------------------------------
1275
1276#Method static SkImageInfo MakeN32Premul(const SkISize& size)
1277
Cary Clark4855f782018-02-06 09:41:53 -05001278#In Constructor
Cary Clark1a8d7622018-03-05 13:26:16 -05001279Creates Image_Info from integral dimensions width and height, kN32_SkColorType,
1280kPremul_SkAlphaType, with Color_Space set to nullptr.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001281
Cary Clark1a8d7622018-03-05 13:26:16 -05001282If Image_Info is part of drawing source: Color_Space defaults to sRGB, mapping
1283into Surface Color_Space.
1284
1285Parameters are not validated to see if their values are legal, or that the
1286combination is supported.
1287
1288#Param size width and height, each must be zero or greater ##
1289
1290#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001291
1292#Example
Cary Clark06c20f32018-03-20 15:53:27 -04001293#Height 128
Cary Clark1a8d7622018-03-05 13:26:16 -05001294 SkBitmap bitmap;
1295 bitmap.allocPixels(SkImageInfo::MakeN32Premul({18, 18}));
1296 SkCanvas offscreen(bitmap);
1297 offscreen.clear(SK_ColorWHITE);
1298 SkPaint paint;
1299 paint.setAntiAlias(true);
1300 paint.setTextSize(15);
1301 offscreen.drawString("\xF0\x9F\x98\xB9", 1, 15, paint);
1302 canvas->scale(6, 6);
1303 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001304##
1305
Cary Clark682c58d2018-05-16 07:07:07 -04001306#SeeAlso MakeN32 MakeS32 MakeA8 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001307
1308#Method ##
1309
1310# ------------------------------------------------------------------------------
1311
1312#Method static SkImageInfo MakeA8(int width, int height)
1313
Cary Clark4855f782018-02-06 09:41:53 -05001314#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001315#Line # creates Image_Info with kAlpha_8_SkColorType, kPremul_SkAlphaType ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001316Creates Image_Info from integral dimensions width and height, kAlpha_8_SkColorType,
1317kPremul_SkAlphaType, with Color_Space set to nullptr.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001318
Cary Clark1a8d7622018-03-05 13:26:16 -05001319#Param width pixel column count; must be zero or greater ##
1320#Param height pixel row count; must be zero or greater ##
1321
1322#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001323
1324#Example
Cary Clark681287e2018-03-16 11:34:15 -04001325#Height 64
1326 uint8_t pixels[][8] = { { 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00},
1327 { 0x00, 0x7f, 0xff, 0x3f, 0x3f, 0x7f, 0x3f, 0x00},
1328 { 0x3f, 0xff, 0x7f, 0x00, 0x7f, 0xff, 0x7f, 0x00},
1329 { 0x00, 0x3f, 0x00, 0x00, 0x3f, 0x7f, 0x3f, 0x00},
1330 { 0x3f, 0x7f, 0x7f, 0x3f, 0x00, 0x00, 0x00, 0x00},
1331 { 0x7f, 0xff, 0xff, 0x7f, 0x00, 0x3f, 0x7f, 0x3f},
1332 { 0x7f, 0xff, 0xff, 0x7f, 0x00, 0x7f, 0xff, 0x7f},
1333 { 0x3f, 0x7f, 0x7f, 0x3f, 0x00, 0x3f, 0x7f, 0x3f} };
1334 SkBitmap bitmap;
1335 bitmap.installPixels(SkImageInfo::MakeA8(8, 8),
1336 (void*) pixels, sizeof(pixels[0]));
1337 SkPaint paint;
1338 canvas->scale(4, 4);
1339 for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) {
1340 paint.setColor(color);
1341 canvas->drawBitmap(bitmap, 0, 0, &paint);
1342 canvas->translate(12, 0);
1343 }
Cary Clark2dc84ad2018-01-26 12:56:22 -05001344##
1345
Cary Clark1a8d7622018-03-05 13:26:16 -05001346#SeeAlso MakeN32 MakeS32 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001347
1348#Method ##
1349
1350# ------------------------------------------------------------------------------
1351
1352#Method static SkImageInfo MakeUnknown(int width, int height)
1353
Cary Clark4855f782018-02-06 09:41:53 -05001354#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001355#Line # creates Image_Info with kUnknown_SkColorType, kUnknown_SkAlphaType ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001356Creates Image_Info from integral dimensions width and height, kUnknown_SkColorType,
1357kUnknown_SkAlphaType, with Color_Space set to nullptr.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001358
Cary Clark1a8d7622018-03-05 13:26:16 -05001359Returned Image_Info as part of source does not draw, and as part of destination
1360can not be drawn to.
1361
1362#Param width pixel column count; must be zero or greater ##
1363#Param height pixel row count; must be zero or greater ##
1364
1365#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001366
1367#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001368#Height 32
1369#Width 384
1370SkImageInfo info; // default constructor
1371SkString string;
1372string.printf("SkImageInfo() %c= SkImageInfo::MakeUnknown(0, 0)",
1373 info == SkImageInfo::MakeUnknown(0, 0) ? '=' : '!');
1374SkPaint paint;
1375canvas->drawString(string, 0, 12, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001376##
1377
Cary Clark1a8d7622018-03-05 13:26:16 -05001378#SeeAlso SkImageInfo() MakeN32 MakeS32 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001379
1380#Method ##
1381
1382# ------------------------------------------------------------------------------
1383
1384#Method static SkImageInfo MakeUnknown()
1385
Cary Clark4855f782018-02-06 09:41:53 -05001386#In Constructor
Cary Clark1a8d7622018-03-05 13:26:16 -05001387Creates Image_Info from integral dimensions width and height set to zero,
1388kUnknown_SkColorType, kUnknown_SkAlphaType, with Color_Space set to nullptr.
1389
1390Returned Image_Info as part of source does not draw, and as part of destination
1391can not be drawn to.
1392
1393#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001394
1395#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001396#Height 32
1397#Width 384
1398SkImageInfo info; // default constructor
1399SkString string;
1400string.printf("SkImageInfo() %c= SkImageInfo::MakeUnknown()",
1401 info == SkImageInfo::MakeUnknown() ? '=' : '!');
1402SkPaint paint;
1403canvas->drawString(string, 0, 12, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001404##
1405
Cary Clark1a8d7622018-03-05 13:26:16 -05001406#SeeAlso SkImageInfo() MakeN32 MakeS32 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001407
1408#Method ##
1409
Cary Clark2dc84ad2018-01-26 12:56:22 -05001410
1411# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05001412#Subtopic Property
1413#Populate
1414#Line # metrics and attributes ##
1415##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001416
1417#Method int width() const
Cary Clark78de7512018-02-07 07:27:09 -05001418#In Property
Cary Clark1a8d7622018-03-05 13:26:16 -05001419#Line # returns pixel column count ##
1420Returns pixel count in each row.
1421
1422#Return pixel width ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001423
1424#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001425#Image 4
1426#Height 96
1427 canvas->translate(10, 10);
1428 canvas->drawBitmap(source, 0, 0);
1429 SkImageInfo imageInfo = source.info();
1430 canvas->translate(0, imageInfo.height());
1431 SkPaint paint;
1432 paint.setTextAlign(SkPaint::kCenter_Align);
1433 canvas->drawLine(0, 10, imageInfo.width(), 10, paint);
1434 canvas->drawString("width", imageInfo.width() / 2, 25, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001435##
1436
Cary Clark1a8d7622018-03-05 13:26:16 -05001437#SeeAlso height SkBitmap::width SkPixelRef::width SkImage::width SkSurface::width
Cary Clark2dc84ad2018-01-26 12:56:22 -05001438
1439#Method ##
1440
1441# ------------------------------------------------------------------------------
1442
1443#Method int height() const
Cary Clark78de7512018-02-07 07:27:09 -05001444#In Property
Cary Clark1a8d7622018-03-05 13:26:16 -05001445#Line # returns pixel row count ##
1446Returns pixel row count.
1447
1448#Return pixel height ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001449
1450#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001451#Image 4
1452#Height 96
1453 canvas->translate(10, 20);
1454 canvas->drawBitmap(source, 0, 0);
1455 SkImageInfo imageInfo = source.info();
1456 SkPaint paint;
1457 paint.setTextAlign(SkPaint::kCenter_Align);
1458 paint.setVerticalText(true);
1459 canvas->drawLine(imageInfo.width() + 10, 0, imageInfo.width() + 10, imageInfo.height(), paint);
1460 canvas->drawString("height", imageInfo.width() + 25, imageInfo.height() / 2, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001461##
1462
Cary Clark1a8d7622018-03-05 13:26:16 -05001463#SeeAlso width SkBitmap::height SkPixelRef::height SkImage::height SkSurface::height
Cary Clark2dc84ad2018-01-26 12:56:22 -05001464
1465#Method ##
1466
1467# ------------------------------------------------------------------------------
1468
1469#Method SkColorType colorType() const
Cary Clark78de7512018-02-07 07:27:09 -05001470#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001471#Line # returns Color_Type ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001472Returns Color_Type, one of: #list_of_color_types#.
1473
1474#Return Color_Type ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001475
1476#Example
Cary Clark681287e2018-03-16 11:34:15 -04001477 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
1478 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
1479 SkImageInfo info = SkImageInfo::MakeA8(16, 32);
1480 SkDebugf("color type: k" "%s" "_SkColorType\n", colors[info.colorType()]);
1481#StdOut
1482color type: kAlpha_8_SkColorType
1483##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001484##
1485
Cary Clark681287e2018-03-16 11:34:15 -04001486#SeeAlso alphaType SkPixmap::colorType SkBitmap::colorType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001487
1488#Method ##
1489
1490# ------------------------------------------------------------------------------
1491
1492#Method SkAlphaType alphaType() const
Cary Clark78de7512018-02-07 07:27:09 -05001493#In Property
Cary Clark682c58d2018-05-16 07:07:07 -04001494#Line # returns Alpha_Type ##
Cary Clark681287e2018-03-16 11:34:15 -04001495Returns Alpha_Type, one of: #list_of_alpha_types#.
1496
1497#Return Alpha_Type ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001498
1499#Example
Cary Clark681287e2018-03-16 11:34:15 -04001500 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
1501 SkImageInfo info = SkImageInfo::MakeA8(16, 32);
1502 SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[info.alphaType()]);
1503#StdOut
1504alpha type: kPremul_SkAlphaType
1505##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001506##
1507
Cary Clark681287e2018-03-16 11:34:15 -04001508#SeeAlso colorType SkPixmap::alphaType SkBitmap::alphaType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001509
1510#Method ##
1511
1512# ------------------------------------------------------------------------------
1513
1514#Method SkColorSpace* colorSpace() const
Cary Clark78de7512018-02-07 07:27:09 -05001515#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001516#Line # returns Color_Space ##
1517Returns Color_Space, the range of colors. The reference count of
1518Color_Space is unchanged. The returned Color_Space is immutable.
1519
1520#Return Color_Space, or nullptr ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001521
1522#Example
Cary Clark681287e2018-03-16 11:34:15 -04001523#Description
1524SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma
1525and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma.
1526##
Cary Clark682c58d2018-05-16 07:07:07 -04001527 SkImageInfo info = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
Cary Clark681287e2018-03-16 11:34:15 -04001528 SkColorSpace::MakeSRGBLinear());
1529 SkColorSpace* colorSpace = info.colorSpace();
1530 SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
1531 colorSpace->gammaCloseToSRGB() ? "true" : "false",
1532 colorSpace->gammaIsLinear() ? "true" : "false",
1533 colorSpace->isSRGB() ? "true" : "false");
1534#StdOut
1535gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
1536##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001537##
1538
Cary Clark681287e2018-03-16 11:34:15 -04001539#SeeAlso Color_Space SkPixmap::colorSpace SkBitmap::colorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001540
1541#Method ##
1542
1543# ------------------------------------------------------------------------------
1544
1545#Method sk_sp<SkColorSpace> refColorSpace() const
Cary Clark78de7512018-02-07 07:27:09 -05001546#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001547#Line # returns Color_Space ##
Cary Clark682c58d2018-05-16 07:07:07 -04001548Returns smart pointer to Color_Space, the range of colors. The smart pointer
Cary Clark681287e2018-03-16 11:34:15 -04001549tracks the number of objects sharing this Color_Space reference so the memory
1550is released when the owners destruct.
1551
1552The returned Color_Space is immutable.
1553
1554#Return Color_Space wrapped in a smart pointer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001555
1556#Example
Cary Clark682c58d2018-05-16 07:07:07 -04001557 SkImageInfo info1 = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
Cary Clark681287e2018-03-16 11:34:15 -04001558 SkColorSpace::MakeSRGBLinear());
1559 SkImageInfo info2 = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
1560 info1.refColorSpace());
1561 SkColorSpace* colorSpace = info2.colorSpace();
1562 SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
1563 colorSpace->gammaCloseToSRGB() ? "true" : "false",
1564 colorSpace->gammaIsLinear() ? "true" : "false",
1565 colorSpace->isSRGB() ? "true" : "false");
Cary Clark2dc84ad2018-01-26 12:56:22 -05001566##
1567
Cary Clark681287e2018-03-16 11:34:15 -04001568#SeeAlso Color_Space SkBitmap::refColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001569
1570#Method ##
1571
1572# ------------------------------------------------------------------------------
1573
1574#Method bool isEmpty() const
Cary Clark78de7512018-02-07 07:27:09 -05001575#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001576#Line # returns if dimensions contain pixels ##
1577
1578Returns if Image_Info describes an empty area of pixels by checking if either
1579width or height is zero or smaller.
1580
1581#Return true if either dimension is zero or smaller ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001582
1583#Example
Cary Clark681287e2018-03-16 11:34:15 -04001584 for (int width : { 0, 2 } ) {
1585 for (int height : { 0, 2 } ) {
1586 SkImageInfo imageInfo= SkImageInfo::MakeA8(width, height);
1587 SkDebugf("width: %d height: %d empty: %s\n", width, height,
1588 imageInfo.isEmpty() ? "true" : "false");
1589 }
1590 }
1591#StdOut
1592width: 0 height: 0 empty: true
1593width: 0 height: 2 empty: true
1594width: 2 height: 0 empty: true
1595width: 2 height: 2 empty: false
1596##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001597##
1598
Cary Clark681287e2018-03-16 11:34:15 -04001599#SeeAlso dimensions bounds SkBitmap::empty SkPixmap::bounds
Cary Clark2dc84ad2018-01-26 12:56:22 -05001600
1601#Method ##
1602
1603# ------------------------------------------------------------------------------
1604
1605#Method bool isOpaque() const
Cary Clark78de7512018-02-07 07:27:09 -05001606#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001607#Line # returns if Alpha_Type is kOpaque_SkAlphaType ##
1608
1609Returns true if Alpha_Type is set to hint that all pixels are opaque; their
1610Color_Alpha value is implicitly or explicitly 1.0. If true, and all pixels are
Cary Clark682c58d2018-05-16 07:07:07 -04001611not opaque, Skia may draw incorrectly.
Cary Clark681287e2018-03-16 11:34:15 -04001612
1613Does not check if Color_Type allows Alpha, or if any pixel value has
1614transparency.
1615
1616#Return true if Alpha_Type is kOpaque_SkAlphaType ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001617
1618#Example
Cary Clark681287e2018-03-16 11:34:15 -04001619 const int height = 2;
1620 const int width = 2;
1621 SkBitmap bitmap;
1622 SkImageInfo imageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType);
1623 bitmap.setInfo(imageInfo);
1624 for (int index = 0; index < 2; ++index) {
1625 bitmap.allocPixels();
1626 bitmap.eraseColor(0x00000000);
1627 SkDebugf("isOpaque: %s\n", imageInfo.isOpaque() ? "true" : "false");
1628 bitmap.eraseColor(0xFFFFFFFF);
1629 SkDebugf("isOpaque: %s\n", imageInfo.isOpaque() ? "true" : "false");
1630 imageInfo = imageInfo.makeAlphaType(kOpaque_SkAlphaType);
1631 bitmap.setInfo(imageInfo);
1632 }
1633#StdOut
1634isOpaque: false
1635isOpaque: false
1636isOpaque: true
1637isOpaque: true
1638##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001639##
1640
Cary Clark681287e2018-03-16 11:34:15 -04001641#SeeAlso Color_Alpha SkColorTypeValidateAlphaType SkBitmap::isOpaque SkImage::isOpaque SkPixmap::isOpaque
Cary Clark2dc84ad2018-01-26 12:56:22 -05001642
1643#Method ##
1644
1645# ------------------------------------------------------------------------------
1646
1647#Method SkISize dimensions() const
Cary Clark78de7512018-02-07 07:27:09 -05001648#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001649#Line # returns width() and height() ##
1650
1651Returns ISize { width(), height() }.
1652
1653#Return integral size of width() and height() ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001654
1655#Example
Cary Clark681287e2018-03-16 11:34:15 -04001656 const int height = 2;
1657 const int width = 2;
1658 SkImageInfo imageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType);
1659 SkISize dimensions = imageInfo.dimensions();
1660 SkIRect bounds = imageInfo.bounds();
1661 SkIRect dimensionsAsBounds = SkIRect::MakeSize(dimensions);
1662 SkDebugf("dimensionsAsBounds %c= bounds\n", dimensionsAsBounds == bounds ? '=' : '!');
1663#StdOut
1664dimensionsAsBounds == bounds
1665##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001666##
1667
Cary Clark681287e2018-03-16 11:34:15 -04001668#SeeAlso width height bounds SkBitmap::dimensions
Cary Clark2dc84ad2018-01-26 12:56:22 -05001669
1670#Method ##
1671
1672# ------------------------------------------------------------------------------
1673
1674#Method SkIRect bounds() const
Cary Clark78de7512018-02-07 07:27:09 -05001675#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001676#Line # returns width() and height() as Rectangle ##
1677Returns IRect { 0, 0, width(), height() }.
1678
1679#Return integral rectangle from origin to width() and height() ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001680
1681#Example
Cary Clark681287e2018-03-16 11:34:15 -04001682#Height 64
1683#Image 4
1684 canvas->scale(.5f, .5f);
1685 SkImageInfo imageInfo = source.info();
1686 SkIRect bounds = imageInfo.bounds();
1687 for (int x : { 0, bounds.width() } ) {
1688 for (int y : { 0, bounds.height() } ) {
1689 canvas->drawBitmap(source, x, y);
1690 }
1691 }
Cary Clark2dc84ad2018-01-26 12:56:22 -05001692##
1693
Cary Clark681287e2018-03-16 11:34:15 -04001694#SeeAlso width height dimensions
Cary Clark2dc84ad2018-01-26 12:56:22 -05001695
1696#Method ##
1697
1698# ------------------------------------------------------------------------------
1699
1700#Method bool gammaCloseToSRGB() const
Cary Clark78de7512018-02-07 07:27:09 -05001701#In Property
Cary Clark682c58d2018-05-16 07:07:07 -04001702#Line # returns if Color_Space gamma is approximately the same as sRGB ##
Cary Clark681287e2018-03-16 11:34:15 -04001703
1704Returns true if associated Color_Space is not nullptr, and Color_Space gamma
Cary Clark682c58d2018-05-16 07:07:07 -04001705is approximately the same as sRGB.
1706This includes the
Cary Clark681287e2018-03-16 11:34:15 -04001707###$
1708$A sRGB transfer function $ https://en.wikipedia.org/wiki/SRGB#The_sRGB_transfer_function_(%22gamma%22) $$
1709$$$#
1710as well as a gamma curve described by a 2.2 exponent.
1711
1712#Return true if Color_Space gamma is approximately the same as sRGB ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001713
1714#Example
Cary Clark681287e2018-03-16 11:34:15 -04001715#Height 144
1716 const int width = 256;
1717 const int height = 64;
1718 auto drawLabel = [=](const char* what, bool closeToSRGB) -> void {
1719 SkString string;
1720 string.printf("%s gamma is %s" "close to sRGB", what, closeToSRGB ? "" : "not ");
1721 SkPaint paint;
1722 paint.setAntiAlias(true);
1723 paint.setTextAlign(SkPaint::kCenter_Align);
1724 canvas->drawString(string, width / 2, 56, paint);
1725 };
1726 SkColor gradColors[] = { 0xFFFF7F00, 0xFF00FF7F, 0xFF0000FF, 0xFF7F7FFF };
1727 SkPoint gradPoints[] = { { 0, 0 }, { width, 0 }, { width * 2, 0 }, { width * 3, 0 } };
1728 SkPaint gradPaint;
1729 gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1730 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1731 canvas->drawRect(SkRect::MakeWH(width, height), gradPaint);
1732 drawLabel("canvas", canvas->imageInfo().gammaCloseToSRGB());
1733 SkBitmap bitmap;
1734 SkImageInfo offscreenInfo = SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType);
1735 bitmap.allocPixels(offscreenInfo);
1736 SkCanvas sRGBOffscreen(bitmap);
1737 sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1738 canvas->translate(0, 80);
1739 canvas->drawBitmap(bitmap, 0, 0);
1740 drawLabel("offscreen", offscreenInfo.gammaCloseToSRGB());
Cary Clark2dc84ad2018-01-26 12:56:22 -05001741##
1742
Cary Clark681287e2018-03-16 11:34:15 -04001743#SeeAlso SkColorSpace::gammaCloseToSRGB
Cary Clark2dc84ad2018-01-26 12:56:22 -05001744
1745#Method ##
1746
1747# ------------------------------------------------------------------------------
1748
1749#Method SkImageInfo makeWH(int newWidth, int newHeight) const
Cary Clark78de7512018-02-07 07:27:09 -05001750#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001751#Line # creates Image_Info with changed dimensions ##
Cary Clark681287e2018-03-16 11:34:15 -04001752Creates Image_Info with the same Color_Type, Color_Space, and Alpha_Type,
1753with dimensions set to width and height.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001754
Cary Clark681287e2018-03-16 11:34:15 -04001755#Param newWidth pixel column count; must be zero or greater ##
1756#Param newHeight pixel row count; must be zero or greater ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001757
Cary Clark681287e2018-03-16 11:34:15 -04001758#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001759
1760#Example
Cary Clark681287e2018-03-16 11:34:15 -04001761#Height 144
1762#Image 3
1763 SkImageInfo canvasImageInfo = canvas->imageInfo();
1764 SkRect canvasBounds = SkRect::Make(canvasImageInfo.bounds());
1765 canvas->drawBitmapRect(source, source.bounds(), canvasBounds, nullptr);
Cary Clark682c58d2018-05-16 07:07:07 -04001766 SkImageInfo insetImageInfo =
Cary Clark681287e2018-03-16 11:34:15 -04001767 canvasImageInfo.makeWH(canvasBounds.width() / 2, canvasBounds.height() / 2);
1768 SkBitmap inset;
1769 inset.allocPixels(insetImageInfo);
1770 SkCanvas offscreen(inset);
1771 offscreen.drawBitmapRect(source, source.bounds(), SkRect::Make(inset.bounds()), nullptr);
1772 canvas->drawBitmap(inset, canvasBounds.width() / 4, canvasBounds.height() / 4);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001773##
1774
Cary Clark682c58d2018-05-16 07:07:07 -04001775#SeeAlso Make makeAlphaType makeColorSpace makeColorType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001776
1777#Method ##
1778
1779# ------------------------------------------------------------------------------
1780
1781#Method SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const
Cary Clark78de7512018-02-07 07:27:09 -05001782#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001783#Line # creates Image_Info with changed Alpha_Type ##
Cary Clark681287e2018-03-16 11:34:15 -04001784Creates Image_Info with same Color_Type, Color_Space, width, and height,
Cary Clark682c58d2018-05-16 07:07:07 -04001785with Alpha_Type set to newAlphaType.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001786
Cary Clark681287e2018-03-16 11:34:15 -04001787Created Image_Info contains newAlphaType even if it is incompatible with
1788Color_Type, in which case Alpha_Type in Image_Info is ignored.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001789
Cary Clark681287e2018-03-16 11:34:15 -04001790#Param newAlphaType one of: #list_of_alpha_types#
Cary Clark2dc84ad2018-01-26 12:56:22 -05001791##
1792
Cary Clark681287e2018-03-16 11:34:15 -04001793#Return created Image_Info ##
1794
1795#Example
1796#Image 3
1797 const int width = 256;
1798 const int height = 128;
1799 SkColor pixels[height][width];
1800 for (int y = 0; y < height; ++y) {
1801 for (int x = 0; x < width; ++x) {
Cary Clark682c58d2018-05-16 07:07:07 -04001802 int red = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 4 + y) * 0.03f)));
1803 int blue = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 3 + y) * 0.04f)));
Cary Clark681287e2018-03-16 11:34:15 -04001804 int green = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 2 + y) * 0.05f)));
1805 int alpha = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 1 + y) * 0.006f)));
Cary Clark682c58d2018-05-16 07:07:07 -04001806 pixels[y][x] =
Cary Clark681287e2018-03-16 11:34:15 -04001807 SkColorSetARGB(alpha, red * alpha / 255, green * alpha / 255, blue * alpha / 255);
1808 }
1809 }
1810 SkBitmap bitmap;
1811 SkImageInfo info = SkImageInfo::Make(width, height, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
1812 bitmap.installPixels(info, (void*) pixels, sizeof(SkColor) * width);
1813 canvas->drawBitmap(source, 0, 0);
1814 canvas->drawBitmap(bitmap, 0, 0);
1815 SkImageInfo unpremulInfo = info.makeAlphaType(kUnpremul_SkAlphaType);
1816 bitmap.installPixels(unpremulInfo, (void*) pixels, sizeof(SkColor) * width);
1817 canvas->drawBitmap(bitmap, 0, 128);
1818##
1819
1820#SeeAlso Make MakeA8 makeColorType makeColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001821
1822#Method ##
1823
1824# ------------------------------------------------------------------------------
1825
1826#Method SkImageInfo makeColorType(SkColorType newColorType) const
Cary Clark78de7512018-02-07 07:27:09 -05001827#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001828#Line # creates Image_Info with changed Color_Type ##
Cary Clark681287e2018-03-16 11:34:15 -04001829Creates Image_Info with same Alpha_Type, Color_Space, width, and height,
1830with Color_Type set to newColorType.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001831
Cary Clark681287e2018-03-16 11:34:15 -04001832#Param newColorType one of: #list_of_color_types#
Cary Clark2dc84ad2018-01-26 12:56:22 -05001833##
1834
Cary Clark681287e2018-03-16 11:34:15 -04001835#Return created Image_Info ##
1836
1837#Example
1838 const int width = 256;
1839 const int height = 128;
1840 SkColor pixels[height][width];
1841 for (int y = 0; y < height; ++y) {
1842 for (int x = 0; x < width; ++x) {
Cary Clark682c58d2018-05-16 07:07:07 -04001843 int red = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 4 + y) * 0.03f)));
1844 int blue = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 3 + y) * 0.04f)));
Cary Clark681287e2018-03-16 11:34:15 -04001845 int green = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 2 + y) * 0.05f)));
1846 int alpha = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 1 + y) * 0.006f)));
Cary Clark682c58d2018-05-16 07:07:07 -04001847 pixels[y][x] =
Cary Clark681287e2018-03-16 11:34:15 -04001848 SkColorSetARGB(alpha, red * alpha / 255, green * alpha / 255, blue * alpha / 255);
1849 }
1850 }
1851 SkBitmap bitmap;
1852 SkImageInfo info = SkImageInfo::Make(width, height, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
1853 bitmap.installPixels(info, (void*) pixels, sizeof(SkColor) * width);
1854 canvas->drawBitmap(source, 0, 0);
1855 canvas->drawBitmap(bitmap, 0, 0);
1856 SkImageInfo rgbaInfo = info.makeColorType(kRGBA_8888_SkColorType);
1857 bitmap.installPixels(rgbaInfo, (void*) pixels, sizeof(SkColor) * width);
1858 canvas->drawBitmap(bitmap, 0, 128);
1859##
1860
1861#SeeAlso Make makeAlphaType makeColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001862
1863#Method ##
1864
1865# ------------------------------------------------------------------------------
1866
1867#Method SkImageInfo makeColorSpace(sk_sp<SkColorSpace> cs) const
Cary Clark78de7512018-02-07 07:27:09 -05001868#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001869#Line # creates Image_Info with changed Color_Space ##
Cary Clark681287e2018-03-16 11:34:15 -04001870Creates Image_Info with same Alpha_Type, Color_Type, width, and height,
1871with Color_Space set to cs.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001872
Cary Clark681287e2018-03-16 11:34:15 -04001873#Param cs range of colors; may be nullptr ##
1874
1875#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001876
1877#Example
Cary Clark681287e2018-03-16 11:34:15 -04001878#Height 224
1879 const int width = 256;
1880 const int height = 64;
1881 auto drawLabel = [=](const char* what, bool closeToSRGB) -> void {
1882 SkString string;
1883 string.printf("%s gamma is %s" "close to sRGB", what, closeToSRGB ? "" : "not ");
1884 SkPaint paint;
1885 paint.setAntiAlias(true);
1886 paint.setTextAlign(SkPaint::kCenter_Align);
1887 canvas->drawString(string, width / 2, 56, paint);
1888 };
1889 SkColor gradColors[] = { 0xFFFF7F00, 0xFF00FF7F, 0xFF0000FF, 0xFF7F7FFF };
1890 SkPoint gradPoints[] = { { 0, 0 }, { width, 0 }, { width * 2, 0 }, { width * 3, 0 } };
1891 SkPaint gradPaint;
1892 gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1893 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1894 canvas->drawRect(SkRect::MakeWH(width, height), gradPaint);
1895 drawLabel("canvas", canvas->imageInfo().gammaCloseToSRGB());
1896 SkBitmap bitmap;
1897 SkImageInfo offscreenInfo = SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType);
1898 bitmap.allocPixels(offscreenInfo);
1899 SkCanvas sRGBOffscreen(bitmap);
1900 sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1901 canvas->translate(0, 80);
1902 canvas->drawBitmap(bitmap, 0, 0);
1903 drawLabel("offscreen", offscreenInfo.gammaCloseToSRGB());
1904 SkImageInfo linearGamma =
1905 offscreenInfo.makeColorSpace(offscreenInfo.colorSpace()->makeLinearGamma());
1906 bitmap.allocPixels(linearGamma);
1907 SkCanvas lgOffscreen(bitmap);
1908 lgOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1909 canvas->translate(0, 80);
1910 canvas->drawBitmap(bitmap, 0, 0);
1911 drawLabel("linear", linearGamma.gammaCloseToSRGB());
Cary Clark2dc84ad2018-01-26 12:56:22 -05001912##
1913
Cary Clark681287e2018-03-16 11:34:15 -04001914#SeeAlso Make MakeS32 makeAlphaType makeColorType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001915
1916#Method ##
1917
1918# ------------------------------------------------------------------------------
1919
1920#Method int bytesPerPixel() const
Cary Clark78de7512018-02-07 07:27:09 -05001921#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001922#Line # returns number of bytes in pixel based on Color_Type ##
1923Returns number of bytes per pixel required by Color_Type.
1924Returns zero if colorType( is kUnknown_SkColorType.
1925
1926#Return bytes in pixel ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001927
1928#Example
Cary Clark681287e2018-03-16 11:34:15 -04001929 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
1930 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
1931 for (SkColorType colorType : { #list_of_color_types#
1932 } ) {
1933 SkImageInfo info = SkImageInfo::Make(1, 1, colorType, kOpaque_SkAlphaType);
1934 SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d\n",
1935 colors[colorType], 13 - strlen(colors[colorType]), " ",
1936 info.bytesPerPixel());
1937 }
1938#StdOut
1939color: kUnknown_SkColorType bytesPerPixel: 0
1940color: kAlpha_8_SkColorType bytesPerPixel: 1
1941color: kRGB_565_SkColorType bytesPerPixel: 2
1942color: kARGB_4444_SkColorType bytesPerPixel: 2
1943color: kRGBA_8888_SkColorType bytesPerPixel: 4
1944color: kRGB_888x_SkColorType bytesPerPixel: 4
1945color: kBGRA_8888_SkColorType bytesPerPixel: 4
1946color: kRGBA_1010102_SkColorType bytesPerPixel: 4
1947color: kRGB_101010x_SkColorType bytesPerPixel: 4
1948color: kGray_8_SkColorType bytesPerPixel: 1
1949color: kRGBA_F16_SkColorType bytesPerPixel: 8
1950##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001951##
1952
Cary Clark681287e2018-03-16 11:34:15 -04001953#SeeAlso width shiftPerPixel SkBitmap::bytesPerPixel
Cary Clark2dc84ad2018-01-26 12:56:22 -05001954
1955#Method ##
1956
1957# ------------------------------------------------------------------------------
1958
1959#Method int shiftPerPixel() const
Cary Clark78de7512018-02-07 07:27:09 -05001960#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001961#Line # returns bit shift from pixels to bytes ##
1962Returns bit shift converting row bytes to row pixels.
1963Returns zero for kUnknown_SkColorType.
1964
1965#Return one of: 0, 1, 2, 3; left shift to convert pixels to bytes ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001966
1967#Example
Cary Clark681287e2018-03-16 11:34:15 -04001968 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
1969 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
1970 for (SkColorType colorType : { #list_of_color_types#
1971 } ) {
1972 SkImageInfo info = SkImageInfo::Make(1, 1, colorType, kOpaque_SkAlphaType);
1973 SkDebugf("color: k" "%s" "_SkColorType" "%*s" "shiftPerPixel: %d\n",
1974 colors[colorType], 14 - strlen(colors[colorType]), " ",
1975 info.shiftPerPixel());
1976 }
1977#StdOut
1978color: kUnknown_SkColorType shiftPerPixel: 0
1979color: kAlpha_8_SkColorType shiftPerPixel: 0
1980color: kRGB_565_SkColorType shiftPerPixel: 1
1981color: kARGB_4444_SkColorType shiftPerPixel: 1
1982color: kRGBA_8888_SkColorType shiftPerPixel: 2
1983color: kRGB_888x_SkColorType shiftPerPixel: 2
1984color: kBGRA_8888_SkColorType shiftPerPixel: 2
1985color: kRGBA_1010102_SkColorType shiftPerPixel: 2
1986color: kRGB_101010x_SkColorType shiftPerPixel: 2
1987color: kGray_8_SkColorType shiftPerPixel: 0
1988color: kRGBA_F16_SkColorType shiftPerPixel: 3
1989##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001990##
1991
Cary Clark06c20f32018-03-20 15:53:27 -04001992#SeeAlso bytesPerPixel minRowBytes SkBitmap::shiftPerPixel SkPixmap::shiftPerPixel
Cary Clark2dc84ad2018-01-26 12:56:22 -05001993
1994#Method ##
1995
1996# ------------------------------------------------------------------------------
1997
1998#Method uint64_t minRowBytes64() const
Cary Clark78de7512018-02-07 07:27:09 -05001999#In Property
Cary Clark681287e2018-03-16 11:34:15 -04002000#Line # returns width() times bytesPerPixel in 64 bits ##
2001
2002Returns minimum bytes per row, computed from pixel width() and Color_Type, which
Cary Clark682c58d2018-05-16 07:07:07 -04002003specifies bytesPerPixel(). Bitmap maximum value for row bytes must fit
2004in 31 bits.
Cary Clark681287e2018-03-16 11:34:15 -04002005
2006#Return width() times bytesPerPixel as unsigned 64-bit integer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002007
2008#Example
Cary Clark681287e2018-03-16 11:34:15 -04002009 for (int shift = 24; shift < 32; ++shift) {
2010 int width = 1 << shift;
Cary Clark682c58d2018-05-16 07:07:07 -04002011 SkImageInfo imageInfo =
Cary Clark681287e2018-03-16 11:34:15 -04002012 SkImageInfo::Make(width, 1, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
2013 uint64_t minRowBytes = imageInfo.minRowBytes64();
2014 bool widthTooLarge = (uint64_t) (int32_t) minRowBytes != minRowBytes;
2015 SkDebugf("RGBA_F16 width %d (0x%08x) %s\n",
Cary Clark682c58d2018-05-16 07:07:07 -04002016 width, width, widthTooLarge ? "too large" : "OK");
Cary Clark681287e2018-03-16 11:34:15 -04002017 }
2018#StdOut
2019RGBA_F16 width 16777216 (0x01000000) OK
2020RGBA_F16 width 33554432 (0x02000000) OK
2021RGBA_F16 width 67108864 (0x04000000) OK
2022RGBA_F16 width 134217728 (0x08000000) OK
2023RGBA_F16 width 268435456 (0x10000000) too large
2024RGBA_F16 width 536870912 (0x20000000) too large
2025RGBA_F16 width 1073741824 (0x40000000) too large
2026RGBA_F16 width -2147483648 (0x80000000) too large
2027##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002028##
2029
Cary Clark681287e2018-03-16 11:34:15 -04002030#SeeAlso minRowBytes computeByteSize computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002031
2032#Method ##
2033
2034# ------------------------------------------------------------------------------
2035
2036#Method size_t minRowBytes() const
Cary Clark78de7512018-02-07 07:27:09 -05002037#In Property
Cary Clark681287e2018-03-16 11:34:15 -04002038#Line # returns width() times bytesPerPixel in 32 bits ##
2039
2040Returns minimum bytes per row, computed from pixel width() and Color_Type, which
Cary Clark682c58d2018-05-16 07:07:07 -04002041specifies bytesPerPixel(). Bitmap maximum value for row bytes must fit
2042in 31 bits.
Cary Clark681287e2018-03-16 11:34:15 -04002043
2044#Return width() times bytesPerPixel as signed 32-bit integer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002045
2046#Example
Cary Clark681287e2018-03-16 11:34:15 -04002047 for (int shift = 24; shift < 32; ++shift) {
2048 int width = 1 << shift;
Cary Clark682c58d2018-05-16 07:07:07 -04002049 SkImageInfo imageInfo =
Cary Clark681287e2018-03-16 11:34:15 -04002050 SkImageInfo::Make(width, 1, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
2051 size_t minRowBytes = imageInfo.minRowBytes();
2052 bool widthTooLarge = !minRowBytes;
2053 SkDebugf("RGBA_F16 width %d (0x%08x) %s\n",
Cary Clark682c58d2018-05-16 07:07:07 -04002054 width, width, widthTooLarge ? "too large" : "OK");
Cary Clark681287e2018-03-16 11:34:15 -04002055 }
2056#StdOut
2057RGBA_F16 width 16777216 (0x01000000) OK
2058RGBA_F16 width 33554432 (0x02000000) OK
2059RGBA_F16 width 67108864 (0x04000000) OK
2060RGBA_F16 width 134217728 (0x08000000) OK
2061RGBA_F16 width 268435456 (0x10000000) too large
2062RGBA_F16 width 536870912 (0x20000000) too large
2063RGBA_F16 width 1073741824 (0x40000000) too large
2064RGBA_F16 width -2147483648 (0x80000000) too large
2065##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002066##
2067
Cary Clark681287e2018-03-16 11:34:15 -04002068#SeeAlso minRowBytes64 computeByteSize computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002069
2070#Method ##
2071
2072# ------------------------------------------------------------------------------
2073
2074#Method size_t computeOffset(int x, int y, size_t rowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05002075#In Utility
Cary Clark681287e2018-03-16 11:34:15 -04002076#Line # returns byte offset within pixel array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002077
Cary Clark681287e2018-03-16 11:34:15 -04002078Returns byte offset of pixel from pixel base address.
2079
2080Asserts in debug build if x or y is outside of bounds. Does not assert if
2081rowBytes is smaller than minRowBytes, even though result may be incorrect.
2082
2083#Param x column index, zero or greater, and less than width() ##
2084#Param y row index, zero or greater, and less than height() ##
2085#Param rowBytes size of pixel row or larger ##
2086
2087#Return offset within pixel array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002088
2089#Example
Cary Clark06c20f32018-03-20 15:53:27 -04002090#Height 128
Cary Clark681287e2018-03-16 11:34:15 -04002091 uint8_t pixels[][12] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00},
2092 { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00},
2093 { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00},
2094 { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF},
2095 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
2096 { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00},
2097 { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00},
2098 { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00} };
2099 SkImageInfo imageInfo = SkImageInfo::MakeA8(8, 8);
2100 SkBitmap bitmap;
2101 bitmap.installPixels(imageInfo, (void*) pixels, sizeof(pixels[0]));
2102 SkPaint paint;
2103 paint.setColor(SK_ColorRED);
2104 canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint);
2105 size_t offset = imageInfo.computeOffset(2, 3, sizeof(pixels[0]));
2106 pixels[0][offset] = 0x7F;
2107 offset = imageInfo.computeOffset(5, 3, sizeof(pixels[0]));
2108 pixels[0][offset] = 0x7F;
2109 bitmap.installPixels(imageInfo, (void*) pixels, sizeof(pixels[0]));
2110 canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(128, 128), &paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05002111##
2112
Cary Clark06c20f32018-03-20 15:53:27 -04002113#SeeAlso height width minRowBytes computeByteSize
Cary Clark2dc84ad2018-01-26 12:56:22 -05002114
2115#Method ##
2116
2117# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05002118#Subtopic Operator
2119#Populate
2120##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002121
2122#Method bool operator==(const SkImageInfo& other)_const
Cary Clark06c20f32018-03-20 15:53:27 -04002123#Line # compares Image_Info for equality ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002124
Cary Clark06c20f32018-03-20 15:53:27 -04002125Compares Image_Info with other, and returns true if width, height, Color_Type,
2126Alpha_Type, and Color_Space are equivalent.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002127
Cary Clark06c20f32018-03-20 15:53:27 -04002128#Param other Image_Info to compare ##
2129
2130#Return true if Image_Info equals other ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002131
2132#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002133 SkImageInfo info1 = SkImageInfo::Make(10, 20, kGray_8_SkColorType, kPremul_SkAlphaType);
2134 SkImageInfo info2 = SkImageInfo::Make(20, 10, kAlpha_8_SkColorType, kUnpremul_SkAlphaType);
2135 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
2136 info2 = info2.makeWH(10, 20);
2137 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
2138 info2 = info2.makeColorType(kGray_8_SkColorType);
2139 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
2140 info2 = info2.makeAlphaType(kPremul_SkAlphaType);
2141 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
2142#StdOut
2143info1 != info2
2144info1 != info2
2145info1 != info2
2146info1 == info2
2147##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002148##
2149
Cary Clark06c20f32018-03-20 15:53:27 -04002150#SeeAlso operator!=(const SkImageInfo& other)_const SkColorSpace::Equals
Cary Clark2dc84ad2018-01-26 12:56:22 -05002151
2152#Method ##
2153
2154# ------------------------------------------------------------------------------
2155
2156#Method bool operator!=(const SkImageInfo& other)_const
Cary Clark06c20f32018-03-20 15:53:27 -04002157#Line # compares Image_Info for inequality ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002158
Cary Clark06c20f32018-03-20 15:53:27 -04002159Compares Image_Info with other, and returns true if width, height, Color_Type,
Cary Clarkffb3d682018-05-17 12:17:28 -04002160Alpha_Type, and Color_Space are not equivalent.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002161
Cary Clark06c20f32018-03-20 15:53:27 -04002162#Param other Image_Info to compare ##
2163
2164#Return true if Image_Info is not equal to other ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002165
2166#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002167 SkImageInfo info1 = SkImageInfo::Make(10, 20, kGray_8_SkColorType, kPremul_SkAlphaType);
2168 SkImageInfo info2 = SkImageInfo::Make(20, 10, kAlpha_8_SkColorType, kUnpremul_SkAlphaType);
2169 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
2170 info2 = info2.makeWH(10, 20);
2171 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
2172 info2 = info2.makeColorType(kGray_8_SkColorType);
2173 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
2174 info2 = info2.makeAlphaType(kPremul_SkAlphaType);
2175 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
2176#StdOut
2177info1 != info2
2178info1 != info2
2179info1 != info2
2180info1 == info2
2181##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002182##
2183
Cary Clark06c20f32018-03-20 15:53:27 -04002184#SeeAlso operator==(const SkImageInfo& other)_const SkColorSpace::Equals
Cary Clark2dc84ad2018-01-26 12:56:22 -05002185
2186#Method ##
2187
2188# ------------------------------------------------------------------------------
2189
2190#Method size_t computeByteSize(size_t rowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05002191#In Utility
Cary Clark682c58d2018-05-16 07:07:07 -04002192#Line # returns memory required by pixel buffer with given row bytes ##
Cary Clark06c20f32018-03-20 15:53:27 -04002193Returns storage required by pixel array, given Image_Info dimensions, Color_Type,
2194and rowBytes. rowBytes is assumed to be at least as large as minRowBytes().
Cary Clark2dc84ad2018-01-26 12:56:22 -05002195
Cary Clark06c20f32018-03-20 15:53:27 -04002196Returns zero if height is zero.
Cary Clark63132862018-06-18 07:26:34 -04002197Returns SIZE_MAX if answer exceeds the range of size_t.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002198
Cary Clark06c20f32018-03-20 15:53:27 -04002199#Param rowBytes size of pixel row or larger ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002200
Cary Clark06c20f32018-03-20 15:53:27 -04002201#Return memory required by pixel buffer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002202
2203#Example
Cary Clark06c20f32018-03-20 15:53:27 -04002204#Height 130
Cary Clark682c58d2018-05-16 07:07:07 -04002205 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2);
2206 const size_t size = info.computeByteSize(100000);
2207 SkAutoTMalloc<SkPMColor> storage(size);
2208 SkPMColor* pixels = storage.get();
2209 SkBitmap bitmap;
2210 bitmap.setInfo(info);
2211 bitmap.setPixels(pixels);
2212 bitmap.eraseColor(SK_ColorRED);
2213 canvas->scale(50, 50);
2214 canvas->rotate(8);
Cary Clark06c20f32018-03-20 15:53:27 -04002215 canvas->drawBitmap(bitmap, 2, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05002216##
2217
Cary Clark06c20f32018-03-20 15:53:27 -04002218#SeeAlso computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002219
2220#Method ##
2221
2222# ------------------------------------------------------------------------------
2223
2224#Method size_t computeMinByteSize() const
Cary Clark78de7512018-02-07 07:27:09 -05002225#In Utility
Cary Clark682c58d2018-05-16 07:07:07 -04002226#Line # returns least memory required by pixel buffer ##
2227Returns storage required by pixel array, given Image_Info dimensions, and
Cary Clark06c20f32018-03-20 15:53:27 -04002228Color_Type. Uses minRowBytes() to compute bytes for pixel row.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002229
Cary Clark06c20f32018-03-20 15:53:27 -04002230Returns zero if height is zero.
Cary Clark63132862018-06-18 07:26:34 -04002231Returns SIZE_MAX if answer exceeds the range of size_t.
Cary Clark06c20f32018-03-20 15:53:27 -04002232
2233#Return least memory required by pixel buffer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002234
2235#Example
Cary Clark06c20f32018-03-20 15:53:27 -04002236#Height 130
Cary Clark682c58d2018-05-16 07:07:07 -04002237 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2);
2238 const size_t size = info.computeMinByteSize();
2239 SkAutoTMalloc<SkPMColor> storage(size);
2240 SkPMColor* pixels = storage.get();
2241 SkBitmap bitmap;
2242 bitmap.setInfo(info);
2243 bitmap.setPixels(pixels);
2244 bitmap.eraseColor(SK_ColorRED);
2245 canvas->scale(50, 50);
2246 canvas->rotate(8);
Cary Clark06c20f32018-03-20 15:53:27 -04002247 canvas->drawBitmap(bitmap, 2, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05002248##
2249
Cary Clark06c20f32018-03-20 15:53:27 -04002250#SeeAlso computeByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002251
2252#Method ##
2253
2254# ------------------------------------------------------------------------------
2255
2256#Method static bool ByteSizeOverflowed(size_t byteSize)
Cary Clark78de7512018-02-07 07:27:09 -05002257#In Utility
Cary Clark06c20f32018-03-20 15:53:27 -04002258#Line # checks result of computeByteSize and computeMinByteSize ##
Cary Clark63132862018-06-18 07:26:34 -04002259Returns true if byteSize equals SIZE_MAX. computeByteSize and
2260computeMinByteSize return SIZE_MAX if size_t can not hold buffer size.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002261
Cary Clark06c20f32018-03-20 15:53:27 -04002262#Param byteSize result of computeByteSize or computeMinByteSize ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002263
Cary Clark06c20f32018-03-20 15:53:27 -04002264#Return true if computeByteSize or computeMinByteSize result exceeds size_t ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002265
2266#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002267 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 1000000000);
2268 for (size_t rowBytes = 100000000; rowBytes < 10000000000000LL; rowBytes *= 10) {
2269 const size_t size = info.computeByteSize(rowBytes);
2270 SkDebugf("rowBytes:%llu size:%llu overflowed:%s\n", rowBytes, size,
2271 SkImageInfo::ByteSizeOverflowed(size) ? "true" : "false");
2272 }
2273#StdOut
2274rowBytes:100000000 size:99999999900000008 overflowed:false
2275rowBytes:1000000000 size:999999999000000008 overflowed:false
2276rowBytes:10000000000 size:9999999990000000008 overflowed:false
2277rowBytes:100000000000 size:18446744073709551615 overflowed:true
2278rowBytes:1000000000000 size:18446744073709551615 overflowed:true
2279##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002280##
2281
Cary Clark06c20f32018-03-20 15:53:27 -04002282#SeeAlso computeByteSize computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002283
2284#Method ##
2285
2286# ------------------------------------------------------------------------------
2287
2288#Method bool validRowBytes(size_t rowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05002289#In Utility
Cary Clark06c20f32018-03-20 15:53:27 -04002290#Line # checks if row bytes is large enough to contain pixel row ##
2291Returns true if rowBytes is smaller than width times pixel size.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002292
Cary Clark06c20f32018-03-20 15:53:27 -04002293#Param rowBytes size of pixel row or larger ##
2294
2295#Return true if rowBytes is large enough to contain pixel row ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002296
2297#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002298 SkImageInfo info = SkImageInfo::MakeN32Premul(16, 8);
2299 for (size_t rowBytes = 60; rowBytes < 72; rowBytes += sizeof(SkPMColor)) {
2300 SkDebugf("validRowBytes(%llu): %s\n", rowBytes, info.validRowBytes(rowBytes) ?
2301 "true" : "false");
2302 }
2303#StdOut
2304validRowBytes(60): false
2305validRowBytes(64): true
2306validRowBytes(68): true
2307##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002308##
2309
Cary Clark06c20f32018-03-20 15:53:27 -04002310#SeeAlso ByteSizeOverflowed computeByteSize computeMinByteSize
Cary Clark2dc84ad2018-01-26 12:56:22 -05002311
2312#Method ##
2313
2314# ------------------------------------------------------------------------------
2315
2316#Method void reset()
Cary Clark78de7512018-02-07 07:27:09 -05002317#In Constructor
Cary Clark06c20f32018-03-20 15:53:27 -04002318#Line # sets zero dimensions, kUnknown_SkColorType, kUnknown_SkAlphaType ##
2319Creates an empty Image_Info with kUnknown_SkColorType, kUnknown_SkAlphaType,
2320a width and height of zero, and no Color_Space.
2321
Cary Clark2dc84ad2018-01-26 12:56:22 -05002322#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002323 SkImageInfo info = SkImageInfo::MakeN32Premul(16, 8);
2324 SkImageInfo copy = info;
2325 SkDebugf("info %c= copy\n", info == copy ? '=' : '!');
2326 copy.reset();
2327 SkDebugf("info %c= reset copy\n", info == copy ? '=' : '!');
2328 SkDebugf("SkImageInfo() %c= reset copy\n", SkImageInfo() == copy ? '=' : '!');
2329#StdOut
2330info == copy
2331info != reset copy
2332SkImageInfo() == reset copy
2333##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002334##
2335
Cary Clark06c20f32018-03-20 15:53:27 -04002336#SeeAlso SkImageInfo()
Cary Clark2dc84ad2018-01-26 12:56:22 -05002337
2338#Method ##
2339
2340# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05002341#Subtopic Utility
2342#Populate
2343#Line # rarely called management functions ##
2344##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002345
2346#Method void validate() const
Cary Clark78de7512018-02-07 07:27:09 -05002347#In Utility
Cary Clark06c20f32018-03-20 15:53:27 -04002348#Line # asserts if Image_Info is invalid (debug only) ##
Cary Clark682c58d2018-05-16 07:07:07 -04002349Asserts if internal values are illegal or inconsistent. Only available if
Cary Clark06c20f32018-03-20 15:53:27 -04002350SK_DEBUG is defined at compile time.
2351
2352#NoExample
Cary Clark2dc84ad2018-01-26 12:56:22 -05002353##
2354
Cary Clark06c20f32018-03-20 15:53:27 -04002355#SeeAlso validRowBytes SkBitmap::validate
Cary Clark2dc84ad2018-01-26 12:56:22 -05002356
2357#Method ##
2358
2359#Struct SkImageInfo ##
2360
Cary Clark08895c42018-02-01 09:37:32 -05002361#Topic Image_Info ##