diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-10-21 14:00:07 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-10-21 14:00:07 +0000 |
commit | 383a697692cf46951fd451f6f4c3d03634a6a1cb (patch) | |
tree | a1dac6fe4fa0e4d34d032e70ff85503843ad39b8 /include/core | |
parent | c2eae4795478ab134a2315b1a9ff2c5de1d049e4 (diff) |
store SkAlphaType inside SkBitmap, on road to support unpremul
BUG=
R=bsalomon@google.com, scroggo@google.com
Review URL: https://codereview.chromium.org/25275004
git-svn-id: http://skia.googlecode.com/svn/trunk@11877 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core')
-rw-r--r-- | include/core/SkBitmap.h | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h index 07d2b95553..3e22069e60 100644 --- a/include/core/SkBitmap.h +++ b/include/core/SkBitmap.h @@ -11,6 +11,7 @@ #define SkBitmap_DEFINED #include "Sk64.h" +#include "SkAlpha.h" #include "SkColor.h" #include "SkColorTable.h" #include "SkPoint.h" @@ -130,6 +131,15 @@ public: */ int rowBytesAsPixels() const { return fRowBytes >> (fBytesPerPixel >> 1); } + SkAlphaType alphaType() const { return (SkAlphaType)fAlphaType; } + + /** + * Set the bitmap's alphaType, returning true on success. If false is + * returned, then the specified new alphaType is incompatible with the + * Config, and the current alphaType is unchanged. + */ + bool setAlphaType(SkAlphaType); + /** Return the address of the pixels for this SkBitmap. */ void* getPixels() const { return fPixels; } @@ -175,12 +185,16 @@ public: /** Returns true if the bitmap is opaque (has no translucent/transparent pixels). */ - bool isOpaque() const; + bool isOpaque() const { + return SkAlphaTypeIsOpaque(this->alphaType()); + } - /** Specify if this bitmap's pixels are all opaque or not. Is only meaningful for configs - that support per-pixel alpha (RGB32, A1, A8). - */ - void setIsOpaque(bool); + /** + * DEPRECATED: use setAlpahType() instead. + */ + void setIsOpaque(bool opaque) { + this->setAlphaType(opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); + } /** Returns true if the bitmap is volatile (i.e. should not be cached by devices.) */ @@ -232,13 +246,6 @@ public: static bool ComputeIsOpaque(const SkBitmap&); /** - * Calls ComputeIsOpaque, and passes its result to setIsOpaque(). - */ - void computeAndSetOpaquePredicate() { - this->setIsOpaque(ComputeIsOpaque(*this)); - } - - /** * Return the bitmap's bounds [0, 0, width, height] as an SkRect */ void getBounds(SkRect* bounds) const; @@ -248,7 +255,14 @@ public: ComputeRowBytes() is called to compute the optimal value. This resets any pixel/colortable ownership, just like reset(). */ - void setConfig(Config, int width, int height, size_t rowBytes = 0); + bool setConfig(Config, int width, int height, size_t rowBytes, SkAlphaType); + + bool setConfig(Config config, int width, int height, size_t rowBytes = 0) { + return this->setConfig(config, width, height, rowBytes, + kPremul_SkAlphaType); + } + + /** Use this to assign a new pixel address for an existing bitmap. This will automatically release any pixelref previously installed. Only call this if you are handling ownership/lifetime of the pixel memory. @@ -672,6 +686,7 @@ private: uint32_t fWidth; uint32_t fHeight; uint8_t fConfig; + uint8_t fAlphaType; uint8_t fFlags; uint8_t fBytesPerPixel; // based on config |