diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-11-25 20:54:56 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-11-25 20:54:56 +0000 |
commit | 72e7808d62c02f0371135b1c152bd00b73f62479 (patch) | |
tree | f5b334c1fa6ce8662458a59fc3f9039a73986e72 /tests | |
parent | aae7c2a5b7a11616879e6179357cf38f5bff53ae (diff) |
Revert "remove kA1_Config, as it is no longer supported"
This reverts commit 2d72d8b242eac6e9d30228f5b0a407236491c369.
git-svn-id: http://skia.googlecode.com/svn/trunk@12387 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r-- | tests/BitmapCopyTest.cpp | 68 | ||||
-rw-r--r-- | tests/BitmapGetColorTest.cpp | 63 | ||||
-rw-r--r-- | tests/BlitRowTest.cpp | 2 | ||||
-rw-r--r-- | tests/ImageDecodingTest.cpp | 2 |
4 files changed, 121 insertions, 14 deletions
diff --git a/tests/BitmapCopyTest.cpp b/tests/BitmapCopyTest.cpp index f61d55e953..5cef1eb986 100644 --- a/tests/BitmapCopyTest.cpp +++ b/tests/BitmapCopyTest.cpp @@ -15,7 +15,7 @@ static const char* boolStr(bool value) { // these are in the same order as the SkBitmap::Config enum static const char* gConfigName[] = { - "None", "A8", "Index8", "565", "4444", "8888" + "None", "A1", "A8", "Index8", "565", "4444", "8888", "RLE_Index8" }; static void report_opaqueness(skiatest::Reporter* reporter, const SkBitmap& src, @@ -57,6 +57,10 @@ static void init_src(const SkBitmap& bitmap) { if (bitmap.getPixels()) { if (bitmap.getColorTable()) { sk_bzero(bitmap.getPixels(), bitmap.getSize()); + } else if (SkBitmap::kA1_Config == bitmap.config()) { + // The A1 config can have uninitialized bits at the + // end of each row if eraseColor is used + memset(bitmap.getPixels(), 0xff, bitmap.getSafeSize()); } else { bitmap.eraseColor(SK_ColorWHITE); } @@ -88,7 +92,7 @@ struct Pair { static uint32_t getPixel(int x, int y, const SkBitmap& bm) { uint32_t val = 0; uint16_t val16; - uint8_t val8; + uint8_t val8, shift; SkAutoLockPixels lock(bm); const void* rawAddr = bm.getAddr(x,y); @@ -106,6 +110,11 @@ static uint32_t getPixel(int x, int y, const SkBitmap& bm) { memcpy(&val8, rawAddr, sizeof(uint8_t)); val = val8; break; + case SkBitmap::kA1_Config: + memcpy(&val8, rawAddr, sizeof(uint8_t)); + shift = x % 8; + val = (val8 >> shift) & 0x1 ; + break; default: break; } @@ -117,7 +126,7 @@ static uint32_t getPixel(int x, int y, const SkBitmap& bm) { // converted to, but at present uint32_t can handle all formats. static void setPixel(int x, int y, uint32_t val, SkBitmap& bm) { uint16_t val16; - uint8_t val8; + uint8_t val8, shift; SkAutoLockPixels lock(bm); void* rawAddr = bm.getAddr(x,y); @@ -135,6 +144,15 @@ static void setPixel(int x, int y, uint32_t val, SkBitmap& bm) { val8 = val & 0xFF; memcpy(rawAddr, &val8, sizeof(uint8_t)); break; + case SkBitmap::kA1_Config: + shift = x % 8; // We assume we're in the right byte. + memcpy(&val8, rawAddr, sizeof(uint8_t)); + if (val & 0x1) // Turn bit on. + val8 |= (0x1 << shift); + else // Turn bit off. + val8 &= ~(0x1 << shift); + memcpy(rawAddr, &val8, sizeof(uint8_t)); + break; default: // Ignore. break; @@ -146,6 +164,7 @@ static void setPixel(int x, int y, uint32_t val, SkBitmap& bm) { static const char* getSkConfigName(const SkBitmap& bm) { switch (bm.config()) { case SkBitmap::kNo_Config: return "SkBitmap::kNo_Config"; + case SkBitmap::kA1_Config: return "SkBitmap::kA1_Config"; case SkBitmap::kA8_Config: return "SkBitmap::kA8_Config"; case SkBitmap::kIndex8_Config: return "SkBitmap::kIndex8_Config"; case SkBitmap::kRGB_565_Config: return "SkBitmap::kRGB_565_Config"; @@ -206,12 +225,13 @@ static void writeCoordPixels(SkBitmap& bm, const Coordinates& coords) { static void TestBitmapCopy(skiatest::Reporter* reporter) { static const Pair gPairs[] = { - { SkBitmap::kNo_Config, "0000000" }, - { SkBitmap::kA8_Config, "0101010" }, - { SkBitmap::kIndex8_Config, "0111010" }, - { SkBitmap::kRGB_565_Config, "0101010" }, - { SkBitmap::kARGB_4444_Config, "0101110" }, - { SkBitmap::kARGB_8888_Config, "0101110" }, + { SkBitmap::kNo_Config, "00000000" }, + { SkBitmap::kA1_Config, "01000000" }, + { SkBitmap::kA8_Config, "00101010" }, + { SkBitmap::kIndex8_Config, "00111010" }, + { SkBitmap::kRGB_565_Config, "00101010" }, + { SkBitmap::kARGB_4444_Config, "00101110" }, + { SkBitmap::kARGB_8888_Config, "00101110" }, }; static const bool isExtracted[] = { @@ -355,6 +375,12 @@ static void TestBitmapCopy(skiatest::Reporter* reporter) { case SkBitmap::kNo_Config: break; + case SkBitmap::kA1_Config: + if (safeSize.fHi != 0x470DE || + safeSize.fLo != 0x4DF82000) + sizeFail = true; + break; + case SkBitmap::kA8_Config: case SkBitmap::kIndex8_Config: if (safeSize.fHi != 0x2386F2 || @@ -385,8 +411,21 @@ static void TestBitmapCopy(skiatest::Reporter* reporter) { reporter->reportFailed(str); } - int subW = 2; - int subH = 2; + int subW, subH; + // Set sizes to be height = 2 to force the last row of the + // source to be used, thus verifying correct operation if + // the bitmap is an extracted subset. + if (gPairs[i].fConfig == SkBitmap::kA1_Config) { + // If one-bit per pixel, use 9 pixels to force more than + // one byte per row. + subW = 9; + subH = 2; + } else { + // All other configurations are at least one byte per pixel, + // and different configs will test copying different numbers + // of bytes. + subW = subH = 2; + } // Create bitmap to act as source for copies and subsets. SkBitmap src, subset; @@ -410,7 +449,12 @@ static void TestBitmapCopy(skiatest::Reporter* reporter) { // The extractedSubset() test case allows us to test copy- // ing when src and dst mave possibly different strides. SkIRect r; - r.set(1, 0, 1 + subW, subH); // 2x2 extracted bitmap + if (gPairs[i].fConfig == SkBitmap::kA1_Config) + // This config seems to need byte-alignment of + // extracted subset bits. + r.set(0, 0, subW, subH); + else + r.set(1, 0, 1 + subW, subH); // 2x2 extracted bitmap srcReady = src.extractSubset(&subset, r); } else { diff --git a/tests/BitmapGetColorTest.cpp b/tests/BitmapGetColorTest.cpp index 40aa3e26bf..11c22e6fa3 100644 --- a/tests/BitmapGetColorTest.cpp +++ b/tests/BitmapGetColorTest.cpp @@ -10,6 +10,67 @@ #include "SkRect.h" #include "SkRandom.h" +static int nextRand(SkRandom& rand, int min, int max) { + return min + (int)rand.nextRangeU(0, max - min); +} + +static void rand_irect(SkIRect* rect, int W, int H, SkRandom& rand) { + const int DX = W / 2; + const int DY = H / 2; + + rect->fLeft = nextRand(rand, -DX, W + DX); + rect->fTop = nextRand(rand, -DY, H + DY); + rect->fRight = nextRand(rand, -DX, W + DX); + rect->fBottom = nextRand(rand, -DY, H + DY); + rect->sort(); +} + +static void test_equal_A1_A8(skiatest::Reporter* reporter, + const SkBitmap& bm1, const SkBitmap& bm8) { + SkASSERT(SkBitmap::kA1_Config == bm1.config()); + SkASSERT(SkBitmap::kA8_Config == bm8.config()); + + REPORTER_ASSERT(reporter, bm1.width() == bm8.width()); + REPORTER_ASSERT(reporter, bm1.height() == bm8.height()); + for (int y = 0; y < bm1.height(); ++y) { + for (int x = 0; x < bm1.width(); ++x) { + int p1 = *bm1.getAddr1(x, y) & (1 << (7 - (x & 7))); + SkASSERT(SkIsPow2(p1)); + p1 = p1 ? 0xFF : 0; + + int p8 = *bm8.getAddr8(x, y); + SkASSERT(0 == p8 || 0xFF == p8); + + REPORTER_ASSERT(reporter, p1 == p8); + } + } +} + +static void test_eraserect_A1(skiatest::Reporter* reporter) { + const int W = 43; + const int H = 13; + + SkBitmap bm1, bm8; + + bm1.setConfig(SkBitmap::kA1_Config, W, H); + bm1.allocPixels(); + bm8.setConfig(SkBitmap::kA8_Config, W, H); + bm8.allocPixels(); + + SkRandom rand; + for (int i = 0; i < 10000; ++i) { + SkIRect area; + rand_irect(&area, W, H, rand); + + bm1.eraseColor(0); + bm8.eraseColor(0); + + bm1.eraseArea(area, SK_ColorWHITE); + bm8.eraseArea(area, SK_ColorWHITE); + test_equal_A1_A8(reporter, bm1, bm8); + } +} + static void TestGetColor(skiatest::Reporter* reporter) { static const struct Rec { SkBitmap::Config fConfig; @@ -44,6 +105,8 @@ static void TestGetColor(skiatest::Reporter* reporter) { SkColor c = bm.getColor(1, 1); REPORTER_ASSERT(reporter, c == gRec[i].fOutColor); } + + test_eraserect_A1(reporter); } #include "TestClassDef.h" diff --git a/tests/BlitRowTest.cpp b/tests/BlitRowTest.cpp index 85761104b2..3903efbfba 100644 --- a/tests/BlitRowTest.cpp +++ b/tests/BlitRowTest.cpp @@ -14,7 +14,7 @@ // these are in the same order as the SkBitmap::Config enum static const char* gConfigName[] = { - "None", "A8", "Index8", "565", "4444", "8888" + "None", "A1", "A8", "Index8", "565", "4444", "8888", "RLE_Index8" }; /** Returns -1 on success, else the x coord of the first bad pixel, return its diff --git a/tests/ImageDecodingTest.cpp b/tests/ImageDecodingTest.cpp index 6fcef1d315..56193f4e47 100644 --- a/tests/ImageDecodingTest.cpp +++ b/tests/ImageDecodingTest.cpp @@ -148,7 +148,7 @@ public: // the list is that each one is different, so we can test // to make sure the correct config is chosen. const SkBitmap::Config configs[] = { - SkBitmap::kA8_Config, + SkBitmap::kA1_Config, SkBitmap::kA8_Config, SkBitmap::kIndex8_Config, SkBitmap::kRGB_565_Config, |