Commit d1ae8544 authored by glen@chromium.org's avatar glen@chromium.org

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
parent 1dbba251
......@@ -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];
......
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment