Chromium Code Reviews| 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 SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType); |
|
msarett
2015/04/09 16:26:32
If we don't add this, gif will try to decode to kI
scroggo
2015/04/09 17:37:17
Another option: we could check for kIndex8, and se
msarett
2015/04/09 19:21:31
Done.
| |
| 45 REPORTER_ASSERT(r, info.dimensions() == size); | 45 REPORTER_ASSERT(r, info.dimensions() == size); |
| 46 SkBitmap bm; | 46 SkBitmap bm; |
| 47 bm.allocPixels(info); | 47 bm.allocPixels(info); |
| 48 SkAutoLockPixels autoLockPixels(bm); | 48 SkAutoLockPixels autoLockPixels(bm); |
| 49 SkImageGenerator::Result result = | 49 SkImageGenerator::Result result = |
| 50 codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); | 50 codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); |
| 51 REPORTER_ASSERT(r, result == SkImageGenerator::kSuccess); | 51 REPORTER_ASSERT(r, result == SkImageGenerator::kSuccess); |
| 52 | 52 |
| 53 SkMD5::Digest digest1, digest2; | 53 SkMD5::Digest digest1, digest2; |
| 54 md5(bm, &digest1); | 54 md5(bm, &digest1); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 // BMP | 87 // BMP |
| 88 check(r, "randPixels.bmp", SkISize::Make(8, 8), false); | 88 check(r, "randPixels.bmp", SkISize::Make(8, 8), false); |
| 89 | 89 |
| 90 // ICO | 90 // ICO |
| 91 // These two tests examine interestingly different behavior: | 91 // These two tests examine interestingly different behavior: |
| 92 // Decodes an embedded BMP image | 92 // Decodes an embedded BMP image |
| 93 check(r, "color_wheel.ico", SkISize::Make(128, 128), false); | 93 check(r, "color_wheel.ico", SkISize::Make(128, 128), false); |
| 94 // Decodes an embedded PNG image | 94 // Decodes an embedded PNG image |
| 95 check(r, "google_chrome.ico", SkISize::Make(256, 256), false); | 95 check(r, "google_chrome.ico", SkISize::Make(256, 256), false); |
| 96 | 96 |
| 97 // GIF | |
| 98 check(r, "box.gif", SkISize::Make(200, 55), false); | |
| 99 check(r, "color_wheel.gif", SkISize::Make(128, 128), false); | |
| 100 check(r, "randPixels.gif", SkISize::Make(8, 8), false); | |
| 101 | |
| 97 // PNG | 102 // PNG |
| 98 check(r, "arrow.png", SkISize::Make(187, 312), true); | 103 check(r, "arrow.png", SkISize::Make(187, 312), true); |
| 99 check(r, "baby_tux.png", SkISize::Make(240, 246), true); | 104 check(r, "baby_tux.png", SkISize::Make(240, 246), true); |
| 100 check(r, "color_wheel.png", SkISize::Make(128, 128), true); | 105 check(r, "color_wheel.png", SkISize::Make(128, 128), true); |
| 101 check(r, "half-transparent-white-pixel.png", SkISize::Make(1, 1), true); | 106 check(r, "half-transparent-white-pixel.png", SkISize::Make(1, 1), true); |
| 102 check(r, "mandrill_128.png", SkISize::Make(128, 128), true); | 107 check(r, "mandrill_128.png", SkISize::Make(128, 128), true); |
| 103 check(r, "mandrill_16.png", SkISize::Make(16, 16), true); | 108 check(r, "mandrill_16.png", SkISize::Make(16, 16), true); |
| 104 check(r, "mandrill_256.png", SkISize::Make(256, 256), true); | 109 check(r, "mandrill_256.png", SkISize::Make(256, 256), true); |
| 105 check(r, "mandrill_32.png", SkISize::Make(32, 32), true); | 110 check(r, "mandrill_32.png", SkISize::Make(32, 32), true); |
| 106 check(r, "mandrill_512.png", SkISize::Make(512, 512), true); | 111 check(r, "mandrill_512.png", SkISize::Make(512, 512), true); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 131 const char emptyGif[] = "GIFVER"; | 136 const char emptyGif[] = "GIFVER"; |
| 132 | 137 |
| 133 test_invalid_stream(r, nonSupportedStream, sizeof(nonSupportedStream)); | 138 test_invalid_stream(r, nonSupportedStream, sizeof(nonSupportedStream)); |
| 134 test_invalid_stream(r, emptyPng, sizeof(emptyPng)); | 139 test_invalid_stream(r, emptyPng, sizeof(emptyPng)); |
| 135 test_invalid_stream(r, emptyJpeg, sizeof(emptyJpeg)); | 140 test_invalid_stream(r, emptyJpeg, sizeof(emptyJpeg)); |
| 136 test_invalid_stream(r, emptyWebp, sizeof(emptyWebp)); | 141 test_invalid_stream(r, emptyWebp, sizeof(emptyWebp)); |
| 137 test_invalid_stream(r, emptyBmp, sizeof(emptyBmp)); | 142 test_invalid_stream(r, emptyBmp, sizeof(emptyBmp)); |
| 138 test_invalid_stream(r, emptyIco, sizeof(emptyIco)); | 143 test_invalid_stream(r, emptyIco, sizeof(emptyIco)); |
| 139 test_invalid_stream(r, emptyGif, sizeof(emptyGif)); | 144 test_invalid_stream(r, emptyGif, sizeof(emptyGif)); |
| 140 } | 145 } |
| OLD | NEW |