skia2/site/user/api/SkBitmap_Reference.md
Cary Clark 7cfcbca716 limit bookmaker status output
streamline 'working as intended' output
notify when output changed
fix bug which appended output incorrectly to SkBitmap.h
fix bug that hid bad SkSurface.h from detection

Docs-Preview: https://skia.org/?cl=90162
Bug: skia:6898
Change-Id: I067cfe5bbad706345fb5cd540cdc3835ce22d822
Reviewed-on: https://skia-review.googlesource.com/90162
Commit-Queue: Cary Clark <caryclark@skia.org>
Reviewed-by: Cary Clark <caryclark@skia.org>
2018-01-04 21:41:09 +00:00

152 KiB

SkBitmap Reference

Bitmap

Class SkBitmap

Bitmap describes a two-dimensional raster pixel array. Bitmap is built on Image Info, containing integer width and height, Color Type and Alpha Type describing the pixel format, and Color Space describing the range of colors. Bitmap points to Pixel Ref, which describes the physical array of pixels. Image Info bounds may be located anywhere fully inside Pixel Ref bounds.

Bitmap can be drawn using Canvas. Bitmap can be a drawing destination for Canvas draw methods. Bitmap flexibility as a pixel container limits some optimizations available to the target platform.

If pixel array is primarily read-only, use Image for better performance. If pixel array is primarily written to, use Surface for better performance.

Declaring SkBitmap const prevents altering Image Info: the Bitmap height, width, and so on cannot change. It does not affect Pixel Ref: a caller may write its pixels. Declaring SkBitmap const affects Bitmap configuration, not its contents.

Bitmap is not thread safe. Each thread must have its own copy of Bitmap fields, although threads may share the underlying pixel array.

Row Bytes

Bitmap pixels may be contiguous, or may have a gap at the end of each row. Row Bytes is the interval from one row to the next. Row Bytes may be specified; sometimes passing zero will compute the Row Bytes from the row width and the number of bytes in a pixel. Row Bytes may be larger than the row requires. This is useful to position one or more Bitmaps within a shared pixel array.

Overview

Subtopics

topics description

Structs

description struct
Allocator
HeapAllocator

Constructors

description function
SkBitmap() Constructs with default values.
SkBitmap(SkBitmap&& src) Takes ownership of pixels.
SkBitmap(const SkBitmap& src) Shares ownership of pixels.
Releases ownership of pixels.

Operators

description function
SkBitmap& operator=(SkBitmap&& src) Takes ownership of pixels.
SkBitmap& operator=(const SkBitmap& src) Shares ownership of pixels.

Member Functions

description function
ComputeIsOpaque Returns true if all pixels are opaque.
allocN32Pixels Allocates compatible Color ARGB pixels, or aborts.
allocPixels Allocates pixels from Image Info, or aborts.
allocPixelsFlags Allocates pixels from Image Info with options, or aborts.
alphaType Returns Image Info Alpha Type.
bounds Returns width and height as Rectangle.
bytesPerPixel Returns number of bytes in pixel based on Color Type.
colorSpace Returns Image Info Color Space.
colorType Returns Image Info Color Type.
computeByteSize Returns size required for pixels.
dimensions Returns width and height.
drawsNothing Returns true if no width, no height, or no Pixel Ref.
empty Returns true if Image Info has zero width or height.
erase Writes Color to rectangle of pixels.
eraseARGB Writes Color to pixels.
eraseArea Deprecated
eraseColor Writes Color to pixels.
eraseRGB Deprecated
extractAlpha Creates Bitmap containing Alpha of pixels.
extractSubset Creates Bitmap, sharing pixels if possible.
getAddr Returns readable pixel address as void pointer.
getAddr16 Returns readable pixel address as 16-bit pointer.
getAddr32 Returns readable pixel address as 32-bit pointer.
getAddr8 Returns readable pixel address as 8-bit pointer.
getBounds Returns width and height as Rectangle.
getColor Returns one pixel as Unpremultiplied Color.
getGenerationID Returns unique ID.
getPixels Returns address of pixels.
getSubset Returns bounds offset by origin.
hasHardwareMipMap Returns Mip Map support present; Android only.
height Returns pixel row count.
info Returns Image Info.
installMaskPixels Creates Pixel Ref from Mask.
installPixels Creates Pixel Ref, with optional release function.
isImmutable Returns true if pixels will not change.
isNull Returns true if Pixel Ref is nullptr.
isOpaque Returns true if Image Info describes opaque pixels.
isVolatile Returns true if pixels should not be cached.
notifyPixelsChanged Marks pixels as changed, altering the unique ID.
peekPixels Returns Pixmap if possible.
pixelRef Returns Pixel Ref, or nullptr.
pixelRefOrigin Returns offset within Pixel Ref.
pixmap Returns Pixmap if possible.
readPixels Copies and converts pixels.
readyToDraw Returns true if address of pixels is not nullptr.
refColorSpace Returns Image Info Color Space.
reset Sets to default values, releases pixel ownership.
rowBytes Returns interval between rows in bytes.
rowBytesAsPixels Returns interval between rows in pixels.
setAlphaType Sets Alpha Type of shared pixels.
setHasHardwareMipMap Sets Mip Map support present; Android only.
setImmutable Marks that pixels will not change.
setInfo Sets height, width, Color Type, and so on, releasing pixels.
setIsVolatile Marks if pixels should not be cached.
setPixelRef Sets Pixel Ref and offset.
setPixels Sets Pixel Ref without an offset.
shiftPerPixel Returns bit shift from pixels to bytes.
swap Exchanges Bitmap pair.
toString Converts Bitmap to machine readable form.
tryAllocN32Pixels Allocates compatible Color ARGB pixels if possible.
tryAllocPixels Allocates pixels from Image Info if possible.
tryAllocPixelsFlags Allocates pixels from Image Info with options if possible.
validate Asserts if Bitmap is invalid (debug only).
width Returns pixel column count.
writePixels Copies and converts pixels.

Class SkBitmap::Allocator

class Allocator : public SkRefCnt {
public:
virtual bool allocPixelRef(SkBitmap* bitmap) = 0;
};

Abstract subclass of HeapAllocator.

allocPixelRef

virtual bool allocPixelRef(SkBitmap* bitmap) = 0

Allocates the pixel memory for the bitmap, given its dimensions and Color Type. Returns true on success, where success means either setPixels or setPixelRef was called.

Parameters

bitmap Bitmap containing Image Info as input, and Pixel Ref as output

Return Value

true if Pixel Ref was allocated

See Also

HeapAllocator


Class SkBitmap::HeapAllocator

class HeapAllocator : public Allocator {
public:
bool allocPixelRef(SkBitmap* bitmap) override;
};

Subclass of Allocator that returns a Pixel Ref that allocates its pixel memory from the heap. This is the default Allocator invoked by allocPixels.

allocPixelRef

bool allocPixelRef(SkBitmap* bitmap) override

Allocates the pixel memory for the bitmap, given its dimensions and Color Type. Returns true on success, where success means either setPixels or setPixelRef was called.

Parameters

bitmap Bitmap containing Image Info as input, and Pixel Ref as output

Return Value

true if pixels are allocated

Example

Example Output

#Volatile
pixel address = (nil)
pixel address = 0x560ddd0ac670

See Also

Allocator tryAllocPixels


SkBitmap

SkBitmap()

Creates an empty Bitmap without pixels, with kUnknown SkColorType, kUnknown SkAlphaType, and with a width and height of zero. Pixel Ref origin is set to (0, 0). Bitmap is not volatile.

