Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: base/gfx/png_encoder.cc

Issue 155227: Merge 20040 - Fix retarded bitmath. << 8 != * 255... (Closed) Base URL: svn://chrome-svn/chrome/branches/191/src/
Patch Set: Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/gfx/png_decoder.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:mergeinfo
Merged /branches/chrome_webkit_merge_branch/base/gfx/png_encoder.cc:r69-2775
Merged /trunk/src/base/gfx/png_encoder.cc:r20040
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/gfx/png_encoder.h" 6 #include "base/gfx/png_encoder.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "third_party/skia/include/core/SkBitmap.h" 9 #include "third_party/skia/include/core/SkBitmap.h"
10 #include "third_party/skia/include/core/SkUnPreMultiply.h"
10 11
11 extern "C" { 12 extern "C" {
12 #include "third_party/libpng/png.h" 13 #include "third_party/libpng/png.h"
13 } 14 }
14 15
15 namespace { 16 namespace {
16 17
17 // Converts BGRA->RGBA and RGBA->BGRA. 18 // Converts BGRA->RGBA and RGBA->BGRA.
18 void ConvertBetweenBGRAandRGBA(const unsigned char* input, int pixel_width, 19 void ConvertBetweenBGRAandRGBA(const unsigned char* input, int pixel_width,
19 unsigned char* output) { 20 unsigned char* output) {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 scoped_array<unsigned char> divided( 208 scoped_array<unsigned char> divided(
208 new unsigned char[input.width() * input.height() * bbp]); 209 new unsigned char[input.width() * input.height() * bbp]);
209 210
210 int i = 0; 211 int i = 0;
211 for (int y = 0; y < input.height(); y++) { 212 for (int y = 0; y < input.height(); y++) {
212 for (int x = 0; x < input.width(); x++) { 213 for (int x = 0; x < input.width(); x++) {
213 uint32 pixel = input.getAddr32(0, y)[x]; 214 uint32 pixel = input.getAddr32(0, y)[x];
214 215
215 int alpha = SkColorGetA(pixel); 216 int alpha = SkColorGetA(pixel);
216 if (alpha != 0 && alpha != 255) { 217 if (alpha != 0 && alpha != 255) {
217 divided[i + 0] = (SkColorGetR(pixel) << 8) / alpha; 218 SkColor unmultiplied = SkUnPreMultiply::PMColorToColor(pixel);
218 divided[i + 1] = (SkColorGetG(pixel) << 8) / alpha; 219 divided[i + 0] = SkColorGetR(unmultiplied);
219 divided[i + 2] = (SkColorGetB(pixel) << 8) / alpha; 220 divided[i + 1] = SkColorGetG(unmultiplied);
221 divided[i + 2] = SkColorGetB(unmultiplied);
220 divided[i + 3] = alpha; 222 divided[i + 3] = alpha;
221 } else { 223 } else {
222 divided[i + 0] = SkColorGetR(pixel); 224 divided[i + 0] = SkColorGetR(pixel);
223 divided[i + 1] = SkColorGetG(pixel); 225 divided[i + 1] = SkColorGetG(pixel);
224 divided[i + 2] = SkColorGetB(pixel); 226 divided[i + 2] = SkColorGetB(pixel);
225 divided[i + 3] = alpha; 227 divided[i + 3] = alpha;
226 } 228 }
227 i += bbp; 229 i += bbp;
228 } 230 }
229 } 231 }
230 232
231 return Encode(divided.get(), 233 return Encode(divided.get(),
232 PNGEncoder::FORMAT_RGBA, input.width(), input.height(), 234 PNGEncoder::FORMAT_RGBA, input.width(), input.height(),
233 input.width() * bbp, discard_transparency, output); 235 input.width() * bbp, discard_transparency, output);
234 } 236 }
OLDNEW
« no previous file with comments | « base/gfx/png_decoder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698