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 "Resources.h" | 8 #include "Resources.h" |
9 #include "SkAndroidCodec.h" | 9 #include "SkAndroidCodec.h" |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
11 #include "SkCodec.h" | 11 #include "SkCodec.h" |
12 #include "SkCodecImageGenerator.h" | 12 #include "SkCodecImageGenerator.h" |
13 #include "SkData.h" | 13 #include "SkData.h" |
| 14 #include "SkFrontBufferedStream.h" |
14 #include "SkImageDecoder.h" | 15 #include "SkImageDecoder.h" |
15 #include "SkMD5.h" | 16 #include "SkMD5.h" |
16 #include "SkRandom.h" | 17 #include "SkRandom.h" |
17 #include "SkStream.h" | 18 #include "SkStream.h" |
18 #include "SkStreamPriv.h" | 19 #include "SkStreamPriv.h" |
19 #include "SkPngChunkReader.h" | 20 #include "SkPngChunkReader.h" |
20 #include "Test.h" | 21 #include "Test.h" |
21 | 22 |
22 #include "png.h" | 23 #include "png.h" |
23 | 24 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 } else { | 174 } else { |
174 codec.reset(SkCodec::NewFromStream(stream.detach())); | 175 codec.reset(SkCodec::NewFromStream(stream.detach())); |
175 } | 176 } |
176 if (!codec) { | 177 if (!codec) { |
177 ERRORF(r, "Unable to decode '%s'", path); | 178 ERRORF(r, "Unable to decode '%s'", path); |
178 return; | 179 return; |
179 } | 180 } |
180 | 181 |
181 // Test full image decodes with SkCodec | 182 // Test full image decodes with SkCodec |
182 SkMD5::Digest codecDigest; | 183 SkMD5::Digest codecDigest; |
183 SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType); | 184 const SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType); |
184 SkBitmap bm; | 185 SkBitmap bm; |
185 SkCodec::Result expectedResult = isIncomplete ? SkCodec::kIncompleteInput :
SkCodec::kSuccess; | 186 SkCodec::Result expectedResult = isIncomplete ? SkCodec::kIncompleteInput :
SkCodec::kSuccess; |
186 test_codec(r, codec.get(), bm, info, size, expectedResult, &codecDigest, nul
lptr); | 187 test_codec(r, codec.get(), bm, info, size, expectedResult, &codecDigest, nul
lptr); |
187 | 188 |
188 // Scanline decoding follows. | 189 // Scanline decoding follows. |
189 // Need to call startScanlineDecode() first. | 190 // Need to call startScanlineDecode() first. |
190 REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0) | 191 REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0) |
191 == 0); | 192 == 0); |
192 REPORTER_ASSERT(r, codec->skipScanlines(1) | 193 REPORTER_ASSERT(r, codec->skipScanlines(1) |
193 == 0); | 194 == 0); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 ERRORF(r, "Unable to decode '%s'", path); | 307 ERRORF(r, "Unable to decode '%s'", path); |
307 return; | 308 return; |
308 } | 309 } |
309 | 310 |
310 SkBitmap bm; | 311 SkBitmap bm; |
311 SkMD5::Digest androidCodecDigest; | 312 SkMD5::Digest androidCodecDigest; |
312 test_codec(r, androidCodec.get(), bm, info, size, expectedResult, &andro
idCodecDigest, | 313 test_codec(r, androidCodec.get(), bm, info, size, expectedResult, &andro
idCodecDigest, |
313 &codecDigest); | 314 &codecDigest); |
314 } | 315 } |
315 | 316 |
316 // Test SkCodecImageGenerator | |
317 if (!isIncomplete) { | 317 if (!isIncomplete) { |
| 318 // Test SkCodecImageGenerator |
318 SkAutoTDelete<SkStream> stream(resource(path)); | 319 SkAutoTDelete<SkStream> stream(resource(path)); |
319 SkAutoTUnref<SkData> fullData(SkData::NewFromStream(stream, stream->getL
ength())); | 320 SkAutoTUnref<SkData> fullData(SkData::NewFromStream(stream, stream->getL
ength())); |
320 SkAutoTDelete<SkImageGenerator> gen(SkCodecImageGenerator::NewFromEncode
dCodec(fullData)); | 321 SkAutoTDelete<SkImageGenerator> gen(SkCodecImageGenerator::NewFromEncode
dCodec(fullData)); |
321 SkBitmap bm; | 322 SkBitmap bm; |
322 bm.allocPixels(info); | 323 bm.allocPixels(info); |
323 SkAutoLockPixels autoLockPixels(bm); | 324 SkAutoLockPixels autoLockPixels(bm); |
324 REPORTER_ASSERT(r, gen->getPixels(info, bm.getPixels(), bm.rowBytes())); | 325 REPORTER_ASSERT(r, gen->getPixels(info, bm.getPixels(), bm.rowBytes())); |
325 compare_to_good_digest(r, codecDigest, bm); | 326 compare_to_good_digest(r, codecDigest, bm); |
| 327 |
| 328 // Test using SkFrontBufferedStream, as Android does |
| 329 SkStream* bufferedStream = SkFrontBufferedStream::Create(new SkMemoryStr
eam(fullData), |
| 330 SkCodec::MinBufferedBytesNeeded()); |
| 331 REPORTER_ASSERT(r, bufferedStream); |
| 332 codec.reset(SkCodec::NewFromStream(bufferedStream)); |
| 333 REPORTER_ASSERT(r, codec); |
| 334 if (codec) { |
| 335 test_info(r, codec.get(), info, SkCodec::kSuccess, &codecDigest); |
| 336 } |
326 } | 337 } |
327 | 338 |
328 // If we've just tested incomplete decodes, let's run the same test again on
full decodes. | 339 // If we've just tested incomplete decodes, let's run the same test again on
full decodes. |
329 if (isIncomplete) { | 340 if (isIncomplete) { |
330 check(r, path, size, supportsScanlineDecoding, supportsSubsetDecoding, f
alse); | 341 check(r, path, size, supportsScanlineDecoding, supportsSubsetDecoding, f
alse); |
331 } | 342 } |
332 } | 343 } |
333 | 344 |
334 DEF_TEST(Codec, r) { | 345 DEF_TEST(Codec, r) { |
335 // WBMP | 346 // WBMP |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
953 // Now test an image which is too big. Any image with a larger header (i.e. | 964 // Now test an image which is too big. Any image with a larger header (i.e. |
954 // has bigger width/height) is also too big. | 965 // has bigger width/height) is also too big. |
955 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header | 966 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header |
956 0x84, 0x80, 0x00, // W: 65536 | 967 0x84, 0x80, 0x00, // W: 65536 |
957 0x84, 0x80, 0x00 }; // H: 65536 | 968 0x84, 0x80, 0x00 }; // H: 65536 |
958 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false)); | 969 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false)); |
959 codec.reset(SkCodec::NewFromStream(stream.detach())); | 970 codec.reset(SkCodec::NewFromStream(stream.detach())); |
960 | 971 |
961 REPORTER_ASSERT(r, !codec); | 972 REPORTER_ASSERT(r, !codec); |
962 } | 973 } |
OLD | NEW |