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

name description
Constructor functions that construct SkImageInfo
Member Function static functions and member methods
Operator operator overloading methods
Related Function similar methods grouped together

Constant

name description

Alpha Type

Enum SkAlphaType

    enum SkAlphaType {
        kUnknown_SkAlphaType,
        kOpaque_SkAlphaType,
        kPremul_SkAlphaType,
        kUnpremul_SkAlphaType,
        kLastEnum_SkAlphaType = kUnpremul_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

kUnknown_SkAlphaType 0Alpha Type is uninitialized.
kOpaque_SkAlphaType 1Pixels are opaque. The Color Type must have no explicit alpha component, or all alpha components must be set to their maximum value.
kPremul_SkAlphaType 2Pixels have alpha premultiplied into color components. Surface pixels must be premultiplied.
kUnpremul_SkAlphaType 3Pixel color component values are independent of alpha value. Images generated from encoded data like PNG do not premultiply pixel color components. kUnpremul_SkAlphaType is supported for Image pixels, but not for Surface pixels.

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

SkPreMultiplyARGB parameter a is set to 255, its maximum value, and is interpreted as Color Alpha of 1.0. kOpaque_SkAlphaType may be set to improve performance. If SkPreMultiplyARGB parameter a is set to a value smaller than 255, kPremul_SkAlphaType must be used instead to avoid undefined results. The four displayed values are the original component values, though not necessarily in the same order.

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

SkPreMultiplyARGB parameter a is set to 150, less than its maximum value, and is interpreted as Color Alpha of about 0.6. kPremul_SkAlphaType must be set, since SkPreMultiplyARGB parameter a is set to a value smaller than 255, to avoid undefined results. The four displayed values reflect that the alpha component has been multiplied by the original color.

Alpha Type Unpremul

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

Example

SkColorSetARGB parameter a is set to 150, less than its maximum value, and is interpreted as Color Alpha of about 0.6. color is not premultiplied; color components may have values greater than color alpha. The four displayed values are the original component values, though not necessarily in the same order.

SkAlphaTypeIsOpaque

static inline bool SkAlphaTypeIsOpaque(SkAlphaType at)

Returns true if Alpha Type equals kOpaque_SkAlphaType. kOpaque_SkAlphaType is a hint that the Color Type is opaque, or that all Color Alpha values are set to their 1.0 equivalent. If Alpha Type is kOpaque_SkAlphaType, and Color Type is not opaque, then the result of drawing any pixel with a Color Alpha value less than 1.0 is undefined.

Parameters

at one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType

Return Value

true if at equals kOpaque_SkAlphaType


Color Type

Color Type Native

Enum SkColorType

    enum SkColorType {
        kUnknown_SkColorType,
        kAlpha_8_SkColorType,
        kRGB_565_SkColorType,
        kARGB_4444_SkColorType,
        kRGBA_8888_SkColorType,
        kRGB_888x_SkColorType,
        kBGRA_8888_SkColorType,
        kRGBA_1010102_SkColorType,
        kRGB_101010x_SkColorType,
        kGray_8_SkColorType,
        kRGBA_F16_SkColorType,

        kLastEnum_SkColorType = kRGBA_F16_SkColorType,
    #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A)
        kN32_SkColorType = kBGRA_8888_SkColorType,
    #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A)
        kN32_SkColorType = kRGBA_8888_SkColorType,
    #else
        #error
    #endif
    };

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

kUnknown_SkColorType 0Color Type is uninitialized; encoding format and size is unknown.
kAlpha_8_SkColorType 1Encodes Color Alpha as Alpha 8 pixel in an 8-bit byte.
kRGB_565_SkColorType 2Encodes Color RGB as BGR 565 pixel in a 16-bit word.
kARGB_4444_SkColorType 3Encodes Color ARGB as ABGR 4444 pixel in a 16-bit word.
kRGBA_8888_SkColorType 4Encodes Color ARGB as RGBA 8888 pixel in a 32-bit word.
kRGB_888x_SkColorType 5Encodes Color RGB as RGB 888x pixel in a 32-bit word.
kBGRA_8888_SkColorType 6Encodes Color ARGB as BGRA 8888 pixel in a 32-bit word.
kRGBA_1010102_SkColorType 7Encodes Color ARGB as RGBA 1010102 pixel in a 32-bit word.
kRGB_101010x_SkColorType 8Encodes Color RGB as RGB 101010x pixel in a 32-bit word.
kGray_8_SkColorType 9Encodes Color Gray as Gray 8 in an 8-bit byte.
kRGBA_F16_SkColorType 10Encodes Color ARGB as RGBA F16 in a 64-bit word.

Constants

kN32_SkColorType 4Encodes Color ARGB as either RGBA 8888 or BGRA 8888, whichever is native to the platform.

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

Alpha 8 pixels can modify another draw. orangePaint fills the bounds of bitmap, with its transparency set to alpha8 pixel value.

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

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

Color_Type_RGB_101010x

Example

Color Type Gray 8

Gray 8 is an 8-bit byte pixel encoding that represents equal values for red, blue, and green, reprsenting colors from black to white. Gray 8 is fully opaque as if its Color Alpha was set to one, and should always be paired with kOpaque_SkAlphaType.

Example

Color Type RGBA F16

RGBA F16 is a 64-bit word pixel encoding that contains sixteen bits of blue, sixteen bits of green, sixteen bits of red, and sixteen bits of alpha.

Each component encodes a floating point value using Half floats . Meaningful colors are represented by the range 0.0 to 1.0, although smaller and larger values may be useful when used in combination with Transfer Mode.

Color_Type_RGBA_F16

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.

Example

SkColorTypeBytesPerPixel

int SkColorTypeBytesPerPixel(SkColorType ct)

Returns the number of bytes required to store a pixel, including unused padding. Returns zero if ct is kUnknown_SkColorType or invalid.

Parameters

ct one of: kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, kGray_8_SkColorType, kRGBA_F16_SkColorType

Return Value

bytes per pixel

Example

kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, kGray_8_SkColorType, kRGBA_F16_SkColorType

See Also

SkImageInfo::bytesPerPixel


SkColorTypeIsAlwaysOpaque

bool SkColorTypeIsAlwaysOpaque(SkColorType ct)

Returns true if Color Type always decodes Color Alpha to 1.0, making the pixel fully opaque. If true, Color Type does not reserve bits to encode Color Alpha.

Parameters

ct one of: kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, kGray_8_SkColorType, kRGBA_F16_SkColorType

Return Value

true if Color Alpha is always set to 1.0

Example

kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, kGray_8_SkColorType, kRGBA_F16_SkColorType

See Also

SkColorTypeValidateAlphaType


SkColorTypeValidateAlphaType

bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType,
                                  SkAlphaType* canonical = nullptr)

