#ifndef SkImageInfo_DEFINED
#define SkImageInfo_DEFINED
-#include "SkTypes.h"
+#include "SkMath.h"
#include "SkSize.h"
-class SkFlattenableWriteBuffer;
-class SkFlattenableReadBuffer;
+class SkWriteBuffer;
+class SkReadBuffer;
/**
* Describes how to interpret the alpha compoent of a pixel.
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,
static int SkColorTypeBytesPerPixel(SkColorType ct) {
static const uint8_t gSize[] = {
+ 0, // Unknown
1, // Alpha_8
2, // RGB_565
2, // ARGB_4444
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;
+}
+
///////////////////////////////////////////////////////////////////////////////
/**
SkAlphaType fAlphaType;
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at) {
- SkASSERT(width >= 0);
- SkASSERT(height >= 0);
SkImageInfo info = {
width, height, ct, at
};
* Sets colortype to the native ARGB32 type.
*/
static SkImageInfo MakeN32(int width, int height, SkAlphaType at) {
- SkASSERT(width >= 0);
- SkASSERT(height >= 0);
SkImageInfo info = {
width, height, kPMColor_SkColorType, at
};
* Sets colortype to the native ARGB32 type, and the alphatype to premul.
*/
static SkImageInfo MakeN32Premul(int width, int height) {
- SkASSERT(width >= 0);
- SkASSERT(height >= 0);
SkImageInfo info = {
width, height, kPMColor_SkColorType, kPremul_SkAlphaType
};
}
static SkImageInfo MakeA8(int width, int height) {
- SkASSERT(width >= 0);
- SkASSERT(height >= 0);
SkImageInfo info = {
width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType
};
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));
}
- void unflatten(SkFlattenableReadBuffer&);
- void flatten(SkFlattenableWriteBuffer&) const;
+ 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