| 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 "Resources.h" | 9 #include "Resources.h" |
| 10 #include "SkAndroidCodec.h" | 10 #include "SkAndroidCodec.h" |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 default: | 431 default: |
| 432 // Everything else is considered a failure. | 432 // Everything else is considered a failure. |
| 433 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str(
)); | 433 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str(
)); |
| 434 } | 434 } |
| 435 | 435 |
| 436 draw_to_canvas(canvas, bitmapInfo, pixels.get(), rowBytes, colorPtr,
colorCount, | 436 draw_to_canvas(canvas, bitmapInfo, pixels.get(), rowBytes, colorPtr,
colorCount, |
| 437 fDstColorType); | 437 fDstColorType); |
| 438 break; | 438 break; |
| 439 } | 439 } |
| 440 case kScanline_Mode: { | 440 case kScanline_Mode: { |
| 441 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, NULL
, colorPtr, |
| 442 &colorCount)) { |
| 443 return "Could not start scanline decoder"; |
| 444 } |
| 445 |
| 441 void* dst = pixels.get(); | 446 void* dst = pixels.get(); |
| 442 uint32_t height = decodeInfo.height(); | 447 uint32_t height = decodeInfo.height(); |
| 443 const bool png = fPath.endsWith("png"); | 448 switch (codec->getScanlineOrder()) { |
| 444 const bool ico = fPath.endsWith("ico"); | 449 case SkCodec::kTopDown_SkScanlineOrder: |
| 445 bool useOldScanlineMethod = !png && !ico; | 450 case SkCodec::kBottomUp_SkScanlineOrder: |
| 446 if (png || ico) { | 451 case SkCodec::kNone_SkScanlineOrder: |
| 447 if (SkCodec::kSuccess == codec->startIncrementalDecode(decodeInf
o, dst, | 452 // We do not need to check the return value. On an incomple
te |
| 448 rowBytes, nullptr, colorPtr, &colorCount)) { | 453 // image, memory will be filled with a default value. |
| 449 int rowsDecoded; | 454 codec->getScanlines(dst, height, rowBytes); |
| 450 if (SkCodec::kIncompleteInput == codec->incrementalDecode(&r
owsDecoded)) { | 455 break; |
| 451 codec->fillIncompleteImage(decodeInfo, dst, rowBytes, | 456 case SkCodec::kOutOfOrder_SkScanlineOrder: { |
| 452 SkCodec::kNo_ZeroInitialized,
height, | 457 for (int y = 0; y < decodeInfo.height(); y++) { |
| 453 rowsDecoded); | 458 int dstY = codec->outputScanline(y); |
| 459 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * dstY); |
| 460 // We complete the loop, even if this call begins to fai
l |
| 461 // due to an incomplete image. This ensures any uniniti
alized |
| 462 // memory will be filled with the proper value. |
| 463 codec->getScanlines(dstPtr, 1, rowBytes); |
| 454 } | 464 } |
| 455 } else { | 465 break; |
| 456 if (png) { | |
| 457 // Error: PNG should support incremental decode. | |
| 458 return "Could not start incremental decode"; | |
| 459 } | |
| 460 // Otherwise, this is an ICO. Since incremental failed, it m
ust contain a BMP, | |
| 461 // which should work via startScanlineDecode | |
| 462 useOldScanlineMethod = true; | |
| 463 } | 466 } |
| 464 } | 467 } |
| 465 | 468 |
| 466 if (useOldScanlineMethod) { | |
| 467 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo,
NULL, colorPtr, | |
| 468 &colorCount)
) { | |
| 469 return "Could not start scanline decoder"; | |
| 470 } | |
| 471 | |
| 472 switch (codec->getScanlineOrder()) { | |
| 473 case SkCodec::kTopDown_SkScanlineOrder: | |
| 474 case SkCodec::kBottomUp_SkScanlineOrder: | |
| 475 // We do not need to check the return value. On an inco
mplete | |
| 476 // image, memory will be filled with a default value. | |
| 477 codec->getScanlines(dst, height, rowBytes); | |
| 478 break; | |
| 479 case SkCodec::kOutOfOrder_SkScanlineOrder: { | |
| 480 for (int y = 0; y < decodeInfo.height(); y++) { | |
| 481 int dstY = codec->outputScanline(y); | |
| 482 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * ds
tY); | |
| 483 // We complete the loop, even if this call begins to
fail | |
| 484 // due to an incomplete image. This ensures any uni
nitialized | |
| 485 // memory will be filled with the proper value. | |
| 486 codec->getScanlines(dstPtr, 1, rowBytes); | |
| 487 } | |
| 488 break; | |
| 489 } | |
| 490 } | |
| 491 } | |
| 492 | |
| 493 draw_to_canvas(canvas, bitmapInfo, dst, rowBytes, colorPtr, colorCou
nt, fDstColorType); | 469 draw_to_canvas(canvas, bitmapInfo, dst, rowBytes, colorPtr, colorCou
nt, fDstColorType); |
| 494 break; | 470 break; |
| 495 } | 471 } |
| 496 case kStripe_Mode: { | 472 case kStripe_Mode: { |
| 497 const int height = decodeInfo.height(); | 473 const int height = decodeInfo.height(); |
| 498 // This value is chosen arbitrarily. We exercise more cases by choo
sing a value that | 474 // This value is chosen arbitrarily. We exercise more cases by choo
sing a value that |
| 499 // does not align with image blocks. | 475 // does not align with image blocks. |
| 500 const int stripeHeight = 37; | 476 const int stripeHeight = 37; |
| 501 const int numStripes = (height + stripeHeight - 1) / stripeHeight; | 477 const int numStripes = (height + stripeHeight - 1) / stripeHeight; |
| 502 void* dst = pixels.get(); | 478 void* dst = pixels.get(); |
| (...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1563 skr.visit(i, drawsAsSingletonPictures); | 1539 skr.visit(i, drawsAsSingletonPictures); |
| 1564 } | 1540 } |
| 1565 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); | 1541 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); |
| 1566 | 1542 |
| 1567 canvas->drawPicture(macroPic); | 1543 canvas->drawPicture(macroPic); |
| 1568 return check_against_reference(bitmap, src, fSink); | 1544 return check_against_reference(bitmap, src, fSink); |
| 1569 }); | 1545 }); |
| 1570 } | 1546 } |
| 1571 | 1547 |
| 1572 } // namespace DM | 1548 } // namespace DM |
| OLD | NEW |