diff options
Diffstat (limited to 'include/core')
-rw-r--r-- | include/core/SkBitmap.h | 12 | ||||
-rw-r--r-- | include/core/SkImageInfo.h | 17 | ||||
-rw-r--r-- | include/core/SkPixmap.h | 8 |
3 files changed, 33 insertions, 4 deletions
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h index 7425eb03d5..cea50b8886 100644 --- a/include/core/SkBitmap.h +++ b/include/core/SkBitmap.h @@ -141,10 +141,13 @@ public: */ void* getPixels() const { return fPixels; } - /** Return the byte size of the pixels, based on the height and rowBytes. - Note this truncates the result to 32bits. Call getSize64() to detect - if the real size exceeds 32bits. - */ + /** + * Returns the size (in bytes) of the bitmap's image buffer. + * If the calculation overflows, or if the height is 0, this returns 0. + */ + size_t computeByteSize() const { return fInfo.computeByteSize(fRowBytes); } + +#ifdef SK_SUPPORT_LEGACY_SAFESIZE64 size_t getSize() const { return fInfo.height() * fRowBytes; } /** Return the number of bytes from the pointer returned by getPixels() @@ -168,6 +171,7 @@ public: int64_t computeSafeSize64() const { return fInfo.getSafeSize64(fRowBytes); } +#endif /** Returns true if this bitmap is marked as immutable, meaning that the contents of its pixels will not change for the lifetime of the bitmap. diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h index f659bf7742..e8a06cb0d1 100644 --- a/include/core/SkImageInfo.h +++ b/include/core/SkImageInfo.h @@ -300,6 +300,7 @@ public: void unflatten(SkReadBuffer&); void flatten(SkWriteBuffer&) const; +#ifdef SK_SUPPORT_LEGACY_SAFESIZE64 int64_t getSafeSize64(size_t rowBytes) const { if (0 == fHeight) { return 0; @@ -314,6 +315,22 @@ public: } return sk_64_asS32(size); } +#endif + + /** + * Returns the size (in bytes) of the image buffer that this info needs, given the specified + * rowBytes. The rowBytes must be >= this->minRowBytes(). + * If the calculation overflows, or if the height is 0, this returns 0. + */ + size_t computeByteSize(size_t rowBytes) const; + + /** + * Returns the minimum size (in bytes) of the image buffer that this info needs. + * If the calculation overflows, or if the height is 0, this returns 0. + */ + size_t computeMinByteSize() const { + return this->computeByteSize(this->minRowBytes()); + } bool validRowBytes(size_t rowBytes) const { uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel()); diff --git a/include/core/SkPixmap.h b/include/core/SkPixmap.h index aa43b3441f..f304bde933 100644 --- a/include/core/SkPixmap.h +++ b/include/core/SkPixmap.h @@ -206,6 +206,7 @@ public: */ int shiftPerPixel() const { return fInfo.shiftPerPixel(); } +#ifdef SK_SUPPORT_LEGACY_SAFESIZE64 /** Returns conservative memory required for pixel storage. Includes unused memory on last row when rowBytesAsPixels() exceeds width(). @@ -228,6 +229,13 @@ public: @return exact pixel storage size if size fits in signed 32 bits */ size_t getSafeSize() const { return fInfo.getSafeSize(fRowBytes); } +#endif + + /** + * Returns the size (in bytes) of the pixmap's image buffer. + * If the calculation overflows, or if the height is 0, this returns 0. + */ + size_t computeByteSize() const { return fInfo.computeByteSize(fRowBytes); } /** Returns true if all pixels are opaque. SkColorType determines how pixels are encoded, and whether pixel describes alpha. Returns true for SkColorType |