Skia
2D Graphics Library
SkPixmap Class Reference

SkPixmap provides a utility to pair SkImageInfo with pixels and row bytes. More...

#include <SkPixmap.h>

Public Member Functions

 SkPixmap ()
 Creates an empty SkPixmap without pixels, with kUnknown_SkColorType, with kUnknown_SkAlphaType, and with a width and height of zero. More...
 
 SkPixmap (const SkImageInfo &info, const void *addr, size_t rowBytes)
 Creates SkPixmap from info width, height, SkAlphaType, and SkColorType. More...
 
void reset ()
 Sets width, height, row bytes to zero; pixel address to nullptr; SkColorType to kUnknown_SkColorType; and SkAlphaType to kUnknown_SkAlphaType. More...
 
void reset (const SkImageInfo &info, const void *addr, size_t rowBytes)
 Sets width, height, SkAlphaType, and SkColorType from info. More...
 
void setColorSpace (sk_sp< SkColorSpace > colorSpace)
 Changes SkColorSpace in SkImageInfo; preserves width, height, SkAlphaType, and SkColorType in SkImage, and leaves pixel address and row bytes unchanged. More...
 
bool reset (const SkMask &mask)
 Deprecated. More...
 
bool extractSubset (SkPixmap *subset, const SkIRect &area) const
 Sets subset width, height, pixel address to intersection of SkPixmap with area, if intersection is not empty; and return true. More...
 
const SkImageInfoinfo () const
 Returns width, height, SkAlphaType, SkColorType, and SkColorSpace. More...
 
size_t rowBytes () const
 Returns row bytes, the interval from one pixel row to the next. More...
 
const void * addr () const
 Returns pixel address, the base address corresponding to the pixel origin. More...
 
int width () const
 Returns pixel count in each pixel row. More...
 
int height () const
 Returns pixel row count. More...
 
SkISize dimensions () const
 Return the dimensions of the pixmap (from its ImageInfo) More...
 
SkColorType colorType () const
 
SkAlphaType alphaType () const
 
SkColorSpacecolorSpace () const
 Returns SkColorSpace, the range of colors, associated with SkImageInfo. More...
 
sk_sp< SkColorSpacerefColorSpace () const
 Returns smart pointer to SkColorSpace, the range of colors, associated with SkImageInfo. More...
 
bool isOpaque () const
 Returns true if SkAlphaType is kOpaque_SkAlphaType. More...
 
SkIRect bounds () const
 Returns SkIRect { 0, 0, width(), height() }. More...
 
int rowBytesAsPixels () const
 Returns number of pixels that fit on row. More...
 
int shiftPerPixel () const
 Returns bit shift converting row bytes to row pixels. More...
 
size_t computeByteSize () const
 Returns minimum memory required for pixel storage. More...
 
bool computeIsOpaque () const
 Returns true if all pixels are opaque. More...
 
SkColor getColor (int x, int y) const
 Returns pixel at (x, y) as unpremultiplied color. More...
 
SkColor4f getColor4f (int x, int y) const
 Returns pixel at (x, y) as unpremultiplied color as an SkColor4f. More...
 
float getAlphaf (int x, int y) const
 Look up the pixel at (x,y) and return its alpha component, normalized to [0..1]. More...
 
const void * addr (int x, int y) const
 Returns readable pixel address at (x, y). More...
 
const uint8_t * addr8 () const
 Returns readable base pixel address. More...
 
const uint16_t * addr16 () const
 Returns readable base pixel address. More...
 
const uint32_t * addr32 () const
 Returns readable base pixel address. More...
 
const uint64_t * addr64 () const
 Returns readable base pixel address. More...
 
const uint16_t * addrF16 () const
 Returns readable base pixel address. More...
 
const uint8_t * addr8 (int x, int y) const
 Returns readable pixel address at (x, y). More...
 
const uint16_t * addr16 (int x, int y) const
 Returns readable pixel address at (x, y). More...
 
const uint32_t * addr32 (int x, int y) const
 Returns readable pixel address at (x, y). More...
 
