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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 | 59 |
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 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]); | |
70 codec->startScanlineDecode(info, nullptr, colors, &colorCount); | 69 codec->startScanlineDecode(info, nullptr, colors, &colorCount); |
71 | 70 |
72 SkBitmap bitmap; | 71 SkBitmap bitmap; |
73 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); | 72 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); |
74 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); | 73 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); |
75 | 74 |
76 codec->skipScanlines(fOffsetTop); | 75 codec->skipScanlines(fOffsetTop); |
77 uint32_t bpp = info.bytesPerPixel(); | 76 |
78 for (uint32_t y = 0; y < fSubsetHeight; y++) { | 77 const uint32_t bpp = info.bytesPerPixel(); |
79 codec->getScanlines(row.get(), 1, 0); | 78 |
80 memcpy(bitmap.getAddr(0, y), row.get() + fOffsetLeft * bpp, | 79 switch (codec->getScanlineOrder()) { |
81 fSubsetWidth * bpp); | 80 case SkCodec::kTopDown_SkScanlineOrder: { |
81 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes ()]); | |
scroggo
2015/10/06 20:36:04
This got moved because it's not needed for kNone.
msarett
2015/10/06 21:58:52
Acknowledged.
| |
82 for (uint32_t y = 0; y < fSubsetHeight; y++) { | |
scroggo
2015/10/06 20:36:04
This code should be unchanged; it's just now insid
msarett
2015/10/06 21:58:52
Acknowledged.
| |
83 codec->getScanlines(row.get(), 1, 0); | |
84 memcpy(bitmap.getAddr(0, y), row.get() + fOffsetLeft * b pp, | |
85 fSubsetWidth * bpp); | |
86 } | |
87 break; | |
88 } | |
89 case SkCodec::kNone_SkScanlineOrder: { | |
90 // decode all scanlines that intersect the subset, and copy the subset | |
91 // into the output. | |
92 SkImageInfo stripeInfo = info.makeWH(info.width(), fSubsetHe ight); | |
93 SkBitmap stripeBm; | |
94 alloc_pixels(&stripeBm, stripeInfo, colors, colorCount); | |
95 | |
96 codec->getScanlines(stripeBm.getPixels(), fSubsetHeight, str ipeBm.rowBytes()); | |
97 for (uint32_t y = 0; y < fSubsetHeight; y++) { | |
98 memcpy(bitmap.getAddr(0, y), stripeBm.getAddr(fOffsetLef t, y), | |
99 fSubsetWidth * bpp); | |
100 } | |
101 break; | |
102 } | |
103 default: | |
104 // We currently are only testing kTopDown and kNone, which a re the only | |
105 // two used by the subsets we care about. skbug.com/4428 | |
106 SkASSERT(false); | |
107 | |
82 } | 108 } |
83 } | 109 } |
84 } else { | 110 } else { |
85 for (int count = 0; count < n; count++) { | 111 for (int count = 0; count < n; count++) { |
86 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m)); | 112 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m)); |
87 int width, height; | 113 int width, height; |
88 decoder->buildTileIndex(fStream->duplicate(), &width, &height); | 114 decoder->buildTileIndex(fStream->duplicate(), &width, &height); |
89 SkBitmap bitmap; | 115 SkBitmap bitmap; |
90 SkIRect rect = SkIRect::MakeXYWH(fOffsetLeft, fOffsetTop, fSubsetWid th, | 116 SkIRect rect = SkIRect::MakeXYWH(fOffsetLeft, fOffsetTop, fSubsetWid th, |
91 fSubsetHeight); | 117 fSubsetHeight); |
92 decoder->decodeSubset(&bitmap, rect, fColorType); | 118 decoder->decodeSubset(&bitmap, rect, fColorType); |
93 } | 119 } |
94 } | 120 } |
95 } | 121 } |
OLD | NEW |