Skia
2D Graphics Library
SkImageInfo Struct Reference

Describes pixel dimensions and encoding. More...

#include <SkImageInfo.h>

Public Member Functions

 SkImageInfo ()=default
 Creates an empty SkImageInfo with kUnknown_SkColorType, kUnknown_SkAlphaType, a width and height of zero, and no SkColorSpace. More...
 
int width () const
 Returns pixel count in each row. More...
 
int height () const
 Returns pixel row count. More...
 
SkColorType colorType () const
 
SkAlphaType alphaType () const
 
SkColorSpacecolorSpace () const
 Returns SkColorSpace, the range of colors. More...
 
sk_sp< SkColorSpacerefColorSpace () const
 Returns smart pointer to SkColorSpace, the range of colors. More...
 
bool isEmpty () const
 Returns if SkImageInfo describes an empty area of pixels by checking if either width or height is zero or smaller. More...
 
const SkColorInfocolorInfo () const
 Returns the dimensionless SkColorInfo that represents the same color type, alpha type, and color space as this SkImageInfo. More...
 
bool isOpaque () const
 Returns true if SkAlphaType is set to hint that all pixels are opaque; their alpha value is implicitly or explicitly 1.0. More...
 
SkISize dimensions () const
 Returns SkISize { width(), height() }. More...
 
SkIRect bounds () const
 Returns SkIRect { 0, 0, width(), height() }. More...
 
bool gammaCloseToSRGB () const
 Returns true if associated SkColorSpace is not nullptr, and SkColorSpace gamma is approximately the same as sRGB. More...
 
SkImageInfo makeWH (int newWidth, int newHeight) const
 Creates SkImageInfo with the same SkColorType, SkColorSpace, and SkAlphaType, with dimensions set to width and height. More...
 
SkImageInfo makeDimensions (SkISize newSize) const
 Creates SkImageInfo with the same SkColorType, SkColorSpace, and SkAlphaType, with dimensions set to newDimensions. More...
 
SkImageInfo makeAlphaType (SkAlphaType newAlphaType) const
 Creates SkImageInfo with same SkColorType, SkColorSpace, width, and height, with SkAlphaType set to newAlphaType. More...
 
SkImageInfo makeColorType (SkColorType newColorType) const
 Creates SkImageInfo with same SkAlphaType, SkColorSpace, width, and height, with SkColorType set to newColorType. More...
 
SkImageInfo makeColorSpace (sk_sp< SkColorSpace > cs) const
 Creates SkImageInfo with same SkAlphaType, SkColorType, width, and height, with SkColorSpace set to cs. More...
 
int bytesPerPixel () const
 Returns number of bytes per pixel required by SkColorType. More...
 
int shiftPerPixel () const
 Returns bit shift converting row bytes to row pixels. More...
 
uint64_t minRowBytes64 () const
 Returns minimum bytes per row, computed from pixel width() and SkColorType, which specifies bytesPerPixel(). More...
 
size_t minRowBytes () const
 Returns minimum bytes per row, computed from pixel width() and SkColorType, which specifies bytesPerPixel(). More...
 
size_t computeOffset (int x, int y, size_t rowBytes) const
 Returns byte offset of pixel from pixel base address. More...
 
bool operator== (const SkImageInfo &other) const
 Compares SkImageInfo with other, and returns true if width, height, SkColorType, SkAlphaType, and SkColorSpace are equivalent. More...
 
bool operator!= (const SkImageInfo &other) const
 Compares SkImageInfo with other, and returns true if width, height, SkColorType, SkAlphaType, and SkColorSpace are not equivalent. More...
 
size_t computeByteSize (size_t rowBytes) const
 Returns storage required by pixel array, given SkImageInfo dimensions, SkColorType, and rowBytes. More...
 
size_t computeMinByteSize () const
 Returns storage required by pixel array, given SkImageInfo dimensions, and SkColorType. More...
 
