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 member functions. 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.
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.
SkBitmap global, struct, and class related member functions share a topic.
SkBitmap related constants are defined by enum, enum class, #define, const, and constexpr.
SkBitmap uses C++ classes to declare the public data structures and interfaces.
SkBitmap can be constructed or initialized by these functions, including C++ class constructors.
SkBitmap operators inline class member functions with arithmetic equivalents.
SkBitmap member functions read and modify the structure properties.
SkBitmap member functions read and modify the structure properties.
Abstract subclass of HeapAllocator.
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.
true if Pixel Ref was allocated
HeapAllocator
SkBitmap member functions read and modify the structure properties.
Subclass of SkBitmap::Allocator that returns a Pixel Ref that allocates its pixel memory from the heap. This is the default SkBitmap::Allocator invoked by allocPixels.
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.
true if pixels are allocated
#Volatile pixel address = (nil) pixel address = 0x560ddd0ac670
SkBitmap::Allocator tryAllocPixels[2][3][4]
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.
empty Bitmap
width: 0 height: 0 color: kUnknown_SkColorType alpha: kUnknown_SkAlphaType width: 25 height: 35 color: kRGBA_8888_SkColorType alpha: kOpaque_SkAlphaType
setInfo
Copies settings from src to returned Bitmap. Shares pixels if src has pixels allocated, so both bitmaps reference the same pixels.
copy of src
original has pixels before copy: true original has pixels after copy: true copy has pixels: true
setInfo setPixelRef setPixels swap
Copies settings from src to returned Bitmap. Moves ownership of src pixels to Bitmap.
copy of src
original has pixels before move: true original has pixels after move: false copy has pixels: true
setInfo setPixelRef setPixels swap
Decrements Pixel Ref reference count, if Pixel Ref is not nullptr.
Pixel Ref
Copies settings from src to returned Bitmap. Shares pixels if src has pixels allocated, so both bitmaps reference the same pixels.
copy of src
original has pixels before copy: true original has pixels after copy: true copy has pixels: true
setInfo setPixelRef setPixels swap
Copies settings from src to returned Bitmap. Moves ownership of src pixels to Bitmap.
copy of src
original has pixels before move: true original has pixels after move: false copy has pixels: true
setInfo setPixelRef setPixels swap
Swaps the fields of the two bitmaps.
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
SkBitmap(SkBitmap&& src) operator=(SkBitmap&& src)
Returns a constant reference to the Pixmap holding the Bitmap pixel address, row bytes, and Image Info.
reference to Pixmap describing this Bitmap
---------- ---xx----- --x--x---- --x------- --xx------ --x-x---x- -x---x--x- -x----xx-- -xx---x--- --xxxx-xx- ----------
peekPixels installPixels[2][3] readPixels[2][3][4] writePixels[2][3]
Returns width, height, Alpha Type, Color Type, and Color Space.
reference to Image Info
width: 56 height: 56 color: BGRA_8888 alpha: Opaque
Image Info
Returns pixel count in each row. Should be equal or less than:
rowBytes / info.bytesPerPixel.
May be less than pixelRef.width. Will not exceed pixelRef.width less pixelRefOrigin.fX.
pixel width in Image Info
bitmap width: 16 info width: 16
height SkPixelRef::width() SkImageInfo::width()
Returns pixel row count.
Maybe be less than pixelRef.height. Will not exceed pixelRef.height less pixelRefOrigin.fY.
pixel height in Image Info
bitmap height: 32 info height: 32
width SkPixelRef::height() SkImageInfo::height()
Returns Color Type, one of: kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, kGray_8_SkColorType, kRGBA_F16_SkColorType.
Color Type in Image Info
color type: kAlpha_8_SkColorType
alphaType SkImageInfo::colorType
Returns Alpha Type, one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType.
Alpha Type in Image Info
alpha type: kPremul_SkAlphaType
colorType SkImageInfo::alphaType
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.
Color Space in Image Info, or nullptr
gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
Color Space SkImageInfo::colorSpace
Returns 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.
Color Space in Image Info wrapped in a smart pointer
gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
Color Space SkImageInfo::colorSpace
Returns number of bytes per pixel required by Color Type. Returns zero if colorType( is kUnknown_SkColorType.
bytes in pixel
color: kUnknown_SkColorType bytesPerPixel: 0 color: kAlpha_8_SkColorType bytesPerPixel: 1 color: kRGB_565_SkColorType bytesPerPixel: 2 color: kARGB_4444_SkColorType bytesPerPixel: 2 color: kRGBA_8888_SkColorType bytesPerPixel: 4 color: kRGB_888x_SkColorType bytesPerPixel: 4 color: kBGRA_8888_SkColorType bytesPerPixel: 4 color: kRGBA_1010102_SkColorType bytesPerPixel: 4 color: kRGB_101010x_SkColorType bytesPerPixel: 4 color: kGray_8_SkColorType bytesPerPixel: 1 color: kRGBA_F16_SkColorType bytesPerPixel: 8
rowBytes rowBytesAsPixels width shiftPerPixel SkImageInfo::bytesPerPixel
Returns number of pixels that fit on row. Should be greater than or equal to width.
maximum pixels per row
rowBytes: 4 rowBytesAsPixels: 1 rowBytes: 5 rowBytesAsPixels: 1 rowBytes: 6 rowBytesAsPixels: 1 rowBytes: 7 rowBytesAsPixels: 1 rowBytes: 8 rowBytesAsPixels: 2
rowBytes shiftPerPixel width bytesPerPixel
Returns bit shift converting row bytes to row pixels. Returns zero for kUnknown_SkColorType.
one of: 0, 1, 2, 3; left shift to convert pixels to bytes
color: kUnknown_SkColorType shiftPerPixel: 0 color: kAlpha_8_SkColorType shiftPerPixel: 0 color: kRGB_565_SkColorType shiftPerPixel: 1 color: kARGB_4444_SkColorType shiftPerPixel: 1 color: kRGBA_8888_SkColorType shiftPerPixel: 2 color: kRGB_888x_SkColorType shiftPerPixel: 2 color: kBGRA_8888_SkColorType shiftPerPixel: 2 color: kRGBA_1010102_SkColorType shiftPerPixel: 2 color: kRGB_101010x_SkColorType shiftPerPixel: 2 color: kGray_8_SkColorType shiftPerPixel: 0 color: kRGBA_F16_SkColorType shiftPerPixel: 3
rowBytes rowBytesAsPixels width bytesPerPixel
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.
true if dimensions do not enclose area
width: 0 height: 0 empty: true width: 0 height: 2 empty: true width: 2 height: 0 empty: true width: 2 height: 2 empty: false
height width drawsNothing
Returns true if Pixel Ref is nullptr.
Does not check if width or height are zero; call drawsNothing to check width, height, and Pixel Ref.
true if no Pixel Ref is associated
empty bitmap does not have pixels bitmap with dimensions does not have pixels allocated bitmap does have pixels
empty drawsNothing pixelRef
Returns true if width or height are zero, or if Pixel Ref is nullptr. If true, Bitmap has no effect when drawn or drawn into.
true if drawing has no effect
empty:true isNull:true drawsNothing:true empty:true isNull:false drawsNothing:true empty:false isNull:true drawsNothing:true empty:false isNull:false drawsNothing:false
empty isNull pixelRef
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.
byte length of pixel row
setInfo returned:false rowBytes:0 setInfo returned:true rowBytes:8
info setInfo SkImageInfo::minRowBytes
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.
true if Alpha Type is set
Alpha Type Color Type Image Info setInfo
Returns pixel address, the base address corresponding to the pixel origin.
pixel address
bitmap.getColor(0, 1) == 0x00000000 bitmap.getColor(0, 0) == 0xFFFFFFFF
isNull drawsNothing
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.
size in bytes of image buffer
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
SkImageInfo::computeByteSize
Returns true if pixels can not change.
Most immutable Bitmap checks trigger an assert only on debug builds.
true if pixels are immutable
original is immutable copy is immutable
setImmutable SkPixelRef::isImmutable SkImage
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.
isImmutable SkPixelRef::setImmutable SkImage
Returns true if Alpha Type is set to hint that all pixels are opaque; their Color Alpha value is implicitly or explicitly 1.0. If true, and all pixels are not opaque, Skia may draw incorrectly.
Does not check if Color Type allows Alpha, or if any pixel value has transparency.
true if Image Info Alpha Type is kOpaque_SkAlphaType
isOpaque: false isOpaque: false isOpaque: true isOpaque: true
ComputeIsOpaque SkImageInfo::isOpaque
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.
true if marked volatile
original is volatile copy is not volatile
setIsVolatile
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.
isVolatile
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.
width:1 height:1 isNull:false width:0 height:0 isNull:true
SkBitmap() SkAlphaType SkColorType
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.
true if all pixels have opaque values or Color Type is opaque
computeIsOpaque: false computeIsOpaque: true computeIsOpaque: false computeIsOpaque: true
isOpaque Color Type Alpha
Returns Rect { 0, 0, width, height }.
bounds
Returns IRect { 0, 0, width, height }.
bounds
Returns IRect { 0, 0, width, height }.
integral rectangle from origin to width and height
getBounds[2]
Returns ISize { width, height }.
integral size of width and height
height width
Returns the bounds of this bitmap, offset by its Pixel Ref origin.
bounds within Pixel Ref bounds
source: 0, 0, 512, 512 subset: 100, 100, 412, 412
extractSubset getBounds[2]
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:
true if Image Info set successfully
Alpha Type Color Type Color Space height rowBytes width
AllocFlags provides the option to zero pixel memory when allocated.
tryAllocPixelsFlags allocPixelsFlags erase eraseColor
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.
flags set to kZeroPixels AllocFlag offers equal or better performance than subsequently calling eraseColor with SK ColorTRANSPARENT.
true if pixels allocation is successful
bitmap allocation succeeded!
allocPixelsFlags tryAllocPixels[2][3][4] SkMallocPixelRef::MakeZeroed
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.
flags set to kZeroPixels AllocFlag offers equal or better performance than subsequently calling eraseColor with SK ColorTRANSPARENT.
tryAllocPixelsFlags allocPixels[2][3][4] SkMallocPixelRef::MakeZeroed
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().
true if pixel storage is allocated
tryAllocPixelsFlags allocPixels[2][3][4] SkMallocPixelRef::MakeAllocate
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().
tryAllocPixels[2][3][4] allocPixelsFlags SkMallocPixelRef::MakeAllocate
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().
true if pixel storage is allocated
tryAllocPixelsFlags allocPixels[2][3][4] SkMallocPixelRef::MakeAllocate
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().
tryAllocPixels[2][3][4] allocPixelsFlags SkMallocPixelRef::MakeAllocate
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.
true if pixel storage is allocated
tryAllocPixels[2][3][4] allocN32Pixels SkMallocPixelRef::MakeAllocate
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.
allocPixels[2][3][4] tryAllocN32Pixels SkMallocPixelRef::MakeAllocate
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.
true if Image Info is set to info
before installPixels releaseProc called install not successful
allocPixels[2][3][4]
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.
true if Image Info is set to info
allocPixels[2][3][4]
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.
true if Image Info was set to pixmap.info
allocPixels[2][3][4]
Deprecated.
soon
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.
installPixels[2][3] allocPixels[2][3][4]
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.
true if the allocation succeeds
allocPixels[2][3][4] installPixels[2][3] setPixels
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.
tryAllocPixels[2][3][4] installPixels[2][3] setPixels
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.
true if custom allocator reports success
allocPixels[2][3][4] Allocator Pixel Ref
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.
allocPixels[2][3][4] Allocator Pixel Ref
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.
Pixel Ref, or nullptr
getPixels getAddr
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.
pixel origin within Pixel Ref
source origin: 0, 0 subset origin: 32, 64
SkPixelRef getSubset setPixelRef
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.
setInfo
Returns true if Bitmap is can be drawn.
true if getPixels is not nullptr
getPixels drawsNothing
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.
unique value for pixels in Pixel Ref
#Volatile empty id 0 alloc id 4 erase id 6
notifyPixelsChanged Pixel Ref
Marks that pixels in Pixel Ref have changed. Subsequent calls to getGenerationID return a different value.
getGenerationID isVolatile Pixel Ref
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; RGB is treated as opaque. If colorType is kAlpha_8_SkColorType, then RGB is ignored.
eraseARGB erase
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.
eraseColor erase
Deprecated.
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; RGB is treated as opaque. If colorType is kAlpha_8_SkColorType, then RGB is ignored.
eraseColor eraseARGB eraseRGB SkCanvas::drawRect
Deprecated.
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.
pixel converted to Unpremultiplied Color
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
getAddr readPixels[2][3][4]
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.
generic pointer to pixel
addr interval == rowBytes
getAddr8 getAddr16 getAddr32 readPixels[2][3][4] SkPixmap::addr[2]
Returns address at (x, y).
Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:
unsigned 32-bit pointer to pixel at (x, y)
addr interval == rowBytes
getAddr8 getAddr16 getAddr readPixels[2][3][4] SkPixmap::addr32[2]
Returns address at (x, y).
Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:
unsigned 16-bit pointer to pixel at (x, y)
addr interval == rowBytes
getAddr8 getAddr getAddr32 readPixels[2][3][4] SkPixmap::addr16[2]
Returns address at (x, y).
Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:
unsigned 8-bit pointer to pixel at (x, y)
&pixels[4][2] == bitmap.getAddr8(2, 4)
getAddr getAddr16 getAddr32 readPixels[2][3][4] SkPixmap::addr8[2]
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:
true if dst is replaced by subset
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
readPixels[2][3][4] writePixels[2][3] SkCanvas::drawBitmap
Copies Rect of pixels from Bitmap pixels to dstPixels. Copy starts at (srcX, srcY), and does not exceed Bitmap (width, 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:
Pixels are copied only if pixel conversion is possible. If Bitmap colorType is kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match. If Bitmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match. If Bitmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must match. If Bitmap 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) >= Bitmap width, or ifabs(srcY) >= Bitmap 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.
true if pixels are copied to dstPixels
writePixels[2][3] SkPixmap::readPixels[2][3][4][5] SkCanvas::readPixels[2][3] SkImage::readPixels[2] SkSurface::readPixels[2][3]
Copies a Rect of pixels from Bitmap to dstPixels. Copy starts at (srcX, srcY), and does not exceed Bitmap (width, 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:
Pixels are copied only if pixel conversion is possible. If Bitmap colorType is kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match. If Bitmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match. If Bitmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must match. If Bitmap 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) >= Bitmap width, or ifabs(srcY) >= Bitmap height.
true if pixels are copied to dstPixels
writePixels[2][3] SkPixmap::readPixels[2][3][4][5] SkCanvas::readPixels[2][3] SkImage::readPixels[2] SkSurface::readPixels[2][3]
Copies a Rect of pixels from Bitmap to dst. Copy starts at (srcX, srcY), and does not exceed Bitmap (width, 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:
Pixels are copied only if pixel conversion is possible. If Bitmap colorType is kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color Type must match. If Bitmap colorType is kGray_8_SkColorType, dst Color Space must match. If Bitmap alphaType is kOpaque_SkAlphaType, dst Alpha Type must match. If Bitmap 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) >= Bitmap width, or ifabs(srcY) >= Bitmap height.
true if pixels are copied to dst
writePixels[2][3] SkPixmap::readPixels[2][3][4][5] SkCanvas::readPixels[2][3] SkImage::readPixels[2] SkSurface::readPixels[2][3]
Copies a Rect of pixels from Bitmap to dst. Copy starts at (0, 0), and does not exceed Bitmap (width, 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:
Pixels are copied only if pixel conversion is possible. If Bitmap colorType is kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color Type must match. If Bitmap colorType is kGray_8_SkColorType, dst Color Space must match. If Bitmap alphaType is kOpaque_SkAlphaType, dst Alpha Type must match. If Bitmap colorSpace is nullptr, dst Color Space must match. Returns false if pixel conversion is not possible.
true if pixels are copied to dst
writePixels[2][3] SkPixmap::readPixels[2][3][4][5] SkCanvas::readPixels[2][3] SkImage::readPixels[2] SkSurface::readPixels[2][3]
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:
Pixels are copied only if pixel conversion is possible. If Bitmap colorType is kGray_8_SkColorType, or kAlpha_8_SkColorType; src Color Type must match. If Bitmap colorType is kGray_8_SkColorType, src Color Space must match. If Bitmap alphaType is kOpaque_SkAlphaType, src Alpha Type must match. If Bitmap 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) >= Bitmap width, or ifabs(dstY) >= Bitmap height.
true if src pixels are copied to Bitmap
readPixels[2][3][4]
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:
Pixels are copied only if pixel conversion is possible. If Bitmap colorType is kGray_8_SkColorType, or kAlpha_8_SkColorType; src Color Type must match. If Bitmap colorType is kGray_8_SkColorType, src Color Space must match. If Bitmap alphaType is kOpaque_SkAlphaType, src Alpha Type must match. If Bitmap colorSpace is nullptr, src Color Space must match. Returns false if pixel conversion is not possible.
true if src pixels are copied to Bitmap
readPixels[2][3][4]
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:
Pixels are copied only if pixel conversion is possible. If Bitmap colorType is kGray_8_SkColorType, or kAlpha_8_SkColorType; src Color Type must match. If Bitmap colorType is kGray_8_SkColorType, src Color Space must match. If Bitmap alphaType is kOpaque_SkAlphaType, src Alpha Type must match. If Bitmap 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.
true if src pixels are copied to Bitmap
readPixels[2][3][4]
For use by Android framework only.
true if setHasHardwareMipMap has been called with true
setHasHardwareMipMap
For use by Android framework only.
hasHardwareMipMap
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.
true if Alpha layer was constructed in dst Pixel Ref
extractSubset
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 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.
true if Alpha layer was constructed in dst Pixel Ref
extractSubset
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 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.
true if Alpha layer was constructed in dst Pixel Ref
extractSubset
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.
true if Bitmap has direct access to pixels
------ -xxx-- x---x- ----x- ---x-- --x--- --x--- ------ --x--- --x--- ------
pixmap installPixels[2][3] readPixels[2][3][4] writePixels[2][3]
Asserts if internal values are illegal or inconsistent. Only available if SK_DEBUG is defined at compile time.
SkImageInfo::validate