Returns true if canonical can be set to a valid Alpha Type for colorType. If there is more than one valid canonical Alpha Type, set to alphaType, if valid. If true is returned and canonical is not nullptr, store valid Alpha Type.

Returns false only if alphaType is kUnknown_SkAlphaType, color type is not kUnknown_SkColorType, and Color Type is not always opaque. If false is returned, canonical is ignored.

For kUnknown_SkColorType: set canonical to kUnknown_SkAlphaType and return true. For kAlpha_8_SkColorType: set canonical to kPremul_SkAlphaType or kOpaque_SkAlphaType and return true if alphaType is not kUnknown_SkAlphaType. For kRGB_565_SkColorType, kRGB_888x_SkColorType, kRGB_101010x_SkColorType, and kGray_8_SkColorType: set canonical to kOpaque_SkAlphaType and return true. For kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, and kRGBA_F16_SkColorType: set canonical to alphaType and return true if alphaType is not kUnknown_SkAlphaType.

Parameters

colorType one of: kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, kGray_8_SkColorType, kRGBA_F16_SkColorType
alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType
canonical storage for Alpha Type

Return Value

true if valid Alpha Type can be associated with colorType

Example

kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, kGray_8_SkColorType, kRGBA_F16_SkColorType

See Also

SkColorTypeIsAlwaysOpaque


YUV ColorSpace

