 |
Skia
2D Graphics Library
|
Go to the documentation of this file.
8 #ifndef SkBitmap_DEFINED
9 #define SkBitmap_DEFINED
140 int width()
const {
return fPixmap.width(); }
149 int height()
const {
return fPixmap.height(); }
201 bool empty()
const {
return fPixmap.info().isEmpty(); }
210 bool isNull()
const {
return nullptr == fPixelRef; }
218 return this->empty() || this->isNull();
229 size_t rowBytes()
const {
return fPixmap.rowBytes(); }
264 void*
getPixels()
const {
return fPixmap.writable_addr(); }
376 SkIPoint origin = this->pixelRefOrigin();
416 kZeroPixels_AllocFlag = 1 << 0,
509 return this->tryAllocPixels(info, info.
minRowBytes());
591 void (*releaseProc)(
void* addr,
void* context),
void* context);
609 return this->installPixels(info, pixels, rowBytes,
nullptr,
nullptr);
656 return this->tryAllocPixels((
Allocator*)
nullptr);
740 return this->getPixels() !=
nullptr;
805 this->erase(c, area);
825 return this->pixmap().getColor(x, y);
837 return this->pixmap().getAlphaf(x, y);
869 inline uint32_t* getAddr32(
int x,
int y)
const;
883 inline uint16_t* getAddr16(
int x,
int y)
const;
897 inline uint8_t* getAddr8(
int x,
int y)
const;
949 int srcX,
int srcY)
const;
1002 return this->readPixels(dst, 0, 0);
1056 return this->writePixels(src, 0, 0);
1068 return this->extractAlpha(dst,
nullptr,
nullptr,
nullptr);
1086 return this->extractAlpha(dst, paint,
nullptr, offset);
1123 const SkMatrix& localMatrix)
const {
1124 return this->makeShader(tmx, tmy, sampling, &localMatrix);
1128 const SkMatrix* localMatrix =
nullptr)
const {
1133 const SkMatrix& localMatrix)
const {
1134 return this->makeShader(sampling, &localMatrix);
1137 #ifdef SK_SUPPORT_LEGACY_IMPLICIT_FILTERQUALITY
1139 const SkMatrix* localMatrix =
nullptr)
const;
1170 virtual bool allocPixelRef(
SkBitmap* bitmap) = 0;
1200 friend class SkImage_Raster;
1201 friend class SkReadBuffer;
@ kClamp
Replicate the edge color if the shader draws outside of its original bounds.
sk_sp< SkImage > asImage() const
Returns a new image from the bitmap.
bool SK_WARN_UNUSED_RESULT tryAllocN32Pixels(int width, int height, bool isOpaque=false)
Sets SkImageInfo to width, height, and native color type; and allocates pixel memory.
void getBounds(SkRect *bounds) const
Returns SkRect { 0, 0, width(), height() }.
void * getAddr(int x, int y) const
Returns pixel address at (x, y).
void erase(SkColor c, const SkIRect &area) const
Replaces pixel values inside area with c.
Definition: SkRefCnt.h:118
Definition: SkBitmap.h:1180
uint32_t * writable_addr32(int x, int y) const
Returns writable pixel address at (x, y).
Definition: SkPixmap.h:509
bool extractAlpha(SkBitmap *dst, const SkPaint *paint, Allocator *allocator, SkIPoint *offset) const
Sets dst to alpha described by pixels.
SkPixelRef * pixelRef() const
Returns SkPixelRef, which contains: pixel base address; its dimensions; and rowBytes(),...
Definition: SkBitmap.h:701
Asserts if internal values are illegal or inconsistent.
Definition: SkBitmap.h:1155
uint8_t * getAddr8(int x, int y) const
Returns address at (x, y).
Definition: SkBitmap.h:1216
SkBitmap(const SkBitmap &src)
Copies settings from src to returned SkBitmap.
SkColorSpace * colorSpace() const
Returns SkColorSpace, the range of colors, associated with SkImageInfo.
Definition: SkBitmap.h:161
bool drawsNothing() const
Returns true if width() or height() are zero, or if SkPixelRef is nullptr.
Definition: SkBitmap.h:217
static bool ComputeIsOpaque(const SkBitmap &bm)
Returns true if all pixels are opaque.
Definition: SkBitmap.h:339
SkBitmap()
Creates an empty SkBitmap without pixels, with kUnknown_SkColorType, kUnknown_SkAlphaType,...
Definition: SkPixelRef.h:33
uint16_t * getAddr16(int x, int y) const
Returns address at (x, y).
Definition: SkBitmap.h:1211
SkColorType colorType() const
Definition: SkBitmap.h:151
SkIRect bounds() const
Returns SkIRect { 0, 0, width(), height() }.
Definition: SkBitmap.h:363
void reset()
Resets to its initial state; all fields are set to zero, as if SkBitmap had been initialized by SkBit...
Definition: SkShader.h:39
constexpr int32_t y() const
Returns y-axis value of SkIPoint.
Definition: SkPoint.h:49
constexpr int32_t x() const
Returns x-axis value of SkIPoint.
Definition: SkPoint.h:43
void setPixels(void *pixels)
Replaces SkPixelRef with pixels, preserving SkImageInfo and rowBytes().
bool extractAlpha(SkBitmap *dst, const SkPaint *paint, SkIPoint *offset) const
Sets dst to alpha described by pixels.
Definition: SkBitmap.h:1084
bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo &info)
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel memory.
Definition: SkBitmap.h:508
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *=nullptr) const
bool writePixels(const SkPixmap &src, int dstX, int dstY)
Copies a SkRect of pixels from src.
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &sampling, const SkMatrix &localMatrix) const
Definition: SkBitmap.h:1122
void notifyPixelsChanged() const
Marks that pixels in SkPixelRef have changed.
uint8_t * writable_addr8(int x, int y) const
Returns writable pixel address at (x, y).
Definition: SkPixmap.h:480
void eraseColor(SkColor c) const
Replaces pixel values with c, interpreted as being in the sRGB SkColorSpace.
bool SK_WARN_UNUSED_RESULT tryAllocPixels()
Allocates pixel memory with HeapAllocator, and replaces existing SkPixelRef.
Definition: SkBitmap.h:655
bool allocPixelRef(SkBitmap *bitmap) override
Allocates the pixel memory for the bitmap, given its dimensions and SkColorType.
uint32_t getGenerationID() const
Returns a unique value corresponding to the pixels in SkPixelRef.
SkTileMode
Definition: SkTileMode.h:13
Definition: SkSamplingOptions.h:50
void allocPixelsFlags(const SkImageInfo &info, uint32_t flags)
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel memory.
sk_sp< SkShader > makeShader(const SkSamplingOptions &sampling, const SkMatrix *localMatrix=nullptr) const
Definition: SkBitmap.h:1127
bool installMaskPixels(const SkMask &mask)
Deprecated.
const SkPixmap & pixmap() const
Returns a constant reference to the SkPixmap holding the SkBitmap pixel address, row bytes,...
Definition: SkBitmap.h:124
bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo &info, size_t rowBytes)
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel memory.
bool extractSubset(SkBitmap *dst, const SkIRect &subset) const
Shares SkPixelRef with dst.
#define SkDEBUGCODE(...)
Definition: SkTypes.h:467
bool installPixels(const SkPixmap &pixmap)
Sets SkImageInfo to pixmap.info() following the rules in setInfo(), and creates SkPixelRef containing...
bool readyToDraw() const
Returns true if SkBitmap is can be drawn.
Definition: SkBitmap.h:739
bool isImmutable() const
Returns true if pixels can not change.
#define SK_API
Definition: SkTypes.h:181
#define SkASSERT(cond)
Definition: SkTypes.h:460
int rowBytesAsPixels() const
Returns number of pixels that fit on row.
Definition: SkBitmap.h:185
int shiftPerPixel() const
Returns bit shift converting row bytes to row pixels.
Definition: SkBitmap.h:192
AllocFlags
Definition: SkBitmap.h:415
Definition: SkImageInfo.h:283
SkBitmap & operator=(SkBitmap &&src)
Copies settings from src to returned SkBitmap.
void swap(SkBitmap &other)
Swaps the fields of the two bitmaps.
int bytesPerPixel() const
Returns number of bytes per pixel required by SkColorType.
Definition: SkBitmap.h:178
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Returns color value from 8-bit component values.
Definition: SkColor.h:47
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 a...
size_t computeByteSize() const
Returns minimum memory required for pixel storage.
Definition: SkBitmap.h:274
sk_sp< SkColorSpace > refColorSpace() const
Returns smart pointer to SkColorSpace, the range of colors, associated with SkImageInfo.
Definition: SkBitmap.h:171
SkAlphaType alphaType() const
Definition: SkBitmap.h:153
~SkBitmap()
Decrements SkPixelRef reference count, if SkPixelRef is not nullptr.
bool writePixels(const SkPixmap &src)
Copies a SkRect of pixels from src.
Definition: SkBitmap.h:1055
sk_sp< SkShader > makeShader(const SkSamplingOptions &sampling, const SkMatrix &localMatrix) const
Definition: SkBitmap.h:1132
bool readPixels(const SkPixmap &dst, int srcX, int srcY) const
Copies a SkRect of pixels from SkBitmap to dst.
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel memory.
bool peekPixels(SkPixmap *pixmap) const
Copies SkBitmap pixel address, row bytes, and SkImageInfo to pixmap, if address is available,...
bool setAlphaType(SkAlphaType alphaType)
Sets SkAlphaType, if alphaType is compatible with SkColorType.
const SkImageInfo & info() const
Returns width, height, SkAlphaType, SkColorType, and SkColorSpace.
Definition: SkBitmap.h:130
void setPixelRef(sk_sp< SkPixelRef > pixelRef, int dx, int dy)
Replaces pixelRef and origin in SkBitmap.
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Returns constructed SkIRect set to: (x, y, x + w, y + h).
Definition: SkRect.h:101
void eraseArea(const SkIRect &area, SkColor c) const
Deprecated.
Definition: SkBitmap.h:804
void allocPixels(const SkImageInfo &info)
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel memory.
bool setInfo(const SkImageInfo &imageInfo, size_t rowBytes=0)
Sets width, height, SkAlphaType, SkColorType, SkColorSpace, and optional rowBytes.
int height() const
Returns pixel row count.
Definition: SkBitmap.h:149
SkBitmap & operator=(const SkBitmap &src)
Copies settings from src to returned SkBitmap.
bool readPixels(const SkPixmap &dst) const
Copies a SkRect of pixels from SkBitmap to dst.
Definition: SkBitmap.h:1001
Definition: SkPixmap.h:31
const void * addr() const
Returns pixel address, the base address corresponding to the pixel origin.
Definition: SkPixmap.h:144
bool SK_WARN_UNUSED_RESULT tryAllocPixels(Allocator *allocator)
Allocates pixel memory with allocator, and replaces existing SkPixelRef.
int width() const
Returns pixel count in each row.
Definition: SkBitmap.h:140
Definition: SkMatrix.h:48
SkIRect getSubset() const
Returns the bounds of this bitmap, offset by its SkPixelRef origin.
Definition: SkBitmap.h:375
uint16_t * writable_addr16(int x, int y) const
Returns writable_addr pixel address at (x, y).
Definition: SkPixmap.h:494
size_t minRowBytes() const
Returns minimum bytes per row, computed from pixel width() and SkColorType, which specifies bytesPerP...
Definition: SkImageInfo.h:606
#define SK_WARN_UNUSED_RESULT
Definition: SkTypes.h:60
SkISize dimensions() const
Returns SkISize { width(), height() }.
Definition: SkBitmap.h:369
void getBounds(SkIRect *bounds) const
Returns SkIRect { 0, 0, width(), height() }.
bool computeIsOpaque() const
Returns true if all pixels are opaque.
void allocN32Pixels(int width, int height, bool isOpaque=false)
Sets SkImageInfo to width, height, and the native color type; and allocates pixel memory.
bool installPixels(const SkImageInfo &info, void *pixels, size_t rowBytes)
Sets SkImageInfo to info following the rules in setInfo(), and creates SkPixelRef containing pixels a...
Definition: SkBitmap.h:608
void setImmutable()
Sets internal flag to mark SkBitmap as immutable.
void * getPixels() const
Returns pixel address, the base address corresponding to the pixel origin.
Definition: SkBitmap.h:264
bool extractAlpha(SkBitmap *dst) const
Sets dst to alpha described by pixels.
Definition: SkBitmap.h:1067
uint32_t SkColor
32-bit ARGB color value, unpremultiplied.
Definition: SkColor.h:35
SkBitmap(SkBitmap &&src)
Copies settings from src to returned SkBitmap.
bool empty() const
Returns true if either width() or height() are zero.
Definition: SkBitmap.h:201
SkColorType
Definition: SkImageInfo.h:64
void allocPixels()
Allocates pixel memory with HeapAllocator, and replaces existing SkPixelRef.
bool isOpaque() const
Returns true if SkAlphaType is set to hint that all pixels are opaque; their alpha value is implicitl...
Definition: SkBitmap.h:305
unsigned U8CPU
Fast type for unsigned 8 bits.
Definition: SkTypes.h:488
float getAlphaf(int x, int y) const
Look up the pixel at (x,y) and return its alpha component, normalized to [0..1].
Definition: SkBitmap.h:836
SkColor getColor(int x, int y) const
Returns pixel at (x, y) as unpremultiplied color.
Definition: SkBitmap.h:824
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY) const
Copies a SkRect of pixels from SkBitmap to dstPixels.
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 t...
Definition: SkBitmap.h:784
uint32_t * getAddr32(int x, int y) const
Returns address at (x, y).
Definition: SkBitmap.h:1206
bool isNull() const
Returns true if SkPixelRef is nullptr.
Definition: SkBitmap.h:210
SkAlphaType
Definition: SkImageInfo.h:37
static bool SkAlphaTypeIsOpaque(SkAlphaType at)
Returns true if SkAlphaType equals kOpaque_SkAlphaType.
Definition: SkImageInfo.h:52
size_t rowBytes() const
Returns row bytes, the interval from one pixel row to the next.
Definition: SkBitmap.h:229
void allocPixels(Allocator *allocator)
Allocates pixel memory with allocator, and replaces existing SkPixelRef.
Definition: SkBitmap.h:50
bool SK_WARN_UNUSED_RESULT tryAllocPixelsFlags(const SkImageInfo &info, uint32_t flags)
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel memory.
Definition: SkColorSpace.h:104
SkIPoint pixelRefOrigin() const
Returns origin of pixels within SkPixelRef.