8 #ifndef SkBitmap_DEFINED
9 #define SkBitmap_DEFINED
12 #include "SkColorTable.h"
13 #include "SkImageInfo.h"
27 #ifdef SK_SUPPORT_LEGACY_BITMAP_GETTEXTURE
43 class SK_API Allocator;
58 SkBitmap(
const SkBitmap& src);
64 SkBitmap(SkBitmap&& src);
71 SkBitmap& operator=(
const SkBitmap& src);
76 SkBitmap& operator=(SkBitmap&& src);
81 void swap(SkBitmap& other);
87 int width()
const {
return fInfo.width(); }
88 int height()
const {
return fInfo.height(); }
89 SkColorType colorType()
const {
return fInfo.colorType(); }
90 SkAlphaType alphaType()
const {
return fInfo.alphaType(); }
91 SkColorSpace* colorSpace()
const {
return fInfo.colorSpace(); }
104 return fRowBytes >> this->shiftPerPixel();
118 bool empty()
const {
return fInfo.isEmpty(); }
124 bool isNull()
const {
return NULL == fPixelRef; }
142 bool setAlphaType(SkAlphaType);
152 size_t getSize()
const {
return fInfo.height() * fRowBytes; }
158 size_t getSafeSize()
const {
return fInfo.getSafeSize(fRowBytes); }
164 return sk_64_mul(fInfo.height(), fRowBytes);
173 return fInfo.getSafeSize64(fRowBytes);
179 bool isImmutable()
const;
192 return SkAlphaTypeIsOpaque(this->alphaType());
197 bool isVolatile()
const;
206 void setIsVolatile(
bool);
222 static bool ComputeIsOpaque(
const SkBitmap&);
227 void getBounds(
SkRect* bounds)
const;
228 void getBounds(
SkIRect* bounds)
const;
230 SkIRect bounds()
const {
return fInfo.bounds(); }
231 SkISize dimensions()
const {
return fInfo.dimensions(); }
234 return SkIRect::MakeXYWH(fPixelRefOrigin.x(), fPixelRefOrigin.y(),
235 fInfo.width(), fInfo.height());
238 bool setInfo(
const SkImageInfo&,
size_t rowBytes = 0);
249 if (!this->tryAllocPixels(info, factory, ctable)) {
262 bool SK_WARN_UNUSED_RESULT tryAllocPixels(
const SkImageInfo& info,
size_t rowBytes);
264 void allocPixels(
const SkImageInfo& info,
size_t rowBytes) {
265 if (!this->tryAllocPixels(info, rowBytes)) {
270 bool SK_WARN_UNUSED_RESULT tryAllocPixels(
const SkImageInfo& info) {
271 return this->tryAllocPixels(info, info.minRowBytes());
275 this->allocPixels(info, info.minRowBytes());
278 bool SK_WARN_UNUSED_RESULT tryAllocN32Pixels(
int width,
int height,
bool isOpaque =
false) {
280 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
281 return this->tryAllocPixels(info);
284 void allocN32Pixels(
int width,
int height,
bool isOpaque =
false) {
286 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
287 this->allocPixels(info);
301 void (*releaseProc)(
void* addr,
void* context),
void* context);
309 return this->installPixels(info, pixels, rowBytes, NULL, NULL, NULL);
318 bool installPixels(
const SkPixmap&);
325 bool installMaskPixels(
const SkMask&);
357 bool copyPixelsTo(
void*
const dst,
size_t dstSize,
size_t dstRowBytes = 0,
358 bool preserveDstPad =
false)
const;
374 return this->tryAllocPixels(NULL, ctable);
378 this->allocPixels(NULL, ctable);
399 bool SK_WARN_UNUSED_RESULT tryAllocPixels(Allocator* allocator,
SkColorTable* ctable);
401 void allocPixels(Allocator* allocator,
SkColorTable* ctable) {
402 if (!this->tryAllocPixels(allocator, ctable)) {
436 return this->setPixelRef(pr, origin.fX, origin.fY);
440 return this->setPixelRef(pr, 0, 0);
447 void lockPixels()
const;
453 void unlockPixels()
const;
462 bool lockPixelsAreWritable()
const;
471 return this->getPixels() != NULL &&
472 (this->colorType() != kIndex_8_SkColorType || fColorTable);
475 #ifdef SK_SUPPORT_LEGACY_BITMAP_GETTEXTURE
476 GrTexture* getTexture()
const {
return nullptr; }
491 uint32_t getGenerationID()
const;
497 void notifyPixelsChanged()
const;
505 void eraseColor(
SkColor c)
const;
517 SK_ATTR_DEPRECATED(
"use eraseARGB or eraseColor")
519 this->eraseARGB(0xFF, r, g, b);
532 this->erase(c, area);
542 SkColor getColor(
int x,
int y)
const;
553 void* getAddr(
int x,
int y)
const;
560 inline uint32_t* getAddr32(
int x,
int y)
const;
567 inline uint16_t* getAddr16(
int x,
int y)
const;
574 inline uint8_t* getAddr8(
int x,
int y)
const;
582 inline SkPMColor getIndex8Color(
int x,
int y)
const;
595 bool extractSubset(SkBitmap* dst,
const SkIRect& subset)
const;
609 bool copyTo(SkBitmap* dst, SkColorType ct, Allocator* = NULL)
const;
611 bool copyTo(SkBitmap* dst, Allocator* allocator = NULL)
const {
612 return this->copyTo(dst, this->colorType(), allocator);
634 bool readPixels(
const SkImageInfo& dstInfo,
void* dstPixels,
size_t dstRowBytes,
635 int srcX,
int srcY)
const;
641 bool canCopyTo(SkColorType colorType)
const;
649 bool deepCopyTo(SkBitmap* dst)
const;
651 #ifdef SK_BUILD_FOR_ANDROID
652 bool hasHardwareMipMap()
const {
653 return (fFlags & kHasHardwareMipMap_Flag) != 0;
656 void setHasHardwareMipMap(
bool hasHardwareMipMap) {
657 if (hasHardwareMipMap) {
658 fFlags |= kHasHardwareMipMap_Flag;
660 fFlags &= ~kHasHardwareMipMap_Flag;
665 bool extractAlpha(SkBitmap* dst)
const {
666 return this->extractAlpha(dst, NULL, NULL, NULL);
669 bool extractAlpha(SkBitmap* dst,
const SkPaint* paint,
671 return this->extractAlpha(dst, paint, NULL, offset);
687 bool extractAlpha(SkBitmap* dst,
const SkPaint* paint, Allocator* allocator,
701 SkDEBUGCODE(
void validate()
const;)
712 virtual bool allocPixelRef(SkBitmap*,
SkColorTable*) = 0;
731 uint8_t* packedAtY(
int y)
const {
732 SkASSERT((
unsigned)y < (
unsigned)fHeight);
737 void setPackedAtY(
int y, uint8_t* addr) {
738 SkASSERT((
unsigned)y < (
unsigned)fHeight);
747 SK_TO_STRING_NONVIRT()
751 mutable
int fPixelLockCount;
753 mutable
void* fPixels;
759 kImageIsVolatile_Flag = 0x02,
760 #ifdef SK_BUILD_FOR_ANDROID
765 kHasHardwareMipMap_Flag = 0x08,
776 void updatePixelsFromRef()
const;
779 static bool ReadRawPixels(SkReadBuffer*, SkBitmap*);
781 friend class SkReadBuffer;
783 friend struct SkBitmapProcState;
801 const SkBitmap& fBitmap;
812 SkASSERT((
unsigned)x < (
unsigned)this->width() && (
unsigned)y < (
unsigned)this->height());
813 return (uint32_t*)((
char*)fPixels + y * fRowBytes + (x << 2));
819 SkASSERT((
unsigned)x < (
unsigned)this->width() && (
unsigned)y < (
unsigned)this->height());
820 return (uint16_t*)((
char*)fPixels + y * fRowBytes + (x << 1));
826 SkASSERT((
unsigned)x < (
unsigned)this->width() && (
unsigned)y < (
unsigned)this->height());
827 return (uint8_t*)fPixels + y * fRowBytes + x;
832 SkASSERT(kIndex_8_SkColorType == this->colorType());
833 SkASSERT((
unsigned)x < (
unsigned)this->width() && (
unsigned)y < (
unsigned)this->height());
834 SkASSERT(fColorTable);
835 return (*fColorTable)[*((
const uint8_t*)fPixels + y * fRowBytes + x)];
size_t rowBytes() const
Return the number of bytes between subsequent rows of the bitmap.
Definition: SkBitmap.h:131
bool empty() const
Return true iff the bitmap has empty dimensions.
Definition: SkBitmap.h:118
int64_t computeSize64() const
Return the full size of the bitmap, in bytes.
Definition: SkBitmap.h:163
int shiftPerPixel() const
Return the shift amount per pixel (i.e.
Definition: SkBitmap.h:111
Definition: SkColorSpace.h:16
Describe an image's dimensions and pixel type.
Definition: SkImageInfo.h:181
void unlockPixels() const
When you are finished access the pixel memory, call this to balance a previous call to lockPixels()...
SkPixelRef * pixelRef() const
Return the current pixelref object or NULL if there is none.
Definition: SkBitmap.h:411
uint16_t * getAddr16(int x, int y) const
Returns the address of the pixel specified by x,y for 16bit pixels.
Definition: SkBitmap.h:816
SkColorTable holds an array SkPMColors (premultiplied 32-bit colors) used by 8-bit bitmaps...
Definition: SkColorTable.h:25
Subclass of Allocator that returns a pixelref that allocates its pixel memory from the heap...
Definition: SkBitmap.h:721
SkIPoint pixelRefOrigin() const
A bitmap can reference a subset of a pixelref's pixels.
Definition: SkBitmap.h:424
Pairs SkImageInfo with actual pixels and rowbytes.
Definition: SkPixmap.h:23
void * getPixels() const
Return the address of the pixels for this SkBitmap.
Definition: SkBitmap.h:146
Definition: SkRefCnt.h:135
The SkPaint class holds the style and color information about how to draw geometries, text and bitmaps.
Definition: SkPaint.h:46
SkColorTable * getColorTable() const
Return the bitmap's colortable, if it uses one (i.e.
Definition: SkBitmap.h:484
bool drawsNothing() const
Return true iff drawing this bitmap has no effect.
Definition: SkBitmap.h:128
bool installPixels(const SkImageInfo &info, void *pixels, size_t rowBytes)
Call installPixels with no ReleaseProc specified.
Definition: SkBitmap.h:308
SkMask is used to describe alpha bitmaps, either 1bit, 8bit, or the 3-channel 3D format.
Definition: SkMask.h:19
void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const
Fill the entire bitmap with the specified color.
Definition: SkBitmap.h:513
static SkImageInfo MakeN32(int width, int height, SkAlphaType at, sk_sp< SkColorSpace > cs=nullptr)
Sets colortype to the native ARGB32 type.
Definition: SkImageInfo.h:199
Concrete implementation that serializes to a flat binary blob.
Definition: SkWriteBuffer.h:68
size_t getSize() const
Return the byte size of the pixels, based on the height and rowBytes.
Definition: SkBitmap.h:152
bool isOpaque() const
Returns true if the bitmap is opaque (has no translucent/transparent pixels).
Definition: SkBitmap.h:191
The SkBitmap class specifies a raster bitmap.
Definition: SkBitmap.h:41
This class is the smart container for pixel memory, and is used with SkBitmap.
Definition: SkPixelRef.h:38
Definition: SkPixmap.h:209
The SkRegion class encapsulates the geometric region used to specify clipping areas for drawing...
Definition: SkRegion.h:30
bool readyToDraw() const
Call this to be sure that the bitmap is valid enough to be drawn (i.e.
Definition: SkBitmap.h:470
uint32_t SkPMColor
32 bit ARGB color value, premultiplied.
Definition: SkColor.h:147
uint8_t * getAddr8(int x, int y) const
Returns the address of the pixel specified by x,y for 8bit pixels.
Definition: SkBitmap.h:823
size_t getSafeSize() const
Return the number of bytes from the pointer returned by getPixels() to the end of the allocated space...
Definition: SkBitmap.h:158
int bytesPerPixel() const
Return the number of bytes per pixel based on the colortype.
Definition: SkBitmap.h:97
uint32_t SkColor
32 bit ARGB color value, not premultiplied.
Definition: SkColor.h:28
Definition: SkBitmap.h:786
#define SkColorSetARGB(a, r, g, b)
gcc will generate static initializers for code of this form: static const SkColor kMyColor = SkColorS...
Definition: SkColor.h:53
Definition: SkWriteBuffer.h:26
uint32_t * getAddr32(int x, int y) const
Returns the address of the pixel specified by x,y for 32bit pixels.
Definition: SkBitmap.h:809
int64_t computeSafeSize64() const
Return the number of bytes from the pointer returned by getPixels() to the end of the allocated space...
Definition: SkBitmap.h:172
Definition: SkPixelRef.h:394
int rowBytesAsPixels() const
Return the rowbytes expressed as a number of pixels (like width and height).
Definition: SkBitmap.h:103
SkIRect holds four 32 bit integer coordinates for a rectangle.
Definition: SkRect.h:20
bool isNull() const
Return true iff the bitmap has no pixelref.
Definition: SkBitmap.h:124
unsigned U8CPU
Fast type for unsigned 8 bits.
Definition: SkTypes.h:251
Definition: SkBitmap.h:726
Definition: GrTexture.h:19
SkIPoint holds two 32 bit integer coordinates.
Definition: SkPoint.h:40
bool SK_WARN_UNUSED_RESULT tryAllocPixels(SkColorTable *ctable=NULL)
Use the standard HeapAllocator to create the pixelref that manages the pixel memory.
Definition: SkBitmap.h:373
void lockPixels() const
Call this to ensure that the bitmap points to the current pixel address in the pixelref.
Light weight class for managing strings.
Definition: SkString.h:121
SkPMColor getIndex8Color(int x, int y) const
Returns the color corresponding to the pixel specified by x,y for colortable based bitmaps...
Definition: SkBitmap.h:830
Types and macros for colors.