Enum SkYUVColorSpace

    enum SkYUVColorSpace {
        kJPEG_SkYUVColorSpace,
        kRec601_SkYUVColorSpace,
        kRec709_SkYUVColorSpace,
        kLastEnum_SkYUVColorSpace = kRec709_SkYUVColorSpace,
    };

Describes color range of YUV pixels. The color mapping from YUV to RGB varies depending on the source. YUV pixels may be generated by JPEG images, standard video streams, or high definition video streams. Each has its own mapping from YUV and RGB.

JPEG YUV values encode the full range of 0 to 255 for all three components. Video YUV values range from 16 to 235 for all three components. Details of encoding and conversion to RGB are described in YCbCr color space .

Constants

kJPEG_SkYUVColorSpace 0Describes standard JPEG color space; CCIR 601

with full range of 0 to 255 for components. kRec601_SkYUVColorSpace 1Describes standard used by SDTV; CCIR 601

with studio range of 16 to 235 range for components. kRec709_SkYUVColorSpace 2Describes standard used by HDTV; Rec. 709

with studio range of 16 to 235 range for components.

See Also

SkImage::MakeFromYUVTexturesCopy SkImage::MakeFromNV12TexturesCopy

Struct SkImageInfo

Describes pixel dimensions and encoding. Bitmap, Image, PixMap, and Surface can be created from Image Info. Image Info can be retrieved from Bitmap and Pixmap, but not from Image and Surface. For example, Image and Surface implementations may defer pixel depth, so may not completely specify Image Info.

Image Info contains dimensions, the pixel integral width and height. It encodes how pixel bits describe Color Alpha, transparency; Color components red, blue, and green; and Color Space, the range and linearity of colors.

Member Function

name description
ByteSizeOverflowed checks result of computeByteSize and computeMinByteSize
Make creates Image Info from dimensions, Color Type, Alpha Type, Color Space
MakeA8 creates Image Info with kAlpha_8_SkColorType, kPremul_SkAlphaType
MakeN32 creates Image Info with Native Color Type
MakeN32Premul creates Image Info with Native Color Type, kPremul_SkAlphaType
MakeS32 creates Image Info with Native Color Type, sRGB Color Space
MakeUnknown creates Image Info with kUnknown_SkColorType, kUnknown_SkAlphaType
alphaType Returns Alpha Type
bounds returns width and height as Rectangle
bytesPerPixel returns number of bytes in pixel based on Color Type
colorSpace returns Color Space
colorType returns Color Type
computeByteSize memory required by pixel buffer with given row bytes
computeMinByteSize least memory required by pixel buffer
computeOffset returns byte offset within pixel array
dimensions returns width and height
gammaCloseToSRGB Returns if Color Space gamma is approximately the same as sRGB
height returns pixel row count
isEmpty returns if dimensions contain pixels
isOpaque returns if Alpha Type is kOpaque_SkAlphaType
makeAlphaType creates Image Info with changed Alpha Type
makeColorSpace creates Image Info with changed Color Space
makeColorType creates Image Info with changed Color Type
makeWH creates Image Info with changed dimensions
minRowBytes returns width times bytesPerPixel in 32 bits
minRowBytes64 returns width times bytesPerPixel in 64 bits
refColorSpace returns Color Space
reset sets zero dimensions, kUnknown_SkColorType, kUnknown_SkAlphaType
shiftPerPixel returns bit shift from pixels to bytes
validRowBytes checks if row bytes is large enough to contain pixel row
validate asserts if Image Info is invalid (debug only)
width returns pixel column count

Related Function

name description
Property metrics and attributes
Utility rarely called management functions

Constructor

