diff options
author | msarett <msarett@google.com> | 2015-10-13 12:50:14 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-13 12:50:14 -0700 |
commit | fdb47571a3b5e72469b67de44e32ac14d9352ab4 (patch) | |
tree | cc98e7952e756c3c8825e7f9af3b280b3fc7b449 /bench | |
parent | eb85b8321bc917169ba26c8fce76b64d2e3dfe81 (diff) |
Add subsetting to SkScanlineDecoder
This CL allows the SkScanlineDecoder to decode partial
scanlines.
This is a first step in efficiently implementing subsetting
in SkScaledCodec.
BUG=skia:4209
Review URL: https://codereview.chromium.org/1390213002
Diffstat (limited to 'bench')
-rw-r--r-- | bench/subset/SubsetSingleBench.cpp | 53 | ||||
-rw-r--r-- | bench/subset/SubsetTranslateBench.cpp | 62 | ||||
-rw-r--r-- | bench/subset/SubsetZoomBench.cpp | 64 |
3 files changed, 48 insertions, 131 deletions
diff --git a/bench/subset/SubsetSingleBench.cpp b/bench/subset/SubsetSingleBench.cpp index b4e92e4e22..47a897fd83 100644 --- a/bench/subset/SubsetSingleBench.cpp +++ b/bench/subset/SubsetSingleBench.cpp @@ -65,56 +65,29 @@ void SubsetSingleBench::onDraw(int n, SkCanvas* canvas) { if (fUseCodec) { for (int count = 0; count < n; count++) { SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplicate())); + SkASSERT(SkCodec::kOutOfOrder_SkScanlineOrder != codec->getScanlineOrder()); const SkImageInfo info = codec->getInfo().makeColorType(fColorType); + // The scanline decoder will handle subsetting in the x-dimension. + SkIRect subset = SkIRect::MakeXYWH(fOffsetLeft, 0, fSubsetWidth, + codec->getInfo().height()); + SkCodec::Options options; + options.fSubset = ⊂ + SkDEBUGCODE(SkCodec::Result result =) - codec->startScanlineDecode(info, nullptr, colors, &colorCount); + codec->startScanlineDecode(info, &options, colors, &colorCount); SkASSERT(result == SkCodec::kSuccess); SkBitmap bitmap; SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); alloc_pixels(&bitmap, subsetInfo, colors, colorCount); - SkDEBUGCODE(int lines = ) codec->skipScanlines(fOffsetTop); - SkASSERT((uint32_t) lines == fOffsetTop); - - const uint32_t bpp = info.bytesPerPixel(); - - switch (codec->getScanlineOrder()) { - case SkCodec::kTopDown_SkScanlineOrder: { - SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]); - for (uint32_t y = 0; y < fSubsetHeight; y++) { - SkDEBUGCODE(lines = ) codec->getScanlines(row.get(), 1, 0); - SkASSERT(lines == 1); - - memcpy(bitmap.getAddr(0, y), row.get() + fOffsetLeft * bpp, - fSubsetWidth * bpp); - } - break; - } - case SkCodec::kNone_SkScanlineOrder: { - // decode all scanlines that intersect the subset, and copy the subset - // into the output. - SkImageInfo stripeInfo = info.makeWH(info.width(), fSubsetHeight); - SkBitmap stripeBm; - alloc_pixels(&stripeBm, stripeInfo, colors, colorCount); - - SkDEBUGCODE(lines = ) codec->getScanlines(stripeBm.getPixels(), fSubsetHeight, - stripeBm.rowBytes()); - SkASSERT((uint32_t) lines == fSubsetHeight); - - for (uint32_t y = 0; y < fSubsetHeight; y++) { - memcpy(bitmap.getAddr(0, y), stripeBm.getAddr(fOffsetLeft, y), - fSubsetWidth * bpp); - } - break; - } - default: - // We currently are only testing kTopDown and kNone, which are the only - // two used by the subsets we care about. skbug.com/4428 - SkASSERT(false); + SkDEBUGCODE(bool success = ) codec->skipScanlines(fOffsetTop); + SkASSERT(success); - } + SkDEBUGCODE(uint32_t lines = ) codec->getScanlines(bitmap.getPixels(), fSubsetHeight, + bitmap.rowBytes()); + SkASSERT(lines == fSubsetHeight); } } else { for (int count = 0; count < n; count++) { diff --git a/bench/subset/SubsetTranslateBench.cpp b/bench/subset/SubsetTranslateBench.cpp index 27c628edde..d8da6db566 100644 --- a/bench/subset/SubsetTranslateBench.cpp +++ b/bench/subset/SubsetTranslateBench.cpp @@ -71,11 +71,8 @@ void SubsetTranslateBench::onDraw(int n, SkCanvas* canvas) { if (fUseCodec) { for (int count = 0; count < n; count++) { SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplicate())); + SkASSERT(SkCodec::kOutOfOrder_SkScanlineOrder != codec->getScanlineOrder()); const SkImageInfo info = codec->getInfo().makeColorType(fColorType); - SkAutoTDeleteArray<uint8_t> row(nullptr); - if (codec->getScanlineOrder() == SkCodec::kTopDown_SkScanlineOrder) { - row.reset(new uint8_t[info.minRowBytes()]); - } SkBitmap bitmap; // Note that we use the same bitmap for all of the subsets. @@ -83,17 +80,8 @@ void SubsetTranslateBench::onDraw(int n, SkCanvas* canvas) { SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); alloc_pixels(&bitmap, subsetInfo, colors, colorCount); - const uint32_t bpp = info.bytesPerPixel(); - for (int x = 0; x < info.width(); x += fSubsetWidth) { for (int y = 0; y < info.height(); y += fSubsetHeight) { - SkDEBUGCODE(SkCodec::Result result =) - codec->startScanlineDecode(info, nullptr, get_colors(&bitmap), &colorCount); - SkASSERT(SkCodec::kSuccess == result); - - SkDEBUGCODE(int lines =) codec->skipScanlines(y); - SkASSERT(y == lines); - const uint32_t currSubsetWidth = x + (int) fSubsetWidth > info.width() ? info.width() - x : fSubsetWidth; @@ -101,38 +89,22 @@ void SubsetTranslateBench::onDraw(int n, SkCanvas* canvas) { y + (int) fSubsetHeight > info.height() ? info.height() - y : fSubsetHeight; - switch (codec->getScanlineOrder()) { - case SkCodec::kTopDown_SkScanlineOrder: - for (uint32_t y = 0; y < currSubsetHeight; y++) { - SkDEBUGCODE(lines =) codec->getScanlines(row.get(), 1, 0); - SkASSERT(1 == lines); - - memcpy(bitmap.getAddr(0, y), row.get() + x * bpp, - currSubsetWidth * bpp); - } - break; - case SkCodec::kNone_SkScanlineOrder: { - // decode all scanlines that intersect the subset, and copy the subset - // into the output. - SkImageInfo stripeInfo = info.makeWH(info.width(), currSubsetHeight); - SkBitmap stripeBm; - alloc_pixels(&stripeBm, stripeInfo, colors, colorCount); - - SkDEBUGCODE(lines =) codec->getScanlines(stripeBm.getPixels(), - currSubsetHeight, stripeBm.rowBytes()); - SkASSERT(currSubsetHeight == (uint32_t) lines); - - for (uint32_t subsetY = 0; subsetY < currSubsetHeight; subsetY++) { - memcpy(bitmap.getAddr(0, subsetY), stripeBm.getAddr(x, subsetY), - currSubsetWidth * bpp); - } - break; - } - default: - // We currently are only testing kTopDown and kNone, which are the only - // two used by the subsets we care about. skbug.com/4428 - SkASSERT(false); - } + // The scanline decoder will handle subsetting in the x-dimension. + SkIRect subset = SkIRect::MakeXYWH(x, 0, currSubsetWidth, + codec->getInfo().height()); + SkCodec::Options options; + options.fSubset = ⊂ + + SkDEBUGCODE(SkCodec::Result result =) + codec->startScanlineDecode(info, &options, get_colors(&bitmap), &colorCount); + SkASSERT(SkCodec::kSuccess == result); + + SkDEBUGCODE(bool success =) codec->skipScanlines(y); + SkASSERT(success); + + SkDEBUGCODE(uint32_t lines =) codec->getScanlines(bitmap.getPixels(), + currSubsetHeight, bitmap.rowBytes()); + SkASSERT(currSubsetHeight == lines); } } } diff --git a/bench/subset/SubsetZoomBench.cpp b/bench/subset/SubsetZoomBench.cpp index 3edc17f1cb..f17a97c26b 100644 --- a/bench/subset/SubsetZoomBench.cpp +++ b/bench/subset/SubsetZoomBench.cpp @@ -61,69 +61,41 @@ void SubsetZoomBench::onDraw(int n, SkCanvas* canvas) { if (fUseCodec) { for (int count = 0; count < n; count++) { SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplicate())); + SkASSERT(SkCodec::kOutOfOrder_SkScanlineOrder != codec->getScanlineOrder()); const SkImageInfo info = codec->getInfo().makeColorType(fColorType); - SkAutoTDeleteArray<uint8_t> row(nullptr); - if (codec->getScanlineOrder() == SkCodec::kTopDown_SkScanlineOrder) { - row.reset(new uint8_t[info.minRowBytes()]); - } const int centerX = info.width() / 2; const int centerY = info.height() / 2; int w = fSubsetWidth; int h = fSubsetHeight; do { - SkDEBUGCODE(SkCodec::Result result = ) - codec->startScanlineDecode(info, nullptr, colors, &colorCount); - SkASSERT(SkCodec::kSuccess == result); - const int subsetStartX = SkTMax(0, centerX - w / 2); const int subsetStartY = SkTMax(0, centerY - h / 2); const int subsetWidth = SkTMin(w, info.width() - subsetStartX); const int subsetHeight = SkTMin(h, info.height() - subsetStartY); + + // The scanline decoder will handle subsetting in the x-dimension. + SkIRect subset = SkIRect::MakeXYWH(subsetStartX, 0, subsetWidth, + codec->getInfo().height()); + SkCodec::Options options; + options.fSubset = ⊂ + + SkDEBUGCODE(SkCodec::Result result = ) + codec->startScanlineDecode(info, &options, colors, &colorCount); + SkASSERT(SkCodec::kSuccess == result); + // Note that if we subsetted and scaled in a single step, we could use the // same bitmap - as is often done in actual use cases. SkBitmap bitmap; SkImageInfo subsetInfo = info.makeWH(subsetWidth, subsetHeight); alloc_pixels(&bitmap, subsetInfo, colors, colorCount); - uint32_t bpp = info.bytesPerPixel(); - - SkDEBUGCODE(int lines = ) codec->skipScanlines(subsetStartY); - SkASSERT(subsetStartY == lines); - - switch (codec->getScanlineOrder()) { - case SkCodec::kTopDown_SkScanlineOrder: - for (int y = 0; y < subsetHeight; y++) { - SkDEBUGCODE(lines = ) codec->getScanlines(row.get(), 1, 0); - SkASSERT(1 == lines); - - memcpy(bitmap.getAddr(0, y), row.get() + subsetStartX * bpp, - subsetWidth * bpp); - } - break; - case SkCodec::kNone_SkScanlineOrder: { - // decode all scanlines that intersect the subset, and copy the subset - // into the output. - SkImageInfo stripeInfo = info.makeWH(info.width(), subsetHeight); - SkBitmap stripeBm; - alloc_pixels(&stripeBm, stripeInfo, colors, colorCount); - - SkDEBUGCODE(lines = ) codec->getScanlines(stripeBm.getPixels(), - subsetHeight, stripeBm.rowBytes()); - SkASSERT(subsetHeight == lines); - - for (int y = 0; y < subsetHeight; y++) { - memcpy(bitmap.getAddr(0, y), - stripeBm.getAddr(subsetStartX, y), - subsetWidth * bpp); - } - break; - } - default: - // We currently are only testing kTopDown and kNone, which are the only - // two used by the subsets we care about. skbug.com/4428 - SkASSERT(false); - } + SkDEBUGCODE(bool success = ) codec->skipScanlines(subsetStartY); + SkASSERT(success); + + SkDEBUGCODE(int lines = ) codec->getScanlines(bitmap.getPixels(), + subsetHeight, bitmap.rowBytes()); + SkASSERT(subsetHeight == lines); w <<= 1; h <<= 1; |