OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2015 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "Resources.h" | |
9 #include "SkBitmap.h" | |
10 #include "SkCodec.h" | |
11 #include "SkMD5.h" | |
12 #include "Test.h" | |
13 | |
14 static SkStreamAsset* resource(const char path[]) { | |
15 SkString fullPath = GetResourcePath(path); | |
16 return SkStream::NewFromFile(fullPath.c_str()); | |
17 } | |
18 | |
19 void md5(const SkBitmap& bm, SkMD5::Digest* digest) { | |
20 SkAutoLockPixels autoLockPixels(bm); | |
21 SkMD5 md5; | |
22 size_t rowLen = bm.info().bytesPerPixel() * bm.height(); | |
scroggo
2015/03/27 12:52:59
Shouldn't bm.height() be bm.width()?
hal.canary
2015/03/27 13:53:02
Done.
| |
23 for (int y = 0; y < bm.height(); ++y) { | |
24 md5.update(static_cast<uint8_t*>(bm.getAddr(0, y)), rowLen); | |
25 } | |
26 md5.finish(*digest); | |
27 } | |
28 | |
29 static void check(skiatest::Reporter* r, | |
30 const char path[], | |
31 SkISize size, | |
32 bool canRewind) { | |
33 SkAutoTDelete<SkStream> stream(resource(path)); | |
34 if (!stream) { | |
35 SkDebugf("Missing resource '%s'\n", path); | |
36 return; | |
37 } | |
38 SkAutoTDelete<SkImageGenerator> gen( | |
39 SkCodec::NewFromStream(stream.detach())); | |
40 if (!gen) { | |
41 ERRORF(r, "Unable to decode '%s'", path); | |
42 return; | |
43 } | |
44 SkImageInfo info = gen->getInfo(); | |
45 REPORTER_ASSERT(r, info.dimensions() == size); | |
46 SkBitmap bm; | |
47 bm.allocPixels(info); | |
48 SkAutoLockPixels autoLockPixels(bm); | |
49 SkImageGenerator::Result result = | |
50 gen->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); | |
51 REPORTER_ASSERT(r, result == SkImageGenerator::kSuccess); | |
52 | |
53 SkMD5::Digest digest1, digest2; | |
54 md5(bm, &digest1); | |
55 | |
56 bm.eraseColor(SK_ColorYELLOW); | |
57 | |
58 result = | |
59 gen->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); | |
60 | |
61 // All ImageGenerators should support re-decoding the pixels. | |
62 // It is a known bug that some can not. | |
63 if (canRewind) { | |
64 REPORTER_ASSERT(r, result == SkImageGenerator::kSuccess); | |
65 // verify that re-decoding gives the same result. | |
66 md5(bm, &digest2); | |
67 REPORTER_ASSERT(r, 0 == memcmp(digest1.data, digest2.data, | |
68 sizeof(digest1.data))); | |
69 } | |
70 } | |
71 | |
72 DEF_TEST(Codec, r) { | |
73 // WBMP | |
74 check(r, "mandrill.wbmp", SkISize::Make(512, 512), true); | |
75 | |
76 // BMP | |
77 // TODO (msarett): SkBmpCodec should be able to rewind. | |
78 check(r, "randPixels.bmp", SkISize::Make(8, 8), false); | |
79 | |
80 // ICO | |
81 // TODO (msarett): SkIcoCodec should be able to rewind. | |
82 check(r, "color_wheel.ico", SkISize::Make(128, 128), false); | |
83 | |
84 // PNG | |
85 // TODO (scroggo): SkPngCodec should be able to rewind. | |
86 check(r, "arrow.png", SkISize::Make(187, 312), false); | |
87 check(r, "baby_tux.png", SkISize::Make(240, 246), false); | |
88 check(r, "color_wheel.png", SkISize::Make(128, 128), false); | |
89 check(r, "half-transparent-white-pixel.png", SkISize::Make(1, 1), false); | |
90 check(r, "mandrill_128.png", SkISize::Make(128, 128), false); | |
91 check(r, "mandrill_16.png", SkISize::Make(16, 16), false); | |
92 check(r, "mandrill_256.png", SkISize::Make(256, 256), false); | |
93 check(r, "mandrill_32.png", SkISize::Make(32, 32), false); | |
94 check(r, "mandrill_512.png", SkISize::Make(512, 512), false); | |
95 check(r, "mandrill_64.png", SkISize::Make(64, 64), false); | |
96 check(r, "plane.png", SkISize::Make(250, 126), false); | |
97 check(r, "randPixels.png", SkISize::Make(8, 8), false); | |
98 check(r, "yellow_rose.png", SkISize::Make(400, 301), false); | |
99 } | |
OLD | NEW |