Skia
2D Graphics Library
|
SkBitmap describes a two-dimensional raster pixel array. More...
#include <SkBitmap.h>
Classes | |
class | HeapAllocator |
Subclass of SkBitmap::Allocator that returns a SkPixelRef that allocates its pixel memory from the heap. More... | |
Public Types | |
enum | AllocFlags { kZeroPixels_AllocFlag = 1 << 0 } |
Public Member Functions | |
SkBitmap () | |
Creates an empty SkBitmap without pixels, with kUnknown_SkColorType, kUnknown_SkAlphaType, and with a width and height of zero. More... | |
SkBitmap (const SkBitmap &src) | |
Copies settings from src to returned SkBitmap. More... | |
SkBitmap (SkBitmap &&src) | |
Copies settings from src to returned SkBitmap. More... | |
~SkBitmap () | |
Decrements SkPixelRef reference count, if SkPixelRef is not nullptr. More... | |
SkBitmap & | operator= (const SkBitmap &src) |
Copies settings from src to returned SkBitmap. More... | |
SkBitmap & | operator= (SkBitmap &&src) |
Copies settings from src to returned SkBitmap. More... | |
void | swap (SkBitmap &other) |
Swaps the fields of the two bitmaps. More... | |
const SkPixmap & | pixmap () const |
Returns a constant reference to the SkPixmap holding the SkBitmap pixel address, row bytes, and SkImageInfo. More... | |
const SkImageInfo & | info () const |
Returns width, height, SkAlphaType, SkColorType, and SkColorSpace. More... | |
int | width () const |
Returns pixel count in each row. More... | |
int | height () const |
Returns pixel row count. More... | |
SkColorType | colorType () const |
SkAlphaType | alphaType () const |
SkColorSpace * | colorSpace () const |
Returns SkColorSpace, the range of colors, associated with SkImageInfo. More... | |
sk_sp< SkColorSpace > | refColorSpace () const |
Returns smart pointer to SkColorSpace, the range of colors, associated with SkImageInfo. More... | |
int | bytesPerPixel () const |
Returns number of bytes per pixel required by SkColorType. More... | |
int | rowBytesAsPixels () const |
Returns number of pixels that fit on row. More... | |
int | shiftPerPixel () const |
Returns bit shift converting row bytes to row pixels. More... | |
bool | empty () const |
Returns true if either width() or height() are zero. More... | |
bool | isNull () const |
Returns true if SkPixelRef is nullptr. More... | |
bool | drawsNothing () const |
Returns true if width() or height() are zero, or if SkPixelRef is nullptr. More... | |
size_t | rowBytes () const |
Returns row bytes, the interval from one pixel row to the next. More... | |
bool | setAlphaType (SkAlphaType alphaType) |
Sets SkAlphaType, if alphaType is compatible with SkColorType. More... | |
void * | getPixels () const |
Returns pixel address, the base address corresponding to the pixel origin. More... | |
size_t | computeByteSize () const |
Returns minimum memory required for pixel storage. More... | |
bool | isImmutable () const |
Returns true if pixels can not change. More... | |
void | setImmutable () |
Sets internal flag to mark SkBitmap as immutable. More... | |
bool | isOpaque () const |
Returns true if SkAlphaType is set to hint that all pixels are opaque; their alpha value is implicitly or explicitly 1.0. More... | |
void | reset () |
Resets to its initial state; all fields are set to zero, as if SkBitmap had been initialized by SkBitmap(). More... | |
void | getBounds (SkRect *bounds) const |
Returns SkRect { 0, 0, width(), height() }. More... | |
void | getBounds (SkIRect *bounds) const |
Returns SkIRect { 0, 0, width(), height() }. More... | |
SkIRect | bounds () const |
Returns SkIRect { 0, 0, width(), height() }. More... | |
SkISize | dimensions () const |
Returns SkISize { width(), height() }. More... | |
SkIRect | getSubset () const |
Returns the bounds of this bitmap, offset by its SkPixelRef origin. More... | |
bool | setInfo (const SkImageInfo &imageInfo, size_t rowBytes=0) |
Sets width, height, SkAlphaType, SkColorType, SkColorSpace, and optional rowBytes. More... | |
bool | tryAllocPixelsFlags (const SkImageInfo &info, uint32_t flags) |
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel memory. More... | |
void | allocPixelsFlags (const SkImageInfo &info, uint32_t flags) |
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel memory. More... | |
bool | tryAllocPixels (const SkImageInfo &info, size_t rowBytes) |
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel memory. More... | |
void | allocPixels (const SkImageInfo &info, size_t rowBytes) |
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel memory. More... | |
bool | tryAllocPixels (const SkImageInfo &info) |
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel memory. More... | |
void | allocPixels (const SkImageInfo &info) |
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel memory. More... | |
bool | tryAllocN32Pixels (int width, int height, bool isOpaque=false) |
Sets SkImageInfo to width, height, and native color type; and allocates pixel memory. More... | |
void | allocN32Pixels (int width, int height, bool isOpaque=false) |
Sets SkImageInfo to width, height, and the native color type; and allocates pixel memory. More... | |
bool | installPixels (const SkImageInfo &info, void *pixels, size_t rowBytes, void(*releaseProc)(void *addr, void *context), void *context) |
Sets SkImageInfo to info following the rules in setInfo(), and creates SkPixelRef containing pixels and rowBytes. More... | |
bool | installPixels (const SkImageInfo &info, void *pixels, size_t rowBytes) |
Sets SkImageInfo to info following the rules in setInfo(), and creates SkPixelRef containing pixels and rowBytes. More... | |
bool | installPixels (const SkPixmap &pixmap) |
Sets SkImageInfo to pixmap.info() following the rules in setInfo(), and creates SkPixelRef containing pixmap.addr() and pixmap.rowBytes(). More... | |
bool | installMaskPixels (SkMaskBuilder &mask) |
Deprecated. More... | |
void | setPixels (void *pixels) |
Replaces SkPixelRef with pixels, preserving SkImageInfo and rowBytes(). More... | |
bool | tryAllocPixels () |
Allocates pixel memory with HeapAllocator, and replaces existing SkPixelRef. More... | |
void | allocPixels () |
Allocates pixel memory with HeapAllocator, and replaces existing SkPixelRef. More... | |
bool | tryAllocPixels (Allocator *allocator) |
Allocates pixel memory with allocator, and replaces existing SkPixelRef. More... | |
void | allocPixels (Allocator *allocator) |
Allocates pixel memory with allocator, and replaces existing SkPixelRef. More... | |
SkPixelRef * | pixelRef () const |
Returns SkPixelRef, which contains: pixel base address; its dimensions; and rowBytes(), the interval from one row to the next. More... | |
SkIPoint | pixelRefOrigin () const |
Returns origin of pixels within SkPixelRef. More... | |
void | setPixelRef (sk_sp< SkPixelRef > pixelRef, int dx, int dy) |
Replaces pixelRef and origin in SkBitmap. More... | |
bool | readyToDraw () const |
Returns true if SkBitmap is can be drawn. More... | |
uint32_t | getGenerationID () const |
Returns a unique value corresponding to the pixels in SkPixelRef. More... | |
void | notifyPixelsChanged () const |
Marks that pixels in SkPixelRef have changed. More... | |
void | eraseColor (SkColor4f) const |
Replaces pixel values with c, interpreted as being in the sRGB SkColorSpace. More... | |
void | eraseColor (SkColor c) const |
Replaces pixel values with c, interpreted as being in the sRGB SkColorSpace. More... | |
void | eraseARGB (U8CPU a, U8CPU r, U8CPU g, U8CPU b) const |
Replaces pixel values with unpremultiplied color built from a, r, g, and b, interpreted as being in the sRGB SkColorSpace. More... | |
void | erase (SkColor4f c, const SkIRect &area) const |
Replaces pixel values inside area with c. More... | |
void | erase (SkColor c, const SkIRect &area) const |
Replaces pixel values inside area with c. More... | |
void | eraseArea (const SkIRect &area, SkColor c) const |
Deprecated. More... | |
SkColor | getColor (int x, int y) const |
Returns pixel at (x, y) as unpremultiplied color. More... | |
SkColor4f | getColor4f (int x, int y) const |
Returns pixel at (x, y) as unpremultiplied float color. More... | |
float | getAlphaf (int x, int y) const |
Look up the pixel at (x,y) and return its alpha component, normalized to [0..1]. More... | |
void * | getAddr (int x, int y) const |
Returns pixel address at (x, y). More... | |
uint32_t * | getAddr32 (int x, int y) const |
Returns address at (x, y). More... | |
uint16_t * | getAddr16 (int x, int y) const |
Returns address at (x, y). More... | |
uint8_t * | getAddr8 (int x, int y) const |
Returns address at (x, y). More... | |
bool | extractSubset (SkBitmap *dst, const SkIRect &subset) const |
Shares SkPixelRef with dst. More... | |
bool | readPixels (const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY) const |
Copies a SkRect of pixels from SkBitmap to dstPixels. More... | |
bool | readPixels (const SkPixmap &dst, int srcX, int srcY) const |
Copies a SkRect of pixels from SkBitmap to dst. More... | |
bool | readPixels (const SkPixmap &dst) const |
Copies a SkRect of pixels from SkBitmap to dst. More... | |
bool | writePixels (const SkPixmap &src, int dstX, int dstY) |
Copies a SkRect of pixels from src. More... | |
bool | writePixels (const SkPixmap &src) |
Copies a SkRect of pixels from src. More... | |
bool | extractAlpha (SkBitmap *dst) const |
Sets dst to alpha described by pixels. More... | |
bool | extractAlpha (SkBitmap *dst, const SkPaint *paint, SkIPoint *offset) const |
Sets dst to alpha described by pixels. More... | |
bool | extractAlpha (SkBitmap *dst, const SkPaint *paint, Allocator *allocator, SkIPoint *offset) const |
Sets dst to alpha described by pixels. More... | |
bool | peekPixels (SkPixmap *pixmap) const |
Copies SkBitmap pixel address, row bytes, and SkImageInfo to pixmap, if address is available, and returns true. More... | |
sk_sp< SkShader > | makeShader (SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const |
Make a shader with the specified tiling, matrix and sampling. More... | |
sk_sp< SkShader > | makeShader (SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &sampling, const SkMatrix &lm) const |
sk_sp< SkShader > | makeShader (const SkSamplingOptions &sampling, const SkMatrix &lm) const |
Defaults to clamp in both X and Y. More... | |
sk_sp< SkShader > | makeShader (const SkSamplingOptions &sampling, const SkMatrix *lm=nullptr) const |
sk_sp< SkImage > | asImage () const |
Returns a new image from the bitmap. More... | |
Static Public Member Functions | |
static bool | ComputeIsOpaque (const SkBitmap &bm) |
Returns true if all pixels are opaque. More... | |
Public Attributes | |
class SK_API | Allocator |
Friends | |
class | SkImage_Raster |
class | SkReadBuffer |
class | GrProxyProvider |
SkBitmap describes a two-dimensional raster pixel array.
SkBitmap is built on SkImageInfo, containing integer width and height, SkColorType and SkAlphaType describing the pixel format, and SkColorSpace describing the range of colors. SkBitmap points to SkPixelRef, which describes the physical array of pixels. SkImageInfo bounds may be located anywhere fully inside SkPixelRef bounds.
SkBitmap can be drawn using SkCanvas. SkBitmap can be a drawing destination for SkCanvas draw member functions. SkBitmap flexibility as a pixel container limits some optimizations available to the target platform.
If pixel array is primarily read-only, use SkImage for better performance. If pixel array is primarily written to, use SkSurface for better performance.
Declaring SkBitmap const prevents altering SkImageInfo: the SkBitmap height, width, and so on cannot change. It does not affect SkPixelRef: a caller may write its pixels. Declaring SkBitmap const affects SkBitmap configuration, not its contents.
SkBitmap is not thread safe. Each thread must have its own copy of SkBitmap fields, although threads may share the underlying pixel array.
enum SkBitmap::AllocFlags |
SkBitmap::SkBitmap | ( | ) |
Creates an empty SkBitmap without pixels, with kUnknown_SkColorType, kUnknown_SkAlphaType, and with a width and height of zero.
SkPixelRef origin is set to (0, 0).
Use setInfo() to associate SkColorType, SkAlphaType, width, and height after SkBitmap has been created.
example: https://fiddle.skia.org/c/@Bitmap_empty_constructor
SkBitmap::SkBitmap | ( | const SkBitmap & | src | ) |
Copies settings from src to returned SkBitmap.
Shares pixels if src has pixels allocated, so both bitmaps reference the same pixels.
src | SkBitmap to copy SkImageInfo, and share SkPixelRef |
example: https://fiddle.skia.org/c/@Bitmap_copy_const_SkBitmap
SkBitmap::SkBitmap | ( | SkBitmap && | src | ) |
Copies settings from src to returned SkBitmap.
Moves ownership of src pixels to SkBitmap.
src | SkBitmap to copy SkImageInfo, and reassign SkPixelRef |
SkBitmap::~SkBitmap | ( | ) |
Decrements SkPixelRef reference count, if SkPixelRef is not nullptr.
void SkBitmap::allocN32Pixels | ( | int | width, |
int | height, | ||
bool | isOpaque = false |
||
) |
Sets SkImageInfo to width, height, and the native color type; and allocates pixel memory.
If isOpaque is true, sets SkImageInfo to kOpaque_SkAlphaType; otherwise, sets to kPremul_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 SkBitmap that matches SkPMColor, the native pixel arrangement on the platform. SkBitmap drawn to output device skips converting its pixel format.
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 |
void SkBitmap::allocPixels | ( | ) |
Allocates pixel memory with HeapAllocator, and replaces existing SkPixelRef.
The allocation size is determined by SkImageInfo width, height, and SkColorType.
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.
void SkBitmap::allocPixels | ( | Allocator * | allocator | ) |
Allocates pixel memory with allocator, and replaces existing SkPixelRef.
The allocation size is determined by SkImageInfo width, height, and SkColorType. 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.
allocator | instance of SkBitmap::Allocator instantiation |
void SkBitmap::allocPixels | ( | const SkImageInfo & | info | ) |
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel memory.
Aborts execution if SkImageInfo 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().
info | contains width, height, SkAlphaType, SkColorType, SkColorSpace |
void SkBitmap::allocPixels | ( | const SkImageInfo & | info, |
size_t | rowBytes | ||
) |
Sets SkImageInfo 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 SkImageInfo 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().
info | contains width, height, SkAlphaType, SkColorType, SkColorSpace |
rowBytes | size of pixel row or larger; may be zero |
void SkBitmap::allocPixelsFlags | ( | const SkImageInfo & | info, |
uint32_t | flags | ||
) |
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel memory.
Memory is zeroed.
Aborts execution if SkImageInfo 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 calloc().
info | contains width, height, SkAlphaType, SkColorType, SkColorSpace |
flags | kZeroPixels_AllocFlag, or zero |
|
inline |
Returns a new image from the bitmap.
If the bitmap is marked immutable, this will share the pixel buffer. If not, it will make a copy of the pixels for the image.
|
inline |
|
inline |
Returns number of bytes per pixel required by SkColorType.
Returns zero if colorType( is kUnknown_SkColorType.
SkColorSpace* SkBitmap::colorSpace | ( | ) | const |
Returns SkColorSpace, the range of colors, associated with SkImageInfo.
The reference count of SkColorSpace is unchanged. The returned SkColorSpace is immutable.
|
inline |
|
inline |
Returns minimum memory required for pixel storage.
Does not include unused memory on last row when rowBytesAsPixels() exceeds width(). Returns SIZE_MAX if result does not fit in size_t. Returns zero if height() or width() is 0. Returns height() times rowBytes() if colorType() is kUnknown_SkColorType.
|
inlinestatic |
Returns true if all pixels are opaque.
SkColorType determines how pixels are encoded, and whether pixel describes alpha. Returns true for SkColorType without alpha in each pixel; for other SkColorType, returns true if all pixels have alpha values equivalent to 1.0 or greater.
For SkColorType kRGB_565_SkColorType or kGray_8_SkColorType: always returns true. For SkColorType kAlpha_8_SkColorType, kBGRA_8888_SkColorType, kRGBA_8888_SkColorType: returns true if all pixel alpha values are 255. For SkColorType kARGB_4444_SkColorType: returns true if all pixel alpha values are 15. For kRGBA_F16_SkColorType: returns true if all pixel alpha values are 1.0 or greater.
Returns false for kUnknown_SkColorType.
bm | SkBitmap to check |
|
inline |
|
inline |
Returns true if width() or height() are zero, or if SkPixelRef is nullptr.
If true, SkBitmap has no effect when drawn or drawn into.
|
inline |
Returns true if either width() or height() are zero.
Does not check if SkPixelRef is nullptr; call drawsNothing() to check width(), height(), and SkPixelRef.
Replaces pixel values inside area with c.
interpreted as being in the sRGB SkColorSpace. If area does not intersect bounds(), call has no effect.
If the colorType() is kGray_8_SkColorType or kRGB_565_SkColorType, then alpha is ignored; RGB is treated as opaque. If colorType() is kAlpha_8_SkColorType, then RGB is ignored.
Input color is ultimately converted to an SkColor4f, so erase(SkColor4f c) will have higher color resolution.
c | unpremultiplied color |
area | rectangle to fill |
Replaces pixel values inside area with c.
interpreted as being in the sRGB SkColorSpace. If area does not intersect bounds(), call has no effect.
If the colorType() is kGray_8_SkColorType or kRGB_565_SkColorType, then alpha is ignored; RGB is treated as opaque. If colorType() is kAlpha_8_SkColorType, then RGB is ignored.
c | unpremultiplied color |
area | rectangle to fill |
|
inline |
Replaces pixel values with unpremultiplied color built from a, r, g, and b, interpreted as being in the sRGB SkColorSpace.
All pixels contained by bounds() are affected. If the colorType() is kGray_8_SkColorType or kRGB_565_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.
a | amount of alpha, from fully transparent (0) to fully opaque (255) |
r | amount of red, from no red (0) to full red (255) |
g | amount of green, from no green (0) to full green (255) |
b | amount of blue, from no blue (0) to full blue (255) |
void SkBitmap::eraseColor | ( | SkColor | c | ) | const |
Replaces pixel values with c, interpreted as being in the sRGB SkColorSpace.
All pixels contained by bounds() are affected. If the colorType() is kGray_8_SkColorType or kRGB_565_SkColorType, then alpha is ignored; RGB is treated as opaque. If colorType() is kAlpha_8_SkColorType, then RGB is ignored.
Input color is ultimately converted to an SkColor4f, so eraseColor(SkColor4f c) will have higher color resolution.
c | unpremultiplied color. |
void SkBitmap::eraseColor | ( | SkColor4f | ) | const |
Replaces pixel values with c, interpreted as being in the sRGB SkColorSpace.
All pixels contained by bounds() are affected. If the colorType() is kGray_8_SkColorType or kRGB_565_SkColorType, then alpha is ignored; RGB is treated as opaque. If colorType() is kAlpha_8_SkColorType, then RGB is ignored.
c | unpremultiplied color |
|
inline |
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 SkPixelRef.
dst | holds SkPixelRef to fill with alpha layer |
bool SkBitmap::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 SkMaskFilter, SkMaskFilter generates mask alpha from SkBitmap. 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 SkBitmap; (0, 0) unless SkMaskFilter generates mask.
dst | holds SkPixelRef to fill with alpha layer |
paint | holds optional SkMaskFilter; may be nullptr |
allocator | function to reserve memory for SkPixelRef; may be nullptr |
offset | top-left position for dst; may be nullptr |
|
inline |
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 SkMaskFilter, SkMaskFilter generates mask alpha from SkBitmap. Uses HeapAllocator to reserve memory for dst SkPixelRef. Sets offset to top-left position for dst for alignment with SkBitmap; (0, 0) unless SkMaskFilter generates mask.
dst | holds SkPixelRef to fill with alpha layer |
paint | holds optional SkMaskFilter; may be nullptr |
offset | top-left position for dst; may be nullptr |
Shares SkPixelRef with dst.
Pixels are not copied; SkBitmap 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.
Return false if:
dst | SkBitmap set to subset |
subset | rectangle of pixels to reference |
void* SkBitmap::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 SkColorType is kUnknown_SkColorType, or SkPixelRef is nullptr.
Performs a lookup of pixel size; for better performance, call one of: getAddr8(), getAddr16(), or getAddr32().
x | column index, zero or greater, and less than width() |
y | row index, zero or greater, and less than height() |
|
inline |
Returns address at (x, y).
Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:
x | column index, zero or greater, and less than width() |
y | row index, zero or greater, and less than height() |
|
inline |
Returns address at (x, y).
Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:
x | column index, zero or greater, and less than width() |
y | row index, zero or greater, and less than height() |
|
inline |
Returns address at (x, y).
Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:
x | column index, zero or greater, and less than width() |
y | row index, zero or greater, and less than height() |
|
inline |
Look up the pixel at (x,y) and return its alpha component, normalized to [0..1].
This is roughly equivalent to SkGetColorA(getColor()), but can be more efficent (and more precise if the pixels store more than 8 bits per component).
x | column index, zero or greater, and less than width() |
y | row index, zero or greater, and less than height() |
void SkBitmap::getBounds | ( | SkIRect * | bounds | ) | const |
void SkBitmap::getBounds | ( | SkRect * | bounds | ) | const |
|
inline |
Returns pixel at (x, y) as unpremultiplied color.
Returns black with alpha if SkColorType is kAlpha_8_SkColorType.
Input is not validated: out of bounds values of x or y trigger an assert() if built with SK_DEBUG defined; and returns undefined values or may crash if SK_RELEASE is defined. Fails if SkColorType is kUnknown_SkColorType or pixel address is nullptr.
SkColorSpace in SkImageInfo is ignored. Some color precision may be lost in the conversion to unpremultiplied color; original pixel data may have additional precision.
x | column index, zero or greater, and less than width() |
y | row index, zero or greater, and less than height() |
|
inline |
Returns pixel at (x, y) as unpremultiplied float color.
Returns black with alpha if SkColorType is kAlpha_8_SkColorType.
Input is not validated: out of bounds values of x or y trigger an assert() if built with SK_DEBUG defined; and returns undefined values or may crash if SK_RELEASE is defined. Fails if SkColorType is kUnknown_SkColorType or pixel address is nullptr.
SkColorSpace in SkImageInfo is ignored. Some color precision may be lost in the conversion to unpremultiplied color.
x | column index, zero or greater, and less than width() |
y | row index, zero or greater, and less than height() |
uint32_t SkBitmap::getGenerationID | ( | ) | const |
Returns a unique value corresponding to the pixels in SkPixelRef.
Returns a different value after notifyPixelsChanged() has been called. Returns zero if SkPixelRef is nullptr.
Determines if pixels have changed since last examined.
|
inline |
Returns pixel address, the base address corresponding to the pixel origin.
|
inline |
Returns the bounds of this bitmap, offset by its SkPixelRef origin.
|
inline |
Returns pixel row count.
Maybe be less than pixelRef().height(). Will not exceed pixelRef().height() less pixelRefOrigin().fY.
|
inline |
Returns width, height, SkAlphaType, SkColorType, and SkColorSpace.
bool SkBitmap::installMaskPixels | ( | SkMaskBuilder & | mask | ) |
Deprecated.
|
inline |
Sets SkImageInfo to info following the rules in setInfo(), and creates SkPixelRef containing pixels and rowBytes.
If SkImageInfo could not be set, or rowBytes is less than info.minRowBytes(): calls reset(), and returns false.
Otherwise, if pixels equals nullptr: sets SkImageInfo, returns true.
Caller must ensure that pixels are valid for the lifetime of SkBitmap and SkPixelRef.
info | contains width, height, SkAlphaType, SkColorType, SkColorSpace |
pixels | address or pixel storage; may be nullptr |
rowBytes | size of pixel row or larger |
bool SkBitmap::installPixels | ( | const SkImageInfo & | info, |
void * | pixels, | ||
size_t | rowBytes, | ||
void(*)(void *addr, void *context) | releaseProc, | ||
void * | context | ||
) |
Sets SkImageInfo to info following the rules in setInfo(), and creates SkPixelRef 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 SkImageInfo 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 SkImageInfo, calls releaseProc if present, returns true.
If SkImageInfo 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.
info | contains width, height, SkAlphaType, SkColorType, SkColorSpace |
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 |
bool SkBitmap::installPixels | ( | const SkPixmap & | pixmap | ) |
Sets SkImageInfo to pixmap.info() following the rules in setInfo(), and creates SkPixelRef containing pixmap.addr() and pixmap.rowBytes().
If SkImageInfo could not be set, or pixmap.rowBytes() is less than SkImageInfo::minRowBytes(): calls reset(), and returns false.
Otherwise, if pixmap.addr() equals nullptr: sets SkImageInfo, returns true.
Caller must ensure that pixmap is valid for the lifetime of SkBitmap and SkPixelRef.
pixmap | SkImageInfo, pixel address, and rowBytes() |
bool SkBitmap::isImmutable | ( | ) | const |
Returns true if pixels can not change.
Most immutable SkBitmap checks trigger an assert only on debug builds.
|
inline |
Returns true if SkPixelRef is nullptr.
Does not check if width() or height() are zero; call drawsNothing() to check width(), height(), and SkPixelRef.
|
inline |
Returns true if SkAlphaType is set to hint that all pixels are opaque; their alpha value is implicitly or explicitly 1.0.
If true, and all pixels are not opaque, Skia may draw incorrectly.
Does not check if SkColorType allows alpha, or if any pixel value has transparency.
sk_sp<SkShader> SkBitmap::makeShader | ( | const SkSamplingOptions & | sampling, |
const SkMatrix & | lm | ||
) | const |
Defaults to clamp in both X and Y.
sk_sp<SkShader> SkBitmap::makeShader | ( | const SkSamplingOptions & | sampling, |
const SkMatrix * | lm = nullptr |
||
) | const |
sk_sp<SkShader> SkBitmap::makeShader | ( | SkTileMode | tmx, |
SkTileMode | tmy, | ||
const SkSamplingOptions & | , | ||
const SkMatrix * | localMatrix = nullptr |
||
) | const |
Make a shader with the specified tiling, matrix and sampling.
sk_sp<SkShader> SkBitmap::makeShader | ( | SkTileMode | tmx, |
SkTileMode | tmy, | ||
const SkSamplingOptions & | sampling, | ||
const SkMatrix & | lm | ||
) | const |
void SkBitmap::notifyPixelsChanged | ( | ) | const |
Marks that pixels in SkPixelRef have changed.
Subsequent calls to getGenerationID() return a different value.
example: https://fiddle.skia.org/c/@Bitmap_notifyPixelsChanged
Copies settings from src to returned SkBitmap.
Shares pixels if src has pixels allocated, so both bitmaps reference the same pixels.
src | SkBitmap to copy SkImageInfo, and share SkPixelRef |
Copies settings from src to returned SkBitmap.
Moves ownership of src pixels to SkBitmap.
src | SkBitmap to copy SkImageInfo, and reassign SkPixelRef |
bool SkBitmap::peekPixels | ( | SkPixmap * | pixmap | ) | const |
Copies SkBitmap pixel address, row bytes, and SkImageInfo 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 SkBitmap.
pixmap | storage for pixel state if pixels are readable; otherwise, ignored |
|
inline |
Returns SkPixelRef, which contains: pixel base address; its dimensions; and rowBytes(), the interval from one row to the next.
Does not change SkPixelRef reference count. SkPixelRef may be shared by multiple bitmaps. If SkPixelRef has not been set, returns nullptr.
SkIPoint SkBitmap::pixelRefOrigin | ( | ) | const |
Returns origin of pixels within SkPixelRef.
SkBitmap bounds is always contained by SkPixelRef bounds, which may be the same size or larger. Multiple SkBitmap can share the same SkPixelRef, where each SkBitmap has different bounds.
The returned origin added to SkBitmap dimensions equals or is smaller than the SkPixelRef dimensions.
Returns (0, 0) if SkPixelRef is nullptr.
|
inline |
Returns a constant reference to the SkPixmap holding the SkBitmap pixel address, row bytes, and SkImageInfo.
bool SkBitmap::readPixels | ( | const SkImageInfo & | dstInfo, |
void * | dstPixels, | ||
size_t | dstRowBytes, | ||
int | srcX, | ||
int | srcY | ||
) | const |
Copies a SkRect of pixels from SkBitmap to dstPixels.
Copy starts at (srcX, srcY), and does not exceed SkBitmap (width(), height()).
dstInfo specifies width, height, SkColorType, SkAlphaType, and SkColorSpace of destination. dstRowBytes specifics the gap from one destination row to the next. Returns true if pixels are copied. Returns false if:
Pixels are copied only if pixel conversion is possible. If SkBitmap colorType() is kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match. If SkBitmap colorType() is kGray_8_SkColorType, dstInfo.colorSpace() must match. If SkBitmap alphaType() is kOpaque_SkAlphaType, dstInfo.alphaType() must match. If SkBitmap 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 if abs(srcX) >= Bitmap width(), or if abs(srcY) >= Bitmap height().
dstInfo | destination width, height, SkColorType, SkAlphaType, SkColorSpace |
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() |
|
inline |
Copies a SkRect of pixels from SkBitmap to dst.
Copy starts at (0, 0), and does not exceed SkBitmap (width(), height()).
dst specifies width, height, SkColorType, SkAlphaType, SkColorSpace, 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 SkBitmap colorType() is kGray_8_SkColorType, or kAlpha_8_SkColorType; dst SkColorType must match. If SkBitmap colorType() is kGray_8_SkColorType, dst SkColorSpace must match. If SkBitmap alphaType() is kOpaque_SkAlphaType, dst SkAlphaType must match. If SkBitmap colorSpace() is nullptr, dst SkColorSpace must match. Returns false if pixel conversion is not possible.
dst | destination SkPixmap: SkImageInfo, pixels, row bytes |
bool SkBitmap::readPixels | ( | const SkPixmap & | dst, |
int | srcX, | ||
int | srcY | ||
) | const |
Copies a SkRect of pixels from SkBitmap to dst.
Copy starts at (srcX, srcY), and does not exceed SkBitmap (width(), height()).
dst specifies width, height, SkColorType, SkAlphaType, SkColorSpace, 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 SkBitmap colorType() is kGray_8_SkColorType, or kAlpha_8_SkColorType; dst SkColorType must match. If SkBitmap colorType() is kGray_8_SkColorType, dst SkColorSpace must match. If SkBitmap alphaType() is kOpaque_SkAlphaType, dst SkAlphaType must match. If SkBitmap colorSpace() is nullptr, dst SkColorSpace 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 if abs(srcX) >= Bitmap width(), or if abs(srcY) >= Bitmap height().
dst | destination SkPixmap: SkImageInfo, pixels, row bytes |
srcX | column index whose absolute value is less than width() |
srcY | row index whose absolute value is less than height() |
|
inline |
Returns true if SkBitmap is can be drawn.
sk_sp<SkColorSpace> SkBitmap::refColorSpace | ( | ) | const |
Returns smart pointer to SkColorSpace, the range of colors, associated with SkImageInfo.
The smart pointer tracks the number of objects sharing this SkColorSpace reference so the memory is released when the owners destruct.
The returned SkColorSpace is immutable.
void SkBitmap::reset | ( | ) |
Resets to its initial state; all fields are set to zero, as if SkBitmap 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 SkPixelRef is allocated, its reference count is decreased by one, releasing its memory if SkBitmap is the sole owner.
|
inline |
Returns row bytes, the interval from one pixel row to the next.
Row bytes is at least as large as: width() * info().bytesPerPixel().
Returns zero if colorType() is kUnknown_SkColorType, or if row bytes supplied to setInfo() is not large enough to hold a row of pixels.
|
inline |
Returns number of pixels that fit on row.
Should be greater than or equal to width().
bool SkBitmap::setAlphaType | ( | SkAlphaType | alphaType | ) |
Sets SkAlphaType, if alphaType is compatible with SkColorType.
Returns true unless alphaType is kUnknown_SkAlphaType and current SkAlphaType is not kUnknown_SkAlphaType.
Returns true if SkColorType is kUnknown_SkColorType. alphaType is ignored, and SkAlphaType remains kUnknown_SkAlphaType.
Returns true if SkColorType is kRGB_565_SkColorType or kGray_8_SkColorType. alphaType is ignored, and SkAlphaType remains kOpaque_SkAlphaType.
If SkColorType is kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kBGRA_8888_SkColorType, or kRGBA_F16_SkColorType: returns true unless alphaType is kUnknown_SkAlphaType and SkAlphaType is not kUnknown_SkAlphaType. If SkAlphaType is kUnknown_SkAlphaType, alphaType is ignored.
If SkColorType is kAlpha_8_SkColorType, returns true unless alphaType is kUnknown_SkAlphaType and SkAlphaType is not kUnknown_SkAlphaType. If SkAlphaType is kUnknown_SkAlphaType, alphaType is ignored. If alphaType is kUnpremul_SkAlphaType, it is treated as kPremul_SkAlphaType.
This changes SkAlphaType in SkPixelRef; all bitmaps sharing SkPixelRef are affected.
void SkBitmap::setImmutable | ( | ) |
Sets internal flag to mark SkBitmap as immutable.
Once set, pixels can not change. Any other bitmap sharing the same SkPixelRef are also marked as immutable. Once SkPixelRef is marked immutable, the setting cannot be cleared.
Writing to immutable SkBitmap pixels triggers an assert on debug builds.
bool SkBitmap::setInfo | ( | const SkImageInfo & | imageInfo, |
size_t | rowBytes = 0 |
||
) |
Sets width, height, SkAlphaType, SkColorType, SkColorSpace, 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 SkColorSpace values, rowBytes of zero is treated as imageInfo.minRowBytes().
Calls reset() and returns false if:
imageInfo | contains width, height, SkAlphaType, SkColorType, SkColorSpace |
rowBytes | imageInfo.minRowBytes() or larger; or zero |
void SkBitmap::setPixelRef | ( | sk_sp< SkPixelRef > | pixelRef, |
int | dx, | ||
int | dy | ||
) |
Replaces pixelRef and origin in SkBitmap.
dx and dy specify the offset within the SkPixelRef 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 SkColorType and SkAlphaType in SkImageInfo.
pixelRef | SkPixelRef describing pixel address and rowBytes() |
dx | column offset in SkPixelRef for bitmap origin |
dy | row offset in SkPixelRef for bitmap origin |
void SkBitmap::setPixels | ( | void * | pixels | ) |
Replaces SkPixelRef with pixels, preserving SkImageInfo and rowBytes().
Sets SkPixelRef origin to (0, 0).
If pixels is nullptr, or if info().colorType() equals kUnknown_SkColorType; release reference to SkPixelRef, and set SkPixelRef to nullptr.
Caller is responsible for handling ownership pixel memory for the lifetime of SkBitmap and SkPixelRef.
pixels | address of pixel storage, managed by caller |
|
inline |
Returns bit shift converting row bytes to row pixels.
Returns zero for kUnknown_SkColorType.
void SkBitmap::swap | ( | SkBitmap & | other | ) |
Swaps the fields of the two bitmaps.
other | SkBitmap exchanged with original |
bool SkBitmap::tryAllocN32Pixels | ( | int | width, |
int | height, | ||
bool | isOpaque = false |
||
) |
Sets SkImageInfo to width, height, and native color type; and allocates pixel memory.
If isOpaque is true, sets SkImageInfo 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 SkBitmap that matches SkPMColor, the native pixel arrangement on the platform. SkBitmap drawn to output device skips converting its pixel format.
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 |
|
inline |
Allocates pixel memory with HeapAllocator, and replaces existing SkPixelRef.
The allocation size is determined by SkImageInfo width, height, and SkColorType.
Returns false if info().colorType() is kUnknown_SkColorType, or allocation fails.
bool SkBitmap::tryAllocPixels | ( | Allocator * | allocator | ) |
Allocates pixel memory with allocator, and replaces existing SkPixelRef.
The allocation size is determined by SkImageInfo width, height, and SkColorType. If allocator is nullptr, use HeapAllocator instead.
Returns false if Allocator::allocPixelRef return false.
allocator | instance of SkBitmap::Allocator instantiation |
|
inline |
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel memory.
Returns false and calls reset() if SkImageInfo 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().
info | contains width, height, SkAlphaType, SkColorType, SkColorSpace |
bool SkBitmap::tryAllocPixels | ( | const SkImageInfo & | info, |
size_t | rowBytes | ||
) |
Sets SkImageInfo 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 SkImageInfo 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().
info | contains width, height, SkAlphaType, SkColorType, SkColorSpace |
rowBytes | size of pixel row or larger; may be zero |
bool SkBitmap::tryAllocPixelsFlags | ( | const SkImageInfo & | info, |
uint32_t | flags | ||
) |
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel memory.
Memory is zeroed.
Returns false and calls reset() if SkImageInfo 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 calloc().
info | contains width, height, SkAlphaType, SkColorType, SkColorSpace |
flags | kZeroPixels_AllocFlag, or zero |
|
inline |
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.
|
inline |
Copies a SkRect of pixels from src.
Copy starts at (0, 0), and does not exceed (src.width(), src.height()).
src specifies width, height, SkColorType, SkAlphaType, SkColorSpace, 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 SkBitmap colorType() is kGray_8_SkColorType, or kAlpha_8_SkColorType; src SkColorType must match. If SkBitmap colorType() is kGray_8_SkColorType, src SkColorSpace must match. If SkBitmap alphaType() is kOpaque_SkAlphaType, src SkAlphaType must match. If SkBitmap colorSpace() is nullptr, src SkColorSpace must match. Returns false if pixel conversion is not possible.
src | source SkPixmap: SkImageInfo, pixels, row bytes |
bool SkBitmap::writePixels | ( | const SkPixmap & | src, |
int | dstX, | ||
int | dstY | ||
) |
Copies a SkRect of pixels from src.
Copy starts at (dstX, dstY), and does not exceed (src.width(), src.height()).
src specifies width, height, SkColorType, SkAlphaType, SkColorSpace, 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 SkBitmap colorType() is kGray_8_SkColorType, or kAlpha_8_SkColorType; src SkColorType must match. If SkBitmap colorType() is kGray_8_SkColorType, src SkColorSpace must match. If SkBitmap alphaType() is kOpaque_SkAlphaType, src SkAlphaType must match. If SkBitmap colorSpace() is nullptr, src SkColorSpace 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 if abs(dstX) >= Bitmap width(), or if abs(dstY) >= Bitmap height().
src | source SkPixmap: SkImageInfo, pixels, row bytes |
dstX | column index whose absolute value is less than width() |
dstY | row index whose absolute value is less than height() |
|
friend |
|
friend |
|
friend |
class SK_API SkBitmap::Allocator |