diff options
author | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-04 22:14:15 +0000 |
---|---|---|
committer | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-04 22:14:15 +0000 |
commit | 995638aaf5f35361d6b98f9c0b313c26ae79deb7 (patch) | |
tree | 17119505693f248d9dee0155874103ad4456a3ad /base/gfx | |
parent | 49a86767be2cc06e412a1167f38d96e238fbcc88 (diff) | |
download | chromium_src-995638aaf5f35361d6b98f9c0b313c26ae79deb7.zip chromium_src-995638aaf5f35361d6b98f9c0b313c26ae79deb7.tar.gz chromium_src-995638aaf5f35361d6b98f9c0b313c26ae79deb7.tar.bz2 |
Twiddle some bits to get PNGEncoder to match ImageOperations. There's a Valgrind error that doesn't yet make sense.
BUG=none
TEST=none
TBR=willchan
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17680 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/gfx')
-rw-r--r-- | base/gfx/png_encoder.cc | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/base/gfx/png_encoder.cc b/base/gfx/png_encoder.cc index 5e364d5..9d93fe6 100644 --- a/base/gfx/png_encoder.cc +++ b/base/gfx/png_encoder.cc @@ -201,29 +201,36 @@ bool PNGEncoder::EncodeBGRASkBitmap(const SkBitmap& input, // This only works with images with four bytes per pixel. static const int bbp = 4; - DCHECK(input.empty() || input.bytesPerPixel() == bbp); + DCHECK(!input.empty()); + DCHECK(input.bytesPerPixel() == bbp); + DCHECK(input.config() == SkBitmap::kARGB_8888_Config); // SkBitmaps are premultiplied, we need to unpremultiply them. scoped_array<unsigned char> divided( new unsigned char[input.width() * input.height() * bbp]); SkAutoLockPixels lock_input(input); + int i = 0; for (int y = 0; y < input.height(); y++) { uint32* src_row = input.getAddr32(0, y); + for (int x = 0; x < input.width(); x++) { - int alpha = SkColorGetA(src_row[x]); + uint32 pixel = src_row[x]; + int alpha = SkColorGetA(pixel); + if (alpha != 0 && alpha != 255) { - divided[i + 0] = (SkColorGetR(src_row[x]) << 8) / alpha; - divided[i + 1] = (SkColorGetG(src_row[x]) << 8) / alpha; - divided[i + 2] = (SkColorGetB(src_row[x]) << 8) / alpha; + divided[i + 0] = (SkColorGetR(pixel) << 8) / alpha; + divided[i + 1] = (SkColorGetG(pixel) << 8) / alpha; + divided[i + 2] = (SkColorGetB(pixel) << 8) / alpha; divided[i + 3] = alpha; } else { - divided[i + 0] = SkColorGetR(src_row[x]); - divided[i + 1] = SkColorGetG(src_row[x]); - divided[i + 2] = SkColorGetB(src_row[x]); - divided[i + 3] = SkColorGetA(src_row[x]); + divided[i + 0] = SkColorGetR(pixel); + divided[i + 1] = SkColorGetG(pixel); + divided[i + 2] = SkColorGetB(pixel); + divided[i + 3] = SkColorGetA(pixel); } + i += bbp; } } |