aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-09 22:01:03 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-09 22:01:03 +0000
commit9230ea29718bcf1a92a89a1a518fb896bbbe00cf (patch)
tree153017a9ac43c57dd65b570beed5ab0ec92a32d1 /include
parent331e237890dcc044155b7015be2341134378bb4e (diff)
make info real in SkPixelRef, and add bitmap::asImageInfo
BUG= R=scroggo@google.com Review URL: https://codereview.chromium.org/108663004 git-svn-id: http://skia.googlecode.com/svn/trunk@12586 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include')
-rw-r--r--include/core/SkBitmap.h7
-rw-r--r--include/core/SkImage.h1
-rw-r--r--include/core/SkImageInfo.h23
-rw-r--r--include/core/SkPixelRef.h6
4 files changed, 35 insertions, 2 deletions
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h
index cd85b6a9b1..c0e299ab94 100644
--- a/include/core/SkBitmap.h
+++ b/include/core/SkBitmap.h
@@ -250,6 +250,13 @@ public:
bool setConfig(const SkImageInfo& info, size_t rowBytes = 0);
+ /**
+ * If the bitmap's config can be represented as SkImageInfo, return true,
+ * and if info is not-null, set it to the bitmap's info. If it cannot be
+ * represented as SkImageInfo, return false and ignore the info parameter.
+ */
+ bool asImageInfo(SkImageInfo* info) const;
+
/** 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.
diff --git a/include/core/SkImage.h b/include/core/SkImage.h
index accfc0db79..0bff589f48 100644
--- a/include/core/SkImage.h
+++ b/include/core/SkImage.h
@@ -41,6 +41,7 @@ public:
typedef SkColorType ColorType;
static const SkColorType kAlpha_8_ColorType = kAlpha_8_SkColorType;
+ static const SkColorType kARGB_4444_ColorType = kARGB_4444_SkColorType;
static const SkColorType kRGB_565_ColorType = kRGB_565_SkColorType;
static const SkColorType kRGBA_8888_ColorType = kRGBA_8888_SkColorType;
static const SkColorType kBGRA_8888_ColorType = kBGRA_8888_SkColorType;
diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h
index c22249b842..1165479f74 100644
--- a/include/core/SkImageInfo.h
+++ b/include/core/SkImageInfo.h
@@ -10,6 +10,9 @@
#include "SkTypes.h"
+class SkFlattenableWriteBuffer;
+class SkFlattenableReadBuffer;
+
/**
* Describes how to interpret the alpha compoent of a pixel.
*/
@@ -63,11 +66,12 @@ static inline bool SkAlphaTypeIsOpaque(SkAlphaType at) {
enum SkColorType {
kAlpha_8_SkColorType,
kRGB_565_SkColorType,
+ kARGB_4444_SkColorType,
kRGBA_8888_SkColorType,
kBGRA_8888_SkColorType,
- kIndex8_SkColorType,
+ kIndex_8_SkColorType,
- kLastEnum_SkColorType = kIndex8_SkColorType,
+ kLastEnum_SkColorType = kIndex_8_SkColorType,
#if SK_PMCOLOR_BYTE_ORDER(B,G,R,A)
kPMColor_SkColorType = kBGRA_8888_SkColorType
@@ -82,6 +86,7 @@ static int SkColorTypeBytesPerPixel(SkColorType ct) {
static const uint8_t gSize[] = {
1, // Alpha_8
2, // RGB_565
+ 2, // ARGB_4444
4, // RGBA_8888
4, // BGRA_8888
1, // kIndex_8
@@ -112,12 +117,26 @@ struct SkImageInfo {
return SkColorTypeBytesPerPixel(fColorType);
}
+ size_t minRowBytes() const {
+ return fWidth * this->bytesPerPixel();
+ }
+
bool operator==(const SkImageInfo& other) const {
return 0 == memcmp(this, &other, sizeof(other));
}
bool operator!=(const SkImageInfo& other) const {
return 0 != memcmp(this, &other, sizeof(other));
}
+
+ void unflatten(SkFlattenableReadBuffer&);
+ void flatten(SkFlattenableWriteBuffer&) const;
+
+ size_t getSafeSize(size_t rowBytes) const {
+ if (0 == fHeight) {
+ return 0;
+ }
+ return (fHeight - 1) * rowBytes + fWidth * this->bytesPerPixel();
+ }
};
#endif
diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h
index c4a7c4e33d..b87b0dc114 100644
--- a/include/core/SkPixelRef.h
+++ b/include/core/SkPixelRef.h
@@ -60,6 +60,10 @@ public:
SkPixelRef(const SkImageInfo&, SkBaseMutex* mutex);
virtual ~SkPixelRef();
+ const SkImageInfo& info() const {
+ return fInfo;
+ }
+
/** Return the pixel memory returned from lockPixels, or null if the
lockCount is 0.
*/
@@ -291,6 +295,8 @@ protected:
private:
SkBaseMutex* fMutex; // must remain in scope for the life of this object
+ SkImageInfo fInfo;
+
void* fPixels;
SkColorTable* fColorTable; // we do not track ownership, subclass does
int fLockCount;