summaryrefslogtreecommitdiffstats
path: root/base/gfx
diff options
context:
space:
mode:
authorglen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-07 17:36:23 +0000
committerglen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-07 17:36:23 +0000
commitd1ae85447a12e97b0758b0d113a12e2d6c6d09b4 (patch)
tree29425393ad85ca17102ea0b8570a44087e23f03a /base/gfx
parent1dbba251922baea90369abe9fdf239e693afb813 (diff)
downloadchromium_src-d1ae85447a12e97b0758b0d113a12e2d6c6d09b4.zip
chromium_src-d1ae85447a12e97b0758b0d113a12e2d6c6d09b4.tar.gz
chromium_src-d1ae85447a12e97b0758b0d113a12e2d6c6d09b4.tar.bz2
Fix retarded bitmath. << 8 != * 255
BUG=13360 Review URL: http://codereview.chromium.org/149164 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20040 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/gfx')
-rw-r--r--base/gfx/png_decoder.cc8
-rw-r--r--base/gfx/png_encoder.cc8
2 files changed, 10 insertions, 6 deletions
diff --git a/base/gfx/png_decoder.cc b/base/gfx/png_decoder.cc
index bd6beb4..fe0bf893 100644
--- a/base/gfx/png_decoder.cc
+++ b/base/gfx/png_decoder.cc
@@ -329,10 +329,12 @@ bool PNGDecoder::Decode(const std::vector<unsigned char>* data,
for (int i = width * height * 4 - 4; i >= 0; i -= 4) {
unsigned char alpha = decoded_data[i + 3];
if (alpha != 0 && alpha != 255) {
+ SkColor premultiplied = SkPreMultiplyARGB(alpha,
+ decoded_data[i], decoded_data[i + 1], decoded_data[i + 2]);
bitmap_data[i + 3] = alpha;
- bitmap_data[i] = (decoded_data[i] * alpha) >> 8;
- bitmap_data[i + 1] = (decoded_data[i + 1] * alpha) >> 8;
- bitmap_data[i + 2] = (decoded_data[i + 2] * alpha) >> 8;
+ bitmap_data[i] = SkColorGetR(premultiplied);
+ bitmap_data[i + 1] = SkColorGetG(premultiplied);
+ bitmap_data[i + 2] = SkColorGetB(premultiplied);
} else {
bitmap_data[i + 3] = alpha;
bitmap_data[i] = decoded_data[i];
diff --git a/base/gfx/png_encoder.cc b/base/gfx/png_encoder.cc
index f8b4bf0..c342736 100644
--- a/base/gfx/png_encoder.cc
+++ b/base/gfx/png_encoder.cc
@@ -7,6 +7,7 @@
#include "base/logging.h"
#include "base/scoped_ptr.h"
#include "third_party/skia/include/core/SkBitmap.h"
+#include "third_party/skia/include/core/SkUnPreMultiply.h"
extern "C" {
#include "third_party/libpng/png.h"
@@ -214,9 +215,10 @@ bool PNGEncoder::EncodeBGRASkBitmap(const SkBitmap& input,
int alpha = SkColorGetA(pixel);
if (alpha != 0 && alpha != 255) {
- divided[i + 0] = (SkColorGetR(pixel) << 8) / alpha;
- divided[i + 1] = (SkColorGetG(pixel) << 8) / alpha;
- divided[i + 2] = (SkColorGetB(pixel) << 8) / alpha;
+ SkColor unmultiplied = SkUnPreMultiply::PMColorToColor(pixel);
+ divided[i + 0] = SkColorGetR(unmultiplied);
+ divided[i + 1] = SkColorGetG(unmultiplied);
+ divided[i + 2] = SkColorGetB(unmultiplied);
divided[i + 3] = alpha;
} else {
divided[i + 0] = SkColorGetR(pixel);