blob: 516de4e35f5ac8adc6c876cfb6068cb900688648 [file] [log] [blame]
Cary Clark2dc84ad2018-01-26 12:56:22 -05001#Topic Image_Info
2#Alias Image_Info_Reference
3
Cary Clarkf895a422018-02-27 09:54:21 -05004Image_Info specifies the dimensions and encoding of the pixels in a Bitmap.
5The dimensions are integral width and height. The encoding is how pixel
6bits describe Color_Alpha, transparency; Color components red, blue,
7and green; and Color_Space, the range and linearity of colors.
8
9Image_Info describes an uncompressed raster pixels. In contrast, Image
10additionally describes compressed pixels like PNG, and Surface describes
11destinations on the GPU. Image and Surface may be specified by Image_Info,
12but Image and Surface may not contain Image_Info.
13
Cary Clark08895c42018-02-01 09:37:32 -050014#Subtopic Overview
Cary Clark4855f782018-02-06 09:41:53 -050015 #Subtopic Subtopic
Cary Clark08895c42018-02-01 09:37:32 -050016 #Populate
17 ##
Cary Clark2dc84ad2018-01-26 12:56:22 -050018##
19
Cary Clark4855f782018-02-06 09:41:53 -050020#Subtopic Constant
Cary Clark08895c42018-02-01 09:37:32 -050021#Populate
22##
Cary Clark2dc84ad2018-01-26 12:56:22 -050023
24# ------------------------------------------------------------------------------
Cary Clark08895c42018-02-01 09:37:32 -050025#Subtopic Alpha_Type
Cary Clarkf895a422018-02-27 09:54:21 -050026#Line # encoding for pixel transparency ##
Cary Clark2dc84ad2018-01-26 12:56:22 -050027#Alias Alpha_Type
28#Alias Alpha_Types
Cary Clarkf895a422018-02-27 09:54:21 -050029
Cary Clark681287e2018-03-16 11:34:15 -040030#PhraseDef list_of_alpha_types
31kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
32kUnpremul_SkAlphaType
33##
34
Cary Clark2dc84ad2018-01-26 12:56:22 -050035#Enum SkAlphaType
Cary Clarkf895a422018-02-27 09:54:21 -050036#Line # encoding for pixel transparency ##
Cary Clark2dc84ad2018-01-26 12:56:22 -050037
38#Code
39 enum SkAlphaType {
40 kUnknown_SkAlphaType,
41 kOpaque_SkAlphaType,
42 kPremul_SkAlphaType,
43 kUnpremul_SkAlphaType,
44 kLastEnum_SkAlphaType = kUnpremul_SkAlphaType,
45 };
46##
47
Cary Clarkf895a422018-02-27 09:54:21 -050048Describes how to interpret the alpha component of a pixel. A pixel may
49be opaque, or Color_Alpha, describing multiple levels of transparency.
50
51In simple blending, Color_Alpha weights the draw color and the destination
52color to create a new color. If alpha describes a weight from zero to one:
53
54#Formula
55 new color = draw color * alpha + destination color * (1 - alpha)
56##
57
58In practice alpha is encoded in two or more bits, where 1.0 equals all bits set.
59
60Color_RGB may have Color_Alpha included in each component value; the stored
61value is the original Color_RGB multiplied by Color_Alpha. Premultiplied color
62components improve performance.
Cary Clark2dc84ad2018-01-26 12:56:22 -050063
64#Const kUnknown_SkAlphaType 0
Cary Clarkf895a422018-02-27 09:54:21 -050065Alpha_Type is uninitialized.
Cary Clark2dc84ad2018-01-26 12:56:22 -050066##
67#Const kOpaque_SkAlphaType 1
Cary Clarkf895a422018-02-27 09:54:21 -050068Pixels are opaque. The Color_Type must have no explicit alpha
69component, or all alpha components must be set to their maximum value.
Cary Clark2dc84ad2018-01-26 12:56:22 -050070##
71#Const kPremul_SkAlphaType 2
Cary Clarkf895a422018-02-27 09:54:21 -050072Pixels have alpha premultiplied into color components.
73Surface pixels must be premultiplied.
Cary Clark2dc84ad2018-01-26 12:56:22 -050074##
75#Const kUnpremul_SkAlphaType 3
Cary Clarkf895a422018-02-27 09:54:21 -050076Pixel color component values are independent of alpha value.
77Images generated from encoded data like PNG do not premultiply pixel color
78components. kUnpremul_SkAlphaType is supported for Image pixels, but not for
79Surface pixels.
Cary Clark2dc84ad2018-01-26 12:56:22 -050080##
81
Cary Clarkf895a422018-02-27 09:54:21 -050082#NoExample
Cary Clark2dc84ad2018-01-26 12:56:22 -050083##
84
Cary Clarkf895a422018-02-27 09:54:21 -050085#SeeAlso SkColorType SkColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -050086
87#Enum SkAlphaType ##
Cary Clarkf895a422018-02-27 09:54:21 -050088
89#Subtopic Opaque
90
91Use Opaque as a hint to optimize drawing when alpha component
92of all pixel is set to its maximum value of 1.0; all alpha component bits are set.
93If Image_Info is set to Opaque but all alpha values are not 1.0, results are
94undefined.
95
96#Example
97#Height 64
98#Description
99SkPreMultiplyARGB parameter a is set to 255, its maximum value, and is interpreted
100as Color_Alpha of 1.0. kOpaque_SkAlphaType may be set to improve performance.
101If SkPreMultiplyARGB parameter a is set to a value smaller than 255,
102kPremul_SkAlphaType must be used instead to avoid undefined results.
103The four displayed values are the original component values, though not necessarily
104in the same order.
105##
106 SkPMColor color = SkPreMultiplyARGB(255, 50, 100, 150);
107 SkString s;
108 s.printf("%u %u %u %u", SkColorGetA(color), SkColorGetR(color),
109 SkColorGetG(color), SkColorGetB(color));
110 SkPaint paint;
111 paint.setAntiAlias(true);
112 canvas->drawString(s, 10, 62, paint);
113 canvas->scale(50, 50);
114 SkBitmap bitmap;
115 SkImageInfo imageInfo = SkImageInfo::Make(1, 1, kN32_SkColorType, kOpaque_SkAlphaType);
116 if (bitmap.installPixels(imageInfo, (void*) &color, imageInfo.minRowBytes())) {
117 canvas->drawBitmap(bitmap, 0, 0);
118 }
119##
120
121#Subtopic Opaque ##
122
123#Subtopic Premul
124
125Use Premul when stored color components are the original color multiplied by the
126alpha component. The alpha component range of 0.0 to 1.0 is achieved by dividing
127the integer bit value by the maximum bit value.
128
129#Formula
130stored color = original color * alpha / max alpha
131##
132
133The color component must be equal to or smaller than the alpha component,
134or the results are undefined.
135
136#Example
137#Description
138SkPreMultiplyARGB parameter a is set to 150, less than its maximum value, and is
139interpreted as Color_Alpha of about 0.6. kPremul_SkAlphaType must be set, since
140SkPreMultiplyARGB parameter a is set to a value smaller than 255,
141to avoid undefined results.
142The four displayed values reflect that the alpha component has been multiplied
143by the original color.
144##
145#Height 64
146 SkPMColor color = SkPreMultiplyARGB(150, 50, 100, 150);
147 SkString s;
148 s.printf("%u %u %u %u", SkColorGetA(color), SkColorGetR(color),
149 SkColorGetG(color), SkColorGetB(color));
150 SkPaint paint;
151 paint.setAntiAlias(true);
152 canvas->drawString(s, 10, 62, paint);
153 canvas->scale(50, 50);
154 SkBitmap bitmap;
155 SkImageInfo imageInfo = SkImageInfo::Make(1, 1, kN32_SkColorType, kPremul_SkAlphaType);
156 if (bitmap.installPixels(imageInfo, (void*) &color, imageInfo.minRowBytes())) {
157 canvas->drawBitmap(bitmap, 0, 0);
158 }
159##
160
161#Subtopic Premul ##
162
163#Subtopic Unpremul
164
165Use Unpremul if stored color components are not divided by the alpha component.
166Some drawing destinations may not support Unpremul.
167
168#Bug 7079
169#Example
Cary Clark681287e2018-03-16 11:34:15 -0400170#Height 64
Cary Clarkf895a422018-02-27 09:54:21 -0500171#Description
172SkColorSetARGB parameter a is set to 150, less than its maximum value, and is
173interpreted as Color_Alpha of about 0.6. color is not premultiplied;
174color components may have values greater than color alpha.
175The four displayed values are the original component values, though not necessarily
176in the same order.
177##
178 SkColor color = SkColorSetARGB(150, 50, 100, 255);
179 SkString s;
180 s.printf("%u %u %u %u", SkColorGetA(color), SkColorGetR(color),
181 SkColorGetG(color), SkColorGetB(color));
182 SkPaint paint;
183 paint.setAntiAlias(true);
184 canvas->drawString(s, 10, 62, paint);
185 canvas->scale(50, 50);
186 SkBitmap bitmap;
187 SkImageInfo imageInfo = SkImageInfo::Make(1, 1, kN32_SkColorType, kUnpremul_SkAlphaType);
188 if (bitmap.installPixels(imageInfo, (void*) &color, imageInfo.minRowBytes())) {
189 canvas->drawBitmap(bitmap, 0, 0);
190 }
191##
192
193#Subtopic Unpremul ##
194
Cary Clark06c20f32018-03-20 15:53:27 -0400195#Method static inline bool SkAlphaTypeIsOpaque(SkAlphaType at)
196#In Property
197#Line # returns if Alpha_Type equals kOpaque_SkAlphaType ##
198
199#Param at one of: #list_of_alpha_types#
200##
201#Return true if at equals kOpaque_SkAlphaType ##
202#NoExample
203##
204##
205
Cary Clark08895c42018-02-01 09:37:32 -0500206#Subtopic Alpha_Type ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500207
208# ------------------------------------------------------------------------------
Cary Clark08895c42018-02-01 09:37:32 -0500209#Subtopic Color_Type
Cary Clarkf895a422018-02-27 09:54:21 -0500210#Line # encoding for pixel color ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500211#Alias Color_Type
212#Alias Color_Types
Cary Clark2a8c48b2018-02-15 17:31:24 -0500213
Cary Clark1a8d7622018-03-05 13:26:16 -0500214#PhraseDef list_of_color_types
215kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType,
216kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType,
217kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType,
218kGray_8_SkColorType, kRGBA_F16_SkColorType
219##
220
Cary Clark2a8c48b2018-02-15 17:31:24 -0500221#Subtopic Native
222#Alias Native_Color_Type
223#Substitute native SkColorType
224##
225
Cary Clark2dc84ad2018-01-26 12:56:22 -0500226#Enum SkColorType
Cary Clarkf895a422018-02-27 09:54:21 -0500227#Line # encoding for pixel color ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500228
229#Code
Cary Clark06c20f32018-03-20 15:53:27 -0400230###$
Cary Clark2dc84ad2018-01-26 12:56:22 -0500231 enum SkColorType {
232 kUnknown_SkColorType,
233 kAlpha_8_SkColorType,
234 kRGB_565_SkColorType,
235 kARGB_4444_SkColorType,
236 kRGBA_8888_SkColorType,
Cary Clark4855f782018-02-06 09:41:53 -0500237 kRGB_888x_SkColorType,
Cary Clark2dc84ad2018-01-26 12:56:22 -0500238 kBGRA_8888_SkColorType,
Cary Clark4855f782018-02-06 09:41:53 -0500239 kRGBA_1010102_SkColorType,
240 kRGB_101010x_SkColorType,
Cary Clark2dc84ad2018-01-26 12:56:22 -0500241 kGray_8_SkColorType,
242 kRGBA_F16_SkColorType,
Cary Clark06c20f32018-03-20 15:53:27 -0400243
Cary Clark2dc84ad2018-01-26 12:56:22 -0500244 kLastEnum_SkColorType = kRGBA_F16_SkColorType,
Cary Clark06c20f32018-03-20 15:53:27 -0400245
246 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A)
Cary Clark2dc84ad2018-01-26 12:56:22 -0500247 kN32_SkColorType = kBGRA_8888_SkColorType,
Cary Clark06c20f32018-03-20 15:53:27 -0400248 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A)
Cary Clark2dc84ad2018-01-26 12:56:22 -0500249 kN32_SkColorType = kRGBA_8888_SkColorType,
Cary Clark06c20f32018-03-20 15:53:27 -0400250 #else
251 #error "SK_*32_SHIFT values must correspond to BGRA or RGBA byte order"
252 #endif
Cary Clark2dc84ad2018-01-26 12:56:22 -0500253 };
Cary Clark06c20f32018-03-20 15:53:27 -0400254$$$#
Cary Clark2dc84ad2018-01-26 12:56:22 -0500255##
256
Cary Clarkf895a422018-02-27 09:54:21 -0500257Describes how pixel bits encode color. A pixel may be an alpha mask, a
258gray level, Color_RGB, or Color_ARGB.
Cary Clark4855f782018-02-06 09:41:53 -0500259
260kN32_SkColorType selects the native 32-bit Color_ARGB format. On Little_Endian
261processors, pixels containing 8-bit Color_ARGB components pack into 32-bit
262kBGRA_8888_SkColorType. On Big_Endian processors, pixels pack into 32-bit
263kRGBA_8888_SkColorType.
Cary Clark2dc84ad2018-01-26 12:56:22 -0500264
265#Const kUnknown_SkColorType 0
Cary Clarkf895a422018-02-27 09:54:21 -0500266
Cary Clark2dc84ad2018-01-26 12:56:22 -0500267##
268#Const kAlpha_8_SkColorType 1
Cary Clarkf895a422018-02-27 09:54:21 -0500269 Encodes Color_Alpha as Alpha_8 pixel in an 8-bit byte.
Cary Clark2dc84ad2018-01-26 12:56:22 -0500270##
271#Const kRGB_565_SkColorType 2
Cary Clarkf895a422018-02-27 09:54:21 -0500272 Encodes Color_RGB as BGR_565 pixel in a 16-bit word.
Cary Clark2dc84ad2018-01-26 12:56:22 -0500273##
274#Const kARGB_4444_SkColorType 3
Cary Clarkf895a422018-02-27 09:54:21 -0500275 Encodes Color_ARGB as ABGR_4444 pixel in a 16-bit word.
Cary Clark2dc84ad2018-01-26 12:56:22 -0500276##
277#Const kRGBA_8888_SkColorType 4
Cary Clarkf895a422018-02-27 09:54:21 -0500278 Encodes Color_ARGB as RGBA_8888 pixel in a 32-bit word.
Cary Clark2dc84ad2018-01-26 12:56:22 -0500279##
Cary Clarkab2621d2018-01-30 10:08:57 -0500280#Const kRGB_888x_SkColorType 5
Cary Clarkf895a422018-02-27 09:54:21 -0500281 Encodes Color_RGB as RGB_888x pixel in a 32-bit word.
Cary Clark2dc84ad2018-01-26 12:56:22 -0500282##
Cary Clarkab2621d2018-01-30 10:08:57 -0500283#Const kBGRA_8888_SkColorType 6
Cary Clarkf895a422018-02-27 09:54:21 -0500284 Encodes Color_ARGB as BGRA_8888 pixel in a 32-bit word.
Cary Clark2dc84ad2018-01-26 12:56:22 -0500285##
Cary Clarkab2621d2018-01-30 10:08:57 -0500286#Const kRGBA_1010102_SkColorType 7
Cary Clarkf895a422018-02-27 09:54:21 -0500287 Encodes Color_ARGB as RGBA_1010102 pixel in a 32-bit word.
Cary Clark2dc84ad2018-01-26 12:56:22 -0500288##
Cary Clarkab2621d2018-01-30 10:08:57 -0500289#Const kRGB_101010x_SkColorType 8
Cary Clarkf895a422018-02-27 09:54:21 -0500290 Encodes Color_RGB as RGB_101010x pixel in a 32-bit word.
Cary Clarkab2621d2018-01-30 10:08:57 -0500291##
292#Const kGray_8_SkColorType 9
Cary Clarkf895a422018-02-27 09:54:21 -0500293 Encodes Color_Gray as Gray_8 in an 8-bit byte.
Cary Clarkab2621d2018-01-30 10:08:57 -0500294##
295#Const kRGBA_F16_SkColorType 10
Cary Clarkf895a422018-02-27 09:54:21 -0500296 Encodes Color_ARGB as RGBA_F16 in a 64-bit word.
Cary Clarkab2621d2018-01-30 10:08:57 -0500297##
Cary Clarkf895a422018-02-27 09:54:21 -0500298
Cary Clarkab2621d2018-01-30 10:08:57 -0500299#ToDo can be 4 or 6; how to document? ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500300#Const kN32_SkColorType 4
Cary Clarkf895a422018-02-27 09:54:21 -0500301 Encodes Color_ARGB as either RGBA_8888 or BGRA_8888, whichever
302 is native to the platform.
303##
304
305#NoExample
306##
307
308#SeeAlso SkAlphaType SkColorSpace
309
310#Enum SkColorType ##
311
312#Subtopic Alpha_8
313
314Alpha_8 is an 8-bit byte pixel encoding that represents transparency. A value of zero is
315completely transparent; a value of 255 is completely opaque. Bitmap with Alpha_8
316pixels does not visibly draw, because its pixels have no color information.
317The paired SkAlphaType is ignored.
318
319#Example
320#Description
321Alpha_8 pixels can modify another draw. orangePaint fills the bounds of bitmap,
322with its transparency set to alpha8 pixel value.
323##
324#Height 64
325 canvas->scale(16, 16);
326 SkBitmap bitmap;
327 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kAlpha_8_SkColorType, kOpaque_SkAlphaType);
328 bitmap.allocPixels(imageInfo);
329 SkCanvas offscreen(bitmap);
330 offscreen.clear(SK_ColorGREEN);
331 SkPaint orangePaint;
332 orangePaint.setARGB(0xFF, 0xFF, 0xA5, 0x00);
333 canvas->drawBitmap(bitmap, 0, 0, &orangePaint);
334 uint8_t alpha8[] = { 0xFF, 0xBB, 0x77, 0x33 };
335 SkPixmap alphaPixmap(imageInfo, &alpha8, imageInfo.minRowBytes());
336 if (bitmap.writePixels(alphaPixmap, 0, 0)) {
337 canvas->drawBitmap(bitmap, 2, 2, &orangePaint);
338 }
339##
340##
341
342#Subtopic BGR_565
343
344BGR_565 is a 16-bit word pixel encoding that contains five bits of blue,
345six bits of green, and five bits of red. BGR_565 is fully opaque as if its
346Color_Alpha was set to one, and should always be paired with kOpaque_SkAlphaType.
347
348#Illustration
349
350#Example
351#Height 96
352 canvas->scale(16, 16);
353 SkBitmap bitmap;
354 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGB_565_SkColorType, kOpaque_SkAlphaType);
355 bitmap.allocPixels(imageInfo);
356 SkCanvas offscreen(bitmap);
357 offscreen.clear(SK_ColorGREEN);
358 canvas->drawBitmap(bitmap, 0, 0);
359 auto pack565 = [](unsigned r, unsigned g, unsigned b) -> uint16_t {
360 return (b << 0) | (g << 5) | (r << 11);
361 };
362 uint16_t red565[] = { pack565(0x1F, 0x00, 0x00), pack565(0x17, 0x00, 0x00),
363 pack565(0x0F, 0x00, 0x00), pack565(0x07, 0x00, 0x00) };
364 uint16_t blue565[] = { pack565(0x00, 0x00, 0x1F), pack565(0x00, 0x00, 0x17),
365 pack565(0x00, 0x00, 0x0F), pack565(0x00, 0x00, 0x07) };
366 SkPixmap redPixmap(imageInfo, &red565, imageInfo.minRowBytes());
367 if (bitmap.writePixels(redPixmap, 0, 0)) {
368 canvas->drawBitmap(bitmap, 2, 2);
369 }
370 SkPixmap bluePixmap(imageInfo, &blue565, imageInfo.minRowBytes());
371 if (bitmap.writePixels(bluePixmap, 0, 0)) {
372 canvas->drawBitmap(bitmap, 4, 4);
373 }
374##
375##
376
377#Subtopic ABGR_4444
378
379ABGR_4444 is a 16-bit word pixel encoding that contains four bits of alpha,
380four bits of blue, four bits of green, and four bits of red.
381
382#Illustration
383
384If paired with kPremul_SkAlphaType: blue, green, and red components are
385premultiplied by the alpha value. If blue, green, or red is greater than alpha,
386the drawn result is undefined.
387
388If paired with kUnpremul_SkAlphaType: alpha, blue, green, and red components
389may have any value. There may be a performance penalty with unpremultipled
390pixels.
391
392If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum;
393blue, green, and red components are fully opaque. If any alpha component is
394less than 15, the drawn result is undefined.
395
396#Bug 7648
397
398#Example
399#Height 96
400 canvas->scale(16, 16);
401 SkBitmap bitmap;
402 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, kPremul_SkAlphaType);
403 bitmap.allocPixels(imageInfo);
404 SkCanvas offscreen(bitmap);
405 offscreen.clear(SK_ColorGREEN);
406 canvas->drawBitmap(bitmap, 0, 0);
407 auto pack4444 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint16_t {
408 return (a << 0) | (b << 4) | (g << 8) | (r << 12);
409 };
410 uint16_t red4444[] = { pack4444(0xF, 0xF, 0x0, 0x0), pack4444(0xF, 0xb, 0x0, 0x0),
411 pack4444(0xF, 0x7, 0x0, 0x0), pack4444(0xF, 0x3, 0x0, 0x0) };
412 uint16_t blue4444[] = { pack4444(0xF, 0x0, 0x0, 0xF), pack4444(0xF, 0x0, 0x0, 0xb),
413 pack4444(0xF, 0x0, 0x0, 0x7), pack4444(0xF, 0x0, 0x0, 0x3) };
414 SkPixmap redPixmap(imageInfo, &red4444, imageInfo.minRowBytes());
415 if (bitmap.writePixels(redPixmap, 0, 0)) {
416 canvas->drawBitmap(bitmap, 2, 2);
417 }
418 SkPixmap bluePixmap(imageInfo, &blue4444, imageInfo.minRowBytes());
419 if (bitmap.writePixels(bluePixmap, 0, 0)) {
420 canvas->drawBitmap(bitmap, 4, 4);
421 }
422##
423##
424
425#Subtopic RGBA_8888
426
427RGBA_8888 is a 32-bit word pixel encoding that contains eight bits of red,
428eight bits of green, eight bits of blue, and eight bits of alpha.
429
430#Illustration
431
432If paired with kPremul_SkAlphaType: red, green, and blue components are
433premultiplied by the alpha value. If red, green, or blue is greater than alpha,
434the drawn result is undefined.
435
436If paired with kUnpremul_SkAlphaType: alpha, red, green, and blue components
437may have any value. There may be a performance penalty with unpremultipled
438pixels.
439
440If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum;
441red, green, and blue components are fully opaque. If any alpha component is
442less than 255, the drawn result is undefined.
443
444On Big_Endian platforms, RGBA_8888 is the native Color_Type, and will have
445the best performance. Use kN32_SkColorType to choose the best Color_Type for
446the platform at compile time.
447
448#Example
449#Height 96
450 canvas->scale(16, 16);
451 SkBitmap bitmap;
452 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
453 bitmap.allocPixels(imageInfo);
454 SkCanvas offscreen(bitmap);
455 offscreen.clear(SK_ColorGREEN);
456 canvas->drawBitmap(bitmap, 0, 0);
457 auto pack8888 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint32_t {
458 return (r << 0) | (g << 8) | (b << 16) | (a << 24);
459 };
460 uint32_t red8888[] = { pack8888(0xFF, 0xFF, 0x0, 0x0), pack8888(0xFF, 0xbb, 0x0, 0x0),
461 pack8888(0xFF, 0x77, 0x0, 0x0), pack8888(0xFF, 0x33, 0x0, 0x0) };
462 uint32_t blue8888[] = { pack8888(0xFF, 0x0, 0x0, 0x0FF), pack8888(0xFF, 0x0, 0x0, 0x0bb),
463 pack8888(0xFF, 0x0, 0x0, 0x077), pack8888(0xFF, 0x0, 0x0, 0x033) };
464 SkPixmap redPixmap(imageInfo, &red8888, imageInfo.minRowBytes());
465 if (bitmap.writePixels(redPixmap, 0, 0)) {
466 canvas->drawBitmap(bitmap, 2, 2);
467 }
468 SkPixmap bluePixmap(imageInfo, &blue8888, imageInfo.minRowBytes());
469 if (bitmap.writePixels(bluePixmap, 0, 0)) {
470 canvas->drawBitmap(bitmap, 4, 4);
471 }
472##
473##
474
475#Subtopic RGB_888x
476
477RGB_888x is a 32-bit word pixel encoding that contains eight bits of red,
Cary Clark681287e2018-03-16 11:34:15 -0400478eight bits of green, eight bits of blue, and eight unused bits. RGB_888x is fully
Cary Clarkf895a422018-02-27 09:54:21 -0500479opaque as if its Color_Alpha was set to one, and should always be paired with
480kOpaque_SkAlphaType.
481
482#Illustration
483
484#Example
485#Bug 7645
486#Height 96
487#Platform cpu
488 canvas->scale(16, 16);
489 SkBitmap bitmap;
490 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGB_888x_SkColorType, kOpaque_SkAlphaType);
491 bitmap.allocPixels(imageInfo);
492 SkCanvas offscreen(bitmap);
493 offscreen.clear(SK_ColorGREEN);
494 canvas->drawBitmap(bitmap, 0, 0);
495 auto pack888 = [](unsigned r, unsigned g, unsigned b) -> uint32_t {
496 return (r << 0) | (g << 8) | (b << 16);
497 };
498 uint32_t red888[] = { pack888(0xFF, 0x00, 0x00), pack888(0xbb, 0x00, 0x00),
499 pack888(0x77, 0x00, 0x00), pack888(0x33, 0x00, 0x00) };
500 uint32_t blue888[] = { pack888(0x00, 0x00, 0xFF), pack888(0x00, 0x00, 0xbb),
501 pack888(0x00, 0x00, 0x77), pack888(0x00, 0x00, 0x33) };
502 if (bitmap.installPixels(imageInfo, (void*) red888, imageInfo.minRowBytes())) {
503 canvas->drawBitmap(bitmap, 2, 2);
504 }
505 if (bitmap.installPixels(imageInfo, (void*) blue888, imageInfo.minRowBytes())) {
506 canvas->drawBitmap(bitmap, 4, 4);
507 }
508##
509##
510
511#Subtopic BGRA_8888
512
513BGRA_8888 is a 32-bit word pixel encoding that contains eight bits of blue,
514eight bits of green, eight bits of red, and eight bits of alpha.
515
516#Illustration
517
518If paired with kPremul_SkAlphaType: blue, green, and red components are
519premultiplied by the alpha value. If blue, green, or red is greater than alpha,
520the drawn result is undefined.
521
522If paired with kUnpremul_SkAlphaType: blue, green, red, and alpha components
523may have any value. There may be a performance penalty with unpremultipled
524pixels.
525
526If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum;
527blue, green, and red components are fully opaque. If any alpha component is
528less than 255, the drawn result is undefined.
529
530On Little_Endian platforms, BGRA_8888 is the native Color_Type, and will have
531the best performance. Use kN32_SkColorType to choose the best Color_Type for
532the platform at compile time.
533
534#Example
535#Height 96
536 canvas->scale(16, 16);
537 SkBitmap bitmap;
538 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
539 bitmap.allocPixels(imageInfo);
540 SkCanvas offscreen(bitmap);
541 offscreen.clear(SK_ColorGREEN);
542 canvas->drawBitmap(bitmap, 0, 0);
543 auto pack8888 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint32_t {
544 return (b << 0) | (g << 8) | (r << 16) | (a << 24);
545 };
546 uint32_t red8888[] = { pack8888(0xFF, 0xFF, 0x0, 0x0), pack8888(0xFF, 0xbb, 0x0, 0x0),
547 pack8888(0xFF, 0x99, 0x0, 0x0), pack8888(0xFF, 0x55, 0x0, 0x0) };
548 uint32_t blue8888[] = { pack8888(0xFF, 0x0, 0x0, 0x0FF), pack8888(0xFF, 0x0, 0x0, 0x0bb),
549 pack8888(0xFF, 0x0, 0x0, 0x099), pack8888(0xFF, 0x0, 0x0, 0x055) };
550 SkPixmap redPixmap(imageInfo, &red8888, imageInfo.minRowBytes());
551 if (bitmap.writePixels(redPixmap, 0, 0)) {
552 canvas->drawBitmap(bitmap, 2, 2);
553 }
554 SkPixmap bluePixmap(imageInfo, &blue8888, imageInfo.minRowBytes());
555 if (bitmap.writePixels(bluePixmap, 0, 0)) {
556 canvas->drawBitmap(bitmap, 4, 4);
557 }
558##
559##
560
561#Subtopic RGBA_1010102
562
563RGBA_1010102 is a 32-bit word pixel encoding that contains ten bits of red,
564ten bits of green, ten bits of blue, and two bits of alpha. Possible alpha
565values are zero: fully transparent; one: 33% opaque; two: 67% opaque;
566three: fully opaque.
567
568#Illustration
569
570If paired with kPremul_SkAlphaType: red, green, and blue components are
571premultiplied by the alpha value. If red, green, or blue is greater than the
572alpha replicated to ten bits, the drawn result is undefined.
573
574If paired with kUnpremul_SkAlphaType: alpha, red, green, and blue components
575may have any value. There may be a performance penalty with unpremultipled
576pixels.
577
578If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum;
579red, green, and blue components are fully opaque. If any alpha component is
580less than 3, the drawn result is undefined.
581
582#Example
583#Bug 7645
584#Height 96
585#Platform cpu
586 canvas->scale(16, 16);
587 SkBitmap bitmap;
588 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGBA_1010102_SkColorType, kOpaque_SkAlphaType);
589 bitmap.allocPixels(imageInfo);
590 SkCanvas offscreen(bitmap);
591 offscreen.clear(SK_ColorGREEN);
592 canvas->drawBitmap(bitmap, 0, 0);
593 auto pack1010102 = [](unsigned r, unsigned g, unsigned b, unsigned a) -> uint32_t {
594 return (r << 0) | (g << 10) | (b << 20) | (a << 30);
595 };
596 uint32_t redBits[] = { pack1010102(0x3FF, 0x000, 0x000, 0x3),
597 pack1010102(0x2ff, 0x000, 0x000, 0x3),
598 pack1010102(0x1ff, 0x000, 0x000, 0x3),
599 pack1010102(0x0ff, 0x000, 0x000, 0x3) };
600 uint32_t blueBits[] = { pack1010102(0x000, 0x000, 0x3FF, 0x3),
601 pack1010102(0x000, 0x000, 0x2ff, 0x3),
602 pack1010102(0x000, 0x000, 0x1ff, 0x3),
603 pack1010102(0x000, 0x000, 0x0ff, 0x3) };
604 if (bitmap.installPixels(imageInfo, (void*) redBits, imageInfo.minRowBytes())) {
605 canvas->drawBitmap(bitmap, 2, 2);
606 }
607 SkPixmap bluePixmap(imageInfo, &blueBits, imageInfo.minRowBytes());
608 if (bitmap.installPixels(imageInfo, (void*) blueBits, imageInfo.minRowBytes())) {
609 canvas->drawBitmap(bitmap, 4, 4);
610 }
611##
612##
613
614#Subtopic RGB_101010x
615
Cary Clark681287e2018-03-16 11:34:15 -0400616RGB_101010x is a 32-bit word pixel encoding that contains ten bits of red,
617ten bits of green, ten bits of blue, and two unused bits. RGB_101010x is fully
618opaque as if its Color_Alpha was set to one, and should always be paired with
619kOpaque_SkAlphaType.
620
Cary Clarkf895a422018-02-27 09:54:21 -0500621#Illustration
622
623#Example
624#Bug 7645
625#Height 96
626#Platform cpu
627 canvas->scale(16, 16);
628 SkBitmap bitmap;
629 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGB_101010x_SkColorType, kOpaque_SkAlphaType);
630 bitmap.allocPixels(imageInfo);
631 SkCanvas offscreen(bitmap);
632 offscreen.clear(SK_ColorGREEN);
633 canvas->drawBitmap(bitmap, 0, 0);
634 auto pack101010x = [](unsigned r, unsigned g, unsigned b) -> uint32_t {
635 return (r << 0) | (g << 10) | (b << 20);
636 };
637 uint32_t redBits[] = { pack101010x(0x3FF, 0x000, 0x000), pack101010x(0x2ff, 0x000, 0x000),
638 pack101010x(0x1ff, 0x000, 0x000), pack101010x(0x0ff, 0x000, 0x000) };
639 uint32_t blueBits[] = { pack101010x(0x000, 0x000, 0x3FF), pack101010x(0x000, 0x000, 0x2ff),
640 pack101010x(0x000, 0x000, 0x1ff), pack101010x(0x000, 0x000, 0x0ff) };
641 if (bitmap.installPixels(imageInfo, (void*) redBits, imageInfo.minRowBytes())) {
642 canvas->drawBitmap(bitmap, 2, 2);
643 }
644 SkPixmap bluePixmap(imageInfo, &blueBits, imageInfo.minRowBytes());
645 if (bitmap.installPixels(imageInfo, (void*) blueBits, imageInfo.minRowBytes())) {
646 canvas->drawBitmap(bitmap, 4, 4);
647 }
648##
649##
650
651#Subtopic Gray_8
652
Cary Clark681287e2018-03-16 11:34:15 -0400653Gray_8 is an 8-bit byte pixel encoding that represents equal values for red,
654blue, and green, reprsenting colors from black to white. Gray_8 is fully
655opaque as if its Color_Alpha was set to one, and should always be paired with
656kOpaque_SkAlphaType.
657
Cary Clarkf895a422018-02-27 09:54:21 -0500658#Example
659#Height 64
660 canvas->scale(16, 16);
661 SkBitmap bitmap;
662 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kGray_8_SkColorType, kOpaque_SkAlphaType);
663 bitmap.allocPixels(imageInfo);
664 SkCanvas offscreen(bitmap);
665 offscreen.clear(SK_ColorGREEN);
666 canvas->drawBitmap(bitmap, 0, 0);
667 uint8_t gray8[] = { 0xFF, 0xBB, 0x77, 0x33 };
668 SkPixmap grayPixmap(imageInfo, &gray8, imageInfo.minRowBytes());
669 if (bitmap.writePixels(grayPixmap, 0, 0)) {
670 canvas->drawBitmap(bitmap, 2, 2);
671 }
672##
673##
674
675#Subtopic RGBA_F16
676
Cary Clark681287e2018-03-16 11:34:15 -0400677RGBA_F16 is a 64-bit word pixel encoding that contains sixteen bits of blue,
678sixteen bits of green, sixteen bits of red, and sixteen bits of alpha.
679
680Each component encodes a floating point value using
681#A Half floats # https://www.khronos.org/opengl/wiki/Small_Float_Formats ##
682. Meaningful colors are represented by the range 0.0 to 1.0, although smaller
683and larger values may be useful when used in combination with Transfer_Mode.
684
Cary Clarkf895a422018-02-27 09:54:21 -0500685#Illustration
686
Cary Clark681287e2018-03-16 11:34:15 -0400687If paired with kPremul_SkAlphaType: blue, green, and red components are
688premultiplied by the alpha value. If blue, green, or red is greater than alpha,
689the drawn result is undefined.
690
691If paired with kUnpremul_SkAlphaType: blue, green, red, and alpha components
692may have any value. There may be a performance penalty with unpremultipled
693pixels.
694
695If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum;
696blue, green, and red components are fully opaque. If any alpha component is
697less than 255, the drawn result is undefined.
698
Cary Clarkf895a422018-02-27 09:54:21 -0500699#ToDo
700FloatToHalf should be replaced with SkFloatToHalf if/when that's made public
Cary Clark2dc84ad2018-01-26 12:56:22 -0500701##
702
703#Example
Cary Clarkf895a422018-02-27 09:54:21 -0500704#Height 96
705#Function
706union FloatUIntUnion {
707 uint32_t fUInt;
708 float fFloat;
709};
710
711uint16_t FloatToHalf(float f) {
712 static const FloatUIntUnion magic = { 15 << 23 };
713 static const uint32_t round_mask = ~0xfffu;
714 FloatUIntUnion floatUnion;
715 floatUnion.fFloat = f;
716 uint32_t sign = floatUnion.fUInt & 0x80000000u;
717 floatUnion.fUInt ^= sign;
718 floatUnion.fUInt &= round_mask;
719 floatUnion.fFloat *= magic.fFloat;
720 floatUnion.fUInt -= round_mask;
721 return (floatUnion.fUInt >> 13) | (sign >> 16);
722}
Cary Clark2dc84ad2018-01-26 12:56:22 -0500723##
724
Cary Clarkf895a422018-02-27 09:54:21 -0500725void draw(SkCanvas* canvas) {
726 canvas->scale(16, 16);
727 SkBitmap bitmap;
728 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
729 bitmap.allocPixels(imageInfo);
730 SkCanvas offscreen(bitmap);
731 offscreen.clear(SK_ColorGREEN);
732 canvas->drawBitmap(bitmap, 0, 0);
733 auto H = [](float c) -> uint16_t {
734 return FloatToHalf(c);
735 };
736 // R G B A
737 uint16_t red_f16[][4] = { { H(1.0f), H(0.0f), H(0.0f), H(1.0f) },
738 { H(.75f), H(0.0f), H(0.0f), H(1.0f) },
739 { H(.50f), H(0.0f), H(0.0f), H(1.0f) },
740 { H(.25f), H(0.0f), H(0.0f), H(1.0f) } };
741 uint16_t blue_f16[][4] = { { H(0.0f), H(0.0f), H(1.0f), H(1.0f) },
742 { H(0.0f), H(0.0f), H(.75f), H(1.0f) },
743 { H(0.0f), H(0.0f), H(.50f), H(1.0f) },
744 { H(0.0f), H(0.0f), H(.25f), H(1.0f) } };
745 SkPixmap redPixmap(imageInfo, red_f16, imageInfo.minRowBytes());
746 if (bitmap.writePixels(redPixmap, 0, 0)) {
747 canvas->drawBitmap(bitmap, 2, 2);
748 }
749 SkPixmap bluePixmap(imageInfo, blue_f16, imageInfo.minRowBytes());
750 if (bitmap.writePixels(bluePixmap, 0, 0)) {
751 canvas->drawBitmap(bitmap, 4, 4);
752 }
753}
754##
755##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500756
Cary Clark08895c42018-02-01 09:37:32 -0500757#Subtopic Color_Type ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500758
759# ------------------------------------------------------------------------------
Cary Clark681287e2018-03-16 11:34:15 -0400760
761#Method int SkColorTypeBytesPerPixel(SkColorType ct)
762#In Property
763#Line # returns Color_Type byte size ##
764
765Returns the number of bytes required to store a pixel, including unused padding.
766Returns zero if ct is kUnknown_SkColorType or invalid.
767
768#Param ct one of: #list_of_color_types#
769##
770
771#Return bytes per pixel ##
772
773#Example
774#Height 192
775 const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
776 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" };
777 SkPaint paint;
778 paint.setTypeface(SkTypeface::MakeFromName("monospace", SkFontStyle()));
779 paint.setAntiAlias(true);
780 paint.setTextSize(10);
781 int y = 15;
782 canvas->drawString(" colorType bytes", 10, y, paint);
783 for (SkColorType colorType : { #list_of_color_types#
784 } ) {
785 int result = SkColorTypeBytesPerPixel(colorType);
786 SkString string;
787 string.printf("%13s %4d", colors[(int) colorType], result);
788 canvas->drawString(string, 10, y += 14, paint);
789 }
790##
791#SeeAlso SkImageInfo::bytesPerPixel
792##
793
794# ------------------------------------------------------------------------------
795
796#Method bool SkColorTypeIsAlwaysOpaque(SkColorType ct)
797#In Property
798#Line # returns if Color_Type includes Color_Alpha ##
799
800Returns true if Color_Type always decodes Color_Alpha to 1.0, making the pixel
801fully opaque. If true, Color_Type does not reserve bits to encode Color_Alpha.
802
803#Param ct one of: #list_of_color_types#
804##
805
806#Return true if Color_Alpha is always set to 1.0 ##
807
808#Example
809#Height 192
810 const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
811 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" };
812 SkPaint paint;
813 paint.setTypeface(SkTypeface::MakeFromName("monospace", SkFontStyle()));
814 paint.setAntiAlias(true);
815 paint.setTextSize(10);
816 int y = 15;
817 canvas->drawString(" colorType bytes", 10, y, paint);
818 for (SkColorType colorType : { #list_of_color_types#
819 } ) {
820 bool result = SkColorTypeIsAlwaysOpaque(colorType);
821 SkString string;
822 string.printf("%13s %6s", colors[(int) colorType], result ? "true" : "false");
823 canvas->drawString(string, 10, y += 14, paint);
824 }
825##
826#SeeAlso SkColorTypeValidateAlphaType
827##
828
829# ------------------------------------------------------------------------------
830
831#Method bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType,
832 SkAlphaType* canonical = nullptr)
833#In Property
834#Line # returns if Alpha_Type is valid ##
835
836Returns true if canonical can be set to a valid Alpha_Type for colorType. If
837there is more than one valid canonical Alpha_Type, set to alphaType, if valid.
838If true is returned and canonical is not nullptr, store valid Alpha_Type.
839
840Returns false only if alphaType is kUnknown_SkAlphaType, color type is not
841kUnknown_SkColorType, and Color_Type is not always opaque. If false is returned,
842canonical is ignored.
843
844For kUnknown_SkColorType: set canonical to kUnknown_SkAlphaType and return true.
845For kAlpha_8_SkColorType: set canonical to kPremul_SkAlphaType or
846kOpaque_SkAlphaType and return true if alphaType is not kUnknown_SkAlphaType.
847For kRGB_565_SkColorType, kRGB_888x_SkColorType, kRGB_101010x_SkColorType, and
848kGray_8_SkColorType: set canonical to kOpaque_SkAlphaType and return true.
849For kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kBGRA_8888_SkColorType,
850kRGBA_1010102_SkColorType, and kRGBA_F16_SkColorType: set canonical to alphaType
851and return true if alphaType is not kUnknown_SkAlphaType.
852
853#Param colorType one of: #list_of_color_types#
854##
855#Param alphaType one of: #list_of_alpha_types#
856##
857#Param canonical storage for Alpha_Type ##
858
859#Return true if valid Alpha_Type can be associated with colorType ##
860
861#Example
862#Height 640
863 const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
864 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" };
865 const char* alphas[] = {"Unknown ", "Opaque ", "Premul ", "Unpremul"};
866 SkAlphaType alphaTypes[] = { #list_of_alpha_types#
867 };
868 SkPaint paint;
869 paint.setTypeface(SkTypeface::MakeFromName("monospace", SkFontStyle()));
870 paint.setAntiAlias(true);
871 paint.setTextSize(10);
872 int y = 15;
873 canvas->drawString(" colorType alphaType canonical", 10, y, paint);
874 for (SkColorType colorType : { #list_of_color_types#
875 } ) {
876 for (SkAlphaType alphaType : alphaTypes) {
877 SkAlphaType canonicalAlphaType = kUnknown_SkAlphaType;
878 bool result = SkColorTypeValidateAlphaType(colorType, alphaType, &canonicalAlphaType);
879 SkString string;
880 string.printf("%13s %10s %10s", colors[(int) colorType], alphas[(int) alphaType],
881 result ? alphas[(int) canonicalAlphaType] : "------ ");
882 canvas->drawString(string, 10, y += 14, paint);
883 }
884 }
885##
886#SeeAlso SkColorTypeIsAlwaysOpaque
887##
888
889# ------------------------------------------------------------------------------
Cary Clark772953472018-02-12 09:38:08 -0500890#Subtopic YUV_ColorSpace
891#Alias YUV_ColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -0500892#Enum SkYUVColorSpace
Cary Clark06c20f32018-03-20 15:53:27 -0400893#Line # color range of YUV pixels ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500894
895#Code
896 enum SkYUVColorSpace {
897 kJPEG_SkYUVColorSpace,
898 kRec601_SkYUVColorSpace,
899 kRec709_SkYUVColorSpace,
900 kLastEnum_SkYUVColorSpace = kRec709_SkYUVColorSpace,
901 };
902##
903
Cary Clark06c20f32018-03-20 15:53:27 -0400904Describes color range of YUV pixels. The color mapping from YUV to RGB varies
905depending on the source. YUV pixels may be generated by JPEG images, standard
906video streams, or high definition video streams. Each has its own mapping from
907YUV and RGB.
908
909JPEG YUV values encode the full range of 0 to 255 for all three components.
910Video YUV values range from 16 to 235 for all three components. Details of
911encoding and conversion to RGB are described in
912#A YCbCr color space # https://en.wikipedia.org/wiki/YCbCr ##
913.
Cary Clark2dc84ad2018-01-26 12:56:22 -0500914
915#Const kJPEG_SkYUVColorSpace 0
Cary Clark06c20f32018-03-20 15:53:27 -0400916Describes standard JPEG color space;
917#A CCIR 601 # https://en.wikipedia.org/wiki/Rec._601 ##
918with full range of 0 to 255 for components.
Cary Clark2dc84ad2018-01-26 12:56:22 -0500919##
920#Const kRec601_SkYUVColorSpace 1
Cary Clark06c20f32018-03-20 15:53:27 -0400921Describes standard used by SDTV;
922#A CCIR 601 # https://en.wikipedia.org/wiki/Rec._601 ##
923with studio range of 16 to 235 range for components.
Cary Clark2dc84ad2018-01-26 12:56:22 -0500924##
925#Const kRec709_SkYUVColorSpace 2
Cary Clark06c20f32018-03-20 15:53:27 -0400926Describes standard used by HDTV;
927#A Rec. 709 # http://en.wikipedia.org/wiki/Rec._709 ##
928with studio range of 16 to 235 range for components.
Cary Clark2dc84ad2018-01-26 12:56:22 -0500929##
930
Cary Clark06c20f32018-03-20 15:53:27 -0400931#NoExample
Cary Clark2dc84ad2018-01-26 12:56:22 -0500932##
933
Cary Clark06c20f32018-03-20 15:53:27 -0400934#SeeAlso SkImage::MakeFromYUVTexturesCopy SkImage::MakeFromNV12TexturesCopy
Cary Clark2dc84ad2018-01-26 12:56:22 -0500935
936#Enum SkYUVColorSpace ##
Cary Clark772953472018-02-12 09:38:08 -0500937#Subtopic YUV_ColorSpace ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500938
939# ------------------------------------------------------------------------------
Cary Clark2dc84ad2018-01-26 12:56:22 -0500940
941#Struct SkImageInfo
942
Cary Clark1a8d7622018-03-05 13:26:16 -0500943Describes pixel dimensions and encoding. Bitmap, Image, PixMap, and Surface
944can be created from Image_Info. Image_Info can be retrieved from Bitmap and
945Pixmap, but not from Image and Surface. For example, Image and Surface
946implementations may defer pixel depth, so may not completely specify Image_Info.
947
948Image_Info contains dimensions, the pixel integral width and height. It encodes
949how pixel bits describe Color_Alpha, transparency; Color components red, blue,
950and green; and Color_Space, the range and linearity of colors.
Cary Clark2dc84ad2018-01-26 12:56:22 -0500951
Cary Clark4855f782018-02-06 09:41:53 -0500952#Subtopic Member_Function
Cary Clark08895c42018-02-01 09:37:32 -0500953#Populate
954##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500955
Cary Clark78de7512018-02-07 07:27:09 -0500956#Subtopic Related_Function
Cary Clark08895c42018-02-01 09:37:32 -0500957#Populate
958##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500959
960# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -0500961#Subtopic Constructor
962#Populate
963##
964
Cary Clark2dc84ad2018-01-26 12:56:22 -0500965#Method SkImageInfo()
966
Cary Clark4855f782018-02-06 09:41:53 -0500967#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -0500968#Line # creates with zero dimensions, kUnknown_SkColorType, kUnknown_SkAlphaType ##
Cary Clark06c20f32018-03-20 15:53:27 -0400969Creates an empty Image_Info with kUnknown_SkColorType, kUnknown_SkAlphaType,
Cary Clark1a8d7622018-03-05 13:26:16 -0500970a width and height of zero, and no Color_Space.
971
972#Return empty Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500973
974#Example
Cary Clark1a8d7622018-03-05 13:26:16 -0500975#Height 32
976#Description
977An empty Image_Info may be passed to SkCanvas::accessTopLayerPixels as storage
978for the Canvas actual Image_Info.
979##
980 SkImageInfo imageInfo;
981 size_t rowBytes;
982 SkIPoint origin;
Cary Clark681287e2018-03-16 11:34:15 -0400983 (void) canvas->accessTopLayerPixels(&imageInfo, &rowBytes, &origin);
Cary Clark1a8d7622018-03-05 13:26:16 -0500984 const char* alphaType[] = { "Unknown", "Opaque", "Premul", "Unpremul" };
985 SkString string;
986 string.printf("k%s_SkAlphaType", alphaType[(int) imageInfo.alphaType()]);
987 SkPaint paint;
988 canvas->drawString(string, 20, 20, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -0500989##
990
Cary Clark1a8d7622018-03-05 13:26:16 -0500991#SeeAlso Make MakeN32 MakeS32 MakeA8
Cary Clark2dc84ad2018-01-26 12:56:22 -0500992
993#Method ##
994
995# ------------------------------------------------------------------------------
996
997#Method static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at,
998 sk_sp<SkColorSpace> cs = nullptr)
Cary Clark4855f782018-02-06 09:41:53 -0500999#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001000#Line # creates Image_Info from dimensions, Color_Type, Alpha_Type, Color_Space ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001001Creates Image_Info from integral dimensions width and height, Color_Type ct,
1002Alpha_Type at, and optionally Color_Space cs.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001003
Cary Clark1a8d7622018-03-05 13:26:16 -05001004If Color_Space cs is nullptr and Image_Info is part of drawing source: Color_Space
1005defaults to sRGB, mapping into Surface Color_Space.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001006
Cary Clark1a8d7622018-03-05 13:26:16 -05001007Parameters are not validated to see if their values are legal, or that the
1008combination is supported.
1009
1010#Param width pixel column count; must be zero or greater ##
1011#Param height pixel row count; must be zero or greater ##
1012#Param ct one of: #list_of_color_types#
1013##
Cary Clark681287e2018-03-16 11:34:15 -04001014#Param at one of: #list_of_alpha_types#
Cary Clark1a8d7622018-03-05 13:26:16 -05001015##
1016#Param cs range of colors; may be nullptr ##
1017
1018#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001019
1020#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001021#Height 48
1022 uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 },
1023 { 0xAC, 0xA8, 0x89, 0xA7, 0x87 },
1024 { 0x9B, 0xB5, 0xE5, 0x95, 0x46 },
1025 { 0x90, 0x81, 0xC5, 0x71, 0x33 },
1026 { 0x75, 0x55, 0x44, 0x40, 0x30 }};
1027 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType);
1028 SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
1029 SkBitmap bitmap;
1030 bitmap.installPixels(pixmap);
1031 canvas->scale(8, 8);
1032 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001033##
1034
Cary Clark1a8d7622018-03-05 13:26:16 -05001035#SeeAlso MakeN32 MakeN32Premul MakeS32 MakeA8
Cary Clark2dc84ad2018-01-26 12:56:22 -05001036
1037#Method ##
1038
1039# ------------------------------------------------------------------------------
1040
1041#Method static SkImageInfo MakeN32(int width, int height, SkAlphaType at,
1042 sk_sp<SkColorSpace> cs = nullptr)
Cary Clark4855f782018-02-06 09:41:53 -05001043#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001044#Line # creates Image_Info with Native_Color_Type ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001045Creates Image_Info from integral dimensions width and height, kN32_SkColorType,
1046Alpha_Type at, and optionally Color_Space cs. kN32_SkColorType will equal either
1047kBGRA_8888_SkColorType or kRGBA_8888_SkColorType, whichever is optimal.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001048
Cary Clark1a8d7622018-03-05 13:26:16 -05001049If Color_Space cs is nullptr and Image_Info is part of drawing source: Color_Space
1050defaults to sRGB, mapping into Surface Color_Space.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001051
Cary Clark1a8d7622018-03-05 13:26:16 -05001052Parameters are not validated to see if their values are legal, or that the
1053combination is supported.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001054
Cary Clark1a8d7622018-03-05 13:26:16 -05001055#Param width pixel column count; must be zero or greater ##
1056#Param height pixel row count; must be zero or greater ##
Cary Clark681287e2018-03-16 11:34:15 -04001057#Param at one of: #list_of_alpha_types#
Cary Clark1a8d7622018-03-05 13:26:16 -05001058##
1059#Param cs range of colors; may be nullptr ##
1060
1061#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001062
1063#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001064#Height 128
1065 SkBitmap bitmap;
1066 bitmap.allocPixels(SkImageInfo::MakeN32(16, 16, kPremul_SkAlphaType));
1067 SkCanvas offscreen(bitmap);
1068 offscreen.clear(SK_ColorWHITE);
1069 SkPaint paint;
1070 offscreen.drawString("g", 0, 10, paint);
1071 canvas->scale(8, 8);
1072 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001073##
1074
Cary Clark1a8d7622018-03-05 13:26:16 -05001075#SeeAlso Make MakeN32Premul MakeS32 MakeA8
Cary Clark2dc84ad2018-01-26 12:56:22 -05001076
1077#Method ##
1078
1079# ------------------------------------------------------------------------------
1080
1081#Method static SkImageInfo MakeS32(int width, int height, SkAlphaType at)
1082
Cary Clark4855f782018-02-06 09:41:53 -05001083#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001084#Line # creates Image_Info with Native_Color_Type, sRGB Color_Space ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001085Creates Image_Info from integral dimensions width and height, kN32_SkColorType,
1086Alpha_Type at, with sRGB Color_Space.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001087
Cary Clark1a8d7622018-03-05 13:26:16 -05001088Parameters are not validated to see if their values are legal, or that the
1089combination is supported.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001090
Cary Clark1a8d7622018-03-05 13:26:16 -05001091#Param width pixel column count; must be zero or greater ##
1092#Param height pixel row count; must be zero or greater ##
Cary Clark681287e2018-03-16 11:34:15 -04001093#Param at one of: #list_of_alpha_types#
Cary Clark2dc84ad2018-01-26 12:56:22 -05001094##
1095
Cary Clark1a8d7622018-03-05 13:26:16 -05001096#Return created Image_Info ##
1097
1098#Example
1099#Set sRGB
1100#Height 128
1101#Description
1102Top gradient is drawn to offscreen without Color_Space. It is darker than middle
1103gradient, drawn to offscreen with sRGB Color_Space. Bottom gradient shares bits
1104with middle, but does not specify the Color_Space in noColorSpaceBitmap. A source
1105without Color_Space is treated as sRGB; the bottom gradient is identical to the
1106middle gradient.
1107##
1108 const int width = 256;
1109 const int height = 32;
1110 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
1111 SkColor gradColors[] = { 0xFFAA0055, 0xFF11CC88 };
1112 SkPoint gradPoints[] = { { 0, 0 }, { width, 0 } };
1113 SkPaint gradPaint;
1114 gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1115 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1116 SkBitmap bitmap;
1117 bitmap.allocPixels(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType));
1118 SkCanvas offscreen(bitmap);
1119 offscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1120 canvas->drawBitmap(bitmap, 0, 0);
1121 bitmap.allocPixels(SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType));
1122 SkCanvas sRGBOffscreen(bitmap);
1123 sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1124 canvas->drawBitmap(bitmap, 0, 48);
1125 SkBitmap noColorSpaceBitmap;
1126 noColorSpaceBitmap.setInfo(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType));
1127 noColorSpaceBitmap.setPixels(bitmap.getAddr(0, 0));
1128 canvas->drawBitmap(noColorSpaceBitmap, 0, 96);
1129##
1130
1131#SeeAlso Make MakeN32 MakeN32Premul MakeA8
Cary Clark2dc84ad2018-01-26 12:56:22 -05001132
1133#Method ##
1134
1135# ------------------------------------------------------------------------------
1136
1137#Method static SkImageInfo MakeN32Premul(int width, int height, sk_sp<SkColorSpace> cs = nullptr)
1138
Cary Clark4855f782018-02-06 09:41:53 -05001139#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001140#Line # creates Image_Info with Native_Color_Type, kPremul_SkAlphaType ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001141Creates Image_Info from integral dimensions width and height, kN32_SkColorType,
1142kPremul_SkAlphaType, with optional Color_Space.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001143
Cary Clark1a8d7622018-03-05 13:26:16 -05001144If Color_Space cs is nullptr and Image_Info is part of drawing source: Color_Space
1145defaults to sRGB, mapping into Surface Color_Space.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001146
Cary Clark1a8d7622018-03-05 13:26:16 -05001147Parameters are not validated to see if their values are legal, or that the
1148combination is supported.
1149
1150#Param width pixel column count; must be zero or greater ##
1151#Param height pixel row count; must be zero or greater ##
1152#Param cs range of colors; may be nullptr ##
1153
1154#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001155
1156#Example
Cary Clark06c20f32018-03-20 15:53:27 -04001157#Height 128
Cary Clark1a8d7622018-03-05 13:26:16 -05001158 SkBitmap bitmap;
1159 bitmap.allocPixels(SkImageInfo::MakeN32Premul(18, 18));
1160 SkCanvas offscreen(bitmap);
1161 offscreen.clear(SK_ColorWHITE);
1162 SkPaint paint;
1163 paint.setAntiAlias(true);
1164 paint.setTextSize(15);
1165 offscreen.drawString("\xF0\x9F\x98\xB8", 1, 15, paint);
1166 canvas->scale(6, 6);
1167 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001168##
1169
Cary Clark1a8d7622018-03-05 13:26:16 -05001170#SeeAlso MakeN32 MakeS32 MakeA8 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001171
1172#Method ##
1173
1174# ------------------------------------------------------------------------------
1175
1176#Method static SkImageInfo MakeN32Premul(const SkISize& size)
1177
Cary Clark4855f782018-02-06 09:41:53 -05001178#In Constructor
Cary Clark1a8d7622018-03-05 13:26:16 -05001179Creates Image_Info from integral dimensions width and height, kN32_SkColorType,
1180kPremul_SkAlphaType, with Color_Space set to nullptr.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001181
Cary Clark1a8d7622018-03-05 13:26:16 -05001182If Image_Info is part of drawing source: Color_Space defaults to sRGB, mapping
1183into Surface Color_Space.
1184
1185Parameters are not validated to see if their values are legal, or that the
1186combination is supported.
1187
1188#Param size width and height, each must be zero or greater ##
1189
1190#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001191
1192#Example
Cary Clark06c20f32018-03-20 15:53:27 -04001193#Height 128
Cary Clark1a8d7622018-03-05 13:26:16 -05001194 SkBitmap bitmap;
1195 bitmap.allocPixels(SkImageInfo::MakeN32Premul({18, 18}));
1196 SkCanvas offscreen(bitmap);
1197 offscreen.clear(SK_ColorWHITE);
1198 SkPaint paint;
1199 paint.setAntiAlias(true);
1200 paint.setTextSize(15);
1201 offscreen.drawString("\xF0\x9F\x98\xB9", 1, 15, paint);
1202 canvas->scale(6, 6);
1203 canvas->drawBitmap(bitmap, 0, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001204##
1205
Cary Clark1a8d7622018-03-05 13:26:16 -05001206#SeeAlso MakeN32 MakeS32 MakeA8 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001207
1208#Method ##
1209
1210# ------------------------------------------------------------------------------
1211
1212#Method static SkImageInfo MakeA8(int width, int height)
1213
Cary Clark4855f782018-02-06 09:41:53 -05001214#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001215#Line # creates Image_Info with kAlpha_8_SkColorType, kPremul_SkAlphaType ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001216Creates Image_Info from integral dimensions width and height, kAlpha_8_SkColorType,
1217kPremul_SkAlphaType, with Color_Space set to nullptr.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001218
Cary Clark1a8d7622018-03-05 13:26:16 -05001219#Param width pixel column count; must be zero or greater ##
1220#Param height pixel row count; must be zero or greater ##
1221
1222#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001223
1224#Example
Cary Clark681287e2018-03-16 11:34:15 -04001225#Height 64
1226 uint8_t pixels[][8] = { { 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00},
1227 { 0x00, 0x7f, 0xff, 0x3f, 0x3f, 0x7f, 0x3f, 0x00},
1228 { 0x3f, 0xff, 0x7f, 0x00, 0x7f, 0xff, 0x7f, 0x00},
1229 { 0x00, 0x3f, 0x00, 0x00, 0x3f, 0x7f, 0x3f, 0x00},
1230 { 0x3f, 0x7f, 0x7f, 0x3f, 0x00, 0x00, 0x00, 0x00},
1231 { 0x7f, 0xff, 0xff, 0x7f, 0x00, 0x3f, 0x7f, 0x3f},
1232 { 0x7f, 0xff, 0xff, 0x7f, 0x00, 0x7f, 0xff, 0x7f},
1233 { 0x3f, 0x7f, 0x7f, 0x3f, 0x00, 0x3f, 0x7f, 0x3f} };
1234 SkBitmap bitmap;
1235 bitmap.installPixels(SkImageInfo::MakeA8(8, 8),
1236 (void*) pixels, sizeof(pixels[0]));
1237 SkPaint paint;
1238 canvas->scale(4, 4);
1239 for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) {
1240 paint.setColor(color);
1241 canvas->drawBitmap(bitmap, 0, 0, &paint);
1242 canvas->translate(12, 0);
1243 }
Cary Clark2dc84ad2018-01-26 12:56:22 -05001244##
1245
Cary Clark1a8d7622018-03-05 13:26:16 -05001246#SeeAlso MakeN32 MakeS32 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001247
1248#Method ##
1249
1250# ------------------------------------------------------------------------------
1251
1252#Method static SkImageInfo MakeUnknown(int width, int height)
1253
Cary Clark4855f782018-02-06 09:41:53 -05001254#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001255#Line # creates Image_Info with kUnknown_SkColorType, kUnknown_SkAlphaType ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001256Creates Image_Info from integral dimensions width and height, kUnknown_SkColorType,
1257kUnknown_SkAlphaType, with Color_Space set to nullptr.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001258
Cary Clark1a8d7622018-03-05 13:26:16 -05001259Returned Image_Info as part of source does not draw, and as part of destination
1260can not be drawn to.
1261
1262#Param width pixel column count; must be zero or greater ##
1263#Param height pixel row count; must be zero or greater ##
1264
1265#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001266
1267#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001268#Height 32
1269#Width 384
1270SkImageInfo info; // default constructor
1271SkString string;
1272string.printf("SkImageInfo() %c= SkImageInfo::MakeUnknown(0, 0)",
1273 info == SkImageInfo::MakeUnknown(0, 0) ? '=' : '!');
1274SkPaint paint;
1275canvas->drawString(string, 0, 12, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001276##
1277
Cary Clark1a8d7622018-03-05 13:26:16 -05001278#SeeAlso SkImageInfo() MakeN32 MakeS32 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001279
1280#Method ##
1281
1282# ------------------------------------------------------------------------------
1283
1284#Method static SkImageInfo MakeUnknown()
1285
Cary Clark4855f782018-02-06 09:41:53 -05001286#In Constructor
Cary Clark1a8d7622018-03-05 13:26:16 -05001287Creates Image_Info from integral dimensions width and height set to zero,
1288kUnknown_SkColorType, kUnknown_SkAlphaType, with Color_Space set to nullptr.
1289
1290Returned Image_Info as part of source does not draw, and as part of destination
1291can not be drawn to.
1292
1293#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001294
1295#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001296#Height 32
1297#Width 384
1298SkImageInfo info; // default constructor
1299SkString string;
1300string.printf("SkImageInfo() %c= SkImageInfo::MakeUnknown()",
1301 info == SkImageInfo::MakeUnknown() ? '=' : '!');
1302SkPaint paint;
1303canvas->drawString(string, 0, 12, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001304##
1305
Cary Clark1a8d7622018-03-05 13:26:16 -05001306#SeeAlso SkImageInfo() MakeN32 MakeS32 Make
Cary Clark2dc84ad2018-01-26 12:56:22 -05001307
1308#Method ##
1309
Cary Clark2dc84ad2018-01-26 12:56:22 -05001310
1311# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05001312#Subtopic Property
1313#Populate
1314#Line # metrics and attributes ##
1315##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001316
1317#Method int width() const
Cary Clark78de7512018-02-07 07:27:09 -05001318#In Property
Cary Clark1a8d7622018-03-05 13:26:16 -05001319#Line # returns pixel column count ##
1320Returns pixel count in each row.
1321
1322#Return pixel width ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001323
1324#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001325#Image 4
1326#Height 96
1327 canvas->translate(10, 10);
1328 canvas->drawBitmap(source, 0, 0);
1329 SkImageInfo imageInfo = source.info();
1330 canvas->translate(0, imageInfo.height());
1331 SkPaint paint;
1332 paint.setTextAlign(SkPaint::kCenter_Align);
1333 canvas->drawLine(0, 10, imageInfo.width(), 10, paint);
1334 canvas->drawString("width", imageInfo.width() / 2, 25, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001335##
1336
Cary Clark1a8d7622018-03-05 13:26:16 -05001337#SeeAlso height SkBitmap::width SkPixelRef::width SkImage::width SkSurface::width
Cary Clark2dc84ad2018-01-26 12:56:22 -05001338
1339#Method ##
1340
1341# ------------------------------------------------------------------------------
1342
1343#Method int height() const
Cary Clark78de7512018-02-07 07:27:09 -05001344#In Property
Cary Clark1a8d7622018-03-05 13:26:16 -05001345#Line # returns pixel row count ##
1346Returns pixel row count.
1347
1348#Return pixel height ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001349
1350#Example
Cary Clark1a8d7622018-03-05 13:26:16 -05001351#Image 4
1352#Height 96
1353 canvas->translate(10, 20);
1354 canvas->drawBitmap(source, 0, 0);
1355 SkImageInfo imageInfo = source.info();
1356 SkPaint paint;
1357 paint.setTextAlign(SkPaint::kCenter_Align);
1358 paint.setVerticalText(true);
1359 canvas->drawLine(imageInfo.width() + 10, 0, imageInfo.width() + 10, imageInfo.height(), paint);
1360 canvas->drawString("height", imageInfo.width() + 25, imageInfo.height() / 2, paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001361##
1362
Cary Clark1a8d7622018-03-05 13:26:16 -05001363#SeeAlso width SkBitmap::height SkPixelRef::height SkImage::height SkSurface::height
Cary Clark2dc84ad2018-01-26 12:56:22 -05001364
1365#Method ##
1366
1367# ------------------------------------------------------------------------------
1368
1369#Method SkColorType colorType() const
Cary Clark78de7512018-02-07 07:27:09 -05001370#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001371#Line # returns Color_Type ##
Cary Clark1a8d7622018-03-05 13:26:16 -05001372Returns Color_Type, one of: #list_of_color_types#.
1373
1374#Return Color_Type ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001375
1376#Example
Cary Clark681287e2018-03-16 11:34:15 -04001377 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
1378 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
1379 SkImageInfo info = SkImageInfo::MakeA8(16, 32);
1380 SkDebugf("color type: k" "%s" "_SkColorType\n", colors[info.colorType()]);
1381#StdOut
1382color type: kAlpha_8_SkColorType
1383##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001384##
1385
Cary Clark681287e2018-03-16 11:34:15 -04001386#SeeAlso alphaType SkPixmap::colorType SkBitmap::colorType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001387
1388#Method ##
1389
1390# ------------------------------------------------------------------------------
1391
1392#Method SkAlphaType alphaType() const
Cary Clark78de7512018-02-07 07:27:09 -05001393#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001394#Line # Returns Alpha_Type ##
1395Returns Alpha_Type, one of: #list_of_alpha_types#.
1396
1397#Return Alpha_Type ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001398
1399#Example
Cary Clark681287e2018-03-16 11:34:15 -04001400 const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
1401 SkImageInfo info = SkImageInfo::MakeA8(16, 32);
1402 SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[info.alphaType()]);
1403#StdOut
1404alpha type: kPremul_SkAlphaType
1405##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001406##
1407
Cary Clark681287e2018-03-16 11:34:15 -04001408#SeeAlso colorType SkPixmap::alphaType SkBitmap::alphaType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001409
1410#Method ##
1411
1412# ------------------------------------------------------------------------------
1413
1414#Method SkColorSpace* colorSpace() const
Cary Clark78de7512018-02-07 07:27:09 -05001415#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001416#Line # returns Color_Space ##
1417Returns Color_Space, the range of colors. The reference count of
1418Color_Space is unchanged. The returned Color_Space is immutable.
1419
1420#Return Color_Space, or nullptr ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001421
1422#Example
Cary Clark681287e2018-03-16 11:34:15 -04001423#Description
1424SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma
1425and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma.
1426##
1427 SkImageInfo info = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
1428 SkColorSpace::MakeSRGBLinear());
1429 SkColorSpace* colorSpace = info.colorSpace();
1430 SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
1431 colorSpace->gammaCloseToSRGB() ? "true" : "false",
1432 colorSpace->gammaIsLinear() ? "true" : "false",
1433 colorSpace->isSRGB() ? "true" : "false");
1434#StdOut
1435gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
1436##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001437##
1438
Cary Clark681287e2018-03-16 11:34:15 -04001439#SeeAlso Color_Space SkPixmap::colorSpace SkBitmap::colorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001440
1441#Method ##
1442
1443# ------------------------------------------------------------------------------
1444
1445#Method sk_sp<SkColorSpace> refColorSpace() const
Cary Clark78de7512018-02-07 07:27:09 -05001446#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001447#Line # returns Color_Space ##
1448Returns smart pointer to Color_Space, the range of colors. The smart pointer
1449tracks the number of objects sharing this Color_Space reference so the memory
1450is released when the owners destruct.
1451
1452The returned Color_Space is immutable.
1453
1454#Return Color_Space wrapped in a smart pointer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001455
1456#Example
Cary Clark681287e2018-03-16 11:34:15 -04001457 SkImageInfo info1 = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
1458 SkColorSpace::MakeSRGBLinear());
1459 SkImageInfo info2 = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
1460 info1.refColorSpace());
1461 SkColorSpace* colorSpace = info2.colorSpace();
1462 SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
1463 colorSpace->gammaCloseToSRGB() ? "true" : "false",
1464 colorSpace->gammaIsLinear() ? "true" : "false",
1465 colorSpace->isSRGB() ? "true" : "false");
Cary Clark2dc84ad2018-01-26 12:56:22 -05001466##
1467
Cary Clark681287e2018-03-16 11:34:15 -04001468#SeeAlso Color_Space SkBitmap::refColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001469
1470#Method ##
1471
1472# ------------------------------------------------------------------------------
1473
1474#Method bool isEmpty() const
Cary Clark78de7512018-02-07 07:27:09 -05001475#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001476#Line # returns if dimensions contain pixels ##
1477
1478Returns if Image_Info describes an empty area of pixels by checking if either
1479width or height is zero or smaller.
1480
1481#Return true if either dimension is zero or smaller ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001482
1483#Example
Cary Clark681287e2018-03-16 11:34:15 -04001484 for (int width : { 0, 2 } ) {
1485 for (int height : { 0, 2 } ) {
1486 SkImageInfo imageInfo= SkImageInfo::MakeA8(width, height);
1487 SkDebugf("width: %d height: %d empty: %s\n", width, height,
1488 imageInfo.isEmpty() ? "true" : "false");
1489 }
1490 }
1491#StdOut
1492width: 0 height: 0 empty: true
1493width: 0 height: 2 empty: true
1494width: 2 height: 0 empty: true
1495width: 2 height: 2 empty: false
1496##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001497##
1498
Cary Clark681287e2018-03-16 11:34:15 -04001499#SeeAlso dimensions bounds SkBitmap::empty SkPixmap::bounds
Cary Clark2dc84ad2018-01-26 12:56:22 -05001500
1501#Method ##
1502
1503# ------------------------------------------------------------------------------
1504
1505#Method bool isOpaque() const
Cary Clark78de7512018-02-07 07:27:09 -05001506#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001507#Line # returns if Alpha_Type is kOpaque_SkAlphaType ##
1508
1509Returns true if Alpha_Type is set to hint that all pixels are opaque; their
1510Color_Alpha value is implicitly or explicitly 1.0. If true, and all pixels are
1511not opaque, Skia may draw incorrectly.
1512
1513Does not check if Color_Type allows Alpha, or if any pixel value has
1514transparency.
1515
1516#Return true if Alpha_Type is kOpaque_SkAlphaType ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001517
1518#Example
Cary Clark681287e2018-03-16 11:34:15 -04001519 const int height = 2;
1520 const int width = 2;
1521 SkBitmap bitmap;
1522 SkImageInfo imageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType);
1523 bitmap.setInfo(imageInfo);
1524 for (int index = 0; index < 2; ++index) {
1525 bitmap.allocPixels();
1526 bitmap.eraseColor(0x00000000);
1527 SkDebugf("isOpaque: %s\n", imageInfo.isOpaque() ? "true" : "false");
1528 bitmap.eraseColor(0xFFFFFFFF);
1529 SkDebugf("isOpaque: %s\n", imageInfo.isOpaque() ? "true" : "false");
1530 imageInfo = imageInfo.makeAlphaType(kOpaque_SkAlphaType);
1531 bitmap.setInfo(imageInfo);
1532 }
1533#StdOut
1534isOpaque: false
1535isOpaque: false
1536isOpaque: true
1537isOpaque: true
1538##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001539##
1540
Cary Clark681287e2018-03-16 11:34:15 -04001541#SeeAlso Color_Alpha SkColorTypeValidateAlphaType SkBitmap::isOpaque SkImage::isOpaque SkPixmap::isOpaque
Cary Clark2dc84ad2018-01-26 12:56:22 -05001542
1543#Method ##
1544
1545# ------------------------------------------------------------------------------
1546
1547#Method SkISize dimensions() const
Cary Clark78de7512018-02-07 07:27:09 -05001548#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001549#Line # returns width() and height() ##
1550
1551Returns ISize { width(), height() }.
1552
1553#Return integral size of width() and height() ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001554
1555#Example
Cary Clark681287e2018-03-16 11:34:15 -04001556 const int height = 2;
1557 const int width = 2;
1558 SkImageInfo imageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType);
1559 SkISize dimensions = imageInfo.dimensions();
1560 SkIRect bounds = imageInfo.bounds();
1561 SkIRect dimensionsAsBounds = SkIRect::MakeSize(dimensions);
1562 SkDebugf("dimensionsAsBounds %c= bounds\n", dimensionsAsBounds == bounds ? '=' : '!');
1563#StdOut
1564dimensionsAsBounds == bounds
1565##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001566##
1567
Cary Clark681287e2018-03-16 11:34:15 -04001568#SeeAlso width height bounds SkBitmap::dimensions
Cary Clark2dc84ad2018-01-26 12:56:22 -05001569
1570#Method ##
1571
1572# ------------------------------------------------------------------------------
1573
1574#Method SkIRect bounds() const
Cary Clark78de7512018-02-07 07:27:09 -05001575#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001576#Line # returns width() and height() as Rectangle ##
1577Returns IRect { 0, 0, width(), height() }.
1578
1579#Return integral rectangle from origin to width() and height() ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001580
1581#Example
Cary Clark681287e2018-03-16 11:34:15 -04001582#Height 64
1583#Image 4
1584 canvas->scale(.5f, .5f);
1585 SkImageInfo imageInfo = source.info();
1586 SkIRect bounds = imageInfo.bounds();
1587 for (int x : { 0, bounds.width() } ) {
1588 for (int y : { 0, bounds.height() } ) {
1589 canvas->drawBitmap(source, x, y);
1590 }
1591 }
Cary Clark2dc84ad2018-01-26 12:56:22 -05001592##
1593
Cary Clark681287e2018-03-16 11:34:15 -04001594#SeeAlso width height dimensions
Cary Clark2dc84ad2018-01-26 12:56:22 -05001595
1596#Method ##
1597
1598# ------------------------------------------------------------------------------
1599
1600#Method bool gammaCloseToSRGB() const
Cary Clark78de7512018-02-07 07:27:09 -05001601#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001602#Line # Returns if Color_Space gamma is approximately the same as sRGB ##
1603
1604Returns true if associated Color_Space is not nullptr, and Color_Space gamma
1605is approximately the same as sRGB.
1606This includes the
1607###$
1608$A sRGB transfer function $ https://en.wikipedia.org/wiki/SRGB#The_sRGB_transfer_function_(%22gamma%22) $$
1609$$$#
1610as well as a gamma curve described by a 2.2 exponent.
1611
1612#Return true if Color_Space gamma is approximately the same as sRGB ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001613
1614#Example
Cary Clark681287e2018-03-16 11:34:15 -04001615#Height 144
1616 const int width = 256;
1617 const int height = 64;
1618 auto drawLabel = [=](const char* what, bool closeToSRGB) -> void {
1619 SkString string;
1620 string.printf("%s gamma is %s" "close to sRGB", what, closeToSRGB ? "" : "not ");
1621 SkPaint paint;
1622 paint.setAntiAlias(true);
1623 paint.setTextAlign(SkPaint::kCenter_Align);
1624 canvas->drawString(string, width / 2, 56, paint);
1625 };
1626 SkColor gradColors[] = { 0xFFFF7F00, 0xFF00FF7F, 0xFF0000FF, 0xFF7F7FFF };
1627 SkPoint gradPoints[] = { { 0, 0 }, { width, 0 }, { width * 2, 0 }, { width * 3, 0 } };
1628 SkPaint gradPaint;
1629 gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1630 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1631 canvas->drawRect(SkRect::MakeWH(width, height), gradPaint);
1632 drawLabel("canvas", canvas->imageInfo().gammaCloseToSRGB());
1633 SkBitmap bitmap;
1634 SkImageInfo offscreenInfo = SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType);
1635 bitmap.allocPixels(offscreenInfo);
1636 SkCanvas sRGBOffscreen(bitmap);
1637 sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1638 canvas->translate(0, 80);
1639 canvas->drawBitmap(bitmap, 0, 0);
1640 drawLabel("offscreen", offscreenInfo.gammaCloseToSRGB());
Cary Clark2dc84ad2018-01-26 12:56:22 -05001641##
1642
Cary Clark681287e2018-03-16 11:34:15 -04001643#SeeAlso SkColorSpace::gammaCloseToSRGB
Cary Clark2dc84ad2018-01-26 12:56:22 -05001644
1645#Method ##
1646
1647# ------------------------------------------------------------------------------
1648
1649#Method SkImageInfo makeWH(int newWidth, int newHeight) const
Cary Clark78de7512018-02-07 07:27:09 -05001650#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001651#Line # creates Image_Info with changed dimensions ##
Cary Clark681287e2018-03-16 11:34:15 -04001652Creates Image_Info with the same Color_Type, Color_Space, and Alpha_Type,
1653with dimensions set to width and height.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001654
Cary Clark681287e2018-03-16 11:34:15 -04001655#Param newWidth pixel column count; must be zero or greater ##
1656#Param newHeight pixel row count; must be zero or greater ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001657
Cary Clark681287e2018-03-16 11:34:15 -04001658#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001659
1660#Example
Cary Clark681287e2018-03-16 11:34:15 -04001661#Height 144
1662#Image 3
1663 SkImageInfo canvasImageInfo = canvas->imageInfo();
1664 SkRect canvasBounds = SkRect::Make(canvasImageInfo.bounds());
1665 canvas->drawBitmapRect(source, source.bounds(), canvasBounds, nullptr);
1666 SkImageInfo insetImageInfo =
1667 canvasImageInfo.makeWH(canvasBounds.width() / 2, canvasBounds.height() / 2);
1668 SkBitmap inset;
1669 inset.allocPixels(insetImageInfo);
1670 SkCanvas offscreen(inset);
1671 offscreen.drawBitmapRect(source, source.bounds(), SkRect::Make(inset.bounds()), nullptr);
1672 canvas->drawBitmap(inset, canvasBounds.width() / 4, canvasBounds.height() / 4);
Cary Clark2dc84ad2018-01-26 12:56:22 -05001673##
1674
Cary Clark681287e2018-03-16 11:34:15 -04001675#SeeAlso Make makeAlphaType makeColorSpace makeColorType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001676
1677#Method ##
1678
1679# ------------------------------------------------------------------------------
1680
1681#Method SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const
Cary Clark78de7512018-02-07 07:27:09 -05001682#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001683#Line # creates Image_Info with changed Alpha_Type ##
Cary Clark681287e2018-03-16 11:34:15 -04001684Creates Image_Info with same Color_Type, Color_Space, width, and height,
1685with Alpha_Type set to newAlphaType.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001686
Cary Clark681287e2018-03-16 11:34:15 -04001687Created Image_Info contains newAlphaType even if it is incompatible with
1688Color_Type, in which case Alpha_Type in Image_Info is ignored.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001689
Cary Clark681287e2018-03-16 11:34:15 -04001690#Param newAlphaType one of: #list_of_alpha_types#
Cary Clark2dc84ad2018-01-26 12:56:22 -05001691##
1692
Cary Clark681287e2018-03-16 11:34:15 -04001693#Return created Image_Info ##
1694
1695#Example
1696#Image 3
1697 const int width = 256;
1698 const int height = 128;
1699 SkColor pixels[height][width];
1700 for (int y = 0; y < height; ++y) {
1701 for (int x = 0; x < width; ++x) {
1702 int red = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 4 + y) * 0.03f)));
1703 int blue = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 3 + y) * 0.04f)));
1704 int green = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 2 + y) * 0.05f)));
1705 int alpha = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 1 + y) * 0.006f)));
1706 pixels[y][x] =
1707 SkColorSetARGB(alpha, red * alpha / 255, green * alpha / 255, blue * alpha / 255);
1708 }
1709 }
1710 SkBitmap bitmap;
1711 SkImageInfo info = SkImageInfo::Make(width, height, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
1712 bitmap.installPixels(info, (void*) pixels, sizeof(SkColor) * width);
1713 canvas->drawBitmap(source, 0, 0);
1714 canvas->drawBitmap(bitmap, 0, 0);
1715 SkImageInfo unpremulInfo = info.makeAlphaType(kUnpremul_SkAlphaType);
1716 bitmap.installPixels(unpremulInfo, (void*) pixels, sizeof(SkColor) * width);
1717 canvas->drawBitmap(bitmap, 0, 128);
1718##
1719
1720#SeeAlso Make MakeA8 makeColorType makeColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001721
1722#Method ##
1723
1724# ------------------------------------------------------------------------------
1725
1726#Method SkImageInfo makeColorType(SkColorType newColorType) const
Cary Clark78de7512018-02-07 07:27:09 -05001727#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001728#Line # creates Image_Info with changed Color_Type ##
Cary Clark681287e2018-03-16 11:34:15 -04001729Creates Image_Info with same Alpha_Type, Color_Space, width, and height,
1730with Color_Type set to newColorType.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001731
Cary Clark681287e2018-03-16 11:34:15 -04001732#Param newColorType one of: #list_of_color_types#
Cary Clark2dc84ad2018-01-26 12:56:22 -05001733##
1734
Cary Clark681287e2018-03-16 11:34:15 -04001735#Return created Image_Info ##
1736
1737#Example
1738 const int width = 256;
1739 const int height = 128;
1740 SkColor pixels[height][width];
1741 for (int y = 0; y < height; ++y) {
1742 for (int x = 0; x < width; ++x) {
1743 int red = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 4 + y) * 0.03f)));
1744 int blue = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 3 + y) * 0.04f)));
1745 int green = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 2 + y) * 0.05f)));
1746 int alpha = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 1 + y) * 0.006f)));
1747 pixels[y][x] =
1748 SkColorSetARGB(alpha, red * alpha / 255, green * alpha / 255, blue * alpha / 255);
1749 }
1750 }
1751 SkBitmap bitmap;
1752 SkImageInfo info = SkImageInfo::Make(width, height, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
1753 bitmap.installPixels(info, (void*) pixels, sizeof(SkColor) * width);
1754 canvas->drawBitmap(source, 0, 0);
1755 canvas->drawBitmap(bitmap, 0, 0);
1756 SkImageInfo rgbaInfo = info.makeColorType(kRGBA_8888_SkColorType);
1757 bitmap.installPixels(rgbaInfo, (void*) pixels, sizeof(SkColor) * width);
1758 canvas->drawBitmap(bitmap, 0, 128);
1759##
1760
1761#SeeAlso Make makeAlphaType makeColorSpace
Cary Clark2dc84ad2018-01-26 12:56:22 -05001762
1763#Method ##
1764
1765# ------------------------------------------------------------------------------
1766
1767#Method SkImageInfo makeColorSpace(sk_sp<SkColorSpace> cs) const
Cary Clark78de7512018-02-07 07:27:09 -05001768#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001769#Line # creates Image_Info with changed Color_Space ##
Cary Clark681287e2018-03-16 11:34:15 -04001770Creates Image_Info with same Alpha_Type, Color_Type, width, and height,
1771with Color_Space set to cs.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001772
Cary Clark681287e2018-03-16 11:34:15 -04001773#Param cs range of colors; may be nullptr ##
1774
1775#Return created Image_Info ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001776
1777#Example
Cary Clark681287e2018-03-16 11:34:15 -04001778#Height 224
1779 const int width = 256;
1780 const int height = 64;
1781 auto drawLabel = [=](const char* what, bool closeToSRGB) -> void {
1782 SkString string;
1783 string.printf("%s gamma is %s" "close to sRGB", what, closeToSRGB ? "" : "not ");
1784 SkPaint paint;
1785 paint.setAntiAlias(true);
1786 paint.setTextAlign(SkPaint::kCenter_Align);
1787 canvas->drawString(string, width / 2, 56, paint);
1788 };
1789 SkColor gradColors[] = { 0xFFFF7F00, 0xFF00FF7F, 0xFF0000FF, 0xFF7F7FFF };
1790 SkPoint gradPoints[] = { { 0, 0 }, { width, 0 }, { width * 2, 0 }, { width * 3, 0 } };
1791 SkPaint gradPaint;
1792 gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
1793 SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
1794 canvas->drawRect(SkRect::MakeWH(width, height), gradPaint);
1795 drawLabel("canvas", canvas->imageInfo().gammaCloseToSRGB());
1796 SkBitmap bitmap;
1797 SkImageInfo offscreenInfo = SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType);
1798 bitmap.allocPixels(offscreenInfo);
1799 SkCanvas sRGBOffscreen(bitmap);
1800 sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1801 canvas->translate(0, 80);
1802 canvas->drawBitmap(bitmap, 0, 0);
1803 drawLabel("offscreen", offscreenInfo.gammaCloseToSRGB());
1804 SkImageInfo linearGamma =
1805 offscreenInfo.makeColorSpace(offscreenInfo.colorSpace()->makeLinearGamma());
1806 bitmap.allocPixels(linearGamma);
1807 SkCanvas lgOffscreen(bitmap);
1808 lgOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
1809 canvas->translate(0, 80);
1810 canvas->drawBitmap(bitmap, 0, 0);
1811 drawLabel("linear", linearGamma.gammaCloseToSRGB());
Cary Clark2dc84ad2018-01-26 12:56:22 -05001812##
1813
Cary Clark681287e2018-03-16 11:34:15 -04001814#SeeAlso Make MakeS32 makeAlphaType makeColorType
Cary Clark2dc84ad2018-01-26 12:56:22 -05001815
1816#Method ##
1817
1818# ------------------------------------------------------------------------------
1819
1820#Method int bytesPerPixel() const
Cary Clark78de7512018-02-07 07:27:09 -05001821#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001822#Line # returns number of bytes in pixel based on Color_Type ##
1823Returns number of bytes per pixel required by Color_Type.
1824Returns zero if colorType( is kUnknown_SkColorType.
1825
1826#Return bytes in pixel ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001827
1828#Example
Cary Clark681287e2018-03-16 11:34:15 -04001829 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
1830 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
1831 for (SkColorType colorType : { #list_of_color_types#
1832 } ) {
1833 SkImageInfo info = SkImageInfo::Make(1, 1, colorType, kOpaque_SkAlphaType);
1834 SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d\n",
1835 colors[colorType], 13 - strlen(colors[colorType]), " ",
1836 info.bytesPerPixel());
1837 }
1838#StdOut
1839color: kUnknown_SkColorType bytesPerPixel: 0
1840color: kAlpha_8_SkColorType bytesPerPixel: 1
1841color: kRGB_565_SkColorType bytesPerPixel: 2
1842color: kARGB_4444_SkColorType bytesPerPixel: 2
1843color: kRGBA_8888_SkColorType bytesPerPixel: 4
1844color: kRGB_888x_SkColorType bytesPerPixel: 4
1845color: kBGRA_8888_SkColorType bytesPerPixel: 4
1846color: kRGBA_1010102_SkColorType bytesPerPixel: 4
1847color: kRGB_101010x_SkColorType bytesPerPixel: 4
1848color: kGray_8_SkColorType bytesPerPixel: 1
1849color: kRGBA_F16_SkColorType bytesPerPixel: 8
1850##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001851##
1852
Cary Clark681287e2018-03-16 11:34:15 -04001853#SeeAlso width shiftPerPixel SkBitmap::bytesPerPixel
Cary Clark2dc84ad2018-01-26 12:56:22 -05001854
1855#Method ##
1856
1857# ------------------------------------------------------------------------------
1858
1859#Method int shiftPerPixel() const
Cary Clark78de7512018-02-07 07:27:09 -05001860#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001861#Line # returns bit shift from pixels to bytes ##
1862Returns bit shift converting row bytes to row pixels.
1863Returns zero for kUnknown_SkColorType.
1864
1865#Return one of: 0, 1, 2, 3; left shift to convert pixels to bytes ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001866
1867#Example
Cary Clark681287e2018-03-16 11:34:15 -04001868 const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
1869 "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
1870 for (SkColorType colorType : { #list_of_color_types#
1871 } ) {
1872 SkImageInfo info = SkImageInfo::Make(1, 1, colorType, kOpaque_SkAlphaType);
1873 SkDebugf("color: k" "%s" "_SkColorType" "%*s" "shiftPerPixel: %d\n",
1874 colors[colorType], 14 - strlen(colors[colorType]), " ",
1875 info.shiftPerPixel());
1876 }
1877#StdOut
1878color: kUnknown_SkColorType shiftPerPixel: 0
1879color: kAlpha_8_SkColorType shiftPerPixel: 0
1880color: kRGB_565_SkColorType shiftPerPixel: 1
1881color: kARGB_4444_SkColorType shiftPerPixel: 1
1882color: kRGBA_8888_SkColorType shiftPerPixel: 2
1883color: kRGB_888x_SkColorType shiftPerPixel: 2
1884color: kBGRA_8888_SkColorType shiftPerPixel: 2
1885color: kRGBA_1010102_SkColorType shiftPerPixel: 2
1886color: kRGB_101010x_SkColorType shiftPerPixel: 2
1887color: kGray_8_SkColorType shiftPerPixel: 0
1888color: kRGBA_F16_SkColorType shiftPerPixel: 3
1889##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001890##
1891
Cary Clark06c20f32018-03-20 15:53:27 -04001892#SeeAlso bytesPerPixel minRowBytes SkBitmap::shiftPerPixel SkPixmap::shiftPerPixel
Cary Clark2dc84ad2018-01-26 12:56:22 -05001893
1894#Method ##
1895
1896# ------------------------------------------------------------------------------
1897
1898#Method uint64_t minRowBytes64() const
Cary Clark78de7512018-02-07 07:27:09 -05001899#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001900#Line # returns width() times bytesPerPixel in 64 bits ##
1901
1902Returns minimum bytes per row, computed from pixel width() and Color_Type, which
1903specifies bytesPerPixel(). Bitmap maximum value for row bytes must be representable
1904as a positive value in a 32-bit signed integer.
1905
1906#Return width() times bytesPerPixel as unsigned 64-bit integer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001907
1908#Example
Cary Clark681287e2018-03-16 11:34:15 -04001909 for (int shift = 24; shift < 32; ++shift) {
1910 int width = 1 << shift;
1911 SkImageInfo imageInfo =
1912 SkImageInfo::Make(width, 1, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
1913 uint64_t minRowBytes = imageInfo.minRowBytes64();
1914 bool widthTooLarge = (uint64_t) (int32_t) minRowBytes != minRowBytes;
1915 SkDebugf("RGBA_F16 width %d (0x%08x) %s\n",
1916 width, width, widthTooLarge ? "too large" : "OK");
1917 }
1918#StdOut
1919RGBA_F16 width 16777216 (0x01000000) OK
1920RGBA_F16 width 33554432 (0x02000000) OK
1921RGBA_F16 width 67108864 (0x04000000) OK
1922RGBA_F16 width 134217728 (0x08000000) OK
1923RGBA_F16 width 268435456 (0x10000000) too large
1924RGBA_F16 width 536870912 (0x20000000) too large
1925RGBA_F16 width 1073741824 (0x40000000) too large
1926RGBA_F16 width -2147483648 (0x80000000) too large
1927##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001928##
1929
Cary Clark681287e2018-03-16 11:34:15 -04001930#SeeAlso minRowBytes computeByteSize computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05001931
1932#Method ##
1933
1934# ------------------------------------------------------------------------------
1935
1936#Method size_t minRowBytes() const
Cary Clark78de7512018-02-07 07:27:09 -05001937#In Property
Cary Clark681287e2018-03-16 11:34:15 -04001938#Line # returns width() times bytesPerPixel in 32 bits ##
1939
1940Returns minimum bytes per row, computed from pixel width() and Color_Type, which
1941specifies bytesPerPixel(). Bitmap maximum value for row bytes must be representable
1942as a positive value in a 32-bit signed integer.
1943
1944#Return width() times bytesPerPixel as signed 32-bit integer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001945
1946#Example
Cary Clark681287e2018-03-16 11:34:15 -04001947 for (int shift = 24; shift < 32; ++shift) {
1948 int width = 1 << shift;
1949 SkImageInfo imageInfo =
1950 SkImageInfo::Make(width, 1, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
1951 size_t minRowBytes = imageInfo.minRowBytes();
1952 bool widthTooLarge = !minRowBytes;
1953 SkDebugf("RGBA_F16 width %d (0x%08x) %s\n",
1954 width, width, widthTooLarge ? "too large" : "OK");
1955 }
1956#StdOut
1957RGBA_F16 width 16777216 (0x01000000) OK
1958RGBA_F16 width 33554432 (0x02000000) OK
1959RGBA_F16 width 67108864 (0x04000000) OK
1960RGBA_F16 width 134217728 (0x08000000) OK
1961RGBA_F16 width 268435456 (0x10000000) too large
1962RGBA_F16 width 536870912 (0x20000000) too large
1963RGBA_F16 width 1073741824 (0x40000000) too large
1964RGBA_F16 width -2147483648 (0x80000000) too large
1965##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001966##
1967
Cary Clark681287e2018-03-16 11:34:15 -04001968#SeeAlso minRowBytes64 computeByteSize computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05001969
1970#Method ##
1971
1972# ------------------------------------------------------------------------------
1973
1974#Method size_t computeOffset(int x, int y, size_t rowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05001975#In Utility
Cary Clark681287e2018-03-16 11:34:15 -04001976#Line # returns byte offset within pixel array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001977
Cary Clark681287e2018-03-16 11:34:15 -04001978Returns byte offset of pixel from pixel base address.
1979
1980Asserts in debug build if x or y is outside of bounds. Does not assert if
1981rowBytes is smaller than minRowBytes, even though result may be incorrect.
1982
1983#Param x column index, zero or greater, and less than width() ##
1984#Param y row index, zero or greater, and less than height() ##
1985#Param rowBytes size of pixel row or larger ##
1986
1987#Return offset within pixel array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001988
1989#Example
Cary Clark06c20f32018-03-20 15:53:27 -04001990#Height 128
Cary Clark681287e2018-03-16 11:34:15 -04001991 uint8_t pixels[][12] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00},
1992 { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00},
1993 { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00},
1994 { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF},
1995 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1996 { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00},
1997 { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00},
1998 { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00} };
1999 SkImageInfo imageInfo = SkImageInfo::MakeA8(8, 8);
2000 SkBitmap bitmap;
2001 bitmap.installPixels(imageInfo, (void*) pixels, sizeof(pixels[0]));
2002 SkPaint paint;
2003 paint.setColor(SK_ColorRED);
2004 canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint);
2005 size_t offset = imageInfo.computeOffset(2, 3, sizeof(pixels[0]));
2006 pixels[0][offset] = 0x7F;
2007 offset = imageInfo.computeOffset(5, 3, sizeof(pixels[0]));
2008 pixels[0][offset] = 0x7F;
2009 bitmap.installPixels(imageInfo, (void*) pixels, sizeof(pixels[0]));
2010 canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(128, 128), &paint);
Cary Clark2dc84ad2018-01-26 12:56:22 -05002011##
2012
Cary Clark06c20f32018-03-20 15:53:27 -04002013#SeeAlso height width minRowBytes computeByteSize
Cary Clark2dc84ad2018-01-26 12:56:22 -05002014
2015#Method ##
2016
2017# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05002018#Subtopic Operator
2019#Populate
2020##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002021
2022#Method bool operator==(const SkImageInfo& other)_const
Cary Clark06c20f32018-03-20 15:53:27 -04002023#Line # compares Image_Info for equality ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002024
Cary Clark06c20f32018-03-20 15:53:27 -04002025Compares Image_Info with other, and returns true if width, height, Color_Type,
2026Alpha_Type, and Color_Space are equivalent.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002027
Cary Clark06c20f32018-03-20 15:53:27 -04002028#Param other Image_Info to compare ##
2029
2030#Return true if Image_Info equals other ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002031
2032#Example
Cary Clark06c20f32018-03-20 15:53:27 -04002033 SkImageInfo info1 = SkImageInfo::Make(10, 20, kGray_8_SkColorType, kPremul_SkAlphaType);
2034 SkImageInfo info2 = SkImageInfo::Make(20, 10, kAlpha_8_SkColorType, kUnpremul_SkAlphaType);
2035 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
2036 info2 = info2.makeWH(10, 20);
2037 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
2038 info2 = info2.makeColorType(kGray_8_SkColorType);
2039 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
2040 info2 = info2.makeAlphaType(kPremul_SkAlphaType);
2041 SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!');
2042#StdOut
2043info1 != info2
2044info1 != info2
2045info1 != info2
2046info1 == info2
2047##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002048##
2049
Cary Clark06c20f32018-03-20 15:53:27 -04002050#SeeAlso operator!=(const SkImageInfo& other)_const SkColorSpace::Equals
Cary Clark2dc84ad2018-01-26 12:56:22 -05002051
2052#Method ##
2053
2054# ------------------------------------------------------------------------------
2055
2056#Method bool operator!=(const SkImageInfo& other)_const
Cary Clark06c20f32018-03-20 15:53:27 -04002057#Line # compares Image_Info for inequality ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002058
Cary Clark06c20f32018-03-20 15:53:27 -04002059Compares Image_Info with other, and returns true if width, height, Color_Type,
2060Alpha_Type, and Color_Space are equivalent.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002061
Cary Clark06c20f32018-03-20 15:53:27 -04002062#Param other Image_Info to compare ##
2063
2064#Return true if Image_Info is not equal to other ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002065
2066#Example
Cary Clark06c20f32018-03-20 15:53:27 -04002067 SkImageInfo info1 = SkImageInfo::Make(10, 20, kGray_8_SkColorType, kPremul_SkAlphaType);
2068 SkImageInfo info2 = SkImageInfo::Make(20, 10, kAlpha_8_SkColorType, kUnpremul_SkAlphaType);
2069 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
2070 info2 = info2.makeWH(10, 20);
2071 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
2072 info2 = info2.makeColorType(kGray_8_SkColorType);
2073 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
2074 info2 = info2.makeAlphaType(kPremul_SkAlphaType);
2075 SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '=');
2076#StdOut
2077info1 != info2
2078info1 != info2
2079info1 != info2
2080info1 == info2
2081##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002082##
2083
Cary Clark06c20f32018-03-20 15:53:27 -04002084#SeeAlso operator==(const SkImageInfo& other)_const SkColorSpace::Equals
Cary Clark2dc84ad2018-01-26 12:56:22 -05002085
2086#Method ##
2087
2088# ------------------------------------------------------------------------------
2089
2090#Method size_t computeByteSize(size_t rowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05002091#In Utility
Cary Clark06c20f32018-03-20 15:53:27 -04002092#Line # memory required by pixel buffer with given row bytes ##
2093Returns storage required by pixel array, given Image_Info dimensions, Color_Type,
2094and rowBytes. rowBytes is assumed to be at least as large as minRowBytes().
Cary Clark2dc84ad2018-01-26 12:56:22 -05002095
Cary Clark06c20f32018-03-20 15:53:27 -04002096Returns zero if height is zero.
2097Returns SK_MaxSizeT if answer exceeds the range of size_t.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002098
Cary Clark06c20f32018-03-20 15:53:27 -04002099#Param rowBytes size of pixel row or larger ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002100
Cary Clark06c20f32018-03-20 15:53:27 -04002101#Return memory required by pixel buffer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002102
2103#Example
Cary Clark06c20f32018-03-20 15:53:27 -04002104#Height 130
2105 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2);
2106 const size_t size = info.computeByteSize(100000);
2107 SkAutoTMalloc<SkPMColor> storage(size);
2108 SkPMColor* pixels = storage.get();
2109 SkBitmap bitmap;
2110 bitmap.setInfo(info);
2111 bitmap.setPixels(pixels);
2112 bitmap.eraseColor(SK_ColorRED);
2113 canvas->scale(50, 50);
2114 canvas->rotate(8);
2115 canvas->drawBitmap(bitmap, 2, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05002116##
2117
Cary Clark06c20f32018-03-20 15:53:27 -04002118#SeeAlso computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002119
2120#Method ##
2121
2122# ------------------------------------------------------------------------------
2123
2124#Method size_t computeMinByteSize() const
Cary Clark78de7512018-02-07 07:27:09 -05002125#In Utility
Cary Clark06c20f32018-03-20 15:53:27 -04002126#Line # least memory required by pixel buffer ##
2127Returns storage required by pixel array, given Image_Info dimensions, and
2128Color_Type. Uses minRowBytes() to compute bytes for pixel row.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002129
Cary Clark06c20f32018-03-20 15:53:27 -04002130Returns zero if height is zero.
2131Returns SK_MaxSizeT if answer exceeds the range of size_t.
2132
2133#Return least memory required by pixel buffer ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002134
2135#Example
Cary Clark06c20f32018-03-20 15:53:27 -04002136#Height 130
2137 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2);
2138 const size_t size = info.computeMinByteSize();
2139 SkAutoTMalloc<SkPMColor> storage(size);
2140 SkPMColor* pixels = storage.get();
2141 SkBitmap bitmap;
2142 bitmap.setInfo(info);
2143 bitmap.setPixels(pixels);
2144 bitmap.eraseColor(SK_ColorRED);
2145 canvas->scale(50, 50);
2146 canvas->rotate(8);
2147 canvas->drawBitmap(bitmap, 2, 0);
Cary Clark2dc84ad2018-01-26 12:56:22 -05002148##
2149
Cary Clark06c20f32018-03-20 15:53:27 -04002150#SeeAlso computeByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002151
2152#Method ##
2153
2154# ------------------------------------------------------------------------------
2155
2156#Method static bool ByteSizeOverflowed(size_t byteSize)
Cary Clark78de7512018-02-07 07:27:09 -05002157#In Utility
Cary Clark06c20f32018-03-20 15:53:27 -04002158#Line # checks result of computeByteSize and computeMinByteSize ##
2159Returns true if byteSize equals SK_MaxSizeT. computeByteSize and
2160computeMinByteSize return SK_MaxSizeT if size_t can not hold buffer size.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002161
Cary Clark06c20f32018-03-20 15:53:27 -04002162#Param byteSize result of computeByteSize or computeMinByteSize ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002163
Cary Clark06c20f32018-03-20 15:53:27 -04002164#Return true if computeByteSize or computeMinByteSize result exceeds size_t ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002165
2166#Example
Cary Clark06c20f32018-03-20 15:53:27 -04002167 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 1000000000);
2168 for (size_t rowBytes = 100000000; rowBytes < 10000000000000LL; rowBytes *= 10) {
2169 const size_t size = info.computeByteSize(rowBytes);
2170 SkDebugf("rowBytes:%llu size:%llu overflowed:%s\n", rowBytes, size,
2171 SkImageInfo::ByteSizeOverflowed(size) ? "true" : "false");
2172 }
2173#StdOut
2174rowBytes:100000000 size:99999999900000008 overflowed:false
2175rowBytes:1000000000 size:999999999000000008 overflowed:false
2176rowBytes:10000000000 size:9999999990000000008 overflowed:false
2177rowBytes:100000000000 size:18446744073709551615 overflowed:true
2178rowBytes:1000000000000 size:18446744073709551615 overflowed:true
2179##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002180##
2181
Cary Clark06c20f32018-03-20 15:53:27 -04002182#SeeAlso computeByteSize computeMinByteSize validRowBytes
Cary Clark2dc84ad2018-01-26 12:56:22 -05002183
2184#Method ##
2185
2186# ------------------------------------------------------------------------------
2187
2188#Method bool validRowBytes(size_t rowBytes) const
Cary Clark78de7512018-02-07 07:27:09 -05002189#In Utility
Cary Clark06c20f32018-03-20 15:53:27 -04002190#Line # checks if row bytes is large enough to contain pixel row ##
2191Returns true if rowBytes is smaller than width times pixel size.
Cary Clark2dc84ad2018-01-26 12:56:22 -05002192
Cary Clark06c20f32018-03-20 15:53:27 -04002193#Param rowBytes size of pixel row or larger ##
2194
2195#Return true if rowBytes is large enough to contain pixel row ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002196
2197#Example
Cary Clark06c20f32018-03-20 15:53:27 -04002198 SkImageInfo info = SkImageInfo::MakeN32Premul(16, 8);
2199 for (size_t rowBytes = 60; rowBytes < 72; rowBytes += sizeof(SkPMColor)) {
2200 SkDebugf("validRowBytes(%llu): %s\n", rowBytes, info.validRowBytes(rowBytes) ?
2201 "true" : "false");
2202 }
2203#StdOut
2204validRowBytes(60): false
2205validRowBytes(64): true
2206validRowBytes(68): true
2207##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002208##
2209
Cary Clark06c20f32018-03-20 15:53:27 -04002210#SeeAlso ByteSizeOverflowed computeByteSize computeMinByteSize
Cary Clark2dc84ad2018-01-26 12:56:22 -05002211
2212#Method ##
2213
2214# ------------------------------------------------------------------------------
2215
2216#Method void reset()
Cary Clark78de7512018-02-07 07:27:09 -05002217#In Constructor
Cary Clark06c20f32018-03-20 15:53:27 -04002218#Line # sets zero dimensions, kUnknown_SkColorType, kUnknown_SkAlphaType ##
2219Creates an empty Image_Info with kUnknown_SkColorType, kUnknown_SkAlphaType,
2220a width and height of zero, and no Color_Space.
2221
Cary Clark2dc84ad2018-01-26 12:56:22 -05002222#Example
Cary Clark06c20f32018-03-20 15:53:27 -04002223 SkImageInfo info = SkImageInfo::MakeN32Premul(16, 8);
2224 SkImageInfo copy = info;
2225 SkDebugf("info %c= copy\n", info == copy ? '=' : '!');
2226 copy.reset();
2227 SkDebugf("info %c= reset copy\n", info == copy ? '=' : '!');
2228 SkDebugf("SkImageInfo() %c= reset copy\n", SkImageInfo() == copy ? '=' : '!');
2229#StdOut
2230info == copy
2231info != reset copy
2232SkImageInfo() == reset copy
2233##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002234##
2235
Cary Clark06c20f32018-03-20 15:53:27 -04002236#SeeAlso SkImageInfo()
Cary Clark2dc84ad2018-01-26 12:56:22 -05002237
2238#Method ##
2239
2240# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -05002241#Subtopic Utility
2242#Populate
2243#Line # rarely called management functions ##
2244##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002245
2246#Method void validate() const
Cary Clark78de7512018-02-07 07:27:09 -05002247#In Utility
Cary Clark06c20f32018-03-20 15:53:27 -04002248#Line # asserts if Image_Info is invalid (debug only) ##
2249Asserts if internal values are illegal or inconsistent. Only available if
2250SK_DEBUG is defined at compile time.
2251
2252#NoExample
Cary Clark2dc84ad2018-01-26 12:56:22 -05002253##
2254
Cary Clark06c20f32018-03-20 15:53:27 -04002255#SeeAlso validRowBytes SkBitmap::validate
Cary Clark2dc84ad2018-01-26 12:56:22 -05002256
2257#Method ##
2258
2259#Struct SkImageInfo ##
2260
Cary Clark08895c42018-02-01 09:37:32 -05002261#Topic Image_Info ##