aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar scroggo <scroggo@chromium.org>2016-05-20 13:56:13 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-05-20 13:56:13 -0700
commitba5848953e00685f9a57343aef94372c5803130a (patch)
treed649d222b437821786d485abd515a81963c1b265 /tests
parent17b4a109219d063dc10a988b1ed46aaefe278477 (diff)
Finish supporting decoding opaque to non-opaque
When decoding to 565 or Gray, allow the client to incorrectly ask for premul. When checking whether it's possible to decode to 565, return whether the source is opaque. In DM, allow decoding to 565 or Gray, even if the client also asked for premul. This fixes a bug introduced in crrev.com/1999593003 when we stopped ever requesting Opaque, resulting in us not testing 565 or Gray. BUG=skia:4616 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=1996993003 Review-Url: https://codereview.chromium.org/1996993003
Diffstat (limited to 'tests')
-rw-r--r--tests/CodecTest.cpp46
1 files changed, 43 insertions, 3 deletions
diff --git a/tests/CodecTest.cpp b/tests/CodecTest.cpp
index 5ac19d9f70..12d6ac8d3d 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