SkImageInfo Reference

Image Info

Image Info specifies the dimensions and encoding of the pixels in a Bitmap. The dimensions are integral width and height. The encoding is how pixel bits describe Color Alpha, transparency; Color components red, blue, and green; and Color Space, the range and linearity of colors.

Image Info describes an uncompressed raster pixels. In contrast, Image additionally describes compressed pixels like PNG, and Surface describes destinations on the GPU. Image and Surface may be specified by Image Info, but Image and Surface may not contain Image Info.

Overview

Overview Subtopic

namedescription
Constructorfunctions that construct SkImageInfo
Member Functionstatic functions and member methods
Operatoroperator overloading methods
Related Functionsimilar methods grouped together

Constant

namedescription

Alpha Type

Enum SkAlphaType

Describes how to interpret the alpha component of a pixel. A pixel may be opaque, or Color Alpha, describing multiple levels of transparency.

In simple blending, Color Alpha weights the draw color and the destination color to create a new color. If alpha describes a weight from zero to one:

new color = draw color * alpha + destination color * (1 - alpha)In practice alpha is encoded in two or more bits, where 1.0 equals all bits set.

Color RGB may have Color Alpha included in each component value; the stored value is the original Color RGB multiplied by Color Alpha. Premultiplied color components improve performance.

Constants

See Also

SkColorType SkColorSpace

Alpha Type Opaque

Use Opaque as a hint to optimize drawing when alpha component of all pixel is set to its maximum value of 1.0; all alpha component bits are set. If Image Info is set to Opaque but all alpha values are not 1.0, results are undefined.

Example

Alpha Type Premul

Use Premul when stored color components are the original color multiplied by the alpha component. The alpha component range of 0.0 to 1.0 is achieved by dividing the integer bit value by the maximum bit value.

stored color = original color * alpha / max alphaThe color component must be equal to or smaller than the alpha component, or the results are undefined.

Example

Alpha Type Unpremul

Use Unpremul if stored color components are not divided by the alpha component. Some drawing destinations may not support Unpremul.

Example

Color Type

Color Type Native

Enum SkColorType

Describes how pixel bits encode color. A pixel may be an alpha mask, a gray level, Color RGB, or Color ARGB.

kN32_SkColorType selects the native 32-bit Color ARGB format. On Little_Endian processors, pixels containing 8-bit Color ARGB components pack into 32-bit kBGRA_8888_SkColorType. On Big_Endian processors, pixels pack into 32-bit kRGBA_8888_SkColorType.

Constants

Constants

See Also

SkAlphaType SkColorSpace

Color Type Alpha 8

Alpha 8 is an 8-bit byte pixel encoding that represents transparency. A value of zero is completely transparent; a value of 255 is completely opaque. Bitmap with Alpha 8 pixels does not visibly draw, because its pixels have no color information. The paired SkAlphaType is ignored.

Example

Color Type BGR 565

BGR 565 is a 16-bit word pixel encoding that contains five bits of blue, six bits of green, and five bits of red. BGR 565 is fully opaque as if its Color Alpha was set to one, and should always be paired with kOpaque_SkAlphaType.

Color_Type_BGR_565

Example

Color Type ABGR 4444

ABGR 4444 is a 16-bit word pixel encoding that contains four bits of alpha, four bits of blue, four bits of green, and four bits of red.

Color_Type_ABGR_4444

If paired with kPremul_SkAlphaType: blue, green, and red components are premultiplied by the alpha value. If blue, green, or red is greater than alpha, the drawn result is undefined.

If paired with kUnpremul_SkAlphaType: alpha, blue, green, and red components may have any value. There may be a performance penalty with unpremultipled pixels.

If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum; blue, green, and red components are fully opaque. If any alpha component is less than 15, the drawn result is undefined.

Example

Color Type RGBA 8888

RGBA 8888 is a 32-bit word pixel encoding that contains eight bits of red, eight bits of green, eight bits of blue, and eight bits of alpha.

Color_Type_RGBA_8888

If paired with kPremul_SkAlphaType: red, green, and blue components are premultiplied by the alpha value. If red, green, or blue is greater than alpha, the drawn result is undefined.

If paired with kUnpremul_SkAlphaType: alpha, red, green, and blue components may have any value. There may be a performance penalty with unpremultipled pixels.

If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum; red, green, and blue components are fully opaque. If any alpha component is less than 255, the drawn result is undefined.

On Big_Endian platforms, RGBA 8888 is the native Color Type, and will have the best performance. Use kN32_SkColorType to choose the best Color Type for the platform at compile time.

Example

Color Type RGB 888x

