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

Unified Diff: dm/DMSrcSink.cpp

Issue 1134113006: dm changes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: changes after code review 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
« no previous file with comments | « dm/DMSrcSink.h ('k') | experimental/example.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..af7429cac3c92e85e272afa5e57da50c68f05a73 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,67 @@ 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()];
+ SkAutoTDeleteArray<char> lineDeleter(line);
+ for (int subset = 0; subset < divisor*divisor; subset++) {
+ //reset scanline decoder for right half of image
+ if (0 == subset%divisor && 0 != subset) {
scroggo 2015/05/18 20:43:18 Alternatively, you could remove the second half of
+ subsetScanlineDecoder = codec->getScanlineDecoder(decodeInfo, NULL,
+ colorPtr, colorCountPtr);
+ }
+ int x;
+ int y;
+ //set drawing position based on subset number
+ if(subset == 0) {
+ //first subset, draw to top left corner
+ x = 0;
+ y = 0;
+ } else if (0 == subset%divisor) {
+ //new column, reset y, increment x by subset width
+ x += subsetDecodeInfo.width();
+ y = 0;
+ } else {
+ //new row, increment y by subset height
+ y += subsetDecodeInfo.height();
+ }
+ for (int y = 0; y < subsetDecodeInfo.height(); ++y) {
+ const SkImageGenerator::Result subsetResult =
+ subsetScanlineDecoder->getScanlines(line, 1, 0);
+ //copy section of line based on x value
+ memcpy(subsetBm.getAddr(0, y), 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);
+ }
break;
}
}
- canvas->drawBitmap(bitmap, 0, 0);
return "";
}
« no previous file with comments | « dm/DMSrcSink.h ('k') | experimental/example.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698