const uint64_t * addr64 (int x, int y) const
 Returns readable pixel address at (x, y). More...
 
const uint16_t * addrF16 (int x, int y) const
 Returns readable pixel address at (x, y). More...
 
void * writable_addr () const
 Returns writable base pixel address. More...
 
void * writable_addr (int x, int y) const
 Returns writable pixel address at (x, y). More...
 
uint8_t * writable_addr8 (int x, int y) const
 Returns writable pixel address at (x, y). More...
 
uint16_t * writable_addr16 (int x, int y) const
 Returns writable_addr pixel address at (x, y). More...
 
uint32_t * writable_addr32 (int x, int y) const
 Returns writable pixel address at (x, y). More...
 
uint64_t * writable_addr64 (int x, int y) const
 Returns writable pixel address at (x, y). More...
 
uint16_t * writable_addrF16 (int x, int y) const
 Returns writable pixel address at (x, y). More...
 
bool readPixels (const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes) const
 Copies a SkRect of pixels to dstPixels. More...
 
bool readPixels (const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY) const
 Copies a SkRect of pixels to dstPixels. More...
 
bool readPixels (const SkPixmap &dst, int srcX, int srcY) const
 Copies a SkRect of pixels to dst. More...
 
bool readPixels (const SkPixmap &dst) const
 Copies pixels inside bounds() to dst. More...
 
bool scalePixels (const SkPixmap &dst, const SkSamplingOptions &) const
 Copies SkBitmap to dst, scaling pixels to fit dst.width() and dst.height(), and converting pixels to match dst.colorType() and dst.alphaType(). More...
 
bool erase (SkColor color, const SkIRect &subset) const
 Writes color to pixels bounded by subset; returns true on success. More...
 
bool erase (SkColor color) const
 Writes color to pixels inside bounds(); returns true on success. More...
 
bool erase (const SkColor4f &color, const SkIRect *subset=nullptr) const
 Writes color to pixels bounded by subset; returns true on success. More...
 

Detailed Description

SkPixmap provides a utility to pair SkImageInfo with pixels and row bytes.

SkPixmap is a low level class which provides convenience functions to access raster destinations. SkCanvas can not draw SkPixmap, nor does SkPixmap provide a direct drawing destination.

Use SkBitmap to draw pixels referenced by SkPixmap; use SkSurface to draw into pixels referenced by SkPixmap.

SkPixmap does not try to manage the lifetime of the pixel memory. Use SkPixelRef to manage pixel memory; SkPixelRef is safe across threads.

Constructor & Destructor Documentation

◆ SkPixmap() [1/2]

SkPixmap::SkPixmap ( )
inline

Creates an empty SkPixmap without pixels, with kUnknown_SkColorType, with kUnknown_SkAlphaType, and with a width and height of zero.

Use reset() to associate pixels, SkColorType, SkAlphaType, width, and height after SkPixmap has been created.

Returns
empty SkPixmap

◆ SkPixmap() [2/2]

SkPixmap::SkPixmap ( const SkImageInfo info,
const void *  addr,
size_t  rowBytes 
)
inline

Creates SkPixmap from info width, height, SkAlphaType, and SkColorType.

addr points to pixels, or nullptr. rowBytes should be info.width() times info.bytesPerPixel(), or larger.

No parameter checking is performed; it is up to the caller to ensure that addr and rowBytes agree with info.

The memory lifetime of pixels is managed by the caller. When SkPixmap goes out of scope, addr is unaffected.

SkPixmap may be later modified by reset() to change its size, pixel type, or storage.

Parameters
infowidth, height, SkAlphaType, SkColorType of SkImageInfo
addrpointer to pixels allocated by caller; may be nullptr
rowBytessize of one row of addr; width times pixel size, or larger
Returns
initialized SkPixmap

Member Function Documentation

◆ addr() [1/2]

const void* SkPixmap::addr ( ) const
inline

Returns pixel address, the base address corresponding to the pixel origin.

It is up to the SkPixmap creator to ensure that pixel address is a useful value.

Returns
pixel address

◆ addr() [2/2]

