8 #ifndef SkBitmap_DEFINED
9 #define SkBitmap_DEFINED
21 #include "include/private/base/SkCPUTypes.h"
22 #include "include/private/base/SkDebug.h"
149 int width()
const {
return fPixmap.width(); }
158 int height()
const {
return fPixmap.height(); }
210 bool empty()
const {
return fPixmap.info().isEmpty(); }
219 bool isNull()
const {
return nullptr == fPixelRef; }
227 return this->empty() || this->isNull();
238 size_t rowBytes()
const {
return fPixmap.rowBytes(); }
273 void*
getPixels()
const {
return fPixmap.writable_addr(); }
385 SkIPoint origin = this->pixelRefOrigin();
425 kZeroPixels_AllocFlag = 1 << 0,
518 return this->tryAllocPixels(info, info.
minRowBytes());
600 void (*releaseProc)(
void* addr,
void* context),
void* context);
618 return this->installPixels(info, pixels, rowBytes,
nullptr,
nullptr);
665 return this->tryAllocPixels((
Allocator*)
nullptr);
749 return this->getPixels() !=
nullptr;
807 void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
const {
845 this->erase(c, area);
865 return this->pixmap().getColor(x, y);
894 return this->pixmap().getAlphaf(x, y);
926 inline uint32_t* getAddr32(
int x,
int y)
const;
940 inline uint16_t* getAddr16(
int x,
int y)
const;
954 inline uint8_t* getAddr8(
int x,
int y)
const;
1006 int srcX,
int srcY)
const;
1059 return this->readPixels(dst, 0, 0);
1113 return this->writePixels(src, 0, 0);
1125 return this->extractAlpha(dst,
nullptr,
nullptr,
nullptr);
1142 SkIPoint* offset)
const {
1143 return this->extractAlpha(dst, paint,
nullptr, offset);
1162 SkIPoint* offset)
const;
1181 const SkMatrix* localMatrix =
nullptr)
const;
1187 const SkMatrix* lm =
nullptr)
const;
1198 SkDEBUGCODE(
void validate()
const;)
1213 virtual bool allocPixelRef(
SkBitmap* bitmap) = 0;
1243 friend class SkImage_Raster;
1244 friend class SkReadBuffer;
1245 friend class GrProxyProvider;
1251 SkASSERT(fPixmap.
addr());
1256 SkASSERT(fPixmap.
addr());
1261 SkASSERT(fPixmap.
addr());
static bool SkAlphaTypeIsOpaque(SkAlphaType at)
Returns true if SkAlphaType equals kOpaque_SkAlphaType.
Definition: SkAlphaType.h:41
SkAlphaType
Describes how to interpret the alpha component of a pixel.
Definition: SkAlphaType.h:26
SkColorType
Describes how pixel bits encode color.
Definition: SkColorType.h:19
Types, consts, functions, and macros for colors.
uint32_t SkColor
32-bit ARGB color value, unpremultiplied.
Definition: SkColor.h:37
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Returns color value from 8-bit component values.
Definition: SkColor.h:49
SkTileMode
Definition: SkTileMode.h:13
Asserts if internal values are illegal or inconsistent.
Definition: SkBitmap.h:1198
Subclass of SkBitmap::Allocator that returns a SkPixelRef that allocates its pixel memory from the he...
Definition: SkBitmap.h:1223
bool allocPixelRef(SkBitmap *bitmap) override
Allocates the pixel memory for the bitmap, given its dimensions and SkColorType.
SkBitmap describes a two-dimensional raster pixel array.
Definition: SkBitmap.h:59
bool extractAlpha(SkBitmap *dst) const
Sets dst to alpha described by pixels.
Definition: SkBitmap.h:1124
bool installMaskPixels(SkMaskBuilder &mask)
Deprecated.
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel memory.
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:807
SkColorSpace * colorSpace() const
Returns SkColorSpace, the range of colors, associated with SkImageInfo.
int shiftPerPixel() const
Returns bit shift converting row bytes to row pixels.
Definition: SkBitmap.h:201
sk_sp< SkColorSpace > refColorSpace() const
Returns smart pointer to SkColorSpace, the range of colors, associated with SkImageInfo.
void setImmutable()
Sets internal flag to mark SkBitmap as immutable.
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...
SkIPoint pixelRefOrigin() const
Returns origin of pixels within SkPixelRef.
void notifyPixelsChanged() const
Marks that pixels in SkPixelRef have changed.
void getBounds(SkRect *bounds) const
Returns SkRect { 0, 0, width(), height() }.
SkAlphaType alphaType() const
Definition: SkBitmap.h:162
bool tryAllocPixels(Allocator *allocator)
Allocates pixel memory with allocator, and replaces existing SkPixelRef.
bool extractAlpha(SkBitmap *dst, const SkPaint *paint, Allocator *allocator, SkIPoint *offset) const
Sets dst to alpha described by pixels.
bool tryAllocPixels()
Allocates pixel memory with HeapAllocator, and replaces existing SkPixelRef.
Definition: SkBitmap.h:664
bool readyToDraw() const
Returns true if SkBitmap is can be drawn.
Definition: SkBitmap.h:748
bool extractSubset(SkBitmap *dst, const SkIRect &subset) const
Shares SkPixelRef with dst.
bool writePixels(const SkPixmap &src)
Copies a SkRect of pixels from src.
Definition: SkBitmap.h:1112
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:617
SkBitmap & operator=(SkBitmap &&src)
Copies settings from src to returned SkBitmap.
SkISize dimensions() const
Returns SkISize { width(), height() }.
Definition: SkBitmap.h:378
const SkPixmap & pixmap() const
Returns a constant reference to the SkPixmap holding the SkBitmap pixel address, row bytes,...
Definition: SkBitmap.h:133
void eraseArea(const SkIRect &area, SkColor c) const
Deprecated.
Definition: SkBitmap.h:844
bool isOpaque() const
Returns true if SkAlphaType is set to hint that all pixels are opaque; their alpha value is implicitl...
Definition: SkBitmap.h:314
SkColor getColor(int x, int y) const
Returns pixel at (x, y) as unpremultiplied color.
Definition: SkBitmap.h:864
bool empty() const
Returns true if either width() or height() are zero.
Definition: SkBitmap.h:210
size_t computeByteSize() const
Returns minimum memory required for pixel storage.
Definition: SkBitmap.h:283
void * getAddr(int x, int y) const
Returns pixel address at (x, y).
uint8_t * getAddr8(int x, int y) const
Returns address at (x, y).
Definition: SkBitmap.h:1260
int width() const
Returns pixel count in each row.
Definition: SkBitmap.h:149
bool writePixels(const SkPixmap &src, int dstX, int dstY)
Copies a SkRect of pixels from src.
SkPixelRef * pixelRef() const
Returns SkPixelRef, which contains: pixel base address; its dimensions; and rowBytes(),...
Definition: SkBitmap.h:710
SkColor4f getColor4f(int x, int y) const
Returns pixel at (x, y) as unpremultiplied float color.
Definition: SkBitmap.h:883
bool extractAlpha(SkBitmap *dst, const SkPaint *paint, SkIPoint *offset) const
Sets dst to alpha described by pixels.
Definition: SkBitmap.h:1141
void eraseColor(SkColor c) const
Replaces pixel values with c, interpreted as being in the sRGB SkColorSpace.
bool isImmutable() const
Returns true if pixels can not change.
void allocPixels()
Allocates pixel memory with HeapAllocator, and replaces existing SkPixelRef.
void allocPixels(Allocator *allocator)
Allocates pixel memory with allocator, and replaces existing SkPixelRef.
size_t rowBytes() const
Returns row bytes, the interval from one pixel row to the next.
Definition: SkBitmap.h:238
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &sampling, const SkMatrix &lm) const
bool isNull() const
Returns true if SkPixelRef is nullptr.
Definition: SkBitmap.h:219
const SkImageInfo & info() const
Returns width, height, SkAlphaType, SkColorType, and SkColorSpace.
Definition: SkBitmap.h:139
void reset()
Resets to its initial state; all fields are set to zero, as if SkBitmap had been initialized by SkBit...
SkColorType colorType() const
Definition: SkBitmap.h:160
bool drawsNothing() const
Returns true if width() or height() are zero, or if SkPixelRef is nullptr.
Definition: SkBitmap.h:226
void setPixels(void *pixels)
Replaces SkPixelRef with pixels, preserving SkImageInfo and rowBytes().
~SkBitmap()
Decrements SkPixelRef reference count, if SkPixelRef is not nullptr.
sk_sp< SkShader > makeShader(const SkSamplingOptions &sampling, const SkMatrix *lm=nullptr) const
SkBitmap(SkBitmap &&src)
Copies settings from src to returned SkBitmap.
void getBounds(SkIRect *bounds) const
Returns SkIRect { 0, 0, width(), height() }.
SkIRect getSubset() const
Returns the bounds of this bitmap, offset by its SkPixelRef origin.
Definition: SkBitmap.h:384
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.
void * getPixels() const
Returns pixel address, the base address corresponding to the pixel origin.
Definition: SkBitmap.h:273
bool readPixels(const SkPixmap &dst) const
Copies a SkRect of pixels from SkBitmap to dst.
Definition: SkBitmap.h:1058
int bytesPerPixel() const
Returns number of bytes per pixel required by SkColorType.
Definition: SkBitmap.h:187
void erase(SkColor c, const SkIRect &area) const
Replaces pixel values inside area with c.
SkBitmap(const SkBitmap &src)
Copies settings from src to returned SkBitmap.
bool installPixels(const SkPixmap &pixmap)
Sets SkImageInfo to pixmap.info() following the rules in setInfo(), and creates SkPixelRef containing...
SkBitmap()
Creates an empty SkBitmap without pixels, with kUnknown_SkColorType, kUnknown_SkAlphaType,...
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY) const
Copies a SkRect of pixels from SkBitmap to dstPixels.
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:893
bool tryAllocPixels(const SkImageInfo &info)
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel memory.
Definition: SkBitmap.h:517
uint32_t getGenerationID() const
Returns a unique value corresponding to the pixels in SkPixelRef.
void allocN32Pixels(int width, int height, bool isOpaque=false)
Sets SkImageInfo to width, height, and the native color type; and allocates pixel memory.
SkIRect bounds() const
Returns SkIRect { 0, 0, width(), height() }.
Definition: SkBitmap.h:372
SkBitmap & operator=(const SkBitmap &src)
Copies settings from src to returned SkBitmap.
bool readPixels(const SkPixmap &dst, int srcX, int srcY) const
Copies a SkRect of pixels from SkBitmap to dst.
bool peekPixels(SkPixmap *pixmap) const
Copies SkBitmap pixel address, row bytes, and SkImageInfo to pixmap, if address is available,...
bool setInfo(const SkImageInfo &imageInfo, size_t rowBytes=0)
Sets width, height, SkAlphaType, SkColorType, SkColorSpace, and optional rowBytes.
static bool ComputeIsOpaque(const SkBitmap &bm)
Returns true if all pixels are opaque.
Definition: SkBitmap.h:348
bool setAlphaType(SkAlphaType alphaType)
Sets SkAlphaType, if alphaType is compatible with SkColorType.
AllocFlags
Definition: SkBitmap.h:424
int height() const
Returns pixel row count.
Definition: SkBitmap.h:158
uint32_t * getAddr32(int x, int y) const
Returns address at (x, y).
Definition: SkBitmap.h:1250
void allocPixelsFlags(const SkImageInfo &info, uint32_t flags)
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel memory.
void setPixelRef(sk_sp< SkPixelRef > pixelRef, int dx, int dy)
Replaces pixelRef and origin in SkBitmap.
int rowBytesAsPixels() const
Returns number of pixels that fit on row.
Definition: SkBitmap.h:194
sk_sp< SkImage > asImage() const
Returns a new image from the bitmap.
bool tryAllocN32Pixels(int width, int height, bool isOpaque=false)
Sets SkImageInfo to width, height, and native color type; and allocates pixel memory.
bool tryAllocPixels(const SkImageInfo &info, size_t rowBytes)
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel memory.
void swap(SkBitmap &other)
Swaps the fields of the two bitmaps.
uint16_t * getAddr16(int x, int y) const
Returns address at (x, y).
Definition: SkBitmap.h:1255
void allocPixels(const SkImageInfo &info)
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel memory.
sk_sp< SkShader > makeShader(const SkSamplingOptions &sampling, const SkMatrix &lm) const
Defaults to clamp in both X and Y.
bool tryAllocPixelsFlags(const SkImageInfo &info, uint32_t flags)
Sets SkImageInfo to info following the rules in setInfo() and allocates pixel memory.
void erase(SkColor4f c, const SkIRect &area) const
Replaces pixel values inside area with c.
void eraseColor(SkColor4f) const
Replaces pixel values with c, interpreted as being in the sRGB SkColorSpace.
Definition: SkColorSpace.h:107
SkImage describes a two dimensional array of pixels to draw.
Definition: SkImage.h:270
SkMatrix holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:53
SkPaint controls options applied when drawing.
Definition: SkPaint.h:44
This class is the smart container for pixel memory, and is used with SkBitmap.
Definition: SkPixelRef.h:28
SkPixmap provides a utility to pair SkImageInfo with pixels and row bytes.
Definition: SkPixmap.h:40
uint32_t * writable_addr32(int x, int y) const
Returns writable pixel address at (x, y).
Definition: SkPixmap.h:537
uint8_t * writable_addr8(int x, int y) const
Returns writable pixel address at (x, y).
Definition: SkPixmap.h:508
bool computeIsOpaque() const
Returns true if all pixels are opaque.
uint16_t * writable_addr16(int x, int y) const
Returns writable_addr pixel address at (x, y).
Definition: SkPixmap.h:522
const void * addr() const
Returns pixel address, the base address corresponding to the pixel origin.
Definition: SkPixmap.h:153
Definition: SkRefCnt.h:119
Shaders specify the source color(s) for what is being drawn.
Definition: SkShader.h:35
RGBA color value, holding four floating point components.
SkIRect holds four 32-bit integer coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:32
static constexpr SkIRect 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:104
Describes pixel dimensions and encoding.
Definition: SkImageInfo.h:194
size_t minRowBytes() const
Returns minimum bytes per row, computed from pixel width() and SkColorType, which specifies bytesPerP...
Definition: SkImageInfo.h:503
SkRect holds four float coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:582
Definition: SkSamplingOptions.h:58