Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1240)

Unified Diff: tests/CodexTest.cpp

Issue 1277253003: Update CodexTest to test valid_alpha. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Test opaque to not, plus conversion check in wbmp Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/codec/SkCodec_wbmp.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/CodexTest.cpp
diff --git a/tests/CodexTest.cpp b/tests/CodexTest.cpp
index b7f1584a16a29a52724c44e752fc7e9f56897d29..24846a69b9654d6dcb4533c7ce992f0d2472156d 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,32 @@ static void check(skiatest::Reporter* r,
SkMD5::Digest digest;
md5(bm, &digest);
- bm.eraseColor(SK_ColorYELLOW);
-
- result =
- codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL);
-
- REPORTER_ASSERT(r, result == SkCodec::kSuccess);
// verify that re-decoding gives the same result.
- compare_to_good_digest(r, digest, bm);
+ test_info(r, codec, info, SkCodec::kSuccess, &digest);
+
+ {
+ // Check alpha type conversions
+ if (info.alphaType() == kOpaque_SkAlphaType) {
+ test_info(r, codec, info.makeAlphaType(kUnpremul_SkAlphaType),
+ SkCodec::kInvalidConversion, NULL);
+ test_info(r, codec, info.makeAlphaType(kPremul_SkAlphaType),
+ SkCodec::kInvalidConversion, NULL);
+ } 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);
+ }
+ }
+
+ // Scanline decoding follows.
stream.reset(resource(path));
SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(
« no previous file with comments | « src/codec/SkCodec_wbmp.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698