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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 | 55 |
56 void SubsetTranslateBench::onDraw(int n, SkCanvas* canvas) { | 56 void SubsetTranslateBench::onDraw(int n, SkCanvas* canvas) { |
57 // When the color type is kIndex8, we will need to store the color table. I f it is | 57 // When the color type is kIndex8, we will need to store the color table. I f it is |
58 // used, it will be initialized by the codec. | 58 // used, it will be initialized by the codec. |
59 int colorCount; | 59 int colorCount; |
60 SkPMColor colors[256]; | 60 SkPMColor colors[256]; |
61 if (fUseCodec) { | 61 if (fUseCodec) { |
62 for (int count = 0; count < n; count++) { | 62 for (int count = 0; count < n; count++) { |
63 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te())); | 63 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te())); |
64 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); | 64 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); |
65 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]); | 65 SkAutoTDeleteArray<uint8_t> row(nullptr); |
66 codec->startScanlineDecode(info, nullptr, colors, &colorCount); | 66 if (codec->getScanlineOrder() == SkCodec::kTopDown_SkScanlineOrder) { |
67 row.reset(new uint8_t[info.minRowBytes()]); | |
68 } | |
67 | 69 |
68 SkBitmap bitmap; | 70 SkBitmap bitmap; |
69 // Note that we use the same bitmap for all of the subsets. | 71 // Note that we use the same bitmap for all of the subsets. |
70 // It might be larger than necessary for the end subsets. | 72 // It might be larger than necessary for the end subsets. |
71 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); | 73 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); |
72 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); | 74 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); |
73 | 75 |
76 const uint32_t bpp = info.bytesPerPixel(); | |
77 | |
74 for (int x = 0; x < info.width(); x += fSubsetWidth) { | 78 for (int x = 0; x < info.width(); x += fSubsetWidth) { |
75 for (int y = 0; y < info.height(); y += fSubsetHeight) { | 79 for (int y = 0; y < info.height(); y += fSubsetHeight) { |
80 codec->startScanlineDecode(info, nullptr, colors, &colorCoun t); | |
scroggo
2015/10/06 20:36:04
Here's the bug (unless I'm missing something?): wi
msarett
2015/10/06 21:58:52
Ugh this is an embarrassing bug.
Theoretically, w
scroggo
2015/10/07 19:50:58
Done.
| |
76 codec->skipScanlines(y); | 81 codec->skipScanlines(y); |
82 | |
77 const uint32_t currSubsetWidth = | 83 const uint32_t currSubsetWidth = |
78 x + (int) fSubsetWidth > info.width() ? | 84 x + (int) fSubsetWidth > info.width() ? |
79 info.width() - x : fSubsetWidth; | 85 info.width() - x : fSubsetWidth; |
80 const uint32_t currSubsetHeight = | 86 const uint32_t currSubsetHeight = |
81 y + (int) fSubsetHeight > info.height() ? | 87 y + (int) fSubsetHeight > info.height() ? |
82 info.height() - y : fSubsetHeight; | 88 info.height() - y : fSubsetHeight; |
83 const uint32_t bpp = info.bytesPerPixel(); | 89 |
84 for (uint32_t y = 0; y < currSubsetHeight; y++) { | 90 switch (codec->getScanlineOrder()) { |
85 codec->getScanlines(row.get(), 1, 0); | 91 case SkCodec::kTopDown_SkScanlineOrder: |
86 memcpy(bitmap.getAddr(0, y), row.get() + x * bpp, | 92 for (uint32_t y = 0; y < currSubsetHeight; y++) { |
scroggo
2015/10/06 20:36:04
Again, I think this loop is unchanged.
msarett
2015/10/06 21:58:52
Acknowledged.
| |
87 currSubsetWidth * bpp); | 93 codec->getScanlines(row.get(), 1, 0); |
94 memcpy(bitmap.getAddr(0, y), row.get() + x * bpp , | |
95 currSubsetWidth * bpp); | |
96 } | |
97 break; | |
98 case SkCodec::kNone_SkScanlineOrder: { | |
99 // decode all scanlines that intersect the subset, a nd copy the subset | |
100 // into the output. | |
101 SkImageInfo stripeInfo = info.makeWH(info.width(), c urrSubsetHeight); | |
102 SkBitmap stripeBm; | |
103 alloc_pixels(&stripeBm, stripeInfo, colors, colorCou nt); | |
104 | |
105 codec->getScanlines(stripeBm.getPixels(), currSubset Height, | |
106 stripeBm.rowBytes()); | |
107 for (uint32_t subsetY = 0; subsetY < currSubsetHeigh t; subsetY++) { | |
108 memcpy(bitmap.getAddr(0, subsetY), stripeBm.getA ddr(x, subsetY), | |
109 currSubsetWidth * bpp); | |
110 } | |
111 break; | |
112 } | |
113 default: | |
114 // We currently are only testing kTopDown and kNone, which are the only | |
115 // two used by the subsets we care about. skbug.com/ 4428 | |
116 SkASSERT(false); | |
88 } | 117 } |
89 } | 118 } |
90 } | 119 } |
91 } | 120 } |
92 } else { | 121 } else { |
93 // We create a color table here to satisfy allocPixels() when the output | 122 // We create a color table here to satisfy allocPixels() when the output |
94 // type is kIndex8. It's okay that this is uninitialized since we never | 123 // type is kIndex8. It's okay that this is uninitialized since we never |
95 // use it. | 124 // use it. |
96 SkColorTable* colorTable = new SkColorTable(colors, 0); | 125 SkColorTable* colorTable = new SkColorTable(colors, 0); |
97 for (int count = 0; count < n; count++) { | 126 for (int count = 0; count < n; count++) { |
(...skipping 18 matching lines...) Expand all Loading... | |
116 const uint32_t currSubsetHeight = y + (int) fSubsetHeight > height ? | 145 const uint32_t currSubsetHeight = y + (int) fSubsetHeight > height ? |
117 height - y : fSubsetHeight; | 146 height - y : fSubsetHeight; |
118 SkIRect rect = SkIRect::MakeXYWH(x, y, currSubsetWidth, | 147 SkIRect rect = SkIRect::MakeXYWH(x, y, currSubsetWidth, |
119 currSubsetHeight); | 148 currSubsetHeight); |
120 decoder->decodeSubset(&bitmap, rect, fColorType); | 149 decoder->decodeSubset(&bitmap, rect, fColorType); |
121 } | 150 } |
122 } | 151 } |
123 } | 152 } |
124 } | 153 } |
125 } | 154 } |
OLD | NEW |