name description
Make creates Image Info from dimensions, Color Type, Alpha Type, Color Space
MakeA8 creates Image Info with kAlpha_8_SkColorType, kPremul_SkAlphaType
MakeN32 creates Image Info with Native Color Type
MakeN32Premul creates Image Info with Native Color Type, kPremul_SkAlphaType
MakeN32Premul(int width, int height, sk sp<SkColorSpace> cs = nullptr)
MakeN32Premul(const SkISize& size)
MakeS32 creates Image Info with Native Color Type, sRGB Color Space
MakeUnknown creates Image Info with kUnknown_SkColorType, kUnknown_SkAlphaType
MakeUnknown(int width, int height)
MakeUnknown()
SkImageInfo() creates with zero dimensions, kUnknown_SkColorType, kUnknown_SkAlphaType
makeAlphaType creates Image Info with changed Alpha Type
makeColorSpace creates Image Info with changed Color Space
makeColorType creates Image Info with changed Color Type
makeWH creates Image Info with changed dimensions
reset sets zero dimensions, kUnknown_SkColorType, kUnknown_SkAlphaType

SkImageInfo

SkImageInfo()

Creates an empty Image Info with kUnknown_SkColorType, kUnknown_SkAlphaType, a width and height of zero, and no Color Space.

Return Value

empty Image Info

Example

An empty Image Info may be passed to SkCanvas::accessTopLayerPixels as storage for the Canvas actual Image Info.

See Also

Make MakeN32 MakeS32 MakeA8


Make

static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at,
                        sk_sp<SkColorSpace> cs = nullptr)

Creates Image Info from integral dimensions width and height, Color Type ct, Alpha Type at, and optionally Color Space cs.

If Color Space cs is nullptr and Image Info is part of drawing source: Color Space defaults to sRGB, mapping into Surface Color Space.

Parameters are not validated to see if their values are legal, or that the combination is supported.

Parameters

width pixel column count; must be zero or greater
height pixel row count; must be zero or greater
ct one of: kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, kGray_8_SkColorType, kRGBA_F16_SkColorType
at one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType
cs range of colors; may be nullptr

Return Value

created Image Info

Example

See Also

MakeN32 MakeN32Premul[2] MakeS32 MakeA8


MakeN32

static SkImageInfo MakeN32(int width, int height, SkAlphaType at, sk_sp<SkColorSpace> cs = nullptr)

Creates Image Info from integral dimensions width and height, kN32_SkColorType, Alpha Type at, and optionally Color Space cs. kN32_SkColorType will equal either kBGRA_8888_SkColorType or kRGBA_8888_SkColorType, whichever is optimal.

If Color Space cs is nullptr and Image Info is part of drawing source: Color Space defaults to sRGB, mapping into Surface Color Space.

Parameters are not validated to see if their values are legal, or that the combination is supported.

Parameters

width pixel column count; must be zero or greater
height pixel row count; must be zero or greater
at one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType
cs range of colors; may be nullptr

Return Value

created Image Info

Example

See Also

Make MakeN32Premul[2] MakeS32 MakeA8


MakeS32

static SkImageInfo MakeS32(int width, int height, SkAlphaType at)

Creates Image Info from integral dimensions width and height, kN32_SkColorType, Alpha Type at, with sRGB Color Space.

Parameters are not validated to see if their values are legal, or that the combination is supported.

Parameters

width pixel column count; must be zero or greater
height pixel row count; must be zero or greater
at one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType

Return Value

created Image Info

Example

Top gradient is drawn to offscreen without Color Space. It is darker than middle gradient, drawn to offscreen with sRGB Color Space. Bottom gradient shares bits with middle, but does not specify the Color Space in noColorSpaceBitmap. A source without Color Space is treated as sRGB; the bottom gradient is identical to the middle gradient.

See Also

Make MakeN32 MakeN32Premul[2] MakeA8


MakeN32Premul

static SkImageInfo MakeN32Premul(int width, int height, sk_sp<SkColorSpace> cs = nullptr)

Creates Image Info from integral dimensions width and height, kN32_SkColorType, kPremul_SkAlphaType, with optional Color Space.

If Color Space cs is nullptr and Image Info is part of drawing source: Color Space defaults to sRGB, mapping into Surface Color Space.

Parameters are not validated to see if their values are legal, or that the combination is supported.

Parameters

width pixel column count; must be zero or greater
height pixel row count; must be zero or greater
cs range of colors; may be nullptr

Return Value

created Image Info

Example

See Also

MakeN32 MakeS32 MakeA8 Make


static SkImageInfo MakeN32Premul(const SkISize& size)