bool validRowBytes (size_t rowBytes) const
 Returns true if rowBytes is valid for this SkImageInfo. More...
 
void reset ()
 Creates an empty SkImageInfo with kUnknown_SkColorType, kUnknown_SkAlphaType, a width and height of zero, and no SkColorSpace. More...
 
 SkImageInfo (SkISize dimensions, const SkColorInfo &colorInfo)
 
 SkImageInfo (SkISize dimensions, SkColorInfo &&colorInfo)
 

Static Public Member Functions

static SkImageInfo Make (int width, int height, SkColorType ct, SkAlphaType at)
 Creates SkImageInfo from integral dimensions width and height, SkColorType ct, SkAlphaType at, and optionally SkColorSpace cs. More...
 
static SkImageInfo Make (int width, int height, SkColorType ct, SkAlphaType at, sk_sp< SkColorSpace > cs)
 
static SkImageInfo Make (SkISize dimensions, SkColorType ct, SkAlphaType at)
 
static SkImageInfo Make (SkISize dimensions, SkColorType ct, SkAlphaType at, sk_sp< SkColorSpace > cs)
 
static SkImageInfo Make (SkISize dimensions, const SkColorInfo &colorInfo)
 Creates SkImageInfo from integral dimensions and SkColorInfo colorInfo,. More...
 
static SkImageInfo Make (SkISize dimensions, SkColorInfo &&colorInfo)
 
static SkImageInfo MakeN32 (int width, int height, SkAlphaType at)
 Creates SkImageInfo from integral dimensions width and height, kN32_SkColorType, SkAlphaType at, and optionally SkColorSpace cs. More...
 
static SkImageInfo MakeN32 (int width, int height, SkAlphaType at, sk_sp< SkColorSpace > cs)
 
static SkImageInfo MakeS32 (int width, int height, SkAlphaType at)
 Creates SkImageInfo from integral dimensions width and height, kN32_SkColorType, SkAlphaType at, with sRGB SkColorSpace. More...
 
static SkImageInfo MakeN32Premul (int width, int height)
 Creates SkImageInfo from integral dimensions width and height, kN32_SkColorType, kPremul_SkAlphaType, with optional SkColorSpace. More...
 
static SkImageInfo MakeN32Premul (int width, int height, sk_sp< SkColorSpace > cs)
 
static SkImageInfo MakeN32Premul (SkISize dimensions)
 Creates SkImageInfo from integral dimensions width and height, kN32_SkColorType, kPremul_SkAlphaType, with SkColorSpace set to nullptr. More...
 
static SkImageInfo MakeN32Premul (SkISize dimensions, sk_sp< SkColorSpace > cs)
 
static SkImageInfo MakeA8 (int width, int height)
 Creates SkImageInfo from integral dimensions width and height, kAlpha_8_SkColorType, kPremul_SkAlphaType, with SkColorSpace set to nullptr. More...
 
static SkImageInfo MakeA8 (SkISize dimensions)
 Creates SkImageInfo from integral dimensions, kAlpha_8_SkColorType, kPremul_SkAlphaType, with SkColorSpace set to nullptr. More...
 
static SkImageInfo MakeUnknown (int width, int height)
 Creates SkImageInfo from integral dimensions width and height, kUnknown_SkColorType, kUnknown_SkAlphaType, with SkColorSpace set to nullptr. More...
 
static SkImageInfo MakeUnknown ()
 Creates SkImageInfo from integral dimensions width and height set to zero, kUnknown_SkColorType, kUnknown_SkAlphaType, with SkColorSpace set to nullptr. More...
 
static bool ByteSizeOverflowed (size_t byteSize)
 Returns true if byteSize equals SIZE_MAX. More...
 

Public Attributes

SkDEBUGCODE(void validate() const ;) private SkISize fDimensions = {0, 0}
 Asserts if internal values are illegal or inconsistent. More...
 

Detailed Description