RGB 888x is a 32-bit word pixel encoding that contains eight bits of red, eight bits of green, eight bits of blue, and eight unused bits. RGB 888x is fully opaque as if its Color Alpha was set to one, and should always be paired with kOpaque_SkAlphaType.

Color_Type_RGB_888x

Example

Color Type BGRA 8888

BGRA 8888 is a 32-bit word pixel encoding that contains eight bits of blue, eight bits of green, eight bits of red, and eight bits of alpha.

Color_Type_BGRA_8888

If paired with kPremul_SkAlphaType: blue, green, and red components are premultiplied by the alpha value. If blue, green, or red is greater than alpha, the drawn result is undefined.

If paired with kUnpremul_SkAlphaType: blue, green, red, and alpha components may have any value. There may be a performance penalty with unpremultipled pixels.

If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum; blue, green, and red components are fully opaque. If any alpha component is less than 255, the drawn result is undefined.

On Little_Endian platforms, BGRA 8888 is the native Color Type, and will have the best performance. Use kN32_SkColorType to choose the best Color Type for the platform at compile time.

Example

Color Type RGBA 1010102

RGBA 1010102 is a 32-bit word pixel encoding that contains ten bits of red, ten bits of green, ten bits of blue, and two bits of alpha. Possible alpha values are zero: fully transparent; one: 33% opaque; two: 67% opaque; three: fully opaque.

Color_Type_RGBA_1010102

If paired with kPremul_SkAlphaType: red, green, and blue components are premultiplied by the alpha value. If red, green, or blue is greater than the alpha replicated to ten bits, the drawn result is undefined.

If paired with kUnpremul_SkAlphaType: alpha, red, green, and blue components may have any value. There may be a performance penalty with unpremultipled pixels.

If paired with kOpaque_SkAlphaType: all alpha component values are at the maximum; red, green, and blue components are fully opaque. If any alpha component is less than 3, the drawn result is undefined.

Example

Color Type RGB 101010x

Color_Type_RGB_101010x

Example

Color Type Gray 8

Example

Color Type RGBA F16

Color_Type_RGBA_F16

Example

YUV ColorSpace

Enum SkYUVColorSpace

Describes the color space a YUV pixel.

Constants

Example

See Also

incomplete

Enum SkDestinationSurfaceColorMode

Constants

Example

See Also

incomplete

Struct SkImageInfo

Describes Image dimensions and pixel type. Used for both source images and render-targets (surfaces).

Member Function

namedescription
ByteSizeOverflowedincomplete
Makecreates Image Info from dimensions, Color Type, Alpha Type, Color Space
MakeA8creates Image Info with kAlpha_8_SkColorType, kPremul_SkAlphaType
MakeN32creates Image Info with Native Color Type
MakeN32Premulcreates Image Info with Native Color Type, kPremul_SkAlphaType
MakeS32creates Image Info with Native Color Type, sRGB Color Space
MakeUnknowncreates Image Info with kUnknown_SkColorType, kUnknown_SkAlphaType
alphaTypeincomplete
boundsincomplete
bytesPerPixelincomplete
colorSpaceincomplete
colorTypeincomplete
computeByteSizeincomplete
computeMinByteSizeincomplete
computeOffsetincomplete
dimensionsincomplete
flattenincomplete
gammaCloseToSRGBincomplete
heightincomplete
isEmptyincomplete
isOpaqueincomplete
makeAlphaTypecreates Image Info with changed Alpha Type
makeColorSpacecreates Image Info with changed Color Space
makeColorTypecreates Image Info with changed Color Type
makeWHcreates Image Info with changed dimensions
minRowBytesincomplete
minRowBytes64incomplete
refColorSpaceincomplete
resetincomplete
shiftPerPixelincomplete
unflattenincomplete
validRowBytesincomplete
validateincomplete
widthincomplete

Related Function

namedescription
Propertymetrics and attributes
Utilityrarely called management functions

Constructor

namedescription
Makecreates Image Info from dimensions, Color Type, Alpha Type, Color Space
MakeA8creates Image Info with kAlpha_8_SkColorType, kPremul_SkAlphaType
MakeN32creates Image Info with Native Color Type
MakeN32Premulcreates Image Info with Native Color Type, kPremul_SkAlphaType
MakeN32Premul(int width, int height, sk sp<SkColorSpace> cs = nullptr)
MakeN32Premul(const SkISize& size)
MakeS32creates Image Info with Native Color Type, sRGB Color Space
MakeUnknowncreates Image Info with kUnknown_SkColorType, kUnknown_SkAlphaType
MakeUnknown(int width, int height)
MakeUnknown()
SkImageInfo()creates with zero dimensions, kUnknown_SkColorType, kUnknown_SkAlphaType
makeAlphaTypecreates Image Info with changed Alpha Type
makeColorSpacecreates Image Info with changed Color Space
makeColorTypecreates Image Info with changed Color Type
makeWHcreates Image Info with changed dimensions
resetincomplete

