Index: tests/CodexTest.cpp |
diff --git a/tests/CodexTest.cpp b/tests/CodexTest.cpp |
index b7f1584a16a29a52724c44e752fc7e9f56897d29..f52765b171e62ba5217143e5b30e985e1e7969f7 100644 |
--- a/tests/CodexTest.cpp |
+++ b/tests/CodexTest.cpp |
@@ -42,6 +42,26 @@ static void compare_to_good_digest(skiatest::Reporter* r, const SkMD5::Digest& g |
REPORTER_ASSERT(r, digest == goodDigest); |
} |
+/** |
+ * Test decoding an SkCodec to a particular SkImageInfo. |
+ * |
+ * Calling getPixels(info) should return expectedResult, and if goodDigest is non NULL, |
+ * the resulting decode should match. |
+ */ |
+static void test_info(skiatest::Reporter* r, SkCodec* codec, const SkImageInfo& info, |
+ SkCodec::Result expectedResult, const SkMD5::Digest* goodDigest) { |
+ SkBitmap bm; |
+ bm.allocPixels(info); |
+ SkAutoLockPixels autoLockPixels(bm); |
+ |
+ SkCodec::Result result = codec->getPixels(info, bm.getPixels(), bm.rowBytes()); |
+ REPORTER_ASSERT(r, result == expectedResult); |
+ |
+ if (goodDigest) { |
+ compare_to_good_digest(r, *goodDigest, bm); |
+ } |
+} |
+ |
SkIRect generate_random_subset(SkRandom* rand, int w, int h) { |
SkIRect rect; |
do { |
@@ -86,14 +106,28 @@ static void check(skiatest::Reporter* r, |
SkMD5::Digest digest; |
md5(bm, &digest); |
- bm.eraseColor(SK_ColorYELLOW); |
+ // verify that re-decoding gives the same result. |
+ test_info(r, codec, info, SkCodec::kSuccess, &digest); |
- result = |
- codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); |
+ { |
+ // Check alpha type conversions |
+ if (info.alphaType() == kOpaque_SkAlphaType) { |
scroggo_chromium
2015/08/07 23:16:31
When I started writing this CL, I expected that an
msarett
2015/08/10 13:51:12
I would guess that most clients would just use the
scroggo_chromium
2015/08/12 14:55:31
Sticking with the existing decision sounds good to
|
+ } else { |
+ // Decoding to opaque should fail |
+ test_info(r, codec, info.makeAlphaType(kOpaque_SkAlphaType), |
+ SkCodec::kInvalidConversion, NULL); |
+ SkAlphaType otherAt = info.alphaType(); |
+ if (kPremul_SkAlphaType == otherAt) { |
+ otherAt = kUnpremul_SkAlphaType; |
+ } else { |
+ otherAt = kPremul_SkAlphaType; |
+ } |
+ // The other non-opaque alpha type should always succeed, but not match. |
+ test_info(r, codec, info.makeAlphaType(otherAt), SkCodec::kSuccess, NULL); |
+ } |
+ } |
- REPORTER_ASSERT(r, result == SkCodec::kSuccess); |
- // verify that re-decoding gives the same result. |
- compare_to_good_digest(r, digest, bm); |
+ // Scanline decoding follows. |
stream.reset(resource(path)); |
SkAutoTDelete<SkScanlineDecoder> scanlineDecoder( |