const void* SkPixmap::addr ( int  x,
int  y 
) const
inline

Returns readable pixel address at (x, y).

Returns nullptr if SkPixelRef is nullptr.

Input is not validated: out of bounds values of x or y trigger an assert() if built with SK_DEBUG defined. Returns nullptr if SkColorType is kUnknown_SkColorType.

Performs a lookup of pixel size; for better performance, call one of: addr8, addr16, addr32, addr64, or addrF16().

Parameters
xcolumn index, zero or greater, and less than width()
yrow index, zero or greater, and less than height()
Returns
readable generic pointer to pixel

◆ addr16() [1/2]

const uint16_t* SkPixmap::addr16 ( ) const
inline

Returns readable base pixel address.

Result is addressable as unsigned 16-bit words. Will trigger an assert() if SkColorType is not kRGB_565_SkColorType or kARGB_4444_SkColorType, and is built with SK_DEBUG defined.

One word corresponds to one pixel.

Returns
readable unsigned 16-bit pointer to pixels

◆ addr16() [2/2]

const uint16_t* SkPixmap::addr16 ( int  x,
int  y 
) const
inline

Returns readable pixel address at (x, y).

Input is not validated: out of bounds values of x or y trigger an assert() if built with SK_DEBUG defined.

Will trigger an assert() if SkColorType is not kRGB_565_SkColorType or kARGB_4444_SkColorType, and is built with SK_DEBUG defined.

Parameters
xcolumn index, zero or greater, and less than width()
yrow index, zero or greater, and less than height()
Returns
readable unsigned 16-bit pointer to pixel at (x, y)

◆ addr32() [1/2]

const uint32_t* SkPixmap::addr32 ( ) const
inline

Returns readable base pixel address.

Result is addressable as unsigned 32-bit words. Will trigger an assert() if SkColorType is not kRGBA_8888_SkColorType or kBGRA_8888_SkColorType, and is built with SK_DEBUG defined.

One word corresponds to one pixel.

Returns
readable unsigned 32-bit pointer to pixels

◆ addr32() [2/2]

const uint32_t* SkPixmap::addr32 ( int  x,
int  y 
) const
inline

Returns readable pixel address at (x, y).

Input is not validated: out of bounds values of x or y trigger an assert() if built with SK_DEBUG defined.

Will trigger an assert() if SkColorType is not kRGBA_8888_SkColorType or kBGRA_8888_SkColorType, and is built with SK_DEBUG defined.

Parameters
xcolumn index, zero or greater, and less than width()
yrow index, zero or greater, and less than height()
Returns
readable unsigned 32-bit pointer to pixel at (x, y)

◆ addr64() [1/2]

const uint64_t* SkPixmap::addr64 ( ) const
inline

Returns readable base pixel address.

Result is addressable as unsigned 64-bit words. Will trigger an assert() if SkColorType is not kRGBA_F16_SkColorType and is built with SK_DEBUG defined.

One word corresponds to one pixel.

Returns
readable unsigned 64-bit pointer to pixels

◆ addr64() [2/2]

const uint64_t* SkPixmap::addr64 ( int  x,
int  y 
) const
inline

Returns readable pixel address at (x, y).

Input is not validated: out of bounds values of x or y trigger an assert() if built with SK_DEBUG defined.

Will trigger an assert() if SkColorType is not kRGBA_F16_SkColorType and is built with SK_DEBUG defined.

Parameters
xcolumn index, zero or greater, and less than width()
yrow index, zero or greater, and less than height()
Returns
readable unsigned 64-bit pointer to pixel at (x, y)

◆ addr8() [1/2]

const uint8_t* SkPixmap::addr8 ( ) const
inline

Returns readable base pixel address.

Result is addressable as unsigned 8-bit bytes. Will trigger an assert() if SkColorType is not kAlpha_8_SkColorType or kGray_8_SkColorType, and is built with SK_DEBUG defined.

One byte corresponds to one pixel.

Returns
readable unsigned 8-bit pointer to pixels

◆ addr8() [2/2]

