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
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h
index cd85b6a..c0e299a 100644
--- a/include/core/SkBitmap.h
+++ b/include/core/SkBitmap.h
@@ -250,6 +250,13 @@
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 accfc0d..0bff589 100644
--- a/include/core/SkImage.h
+++ b/include/core/SkImage.h
@@ -41,6 +41,7 @@
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 c22249b..1165479 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 @@
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 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 @@
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 c4a7c4e..b87b0dc 100644
--- a/include/core/SkPixelRef.h
+++ b/include/core/SkPixelRef.h
@@ -60,6 +60,10 @@
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 @@
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;