Use setInfo to associate SkColorType, SkAlphaType, width, and height after Bitmap has been created.

Return Value

empty Bitmap

Example

Example Output

width:  0  height:  0  color: kUnknown_SkColorType  alpha: kUnknown_SkAlphaType
width: 25  height: 35  color: kRGBA_8888_SkColorType  alpha: kOpaque_SkAlphaType

See Also

setInfo


SkBitmap

SkBitmap(const SkBitmap& src)

Copies settings from src to returned Bitmap. Shares pixels if src has pixels allocated, so both bitmaps reference the same pixels.

Parameters

src Bitmap to copy Image Info, and share Pixel Ref

Return Value

copy of src

Example

Example Output

original has pixels before copy: true
original has pixels after copy: true
copy has pixels: true

See Also

setInfo setPixelRef setPixels swap


SkBitmap

SkBitmap(SkBitmap&& src)

Copies settings from src to returned Bitmap. Moves ownership of src pixels to Bitmap.

Parameters

src Bitmap to copy Image Info, and reassign Pixel Ref

Return Value

copy of src

Example

Example Output

original has pixels before move: true
original has pixels after move: false
copy has pixels: true

See Also

setInfo setPixelRef setPixels swap


~SkBitmap

~SkBitmap()

Decrements Pixel Ref reference count, if Pixel Ref is not nullptr.

See Also

Pixel Ref


operator=

SkBitmap& operator=(const SkBitmap& src)

Copies settings from src to returned Bitmap. Shares pixels if src has pixels allocated, so both bitmaps reference the same pixels.

Parameters

src Bitmap to copy Image Info, and share Pixel Ref

Return Value

copy of src

Example

Example Output

original has pixels before copy: true
original has pixels after copy: true
copy has pixels: true

See Also

setInfo setPixelRef setPixels swap


operator=

SkBitmap& operator=(SkBitmap&& src)

Copies settings from src to returned Bitmap. Moves ownership of src pixels to Bitmap.

Parameters

src Bitmap to copy Image Info, and reassign Pixel Ref

Return Value

copy of src

Example

Example Output

original has pixels before move: true
original has pixels after move: false
copy has pixels: true

See Also

setInfo setPixelRef setPixels swap


swap

void swap(SkBitmap& other)

Swaps the fields of the two bitmaps.

Parameters

other Bitmap exchanged with original

Example

Example Output

one width:1 height:1 colorType:kRGBA_8888_SkColorType alphaType:kOpaque_SkAlphaType
two width:2 height:2 colorType:kBGRA_8888_SkColorType alphaType:kPremul_SkAlphaType
one width:2 height:2 colorType:kBGRA_8888_SkColorType alphaType:kPremul_SkAlphaType
two width:1 height:1 colorType:kRGBA_8888_SkColorType alphaType:kOpaque_SkAlphaType

See Also

SkBitmap(SkBitmap&& src) operator=(SkBitmap&& src)


pixmap

SkPixmap pixmap() const

Returns Pixmap with Bitmap pixel address, row bytes, and Image Info, if address is available. If pixel address is not available, returns default constructed Pixmap: nullptr pixels, kUnknown SkColorType, kUnknown SkAlphaType, width and height of zero.

Returned Pixmap becomes invalid on any future change to Bitmap

Return Value

Pixmap describing Bitmap, if pixels are readable; otherwise containing zeroes

Example

Example Output

----------
---xx-----
--x--x----
--x-------
--xx------
--x-x---x-
-x---x--x-
-x----xx--
-xx---x---
--xxxx-xx-
----------

See Also

peekPixels installPixels readPixels writePixels


info

const SkImageInfo& info() const

Returns width, height, Alpha Type, Color Type, and Color Space.

Return Value

reference to Image Info

Example

Example Output

width: 56 height: 56 color: BGRA_8888 alpha: Opaque

See Also

Image Info


width

int width() const

Returns pixel count in each row. Should be equal or less than:

rowBytes / info.bytesPerPixel.

Maybe be less than pixelRef.width. Will not exceed pixelRef.width less pixelRefOrigin.fX.

Return Value

pixel width in Image Info

Example

Example Output

bitmap width: 16  info width: 16

See Also

height SkPixelRef::width() SkImageInfo::width()


height

int height() const

Returns pixel row count.

Maybe be less than pixelRef.height. Will not exceed pixelRef.height less pixelRefOrigin.fY.

Return Value

pixel height in Image Info

Example

Example Output

bitmap height: 32  info height: 32

See Also

width SkPixelRef::height() SkImageInfo::height()


colorType

SkColorType colorType() const

Returns Color Type, one of: kUnknown SkColorType, kAlpha 8 SkColorType, kRGB 565 SkColorType, kARGB 4444 SkColorType, kRGBA 8888 SkColorType, kBGRA 8888 SkColorType, kGray 8 SkColorType, kRGBA F16 SkColorType.

Return Value

Color Type in Image Info

Example

Example Output

color type: kAlpha_SkColorType

See Also

alphaType SkImageInfo::colorType


alphaType

SkAlphaType alphaType() const

Returns Alpha Type, one of: kUnknown SkAlphaType, kOpaque SkAlphaType, kPremul SkAlphaType, kUnpremul SkAlphaType.

Return Value

Alpha Type in Image Info

Example

Example Output

alpha type: kPremul_SkAlphaType

See Also

colorType SkImageInfo::alphaType


colorSpace

SkColorSpace* colorSpace() const

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

Return Value

Color Space in Image Info, 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 SkImageInfo::colorSpace


refColorSpace

sk_sp<SkColorSpace> refColorSpace() const

Returns a smart pointer to Color Space, the range of colors, associated with Image Info. 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 in Image Info wrapped in a smart pointer

Example

Example Output

gammaCloseToSRGB: false  gammaIsLinear: true  isSRGB: false

See Also

Color Space SkImageInfo::colorSpace


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

Example Output

color: kUnknown_SkColorType   bytesPerPixel: 0
color: kAlpha_SkColorType     bytesPerPixel: 1
color: kRGB_565_SkColorType   bytesPerPixel: 2
color: kARGB_4444_SkColorType bytesPerPixel: 2
color: kRGBA_8888_SkColorType bytesPerPixel: 4
color: kBGRA_8888_SkColorType bytesPerPixel: 4
color: kGray_8_SkColorType    bytesPerPixel: 1
color: kRGBA_F16_SkColorType  bytesPerPixel: 8

See Also

rowBytes rowBytesAsPixels width shiftPerPixel


rowBytesAsPixels

int rowBytesAsPixels() const

Returns number of pixels that fit on row. Should be greater than or equal to width.

Return Value

maximum pixels per row

Example

Example Output

rowBytes: 4 rowBytesAsPixels: 1
rowBytes: 5 rowBytesAsPixels: 1
rowBytes: 6 rowBytesAsPixels: 1
rowBytes: 7 rowBytesAsPixels: 1
rowBytes: 8 rowBytesAsPixels: 2

See Also

rowBytes shiftPerPixel width 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

Example Output

color: kUnknown_SkColorType   shiftPerPixel: 0
color: kAlpha_SkColorType     shiftPerPixel: 0
color: kRGB_565_SkColorType   shiftPerPixel: 1
color: kARGB_4444_SkColorType shiftPerPixel: 1
color: kRGBA_8888_SkColorType shiftPerPixel: 2
color: kBGRA_8888_SkColorType shiftPerPixel: 2
color: kGray_8_SkColorType    shiftPerPixel: 0
color: kRGBA_F16_SkColorType  shiftPerPixel: 3

