Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Unified Diff: dm/DMSrcSink.cpp

Issue 1134113006: dm changes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: removing extraX and extraY variables and moving declarations Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« dm/DM.cpp ('K') | « dm/DMSrcSink.h ('k') | src/codec/SkCodec_libpng.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dm/DMSrcSink.cpp
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index 090a24d86a62590f123881274578b0468e59a01d..beaabc60b0d67234e81c7015e2dc324bfbc98bdc 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,103 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
fPath.c_str(), y-1, (int) result);
}
}
+ canvas->drawBitmap(bitmap, 0, 0);
+ break;
+ }
+ case kScanline_Subset_Mode: {
+ //this mode decodes the image in divisor*divisor subsets, using a scanline decoder
+ const int divisor = 2;
+ const int w = decodeInfo.width();
+ const int h = decodeInfo.height();
+ 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);
+ }
+ const int subsetWidth = w/divisor;
+ const int subsetHeight = h/divisor;
+ /*
+ * if w or h are not evenly divided by divisor need to adjust width and height of end
+ * subsets to cover entire image.
+ * Add w%divisor and h%divisor to largestSubsetBm's width and height to adjust width
+ * and height of end subsets.
+ * subsetBm is extracted from largestSubsetBm.
+ * subsetBm's size is determined based on the current subset and may be larger for end
+ * subsets.
+ */
+ SkImageInfo largestSubsetDecodeInfo =
+ decodeInfo.makeWH(subsetWidth + w%divisor, subsetHeight + h%divisor);
+ SkBitmap largestSubsetBm;
+ if (!largestSubsetBm.tryAllocPixels(largestSubsetDecodeInfo, NULL, colorTable.get())) {
+ return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPath.c_str(),
+ largestSubsetDecodeInfo.width(), largestSubsetDecodeInfo.height());
+ }
+ char* line = SkNEW_ARRAY(char, decodeInfo.minRowBytes());
+ SkAutoTDeleteArray<char> lineDeleter(line);
+ for (int x = 0; x < subsetWidth*divisor; x += subsetWidth) {
+ //currentSubsetWidth may be larger than subsetWidth for rightmost subsets
+ int currentSubsetWidth;
+ if (x + 2*subsetWidth > w) {
msarett 2015/05/22 17:42:19 Is there another way to check for the end subset?
scroggo 2015/05/22 18:39:54 I agree that this seems a little clunky. I think i
emmaleer 2015/05/22 21:55:21 On 2015/05/22 18:39:54, scroggo wrote: > On 2015/0
scroggo 2015/05/26 14:09:34 I still find this loop a little clunky. What if we
emmaleer 2015/05/26 19:15:04 On 2015/05/26 14:09:34, scroggo wrote: > On 2015/0
+ currentSubsetWidth = subsetWidth + w - subsetWidth*divisor;
msarett 2015/05/22 17:42:19 nit: Can this be w%divisor? Can we reuse the valu
emmaleer 2015/05/22 21:55:21 On 2015/05/22 17:42:19, msarett wrote: > nit: Can
scroggo 2015/05/26 14:09:34 The thing I did not like about it was that it was
emmaleer 2015/05/26 19:15:04 Acknowledged.
+ } else {
+ currentSubsetWidth = subsetWidth;
+ }
+ for (int y = 0; y < subsetHeight*divisor; y += subsetHeight) {
+ //currentSubsetHeight may be larger than subsetHeight for bottom subsets
+ int currentSubsetHeight;
+ if (y + 2*subsetHeight > h) {
+ currentSubsetHeight = subsetHeight + h - subsetHeight*divisor;
msarett 2015/05/22 17:42:18 nit: Can this be h%divisor? Can we reuse the valu
emmaleer 2015/05/22 21:55:21 On 2015/05/22 17:42:18, msarett wrote: > nit: Can
+ } else {
+ currentSubsetHeight = subsetHeight;
+ }
+ //create scanline decoder for each subset
+ SkScanlineDecoder* subsetScanlineDecoder = codec->getScanlineDecoder(decodeInfo,
+ NULL, colorPtr, colorCountPtr);
+ if (NULL == subsetScanlineDecoder) {
+ if (x == 0 && y == 0) {
+ //first try, image may not be compatible
+ return Error::Nonfatal("Cannot use scanline decoder for all images");
+ } else {
+ return "Error scanline decoder is NULL";
+ }
+ }
+ //skip to first line of subset
+ const SkImageGenerator::Result skipResult =
+ subsetScanlineDecoder->skipScanlines(y);
+ switch (skipResult) {
+ case SkImageGenerator::kSuccess:
+ case SkImageGenerator::kIncompleteInput:
+ break;
+ default:
+ return SkStringPrintf("%s failed after attempting to skip %d scanlines"
+ "with error message %d", fPath.c_str(), y, (int) skipResult);
+ }
+ //create and set size of subsetBm
+ SkBitmap subsetBm;
+ SkIRect bounds = SkIRect::MakeWH(subsetWidth, subsetHeight);
+ bounds.setXYWH(0, 0, currentSubsetWidth, currentSubsetHeight);
+ SkAssertResult(largestSubsetBm.extractSubset(&subsetBm, bounds));
+ SkAutoLockPixels autlockSubsetBm(subsetBm, true);
+ for (int subsetY = 0; subsetY < currentSubsetHeight; ++subsetY) {
+ const SkImageGenerator::Result subsetResult =
+ subsetScanlineDecoder->getScanlines(line, 1, 0);
+ const size_t bpp = decodeInfo.bytesPerPixel();
+ //copy section of line based on x value
+ memcpy(subsetBm.getAddr(0, subsetY), line + x*bpp, currentSubsetWidth*bpp);
+ 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);
+ }
+ }
break;
}
}
- canvas->drawBitmap(bitmap, 0, 0);
return "";
}
« dm/DM.cpp ('K') | « dm/DMSrcSink.h ('k') | src/codec/SkCodec_libpng.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698