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

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: Rebase Created 4 years, 3 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') | 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 "DMSrcSink.h" 8 #include "DMSrcSink.h"
9 #include "Resources.h" 9 #include "Resources.h"
10 #include "SkAndroidCodec.h" 10 #include "SkAndroidCodec.h"
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 default: 439 default:
440 // Everything else is considered a failure. 440 // Everything else is considered a failure.
441 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( )); 441 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( ));
442 } 442 }
443 443
444 draw_to_canvas(canvas, bitmapInfo, pixels.get(), rowBytes, colorPtr, colorCount, 444 draw_to_canvas(canvas, bitmapInfo, pixels.get(), rowBytes, colorPtr, colorCount,
445 fDstColorType); 445 fDstColorType);
446 break; 446 break;
447 } 447 }
448 case kScanline_Mode: { 448 case kScanline_Mode: {
449 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, NULL , colorPtr,
450 &colorCount)) {
451 return "Could not start scanline decoder";
452 }
453
454 void* dst = pixels.get(); 449 void* dst = pixels.get();
455 uint32_t height = decodeInfo.height(); 450 uint32_t height = decodeInfo.height();
456 switch (codec->getScanlineOrder()) { 451 const bool png = fPath.endsWith("png");
457 case SkCodec::kTopDown_SkScanlineOrder: 452 const bool ico = fPath.endsWith("ico");
458 case SkCodec::kBottomUp_SkScanlineOrder: 453 bool useOldScanlineMethod = !png && !ico;
459 case SkCodec::kNone_SkScanlineOrder: 454 if (png || ico) {
460 // We do not need to check the return value. On an incomple te 455 if (SkCodec::kSuccess == codec->startIncrementalDecode(decodeInf o, dst,
461 // image, memory will be filled with a default value. 456 rowBytes, nullptr, colorPtr, &colorCount)) {
462 codec->getScanlines(dst, height, rowBytes); 457 int rowsDecoded;
463 break; 458 if (SkCodec::kIncompleteInput == codec->incrementalDecode(&r owsDecoded)) {
464 case SkCodec::kOutOfOrder_SkScanlineOrder: { 459 codec->fillIncompleteImage(decodeInfo, dst, rowBytes,
465 for (int y = 0; y < decodeInfo.height(); y++) { 460 SkCodec::kNo_ZeroInitialized, height,
466 int dstY = codec->outputScanline(y); 461 rowsDecoded);
467 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * dstY);
468 // We complete the loop, even if this call begins to fai l
469 // due to an incomplete image. This ensures any uniniti alized
470 // memory will be filled with the proper value.
471 codec->getScanlines(dstPtr, 1, rowBytes);
472 } 462 }
473 break; 463 } else {
464 if (png) {
465 // Error: PNG should support incremental decode.
466 return "Could not start incremental decode";
467 }
468 // Otherwise, this is an ICO. Since incremental failed, it m ust contain a BMP,
469 // which should work via startScanlineDecode
470 useOldScanlineMethod = true;
474 } 471 }
475 } 472 }
476 473
474 if (useOldScanlineMethod) {
475 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, NULL, colorPtr,
476 &colorCount) ) {
477 return "Could not start scanline decoder";
478 }
479
480 switch (codec->getScanlineOrder()) {
481 case SkCodec::kTopDown_SkScanlineOrder:
482 case SkCodec::kBottomUp_SkScanlineOrder:
483 // We do not need to check the return value. On an inco mplete
484 // image, memory will be filled with a default value.
485 codec->getScanlines(dst, height, rowBytes);
486 break;
487 case SkCodec::kOutOfOrder_SkScanlineOrder: {
488 for (int y = 0; y < decodeInfo.height(); y++) {
489 int dstY = codec->outputScanline(y);
490 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * ds tY);
491 // We complete the loop, even if this call begins to fail
492 // due to an incomplete image. This ensures any uni nitialized
493 // memory will be filled with the proper value.
494 codec->getScanlines(dstPtr, 1, rowBytes);
495 }
496 break;
497 }
498 }
499 }
500
477 draw_to_canvas(canvas, bitmapInfo, dst, rowBytes, colorPtr, colorCou nt, fDstColorType); 501 draw_to_canvas(canvas, bitmapInfo, dst, rowBytes, colorPtr, colorCou nt, fDstColorType);
478 break; 502 break;
479 } 503 }
480 case kStripe_Mode: { 504 case kStripe_Mode: {
481 const int height = decodeInfo.height(); 505 const int height = decodeInfo.height();
482 // This value is chosen arbitrarily. We exercise more cases by choo sing a value that 506 // This value is chosen arbitrarily. We exercise more cases by choo sing a value that
483 // does not align with image blocks. 507 // does not align with image blocks.
484 const int stripeHeight = 37; 508 const int stripeHeight = 37;
485 const int numStripes = (height + stripeHeight - 1) / stripeHeight; 509 const int numStripes = (height + stripeHeight - 1) / stripeHeight;
486 void* dst = pixels.get(); 510 void* dst = pixels.get();
(...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1659 Error err = src.draw(&rec); 1683 Error err = src.draw(&rec);
1660 if (!err.isEmpty()) { 1684 if (!err.isEmpty()) {
1661 return err; 1685 return err;
1662 } 1686 }
1663 dl->draw(canvas); 1687 dl->draw(canvas);
1664 return check_against_reference(bitmap, src, fSink); 1688 return check_against_reference(bitmap, src, fSink);
1665 }); 1689 });
1666 } 1690 }
1667 1691
1668 } // namespace DM 1692 } // namespace DM
OLDNEW
« no previous file with comments | « no previous file | fuzz/fuzz.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698