| 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 "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkCodec.h" | 10 #include "SkCodec.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 SkAutoTDelete<SkStream> stream(resource(path)); | 34 SkAutoTDelete<SkStream> stream(resource(path)); |
| 35 if (!stream) { | 35 if (!stream) { |
| 36 SkDebugf("Missing resource '%s'\n", path); | 36 SkDebugf("Missing resource '%s'\n", path); |
| 37 return; | 37 return; |
| 38 } | 38 } |
| 39 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); | 39 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); |
| 40 if (!codec) { | 40 if (!codec) { |
| 41 ERRORF(r, "Unable to decode '%s'", path); | 41 ERRORF(r, "Unable to decode '%s'", path); |
| 42 return; | 42 return; |
| 43 } | 43 } |
| 44 SkImageInfo info = codec->getInfo(); | 44 |
| 45 // This test is used primarily to verify rewinding works properly. Using kN
32 allows |
| 46 // us to test this without the added overhead of creating different bitmaps
depending |
| 47 // on the color type (ex: building a color table for kIndex8). DM is where
we test |
| 48 // decodes to all possible destination color types. |
| 49 SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType); |
| 45 REPORTER_ASSERT(r, info.dimensions() == size); | 50 REPORTER_ASSERT(r, info.dimensions() == size); |
| 46 SkBitmap bm; | 51 SkBitmap bm; |
| 47 bm.allocPixels(info); | 52 bm.allocPixels(info); |
| 48 SkAutoLockPixels autoLockPixels(bm); | 53 SkAutoLockPixels autoLockPixels(bm); |
| 49 SkImageGenerator::Result result = | 54 SkImageGenerator::Result result = |
| 50 codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); | 55 codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); |
| 51 REPORTER_ASSERT(r, result == SkImageGenerator::kSuccess); | 56 REPORTER_ASSERT(r, result == SkImageGenerator::kSuccess); |
| 52 | 57 |
| 53 SkMD5::Digest digest1, digest2; | 58 SkMD5::Digest digest1, digest2; |
| 54 md5(bm, &digest1); | 59 md5(bm, &digest1); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 // BMP | 92 // BMP |
| 88 check(r, "randPixels.bmp", SkISize::Make(8, 8), false); | 93 check(r, "randPixels.bmp", SkISize::Make(8, 8), false); |
| 89 | 94 |
| 90 // ICO | 95 // ICO |
| 91 // These two tests examine interestingly different behavior: | 96 // These two tests examine interestingly different behavior: |
| 92 // Decodes an embedded BMP image | 97 // Decodes an embedded BMP image |
| 93 check(r, "color_wheel.ico", SkISize::Make(128, 128), false); | 98 check(r, "color_wheel.ico", SkISize::Make(128, 128), false); |
| 94 // Decodes an embedded PNG image | 99 // Decodes an embedded PNG image |
| 95 check(r, "google_chrome.ico", SkISize::Make(256, 256), false); | 100 check(r, "google_chrome.ico", SkISize::Make(256, 256), false); |
| 96 | 101 |
| 102 // GIF |
| 103 check(r, "box.gif", SkISize::Make(200, 55), false); |
| 104 check(r, "color_wheel.gif", SkISize::Make(128, 128), false); |
| 105 check(r, "randPixels.gif", SkISize::Make(8, 8), false); |
| 106 |
| 97 // PNG | 107 // PNG |
| 98 check(r, "arrow.png", SkISize::Make(187, 312), true); | 108 check(r, "arrow.png", SkISize::Make(187, 312), true); |
| 99 check(r, "baby_tux.png", SkISize::Make(240, 246), true); | 109 check(r, "baby_tux.png", SkISize::Make(240, 246), true); |
| 100 check(r, "color_wheel.png", SkISize::Make(128, 128), true); | 110 check(r, "color_wheel.png", SkISize::Make(128, 128), true); |
| 101 check(r, "half-transparent-white-pixel.png", SkISize::Make(1, 1), true); | 111 check(r, "half-transparent-white-pixel.png", SkISize::Make(1, 1), true); |
| 102 check(r, "mandrill_128.png", SkISize::Make(128, 128), true); | 112 check(r, "mandrill_128.png", SkISize::Make(128, 128), true); |
| 103 check(r, "mandrill_16.png", SkISize::Make(16, 16), true); | 113 check(r, "mandrill_16.png", SkISize::Make(16, 16), true); |
| 104 check(r, "mandrill_256.png", SkISize::Make(256, 256), true); | 114 check(r, "mandrill_256.png", SkISize::Make(256, 256), true); |
| 105 check(r, "mandrill_32.png", SkISize::Make(32, 32), true); | 115 check(r, "mandrill_32.png", SkISize::Make(32, 32), true); |
| 106 check(r, "mandrill_512.png", SkISize::Make(512, 512), true); | 116 check(r, "mandrill_512.png", SkISize::Make(512, 512), true); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 131 const char emptyGif[] = "GIFVER"; | 141 const char emptyGif[] = "GIFVER"; |
| 132 | 142 |
| 133 test_invalid_stream(r, nonSupportedStream, sizeof(nonSupportedStream)); | 143 test_invalid_stream(r, nonSupportedStream, sizeof(nonSupportedStream)); |
| 134 test_invalid_stream(r, emptyPng, sizeof(emptyPng)); | 144 test_invalid_stream(r, emptyPng, sizeof(emptyPng)); |
| 135 test_invalid_stream(r, emptyJpeg, sizeof(emptyJpeg)); | 145 test_invalid_stream(r, emptyJpeg, sizeof(emptyJpeg)); |
| 136 test_invalid_stream(r, emptyWebp, sizeof(emptyWebp)); | 146 test_invalid_stream(r, emptyWebp, sizeof(emptyWebp)); |
| 137 test_invalid_stream(r, emptyBmp, sizeof(emptyBmp)); | 147 test_invalid_stream(r, emptyBmp, sizeof(emptyBmp)); |
| 138 test_invalid_stream(r, emptyIco, sizeof(emptyIco)); | 148 test_invalid_stream(r, emptyIco, sizeof(emptyIco)); |
| 139 test_invalid_stream(r, emptyGif, sizeof(emptyGif)); | 149 test_invalid_stream(r, emptyGif, sizeof(emptyGif)); |
| 140 } | 150 } |
| OLD | NEW |