See Also

rowBytes rowBytesAsPixels width bytesPerPixel


empty

bool empty() const

Returns true if either width or height are zero.

Does not check if Pixel Ref is nullptr; call drawsNothing to check width, height, and Pixel Ref.

Return Value

true if dimensions do not enclose area

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

height width drawsNothing


isNull

bool isNull() const

Return true if Pixel Ref is nullptr.

Does not check if width or height are zero; call drawsNothing to check width, height, and Pixel Ref.

Return Value

true if no Pixel Ref is associated

Example

Example Output

empty bitmap does not have pixels
bitmap with dimensions does not have pixels
allocated bitmap does have pixels

See Also

empty drawsNothing pixelRef


drawsNothing

bool drawsNothing() const

Return true if width or height are zero, or if Pixel Ref is nullptr. If true, Bitmap has no effect when drawn or drawn into.

Return Value

true if drawing has no effect

Example

Example Output

empty:true  isNull:true  drawsNothing:true
empty:true  isNull:false drawsNothing:true
empty:false isNull:true  drawsNothing:true
empty:false isNull:false drawsNothing:false

See Also

empty isNull pixelRef


rowBytes

size_t rowBytes() const

Returns row bytes, the interval from one pixel row to the next. Row bytes is at least as large aswidth * info.bytesPerPixel.

Returns zero if colorType is kUnknown SkColorType, or if row bytes supplied to setInfo is not large enough to hold a row of pixels.

Return Value

byte length of pixel row

Example

Example Output

setInfo returned:false rowBytes:0
setInfo returned:true  rowBytes:8

See Also

info setInfo SkImageInfo::minRowBytes


setAlphaType

bool setAlphaType(SkAlphaType alphaType)

Sets Alpha Type, if alphaType is compatible with Color Type. Returns true unless alphaType is kUnknown SkAlphaType and current Alpha Type is not kUnknown SkAlphaType.

Returns true if Color Type is kUnknown SkColorType. alphaType is ignored, and Alpha Type remains kUnknown SkAlphaType.

Returns true if Color Type is kRGB 565 SkColorType or kGray 8 SkColorType. alphaType is ignored, and Alpha Type remains kOpaque SkAlphaType.

If Color Type is kARGB 4444 SkColorType, kRGBA 8888 SkColorType, kBGRA 8888 SkColorType, or kRGBA F16 SkColorType: returns true unless alphaType is kUnknown SkAlphaType and Alpha Type is not kUnknown SkAlphaType. If Alpha Type is kUnknown SkAlphaType, alphaType is ignored.

If Color Type is kAlpha 8 SkColorType, returns true unless alphaType is kUnknown SkAlphaType and Alpha Type is not kUnknown SkAlphaType. If Alpha Type is kUnknown SkAlphaType, alphaType is ignored. If alphaType is kUnpremul SkAlphaType, it is treated as kPremul SkAlphaType.

This changes Alpha Type in Pixel Ref; all bitmaps sharing Pixel Ref are affected.

Parameters

alphaType one of: kUnknown SkAlphaType, kOpaque SkAlphaType, kPremul SkAlphaType, kUnpremul SkAlphaType

Return Value

true if Alpha Type is set

Example

See Also

Alpha Type Color Type Image Info setInfo


getPixels

void* getPixels() const

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

Return Value

pixel address

Example

Example Output

bitmap.getColor(0, 1) == 0x00000000
bitmap.getColor(0, 0) == 0xFFFFFFFF

See Also

isNull drawsNothing


computeByteSize

size_t computeByteSize() const

Returns minimum memory required for pixel storage. Does not include unused memory on last row when rowBytesAsPixels exceeds width. Returns zero 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.

Return Value

size in bytes of image buffer

Example

Example Output

width:       1 height:       1 computeByteSize:             4
width:       1 height:    1000 computeByteSize:          4999
width:       1 height: 1000000 computeByteSize:       4999999
width:    1000 height:       1 computeByteSize:          4000
width:    1000 height:    1000 computeByteSize:       4999000
width:    1000 height: 1000000 computeByteSize:    4999999000
width: 1000000 height:       1 computeByteSize:       4000000
width: 1000000 height:    1000 computeByteSize:    4999000000
width: 1000000 height: 1000000 computeByteSize: 4999999000000

See Also

SkImageInfo::computeByteSize


isImmutable

bool isImmutable() const

Returns true if pixels can not change.

Most immutable Bitmap checks trigger an assert only on debug builds.

Return Value

true if pixels are immutable

Example

Example Output

original is immutable
copy is immutable

See Also

setImmutable SkPixelRef::isImmutable SkImage


setImmutable

void setImmutable()

Sets internal flag to mark Bitmap as immutable. Once set, pixels can not change. Any other bitmap sharing the same Pixel Ref are also marked as immutable. Once Pixel Ref is marked immutable, the setting cannot be cleared.

Writing to immutable Bitmap pixels triggers an assert on debug builds.

Example

Triggers assert if SK_DEBUG is true, runs fine otherwise.

See Also

isImmutable SkPixelRef::setImmutable SkImage


isOpaque

bool isOpaque() const

Returns true if Alpha Type is kOpaque SkAlphaType. Does not check if Color Type allows Alpha, or if any pixel value has transparency.

Return Value

true if Image Info describes opaque Alpha

Example

isOpaque ignores whether all pixels are opaque or not.

Example Output

isOpaque: false
isOpaque: false
isOpaque: true
isOpaque: true

See Also

ComputeIsOpaque SkImageInfo::isOpaque


isVolatile

bool isVolatile() const

If true, provides a hint to caller that pixels should not be cached. Only true if setIsVolatile has been called to mark as volatile.

Volatile state is not shared by other bitmaps sharing the same Pixel Ref.

Return Value

true if marked volatile

Example

Example Output

original is volatile
copy is not volatile

See Also

setIsVolatile


setIsVolatile

void setIsVolatile(bool isVolatile)

Sets if pixels should be read from Pixel Ref on every access. Bitmaps are not volatile by default; a GPU back end may upload pixel values expecting them to be accessed repeatedly. Marking temporary Bitmaps as volatile provides a hint to Device that the Bitmap pixels should not be cached. This can improve performance by avoiding overhead and reducing resource consumption on Device.

Parameters

isVolatile true if backing pixels are temporary

Example

See Also

isVolatile


reset

void reset()

Resets to its initial state; all fields are set to zero, as if Bitmap had been initialized by SkBitmap().

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

If Pixel Ref is allocated, its reference count is decreased by one, releasing its memory if Bitmap is the sole owner.

Example

Example Output

width:1 height:1 isNull:false
width:0 height:0 isNull:true

See Also

SkBitmap() SkAlphaType SkColorType


ComputeIsOpaque

static bool ComputeIsOpaque(const SkBitmap& bm)

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

For Color Types kRGB 565 SkColorType or kGray 8 SkColorType: always returns true. For Color Types kAlpha 8 SkColorType, kBGRA 8888 SkColorType, kRGBA 8888 SkColorType: returns true if all pixel Alpha values are 255. For Color Type 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.

Parameters

bm Bitmap to check

Return Value

true if all pixels have opaque values or Color Type is opaque

Example

Example Output

computeIsOpaque: false
computeIsOpaque: true
computeIsOpaque: false
computeIsOpaque: true

See Also

isOpaque Color Type Alpha


getBounds

void getBounds(SkRect* bounds) const

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

Parameters

bounds container for floating point rectangle

Example

See Also

bounds


void getBounds(SkIRect* bounds) const

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

