SkBitmap Reference
===
---
class SkBitmap {
public:
SkBitmap();
SkBitmap(const SkBitmap& src);
SkBitmap(SkBitmap&& src);
~SkBitmap();
SkBitmap& operator=(const SkBitmap& src);
SkBitmap& operator=(SkBitmap&& src);
void swap(SkBitmap& other);
const SkPixmap& pixmap() const;
const SkImageInfo& info() const;
int width() const;
int height() const;
SkColorType colorType() const;
SkAlphaType alphaType() const;
SkColorSpace* colorSpace() const;
sk_sp<SkColorSpace> refColorSpace() const;
int bytesPerPixel() const;
int rowBytesAsPixels() const;
int shiftPerPixel() const;
bool empty() const;
bool isNull() const;
bool drawsNothing() const;
size_t rowBytes() const;
bool setAlphaType(SkAlphaType alphaType);
void* getPixels() const;
size_t computeByteSize() const;
bool isImmutable() const;
void setImmutable();
bool isOpaque() const;
bool isVolatile() const;
void setIsVolatile(bool isVolatile);
void reset();
static bool ComputeIsOpaque(const SkBitmap& bm);
void getBounds(SkRect* bounds) const;
void getBounds(SkIRect* bounds) const;
SkIRect bounds() const;
SkISize dimensions() const;
SkIRect getSubset() const;
bool setInfo(const SkImageInfo& imageInfo, size_t rowBytes = 0);
enum AllocFlags {
kZeroPixels_AllocFlag = 1 << 0,
};
bool tryAllocPixelsFlags(const SkImageInfo& info, uint32_t flags);
void allocPixelsFlags(const SkImageInfo& info, uint32_t flags);
bool tryAllocPixels(const SkImageInfo& info, size_t rowBytes);
void allocPixels(const SkImageInfo& info, size_t rowBytes);
bool tryAllocPixels(const SkImageInfo& info);
void allocPixels(const SkImageInfo& info);
bool tryAllocN32Pixels(int width, int height, bool isOpaque = false);
void allocN32Pixels(int width, int height, bool isOpaque = false);
bool installPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
void (*releaseProc)(void* addr, void* context), void* context);
bool installPixels(const SkImageInfo& info, void* pixels, size_t rowBytes);
bool installPixels(const SkPixmap& pixmap);
bool installMaskPixels(const SkMask& mask);
void setPixels(void* pixels);
bool tryAllocPixels();
void allocPixels();
bool tryAllocPixels(Allocator* allocator);
void allocPixels(Allocator* allocator);
SkPixelRef* pixelRef() const;
SkIPoint pixelRefOrigin() const;
void setPixelRef(sk_sp<SkPixelRef> pixelRef, int dx, int dy);
bool readyToDraw() const;
uint32_t getGenerationID() const;
void notifyPixelsChanged() const;
void eraseColor(SkColor c) const;
void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const;
void erase(SkColor c, const SkIRect& area) const;
void eraseArea(const SkIRect& area, SkColor c) const;
SkColor getColor(int x, int y) const;
float getAlphaf(int x, int y) const;
void* getAddr(int x, int y) const;
uint32_t* getAddr32(int x, int y) const;
uint16_t* getAddr16(int x, int y) const;
uint8_t* getAddr8(int x, int y) const;
bool extractSubset(SkBitmap* dst, const SkIRect& subset) const;
bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
int srcX, int srcY) const;
bool readPixels(const SkPixmap& dst, int srcX, int srcY) const;
bool readPixels(const SkPixmap& dst) const;
bool writePixels(const SkPixmap& src, int dstX, int dstY);
bool writePixels(const SkPixmap& src);
bool extractAlpha(SkBitmap* dst) const;
bool extractAlpha(SkBitmap* dst, const SkPaint* paint,
SkIPoint* offset) const;
bool extractAlpha(SkBitmap* dst, const SkPaint* paint, Allocator* allocator,
SkIPoint* offset) const;
bool peekPixels(SkPixmap* pixmap) const;
void validate() const;
class Allocator : public SkRefCnt {
public:
virtual bool allocPixelRef(SkBitmap* bitmap) = 0;
};
class HeapAllocator : public Allocator {
public:
bool allocPixelRef(SkBitmap* bitmap) override;
};
};
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.
---
class Allocator : public SkRefCnt {
public:
virtual bool allocPixelRef(SkBitmap* bitmap) = 0;
};
Abstract subclass of HeapAllocator.
---
virtual bool allocPixelRef(SkBitmap* bitmap) = 0
Allocates the pixel memory for the bitmap, given its dimensions and
SkColorType. Returns true on success, where success means either setPixels()
or setPixelRef() was called.
### Parameters
### Return Value
true if SkPixelRef was allocated
### See Also
HeapAllocator
---
class HeapAllocator : public Allocator {
public:
bool allocPixelRef(SkBitmap* bitmap) override;
};
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.
---
bool allocPixelRef(SkBitmap* bitmap) override
Allocates the pixel memory for the bitmap, given its dimensions and
SkColorType. Returns true on success, where success means either setPixels()
or setPixelRef() was called.
### Parameters
### Return Value
true if pixels are allocated
### Example
#### Example Output
~~~~
#Volatile
pixel address = (nil)
pixel address = 0x560ddd0ac670
~~~~
### See Also
SkBitmap::Allocator tryAllocPixels
---
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). SkBitmap is not volatile.
Use setInfo() to associate SkColorType, SkAlphaType, width, and height
after SkBitmap has been created.
### Return Value
empty SkBitmap
### 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(const SkBitmap& src)
Copies settings from src to returned SkBitmap. Shares pixels if src has pixels
allocated, so both bitmaps reference the same pixels.
### Parameters
### 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&& src)
Copies settings from src to returned SkBitmap. Moves ownership of src pixels to
SkBitmap.
### Parameters
### 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()
Decrements SkPixelRef reference count, if SkPixelRef is not nullptr.
### See Also
Pixel_Ref
---
SkBitmap& operator=(const SkBitmap& src)
Copies settings from src to returned SkBitmap. Shares pixels if src has pixels
allocated, so both bitmaps reference the same pixels.
### Parameters
### 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& operator=(SkBitmap&& src)
Copies settings from src to returned SkBitmap. Moves ownership of src pixels to
SkBitmap.
### Parameters
### 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
---
void swap(SkBitmap& other)
Swaps the fields of the two bitmaps.
### Parameters
### 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) SkBitmap(SkBitmap&& src)operator=(SkBitmap&& src)
---
const SkPixmap& pixmap() const
Returns a constant reference to the SkPixmap holding the SkBitmap pixel
address, row bytes, and SkImageInfo.
### Return Value
reference to SkPixmap describing this SkBitmap
### 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
---
const SkImageInfo& info() const
Returns width, height, SkAlphaType, SkColorType, and SkColorSpace.
### Return Value
reference to SkImageInfo
### Example
#### Example Output
~~~~
width: 56 height: 56 color: BGRA_8888 alpha: Opaque
~~~~
### See Also
Image_Info
---
int width() const
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.
### Return Value
pixel width in Image_Info
### Example
#### Example Output
~~~~
bitmap width: 16 info width: 16
~~~~
### See Also
height() SkPixelRef::width() SkImageInfo::width()
---
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 SkImageInfo
### Example
#### Example Output
~~~~
bitmap height: 32 info height: 32
~~~~
### See Also
width() SkPixelRef::height() SkImageInfo::height()
---
SkColorType colorType() const
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
.
### Return Value
Color_Type in Image_Info
### Example
#### Example Output
~~~~
color type: kAlpha_8_SkColorType
~~~~
### See Also
alphaType() SkImageInfo::colorType
---
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
---
SkColorSpace* colorSpace() const
Returns SkColorSpace, the range of colors, associated with SkImageInfo. The
reference count of SkColorSpace is unchanged. The returned SkColorSpace is
immutable.
### Return Value
SkColorSpace in SkImageInfo, or nullptr
### Example
#### Example Output
~~~~
gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
~~~~
### See Also
Color_Space SkImageInfo::colorSpace
---
sk_sp<SkColorSpace> 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.
### Return Value
SkColorSpace in SkImageInfo wrapped in a smart pointer
### Example
#### Example Output
~~~~
gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
~~~~
### See Also
Color_Space SkImageInfo::colorSpace
---
int bytesPerPixel() const
Returns number of bytes per pixel required by SkColorType.
Returns zero if colorType( is kUnknown_SkColorType.
### Return Value
bytes in pixel
### Example
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
#### Example Output
~~~~
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
~~~~
### See Also
rowBytes rowBytesAsPixels width shiftPerPixel SkImageInfo::bytesPerPixel
---
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
---
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
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
#### Example Output
~~~~
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
~~~~
### See Also
rowBytes rowBytesAsPixels width bytesPerPixel
---
bool empty() const
Returns true if either width() or height() are zero.
Does not check if SkPixelRef is nullptr; call drawsNothing() to check width(),
height(), and SkPixelRef.
### 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
---
bool isNull() const
Returns true if SkPixelRef is nullptr.
Does not check if width() or height() are zero; call drawsNothing() to check
width(), height(), and SkPixelRef.
### Return Value
true if no SkPixelRef 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
---
bool drawsNothing() const
Returns true if width() or height() are zero, or if SkPixelRef is nullptr.
If true, SkBitmap 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
---
size_t rowBytes() const
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.
### 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
---
bool 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.
### Parameters
kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
kUnpremul_SkAlphaType
### Return Value
true if SkAlphaType is set
### Example
kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
kUnpremul_SkAlphaType
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
### See Also
Alpha_Type Color_Type Image_Info setInfo
---
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
---
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
---
bool isImmutable() const
Returns true if pixels can not change.
Most immutable SkBitmap 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
---
void 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.
### Example
Triggers assert if SK_DEBUG is true, runs fine otherwise.
### See Also
isImmutable SkPixelRef::setImmutable SkImage
---
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. 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.
### Return Value
true if SkImageInfo SkAlphaType is kOpaque_SkAlphaType
### 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
---
bool isVolatile() const
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 SkPixelRef.
### Return Value
true if marked volatile
### Example
#### Example Output
~~~~
original is volatile
copy is not volatile
~~~~
### See Also
setIsVolatile
---
void setIsVolatile(bool isVolatile)
Sets if pixels should be read from SkPixelRef on every access. SkBitmap are not
volatile by default; a GPU back end may upload pixel values expecting them to be
accessed repeatedly. Marking temporary SkBitmap as volatile provides a hint to
SkBaseDevice that the SkBitmap pixels should not be cached. This can
improve performance by avoiding overhead and reducing resource
consumption on SkBaseDevice.
### Parameters
### Example
### See Also
isVolatile
---
void 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.
### Example
#### Example Output
~~~~
width:1 height:1 isNull:false
width:0 height:0 isNull:true
~~~~
### See Also
SkBitmap() SkAlphaType SkColorType
---
static bool ComputeIsOpaque(const SkBitmap& bm)
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.
### Parameters
### Return Value
true if all pixels have opaque values or SkColorType is opaque
### Example
#### Example Output
~~~~
computeIsOpaque: false
computeIsOpaque: true
computeIsOpaque: false
computeIsOpaque: true
~~~~
### See Also
isOpaque Color_Type Alpha
---
void getBounds(SkRect* bounds) const
Returns SkRect { 0, 0, width(), height() }.
### Parameters
### Example
### See Also
bounds()
---
void getBounds(SkIRect* bounds) const
Returns SkIRect { 0, 0, width(), height() }.
### Parameters
bounds |
container for integral rectangle |
### Example
### See Also
bounds()
---
SkIRect bounds() const
Returns SkIRect { 0, 0, width(), height() }.
### Return Value
integral rectangle from origin to width() and height()
### Example
### See Also
getBounds
---
SkISize dimensions() const
Returns SkISize { width(), height() }.
### Return Value
integral size of width() and height()
### Example
### See Also
height width
---
SkIRect getSubset() const
Returns the bounds of this bitmap, offset by its SkPixelRef origin.
### Return Value
bounds within SkPixelRef bounds
### Example
#### Example Output
~~~~
source: 0, 0, 512, 512
subset: 100, 100, 412, 412
~~~~
### See Also
extractSubset getBounds
---
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:
### Parameters
### Return Value
true if Image_Info set successfully
### Example
### See Also
Alpha_Type Color_Type Color_Space height rowBytes width
---
enum AllocFlags {
kZeroPixels_AllocFlag = 1 << 0,
};
AllocFlags provides the option to zero pixel memory when allocated.
### Constants
### See Also
tryAllocPixelsFlags allocPixelsFlags erase eraseColor
---
bool tryAllocPixelsFlags(const SkImageInfo& info, uint32_t flags)
Sets SkImageInfo 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 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 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.
### Parameters
### Return Value
true if pixels allocation is successful
### Example
#### Example Output
~~~~
bitmap allocation succeeded!
~~~~
### See Also
allocPixelsFlags tryAllocPixels SkMallocPixelRef::MakeZeroed
---
void allocPixelsFlags(const SkImageInfo& info, uint32_t flags)
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel
memory. If flags is kZeroPixels_AllocFlag, 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 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.
### Parameters
### 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
---
bool 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().
### Parameters
### Return Value
true if pixel storage is allocated
### Example
### See Also
tryAllocPixelsFlags allocPixels SkMallocPixelRef::MakeAllocate
---
void 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().
### Parameters
### Example
### See Also
tryAllocPixels allocPixelsFlags SkMallocPixelRef::MakeAllocate
---
bool tryAllocPixels(const SkImageInfo& info)
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().
### Parameters
### Return Value
true if pixel storage is allocated
### Example
### See Also
tryAllocPixelsFlags allocPixels SkMallocPixelRef::MakeAllocate
---
void 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().
### Parameters
### Example
### See Also
tryAllocPixels allocPixelsFlags SkMallocPixelRef::MakeAllocate
---
bool 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.
### 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
---
void 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 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 SkBitmap that matches SkPMColor, the native pixel arrangement on
the platform. SkBitmap 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
---
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. 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.
### Parameters
### Return Value
true if SkImageInfo is set to info
### Example
#### Example Output
~~~~
before installPixels
releaseProc called
install not successful
~~~~
### See Also
allocPixels
---
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.
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.
### Parameters
### Return Value
true if SkImageInfo is set to info
### Example
### See Also
allocPixels
---
bool 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.
### Parameters
### Return Value
true if SkImageInfo was set to pixmap.info()
### Example
Draw a five by five
bitmap, and draw it again with a center white
pixel.
### See Also
allocPixels
---
bool installMaskPixels(const SkMask& mask)
To be deprecated soon.
---
void 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.
### Parameters
### Example
### See Also
installPixels allocPixels
---
bool tryAllocPixels()
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.
### Return Value
true if the allocation succeeds
### Example
### See Also
allocPixels installPixels setPixels
---
void 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.
### Example
### See Also
tryAllocPixels installPixels setPixels
---
bool 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.
### Parameters
### 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 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.
### Parameters
### Example
### See Also
allocPixels Allocator Pixel_Ref
---
SkPixelRef* pixelRef() const
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.
### Return Value
SkPixelRef, or nullptr
### Example
### See Also
getPixels getAddr
---
SkIPoint 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.
### Return Value
pixel origin within SkPixelRef
### Example
#### Example Output
~~~~
source origin: 0, 0
subset origin: 32, 64
~~~~
### See Also
SkPixelRef getSubset setPixelRef
---
void 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.
### Parameters
### Example
Treating 32-bit
data as 8-bit
data is unlikely to produce useful results.
### See Also
setInfo
---
bool readyToDraw() const
Returns true if SkBitmap is can be drawn.
### Return Value
true if getPixels() is not nullptr
### Example
### See Also
getPixels drawsNothing
---
uint32_t 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.
### Return Value
unique value for pixels in SkPixelRef
### Example
#### Example Output
~~~~
#Volatile
empty id 0
alloc id 4
erase id 6
~~~~
### See Also
notifyPixelsChanged Pixel_Ref
---
void notifyPixelsChanged() const
Marks that pixels in SkPixelRef have changed. Subsequent calls to
getGenerationID() return a different value.
### Example
### See Also
getGenerationID isVolatile Pixel_Ref
---
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 kRGB_565_SkColorType, then alpha
is ignored; RGB is treated as opaque. If colorType() is kAlpha_8_SkColorType,
then RGB is ignored.
### Parameters
### Example
### See Also
eraseARGB erase
---
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 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.
### Parameters
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) |
### Example
### See Also
eraseColor 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 kRGB_565_SkColorType, then alpha
is ignored; RGB is treated as opaque. If colorType() is kAlpha_8_SkColorType,
then RGB is ignored.
### Parameters
### Example
### See Also
eraseColor eraseARGB SkCanvas::drawRect
---
void eraseArea(const SkIRect& area, SkColor c) const
Deprecated.
---
SkColor getColor(int x, int y) const
Returns pixel at (x, y) as unpremultiplied color.
Returns black with alpha if SkColorType is kAlpha_8_SkColorType.
Input is not validated: out of bounds values of x or y trigger an assert() if
built with SK_DEBUG defined; and returns undefined values or may crash if
SK_RELEASE is defined. Fails if SkColorType is kUnknown_SkColorType or
pixel address is nullptr.
SkColorSpace in SkImageInfo is ignored. Some color precision may be lost in the
conversion to unpremultiplied color; original pixel data may have additional
precision.
### Parameters
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
getAlphaf getAddr readPixels
---
float getAlphaf(int x, int y) const
Looks 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 efficient
(and more precise if the pixels store more than 8 bits per component).
### Parameters
x |
column index, zero or greater, and less than width() |
y |
row index, zero or greater, and less than height() |
### Return Value
alpha converted to normalized float
### See Also
getColor
---
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
SkColorType is kUnknown_SkColorType, or SkPixelRef 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
---
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:
### 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
---
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:
### 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
---
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:
### 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
---
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:
### Parameters
### 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
---
bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, int srcY) const
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 if abs(srcX) >= Bitmap width()
, or if abs(srcY) >= Bitmap height()
.
### Parameters
### 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 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 if abs(srcX) >= Bitmap width()
, or if abs(srcY) >= Bitmap height()
.
### Parameters
### 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 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.
### Parameters
### Return Value
true if pixels are copied to dst
### Example
### See Also
writePixels SkPixmap::readPixels SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
---
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:
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 if abs(dstX) >= Bitmap width()
, or if abs(dstY) >= Bitmap height()
.
### Parameters
### 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:
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.
### Parameters
### Return Value
true if src pixels are copied to Bitmap
### Example
### See Also
readPixels
---
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 SkPixelRef.
### Parameters
### Return Value
true if alpha layer was constructed in dst SkPixelRef
### 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 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.
### Parameters
### Return Value
true if alpha layer was constructed in dst SkPixelRef
### 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 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.
### Parameters
### Return Value
true if alpha layer was constructed in dst SkPixelRef
### Example
### See Also
extractSubset
---
bool 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.
### Parameters
pixmap |
storage for pixel state if pixels are readable; otherwise, ignored |
### Return Value
true if SkBitmap has direct access to pixels
### Example
#### Example Output
~~~~
------
-xxx--
x---x-
----x-
---x--
--x---
--x---
------
--x---
--x---
------
~~~~
### See Also
pixmap installPixels readPixels writePixels
---
void validate() const;
### See Also
SkImageInfo::validate