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 "SubsetZoomBench.h" | 9 #include "SubsetZoomBench.h" |
10 #include "SubsetBenchPriv.h" | 10 #include "SubsetBenchPriv.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 SkAutoTDeleteArray<uint8_t> row(nullptr); | 65 SkAutoTDeleteArray<uint8_t> row(nullptr); |
66 if (codec->getScanlineOrder() == SkCodec::kTopDown_SkScanlineOrder)
{ | 66 if (codec->getScanlineOrder() == SkCodec::kTopDown_SkScanlineOrder)
{ |
67 row.reset(new uint8_t[info.minRowBytes()]); | 67 row.reset(new uint8_t[info.minRowBytes()]); |
68 } | 68 } |
69 | 69 |
70 const int centerX = info.width() / 2; | 70 const int centerX = info.width() / 2; |
71 const int centerY = info.height() / 2; | 71 const int centerY = info.height() / 2; |
72 int w = fSubsetWidth; | 72 int w = fSubsetWidth; |
73 int h = fSubsetHeight; | 73 int h = fSubsetHeight; |
74 do { | 74 do { |
75 SkDEBUGCODE(SkCodec::Result result = ) | |
76 codec->startScanlineDecode(info, nullptr, colors, &colorCount); | |
77 SkASSERT(SkCodec::kSuccess == result); | |
78 | |
79 const int subsetStartX = SkTMax(0, centerX - w / 2); | 75 const int subsetStartX = SkTMax(0, centerX - w / 2); |
80 const int subsetStartY = SkTMax(0, centerY - h / 2); | 76 const int subsetStartY = SkTMax(0, centerY - h / 2); |
81 const int subsetWidth = SkTMin(w, info.width() - subsetStartX); | 77 const int subsetWidth = SkTMin(w, info.width() - subsetStartX); |
82 const int subsetHeight = SkTMin(h, info.height() - subsetStartY)
; | 78 const int subsetHeight = SkTMin(h, info.height() - subsetStartY)
; |
| 79 |
| 80 // The scanline decoder will handle subsetting in the x-dimensio
n. |
| 81 SkIRect subset = SkIRect::MakeXYWH(subsetStartX, 0, subsetWidth, |
| 82 codec->getInfo().height()); |
| 83 SkCodec::Options options; |
| 84 options.fSubset = ⊂ |
| 85 |
| 86 SkDEBUGCODE(SkCodec::Result result = ) |
| 87 codec->startScanlineDecode(info, &options, colors, &colorCount); |
| 88 SkASSERT(SkCodec::kSuccess == result); |
| 89 |
83 // Note that if we subsetted and scaled in a single step, we cou
ld use the | 90 // Note that if we subsetted and scaled in a single step, we cou
ld use the |
84 // same bitmap - as is often done in actual use cases. | 91 // same bitmap - as is often done in actual use cases. |
85 SkBitmap bitmap; | 92 SkBitmap bitmap; |
86 SkImageInfo subsetInfo = info.makeWH(subsetWidth, subsetHeight); | 93 SkImageInfo subsetInfo = info.makeWH(subsetWidth, subsetHeight); |
87 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); | 94 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); |
88 | 95 |
89 uint32_t bpp = info.bytesPerPixel(); | 96 SkDEBUGCODE(bool success = ) codec->skipScanlines(subsetStartY); |
| 97 SkASSERT(success); |
90 | 98 |
91 SkDEBUGCODE(int lines = ) codec->skipScanlines(subsetStartY); | 99 SkDEBUGCODE(int lines = ) codec->getScanlines(bitmap.getPixels()
, |
92 SkASSERT(subsetStartY == lines); | 100 subsetHeight, bitmap.rowBytes()); |
93 | 101 SkASSERT(subsetHeight == lines); |
94 switch (codec->getScanlineOrder()) { | |
95 case SkCodec::kTopDown_SkScanlineOrder: | |
96 for (int y = 0; y < subsetHeight; y++) { | |
97 SkDEBUGCODE(lines = ) codec->getScanlines(row.get(),
1, 0); | |
98 SkASSERT(1 == lines); | |
99 | |
100 memcpy(bitmap.getAddr(0, y), row.get() + subsetStart
X * bpp, | |
101 subsetWidth * bpp); | |
102 } | |
103 break; | |
104 case SkCodec::kNone_SkScanlineOrder: { | |
105 // decode all scanlines that intersect the subset, and c
opy the subset | |
106 // into the output. | |
107 SkImageInfo stripeInfo = info.makeWH(info.width(), subse
tHeight); | |
108 SkBitmap stripeBm; | |
109 alloc_pixels(&stripeBm, stripeInfo, colors, colorCount); | |
110 | |
111 SkDEBUGCODE(lines = ) codec->getScanlines(stripeBm.getPi
xels(), | |
112 subsetHeight, stripeBm.rowBytes()); | |
113 SkASSERT(subsetHeight == lines); | |
114 | |
115 for (int y = 0; y < subsetHeight; y++) { | |
116 memcpy(bitmap.getAddr(0, y), | |
117 stripeBm.getAddr(subsetStartX, y), | |
118 subsetWidth * bpp); | |
119 } | |
120 break; | |
121 } | |
122 default: | |
123 // We currently are only testing kTopDown and kNone, whi
ch are the only | |
124 // two used by the subsets we care about. skbug.com/4428 | |
125 SkASSERT(false); | |
126 } | |
127 | 102 |
128 w <<= 1; | 103 w <<= 1; |
129 h <<= 1; | 104 h <<= 1; |
130 } while (w < 2 * info.width() || h < 2 * info.height()); | 105 } while (w < 2 * info.width() || h < 2 * info.height()); |
131 } | 106 } |
132 } else { | 107 } else { |
133 for (int count = 0; count < n; count++) { | 108 for (int count = 0; count < n; count++) { |
134 int width, height; | 109 int width, height; |
135 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea
m)); | 110 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea
m)); |
136 SkAssertResult(decoder->buildTileIndex(fStream->duplicate(), &width,
&height)); | 111 SkAssertResult(decoder->buildTileIndex(fStream->duplicate(), &width,
&height)); |
(...skipping 10 matching lines...) Expand all Loading... |
147 SkBitmap bitmap; | 122 SkBitmap bitmap; |
148 SkIRect rect = SkIRect::MakeXYWH(subsetStartX, subsetStartY, sub
setWidth, | 123 SkIRect rect = SkIRect::MakeXYWH(subsetStartX, subsetStartY, sub
setWidth, |
149 subsetHeight); | 124 subsetHeight); |
150 SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorType))
; | 125 SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorType))
; |
151 w <<= 1; | 126 w <<= 1; |
152 h <<= 1; | 127 h <<= 1; |
153 } while (w < 2 * width || h < 2 * height); | 128 } while (w < 2 * width || h < 2 * height); |
154 } | 129 } |
155 } | 130 } |
156 } | 131 } |
OLD | NEW |