diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp index 71e3ece134..f596688b09 100644 --- a/src/core/SkBitmap.cpp +++ b/src/core/SkBitmap.cpp @@ -382,34 +382,7 @@ void* SkBitmap::getAddr(int x, int y) const { char* base = (char*)this->getPixels(); if (base) { - base += y * this->rowBytes(); - switch (this->colorType()) { - case kRGBA_F32_SkColorType: - base += x << 4; - break; - case kRGBA_F16_SkColorType: - base += x << 3; - break; - case kRGB_888x_SkColorType: - case kRGBA_8888_SkColorType: - case kBGRA_8888_SkColorType: - case kRGB_101010x_SkColorType: - case kRGBA_1010102_SkColorType: - base += x << 2; - break; - case kARGB_4444_SkColorType: - case kRGB_565_SkColorType: - base += x << 1; - break; - case kAlpha_8_SkColorType: - case kGray_8_SkColorType: - base += x; - break; - default: - SkDEBUGFAIL("Can't return addr for config"); - base = nullptr; - break; - } + base += (y * this->rowBytes()) + (x << this->shiftPerPixel()); } return base; } @@ -420,12 +393,9 @@ void* SkBitmap::getAddr(int x, int y) const { void SkBitmap::erase(SkColor c, const SkIRect& area) const { SkDEBUGCODE(this->validate();) - switch (this->colorType()) { - case kUnknown_SkColorType: - // TODO: can we ASSERT that we never get here? - return; // can't erase. Should we bzero so the memory is not uninitialized? - default: - break; + if (kUnknown_SkColorType == this->colorType()) { + // TODO: can we ASSERT that we never get here? + return; // can't erase. Should we bzero so the memory is not uninitialized? } SkPixmap result; diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp index 8d16e640d5..ae96e80462 100644 --- a/src/core/SkBitmapDevice.cpp +++ b/src/core/SkBitmapDevice.cpp @@ -188,34 +188,15 @@ public: static bool valid_for_bitmap_device(const SkImageInfo& info, SkAlphaType* newAlphaType) { - if (info.width() < 0 || info.height() < 0) { + if (info.width() < 0 || info.height() < 0 || kUnknown_SkColorType == info.colorType()) { return false; } - SkAlphaType canonicalAlphaType = info.alphaType(); - - switch (info.colorType()) { - case kAlpha_8_SkColorType: - case kARGB_4444_SkColorType: - case kRGBA_8888_SkColorType: - case kBGRA_8888_SkColorType: - case kRGBA_1010102_SkColorType: - case kRGBA_F16_SkColorType: - case kRGBA_F32_SkColorType: - break; - case kGray_8_SkColorType: - case kRGB_565_SkColorType: - case kRGB_888x_SkColorType: - case kRGB_101010x_SkColorType: - canonicalAlphaType = kOpaque_SkAlphaType; - break; - default: - return false; - } - if (newAlphaType) { - *newAlphaType = canonicalAlphaType; + *newAlphaType = SkColorTypeIsAlwaysOpaque(info.colorType()) ? kOpaque_SkAlphaType + : info.alphaType(); } + return true; }