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 "SamplePipeControllers.h" | 9 #include "SamplePipeControllers.h" |
10 #include "SkAndroidCodec.h" | 10 #include "SkAndroidCodec.h" |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 return ""; | 677 return ""; |
678 } | 678 } |
679 case kDivisor_Mode: { | 679 case kDivisor_Mode: { |
680 const int width = codec->getInfo().width(); | 680 const int width = codec->getInfo().width(); |
681 const int height = codec->getInfo().height(); | 681 const int height = codec->getInfo().height(); |
682 const int divisor = 2; | 682 const int divisor = 2; |
683 if (width < divisor || height < divisor) { | 683 if (width < divisor || height < divisor) { |
684 return Error::Nonfatal("Divisor is larger than image dimension.\
n"); | 684 return Error::Nonfatal("Divisor is larger than image dimension.\
n"); |
685 } | 685 } |
686 | 686 |
687 // Rounding the size of the subsets may leave some pixels uninitiali
zed on the bottom | 687 // Keep track of the final decoded dimensions. |
688 // and right edges of the bitmap. | 688 int finalScaledWidth = 0; |
689 bitmap.eraseColor(0); | 689 int finalScaledHeight = 0; |
690 for (int x = 0; x < divisor; x++) { | 690 for (int x = 0; x < divisor; x++) { |
691 for (int y = 0; y < divisor; y++) { | 691 for (int y = 0; y < divisor; y++) { |
692 // Calculate the subset dimensions | 692 // Calculate the subset dimensions |
693 int subsetWidth = width / divisor; | 693 int subsetWidth = width / divisor; |
694 int subsetHeight = height / divisor; | 694 int subsetHeight = height / divisor; |
695 const int left = x * subsetWidth; | 695 const int left = x * subsetWidth; |
696 const int top = y * subsetHeight; | 696 const int top = y * subsetHeight; |
697 | 697 |
698 // Increase the size of the last subset in each row or colum
n, when the | 698 // Increase the size of the last subset in each row or colum
n, when the |
699 // divisor does not divide evenly into the image dimensions | 699 // divisor does not divide evenly into the image dimensions |
700 subsetWidth += (x + 1 == divisor) ? (width % divisor) : 0; | 700 subsetWidth += (x + 1 == divisor) ? (width % divisor) : 0; |
701 subsetHeight += (y + 1 == divisor) ? (height % divisor) : 0; | 701 subsetHeight += (y + 1 == divisor) ? (height % divisor) : 0; |
702 SkIRect subset = SkIRect::MakeXYWH(left, top, subsetWidth, s
ubsetHeight); | 702 SkIRect subset = SkIRect::MakeXYWH(left, top, subsetWidth, s
ubsetHeight); |
703 if (!codec->getSupportedSubset(&subset)) { | 703 if (!codec->getSupportedSubset(&subset)) { |
704 return "Could not get supported subset to decode.\n"; | 704 return "Could not get supported subset to decode.\n"; |
705 } | 705 } |
706 options.fSubset = ⊂ | 706 options.fSubset = ⊂ |
707 void* pixels = bitmap.getAddr(subset.left() / fSampleSize, | 707 const int scaledWidthOffset = subset.left() / fSampleSize; |
708 subset.top() / fSampleSize); | 708 const int scaledHeightOffset = subset.top() / fSampleSize; |
| 709 void* pixels = bitmap.getAddr(scaledWidthOffset, scaledHeigh
tOffset); |
709 SkISize scaledSubsetSize = codec->getSampledSubsetDimensions
(fSampleSize, | 710 SkISize scaledSubsetSize = codec->getSampledSubsetDimensions
(fSampleSize, |
710 subset); | 711 subset); |
711 SkImageInfo subsetDecodeInfo = decodeInfo.makeWH(scaledSubse
tSize.width(), | 712 SkImageInfo subsetDecodeInfo = decodeInfo.makeWH(scaledSubse
tSize.width(), |
712 scaledSubsetSize.height()); | 713 scaledSubsetSize.height()); |
713 | 714 |
| 715 if (x + 1 == divisor && y + 1 == divisor) { |
| 716 finalScaledWidth = scaledWidthOffset + scaledSubsetSize.
width(); |
| 717 finalScaledHeight = scaledHeightOffset + scaledSubsetSiz
e.height(); |
| 718 } |
| 719 |
714 switch (codec->getAndroidPixels(subsetDecodeInfo, pixels, bi
tmap.rowBytes(), | 720 switch (codec->getAndroidPixels(subsetDecodeInfo, pixels, bi
tmap.rowBytes(), |
715 &options)) { | 721 &options)) { |
716 case SkCodec::kSuccess: | 722 case SkCodec::kSuccess: |
717 case SkCodec::kIncompleteInput: | 723 case SkCodec::kIncompleteInput: |
718 break; | 724 break; |
719 case SkCodec::kInvalidConversion: | 725 case SkCodec::kInvalidConversion: |
720 return Error::Nonfatal("Cannot convert to requested
color type.\n"); | 726 return Error::Nonfatal("Cannot convert to requested
color type.\n"); |
721 default: | 727 default: |
722 return SkStringPrintf("Couldn't getPixels %s.", fPat
h.c_str()); | 728 return SkStringPrintf("Couldn't getPixels %s.", fPat
h.c_str()); |
723 } | 729 } |
724 } | 730 } |
725 } | 731 } |
726 canvas->drawBitmap(bitmap, 0, 0); | 732 |
| 733 SkRect rect = SkRect::MakeXYWH(0, 0, (SkScalar) finalScaledWidth, |
| 734 (SkScalar) finalScaledHeight); |
| 735 canvas->drawBitmapRect(bitmap, rect, rect, nullptr); |
727 return ""; | 736 return ""; |
728 } | 737 } |
729 default: | 738 default: |
730 SkASSERT(false); | 739 SkASSERT(false); |
731 return "Error: Should not be reached.\n"; | 740 return "Error: Should not be reached.\n"; |
732 } | 741 } |
733 } | 742 } |
734 | 743 |
735 SkISize AndroidCodecSrc::size() const { | 744 SkISize AndroidCodecSrc::size() const { |
736 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 745 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1355 skr.visit<void>(i, drawsAsSingletonPictures); | 1364 skr.visit<void>(i, drawsAsSingletonPictures); |
1356 } | 1365 } |
1357 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1366 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
1358 | 1367 |
1359 canvas->drawPicture(macroPic); | 1368 canvas->drawPicture(macroPic); |
1360 return ""; | 1369 return ""; |
1361 }); | 1370 }); |
1362 } | 1371 } |
1363 | 1372 |
1364 } // namespace DM | 1373 } // namespace DM |
OLD | NEW |