Parameters

bounds container for integral rectangle

Example

See Also

bounds


bounds

SkIRect bounds() const

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

Return Value

integral rectangle from origin to width and height

Example

See Also

getBounds


dimensions

SkISize dimensions() const

Returns ISize { width, height }.

Return Value

integral size of width and height

Example

See Also

height width


getSubset

SkIRect getSubset() const

Returns the bounds of this bitmap, offset by its Pixel Ref origin.

Return Value

bounds within Pixel Ref bounds

Example

Example Output

source: 0, 0, 512, 512
subset: 100, 100, 412, 412

See Also

extractSubset getBounds


setInfo

bool setInfo(const SkImageInfo& imageInfo, size_t rowBytes = 0)

Sets width, height, Alpha Type, Color Type, Color Space, and optional rowBytes. Frees pixels, and returns true if successful.

imageInfo.alphaType may be altered to a value permitted by imageInfo.colorSpace. If imageInfo.colorType is kUnknown SkColorType, imageInfo.alphaType is set to kUnknown SkAlphaType. If imageInfo.colorType is kAlpha 8 SkColorType and imageInfo.alphaType is kUnpremul SkAlphaType, imageInfo.alphaType is replaced by kPremul SkAlphaType. If imageInfo.colorType is kRGB 565 SkColorType or kGray 8 SkColorType, imageInfo.alphaType is set to kOpaque SkAlphaType. If imageInfo.colorType is kARGB 4444 SkColorType, kRGBA 8888 SkColorType, kBGRA 8888 SkColorType, or kRGBA F16 SkColorType: imageInfo.alphaType remains unchanged.

rowBytes must equal or exceed imageInfo.minRowBytes. If imageInfo.colorSpace is kUnknown SkColorType, rowBytes is ignored and treated as zero; for all other Color Space values, rowBytes of zero is treated as imageInfo.minRowBytes.

Calls reset and returns false if:

rowBytes exceeds 31 bits
imageInfo.width is negative
imageInfo.height is negative
rowBytes is positive and less than imageInfo.width times imageInfo.bytesPerPixel

Parameters

imageInfo contains width, height, Alpha Type, Color Type, Color Space
rowBytes imageInfo.minRowBytes or larger; or zero

Return Value

true if Image Info set successfully

Example

See Also

Alpha Type Color Type Color Space height rowBytes width


Enum SkBitmap::AllocFlags

enum AllocFlags {
kZeroPixels AllocFlag = 1 << 0,
};

AllocFlags provides the option to zero pixel memory when allocated.

Constants

SkBitmap::kZeroPixels_AllocFlag 1Instructs tryAllocPixelsFlags and allocPixelsFlags to zero pixel memory.

See Also

tryAllocPixelsFlags allocPixelsFlags erase eraseColor

tryAllocPixelsFlags

bool SK_WARN_UNUSED_RESULT tryAllocPixelsFlags(const SkImageInfo& info, uint32_t flags)

Sets Image Info to info following the rules in setInfo and allocates pixel memory. If flags is kZeroPixels AllocFlag, memory is zeroed.

Returns false and calls reset if Image Info could not be set, or memory could not be allocated, or memory could not optionally be zeroed.

On most platforms, allocating pixel memory may succeed even though there is not sufficient memory to hold pixels; allocation does not take place until the pixels are written to. The actual behavior depends on the platform implementation of malloc(), if flags is zero, and calloc(), if flags is kZeroPixels AllocFlag.

Passing kZeroPixels AllocFlag is usually faster than separately calling

Parameters

info contains width, height, Alpha Type, Color Type, Color Space
flags kZeroPixels AllocFlag, or zero

Return Value

true if pixels allocation is successful

Example

Example Output

bitmap allocation succeeded!

See Also

allocPixelsFlags tryAllocPixels SkMallocPixelRef::MakeZeroed


allocPixelsFlags

void allocPixelsFlags(const SkImageInfo& info, uint32_t flags)

Sets Image Info to info following the rules in setInfo and allocates pixel memory. If flags is kZeroPixels AllocFlag, memory is zeroed.

Aborts execution if Image Info could not be set, or memory could not be allocated, or memory could not optionally be zeroed. Abort steps may be provided by the user at compile time by defining SK_ABORT.

On most platforms, allocating pixel memory may succeed even though there is not sufficient memory to hold pixels; allocation does not take place until the pixels are written to. The actual behavior depends on the platform implementation of malloc(), if flags is zero, and calloc(), if flags is kZeroPixels AllocFlag.

Passing kZeroPixels AllocFlag is usually faster than separately calling

Parameters

info contains width, height, Alpha Type, Color Type, Color Space
flags kZeroPixels AllocFlag, or zero

Example

Text is drawn on a transparent background; drawing the bitmap a second time lets the first draw show through.

See Also

tryAllocPixelsFlags allocPixels SkMallocPixelRef::MakeZeroed


tryAllocPixels

bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo& info, size_t rowBytes)

Sets Image Info to info following the rules in setInfo and allocates pixel memory. rowBytes must equal or exceed info.width times info.bytesPerPixel, or equal zero. Pass in zero for rowBytes to compute the minimum valid value.

Returns false and calls reset if Image Info could not be set, or memory could not be allocated.

On most platforms, allocating pixel memory may succeed even though there is not sufficient memory to hold pixels; allocation does not take place until the pixels are written to. The actual behavior depends on the platform implementation of malloc().

Parameters

info contains width, height, Alpha Type, Color Type, Color Space
rowBytes size of pixel row or larger; may be zero

Return Value

true if pixel storage is allocated

Example

See Also

tryAllocPixelsFlags allocPixels SkMallocPixelRef::MakeAllocate


allocPixels

void allocPixels(const SkImageInfo& info, size_t rowBytes)

Sets Image Info to info following the rules in setInfo and allocates pixel memory. rowBytes must equal or exceed info.width times info.bytesPerPixel, or equal zero. Pass in zero for rowBytes to compute the minimum valid value.

Aborts execution if Image Info could not be set, or memory could not be allocated. Abort steps may be provided by the user at compile time by defining SK_ABORT.

On most platforms, allocating pixel memory may succeed even though there is not sufficient memory to hold pixels; allocation does not take place until the pixels are written to. The actual behavior depends on the platform implementation of malloc().

Parameters

info contains width, height, Alpha Type, Color Type, Color Space
rowBytes size of pixel row or larger; may be zero

Example

See Also

tryAllocPixels allocPixelsFlags SkMallocPixelRef::MakeAllocate


bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo& info)

Sets Image Info to info following the rules in setInfo and allocates pixel memory.

Returns false and calls reset if Image Info could not be set, or memory could not be allocated.

On most platforms, allocating pixel memory may succeed even though there is not sufficient memory to hold pixels; allocation does not take place until the pixels are written to. The actual behavior depends on the platform implementation of malloc().

Parameters

info contains width, height, Alpha Type, Color Type, Color Space

Return Value

true if pixel storage is allocated

Example

See Also

tryAllocPixelsFlags allocPixels SkMallocPixelRef::MakeAllocate


void allocPixels(const SkImageInfo& info)

Sets Image Info to info following the rules in setInfo and allocates pixel memory.

Aborts execution if Image Info could not be set, or memory could not be allocated. Abort steps may be provided by the user at compile time by defining SK_ABORT.

On most platforms, allocating pixel memory may succeed even though there is not sufficient memory to hold pixels; allocation does not take place until the pixels are written to. The actual behavior depends on the platform implementation of malloc().

Parameters