Describes pixel dimensions and encoding.

SkBitmap, SkImage, PixMap, and SkSurface can be created from SkImageInfo. SkImageInfo can be retrieved from SkBitmap and SkPixmap, but not from SkImage and SkSurface. For example, SkImage and SkSurface implementations may defer pixel depth, so may not completely specify SkImageInfo.

SkImageInfo contains dimensions, the pixel integral width and height. It encodes how pixel bits describe alpha, transparency; color components red, blue, and green; and SkColorSpace, the range and linearity of colors.

Constructor & Destructor Documentation

◆ SkImageInfo() [1/3]

SkImageInfo::SkImageInfo ( )
default

Creates an empty SkImageInfo with kUnknown_SkColorType, kUnknown_SkAlphaType, a width and height of zero, and no SkColorSpace.

Returns
empty SkImageInfo

◆ SkImageInfo() [2/3]

SkImageInfo::SkImageInfo ( SkISize  dimensions,
const SkColorInfo colorInfo 
)
inline

◆ SkImageInfo() [3/3]

SkImageInfo::SkImageInfo ( SkISize  dimensions,
SkColorInfo &&  colorInfo 
)
inline

Member Function Documentation

◆ alphaType()

SkAlphaType SkImageInfo::alphaType ( ) const
inline

◆ bounds()

SkIRect SkImageInfo::bounds ( ) const
inline

Returns SkIRect { 0, 0, width(), height() }.

Returns
integral rectangle from origin to width() and height()

◆ ByteSizeOverflowed()

static bool SkImageInfo::ByteSizeOverflowed ( size_t  byteSize)
inlinestatic

Returns true if byteSize equals SIZE_MAX.

computeByteSize() and computeMinByteSize() return SIZE_MAX if size_t can not hold buffer size.

Parameters
byteSizeresult of computeByteSize() or computeMinByteSize()
Returns
true if computeByteSize() or computeMinByteSize() result exceeds size_t

◆ bytesPerPixel()

int SkImageInfo::bytesPerPixel ( ) const
inline

Returns number of bytes per pixel required by SkColorType.

