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

Side by Side Diff: dm/DMSrcSink.cpp

Issue 1997703003: Make SkPngCodec decode progressively. (Closed) Base URL: https://skia.googlesource.com/skia.git@foil
Patch Set: Use the correct Options object 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 unified diff | Download patch
« no previous file with comments | « no previous file | fuzz/fuzz.cpp » ('j') | src/codec/SkGifCodec.cpp » ('J')
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 "DMSrcSink.h" 8 #include "DMSrcSink.h"
9 #include "SkAndroidCodec.h" 9 #include "SkAndroidCodec.h"
10 #include "SkCodec.h" 10 #include "SkCodec.h"
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 default: 425 default:
426 // Everything else is considered a failure. 426 // Everything else is considered a failure.
427 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( )); 427 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( ));
428 } 428 }
429 429
430 draw_to_canvas(canvas, bitmapInfo, pixels.get(), rowBytes, colorPtr, colorCount, 430 draw_to_canvas(canvas, bitmapInfo, pixels.get(), rowBytes, colorPtr, colorCount,
431 fDstColorType); 431 fDstColorType);
432 break; 432 break;
433 } 433 }
434 case kScanline_Mode: { 434 case kScanline_Mode: {
435 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, NULL , colorPtr,
436 &colorCount)) {
437 return "Could not start scanline decoder";
438 }
439
440 void* dst = pixels.get(); 435 void* dst = pixels.get();
441 uint32_t height = decodeInfo.height(); 436 uint32_t height = decodeInfo.height();
442 switch (codec->getScanlineOrder()) { 437 const bool png = fPath.endsWith("png");
443 case SkCodec::kTopDown_SkScanlineOrder: 438 const bool ico = fPath.endsWith("ico");
444 case SkCodec::kBottomUp_SkScanlineOrder: 439 bool useOldScanlineMethod = !png && !ico;
445 case SkCodec::kNone_SkScanlineOrder: 440 if (png || ico) {
446 // We do not need to check the return value. On an incomple te 441 if (SkCodec::kSuccess == codec->startIncrementalDecode(decodeInf o, dst,
447 // image, memory will be filled with a default value. 442 rowBytes, nullptr, colorPtr, &colorCount)) {
448 codec->getScanlines(dst, height, rowBytes); 443 int rowsDecoded;
449 break; 444 if (SkCodec::kIncompleteInput == codec->incrementalDecode(&r owsDecoded)) {
450 case SkCodec::kOutOfOrder_SkScanlineOrder: { 445 codec->fillIncompleteImage(decodeInfo, dst, rowBytes,
451 for (int y = 0; y < decodeInfo.height(); y++) { 446 SkCodec::kNo_ZeroInitialized, height,
452 int dstY = codec->outputScanline(y); 447 rowsDecoded);
453 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * dstY);
454 // We complete the loop, even if this call begins to fai l
455 // due to an incomplete image. This ensures any uniniti alized
456 // memory will be filled with the proper value.
457 codec->getScanlines(dstPtr, 1, rowBytes);
458 } 448 }
459 break; 449 } else {
450 if (png) {
451 // Error: PNG should support incremental decode.
452 return "Could not start incremental decode";
453 }
454 // Otherwise, this is an ICO. Since incremental failed, it m ust contain a BMP,
455 // which should work via startScanlineDecode
456 useOldScanlineMethod = true;
460 } 457 }
461 } 458 }
462 459
460 if (useOldScanlineMethod) {
461 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, NULL, colorPtr,
462 &colorCount) ) {
463 return "Could not start scanline decoder";
464 }
465
466 switch (codec->getScanlineOrder()) {
467 case SkCodec::kTopDown_SkScanlineOrder:
468 case SkCodec::kBottomUp_SkScanlineOrder:
469 // We do not need to check the return value. On an inco mplete
470 // image, memory will be filled with a default value.
471 codec->getScanlines(dst, height, rowBytes);
472 break;
473 case SkCodec::kOutOfOrder_SkScanlineOrder: {
474 for (int y = 0; y < decodeInfo.height(); y++) {
475 int dstY = codec->outputScanline(y);
476 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * ds tY);
477 // We complete the loop, even if this call begins to fail
478 // due to an incomplete image. This ensures any uni nitialized
479 // memory will be filled with the proper value.
480 codec->getScanlines(dstPtr, 1, rowBytes);
481 }
482 break;
483 }
484 }
485 }
486
463 draw_to_canvas(canvas, bitmapInfo, dst, rowBytes, colorPtr, colorCou nt, fDstColorType); 487 draw_to_canvas(canvas, bitmapInfo, dst, rowBytes, colorPtr, colorCou nt, fDstColorType);
464 break; 488 break;
465 } 489 }
466 case kStripe_Mode: { 490 case kStripe_Mode: {
467 const int height = decodeInfo.height(); 491 const int height = decodeInfo.height();
468 // This value is chosen arbitrarily. We exercise more cases by choo sing a value that 492 // This value is chosen arbitrarily. We exercise more cases by choo sing a value that
469 // does not align with image blocks. 493 // does not align with image blocks.
470 const int stripeHeight = 37; 494 const int stripeHeight = 37;
471 const int numStripes = (height + stripeHeight - 1) / stripeHeight; 495 const int numStripes = (height + stripeHeight - 1) / stripeHeight;
472 void* dst = pixels.get(); 496 void* dst = pixels.get();
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 skr.visit(i, drawsAsSingletonPictures); 1554 skr.visit(i, drawsAsSingletonPictures);
1531 } 1555 }
1532 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); 1556 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture());
1533 1557
1534 canvas->drawPicture(macroPic); 1558 canvas->drawPicture(macroPic);
1535 return check_against_reference(bitmap, src, fSink); 1559 return check_against_reference(bitmap, src, fSink);
1536 }); 1560 });
1537 } 1561 }
1538 1562
1539 } // namespace DM 1563 } // namespace DM
OLDNEW
« no previous file with comments | « no previous file | fuzz/fuzz.cpp » ('j') | src/codec/SkGifCodec.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698