Index: dm/DMSrcSink.cpp |
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp |
index 090a24d86a62590f123881274578b0468e59a01d..e208770490623f327d31046259e8238139705a54 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,63 @@ 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 divisor*divisor subsets, using a scanline decoder |
+ const int divisor = 2; |
+ 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()/divisor, |
+ decodeInfo.height()/divisor); |
+ 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()]; |
msarett
2015/05/19 14:01:13
nit: Let's check with Leon, but I think the prefer
scroggo
2015/05/19 15:21:41
The short answer is yes.
A little background: we
emmaleer
2015/05/21 17:51:13
Acknowledged.
|
+ SkAutoTDeleteArray<char> lineDeleter(line); |
+ const int subsetWidth = subsetDecodeInfo.width(); |
+ const int subsetHeight = subsetDecodeInfo.height(); |
+ const int w = subsetWidth*divisor; |
scroggo
2015/05/18 23:02:17
I think it would be better to use decodeInfo.width
msarett
2015/05/19 14:01:13
I think this is the tricky part of this test. If
scroggo
2015/05/19 15:21:41
Indeed. We need to investigate how exactly BitmapR
emmaleer
2015/05/21 17:51:13
On 2015/05/19 15:21:41, scroggo wrote:
> On 2015/0
|
+ const int h = subsetHeight*divisor; |
+ if (divisor > w || divisor > h) { |
+ return SkStringPrintf("divisor %d is too big for %s with dimensions (%d x %d)", |
+ divisor, fPath.c_str(), w, h); |
+ } |
+ for (int x = 0; x < w; x += subsetWidth) { |
+ for (int y = 0; y < h; y += subsetHeight) { |
+ for (int subsetY = 0; subsetY < subsetHeight; ++subsetY) { |
msarett
2015/05/19 14:01:13
My preference is to use a different scanline decod
scroggo
2015/05/19 15:21:41
Good questions. I think it's reasonable to use a n
emmaleer
2015/05/21 17:51:13
On 2015/05/19 15:21:41, scroggo wrote:
> On 2015/0
|
+ const SkImageGenerator::Result subsetResult = |
+ subsetScanlineDecoder->getScanlines(line, 1, 0); |
msarett
2015/05/19 14:01:13
I'm a little confused about how this works. It lo
scroggo
2015/05/19 15:21:41
I missed this at first, too - at the end of the y
emmaleer
2015/05/21 17:51:13
On 2015/05/19 15:21:41, scroggo wrote:
> On 2015/0
|
+ //copy section of line based on x value |
+ memcpy(subsetBm.getAddr(0, subsetY), |
+ line + x*subsetDecodeInfo.bytesPerPixel(), |
+ subsetDecodeInfo.width()*subsetDecodeInfo.bytesPerPixel()); |
+ 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); |
+ } |
+ } |
+ canvas->drawBitmap(subsetBm, x, y); |
+ } |
+ subsetScanlineDecoder = codec->getScanlineDecoder(decodeInfo, NULL, |
+ colorPtr, colorCountPtr); |
+ if (NULL == subsetScanlineDecoder) { |
+ return SkStringPrintf("Error scanline decoder is NULL"); |
scroggo
2015/05/18 23:02:17
No need for SkStringPrintf. You're returning an Er
|
+ } |
+ } |
break; |
} |
} |
- canvas->drawBitmap(bitmap, 0, 0); |
return ""; |
} |