info contains width, height, Alpha Type, Color Type, Color Space

Example

See Also

tryAllocPixels allocPixelsFlags SkMallocPixelRef::MakeAllocate


tryAllocN32Pixels

bool SK_WARN_UNUSED_RESULT tryAllocN32Pixels(int width, int height, bool isOpaque = false)

Sets Image Info to width, height, and Native Color Type; and allocates pixel memory. If isOpaque is true, sets Image Info to kOpaque SkAlphaType; otherwise, sets to kPremul SkAlphaType.

Calls reset and returns false if width exceeds 29 bits or is negative, or height is negative.

Returns false if allocation fails.

Use to create Bitmap that matches SkPMColor, the native pixel arrangement on the platform. Bitmap drawn to output device skips converting its pixel format.

Parameters

width pixel column count; must be zero or greater
height pixel row count; must be zero or greater
isOpaque true if pixels do not have transparency

Return Value

true if pixel storage is allocated

Example

See Also

tryAllocPixels allocN32Pixels SkMallocPixelRef::MakeAllocate


allocN32Pixels

void allocN32Pixels(int width, int height, bool isOpaque = false)

Sets Image Info to width, height, and the Native Color Type; and allocates pixel memory. If isOpaque is true, sets Image Info to kPremul SkAlphaType; otherwise, sets to kOpaque SkAlphaType.

Aborts if width exceeds 29 bits or is negative, or height is negative, or allocation fails. Abort steps may be provided by the user at compile time by defining SK_ABORT.

Use to create Bitmap that matches SkPMColor, the native pixel arrangement on the platform. Bitmap drawn to output device skips converting its pixel format.

Parameters

width pixel column count; must be zero or greater
height pixel row count; must be zero or greater
isOpaque true if pixels do not have transparency

Example

See Also

allocPixels tryAllocN32Pixels SkMallocPixelRef::MakeAllocate


installPixels

bool installPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, void (*releaseProc)
                   (void* addr, void* context) , void* context)

Sets Image Info to info following the rules in setInfo, and creates Pixel Ref containing pixels and rowBytes. releaseProc, if not nullptr, is called immediately on failure or when pixels are no longer referenced. context may be nullptr.

If Image Info could not be set, or rowBytes is less than info.minRowBytes: calls releaseProc if present, calls reset, and returns false.

Otherwise, if pixels equals nullptr: sets Image Info, calls releaseProc if present, returns true.

If Image Info is set, pixels is not nullptr, and releaseProc is not nullptr: when pixels are no longer referenced, calls releaseProc with pixels and context as parameters.

Parameters

info contains width, height, Alpha Type, Color Type, Color Space
pixels address or pixel storage; may be nullptr
rowBytes size of pixel row or larger
releaseProc function called when pixels can be deleted; may be nullptr
context caller state passed to releaseProc; may be nullptr

Return Value

true if Image Info is set to info

Example

releaseProc is called immediately because rowBytes is too small for Pixel Ref.

Example Output

before installPixels
releaseProc called
install not successful

See Also

allocPixels


bool installPixels(const SkImageInfo& info, void* pixels, size_t rowBytes)

Sets Image Info to info following the rules in setInfo, and creates Pixel Ref containing pixels and rowBytes.

If Image Info could not be set, or rowBytes is less than info.minRowBytes: calls reset, and returns false.

Otherwise, if pixels equals nullptr: sets Image Info, returns true.

Caller must ensure that pixels are valid for the lifetime of Bitmap and Pixel Ref.

Parameters

info contains width, height, Alpha Type, Color Type, Color Space
pixels address or pixel storage; may be nullptr
rowBytes size of pixel row or larger

Return Value

true if Image Info is set to info

Example

GPU does not support kUnpremul SkAlphaType, does not assert that it does not.

See Also

allocPixels


bool installPixels(const SkPixmap& pixmap)

Sets Image Info to pixmap.info following the rules in setInfo, and creates Pixel Ref containing pixmap.addr() and pixmap.rowBytes.

If Image Info could not be set, or pixmap.rowBytes is less than SkImageInfo::minRowBytes: calls reset, and returns false.

Otherwise, if pixmap.addr() equals nullptr: sets Image Info, returns true.

Caller must ensure that pixmap is valid for the lifetime of Bitmap and Pixel Ref.

Parameters

pixmap Image Info, pixel address, and rowBytes

Return Value

true if Image Info was set to pixmap.info

Example

Draw a five by five bitmap, and draw it again with a center white pixel.

See Also

allocPixels


installMaskPixels

bool installMaskPixels(const SkMask& mask)

Sets Image Info to mask width, mask height, kAlpha 8 SkColorType, and kPremul SkAlphaType. Sets Pixel Ref to mask image and mask rowBytes.

Returns false and calls reset if mask format is not SkMask::kA8 Format, or if mask width or mask height is negative, or if mask rowBytes is less than mask width.

Caller must ensure that mask is valid for the lifetime of Bitmap and Pixel Ref.

Parameters

mask Alpha 8-bit bitmap

Return Value

true if Image Info and Pixel Ref refer to mask

Example

Draw a five by five bitmap, and draw it again with a center white pixel.

See Also

installPixels allocPixels


setPixels

void setPixels(void* pixels)

Replaces Pixel Ref with pixels, preserving Image Info and rowBytes. Sets Pixel Ref origin to (0, 0).

If pixels is nullptr, or if info.colorType equals kUnknown SkColorType; release reference to Pixel Ref, and set Pixel Ref to nullptr.

Caller is responsible for handling ownership pixel memory for the lifetime of Bitmap and Pixel Ref.

Parameters

pixels address of pixel storage, managed by caller

Example

See Also

installPixels allocPixels


bool SK_WARN_UNUSED_RESULT tryAllocPixels()

Allocates pixel memory with HeapAllocator, and replaces existing Pixel Ref. The allocation size is determined by Image Info width, height, and Color Type.

Returns false if info.colorType is kUnknown SkColorType, or allocation fails.

Return Value

true if the allocation succeeds

Example

Bitmap hosts and draws gray values in set1. tryAllocPixels replaces Pixel Ref and erases it to black, but does not alter set1. setPixels replaces black Pixel Ref with set1.

See Also

allocPixels installPixels setPixels


void allocPixels()

Allocates pixel memory with HeapAllocator, and replaces existing Pixel Ref. The allocation size is determined by Image Info width, height, and Color Type.

Aborts if info.colorType is kUnknown SkColorType, or allocation fails. Abort steps may be provided by the user at compile time by defining SK_ABORT.

Example

Bitmap hosts and draws gray values in set1. allocPixels replaces Pixel Ref and erases it to black, but does not alter set1. setPixels replaces black Pixel Ref with set2.

See Also

tryAllocPixels installPixels setPixels


bool SK_WARN_UNUSED_RESULT tryAllocPixels(Allocator* allocator)

Allocates pixel memory with allocator, and replaces existing Pixel Ref. The allocation size is determined by Image Info width, height, and Color Type. If allocator is nullptr, use HeapAllocator instead.

Returns false if allocator allocPixelRef return false.

Parameters

allocator instance of SkBitmap::Allocator instantiation

Return Value

true if custom allocator reports success

Example

HeapAllocator limits the maximum size of Bitmap to two gigabytes. Using a custom allocator, this limitation may be relaxed. This example can be modified to allocate an eight gigabyte Bitmap on a 64 bit platform with sufficient memory.

See Also

allocPixels Allocator Pixel Ref


void allocPixels(Allocator* allocator)

