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