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 12 matching lines...) Expand all Loading... |
23 size_t rowLen = bm.info().bytesPerPixel() * bm.width(); | 23 size_t rowLen = bm.info().bytesPerPixel() * bm.width(); |
24 for (int y = 0; y < bm.height(); ++y) { | 24 for (int y = 0; y < bm.height(); ++y) { |
25 md5.update(static_cast<uint8_t*>(bm.getAddr(0, y)), rowLen); | 25 md5.update(static_cast<uint8_t*>(bm.getAddr(0, y)), rowLen); |
26 } | 26 } |
27 md5.finish(*digest); | 27 md5.finish(*digest); |
28 } | 28 } |
29 | 29 |
30 static void check(skiatest::Reporter* r, | 30 static void check(skiatest::Reporter* r, |
31 const char path[], | 31 const char path[], |
32 SkISize size, | 32 SkISize size, |
33 bool canRewind) { | 33 bool supportsScanlineDecoding) { |
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<SkImageGenerator> gen( | 39 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); |
40 SkCodec::NewFromStream(stream.detach())); | 40 if (!codec) { |
41 if (!gen) { | |
42 ERRORF(r, "Unable to decode '%s'", path); | 41 ERRORF(r, "Unable to decode '%s'", path); |
43 return; | 42 return; |
44 } | 43 } |
45 SkImageInfo info = gen->getInfo(); | 44 SkImageInfo info = codec->getInfo(); |
46 REPORTER_ASSERT(r, info.dimensions() == size); | 45 REPORTER_ASSERT(r, info.dimensions() == size); |
47 SkBitmap bm; | 46 SkBitmap bm; |
48 bm.allocPixels(info); | 47 bm.allocPixels(info); |
49 SkAutoLockPixels autoLockPixels(bm); | 48 SkAutoLockPixels autoLockPixels(bm); |
50 SkImageGenerator::Result result = | 49 SkImageGenerator::Result result = |
51 gen->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); | 50 codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); |
52 REPORTER_ASSERT(r, result == SkImageGenerator::kSuccess); | 51 REPORTER_ASSERT(r, result == SkImageGenerator::kSuccess); |
53 | 52 |
54 SkMD5::Digest digest1, digest2; | 53 SkMD5::Digest digest1, digest2; |
55 md5(bm, &digest1); | 54 md5(bm, &digest1); |
56 | 55 |
57 bm.eraseColor(SK_ColorYELLOW); | 56 bm.eraseColor(SK_ColorYELLOW); |
58 | 57 |
59 result = | 58 result = |
60 gen->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); | 59 codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); |
61 | 60 |
62 // All ImageGenerators should support re-decoding the pixels. | 61 REPORTER_ASSERT(r, result == SkImageGenerator::kSuccess); |
63 // It is a known bug that some can not. | 62 // verify that re-decoding gives the same result. |
64 if (canRewind) { | 63 md5(bm, &digest2); |
65 REPORTER_ASSERT(r, result == SkImageGenerator::kSuccess); | 64 REPORTER_ASSERT(r, digest1 == digest2); |
66 // verify that re-decoding gives the same result. | 65 |
67 md5(bm, &digest2); | 66 SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(info); |
68 REPORTER_ASSERT(r, digest1 == digest2); | 67 if (supportsScanlineDecoding) { |
| 68 bm.eraseColor(SK_ColorYELLOW); |
| 69 REPORTER_ASSERT(r, scanlineDecoder); |
| 70 for (int y = 0; y < info.height(); y++) { |
| 71 result = scanlineDecoder->getScanlines(bm.getAddr(0, y), 1, 0); |
| 72 REPORTER_ASSERT(r, result == SkImageGenerator::kSuccess); |
| 73 } |
| 74 // verify that scanline decoding gives the same result. |
| 75 SkMD5::Digest digest3; |
| 76 md5(bm, &digest3); |
| 77 REPORTER_ASSERT(r, digest3 == digest1); |
| 78 } else { |
| 79 REPORTER_ASSERT(r, !scanlineDecoder); |
69 } | 80 } |
70 } | 81 } |
71 | 82 |
72 DEF_TEST(Codec, r) { | 83 DEF_TEST(Codec, r) { |
73 // WBMP | 84 // WBMP |
74 check(r, "mandrill.wbmp", SkISize::Make(512, 512), true); | 85 check(r, "mandrill.wbmp", SkISize::Make(512, 512), false); |
75 | 86 |
76 // BMP | 87 // BMP |
77 check(r, "randPixels.bmp", SkISize::Make(8, 8), true); | 88 check(r, "randPixels.bmp", SkISize::Make(8, 8), false); |
78 | 89 |
79 // ICO | 90 // ICO |
80 check(r, "color_wheel.ico", SkISize::Make(128, 128), true); | 91 check(r, "color_wheel.ico", SkISize::Make(128, 128), false); |
81 | 92 |
82 // PNG | 93 // PNG |
83 check(r, "arrow.png", SkISize::Make(187, 312), true); | 94 check(r, "arrow.png", SkISize::Make(187, 312), true); |
84 check(r, "baby_tux.png", SkISize::Make(240, 246), true); | 95 check(r, "baby_tux.png", SkISize::Make(240, 246), true); |
85 check(r, "color_wheel.png", SkISize::Make(128, 128), true); | 96 check(r, "color_wheel.png", SkISize::Make(128, 128), true); |
86 check(r, "half-transparent-white-pixel.png", SkISize::Make(1, 1), true); | 97 check(r, "half-transparent-white-pixel.png", SkISize::Make(1, 1), true); |
87 check(r, "mandrill_128.png", SkISize::Make(128, 128), true); | 98 check(r, "mandrill_128.png", SkISize::Make(128, 128), true); |
88 check(r, "mandrill_16.png", SkISize::Make(16, 16), true); | 99 check(r, "mandrill_16.png", SkISize::Make(16, 16), true); |
89 check(r, "mandrill_256.png", SkISize::Make(256, 256), true); | 100 check(r, "mandrill_256.png", SkISize::Make(256, 256), true); |
90 check(r, "mandrill_32.png", SkISize::Make(32, 32), true); | 101 check(r, "mandrill_32.png", SkISize::Make(32, 32), true); |
91 check(r, "mandrill_512.png", SkISize::Make(512, 512), true); | 102 check(r, "mandrill_512.png", SkISize::Make(512, 512), true); |
92 check(r, "mandrill_64.png", SkISize::Make(64, 64), true); | 103 check(r, "mandrill_64.png", SkISize::Make(64, 64), true); |
93 check(r, "plane.png", SkISize::Make(250, 126), true); | 104 check(r, "plane.png", SkISize::Make(250, 126), true); |
94 check(r, "randPixels.png", SkISize::Make(8, 8), true); | 105 check(r, "randPixels.png", SkISize::Make(8, 8), true); |
95 check(r, "yellow_rose.png", SkISize::Make(400, 301), true); | 106 check(r, "yellow_rose.png", SkISize::Make(400, 301), true); |
96 } | 107 } |
OLD | NEW |