Chromium Code Reviews| 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 "Test.h" | |
| 12 | |
| 13 static SkStreamAsset* resource(const char path[]) { | |
| 14 SkString fullPath = GetResourcePath(path); | |
| 15 return SkStream::NewFromFile(fullPath.c_str()); | |
| 16 } | |
| 17 | |
| 18 static void check(skiatest::Reporter* r, | |
| 19 const char path[], | |
| 20 SkISize size, | |
| 21 bool canRewind) { | |
| 22 SkAutoTDelete<SkStream> stream(resource(path)); | |
| 23 if (!stream) { | |
| 24 SkDebugf("Missing resource '%s'\n", path); | |
| 25 return; | |
| 26 } | |
| 27 SkAutoTDelete<SkImageGenerator> gen( | |
| 28 SkCodec::NewFromStream(stream.detach())); | |
| 29 if (!gen) { | |
| 30 ERRORF(r, "Unable to decode '%s'", path); | |
| 31 return; | |
| 32 } | |
| 33 SkImageInfo info = gen->getInfo(); | |
| 34 if (!size.isZero()) { | |
|
scroggo
2015/03/26 20:29:45
is size ever zero? Why? (It doesn't look like it f
hal.canary
2015/03/26 21:46:09
I didn't know the dimensions of all the files when
| |
| 35 REPORTER_ASSERT(r, info.dimensions() == size); | |
| 36 } | |
| 37 SkBitmap bm; | |
| 38 bm.allocPixels(info); | |
| 39 SkAutoLockPixels autoLockPixels(bm); | |
| 40 SkImageGenerator::Result result = | |
| 41 gen->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); | |
| 42 REPORTER_ASSERT(r, result == SkImageGenerator::kSuccess); | |
| 43 | |
| 44 result = | |
| 45 gen->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); | |
| 46 | |
| 47 // All ImageGenerators should support re-decoding the pixels. It | |
| 48 // is a know bug that some can not. | |
|
scroggo
2015/03/26 20:29:45
known*
hal.canary
2015/03/26 21:46:09
Done.
| |
| 49 if (canRewind) { | |
| 50 REPORTER_ASSERT(r, result == SkImageGenerator::kSuccess); | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 DEF_TEST(Codec, r) { | |
| 55 // WBMP | |
|
scroggo
2015/03/26 20:29:44
ICO, too?
hal.canary
2015/03/26 21:46:09
Done.
| |
| 56 check(r, "mandrill.wbmp", SkISize::Make(512, 512), true); | |
| 57 | |
| 58 // BMP | |
|
scroggo
2015/03/26 20:29:44
FIXME (msarett): SkBmpCodec should be able to rewi
hal.canary
2015/03/26 21:46:09
Done.
| |
| 59 check(r, "randPixels.bmp", SkISize::Make(8, 8), false); | |
| 60 | |
| 61 // PNG | |
|
scroggo
2015/03/26 20:29:44
FIXME (scroggo): SkPngCodec should be able to rewi
hal.canary
2015/03/26 21:46:09
Done.
| |
| 62 check(r, "arrow.png", SkISize::Make(187, 312), false); | |
| 63 check(r, "baby_tux.png", SkISize::Make(240, 246), false); | |
| 64 check(r, "color_wheel.png", SkISize::Make(128, 128), false); | |
| 65 check(r, "half-transparent-white-pixel.png", SkISize::Make(1, 1), false); | |
| 66 check(r, "mandrill_128.png", SkISize::Make(128, 128), false); | |
| 67 check(r, "mandrill_16.png", SkISize::Make(16, 16), false); | |
| 68 check(r, "mandrill_256.png", SkISize::Make(256, 256), false); | |
| 69 check(r, "mandrill_32.png", SkISize::Make(32, 32), false); | |
| 70 check(r, "mandrill_512.png", SkISize::Make(512, 512), false); | |
| 71 check(r, "mandrill_64.png", SkISize::Make(64, 64), false); | |
| 72 check(r, "plane.png", SkISize::Make(250, 126), false); | |
| 73 check(r, "randPixels.png", SkISize::Make(8, 8), false); | |
| 74 check(r, "yellow_rose.png", SkISize::Make(400, 301), false); | |
| 75 } | |
| OLD | NEW |