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" |
(...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1005 // Now test an image which is too big. Any image with a larger header (i.e. | 1005 // Now test an image which is too big. Any image with a larger header (i.e. |
1006 // has bigger width/height) is also too big. | 1006 // has bigger width/height) is also too big. |
1007 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header | 1007 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header |
1008 0x84, 0x80, 0x00, // W: 65536 | 1008 0x84, 0x80, 0x00, // W: 65536 |
1009 0x84, 0x80, 0x00 }; // H: 65536 | 1009 0x84, 0x80, 0x00 }; // H: 65536 |
1010 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false)); | 1010 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false)); |
1011 codec.reset(SkCodec::NewFromStream(stream.release())); | 1011 codec.reset(SkCodec::NewFromStream(stream.release())); |
1012 | 1012 |
1013 REPORTER_ASSERT(r, !codec); | 1013 REPORTER_ASSERT(r, !codec); |
1014 } | 1014 } |
| 1015 |
| 1016 DEF_TEST(Codec_jpeg_rewind, r) { |
| 1017 const char* path = "mandrill_512_q075.jpg"; |
| 1018 SkAutoTDelete<SkStream> stream(resource(path)); |
| 1019 if (!stream) { |
| 1020 SkDebugf("Missing resource '%s'\n", path); |
| 1021 return; |
| 1022 } |
| 1023 SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(stream.rel
ease())); |
| 1024 if (!codec) { |
| 1025 ERRORF(r, "Unable to create codec '%s'.", path); |
| 1026 return; |
| 1027 } |
| 1028 |
| 1029 const int width = codec->getInfo().width(); |
| 1030 const int height = codec->getInfo().height(); |
| 1031 size_t rowBytes = sizeof(SkPMColor) * width; |
| 1032 SkAutoMalloc pixelStorage(height * rowBytes); |
| 1033 |
| 1034 // Perform a sampled decode. |
| 1035 SkAndroidCodec::AndroidOptions opts; |
| 1036 opts.fSampleSize = 12; |
| 1037 codec->getAndroidPixels(codec->getInfo().makeWH(width / 12, height / 12), pi
xelStorage.get(), |
| 1038 rowBytes, &opts); |
| 1039 |
| 1040 // Rewind the codec and perform a full image decode. |
| 1041 SkCodec::Result result = codec->getPixels(codec->getInfo(), pixelStorage.get
(), rowBytes); |
| 1042 REPORTER_ASSERT(r, SkCodec::kSuccess == result); |
| 1043 } |
OLD | NEW |