blob: 460d9e6f99723d7d41cb8399dca902e5562ff088 [file] [log] [blame]
Cary Clark2dc84ad2018-01-26 12:56:22 -05001#Topic Image_Info
Cary Clark137b8742018-05-30 09:21:49 -04002#Alias Image_Info_Reference ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05003
Cary Clark61313f32018-10-08 14:57:48 -04004#Code
5#Populate
6##
7
Cary Clarkf895a422018-02-27 09:54:21 -05008Image_Info specifies the dimensions and encoding of the pixels in a Bitmap.
9The dimensions are integral width and height. The encoding is how pixel
10bits describe Color_Alpha, transparency; Color components red, blue,
11and green; and Color_Space, the range and linearity of colors.
12
13Image_Info describes an uncompressed raster pixels. In contrast, Image
14additionally describes compressed pixels like PNG, and Surface describes
15destinations on the GPU. Image and Surface may be specified by Image_Info,
16but Image and Surface may not contain Image_Info.
17
Cary Clark2dc84ad2018-01-26 12:56:22 -050018# ------------------------------------------------------------------------------
Cary Clark08895c42018-02-01 09:37:32 -050019#Subtopic Alpha_Type
Cary Clarkf895a422018-02-27 09:54:21 -050020#Line # encoding for pixel transparency ##
Cary Clark137b8742018-05-30 09:21:49 -040021#Alias Alpha_Type ##
22#Alias Alpha_Types ##
Cary Clarkf895a422018-02-27 09:54:21 -050023
Cary Clark681287e2018-03-16 11:34:15 -040024#PhraseDef list_of_alpha_types
25kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
26kUnpremul_SkAlphaType
27##
28
Cary Clark2dc84ad2018-01-26 12:56:22 -050029#Enum SkAlphaType
Cary Clarkf895a422018-02-27 09:54:21 -050030#Line # encoding for pixel transparency ##
Cary Clark2dc84ad2018-01-26 12:56:22 -050031
32#Code
Cary Clark61313f32018-10-08 14:57:48 -040033#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -050034##
35
Cary Clarkf895a422018-02-27 09:54:21 -050036Describes how to interpret the alpha component of a pixel. A pixel may
37be opaque, or Color_Alpha, describing multiple levels of transparency.
38
39In simple blending, Color_Alpha weights the draw color and the destination
Cary Clark61313f32018-10-08 14:57:48 -040040color to create a new color. If alpha describes a weight from zero to one,
41new color is set to: #Formula # draw color * alpha + destination color * (1 - alpha) ##.
Cary Clarkf895a422018-02-27 09:54:21 -050042
43In practice alpha is encoded in two or more bits, where 1.0 equals all bits set.
44
Cary Clarkffb3d682018-05-17 12:17:28 -040045RGB may have Color_Alpha included in each component value; the stored
46value is the original RGB multiplied by Color_Alpha. Premultiplied color
Cary Clarkf895a422018-02-27 09:54:21 -050047components improve performance.
Cary Clark2dc84ad2018-01-26 12:56:22 -050048
49#Const kUnknown_SkAlphaType 0
Cary Clark682c58d2018-05-16 07:07:07 -040050#Line # uninitialized ##
51 Alpha_Type is uninitialized.
Cary Clark2dc84ad2018-01-26 12:56:22 -050052##
53#Const kOpaque_SkAlphaType 1
Cary Clark682c58d2018-05-16 07:07:07 -040054#Line # pixel is opaque ##
55#Details Opaque
56 Pixels are opaque. The Color_Type must have no explicit alpha
57 component, or all alpha components must be set to their maximum value.
Cary Clark2dc84ad2018-01-26 12:56:22 -050058##
59#Const kPremul_SkAlphaType 2
Cary Clark682c58d2018-05-16 07:07:07 -040060#Line # pixel components are Premultiplied by Alpha ##
61#Details Premul
62 Pixels have Alpha Premultiplied into color components.
63 Surface pixels must be Premultiplied.
Cary Clark2dc84ad2018-01-26 12:56:22 -050064##
65#Const kUnpremul_SkAlphaType 3
Cary Clark682c58d2018-05-16 07:07:07 -040066#Line # pixel components are independent of Alpha ##
67#Details Unpremul
68 Pixel color component values are independent of alpha value.
69 Images generated from encoded data like PNG do not Premultiply pixel color
70 components. kUnpremul_SkAlphaType is supported for Image pixels, but not for
71 Surface pixels.
72##
73#Const kLastEnum_SkAlphaType 3
74#Line # last valid value ##
75 Used by tests to iterate through all valid values.
Cary Clark2dc84ad2018-01-26 12:56:22 -050076##
77
Cary Clarkf895a422018-02-27 09:54:21 -050078#NoExample
Cary Clark2dc84ad2018-01-26 12:56:22 -050079##
80
Cary Clarkf895a422018-02-27 09:54:21 -050081#SeeAlso SkColorType SkColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -050082
83#Enum SkAlphaType ##
Cary Clarkf895a422018-02-27 09:54:21 -050084
85#Subtopic Opaque
Cary Clark682c58d2018-05-16 07:07:07 -040086#Line # hints all pixels are opaque ##
87Use kOpaque_SkAlphaType as a hint to optimize drawing when Alpha component
Cary Clarkf895a422018-02-27 09:54:21 -050088of all pixel is set to its maximum value of 1.0; all alpha component bits are set.
Cary Clark682c58d2018-05-16 07:07:07 -040089If Image_Info is set to kOpaque_SkAlphaType but all alpha values are not 1.0,
90results are undefined.
Cary Clarkf895a422018-02-27 09:54:21 -050091
92#Example
93#Height 64
94#Description
95SkPreMultiplyARGB parameter a is set to 255, its maximum value, and is interpreted
96as Color_Alpha of 1.0. kOpaque_SkAlphaType may be set to improve performance.
Cary Clark682c58d2018-05-16 07:07:07 -040097If SkPreMultiplyARGB parameter a is set to a value smaller than 255,
Cary Clarkf895a422018-02-27 09:54:21 -050098kPremul_SkAlphaType must be used instead to avoid undefined results.
99The four displayed values are the original component values, though not necessarily
100in the same order.
101##
102 SkPMColor color = SkPreMultiplyARGB(255, 50, 100, 150);
103 SkString s;
104 s.printf("%u %u %u %u", SkColorGetA(color), SkColorGetR(color),
105 SkColorGetG(color), SkColorGetB(color));
106 SkPaint paint;
107 paint.setAntiAlias(true);
108 canvas->drawString(s, 10, 62, paint);
109 canvas->scale(50, 50);
110 SkBitmap bitmap;
111 SkImageInfo imageInfo = SkImageInfo::Make(1, 1, kN32_SkColorType, kOpaque_SkAlphaType);
112 if (bitmap.installPixels(imageInfo, (void*) &color, imageInfo.minRowBytes())) {
113 canvas->drawBitmap(bitmap, 0, 0);
114 }
115##
116
117#Subtopic Opaque ##
118
119#Subtopic Premul
Cary Clark682c58d2018-05-16 07:07:07 -0400120#Line # stores components scaled by Alpha ##
121Use kPremul_SkAlphaType when stored color components are the original color
122multiplied by the alpha component. The alpha component range of 0.0 to 1.0 is
123achieved by dividing the integer bit value by the maximum bit value.
Cary Clarkf895a422018-02-27 09:54:21 -0500124
Cary Clark682c58d2018-05-16 07:07:07 -0400125#Code
Cary Clarkf895a422018-02-27 09:54:21 -0500126stored color = original color * alpha / max alpha
127##
128
129The color component must be equal to or smaller than the alpha component,
130or the results are undefined.
131
132#Example
133#Description
134SkPreMultiplyARGB parameter a is set to 150, less than its maximum value, and is
135interpreted as Color_Alpha of about 0.6. kPremul_SkAlphaType must be set, since
Cary Clark682c58d2018-05-16 07:07:07 -0400136SkPreMultiplyARGB parameter a is set to a value smaller than 255,
Cary Clarkf895a422018-02-27 09:54:21 -0500137to avoid undefined results.
138The four displayed values reflect that the alpha component has been multiplied
139by the original color.
140##
141#Height 64
142 SkPMColor color = SkPreMultiplyARGB(150, 50, 100, 150);
143 SkString s;
144 s.printf("%u %u %u %u", SkColorGetA(color), SkColorGetR(color),
145 SkColorGetG(color), SkColorGetB(color));
146 SkPaint paint;
147 paint.setAntiAlias(true);
148 canvas->drawString(s, 10, 62, paint);
149 canvas->scale(50, 50);
150 SkBitmap bitmap;
151 SkImageInfo imageInfo = SkImageInfo::Make(1, 1, kN32_SkColorType, kPremul_SkAlphaType);
152 if (bitmap.installPixels(imageInfo, (void*) &color, imageInfo.minRowBytes())) {
153 canvas->drawBitmap(bitmap, 0, 0);
154 }
155##
156
157#Subtopic Premul ##
158
159#Subtopic Unpremul
Cary Clark682c58d2018-05-16 07:07:07 -0400160#Line # stores components without Alpha scaling ##
161Use kUnpremul_SkAlphaType if stored color components are not divided by the
162alpha component. Some drawing destinations may not support
163kUnpremul_SkAlphaType.
Cary Clarkf895a422018-02-27 09:54:21 -0500164
165#Bug 7079
166#Example
Cary Clark681287e2018-03-16 11:34:15 -0400167#Height 64
Cary Clarkf895a422018-02-27 09:54:21 -0500168#Description
169SkColorSetARGB parameter a is set to 150, less than its maximum value, and is
Cary Clark682c58d2018-05-16 07:07:07 -0400170interpreted as Color_Alpha of about 0.6. color is not Premultiplied;
Cary Clarkf895a422018-02-27 09:54:21 -0500171color components may have values greater than color alpha.
172The four displayed values are the original component values, though not necessarily
173in the same order.
174##
175 SkColor color = SkColorSetARGB(150, 50, 100, 255);
176 SkString s;
177 s.printf("%u %u %u %u", SkColorGetA(color), SkColorGetR(color),
178 SkColorGetG(color), SkColorGetB(color));
179 SkPaint paint;
180 paint.setAntiAlias(true);
181 canvas->drawString(s, 10, 62, paint);
182 canvas->scale(50, 50);
183 SkBitmap bitmap;
184 SkImageInfo imageInfo = SkImageInfo::Make(1, 1, kN32_SkColorType, kUnpremul_SkAlphaType);
185 if (bitmap.installPixels(imageInfo, (void*) &color, imageInfo.minRowBytes())) {
186 canvas->drawBitmap(bitmap, 0, 0);
187 }
188##
189
190#Subtopic Unpremul ##
191
Cary Clark06c20f32018-03-20 15:53:27 -0400192#Method static inline bool SkAlphaTypeIsOpaque(SkAlphaType at)
193#In Property
194#Line # returns if Alpha_Type equals kOpaque_SkAlphaType ##
195
Cary Clarka4f581a2018-04-03 15:31:59 -0400196Returns true if Alpha_Type equals kOpaque_SkAlphaType. kOpaque_SkAlphaType is a
197hint that the Color_Type is opaque, or that all Color_Alpha values are set to
198their 1.0 equivalent. If Alpha_Type is kOpaque_SkAlphaType, and Color_Type is not
199opaque, then the result of drawing any pixel with a Color_Alpha value less than
2001.0 is undefined.
201
Cary Clark06c20f32018-03-20 15:53:27 -0400202#Param at one of: #list_of_alpha_types#
203##
204#Return true if at equals kOpaque_SkAlphaType ##
205#NoExample
206##
207##
208
Cary Clark08895c42018-02-01 09:37:32 -0500209#Subtopic Alpha_Type ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500210
211# ------------------------------------------------------------------------------
Cary Clark08895c42018-02-01 09:37:32 -0500212#Subtopic Color_Type
Cary Clarkf895a422018-02-27 09:54:21 -0500213#Line # encoding for pixel color ##
Cary Clark137b8742018-05-30 09:21:49 -0400214#Alias Color_Type ##
215#Alias Color_Types ##
Cary Clark2a8c48b2018-02-15 17:31:24 -0500216
Cary Clark1a8d7622018-03-05 13:26:16 -0500217#PhraseDef list_of_color_types
218kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType,
219kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType,
220kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType,
221kGray_8_SkColorType, kRGBA_F16_SkColorType
222##
223
Cary Clark2dc84ad2018-01-26 12:56:22 -0500224#Enum SkColorType
Cary Clarkf895a422018-02-27 09:54:21 -0500225#Line # encoding for pixel color ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500226
227#Code
Cary Clark61313f32018-10-08 14:57:48 -0400228#Populate
229##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500230
Cary Clarkf895a422018-02-27 09:54:21 -0500231Describes how pixel bits encode color. A pixel may be an alpha mask, a
Cary Clark137b8742018-05-30 09:21:49 -0400232Grayscale, RGB, or ARGB.
Cary Clark4855f782018-02-06 09:41:53 -0500233
Cary Clarkffb3d682018-05-17 12:17:28 -0400234kN32_SkColorType selects the native 32-bit ARGB format. On Little_Endian
235processors, pixels containing 8-bit ARGB components pack into 32-bit
Cary Clark4855f782018-02-06 09:41:53 -0500236kBGRA_8888_SkColorType. On Big_Endian processors, pixels pack into 32-bit
237kRGBA_8888_SkColorType.
Cary Clark2dc84ad2018-01-26 12:56:22 -0500238
239#Const kUnknown_SkColorType 0
Cary Clark682c58d2018-05-16 07:07:07 -0400240#Line # uninitialized ##
241 Color_Type is set to kUnknown_SkColorType by default. If set,
242 encoding format and size is unknown.
Cary Clarkab2621d2018-01-30 10:08:57 -0500243##
Cary Clarkf895a422018-02-27 09:54:21 -0500244
Cary Clark682c58d2018-05-16 07:07:07 -0400245#Const kAlpha_8_SkColorType 1
246#Line # pixel with Alpha in 8-bit byte ##
247#Details Alpha_8
248 Stores 8-bit byte pixel encoding that represents transparency. Value of zero
249 is completely transparent; a value of 255 is completely opaque.
250##
251
252#Const kRGB_565_SkColorType 2
253#Line # pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word ##
254#Details RGB_565
255 Stores 16-bit word pixel encoding that contains five bits of blue,
256 six bits of green, and five bits of red.
257##
258
259#Const kARGB_4444_SkColorType 3
260#Line # pixel with 4 bits for alpha, red, green, blue; in 16-bit word ##
261#Details ARGB_4444
262 Stores 16-bit word pixel encoding that contains four bits of alpha,
263 four bits of blue, four bits of green, and four bits of red.
264##
265
266#Const kRGBA_8888_SkColorType 4
267#Line # pixel with 8 bits for red, green, blue, alpha; in 32-bit word ##
268#Details RGBA_8888
269 Stores 32-bit word pixel encoding that contains eight bits of red,
270 eight bits of green, eight bits of blue, and eight bits of alpha.
271##
272
273#Const kRGB_888x_SkColorType 5
274#Line # pixel with 8 bits each for red, green, blue; in 32-bit word ##
275#Details RGB_888
276 Stores 32-bit word pixel encoding that contains eight bits of red,
277 eight bits of green, eight bits of blue, and eight unused bits.
278##
279
280#Const kBGRA_8888_SkColorType 6
281#Line # pixel with 8 bits for blue, green, red, alpha; in 32-bit word ##
282#Details BGRA_8888
283 Stores 32-bit word pixel encoding that contains eight bits of blue,
284 eight bits of green, eight bits of red, and eight bits of alpha.
285##
286
287#Const kRGBA_1010102_SkColorType 7
288#Line # 10 bits for red, green, blue; 2 bits for alpha; in 32-bit word ##
289#Details RGBA_1010102
290 Stores 32-bit word pixel encoding that contains ten bits of red,
291 ten bits of green, ten bits of blue, and two bits of alpha.
292##
293
294#Const kRGB_101010x_SkColorType 8
295#Line # pixel with 10 bits each for red, green, blue; in 32-bit word ##
296#Details RGB_101010
297 Stores 32-bit word pixel encoding that contains ten bits of red,
298 ten bits of green, ten bits of blue, and two unused bits.
299##
300
301#Const kGray_8_SkColorType 9
Cary Clark137b8742018-05-30 09:21:49 -0400302#Line # pixel with Grayscale level in 8-bit byte ##
Cary Clark682c58d2018-05-16 07:07:07 -0400303#Details Gray_8
304 Stores 8-bit byte pixel encoding that equivalent to equal values for red,
305 blue, and green, representing colors from black to white.
306##
307
308#Const kRGBA_F16_SkColorType 10
309#Line # pixel with half floats for red, green, blue, alpha; in 64-bit word ##
310#Details RGBA_F16
311 Stores 64-bit word pixel encoding that contains 16 bits of blue,
Cary Clark224c7002018-06-27 11:00:21 -0400312 16 bits of green, 16 bits of red, and 16 bits of alpha. Each component
313 is encoded as a half float.
Cary Clark682c58d2018-05-16 07:07:07 -0400314##
315
Cary Clark224c7002018-06-27 11:00:21 -0400316#Const kRGBA_F32_SkColorType 11
317#Line # pixel using C float for red, green, blue, alpha; in 128-bit word ##
318#Details RGBA_F32
319 Stores 128-bit word pixel encoding that contains 32 bits of blue,
320 32 bits of green, 32 bits of red, and 32 bits of alpha. Each component
321 is encoded as a single precision float.
322##
323
324#Const kLastEnum_SkColorType 11
Cary Clark682c58d2018-05-16 07:07:07 -0400325#NoJustify
326#Line # last valid value ##
327 Used by tests to iterate through all valid values.
328##
329
330#Const kN32_SkColorType 4 or 6
Cary Clark137b8742018-05-30 09:21:49 -0400331#Alias Native_Color_Type ##
Cary Clark682c58d2018-05-16 07:07:07 -0400332#NoJustify
Cary Clarkffb3d682018-05-17 12:17:28 -0400333#Line # native ARGB 32-bit encoding ##
334 Encodes ARGB as either kRGBA_8888_SkColorType or
Cary Clark682c58d2018-05-16 07:07:07 -0400335 kBGRA_8888_SkColorType, whichever is native to the platform.
Cary Clarkf895a422018-02-27 09:54:21 -0500336##
337
338#NoExample
339##
340
341#SeeAlso SkAlphaType SkColorSpace
342
343#Enum SkColorType ##
344
345#Subtopic Alpha_8
Cary Clark682c58d2018-05-16 07:07:07 -0400346#Line # encodes transparency only ##
347 Alpha pixels encode transparency without color information. Value of zero is
348 completely transparent; a value of 255 is completely opaque. Bitmap
349 pixels do not visibly draw, because its pixels have no color information.
350 When SkColorType is set to kAlpha_8_SkColorType, the paired SkAlphaType is
351 ignored.
Cary Clarkf895a422018-02-27 09:54:21 -0500352
Cary Clark682c58d2018-05-16 07:07:07 -0400353 #Example
354 #Description
355 Alpha pixels can modify another draw. orangePaint fills the bounds of bitmap,
356 with its transparency set to alpha8 pixel value.
357 ##
358 #Height 64
359 canvas->scale(16, 16);
360 SkBitmap bitmap;
361 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kAlpha_8_SkColorType, kOpaque_SkAlphaType);
362 bitmap.allocPixels(imageInfo);
363 SkCanvas offscreen(bitmap);
364 offscreen.clear(SK_ColorGREEN);
365 SkPaint orangePaint;
366 orangePaint.setARGB(0xFF, 0xFF, 0xA5, 0x00);
367 canvas->drawBitmap(bitmap, 0, 0, &orangePaint);
368 uint8_t alpha8[] = { 0xFF, 0xBB, 0x77, 0x33 };
369 SkPixmap alphaPixmap(imageInfo, &alpha8, imageInfo.minRowBytes());
370 if (bitmap.writePixels(alphaPixmap, 0, 0)) {
371 canvas->drawBitmap(bitmap, 2, 2, &orangePaint);
372 }
373 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400374 #SeeAlso Alpha Gray_8
Cary Clarkf895a422018-02-27 09:54:21 -0500375##
376
Cary Clark682c58d2018-05-16 07:07:07 -0400377#Subtopic RGB_565
Cary Clarkffb3d682018-05-17 12:17:28 -0400378#Line # encodes RGB in 16 bits ##
379 kRGB_565_SkColorType encodes RGB to fit in a 16-bit word. Red and blue
Cary Clark682c58d2018-05-16 07:07:07 -0400380 components use five bits describing 32 levels. Green components, more sensitive
381 to the eye, use six bits describing 64 levels. kRGB_565_SkColorType has no
382 bits for Alpha.
383
384 Pixels are fully opaque as if its Color_Alpha was set to one, and should
385 always be paired with kOpaque_SkAlphaType.
Cary Clarkf895a422018-02-27 09:54:21 -0500386
Cary Clark682c58d2018-05-16 07:07:07 -0400387 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500388
Cary Clark682c58d2018-05-16 07:07:07 -0400389 #Example
390 #Height 96
391 canvas->scale(16, 16);
392 SkBitmap bitmap;
393 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGB_565_SkColorType, kOpaque_SkAlphaType);
394 bitmap.allocPixels(imageInfo);
395 SkCanvas offscreen(bitmap);
396 offscreen.clear(SK_ColorGREEN);
397 canvas->drawBitmap(bitmap, 0, 0);
398 auto pack565 = [](unsigned r, unsigned g, unsigned b) -> uint16_t {
399 return (b << 0) | (g << 5) | (r << 11);
400 };
401 uint16_t red565[] = { pack565(0x1F, 0x00, 0x00), pack565(0x17, 0x00, 0x00),
402 pack565(0x0F, 0x00, 0x00), pack565(0x07, 0x00, 0x00) };
403 uint16_t blue565[] = { pack565(0x00, 0x00, 0x1F), pack565(0x00, 0x00, 0x17),
404 pack565(0x00, 0x00, 0x0F), pack565(0x00, 0x00, 0x07) };
405 SkPixmap redPixmap(imageInfo, &red565, imageInfo.minRowBytes());
406 if (bitmap.writePixels(redPixmap, 0, 0)) {
407 canvas->drawBitmap(bitmap, 2, 2);
408 }
409 SkPixmap bluePixmap(imageInfo, &blue565, imageInfo.minRowBytes());
410 if (bitmap.writePixels(bluePixmap, 0, 0)) {
411 canvas->drawBitmap(bitmap, 4, 4);
412 }
413 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400414 #SeeAlso ARGB_4444 RGBA_8888
Cary Clarkf895a422018-02-27 09:54:21 -0500415##
416
Cary Clark682c58d2018-05-16 07:07:07 -0400417#Subtopic ARGB_4444
Cary Clarkffb3d682018-05-17 12:17:28 -0400418#Line # encodes ARGB in 16 bits ##
419 kARGB_4444_SkColorType encodes ARGB to fit in 16-bit word. Each
Cary Clark682c58d2018-05-16 07:07:07 -0400420 component: alpha, blue, green, and red; use four bits, describing 16 levels.
421 Note that kARGB_4444_SkColorType is misnamed; the acronym does not
422 describe the actual component order.
Cary Clarkf895a422018-02-27 09:54:21 -0500423
Cary Clark682c58d2018-05-16 07:07:07 -0400424 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500425
Cary Clark682c58d2018-05-16 07:07:07 -0400426 If paired with kPremul_SkAlphaType: blue, green, and red components are
427 Premultiplied by the alpha value. If blue, green, or red is greater than alpha,
428 the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500429
Cary Clark682c58d2018-05-16 07:07:07 -0400430 If paired with kUnpremul_SkAlphaType: alpha, blue, green, and red components
431 may have any value. There may be a performance penalty with Unpremultipled
432 pixels.
Cary Clarkf895a422018-02-27 09:54:21 -0500433
Cary Clark682c58d2018-05-16 07:07:07 -0400434 If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum;
435 blue, green, and red components are fully opaque. If any alpha component is
436 less than 15, the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500437
Cary Clark682c58d2018-05-16 07:07:07 -0400438 #Bug 7648
Cary Clarkf895a422018-02-27 09:54:21 -0500439
Cary Clark682c58d2018-05-16 07:07:07 -0400440 #Example
441 #Height 96
442 canvas->scale(16, 16);
443 SkBitmap bitmap;
444 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, kPremul_SkAlphaType);
445 bitmap.allocPixels(imageInfo);
446 SkCanvas offscreen(bitmap);
447 offscreen.clear(SK_ColorGREEN);
448 canvas->drawBitmap(bitmap, 0, 0);
449 auto pack4444 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint16_t {
450 return (a << 0) | (b << 4) | (g << 8) | (r << 12);
451 };
452 uint16_t red4444[] = { pack4444(0xF, 0xF, 0x0, 0x0), pack4444(0xF, 0xb, 0x0, 0x0),
453 pack4444(0xF, 0x7, 0x0, 0x0), pack4444(0xF, 0x3, 0x0, 0x0) };
454 uint16_t blue4444[] = { pack4444(0xF, 0x0, 0x0, 0xF), pack4444(0xF, 0x0, 0x0, 0xb),
455 pack4444(0xF, 0x0, 0x0, 0x7), pack4444(0xF, 0x0, 0x0, 0x3) };
456 SkPixmap redPixmap(imageInfo, &red4444, imageInfo.minRowBytes());
457 if (bitmap.writePixels(redPixmap, 0, 0)) {
458 canvas->drawBitmap(bitmap, 2, 2);
459 }
460 SkPixmap bluePixmap(imageInfo, &blue4444, imageInfo.minRowBytes());
461 if (bitmap.writePixels(bluePixmap, 0, 0)) {
462 canvas->drawBitmap(bitmap, 4, 4);
463 }
464 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400465 #SeeAlso RGBA_8888
Cary Clarkf895a422018-02-27 09:54:21 -0500466##
467
468#Subtopic RGBA_8888
Cary Clarkffb3d682018-05-17 12:17:28 -0400469#Line # encodes ARGB Big_Endian in 32 bits ##
470 kRGBA_8888_SkColorType encodes ARGB into a 32-bit word. Each component:
Cary Clark682c58d2018-05-16 07:07:07 -0400471 red, green, blue, alpha; use eight bits, describing 256 levels.
Cary Clarkf895a422018-02-27 09:54:21 -0500472
Cary Clark682c58d2018-05-16 07:07:07 -0400473 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500474
Cary Clark682c58d2018-05-16 07:07:07 -0400475 If paired with kPremul_SkAlphaType: red, green, and blue components are
476 Premultiplied by the alpha value. If red, green, or blue is greater than alpha,
477 the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500478
Cary Clark682c58d2018-05-16 07:07:07 -0400479 If paired with kUnpremul_SkAlphaType: alpha, red, green, and blue components
480 may have any value. There may be a performance penalty with Unpremultipled
481 pixels.
Cary Clarkf895a422018-02-27 09:54:21 -0500482
Cary Clark682c58d2018-05-16 07:07:07 -0400483 If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum;
484 red, green, and blue components are fully opaque. If any alpha component is
485 less than 255, the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500486
Cary Clark682c58d2018-05-16 07:07:07 -0400487 On Big_Endian platforms, kRGBA_8888_SkColorType is the native Color_Type, and
488 will have the best performance. Use kN32_SkColorType to choose the best
489 Color_Type for the platform at compile time.
Cary Clarkf895a422018-02-27 09:54:21 -0500490
Cary Clark682c58d2018-05-16 07:07:07 -0400491 #Example
492 #Height 96
493 canvas->scale(16, 16);
494 SkBitmap bitmap;
495 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
496 bitmap.allocPixels(imageInfo);
497 SkCanvas offscreen(bitmap);
498 offscreen.clear(SK_ColorGREEN);
499 canvas->drawBitmap(bitmap, 0, 0);
500 auto pack8888 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint32_t {
501 return (r << 0) | (g << 8) | (b << 16) | (a << 24);
502 };
503 uint32_t red8888[] = { pack8888(0xFF, 0xFF, 0x0, 0x0), pack8888(0xFF, 0xbb, 0x0, 0x0),
504 pack8888(0xFF, 0x77, 0x0, 0x0), pack8888(0xFF, 0x33, 0x0, 0x0) };
505 uint32_t blue8888[] = { pack8888(0xFF, 0x0, 0x0, 0x0FF), pack8888(0xFF, 0x0, 0x0, 0x0bb),
506 pack8888(0xFF, 0x0, 0x0, 0x077), pack8888(0xFF, 0x0, 0x0, 0x033) };
507 SkPixmap redPixmap(imageInfo, &red8888, imageInfo.minRowBytes());
508 if (bitmap.writePixels(redPixmap, 0, 0)) {
509 canvas->drawBitmap(bitmap, 2, 2);
510 }
511 SkPixmap bluePixmap(imageInfo, &blue8888, imageInfo.minRowBytes());
512 if (bitmap.writePixels(bluePixmap, 0, 0)) {
513 canvas->drawBitmap(bitmap, 4, 4);
514 }
515 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400516 #SeeAlso RGB_888 BGRA_8888
Cary Clarkf895a422018-02-27 09:54:21 -0500517##
518
Cary Clark682c58d2018-05-16 07:07:07 -0400519#Subtopic RGB_888
Cary Clarkffb3d682018-05-17 12:17:28 -0400520#Line # encodes RGB in 32 bits ##
521 kRGB_888x_SkColorType encodes RGB into a 32-bit word. Each component:
Cary Clark682c58d2018-05-16 07:07:07 -0400522 red, green, blue; use eight bits, describing 256 levels. Eight bits are
523 unused. Pixels described by kRGB_888x_SkColorType are fully opaque as if
524 their Color_Alpha was set to one, and should always be paired with
525 kOpaque_SkAlphaType.
Cary Clarkf895a422018-02-27 09:54:21 -0500526
Cary Clark682c58d2018-05-16 07:07:07 -0400527 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500528
Cary Clark682c58d2018-05-16 07:07:07 -0400529 #Example
530 #Bug 7645
531 #Height 96
532 #Platform cpu
533 canvas->scale(16, 16);
534 SkBitmap bitmap;
535 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGB_888x_SkColorType, kOpaque_SkAlphaType);
536 bitmap.allocPixels(imageInfo);
537 SkCanvas offscreen(bitmap);
538 offscreen.clear(SK_ColorGREEN);
539 canvas->drawBitmap(bitmap, 0, 0);
540 auto pack888 = [](unsigned r, unsigned g, unsigned b) -> uint32_t {
541 return (r << 0) | (g << 8) | (b << 16);
542 };
543 uint32_t red888[] = { pack888(0xFF, 0x00, 0x00), pack888(0xbb, 0x00, 0x00),
544 pack888(0x77, 0x00, 0x00), pack888(0x33, 0x00, 0x00) };
545 uint32_t blue888[] = { pack888(0x00, 0x00, 0xFF), pack888(0x00, 0x00, 0xbb),
546 pack888(0x00, 0x00, 0x77), pack888(0x00, 0x00, 0x33) };
547 if (bitmap.installPixels(imageInfo, (void*) red888, imageInfo.minRowBytes())) {
548 canvas->drawBitmap(bitmap, 2, 2);
549 }
550 if (bitmap.installPixels(imageInfo, (void*) blue888, imageInfo.minRowBytes())) {
551 canvas->drawBitmap(bitmap, 4, 4);
552 }
553 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400554 #SeeAlso RGBA_8888 BGRA_8888
Cary Clarkf895a422018-02-27 09:54:21 -0500555##
556
557#Subtopic BGRA_8888
Cary Clarkffb3d682018-05-17 12:17:28 -0400558#Line # encodes ARGB Little_Endian in 32 bits ##
559 kBGRA_8888_SkColorType encodes ARGB into a 32-bit word. Each component:
Cary Clark682c58d2018-05-16 07:07:07 -0400560 blue, green, red, and alpha; use eight bits, describing 256 levels.
Cary Clarkf895a422018-02-27 09:54:21 -0500561
Cary Clark682c58d2018-05-16 07:07:07 -0400562 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500563
Cary Clark682c58d2018-05-16 07:07:07 -0400564 If paired with kPremul_SkAlphaType: blue, green, and red components are
565 Premultiplied by the alpha value. If blue, green, or red is greater than alpha,
566 the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500567
Cary Clark682c58d2018-05-16 07:07:07 -0400568 If paired with kUnpremul_SkAlphaType: blue, green, red, and alpha components
569 may have any value. There may be a performance penalty with Unpremultiplied
570 pixels.
Cary Clarkf895a422018-02-27 09:54:21 -0500571
Cary Clark682c58d2018-05-16 07:07:07 -0400572 If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum;
573 blue, green, and red components are fully opaque. If any alpha component is
574 less than 255, the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500575
Cary Clark682c58d2018-05-16 07:07:07 -0400576 On Little_Endian platforms, kBGRA_8888_SkColorType is the native Color_Type,
577 and will have the best performance. Use kN32_SkColorType to choose the best
578 Color_Type for the platform at compile time.
Cary Clarkf895a422018-02-27 09:54:21 -0500579
Cary Clark682c58d2018-05-16 07:07:07 -0400580 #Example
581 #Height 96
582 canvas->scale(16, 16);
583 SkBitmap bitmap;
584 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
585 bitmap.allocPixels(imageInfo);
586 SkCanvas offscreen(bitmap);
587 offscreen.clear(SK_ColorGREEN);
588 canvas->drawBitmap(bitmap, 0, 0);
589 auto pack8888 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint32_t {
590 return (b << 0) | (g << 8) | (r << 16) | (a << 24);
591 };
592 uint32_t red8888[] = { pack8888(0xFF, 0xFF, 0x0, 0x0), pack8888(0xFF, 0xbb, 0x0, 0x0),
593 pack8888(0xFF, 0x99, 0x0, 0x0), pack8888(0xFF, 0x55, 0x0, 0x0) };
594 uint32_t blue8888[] = { pack8888(0xFF, 0x0, 0x0, 0x0FF), pack8888(0xFF, 0x0, 0x0, 0x0bb),
595 pack8888(0xFF, 0x0, 0x0, 0x099), pack8888(0xFF, 0x0, 0x0, 0x055) };
596 SkPixmap redPixmap(imageInfo, &red8888, imageInfo.minRowBytes());
597 if (bitmap.writePixels(redPixmap, 0, 0)) {
598 canvas->drawBitmap(bitmap, 2, 2);
599 }
600 SkPixmap bluePixmap(imageInfo, &blue8888, imageInfo.minRowBytes());
601 if (bitmap.writePixels(bluePixmap, 0, 0)) {
602 canvas->drawBitmap(bitmap, 4, 4);
603 }
604 ##
605 #SeeAlso RGBA_8888
Cary Clarkf895a422018-02-27 09:54:21 -0500606##
607
608#Subtopic RGBA_1010102
Cary Clarkffb3d682018-05-17 12:17:28 -0400609#Line # encodes ARGB ten bits per color component ##
610 kRGBA_1010102_SkColorType encodes ARGB into a 32-bit word. Each
Cary Clark682c58d2018-05-16 07:07:07 -0400611 Color component: red, green, and blue; use ten bits, describing 1024 levels.
612 Two bits contain alpha, describing four levels. Possible alpha
613 values are zero: fully transparent; one: 33% opaque; two: 67% opaque;
614 three: fully opaque.
Cary Clarkf895a422018-02-27 09:54:21 -0500615
Cary Clark682c58d2018-05-16 07:07:07 -0400616 At present, Color in Paint does not provide enough precision to
617 draw all colors possible to a kRGBA_1010102_SkColorType Surface.
Cary Clarkf895a422018-02-27 09:54:21 -0500618
Cary Clark682c58d2018-05-16 07:07:07 -0400619 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500620
Cary Clark682c58d2018-05-16 07:07:07 -0400621 If paired with kPremul_SkAlphaType: red, green, and blue components are
622 Premultiplied by the alpha value. If red, green, or blue is greater than the
623 alpha replicated to ten bits, the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500624
Cary Clark682c58d2018-05-16 07:07:07 -0400625 If paired with kUnpremul_SkAlphaType: alpha, red, green, and blue components
626 may have any value. There may be a performance penalty with Unpremultiplied
627 pixels.
Cary Clarkf895a422018-02-27 09:54:21 -0500628
Cary Clark682c58d2018-05-16 07:07:07 -0400629 If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum;
630 red, green, and blue components are fully opaque. If any alpha component is
631 less than three, the drawn result is undefined.
Cary Clarkf895a422018-02-27 09:54:21 -0500632
Cary Clark682c58d2018-05-16 07:07:07 -0400633 #Example
634 #Bug 7645
635 #Height 96
636 #Platform cpu
637 canvas->scale(16, 16);
638 SkBitmap bitmap;
639 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGBA_1010102_SkColorType, kOpaque_SkAlphaType);
640 bitmap.allocPixels(imageInfo);
641 SkCanvas offscreen(bitmap);
642 offscreen.clear(SK_ColorGREEN);
643 canvas->drawBitmap(bitmap, 0, 0);
644 auto pack1010102 = [](unsigned r, unsigned g, unsigned b, unsigned a) -> uint32_t {
645 return (r << 0) | (g << 10) | (b << 20) | (a << 30);
646 };
647 uint32_t redBits[] = { pack1010102(0x3FF, 0x000, 0x000, 0x3),
648 pack1010102(0x2ff, 0x000, 0x000, 0x3),
649 pack1010102(0x1ff, 0x000, 0x000, 0x3),
650 pack1010102(0x0ff, 0x000, 0x000, 0x3) };
651 uint32_t blueBits[] = { pack1010102(0x000, 0x000, 0x3FF, 0x3),
652 pack1010102(0x000, 0x000, 0x2ff, 0x3),
653 pack1010102(0x000, 0x000, 0x1ff, 0x3),
654 pack1010102(0x000, 0x000, 0x0ff, 0x3) };
655 if (bitmap.installPixels(imageInfo, (void*) redBits, imageInfo.minRowBytes())) {
656 canvas->drawBitmap(bitmap, 2, 2);
657 }
658 SkPixmap bluePixmap(imageInfo, &blueBits, imageInfo.minRowBytes());
659 if (bitmap.installPixels(imageInfo, (void*) blueBits, imageInfo.minRowBytes())) {
660 canvas->drawBitmap(bitmap, 4, 4);
661 }
662 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400663 #SeeAlso RGB_101010 RGBA_8888
Cary Clarkf895a422018-02-27 09:54:21 -0500664##
665
Cary Clark682c58d2018-05-16 07:07:07 -0400666#Subtopic RGB_101010
Cary Clarkffb3d682018-05-17 12:17:28 -0400667#Line # encodes RGB ten bits per color component ##
668 kRGB_101010x_SkColorType encodes RGB into a 32-bit word. Each
Cary Clark682c58d2018-05-16 07:07:07 -0400669 Color component: red, green, and blue; use ten bits, describing 1024 levels.
670 Two bits are unused. Pixels described by kRGB_101010x_SkColorType are fully
671 opaque as if its Color_Alpha was set to one, and should always be paired
672 with kOpaque_SkAlphaType.
Cary Clarkf895a422018-02-27 09:54:21 -0500673
Cary Clark682c58d2018-05-16 07:07:07 -0400674 At present, Color in Paint does not provide enough precision to
675 draw all colors possible to a kRGB_101010x_SkColorType Surface.
Cary Clark681287e2018-03-16 11:34:15 -0400676
Cary Clark682c58d2018-05-16 07:07:07 -0400677 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500678
Cary Clark682c58d2018-05-16 07:07:07 -0400679 #Example
680 #Bug 7645
681 #Height 96
682 #Platform cpu
683 canvas->scale(16, 16);
684 SkBitmap bitmap;
685 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGB_101010x_SkColorType, kOpaque_SkAlphaType);
686 bitmap.allocPixels(imageInfo);
687 SkCanvas offscreen(bitmap);
688 offscreen.clear(SK_ColorGREEN);
689 canvas->drawBitmap(bitmap, 0, 0);
690 auto pack101010x = [](unsigned r, unsigned g, unsigned b) -> uint32_t {
691 return (r << 0) | (g << 10) | (b << 20);
692 };
693 uint32_t redBits[] = { pack101010x(0x3FF, 0x000, 0x000), pack101010x(0x2ff, 0x000, 0x000),
694 pack101010x(0x1ff, 0x000, 0x000), pack101010x(0x0ff, 0x000, 0x000) };
695 uint32_t blueBits[] = { pack101010x(0x000, 0x000, 0x3FF), pack101010x(0x000, 0x000, 0x2ff),
696 pack101010x(0x000, 0x000, 0x1ff), pack101010x(0x000, 0x000, 0x0ff) };
697 if (bitmap.installPixels(imageInfo, (void*) redBits, imageInfo.minRowBytes())) {
698 canvas->drawBitmap(bitmap, 2, 2);
699 }
700 SkPixmap bluePixmap(imageInfo, &blueBits, imageInfo.minRowBytes());
701 if (bitmap.installPixels(imageInfo, (void*) blueBits, imageInfo.minRowBytes())) {
702 canvas->drawBitmap(bitmap, 4, 4);
703 }
704 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400705 #SeeAlso RGBA_1010102
Cary Clarkf895a422018-02-27 09:54:21 -0500706##
707
708#Subtopic Gray_8
Cary Clark137b8742018-05-30 09:21:49 -0400709#Line # encodes level of Grayscale in 8 bits ##
710 kGray_8_SkColorType encodes Grayscale level in eight bits that is equivalent
Cary Clark682c58d2018-05-16 07:07:07 -0400711 to equal values for red, blue, and green, representing colors from black to
712 white. Pixels described by kGray_8_SkColorType are fully
713 opaque as if its Color_Alpha was set to one, and should always be paired with
714 kOpaque_SkAlphaType.
Cary Clarkf895a422018-02-27 09:54:21 -0500715
Cary Clark682c58d2018-05-16 07:07:07 -0400716 #Example
717 #Height 64
718 canvas->scale(16, 16);
719 SkBitmap bitmap;
720 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kGray_8_SkColorType, kOpaque_SkAlphaType);
721 bitmap.allocPixels(imageInfo);
722 SkCanvas offscreen(bitmap);
723 offscreen.clear(SK_ColorGREEN);
724 canvas->drawBitmap(bitmap, 0, 0);
725 uint8_t gray8[] = { 0xFF, 0xBB, 0x77, 0x33 };
726 SkPixmap grayPixmap(imageInfo, &gray8, imageInfo.minRowBytes());
727 if (bitmap.writePixels(grayPixmap, 0, 0)) {
728 canvas->drawBitmap(bitmap, 2, 2);
729 }
730 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400731 #SeeAlso Alpha_8
Cary Clarkf895a422018-02-27 09:54:21 -0500732##
733
734#Subtopic RGBA_F16
Cary Clarkffb3d682018-05-17 12:17:28 -0400735#Line # encodes ARGB as half floats ##
736 kRGBA_F16_SkColorType encodes ARGB into a 64-bit word. Each component:
Cary Clark224c7002018-06-27 11:00:21 -0400737 blue, green, red, and alpha; use 16 bits, describing a floating point value,
Cary Clark929e4362018-06-19 09:07:28 -0400738 from -65500 to 65000 with 3.31 decimal digits of precision.
Cary Clarkf895a422018-02-27 09:54:21 -0500739
Cary Clark682c58d2018-05-16 07:07:07 -0400740 At present, Color in Paint does not provide enough precision or range to
741 draw all colors possible to a kRGBA_F16_SkColorType Surface.
Cary Clark681287e2018-03-16 11:34:15 -0400742
Cary Clark682c58d2018-05-16 07:07:07 -0400743 Each component encodes a floating point value using
744 #A Half floats # https://www.khronos.org/opengl/wiki/Small_Float_Formats ##
745 . Meaningful colors are represented by the range 0.0 to 1.0, although smaller
746 and larger values may be useful when used in combination with Transfer_Mode.
Cary Clark681287e2018-03-16 11:34:15 -0400747
Cary Clark682c58d2018-05-16 07:07:07 -0400748 #Illustration
Cary Clarkf895a422018-02-27 09:54:21 -0500749
Cary Clark682c58d2018-05-16 07:07:07 -0400750 If paired with kPremul_SkAlphaType: blue, green, and red components are
751 Premultiplied by the alpha value. If blue, green, or red is greater than alpha,
752 the drawn result is undefined.
Cary Clark681287e2018-03-16 11:34:15 -0400753
Cary Clark682c58d2018-05-16 07:07:07 -0400754 If paired with kUnpremul_SkAlphaType: blue, green, red, and alpha components
755 may have any value. There may be a performance penalty with Unpremultiplied
756 pixels.
Cary Clark681287e2018-03-16 11:34:15 -0400757
Cary Clark682c58d2018-05-16 07:07:07 -0400758 If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum;
759 blue, green, and red components are fully opaque. If any alpha component is
Cary Clark224c7002018-06-27 11:00:21 -0400760 less than one, the drawn result is undefined.
Cary Clark681287e2018-03-16 11:34:15 -0400761
Cary Clark682c58d2018-05-16 07:07:07 -0400762 #ToDo
763 FloatToHalf should be replaced with SkFloatToHalf if/when that's made public
764 ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500765
Cary Clark682c58d2018-05-16 07:07:07 -0400766 #Example
767 #Height 96
768 #Function
769 union FloatUIntUnion {
770 uint32_t fUInt;
771 float fFloat;
Cary Clarkf895a422018-02-27 09:54:21 -0500772 };
Cary Clark682c58d2018-05-16 07:07:07 -0400773
774 uint16_t FloatToHalf(float f) {
775 static const FloatUIntUnion magic = { 15 << 23 };
776 static const uint32_t round_mask = ~0xfffu;
777 FloatUIntUnion floatUnion;
778 floatUnion.fFloat = f;
779 uint32_t sign = floatUnion.fUInt & 0x80000000u;
780 floatUnion.fUInt ^= sign;
781 floatUnion.fUInt &= round_mask;
782 floatUnion.fFloat *= magic.fFloat;
783 floatUnion.fUInt -= round_mask;
784 return (floatUnion.fUInt >> 13) | (sign >> 16);
Cary Clarkf895a422018-02-27 09:54:21 -0500785 }
Cary Clark682c58d2018-05-16 07:07:07 -0400786 ##
787
788 void draw(SkCanvas* canvas) {
789 canvas->scale(16, 16);
790 SkBitmap bitmap;
791 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
792 bitmap.allocPixels(imageInfo);
793 SkCanvas offscreen(bitmap);
794 offscreen.clear(SK_ColorGREEN);
795 canvas->drawBitmap(bitmap, 0, 0);
796 auto H = [](float c) -> uint16_t {
797 return FloatToHalf(c);
798 };
799 // R G B A
Cary Clark224c7002018-06-27 11:00:21 -0400800 uint16_t red_f16[][4] = { { H(1.0), H(0.0), H(0.0), H(1.0) },
801 { H(.75), H(0.0), H(0.0), H(1.0) },
802 { H(.50), H(0.0), H(0.0), H(1.0) },
803 { H(.25), H(0.0), H(0.0), H(1.0) } };
804 uint16_t blue_f16[][4] = { { H(0.0), H(0.0), H(1.0), H(1.0) },
805 { H(0.0), H(0.0), H(.75), H(1.0) },
806 { H(0.0), H(0.0), H(.50), H(1.0) },
807 { H(0.0), H(0.0), H(.25), H(1.0) } };
Cary Clark682c58d2018-05-16 07:07:07 -0400808 SkPixmap redPixmap(imageInfo, red_f16, imageInfo.minRowBytes());
809 if (bitmap.writePixels(redPixmap, 0, 0)) {
810 canvas->drawBitmap(bitmap, 2, 2);
811 }
812 SkPixmap bluePixmap(imageInfo, blue_f16, imageInfo.minRowBytes());
813 if (bitmap.writePixels(bluePixmap, 0, 0)) {
814 canvas->drawBitmap(bitmap, 4, 4);
815 }
Cary Clarkf895a422018-02-27 09:54:21 -0500816 }
Cary Clark682c58d2018-05-16 07:07:07 -0400817 ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400818 #SeeAlso SkColor4f
Cary Clarkf895a422018-02-27 09:54:21 -0500819##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500820
Cary Clark224c7002018-06-27 11:00:21 -0400821#Subtopic RGBA_F32
822#Line # encodes ARGB as single precision floats ##
823 kRGBA_F32_SkColorType encodes ARGB into a 128-bit word. Each component:
824 blue, green, red, and alpha; use 32 bits, describing a floating point value,
825 from -3.402823e+38 to 3.402823e+38 with 7.225 decimal digits of precision.
826
827 At present, Color in Paint does not provide enough precision or range to
828 draw all colors possible to a kRGBA_F32_SkColorType Surface.
829
830 Each component encodes a floating point value using
831 #A single-precision floats # https://en.wikipedia.org/wiki/Single-precision_floating-point_format ##
832 . Meaningful colors are represented by the range 0.0 to 1.0, although smaller
833 and larger values may be useful when used in combination with Transfer_Mode.
834
835 #Illustration
836
837 If paired with kPremul_SkAlphaType: blue, green, and red components are
838 Premultiplied by the alpha value. If blue, green, or red is greater than alpha,
839 the drawn result is undefined.
840
841 If paired with kUnpremul_SkAlphaType: blue, green, red, and alpha components
842 may have any value. There may be a performance penalty with Unpremultiplied
843 pixels.
844
845 If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum;
846 blue, green, and red components are fully opaque. If any alpha component is
847 less than one, the drawn result is undefined.
848
849 #NoExample
Cary Clark61313f32018-10-08 14:57:48 -0400850 canvas->scale(16, 16);
851 SkBitmap bitmap;
852 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGBA_F32_SkColorType, kPremul_SkAlphaType);
853 bitmap.allocPixels(imageInfo);
854 SkCanvas offscreen(bitmap);
855 offscreen.clear(SK_ColorGREEN);
856 canvas->drawBitmap(bitmap, 0, 0);
857 // R G B A
858 float red_f32[][4] = { { 1.0, 0.0, 0.0, 1.0 },
859 { .75, 0.0, 0.0, 1.0 },
860 { .50, 0.0, 0.0, 1.0 },
861 { .25, 0.0, 0.0, 1.0 } };
862 float blue_f32[][4] = { { 0.0, 0.0, 1.0, 1.0 },
863 { 0.0, 0.0, .75, 1.0 },
864 { 0.0, 0.0, .50, 1.0 },
865 { 0.0, 0.0, .25, 1.0 } };
866 SkPixmap redPixmap(imageInfo, red_f32, imageInfo.minRowBytes());
867 if (bitmap.writePixels(redPixmap, 0, 0)) {
868 canvas->drawBitmap(bitmap, 2, 2);
869 }
870 SkPixmap bluePixmap(imageInfo, blue_f32, imageInfo.minRowBytes());
871 if (bitmap.writePixels(bluePixmap, 0, 0)) {
872 canvas->drawBitmap(bitmap, 4, 4);
Cary Clark224c7002018-06-27 11:00:21 -0400873 }
874 ##
875 #SeeAlso SkColor4f
876##
877
878
Cary Clark08895c42018-02-01 09:37:32 -0500879#Subtopic Color_Type ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500880
881# ------------------------------------------------------------------------------
Cary Clark681287e2018-03-16 11:34:15 -0400882
883#Method int SkColorTypeBytesPerPixel(SkColorType ct)
884#In Property
885#Line # returns Color_Type byte size ##
886
887Returns the number of bytes required to store a pixel, including unused padding.
888Returns zero if ct is kUnknown_SkColorType or invalid.
889
890#Param ct one of: #list_of_color_types#
891##
892
893#Return bytes per pixel ##
894
895#Example
896#Height 192
897 const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
898 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" };
899 SkPaint paint;
900 paint.setTypeface(SkTypeface::MakeFromName("monospace", SkFontStyle()));
901 paint.setAntiAlias(true);
902 paint.setTextSize(10);
903 int y = 15;
904 canvas->drawString(" colorType bytes", 10, y, paint);
905 for (SkColorType colorType : { #list_of_color_types#
906 } ) {
907 int result = SkColorTypeBytesPerPixel(colorType);
908 SkString string;
909 string.printf("%13s %4d", colors[(int) colorType], result);
910 canvas->drawString(string, 10, y += 14, paint);
911 }
912##
913#SeeAlso SkImageInfo::bytesPerPixel
914##
915
916# ------------------------------------------------------------------------------
917
918#Method bool SkColorTypeIsAlwaysOpaque(SkColorType ct)
919#In Property
920#Line # returns if Color_Type includes Color_Alpha ##
921
922Returns true if Color_Type always decodes Color_Alpha to 1.0, making the pixel
923fully opaque. If true, Color_Type does not reserve bits to encode Color_Alpha.
924
925#Param ct one of: #list_of_color_types#
926##
927
928#Return true if Color_Alpha is always set to 1.0 ##
929
930#Example
931#Height 192
932 const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
933 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" };
934 SkPaint paint;
935 paint.setTypeface(SkTypeface::MakeFromName("monospace", SkFontStyle()));
936 paint.setAntiAlias(true);
937 paint.setTextSize(10);
938 int y = 15;
939 canvas->drawString(" colorType bytes", 10, y, paint);
940 for (SkColorType colorType : { #list_of_color_types#
941 } ) {
942 bool result = SkColorTypeIsAlwaysOpaque(colorType);
943 SkString string;
944 string.printf("%13s %6s", colors[(int) colorType], result ? "true" : "false");
945 canvas->drawString(string, 10, y += 14, paint);
946 }
947##
948#SeeAlso SkColorTypeValidateAlphaType
949##
950
951# ------------------------------------------------------------------------------
952
953#Method bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType,
954 SkAlphaType* canonical = nullptr)
955#In Property
956#Line # returns if Alpha_Type is valid ##
957
958Returns true if canonical can be set to a valid Alpha_Type for colorType. If
959there is more than one valid canonical Alpha_Type, set to alphaType, if valid.
960If true is returned and canonical is not nullptr, store valid Alpha_Type.
961
962Returns false only if alphaType is kUnknown_SkAlphaType, color type is not
963kUnknown_SkColorType, and Color_Type is not always opaque. If false is returned,
964canonical is ignored.
965
966For kUnknown_SkColorType: set canonical to kUnknown_SkAlphaType and return true.
Cary Clark682c58d2018-05-16 07:07:07 -0400967For kAlpha_8_SkColorType: set canonical to kPremul_SkAlphaType or
Cary Clark681287e2018-03-16 11:34:15 -0400968kOpaque_SkAlphaType and return true if alphaType is not kUnknown_SkAlphaType.
969For kRGB_565_SkColorType, kRGB_888x_SkColorType, kRGB_101010x_SkColorType, and
970kGray_8_SkColorType: set canonical to kOpaque_SkAlphaType and return true.
971For kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kBGRA_8888_SkColorType,
972kRGBA_1010102_SkColorType, and kRGBA_F16_SkColorType: set canonical to alphaType
973and return true if alphaType is not kUnknown_SkAlphaType.
974
975#Param colorType one of: #list_of_color_types#
976##
977#Param alphaType one of: #list_of_alpha_types#
978##
979#Param canonical storage for Alpha_Type ##
980
981#Return true if valid Alpha_Type can be associated with colorType ##
982
983#Example
984#Height 640
985 const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
986 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" };
987 const char* alphas[] = {"Unknown ", "Opaque ", "Premul ", "Unpremul"};
988 SkAlphaType alphaTypes[] = { #list_of_alpha_types#
989 };
990 SkPaint paint;
991 paint.setTypeface(SkTypeface::MakeFromName("monospace", SkFontStyle()));
992 paint.setAntiAlias(true);
993 paint.setTextSize(10);
994 int y = 15;
995 canvas->drawString(" colorType alphaType canonical", 10, y, paint);
996 for (SkColorType colorType : { #list_of_color_types#
997 } ) {
998 for (SkAlphaType alphaType : alphaTypes) {
999 SkAlphaType canonicalAlphaType = kUnknown_SkAlphaType;
1000 bool result = SkColorTypeValidateAlphaType(colorType, alphaType, &canonicalAlphaType);
1001 SkString string;
1002 string.printf("%13s %10s %10s", colors[(int) colorType], alphas[(int) alphaType],
1003 result ? alphas[(int) canonicalAlphaType] : "------ ");
1004 canvas->drawString(string, 10, y += 14, paint);
1005 }
1006 }
1007##
1008#SeeAlso SkColorTypeIsAlwaysOpaque
1009##
1010
1011# ------------------------------------------------------------------------------
Cary Clark772953472018-02-12 09:38:08 -05001012#Subtopic YUV_ColorSpace
Cary Clark682c58d2018-05-16 07:07:07 -04001013#Line # color range of YUV pixels ##
Cary Clark137b8742018-05-30 09:21:49 -04001014#Alias YUV_ColorSpace ##
1015
Cary Clark2dc84ad2018-01-26 12:56:22 -05001016#Enum SkYUVColorSpace
Cary Clark06c20f32018-03-20 15:53:27 -04001017#Line # color range of YUV pixels ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001018
1019#Code
Cary Clark61313f32018-10-08 14:57:48 -04001020#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001021##
1022
Cary Clark06c20f32018-03-20 15:53:27 -04001023Describes color range of YUV pixels. The color mapping from YUV to RGB varies
1024depending on the source. YUV pixels may be generated by JPEG images, standard
1025video streams, or high definition video streams. Each has its own mapping from
1026YUV and RGB.
1027
1028JPEG YUV values encode the full range of 0 to 255 for all three components.
1029Video YUV values range from 16 to 235 for all three components. Details of
Cary Clark682c58d2018-05-16 07:07:07 -04001030encoding and conversion to RGB are described in
Cary Clark06c20f32018-03-20 15:53:27 -04001031#A YCbCr color space # https://en.wikipedia.org/wiki/YCbCr ##
1032.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001033
1034#Const kJPEG_SkYUVColorSpace 0
Cary Clark682c58d2018-05-16 07:07:07 -04001035#Line # describes full range ##
1036Describes standard JPEG color space;
Cary Clark06c20f32018-03-20 15:53:27 -04001037#A CCIR 601 # https://en.wikipedia.org/wiki/Rec._601 ##
1038with full range of 0 to 255 for components.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001039##
1040#Const kRec601_SkYUVColorSpace 1
Cary Clark682c58d2018-05-16 07:07:07 -04001041#Line # describes SDTV range ##
1042Describes standard used by standard definition television;
Cary Clark06c20f32018-03-20 15:53:27 -04001043#A CCIR 601 # https://en.wikipedia.org/wiki/Rec._601 ##
1044with studio range of 16 to 235 range for components.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001045##
1046#Const kRec709_SkYUVColorSpace 2
Cary Clark682c58d2018-05-16 07:07:07 -04001047#Line # describes HDTV range ##
1048Describes standard used by high definition television;
1049#A Rec. 709 # https://en.wikipedia.org/wiki/Rec._709 ##
Cary Clark06c20f32018-03-20 15:53:27 -04001050with studio range of 16 to 235 range for components.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001051##
Cary Clark682c58d2018-05-16 07:07:07 -04001052#Const kLastEnum_SkYUVColorSpace 2
1053#Line # last valid value ##
1054 Used by tests to iterate through all valid values.
1055##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001056
Cary Clark06c20f32018-03-20 15:53:27 -04001057#NoExample
Cary Clark2dc84ad2018-01-26 12:56:22 -05001058##
1059
Cary Clark06c20f32018-03-20 15:53:27 -04001060#SeeAlso SkImage::MakeFromYUVTexturesCopy SkImage::MakeFromNV12TexturesCopy
Cary Clark2dc84ad2018-01-26 12:56:22 -05001061
1062#Enum SkYUVColorSpace ##
Cary Clark772953472018-02-12 09:38:08 -05001063#Subtopic YUV_ColorSpace ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001064
1065# ------------------------------------------------------------------------------
Cary Clark2dc84ad2018-01-26 12:56:22 -05001066
1067#Struct SkImageInfo
1068
Cary Clark61313f32018-10-08 14:57:48 -04001069#Code
1070#Populate
1071##
1072
Cary Clark682c58d2018-05-16 07:07:07 -04001073Describes pixel dimensions and encoding. Bitmap, Image, PixMap, and Surface
Cary Clark1a8d7622018-03-05 13:26:16 -05001074can be created from Image_Info. Image_Info can be retrieved from Bitmap and
1075Pixmap, but not from Image and Surface. For example, Image and Surface
1076implementations may defer pixel depth, so may not completely specify Image_Info.
1077
1078Image_Info contains dimensions, the pixel integral width and height. It encodes
1079how pixel bits describe Color_Alpha, transparency; Color components red, blue,
1080and green; and Color_Space, the range and linearity of colors.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001081
Cary Clark2dc84ad2018-01-26 12:56:22 -05001082# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05001083
Cary Clark2dc84ad2018-01-26 12:56:22 -05001084#Method SkImageInfo()
1085
Cary Clark61313f32018-10-08 14:57:48 -04001086#In Constructors
Cary Clark82f1f742018-06-28 08:50:35 -04001087#Line # creates with zeroed dimensions, kUnknown_SkColorType, kUnknown_SkAlphaType ##
Cary Clark06c20f32018-03-20 15:53:27 -04001088Creates an empty Image_Info with kUnknown_SkColorType, kUnknown_SkAlphaType,
Cary Clark1a8d7622018-03-05 13:26:16 -05001089a width and height of zero, and no Color_Space.
1090
1091#Return empty Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001092
1093#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001094#Height 32
1095#Description
1096An empty Image_Info may be passed to SkCanvas::accessTopLayerPixels as storage
1097for the Canvas actual Image_Info.
1098##
1099 SkImageInfo imageInfo;
1100 size_t rowBytes;
1101 SkIPoint origin;
Cary Clark681287e2018-03-16 11:34:15 -04001102 (void) canvas->accessTopLayerPixels(&imageInfo, &rowBytes, &origin);
Cary Clark1a8d7622018-03-05 13:26:16 -05001103 const char* alphaType[] = { "Unknown", "Opaque", "Premul", "Unpremul" };
1104 SkString string;
1105 string.printf("k%s_SkAlphaType", alphaType[(int) imageInfo.alphaType()]);
1106 SkPaint paint;
1107 canvas->drawString(string, 20, 20, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001108##
1109
Cary Clark1a8d7622018-03-05 13:26:16 -05001110#SeeAlso Make MakeN32 MakeS32 MakeA8
Cary Clark2dc84ad2018-01-26 12:56:22 -05001111
1112#Method ##
1113
1114# ------------------------------------------------------------------------------
1115
1116#Method static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at,
1117 sk_sp<SkColorSpace> cs = nullptr)
Cary Clark61313f32018-10-08 14:57:48 -04001118#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001119#Line # creates Image_Info from dimensions, Color_Type, Alpha_Type, Color_Space ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001120Creates Image_Info from integral dimensions width and height, Color_Type ct,
1121Alpha_Type at, and optionally Color_Space cs.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001122
Cary Clark1a8d7622018-03-05 13:26:16 -05001123If Color_Space cs is nullptr and Image_Info is part of drawing source: Color_Space
1124defaults to sRGB, mapping into Surface Color_Space.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001125
Cary Clark1a8d7622018-03-05 13:26:16 -05001126Parameters are not validated to see if their values are legal, or that the
1127combination is supported.
1128
1129#Param width pixel column count; must be zero or greater ##
1130#Param height pixel row count; must be zero or greater ##
1131#Param ct one of: #list_of_color_types#
1132##
Cary Clark681287e2018-03-16 11:34:15 -04001133#Param at one of: #list_of_alpha_types#
Cary Clark1a8d7622018-03-05 13:26:16 -05001134##
1135#Param cs range of colors; may be nullptr ##
1136
1137#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001138
1139#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001140#Height 48
1141 uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 },
1142 { 0xAC, 0xA8, 0x89, 0xA7, 0x87 },
1143 { 0x9B, 0xB5, 0xE5, 0x95, 0x46 },
1144 { 0x90, 0x81, 0xC5, 0x71, 0x33 },
1145 { 0x75, 0x55, 0x44, 0x40, 0x30 }};
1146 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType);
1147 SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
1148 SkBitmap bitmap;
1149 bitmap.installPixels(pixmap);
1150 canvas->scale(8, 8);
1151 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001152##
1153
Cary Clark1a8d7622018-03-05 13:26:16 -05001154#SeeAlso MakeN32 MakeN32Premul MakeS32 MakeA8
Cary Clark2dc84ad2018-01-26 12:56:22 -05001155
1156#Method ##
1157
1158# ------------------------------------------------------------------------------
1159
1160#Method static SkImageInfo MakeN32(int width, int height, SkAlphaType at,
1161 sk_sp<SkColorSpace> cs = nullptr)
Cary Clark61313f32018-10-08 14:57:48 -04001162#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001163#Line # creates Image_Info with Native_Color_Type ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001164Creates Image_Info from integral dimensions width and height, kN32_SkColorType,
1165Alpha_Type at, and optionally Color_Space cs. kN32_SkColorType will equal either
1166kBGRA_8888_SkColorType or kRGBA_8888_SkColorType, whichever is optimal.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001167
Cary Clark1a8d7622018-03-05 13:26:16 -05001168If Color_Space cs is nullptr and Image_Info is part of drawing source: Color_Space
1169defaults to sRGB, mapping into Surface Color_Space.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001170
Cary Clark1a8d7622018-03-05 13:26:16 -05001171Parameters are not validated to see if their values are legal, or that the
1172combination is supported.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001173
Cary Clark1a8d7622018-03-05 13:26:16 -05001174#Param width pixel column count; must be zero or greater ##
1175#Param height pixel row count; must be zero or greater ##
Cary Clark681287e2018-03-16 11:34:15 -04001176#Param at one of: #list_of_alpha_types#
Cary Clark1a8d7622018-03-05 13:26:16 -05001177##
1178#Param cs range of colors; may be nullptr ##
1179
1180#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001181
1182#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001183#Height 128
1184 SkBitmap bitmap;
1185 bitmap.allocPixels(SkImageInfo::MakeN32(16, 16, kPremul_SkAlphaType));
1186 SkCanvas offscreen(bitmap);
1187 offscreen.clear(SK_ColorWHITE);
1188 SkPaint paint;
1189 offscreen.drawString("g", 0, 10, paint);
1190 canvas->scale(8, 8);
1191 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001192##
1193
Cary Clark1a8d7622018-03-05 13:26:16 -05001194#SeeAlso Make MakeN32Premul MakeS32 MakeA8
Cary Clark2dc84ad2018-01-26 12:56:22 -05001195
1196#Method ##
1197
1198# ------------------------------------------------------------------------------
1199
1200#Method static SkImageInfo MakeS32(int width, int height, SkAlphaType at)
1201
Cary Clark61313f32018-10-08 14:57:48 -04001202#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001203#Line # creates Image_Info with Native_Color_Type, sRGB Color_Space ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001204Creates Image_Info from integral dimensions width and height, kN32_SkColorType,
1205Alpha_Type at, with sRGB Color_Space.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001206
Cary Clark1a8d7622018-03-05 13:26:16 -05001207Parameters are not validated to see if their values are legal, or that the
1208combination is supported.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001209
Cary Clark1a8d7622018-03-05 13:26:16 -05001210#Param width pixel column count; must be zero or greater ##
1211#Param height pixel row count; must be zero or greater ##
Cary Clark681287e2018-03-16 11:34:15 -04001212#Param at one of: #list_of_alpha_types#
Cary Clark2dc84ad2018-01-26 12:56:22 -05001213##
1214
Cary Clark1a8d7622018-03-05 13:26:16 -05001215#Return created Image_Info ##
1216
1217#Example
1218#Set sRGB
1219#Height 128
1220#Description
Cary Clark682c58d2018-05-16 07:07:07 -04001221Top gradient is drawn to offScreen without Color_Space. It is darker than middle
1222gradient, drawn to offScreen with sRGB Color_Space. Bottom gradient shares bits
Cary Clark1a8d7622018-03-05 13:26:16 -05001223with middle, but does not specify the Color_Space in noColorSpaceBitmap. A source
1224without Color_Space is treated as sRGB; the bottom gradient is identical to the
1225middle gradient.
1226##
1227 const int width = 256;
1228 const int height = 32;
1229 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
1230 SkColor gradColors[] = { 0xFFAA0055, 0xFF11CC88 };
1231 SkPoint gradPoints[] = { { 0, 0 }, { width, 0 } };
1232 SkPaint gradPaint;
1233 gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1234 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1235 SkBitmap bitmap;
1236 bitmap.allocPixels(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType));
Cary Clark682c58d2018-05-16 07:07:07 -04001237 SkCanvas offScreen(bitmap);
1238 offScreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
Cary Clark1a8d7622018-03-05 13:26:16 -05001239 canvas->drawBitmap(bitmap, 0, 0);
1240 bitmap.allocPixels(SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType));
1241 SkCanvas sRGBOffscreen(bitmap);
1242 sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1243 canvas->drawBitmap(bitmap, 0, 48);
1244 SkBitmap noColorSpaceBitmap;
1245 noColorSpaceBitmap.setInfo(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType));
1246 noColorSpaceBitmap.setPixels(bitmap.getAddr(0, 0));
1247 canvas->drawBitmap(noColorSpaceBitmap, 0, 96);
1248##
1249
1250#SeeAlso Make MakeN32 MakeN32Premul MakeA8
Cary Clark2dc84ad2018-01-26 12:56:22 -05001251
1252#Method ##
1253
1254# ------------------------------------------------------------------------------
1255
1256#Method static SkImageInfo MakeN32Premul(int width, int height, sk_sp<SkColorSpace> cs = nullptr)
1257
Cary Clark61313f32018-10-08 14:57:48 -04001258#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001259#Line # creates Image_Info with Native_Color_Type, kPremul_SkAlphaType ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001260Creates Image_Info from integral dimensions width and height, kN32_SkColorType,
1261kPremul_SkAlphaType, with optional Color_Space.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001262
Cary Clark1a8d7622018-03-05 13:26:16 -05001263If Color_Space cs is nullptr and Image_Info is part of drawing source: Color_Space
1264defaults to sRGB, mapping into Surface Color_Space.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001265
Cary Clark1a8d7622018-03-05 13:26:16 -05001266Parameters are not validated to see if their values are legal, or that the
1267combination is supported.
1268
1269#Param width pixel column count; must be zero or greater ##
1270#Param height pixel row count; must be zero or greater ##
1271#Param cs range of colors; may be nullptr ##
1272
1273#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001274
1275#Example
Cary Clark06c20f32018-03-20 15:53:27 -04001276#Height 128
Cary Clark1a8d7622018-03-05 13:26:16 -05001277 SkBitmap bitmap;
1278 bitmap.allocPixels(SkImageInfo::MakeN32Premul(18, 18));
1279 SkCanvas offscreen(bitmap);
1280 offscreen.clear(SK_ColorWHITE);
1281 SkPaint paint;
1282 paint.setAntiAlias(true);
1283 paint.setTextSize(15);
1284 offscreen.drawString("\xF0\x9F\x98\xB8", 1, 15, paint);
1285 canvas->scale(6, 6);
1286 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001287##
1288
Cary Clark1a8d7622018-03-05 13:26:16 -05001289#SeeAlso MakeN32 MakeS32 MakeA8 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001290
1291#Method ##
1292
1293# ------------------------------------------------------------------------------
1294
1295#Method static SkImageInfo MakeN32Premul(const SkISize& size)
1296
Cary Clark61313f32018-10-08 14:57:48 -04001297#In Constructors
Cary Clark1a8d7622018-03-05 13:26:16 -05001298Creates Image_Info from integral dimensions width and height, kN32_SkColorType,
1299kPremul_SkAlphaType, with Color_Space set to nullptr.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001300
Cary Clark1a8d7622018-03-05 13:26:16 -05001301If Image_Info is part of drawing source: Color_Space defaults to sRGB, mapping
1302into Surface Color_Space.
1303
1304Parameters are not validated to see if their values are legal, or that the
1305combination is supported.
1306
1307#Param size width and height, each must be zero or greater ##
1308
1309#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001310
1311#Example
Cary Clark06c20f32018-03-20 15:53:27 -04001312#Height 128
Cary Clark1a8d7622018-03-05 13:26:16 -05001313 SkBitmap bitmap;
1314 bitmap.allocPixels(SkImageInfo::MakeN32Premul({18, 18}));
1315 SkCanvas offscreen(bitmap);
1316 offscreen.clear(SK_ColorWHITE);
1317 SkPaint paint;
1318 paint.setAntiAlias(true);
1319 paint.setTextSize(15);
1320 offscreen.drawString("\xF0\x9F\x98\xB9", 1, 15, paint);
1321 canvas->scale(6, 6);
1322 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001323##
1324
Cary Clark682c58d2018-05-16 07:07:07 -04001325#SeeAlso MakeN32 MakeS32 MakeA8 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001326
1327#Method ##
1328
1329# ------------------------------------------------------------------------------
1330
1331#Method static SkImageInfo MakeA8(int width, int height)
1332
Cary Clark61313f32018-10-08 14:57:48 -04001333#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001334#Line # creates Image_Info with kAlpha_8_SkColorType, kPremul_SkAlphaType ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001335Creates Image_Info from integral dimensions width and height, kAlpha_8_SkColorType,
1336kPremul_SkAlphaType, with Color_Space set to nullptr.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001337
Cary Clark1a8d7622018-03-05 13:26:16 -05001338#Param width pixel column count; must be zero or greater ##
1339#Param height pixel row count; must be zero or greater ##
1340
1341#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001342
1343#Example
Cary Clark681287e2018-03-16 11:34:15 -04001344#Height 64
1345 uint8_t pixels[][8] = { { 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00},
1346 { 0x00, 0x7f, 0xff, 0x3f, 0x3f, 0x7f, 0x3f, 0x00},
1347 { 0x3f, 0xff, 0x7f, 0x00, 0x7f, 0xff, 0x7f, 0x00},
1348 { 0x00, 0x3f, 0x00, 0x00, 0x3f, 0x7f, 0x3f, 0x00},
1349 { 0x3f, 0x7f, 0x7f, 0x3f, 0x00, 0x00, 0x00, 0x00},
1350 { 0x7f, 0xff, 0xff, 0x7f, 0x00, 0x3f, 0x7f, 0x3f},
1351 { 0x7f, 0xff, 0xff, 0x7f, 0x00, 0x7f, 0xff, 0x7f},
1352 { 0x3f, 0x7f, 0x7f, 0x3f, 0x00, 0x3f, 0x7f, 0x3f} };
1353 SkBitmap bitmap;
1354 bitmap.installPixels(SkImageInfo::MakeA8(8, 8),
1355 (void*) pixels, sizeof(pixels[0]));
1356 SkPaint paint;
1357 canvas->scale(4, 4);
1358 for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) {
1359 paint.setColor(color);
1360 canvas->drawBitmap(bitmap, 0, 0, &paint);
1361 canvas->translate(12, 0);
1362 }
Cary Clark2dc84ad2018-01-26 12:56:22 -05001363##
1364
Cary Clark1a8d7622018-03-05 13:26:16 -05001365#SeeAlso MakeN32 MakeS32 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001366
1367#Method ##
1368
1369# ------------------------------------------------------------------------------
1370
1371#Method static SkImageInfo MakeUnknown(int width, int height)
1372
Cary Clark61313f32018-10-08 14:57:48 -04001373#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001374#Line # creates Image_Info with kUnknown_SkColorType, kUnknown_SkAlphaType ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001375Creates Image_Info from integral dimensions width and height, kUnknown_SkColorType,
1376kUnknown_SkAlphaType, with Color_Space set to nullptr.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001377
Cary Clark1a8d7622018-03-05 13:26:16 -05001378Returned Image_Info as part of source does not draw, and as part of destination
1379can not be drawn to.
1380
1381#Param width pixel column count; must be zero or greater ##
1382#Param height pixel row count; must be zero or greater ##
1383
1384#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001385
1386#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001387#Height 32
1388#Width 384
1389SkImageInfo info; // default constructor
1390SkString string;
1391string.printf("SkImageInfo() %c= SkImageInfo::MakeUnknown(0, 0)",
1392 info == SkImageInfo::MakeUnknown(0, 0) ? '=' : '!');
1393SkPaint paint;
1394canvas->drawString(string, 0, 12, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001395##
1396
Cary Clark1a8d7622018-03-05 13:26:16 -05001397#SeeAlso SkImageInfo() MakeN32 MakeS32 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001398
1399#Method ##
1400
1401# ------------------------------------------------------------------------------
1402
1403#Method static SkImageInfo MakeUnknown()
1404
Cary Clark61313f32018-10-08 14:57:48 -04001405#In Constructors
Cary Clark1a8d7622018-03-05 13:26:16 -05001406Creates Image_Info from integral dimensions width and height set to zero,
1407kUnknown_SkColorType, kUnknown_SkAlphaType, with Color_Space set to nullptr.
1408
1409Returned Image_Info as part of source does not draw, and as part of destination
1410can not be drawn to.
1411
1412#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001413
1414#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001415#Height 32
1416#Width 384
1417SkImageInfo info; // default constructor
1418SkString string;
1419string.printf("SkImageInfo() %c= SkImageInfo::MakeUnknown()",
1420 info == SkImageInfo::MakeUnknown() ? '=' : '!');
1421SkPaint paint;
1422canvas->drawString(string, 0, 12, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001423##
1424
Cary Clark1a8d7622018-03-05 13:26:16 -05001425#SeeAlso SkImageInfo() MakeN32 MakeS32 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001426
1427#Method ##
1428
Cary Clark2dc84ad2018-01-26 12:56:22 -05001429
1430# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05001431#Subtopic Property
Cary Clark78de7512018-02-07 07:27:09 -05001432#Line # metrics and attributes ##
1433##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001434
1435#Method int width() const
Cary Clark78de7512018-02-07 07:27:09 -05001436#In Property
Cary Clark1a8d7622018-03-05 13:26:16 -05001437#Line # returns pixel column count ##
1438Returns pixel count in each row.
1439
1440#Return pixel width ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001441
1442#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001443#Image 4
1444#Height 96
1445 canvas->translate(10, 10);
1446 canvas->drawBitmap(source, 0, 0);
1447 SkImageInfo imageInfo = source.info();
1448 canvas->translate(0, imageInfo.height());
1449 SkPaint paint;
1450 paint.setTextAlign(SkPaint::kCenter_Align);
1451 canvas->drawLine(0, 10, imageInfo.width(), 10, paint);
1452 canvas->drawString("width", imageInfo.width() / 2, 25, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001453##
1454
Cary Clark1a8d7622018-03-05 13:26:16 -05001455#SeeAlso height SkBitmap::width SkPixelRef::width SkImage::width SkSurface::width
Cary Clark2dc84ad2018-01-26 12:56:22 -05001456
1457#Method ##
1458
1459# ------------------------------------------------------------------------------
1460
1461#Method int height() const
Cary Clark78de7512018-02-07 07:27:09 -05001462#In Property
Cary Clark1a8d7622018-03-05 13:26:16 -05001463#Line # returns pixel row count ##
1464Returns pixel row count.
1465
1466#Return pixel height ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001467
1468#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001469#Image 4
1470#Height 96
1471 canvas->translate(10, 20);
1472 canvas->drawBitmap(source, 0, 0);
1473 SkImageInfo imageInfo = source.info();
1474 SkPaint paint;
1475 paint.setTextAlign(SkPaint::kCenter_Align);
1476 paint.setVerticalText(true);
1477 canvas->drawLine(imageInfo.width() + 10, 0, imageInfo.width() + 10, imageInfo.height(), paint);
1478 canvas->drawString("height", imageInfo.width() + 25, imageInfo.height() / 2, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001479##
1480
Cary Clark1a8d7622018-03-05 13:26:16 -05001481#SeeAlso width SkBitmap::height SkPixelRef::height SkImage::height SkSurface::height
Cary Clark2dc84ad2018-01-26 12:56:22 -05001482
1483#Method ##
1484
1485# ------------------------------------------------------------------------------
1486
1487#Method SkColorType colorType() const
Cary Clark78de7512018-02-07 07:27:09 -05001488#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001489#Line # returns Color_Type ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001490Returns Color_Type, one of: #list_of_color_types#.
1491
1492#Return Color_Type ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001493
1494#Example
Cary Clark681287e2018-03-16 11:34:15 -04001495 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
1496 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
1497 SkImageInfo info = SkImageInfo::MakeA8(16, 32);
1498 SkDebugf("color type: k" "%s" "_SkColorType\n", colors[info.colorType()]);
1499#StdOut
1500color type: kAlpha_8_SkColorType
1501##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001502##
1503
Cary Clark681287e2018-03-16 11:34:15 -04001504#SeeAlso alphaType SkPixmap::colorType SkBitmap::colorType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001505
1506#Method ##
1507
1508# ------------------------------------------------------------------------------
1509
1510#Method SkAlphaType alphaType() const
Cary Clark78de7512018-02-07 07:27:09 -05001511#In Property
Cary Clark682c58d2018-05-16 07:07:07 -04001512#Line # returns Alpha_Type ##
Cary Clark681287e2018-03-16 11:34:15 -04001513Returns Alpha_Type, one of: #list_of_alpha_types#.
1514
1515#Return Alpha_Type ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001516
1517#Example
Cary Clark681287e2018-03-16 11:34:15 -04001518 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
1519 SkImageInfo info = SkImageInfo::MakeA8(16, 32);
1520 SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[info.alphaType()]);
1521#StdOut
1522alpha type: kPremul_SkAlphaType
1523##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001524##
1525
Cary Clark681287e2018-03-16 11:34:15 -04001526#SeeAlso colorType SkPixmap::alphaType SkBitmap::alphaType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001527
1528#Method ##
1529
1530# ------------------------------------------------------------------------------
1531
1532#Method SkColorSpace* colorSpace() const
Cary Clark78de7512018-02-07 07:27:09 -05001533#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001534#Line # returns Color_Space ##
1535Returns Color_Space, the range of colors. The reference count of
1536Color_Space is unchanged. The returned Color_Space is immutable.
1537
1538#Return Color_Space, or nullptr ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001539
1540#Example
Cary Clark681287e2018-03-16 11:34:15 -04001541#Description
1542SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma
1543and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma.
1544##
Cary Clark682c58d2018-05-16 07:07:07 -04001545 SkImageInfo info = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
Cary Clark681287e2018-03-16 11:34:15 -04001546 SkColorSpace::MakeSRGBLinear());
1547 SkColorSpace* colorSpace = info.colorSpace();
1548 SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
1549 colorSpace->gammaCloseToSRGB() ? "true" : "false",
1550 colorSpace->gammaIsLinear() ? "true" : "false",
1551 colorSpace->isSRGB() ? "true" : "false");
1552#StdOut
1553gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
1554##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001555##
1556
Cary Clark681287e2018-03-16 11:34:15 -04001557#SeeAlso Color_Space SkPixmap::colorSpace SkBitmap::colorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001558
1559#Method ##
1560
1561# ------------------------------------------------------------------------------
1562
1563#Method sk_sp<SkColorSpace> refColorSpace() const
Cary Clark78de7512018-02-07 07:27:09 -05001564#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001565#Line # returns Color_Space ##
Cary Clark682c58d2018-05-16 07:07:07 -04001566Returns smart pointer to Color_Space, the range of colors. The smart pointer
Cary Clark681287e2018-03-16 11:34:15 -04001567tracks the number of objects sharing this Color_Space reference so the memory
1568is released when the owners destruct.
1569
1570The returned Color_Space is immutable.
1571
1572#Return Color_Space wrapped in a smart pointer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001573
1574#Example
Cary Clark682c58d2018-05-16 07:07:07 -04001575 SkImageInfo info1 = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
Cary Clark681287e2018-03-16 11:34:15 -04001576 SkColorSpace::MakeSRGBLinear());
1577 SkImageInfo info2 = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
1578 info1.refColorSpace());
1579 SkColorSpace* colorSpace = info2.colorSpace();
1580 SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
1581 colorSpace->gammaCloseToSRGB() ? "true" : "false",
1582 colorSpace->gammaIsLinear() ? "true" : "false",
1583 colorSpace->isSRGB() ? "true" : "false");
Cary Clark2dc84ad2018-01-26 12:56:22 -05001584##
1585
Cary Clark681287e2018-03-16 11:34:15 -04001586#SeeAlso Color_Space SkBitmap::refColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001587
1588#Method ##
1589
1590# ------------------------------------------------------------------------------
1591
1592#Method bool isEmpty() const
Cary Clark78de7512018-02-07 07:27:09 -05001593#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001594#Line # returns if dimensions contain pixels ##
1595
1596Returns if Image_Info describes an empty area of pixels by checking if either
1597width or height is zero or smaller.
1598
1599#Return true if either dimension is zero or smaller ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001600
1601#Example
Cary Clark681287e2018-03-16 11:34:15 -04001602 for (int width : { 0, 2 } ) {
1603 for (int height : { 0, 2 } ) {
1604 SkImageInfo imageInfo= SkImageInfo::MakeA8(width, height);
1605 SkDebugf("width: %d height: %d empty: %s\n", width, height,
1606 imageInfo.isEmpty() ? "true" : "false");
1607 }
1608 }
1609#StdOut
1610width: 0 height: 0 empty: true
1611width: 0 height: 2 empty: true
1612width: 2 height: 0 empty: true
1613width: 2 height: 2 empty: false
1614##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001615##
1616
Cary Clark681287e2018-03-16 11:34:15 -04001617#SeeAlso dimensions bounds SkBitmap::empty SkPixmap::bounds
Cary Clark2dc84ad2018-01-26 12:56:22 -05001618
1619#Method ##
1620
1621# ------------------------------------------------------------------------------
1622
1623#Method bool isOpaque() const
Cary Clark78de7512018-02-07 07:27:09 -05001624#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001625#Line # returns if Alpha_Type is kOpaque_SkAlphaType ##
1626
1627Returns true if Alpha_Type is set to hint that all pixels are opaque; their
1628Color_Alpha value is implicitly or explicitly 1.0. If true, and all pixels are
Cary Clark682c58d2018-05-16 07:07:07 -04001629not opaque, Skia may draw incorrectly.
Cary Clark681287e2018-03-16 11:34:15 -04001630
1631Does not check if Color_Type allows Alpha, or if any pixel value has
1632transparency.
1633
1634#Return true if Alpha_Type is kOpaque_SkAlphaType ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001635
1636#Example
Cary Clark681287e2018-03-16 11:34:15 -04001637 const int height = 2;
1638 const int width = 2;
1639 SkBitmap bitmap;
1640 SkImageInfo imageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType);
1641 bitmap.setInfo(imageInfo);
1642 for (int index = 0; index < 2; ++index) {
1643 bitmap.allocPixels();
1644 bitmap.eraseColor(0x00000000);
1645 SkDebugf("isOpaque: %s\n", imageInfo.isOpaque() ? "true" : "false");
1646 bitmap.eraseColor(0xFFFFFFFF);
1647 SkDebugf("isOpaque: %s\n", imageInfo.isOpaque() ? "true" : "false");
1648 imageInfo = imageInfo.makeAlphaType(kOpaque_SkAlphaType);
1649 bitmap.setInfo(imageInfo);
1650 }
1651#StdOut
1652isOpaque: false
1653isOpaque: false
1654isOpaque: true
1655isOpaque: true
1656##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001657##
1658
Cary Clark681287e2018-03-16 11:34:15 -04001659#SeeAlso Color_Alpha SkColorTypeValidateAlphaType SkBitmap::isOpaque SkImage::isOpaque SkPixmap::isOpaque
Cary Clark2dc84ad2018-01-26 12:56:22 -05001660
1661#Method ##
1662
1663# ------------------------------------------------------------------------------
1664
1665#Method SkISize dimensions() const
Cary Clark78de7512018-02-07 07:27:09 -05001666#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001667#Line # returns width() and height() ##
1668
1669Returns ISize { width(), height() }.
1670
1671#Return integral size of width() and height() ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001672
1673#Example
Cary Clark681287e2018-03-16 11:34:15 -04001674 const int height = 2;
1675 const int width = 2;
1676 SkImageInfo imageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType);
1677 SkISize dimensions = imageInfo.dimensions();
1678 SkIRect bounds = imageInfo.bounds();
1679 SkIRect dimensionsAsBounds = SkIRect::MakeSize(dimensions);
1680 SkDebugf("dimensionsAsBounds %c= bounds\n", dimensionsAsBounds == bounds ? '=' : '!');
1681#StdOut
1682dimensionsAsBounds == bounds
1683##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001684##
1685
Cary Clark681287e2018-03-16 11:34:15 -04001686#SeeAlso width height bounds SkBitmap::dimensions
Cary Clark2dc84ad2018-01-26 12:56:22 -05001687
1688#Method ##
1689
1690# ------------------------------------------------------------------------------
1691
1692#Method SkIRect bounds() const
Cary Clark78de7512018-02-07 07:27:09 -05001693#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001694#Line # returns width() and height() as Rectangle ##
1695Returns IRect { 0, 0, width(), height() }.
1696
1697#Return integral rectangle from origin to width() and height() ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001698
1699#Example
Cary Clark681287e2018-03-16 11:34:15 -04001700#Height 64
1701#Image 4
1702 canvas->scale(.5f, .5f);
1703 SkImageInfo imageInfo = source.info();
1704 SkIRect bounds = imageInfo.bounds();
1705 for (int x : { 0, bounds.width() } ) {
1706 for (int y : { 0, bounds.height() } ) {
1707 canvas->drawBitmap(source, x, y);
1708 }
1709 }
Cary Clark2dc84ad2018-01-26 12:56:22 -05001710##
1711
Cary Clark681287e2018-03-16 11:34:15 -04001712#SeeAlso width height dimensions
Cary Clark2dc84ad2018-01-26 12:56:22 -05001713
1714#Method ##
1715
1716# ------------------------------------------------------------------------------
1717
1718#Method bool gammaCloseToSRGB() const
Cary Clark78de7512018-02-07 07:27:09 -05001719#In Property
Cary Clark682c58d2018-05-16 07:07:07 -04001720#Line # returns if Color_Space gamma is approximately the same as sRGB ##
Cary Clark681287e2018-03-16 11:34:15 -04001721
1722Returns true if associated Color_Space is not nullptr, and Color_Space gamma
Cary Clark682c58d2018-05-16 07:07:07 -04001723is approximately the same as sRGB.
1724This includes the
Cary Clark681287e2018-03-16 11:34:15 -04001725###$
1726$A sRGB transfer function $ https://en.wikipedia.org/wiki/SRGB#The_sRGB_transfer_function_(%22gamma%22) $$
1727$$$#
1728as well as a gamma curve described by a 2.2 exponent.
1729
1730#Return true if Color_Space gamma is approximately the same as sRGB ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001731
1732#Example
Cary Clark681287e2018-03-16 11:34:15 -04001733#Height 144
1734 const int width = 256;
1735 const int height = 64;
1736 auto drawLabel = [=](const char* what, bool closeToSRGB) -> void {
1737 SkString string;
1738 string.printf("%s gamma is %s" "close to sRGB", what, closeToSRGB ? "" : "not ");
1739 SkPaint paint;
1740 paint.setAntiAlias(true);
1741 paint.setTextAlign(SkPaint::kCenter_Align);
1742 canvas->drawString(string, width / 2, 56, paint);
1743 };
1744 SkColor gradColors[] = { 0xFFFF7F00, 0xFF00FF7F, 0xFF0000FF, 0xFF7F7FFF };
1745 SkPoint gradPoints[] = { { 0, 0 }, { width, 0 }, { width * 2, 0 }, { width * 3, 0 } };
1746 SkPaint gradPaint;
1747 gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1748 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1749 canvas->drawRect(SkRect::MakeWH(width, height), gradPaint);
1750 drawLabel("canvas", canvas->imageInfo().gammaCloseToSRGB());
1751 SkBitmap bitmap;
1752 SkImageInfo offscreenInfo = SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType);
1753 bitmap.allocPixels(offscreenInfo);
1754 SkCanvas sRGBOffscreen(bitmap);
1755 sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1756 canvas->translate(0, 80);
1757 canvas->drawBitmap(bitmap, 0, 0);
1758 drawLabel("offscreen", offscreenInfo.gammaCloseToSRGB());
Cary Clark2dc84ad2018-01-26 12:56:22 -05001759##
1760
Cary Clark681287e2018-03-16 11:34:15 -04001761#SeeAlso SkColorSpace::gammaCloseToSRGB
Cary Clark2dc84ad2018-01-26 12:56:22 -05001762
1763#Method ##
1764
1765# ------------------------------------------------------------------------------
1766
1767#Method SkImageInfo makeWH(int newWidth, int newHeight) const
Cary Clark61313f32018-10-08 14:57:48 -04001768#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001769#Line # creates Image_Info with changed dimensions ##
Cary Clark681287e2018-03-16 11:34:15 -04001770Creates Image_Info with the same Color_Type, Color_Space, and Alpha_Type,
1771with dimensions set to width and height.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001772
Cary Clark681287e2018-03-16 11:34:15 -04001773#Param newWidth pixel column count; must be zero or greater ##
1774#Param newHeight pixel row count; must be zero or greater ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001775
Cary Clark681287e2018-03-16 11:34:15 -04001776#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001777
1778#Example
Cary Clark681287e2018-03-16 11:34:15 -04001779#Height 144
1780#Image 3
1781 SkImageInfo canvasImageInfo = canvas->imageInfo();
1782 SkRect canvasBounds = SkRect::Make(canvasImageInfo.bounds());
1783 canvas->drawBitmapRect(source, source.bounds(), canvasBounds, nullptr);
Cary Clark682c58d2018-05-16 07:07:07 -04001784 SkImageInfo insetImageInfo =
Cary Clark681287e2018-03-16 11:34:15 -04001785 canvasImageInfo.makeWH(canvasBounds.width() / 2, canvasBounds.height() / 2);
1786 SkBitmap inset;
1787 inset.allocPixels(insetImageInfo);
1788 SkCanvas offscreen(inset);
1789 offscreen.drawBitmapRect(source, source.bounds(), SkRect::Make(inset.bounds()), nullptr);
1790 canvas->drawBitmap(inset, canvasBounds.width() / 4, canvasBounds.height() / 4);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001791##
1792
Cary Clark682c58d2018-05-16 07:07:07 -04001793#SeeAlso Make makeAlphaType makeColorSpace makeColorType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001794
1795#Method ##
1796
1797# ------------------------------------------------------------------------------
1798
1799#Method SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const
Cary Clark61313f32018-10-08 14:57:48 -04001800#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001801#Line # creates Image_Info with changed Alpha_Type ##
Cary Clark681287e2018-03-16 11:34:15 -04001802Creates Image_Info with same Color_Type, Color_Space, width, and height,
Cary Clark682c58d2018-05-16 07:07:07 -04001803with Alpha_Type set to newAlphaType.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001804
Cary Clark681287e2018-03-16 11:34:15 -04001805Created Image_Info contains newAlphaType even if it is incompatible with
1806Color_Type, in which case Alpha_Type in Image_Info is ignored.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001807
Cary Clark681287e2018-03-16 11:34:15 -04001808#Param newAlphaType one of: #list_of_alpha_types#
Cary Clark2dc84ad2018-01-26 12:56:22 -05001809##
1810
Cary Clark681287e2018-03-16 11:34:15 -04001811#Return created Image_Info ##
1812
1813#Example
1814#Image 3
1815 const int width = 256;
1816 const int height = 128;
1817 SkColor pixels[height][width];
1818 for (int y = 0; y < height; ++y) {
1819 for (int x = 0; x < width; ++x) {
Cary Clark682c58d2018-05-16 07:07:07 -04001820 int red = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 4 + y) * 0.03f)));
1821 int blue = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 3 + y) * 0.04f)));
Cary Clark681287e2018-03-16 11:34:15 -04001822 int green = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 2 + y) * 0.05f)));
1823 int alpha = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 1 + y) * 0.006f)));
Cary Clark682c58d2018-05-16 07:07:07 -04001824 pixels[y][x] =
Cary Clark681287e2018-03-16 11:34:15 -04001825 SkColorSetARGB(alpha, red * alpha / 255, green * alpha / 255, blue * alpha / 255);
1826 }
1827 }
1828 SkBitmap bitmap;
1829 SkImageInfo info = SkImageInfo::Make(width, height, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
1830 bitmap.installPixels(info, (void*) pixels, sizeof(SkColor) * width);
1831 canvas->drawBitmap(source, 0, 0);
1832 canvas->drawBitmap(bitmap, 0, 0);
1833 SkImageInfo unpremulInfo = info.makeAlphaType(kUnpremul_SkAlphaType);
1834 bitmap.installPixels(unpremulInfo, (void*) pixels, sizeof(SkColor) * width);
1835 canvas->drawBitmap(bitmap, 0, 128);
1836##
1837
1838#SeeAlso Make MakeA8 makeColorType makeColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001839
1840#Method ##
1841
1842# ------------------------------------------------------------------------------
1843
1844#Method SkImageInfo makeColorType(SkColorType newColorType) const
Cary Clark61313f32018-10-08 14:57:48 -04001845#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001846#Line # creates Image_Info with changed Color_Type ##
Cary Clark681287e2018-03-16 11:34:15 -04001847Creates Image_Info with same Alpha_Type, Color_Space, width, and height,
1848with Color_Type set to newColorType.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001849
Cary Clark681287e2018-03-16 11:34:15 -04001850#Param newColorType one of: #list_of_color_types#
Cary Clark2dc84ad2018-01-26 12:56:22 -05001851##
1852
Cary Clark681287e2018-03-16 11:34:15 -04001853#Return created Image_Info ##
1854
1855#Example
1856 const int width = 256;
1857 const int height = 128;
1858 SkColor pixels[height][width];
1859 for (int y = 0; y < height; ++y) {
1860 for (int x = 0; x < width; ++x) {
Cary Clark682c58d2018-05-16 07:07:07 -04001861 int red = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 4 + y) * 0.03f)));
1862 int blue = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 3 + y) * 0.04f)));
Cary Clark681287e2018-03-16 11:34:15 -04001863 int green = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 2 + y) * 0.05f)));
1864 int alpha = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 1 + y) * 0.006f)));
Cary Clark682c58d2018-05-16 07:07:07 -04001865 pixels[y][x] =
Cary Clark681287e2018-03-16 11:34:15 -04001866 SkColorSetARGB(alpha, red * alpha / 255, green * alpha / 255, blue * alpha / 255);
1867 }
1868 }
1869 SkBitmap bitmap;
1870 SkImageInfo info = SkImageInfo::Make(width, height, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
1871 bitmap.installPixels(info, (void*) pixels, sizeof(SkColor) * width);
1872 canvas->drawBitmap(source, 0, 0);
1873 canvas->drawBitmap(bitmap, 0, 0);
1874 SkImageInfo rgbaInfo = info.makeColorType(kRGBA_8888_SkColorType);
1875 bitmap.installPixels(rgbaInfo, (void*) pixels, sizeof(SkColor) * width);
1876 canvas->drawBitmap(bitmap, 0, 128);
1877##
1878
1879#SeeAlso Make makeAlphaType makeColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001880
1881#Method ##
1882
1883# ------------------------------------------------------------------------------
1884
1885#Method SkImageInfo makeColorSpace(sk_sp<SkColorSpace> cs) const
Cary Clark61313f32018-10-08 14:57:48 -04001886#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001887#Line # creates Image_Info with changed Color_Space ##
Cary Clark681287e2018-03-16 11:34:15 -04001888Creates Image_Info with same Alpha_Type, Color_Type, width, and height,
1889with Color_Space set to cs.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001890
Cary Clark681287e2018-03-16 11:34:15 -04001891#Param cs range of colors; may be nullptr ##
1892
1893#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001894
1895#Example
Cary Clark681287e2018-03-16 11:34:15 -04001896#Height 224
1897 const int width = 256;
1898 const int height = 64;
1899 auto drawLabel = [=](const char* what, bool closeToSRGB) -> void {
1900 SkString string;
1901 string.printf("%s gamma is %s" "close to sRGB", what, closeToSRGB ? "" : "not ");
1902 SkPaint paint;
1903 paint.setAntiAlias(true);
1904 paint.setTextAlign(SkPaint::kCenter_Align);
1905 canvas->drawString(string, width / 2, 56, paint);
1906 };
1907 SkColor gradColors[] = { 0xFFFF7F00, 0xFF00FF7F, 0xFF0000FF, 0xFF7F7FFF };
1908 SkPoint gradPoints[] = { { 0, 0 }, { width, 0 }, { width * 2, 0 }, { width * 3, 0 } };
1909 SkPaint gradPaint;
1910 gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1911 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1912 canvas->drawRect(SkRect::MakeWH(width, height), gradPaint);
1913 drawLabel("canvas", canvas->imageInfo().gammaCloseToSRGB());
1914 SkBitmap bitmap;
1915 SkImageInfo offscreenInfo = SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType);
1916 bitmap.allocPixels(offscreenInfo);
1917 SkCanvas sRGBOffscreen(bitmap);
1918 sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1919 canvas->translate(0, 80);
1920 canvas->drawBitmap(bitmap, 0, 0);
1921 drawLabel("offscreen", offscreenInfo.gammaCloseToSRGB());
1922 SkImageInfo linearGamma =
1923 offscreenInfo.makeColorSpace(offscreenInfo.colorSpace()->makeLinearGamma());
1924 bitmap.allocPixels(linearGamma);
1925 SkCanvas lgOffscreen(bitmap);
1926 lgOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1927 canvas->translate(0, 80);
1928 canvas->drawBitmap(bitmap, 0, 0);
1929 drawLabel("linear", linearGamma.gammaCloseToSRGB());
Cary Clark2dc84ad2018-01-26 12:56:22 -05001930##
1931
Cary Clark681287e2018-03-16 11:34:15 -04001932#SeeAlso Make MakeS32 makeAlphaType makeColorType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001933
1934#Method ##
1935
1936# ------------------------------------------------------------------------------
1937
1938#Method int bytesPerPixel() const
Cary Clark78de7512018-02-07 07:27:09 -05001939#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001940#Line # returns number of bytes in pixel based on Color_Type ##
1941Returns number of bytes per pixel required by Color_Type.
1942Returns zero if colorType( is kUnknown_SkColorType.
1943
1944#Return bytes in pixel ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001945
1946#Example
Cary Clark681287e2018-03-16 11:34:15 -04001947 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
1948 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
1949 for (SkColorType colorType : { #list_of_color_types#
1950 } ) {
1951 SkImageInfo info = SkImageInfo::Make(1, 1, colorType, kOpaque_SkAlphaType);
1952 SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d\n",
1953 colors[colorType], 13 - strlen(colors[colorType]), " ",
1954 info.bytesPerPixel());
1955 }
1956#StdOut
1957color: kUnknown_SkColorType bytesPerPixel: 0
1958color: kAlpha_8_SkColorType bytesPerPixel: 1
1959color: kRGB_565_SkColorType bytesPerPixel: 2
1960color: kARGB_4444_SkColorType bytesPerPixel: 2
1961color: kRGBA_8888_SkColorType bytesPerPixel: 4
1962color: kRGB_888x_SkColorType bytesPerPixel: 4
1963color: kBGRA_8888_SkColorType bytesPerPixel: 4
1964color: kRGBA_1010102_SkColorType bytesPerPixel: 4
1965color: kRGB_101010x_SkColorType bytesPerPixel: 4
1966color: kGray_8_SkColorType bytesPerPixel: 1
1967color: kRGBA_F16_SkColorType bytesPerPixel: 8
1968##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001969##
1970
Cary Clark681287e2018-03-16 11:34:15 -04001971#SeeAlso width shiftPerPixel SkBitmap::bytesPerPixel
Cary Clark2dc84ad2018-01-26 12:56:22 -05001972
1973#Method ##
1974
1975# ------------------------------------------------------------------------------
1976
1977#Method int shiftPerPixel() const
Cary Clark78de7512018-02-07 07:27:09 -05001978#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001979#Line # returns bit shift from pixels to bytes ##
1980Returns bit shift converting row bytes to row pixels.
1981Returns zero for kUnknown_SkColorType.
1982
1983#Return one of: 0, 1, 2, 3; left shift to convert pixels to bytes ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001984
1985#Example
Cary Clark681287e2018-03-16 11:34:15 -04001986 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
1987 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
1988 for (SkColorType colorType : { #list_of_color_types#
1989 } ) {
1990 SkImageInfo info = SkImageInfo::Make(1, 1, colorType, kOpaque_SkAlphaType);
1991 SkDebugf("color: k" "%s" "_SkColorType" "%*s" "shiftPerPixel: %d\n",
1992 colors[colorType], 14 - strlen(colors[colorType]), " ",
1993 info.shiftPerPixel());
1994 }
1995#StdOut
1996color: kUnknown_SkColorType shiftPerPixel: 0
1997color: kAlpha_8_SkColorType shiftPerPixel: 0
1998color: kRGB_565_SkColorType shiftPerPixel: 1
1999color: kARGB_4444_SkColorType shiftPerPixel: 1
2000color: kRGBA_8888_SkColorType shiftPerPixel: 2
2001color: kRGB_888x_SkColorType shiftPerPixel: 2
2002color: kBGRA_8888_SkColorType shiftPerPixel: 2
2003color: kRGBA_1010102_SkColorType shiftPerPixel: 2
2004color: kRGB_101010x_SkColorType shiftPerPixel: 2
2005color: kGray_8_SkColorType shiftPerPixel: 0
2006color: kRGBA_F16_SkColorType shiftPerPixel: 3
2007##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002008##
2009
Cary Clark06c20f32018-03-20 15:53:27 -04002010#SeeAlso bytesPerPixel minRowBytes SkBitmap::shiftPerPixel SkPixmap::shiftPerPixel
Cary Clark2dc84ad2018-01-26 12:56:22 -05002011
2012#Method ##
2013
2014# ------------------------------------------------------------------------------
2015
2016#Method uint64_t minRowBytes64() const
Cary Clark78de7512018-02-07 07:27:09 -05002017#In Property
Cary Clark681287e2018-03-16 11:34:15 -04002018#Line # returns width() times bytesPerPixel in 64 bits ##
2019
2020Returns minimum bytes per row, computed from pixel width() and Color_Type, which
Cary Clark682c58d2018-05-16 07:07:07 -04002021specifies bytesPerPixel(). Bitmap maximum value for row bytes must fit
2022in 31 bits.
Cary Clark681287e2018-03-16 11:34:15 -04002023
2024#Return width() times bytesPerPixel as unsigned 64-bit integer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002025
2026#Example
Cary Clark681287e2018-03-16 11:34:15 -04002027 for (int shift = 24; shift < 32; ++shift) {
2028 int width = 1 << shift;
Cary Clark682c58d2018-05-16 07:07:07 -04002029 SkImageInfo imageInfo =
Cary Clark681287e2018-03-16 11:34:15 -04002030 SkImageInfo::Make(width, 1, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
2031 uint64_t minRowBytes = imageInfo.minRowBytes64();
2032 bool widthTooLarge = (uint64_t) (int32_t) minRowBytes != minRowBytes;
2033 SkDebugf("RGBA_F16 width %d (0x%08x) %s\n",
Cary Clark682c58d2018-05-16 07:07:07 -04002034 width, width, widthTooLarge ? "too large" : "OK");
Cary Clark681287e2018-03-16 11:34:15 -04002035 }
2036#StdOut
2037RGBA_F16 width 16777216 (0x01000000) OK
2038RGBA_F16 width 33554432 (0x02000000) OK
2039RGBA_F16 width 67108864 (0x04000000) OK
2040RGBA_F16 width 134217728 (0x08000000) OK
2041RGBA_F16 width 268435456 (0x10000000) too large
2042RGBA_F16 width 536870912 (0x20000000) too large
2043RGBA_F16 width 1073741824 (0x40000000) too large
2044RGBA_F16 width -2147483648 (0x80000000) too large
2045##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002046##
2047
Cary Clark681287e2018-03-16 11:34:15 -04002048#SeeAlso minRowBytes computeByteSize computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002049
2050#Method ##
2051
2052# ------------------------------------------------------------------------------
2053
2054#Method size_t minRowBytes() const
Cary Clark78de7512018-02-07 07:27:09 -05002055#In Property
Cary Clark681287e2018-03-16 11:34:15 -04002056#Line # returns width() times bytesPerPixel in 32 bits ##
2057
2058Returns minimum bytes per row, computed from pixel width() and Color_Type, which
Cary Clark682c58d2018-05-16 07:07:07 -04002059specifies bytesPerPixel(). Bitmap maximum value for row bytes must fit
2060in 31 bits.
Cary Clark681287e2018-03-16 11:34:15 -04002061
2062#Return width() times bytesPerPixel as signed 32-bit integer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002063
2064#Example
Cary Clark681287e2018-03-16 11:34:15 -04002065 for (int shift = 24; shift < 32; ++shift) {
2066 int width = 1 << shift;
Cary Clark682c58d2018-05-16 07:07:07 -04002067 SkImageInfo imageInfo =
Cary Clark681287e2018-03-16 11:34:15 -04002068 SkImageInfo::Make(width, 1, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
2069 size_t minRowBytes = imageInfo.minRowBytes();
2070 bool widthTooLarge = !minRowBytes;
2071 SkDebugf("RGBA_F16 width %d (0x%08x) %s\n",
Cary Clark682c58d2018-05-16 07:07:07 -04002072 width, width, widthTooLarge ? "too large" : "OK");
Cary Clark681287e2018-03-16 11:34:15 -04002073 }
2074#StdOut
2075RGBA_F16 width 16777216 (0x01000000) OK
2076RGBA_F16 width 33554432 (0x02000000) OK
2077RGBA_F16 width 67108864 (0x04000000) OK
2078RGBA_F16 width 134217728 (0x08000000) OK
2079RGBA_F16 width 268435456 (0x10000000) too large
2080RGBA_F16 width 536870912 (0x20000000) too large
2081RGBA_F16 width 1073741824 (0x40000000) too large
2082RGBA_F16 width -2147483648 (0x80000000) too large
2083##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002084##
2085
Cary Clark681287e2018-03-16 11:34:15 -04002086#SeeAlso minRowBytes64 computeByteSize computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002087
2088#Method ##
2089
2090# ------------------------------------------------------------------------------
2091
2092#Method size_t computeOffset(int x, int y, size_t rowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05002093#In Utility
Cary Clark681287e2018-03-16 11:34:15 -04002094#Line # returns byte offset within pixel array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002095
Cary Clark681287e2018-03-16 11:34:15 -04002096Returns byte offset of pixel from pixel base address.
2097
2098Asserts in debug build if x or y is outside of bounds. Does not assert if
2099rowBytes is smaller than minRowBytes, even though result may be incorrect.
2100
2101#Param x column index, zero or greater, and less than width() ##
2102#Param y row index, zero or greater, and less than height() ##
2103#Param rowBytes size of pixel row or larger ##
2104
2105#Return offset within pixel array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002106
2107#Example
Cary Clark06c20f32018-03-20 15:53:27 -04002108#Height 128
Cary Clark681287e2018-03-16 11:34:15 -04002109 uint8_t pixels[][12] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00},
2110 { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00},
2111 { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00},
2112 { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF},
2113 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
2114 { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00},
2115 { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00},
2116 { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00} };
2117 SkImageInfo imageInfo = SkImageInfo::MakeA8(8, 8);
2118 SkBitmap bitmap;
2119 bitmap.installPixels(imageInfo, (void*) pixels, sizeof(pixels[0]));
2120 SkPaint paint;
2121 paint.setColor(SK_ColorRED);
2122 canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint);
2123 size_t offset = imageInfo.computeOffset(2, 3, sizeof(pixels[0]));
2124 pixels[0][offset] = 0x7F;
2125 offset = imageInfo.computeOffset(5, 3, sizeof(pixels[0]));
2126 pixels[0][offset] = 0x7F;
2127 bitmap.installPixels(imageInfo, (void*) pixels, sizeof(pixels[0]));
2128 canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(128, 128), &paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05002129##
2130
Cary Clark06c20f32018-03-20 15:53:27 -04002131#SeeAlso height width minRowBytes computeByteSize
Cary Clark2dc84ad2018-01-26 12:56:22 -05002132
2133#Method ##
2134
2135# ------------------------------------------------------------------------------
2136
2137#Method bool operator==(const SkImageInfo& other)_const
Cary Clark06c20f32018-03-20 15:53:27 -04002138#Line # compares Image_Info for equality ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002139
Cary Clark06c20f32018-03-20 15:53:27 -04002140Compares Image_Info with other, and returns true if width, height, Color_Type,
2141Alpha_Type, and Color_Space are equivalent.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002142
Cary Clark06c20f32018-03-20 15:53:27 -04002143#Param other Image_Info to compare ##
2144
2145#Return true if Image_Info equals other ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002146
2147#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002148 SkImageInfo info1 = SkImageInfo::Make(10, 20, kGray_8_SkColorType, kPremul_SkAlphaType);
2149 SkImageInfo info2 = SkImageInfo::Make(20, 10, kAlpha_8_SkColorType, kUnpremul_SkAlphaType);
2150 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
2151 info2 = info2.makeWH(10, 20);
2152 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
2153 info2 = info2.makeColorType(kGray_8_SkColorType);
2154 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
2155 info2 = info2.makeAlphaType(kPremul_SkAlphaType);
2156 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
2157#StdOut
2158info1 != info2
2159info1 != info2
2160info1 != info2
2161info1 == info2
2162##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002163##
2164
Cary Clark06c20f32018-03-20 15:53:27 -04002165#SeeAlso operator!=(const SkImageInfo& other)_const SkColorSpace::Equals
Cary Clark2dc84ad2018-01-26 12:56:22 -05002166
2167#Method ##
2168
2169# ------------------------------------------------------------------------------
2170
2171#Method bool operator!=(const SkImageInfo& other)_const
Cary Clark06c20f32018-03-20 15:53:27 -04002172#Line # compares Image_Info for inequality ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002173
Cary Clark06c20f32018-03-20 15:53:27 -04002174Compares Image_Info with other, and returns true if width, height, Color_Type,
Cary Clarkffb3d682018-05-17 12:17:28 -04002175Alpha_Type, and Color_Space are not equivalent.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002176
Cary Clark06c20f32018-03-20 15:53:27 -04002177#Param other Image_Info to compare ##
2178
2179#Return true if Image_Info is not equal to other ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002180
2181#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002182 SkImageInfo info1 = SkImageInfo::Make(10, 20, kGray_8_SkColorType, kPremul_SkAlphaType);
2183 SkImageInfo info2 = SkImageInfo::Make(20, 10, kAlpha_8_SkColorType, kUnpremul_SkAlphaType);
2184 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
2185 info2 = info2.makeWH(10, 20);
2186 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
2187 info2 = info2.makeColorType(kGray_8_SkColorType);
2188 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
2189 info2 = info2.makeAlphaType(kPremul_SkAlphaType);
2190 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
2191#StdOut
2192info1 != info2
2193info1 != info2
2194info1 != info2
2195info1 == info2
2196##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002197##
2198
Cary Clark06c20f32018-03-20 15:53:27 -04002199#SeeAlso operator==(const SkImageInfo& other)_const SkColorSpace::Equals
Cary Clark2dc84ad2018-01-26 12:56:22 -05002200
2201#Method ##
2202
2203# ------------------------------------------------------------------------------
2204
2205#Method size_t computeByteSize(size_t rowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05002206#In Utility
Cary Clark682c58d2018-05-16 07:07:07 -04002207#Line # returns memory required by pixel buffer with given row bytes ##
Cary Clark06c20f32018-03-20 15:53:27 -04002208Returns storage required by pixel array, given Image_Info dimensions, Color_Type,
2209and rowBytes. rowBytes is assumed to be at least as large as minRowBytes().
Cary Clark2dc84ad2018-01-26 12:56:22 -05002210
Cary Clark06c20f32018-03-20 15:53:27 -04002211Returns zero if height is zero.
Cary Clark63132862018-06-18 07:26:34 -04002212Returns SIZE_MAX if answer exceeds the range of size_t.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002213
Cary Clark06c20f32018-03-20 15:53:27 -04002214#Param rowBytes size of pixel row or larger ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002215
Cary Clark06c20f32018-03-20 15:53:27 -04002216#Return memory required by pixel buffer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002217
2218#Example
Cary Clark06c20f32018-03-20 15:53:27 -04002219#Height 130
Cary Clark682c58d2018-05-16 07:07:07 -04002220 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2);
2221 const size_t size = info.computeByteSize(100000);
2222 SkAutoTMalloc<SkPMColor> storage(size);
2223 SkPMColor* pixels = storage.get();
2224 SkBitmap bitmap;
2225 bitmap.setInfo(info);
2226 bitmap.setPixels(pixels);
2227 bitmap.eraseColor(SK_ColorRED);
2228 canvas->scale(50, 50);
2229 canvas->rotate(8);
Cary Clark06c20f32018-03-20 15:53:27 -04002230 canvas->drawBitmap(bitmap, 2, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05002231##
2232
Cary Clark06c20f32018-03-20 15:53:27 -04002233#SeeAlso computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002234
2235#Method ##
2236
2237# ------------------------------------------------------------------------------
2238
2239#Method size_t computeMinByteSize() const
Cary Clark78de7512018-02-07 07:27:09 -05002240#In Utility
Cary Clark682c58d2018-05-16 07:07:07 -04002241#Line # returns least memory required by pixel buffer ##
2242Returns storage required by pixel array, given Image_Info dimensions, and
Cary Clark06c20f32018-03-20 15:53:27 -04002243Color_Type. Uses minRowBytes() to compute bytes for pixel row.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002244
Cary Clark06c20f32018-03-20 15:53:27 -04002245Returns zero if height is zero.
Cary Clark63132862018-06-18 07:26:34 -04002246Returns SIZE_MAX if answer exceeds the range of size_t.
Cary Clark06c20f32018-03-20 15:53:27 -04002247
2248#Return least memory required by pixel buffer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002249
2250#Example
Cary Clark06c20f32018-03-20 15:53:27 -04002251#Height 130
Cary Clark682c58d2018-05-16 07:07:07 -04002252 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2);
2253 const size_t size = info.computeMinByteSize();
2254 SkAutoTMalloc<SkPMColor> storage(size);
2255 SkPMColor* pixels = storage.get();
2256 SkBitmap bitmap;
2257 bitmap.setInfo(info);
2258 bitmap.setPixels(pixels);
2259 bitmap.eraseColor(SK_ColorRED);
2260 canvas->scale(50, 50);
2261 canvas->rotate(8);
Cary Clark06c20f32018-03-20 15:53:27 -04002262 canvas->drawBitmap(bitmap, 2, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05002263##
2264
Cary Clark06c20f32018-03-20 15:53:27 -04002265#SeeAlso computeByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002266
2267#Method ##
2268
2269# ------------------------------------------------------------------------------
2270
2271#Method static bool ByteSizeOverflowed(size_t byteSize)
Cary Clark78de7512018-02-07 07:27:09 -05002272#In Utility
Cary Clark06c20f32018-03-20 15:53:27 -04002273#Line # checks result of computeByteSize and computeMinByteSize ##
Cary Clark63132862018-06-18 07:26:34 -04002274Returns true if byteSize equals SIZE_MAX. computeByteSize and
2275computeMinByteSize return SIZE_MAX if size_t can not hold buffer size.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002276
Cary Clark06c20f32018-03-20 15:53:27 -04002277#Param byteSize result of computeByteSize or computeMinByteSize ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002278
Cary Clark06c20f32018-03-20 15:53:27 -04002279#Return true if computeByteSize or computeMinByteSize result exceeds size_t ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002280
2281#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002282 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 1000000000);
2283 for (size_t rowBytes = 100000000; rowBytes < 10000000000000LL; rowBytes *= 10) {
2284 const size_t size = info.computeByteSize(rowBytes);
2285 SkDebugf("rowBytes:%llu size:%llu overflowed:%s\n", rowBytes, size,
2286 SkImageInfo::ByteSizeOverflowed(size) ? "true" : "false");
2287 }
2288#StdOut
2289rowBytes:100000000 size:99999999900000008 overflowed:false
2290rowBytes:1000000000 size:999999999000000008 overflowed:false
2291rowBytes:10000000000 size:9999999990000000008 overflowed:false
2292rowBytes:100000000000 size:18446744073709551615 overflowed:true
2293rowBytes:1000000000000 size:18446744073709551615 overflowed:true
2294##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002295##
2296
Cary Clark06c20f32018-03-20 15:53:27 -04002297#SeeAlso computeByteSize computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002298
2299#Method ##
2300
2301# ------------------------------------------------------------------------------
2302
2303#Method bool validRowBytes(size_t rowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05002304#In Utility
Cary Clark06c20f32018-03-20 15:53:27 -04002305#Line # checks if row bytes is large enough to contain pixel row ##
2306Returns true if rowBytes is smaller than width times pixel size.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002307
Cary Clark06c20f32018-03-20 15:53:27 -04002308#Param rowBytes size of pixel row or larger ##
2309
2310#Return true if rowBytes is large enough to contain pixel row ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002311
2312#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002313 SkImageInfo info = SkImageInfo::MakeN32Premul(16, 8);
2314 for (size_t rowBytes = 60; rowBytes < 72; rowBytes += sizeof(SkPMColor)) {
2315 SkDebugf("validRowBytes(%llu): %s\n", rowBytes, info.validRowBytes(rowBytes) ?
2316 "true" : "false");
2317 }
2318#StdOut
2319validRowBytes(60): false
2320validRowBytes(64): true
2321validRowBytes(68): true
2322##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002323##
2324
Cary Clark06c20f32018-03-20 15:53:27 -04002325#SeeAlso ByteSizeOverflowed computeByteSize computeMinByteSize
Cary Clark2dc84ad2018-01-26 12:56:22 -05002326
2327#Method ##
2328
2329# ------------------------------------------------------------------------------
2330
2331#Method void reset()
Cary Clark61313f32018-10-08 14:57:48 -04002332#In Constructors
Cary Clark06c20f32018-03-20 15:53:27 -04002333#Line # sets zero dimensions, kUnknown_SkColorType, kUnknown_SkAlphaType ##
2334Creates an empty Image_Info with kUnknown_SkColorType, kUnknown_SkAlphaType,
2335a width and height of zero, and no Color_Space.
2336
Cary Clark2dc84ad2018-01-26 12:56:22 -05002337#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002338 SkImageInfo info = SkImageInfo::MakeN32Premul(16, 8);
2339 SkImageInfo copy = info;
2340 SkDebugf("info %c= copy\n", info == copy ? '=' : '!');
2341 copy.reset();
2342 SkDebugf("info %c= reset copy\n", info == copy ? '=' : '!');
2343 SkDebugf("SkImageInfo() %c= reset copy\n", SkImageInfo() == copy ? '=' : '!');
2344#StdOut
2345info == copy
2346info != reset copy
2347SkImageInfo() == reset copy
2348##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002349##
2350
Cary Clark06c20f32018-03-20 15:53:27 -04002351#SeeAlso SkImageInfo()
Cary Clark2dc84ad2018-01-26 12:56:22 -05002352
2353#Method ##
2354
2355# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05002356#Subtopic Utility
Cary Clark78de7512018-02-07 07:27:09 -05002357#Line # rarely called management functions ##
2358##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002359
2360#Method void validate() const
Cary Clark78de7512018-02-07 07:27:09 -05002361#In Utility
Cary Clark06c20f32018-03-20 15:53:27 -04002362#Line # asserts if Image_Info is invalid (debug only) ##
Cary Clark682c58d2018-05-16 07:07:07 -04002363Asserts if internal values are illegal or inconsistent. Only available if
Cary Clark06c20f32018-03-20 15:53:27 -04002364SK_DEBUG is defined at compile time.
2365
2366#NoExample
Cary Clark2dc84ad2018-01-26 12:56:22 -05002367##
2368
Cary Clark06c20f32018-03-20 15:53:27 -04002369#SeeAlso validRowBytes SkBitmap::validate
Cary Clark2dc84ad2018-01-26 12:56:22 -05002370
2371#Method ##
2372
2373#Struct SkImageInfo ##
2374
Cary Clark08895c42018-02-01 09:37:32 -05002375#Topic Image_Info ##