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" | |
13 #include "SkData.h" | 12 #include "SkData.h" |
14 #include "SkImageDecoder.h" | 13 #include "SkImageDecoder.h" |
15 #include "SkMD5.h" | 14 #include "SkMD5.h" |
16 #include "SkRandom.h" | 15 #include "SkRandom.h" |
17 #include "SkStream.h" | 16 #include "SkStream.h" |
18 #include "SkStreamPriv.h" | 17 #include "SkStreamPriv.h" |
19 #include "SkPngChunkReader.h" | 18 #include "SkPngChunkReader.h" |
20 #include "Test.h" | 19 #include "Test.h" |
21 | 20 |
22 #include "png.h" | 21 #include "png.h" |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 ERRORF(r, "Unable to decode '%s'", path); | 372 ERRORF(r, "Unable to decode '%s'", path); |
374 return; | 373 return; |
375 } | 374 } |
376 | 375 |
377 SkBitmap bm; | 376 SkBitmap bm; |
378 SkMD5::Digest scaledCodecDigest; | 377 SkMD5::Digest scaledCodecDigest; |
379 test_android_codec(r, codec, bm, info, size, expectedResult, | 378 test_android_codec(r, codec, bm, info, size, expectedResult, |
380 &scaledCodecDigest, &codecDigest); | 379 &scaledCodecDigest, &codecDigest); |
381 } | 380 } |
382 | 381 |
383 // Test SkCodecImageGenerator | |
384 if (!isIncomplete) { | |
385 SkAutoTDelete<SkStream> stream(resource(path)); | |
386 SkAutoTUnref<SkData> fullData(SkData::NewFromStream(stream, stream->getL
ength())); | |
387 SkAutoTDelete<SkImageGenerator> gen(SkCodecImageGenerator::NewFromEncode
dCodec(fullData)); | |
388 SkBitmap bm; | |
389 bm.allocPixels(info); | |
390 SkAutoLockPixels autoLockPixels(bm); | |
391 REPORTER_ASSERT(r, gen->getPixels(info, bm.getPixels(), bm.rowBytes())); | |
392 compare_to_good_digest(r, codecDigest, bm); | |
393 } | |
394 | |
395 // If we've just tested incomplete decodes, let's run the same test again on
full decodes. | 382 // If we've just tested incomplete decodes, let's run the same test again on
full decodes. |
396 if (isIncomplete) { | 383 if (isIncomplete) { |
397 check(r, path, size, supportsScanlineDecoding, supportsSubsetDecoding, f
alse); | 384 check(r, path, size, supportsScanlineDecoding, supportsSubsetDecoding, f
alse); |
398 } | 385 } |
399 } | 386 } |
400 | 387 |
401 DEF_TEST(Codec, r) { | 388 DEF_TEST(Codec, r) { |
402 // WBMP | 389 // WBMP |
403 check(r, "mandrill.wbmp", SkISize::Make(512, 512), true, false); | 390 check(r, "mandrill.wbmp", SkISize::Make(512, 512), true, false); |
404 | 391 |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 // Now test an image which is too big. Any image with a larger header (i.e. | 947 // Now test an image which is too big. Any image with a larger header (i.e. |
961 // has bigger width/height) is also too big. | 948 // has bigger width/height) is also too big. |
962 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header | 949 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header |
963 0x84, 0x80, 0x00, // W: 65536 | 950 0x84, 0x80, 0x00, // W: 65536 |
964 0x84, 0x80, 0x00 }; // H: 65536 | 951 0x84, 0x80, 0x00 }; // H: 65536 |
965 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false)); | 952 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false)); |
966 codec.reset(SkCodec::NewFromStream(stream.detach())); | 953 codec.reset(SkCodec::NewFromStream(stream.detach())); |
967 | 954 |
968 REPORTER_ASSERT(r, !codec); | 955 REPORTER_ASSERT(r, !codec); |
969 } | 956 } |
OLD | NEW |