Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: tests/CodexTest.cpp

Issue 1757333002: Fix bug in SkGifCodec / Switch SkImageDec tests to use Codec (Closed) Base URL: https://skia.googlesource.com/skia.git@m50
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/CodecPriv.h ('k') | tests/FrontBufferedStreamTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 885 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 910
912 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr); 911 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr);
913 912
914 // Similarly, a stream which does not peek should still succeed. 913 // Similarly, a stream which does not peek should still succeed.
915 codec.reset(SkCodec::NewFromStream(new LimitedPeekingMemStream(data, 0))); 914 codec.reset(SkCodec::NewFromStream(new LimitedPeekingMemStream(data, 0)));
916 REPORTER_ASSERT(r, codec); 915 REPORTER_ASSERT(r, codec);
917 916
918 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr); 917 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr);
919 } 918 }
920 919
921 // SkCodec's wbmp decoder was initially more restrictive than SkImageDecoder. 920 // SkCodec's wbmp decoder was initially unnecessarily restrictive.
922 // It required the second byte to be zero. But SkImageDecoder allowed a couple 921 // It required the second byte to be zero. The wbmp specification allows
923 // of bits to be 1 (so long as they do not overlap with 0x9F). Test that 922 // a couple of bits to be 1 (so long as they do not overlap with 0x9F).
924 // SkCodec now supports an image with these bits set. 923 // Test that SkCodec now supports an image with these bits set.
925 DEF_TEST(Codec_wbmp, r) { 924 DEF_TEST(Codec_wbmp, r) {
926 const char* path = "mandrill.wbmp"; 925 const char* path = "mandrill.wbmp";
927 SkAutoTDelete<SkStream> stream(resource(path)); 926 SkAutoTDelete<SkStream> stream(resource(path));
928 if (!stream) { 927 if (!stream) {
929 SkDebugf("Missing resource '%s'\n", path); 928 SkDebugf("Missing resource '%s'\n", path);
930 return; 929 return;
931 } 930 }
932 931
933 // Modify the stream to contain a second byte with some bits set. 932 // Modify the stream to contain a second byte with some bits set.
934 SkAutoTUnref<SkData> data(SkCopyStreamToData(stream)); 933 SkAutoTUnref<SkData> data(SkCopyStreamToData(stream));
935 uint8_t* writeableData = static_cast<uint8_t*>(data->writable_data()); 934 uint8_t* writeableData = static_cast<uint8_t*>(data->writable_data());
936 writeableData[1] = static_cast<uint8_t>(~0x9F); 935 writeableData[1] = static_cast<uint8_t>(~0x9F);
937 936
938 // SkImageDecoder supports this. 937 // SkCodec should support this.
939 SkBitmap bitmap;
940 REPORTER_ASSERT(r, SkImageDecoder::DecodeMemory(data->data(), data->size(), &bitmap));
941
942 // So SkCodec should, too.
943 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data)); 938 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data));
944 REPORTER_ASSERT(r, codec); 939 REPORTER_ASSERT(r, codec);
945 if (!codec) { 940 if (!codec) {
946 return; 941 return;
947 } 942 }
948 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr); 943 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr);
949 } 944 }
950 945
951 // wbmp images have a header that can be arbitrarily large, depending on the 946 // wbmp images have a header that can be arbitrarily large, depending on the
952 // size of the image. We cap the size at 65535, meaning we only need to look at 947 // size of the image. We cap the size at 65535, meaning we only need to look at
(...skipping 16 matching lines...) Expand all
969 // 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.
970 // has bigger width/height) is also too big. 965 // has bigger width/height) is also too big.
971 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header 966 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header
972 0x84, 0x80, 0x00, // W: 65536 967 0x84, 0x80, 0x00, // W: 65536
973 0x84, 0x80, 0x00 }; // H: 65536 968 0x84, 0x80, 0x00 }; // H: 65536
974 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false)); 969 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false));
975 codec.reset(SkCodec::NewFromStream(stream.detach())); 970 codec.reset(SkCodec::NewFromStream(stream.detach()));
976 971
977 REPORTER_ASSERT(r, !codec); 972 REPORTER_ASSERT(r, !codec);
978 } 973 }
OLDNEW
« no previous file with comments | « tests/CodecPriv.h ('k') | tests/FrontBufferedStreamTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698