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

Unified Diff: tests/CodecTest.cpp

Issue 1996993003: Finish supporting decoding opaque to non-opaque (Closed) Base URL: https://skia.googlesource.com/skia.git@opaque
Patch Set: Add tests Created 4 years, 7 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
« dm/DMSrcSink.cpp ('K') | « src/codec/SkWbmpCodec.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/CodecTest.cpp
diff --git a/tests/CodecTest.cpp b/tests/CodecTest.cpp
index 5ac19d9f7050efccd5ba34f364a851d8c77efd88..12d6ac8d3d2997a164da8219a4bd39f7923e349b 100644
--- a/tests/CodecTest.cpp
+++ b/tests/CodecTest.cpp
@@ -103,9 +103,49 @@ static void test_codec(skiatest::Reporter* r, Codec* codec, SkBitmap& bm, const
{
// Test decoding to 565
SkImageInfo info565 = info.makeColorType(kRGB_565_SkColorType);
- SkCodec::Result expected565 = info.alphaType() == kOpaque_SkAlphaType ?
- expectedResult : SkCodec::kInvalidConversion;
- test_info(r, codec, info565, expected565, nullptr);
+ if (info.alphaType() == kOpaque_SkAlphaType) {
+ // Decoding to 565 should succeed.
+ SkBitmap bm565;
+ bm565.allocPixels(info565);
+ SkAutoLockPixels alp(bm565);
+
+ // This will allow comparison even if the image is incomplete.
+ bm565.eraseColor(SK_ColorBLACK);
+
+ REPORTER_ASSERT(r, expectedResult == codec->getPixels(info565,
+ bm565.getPixels(), bm565.rowBytes()));
+
+ SkMD5::Digest digest565;
+ md5(bm565, &digest565);
+
+ // A dumb client's request for non-opaque should also succeed.
+ for (auto alpha : { kPremul_SkAlphaType, kUnpremul_SkAlphaType }) {
+ info565 = info565.makeAlphaType(alpha);
+ test_info(r, codec, info565, expectedResult, &digest565);
+ }
+ } else {
+ test_info(r, codec, info565, SkCodec::kInvalidConversion, nullptr);
+ }
+ }
+
+ if (codec->getInfo().colorType() == kGray_8_SkColorType) {
+ SkImageInfo grayInfo = codec->getInfo();
+ SkBitmap grayBm;
+ grayBm.allocPixels(grayInfo);
+ SkAutoLockPixels alp(grayBm);
+
+ grayBm.eraseColor(SK_ColorBLACK);
+
+ REPORTER_ASSERT(r, expectedResult == codec->getPixels(grayInfo,
+ grayBm.getPixels(), grayBm.rowBytes()));
+
+ SkMD5::Digest grayDigest;
+ md5(grayBm, &grayDigest);
+
+ for (auto alpha : { kPremul_SkAlphaType, kUnpremul_SkAlphaType }) {
+ grayInfo = grayInfo.makeAlphaType(alpha);
+ test_info(r, codec, grayInfo, expectedResult, &grayDigest);
+ }
}
// Verify that re-decoding gives the same result. It is interesting to check this after
« dm/DMSrcSink.cpp ('K') | « src/codec/SkWbmpCodec.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698