blob: 76749b0923aef908a498b34a23659692e48161e5 [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);
Cary Clark1a8d7622018-03-05 13:26:16 -05001476 canvas->drawLine(imageInfo.width() + 10, 0, imageInfo.width() + 10, imageInfo.height(), paint);
Cary Clark92694be2018-10-25 08:15:36 -04001477 canvas->drawString("height", imageInfo.width() + 34, imageInfo.height() / 2, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001478##
1479
Cary Clark1a8d7622018-03-05 13:26:16 -05001480#SeeAlso width SkBitmap::height SkPixelRef::height SkImage::height SkSurface::height
Cary Clark2dc84ad2018-01-26 12:56:22 -05001481
1482#Method ##
1483
1484# ------------------------------------------------------------------------------
1485
1486#Method SkColorType colorType() const
Cary Clark78de7512018-02-07 07:27:09 -05001487#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001488#Line # returns Color_Type ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001489Returns Color_Type, one of: #list_of_color_types#.
1490
1491#Return Color_Type ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001492
1493#Example
Cary Clark681287e2018-03-16 11:34:15 -04001494 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
1495 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
1496 SkImageInfo info = SkImageInfo::MakeA8(16, 32);
1497 SkDebugf("color type: k" "%s" "_SkColorType\n", colors[info.colorType()]);
1498#StdOut
1499color type: kAlpha_8_SkColorType
1500##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001501##
1502
Cary Clark681287e2018-03-16 11:34:15 -04001503#SeeAlso alphaType SkPixmap::colorType SkBitmap::colorType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001504
1505#Method ##
1506
1507# ------------------------------------------------------------------------------
1508
1509#Method SkAlphaType alphaType() const
Cary Clark78de7512018-02-07 07:27:09 -05001510#In Property
Cary Clark682c58d2018-05-16 07:07:07 -04001511#Line # returns Alpha_Type ##
Cary Clark681287e2018-03-16 11:34:15 -04001512Returns Alpha_Type, one of: #list_of_alpha_types#.
1513
1514#Return Alpha_Type ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001515
1516#Example
Cary Clark681287e2018-03-16 11:34:15 -04001517 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
1518 SkImageInfo info = SkImageInfo::MakeA8(16, 32);
1519 SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[info.alphaType()]);
1520#StdOut
1521alpha type: kPremul_SkAlphaType
1522##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001523##
1524
Cary Clark681287e2018-03-16 11:34:15 -04001525#SeeAlso colorType SkPixmap::alphaType SkBitmap::alphaType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001526
1527#Method ##
1528
1529# ------------------------------------------------------------------------------
1530
1531#Method SkColorSpace* colorSpace() const
Cary Clark78de7512018-02-07 07:27:09 -05001532#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001533#Line # returns Color_Space ##
1534Returns Color_Space, the range of colors. The reference count of
1535Color_Space is unchanged. The returned Color_Space is immutable.
1536
1537#Return Color_Space, or nullptr ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001538
1539#Example
Cary Clark681287e2018-03-16 11:34:15 -04001540#Description
1541SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma
1542and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma.
1543##
Cary Clark682c58d2018-05-16 07:07:07 -04001544 SkImageInfo info = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
Cary Clark681287e2018-03-16 11:34:15 -04001545 SkColorSpace::MakeSRGBLinear());
1546 SkColorSpace* colorSpace = info.colorSpace();
1547 SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
1548 colorSpace->gammaCloseToSRGB() ? "true" : "false",
1549 colorSpace->gammaIsLinear() ? "true" : "false",
1550 colorSpace->isSRGB() ? "true" : "false");
1551#StdOut
1552gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
1553##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001554##
1555
Cary Clark681287e2018-03-16 11:34:15 -04001556#SeeAlso Color_Space SkPixmap::colorSpace SkBitmap::colorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001557
1558#Method ##
1559
1560# ------------------------------------------------------------------------------
1561
1562#Method sk_sp<SkColorSpace> refColorSpace() const
Cary Clark78de7512018-02-07 07:27:09 -05001563#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001564#Line # returns Color_Space ##
Cary Clark682c58d2018-05-16 07:07:07 -04001565Returns smart pointer to Color_Space, the range of colors. The smart pointer
Cary Clark681287e2018-03-16 11:34:15 -04001566tracks the number of objects sharing this Color_Space reference so the memory
1567is released when the owners destruct.
1568
1569The returned Color_Space is immutable.
1570
1571#Return Color_Space wrapped in a smart pointer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001572
1573#Example
Cary Clark682c58d2018-05-16 07:07:07 -04001574 SkImageInfo info1 = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
Cary Clark681287e2018-03-16 11:34:15 -04001575 SkColorSpace::MakeSRGBLinear());
1576 SkImageInfo info2 = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
1577 info1.refColorSpace());
1578 SkColorSpace* colorSpace = info2.colorSpace();
1579 SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
1580 colorSpace->gammaCloseToSRGB() ? "true" : "false",
1581 colorSpace->gammaIsLinear() ? "true" : "false",
1582 colorSpace->isSRGB() ? "true" : "false");
Cary Clark2dc84ad2018-01-26 12:56:22 -05001583##
1584
Cary Clark681287e2018-03-16 11:34:15 -04001585#SeeAlso Color_Space SkBitmap::refColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001586
1587#Method ##
1588
1589# ------------------------------------------------------------------------------
1590
1591#Method bool isEmpty() const
Cary Clark78de7512018-02-07 07:27:09 -05001592#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001593#Line # returns if dimensions contain pixels ##
1594
1595Returns if Image_Info describes an empty area of pixels by checking if either
1596width or height is zero or smaller.
1597
1598#Return true if either dimension is zero or smaller ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001599
1600#Example
Cary Clark681287e2018-03-16 11:34:15 -04001601 for (int width : { 0, 2 } ) {
1602 for (int height : { 0, 2 } ) {
1603 SkImageInfo imageInfo= SkImageInfo::MakeA8(width, height);
1604 SkDebugf("width: %d height: %d empty: %s\n", width, height,
1605 imageInfo.isEmpty() ? "true" : "false");
1606 }
1607 }
1608#StdOut
1609width: 0 height: 0 empty: true
1610width: 0 height: 2 empty: true
1611width: 2 height: 0 empty: true
1612width: 2 height: 2 empty: false
1613##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001614##
1615
Cary Clark681287e2018-03-16 11:34:15 -04001616#SeeAlso dimensions bounds SkBitmap::empty SkPixmap::bounds
Cary Clark2dc84ad2018-01-26 12:56:22 -05001617
1618#Method ##
1619
1620# ------------------------------------------------------------------------------
1621
1622#Method bool isOpaque() const
Cary Clark78de7512018-02-07 07:27:09 -05001623#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001624#Line # returns if Alpha_Type is kOpaque_SkAlphaType ##
1625
1626Returns true if Alpha_Type is set to hint that all pixels are opaque; their
1627Color_Alpha value is implicitly or explicitly 1.0. If true, and all pixels are
Cary Clark682c58d2018-05-16 07:07:07 -04001628not opaque, Skia may draw incorrectly.
Cary Clark681287e2018-03-16 11:34:15 -04001629
1630Does not check if Color_Type allows Alpha, or if any pixel value has
1631transparency.
1632
1633#Return true if Alpha_Type is kOpaque_SkAlphaType ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001634
1635#Example
Cary Clark681287e2018-03-16 11:34:15 -04001636 const int height = 2;
1637 const int width = 2;
1638 SkBitmap bitmap;
1639 SkImageInfo imageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType);
1640 bitmap.setInfo(imageInfo);
1641 for (int index = 0; index < 2; ++index) {
1642 bitmap.allocPixels();
1643 bitmap.eraseColor(0x00000000);
1644 SkDebugf("isOpaque: %s\n", imageInfo.isOpaque() ? "true" : "false");
1645 bitmap.eraseColor(0xFFFFFFFF);
1646 SkDebugf("isOpaque: %s\n", imageInfo.isOpaque() ? "true" : "false");
1647 imageInfo = imageInfo.makeAlphaType(kOpaque_SkAlphaType);
1648 bitmap.setInfo(imageInfo);
1649 }
1650#StdOut
1651isOpaque: false
1652isOpaque: false
1653isOpaque: true
1654isOpaque: true
1655##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001656##
1657
Cary Clark681287e2018-03-16 11:34:15 -04001658#SeeAlso Color_Alpha SkColorTypeValidateAlphaType SkBitmap::isOpaque SkImage::isOpaque SkPixmap::isOpaque
Cary Clark2dc84ad2018-01-26 12:56:22 -05001659
1660#Method ##
1661
1662# ------------------------------------------------------------------------------
1663
1664#Method SkISize dimensions() const
Cary Clark78de7512018-02-07 07:27:09 -05001665#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001666#Line # returns width() and height() ##
1667
1668Returns ISize { width(), height() }.
1669
1670#Return integral size of width() and height() ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001671
1672#Example
Cary Clark681287e2018-03-16 11:34:15 -04001673 const int height = 2;
1674 const int width = 2;
1675 SkImageInfo imageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType);
1676 SkISize dimensions = imageInfo.dimensions();
1677 SkIRect bounds = imageInfo.bounds();
1678 SkIRect dimensionsAsBounds = SkIRect::MakeSize(dimensions);
1679 SkDebugf("dimensionsAsBounds %c= bounds\n", dimensionsAsBounds == bounds ? '=' : '!');
1680#StdOut
1681dimensionsAsBounds == bounds
1682##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001683##
1684
Cary Clark681287e2018-03-16 11:34:15 -04001685#SeeAlso width height bounds SkBitmap::dimensions
Cary Clark2dc84ad2018-01-26 12:56:22 -05001686
1687#Method ##
1688
1689# ------------------------------------------------------------------------------
1690
1691#Method SkIRect bounds() const
Cary Clark78de7512018-02-07 07:27:09 -05001692#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001693#Line # returns width() and height() as Rectangle ##
1694Returns IRect { 0, 0, width(), height() }.
1695
1696#Return integral rectangle from origin to width() and height() ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001697
1698#Example
Cary Clark681287e2018-03-16 11:34:15 -04001699#Height 64
1700#Image 4
1701 canvas->scale(.5f, .5f);
1702 SkImageInfo imageInfo = source.info();
1703 SkIRect bounds = imageInfo.bounds();
1704 for (int x : { 0, bounds.width() } ) {
1705 for (int y : { 0, bounds.height() } ) {
1706 canvas->drawBitmap(source, x, y);
1707 }
1708 }
Cary Clark2dc84ad2018-01-26 12:56:22 -05001709##
1710
Cary Clark681287e2018-03-16 11:34:15 -04001711#SeeAlso width height dimensions
Cary Clark2dc84ad2018-01-26 12:56:22 -05001712
1713#Method ##
1714
1715# ------------------------------------------------------------------------------
1716
1717#Method bool gammaCloseToSRGB() const
Cary Clark78de7512018-02-07 07:27:09 -05001718#In Property
Cary Clark682c58d2018-05-16 07:07:07 -04001719#Line # returns if Color_Space gamma is approximately the same as sRGB ##
Cary Clark681287e2018-03-16 11:34:15 -04001720
1721Returns true if associated Color_Space is not nullptr, and Color_Space gamma
Cary Clark682c58d2018-05-16 07:07:07 -04001722is approximately the same as sRGB.
1723This includes the
Cary Clark681287e2018-03-16 11:34:15 -04001724###$
1725$A sRGB transfer function $ https://en.wikipedia.org/wiki/SRGB#The_sRGB_transfer_function_(%22gamma%22) $$
1726$$$#
1727as well as a gamma curve described by a 2.2 exponent.
1728
1729#Return true if Color_Space gamma is approximately the same as sRGB ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001730
1731#Example
Cary Clark681287e2018-03-16 11:34:15 -04001732#Height 144
1733 const int width = 256;
1734 const int height = 64;
1735 auto drawLabel = [=](const char* what, bool closeToSRGB) -> void {
1736 SkString string;
1737 string.printf("%s gamma is %s" "close to sRGB", what, closeToSRGB ? "" : "not ");
1738 SkPaint paint;
1739 paint.setAntiAlias(true);
1740 paint.setTextAlign(SkPaint::kCenter_Align);
1741 canvas->drawString(string, width / 2, 56, paint);
1742 };
1743 SkColor gradColors[] = { 0xFFFF7F00, 0xFF00FF7F, 0xFF0000FF, 0xFF7F7FFF };
1744 SkPoint gradPoints[] = { { 0, 0 }, { width, 0 }, { width * 2, 0 }, { width * 3, 0 } };
1745 SkPaint gradPaint;
1746 gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1747 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1748 canvas->drawRect(SkRect::MakeWH(width, height), gradPaint);
1749 drawLabel("canvas", canvas->imageInfo().gammaCloseToSRGB());
1750 SkBitmap bitmap;
1751 SkImageInfo offscreenInfo = SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType);
1752 bitmap.allocPixels(offscreenInfo);
1753 SkCanvas sRGBOffscreen(bitmap);
1754 sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1755 canvas->translate(0, 80);
1756 canvas->drawBitmap(bitmap, 0, 0);
1757 drawLabel("offscreen", offscreenInfo.gammaCloseToSRGB());
Cary Clark2dc84ad2018-01-26 12:56:22 -05001758##
1759
Cary Clark681287e2018-03-16 11:34:15 -04001760#SeeAlso SkColorSpace::gammaCloseToSRGB
Cary Clark2dc84ad2018-01-26 12:56:22 -05001761
1762#Method ##
1763
1764# ------------------------------------------------------------------------------
1765
1766#Method SkImageInfo makeWH(int newWidth, int newHeight) const
Cary Clark61313f32018-10-08 14:57:48 -04001767#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001768#Line # creates Image_Info with changed dimensions ##
Cary Clark681287e2018-03-16 11:34:15 -04001769Creates Image_Info with the same Color_Type, Color_Space, and Alpha_Type,
1770with dimensions set to width and height.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001771
Cary Clark681287e2018-03-16 11:34:15 -04001772#Param newWidth pixel column count; must be zero or greater ##
1773#Param newHeight pixel row count; must be zero or greater ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001774
Cary Clark681287e2018-03-16 11:34:15 -04001775#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001776
1777#Example
Cary Clark681287e2018-03-16 11:34:15 -04001778#Height 144
1779#Image 3
1780 SkImageInfo canvasImageInfo = canvas->imageInfo();
1781 SkRect canvasBounds = SkRect::Make(canvasImageInfo.bounds());
1782 canvas->drawBitmapRect(source, source.bounds(), canvasBounds, nullptr);
Cary Clark682c58d2018-05-16 07:07:07 -04001783 SkImageInfo insetImageInfo =
Cary Clark681287e2018-03-16 11:34:15 -04001784 canvasImageInfo.makeWH(canvasBounds.width() / 2, canvasBounds.height() / 2);
1785 SkBitmap inset;
1786 inset.allocPixels(insetImageInfo);
1787 SkCanvas offscreen(inset);
1788 offscreen.drawBitmapRect(source, source.bounds(), SkRect::Make(inset.bounds()), nullptr);
1789 canvas->drawBitmap(inset, canvasBounds.width() / 4, canvasBounds.height() / 4);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001790##
1791
Cary Clark682c58d2018-05-16 07:07:07 -04001792#SeeAlso Make makeAlphaType makeColorSpace makeColorType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001793
1794#Method ##
1795
1796# ------------------------------------------------------------------------------
1797
1798#Method SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const
Cary Clark61313f32018-10-08 14:57:48 -04001799#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001800#Line # creates Image_Info with changed Alpha_Type ##
Cary Clark681287e2018-03-16 11:34:15 -04001801Creates Image_Info with same Color_Type, Color_Space, width, and height,
Cary Clark682c58d2018-05-16 07:07:07 -04001802with Alpha_Type set to newAlphaType.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001803
Cary Clark681287e2018-03-16 11:34:15 -04001804Created Image_Info contains newAlphaType even if it is incompatible with
1805Color_Type, in which case Alpha_Type in Image_Info is ignored.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001806
Cary Clark681287e2018-03-16 11:34:15 -04001807#Param newAlphaType one of: #list_of_alpha_types#
Cary Clark2dc84ad2018-01-26 12:56:22 -05001808##
1809
Cary Clark681287e2018-03-16 11:34:15 -04001810#Return created Image_Info ##
1811
1812#Example
1813#Image 3
1814 const int width = 256;
1815 const int height = 128;
1816 SkColor pixels[height][width];
1817 for (int y = 0; y < height; ++y) {
1818 for (int x = 0; x < width; ++x) {
Cary Clark682c58d2018-05-16 07:07:07 -04001819 int red = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 4 + y) * 0.03f)));
1820 int blue = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 3 + y) * 0.04f)));
Cary Clark681287e2018-03-16 11:34:15 -04001821 int green = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 2 + y) * 0.05f)));
1822 int alpha = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 1 + y) * 0.006f)));
Cary Clark682c58d2018-05-16 07:07:07 -04001823 pixels[y][x] =
Cary Clark681287e2018-03-16 11:34:15 -04001824 SkColorSetARGB(alpha, red * alpha / 255, green * alpha / 255, blue * alpha / 255);
1825 }
1826 }
1827 SkBitmap bitmap;
1828 SkImageInfo info = SkImageInfo::Make(width, height, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
1829 bitmap.installPixels(info, (void*) pixels, sizeof(SkColor) * width);
1830 canvas->drawBitmap(source, 0, 0);
1831 canvas->drawBitmap(bitmap, 0, 0);
1832 SkImageInfo unpremulInfo = info.makeAlphaType(kUnpremul_SkAlphaType);
1833 bitmap.installPixels(unpremulInfo, (void*) pixels, sizeof(SkColor) * width);
1834 canvas->drawBitmap(bitmap, 0, 128);
1835##
1836
1837#SeeAlso Make MakeA8 makeColorType makeColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001838
1839#Method ##
1840
1841# ------------------------------------------------------------------------------
1842
1843#Method SkImageInfo makeColorType(SkColorType newColorType) const
Cary Clark61313f32018-10-08 14:57:48 -04001844#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001845#Line # creates Image_Info with changed Color_Type ##
Cary Clark681287e2018-03-16 11:34:15 -04001846Creates Image_Info with same Alpha_Type, Color_Space, width, and height,
1847with Color_Type set to newColorType.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001848
Cary Clark681287e2018-03-16 11:34:15 -04001849#Param newColorType one of: #list_of_color_types#
Cary Clark2dc84ad2018-01-26 12:56:22 -05001850##
1851
Cary Clark681287e2018-03-16 11:34:15 -04001852#Return created Image_Info ##
1853
1854#Example
1855 const int width = 256;
1856 const int height = 128;
1857 SkColor pixels[height][width];
1858 for (int y = 0; y < height; ++y) {
1859 for (int x = 0; x < width; ++x) {
Cary Clark682c58d2018-05-16 07:07:07 -04001860 int red = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 4 + y) * 0.03f)));
1861 int blue = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 3 + y) * 0.04f)));
Cary Clark681287e2018-03-16 11:34:15 -04001862 int green = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 2 + y) * 0.05f)));
1863 int alpha = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 1 + y) * 0.006f)));
Cary Clark682c58d2018-05-16 07:07:07 -04001864 pixels[y][x] =
Cary Clark681287e2018-03-16 11:34:15 -04001865 SkColorSetARGB(alpha, red * alpha / 255, green * alpha / 255, blue * alpha / 255);
1866 }
1867 }
1868 SkBitmap bitmap;
1869 SkImageInfo info = SkImageInfo::Make(width, height, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
1870 bitmap.installPixels(info, (void*) pixels, sizeof(SkColor) * width);
1871 canvas->drawBitmap(source, 0, 0);
1872 canvas->drawBitmap(bitmap, 0, 0);
1873 SkImageInfo rgbaInfo = info.makeColorType(kRGBA_8888_SkColorType);
1874 bitmap.installPixels(rgbaInfo, (void*) pixels, sizeof(SkColor) * width);
1875 canvas->drawBitmap(bitmap, 0, 128);
1876##
1877
1878#SeeAlso Make makeAlphaType makeColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001879
1880#Method ##
1881
1882# ------------------------------------------------------------------------------
1883
1884#Method SkImageInfo makeColorSpace(sk_sp<SkColorSpace> cs) const
Cary Clark61313f32018-10-08 14:57:48 -04001885#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001886#Line # creates Image_Info with changed Color_Space ##
Cary Clark681287e2018-03-16 11:34:15 -04001887Creates Image_Info with same Alpha_Type, Color_Type, width, and height,
1888with Color_Space set to cs.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001889
Cary Clark681287e2018-03-16 11:34:15 -04001890#Param cs range of colors; may be nullptr ##
1891
1892#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001893
1894#Example
Cary Clark681287e2018-03-16 11:34:15 -04001895#Height 224
1896 const int width = 256;
1897 const int height = 64;
1898 auto drawLabel = [=](const char* what, bool closeToSRGB) -> void {
1899 SkString string;
1900 string.printf("%s gamma is %s" "close to sRGB", what, closeToSRGB ? "" : "not ");
1901 SkPaint paint;
1902 paint.setAntiAlias(true);
1903 paint.setTextAlign(SkPaint::kCenter_Align);
1904 canvas->drawString(string, width / 2, 56, paint);
1905 };
1906 SkColor gradColors[] = { 0xFFFF7F00, 0xFF00FF7F, 0xFF0000FF, 0xFF7F7FFF };
1907 SkPoint gradPoints[] = { { 0, 0 }, { width, 0 }, { width * 2, 0 }, { width * 3, 0 } };
1908 SkPaint gradPaint;
1909 gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1910 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1911 canvas->drawRect(SkRect::MakeWH(width, height), gradPaint);
1912 drawLabel("canvas", canvas->imageInfo().gammaCloseToSRGB());
1913 SkBitmap bitmap;
1914 SkImageInfo offscreenInfo = SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType);
1915 bitmap.allocPixels(offscreenInfo);
1916 SkCanvas sRGBOffscreen(bitmap);
1917 sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1918 canvas->translate(0, 80);
1919 canvas->drawBitmap(bitmap, 0, 0);
1920 drawLabel("offscreen", offscreenInfo.gammaCloseToSRGB());
1921 SkImageInfo linearGamma =
1922 offscreenInfo.makeColorSpace(offscreenInfo.colorSpace()->makeLinearGamma());
1923 bitmap.allocPixels(linearGamma);
1924 SkCanvas lgOffscreen(bitmap);
1925 lgOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1926 canvas->translate(0, 80);
1927 canvas->drawBitmap(bitmap, 0, 0);
1928 drawLabel("linear", linearGamma.gammaCloseToSRGB());
Cary Clark2dc84ad2018-01-26 12:56:22 -05001929##
1930
Cary Clark681287e2018-03-16 11:34:15 -04001931#SeeAlso Make MakeS32 makeAlphaType makeColorType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001932
1933#Method ##
1934
1935# ------------------------------------------------------------------------------
1936
1937#Method int bytesPerPixel() const
Cary Clark78de7512018-02-07 07:27:09 -05001938#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001939#Line # returns number of bytes in pixel based on Color_Type ##
1940Returns number of bytes per pixel required by Color_Type.
1941Returns zero if colorType( is kUnknown_SkColorType.
1942
1943#Return bytes in pixel ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001944
1945#Example
Cary Clark681287e2018-03-16 11:34:15 -04001946 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
1947 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
1948 for (SkColorType colorType : { #list_of_color_types#
1949 } ) {
1950 SkImageInfo info = SkImageInfo::Make(1, 1, colorType, kOpaque_SkAlphaType);
1951 SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d\n",
1952 colors[colorType], 13 - strlen(colors[colorType]), " ",
1953 info.bytesPerPixel());
1954 }
1955#StdOut
1956color: kUnknown_SkColorType bytesPerPixel: 0
1957color: kAlpha_8_SkColorType bytesPerPixel: 1
1958color: kRGB_565_SkColorType bytesPerPixel: 2
1959color: kARGB_4444_SkColorType bytesPerPixel: 2
1960color: kRGBA_8888_SkColorType bytesPerPixel: 4
1961color: kRGB_888x_SkColorType bytesPerPixel: 4
1962color: kBGRA_8888_SkColorType bytesPerPixel: 4
1963color: kRGBA_1010102_SkColorType bytesPerPixel: 4
1964color: kRGB_101010x_SkColorType bytesPerPixel: 4
1965color: kGray_8_SkColorType bytesPerPixel: 1
1966color: kRGBA_F16_SkColorType bytesPerPixel: 8
1967##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001968##
1969
Cary Clark681287e2018-03-16 11:34:15 -04001970#SeeAlso width shiftPerPixel SkBitmap::bytesPerPixel
Cary Clark2dc84ad2018-01-26 12:56:22 -05001971
1972#Method ##
1973
1974# ------------------------------------------------------------------------------
1975
1976#Method int shiftPerPixel() const
Cary Clark78de7512018-02-07 07:27:09 -05001977#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001978#Line # returns bit shift from pixels to bytes ##
1979Returns bit shift converting row bytes to row pixels.
1980Returns zero for kUnknown_SkColorType.
1981
1982#Return one of: 0, 1, 2, 3; left shift to convert pixels to bytes ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001983
1984#Example
Cary Clark681287e2018-03-16 11:34:15 -04001985 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
1986 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
1987 for (SkColorType colorType : { #list_of_color_types#
1988 } ) {
1989 SkImageInfo info = SkImageInfo::Make(1, 1, colorType, kOpaque_SkAlphaType);
1990 SkDebugf("color: k" "%s" "_SkColorType" "%*s" "shiftPerPixel: %d\n",
1991 colors[colorType], 14 - strlen(colors[colorType]), " ",
1992 info.shiftPerPixel());
1993 }
1994#StdOut
1995color: kUnknown_SkColorType shiftPerPixel: 0
1996color: kAlpha_8_SkColorType shiftPerPixel: 0
1997color: kRGB_565_SkColorType shiftPerPixel: 1
1998color: kARGB_4444_SkColorType shiftPerPixel: 1
1999color: kRGBA_8888_SkColorType shiftPerPixel: 2
2000color: kRGB_888x_SkColorType shiftPerPixel: 2
2001color: kBGRA_8888_SkColorType shiftPerPixel: 2
2002color: kRGBA_1010102_SkColorType shiftPerPixel: 2
2003color: kRGB_101010x_SkColorType shiftPerPixel: 2
2004color: kGray_8_SkColorType shiftPerPixel: 0
2005color: kRGBA_F16_SkColorType shiftPerPixel: 3
2006##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002007##
2008
Cary Clark06c20f32018-03-20 15:53:27 -04002009#SeeAlso bytesPerPixel minRowBytes SkBitmap::shiftPerPixel SkPixmap::shiftPerPixel
Cary Clark2dc84ad2018-01-26 12:56:22 -05002010
2011#Method ##
2012
2013# ------------------------------------------------------------------------------
2014
2015#Method uint64_t minRowBytes64() const
Cary Clark78de7512018-02-07 07:27:09 -05002016#In Property
Cary Clark681287e2018-03-16 11:34:15 -04002017#Line # returns width() times bytesPerPixel in 64 bits ##
2018
2019Returns minimum bytes per row, computed from pixel width() and Color_Type, which
Cary Clark682c58d2018-05-16 07:07:07 -04002020specifies bytesPerPixel(). Bitmap maximum value for row bytes must fit
2021in 31 bits.
Cary Clark681287e2018-03-16 11:34:15 -04002022
2023#Return width() times bytesPerPixel as unsigned 64-bit integer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002024
2025#Example
Cary Clark681287e2018-03-16 11:34:15 -04002026 for (int shift = 24; shift < 32; ++shift) {
2027 int width = 1 << shift;
Cary Clark682c58d2018-05-16 07:07:07 -04002028 SkImageInfo imageInfo =
Cary Clark681287e2018-03-16 11:34:15 -04002029 SkImageInfo::Make(width, 1, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
2030 uint64_t minRowBytes = imageInfo.minRowBytes64();
2031 bool widthTooLarge = (uint64_t) (int32_t) minRowBytes != minRowBytes;
2032 SkDebugf("RGBA_F16 width %d (0x%08x) %s\n",
Cary Clark682c58d2018-05-16 07:07:07 -04002033 width, width, widthTooLarge ? "too large" : "OK");
Cary Clark681287e2018-03-16 11:34:15 -04002034 }
2035#StdOut
2036RGBA_F16 width 16777216 (0x01000000) OK
2037RGBA_F16 width 33554432 (0x02000000) OK
2038RGBA_F16 width 67108864 (0x04000000) OK
2039RGBA_F16 width 134217728 (0x08000000) OK
2040RGBA_F16 width 268435456 (0x10000000) too large
2041RGBA_F16 width 536870912 (0x20000000) too large
2042RGBA_F16 width 1073741824 (0x40000000) too large
2043RGBA_F16 width -2147483648 (0x80000000) too large
2044##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002045##
2046
Cary Clark681287e2018-03-16 11:34:15 -04002047#SeeAlso minRowBytes computeByteSize computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002048
2049#Method ##
2050
2051# ------------------------------------------------------------------------------
2052
2053#Method size_t minRowBytes() const
Cary Clark78de7512018-02-07 07:27:09 -05002054#In Property
Cary Clark681287e2018-03-16 11:34:15 -04002055#Line # returns width() times bytesPerPixel in 32 bits ##
2056
2057Returns minimum bytes per row, computed from pixel width() and Color_Type, which
Cary Clark682c58d2018-05-16 07:07:07 -04002058specifies bytesPerPixel(). Bitmap maximum value for row bytes must fit
2059in 31 bits.
Cary Clark681287e2018-03-16 11:34:15 -04002060
2061#Return width() times bytesPerPixel as signed 32-bit integer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002062
2063#Example
Cary Clark681287e2018-03-16 11:34:15 -04002064 for (int shift = 24; shift < 32; ++shift) {
2065 int width = 1 << shift;
Cary Clark682c58d2018-05-16 07:07:07 -04002066 SkImageInfo imageInfo =
Cary Clark681287e2018-03-16 11:34:15 -04002067 SkImageInfo::Make(width, 1, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
2068 size_t minRowBytes = imageInfo.minRowBytes();
2069 bool widthTooLarge = !minRowBytes;
2070 SkDebugf("RGBA_F16 width %d (0x%08x) %s\n",
Cary Clark682c58d2018-05-16 07:07:07 -04002071 width, width, widthTooLarge ? "too large" : "OK");
Cary Clark681287e2018-03-16 11:34:15 -04002072 }
2073#StdOut
2074RGBA_F16 width 16777216 (0x01000000) OK
2075RGBA_F16 width 33554432 (0x02000000) OK
2076RGBA_F16 width 67108864 (0x04000000) OK
2077RGBA_F16 width 134217728 (0x08000000) OK
2078RGBA_F16 width 268435456 (0x10000000) too large
2079RGBA_F16 width 536870912 (0x20000000) too large
2080RGBA_F16 width 1073741824 (0x40000000) too large
2081RGBA_F16 width -2147483648 (0x80000000) too large
2082##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002083##
2084
Cary Clark681287e2018-03-16 11:34:15 -04002085#SeeAlso minRowBytes64 computeByteSize computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002086
2087#Method ##
2088
2089# ------------------------------------------------------------------------------
2090
2091#Method size_t computeOffset(int x, int y, size_t rowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05002092#In Utility
Cary Clark681287e2018-03-16 11:34:15 -04002093#Line # returns byte offset within pixel array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002094
Cary Clark681287e2018-03-16 11:34:15 -04002095Returns byte offset of pixel from pixel base address.
2096
2097Asserts in debug build if x or y is outside of bounds. Does not assert if
2098rowBytes is smaller than minRowBytes, even though result may be incorrect.
2099
2100#Param x column index, zero or greater, and less than width() ##
2101#Param y row index, zero or greater, and less than height() ##
2102#Param rowBytes size of pixel row or larger ##
2103
2104#Return offset within pixel array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002105
2106#Example
Cary Clark06c20f32018-03-20 15:53:27 -04002107#Height 128
Cary Clark681287e2018-03-16 11:34:15 -04002108 uint8_t pixels[][12] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00},
2109 { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00},
2110 { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00},
2111 { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF},
2112 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
2113 { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00},
2114 { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00},
2115 { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00} };
2116 SkImageInfo imageInfo = SkImageInfo::MakeA8(8, 8);
2117 SkBitmap bitmap;
2118 bitmap.installPixels(imageInfo, (void*) pixels, sizeof(pixels[0]));
2119 SkPaint paint;
2120 paint.setColor(SK_ColorRED);
2121 canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint);
2122 size_t offset = imageInfo.computeOffset(2, 3, sizeof(pixels[0]));
2123 pixels[0][offset] = 0x7F;
2124 offset = imageInfo.computeOffset(5, 3, sizeof(pixels[0]));
2125 pixels[0][offset] = 0x7F;
2126 bitmap.installPixels(imageInfo, (void*) pixels, sizeof(pixels[0]));
2127 canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(128, 128), &paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05002128##
2129
Cary Clark06c20f32018-03-20 15:53:27 -04002130#SeeAlso height width minRowBytes computeByteSize
Cary Clark2dc84ad2018-01-26 12:56:22 -05002131
2132#Method ##
2133
2134# ------------------------------------------------------------------------------
2135
2136#Method bool operator==(const SkImageInfo& other)_const
Cary Clark06c20f32018-03-20 15:53:27 -04002137#Line # compares Image_Info for equality ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002138
Cary Clark06c20f32018-03-20 15:53:27 -04002139Compares Image_Info with other, and returns true if width, height, Color_Type,
2140Alpha_Type, and Color_Space are equivalent.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002141
Cary Clark06c20f32018-03-20 15:53:27 -04002142#Param other Image_Info to compare ##
2143
2144#Return true if Image_Info equals other ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002145
2146#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002147 SkImageInfo info1 = SkImageInfo::Make(10, 20, kGray_8_SkColorType, kPremul_SkAlphaType);
2148 SkImageInfo info2 = SkImageInfo::Make(20, 10, kAlpha_8_SkColorType, kUnpremul_SkAlphaType);
2149 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
2150 info2 = info2.makeWH(10, 20);
2151 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
2152 info2 = info2.makeColorType(kGray_8_SkColorType);
2153 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
2154 info2 = info2.makeAlphaType(kPremul_SkAlphaType);
2155 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
2156#StdOut
2157info1 != info2
2158info1 != info2
2159info1 != info2
2160info1 == info2
2161##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002162##
2163
Cary Clark06c20f32018-03-20 15:53:27 -04002164#SeeAlso operator!=(const SkImageInfo& other)_const SkColorSpace::Equals
Cary Clark2dc84ad2018-01-26 12:56:22 -05002165
2166#Method ##
2167
2168# ------------------------------------------------------------------------------
2169
2170#Method bool operator!=(const SkImageInfo& other)_const
Cary Clark06c20f32018-03-20 15:53:27 -04002171#Line # compares Image_Info for inequality ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002172
Cary Clark06c20f32018-03-20 15:53:27 -04002173Compares Image_Info with other, and returns true if width, height, Color_Type,
Cary Clarkffb3d682018-05-17 12:17:28 -04002174Alpha_Type, and Color_Space are not equivalent.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002175
Cary Clark06c20f32018-03-20 15:53:27 -04002176#Param other Image_Info to compare ##
2177
2178#Return true if Image_Info is not equal to other ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002179
2180#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002181 SkImageInfo info1 = SkImageInfo::Make(10, 20, kGray_8_SkColorType, kPremul_SkAlphaType);
2182 SkImageInfo info2 = SkImageInfo::Make(20, 10, kAlpha_8_SkColorType, kUnpremul_SkAlphaType);
2183 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
2184 info2 = info2.makeWH(10, 20);
2185 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
2186 info2 = info2.makeColorType(kGray_8_SkColorType);
2187 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
2188 info2 = info2.makeAlphaType(kPremul_SkAlphaType);
2189 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
2190#StdOut
2191info1 != info2
2192info1 != info2
2193info1 != info2
2194info1 == info2
2195##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002196##
2197
Cary Clark06c20f32018-03-20 15:53:27 -04002198#SeeAlso operator==(const SkImageInfo& other)_const SkColorSpace::Equals
Cary Clark2dc84ad2018-01-26 12:56:22 -05002199
2200#Method ##
2201
2202# ------------------------------------------------------------------------------
2203
2204#Method size_t computeByteSize(size_t rowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05002205#In Utility
Cary Clark682c58d2018-05-16 07:07:07 -04002206#Line # returns memory required by pixel buffer with given row bytes ##
Cary Clark06c20f32018-03-20 15:53:27 -04002207Returns storage required by pixel array, given Image_Info dimensions, Color_Type,
2208and rowBytes. rowBytes is assumed to be at least as large as minRowBytes().
Cary Clark2dc84ad2018-01-26 12:56:22 -05002209
Cary Clark06c20f32018-03-20 15:53:27 -04002210Returns zero if height is zero.
Cary Clark63132862018-06-18 07:26:34 -04002211Returns SIZE_MAX if answer exceeds the range of size_t.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002212
Cary Clark06c20f32018-03-20 15:53:27 -04002213#Param rowBytes size of pixel row or larger ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002214
Cary Clark06c20f32018-03-20 15:53:27 -04002215#Return memory required by pixel buffer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002216
2217#Example
Cary Clark06c20f32018-03-20 15:53:27 -04002218#Height 130
Cary Clark682c58d2018-05-16 07:07:07 -04002219 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2);
2220 const size_t size = info.computeByteSize(100000);
2221 SkAutoTMalloc<SkPMColor> storage(size);
2222 SkPMColor* pixels = storage.get();
2223 SkBitmap bitmap;
2224 bitmap.setInfo(info);
2225 bitmap.setPixels(pixels);
2226 bitmap.eraseColor(SK_ColorRED);
2227 canvas->scale(50, 50);
2228 canvas->rotate(8);
Cary Clark06c20f32018-03-20 15:53:27 -04002229 canvas->drawBitmap(bitmap, 2, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05002230##
2231
Cary Clark06c20f32018-03-20 15:53:27 -04002232#SeeAlso computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002233
2234#Method ##
2235
2236# ------------------------------------------------------------------------------
2237
2238#Method size_t computeMinByteSize() const
Cary Clark78de7512018-02-07 07:27:09 -05002239#In Utility
Cary Clark682c58d2018-05-16 07:07:07 -04002240#Line # returns least memory required by pixel buffer ##
2241Returns storage required by pixel array, given Image_Info dimensions, and
Cary Clark06c20f32018-03-20 15:53:27 -04002242Color_Type. Uses minRowBytes() to compute bytes for pixel row.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002243
Cary Clark06c20f32018-03-20 15:53:27 -04002244Returns zero if height is zero.
Cary Clark63132862018-06-18 07:26:34 -04002245Returns SIZE_MAX if answer exceeds the range of size_t.
Cary Clark06c20f32018-03-20 15:53:27 -04002246
2247#Return least memory required by pixel buffer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002248
2249#Example
Cary Clark06c20f32018-03-20 15:53:27 -04002250#Height 130
Cary Clark682c58d2018-05-16 07:07:07 -04002251 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2);
2252 const size_t size = info.computeMinByteSize();
2253 SkAutoTMalloc<SkPMColor> storage(size);
2254 SkPMColor* pixels = storage.get();
2255 SkBitmap bitmap;
2256 bitmap.setInfo(info);
2257 bitmap.setPixels(pixels);
2258 bitmap.eraseColor(SK_ColorRED);
2259 canvas->scale(50, 50);
2260 canvas->rotate(8);
Cary Clark06c20f32018-03-20 15:53:27 -04002261 canvas->drawBitmap(bitmap, 2, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05002262##
2263
Cary Clark06c20f32018-03-20 15:53:27 -04002264#SeeAlso computeByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002265
2266#Method ##
2267
2268# ------------------------------------------------------------------------------
2269
2270#Method static bool ByteSizeOverflowed(size_t byteSize)
Cary Clark78de7512018-02-07 07:27:09 -05002271#In Utility
Cary Clark06c20f32018-03-20 15:53:27 -04002272#Line # checks result of computeByteSize and computeMinByteSize ##
Cary Clark63132862018-06-18 07:26:34 -04002273Returns true if byteSize equals SIZE_MAX. computeByteSize and
2274computeMinByteSize return SIZE_MAX if size_t can not hold buffer size.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002275
Cary Clark06c20f32018-03-20 15:53:27 -04002276#Param byteSize result of computeByteSize or computeMinByteSize ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002277
Cary Clark06c20f32018-03-20 15:53:27 -04002278#Return true if computeByteSize or computeMinByteSize result exceeds size_t ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002279
2280#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002281 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 1000000000);
2282 for (size_t rowBytes = 100000000; rowBytes < 10000000000000LL; rowBytes *= 10) {
2283 const size_t size = info.computeByteSize(rowBytes);
2284 SkDebugf("rowBytes:%llu size:%llu overflowed:%s\n", rowBytes, size,
2285 SkImageInfo::ByteSizeOverflowed(size) ? "true" : "false");
2286 }
2287#StdOut
2288rowBytes:100000000 size:99999999900000008 overflowed:false
2289rowBytes:1000000000 size:999999999000000008 overflowed:false
2290rowBytes:10000000000 size:9999999990000000008 overflowed:false
2291rowBytes:100000000000 size:18446744073709551615 overflowed:true
2292rowBytes:1000000000000 size:18446744073709551615 overflowed:true
2293##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002294##
2295
Cary Clark06c20f32018-03-20 15:53:27 -04002296#SeeAlso computeByteSize computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002297
2298#Method ##
2299
2300# ------------------------------------------------------------------------------
2301
2302#Method bool validRowBytes(size_t rowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05002303#In Utility
Cary Clark06c20f32018-03-20 15:53:27 -04002304#Line # checks if row bytes is large enough to contain pixel row ##
2305Returns true if rowBytes is smaller than width times pixel size.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002306
Cary Clark06c20f32018-03-20 15:53:27 -04002307#Param rowBytes size of pixel row or larger ##
2308
2309#Return true if rowBytes is large enough to contain pixel row ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002310
2311#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002312 SkImageInfo info = SkImageInfo::MakeN32Premul(16, 8);
2313 for (size_t rowBytes = 60; rowBytes < 72; rowBytes += sizeof(SkPMColor)) {
2314 SkDebugf("validRowBytes(%llu): %s\n", rowBytes, info.validRowBytes(rowBytes) ?
2315 "true" : "false");
2316 }
2317#StdOut
2318validRowBytes(60): false
2319validRowBytes(64): true
2320validRowBytes(68): true
2321##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002322##
2323
Cary Clark06c20f32018-03-20 15:53:27 -04002324#SeeAlso ByteSizeOverflowed computeByteSize computeMinByteSize
Cary Clark2dc84ad2018-01-26 12:56:22 -05002325
2326#Method ##
2327
2328# ------------------------------------------------------------------------------
2329
2330#Method void reset()
Cary Clark61313f32018-10-08 14:57:48 -04002331#In Constructors
Cary Clark06c20f32018-03-20 15:53:27 -04002332#Line # sets zero dimensions, kUnknown_SkColorType, kUnknown_SkAlphaType ##
2333Creates an empty Image_Info with kUnknown_SkColorType, kUnknown_SkAlphaType,
2334a width and height of zero, and no Color_Space.
2335
Cary Clark2dc84ad2018-01-26 12:56:22 -05002336#Example
Cary Clark682c58d2018-05-16 07:07:07 -04002337 SkImageInfo info = SkImageInfo::MakeN32Premul(16, 8);
2338 SkImageInfo copy = info;
2339 SkDebugf("info %c= copy\n", info == copy ? '=' : '!');
2340 copy.reset();
2341 SkDebugf("info %c= reset copy\n", info == copy ? '=' : '!');
2342 SkDebugf("SkImageInfo() %c= reset copy\n", SkImageInfo() == copy ? '=' : '!');
2343#StdOut
2344info == copy
2345info != reset copy
2346SkImageInfo() == reset copy
2347##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002348##
2349
Cary Clark06c20f32018-03-20 15:53:27 -04002350#SeeAlso SkImageInfo()
Cary Clark2dc84ad2018-01-26 12:56:22 -05002351
2352#Method ##
2353
2354# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05002355#Subtopic Utility
Cary Clark78de7512018-02-07 07:27:09 -05002356#Line # rarely called management functions ##
2357##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002358
2359#Method void validate() const
Cary Clark78de7512018-02-07 07:27:09 -05002360#In Utility
Cary Clark06c20f32018-03-20 15:53:27 -04002361#Line # asserts if Image_Info is invalid (debug only) ##
Cary Clark682c58d2018-05-16 07:07:07 -04002362Asserts if internal values are illegal or inconsistent. Only available if
Cary Clark06c20f32018-03-20 15:53:27 -04002363SK_DEBUG is defined at compile time.
2364
2365#NoExample
Cary Clark2dc84ad2018-01-26 12:56:22 -05002366##
2367
Cary Clark06c20f32018-03-20 15:53:27 -04002368#SeeAlso validRowBytes SkBitmap::validate
Cary Clark2dc84ad2018-01-26 12:56:22 -05002369
2370#Method ##
2371
2372#Struct SkImageInfo ##
2373
Cary Clark08895c42018-02-01 09:37:32 -05002374#Topic Image_Info ##