blob: c477d4f7527253430223f4136f9ad0f4ffbedf43 [file] [log] [blame]
Cary Clark2dc84ad2018-01-26 12:56:22 -05001#Topic Image_Info
2#Alias Image_Info_Reference
3
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 Clark2dc84ad2018-01-26 12:56:22 -050025#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 Clark2dc84ad2018-01-26 12:56:22 -0500227#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 Clarkffb3d682018-05-17 12:17:28 -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 Clarkffb3d682018-05-17 12:17:28 -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
358#Alias Native_Color_Type
359#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 Clarkffb3d682018-05-17 12:17:28 -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.
765 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 Clark772953472018-02-12 09:38:08 -0500983#Alias YUV_ColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -0500984#Enum SkYUVColorSpace
Cary Clark06c20f32018-03-20 15:53:27 -0400985#Line # color range of YUV pixels ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500986
987#Code
988 enum SkYUVColorSpace {
989 kJPEG_SkYUVColorSpace,
990 kRec601_SkYUVColorSpace,
991 kRec709_SkYUVColorSpace,
992 kLastEnum_SkYUVColorSpace = kRec709_SkYUVColorSpace,
993 };
994##
995
Cary Clark06c20f32018-03-20 15:53:27 -0400996Describes color range of YUV pixels. The color mapping from YUV to RGB varies
997depending on the source. YUV pixels may be generated by JPEG images, standard
998video streams, or high definition video streams. Each has its own mapping from
999YUV and RGB.
1000
1001JPEG YUV values encode the full range of 0 to 255 for all three components.
1002Video YUV values range from 16 to 235 for all three components. Details of
Cary Clark682c58d2018-05-16 07:07:07 -04001003encoding and conversion to RGB are described in
Cary Clark06c20f32018-03-20 15:53:27 -04001004#A YCbCr color space # https://en.wikipedia.org/wiki/YCbCr ##
1005.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001006
1007#Const kJPEG_SkYUVColorSpace 0
Cary Clark682c58d2018-05-16 07:07:07 -04001008#Line # describes full range ##
1009Describes standard JPEG color space;
Cary Clark06c20f32018-03-20 15:53:27 -04001010#A CCIR 601 # https://en.wikipedia.org/wiki/Rec._601 ##
1011with full range of 0 to 255 for components.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001012##
1013#Const kRec601_SkYUVColorSpace 1
Cary Clark682c58d2018-05-16 07:07:07 -04001014#Line # describes SDTV range ##
1015Describes standard used by standard definition television;
Cary Clark06c20f32018-03-20 15:53:27 -04001016#A CCIR 601 # https://en.wikipedia.org/wiki/Rec._601 ##
1017with studio range of 16 to 235 range for components.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001018##
1019#Const kRec709_SkYUVColorSpace 2
Cary Clark682c58d2018-05-16 07:07:07 -04001020#Line # describes HDTV range ##
1021Describes standard used by high definition television;
1022#A Rec. 709 # https://en.wikipedia.org/wiki/Rec._709 ##
Cary Clark06c20f32018-03-20 15:53:27 -04001023with studio range of 16 to 235 range for components.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001024##
Cary Clark682c58d2018-05-16 07:07:07 -04001025#Const kLastEnum_SkYUVColorSpace 2
1026#Line # last valid value ##
1027 Used by tests to iterate through all valid values.
1028##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001029
Cary Clark06c20f32018-03-20 15:53:27 -04001030#NoExample
Cary Clark2dc84ad2018-01-26 12:56:22 -05001031##
1032
Cary Clark06c20f32018-03-20 15:53:27 -04001033#SeeAlso SkImage::MakeFromYUVTexturesCopy SkImage::MakeFromNV12TexturesCopy
Cary Clark2dc84ad2018-01-26 12:56:22 -05001034
1035#Enum SkYUVColorSpace ##
Cary Clark772953472018-02-12 09:38:08 -05001036#Subtopic YUV_ColorSpace ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001037
1038# ------------------------------------------------------------------------------
Cary Clark2dc84ad2018-01-26 12:56:22 -05001039
1040#Struct SkImageInfo
1041
Cary Clark682c58d2018-05-16 07:07:07 -04001042Describes pixel dimensions and encoding. Bitmap, Image, PixMap, and Surface
Cary Clark1a8d7622018-03-05 13:26:16 -05001043can be created from Image_Info. Image_Info can be retrieved from Bitmap and
1044Pixmap, but not from Image and Surface. For example, Image and Surface
1045implementations may defer pixel depth, so may not completely specify Image_Info.
1046
1047Image_Info contains dimensions, the pixel integral width and height. It encodes
1048how pixel bits describe Color_Alpha, transparency; Color components red, blue,
1049and green; and Color_Space, the range and linearity of colors.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001050
Cary Clark4855f782018-02-06 09:41:53 -05001051#Subtopic Member_Function
Cary Clark08895c42018-02-01 09:37:32 -05001052#Populate
1053##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001054
Cary Clark78de7512018-02-07 07:27:09 -05001055#Subtopic Related_Function
Cary Clark08895c42018-02-01 09:37:32 -05001056#Populate
1057##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001058
1059# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05001060#Subtopic Constructor
1061#Populate
1062##
1063
Cary Clark2dc84ad2018-01-26 12:56:22 -05001064#Method SkImageInfo()
1065
Cary Clark4855f782018-02-06 09:41:53 -05001066#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001067#Line # creates with zero dimensions, kUnknown_SkColorType, kUnknown_SkAlphaType ##
Cary Clark06c20f32018-03-20 15:53:27 -04001068Creates an empty Image_Info with kUnknown_SkColorType, kUnknown_SkAlphaType,
Cary Clark1a8d7622018-03-05 13:26:16 -05001069a width and height of zero, and no Color_Space.
1070
1071#Return empty Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001072
1073#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001074#Height 32
1075#Description
1076An empty Image_Info may be passed to SkCanvas::accessTopLayerPixels as storage
1077for the Canvas actual Image_Info.
1078##
1079 SkImageInfo imageInfo;
1080 size_t rowBytes;
1081 SkIPoint origin;
Cary Clark681287e2018-03-16 11:34:15 -04001082 (void) canvas->accessTopLayerPixels(&imageInfo, &rowBytes, &origin);
Cary Clark1a8d7622018-03-05 13:26:16 -05001083 const char* alphaType[] = { "Unknown", "Opaque", "Premul", "Unpremul" };
1084 SkString string;
1085 string.printf("k%s_SkAlphaType", alphaType[(int) imageInfo.alphaType()]);
1086 SkPaint paint;
1087 canvas->drawString(string, 20, 20, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001088##
1089
Cary Clark1a8d7622018-03-05 13:26:16 -05001090#SeeAlso Make MakeN32 MakeS32 MakeA8
Cary Clark2dc84ad2018-01-26 12:56:22 -05001091
1092#Method ##
1093
1094# ------------------------------------------------------------------------------
1095
1096#Method static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at,
1097 sk_sp<SkColorSpace> cs = nullptr)
Cary Clark4855f782018-02-06 09:41:53 -05001098#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001099#Line # creates Image_Info from dimensions, Color_Type, Alpha_Type, Color_Space ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001100Creates Image_Info from integral dimensions width and height, Color_Type ct,
1101Alpha_Type at, and optionally Color_Space cs.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001102
Cary Clark1a8d7622018-03-05 13:26:16 -05001103If Color_Space cs is nullptr and Image_Info is part of drawing source: Color_Space
1104defaults to sRGB, mapping into Surface Color_Space.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001105
Cary Clark1a8d7622018-03-05 13:26:16 -05001106Parameters are not validated to see if their values are legal, or that the
1107combination is supported.
1108
1109#Param width pixel column count; must be zero or greater ##
1110#Param height pixel row count; must be zero or greater ##
1111#Param ct one of: #list_of_color_types#
1112##
Cary Clark681287e2018-03-16 11:34:15 -04001113#Param at one of: #list_of_alpha_types#
Cary Clark1a8d7622018-03-05 13:26:16 -05001114##
1115#Param cs range of colors; may be nullptr ##
1116
1117#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001118
1119#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001120#Height 48
1121 uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 },
1122 { 0xAC, 0xA8, 0x89, 0xA7, 0x87 },
1123 { 0x9B, 0xB5, 0xE5, 0x95, 0x46 },
1124 { 0x90, 0x81, 0xC5, 0x71, 0x33 },
1125 { 0x75, 0x55, 0x44, 0x40, 0x30 }};
1126 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType);
1127 SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
1128 SkBitmap bitmap;
1129 bitmap.installPixels(pixmap);
1130 canvas->scale(8, 8);
1131 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001132##
1133
Cary Clark1a8d7622018-03-05 13:26:16 -05001134#SeeAlso MakeN32 MakeN32Premul MakeS32 MakeA8
Cary Clark2dc84ad2018-01-26 12:56:22 -05001135
1136#Method ##
1137
1138# ------------------------------------------------------------------------------
1139
1140#Method static SkImageInfo MakeN32(int width, int height, SkAlphaType at,
1141 sk_sp<SkColorSpace> cs = nullptr)
Cary Clark4855f782018-02-06 09:41:53 -05001142#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001143#Line # creates Image_Info with Native_Color_Type ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001144Creates Image_Info from integral dimensions width and height, kN32_SkColorType,
1145Alpha_Type at, and optionally Color_Space cs. kN32_SkColorType will equal either
1146kBGRA_8888_SkColorType or kRGBA_8888_SkColorType, whichever is optimal.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001147
Cary Clark1a8d7622018-03-05 13:26:16 -05001148If Color_Space cs is nullptr and Image_Info is part of drawing source: Color_Space
1149defaults to sRGB, mapping into Surface Color_Space.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001150
Cary Clark1a8d7622018-03-05 13:26:16 -05001151Parameters are not validated to see if their values are legal, or that the
1152combination is supported.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001153
Cary Clark1a8d7622018-03-05 13:26:16 -05001154#Param width pixel column count; must be zero or greater ##
1155#Param height pixel row count; must be zero or greater ##
Cary Clark681287e2018-03-16 11:34:15 -04001156#Param at one of: #list_of_alpha_types#
Cary Clark1a8d7622018-03-05 13:26:16 -05001157##
1158#Param cs range of colors; may be nullptr ##
1159
1160#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001161
1162#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001163#Height 128
1164 SkBitmap bitmap;
1165 bitmap.allocPixels(SkImageInfo::MakeN32(16, 16, kPremul_SkAlphaType));
1166 SkCanvas offscreen(bitmap);
1167 offscreen.clear(SK_ColorWHITE);
1168 SkPaint paint;
1169 offscreen.drawString("g", 0, 10, paint);
1170 canvas->scale(8, 8);
1171 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001172##
1173
Cary Clark1a8d7622018-03-05 13:26:16 -05001174#SeeAlso Make MakeN32Premul MakeS32 MakeA8
Cary Clark2dc84ad2018-01-26 12:56:22 -05001175
1176#Method ##
1177
1178# ------------------------------------------------------------------------------
1179
1180#Method static SkImageInfo MakeS32(int width, int height, SkAlphaType at)
1181
Cary Clark4855f782018-02-06 09:41:53 -05001182#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001183#Line # creates Image_Info with Native_Color_Type, sRGB Color_Space ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001184Creates Image_Info from integral dimensions width and height, kN32_SkColorType,
1185Alpha_Type at, with sRGB Color_Space.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001186
Cary Clark1a8d7622018-03-05 13:26:16 -05001187Parameters are not validated to see if their values are legal, or that the
1188combination is supported.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001189
Cary Clark1a8d7622018-03-05 13:26:16 -05001190#Param width pixel column count; must be zero or greater ##
1191#Param height pixel row count; must be zero or greater ##
Cary Clark681287e2018-03-16 11:34:15 -04001192#Param at one of: #list_of_alpha_types#
Cary Clark2dc84ad2018-01-26 12:56:22 -05001193##
1194
Cary Clark1a8d7622018-03-05 13:26:16 -05001195#Return created Image_Info ##
1196
1197#Example
1198#Set sRGB
1199#Height 128
1200#Description
Cary Clark682c58d2018-05-16 07:07:07 -04001201Top gradient is drawn to offScreen without Color_Space. It is darker than middle
1202gradient, drawn to offScreen with sRGB Color_Space. Bottom gradient shares bits
Cary Clark1a8d7622018-03-05 13:26:16 -05001203with middle, but does not specify the Color_Space in noColorSpaceBitmap. A source
1204without Color_Space is treated as sRGB; the bottom gradient is identical to the
1205middle gradient.
1206##
1207 const int width = 256;
1208 const int height = 32;
1209 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
1210 SkColor gradColors[] = { 0xFFAA0055, 0xFF11CC88 };
1211 SkPoint gradPoints[] = { { 0, 0 }, { width, 0 } };
1212 SkPaint gradPaint;
1213 gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1214 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1215 SkBitmap bitmap;
1216 bitmap.allocPixels(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType));
Cary Clark682c58d2018-05-16 07:07:07 -04001217 SkCanvas offScreen(bitmap);
1218 offScreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
Cary Clark1a8d7622018-03-05 13:26:16 -05001219 canvas->drawBitmap(bitmap, 0, 0);
1220 bitmap.allocPixels(SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType));
1221 SkCanvas sRGBOffscreen(bitmap);
1222 sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1223 canvas->drawBitmap(bitmap, 0, 48);
1224 SkBitmap noColorSpaceBitmap;
1225 noColorSpaceBitmap.setInfo(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType));
1226 noColorSpaceBitmap.setPixels(bitmap.getAddr(0, 0));
1227 canvas->drawBitmap(noColorSpaceBitmap, 0, 96);
1228##
1229
1230#SeeAlso Make MakeN32 MakeN32Premul MakeA8
Cary Clark2dc84ad2018-01-26 12:56:22 -05001231
1232#Method ##
1233
1234# ------------------------------------------------------------------------------
1235
1236#Method static SkImageInfo MakeN32Premul(int width, int height, sk_sp<SkColorSpace> cs = nullptr)
1237
Cary Clark4855f782018-02-06 09:41:53 -05001238#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001239#Line # creates Image_Info with Native_Color_Type, kPremul_SkAlphaType ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001240Creates Image_Info from integral dimensions width and height, kN32_SkColorType,
1241kPremul_SkAlphaType, with optional Color_Space.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001242
Cary Clark1a8d7622018-03-05 13:26:16 -05001243If Color_Space cs is nullptr and Image_Info is part of drawing source: Color_Space
1244defaults to sRGB, mapping into Surface Color_Space.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001245
Cary Clark1a8d7622018-03-05 13:26:16 -05001246Parameters are not validated to see if their values are legal, or that the
1247combination is supported.
1248
1249#Param width pixel column count; must be zero or greater ##
1250#Param height pixel row count; must be zero or greater ##
1251#Param cs range of colors; may be nullptr ##
1252
1253#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001254
1255#Example
Cary Clark06c20f32018-03-20 15:53:27 -04001256#Height 128
Cary Clark1a8d7622018-03-05 13:26:16 -05001257 SkBitmap bitmap;
1258 bitmap.allocPixels(SkImageInfo::MakeN32Premul(18, 18));
1259 SkCanvas offscreen(bitmap);
1260 offscreen.clear(SK_ColorWHITE);
1261 SkPaint paint;
1262 paint.setAntiAlias(true);
1263 paint.setTextSize(15);
1264 offscreen.drawString("\xF0\x9F\x98\xB8", 1, 15, paint);
1265 canvas->scale(6, 6);
1266 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001267##
1268
Cary Clark1a8d7622018-03-05 13:26:16 -05001269#SeeAlso MakeN32 MakeS32 MakeA8 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001270
1271#Method ##
1272
1273# ------------------------------------------------------------------------------
1274
1275#Method static SkImageInfo MakeN32Premul(const SkISize& size)
1276
Cary Clark4855f782018-02-06 09:41:53 -05001277#In Constructor
Cary Clark1a8d7622018-03-05 13:26:16 -05001278Creates Image_Info from integral dimensions width and height, kN32_SkColorType,
1279kPremul_SkAlphaType, with Color_Space set to nullptr.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001280
Cary Clark1a8d7622018-03-05 13:26:16 -05001281If Image_Info is part of drawing source: Color_Space defaults to sRGB, mapping
1282into Surface Color_Space.
1283
1284Parameters are not validated to see if their values are legal, or that the
1285combination is supported.
1286
1287#Param size width and height, each must be zero or greater ##
1288
1289#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001290
1291#Example
Cary Clark06c20f32018-03-20 15:53:27 -04001292#Height 128
Cary Clark1a8d7622018-03-05 13:26:16 -05001293 SkBitmap bitmap;
1294 bitmap.allocPixels(SkImageInfo::MakeN32Premul({18, 18}));
1295 SkCanvas offscreen(bitmap);
1296 offscreen.clear(SK_ColorWHITE);
1297 SkPaint paint;
1298 paint.setAntiAlias(true);
1299 paint.setTextSize(15);
1300 offscreen.drawString("\xF0\x9F\x98\xB9", 1, 15, paint);
1301 canvas->scale(6, 6);
1302 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001303##
1304
Cary Clark682c58d2018-05-16 07:07:07 -04001305#SeeAlso MakeN32 MakeS32 MakeA8 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001306
1307#Method ##
1308
1309# ------------------------------------------------------------------------------
1310
1311#Method static SkImageInfo MakeA8(int width, int height)
1312
Cary Clark4855f782018-02-06 09:41:53 -05001313#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001314#Line # creates Image_Info with kAlpha_8_SkColorType, kPremul_SkAlphaType ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001315Creates Image_Info from integral dimensions width and height, kAlpha_8_SkColorType,
1316kPremul_SkAlphaType, with Color_Space set to nullptr.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001317
Cary Clark1a8d7622018-03-05 13:26:16 -05001318#Param width pixel column count; must be zero or greater ##
1319#Param height pixel row count; must be zero or greater ##
1320
1321#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001322
1323#Example
Cary Clark681287e2018-03-16 11:34:15 -04001324#Height 64
1325 uint8_t pixels[][8] = { { 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00},
1326 { 0x00, 0x7f, 0xff, 0x3f, 0x3f, 0x7f, 0x3f, 0x00},
1327 { 0x3f, 0xff, 0x7f, 0x00, 0x7f, 0xff, 0x7f, 0x00},
1328 { 0x00, 0x3f, 0x00, 0x00, 0x3f, 0x7f, 0x3f, 0x00},
1329 { 0x3f, 0x7f, 0x7f, 0x3f, 0x00, 0x00, 0x00, 0x00},
1330 { 0x7f, 0xff, 0xff, 0x7f, 0x00, 0x3f, 0x7f, 0x3f},
1331 { 0x7f, 0xff, 0xff, 0x7f, 0x00, 0x7f, 0xff, 0x7f},
1332 { 0x3f, 0x7f, 0x7f, 0x3f, 0x00, 0x3f, 0x7f, 0x3f} };
1333 SkBitmap bitmap;
1334 bitmap.installPixels(SkImageInfo::MakeA8(8, 8),
1335 (void*) pixels, sizeof(pixels[0]));
1336 SkPaint paint;
1337 canvas->scale(4, 4);
1338 for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) {
1339 paint.setColor(color);
1340 canvas->drawBitmap(bitmap, 0, 0, &paint);
1341 canvas->translate(12, 0);
1342 }
Cary Clark2dc84ad2018-01-26 12:56:22 -05001343##
1344
Cary Clark1a8d7622018-03-05 13:26:16 -05001345#SeeAlso MakeN32 MakeS32 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001346
1347#Method ##
1348
1349# ------------------------------------------------------------------------------
1350
1351#Method static SkImageInfo MakeUnknown(int width, int height)
1352
Cary Clark4855f782018-02-06 09:41:53 -05001353#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001354#Line # creates Image_Info with kUnknown_SkColorType, kUnknown_SkAlphaType ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001355Creates Image_Info from integral dimensions width and height, kUnknown_SkColorType,
1356kUnknown_SkAlphaType, with Color_Space set to nullptr.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001357
Cary Clark1a8d7622018-03-05 13:26:16 -05001358Returned Image_Info as part of source does not draw, and as part of destination
1359can not be drawn to.
1360
1361#Param width pixel column count; must be zero or greater ##
1362#Param height pixel row count; must be zero or greater ##
1363
1364#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001365
1366#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001367#Height 32
1368#Width 384
1369SkImageInfo info; // default constructor
1370SkString string;
1371string.printf("SkImageInfo() %c= SkImageInfo::MakeUnknown(0, 0)",
1372 info == SkImageInfo::MakeUnknown(0, 0) ? '=' : '!');
1373SkPaint paint;
1374canvas->drawString(string, 0, 12, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001375##
1376
Cary Clark1a8d7622018-03-05 13:26:16 -05001377#SeeAlso SkImageInfo() MakeN32 MakeS32 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001378
1379#Method ##
1380
1381# ------------------------------------------------------------------------------
1382
1383#Method static SkImageInfo MakeUnknown()
1384
Cary Clark4855f782018-02-06 09:41:53 -05001385#In Constructor
Cary Clark1a8d7622018-03-05 13:26:16 -05001386Creates Image_Info from integral dimensions width and height set to zero,
1387kUnknown_SkColorType, kUnknown_SkAlphaType, with Color_Space set to nullptr.
1388
1389Returned Image_Info as part of source does not draw, and as part of destination
1390can not be drawn to.
1391
1392#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001393
1394#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001395#Height 32
1396#Width 384
1397SkImageInfo info; // default constructor
1398SkString string;
1399string.printf("SkImageInfo() %c= SkImageInfo::MakeUnknown()",
1400 info == SkImageInfo::MakeUnknown() ? '=' : '!');
1401SkPaint paint;
1402canvas->drawString(string, 0, 12, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001403##
1404
Cary Clark1a8d7622018-03-05 13:26:16 -05001405#SeeAlso SkImageInfo() MakeN32 MakeS32 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001406
1407#Method ##
1408
Cary Clark2dc84ad2018-01-26 12:56:22 -05001409
1410# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05001411#Subtopic Property
1412#Populate
1413#Line # metrics and attributes ##
1414##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001415
1416#Method int width() const
Cary Clark78de7512018-02-07 07:27:09 -05001417#In Property
Cary Clark1a8d7622018-03-05 13:26:16 -05001418#Line # returns pixel column count ##
1419Returns pixel count in each row.
1420
1421#Return pixel width ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001422
1423#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001424#Image 4
1425#Height 96
1426 canvas->translate(10, 10);
1427 canvas->drawBitmap(source, 0, 0);
1428 SkImageInfo imageInfo = source.info();
1429 canvas->translate(0, imageInfo.height());
1430 SkPaint paint;
1431 paint.setTextAlign(SkPaint::kCenter_Align);
1432 canvas->drawLine(0, 10, imageInfo.width(), 10, paint);
1433 canvas->drawString("width", imageInfo.width() / 2, 25, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001434##
1435
Cary Clark1a8d7622018-03-05 13:26:16 -05001436#SeeAlso height SkBitmap::width SkPixelRef::width SkImage::width SkSurface::width
Cary Clark2dc84ad2018-01-26 12:56:22 -05001437
1438#Method ##
1439
1440# ------------------------------------------------------------------------------
1441
1442#Method int height() const
Cary Clark78de7512018-02-07 07:27:09 -05001443#In Property
Cary Clark1a8d7622018-03-05 13:26:16 -05001444#Line # returns pixel row count ##
1445Returns pixel row count.
1446
1447#Return pixel height ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001448
1449#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001450#Image 4
1451#Height 96
1452 canvas->translate(10, 20);
1453 canvas->drawBitmap(source, 0, 0);
1454 SkImageInfo imageInfo = source.info();
1455 SkPaint paint;
1456 paint.setTextAlign(SkPaint::kCenter_Align);
1457 paint.setVerticalText(true);
1458 canvas->drawLine(imageInfo.width() + 10, 0, imageInfo.width() + 10, imageInfo.height(), paint);
1459 canvas->drawString("height", imageInfo.width() + 25, imageInfo.height() / 2, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001460##
1461
Cary Clark1a8d7622018-03-05 13:26:16 -05001462#SeeAlso width SkBitmap::height SkPixelRef::height SkImage::height SkSurface::height
Cary Clark2dc84ad2018-01-26 12:56:22 -05001463
1464#Method ##
1465
1466# ------------------------------------------------------------------------------
1467
1468#Method SkColorType colorType() const
Cary Clark78de7512018-02-07 07:27:09 -05001469#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001470#Line # returns Color_Type ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001471Returns Color_Type, one of: #list_of_color_types#.
1472
1473#Return Color_Type ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001474
1475#Example
Cary Clark681287e2018-03-16 11:34:15 -04001476 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
1477 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
1478 SkImageInfo info = SkImageInfo::MakeA8(16, 32);
1479 SkDebugf("color type: k" "%s" "_SkColorType\n", colors[info.colorType()]);
1480#StdOut
1481color type: kAlpha_8_SkColorType
1482##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001483##
1484
Cary Clark681287e2018-03-16 11:34:15 -04001485#SeeAlso alphaType SkPixmap::colorType SkBitmap::colorType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001486
1487#Method ##
1488
1489# ------------------------------------------------------------------------------
1490
1491#Method SkAlphaType alphaType() const
Cary Clark78de7512018-02-07 07:27:09 -05001492#In Property
Cary Clark682c58d2018-05-16 07:07:07 -04001493#Line # returns Alpha_Type ##
Cary Clark681287e2018-03-16 11:34:15 -04001494Returns Alpha_Type, one of: #list_of_alpha_types#.
1495
1496#Return Alpha_Type ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001497
1498#Example
Cary Clark681287e2018-03-16 11:34:15 -04001499 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
1500 SkImageInfo info = SkImageInfo::MakeA8(16, 32);
1501 SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[info.alphaType()]);
1502#StdOut
1503alpha type: kPremul_SkAlphaType
1504##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001505##
1506
Cary Clark681287e2018-03-16 11:34:15 -04001507#SeeAlso colorType SkPixmap::alphaType SkBitmap::alphaType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001508
1509#Method ##
1510
1511# ------------------------------------------------------------------------------
1512
1513#Method SkColorSpace* colorSpace() const
Cary Clark78de7512018-02-07 07:27:09 -05001514#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001515#Line # returns Color_Space ##
1516Returns Color_Space, the range of colors. The reference count of
1517Color_Space is unchanged. The returned Color_Space is immutable.
1518
1519#Return Color_Space, or nullptr ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001520
1521#Example
Cary Clark681287e2018-03-16 11:34:15 -04001522#Description
1523SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma
1524and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma.
1525##
Cary Clark682c58d2018-05-16 07:07:07 -04001526 SkImageInfo info = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
Cary Clark681287e2018-03-16 11:34:15 -04001527 SkColorSpace::MakeSRGBLinear());
1528 SkColorSpace* colorSpace = info.colorSpace();
1529 SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
1530 colorSpace->gammaCloseToSRGB() ? "true" : "false",
1531 colorSpace->gammaIsLinear() ? "true" : "false",
1532 colorSpace->isSRGB() ? "true" : "false");
1533#StdOut
1534gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
1535##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001536##
1537
Cary Clark681287e2018-03-16 11:34:15 -04001538#SeeAlso Color_Space SkPixmap::colorSpace SkBitmap::colorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001539
1540#Method ##
1541
1542# ------------------------------------------------------------------------------
1543
1544#Method sk_sp<SkColorSpace> refColorSpace() const
Cary Clark78de7512018-02-07 07:27:09 -05001545#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001546#Line # returns Color_Space ##
Cary Clark682c58d2018-05-16 07:07:07 -04001547Returns smart pointer to Color_Space, the range of colors. The smart pointer
Cary Clark681287e2018-03-16 11:34:15 -04001548tracks the number of objects sharing this Color_Space reference so the memory
1549is released when the owners destruct.
1550
1551The returned Color_Space is immutable.
1552
1553#Return Color_Space wrapped in a smart pointer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001554
1555#Example
Cary Clark682c58d2018-05-16 07:07:07 -04001556 SkImageInfo info1 = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
Cary Clark681287e2018-03-16 11:34:15 -04001557 SkColorSpace::MakeSRGBLinear());
1558 SkImageInfo info2 = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
1559 info1.refColorSpace());
1560 SkColorSpace* colorSpace = info2.colorSpace();
1561 SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
1562 colorSpace->gammaCloseToSRGB() ? "true" : "false",
1563 colorSpace->gammaIsLinear() ? "true" : "false",
1564 colorSpace->isSRGB() ? "true" : "false");
Cary Clark2dc84ad2018-01-26 12:56:22 -05001565##
1566
Cary Clark681287e2018-03-16 11:34:15 -04001567#SeeAlso Color_Space SkBitmap::refColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001568
1569#Method ##
1570
1571# ------------------------------------------------------------------------------
1572
1573#Method bool isEmpty() const
Cary Clark78de7512018-02-07 07:27:09 -05001574#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001575#Line # returns if dimensions contain pixels ##
1576
1577Returns if Image_Info describes an empty area of pixels by checking if either
1578width or height is zero or smaller.
1579
1580#Return true if either dimension is zero or smaller ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001581
1582#Example
Cary Clark681287e2018-03-16 11:34:15 -04001583 for (int width : { 0, 2 } ) {
1584 for (int height : { 0, 2 } ) {
1585 SkImageInfo imageInfo= SkImageInfo::MakeA8(width, height);
1586 SkDebugf("width: %d height: %d empty: %s\n", width, height,
1587 imageInfo.isEmpty() ? "true" : "false");
1588 }
1589 }
1590#StdOut
1591width: 0 height: 0 empty: true
1592width: 0 height: 2 empty: true
1593width: 2 height: 0 empty: true
1594width: 2 height: 2 empty: false
1595##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001596##
1597
Cary Clark681287e2018-03-16 11:34:15 -04001598#SeeAlso dimensions bounds SkBitmap::empty SkPixmap::bounds
Cary Clark2dc84ad2018-01-26 12:56:22 -05001599
1600#Method ##
1601
1602# ------------------------------------------------------------------------------
1603
1604#Method bool isOpaque() const
Cary Clark78de7512018-02-07 07:27:09 -05001605#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001606#Line # returns if Alpha_Type is kOpaque_SkAlphaType ##
1607
1608Returns true if Alpha_Type is set to hint that all pixels are opaque; their
1609Color_Alpha value is implicitly or explicitly 1.0. If true, and all pixels are
Cary Clark682c58d2018-05-16 07:07:07 -04001610not opaque, Skia may draw incorrectly.
Cary Clark681287e2018-03-16 11:34:15 -04001611
1612Does not check if Color_Type allows Alpha, or if any pixel value has
1613transparency.
1614
1615#Return true if Alpha_Type is kOpaque_SkAlphaType ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001616
1617#Example
Cary Clark681287e2018-03-16 11:34:15 -04001618 const int height = 2;
1619 const int width = 2;
1620 SkBitmap bitmap;
1621 SkImageInfo imageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType);
1622 bitmap.setInfo(imageInfo);
1623 for (int index = 0; index < 2; ++index) {
1624 bitmap.allocPixels();
1625 bitmap.eraseColor(0x00000000);
1626 SkDebugf("isOpaque: %s\n", imageInfo.isOpaque() ? "true" : "false");
1627 bitmap.eraseColor(0xFFFFFFFF);
1628 SkDebugf("isOpaque: %s\n", imageInfo.isOpaque() ? "true" : "false");
1629 imageInfo = imageInfo.makeAlphaType(kOpaque_SkAlphaType);
1630 bitmap.setInfo(imageInfo);
1631 }
1632#StdOut
1633isOpaque: false
1634isOpaque: false
1635isOpaque: true
1636isOpaque: true
1637##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001638##
1639
Cary Clark681287e2018-03-16 11:34:15 -04001640#SeeAlso Color_Alpha SkColorTypeValidateAlphaType SkBitmap::isOpaque SkImage::isOpaque SkPixmap::isOpaque
Cary Clark2dc84ad2018-01-26 12:56:22 -05001641
1642#Method ##
1643
1644# ------------------------------------------------------------------------------
1645
1646#Method SkISize dimensions() const
Cary Clark78de7512018-02-07 07:27:09 -05001647#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001648#Line # returns width() and height() ##
1649
1650Returns ISize { width(), height() }.
1651
1652#Return integral size of width() and height() ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001653
1654#Example
Cary Clark681287e2018-03-16 11:34:15 -04001655 const int height = 2;
1656 const int width = 2;
1657 SkImageInfo imageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType);
1658 SkISize dimensions = imageInfo.dimensions();
1659 SkIRect bounds = imageInfo.bounds();
1660 SkIRect dimensionsAsBounds = SkIRect::MakeSize(dimensions);
1661 SkDebugf("dimensionsAsBounds %c= bounds\n", dimensionsAsBounds == bounds ? '=' : '!');
1662#StdOut
1663dimensionsAsBounds == bounds
1664##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001665##
1666
Cary Clark681287e2018-03-16 11:34:15 -04001667#SeeAlso width height bounds SkBitmap::dimensions
Cary Clark2dc84ad2018-01-26 12:56:22 -05001668
1669#Method ##
1670
1671# ------------------------------------------------------------------------------
1672
1673#Method SkIRect bounds() const
Cary Clark78de7512018-02-07 07:27:09 -05001674#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001675#Line # returns width() and height() as Rectangle ##
1676Returns IRect { 0, 0, width(), height() }.
1677
1678#Return integral rectangle from origin to width() and height() ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001679
1680#Example
Cary Clark681287e2018-03-16 11:34:15 -04001681#Height 64
1682#Image 4
1683 canvas->scale(.5f, .5f);
1684 SkImageInfo imageInfo = source.info();
1685 SkIRect bounds = imageInfo.bounds();
1686 for (int x : { 0, bounds.width() } ) {
1687 for (int y : { 0, bounds.height() } ) {
1688 canvas->drawBitmap(source, x, y);
1689 }
1690 }
Cary Clark2dc84ad2018-01-26 12:56:22 -05001691##
1692
Cary Clark681287e2018-03-16 11:34:15 -04001693#SeeAlso width height dimensions
Cary Clark2dc84ad2018-01-26 12:56:22 -05001694
1695#Method ##
1696
1697# ------------------------------------------------------------------------------
1698
1699#Method bool gammaCloseToSRGB() const
Cary Clark78de7512018-02-07 07:27:09 -05001700#In Property
Cary Clark682c58d2018-05-16 07:07:07 -04001701#Line # returns if Color_Space gamma is approximately the same as sRGB ##
Cary Clark681287e2018-03-16 11:34:15 -04001702
1703Returns true if associated Color_Space is not nullptr, and Color_Space gamma
Cary Clark682c58d2018-05-16 07:07:07 -04001704is approximately the same as sRGB.
1705This includes the
Cary Clark681287e2018-03-16 11:34:15 -04001706###$
1707$A sRGB transfer function $ https://en.wikipedia.org/wiki/SRGB#The_sRGB_transfer_function_(%22gamma%22) $$
1708$$$#
1709as well as a gamma curve described by a 2.2 exponent.
1710
1711#Return true if Color_Space gamma is approximately the same as sRGB ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001712
1713#Example
Cary Clark681287e2018-03-16 11:34:15 -04001714#Height 144
1715 const int width = 256;
1716 const int height = 64;
1717 auto drawLabel = [=](const char* what, bool closeToSRGB) -> void {
1718 SkString string;
1719 string.printf("%s gamma is %s" "close to sRGB", what, closeToSRGB ? "" : "not ");
1720 SkPaint paint;
1721 paint.setAntiAlias(true);
1722 paint.setTextAlign(SkPaint::kCenter_Align);
1723 canvas->drawString(string, width / 2, 56, paint);
1724 };
1725 SkColor gradColors[] = { 0xFFFF7F00, 0xFF00FF7F, 0xFF0000FF, 0xFF7F7FFF };
1726 SkPoint gradPoints[] = { { 0, 0 }, { width, 0 }, { width * 2, 0 }, { width * 3, 0 } };
1727 SkPaint gradPaint;
1728 gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1729 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1730 canvas->drawRect(SkRect::MakeWH(width, height), gradPaint);
1731 drawLabel("canvas", canvas->imageInfo().gammaCloseToSRGB());
1732 SkBitmap bitmap;
1733 SkImageInfo offscreenInfo = SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType);
1734 bitmap.allocPixels(offscreenInfo);
1735 SkCanvas sRGBOffscreen(bitmap);
1736 sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1737 canvas->translate(0, 80);
1738 canvas->drawBitmap(bitmap, 0, 0);
1739 drawLabel("offscreen", offscreenInfo.gammaCloseToSRGB());
Cary Clark2dc84ad2018-01-26 12:56:22 -05001740##
1741
Cary Clark681287e2018-03-16 11:34:15 -04001742#SeeAlso SkColorSpace::gammaCloseToSRGB
Cary Clark2dc84ad2018-01-26 12:56:22 -05001743
1744#Method ##
1745
1746# ------------------------------------------------------------------------------
1747
1748#Method SkImageInfo makeWH(int newWidth, int newHeight) const
Cary Clark78de7512018-02-07 07:27:09 -05001749#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001750#Line # creates Image_Info with changed dimensions ##
Cary Clark681287e2018-03-16 11:34:15 -04001751Creates Image_Info with the same Color_Type, Color_Space, and Alpha_Type,
1752with dimensions set to width and height.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001753
Cary Clark681287e2018-03-16 11:34:15 -04001754#Param newWidth pixel column count; must be zero or greater ##
1755#Param newHeight pixel row count; must be zero or greater ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001756
Cary Clark681287e2018-03-16 11:34:15 -04001757#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001758
1759#Example
Cary Clark681287e2018-03-16 11:34:15 -04001760#Height 144
1761#Image 3
1762 SkImageInfo canvasImageInfo = canvas->imageInfo();
1763 SkRect canvasBounds = SkRect::Make(canvasImageInfo.bounds());
1764 canvas->drawBitmapRect(source, source.bounds(), canvasBounds, nullptr);
Cary Clark682c58d2018-05-16 07:07:07 -04001765 SkImageInfo insetImageInfo =
Cary Clark681287e2018-03-16 11:34:15 -04001766 canvasImageInfo.makeWH(canvasBounds.width() / 2, canvasBounds.height() / 2);
1767 SkBitmap inset;
1768 inset.allocPixels(insetImageInfo);
1769 SkCanvas offscreen(inset);
1770 offscreen.drawBitmapRect(source, source.bounds(), SkRect::Make(inset.bounds()), nullptr);
1771 canvas->drawBitmap(inset, canvasBounds.width() / 4, canvasBounds.height() / 4);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001772##
1773
Cary Clark682c58d2018-05-16 07:07:07 -04001774#SeeAlso Make makeAlphaType makeColorSpace makeColorType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001775
1776#Method ##
1777
1778# ------------------------------------------------------------------------------
1779
1780#Method SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const
Cary Clark78de7512018-02-07 07:27:09 -05001781#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001782#Line # creates Image_Info with changed Alpha_Type ##
Cary Clark681287e2018-03-16 11:34:15 -04001783Creates Image_Info with same Color_Type, Color_Space, width, and height,
Cary Clark682c58d2018-05-16 07:07:07 -04001784with Alpha_Type set to newAlphaType.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001785
Cary Clark681287e2018-03-16 11:34:15 -04001786Created Image_Info contains newAlphaType even if it is incompatible with
1787Color_Type, in which case Alpha_Type in Image_Info is ignored.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001788
Cary Clark681287e2018-03-16 11:34:15 -04001789#Param newAlphaType one of: #list_of_alpha_types#
Cary Clark2dc84ad2018-01-26 12:56:22 -05001790##
1791
Cary Clark681287e2018-03-16 11:34:15 -04001792#Return created Image_Info ##
1793
1794#Example
1795#Image 3
1796 const int width = 256;
1797 const int height = 128;
1798 SkColor pixels[height][width];
1799 for (int y = 0; y < height; ++y) {
1800 for (int x = 0; x < width; ++x) {
Cary Clark682c58d2018-05-16 07:07:07 -04001801 int red = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 4 + y) * 0.03f)));
1802 int blue = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 3 + y) * 0.04f)));
Cary Clark681287e2018-03-16 11:34:15 -04001803 int green = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 2 + y) * 0.05f)));
1804 int alpha = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 1 + y) * 0.006f)));
Cary Clark682c58d2018-05-16 07:07:07 -04001805 pixels[y][x] =
Cary Clark681287e2018-03-16 11:34:15 -04001806 SkColorSetARGB(alpha, red * alpha / 255, green * alpha / 255, blue * alpha / 255);
1807 }
1808 }
1809 SkBitmap bitmap;
1810 SkImageInfo info = SkImageInfo::Make(width, height, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
1811 bitmap.installPixels(info, (void*) pixels, sizeof(SkColor) * width);
1812 canvas->drawBitmap(source, 0, 0);
1813 canvas->drawBitmap(bitmap, 0, 0);
1814 SkImageInfo unpremulInfo = info.makeAlphaType(kUnpremul_SkAlphaType);
1815 bitmap.installPixels(unpremulInfo, (void*) pixels, sizeof(SkColor) * width);
1816 canvas->drawBitmap(bitmap, 0, 128);
1817##
1818
1819#SeeAlso Make MakeA8 makeColorType makeColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001820
1821#Method ##
1822
1823# ------------------------------------------------------------------------------
1824
1825#Method SkImageInfo makeColorType(SkColorType newColorType) const
Cary Clark78de7512018-02-07 07:27:09 -05001826#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001827#Line # creates Image_Info with changed Color_Type ##
Cary Clark681287e2018-03-16 11:34:15 -04001828Creates Image_Info with same Alpha_Type, Color_Space, width, and height,
1829with Color_Type set to newColorType.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001830
Cary Clark681287e2018-03-16 11:34:15 -04001831#Param newColorType one of: #list_of_color_types#
Cary Clark2dc84ad2018-01-26 12:56:22 -05001832##
1833
Cary Clark681287e2018-03-16 11:34:15 -04001834#Return created Image_Info ##
1835
1836#Example
1837 const int width = 256;
1838 const int height = 128;
1839 SkColor pixels[height][width];
1840 for (int y = 0; y < height; ++y) {
1841 for (int x = 0; x < width; ++x) {
Cary Clark682c58d2018-05-16 07:07:07 -04001842 int red = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 4 + y) * 0.03f)));
1843 int blue = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 3 + y) * 0.04f)));
Cary Clark681287e2018-03-16 11:34:15 -04001844 int green = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 2 + y) * 0.05f)));
1845 int alpha = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 1 + y) * 0.006f)));
Cary Clark682c58d2018-05-16 07:07:07 -04001846 pixels[y][x] =
Cary Clark681287e2018-03-16 11:34:15 -04001847 SkColorSetARGB(alpha, red * alpha / 255, green * alpha / 255, blue * alpha / 255);
1848 }
1849 }
1850 SkBitmap bitmap;
1851 SkImageInfo info = SkImageInfo::Make(width, height, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
1852 bitmap.installPixels(info, (void*) pixels, sizeof(SkColor) * width);
1853 canvas->drawBitmap(source, 0, 0);
1854 canvas->drawBitmap(bitmap, 0, 0);
1855 SkImageInfo rgbaInfo = info.makeColorType(kRGBA_8888_SkColorType);
1856 bitmap.installPixels(rgbaInfo, (void*) pixels, sizeof(SkColor) * width);
1857 canvas->drawBitmap(bitmap, 0, 128);
1858##
1859
1860#SeeAlso Make makeAlphaType makeColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001861
1862#Method ##
1863
1864# ------------------------------------------------------------------------------
1865
1866#Method SkImageInfo makeColorSpace(sk_sp<SkColorSpace> cs) const
Cary Clark78de7512018-02-07 07:27:09 -05001867#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001868#Line # creates Image_Info with changed Color_Space ##
Cary Clark681287e2018-03-16 11:34:15 -04001869Creates Image_Info with same Alpha_Type, Color_Type, width, and height,
1870with Color_Space set to cs.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001871
Cary Clark681287e2018-03-16 11:34:15 -04001872#Param cs range of colors; may be nullptr ##
1873
1874#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001875
1876#Example
Cary Clark681287e2018-03-16 11:34:15 -04001877#Height 224
1878 const int width = 256;
1879 const int height = 64;
1880 auto drawLabel = [=](const char* what, bool closeToSRGB) -> void {
1881 SkString string;
1882 string.printf("%s gamma is %s" "close to sRGB", what, closeToSRGB ? "" : "not ");
1883 SkPaint paint;
1884 paint.setAntiAlias(true);
1885 paint.setTextAlign(SkPaint::kCenter_Align);
1886 canvas->drawString(string, width / 2, 56, paint);
1887 };
1888 SkColor gradColors[] = { 0xFFFF7F00, 0xFF00FF7F, 0xFF0000FF, 0xFF7F7FFF };
1889 SkPoint gradPoints[] = { { 0, 0 }, { width, 0 }, { width * 2, 0 }, { width * 3, 0 } };
1890 SkPaint gradPaint;
1891 gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1892 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1893 canvas->drawRect(SkRect::MakeWH(width, height), gradPaint);
1894 drawLabel("canvas", canvas->imageInfo().gammaCloseToSRGB());
1895 SkBitmap bitmap;
1896 SkImageInfo offscreenInfo = SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType);
1897 bitmap.allocPixels(offscreenInfo);
1898 SkCanvas sRGBOffscreen(bitmap);
1899 sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1900 canvas->translate(0, 80);
1901 canvas->drawBitmap(bitmap, 0, 0);
1902 drawLabel("offscreen", offscreenInfo.gammaCloseToSRGB());
1903 SkImageInfo linearGamma =
1904 offscreenInfo.makeColorSpace(offscreenInfo.colorSpace()->makeLinearGamma());
1905 bitmap.allocPixels(linearGamma);
1906 SkCanvas lgOffscreen(bitmap);
1907 lgOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1908 canvas->translate(0, 80);
1909 canvas->drawBitmap(bitmap, 0, 0);
1910 drawLabel("linear", linearGamma.gammaCloseToSRGB());
Cary Clark2dc84ad2018-01-26 12:56:22 -05001911##
1912
Cary Clark681287e2018-03-16 11:34:15 -04001913#SeeAlso Make MakeS32 makeAlphaType makeColorType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001914
1915#Method ##
1916
1917# ------------------------------------------------------------------------------
1918
1919#Method int bytesPerPixel() const
Cary Clark78de7512018-02-07 07:27:09 -05001920#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001921#Line # returns number of bytes in pixel based on Color_Type ##
1922Returns number of bytes per pixel required by Color_Type.
1923Returns zero if colorType( is kUnknown_SkColorType.
1924
1925#Return bytes in pixel ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001926
1927#Example
Cary Clark681287e2018-03-16 11:34:15 -04001928 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
1929 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
1930 for (SkColorType colorType : { #list_of_color_types#
1931 } ) {
1932 SkImageInfo info = SkImageInfo::Make(1, 1, colorType, kOpaque_SkAlphaType);
1933 SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d\n",
1934 colors[colorType], 13 - strlen(colors[colorType]), " ",
1935 info.bytesPerPixel());
1936 }
1937#StdOut
1938color: kUnknown_SkColorType bytesPerPixel: 0
1939color: kAlpha_8_SkColorType bytesPerPixel: 1
1940color: kRGB_565_SkColorType bytesPerPixel: 2
1941color: kARGB_4444_SkColorType bytesPerPixel: 2
1942color: kRGBA_8888_SkColorType bytesPerPixel: 4
1943color: kRGB_888x_SkColorType bytesPerPixel: 4
1944color: kBGRA_8888_SkColorType bytesPerPixel: 4
1945color: kRGBA_1010102_SkColorType bytesPerPixel: 4
1946color: kRGB_101010x_SkColorType bytesPerPixel: 4
1947color: kGray_8_SkColorType bytesPerPixel: 1
1948color: kRGBA_F16_SkColorType bytesPerPixel: 8
1949##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001950##
1951
Cary Clark681287e2018-03-16 11:34:15 -04001952#SeeAlso width shiftPerPixel SkBitmap::bytesPerPixel
Cary Clark2dc84ad2018-01-26 12:56:22 -05001953
1954#Method ##
1955
1956# ------------------------------------------------------------------------------
1957
1958#Method int shiftPerPixel() const
Cary Clark78de7512018-02-07 07:27:09 -05001959#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001960#Line # returns bit shift from pixels to bytes ##
1961Returns bit shift converting row bytes to row pixels.
1962Returns zero for kUnknown_SkColorType.
1963
1964#Return one of: 0, 1, 2, 3; left shift to convert pixels to bytes ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001965
1966#Example
Cary Clark681287e2018-03-16 11:34:15 -04001967 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
1968 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
1969 for (SkColorType colorType : { #list_of_color_types#
1970 } ) {
1971 SkImageInfo info = SkImageInfo::Make(1, 1, colorType, kOpaque_SkAlphaType);
1972 SkDebugf("color: k" "%s" "_SkColorType" "%*s" "shiftPerPixel: %d\n",
1973 colors[colorType], 14 - strlen(colors[colorType]), " ",
1974 info.shiftPerPixel());
1975 }
1976#StdOut
1977color: kUnknown_SkColorType shiftPerPixel: 0
1978color: kAlpha_8_SkColorType shiftPerPixel: 0
1979color: kRGB_565_SkColorType shiftPerPixel: 1
1980color: kARGB_4444_SkColorType shiftPerPixel: 1
1981color: kRGBA_8888_SkColorType shiftPerPixel: 2
1982color: kRGB_888x_SkColorType shiftPerPixel: 2
1983color: kBGRA_8888_SkColorType shiftPerPixel: 2
1984color: kRGBA_1010102_SkColorType shiftPerPixel: 2
1985color: kRGB_101010x_SkColorType shiftPerPixel: 2
1986color: kGray_8_SkColorType shiftPerPixel: 0
1987color: kRGBA_F16_SkColorType shiftPerPixel: 3
1988##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001989##
1990
Cary Clark06c20f32018-03-20 15:53:27 -04001991#SeeAlso bytesPerPixel minRowBytes SkBitmap::shiftPerPixel SkPixmap::shiftPerPixel
Cary Clark2dc84ad2018-01-26 12:56:22 -05001992
1993#Method ##
1994
1995# ------------------------------------------------------------------------------
1996
1997#Method uint64_t minRowBytes64() const
Cary Clark78de7512018-02-07 07:27:09 -05001998#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001999#Line # returns width() times bytesPerPixel in 64 bits ##
2000
2001Returns minimum bytes per row, computed from pixel width() and Color_Type, which
Cary Clark682c58d2018-05-16 07:07:07 -04002002specifies bytesPerPixel(). Bitmap maximum value for row bytes must fit
2003in 31 bits.
Cary Clark681287e2018-03-16 11:34:15 -04002004
2005#Return width() times bytesPerPixel as unsigned 64-bit integer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002006
2007#Example
Cary Clark681287e2018-03-16 11:34:15 -04002008 for (int shift = 24; shift < 32; ++shift) {
2009 int width = 1 << shift;
Cary Clark682c58d2018-05-16 07:07:07 -04002010 SkImageInfo imageInfo =
Cary Clark681287e2018-03-16 11:34:15 -04002011 SkImageInfo::Make(width, 1, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
2012 uint64_t minRowBytes = imageInfo.minRowBytes64();
2013 bool widthTooLarge = (uint64_t) (int32_t) minRowBytes != minRowBytes;
2014 SkDebugf("RGBA_F16 width %d (0x%08x) %s\n",
Cary Clark682c58d2018-05-16 07:07:07 -04002015 width, width, widthTooLarge ? "too large" : "OK");
Cary Clark681287e2018-03-16 11:34:15 -04002016 }
2017#StdOut
2018RGBA_F16 width 16777216 (0x01000000) OK
2019RGBA_F16 width 33554432 (0x02000000) OK
2020RGBA_F16 width 67108864 (0x04000000) OK
2021RGBA_F16 width 134217728 (0x08000000) OK
2022RGBA_F16 width 268435456 (0x10000000) too large
2023RGBA_F16 width 536870912 (0x20000000) too large
2024RGBA_F16 width 1073741824 (0x40000000) too large
2025RGBA_F16 width -2147483648 (0x80000000) too large
2026##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002027##
2028
Cary Clark681287e2018-03-16 11:34:15 -04002029#SeeAlso minRowBytes computeByteSize computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002030
2031#Method ##
2032
2033# ------------------------------------------------------------------------------
2034
2035#Method size_t minRowBytes() const
Cary Clark78de7512018-02-07 07:27:09 -05002036#In Property
Cary Clark681287e2018-03-16 11:34:15 -04002037#Line # returns width() times bytesPerPixel in 32 bits ##
2038
2039Returns minimum bytes per row, computed from pixel width() and Color_Type, which
Cary Clark682c58d2018-05-16 07:07:07 -04002040specifies bytesPerPixel(). Bitmap maximum value for row bytes must fit
2041in 31 bits.
Cary Clark681287e2018-03-16 11:34:15 -04002042
2043#Return width() times bytesPerPixel as signed 32-bit integer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002044
2045#Example
Cary Clark681287e2018-03-16 11:34:15 -04002046 for (int shift = 24; shift < 32; ++shift) {
2047 int width = 1 << shift;
Cary Clark682c58d2018-05-16 07:07:07 -04002048 SkImageInfo imageInfo =
Cary Clark681287e2018-03-16 11:34:15 -04002049 SkImageInfo::Make(width, 1, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
2050 size_t minRowBytes = imageInfo.minRowBytes();
2051 bool widthTooLarge = !minRowBytes;
2052 SkDebugf("RGBA_F16 width %d (0x%08x) %s\n",
Cary Clark682c58d2018-05-16 07:07:07 -04002053 width, width, widthTooLarge ? "too large" : "OK");
Cary Clark681287e2018-03-16 11:34:15 -04002054 }
2055#StdOut
2056RGBA_F16 width 16777216 (0x01000000) OK
2057RGBA_F16 width 33554432 (0x02000000) OK
2058RGBA_F16 width 67108864 (0x04000000) OK
2059RGBA_F16 width 134217728 (0x08000000) OK
2060RGBA_F16 width 268435456 (0x10000000) too large
2061RGBA_F16 width 536870912 (0x20000000) too large
2062RGBA_F16 width 1073741824 (0x40000000) too large
2063RGBA_F16 width -2147483648 (0x80000000) too large
2064##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002065##
2066
Cary Clark681287e2018-03-16 11:34:15 -04002067#SeeAlso minRowBytes64 computeByteSize computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002068
2069#Method ##
2070
2071# ------------------------------------------------------------------------------
2072
2073#Method size_t computeOffset(int x, int y, size_t rowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05002074#In Utility
Cary Clark681287e2018-03-16 11:34:15 -04002075#Line # returns byte offset within pixel array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002076
Cary Clark681287e2018-03-16 11:34:15 -04002077Returns byte offset of pixel from pixel base address.
2078
2079Asserts in debug build if x or y is outside of bounds. Does not assert if
2080rowBytes is smaller than minRowBytes, even though result may be incorrect.
2081
2082#Param x column index, zero or greater, and less than width() ##
2083#Param y row index, zero or greater, and less than height() ##
2084#Param rowBytes size of pixel row or larger ##
2085
2086#Return offset within pixel array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002087
2088#Example
Cary Clark06c20f32018-03-20 15:53:27 -04002089#Height 128
Cary Clark681287e2018-03-16 11:34:15 -04002090 uint8_t pixels[][12] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00},
2091 { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00},
2092 { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00},
2093 { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF},
2094 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
2095 { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00},
2096 { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00},
2097 { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00} };
2098 SkImageInfo imageInfo = SkImageInfo::MakeA8(8, 8);
2099 SkBitmap bitmap;
2100 bitmap.installPixels(imageInfo, (void*) pixels, sizeof(pixels[0]));
2101 SkPaint paint;
2102 paint.setColor(SK_ColorRED);
2103 canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint);
2104 size_t offset = imageInfo.computeOffset(2, 3, sizeof(pixels[0]));
2105 pixels[0][offset] = 0x7F;
2106 offset = imageInfo.computeOffset(5, 3, sizeof(pixels[0]));
2107 pixels[0][offset] = 0x7F;
2108 bitmap.installPixels(imageInfo, (void*) pixels, sizeof(pixels[0]));
2109 canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(128, 128), &paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05002110##
2111
Cary Clark06c20f32018-03-20 15:53:27 -04002112#SeeAlso height width minRowBytes computeByteSize
Cary Clark2dc84ad2018-01-26 12:56:22 -05002113
2114#Method ##
2115
2116# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05002117#Subtopic Operator
2118#Populate
2119##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002120
2121#Method bool operator==(const SkImageInfo& other)_const
Cary Clark06c20f32018-03-20 15:53:27 -04002122#Line # compares Image_Info for equality ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002123
Cary Clark06c20f32018-03-20 15:53:27 -04002124Compares Image_Info with other, and returns true if width, height, Color_Type,
2125Alpha_Type, and Color_Space are equivalent.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002126
Cary Clark06c20f32018-03-20 15:53:27 -04002127#Param other Image_Info to compare ##
2128
2129#Return true if Image_Info equals other ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002130
2131#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002132 SkImageInfo info1 = SkImageInfo::Make(10, 20, kGray_8_SkColorType, kPremul_SkAlphaType);
2133 SkImageInfo info2 = SkImageInfo::Make(20, 10, kAlpha_8_SkColorType, kUnpremul_SkAlphaType);
2134 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
2135 info2 = info2.makeWH(10, 20);
2136 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
2137 info2 = info2.makeColorType(kGray_8_SkColorType);
2138 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
2139 info2 = info2.makeAlphaType(kPremul_SkAlphaType);
2140 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
2141#StdOut
2142info1 != info2
2143info1 != info2
2144info1 != info2
2145info1 == info2
2146##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002147##
2148
Cary Clark06c20f32018-03-20 15:53:27 -04002149#SeeAlso operator!=(const SkImageInfo& other)_const SkColorSpace::Equals
Cary Clark2dc84ad2018-01-26 12:56:22 -05002150
2151#Method ##
2152
2153# ------------------------------------------------------------------------------
2154
2155#Method bool operator!=(const SkImageInfo& other)_const
Cary Clark06c20f32018-03-20 15:53:27 -04002156#Line # compares Image_Info for inequality ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002157
Cary Clark06c20f32018-03-20 15:53:27 -04002158Compares Image_Info with other, and returns true if width, height, Color_Type,
Cary Clarkffb3d682018-05-17 12:17:28 -04002159Alpha_Type, and Color_Space are not equivalent.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002160
Cary Clark06c20f32018-03-20 15:53:27 -04002161#Param other Image_Info to compare ##
2162
2163#Return true if Image_Info is not equal to other ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002164
2165#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002166 SkImageInfo info1 = SkImageInfo::Make(10, 20, kGray_8_SkColorType, kPremul_SkAlphaType);
2167 SkImageInfo info2 = SkImageInfo::Make(20, 10, kAlpha_8_SkColorType, kUnpremul_SkAlphaType);
2168 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
2169 info2 = info2.makeWH(10, 20);
2170 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
2171 info2 = info2.makeColorType(kGray_8_SkColorType);
2172 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
2173 info2 = info2.makeAlphaType(kPremul_SkAlphaType);
2174 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
2175#StdOut
2176info1 != info2
2177info1 != info2
2178info1 != info2
2179info1 == info2
2180##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002181##
2182
Cary Clark06c20f32018-03-20 15:53:27 -04002183#SeeAlso operator==(const SkImageInfo& other)_const SkColorSpace::Equals
Cary Clark2dc84ad2018-01-26 12:56:22 -05002184
2185#Method ##
2186
2187# ------------------------------------------------------------------------------
2188
2189#Method size_t computeByteSize(size_t rowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05002190#In Utility
Cary Clark682c58d2018-05-16 07:07:07 -04002191#Line # returns memory required by pixel buffer with given row bytes ##
Cary Clark06c20f32018-03-20 15:53:27 -04002192Returns storage required by pixel array, given Image_Info dimensions, Color_Type,
2193and rowBytes. rowBytes is assumed to be at least as large as minRowBytes().
Cary Clark2dc84ad2018-01-26 12:56:22 -05002194
Cary Clark06c20f32018-03-20 15:53:27 -04002195Returns zero if height is zero.
2196Returns SK_MaxSizeT if answer exceeds the range of size_t.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002197
Cary Clark06c20f32018-03-20 15:53:27 -04002198#Param rowBytes size of pixel row or larger ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002199
Cary Clark06c20f32018-03-20 15:53:27 -04002200#Return memory required by pixel buffer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002201
2202#Example
Cary Clark06c20f32018-03-20 15:53:27 -04002203#Height 130
Cary Clark682c58d2018-05-16 07:07:07 -04002204 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2);
2205 const size_t size = info.computeByteSize(100000);
2206 SkAutoTMalloc<SkPMColor> storage(size);
2207 SkPMColor* pixels = storage.get();
2208 SkBitmap bitmap;
2209 bitmap.setInfo(info);
2210 bitmap.setPixels(pixels);
2211 bitmap.eraseColor(SK_ColorRED);
2212 canvas->scale(50, 50);
2213 canvas->rotate(8);
Cary Clark06c20f32018-03-20 15:53:27 -04002214 canvas->drawBitmap(bitmap, 2, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05002215##
2216
Cary Clark06c20f32018-03-20 15:53:27 -04002217#SeeAlso computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002218
2219#Method ##
2220
2221# ------------------------------------------------------------------------------
2222
2223#Method size_t computeMinByteSize() const
Cary Clark78de7512018-02-07 07:27:09 -05002224#In Utility
Cary Clark682c58d2018-05-16 07:07:07 -04002225#Line # returns least memory required by pixel buffer ##
2226Returns storage required by pixel array, given Image_Info dimensions, and
Cary Clark06c20f32018-03-20 15:53:27 -04002227Color_Type. Uses minRowBytes() to compute bytes for pixel row.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002228
Cary Clark06c20f32018-03-20 15:53:27 -04002229Returns zero if height is zero.
2230Returns SK_MaxSizeT if answer exceeds the range of size_t.
2231
2232#Return least memory required by pixel buffer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002233
2234#Example
Cary Clark06c20f32018-03-20 15:53:27 -04002235#Height 130
Cary Clark682c58d2018-05-16 07:07:07 -04002236 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2);
2237 const size_t size = info.computeMinByteSize();
2238 SkAutoTMalloc<SkPMColor> storage(size);
2239 SkPMColor* pixels = storage.get();
2240 SkBitmap bitmap;
2241 bitmap.setInfo(info);
2242 bitmap.setPixels(pixels);
2243 bitmap.eraseColor(SK_ColorRED);
2244 canvas->scale(50, 50);
2245 canvas->rotate(8);
Cary Clark06c20f32018-03-20 15:53:27 -04002246 canvas->drawBitmap(bitmap, 2, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05002247##
2248
Cary Clark06c20f32018-03-20 15:53:27 -04002249#SeeAlso computeByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002250
2251#Method ##
2252
2253# ------------------------------------------------------------------------------
2254
2255#Method static bool ByteSizeOverflowed(size_t byteSize)
Cary Clark78de7512018-02-07 07:27:09 -05002256#In Utility
Cary Clark06c20f32018-03-20 15:53:27 -04002257#Line # checks result of computeByteSize and computeMinByteSize ##
2258Returns true if byteSize equals SK_MaxSizeT. computeByteSize and
2259computeMinByteSize return SK_MaxSizeT if size_t can not hold buffer size.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002260
Cary Clark06c20f32018-03-20 15:53:27 -04002261#Param byteSize result of computeByteSize or computeMinByteSize ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002262
Cary Clark06c20f32018-03-20 15:53:27 -04002263#Return true if computeByteSize or computeMinByteSize result exceeds size_t ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002264
2265#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002266 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 1000000000);
2267 for (size_t rowBytes = 100000000; rowBytes < 10000000000000LL; rowBytes *= 10) {
2268 const size_t size = info.computeByteSize(rowBytes);
2269 SkDebugf("rowBytes:%llu size:%llu overflowed:%s\n", rowBytes, size,
2270 SkImageInfo::ByteSizeOverflowed(size) ? "true" : "false");
2271 }
2272#StdOut
2273rowBytes:100000000 size:99999999900000008 overflowed:false
2274rowBytes:1000000000 size:999999999000000008 overflowed:false
2275rowBytes:10000000000 size:9999999990000000008 overflowed:false
2276rowBytes:100000000000 size:18446744073709551615 overflowed:true
2277rowBytes:1000000000000 size:18446744073709551615 overflowed:true
2278##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002279##
2280
Cary Clark06c20f32018-03-20 15:53:27 -04002281#SeeAlso computeByteSize computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002282
2283#Method ##
2284
2285# ------------------------------------------------------------------------------
2286
2287#Method bool validRowBytes(size_t rowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05002288#In Utility
Cary Clark06c20f32018-03-20 15:53:27 -04002289#Line # checks if row bytes is large enough to contain pixel row ##
2290Returns true if rowBytes is smaller than width times pixel size.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002291
Cary Clark06c20f32018-03-20 15:53:27 -04002292#Param rowBytes size of pixel row or larger ##
2293
2294#Return true if rowBytes is large enough to contain pixel row ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002295
2296#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002297 SkImageInfo info = SkImageInfo::MakeN32Premul(16, 8);
2298 for (size_t rowBytes = 60; rowBytes < 72; rowBytes += sizeof(SkPMColor)) {
2299 SkDebugf("validRowBytes(%llu): %s\n", rowBytes, info.validRowBytes(rowBytes) ?
2300 "true" : "false");
2301 }
2302#StdOut
2303validRowBytes(60): false
2304validRowBytes(64): true
2305validRowBytes(68): true
2306##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002307##
2308
Cary Clark06c20f32018-03-20 15:53:27 -04002309#SeeAlso ByteSizeOverflowed computeByteSize computeMinByteSize
Cary Clark2dc84ad2018-01-26 12:56:22 -05002310
2311#Method ##
2312
2313# ------------------------------------------------------------------------------
2314
2315#Method void reset()
Cary Clark78de7512018-02-07 07:27:09 -05002316#In Constructor
Cary Clark06c20f32018-03-20 15:53:27 -04002317#Line # sets zero dimensions, kUnknown_SkColorType, kUnknown_SkAlphaType ##
2318Creates an empty Image_Info with kUnknown_SkColorType, kUnknown_SkAlphaType,
2319a width and height of zero, and no Color_Space.
2320
Cary Clark2dc84ad2018-01-26 12:56:22 -05002321#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002322 SkImageInfo info = SkImageInfo::MakeN32Premul(16, 8);
2323 SkImageInfo copy = info;
2324 SkDebugf("info %c= copy\n", info == copy ? '=' : '!');
2325 copy.reset();
2326 SkDebugf("info %c= reset copy\n", info == copy ? '=' : '!');
2327 SkDebugf("SkImageInfo() %c= reset copy\n", SkImageInfo() == copy ? '=' : '!');
2328#StdOut
2329info == copy
2330info != reset copy
2331SkImageInfo() == reset copy
2332##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002333##
2334
Cary Clark06c20f32018-03-20 15:53:27 -04002335#SeeAlso SkImageInfo()
Cary Clark2dc84ad2018-01-26 12:56:22 -05002336
2337#Method ##
2338
2339# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05002340#Subtopic Utility
2341#Populate
2342#Line # rarely called management functions ##
2343##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002344
2345#Method void validate() const
Cary Clark78de7512018-02-07 07:27:09 -05002346#In Utility
Cary Clark06c20f32018-03-20 15:53:27 -04002347#Line # asserts if Image_Info is invalid (debug only) ##
Cary Clark682c58d2018-05-16 07:07:07 -04002348Asserts if internal values are illegal or inconsistent. Only available if
Cary Clark06c20f32018-03-20 15:53:27 -04002349SK_DEBUG is defined at compile time.
2350
2351#NoExample
Cary Clark2dc84ad2018-01-26 12:56:22 -05002352##
2353
Cary Clark06c20f32018-03-20 15:53:27 -04002354#SeeAlso validRowBytes SkBitmap::validate
Cary Clark2dc84ad2018-01-26 12:56:22 -05002355
2356#Method ##
2357
2358#Struct SkImageInfo ##
2359
Cary Clark08895c42018-02-01 09:37:32 -05002360#Topic Image_Info ##