diff options
author | 2014-02-11 02:20:17 +0000 | |
---|---|---|
committer | 2014-02-11 02:20:17 +0000 | |
commit | 169a0ed50a5e451711c341795572e7177a540a24 (patch) | |
tree | 57874a07c8cb6652cedd414e2ba8eed4d8e83d6c /include/core/SkImageInfo.h | |
parent | 7e90e8dbb96f2084f7dd4a6a20cb4b880b362438 (diff) |
SkBitmap now really stores SkImageInfo -- config is just a ruse
(edited) clone of https://codereview.chromium.org/159173004/
Review URL: https://codereview.chromium.org/159463003
git-svn-id: http://skia.googlecode.com/svn/trunk@13391 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core/SkImageInfo.h')
-rw-r--r-- | include/core/SkImageInfo.h | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h index 722ff27437..73b8b8c12c 100644 --- a/include/core/SkImageInfo.h +++ b/include/core/SkImageInfo.h @@ -8,7 +8,7 @@ #ifndef SkImageInfo_DEFINED #define SkImageInfo_DEFINED -#include "SkTypes.h" +#include "SkMath.h" #include "SkSize.h" class SkWriteBuffer; @@ -59,12 +59,17 @@ static inline bool SkAlphaTypeIsOpaque(SkAlphaType at) { return (unsigned)at <= kOpaque_SkAlphaType; } +static inline bool SkAlphaTypeIsValid(unsigned value) { + return value <= kLastEnum_SkAlphaType; +} + /////////////////////////////////////////////////////////////////////////////// /** * Describes how to interpret the components of a pixel. */ enum SkColorType { + kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, @@ -85,6 +90,7 @@ enum SkColorType { static int SkColorTypeBytesPerPixel(SkColorType ct) { static const uint8_t gSize[] = { + 0, // Unknown 1, // Alpha_8 2, // RGB_565 2, // ARGB_4444 @@ -99,6 +105,14 @@ static int SkColorTypeBytesPerPixel(SkColorType ct) { return gSize[ct]; } +static inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) { + return width * SkColorTypeBytesPerPixel(ct); +} + +static inline bool SkColorTypeIsValid(unsigned value) { + return value <= kLastEnum_SkColorType; +} + /////////////////////////////////////////////////////////////////////////////// /** @@ -159,18 +173,31 @@ struct SkImageInfo { return info; } + int width() const { return fWidth; } + int height() const { return fHeight; } + SkColorType colorType() const { return fColorType; } + SkAlphaType alphaType() const { return fAlphaType; } + + bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; } + bool isOpaque() const { return SkAlphaTypeIsOpaque(fAlphaType); } + SkISize dimensions() const { return SkISize::Make(fWidth, fHeight); } + int bytesPerPixel() const { return SkColorTypeBytesPerPixel(fColorType); } + uint64_t minRowBytes64() const { + return sk_64_mul(fWidth, this->bytesPerPixel()); + } + size_t minRowBytes() const { - return fWidth * this->bytesPerPixel(); + return (size_t)this->minRowBytes64(); } - + bool operator==(const SkImageInfo& other) const { return 0 == memcmp(this, &other, sizeof(other)); } @@ -181,12 +208,23 @@ struct SkImageInfo { void unflatten(SkReadBuffer&); void flatten(SkWriteBuffer&) const; - size_t getSafeSize(size_t rowBytes) const { + int64_t getSafeSize64(size_t rowBytes) const { if (0 == fHeight) { return 0; } - return (fHeight - 1) * rowBytes + fWidth * this->bytesPerPixel(); + return sk_64_mul(fHeight - 1, rowBytes) + fWidth * this->bytesPerPixel(); } + + size_t getSafeSize(size_t rowBytes) const { + return (size_t)this->getSafeSize64(rowBytes); + } + + bool validRowBytes(size_t rowBytes) const { + uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel()); + return rowBytes >= rb; + } + + SkDEBUGCODE(void validate() const;) }; #endif |