OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include <stdlib.h> | |
6 #include <time.h> | |
7 | |
8 #include "base/perftimer.h" | |
9 #include "base/gfx/convolver.h" | |
10 #include "base/gfx/image_operations.h" | |
11 #include "base/gfx/image_resizer.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
14 namespace { | |
15 | |
16 void FillRandomData(char* dest, int byte_count) { | |
17 srand(static_cast<unsigned>(time(NULL))); | |
18 for (int i = 0; i < byte_count; i++) | |
19 dest[i] = rand() * 255 / RAND_MAX; | |
20 } | |
21 | |
22 } // namespace | |
23 | |
24 // Old code gives [1521, 1519]ms for this, 4000x4000 -> 2100x2100 lanczos8 | |
25 | |
26 TEST(ImageResizePerf, BigFilter) { | |
27 static const int kSrcWidth = 4000; | |
28 static const int kSrcHeight = 4000; | |
29 static const int kSrcByteSize = kSrcWidth * kSrcHeight * 4; | |
30 | |
31 SkBitmap src_bmp; | |
32 src_bmp.setConfig(SkBitmap::kARGB_8888_Config, kSrcWidth, kSrcHeight); | |
33 src_bmp.allocPixels(); | |
34 FillRandomData(reinterpret_cast<char*>(src_bmp.getAddr32(0, 0)), | |
35 kSrcByteSize); | |
36 | |
37 // Make the dest size > 1/2 so the 50% optimization doesn't kick in. | |
38 static const int kDestWidth = 1400; | |
39 static const int kDestHeight = 1400; | |
40 | |
41 PerfTimeLogger resize_timer("resize"); | |
42 gfx::ImageResizer resizer(gfx::ImageResizer::LANCZOS3); | |
43 SkBitmap dest = resizer.Resize(src_bmp, kDestWidth, kDestHeight); | |
44 } | |
45 | |
46 // The original image filter we were using took 523ms for this test, while this | |
47 // one takes 857ms. | |
48 // TODO(brettw) make this at least 64% faster. | |
49 TEST(ImageOperationPerf, BigFilter) { | |
50 static const int kSrcWidth = 4000; | |
51 static const int kSrcHeight = 4000; | |
52 static const int kSrcByteSize = kSrcWidth * kSrcHeight * 4; | |
53 | |
54 SkBitmap src_bmp; | |
55 src_bmp.setConfig(SkBitmap::kARGB_8888_Config, kSrcWidth, kSrcHeight); | |
56 src_bmp.allocPixels(); | |
57 src_bmp.setIsOpaque(true); | |
58 FillRandomData(reinterpret_cast<char*>(src_bmp.getAddr32(0, 0)), | |
59 kSrcByteSize); | |
60 | |
61 // Make the dest size > 1/2 so the 50% optimization doesn't kick in. | |
62 static const int kDestWidth = 1400; | |
63 static const int kDestHeight = 1400; | |
64 | |
65 PerfTimeLogger resize_timer("resize"); | |
66 SkBitmap dest = gfx::ImageOperations::Resize(src_bmp, | |
67 gfx::ImageOperations::RESIZE_LANCZOS3, (float)kDestWidth / (float)kSrcWidt
h, | |
68 (float)kDestHeight / (float)kSrcHeight); | |
69 } | |
70 | |
OLD | NEW |