Chromium Code Reviews| Index: tests/PathUtilsTest.cpp |
| diff --git a/tests/PathUtilsTest.cpp b/tests/PathUtilsTest.cpp |
| index 1b497880b2b02c516876def92a03859686f22c16..fd429de9b6a242f5c561fcc7475c18fe720ed68d 100644 |
| --- a/tests/PathUtilsTest.cpp |
| +++ b/tests/PathUtilsTest.cpp |
| @@ -14,14 +14,12 @@ |
| #include "SkRandom.h" |
| #include "SkTime.h" |
|
robertphillips
2013/07/15 17:14:39
prefix all with SK_
dierk
2013/07/15 17:28:21
Done.
|
| -#define NUM_IT 1000 |
| +#define NUM_IT 100 |
|
robertphillips
2013/07/15 17:14:39
SK_ColorWHITE
dierk
2013/07/15 17:28:21
Done.
|
| #define ON 0xFF000000 // black pixel |
|
robertphillips
2013/07/15 17:14:39
SK_ColorWHITE
dierk
2013/07/15 17:28:21
Done.
|
| -#define OFF 0x00000000 // transparent pixel |
| +#define OFF 0xFFFFFFFF // white pixel |
| class SkBitmap; |
|
robertphillips
2013/07/15 17:14:39
fill_random_bits
dierk
2013/07/15 17:28:21
Done.
|
| -//this function is redefined for sample, test, and bench. is there anywhere |
| -// I can put it to avoid code duplcation? |
| static void fillRandomBits( int chars, char* bits ){ |
| SkMWCRandom rand(SkTime::GetMSecs()); |
| @@ -30,24 +28,49 @@ static void fillRandomBits( int chars, char* bits ){ |
| } |
| } |
|
robertphillips
2013/07/15 17:14:39
get_bit
dierk
2013/07/15 17:28:21
Done.
|
| -//also defined within PathUtils.cpp, but not in scope here. Anyway to call it |
| -// without re-defining it? |
| static int getBit( const char* buffer, int x ) { |
| int byte = x >> 3; |
| int bit = x & 7; |
| - return buffer[byte] & (1 << bit); |
| + return buffer[byte] & (128 >> bit); |
| } |
| +/* // useful for debugging errors |
| + #include <iostream> |
|
robertphillips
2013/07/15 17:14:39
print_bits
dierk
2013/07/15 17:28:21
Done.
|
| +static void printBits( const char* bits, int w, int h) { |
| + |
| + for (int y = 0; y < h; ++y) { |
| + for (int x = 0; x < w; ++x){ |
| + bool bit = getBit(&bits[y], x)!=0; |
| + std::cout << bit; |
|
robertphillips
2013/07/15 17:14:39
move } left
dierk
2013/07/15 17:28:21
Done.
|
| + } |
| + std::cout << std::endl; |
| + } |
| +} |
| + |
|
robertphillips
2013/07/15 17:14:39
print_bmp
dierk
2013/07/15 17:28:21
Done.
|
| +static void printBmp( SkBitmap* bmp, int w, int h){ |
| + |
| + for (int y = 0; y < h; ++y) { |
| + for (int x = 0; x < w; ++x) { |
| + int d = *bmp->getAddr32(x,y); |
| + if (d == -1) |
| + std::cout << 0; |
| + else |
| + std::cout << 1; |
| + } |
| + std::cout << std::endl; |
| + } |
| + } |
| +*/ |
|
robertphillips
2013/07/15 17:14:39
binary_to_skbitmap
dierk
2013/07/15 17:28:21
Done.
|
| static void bin2SkBitmap(const char* bin_bmp, SkBitmap* sk_bmp, |
| - int h, int w, int stride){ |
| + int h, int w, int rowBytes){ |
| //init the SkBitmap |
| sk_bmp->setConfig(SkBitmap::kARGB_8888_Config, w, h); |
| sk_bmp->allocPixels(); |
| for (int y = 0; y < h; ++y) { // for every row |
| - const char* curLine = &bin_bmp[y * stride]; |
| + const char* curLine = &bin_bmp[y * rowBytes]; |
| for (int x = 0; x < w; ++x) {// for every pixel |
| if (getBit(curLine, x)) { |
| *sk_bmp->getAddr32(x,y) = ON; |
| @@ -64,14 +87,14 @@ static bool test_bmp(skiatest::Reporter* reporter, |
| int h, int w) { |
| for (int y = 0; y < h; ++y) { // loop through all pixels |
| for (int x = 0; x < w; ++x) { |
| - REPORTER_ASSERT( reporter, *bmp1->getAddr32(x,y) == *bmp1->getAddr32(x,y) ); |
| + REPORTER_ASSERT( reporter, *bmp1->getAddr32(x,y) == *bmp2->getAddr32(x,y) ); |
| } |
| } |
| return true; |
| } |
| static void test_path_eq(skiatest::Reporter* reporter, const SkPath* path, |
| - const SkBitmap* truth, int h, int w){ |
| + const SkBitmap* truth, int w, int h){ |
| // make paint |
| SkPaint bmpPaint; |
| bmpPaint.setAntiAlias(true); // Black paint for bitmap |
| @@ -82,55 +105,56 @@ static void test_path_eq(skiatest::Reporter* reporter, const SkPath* path, |
| SkBitmap bmp; |
| bmp.setConfig(SkBitmap::kARGB_8888_Config, w, h); |
| bmp.allocPixels(); |
| - SkCanvas(bmp).drawPath(*path, bmpPaint); |
| + SkCanvas canvas(bmp); |
|
robertphillips
2013/07/15 17:14:39
SK_ColorWHITE
dierk
2013/07/15 17:28:21
Done.
|
| + canvas.clear(0xFFFFFFFF); |
| + canvas.drawPath(*path, bmpPaint); |
| // test bmp |
| - test_bmp(reporter, &bmp, truth, h, w); |
| + test_bmp(reporter, truth, &bmp, h, w); |
| } |
| static void test_path(skiatest::Reporter* reporter, const SkBitmap* truth, |
| - const char* bin_bmp, int h, int w, int stride){ |
| + const char* bin_bmp, int w, int h, int stride){ |
| // make path |
| SkPath path; |
| - SkPathUtils::BitsToPath_Path(&path, bin_bmp, h, w, stride); |
| + SkPathUtils::BitsToPath_Path(&path, bin_bmp, w, h, stride); |
| //test for correctness |
| - test_path_eq(reporter, &path, truth, h, w); |
| + test_path_eq(reporter, &path, truth, w, h); |
| } |
| static void test_region(skiatest::Reporter* reporter, const SkBitmap* truth, |
| - const char* bin_bmp, int h, int w, int stride){ |
| + const char* bin_bmp, int w, int h, int stride){ |
| //generate bitmap |
| SkPath path; |
| - SkPathUtils::BitsToPath_Region(&path, bin_bmp, h, w, stride); |
| + SkPathUtils::BitsToPath_Region(&path, bin_bmp, w, h, stride); |
| //test for correctness |
| - test_path_eq(reporter, &path, truth, h, w); |
| + test_path_eq(reporter, &path, truth, w, h); |
| } |
| -#define W_tests 4 |
| - |
| static void TestPathUtils(skiatest::Reporter* reporter) { |
|
robertphillips
2013/07/15 17:14:39
I would remove the 4
dierk
2013/07/15 17:28:21
Done.
|
| - const int w[W_tests] = {4, 8, 12, 16}; |
| - const int h = 8, stride = 4; |
| + const int w[4] = {4, 8, 12, 16}; |
| +// const int w[1] = {8}; |
| + const int h = 8, rowBytes = 4; |
| - char bits[ h * stride ]; |
| + char bits[ h * rowBytes ]; |
| static char* bin_bmp = &bits[0]; |
| //loop to run randomized test lots of times |
| for (int it = 0; it < NUM_IT; ++it) |
| { |
| // generate a random binary bitmap |
| - fillRandomBits( h * stride, bin_bmp); // generate random bitmap |
| + fillRandomBits( h * rowBytes, bin_bmp); // generate random bitmap |
| // for each bitmap width, use subset of binary bitmap |
| - for (int i = 0; i < W_tests; ++i) { |
| + for (uint i = 0; i < SK_ARRAY_COUNT(w); ++i) { |
| // generate truth bitmap |
| SkBitmap bmpTruth; |
| - bin2SkBitmap(bin_bmp, &bmpTruth, h, w[i], stride); |
| + bin2SkBitmap(bin_bmp, &bmpTruth, h, w[i], rowBytes); |
| - test_path(reporter, &bmpTruth, bin_bmp, h, w[i], stride); |
| - test_region(reporter, &bmpTruth, bin_bmp, h, w[i], stride); |
| + test_path(reporter, &bmpTruth, bin_bmp, w[i], h, rowBytes); |
| + test_region(reporter, &bmpTruth, bin_bmp, w[i], h, rowBytes); |
| } |
| } |
| } |