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 "SkFrontBufferedStream.h" |
15 #include "SkImageDecoder.h" | |
16 #include "SkMD5.h" | 15 #include "SkMD5.h" |
17 #include "SkRandom.h" | 16 #include "SkRandom.h" |
18 #include "SkStream.h" | 17 #include "SkStream.h" |
19 #include "SkStreamPriv.h" | 18 #include "SkStreamPriv.h" |
20 #include "SkPngChunkReader.h" | 19 #include "SkPngChunkReader.h" |
21 #include "Test.h" | 20 #include "Test.h" |
22 | 21 |
23 #include "png.h" | 22 #include "png.h" |
24 | 23 |
25 static SkStreamAsset* resource(const char path[]) { | 24 static SkStreamAsset* resource(const char path[]) { |
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 | 907 |
909 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr); | 908 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr); |
910 | 909 |
911 // Similarly, a stream which does not peek should still succeed. | 910 // Similarly, a stream which does not peek should still succeed. |
912 codec.reset(SkCodec::NewFromStream(new LimitedPeekingMemStream(data, 0))); | 911 codec.reset(SkCodec::NewFromStream(new LimitedPeekingMemStream(data, 0))); |
913 REPORTER_ASSERT(r, codec); | 912 REPORTER_ASSERT(r, codec); |
914 | 913 |
915 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr); | 914 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr); |
916 } | 915 } |
917 | 916 |
918 // SkCodec's wbmp decoder was initially more restrictive than SkImageDecoder. | 917 // SkCodec's wbmp decoder was initially unnecessarily restrictive. |
919 // It required the second byte to be zero. But SkImageDecoder allowed a couple | 918 // It required the second byte to be zero. The wbmp specification allows |
920 // of bits to be 1 (so long as they do not overlap with 0x9F). Test that | 919 // a couple of bits to be 1 (so long as they do not overlap with 0x9F). |
921 // SkCodec now supports an image with these bits set. | 920 // Test that SkCodec now supports an image with these bits set. |
922 DEF_TEST(Codec_wbmp, r) { | 921 DEF_TEST(Codec_wbmp, r) { |
923 const char* path = "mandrill.wbmp"; | 922 const char* path = "mandrill.wbmp"; |
924 SkAutoTDelete<SkStream> stream(resource(path)); | 923 SkAutoTDelete<SkStream> stream(resource(path)); |
925 if (!stream) { | 924 if (!stream) { |
926 SkDebugf("Missing resource '%s'\n", path); | 925 SkDebugf("Missing resource '%s'\n", path); |
927 return; | 926 return; |
928 } | 927 } |
929 | 928 |
930 // Modify the stream to contain a second byte with some bits set. | 929 // Modify the stream to contain a second byte with some bits set. |
931 SkAutoTUnref<SkData> data(SkCopyStreamToData(stream)); | 930 SkAutoTUnref<SkData> data(SkCopyStreamToData(stream)); |
932 uint8_t* writeableData = static_cast<uint8_t*>(data->writable_data()); | 931 uint8_t* writeableData = static_cast<uint8_t*>(data->writable_data()); |
933 writeableData[1] = static_cast<uint8_t>(~0x9F); | 932 writeableData[1] = static_cast<uint8_t>(~0x9F); |
934 | 933 |
935 // SkImageDecoder supports this. | 934 // SkCodec should support this. |
936 SkBitmap bitmap; | |
937 REPORTER_ASSERT(r, SkImageDecoder::DecodeMemory(data->data(), data->size(),
&bitmap)); | |
938 | |
939 // So SkCodec should, too. | |
940 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data)); | 935 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data)); |
941 REPORTER_ASSERT(r, codec); | 936 REPORTER_ASSERT(r, codec); |
942 if (!codec) { | 937 if (!codec) { |
943 return; | 938 return; |
944 } | 939 } |
945 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr); | 940 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr); |
946 } | 941 } |
947 | 942 |
948 // wbmp images have a header that can be arbitrarily large, depending on the | 943 // wbmp images have a header that can be arbitrarily large, depending on the |
949 // size of the image. We cap the size at 65535, meaning we only need to look at | 944 // size of the image. We cap the size at 65535, meaning we only need to look at |
(...skipping 16 matching lines...) Expand all Loading... |
966 // Now test an image which is too big. Any image with a larger header (i.e. | 961 // Now test an image which is too big. Any image with a larger header (i.e. |
967 // has bigger width/height) is also too big. | 962 // has bigger width/height) is also too big. |
968 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header | 963 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header |
969 0x84, 0x80, 0x00, // W: 65536 | 964 0x84, 0x80, 0x00, // W: 65536 |
970 0x84, 0x80, 0x00 }; // H: 65536 | 965 0x84, 0x80, 0x00 }; // H: 65536 |
971 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false)); | 966 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false)); |
972 codec.reset(SkCodec::NewFromStream(stream.detach())); | 967 codec.reset(SkCodec::NewFromStream(stream.detach())); |
973 | 968 |
974 REPORTER_ASSERT(r, !codec); | 969 REPORTER_ASSERT(r, !codec); |
975 } | 970 } |
OLD | NEW |