Returns zero if colorType( is kUnknown_SkColorType.

Returns
bytes in pixel

◆ colorInfo()

const SkColorInfo& SkImageInfo::colorInfo ( ) const
inline

Returns the dimensionless SkColorInfo that represents the same color type, alpha type, and color space as this SkImageInfo.

◆ colorSpace()

SkColorSpace* SkImageInfo::colorSpace ( ) const

Returns SkColorSpace, the range of colors.

The reference count of SkColorSpace is unchanged. The returned SkColorSpace is immutable.

Returns
SkColorSpace, or nullptr

◆ colorType()

SkColorType SkImageInfo::colorType ( ) const
inline

◆ computeByteSize()

size_t SkImageInfo::computeByteSize ( size_t  rowBytes) const

Returns storage required by pixel array, given SkImageInfo dimensions, SkColorType, and rowBytes.

rowBytes is assumed to be at least as large as minRowBytes().

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

Parameters
rowBytessize of pixel row or larger
Returns
memory required by pixel buffer

◆ computeMinByteSize()

size_t SkImageInfo::computeMinByteSize ( ) const
inline

Returns storage required by pixel array, given SkImageInfo dimensions, and SkColorType.

Uses minRowBytes() to compute bytes for pixel row.

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

Returns
least memory required by pixel buffer

◆ computeOffset()

size_t SkImageInfo::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
xcolumn index, zero or greater, and less than width()
yrow index, zero or greater, and less than height()
rowBytessize of pixel row or larger
Returns
offset within pixel array

example: https://fiddle.skia.org/c/@ImageInfo_computeOffset

◆ dimensions()

SkISize SkImageInfo::dimensions ( ) const
inline

Returns SkISize { width(), height() }.

Returns
integral size of width() and height()

◆ gammaCloseToSRGB()

bool SkImageInfo::gammaCloseToSRGB ( ) const
inline

Returns true if associated SkColorSpace is not nullptr, and SkColorSpace gamma is approximately the same as sRGB.

This includes the

Returns
true if SkColorSpace gamma is approximately the same as sRGB

◆ height()

int SkImageInfo::height ( ) const
inline

Returns pixel row count.

Returns
pixel height

◆ isEmpty()

bool SkImageInfo::isEmpty ( ) const
inline

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

Returns
true if either dimension is zero or smaller

◆ isOpaque()

bool SkImageInfo::isOpaque ( ) const
inline

Returns true if SkAlphaType is set to hint that all pixels are opaque; their alpha value is implicitly or explicitly 1.0.

If true, and all pixels are not opaque, Skia may draw incorrectly.

Does not check if SkColorType allows alpha, or if any pixel value has transparency.

Returns
true if SkAlphaType is kOpaque_SkAlphaType

◆ Make() [1/6]

static SkImageInfo SkImageInfo::Make ( int  width,
int  height,
SkColorType  ct,
SkAlphaType  at 
)
static

Creates SkImageInfo from integral dimensions width and height, SkColorType ct, SkAlphaType at, and optionally SkColorSpace cs.

If SkColorSpace cs is nullptr and SkImageInfo is part of drawing source: SkColorSpace defaults to sRGB, mapping into SkSurface SkColorSpace.

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

Parameters
widthpixel column count; must be zero or greater
heightpixel row count; must be zero or greater
csrange of colors; may be nullptr
Returns
created SkImageInfo

◆ Make() [2/6]

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

◆ Make() [3/6]

static SkImageInfo SkImageInfo::Make ( SkISize  dimensions,
const SkColorInfo colorInfo 
)
inlinestatic

Creates SkImageInfo from integral dimensions and SkColorInfo colorInfo,.

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

Parameters
dimensionspixel column and row count; must be zeros or greater
SkColorInfothe pixel encoding consisting of SkColorType, SkAlphaType, and SkColorSpace (which may be nullptr)
Returns
created SkImageInfo

◆ Make() [4/6]

static SkImageInfo SkImageInfo::Make ( SkISize  dimensions,
SkColorInfo &&  colorInfo 
)
inlinestatic

◆ Make() [5/6]

static SkImageInfo SkImageInfo::Make ( SkISize  dimensions,
SkColorType  ct,
SkAlphaType  at 
)
static

◆ Make() [6/6]

static SkImageInfo SkImageInfo::Make ( SkISize  dimensions,
SkColorType  ct,
SkAlphaType  at,
sk_sp< SkColorSpace cs 
)
static

◆ MakeA8() [1/2]

static SkImageInfo SkImageInfo::MakeA8 ( int  width,
int  height 
)
static

Creates SkImageInfo from integral dimensions width and height, kAlpha_8_SkColorType, kPremul_SkAlphaType, with SkColorSpace set to nullptr.

Parameters
widthpixel column count; must be zero or greater
heightpixel row count; must be zero or greater
Returns
created SkImageInfo

◆ MakeA8() [2/2]

static SkImageInfo SkImageInfo::MakeA8 ( SkISize  dimensions)
static

Creates SkImageInfo from integral dimensions, kAlpha_8_SkColorType, kPremul_SkAlphaType, with SkColorSpace set to nullptr.

Parameters
dimensionspixel row and column count; must be zero or greater
Returns
created SkImageInfo

◆ makeAlphaType()

SkImageInfo SkImageInfo::makeAlphaType ( SkAlphaType  newAlphaType) const
inline

Creates SkImageInfo with same SkColorType, SkColorSpace, width, and height, with SkAlphaType set to newAlphaType.

Created SkImageInfo contains newAlphaType even if it is incompatible with SkColorType, in which case SkAlphaType in SkImageInfo is ignored.

Returns
created SkImageInfo

◆ makeColorSpace()

SkImageInfo SkImageInfo::makeColorSpace ( sk_sp< SkColorSpace cs) const

Creates SkImageInfo with same SkAlphaType, SkColorType, width, and height, with SkColorSpace set to cs.

Parameters
csrange of colors; may be nullptr
Returns
created SkImageInfo

◆ makeColorType()

SkImageInfo SkImageInfo::makeColorType ( SkColorType  newColorType) const
inline

Creates SkImageInfo with same SkAlphaType, SkColorSpace, width, and height, with SkColorType set to newColorType.

Returns
created SkImageInfo

◆ makeDimensions()

SkImageInfo SkImageInfo::makeDimensions ( SkISize  newSize) const
inline

Creates SkImageInfo with the same SkColorType, SkColorSpace, and SkAlphaType, with dimensions set to newDimensions.

Parameters
newSizepixel column and row count; must be zero or greater
Returns
created SkImageInfo

◆ MakeN32() [1/2]

static SkImageInfo SkImageInfo::MakeN32 ( int  width,
int  height,
SkAlphaType  at 
)
static

Creates SkImageInfo from integral dimensions width and height, kN32_SkColorType, SkAlphaType at, and optionally SkColorSpace cs.

kN32_SkColorType will equal either kBGRA_8888_SkColorType or kRGBA_8888_SkColorType, whichever is optimal.

If SkColorSpace cs is nullptr and SkImageInfo is part of drawing source: SkColorSpace defaults to sRGB, mapping into SkSurface SkColorSpace.

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

Parameters
widthpixel column count; must be zero or greater
heightpixel row count; must be zero or greater
csrange of colors; may be nullptr
Returns
created SkImageInfo

◆ MakeN32() [2/2]

static SkImageInfo SkImageInfo::MakeN32 ( int  width,
int  height,
SkAlphaType  at,
sk_sp< SkColorSpace cs 
)
static

◆ MakeN32Premul() [1/4]

static SkImageInfo SkImageInfo::MakeN32Premul ( int  width,
int  height 
)
static

Creates SkImageInfo from integral dimensions width and height, kN32_SkColorType, kPremul_SkAlphaType, with optional SkColorSpace.

If SkColorSpace cs is nullptr and SkImageInfo is part of drawing source: SkColorSpace defaults to sRGB, mapping into SkSurface SkColorSpace.

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

Parameters
widthpixel column count; must be zero or greater
heightpixel row count; must be zero or greater
csrange of colors; may be nullptr
Returns
created SkImageInfo

◆ MakeN32Premul() [2/4]

static SkImageInfo SkImageInfo::MakeN32Premul ( int  width,
int  height,
sk_sp< SkColorSpace cs 
)
static

◆ MakeN32Premul() [3/4]

static SkImageInfo SkImageInfo::MakeN32Premul ( SkISize  dimensions)
static

Creates SkImageInfo from integral dimensions width and height, kN32_SkColorType, kPremul_SkAlphaType, with SkColorSpace set to nullptr.

If SkImageInfo is part of drawing source: SkColorSpace defaults to sRGB, mapping into SkSurface SkColorSpace.

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

Parameters
dimensionswidth and height, each must be zero or greater
csrange of colors; may be nullptr
Returns
created SkImageInfo

◆ MakeN32Premul() [4/4]

static SkImageInfo SkImageInfo::MakeN32Premul ( SkISize  dimensions,
sk_sp< SkColorSpace cs 
)
static

◆ MakeS32()

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

Creates SkImageInfo from integral dimensions width and height, kN32_SkColorType, SkAlphaType at, with sRGB SkColorSpace.

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

Parameters
widthpixel column count; must be zero or greater
heightpixel row count; must be zero or greater
Returns
created SkImageInfo

example: https://fiddle.skia.org/c/@ImageInfo_MakeS32

◆ MakeUnknown() [1/2]

static SkImageInfo SkImageInfo::MakeUnknown ( )
inlinestatic

Creates SkImageInfo from integral dimensions width and height set to zero, kUnknown_SkColorType, kUnknown_SkAlphaType, with SkColorSpace set to nullptr.

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

Returns
created SkImageInfo

◆ MakeUnknown() [2/2]

static SkImageInfo SkImageInfo::MakeUnknown ( int  width,
int  height 
)
static

Creates SkImageInfo from integral dimensions width and height, kUnknown_SkColorType, kUnknown_SkAlphaType, with SkColorSpace set to nullptr.

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

Parameters
widthpixel column count; must be zero or greater
heightpixel row count; must be zero or greater
Returns
created SkImageInfo

◆ makeWH()

SkImageInfo SkImageInfo::makeWH ( int  newWidth,
int  newHeight 
) const
inline

Creates SkImageInfo with the same SkColorType, SkColorSpace, and SkAlphaType, with dimensions set to width and height.

Parameters
newWidthpixel column count; must be zero or greater
newHeightpixel row count; must be zero or greater
Returns
created SkImageInfo

◆ minRowBytes()

size_t SkImageInfo::minRowBytes ( ) const
inline

Returns minimum bytes per row, computed from pixel width() and SkColorType, which specifies bytesPerPixel().

SkBitmap maximum value for row bytes must fit in 31 bits.

Returns
width() times bytesPerPixel() as size_t

◆ minRowBytes64()

uint64_t SkImageInfo::minRowBytes64 ( ) const
inline

Returns minimum bytes per row, computed from pixel width() and SkColorType, which specifies bytesPerPixel().

SkBitmap maximum value for row bytes must fit in 31 bits.

Returns
width() times bytesPerPixel() as unsigned 64-bit integer

◆ operator!=()

bool SkImageInfo::operator!= ( const SkImageInfo other) const
inline

Compares SkImageInfo with other, and returns true if width, height, SkColorType, SkAlphaType, and SkColorSpace are not equivalent.

Parameters
otherSkImageInfo to compare
Returns
true if SkImageInfo is not equal to other

◆ operator==()

bool SkImageInfo::operator== ( const SkImageInfo other) const
inline

Compares SkImageInfo with other, and returns true if width, height, SkColorType, SkAlphaType, and SkColorSpace are equivalent.

Parameters
otherSkImageInfo to compare
Returns
true if SkImageInfo equals other

◆ refColorSpace()

sk_sp<SkColorSpace> SkImageInfo::refColorSpace ( ) const

Returns smart pointer to SkColorSpace, the range of colors.

The smart pointer tracks the number of objects sharing this SkColorSpace reference so the memory is released when the owners destruct.

The returned SkColorSpace is immutable.

Returns
SkColorSpace wrapped in a smart pointer

◆ reset()

void SkImageInfo::reset ( )
inline

Creates an empty SkImageInfo with kUnknown_SkColorType, kUnknown_SkAlphaType, a width and height of zero, and no SkColorSpace.

◆ shiftPerPixel()

int SkImageInfo::shiftPerPixel ( ) const
inline

Returns bit shift converting row bytes to row pixels.

Returns zero for kUnknown_SkColorType.

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

◆ validRowBytes()

bool SkImageInfo::validRowBytes ( size_t  rowBytes) const
inline

Returns true if rowBytes is valid for this SkImageInfo.

Parameters
rowBytessize of pixel row including padding
Returns
true if rowBytes is large enough to contain pixel row and is properly aligned

◆ width()

int SkImageInfo::width ( ) const
inline

Returns pixel count in each row.

Returns
pixel width

Member Data Documentation

◆ fDimensions

SkDEBUGCODE (void validate() const;) private SkISize SkImageInfo::fDimensions = {0, 0}

Asserts if internal values are illegal or inconsistent.

Only available if SK_DEBUG is defined at compile time.


The documentation for this struct was generated from the following file: