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

Side by Side Diff: tests/CodecTest.cpp

Issue 2045293002: Add support for multiple frames in SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Don't need giflib for SkGifCodec anymore Created 4 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 unified diff | Download patch
« cmake/CMakeLists.txt ('K') | « tests/CodecPartialTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Resources.h" 8 #include "Resources.h"
9 #include "SkAndroidCodec.h" 9 #include "SkAndroidCodec.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 SkMD5::Digest codecDigest; 282 SkMD5::Digest codecDigest;
283 const SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType); 283 const SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType);
284 SkBitmap bm; 284 SkBitmap bm;
285 SkCodec::Result expectedResult = isIncomplete ? SkCodec::kIncompleteInput : SkCodec::kSuccess; 285 SkCodec::Result expectedResult = isIncomplete ? SkCodec::kIncompleteInput : SkCodec::kSuccess;
286 test_codec(r, codec.get(), bm, info, size, expectedResult, &codecDigest, nul lptr); 286 test_codec(r, codec.get(), bm, info, size, expectedResult, &codecDigest, nul lptr);
287 287
288 // Scanline decoding follows. 288 // Scanline decoding follows.
289 289
290 if (supportsNewScanlineDecoding && !isIncomplete) { 290 if (supportsNewScanlineDecoding && !isIncomplete) {
291 test_incremental_decode(r, codec, info, codecDigest); 291 test_incremental_decode(r, codec, info, codecDigest);
292 test_in_stripes(r, codec, info, codecDigest); 292 // This is only supported by codecs that use incremental decoding to
293 // support subset decodes - png and jpeg (once SkJpegCodec is
294 // converted).
295 if (SkStrEndsWith(path, "png") || SkStrEndsWith(path, "PNG")) {
296 test_in_stripes(r, codec, info, codecDigest);
297 }
293 } 298 }
294 299
295 // Need to call startScanlineDecode() first. 300 // Need to call startScanlineDecode() first.
296 REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0) == 0); 301 REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0) == 0);
297 REPORTER_ASSERT(r, !codec->skipScanlines(1)); 302 REPORTER_ASSERT(r, !codec->skipScanlines(1));
298 const SkCodec::Result startResult = codec->startScanlineDecode(info); 303 const SkCodec::Result startResult = codec->startScanlineDecode(info);
299 if (supportsScanlineDecoding) { 304 if (supportsScanlineDecoding) {
300 bm.eraseColor(SK_ColorYELLOW); 305 bm.eraseColor(SK_ColorYELLOW);
301 306
302 REPORTER_ASSERT(r, startResult == SkCodec::kSuccess); 307 REPORTER_ASSERT(r, startResult == SkCodec::kSuccess);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 467
463 // ICO 468 // ICO
464 // FIXME: We are not ready to test incomplete ICOs 469 // FIXME: We are not ready to test incomplete ICOs
465 // These two tests examine interestingly different behavior: 470 // These two tests examine interestingly different behavior:
466 // Decodes an embedded BMP image 471 // Decodes an embedded BMP image
467 check(r, "color_wheel.ico", SkISize::Make(128, 128), true, false, false); 472 check(r, "color_wheel.ico", SkISize::Make(128, 128), true, false, false);
468 // Decodes an embedded PNG image 473 // Decodes an embedded PNG image
469 check(r, "google_chrome.ico", SkISize::Make(256, 256), false, false, false, true); 474 check(r, "google_chrome.ico", SkISize::Make(256, 256), false, false, false, true);
470 475
471 // GIF 476 // GIF
472 // FIXME: We are not ready to test incomplete GIFs 477 check(r, "box.gif", SkISize::Make(200, 55), false, false, true, true);
473 check(r, "box.gif", SkISize::Make(200, 55), true, false, false); 478 check(r, "color_wheel.gif", SkISize::Make(128, 128), false, false, true, tru e);
474 check(r, "color_wheel.gif", SkISize::Make(128, 128), true, false, false);
475 // randPixels.gif is too small to test incomplete 479 // randPixels.gif is too small to test incomplete
476 check(r, "randPixels.gif", SkISize::Make(8, 8), true, false, false); 480 check(r, "randPixels.gif", SkISize::Make(8, 8), false, false, false, true);
477 481
478 // JPG 482 // JPG
479 check(r, "CMYK.jpg", SkISize::Make(642, 516), true, false, true); 483 check(r, "CMYK.jpg", SkISize::Make(642, 516), true, false, true);
480 check(r, "color_wheel.jpg", SkISize::Make(128, 128), true, false, true); 484 check(r, "color_wheel.jpg", SkISize::Make(128, 128), true, false, true);
481 // grayscale.jpg is too small to test incomplete 485 // grayscale.jpg is too small to test incomplete
482 check(r, "grayscale.jpg", SkISize::Make(128, 128), true, false, false); 486 check(r, "grayscale.jpg", SkISize::Make(128, 128), true, false, false);
483 check(r, "mandrill_512_q075.jpg", SkISize::Make(512, 512), true, false, true ); 487 check(r, "mandrill_512_q075.jpg", SkISize::Make(512, 512), true, false, true );
484 // randPixels.jpg is too small to test incomplete 488 // randPixels.jpg is too small to test incomplete
485 check(r, "randPixels.jpg", SkISize::Make(8, 8), true, false, false); 489 check(r, "randPixels.jpg", SkISize::Make(8, 8), true, false, false);
486 490
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 REPORTER_ASSERT(r, SkCodec::kUnimplemented == result); 1212 REPORTER_ASSERT(r, SkCodec::kUnimplemented == result);
1209 } 1213 }
1210 } 1214 }
1211 1215
1212 DEF_TEST(Codec_F16ConversionPossible, r) { 1216 DEF_TEST(Codec_F16ConversionPossible, r) {
1213 test_conversion_possible(r, "color_wheel.webp", false, false); 1217 test_conversion_possible(r, "color_wheel.webp", false, false);
1214 test_conversion_possible(r, "mandrill_512_q075.jpg", true, false); 1218 test_conversion_possible(r, "mandrill_512_q075.jpg", true, false);
1215 test_conversion_possible(r, "yellow_rose.png", false, true); 1219 test_conversion_possible(r, "yellow_rose.png", false, true);
1216 } 1220 }
1217 1221
1222 static void decode_frame(skiatest::Reporter* r, SkCodec* codec, size_t frame) {
1223 SkBitmap bm;
1224 auto info = codec->getInfo().makeColorType(kN32_SkColorType);
1225 bm.allocPixels(info);
1226
1227 SkCodec::Options opts;
1228 SkCodec::MultiFrameOptions multiOpts;
1229 multiOpts.fIndex = frame;
1230 opts.fFrameOptions = &multiOpts;
1231 REPORTER_ASSERT(r, SkCodec::kSuccess == codec->getPixels(info,
1232 bm.getPixels(), bm.rowBytes(), &opts, nullptr, nullptr));
1233 }
1234
1235 // For an animated image, we should only read enough to decode the requested
1236 // frame if the client never calls getFrameInfo.
1237 DEF_TEST(Codec_skipFullParse, r) {
1238 auto path = "test640x479.gif";
1239 SkStream* stream(GetResourceAsStream(path));
1240 if (!stream) {
1241 return;
1242 }
1243
1244 // Note that we cheat and hold on to the stream pointer, but SkCodec will
1245 // take ownership. We will not refer to the stream after the SkCodec
1246 // deletes it.
1247 std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream));
1248 if (!codec) {
1249 ERRORF(r, "Failed to create codec for %s", path);
1250 return;
1251 }
1252
1253 REPORTER_ASSERT(r, stream->hasPosition());
1254 const size_t sizePosition = stream->getPosition();
1255 REPORTER_ASSERT(r, stream->hasLength() && sizePosition < stream->getLength() );
1256
1257 // This should read more of the stream, but not the whole stream.
1258 decode_frame(r, codec.get(), 0);
1259 const size_t positionAfterFirstFrame = stream->getPosition();
1260 REPORTER_ASSERT(r, positionAfterFirstFrame > sizePosition
1261 && positionAfterFirstFrame < stream->getLength());
1262
1263 // Again, this should read more of the stream.
1264 decode_frame(r, codec.get(), 2);
1265 const size_t positionAfterThirdFrame = stream->getPosition();
1266 REPORTER_ASSERT(r, positionAfterThirdFrame > positionAfterFirstFrame
1267 && positionAfterThirdFrame < stream->getLength());
1268
1269 // This does not need to read any more of the stream, since it has already
1270 // parsed the second frame.
1271 decode_frame(r, codec.get(), 1);
1272 REPORTER_ASSERT(r, stream->getPosition() == positionAfterThirdFrame);
1273
1274 // This should read the rest of the frames.
1275 decode_frame(r, codec.get(), 3);
1276 const size_t finalPosition = stream->getPosition();
1277 REPORTER_ASSERT(r, finalPosition > positionAfterThirdFrame);
1278
1279 // There may be more data in the stream.
1280 auto frameInfo = codec->getFrameInfo();
1281 REPORTER_ASSERT(r, frameInfo.size() == 4);
1282 REPORTER_ASSERT(r, stream->getPosition() >= finalPosition);
1283 }
1284
1218 // Only rewinds up to a limit. 1285 // Only rewinds up to a limit.
1219 class LimitedRewindingStream : public SkStream { 1286 class LimitedRewindingStream : public SkStream {
1220 public: 1287 public:
1221 static SkStream* Make(const char path[], size_t limit) { 1288 static SkStream* Make(const char path[], size_t limit) {
1222 SkStream* stream = GetResourceAsStream(path); 1289 SkStream* stream = GetResourceAsStream(path);
1223 if (!stream) { 1290 if (!stream) {
1224 return nullptr; 1291 return nullptr;
1225 } 1292 }
1226 return new LimitedRewindingStream(stream, limit); 1293 return new LimitedRewindingStream(stream, limit);
1227 } 1294 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 } 1326 }
1260 }; 1327 };
1261 1328
1262 DEF_TEST(Codec_fallBack, r) { 1329 DEF_TEST(Codec_fallBack, r) {
1263 // SkAndroidCodec needs to be able to fall back to scanline decoding 1330 // SkAndroidCodec needs to be able to fall back to scanline decoding
1264 // if incremental decoding does not work. Make sure this does not 1331 // if incremental decoding does not work. Make sure this does not
1265 // require a rewind. 1332 // require a rewind.
1266 1333
1267 // Formats that currently do not support incremental decoding 1334 // Formats that currently do not support incremental decoding
1268 auto files = { 1335 auto files = {
1269 "box.gif",
1270 "CMYK.jpg", 1336 "CMYK.jpg",
1271 "color_wheel.ico", 1337 "color_wheel.ico",
1272 "mandrill.wbmp", 1338 "mandrill.wbmp",
1273 "randPixels.bmp", 1339 "randPixels.bmp",
1274 }; 1340 };
1275 for (auto file : files) { 1341 for (auto file : files) {
1276 SkStream* stream = LimitedRewindingStream::Make(file, 14); 1342 SkStream* stream = LimitedRewindingStream::Make(file, 14);
1277 if (!stream) { 1343 if (!stream) {
1278 SkDebugf("Missing resources (%s). Set --resourcePath.\n", file); 1344 SkDebugf("Missing resources (%s). Set --resourcePath.\n", file);
1279 return; 1345 return;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 auto result = codec->startIncrementalDecode(info, bm.getPixels(), bm.rowByte s()); 1420 auto result = codec->startIncrementalDecode(info, bm.getPixels(), bm.rowByte s());
1355 REPORTER_ASSERT(r, result == SkCodec::kSuccess); 1421 REPORTER_ASSERT(r, result == SkCodec::kSuccess);
1356 1422
1357 // This is an arbitrary value. The important fact is that it is not zero, an d rowsDecoded 1423 // This is an arbitrary value. The important fact is that it is not zero, an d rowsDecoded
1358 // should get set to zero by incrementalDecode. 1424 // should get set to zero by incrementalDecode.
1359 int rowsDecoded = 77; 1425 int rowsDecoded = 77;
1360 result = codec->incrementalDecode(&rowsDecoded); 1426 result = codec->incrementalDecode(&rowsDecoded);
1361 REPORTER_ASSERT(r, result == SkCodec::kIncompleteInput); 1427 REPORTER_ASSERT(r, result == SkCodec::kIncompleteInput);
1362 REPORTER_ASSERT(r, rowsDecoded == 0); 1428 REPORTER_ASSERT(r, rowsDecoded == 0);
1363 } 1429 }
OLDNEW
« cmake/CMakeLists.txt ('K') | « tests/CodecPartialTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698