Chromium Code Reviews| Index: dm/DMSrcSink.cpp |
| diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp |
| index 090a24d86a62590f123881274578b0468e59a01d..af303c12192c3bb0a1cfb70dd5ecd611a8481c0f 100644 |
| --- a/dm/DMSrcSink.cpp |
| +++ b/dm/DMSrcSink.cpp |
| @@ -141,6 +141,7 @@ Error CodecSrc::draw(SkCanvas* canvas) const { |
| // Everything else is considered a failure. |
| return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str()); |
| } |
| + canvas->drawBitmap(bitmap, 0, 0); |
| break; |
| case kScanline_Mode: { |
| SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(decodeInfo, NULL, |
| @@ -160,10 +161,82 @@ Error CodecSrc::draw(SkCanvas* canvas) const { |
| fPath.c_str(), y-1, (int) result); |
| } |
| } |
| + canvas->drawBitmap(bitmap, 0, 0); |
| + break; |
| + } |
| + case kSubset_Mode: { |
| + //this mode decodes the image in 4 subsets, using a scanline decoder |
| + int fDivisor = 2; |
|
scroggo
2015/05/18 14:03:58
style nit: Skia adds an 'f' to the beginning of va
emmaleeroach
2015/05/18 20:04:27
On 2015/05/18 14:03:58, scroggo wrote:
> style nit
|
| + SkScanlineDecoder* subsetScanlineDecoder = codec->getScanlineDecoder(decodeInfo, NULL, |
| + colorPtr, colorCountPtr); |
| + if (NULL == subsetScanlineDecoder) { |
| + return Error::Nonfatal("Cannot use scanline decoder for all images"); |
| + } |
| + SkImageInfo subsetDecodeInfo = decodeInfo.makeWH(decodeInfo.width()/fDivisor, |
| + decodeInfo.height()/fDivisor); |
| + SkBitmap subsetBm; |
| + if (!subsetBm.tryAllocPixels(subsetDecodeInfo, NULL, colorTable.get())) { |
| + return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPath.c_str(), |
| + subsetDecodeInfo.width(), subsetDecodeInfo.height()); |
| + } |
| + char* line = new char[decodeInfo.width()*decodeInfo.bytesPerPixel()]; |
|
scroggo
2015/05/18 14:03:58
This will leak. You can solve this a few different
emmaleeroach
2015/05/18 20:04:27
On 2015/05/18 14:03:58, scroggo wrote:
> This will
scroggo
2015/05/18 20:43:18
Yes.
|
| + for (int subset = 0; subset < fDivisor*2; subset++) { |
|
scroggo
2015/05/18 14:03:58
subset < fDivisor*2
Shouldn't this be subset < fD
emmaleeroach
2015/05/18 20:04:27
On 2015/05/18 14:03:58, scroggo wrote:
> subset <
|
| + //reset scanline decoder for right half of image |
| + if (subset == 2) { |
|
scroggo
2015/05/18 14:03:59
Again, this supposes that fDivisor is 2. The nice
emmaleeroach
2015/05/18 20:04:27
On 2015/05/18 14:03:59, scroggo wrote:
> Again, th
|
| + subsetScanlineDecoder = codec->getScanlineDecoder(decodeInfo, NULL, |
| + colorPtr, colorCountPtr); |
| + if (NULL == subsetScanlineDecoder) { |
| + return Error::Nonfatal("Cannot use scanline decoder for all images"); |
|
scroggo
2015/05/18 14:03:59
I think in this case we have an actual error. If t
emmaleeroach
2015/05/18 20:04:27
On 2015/05/18 14:03:59, scroggo wrote:
> I think i
scroggo
2015/05/18 20:43:18
Oh, no, the check is necessary; the behavior if su
emmaleeroach
2015/05/18 22:35:14
On 2015/05/18 20:43:18, scroggo wrote:
> On 2015/0
scroggo
2015/05/18 23:02:17
Yes. Both the message itself and "Error::Nonfatal"
|
| + } |
| + } |
| + for (int y = 0; y < subsetDecodeInfo.height(); ++y) { |
| + const SkImageGenerator::Result subsetResult = |
| + subsetScanlineDecoder->getScanlines(line, 1, 0); |
| + if (subset == 0 || subset == 1) { |
| + //if subset is on left copy left half of line |
| + memcpy(subsetBm.getAddr(0, y), line, |
| + subsetDecodeInfo.width()*subsetDecodeInfo.bytesPerPixel()); |
| + } else { |
| + //if subset if on right copy right half of line |
|
scroggo
2015/05/18 14:03:58
is*
emmaleeroach
2015/05/18 20:04:27
Acknowledged.
|
| + memcpy(subsetBm.getAddr(0,y), |
|
scroggo
2015/05/18 14:03:58
Won't this copy to the beginning of this row?
emmaleeroach
2015/05/18 20:04:27
On 2015/05/18 14:03:58, scroggo wrote:
> Won't thi
scroggo
2015/05/18 20:43:18
Oh, of course!
|
| + line + subsetDecodeInfo.width()*subsetDecodeInfo.bytesPerPixel(), |
| + subsetDecodeInfo.width()*subsetDecodeInfo.bytesPerPixel()); |
|
scroggo
2015/05/18 14:03:58
Won't this copy too much?
emmaleeroach
2015/05/18 20:04:27
On 2015/05/18 14:03:58, scroggo wrote:
> Won't thi
scroggo
2015/05/18 20:43:17
Got it. My eyes must have glazed over when I read
|
| + } |
| + switch (subsetResult) { |
| + case SkImageGenerator::kSuccess: |
| + case SkImageGenerator::kIncompleteInput: |
| + break; |
| + default: |
| + return SkStringPrintf("%s failed after %d scanlines with error" |
| + "message %d", fPath.c_str(), y-1, (int) subsetResult); |
| + } |
| + } |
| + int w; |
| + int h; |
|
scroggo
2015/05/18 14:03:58
nit: These variables look like width and height, b
emmaleeroach
2015/05/18 20:04:27
On 2015/05/18 14:03:58, scroggo wrote:
> nit: Thes
|
| + //set drawing position based on subset number |
| + switch (subset) { |
|
scroggo
2015/05/18 14:03:58
nit: This works with a divisor of 2, but I think i
emmaleeroach
2015/05/18 20:04:27
On 2015/05/18 14:03:58, scroggo wrote:
> nit: This
scroggo
2015/05/18 20:43:18
https://skia.googlesource.com/skia/+/7be0ce0ab123b
emmaleeroach
2015/05/18 22:35:14
On 2015/05/18 20:43:18, scroggo wrote:
> On 2015/0
|
| + case 0: |
| + w = 0; |
| + h = 0; |
| + break; |
| + case 1: |
| + w = 0; |
| + h = subsetDecodeInfo.height(); |
| + break; |
| + case 2: |
| + w = subsetDecodeInfo.width(); |
| + h = 0; |
| + break; |
| + case 3: |
| + w = subsetDecodeInfo.width(); |
| + h = subsetDecodeInfo.height(); |
| + break; |
| + } |
| + canvas->drawBitmap(subsetBm, w, h); |
| + } |
| break; |
| } |
| } |
| - canvas->drawBitmap(bitmap, 0, 0); |
| return ""; |
| } |