const uint8_t* SkPixmap::addr8 ( int  x,
int  y 
) const
inline

Returns readable pixel address at (x, y).

Input is not validated: out of bounds values of x or y trigger an assert() if built with SK_DEBUG defined.

Will trigger an assert() if SkColorType is not kAlpha_8_SkColorType or kGray_8_SkColorType, and is built with SK_DEBUG defined.

Parameters
xcolumn index, zero or greater, and less than width()
yrow index, zero or greater, and less than height()
Returns
readable unsigned 8-bit pointer to pixel at (x, y)

◆ addrF16() [1/2]

const uint16_t* SkPixmap::addrF16 ( ) const
inline

Returns readable base pixel address.

Result is addressable as unsigned 16-bit words. Will trigger an assert() if SkColorType is not kRGBA_F16_SkColorType and is built with SK_DEBUG defined.

Each word represents one color component encoded as a half float. Four words correspond to one pixel.

Returns
readable unsigned 16-bit pointer to first component of pixels

◆ addrF16() [2/2]

const uint16_t* SkPixmap::addrF16 ( int  x,
int  y 
) const
inline

Returns readable pixel address at (x, y).

Input is not validated: out of bounds values of x or y trigger an assert() if built with SK_DEBUG defined.

Will trigger an assert() if SkColorType is not kRGBA_F16_SkColorType and is built with SK_DEBUG defined.

Each unsigned 16-bit word represents one color component encoded as a half float. Four words correspond to one pixel.

Parameters
xcolumn index, zero or greater, and less than width()
yrow index, zero or greater, and less than height()
Returns
readable unsigned 16-bit pointer to pixel component at (x, y)

◆ alphaType()

SkAlphaType SkPixmap::alphaType ( ) const
inline

◆ bounds()

SkIRect SkPixmap::bounds ( ) const
inline

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

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

◆ colorSpace()

SkColorSpace* SkPixmap::colorSpace ( ) const

Returns SkColorSpace, the range of colors, associated with SkImageInfo.

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

Returns
SkColorSpace in SkImageInfo, or nullptr

◆ colorType()

SkColorType SkPixmap::colorType ( ) const
inline

◆ computeByteSize()

size_t SkPixmap::computeByteSize ( ) const
inline

Returns minimum memory required for pixel storage.

Does not include unused memory on last row when rowBytesAsPixels() exceeds width(). Returns SIZE_MAX if result does not fit in size_t. Returns zero if height() or width() is 0. Returns height() times rowBytes() if colorType() is kUnknown_SkColorType.

Returns
size in bytes of image buffer

◆ computeIsOpaque()

bool SkPixmap::computeIsOpaque ( ) const

Returns true if all pixels are opaque.

SkColorType determines how pixels are encoded, and whether pixel describes alpha. Returns true for SkColorType without alpha in each pixel; for other SkColorType, returns true if all pixels have alpha values equivalent to 1.0 or greater.

For SkColorType kRGB_565_SkColorType or kGray_8_SkColorType: always returns true. For SkColorType kAlpha_8_SkColorType, kBGRA_8888_SkColorType, kRGBA_8888_SkColorType: returns true if all pixel alpha values are 255. For SkColorType kARGB_4444_SkColorType: returns true if all pixel alpha values are 15. For kRGBA_F16_SkColorType: returns true if all pixel alpha values are 1.0 or greater.

Returns false for kUnknown_SkColorType.

Returns
true if all pixels have opaque values or SkColorType is opaque

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

◆ dimensions()

SkISize SkPixmap::dimensions ( ) const
inline

Return the dimensions of the pixmap (from its ImageInfo)

◆ erase() [1/3]

bool SkPixmap::erase ( const SkColor4f color,
const SkIRect subset = nullptr 
) const

Writes color to pixels bounded by subset; returns true on success.

if subset is nullptr, writes colors pixels inside bounds(). Returns false if colorType() is kUnknown_SkColorType, if subset is not nullptr and does not intersect bounds(), or if subset is nullptr and bounds() is empty.

Parameters
colorunpremultiplied color to write
subsetbounding integer SkRect of pixels to write; may be nullptr
Returns
true if pixels are changed

