aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-11-07 18:30:18 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-11-07 18:30:18 +0000
commit2a7579d11796866b0026755ab52597d09f4509cc (patch)
tree786887dfa086b39139f8b7b37b6f0634d8db9eac /src
parent4a26d9d62a6d762a518c0ca08d43189916b75cf2 (diff)
CG imagedecoder never sets isOpaque, so add method to SkBitmap to compute that,
and call it from CG imagedecoder. Review URL: https://codereview.appspot.com/6816101 git-svn-id: http://skia.googlecode.com/svn/trunk@6334 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/core/SkBitmap.cpp75
-rw-r--r--src/ports/SkImageDecoder_CG.cpp3
2 files changed, 78 insertions, 0 deletions
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index faf6e0353d..458cb615e6 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -668,6 +668,81 @@ SkColor SkBitmap::getColor(int x, int y) const {
return 0;
}
+bool SkBitmap::ComputeIsOpaque(const SkBitmap& bm) {
+ SkAutoLockPixels alp(bm);
+ if (!bm.getPixels()) {
+ return false;
+ }
+
+ const int height = bm.height();
+ const int width = bm.width();
+
+ switch (bm.config()) {
+ case SkBitmap::kA1_Config: {
+ // TODO
+ } break;
+ case SkBitmap::kA8_Config: {
+ unsigned a = 0xFF;
+ for (int y = 0; y < height; ++y) {
+ const uint8_t* row = bm.getAddr8(0, y);
+ for (int x = 0; x < width; ++x) {
+ a &= row[x];
+ }
+ if (0xFF != a) {
+ return false;
+ }
+ }
+ return true;
+ } break;
+ case kRLE_Index8_Config:
+ case SkBitmap::kIndex8_Config: {
+ SkAutoLockColors alc(bm);
+ const SkPMColor* table = alc.colors();
+ if (!table) {
+ return false;
+ }
+ SkPMColor c = ~0;
+ for (int i = bm.getColorTable()->count() - 1; i >= 0; --i) {
+ c &= table[i];
+ }
+ return 0xFF == SkGetPackedA32(c);
+ } break;
+ case SkBitmap::kRGB_565_Config:
+ return true;
+ break;
+ case SkBitmap::kARGB_4444_Config: {
+ unsigned c = 0xFFFF;
+ for (int y = 0; y < height; ++y) {
+ const SkPMColor16* row = bm.getAddr16(0, y);
+ for (int x = 0; x < width; ++x) {
+ c &= row[x];
+ }
+ if (0xF != SkGetPackedA4444(c)) {
+ return false;
+ }
+ }
+ return true;
+ } break;
+ case SkBitmap::kARGB_8888_Config: {
+ SkPMColor c = ~0;
+ for (int y = 0; y < height; ++y) {
+ const SkPMColor* row = bm.getAddr32(0, y);
+ for (int x = 0; x < width; ++x) {
+ c &= row[x];
+ }
+ if (0xFF != SkGetPackedA32(c)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ default:
+ break;
+ }
+ return false;
+}
+
+
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/ports/SkImageDecoder_CG.cpp b/src/ports/SkImageDecoder_CG.cpp
index bcd3e3741c..ba7a89c91e 100644
--- a/src/ports/SkImageDecoder_CG.cpp
+++ b/src/ports/SkImageDecoder_CG.cpp
@@ -6,6 +6,7 @@
* found in the LICENSE file.
*/
+#include "SkColorPriv.h"
#include "SkImageDecoder.h"
#include "SkImageEncoder.h"
@@ -86,6 +87,8 @@ bool SkImageDecoder_CG::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
CGContextDrawImage(cg, CGRectMake(0, 0, width, height), image);
CGContextRelease(cg);
+ // since CGImage won't tell us if it is opaque, we have to compute it.
+ bm->computeAndSetOpaquePredicate();
bm->unlockPixels();
return true;
}