Allocates pixel memory with allocator, and replaces existing Pixel Ref. The allocation size is determined by Image Info width, height, and Color Type. If allocator is nullptr, use HeapAllocator instead.

Aborts if allocator allocPixelRef return false. Abort steps may be provided by the user at compile time by defining SK_ABORT.

Parameters

allocator instance of SkBitmap::Allocator instantiation

Example

See Also

allocPixels Allocator Pixel Ref


pixelRef

SkPixelRef* pixelRef() const

Returns Pixel Ref, which contains: pixel base address; its dimensions; and rowBytes, the interval from one row to the next. Does not change Pixel Ref reference count. Pixel Ref may be shared by multiple bitmaps. If Pixel Ref has not been set, returns nullptr.

Return Value

Pixel Ref, or nullptr

Example

See Also

getPixels getAddr


pixelRefOrigin

SkIPoint pixelRefOrigin() const

Returns origin of pixels within Pixel Ref. Bitmap bounds is always contained by Pixel Ref bounds, which may be the same size or larger. Multiple Bitmaps can share the same Pixel Ref, where each Bitmap has different bounds.

The returned origin added to Bitmap dimensions equals or is smaller than the Pixel Ref dimensions.

Returns (0, 0) if Pixel Ref is nullptr.

Return Value

pixel origin within Pixel Ref

Example

Example Output

source origin: 0, 0
subset origin: 32, 64

See Also

SkPixelRef getSubset setPixelRef


setPixelRef

void setPixelRef(sk_sp<SkPixelRef> pixelRef, int dx, int dy)

Replaces pixelRef and origin in Bitmap. dx and dy specify the offset within the Pixel Ref pixels for the top-left corner of the bitmap.

Asserts in debug builds if dx or dy are out of range. Pins dx and dy to legal range in release builds.

The caller is responsible for ensuring that the pixels match the Color Type and Alpha Type in Image Info.

Parameters

pixelRef Pixel Ref describing pixel address and rowBytes
dx column offset in Pixel Ref for bitmap origin
dy row offset in Pixel Ref for bitmap origin

Example

Treating 32 bit data as 8 bit data is unlikely to produce useful results.

See Also

setInfo


readyToDraw

bool readyToDraw() const

Returns true if Bitmap is can be drawn.

Return Value

true if getPixels is not nullptr

Example

See Also

getPixels drawsNothing


getGenerationID

uint32_t getGenerationID() const

Returns a unique value corresponding to the pixels in Pixel Ref. Returns a different value after notifyPixelsChanged has been called. Returns zero if Pixel Ref is nullptr.

Determines if pixels have changed since last examined.

Return Value

unique value for pixels in Pixel Ref

Example

Example Output

#Volatile
empty id 0
alloc id 4
erase id 6

See Also

notifyPixelsChanged Pixel Ref


notifyPixelsChanged

void notifyPixelsChanged() const

Marks that pixels in Pixel Ref have changed. Subsequent calls to getGenerationID return a different value.

Example

See Also

getGenerationID isVolatile Pixel Ref


eraseColor

void eraseColor(SkColor c) const

Replaces pixel values with c. All pixels contained by bounds are affected. If the colorType is kGray 8 SkColorType or k565_SkColorType, then Color Alpha is ignored; Color RGB is treated as opaque. If colorType is kAlpha 8 SkColorType, then Color RGB is ignored.

Parameters

c Unpremultiplied Color

Example

See Also

eraseARGB erase


eraseARGB

void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const

Replaces pixel values with Unpremultiplied Color built from a, r, g, and b. All pixels contained by bounds are affected. If the colorType is kGray 8 SkColorType or k565_SkColorType, then a is ignored; r, g, and b are treated as opaque. If colorType is kAlpha 8 SkColorType, then r, g, and b are ignored.

Parameters

a amount of Color Alpha, from fully transparent (0) to fully opaque (255)
r amount of Color RGB Red, from no red (0) to full red (255)
g amount of Color RGB Green, from no green (0) to full green (255)
b amount of Color RGB Blue, from no blue (0) to full blue (255)

Example

See Also

eraseColor erase


eraseRGB

void eraseRGB(U8CPU r, U8CPU g, U8CPU b) const

Deprecated. Use eraseARGB or eraseColor.

Parameters

r amount of red
g amount of green
b amount of blue

See Also

eraseColor eraseARGB erase


erase

void erase(SkColor c, const SkIRect& area) const

Replaces pixel values inside area with c. If area does not intersect bounds, call has no effect.

If the colorType is kGray 8 SkColorType or k565_SkColorType, then Color Alpha is ignored; Color RGB is treated as opaque. If colorType is kAlpha 8 SkColorType, then Color RGB is ignored.

Parameters

c Unpremultiplied Color
area rectangle to fill

Example

See Also

eraseColor eraseARGB eraseRGB SkCanvas::drawRect


eraseArea

void eraseArea(const SkIRect& area, SkColor c) const

Legacy call to be deprecated.


getColor

SkColor getColor(int x, int y) const

Returns pixel at (x, y) as Unpremultiplied Color. Returns black with Alpha if Color Type 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 Color Type is kUnknown SkColorType or pixel address is nullptr.

Color Space in Image Info is ignored. Some Color precision may be lost in the conversion to Unpremultiplied Color; original pixel data may have additional precision.

Parameters

x column index, zero or greater, and less than width
y row index, zero or greater, and less than height

Return Value

pixel converted to Unpremultiplied Color

Example

Example Output

Premultiplied:
(0, 0) 0x00000000 0x2a0e002a 0x55380055 0x7f7f007f
(0, 1) 0x2a000e2a 0x551c1c55 0x7f542a7f 0xaaaa38aa
(0, 2) 0x55003855 0x7f2a547f 0xaa7171aa 0xd4d48dd4
(0, 3) 0x7f007f7f 0xaa38aaaa 0xd48dd4d4 0xffffffff
Unpremultiplied:
(0, 0) 0x00000000 0x2a5500ff 0x55a800ff 0x7fff00ff
(0, 1) 0x2a0055ff 0x555454ff 0x7fa954ff 0xaaff54ff
(0, 2) 0x5500a8ff 0x7f54a9ff 0xaaaaaaff 0xd4ffaaff
(0, 3) 0x7f00ffff 0xaa54ffff 0xd4aaffff 0xffffffff

See Also

getAddr readPixels


getAddr

void* getAddr(int x, int y) const

Returns pixel address at (x, y).

Input is not validated: out of bounds values of x or y, or kUnknown SkColorType, trigger an assert() if built with SK_DEBUG defined. Returns nullptr if Color Type is kUnknown SkColorType, or Pixel Ref is nullptr.

Performs a lookup of pixel size; for better performance, call one of: getAddr8, getAddr16, or getAddr32.

Parameters

x column index, zero or greater, and less than width
y row index, zero or greater, and less than height

Return Value

generic pointer to pixel

Example

Example Output

addr interval == rowBytes

See Also

getAddr8 getAddr16 getAddr32 readPixels SkPixmap::addr


getAddr32

inline uint32_t* getAddr32(int x, int y) const

Returns address at (x, y).

Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:

Pixel Ref is nullptr
bytesPerPixel is not four
x is negative, or not less than width
y is negative, or not less than height

Parameters

x column index, zero or greater, and less than width
y row index, zero or greater, and less than height

Return Value

unsigned 32-bit pointer to pixel at (x, y)

Example

Example Output

addr interval == rowBytes

See Also

getAddr8 getAddr16 getAddr readPixels SkPixmap::addr32


getAddr16

inline uint16_t* getAddr16(int x, int y) const