◆ erase() [2/3]

bool SkPixmap::erase ( SkColor  color) const
inline

Writes color to pixels inside bounds(); returns true on success.

Returns false if colorType() is kUnknown_SkColorType, or if bounds() is empty.

Parameters
colorsRGB unpremultiplied color to write
Returns
true if pixels are changed

◆ erase() [3/3]

bool SkPixmap::erase ( SkColor  color,
const SkIRect subset 
) const

Writes color to pixels bounded by subset; returns true on success.

Returns false if colorType() is kUnknown_SkColorType, or if subset does not intersect bounds().

Parameters
colorsRGB unpremultiplied color to write
subsetbounding integer SkRect of written pixels
Returns
true if pixels are changed

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

◆ extractSubset()

bool SkPixmap::extractSubset ( SkPixmap subset,
const SkIRect area 
) const

Sets subset width, height, pixel address to intersection of SkPixmap with area, if intersection is not empty; and return true.

Otherwise, leave subset unchanged and return false.

Failing to read the return value generates a compile time warning.

Parameters
subsetstorage for width, height, pixel address of intersection
areabounds to intersect with SkPixmap
Returns
true if intersection of SkPixmap and area is not empty

◆ getAlphaf()

float SkPixmap::getAlphaf ( int  x,
int  y 
) const

Look up the pixel at (x,y) and return its alpha component, normalized to [0..1].

This is roughly equivalent to SkGetColorA(getColor()), but can be more efficent (and more precise if the pixels store more than 8 bits per component).

Parameters
xcolumn index, zero or greater, and less than width()
yrow index, zero or greater, and less than height()
Returns
alpha converted to normalized float

◆ getColor()

SkColor SkPixmap::getColor ( int  x,
int  y 
) const

Returns pixel at (x, y) as unpremultiplied color.

Returns black with alpha if SkColorType is kAlpha_8_SkColorType.

Input is not validated: out of bounds values of x or y trigger an assert() if built with SK_DEBUG defined; and returns undefined values or may crash if SK_RELEASE is defined. Fails if SkColorType is kUnknown_SkColorType or pixel address is nullptr.

SkColorSpace in SkImageInfo is ignored. Some color precision may be lost in the conversion to unpremultiplied color; original pixel data may have additional precision.

Parameters
xcolumn index, zero or greater, and less than width()
yrow index, zero or greater, and less than height()
Returns
pixel converted to unpremultiplied color

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

◆ getColor4f()

SkColor4f SkPixmap::getColor4f ( int  x,
int  y 
) const

Returns pixel at (x, y) as unpremultiplied color as an SkColor4f.

Returns black with alpha if SkColorType is kAlpha_8_SkColorType.

Input is not validated: out of bounds values of x or y trigger an assert() if built with SK_DEBUG defined; and returns undefined values or may crash if SK_RELEASE is defined. Fails if SkColorType is kUnknown_SkColorType or pixel address is nullptr.

SkColorSpace in SkImageInfo is ignored. Some color precision may be lost in the conversion to unpremultiplied color; original pixel data may have additional precision, though this is less likely than for getColor(). Rounding errors may occur if the underlying type has lower precision.

Parameters
xcolumn index, zero or greater, and less than width()
yrow index, zero or greater, and less than height()
Returns
pixel converted to unpremultiplied float color

◆ height()

int SkPixmap::height ( ) const
inline

Returns pixel row count.

Returns
pixel height in SkImageInfo

◆ info()

const SkImageInfo& SkPixmap::info ( ) const
inline

Returns width, height, SkAlphaType, SkColorType, and SkColorSpace.

Returns
reference to SkImageInfo

◆ isOpaque()

bool SkPixmap::isOpaque ( ) const
inline

Returns true if SkAlphaType is kOpaque_SkAlphaType.

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

Returns
true if SkImageInfo has opaque SkAlphaType

◆ readPixels() [1/4]

bool SkPixmap::readPixels ( const SkImageInfo dstInfo,
void *  dstPixels,
size_t  dstRowBytes 
) const
inline

