diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-12-09 22:01:03 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-12-09 22:01:03 +0000 |
commit | 9230ea29718bcf1a92a89a1a518fb896bbbe00cf (patch) | |
tree | 153017a9ac43c57dd65b570beed5ab0ec92a32d1 /src/image | |
parent | 331e237890dcc044155b7015be2341134378bb4e (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 'src/image')
-rw-r--r-- | src/image/SkImagePriv.cpp | 52 | ||||
-rw-r--r-- | src/image/SkImagePriv.h | 7 |
2 files changed, 7 insertions, 52 deletions
diff --git a/src/image/SkImagePriv.cpp b/src/image/SkImagePriv.cpp index f1916c6c1c..1e24c48c5b 100644 --- a/src/image/SkImagePriv.cpp +++ b/src/image/SkImagePriv.cpp @@ -14,13 +14,16 @@ SkBitmap::Config SkImageInfoToBitmapConfig(const SkImageInfo& info) { case kAlpha_8_SkColorType: return SkBitmap::kA8_Config; + case kARGB_4444_SkColorType: + return SkBitmap::kARGB_4444_Config; + case kRGB_565_SkColorType: return SkBitmap::kRGB_565_Config; - + case kPMColor_SkColorType: return SkBitmap::kARGB_8888_Config; - case kIndex8_SkColorType: + case kIndex_8_SkColorType: return SkBitmap::kIndex8_Config; default: @@ -30,52 +33,9 @@ SkBitmap::Config SkImageInfoToBitmapConfig(const SkImageInfo& info) { return SkBitmap::kNo_Config; } -int SkImageBytesPerPixel(SkColorType ct) { - static const uint8_t gColorTypeBytesPerPixel[] = { - 1, // kAlpha_8_SkColorType - 2, // kRGB_565_SkColorType - 4, // kRGBA_8888_SkColorType - 4, // kBGRA_8888_SkColorType - 4, // kPMColor_SkColorType - 1, // kIndex8_SkColorType - }; - - SkASSERT((size_t)ct < SK_ARRAY_COUNT(gColorTypeBytesPerPixel)); - return gColorTypeBytesPerPixel[ct]; -} - -bool SkBitmapToImageInfo(const SkBitmap& bm, SkImageInfo* info) { - switch (bm.config()) { - case SkBitmap::kA8_Config: - info->fColorType = kAlpha_8_SkColorType; - break; - - case SkBitmap::kIndex8_Config: - info->fColorType = kIndex8_SkColorType; - break; - - case SkBitmap::kRGB_565_Config: - info->fColorType = kRGB_565_SkColorType; - break; - - case SkBitmap::kARGB_8888_Config: - info->fColorType = kPMColor_SkColorType; - break; - - default: - return false; - } - - info->fWidth = bm.width(); - info->fHeight = bm.height(); - info->fAlphaType = bm.isOpaque() ? kOpaque_SkAlphaType : - kPremul_SkAlphaType; - return true; -} - SkImage* SkNewImageFromBitmap(const SkBitmap& bm, bool canSharePixelRef) { SkImageInfo info; - if (!SkBitmapToImageInfo(bm, &info)) { + if (!bm.asImageInfo(&info)) { return NULL; } diff --git a/src/image/SkImagePriv.h b/src/image/SkImagePriv.h index 188b16d530..bf28f598c5 100644 --- a/src/image/SkImagePriv.h +++ b/src/image/SkImagePriv.h @@ -15,10 +15,6 @@ class SkPicture; extern SkBitmap::Config SkImageInfoToBitmapConfig(const SkImageInfo&); -extern int SkImageBytesPerPixel(SkColorType); - -extern bool SkBitmapToImageInfo(const SkBitmap&, SkImageInfo*); - // Call this if you explicitly want to use/share this pixelRef in the image extern SkImage* SkNewImageFromPixelRef(const SkImageInfo&, SkPixelRef*, size_t rowBytes); @@ -48,8 +44,7 @@ extern void SkImagePrivDrawPicture(SkCanvas*, SkPicture*, extern SkImage* SkNewImageFromPicture(const SkPicture*); static inline size_t SkImageMinRowBytes(const SkImageInfo& info) { - size_t rb = info.fWidth * SkImageBytesPerPixel(info.fColorType); - return SkAlign4(rb); + return SkAlign4(info.minRowBytes()); } // Given an image created from SkNewImageFromBitmap, return its pixelref. This |