Returns address at (x, y).

Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:

Pixel Ref is nullptr
bytesPerPixel is not two
x is negative, or not less than width
y is negative, or not less than height

Parameters

x column index, zero or greater, and less than width
y row index, zero or greater, and less than height

Return Value

unsigned 16-bit pointer to pixel at (x, y)

Example

Example Output

addr interval == rowBytes

See Also

getAddr8 getAddr getAddr32 readPixels SkPixmap::addr16


getAddr8

inline uint8_t* getAddr8(int x, int y) const

Returns address at (x, y).

Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:

Pixel Ref is nullptr
bytesPerPixel is not one
x is negative, or not less than width
y is negative, or not less than height

Parameters

x column index, zero or greater, and less than width
y row index, zero or greater, and less than height

Return Value

unsigned 8-bit pointer to pixel at (x, y)

Example

Example Output

&pixels[4][2] == bitmap.getAddr8(2, 4)

See Also

getAddr getAddr16 getAddr32 readPixels SkPixmap::addr8


extractSubset

bool extractSubset(SkBitmap* dst, const SkIRect& subset) const

Shares Pixel Ref with dst. Pixels are not copied; Bitmap and dst point to the same pixels; dst bounds are set to the intersection of subset and the original bounds.

subset may be larger than bounds. Any area outside of bounds is ignored.

Any contents of dst are discarded. isVolatile setting is copied to dst. dst is set to colorType, alphaType, and colorSpace.

Return false if:

dst is nullptr
Pixel Ref is nullptr
subset does not intersect bounds

Parameters

dst Bitmap set to subset
subset rectangle of pixels to reference

Return Value

true if dst is replaced by subset

Example

Example Output

bounds: 0, 0, 512, 512
subset: -100,  100,    0,  200  success; false
subset: -100,  100,  100,  200  success; true  subset: 0, 0, 100, 100
subset: -100,  100, 1000,  200  success; true  subset: 0, 0, 512, 100
subset:    0,  100,    0,  200  success; false
subset:    0,  100,  100,  200  success; true  subset: 0, 0, 100, 100
subset:    0,  100, 1000,  200  success; true  subset: 0, 0, 512, 100
subset:  100,  100,    0,  200  success; false
subset:  100,  100,  100,  200  success; false
subset:  100,  100, 1000,  200  success; true  subset: 0, 0, 412, 100
subset: 1000,  100,    0,  200  success; false
subset: 1000,  100,  100,  200  success; false
subset: 1000,  100, 1000,  200  success; false

See Also

readPixels writePixels SkCanvas::drawBitmap


readPixels

bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, int srcY,
                SkTransferFunctionBehavior behavior) const

Copies a Rect of pixels to dstPixels. Copy starts at (srcX, srcY), and does not exceed (this->width, this->height).

dstInfo specifies width, height, Color Type, Alpha Type, and Color Space of destination. dstRowBytes specifics the gap from one destination row to the next. Returns true if pixels are copied. Returns false if:

dstInfo.addr() equals nullptr
dstRowBytes is less than dstInfo.minRowBytes
Pixel Ref is nullptr

Pixels are copied only if pixel conversion is possible. If this->colorType is kGray 8 SkColorType, or kAlpha 8 SkColorType; dstInfo.colorType must match. If this->colorType is kGray 8 SkColorType, dstInfo.colorSpace must match. If this->alphaType is kOpaque SkAlphaType, dstInfo.alphaType must match. If this->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 width or height is zero or negative. Returns false ifabs(srcX) >= this->width, or ifabs(srcY) >= this->height.

If behavior is SkTransferFunctionBehavior::kRespect: converts source pixels to a linear space before converting to dstInfo. If behavior is SkTransferFunctionBehavior::kIgnore: source pixels are treated as if they are linear, regardless of how they are encoded.

Parameters

dstInfo destination width, height, Color Type, Alpha Type, Color Space
dstPixels destination pixel storage
dstRowBytes destination row length
srcX column index whose absolute value is less than width
srcY row index whose absolute value is less than height
behavior one of: SkTransferFunctionBehavior::kRespect, SkTransferFunctionBehavior::kIgnore

Return Value

true if pixels are copied to dstPixels

Example

See Also

writePixels SkPixmap::readPixels SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels


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

Copies a Rect of pixels to dstPixels. Copy starts at (srcX, srcY), and does not exceed (this->width, this->height).

dstInfo specifies width, height, Color Type, Alpha Type, and Color Space of destination. dstRowBytes specifics the gap from one destination row to the next. Returns true if pixels are copied. Returns false if:

dstInfo.addr() equals nullptr
dstRowBytes is less than dstInfo.minRowBytes
Pixel Ref is nullptr

Pixels are copied only if pixel conversion is possible. If this->colorType is kGray 8 SkColorType, or kAlpha 8 SkColorType; dstInfo.colorType must match. If this->colorType is kGray 8 SkColorType, dstInfo.colorSpace must match. If this->alphaType is kOpaque SkAlphaType, dstInfo.alphaType must match. If this->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 width or height is zero or negative. Returns false ifabs(srcX) >= this->width, or ifabs(srcY) >= this->height.

Parameters

dstInfo destination width, height, Color Type, Alpha Type, Color Space
dstPixels destination pixel storage
dstRowBytes destination row length
srcX column index whose absolute value is less than width
srcY row index whose absolute value is less than height

Return Value

true if pixels are copied to dstPixels

Example

Transferring the gradient from 8 bits per component to 4 bits per component creates visible banding.

See Also

writePixels SkPixmap::readPixels SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels


bool readPixels(const SkPixmap& dst, int srcX, int srcY) const

Copies a Rect of pixels to dst. Copy starts at (srcX, srcY), and does not exceed (this->width, this->height).

dst specifies width, height, Color Type, Alpha Type, Color Space, pixel storage, and row bytes of destination. dst.rowBytes specifics the gap from one destination row to the next. Returns true if pixels are copied. Returns false if:

dst pixel storage equals nullptr
dst.rowBytes is less than SkImageInfo::minRowBytes
Pixel Ref is nullptr

Pixels are copied only if pixel conversion is possible. If this->colorType is kGray 8 SkColorType, or kAlpha 8 SkColorType; dst Color Type must match. If this->colorType is kGray 8 SkColorType, dst Color Space must match. If this->alphaType is kOpaque SkAlphaType, dst Alpha Type must match. If this->colorSpace is nullptr, dst Color Space 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 width or height is zero or negative. Returns false ifabs(srcX) >= this->width, or ifabs(srcY) >= this->height.

Parameters

dst destination Pixmap: Image Info, pixels, row bytes
srcX column index whose absolute value is less than width
srcY row index whose absolute value is less than height

Return Value

true if pixels are copied to dst

Example

See Also

writePixels SkPixmap::readPixels SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels


bool readPixels(const SkPixmap& dst) const

Copies a Rect of pixels to dst. Copy starts at (0, 0), and does not exceed (this->width, this->height).

dst specifies width, height, Color Type, Alpha Type, Color Space, pixel storage, and row bytes of destination. dst.rowBytes specifics the gap from one destination row to the next. Returns true if pixels are copied. Returns false if:

dst pixel storage equals nullptr
dst.rowBytes is less than SkImageInfo::minRowBytes
Pixel Ref is nullptr

Pixels are copied only if pixel conversion is possible. If this->colorType is kGray 8 SkColorType, or kAlpha 8 SkColorType; dst Color Type must match. If this->colorType is kGray 8 SkColorType, dst Color Space must match. If this->alphaType is kOpaque SkAlphaType, dst Alpha Type must match. If this->colorSpace is nullptr, dst Color Space must match. Returns false if pixel conversion is not possible.