Copies a SkRect of pixels to dstPixels.

Copy starts at (0, 0), and does not exceed SkPixmap (width(), height()).

dstInfo specifies width, height, SkColorType, SkAlphaType, and SkColorSpace of destination. dstRowBytes specifics the gap from one destination row to the next. Returns true if pixels are copied. Returns false if dstInfo address equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes().

Pixels are copied only if pixel conversion is possible. If SkPixmap colorType() is kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match. If SkPixmap colorType() is kGray_8_SkColorType, dstInfo.colorSpace() must match. If SkPixmap alphaType() is kOpaque_SkAlphaType, dstInfo.alphaType() must match. If SkPixmap colorSpace() is nullptr, dstInfo.colorSpace() must match. Returns false if pixel conversion is not possible.

Returns false if SkPixmap width() or height() is zero or negative.

Parameters
dstInfodestination width, height, SkColorType, SkAlphaType, SkColorSpace
dstPixelsdestination pixel storage
dstRowBytesdestination row length
Returns
true if pixels are copied to dstPixels

◆ readPixels() [2/4]

bool SkPixmap::readPixels ( const SkImageInfo dstInfo,
void *  dstPixels,
size_t  dstRowBytes,
int  srcX,
int  srcY 
) const

Copies a SkRect of pixels to dstPixels.

Copy starts at (srcX, srcY), and does not exceed SkPixmap (width(), height()).

dstInfo specifies width, height, SkColorType, SkAlphaType, and SkColorSpace of destination. dstRowBytes specifics the gap from one destination row to the next. Returns true if pixels are copied. Returns false if dstInfo address equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes().

Pixels are copied only if pixel conversion is possible. If SkPixmap colorType() is kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match. If SkPixmap colorType() is kGray_8_SkColorType, dstInfo.colorSpace() must match. If SkPixmap alphaType() is kOpaque_SkAlphaType, dstInfo.alphaType() must match. If SkPixmap colorSpace() is nullptr, dstInfo.colorSpace() must match. Returns false if pixel conversion is not possible.

srcX and srcY may be negative to copy only top or left of source. Returns false if SkPixmap width() or height() is zero or negative. Returns false if: abs(srcX) >= Pixmap width(), or if abs(srcY) >= Pixmap height().

Parameters
dstInfodestination width, height, SkColorType, SkAlphaType, SkColorSpace
dstPixelsdestination pixel storage
dstRowBytesdestination row length
srcXcolumn index whose absolute value is less than width()
srcYrow index whose absolute value is less than height()
Returns
true if pixels are copied to dstPixels

◆ readPixels() [3/4]

bool SkPixmap::readPixels ( const SkPixmap dst) const
inline

Copies pixels inside bounds() to dst.

dst specifies width, height, SkColorType, SkAlphaType, and SkColorSpace of destination. Returns true if pixels are copied. Returns false if dst address equals nullptr, or dst.rowBytes() is less than dst SkImageInfo::minRowBytes.

Pixels are copied only if pixel conversion is possible. If SkPixmap colorType() is kGray_8_SkColorType, or kAlpha_8_SkColorType; dst SkColorType must match. If SkPixmap colorType() is kGray_8_SkColorType, dst SkColorSpace must match. If SkPixmap alphaType() is kOpaque_SkAlphaType, dst SkAlphaType must match. If SkPixmap colorSpace() is nullptr, dst SkColorSpace must match. Returns false if pixel conversion is not possible.

Returns false if SkPixmap width() or height() is zero or negative.

Parameters
dstSkImageInfo and pixel address to write to
Returns
true if pixels are copied to dst

◆ readPixels() [4/4]

bool SkPixmap::readPixels ( const SkPixmap dst,
int  srcX,
int  srcY 
) const
inline

Copies a SkRect of pixels to dst.

Copy starts at (srcX, srcY), and does not exceed SkPixmap (width(), height()). dst specifies width, height, SkColorType, SkAlphaType, and SkColorSpace of destination. Returns true if pixels are copied. Returns false if dst address equals nullptr, or dst.rowBytes() is less than dst SkImageInfo::minRowBytes.

