Remove colorType switches in SkBitmap and SkBitmapDevice

Bug: skia:
Change-Id: Ia82461153d7f263e7cda34dc9c98d588b3c5351c
Reviewed-on: https://skia-review.googlesource.com/c/167880
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2018-11-02 13:49:56 -04:00 committed by Skia Commit-Bot
parent ef1c83a0c5
commit 713d034375
2 changed files with 8 additions and 57 deletions

View File

@ -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;

View File

@ -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;
}