SkImageInfo

Return Value

incomplete

Example

See Also

incomplete


Make

Parameters

Return Value

incomplete

Example

See Also

incomplete


MakeN32

Sets Color Type to kN32_SkColorType.

Parameters

Return Value

incomplete

Example

See Also

incomplete


MakeS32

Creates Image Info marked as sRGB with kN32_SkColorType swizzle.

Parameters

Return Value

incomplete

Example

See Also

incomplete


MakeN32Premul

Sets Color Type to kN32_SkColorType, and the Alpha Type to kPremul_SkAlphaType.

Parameters

Return Value

incomplete

Example

See Also

incomplete


Parameters

Return Value

incomplete

Example

See Also

incomplete


MakeA8

Parameters

Return Value

incomplete

Example

See Also

incomplete


MakeUnknown

Parameters

Return Value

incomplete

Example

See Also

incomplete


Return Value

incomplete

Example

See Also

incomplete


Property

namedescription
alphaTypeincomplete
boundsincomplete
bytesPerPixelincomplete
colorSpaceincomplete
colorTypeincomplete
dimensionsincomplete
gammaCloseToSRGBincomplete
heightincomplete
isEmptyincomplete
isOpaqueincomplete
minRowBytesincomplete
minRowBytes64incomplete
refColorSpaceincomplete
shiftPerPixelincomplete
widthincomplete

width

Return Value

incomplete

Example

See Also

incomplete


height

Return Value

incomplete

Example

See Also

incomplete


colorType

Return Value

incomplete

Example

See Also

incomplete


alphaType

Return Value

incomplete

Example

See Also

incomplete


colorSpace

Return Value

incomplete

Example

See Also

incomplete


refColorSpace

Return Value

incomplete

Example

See Also

incomplete


isEmpty

Return Value

incomplete

Example

See Also

incomplete


isOpaque

Return Value

incomplete

Example

See Also

incomplete


dimensions

Return Value

incomplete

Example

See Also

incomplete


bounds

Return Value

incomplete

Example

See Also

incomplete


gammaCloseToSRGB

Return Value

incomplete

Example

See Also

incomplete


makeWH

Creates Image Info with the same Color Type and Alpha Type as this info, but with the specified width and height.

Parameters

Return Value

incomplete

Example

See Also

incomplete


makeAlphaType

Parameters

Return Value

incomplete

Example

See Also

incomplete


makeColorType

Parameters

Return Value

incomplete

Example

See Also

incomplete


makeColorSpace

Parameters

Return Value

incomplete

Example

See Also

incomplete


bytesPerPixel

Return Value

incomplete

Example

See Also

incomplete


shiftPerPixel

Return Value

incomplete

Example

See Also

incomplete


minRowBytes64

Return Value

incomplete

Example

See Also

incomplete


minRowBytes

Return Value

incomplete

Example

See Also

incomplete


computeOffset

Parameters

Return Value

incomplete

Example

See Also

incomplete


Operator

namedescription
operator!=(const SkImageInfo& other) constincomplete
operator==(const SkImageInfo& other) constincomplete

operator==

Parameters

Return Value

incomplete

Example

See Also

incomplete


operator!=

Parameters

Return Value

incomplete

Example

See Also

incomplete


unflatten

Parameters

Example

See Also

incomplete


flatten

Parameters

Example

See Also

incomplete


computeByteSize

Returns the size (in bytes) of the image buffer that this info needs, given the specified rowBytes. The rowBytes must be >= this->minRowBytes. if (height == 0) { return 0; } else { return (height - 1) * rowBytes + width * bytes_per_pixel.

If the calculation overflows this returns SK MaxSizeT.

Parameters

Return Value

incomplete

Example

See Also

incomplete


computeMinByteSize

Returns the minimum size (in bytes) of the image buffer that this info needs. If the calculation overflows, or if the height is 0, this returns 0.

Return Value

incomplete

Example

See Also

incomplete


ByteSizeOverflowed

Returns true if the result of computeByteSize (or computeMinByteSize) overflowed

Parameters

Return Value

incomplete

Example

See Also

incomplete


validRowBytes

Parameters

Return Value

incomplete

Example

See Also

incomplete


reset

Example

See Also

incomplete


Utility

namedescription
ByteSizeOverflowedincomplete
computeByteSizeincomplete
computeMinByteSizeincomplete
computeOffsetincomplete
flattenincomplete
unflattenincomplete
validRowBytesincomplete
validateincomplete

validate

Example

See Also

incomplete