diff options
author | Hal Canary <halcanary@google.com> | 2016-12-07 15:24:59 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-12-07 21:44:39 +0000 |
commit | 58a769490a4593a93b08031365b88be7a5ecfa0e (patch) | |
tree | 62906a1b64a6a6a1db8ab56e137b66cd1a9e5c02 /src/core/SkPixmap.cpp | |
parent | e1f29c7b3c301ba8aa649ca8fb74237b4960fd4f (diff) |
SkBitmap::ComputeIsOpaque -> SkPixmap::computeIsOpaque
Motivation: Twice internal Skia clients have to do something awkward like this:
bool ComputeIsOpaque(const SkPixmap& pixmap) {
SkBitmap bm;
return bm.installPixels(pixmap) && SkBitmap::ComputeIsOpaque(bm);
}
Change-Id: I7263c06f754c1305ecb07c4c005d9cfb9d1f523d
Reviewed-on: https://skia-review.googlesource.com/5684
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'src/core/SkPixmap.cpp')
-rw-r--r-- | src/core/SkPixmap.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/core/SkPixmap.cpp b/src/core/SkPixmap.cpp index c73b918f1c..3e89af65ed 100644 --- a/src/core/SkPixmap.cpp +++ b/src/core/SkPixmap.cpp @@ -332,3 +332,82 @@ SkColor SkPixmap::getColor(int x, int y) const { return SkColorSetARGB(0, 0, 0, 0); } } + +bool SkPixmap::computeIsOpaque() const { + const int height = this->height(); + const int width = this->width(); + + switch (this->colorType()) { + case kAlpha_8_SkColorType: { + unsigned a = 0xFF; + for (int y = 0; y < height; ++y) { + const uint8_t* row = this->addr8(0, y); + for (int x = 0; x < width; ++x) { + a &= row[x]; + } + if (0xFF != a) { + return false; + } + } + return true; + } break; + case kIndex_8_SkColorType: { + const SkColorTable* ctable = this->ctable(); + if (nullptr == ctable) { + return false; + } + const SkPMColor* table = ctable->readColors(); + SkPMColor c = (SkPMColor)~0; + for (int i = ctable->count() - 1; i >= 0; --i) { + c &= table[i]; + } + return 0xFF == SkGetPackedA32(c); + } break; + case kRGB_565_SkColorType: + case kGray_8_SkColorType: + return true; + break; + case kARGB_4444_SkColorType: { + unsigned c = 0xFFFF; + for (int y = 0; y < height; ++y) { + const SkPMColor16* row = this->addr16(0, y); + for (int x = 0; x < width; ++x) { + c &= row[x]; + } + if (0xF != SkGetPackedA4444(c)) { + return false; + } + } + return true; + } break; + case kBGRA_8888_SkColorType: + case kRGBA_8888_SkColorType: { + SkPMColor c = (SkPMColor)~0; + for (int y = 0; y < height; ++y) { + const SkPMColor* row = this->addr32(0, y); + for (int x = 0; x < width; ++x) { + c &= row[x]; + } + if (0xFF != SkGetPackedA32(c)) { + return false; + } + } + return true; + } + case kRGBA_F16_SkColorType: { + const SkHalf* row = (const SkHalf*)this->addr(); + for (int y = 0; y < height; ++y) { + for (int x = 0; x < width; ++x) { + if (row[4 * x + 3] < SK_Half1) { + return false; + } + } + row += this->rowBytes() >> 1; + } + return true; + } + default: + break; + } + return false; +} |