| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 // two used by the subsets we care about. skbug.com/
4428 | 133 // two used by the subsets we care about. skbug.com/
4428 |
| 134 SkASSERT(false); | 134 SkASSERT(false); |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 } else { | 139 } else { |
| 140 // We create a color table here to satisfy allocPixels() when the output | 140 // 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 | 141 // type is kIndex8. It's okay that this is uninitialized since we never |
| 142 // use it. | 142 // use it. |
| 143 SkColorTable* colorTable = new SkColorTable(colors, 0); | 143 SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colors, 0)); |
| 144 for (int count = 0; count < n; count++) { | 144 for (int count = 0; count < n; count++) { |
| 145 int width, height; | 145 int width, height; |
| 146 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea
m)); | 146 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea
m)); |
| 147 SkAssertResult(decoder->buildTileIndex(fStream->duplicate(), &width,
&height)); | 147 SkAssertResult(decoder->buildTileIndex(fStream->duplicate(), &width,
&height)); |
| 148 SkBitmap bitmap; | 148 SkBitmap bitmap; |
| 149 // Note that we use the same bitmap for all of the subsets. | 149 // Note that we use the same bitmap for all of the subsets. |
| 150 // It might be larger than necessary for the end subsets. | 150 // It might be larger than necessary for the end subsets. |
| 151 // If we do not include this step, decodeSubset() would allocate spa
ce | 151 // If we do not include this step, decodeSubset() would allocate spa
ce |
| 152 // for the pixels automatically, but this would not allow us to reus
e the | 152 // for the pixels automatically, but this would not allow us to reus
e the |
| 153 // same bitmap as the other subsets. We want to reuse the same bitm
ap | 153 // same bitmap as the other subsets. We want to reuse the same bitm
ap |
| 154 // because it gives a more fair comparison with SkCodec and is a com
mon | 154 // because it gives a more fair comparison with SkCodec and is a com
mon |
| 155 // use case of BitmapRegionDecoder. | 155 // use case of BitmapRegionDecoder. |
| 156 bitmap.allocPixels(SkImageInfo::Make(fSubsetWidth, fSubsetHeight, | 156 bitmap.allocPixels(SkImageInfo::Make(fSubsetWidth, fSubsetHeight, |
| 157 fColorType, kOpaque_SkAlphaType), nullptr, colorTable); | 157 fColorType, kOpaque_SkAlphaType), nullptr, colorTable); |
| 158 | 158 |
| 159 for (int x = 0; x < width; x += fSubsetWidth) { | 159 for (int x = 0; x < width; x += fSubsetWidth) { |
| 160 for (int y = 0; y < height; y += fSubsetHeight) { | 160 for (int y = 0; y < height; y += fSubsetHeight) { |
| 161 const uint32_t currSubsetWidth = x + (int) fSubsetWidth > wi
dth ? | 161 const uint32_t currSubsetWidth = x + (int) fSubsetWidth > wi
dth ? |
| 162 width - x : fSubsetWidth; | 162 width - x : fSubsetWidth; |
| 163 const uint32_t currSubsetHeight = y + (int) fSubsetHeight >
height ? | 163 const uint32_t currSubsetHeight = y + (int) fSubsetHeight >
height ? |
| 164 height - y : fSubsetHeight; | 164 height - y : fSubsetHeight; |
| 165 SkIRect rect = SkIRect::MakeXYWH(x, y, currSubsetWidth, | 165 SkIRect rect = SkIRect::MakeXYWH(x, y, currSubsetWidth, |
| 166 currSubsetHeight); | 166 currSubsetHeight); |
| 167 SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorTy
pe)); | 167 SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorTy
pe)); |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 } | 172 } |
| OLD | NEW |