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 "SubsetTranslateBench.h" | 9 #include "SubsetTranslateBench.h" |
10 #include "SubsetBenchPriv.h" | 10 #include "SubsetBenchPriv.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 if (codec->getScanlineOrder() == SkCodec::kTopDown_SkScanlineOrder) { | 76 if (codec->getScanlineOrder() == SkCodec::kTopDown_SkScanlineOrder) { |
77 row.reset(new uint8_t[info.minRowBytes()]); | 77 row.reset(new uint8_t[info.minRowBytes()]); |
78 } | 78 } |
79 | 79 |
80 SkBitmap bitmap; | 80 SkBitmap bitmap; |
81 // Note that we use the same bitmap for all of the subsets. | 81 // Note that we use the same bitmap for all of the subsets. |
82 // It might be larger than necessary for the end subsets. | 82 // It might be larger than necessary for the end subsets. |
83 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); | 83 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); |
84 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); | 84 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); |
85 | 85 |
86 const uint32_t bpp = info.bytesPerPixel(); | |
87 | |
88 for (int x = 0; x < info.width(); x += fSubsetWidth) { | 86 for (int x = 0; x < info.width(); x += fSubsetWidth) { |
89 for (int y = 0; y < info.height(); y += fSubsetHeight) { | 87 for (int y = 0; y < info.height(); y += fSubsetHeight) { |
90 SkDEBUGCODE(SkCodec::Result result =) | |
91 codec->startScanlineDecode(info, nullptr, get_colors(&bitmap ), &colorCount); | |
92 SkASSERT(SkCodec::kSuccess == result); | |
93 | |
94 SkDEBUGCODE(int lines =) codec->skipScanlines(y); | |
95 SkASSERT(y == lines); | |
96 | |
97 const uint32_t currSubsetWidth = | 88 const uint32_t currSubsetWidth = |
98 x + (int) fSubsetWidth > info.width() ? | 89 x + (int) fSubsetWidth > info.width() ? |
99 info.width() - x : fSubsetWidth; | 90 info.width() - x : fSubsetWidth; |
100 const uint32_t currSubsetHeight = | 91 const uint32_t currSubsetHeight = |
101 y + (int) fSubsetHeight > info.height() ? | 92 y + (int) fSubsetHeight > info.height() ? |
102 info.height() - y : fSubsetHeight; | 93 info.height() - y : fSubsetHeight; |
103 | 94 |
104 switch (codec->getScanlineOrder()) { | 95 // The scanline decoder will handle subsetting in the x-dime nsion. |
105 case SkCodec::kTopDown_SkScanlineOrder: | 96 SkIRect subset = SkIRect::MakeXYWH(x, 0, currSubsetWidth, |
106 for (uint32_t y = 0; y < currSubsetHeight; y++) { | 97 codec->getInfo().height()); |
107 SkDEBUGCODE(lines =) codec->getScanlines(row.get (), 1, 0); | 98 SkCodec::Options options; |
108 SkASSERT(1 == lines); | 99 options.fSubset = ⊂ |
109 | 100 |
110 memcpy(bitmap.getAddr(0, y), row.get() + x * bpp , | 101 SkDEBUGCODE(SkCodec::Result result =) |
111 currSubsetWidth * bpp); | 102 codec->startScanlineDecode(info, &options, get_colors(&bitma p), &colorCount); |
112 } | 103 SkASSERT(SkCodec::kSuccess == result); |
113 break; | |
114 case SkCodec::kNone_SkScanlineOrder: { | |
115 // decode all scanlines that intersect the subset, a nd copy the subset | |
116 // into the output. | |
117 SkImageInfo stripeInfo = info.makeWH(info.width(), c urrSubsetHeight); | |
118 SkBitmap stripeBm; | |
119 alloc_pixels(&stripeBm, stripeInfo, colors, colorCou nt); | |
120 | 104 |
121 SkDEBUGCODE(lines =) codec->getScanlines(stripeBm.ge tPixels(), | 105 SkDEBUGCODE(bool success =) codec->skipScanlines(y); |
122 currSubsetHeight, stripeBm.rowBytes()); | 106 SkASSERT(success); |
123 SkASSERT(currSubsetHeight == (uint32_t) lines); | |
124 | 107 |
125 for (uint32_t subsetY = 0; subsetY < currSubsetHeigh t; subsetY++) { | 108 SkDEBUGCODE(int lines =) codec->getScanlines(bitmap.getPixel s(), |
scroggo
2015/10/12 16:11:20
Similar to the other one, can we declare this as a
msarett
2015/10/12 17:13:55
Yes.
| |
126 memcpy(bitmap.getAddr(0, subsetY), stripeBm.getA ddr(x, subsetY), | 109 currSubsetHeight, bitmap.rowBytes()); |
127 currSubsetWidth * bpp); | 110 SkASSERT(currSubsetHeight == (uint32_t) lines); |
128 } | |
129 break; | |
130 } | |
131 default: | |
132 // We currently are only testing kTopDown and kNone, which are the only | |
133 // two used by the subsets we care about. skbug.com/ 4428 | |
134 SkASSERT(false); | |
135 } | |
136 } | 111 } |
137 } | 112 } |
138 } | 113 } |
139 } else { | 114 } else { |
140 // We create a color table here to satisfy allocPixels() when the output | 115 // We create a color table here to satisfy allocPixels() when the output |
141 // type is kIndex8. It's okay that this is uninitialized since we never | 116 // type is kIndex8. It's okay that this is uninitialized since we never |
142 // use it. | 117 // use it. |
143 SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colors, 0)); | 118 SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colors, 0)); |
144 for (int count = 0; count < n; count++) { | 119 for (int count = 0; count < n; count++) { |
145 int width, height; | 120 int width, height; |
(...skipping 17 matching lines...) Expand all Loading... | |
163 const uint32_t currSubsetHeight = y + (int) fSubsetHeight > height ? | 138 const uint32_t currSubsetHeight = y + (int) fSubsetHeight > height ? |
164 height - y : fSubsetHeight; | 139 height - y : fSubsetHeight; |
165 SkIRect rect = SkIRect::MakeXYWH(x, y, currSubsetWidth, | 140 SkIRect rect = SkIRect::MakeXYWH(x, y, currSubsetWidth, |
166 currSubsetHeight); | 141 currSubsetHeight); |
167 SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorTy pe)); | 142 SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorTy pe)); |
168 } | 143 } |
169 } | 144 } |
170 } | 145 } |
171 } | 146 } |
172 } | 147 } |
OLD | NEW |