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

Side by Side Diff: base/gfx/png_decoder.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 | « no previous file | base/gfx/png_encoder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Modified: svn:mergeinfo
Merged /trunk/src/base/gfx/png_decoder.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/gfx/png_decoder.h" 5 #include "base/gfx/png_decoder.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "third_party/skia/include/core/SkBitmap.h" 8 #include "third_party/skia/include/core/SkBitmap.h"
9 9
10 extern "C" { 10 extern "C" {
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 std::vector<unsigned char> decoded_data; 322 std::vector<unsigned char> decoded_data;
323 if (PNGDecoder::Decode(&data->front(), data->size(), PNGDecoder::FORMAT_BGRA, 323 if (PNGDecoder::Decode(&data->front(), data->size(), PNGDecoder::FORMAT_BGRA,
324 &decoded_data, &width, &height)) { 324 &decoded_data, &width, &height)) {
325 bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); 325 bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height);
326 bitmap->allocPixels(); 326 bitmap->allocPixels();
327 unsigned char* bitmap_data = 327 unsigned char* bitmap_data =
328 reinterpret_cast<unsigned char*>(bitmap->getAddr32(0, 0)); 328 reinterpret_cast<unsigned char*>(bitmap->getAddr32(0, 0));
329 for (int i = width * height * 4 - 4; i >= 0; i -= 4) { 329 for (int i = width * height * 4 - 4; i >= 0; i -= 4) {
330 unsigned char alpha = decoded_data[i + 3]; 330 unsigned char alpha = decoded_data[i + 3];
331 if (alpha != 0 && alpha != 255) { 331 if (alpha != 0 && alpha != 255) {
332 SkColor premultiplied = SkPreMultiplyARGB(alpha,
333 decoded_data[i], decoded_data[i + 1], decoded_data[i + 2]);
332 bitmap_data[i + 3] = alpha; 334 bitmap_data[i + 3] = alpha;
333 bitmap_data[i] = (decoded_data[i] * alpha) >> 8; 335 bitmap_data[i] = SkColorGetR(premultiplied);
334 bitmap_data[i + 1] = (decoded_data[i + 1] * alpha) >> 8; 336 bitmap_data[i + 1] = SkColorGetG(premultiplied);
335 bitmap_data[i + 2] = (decoded_data[i + 2] * alpha) >> 8; 337 bitmap_data[i + 2] = SkColorGetB(premultiplied);
336 } else { 338 } else {
337 bitmap_data[i + 3] = alpha; 339 bitmap_data[i + 3] = alpha;
338 bitmap_data[i] = decoded_data[i]; 340 bitmap_data[i] = decoded_data[i];
339 bitmap_data[i + 1] = decoded_data[i + 1]; 341 bitmap_data[i + 1] = decoded_data[i + 1];
340 bitmap_data[i + 2] = decoded_data[i + 2]; 342 bitmap_data[i + 2] = decoded_data[i + 2];
341 } 343 }
342 } 344 }
343 return true; 345 return true;
344 } 346 }
345 return false; 347 return false;
(...skipping 16 matching lines...) Expand all
362 } 364 }
363 bitmap_data[i + 3] = alpha; 365 bitmap_data[i + 3] = alpha;
364 bitmap_data[i] = (bgra[i] * alpha) >> 8; 366 bitmap_data[i] = (bgra[i] * alpha) >> 8;
365 bitmap_data[i + 1] = (bgra[i + 1] * alpha) >> 8; 367 bitmap_data[i + 1] = (bgra[i + 1] * alpha) >> 8;
366 bitmap_data[i + 2] = (bgra[i + 2] * alpha) >> 8; 368 bitmap_data[i + 2] = (bgra[i + 2] * alpha) >> 8;
367 } 369 }
368 370
369 bitmap->setIsOpaque(opaque); 371 bitmap->setIsOpaque(opaque);
370 return bitmap; 372 return bitmap;
371 } 373 }
OLDNEW
« no previous file with comments | « no previous file | base/gfx/png_encoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698