diff options
Diffstat (limited to 'include/core')
-rw-r--r-- | include/core/SkBitmap.h | 24 | ||||
-rw-r--r-- | include/core/SkImageInfo.h | 67 |
2 files changed, 49 insertions, 42 deletions
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h index c58c78d764..4e512c0535 100644 --- a/include/core/SkBitmap.h +++ b/include/core/SkBitmap.h @@ -78,10 +78,10 @@ public: const SkImageInfo& info() const { return fInfo; } - int width() const { return fInfo.fWidth; } - int height() const { return fInfo.fHeight; } - SkColorType colorType() const { return fInfo.fColorType; } - SkAlphaType alphaType() const { return fInfo.fAlphaType; } + int width() const { return fInfo.width(); } + int height() const { return fInfo.height(); } + SkColorType colorType() const { return fInfo.colorType(); } + SkAlphaType alphaType() const { return fInfo.alphaType(); } /** * Return the number of bytes per pixel based on the colortype. If the colortype is @@ -142,7 +142,7 @@ public: Note this truncates the result to 32bits. Call getSize64() to detect if the real size exceeds 32bits. */ - size_t getSize() const { return fInfo.fHeight * fRowBytes; } + size_t getSize() const { return fInfo.height() * fRowBytes; } /** Return the number of bytes from the pointer returned by getPixels() to the end of the allocated space in the buffer. Required in @@ -154,7 +154,7 @@ public: * Return the full size of the bitmap, in bytes. */ int64_t computeSize64() const { - return sk_64_mul(fInfo.fHeight, fRowBytes); + return sk_64_mul(fInfo.height(), fRowBytes); } /** @@ -264,18 +264,14 @@ public: } bool SK_WARN_UNUSED_RESULT tryAllocN32Pixels(int width, int height, bool isOpaque = false) { - SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); - if (isOpaque) { - info.fAlphaType = kOpaque_SkAlphaType; - } + SkImageInfo info = SkImageInfo::MakeN32(width, height, + isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); return this->tryAllocPixels(info); } SK_ALLOCPIXELS_RETURN_TYPE allocN32Pixels(int width, int height, bool isOpaque = false) { - SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); - if (isOpaque) { - info.fAlphaType = kOpaque_SkAlphaType; - } + SkImageInfo info = SkImageInfo::MakeN32(width, height, + isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); return this->allocPixels(info); } diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h index 3d82dc805c..6204cb3b81 100644 --- a/include/core/SkImageInfo.h +++ b/include/core/SkImageInfo.h @@ -136,36 +136,30 @@ bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType, * Describe an image's dimensions and pixel type. */ struct SkImageInfo { - int fWidth; - int fHeight; - SkColorType fColorType; - SkAlphaType fAlphaType; +public: + SkImageInfo() + : fWidth(0) + , fHeight(0) + , fColorType(kUnknown_SkColorType) + , fAlphaType(kIgnore_SkAlphaType) + {} static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at) { - SkImageInfo info = { - width, height, ct, at - }; - return info; + return SkImageInfo(width, height, ct, at); } /** * Sets colortype to the native ARGB32 type. */ static SkImageInfo MakeN32(int width, int height, SkAlphaType at) { - SkImageInfo info = { - width, height, kN32_SkColorType, at - }; - return info; + return SkImageInfo(width, height, kN32_SkColorType, at); } /** * Sets colortype to the native ARGB32 type, and the alphatype to premul. */ static SkImageInfo MakeN32Premul(int width, int height) { - SkImageInfo info = { - width, height, kN32_SkColorType, kPremul_SkAlphaType - }; - return info; + return SkImageInfo(width, height, kN32_SkColorType, kPremul_SkAlphaType); } /** @@ -176,24 +170,15 @@ struct SkImageInfo { } static SkImageInfo MakeA8(int width, int height) { - SkImageInfo info = { - width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType - }; - return info; + return SkImageInfo(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType); } static SkImageInfo MakeUnknown(int width, int height) { - SkImageInfo info = { - width, height, kUnknown_SkColorType, kIgnore_SkAlphaType - }; - return info; + return SkImageInfo(width, height, kUnknown_SkColorType, kIgnore_SkAlphaType); } static SkImageInfo MakeUnknown() { - SkImageInfo info = { - 0, 0, kUnknown_SkColorType, kIgnore_SkAlphaType - }; - return info; + return SkImageInfo(); } int width() const { return fWidth; } @@ -217,6 +202,14 @@ struct SkImageInfo { return SkImageInfo::Make(newWidth, newHeight, fColorType, fAlphaType); } + SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const { + return SkImageInfo::Make(fWidth, fHeight, fColorType, newAlphaType); + } + + SkImageInfo makeColorType(SkColorType newColorType) const { + return SkImageInfo::Make(fWidth, fHeight, newColorType, fAlphaType); + } + int bytesPerPixel() const { return SkColorTypeBytesPerPixel(fColorType); } @@ -256,6 +249,24 @@ struct SkImageInfo { } SkDEBUGCODE(void validate() const;) + +#ifdef SK_SUPPORT_LEGACY_PUBLIC_IMAGEINFO_FIELDS +public: +#else +private: +#endif + int fWidth; + int fHeight; + SkColorType fColorType; + SkAlphaType fAlphaType; + +private: + SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at) + : fWidth(width) + , fHeight(height) + , fColorType(ct) + , fAlphaType(at) + {} }; #endif |