summaryrefslogtreecommitdiffstats
path: root/base/gfx/png_decoder.cc
diff options
context:
space:
mode:
Diffstat (limited to 'base/gfx/png_decoder.cc')
-rw-r--r--base/gfx/png_decoder.cc24
1 files changed, 21 insertions, 3 deletions
diff --git a/base/gfx/png_decoder.cc b/base/gfx/png_decoder.cc
index e493464..bd36c57 100644
--- a/base/gfx/png_decoder.cc
+++ b/base/gfx/png_decoder.cc
@@ -261,8 +261,8 @@ class PngReadStructDestroyer {
// static
bool PNGDecoder::Decode(const unsigned char* input, size_t input_size,
- ColorFormat format, std::vector<unsigned char>* output,
- int* w, int* h) {
+ ColorFormat format, std::vector<unsigned char>* output,
+ int* w, int* h) {
if (input_size < 8)
return false; // Input data too small to be a png
@@ -324,7 +324,25 @@ bool PNGDecoder::Decode(const std::vector<unsigned char>* data,
&decoded_data, &width, &height)) {
bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height);
bitmap->allocPixels();
- memcpy(bitmap->getPixels(), &decoded_data.front(), width * height * 4);
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ int pix = (y * height + x) * 4;
+ unsigned char alpha = decoded_data[pix + 3];
+ if (alpha != 0 && alpha != 255) {
+ bitmap->getAddr32(0, y)[x] = SkColorSetARGB(
+ alpha,
+ (decoded_data[pix + 2] * alpha) >> 8,
+ (decoded_data[pix + 1] * alpha) >> 8,
+ (decoded_data[pix] * alpha) >> 8);
+ } else {
+ bitmap->getAddr32(0, y)[x] = SkColorSetARGB(
+ alpha,
+ decoded_data[pix + 2],
+ decoded_data[pix + 1],
+ decoded_data[pix]);
+ }
+ }
+ }
return true;
}
return false;