aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/core/SkBitmap.h6
-rw-r--r--include/core/SkImageInfo.h15
-rw-r--r--include/core/SkPixmap.h6
3 files changed, 27 insertions, 0 deletions
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h
index 7425eb03d5..5b4e1a6863 100644
--- a/include/core/SkBitmap.h
+++ b/include/core/SkBitmap.h
@@ -141,6 +141,12 @@ public:
*/
void* getPixels() const { return fPixels; }
+ /**
+ * 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); }
+
/** 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.
diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h
index f659bf7742..c47dbb28b1 100644
--- a/include/core/SkImageInfo.h
+++ b/include/core/SkImageInfo.h
@@ -315,6 +315,21 @@ public:
return sk_64_asS32(size);
}
+ /**
+ * 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());
return rowBytes >= rb;
diff --git a/include/core/SkPixmap.h b/include/core/SkPixmap.h
index aa43b3441f..8115756b91 100644
--- a/include/core/SkPixmap.h
+++ b/include/core/SkPixmap.h
@@ -229,6 +229,12 @@ public:
*/
size_t getSafeSize() const { return fInfo.getSafeSize(fRowBytes); }
+ /**
+ * 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
without alpha in each pixel; for other SkColorType, returns true if all