OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 5 #include <algorithm> |
6 #include <iomanip> | 6 #include <iomanip> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "skia/ext/image_operations.h" | 12 #include "skia/ext/image_operations.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "third_party/skia/include/core/SkBitmap.h" | 14 #include "third_party/skia/include/core/SkBitmap.h" |
15 #include "third_party/skia/include/core/SkRect.h" | 15 #include "third_party/skia/include/core/SkRect.h" |
16 #include "ui/gfx/codec/png_codec.h" | 16 #include "ui/gfx/codec/png_codec.h" |
| 17 #include "ui/gfx/size.h" |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 // Computes the average pixel value for the given range, inclusive. | 21 // Computes the average pixel value for the given range, inclusive. |
21 uint32_t AveragePixel(const SkBitmap& bmp, | 22 uint32_t AveragePixel(const SkBitmap& bmp, |
22 int x_min, int x_max, | 23 int x_min, int x_max, |
23 int y_min, int y_max) { | 24 int y_min, int y_max) { |
24 float accum[4] = {0, 0, 0, 0}; | 25 float accum[4] = {0, 0, 0, 0}; |
25 int count = 0; | 26 int count = 0; |
26 for (int y = y_min; y <= y_max; y++) { | 27 for (int y = y_min; y <= y_max; y++) { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 // to check them visually. | 187 // to check them visually. |
187 #define DEBUG_BITMAP_GENERATION (0) | 188 #define DEBUG_BITMAP_GENERATION (0) |
188 | 189 |
189 #if DEBUG_BITMAP_GENERATION | 190 #if DEBUG_BITMAP_GENERATION |
190 void SaveBitmapToPNG(const SkBitmap& bmp, const char* path) { | 191 void SaveBitmapToPNG(const SkBitmap& bmp, const char* path) { |
191 SkAutoLockPixels lock(bmp); | 192 SkAutoLockPixels lock(bmp); |
192 std::vector<unsigned char> png; | 193 std::vector<unsigned char> png; |
193 gfx::PNGCodec::ColorFormat color_format = gfx::PNGCodec::FORMAT_RGBA; | 194 gfx::PNGCodec::ColorFormat color_format = gfx::PNGCodec::FORMAT_RGBA; |
194 if (!gfx::PNGCodec::Encode( | 195 if (!gfx::PNGCodec::Encode( |
195 reinterpret_cast<const unsigned char*>(bmp.getPixels()), | 196 reinterpret_cast<const unsigned char*>(bmp.getPixels()), |
196 color_format, bmp.width(), bmp.height(), | 197 color_format, gfx::Size(bmp.width(), bmp.height()), |
197 static_cast<int>(bmp.rowBytes()), | 198 static_cast<int>(bmp.rowBytes()), |
198 false, &png)) { | 199 false, std::vector<gfx::PNGCodec::Comment>(), &png)) { |
199 FAIL() << "Failed to encode image"; | 200 FAIL() << "Failed to encode image"; |
200 } | 201 } |
201 | 202 |
202 const FilePath fpath(path); | 203 const FilePath fpath(path); |
203 const int num_written = | 204 const int num_written = |
204 file_util::WriteFile(fpath, reinterpret_cast<const char*>(&png[0]), | 205 file_util::WriteFile(fpath, reinterpret_cast<const char*>(&png[0]), |
205 png.size()); | 206 png.size()); |
206 if (num_written != static_cast<int>(png.size())) { | 207 if (num_written != static_cast<int>(png.size())) { |
207 FAIL() << "Failed to write dest \"" << path << '"'; | 208 FAIL() << "Failed to write dest \"" << path << '"'; |
208 } | 209 } |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 ADD_FAILURE() << "Maximum observed color distance: " | 635 ADD_FAILURE() << "Maximum observed color distance: " |
635 << max_observed_distance; | 636 << max_observed_distance; |
636 | 637 |
637 #if DEBUG_BITMAP_GENERATION | 638 #if DEBUG_BITMAP_GENERATION |
638 SaveBitmapToPNG(src, "/tmp/CompareLanczosMethods_source.png"); | 639 SaveBitmapToPNG(src, "/tmp/CompareLanczosMethods_source.png"); |
639 SaveBitmapToPNG(dest_l2, "/tmp/CompareLanczosMethods_lanczos2.png"); | 640 SaveBitmapToPNG(dest_l2, "/tmp/CompareLanczosMethods_lanczos2.png"); |
640 SaveBitmapToPNG(dest_l3, "/tmp/CompareLanczosMethods_lanczos3.png"); | 641 SaveBitmapToPNG(dest_l3, "/tmp/CompareLanczosMethods_lanczos3.png"); |
641 #endif // #if DEBUG_BITMAP_GENERATION | 642 #endif // #if DEBUG_BITMAP_GENERATION |
642 } | 643 } |
643 } | 644 } |
OLD | NEW |