Index: tests/TextureCompressionTest.cpp |
diff --git a/tests/TextureCompressionTest.cpp b/tests/TextureCompressionTest.cpp |
index 503605b003e4303cb42b168fe9ae0175f16f208e..49ba271b22343dae06deccfebcefdb57632035ed 100644 |
--- a/tests/TextureCompressionTest.cpp |
+++ b/tests/TextureCompressionTest.cpp |
@@ -75,6 +75,81 @@ DEF_TEST(CompressAlphaFailColorType, reporter) { |
} |
/** |
+ * Make sure that if you compress a texture with alternating black/white pixels, and |
+ * then decompress it, you get what you started with. |
+ */ |
+DEF_TEST(CompressCheckerboard, reporter) { |
+ SkBitmap bitmap; |
+ static const int kWidth = 12; |
+ static const int kHeight = 12; |
+ SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight); |
+ |
+ // ASTC is at most 12x12, and any dimension divisible by 12 is also divisible |
+ // by 4, which is the dimensions of R11_EAC and LATC. In the future, we might |
+ // support additional variants of ASTC, such as 5x6 and 8x8, in which case this would |
+ // need to be updated. |
+ REPORTER_ASSERT(reporter, kWidth % 12 == 0); |
+ REPORTER_ASSERT(reporter, kHeight % 12 == 0); |
+ |
+ bool setInfoSuccess = bitmap.setInfo(info); |
+ REPORTER_ASSERT(reporter, setInfoSuccess); |
+ |
+ bool allocPixelsSuccess = bitmap.allocPixels(info); |
+ REPORTER_ASSERT(reporter, allocPixelsSuccess); |
+ |
+ bitmap.lockPixels(); |
+ uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels()); |
+ REPORTER_ASSERT(reporter, NULL != pixels); |
+ |
+ for (int y = 0; y < kHeight; ++y) { |
+ for (int x = 0; x < kWidth; ++x) { |
+ if ((x ^ y) & 1) { |
+ pixels[x] = 0xFF; |
+ } else { |
+ pixels[x] = 0; |
+ } |
+ } |
+ pixels += bitmap.rowBytes(); |
+ } |
+ bitmap.unlockPixels(); |
+ |
robertphillips
2014/07/31 15:01:02
SkAutoMalloc ?
krajcevski
2014/07/31 15:12:19
Done.
|
+ uint8_t* decompBuffer = reinterpret_cast<uint8_t*>(sk_malloc_throw(kWidth*kHeight)); |
+ REPORTER_ASSERT(reporter, NULL != decompBuffer); |
+ if (NULL == decompBuffer) { |
+ return; |
+ } |
+ |
+ for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { |
+ const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor::Format>(i); |
+ |
+ // ASTC is for RGBA data, and doesn't fit the paradigm of this test. |
robertphillips
2014/07/31 15:01:02
// TODO: add ASTC decompression test (when ASTC de
krajcevski
2014/07/31 15:12:19
Done.
|
+ if (SkTextureCompressor::kASTC_12x12_Format == fmt) { |
+ continue; |
+ } |
+ |
+ SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap, fmt)); |
+ REPORTER_ASSERT(reporter, NULL != data); |
+ |
+ bool decompResult = SkTextureCompressor::DecompressBufferFromFormat( |
robertphillips
2014/07/31 15:01:02
tab these guys over a bit (and maybe split across
krajcevski
2014/07/31 15:12:18
Done.
|
+ decompBuffer, kWidth, data->bytes(), kWidth, kHeight, fmt); |
+ REPORTER_ASSERT(reporter, decompResult); |
+ |
+ bitmap.lockPixels(); |
+ pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels()); |
+ REPORTER_ASSERT(reporter, NULL != pixels); |
+ |
+ for (int y = 0; y < kHeight; ++y) { |
+ for (int x = 0; x < kWidth; ++x) { |
+ bool ok = pixels[y*bitmap.rowBytes() + x] == decompBuffer[y*kWidth + x]; |
+ REPORTER_ASSERT(reporter, ok); |
+ } |
+ } |
+ } |
+ |
+ sk_free(decompBuffer); |
+} |
+ |
+/** |
* Make sure that if we pass in a solid color bitmap that we get the appropriate results |
*/ |
DEF_TEST(CompressLATC, reporter) { |