Pixels are copied only if pixel conversion is possible. If SkPixmap colorType() is kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.info().colorType must match. If SkPixmap colorType() is kGray_8_SkColorType, dst.info().colorSpace must match. If SkPixmap alphaType() is kOpaque_SkAlphaType, dst.info().alphaType must match. If SkPixmap colorSpace() is nullptr, dst.info().colorSpace must match. Returns false if pixel conversion is not possible.

srcX and srcY may be negative to copy only top or left of source. Returns false SkPixmap width() or height() is zero or negative. Returns false if: abs(srcX) >= Pixmap width(), or if abs(srcY) >= Pixmap height().

Parameters
dstSkImageInfo and pixel address to write to
srcXcolumn index whose absolute value is less than width()
srcYrow index whose absolute value is less than height()
Returns
true if pixels are copied to dst

◆ refColorSpace()

sk_sp<SkColorSpace> SkPixmap::refColorSpace ( ) const

Returns smart pointer to SkColorSpace, the range of colors, associated with SkImageInfo.

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 in SkImageInfo wrapped in a smart pointer

◆ reset() [1/3]

void SkPixmap::reset ( )

Sets width, height, row bytes to zero; pixel address to nullptr; SkColorType to kUnknown_SkColorType; and SkAlphaType to kUnknown_SkAlphaType.

The prior pixels are unaffected; it is up to the caller to release pixels memory if desired.

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

◆ reset() [2/3]

void SkPixmap::reset ( const SkImageInfo info,
const void *  addr,
size_t  rowBytes 
)

Sets width, height, SkAlphaType, and SkColorType from info.

Sets pixel address from addr, which may be nullptr. Sets row bytes from rowBytes, which should be info.width() times info.bytesPerPixel(), or larger.

Does not check addr. Asserts if built with SK_DEBUG defined and if rowBytes is too small to hold one row of pixels.

The memory lifetime pixels are managed by the caller. When SkPixmap goes out of scope, addr is unaffected.

Parameters
infowidth, height, SkAlphaType, SkColorType of SkImageInfo
addrpointer to pixels allocated by caller; may be nullptr
rowBytessize of one row of addr; width times pixel size, or larger

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

◆ reset() [3/3]

bool SkPixmap::reset ( const SkMask &  mask)

Deprecated.

◆ rowBytes()

size_t SkPixmap::rowBytes ( ) const
inline

Returns row bytes, the interval from one pixel row to the next.

Row bytes is at least as large as: width() * info().bytesPerPixel().

Returns zero if colorType() is kUnknown_SkColorType. It is up to the SkBitmap creator to ensure that row bytes is a useful value.

Returns
byte length of pixel row

◆ rowBytesAsPixels()

int SkPixmap::rowBytesAsPixels ( ) const
inline

Returns number of pixels that fit on row.

Should be greater than or equal to width().

Returns
maximum pixels per row

◆ scalePixels()

bool SkPixmap::scalePixels ( const SkPixmap dst,
const SkSamplingOptions  
) const

Copies SkBitmap to dst, scaling pixels to fit dst.width() and dst.height(), and converting pixels to match dst.colorType() and dst.alphaType().

Returns true if pixels are copied. Returns false if dst address is nullptr, or dst.rowBytes() is less than dst SkImageInfo::minRowBytes.

Pixels are copied only if pixel conversion is possible. If SkPixmap colorType() is kGray_8_SkColorType, or kAlpha_8_SkColorType; dst SkColorType must match. If SkPixmap colorType() is kGray_8_SkColorType, dst SkColorSpace must match. If SkPixmap alphaType() is kOpaque_SkAlphaType, dst SkAlphaType must match. If SkPixmap colorSpace() is nullptr, dst SkColorSpace must match. Returns false if pixel conversion is not possible.

Returns false if SkBitmap width() or height() is zero or negative.

Parameters
dstSkImageInfo and pixel address to write to
Returns
true if pixels are scaled to fit dst

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

◆ setColorSpace()

