Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "CodecBenchPriv.h" | 8 #include "CodecBenchPriv.h" |
| 9 #include "SubsetSingleBench.h" | 9 #include "SubsetSingleBench.h" |
| 10 #include "SubsetBenchPriv.h" | 10 #include "SubsetBenchPriv.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 void SubsetSingleBench::onDraw(int n, SkCanvas* canvas) { | 60 void SubsetSingleBench::onDraw(int n, SkCanvas* canvas) { |
| 61 // When the color type is kIndex8, we will need to store the color table. I f it is | 61 // When the color type is kIndex8, we will need to store the color table. I f it is |
| 62 // used, it will be initialized by the codec. | 62 // used, it will be initialized by the codec. |
| 63 int colorCount; | 63 int colorCount; |
| 64 SkPMColor colors[256]; | 64 SkPMColor colors[256]; |
| 65 if (fUseCodec) { | 65 if (fUseCodec) { |
| 66 for (int count = 0; count < n; count++) { | 66 for (int count = 0; count < n; count++) { |
| 67 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te())); | 67 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te())); |
| 68 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); | 68 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); |
| 69 | 69 |
| 70 // The scanline decoder will handle subsetting in the x-dimension. | |
| 71 SkIRect subset = SkIRect::MakeXYWH(fOffsetLeft, 0, fSubsetWidth, | |
| 72 codec->getInfo().height()); | |
| 73 SkCodec::Options options; | |
| 74 options.fSubset = ⊂ | |
| 75 | |
| 70 SkDEBUGCODE(SkCodec::Result result =) | 76 SkDEBUGCODE(SkCodec::Result result =) |
| 71 codec->startScanlineDecode(info, nullptr, colors, &colorCount); | 77 codec->startScanlineDecode(info, &options, colors, &colorCount); |
| 72 SkASSERT(result == SkCodec::kSuccess); | 78 SkASSERT(result == SkCodec::kSuccess); |
| 73 | 79 |
| 74 SkBitmap bitmap; | 80 SkBitmap bitmap; |
| 75 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); | 81 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); |
| 76 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); | 82 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); |
| 77 | 83 |
| 78 SkDEBUGCODE(int lines = ) codec->skipScanlines(fOffsetTop); | 84 SkDEBUGCODE(bool success = ) codec->skipScanlines(fOffsetTop); |
| 79 SkASSERT((uint32_t) lines == fOffsetTop); | 85 SkASSERT(success); |
| 80 | 86 |
| 81 const uint32_t bpp = info.bytesPerPixel(); | 87 SkDEBUGCODE(int lines = ) codec->getScanlines(bitmap.getPixels(), fS ubsetHeight, |
|
scroggo
2015/10/12 16:11:20
What would happen if you just declared lines as a
msarett
2015/10/12 17:13:55
Yes that will.
| |
| 82 | 88 bitmap.rowBytes()); |
| 83 switch (codec->getScanlineOrder()) { | 89 SkASSERT((uint32_t) lines == fSubsetHeight); |
|
scroggo
2015/10/12 16:11:20
Oh, this is interesting. If I understand correctly
msarett
2015/10/12 17:13:55
It doesn't work for kOutOfOrder. I'll add a check
| |
| 84 case SkCodec::kTopDown_SkScanlineOrder: { | |
| 85 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes ()]); | |
| 86 for (uint32_t y = 0; y < fSubsetHeight; y++) { | |
| 87 SkDEBUGCODE(lines = ) codec->getScanlines(row.get(), 1, 0); | |
| 88 SkASSERT(lines == 1); | |
| 89 | |
| 90 memcpy(bitmap.getAddr(0, y), row.get() + fOffsetLeft * b pp, | |
| 91 fSubsetWidth * bpp); | |
| 92 } | |
| 93 break; | |
| 94 } | |
| 95 case SkCodec::kNone_SkScanlineOrder: { | |
| 96 // decode all scanlines that intersect the subset, and copy the subset | |
| 97 // into the output. | |
| 98 SkImageInfo stripeInfo = info.makeWH(info.width(), fSubsetHe ight); | |
| 99 SkBitmap stripeBm; | |
| 100 alloc_pixels(&stripeBm, stripeInfo, colors, colorCount); | |
| 101 | |
| 102 SkDEBUGCODE(lines = ) codec->getScanlines(stripeBm.getPixels (), fSubsetHeight, | |
| 103 stripeBm.rowBytes ()); | |
| 104 SkASSERT((uint32_t) lines == fSubsetHeight); | |
| 105 | |
| 106 for (uint32_t y = 0; y < fSubsetHeight; y++) { | |
| 107 memcpy(bitmap.getAddr(0, y), stripeBm.getAddr(fOffsetLef t, y), | |
| 108 fSubsetWidth * bpp); | |
| 109 } | |
| 110 break; | |
| 111 } | |
| 112 default: | |
| 113 // We currently are only testing kTopDown and kNone, which a re the only | |
| 114 // two used by the subsets we care about. skbug.com/4428 | |
| 115 SkASSERT(false); | |
| 116 | |
| 117 } | |
| 118 } | 90 } |
| 119 } else { | 91 } else { |
| 120 for (int count = 0; count < n; count++) { | 92 for (int count = 0; count < n; count++) { |
| 121 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m)); | 93 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m)); |
| 122 int width, height; | 94 int width, height; |
| 123 SkAssertResult(decoder->buildTileIndex(fStream->duplicate(), &width, &height)); | 95 SkAssertResult(decoder->buildTileIndex(fStream->duplicate(), &width, &height)); |
| 124 SkBitmap bitmap; | 96 SkBitmap bitmap; |
| 125 SkIRect rect = SkIRect::MakeXYWH(fOffsetLeft, fOffsetTop, fSubsetWid th, | 97 SkIRect rect = SkIRect::MakeXYWH(fOffsetLeft, fOffsetTop, fSubsetWid th, |
| 126 fSubsetHeight); | 98 fSubsetHeight); |
| 127 SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorType)); | 99 SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorType)); |
| 128 } | 100 } |
| 129 } | 101 } |
| 130 } | 102 } |
| OLD | NEW |