OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "Test.h" | 9 #include "SkPathUtils.h" |
10 | 10 |
11 #include "SkBitmap.h" | 11 #include "SkBitmap.h" |
12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
13 #include "SkPathUtils.h" | |
14 #include "SkRandom.h" | 13 #include "SkRandom.h" |
15 #include "SkTime.h" | 14 #include "SkTime.h" |
16 | 15 #include "Test.h" |
17 #define SK_NUM_IT 100 | |
18 | 16 |
19 class SkBitmap; | 17 class SkBitmap; |
tfarina
2013/07/16 18:08:50
you don't need this forward declaration, since you
| |
20 | 18 |
19 const int kNumIt = 100; | |
20 | |
21 static void fill_random_bits( int chars, char* bits ){ | 21 static void fill_random_bits( int chars, char* bits ){ |
tfarina
2013/07/16 18:08:50
micro-style-nit: no need of whitespace after ( and
| |
22 SkMWCRandom rand(SkTime::GetMSecs()); | 22 SkMWCRandom rand(SkTime::GetMSecs()); |
23 | 23 |
24 for (int i = 0; i < chars; ++i){ | 24 for (int i = 0; i < chars; ++i){ |
25 bits[i] = rand.nextU(); | 25 bits[i] = rand.nextU(); |
26 } | 26 } |
27 } | 27 } |
28 | 28 |
29 static int get_bit( const char* buffer, int x ) { | 29 static int get_bit( const char* buffer, int x ) { |
30 int byte = x >> 3; | 30 int byte = x >> 3; |
31 int bit = x & 7; | 31 int bit = x & 7; |
32 | 32 |
33 return buffer[byte] & (128 >> bit); | 33 return buffer[byte] & (128 >> bit); |
34 } | 34 } |
35 | |
35 /* // useful for debugging errors | 36 /* // useful for debugging errors |
36 #include <iostream> | 37 #include <iostream> |
tfarina
2013/07/16 18:08:50
can we move this include above?
Oh, looks like al
| |
37 static void print_bits( const char* bits, int w, int h) { | 38 static void print_bits( const char* bits, int w, int h) { |
38 | 39 |
39 for (int y = 0; y < h; ++y) { | 40 for (int y = 0; y < h; ++y) { |
40 for (int x = 0; x < w; ++x){ | 41 for (int x = 0; x < w; ++x){ |
41 bool bit = get_bit(&bits[y], x)!=0; | 42 bool bit = get_bit(&bits[y], x)!=0; |
42 std::cout << bit; | 43 std::cout << bit; |
43 } | 44 } |
44 std::cout << std::endl; | 45 std::cout << std::endl; |
45 } | 46 } |
46 } | 47 } |
47 | 48 |
48 static void print_bmp( SkBitmap* bmp, int w, int h){ | 49 static void print_bmp( SkBitmap* bmp, int w, int h){ |
49 | 50 |
50 for (int y = 0; y < h; ++y) { | 51 for (int y = 0; y < h; ++y) { |
51 for (int x = 0; x < w; ++x) { | 52 for (int x = 0; x < w; ++x) { |
52 int d = *bmp->getAddr32(x,y); | 53 int d = *bmp->getAddr32(x,y); |
53 if (d == -1) | 54 if (d == -1) |
54 std::cout << 0; | 55 std::cout << 0; |
55 else | 56 else |
56 std::cout << 1; | 57 std::cout << 1; |
57 } | 58 } |
58 std::cout << std::endl; | 59 std::cout << std::endl; |
59 } | 60 } |
60 } | 61 } |
61 */ | 62 */ |
62 | 63 |
63 static void binary_to_skbitmap(const char* bin_bmp, SkBitmap* sk_bmp, | 64 static void binary_to_skbitmap(const char* bin_bmp, SkBitmap* sk_bmp, |
64 int w, int h, int rowBytes){ | 65 int w, int h, int rowBytes){ |
65 //init the SkBitmap | 66 //init the SkBitmap |
66 sk_bmp->setConfig(SkBitmap::kARGB_8888_Config, w, h); | 67 sk_bmp->setConfig(SkBitmap::kARGB_8888_Config, w, h); |
67 sk_bmp->allocPixels(); | 68 sk_bmp->allocPixels(); |
68 | 69 |
69 for (int y = 0; y < h; ++y) { // for every row | 70 for (int y = 0; y < h; ++y) { // for every row |
70 | 71 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 } | 133 } |
133 | 134 |
134 static void TestPathUtils(skiatest::Reporter* reporter) { | 135 static void TestPathUtils(skiatest::Reporter* reporter) { |
135 const int w[] = {4, 8, 12, 16}; | 136 const int w[] = {4, 8, 12, 16}; |
136 const int h = 8, rowBytes = 4; | 137 const int h = 8, rowBytes = 4; |
137 | 138 |
138 char bits[ h * rowBytes ]; | 139 char bits[ h * rowBytes ]; |
139 static char* binBmp = &bits[0]; | 140 static char* binBmp = &bits[0]; |
140 | 141 |
141 //loop to run randomized test lots of times | 142 //loop to run randomized test lots of times |
142 for (int it = 0; it < SK_NUM_IT; ++it) | 143 for (int it = 0; it < kNumIt; ++it) |
143 { | 144 { |
144 // generate a random binary bitmap | 145 // generate a random binary bitmap |
145 fill_random_bits( h * rowBytes, binBmp); // generate random bitmap | 146 fill_random_bits( h * rowBytes, binBmp); // generate random bitmap |
146 | 147 |
147 // for each bitmap width, use subset of binary bitmap | 148 // for each bitmap width, use subset of binary bitmap |
148 for (unsigned int i = 0; i < SK_ARRAY_COUNT(w); ++i) { | 149 for (unsigned int i = 0; i < SK_ARRAY_COUNT(w); ++i) { |
149 // generate truth bitmap | 150 // generate truth bitmap |
150 SkBitmap bmpTruth; | 151 SkBitmap bmpTruth; |
151 binary_to_skbitmap(binBmp, &bmpTruth, w[i], h, rowBytes); | 152 binary_to_skbitmap(binBmp, &bmpTruth, w[i], h, rowBytes); |
152 | 153 |
153 test_path(reporter, &bmpTruth, binBmp, w[i], h, rowBytes); | 154 test_path(reporter, &bmpTruth, binBmp, w[i], h, rowBytes); |
154 test_region(reporter, &bmpTruth, binBmp, w[i], h, rowBytes); | 155 test_region(reporter, &bmpTruth, binBmp, w[i], h, rowBytes); |
155 } | 156 } |
156 } | 157 } |
157 } | 158 } |
158 | 159 |
159 #include "TestClassDef.h" | 160 #include "TestClassDef.h" |
160 DEFINE_TESTCLASS("PathUtils", PathUtils, TestPathUtils) | 161 DEFINE_TESTCLASS("PathUtils", PathUtils, TestPathUtils) |
OLD | NEW |