void SkPixmap::setColorSpace ( sk_sp< SkColorSpace colorSpace)

Changes SkColorSpace in SkImageInfo; preserves width, height, SkAlphaType, and SkColorType in SkImage, and leaves pixel address and row bytes unchanged.

SkColorSpace reference count is incremented.

Parameters
colorSpaceSkColorSpace moved to SkImageInfo

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

◆ shiftPerPixel()

int SkPixmap::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

◆ width()

int SkPixmap::width ( ) const
inline

Returns pixel count in each pixel row.

Should be equal or less than: rowBytes() / info().bytesPerPixel().

Returns
pixel width in SkImageInfo

◆ writable_addr() [1/2]

void* SkPixmap::writable_addr ( ) const
inline

Returns writable base pixel address.

Returns
writable generic base pointer to pixels

◆ writable_addr() [2/2]

void* SkPixmap::writable_addr ( int  x,
int  y 
) const
inline

Returns writable pixel address at (x, y).

Input is not validated: out of bounds values of x or y trigger an assert() if built with SK_DEBUG defined. Returns zero if SkColorType is kUnknown_SkColorType.

Parameters
xcolumn index, zero or greater, and less than width()
yrow index, zero or greater, and less than height()
Returns
writable generic pointer to pixel

◆ writable_addr16()

uint16_t* SkPixmap::writable_addr16 ( int  x,
int  y 
) const
inline

Returns writable_addr pixel address at (x, y).

Result is addressable as unsigned 16-bit words. Will trigger an assert() if SkColorType is not kRGB_565_SkColorType or kARGB_4444_SkColorType, and is built with SK_DEBUG defined.

One word corresponds to one pixel.

Parameters
xcolumn index, zero or greater, and less than width()
yrow index, zero or greater, and less than height()
Returns
writable unsigned 16-bit pointer to pixel

◆ writable_addr32()

uint32_t* SkPixmap::writable_addr32 ( int  x,
int  y 
) const
inline

Returns writable pixel address at (x, y).

Result is addressable as unsigned 32-bit words. Will trigger an assert() if SkColorType is not kRGBA_8888_SkColorType or kBGRA_8888_SkColorType, and is built with SK_DEBUG defined.

One word corresponds to one pixel.

Parameters
xcolumn index, zero or greater, and less than width()
yrow index, zero or greater, and less than height()
Returns
writable unsigned 32-bit pointer to pixel

◆ writable_addr64()

uint64_t* SkPixmap::writable_addr64 ( int  x,
int  y 
) const
inline

Returns writable pixel address at (x, y).

Result is addressable as unsigned 64-bit words. Will trigger an assert() if SkColorType is not kRGBA_F16_SkColorType and is built with SK_DEBUG defined.

One word corresponds to one pixel.

Parameters
xcolumn index, zero or greater, and less than width()
yrow index, zero or greater, and less than height()
Returns
writable unsigned 64-bit pointer to pixel

◆ writable_addr8()

uint8_t* SkPixmap::writable_addr8 ( int  x,
int  y 
) const
inline

Returns writable pixel address at (x, y).

Result is addressable as unsigned 8-bit bytes. Will trigger an assert() if SkColorType is not kAlpha_8_SkColorType or kGray_8_SkColorType, and is built with SK_DEBUG defined.

One byte corresponds to one pixel.

Parameters
xcolumn index, zero or greater, and less than width()
yrow index, zero or greater, and less than height()
Returns
writable unsigned 8-bit pointer to pixels

◆ writable_addrF16()

uint16_t* SkPixmap::writable_addrF16 ( int  x,
int  y 
) const
inline

Returns writable pixel address at (x, y).

Result is addressable as unsigned 16-bit words. Will trigger an assert() if SkColorType is not kRGBA_F16_SkColorType and is built with SK_DEBUG defined.

Each word represents one color component encoded as a half float. Four words correspond to one pixel.

Parameters
xcolumn index, zero or greater, and less than width()
yrow index, zero or greater, and less than height()
Returns
writable unsigned 16-bit pointer to first component of pixel

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