diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-07-16 16:36:47 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-07-16 16:36:47 +0000 |
commit | 40f960edc0fd141093ea942d9aa66fe67aad8ce7 (patch) | |
tree | 60da6b84e65b2788b69f68de6d794c863321b481 | |
parent | 8d0a524a4847bc7e1cc63a93b78922739466c201 (diff) |
Fixed PathUtils nits.
Fixed PathUtils nits
BUG=
R=robertphillips@google.com
Author: dierk@google.com
Review URL: https://chromiumcodereview.appspot.com/19392002
git-svn-id: http://skia.googlecode.com/svn/trunk@10108 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | tests/PathUtilsTest.cpp | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/tests/PathUtilsTest.cpp b/tests/PathUtilsTest.cpp index 3dec43943e..2c403e3743 100644 --- a/tests/PathUtilsTest.cpp +++ b/tests/PathUtilsTest.cpp @@ -14,13 +14,11 @@ #include "SkRandom.h" #include "SkTime.h" -#define NUM_IT 100 -#define ON 0xFF000000 // black pixel -#define OFF 0xFFFFFFFF // white pixel +#define SK_NUM_IT 100 class SkBitmap; -static void fillRandomBits( int chars, char* bits ){ +static void fill_random_bits( int chars, char* bits ){ SkMWCRandom rand(SkTime::GetMSecs()); for (int i = 0; i < chars; ++i){ @@ -28,7 +26,7 @@ static void fillRandomBits( int chars, char* bits ){ } } -static int getBit( const char* buffer, int x ) { +static int get_bit( const char* buffer, int x ) { int byte = x >> 3; int bit = x & 7; @@ -36,18 +34,18 @@ static int getBit( const char* buffer, int x ) { } /* // useful for debugging errors #include <iostream> -static void printBits( const char* bits, int w, int h) { +static void print_bits( 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; + bool bit = get_bit(&bits[y], x)!=0; std::cout << bit; } std::cout << std::endl; } } -static void printBmp( SkBitmap* bmp, int w, int h){ +static void print_bmp( SkBitmap* bmp, int w, int h){ for (int y = 0; y < h; ++y) { for (int x = 0; x < w; ++x) { @@ -56,14 +54,14 @@ static void printBmp( SkBitmap* bmp, int w, int h){ std::cout << 0; else std::cout << 1; - } + } std::cout << std::endl; } } */ -static void bin2SkBitmap(const char* bin_bmp, SkBitmap* sk_bmp, - int h, int w, int rowBytes){ +static void binary_to_skbitmap(const char* bin_bmp, SkBitmap* sk_bmp, + int w, int h, int rowBytes){ //init the SkBitmap sk_bmp->setConfig(SkBitmap::kARGB_8888_Config, w, h); sk_bmp->allocPixels(); @@ -72,11 +70,11 @@ static void bin2SkBitmap(const char* bin_bmp, SkBitmap* sk_bmp, 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; + if (get_bit(curLine, x)) { + *sk_bmp->getAddr32(x,y) = SK_ColorBLACK; } else { - *sk_bmp->getAddr32(x,y) = OFF; + *sk_bmp->getAddr32(x,y) = SK_ColorWHITE; } } } @@ -84,7 +82,7 @@ static void bin2SkBitmap(const char* bin_bmp, SkBitmap* sk_bmp, static bool test_bmp(skiatest::Reporter* reporter, const SkBitmap* bmp1, const SkBitmap* bmp2, - int h, int w) { + int w, int h) { 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) == *bmp2->getAddr32(x,y) ); @@ -106,55 +104,54 @@ static void test_path_eq(skiatest::Reporter* reporter, const SkPath* path, bmp.setConfig(SkBitmap::kARGB_8888_Config, w, h); bmp.allocPixels(); SkCanvas canvas(bmp); - canvas.clear(0xFFFFFFFF); + canvas.clear(SK_ColorWHITE); canvas.drawPath(*path, bmpPaint); // test bmp - test_bmp(reporter, truth, &bmp, h, w); + test_bmp(reporter, truth, &bmp, w, h); } static void test_path(skiatest::Reporter* reporter, const SkBitmap* truth, - const char* bin_bmp, int w, int h, int stride){ + const char* bin_bmp, int w, int h, int rowBytes){ // make path SkPath path; - SkPathUtils::BitsToPath_Path(&path, bin_bmp, w, h, stride); + SkPathUtils::BitsToPath_Path(&path, bin_bmp, w, h, rowBytes); //test for correctness test_path_eq(reporter, &path, truth, w, h); } static void test_region(skiatest::Reporter* reporter, const SkBitmap* truth, - const char* bin_bmp, int w, int h, int stride){ + const char* bin_bmp, int w, int h, int rowBytes){ //generate bitmap SkPath path; - SkPathUtils::BitsToPath_Region(&path, bin_bmp, w, h, stride); + SkPathUtils::BitsToPath_Region(&path, bin_bmp, w, h, rowBytes); //test for correctness test_path_eq(reporter, &path, truth, w, h); } static void TestPathUtils(skiatest::Reporter* reporter) { - const int w[4] = {4, 8, 12, 16}; -// const int w[1] = {8}; + const int w[] = {4, 8, 12, 16}; const int h = 8, rowBytes = 4; char bits[ h * rowBytes ]; - static char* bin_bmp = &bits[0]; + static char* binBmp = &bits[0]; //loop to run randomized test lots of times - for (int it = 0; it < NUM_IT; ++it) + for (int it = 0; it < SK_NUM_IT; ++it) { // generate a random binary bitmap - fillRandomBits( h * rowBytes, bin_bmp); // generate random bitmap + fill_random_bits( h * rowBytes, binBmp); // generate random bitmap // for each bitmap width, use subset of binary bitmap for (unsigned int i = 0; i < SK_ARRAY_COUNT(w); ++i) { // generate truth bitmap SkBitmap bmpTruth; - bin2SkBitmap(bin_bmp, &bmpTruth, h, w[i], rowBytes); + binary_to_skbitmap(binBmp, &bmpTruth, w[i], h, rowBytes); - test_path(reporter, &bmpTruth, bin_bmp, w[i], h, rowBytes); - test_region(reporter, &bmpTruth, bin_bmp, w[i], h, rowBytes); + test_path(reporter, &bmpTruth, binBmp, w[i], h, rowBytes); + test_region(reporter, &bmpTruth, binBmp, w[i], h, rowBytes); } } } |