Creates Image Info from integral dimensions width and height, kN32_SkColorType, kPremul_SkAlphaType, with Color Space set to nullptr.

If Image Info is part of drawing source: Color Space defaults to sRGB, mapping into Surface Color Space.

Parameters are not validated to see if their values are legal, or that the combination is supported.

Parameters

size width and height, each must be zero or greater

Return Value

created Image Info

Example

See Also

MakeN32 MakeS32 MakeA8 Make


MakeA8

static SkImageInfo MakeA8(int width, int height)

Creates Image Info from integral dimensions width and height, kAlpha_8_SkColorType, kPremul_SkAlphaType, with Color Space set to nullptr.

Parameters

width pixel column count; must be zero or greater
height pixel row count; must be zero or greater

Return Value

created Image Info

Example

See Also

MakeN32 MakeS32 Make


MakeUnknown

static SkImageInfo MakeUnknown(int width, int height)

Creates Image Info from integral dimensions width and height, kUnknown_SkColorType, kUnknown_SkAlphaType, with Color Space set to nullptr.

Returned Image Info as part of source does not draw, and as part of destination can not be drawn to.

Parameters

width pixel column count; must be zero or greater
height pixel row count; must be zero or greater

Return Value

created Image Info

Example

See Also

SkImageInfo() MakeN32 MakeS32 Make


static SkImageInfo MakeUnknown()

Creates Image Info from integral dimensions width and height set to zero, kUnknown_SkColorType, kUnknown_SkAlphaType, with Color Space set to nullptr.

Returned Image Info as part of source does not draw, and as part of destination can not be drawn to.

Return Value

created Image Info

Example

See Also

SkImageInfo() MakeN32 MakeS32 Make


Property

name description
alphaType Returns Alpha Type
bounds returns width and height as Rectangle
bytesPerPixel returns number of bytes in pixel based on Color Type
colorSpace returns Color Space
colorType returns Color Type
dimensions returns width and height
gammaCloseToSRGB Returns if Color Space gamma is approximately the same as sRGB
height returns pixel row count
isEmpty returns if dimensions contain pixels
isOpaque returns if Alpha Type is kOpaque_SkAlphaType
minRowBytes returns width times bytesPerPixel in 32 bits
minRowBytes64 returns width times bytesPerPixel in 64 bits
refColorSpace returns Color Space
shiftPerPixel returns bit shift from pixels to bytes
width returns pixel column count

width

int width() const

Returns pixel count in each row.

Return Value

pixel width

Example

See Also

height SkBitmap::width SkPixelRef::width SkImage::width SkSurface::width


height

int height() const

Returns pixel row count.

Return Value

pixel height

Example

See Also

width SkBitmap::height SkPixelRef::height SkImage::height SkSurface::height


colorType

SkColorType colorType() const

Returns Color Type, one of: kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, kGray_8_SkColorType, kRGBA_F16_SkColorType.

Return Value

Color Type

Example

#### Example Output ~~~~ color type: kAlpha_8_SkColorType ~~~~

See Also

alphaType SkPixmap::colorType SkBitmap::colorType


alphaType

SkAlphaType alphaType() const

Returns Alpha Type, one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType.

Return Value

Alpha Type

Example

#### Example Output ~~~~ alpha type: kPremul_SkAlphaType ~~~~

See Also

colorType SkPixmap::alphaType SkBitmap::alphaType


colorSpace

SkColorSpace* colorSpace() const

Returns Color Space, the range of colors. The reference count of Color Space is unchanged. The returned Color Space is immutable.

Return Value

Color Space, or nullptr

Example

SkColorSpace::MakeSRGBLinear creates Color Space with linear gamma and an sRGB gamut. This Color Space gamma is not close to sRGB gamma.

Example Output

gammaCloseToSRGB: false  gammaIsLinear: true  isSRGB: false

See Also

Color Space SkPixmap::colorSpace SkBitmap::colorSpace


refColorSpace

sk_sp<SkColorSpace> refColorSpace() const

Returns smart pointer to Color Space, the range of colors. The smart pointer tracks the number of objects sharing this Color Space reference so the memory is released when the owners destruct.