Parameters

dst destination Pixmap: Image Info, pixels, row bytes

Return Value

true if pixels are copied to dst

Example

See Also

writePixels SkPixmap::readPixels SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels


writePixels

bool writePixels(const SkPixmap& src, int dstX, int dstY)

Copies a Rect of pixels from src. Copy starts at (dstX, dstY), and does not exceed (src.width, src.height).

src specifies width, height, Color Type, Alpha Type, Color Space, pixel storage, and row bytes of source. src.rowBytes specifics the gap from one source row to the next. Returns true if pixels are copied. Returns false if:

src pixel storage equals nullptr
src.rowBytes is less than SkImageInfo::minRowBytes
Pixel Ref is nullptr

Pixels are copied only if pixel conversion is possible. If this->colorType is kGray 8 SkColorType, or kAlpha 8 SkColorType; src Color Type must match. If this->colorType is kGray 8 SkColorType, src Color Space must match. If this->alphaType is kOpaque SkAlphaType, src Alpha Type must match. If this->colorSpace is nullptr, src Color Space must match. Returns false if pixel conversion is not possible. dstX and dstY may be negative to copy only top or left of source. Returns false if width or height is zero or negative. Returns false ifabs(dstX) >= this->width, or ifabs(dstY) >= this->height.

Parameters

src source Pixmap: Image Info, pixels, row bytes
dstX column index whose absolute value is less than width
dstY row index whose absolute value is less than height

Return Value

true if src pixels are copied to Bitmap

Example

See Also

readPixels


bool writePixels(const SkPixmap& src)

Copies a Rect of pixels from src. Copy starts at (0, 0), and does not exceed (src.width, src.height).

src specifies width, height, Color Type, Alpha Type, Color Space, pixel storage, and row bytes of source. src.rowBytes specifics the gap from one source row to the next. Returns true if pixels are copied. Returns false if:

src pixel storage equals nullptr
src.rowBytes is less than SkImageInfo::minRowBytes
Pixel Ref is nullptr

Pixels are copied only if pixel conversion is possible. If this->colorType is kGray 8 SkColorType, or kAlpha 8 SkColorType; src Color Type must match. If this->colorType is kGray 8 SkColorType, src Color Space must match. If this->alphaType is kOpaque SkAlphaType, src Alpha Type must match. If this->colorSpace is nullptr, src Color Space must match. Returns false if pixel conversion is not possible.

Parameters

src source Pixmap: Image Info, pixels, row bytes

Return Value

true if src pixels are copied to Bitmap

Example

See Also

readPixels


bool writePixels(const SkPixmap& src, int x, int y, SkTransferFunctionBehavior behavior)

Copies a Rect of pixels from src. Copy starts at (0, 0), and does not exceed (src.width, src.height).

src specifies width, height, Color Type, Alpha Type, Color Space, pixel storage, and row bytes of source. src.rowBytes specifics the gap from one source row to the next. Returns true if pixels are copied. Returns false if:

src pixel storage equals nullptr
src.rowBytes is less than SkImageInfo::minRowBytes
Pixel Ref is nullptr

Pixels are copied only if pixel conversion is possible. If this->colorType is kGray 8 SkColorType, or kAlpha 8 SkColorType; src Color Type must match. If this->colorType is kGray 8 SkColorType, src Color Space must match. If this->alphaType is kOpaque SkAlphaType, src Alpha Type must match. If this->colorSpace is nullptr, src Color Space must match. Returns false if pixel conversion is not possible. Returns false if width or height is zero or negative.

If behavior is SkTransferFunctionBehavior::kRespect: converts src pixels to a linear space before converting to Image Info. If behavior is SkTransferFunctionBehavior::kIgnore: src pixels are treated as if they are linear, regardless of how they are encoded.

Parameters

src source Pixmap: Image Info, pixels, row bytes
x column index whose absolute value is less than width
y row index whose absolute value is less than height
behavior one of: SkTransferFunctionBehavior::kRespect, SkTransferFunctionBehavior::kIgnore

Return Value

true if src pixels are copied to Bitmap

Example

See Also

readPixels


hasHardwareMipMap

bool hasHardwareMipMap() const

Return Value

true if setHasHardwareMipMap has been called with true

See Also

setHasHardwareMipMap


setHasHardwareMipMap

void setHasHardwareMipMap(bool hasHardwareMipMap)

Parameters

hasHardwareMipMap sets state

See Also

hasHardwareMipMap


extractAlpha

bool extractAlpha(SkBitmap* dst) const

Sets dst to Alpha described by pixels. Returns false if dst cannot be written to or dst pixels cannot be allocated.

Uses HeapAllocator to reserve memory for dst Pixel Ref.

Parameters

dst holds Pixel Ref to fill with alpha layer

Return Value

true if Alpha layer was constructed in dst Pixel Ref

Example

See Also

extractSubset


bool extractAlpha(SkBitmap* dst, const SkPaint* paint, SkIPoint* offset) const

Sets dst to Alpha described by pixels. Returns false if dst cannot be written to or dst pixels cannot be allocated.

If paint is not nullptr and contains Mask Filter, SkMaskFilter::filterMask generates Mask Alpha from Bitmap. Uses HeapAllocator to reserve memory for dst Pixel Ref. Sets offset to top-left position for dst for alignment with Bitmap; (0, 0) unless SkMaskFilter generates mask.

Parameters

dst holds Pixel Ref to fill with alpha layer
paint holds optional Mask Filter; may be nullptr
offset top-left position for dst; may be nullptr

Return Value

true if Alpha layer was constructed in dst Pixel Ref

Example

See Also

extractSubset


bool extractAlpha(SkBitmap* dst, const SkPaint* paint, Allocator* allocator, SkIPoint* offset) const

Sets dst to Alpha described by pixels. Returns false if dst cannot be written to or dst pixels cannot be allocated.

If paint is not nullptr and contains Mask Filter, SkMaskFilter::filterMask generates Mask Alpha from Bitmap. allocator may reference a custom allocation class or be set to nullptr to use HeapAllocator. Sets offset to top-left position for dst for alignment with Bitmap; (0, 0) unless SkMaskFilter generates mask.

Parameters

dst holds Pixel Ref to fill with alpha layer
paint holds optional Mask Filter; may be nullptr
allocator method to reserve memory for Pixel Ref; may be nullptr
offset top-left position for dst; may be nullptr

Return Value

true if Alpha layer was constructed in dst Pixel Ref

Example

See Also

extractSubset


peekPixels

bool peekPixels(SkPixmap* pixmap) const

Copies Bitmap pixel address, row bytes, and Image Info to pixmap, if address is available, and returns true. If pixel address is not available, return false and leave pixmap unchanged.

pixmap contents become invalid on any future change to Bitmap.

Parameters

pixmap storage for pixel state if pixels are readable; otherwise, ignored

Return Value

true if Bitmap has direct access to pixels

Example

Example Output

------
-xxx--
x---x-
----x-
---x--
--x---
--x---
------
--x---
--x---
------

See Also

pixmap installPixels readPixels writePixels


validate

void validate() const;

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

See Also

SkImageInfo::validate()


toString

void toString(SkString* str) const;

Creates string representation. The representation is read by internal debugging tools. The interface and implementation may be suppressed by defining SK_IGNORE_TO_STRING.

Parameters

str storage for string representation

Example

Example Output

bitmap dimensions (6, 11)

See Also

SkPaint::toString