| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |