aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ports
diff options
context:
space:
mode:
Diffstat (limited to 'src/ports')
-rw-r--r--src/ports/SkImageDecoder_WIC.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/ports/SkImageDecoder_WIC.cpp b/src/ports/SkImageDecoder_WIC.cpp
index 79d107adec..5a36ace56a 100644
--- a/src/ports/SkImageDecoder_WIC.cpp
+++ b/src/ports/SkImageDecoder_WIC.cpp
@@ -17,6 +17,7 @@
#include "SkMovie.h"
#include "SkStream.h"
#include "SkTScopedComPtr.h"
+#include "SkUnPreMultiply.h"
class SkImageDecoder_WIC : public SkImageDecoder {
protected:
@@ -134,6 +135,9 @@ bool SkImageDecoder_WIC::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
stride * height,
reinterpret_cast<BYTE *>(bm->getPixels())
);
+
+ // Note: we don't need to premultiply here since we specified PBGRA
+ bm->computeAndSetOpaquePredicate();
}
return SUCCEEDED(hr);
@@ -183,7 +187,7 @@ bool SkImageEncoder_WIC::onEncode(SkWStream* stream
//Convert to 8888 if needed.
const SkBitmap* bitmap;
SkBitmap bitmapCopy;
- if (SkBitmap::kARGB_8888_Config == bitmapOrig.config()) {
+ if (SkBitmap::kARGB_8888_Config == bitmapOrig.config() && bitmapOrig.isOpaque()) {
bitmap = &bitmapOrig;
} else {
if (!bitmapOrig.copyTo(&bitmapCopy, SkBitmap::kARGB_8888_Config)) {
@@ -192,6 +196,23 @@ bool SkImageEncoder_WIC::onEncode(SkWStream* stream
bitmap = &bitmapCopy;
}
+ // We cannot use PBGRA so we need to unpremultiply ourselves
+ if (!bitmap->isOpaque()) {
+ SkAutoLockPixels alp(*bitmap);
+
+ uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap->getPixels());
+ for (int y = 0; y < bitmap->height(); ++y) {
+ for (int x = 0; x < bitmap->width(); ++x) {
+ uint8_t* bytes = pixels + y * bitmap->rowBytes() + x * bitmap->bytesPerPixel();
+
+ SkPMColor* src = reinterpret_cast<SkPMColor*>(bytes);
+ SkColor* dst = reinterpret_cast<SkColor*>(bytes);
+
+ *dst = SkUnPreMultiply::PMColorToColor(*src);
+ }
+ }
+ }
+
//Initialize COM.
SkAutoCoInitialize scopedCo;
if (!scopedCo.succeeded()) {