| 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/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 | 10 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 return true; | 194 return true; |
| 195 } | 195 } |
| 196 | 196 |
| 197 // static | 197 // static |
| 198 bool PNGEncoder::EncodeBGRASkBitmap(const SkBitmap& input, | 198 bool PNGEncoder::EncodeBGRASkBitmap(const SkBitmap& input, |
| 199 bool discard_transparency, | 199 bool discard_transparency, |
| 200 std::vector<unsigned char>* output) { | 200 std::vector<unsigned char>* output) { |
| 201 static const int bbp = 4; | 201 static const int bbp = 4; |
| 202 | 202 |
| 203 SkAutoLockPixels lock_input(input); | 203 SkAutoLockPixels lock_input(input); |
| 204 CHECK(!input.empty()); | 204 DCHECK(input.bytesPerPixel() == bbp); |
| 205 CHECK(input.bytesPerPixel() == bbp); | 205 DCHECK(input.getConfig() == SkBitmap::kARGB_8888_Config); |
| 206 CHECK(input.getConfig() == SkBitmap::kARGB_8888_Config); | 206 DCHECK(input.width() > 1 && input.height() > 1); |
| 207 CHECK(input.width() > 1 && input.height() > 1); | |
| 208 | 207 |
| 209 // SkBitmaps are premultiplied, we need to unpremultiply them. | 208 // SkBitmaps are premultiplied, we need to unpremultiply them. |
| 210 scoped_array<unsigned char> divided( | 209 scoped_array<unsigned char> divided( |
| 211 new unsigned char[input.width() * input.height() * bbp]); | 210 new unsigned char[input.width() * input.height() * bbp]); |
| 212 | 211 |
| 213 int i = 0; | 212 int i = 0; |
| 214 for (int y = 0; y < input.height(); y++) { | 213 for (int y = 0; y < input.height(); y++) { |
| 215 for (int x = 0; x < input.width(); x++) { | 214 for (int x = 0; x < input.width(); x++) { |
| 216 uint32 pixel = input.getAddr32(0, y)[x]; | 215 uint32 pixel = input.getAddr32(0, y)[x]; |
| 217 | 216 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 228 divided[i + 3] = alpha; | 227 divided[i + 3] = alpha; |
| 229 } | 228 } |
| 230 i += bbp; | 229 i += bbp; |
| 231 } | 230 } |
| 232 } | 231 } |
| 233 | 232 |
| 234 return Encode(divided.get(), | 233 return Encode(divided.get(), |
| 235 PNGEncoder::FORMAT_RGBA, input.width(), input.height(), | 234 PNGEncoder::FORMAT_RGBA, input.width(), input.height(), |
| 236 input.width() * bbp, discard_transparency, output); | 235 input.width() * bbp, discard_transparency, output); |
| 237 } | 236 } |
| OLD | NEW |