The returned Color Space is immutable.

Return Value

Color Space wrapped in a smart pointer

Example

See Also

Color Space SkBitmap::refColorSpace


isEmpty

bool isEmpty() const

Returns if Image Info describes an empty area of pixels by checking if either width or height is zero or smaller.

Return Value

true if either dimension is zero or smaller

Example

#### Example Output ~~~~ width: 0 height: 0 empty: true width: 0 height: 2 empty: true width: 2 height: 0 empty: true width: 2 height: 2 empty: false ~~~~

See Also

dimensions bounds SkBitmap::empty SkPixmap::bounds


isOpaque

bool isOpaque() const

Returns true if Alpha Type is set to hint that all pixels are opaque; their Color Alpha value is implicitly or explicitly 1.0. If true, and all pixels are not opaque, Skia may draw incorrectly.

Does not check if Color Type allows Alpha, or if any pixel value has transparency.

Return Value

true if Alpha Type is kOpaque_SkAlphaType

Example

#### Example Output ~~~~ isOpaque: false isOpaque: false isOpaque: true isOpaque: true ~~~~

See Also

Color Alpha SkColorTypeValidateAlphaType SkBitmap::isOpaque SkImage::isOpaque SkPixmap::isOpaque


dimensions

SkISize dimensions() const

Returns ISize { width, height }.

Return Value

integral size of width and height

Example

#### Example Output ~~~~ dimensionsAsBounds == bounds ~~~~

See Also

width height bounds SkBitmap::dimensions


bounds

SkIRect bounds() const

Returns IRect { 0, 0, width, height }.

Return Value

integral rectangle from origin to width and height

Example

See Also

width height dimensions


gammaCloseToSRGB

bool gammaCloseToSRGB() const

Returns true if associated Color Space is not nullptr, and Color Space gamma is approximately the same as sRGB. This includes the sRGB transfer function $ https://en.wikipedia.org/wiki/SRGB#The_sRGB_transfer_function_(%22gamma%22) as well as a gamma curve described by a 2.2 exponent.

Return Value

true if Color Space gamma is approximately the same as sRGB

Example

See Also

SkColorSpace::gammaCloseToSRGB


makeWH

SkImageInfo makeWH(int newWidth, int newHeight) const

Creates Image Info with the same Color Type, Color Space, and Alpha Type, with dimensions set to width and height.

Parameters

newWidth pixel column count; must be zero or greater
newHeight pixel row count; must be zero or greater

Return Value

created Image Info

Example

See Also

Make makeAlphaType makeColorSpace makeColorType


makeAlphaType

SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const

Creates Image Info with same Color Type, Color Space, width, and height, with Alpha Type set to newAlphaType.

Created Image Info contains newAlphaType even if it is incompatible with Color Type, in which case Alpha Type in Image Info is ignored.

Parameters

newAlphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType

Return Value

created Image Info

Example

See Also

Make MakeA8 makeColorType makeColorSpace


makeColorType

SkImageInfo makeColorType(SkColorType newColorType) const

Creates Image Info with same Alpha Type, Color Space, width, and height, with Color Type set to newColorType.

Parameters

newColorType one of: kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, kGray_8_SkColorType, kRGBA_F16_SkColorType

Return Value

created Image Info

Example

See Also

Make makeAlphaType makeColorSpace


makeColorSpace

SkImageInfo makeColorSpace(sk_sp<SkColorSpace> cs) const

Creates Image Info with same Alpha Type, Color Type, width, and height, with Color Space set to cs.

Parameters

cs range of colors; may be nullptr

Return Value

created Image Info

Example

See Also

Make MakeS32 makeAlphaType makeColorType


bytesPerPixel

int bytesPerPixel() const

