OLD | NEW |
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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 default: | 427 default: |
428 // Everything else is considered a failure. | 428 // Everything else is considered a failure. |
429 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str(
)); | 429 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str(
)); |
430 } | 430 } |
431 premultiply_if_necessary(bitmap); | 431 premultiply_if_necessary(bitmap); |
432 swap_rb_if_necessary(bitmap, fDstColorType); | 432 swap_rb_if_necessary(bitmap, fDstColorType); |
433 canvas->drawBitmap(bitmap, 0, 0); | 433 canvas->drawBitmap(bitmap, 0, 0); |
434 break; | 434 break; |
435 } | 435 } |
436 case kScanline_Mode: { | 436 case kScanline_Mode: { |
437 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, NULL
, colorPtr, | 437 const bool png = fPath.endsWith("png"); |
438 colorCountPtr))
{ | 438 const bool ico = fPath.endsWith("ico"); |
439 return "Could not start scanline decoder"; | 439 bool useOldScanlineMethod = !png && !ico; |
440 } | 440 if (png || ico) { |
441 | 441 if (SkCodec::kSuccess == codec->startIncrementalDecode(decodeInf
o, |
442 void* dst = bitmap.getAddr(0, 0); | 442 bitmap.getPixels(), bitmap.rowBytes(), nullptr, colorPtr
, colorCountPtr)) { |
443 size_t rowBytes = bitmap.rowBytes(); | 443 int rowsDecoded; |
444 uint32_t height = decodeInfo.height(); | 444 if (SkCodec::kIncompleteInput == codec->incrementalDecode(&r
owsDecoded)) { |
445 switch (codec->getScanlineOrder()) { | 445 codec->fillIncompleteImage(decodeInfo, bitmap.getPixels(
), bitmap.rowBytes(), |
446 case SkCodec::kTopDown_SkScanlineOrder: | 446 SkCodec::kNo_ZeroInitialized,
decodeInfo.height(), |
447 case SkCodec::kBottomUp_SkScanlineOrder: | 447 rowsDecoded); |
448 case SkCodec::kNone_SkScanlineOrder: | |
449 // We do not need to check the return value. On an incomple
te | |
450 // image, memory will be filled with a default value. | |
451 codec->getScanlines(dst, height, rowBytes); | |
452 break; | |
453 case SkCodec::kOutOfOrder_SkScanlineOrder: { | |
454 for (int y = 0; y < decodeInfo.height(); y++) { | |
455 int dstY = codec->outputScanline(y); | |
456 void* dstPtr = bitmap.getAddr(0, dstY); | |
457 // We complete the loop, even if this call begins to fai
l | |
458 // due to an incomplete image. This ensures any uniniti
alized | |
459 // memory will be filled with the proper value. | |
460 codec->getScanlines(dstPtr, 1, bitmap.rowBytes()); | |
461 } | 448 } |
462 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; |
463 } | 457 } |
464 } | 458 } |
465 | 459 |
| 460 if (useOldScanlineMethod) { |
| 461 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo,
NULL, colorPtr, |
| 462 colorCountPt
r)) { |
| 463 return "Could not start scanline decoder"; |
| 464 } |
| 465 |
| 466 void* dst = bitmap.getAddr(0, 0); |
| 467 size_t rowBytes = bitmap.rowBytes(); |
| 468 uint32_t height = decodeInfo.height(); |
| 469 switch (codec->getScanlineOrder()) { |
| 470 case SkCodec::kTopDown_SkScanlineOrder: |
| 471 case SkCodec::kBottomUp_SkScanlineOrder: |
| 472 // We do not need to check the return value. On an inco
mplete |
| 473 // image, memory will be filled with a default value. |
| 474 codec->getScanlines(dst, height, rowBytes); |
| 475 break; |
| 476 case SkCodec::kOutOfOrder_SkScanlineOrder: { |
| 477 for (int y = 0; y < decodeInfo.height(); y++) { |
| 478 int dstY = codec->outputScanline(y); |
| 479 void* dstPtr = bitmap.getAddr(0, dstY); |
| 480 // We complete the loop, even if this call begins to
fail |
| 481 // due to an incomplete image. This ensures any uni
nitialized |
| 482 // memory will be filled with the proper value. |
| 483 codec->getScanlines(dstPtr, 1, bitmap.rowBytes()); |
| 484 } |
| 485 break; |
| 486 } |
| 487 } |
| 488 } |
| 489 |
466 premultiply_if_necessary(bitmap); | 490 premultiply_if_necessary(bitmap); |
467 swap_rb_if_necessary(bitmap, fDstColorType); | 491 swap_rb_if_necessary(bitmap, fDstColorType); |
468 canvas->drawBitmap(bitmap, 0, 0); | 492 canvas->drawBitmap(bitmap, 0, 0); |
469 break; | 493 break; |
470 } | 494 } |
471 case kStripe_Mode: { | 495 case kStripe_Mode: { |
472 const int height = decodeInfo.height(); | 496 const int height = decodeInfo.height(); |
473 // This value is chosen arbitrarily. We exercise more cases by choo
sing a value that | 497 // This value is chosen arbitrarily. We exercise more cases by choo
sing a value that |
474 // does not align with image blocks. | 498 // does not align with image blocks. |
475 const int stripeHeight = 37; | 499 const int stripeHeight = 37; |
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1499 skr.visit(i, drawsAsSingletonPictures); | 1523 skr.visit(i, drawsAsSingletonPictures); |
1500 } | 1524 } |
1501 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); | 1525 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); |
1502 | 1526 |
1503 canvas->drawPicture(macroPic); | 1527 canvas->drawPicture(macroPic); |
1504 return check_against_reference(bitmap, src, fSink); | 1528 return check_against_reference(bitmap, src, fSink); |
1505 }); | 1529 }); |
1506 } | 1530 } |
1507 | 1531 |
1508 } // namespace DM | 1532 } // namespace DM |
OLD | NEW |