OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "CodecPriv.h" | 8 #include "CodecPriv.h" |
9 #include "Resources.h" | 9 #include "Resources.h" |
10 #include "SkAndroidCodec.h" | 10 #include "SkAndroidCodec.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 // Regression test for decoding a gif image with sampleSize of 4, which was | 191 // Regression test for decoding a gif image with sampleSize of 4, which was |
192 // previously crashing. | 192 // previously crashing. |
193 DEF_TEST(Gif_Sampled, r) { | 193 DEF_TEST(Gif_Sampled, r) { |
194 SkAutoTDelete<SkFILEStream> stream( | 194 SkAutoTDelete<SkFILEStream> stream( |
195 new SkFILEStream(GetResourcePath("test640x479.gif").c_str())); | 195 new SkFILEStream(GetResourcePath("test640x479.gif").c_str())); |
196 REPORTER_ASSERT(r, stream->isValid()); | 196 REPORTER_ASSERT(r, stream->isValid()); |
197 if (!stream->isValid()) { | 197 if (!stream->isValid()) { |
198 return; | 198 return; |
199 } | 199 } |
200 | 200 |
201 SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(stream.det
ach())); | 201 SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(stream.rel
ease())); |
202 REPORTER_ASSERT(r, codec); | 202 REPORTER_ASSERT(r, codec); |
203 if (!codec) { | 203 if (!codec) { |
204 return; | 204 return; |
205 } | 205 } |
206 | 206 |
207 // Construct a color table for the decode if necessary | 207 // Construct a color table for the decode if necessary |
208 SkAutoTUnref<SkColorTable> colorTable(nullptr); | 208 SkAutoTUnref<SkColorTable> colorTable(nullptr); |
209 SkPMColor* colorPtr = nullptr; | 209 SkPMColor* colorPtr = nullptr; |
210 int* colorCountPtr = nullptr; | 210 int* colorCountPtr = nullptr; |
211 int maxColors = 256; | 211 int maxColors = 256; |
212 if (kIndex_8_SkColorType == codec->getInfo().colorType()) { | 212 if (kIndex_8_SkColorType == codec->getInfo().colorType()) { |
213 SkPMColor colors[256]; | 213 SkPMColor colors[256]; |
214 colorTable.reset(new SkColorTable(colors, maxColors)); | 214 colorTable.reset(new SkColorTable(colors, maxColors)); |
215 colorPtr = const_cast<SkPMColor*>(colorTable->readColors()); | 215 colorPtr = const_cast<SkPMColor*>(colorTable->readColors()); |
216 colorCountPtr = &maxColors; | 216 colorCountPtr = &maxColors; |
217 } | 217 } |
218 | 218 |
219 SkAndroidCodec::AndroidOptions options; | 219 SkAndroidCodec::AndroidOptions options; |
220 options.fSampleSize = 4; | 220 options.fSampleSize = 4; |
221 options.fColorPtr = colorPtr; | 221 options.fColorPtr = colorPtr; |
222 options.fColorCount = colorCountPtr; | 222 options.fColorCount = colorCountPtr; |
223 | 223 |
224 SkBitmap bm; | 224 SkBitmap bm; |
225 bm.allocPixels(codec->getInfo(), nullptr, colorTable.get()); | 225 bm.allocPixels(codec->getInfo(), nullptr, colorTable.get()); |
226 const SkCodec::Result result = codec->getAndroidPixels(codec->getInfo(), bm.
getPixels(), | 226 const SkCodec::Result result = codec->getAndroidPixels(codec->getInfo(), bm.
getPixels(), |
227 bm.rowBytes(), &options); | 227 bm.rowBytes(), &options); |
228 REPORTER_ASSERT(r, result == SkCodec::kSuccess); | 228 REPORTER_ASSERT(r, result == SkCodec::kSuccess); |
229 } | 229 } |
OLD | NEW |