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

Unified Diff: tests/CodexTest.cpp

Issue 1332053002: Fill incomplete images in SkCodec parent class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Forgot to add SkSampler.cpp Created 5 years, 2 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
Index: tests/CodexTest.cpp
diff --git a/tests/CodexTest.cpp b/tests/CodexTest.cpp
index 63631822de45b16c3f3a31bd0406139a7d8b7343..cfdc00341577faf5330ea69564765af34212312c 100644
--- a/tests/CodexTest.cpp
+++ b/tests/CodexTest.cpp
@@ -75,14 +75,15 @@ SkIRect generate_random_subset(SkRandom* rand, int w, int h) {
}
static void test_codec(skiatest::Reporter* r, SkCodec* codec, SkBitmap& bm, const SkImageInfo& info,
- const SkISize& size, bool supports565, SkMD5::Digest* digest,
- const SkMD5::Digest* goodDigest) {
+ const SkISize& size, bool supports565, SkCodec::Result expectedResult,
+ SkMD5::Digest* digest, const SkMD5::Digest* goodDigest) {
+
REPORTER_ASSERT(r, info.dimensions() == size);
bm.allocPixels(info);
SkAutoLockPixels autoLockPixels(bm);
SkCodec::Result result = codec->getPixels(info, bm.getPixels(), bm.rowBytes());
- REPORTER_ASSERT(r, result == SkCodec::kSuccess);
+ REPORTER_ASSERT(r, result == expectedResult);
md5(bm, digest);
if (goodDigest) {
@@ -92,16 +93,16 @@ static void test_codec(skiatest::Reporter* r, SkCodec* codec, SkBitmap& bm, cons
{
// Test decoding to 565
SkImageInfo info565 = info.makeColorType(kRGB_565_SkColorType);
- SkCodec::Result expected = (supports565 && info.alphaType() == kOpaque_SkAlphaType) ?
- SkCodec::kSuccess : SkCodec::kInvalidConversion;
- test_info(r, codec, info565, expected, nullptr);
+ SkCodec::Result expected565 = (supports565 && info.alphaType() == kOpaque_SkAlphaType) ?
+ expectedResult : SkCodec::kInvalidConversion;
+ test_info(r, codec, info565, expected565, nullptr);
}
// Verify that re-decoding gives the same result. It is interesting to check this after
// a decode to 565, since choosing to decode to 565 may result in some of the decode
// options being modified. These options should return to their defaults on another
// decode to kN32, so the new digest should match the old digest.
- test_info(r, codec, info, SkCodec::kSuccess, digest);
+ test_info(r, codec, info, expectedResult, digest);
{
// Check alpha type conversions
@@ -121,7 +122,7 @@ static void test_codec(skiatest::Reporter* r, SkCodec* codec, SkBitmap& bm, cons
otherAt = kPremul_SkAlphaType;
}
// The other non-opaque alpha type should always succeed, but not match.
- test_info(r, codec, info.makeAlphaType(otherAt), SkCodec::kSuccess, nullptr);
+ test_info(r, codec, info.makeAlphaType(otherAt), expectedResult, nullptr);
}
}
}
@@ -131,7 +132,8 @@ static void check(skiatest::Reporter* r,
SkISize size,
bool supportsScanlineDecoding,
bool supportsSubsetDecoding,
- bool supports565 = true) {
+ bool supports565 = true,
+ bool isIncomplete = false) {
SkAutoTDelete<SkStream> stream(resource(path));
if (!stream) {
@@ -148,14 +150,15 @@ static void check(skiatest::Reporter* r,
SkMD5::Digest codecDigest;
SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType);
SkBitmap bm;
- test_codec(r, codec, bm, info, size, supports565, &codecDigest, nullptr);
+ SkCodec::Result expectedResult = isIncomplete ? SkCodec::kIncompleteInput : SkCodec::kSuccess;
+ test_codec(r, codec, bm, info, size, supports565, expectedResult, &codecDigest, nullptr);
// Scanline decoding follows.
// Need to call startScanlineDecode() first.
REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0)
- == SkCodec::kScanlineDecodingNotStarted);
+ == 0);
REPORTER_ASSERT(r, codec->skipScanlines(1)
- == SkCodec::kScanlineDecodingNotStarted);
+ == 0);
const SkCodec::Result startResult = codec->startScanlineDecode(info);
if (supportsScanlineDecoding) {
@@ -164,8 +167,10 @@ static void check(skiatest::Reporter* r,
REPORTER_ASSERT(r, startResult == SkCodec::kSuccess);
for (int y = 0; y < info.height(); y++) {
- SkCodec::Result result = codec->getScanlines(bm.getAddr(0, y), 1, 0);
- REPORTER_ASSERT(r, result == SkCodec::kSuccess);
+ const uint32_t lines = codec->getScanlines(bm.getAddr(0, y), 1, 0);
+ if (!isIncomplete) {
+ REPORTER_ASSERT(r, 1 == lines);
+ }
}
// verify that scanline decoding gives the same result.
if (SkCodec::kTopDown_SkScanlineOrder == codec->getScanlineOrder()) {
@@ -174,19 +179,19 @@ static void check(skiatest::Reporter* r,
// Cannot continue to decode scanlines beyond the end
REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0)
- == SkCodec::kInvalidParameters);
+ == 0);
// Interrupting a scanline decode with a full decode starts from
// scratch
REPORTER_ASSERT(r, codec->startScanlineDecode(info) == SkCodec::kSuccess);
REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0)
- == SkCodec::kSuccess);
+ == 1);
REPORTER_ASSERT(r, codec->getPixels(bm.info(), bm.getPixels(), bm.rowBytes())
- == SkCodec::kSuccess);
+ == expectedResult);
REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0)
- == SkCodec::kScanlineDecodingNotStarted);
+ == 0);
REPORTER_ASSERT(r, codec->skipScanlines(1)
- == SkCodec::kScanlineDecodingNotStarted);
+ == 0);
} else {
REPORTER_ASSERT(r, startResult == SkCodec::kUnimplemented);
}
@@ -241,7 +246,8 @@ static void check(skiatest::Reporter* r,
SkBitmap bm;
SkMD5::Digest scaledCodecDigest;
- test_codec(r, codec, bm, info, size, supports565, &scaledCodecDigest, &codecDigest);
+ test_codec(r, codec, bm, info, size, supports565, expectedResult, &scaledCodecDigest,
+ &codecDigest);
}
}
@@ -291,6 +297,8 @@ DEF_TEST(Codec, r) {
check(r, "plane_interlaced.png", SkISize::Make(250, 126), true, false);
check(r, "randPixels.png", SkISize::Make(8, 8), true, false);
check(r, "yellow_rose.png", SkISize::Make(400, 301), true, false);
+ // Incomplete Image
+ check(r, "incomplete_images/android.png", SkISize::Make(1024, 1218), true, false, true, true);
}
// Test interlaced PNG in stripes, similar to DM's kStripe_Mode
@@ -344,12 +352,12 @@ DEF_TEST(Codec_stripes, r) {
// Odd stripes
for (int i = 1; i < numStripes; i += 2) {
// Skip the even stripes
- result = codec->skipScanlines(stripeHeight);
- REPORTER_ASSERT(r, result == SkCodec::kSuccess);
+ bool skipResult = codec->skipScanlines(stripeHeight);
+ REPORTER_ASSERT(r, skipResult);
- result = codec->getScanlines(bm.getAddr(0, i * stripeHeight), stripeHeight,
+ int linesDecoded = codec->getScanlines(bm.getAddr(0, i * stripeHeight), stripeHeight,
bm.rowBytes());
- REPORTER_ASSERT(r, result == SkCodec::kSuccess);
+ REPORTER_ASSERT(r, linesDecoded == stripeHeight);
}
// Even stripes
@@ -357,14 +365,14 @@ DEF_TEST(Codec_stripes, r) {
REPORTER_ASSERT(r, result == SkCodec::kSuccess);
for (int i = 0; i < numStripes; i += 2) {
- result = codec->getScanlines(bm.getAddr(0, i * stripeHeight), stripeHeight,
+ int linesDecoded = codec->getScanlines(bm.getAddr(0, i * stripeHeight), stripeHeight,
bm.rowBytes());
- REPORTER_ASSERT(r, result == SkCodec::kSuccess);
+ REPORTER_ASSERT(r, linesDecoded == stripeHeight);
// Skip the odd stripes
if (i + 1 < numStripes) {
- result = codec->skipScanlines(stripeHeight);
- REPORTER_ASSERT(r, result == SkCodec::kSuccess);
+ bool skipResult = codec->skipScanlines(stripeHeight);
+ REPORTER_ASSERT(r, skipResult);
}
}
@@ -373,12 +381,12 @@ DEF_TEST(Codec_stripes, r) {
result = codec->startScanlineDecode(info);
REPORTER_ASSERT(r, result == SkCodec::kSuccess);
- result = codec->skipScanlines(height - remainingLines);
- REPORTER_ASSERT(r, result == SkCodec::kSuccess);
+ bool skipResult = codec->skipScanlines(height - remainingLines);
+ REPORTER_ASSERT(r, skipResult);
- result = codec->getScanlines(bm.getAddr(0, height - remainingLines),
+ int linesDecoded = codec->getScanlines(bm.getAddr(0, height - remainingLines),
remainingLines, bm.rowBytes());
- REPORTER_ASSERT(r, result == SkCodec::kSuccess);
+ REPORTER_ASSERT(r, linesDecoded == remainingLines);
}
compare_to_good_digest(r, digest, bm);
« src/codec/SkWebpCodec.h ('K') | « src/codec/SkWebpCodec.cpp ('k') | tests/SwizzlerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698