Returns number of bytes per pixel required by Color Type. Returns zero if colorType( is kUnknown_SkColorType.

Return Value

bytes in pixel

Example

kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, kGray_8_SkColorType, kRGBA_F16_SkColorType #### Example Output ~~~~ color: kUnknown_SkColorType bytesPerPixel: 0 color: kAlpha_8_SkColorType bytesPerPixel: 1 color: kRGB_565_SkColorType bytesPerPixel: 2 color: kARGB_4444_SkColorType bytesPerPixel: 2 color: kRGBA_8888_SkColorType bytesPerPixel: 4 color: kRGB_888x_SkColorType bytesPerPixel: 4 color: kBGRA_8888_SkColorType bytesPerPixel: 4 color: kRGBA_1010102_SkColorType bytesPerPixel: 4 color: kRGB_101010x_SkColorType bytesPerPixel: 4 color: kGray_8_SkColorType bytesPerPixel: 1 color: kRGBA_F16_SkColorType bytesPerPixel: 8 ~~~~

See Also

width shiftPerPixel SkBitmap::bytesPerPixel


shiftPerPixel

int shiftPerPixel() const

Returns bit shift converting row bytes to row pixels. Returns zero for kUnknown_SkColorType.

Return Value

one of: 0, 1, 2, 3; left shift to convert pixels to bytes

Example

kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, kGray_8_SkColorType, kRGBA_F16_SkColorType #### Example Output ~~~~ color: kUnknown_SkColorType shiftPerPixel: 0 color: kAlpha_8_SkColorType shiftPerPixel: 0 color: kRGB_565_SkColorType shiftPerPixel: 1 color: kARGB_4444_SkColorType shiftPerPixel: 1 color: kRGBA_8888_SkColorType shiftPerPixel: 2 color: kRGB_888x_SkColorType shiftPerPixel: 2 color: kBGRA_8888_SkColorType shiftPerPixel: 2 color: kRGBA_1010102_SkColorType shiftPerPixel: 2 color: kRGB_101010x_SkColorType shiftPerPixel: 2 color: kGray_8_SkColorType shiftPerPixel: 0 color: kRGBA_F16_SkColorType shiftPerPixel: 3 ~~~~

See Also

bytesPerPixel minRowBytes SkBitmap::shiftPerPixel SkPixmap::shiftPerPixel


minRowBytes64

uint64_t minRowBytes64() const

Returns minimum bytes per row, computed from pixel width and Color Type, which specifies bytesPerPixel. Bitmap maximum value for row bytes must be representable as a positive value in a 32-bit signed integer.

Return Value

width times bytesPerPixel as unsigned 64-bit integer

Example

#### Example Output ~~~~ RGBA_F16 width 16777216 (0x01000000) OK RGBA_F16 width 33554432 (0x02000000) OK RGBA_F16 width 67108864 (0x04000000) OK RGBA_F16 width 134217728 (0x08000000) OK RGBA_F16 width 268435456 (0x10000000) too large RGBA_F16 width 536870912 (0x20000000) too large RGBA_F16 width 1073741824 (0x40000000) too large RGBA_F16 width -2147483648 (0x80000000) too large ~~~~

See Also

minRowBytes computeByteSize computeMinByteSize validRowBytes


minRowBytes

size_t minRowBytes() const

Returns minimum bytes per row, computed from pixel width and Color Type, which specifies bytesPerPixel. Bitmap maximum value for row bytes must be representable as a positive value in a 32-bit signed integer.

Return Value

width times bytesPerPixel as signed 32-bit integer

Example

#### Example Output ~~~~ RGBA_F16 width 16777216 (0x01000000) OK RGBA_F16 width 33554432 (0x02000000) OK RGBA_F16 width 67108864 (0x04000000) OK RGBA_F16 width 134217728 (0x08000000) OK RGBA_F16 width 268435456 (0x10000000) too large RGBA_F16 width 536870912 (0x20000000) too large RGBA_F16 width 1073741824 (0x40000000) too large RGBA_F16 width -2147483648 (0x80000000) too large ~~~~

See Also

minRowBytes64 computeByteSize computeMinByteSize validRowBytes


computeOffset

size_t computeOffset(int x, int y, size_t rowBytes) const

Returns byte offset of pixel from pixel base address.

Asserts in debug build if x or y is outside of bounds. Does not assert if rowBytes is smaller than minRowBytes, even though result may be incorrect.

Parameters

x column index, zero or greater, and less than width
y row index, zero or greater, and less than height
rowBytes size of pixel row or larger

Return Value

offset within pixel array

Example

See Also

height width minRowBytes computeByteSize


Operator

name description
operator!=(const SkImageInfo& other) const compares Image Info for inequality
operator==(const SkImageInfo& other) const compares Image Info for equality

operator==

bool operator==(const SkImageInfo& other) _const

Compares Image Info with other, and returns true if width, height, Color Type, Alpha Type, and Color Space are equivalent.

Parameters

other Image Info to compare

Return Value

true if Image Info equals other

Example

#### Example Output ~~~~ info1 != info2 info1 != info2 info1 != info2 info1 == info2 ~~~~

See Also

operator!=(const SkImageInfo& other) const SkColorSpace::Equals


operator!=

bool operator!=(const SkImageInfo& other) _const

Compares Image Info with other, and returns true if width, height, Color Type, Alpha Type, and Color Space are equivalent.

Parameters

other Image Info to compare

Return Value

true if Image Info is not equal to other

Example

#### Example Output ~~~~ info1 != info2 info1 != info2 info1 != info2 info1 == info2 ~~~~

See Also

operator==(const SkImageInfo& other) const SkColorSpace::Equals


computeByteSize

size_t computeByteSize(size_t rowBytes) const

Returns storage required by pixel array, given Image Info dimensions, Color Type, and rowBytes. rowBytes is assumed to be at least as large as minRowBytes.

Returns zero if height is zero. Returns SK MaxSizeT if answer exceeds the range of size_t.

Parameters

rowBytes size of pixel row or larger

Return Value

memory required by pixel buffer

Example

See Also

computeMinByteSize validRowBytes


computeMinByteSize

size_t computeMinByteSize() const

Returns storage required by pixel array, given Image Info dimensions, and Color Type. Uses minRowBytes to compute bytes for pixel row.

Returns zero if height is zero. Returns SK MaxSizeT if answer exceeds the range of size_t.

Return Value

least memory required by pixel buffer

Example

See Also

computeByteSize validRowBytes


ByteSizeOverflowed

static bool ByteSizeOverflowed(size_t byteSize)

Returns true if byteSize equals SK MaxSizeT. computeByteSize and computeMinByteSize return SK MaxSizeT if size_t can not hold buffer size.

Parameters

byteSize result of computeByteSize or computeMinByteSize

Return Value

true if computeByteSize or computeMinByteSize result exceeds size_t

Example

#### Example Output ~~~~ rowBytes:100000000 size:99999999900000008 overflowed:false rowBytes:1000000000 size:999999999000000008 overflowed:false rowBytes:10000000000 size:9999999990000000008 overflowed:false rowBytes:100000000000 size:18446744073709551615 overflowed:true rowBytes:1000000000000 size:18446744073709551615 overflowed:true ~~~~

See Also

computeByteSize computeMinByteSize validRowBytes


validRowBytes

bool validRowBytes(size_t rowBytes) const

Returns true if rowBytes is smaller than width times pixel size.

Parameters

rowBytes size of pixel row or larger

Return Value

true if rowBytes is large enough to contain pixel row

Example

#### Example Output ~~~~ validRowBytes(60): false validRowBytes(64): true validRowBytes(68): true ~~~~

See Also

ByteSizeOverflowed computeByteSize computeMinByteSize


reset

void reset()

Creates an empty Image Info with kUnknown_SkColorType, kUnknown_SkAlphaType, a width and height of zero, and no Color Space.

Example

#### Example Output ~~~~ info == copy info != reset copy SkImageInfo() == reset copy ~~~~

See Also

SkImageInfo()


Utility

name description
ByteSizeOverflowed checks result of computeByteSize and computeMinByteSize
computeByteSize memory required by pixel buffer with given row bytes
computeMinByteSize least memory required by pixel buffer
computeOffset returns byte offset within pixel array
validRowBytes checks if row bytes is large enough to contain pixel row
validate asserts if Image Info is invalid (debug only)

validate

void validate() const

Asserts if internal values are illegal or inconsistent. Only available if SK_DEBUG is defined at compile time.

See Also

validRowBytes SkBitmap::validate