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

Unified Diff: dm/DMSrcSink.cpp

Issue 1719073002: Use new jpeg_crop_scanlines() API to optimize jpeg subset decodes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 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
Index: dm/DMSrcSink.cpp
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index 7ccaf223fc3a32b8e2baa867dcd575454332b6ec..093ee88c4e630343cfa6896f9a2a41c8f921f2a8 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -470,54 +470,39 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
canvas->drawBitmap(bitmap, 0, 0);
break;
}
- case kStripe_Mode: {
+ case kTile_Mode: {
+ const int width = decodeInfo.width();
const int height = decodeInfo.height();
// This value is chosen arbitrarily. We exercise more cases by choosing a value that
// does not align with image blocks.
scroggo 2016/02/22 15:55:03 Given that our implementation changes a bit depend
msarett 2016/02/22 17:38:15 Agreed. Changing this value to one that will test
- const int stripeHeight = 37;
- const int numStripes = (height + stripeHeight - 1) / stripeHeight;
+ const int tileSize = 51;
scroggo 2016/02/22 15:55:03 Why the change from 37 to 51?
msarett 2016/02/22 17:38:15 The larger the value, the test runs. however, I'v
scroggo 2016/02/22 18:46:47 I'm guessing you left out the word "faster"?
msarett 2016/02/22 19:07:43 Haha yes.
+ const int tileWidth = (width + tileSize - 1) / tileSize;
+ const int tileHeight = (height + tileSize - 1) / tileSize;
scroggo 2016/02/22 15:55:03 Why are we concerned with tiles in Y here? The old
msarett 2016/02/22 17:38:16 I guess we just use this to know how many times to
- // Decode odd stripes
- if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, NULL, colorPtr,
- colorCountPtr)
- || SkCodec::kTopDown_SkScanlineOrder != codec->getScanlineOrder()) {
- // This mode was designed to test the new skip scanlines API in libjpeg-turbo.
- // Jpegs have kTopDown_SkScanlineOrder, and at this time, it is not interesting
- // to run this test for image types that do not have this scanline ordering.
- return Error::Nonfatal("Could not start top-down scanline decoder");
- }
-
- for (int i = 0; i < numStripes; i += 2) {
- // Skip a stripe
- const int linesToSkip = SkTMin(stripeHeight, height - i * stripeHeight);
- codec->skipScanlines(linesToSkip);
+ SkCodec::Options opts;
+ SkIRect subset;
+ for (int tileX = 0; tileX < tileWidth; tileX++) {
+ const int startX = tileX * tileSize;
+ subset = SkIRect::MakeXYWH(startX, 0, SkTMin(tileSize, width - startX), height);
+ opts.fSubset = &subset;
+ for (int tileY = 0; tileY < tileHeight; tileY++) {
+ if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, &opts,
+ colorPtr, colorCountPtr) ||
+ SkCodec::kTopDown_SkScanlineOrder != codec->getScanlineOrder()) {
scroggo 2016/02/22 15:55:03 This is now only used for JPEG, so it seems like w
msarett 2016/02/22 17:38:16 Yes, I've fixed this.
+ if (0 == tileY && 0 == tileX) {
+ return Error::Nonfatal("Could not start top-down scanline decoder");
scroggo 2016/02/22 15:55:03 Is this not a bug? Why would startScanlineDecode f
msarett 2016/02/22 17:38:15 I believe that we used to need this when kInvalidC
scroggo 2016/02/22 18:46:47 sgtm
+ }
+ return "Could not restart scanline decoder.";
+ }
- // Read a stripe
- const int startY = (i + 1) * stripeHeight;
- const int linesToRead = SkTMin(stripeHeight, height - startY);
- if (linesToRead > 0) {
- codec->getScanlines(bitmap.getAddr(0, startY), linesToRead, bitmap.rowBytes());
+ const int startY = tileY * tileSize;
+ codec->skipScanlines(startY);
+ const int linesToGet = SkTMin(tileSize, height - startY);
+ codec->getScanlines(bitmap.getAddr(startX, startY), linesToGet,
+ bitmap.rowBytes());
}
}
- // Decode even stripes
- const SkCodec::Result startResult = codec->startScanlineDecode(decodeInfo, nullptr,
- colorPtr, colorCountPtr);
- if (SkCodec::kSuccess != startResult) {
- return "Failed to restart scanline decoder with same parameters.";
- }
- for (int i = 0; i < numStripes; i += 2) {
- // Read a stripe
- const int startY = i * stripeHeight;
- const int linesToRead = SkTMin(stripeHeight, height - startY);
- codec->getScanlines(bitmap.getAddr(0, startY), linesToRead, bitmap.rowBytes());
-
- // Skip a stripe
- const int linesToSkip = SkTMin(stripeHeight, height - (i + 1) * stripeHeight);
- if (linesToSkip > 0) {
- codec->skipScanlines(linesToSkip);
- }
- }
premultiply_if_necessary(bitmap);
canvas->drawBitmap(bitmap, 0, 0);
break;

Powered by Google App Engine
This is Rietveld 408576698