| 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 10 matching lines...) Expand all Loading... |
| 21 SkAutoLockPixels autoLockPixels(bm); | 21 SkAutoLockPixels autoLockPixels(bm); |
| 22 SkASSERT(bm.getPixels()); | 22 SkASSERT(bm.getPixels()); |
| 23 SkMD5 md5; | 23 SkMD5 md5; |
| 24 size_t rowLen = bm.info().bytesPerPixel() * bm.width(); | 24 size_t rowLen = bm.info().bytesPerPixel() * bm.width(); |
| 25 for (int y = 0; y < bm.height(); ++y) { | 25 for (int y = 0; y < bm.height(); ++y) { |
| 26 md5.update(static_cast<uint8_t*>(bm.getAddr(0, y)), rowLen); | 26 md5.update(static_cast<uint8_t*>(bm.getAddr(0, y)), rowLen); |
| 27 } | 27 } |
| 28 md5.finish(*digest); | 28 md5.finish(*digest); |
| 29 } | 29 } |
| 30 | 30 |
| 31 /** |
| 32 * Compute the digest for bm and compare it to a known good digest. |
| 33 * @param r Reporter to assert that bm's digest matches goodDigest. |
| 34 * @param goodDigest The known good digest to compare to. |
| 35 * @param bm The bitmap to test. |
| 36 */ |
| 37 static void compare_to_good_digest(skiatest::Reporter* r, const SkMD5::Digest& g
oodDigest, |
| 38 const SkBitmap& bm) { |
| 39 SkMD5::Digest digest; |
| 40 md5(bm, &digest); |
| 41 REPORTER_ASSERT(r, digest == goodDigest); |
| 42 } |
| 43 |
| 31 static void check(skiatest::Reporter* r, | 44 static void check(skiatest::Reporter* r, |
| 32 const char path[], | 45 const char path[], |
| 33 SkISize size, | 46 SkISize size, |
| 34 bool supportsScanlineDecoding) { | 47 bool supportsScanlineDecoding) { |
| 35 SkAutoTDelete<SkStream> stream(resource(path)); | 48 SkAutoTDelete<SkStream> stream(resource(path)); |
| 36 if (!stream) { | 49 if (!stream) { |
| 37 SkDebugf("Missing resource '%s'\n", path); | 50 SkDebugf("Missing resource '%s'\n", path); |
| 38 return; | 51 return; |
| 39 } | 52 } |
| 40 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); | 53 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); |
| 41 if (!codec) { | 54 if (!codec) { |
| 42 ERRORF(r, "Unable to decode '%s'", path); | 55 ERRORF(r, "Unable to decode '%s'", path); |
| 43 return; | 56 return; |
| 44 } | 57 } |
| 45 | 58 |
| 46 // This test is used primarily to verify rewinding works properly. Using kN
32 allows | 59 // This test is used primarily to verify rewinding works properly. Using kN
32 allows |
| 47 // us to test this without the added overhead of creating different bitmaps
depending | 60 // us to test this without the added overhead of creating different bitmaps
depending |
| 48 // on the color type (ex: building a color table for kIndex8). DM is where
we test | 61 // on the color type (ex: building a color table for kIndex8). DM is where
we test |
| 49 // decodes to all possible destination color types. | 62 // decodes to all possible destination color types. |
| 50 SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType); | 63 SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType); |
| 51 REPORTER_ASSERT(r, info.dimensions() == size); | 64 REPORTER_ASSERT(r, info.dimensions() == size); |
| 52 SkBitmap bm; | 65 SkBitmap bm; |
| 53 bm.allocPixels(info); | 66 bm.allocPixels(info); |
| 54 SkAutoLockPixels autoLockPixels(bm); | 67 SkAutoLockPixels autoLockPixels(bm); |
| 55 SkCodec::Result result = | 68 SkCodec::Result result = |
| 56 codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); | 69 codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); |
| 57 REPORTER_ASSERT(r, result == SkCodec::kSuccess); | 70 REPORTER_ASSERT(r, result == SkCodec::kSuccess); |
| 58 | 71 |
| 59 SkMD5::Digest digest1, digest2; | 72 SkMD5::Digest digest; |
| 60 md5(bm, &digest1); | 73 md5(bm, &digest); |
| 61 | 74 |
| 62 bm.eraseColor(SK_ColorYELLOW); | 75 bm.eraseColor(SK_ColorYELLOW); |
| 63 | 76 |
| 64 result = | 77 result = |
| 65 codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); | 78 codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); |
| 66 | 79 |
| 67 REPORTER_ASSERT(r, result == SkCodec::kSuccess); | 80 REPORTER_ASSERT(r, result == SkCodec::kSuccess); |
| 68 // verify that re-decoding gives the same result. | 81 // verify that re-decoding gives the same result. |
| 69 md5(bm, &digest2); | 82 compare_to_good_digest(r, digest, bm); |
| 70 REPORTER_ASSERT(r, digest1 == digest2); | |
| 71 | 83 |
| 72 SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(info); | 84 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(codec->getScanlineDecoder(i
nfo)); |
| 73 if (supportsScanlineDecoding) { | 85 if (supportsScanlineDecoding) { |
| 74 bm.eraseColor(SK_ColorYELLOW); | 86 bm.eraseColor(SK_ColorYELLOW); |
| 75 REPORTER_ASSERT(r, scanlineDecoder); | 87 REPORTER_ASSERT(r, scanlineDecoder); |
| 76 | 88 |
| 77 // Regular decodes should be disabled after creating a scanline decoder | 89 // Regular decodes should not be affected by creating a scanline decoder |
| 78 result = codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NUL
L, NULL); | 90 result = codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NUL
L, NULL); |
| 79 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result); | 91 REPORTER_ASSERT(r, SkCodec::kSuccess == result); |
| 92 compare_to_good_digest(r, digest, bm); |
| 93 |
| 94 bm.eraseColor(SK_ColorYELLOW); |
| 95 |
| 80 for (int y = 0; y < info.height(); y++) { | 96 for (int y = 0; y < info.height(); y++) { |
| 81 result = scanlineDecoder->getScanlines(bm.getAddr(0, y), 1, 0); | 97 result = scanlineDecoder->getScanlines(bm.getAddr(0, y), 1, 0); |
| 82 REPORTER_ASSERT(r, result == SkCodec::kSuccess); | 98 REPORTER_ASSERT(r, result == SkCodec::kSuccess); |
| 83 } | 99 } |
| 84 // verify that scanline decoding gives the same result. | 100 // verify that scanline decoding gives the same result. |
| 85 SkMD5::Digest digest3; | 101 compare_to_good_digest(r, digest, bm); |
| 86 md5(bm, &digest3); | |
| 87 REPORTER_ASSERT(r, digest3 == digest1); | |
| 88 } else { | 102 } else { |
| 89 REPORTER_ASSERT(r, !scanlineDecoder); | 103 REPORTER_ASSERT(r, !scanlineDecoder); |
| 90 } | 104 } |
| 91 } | 105 } |
| 92 | 106 |
| 93 DEF_TEST(Codec, r) { | 107 DEF_TEST(Codec, r) { |
| 94 // WBMP | 108 // WBMP |
| 95 check(r, "mandrill.wbmp", SkISize::Make(512, 512), false); | 109 check(r, "mandrill.wbmp", SkISize::Make(512, 512), false); |
| 96 | 110 |
| 97 // WEBP | 111 // WEBP |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 test_empty(r, "empty_images/zero-embedded.ico"); | 236 test_empty(r, "empty_images/zero-embedded.ico"); |
| 223 test_empty(r, "empty_images/zero-width.bmp"); | 237 test_empty(r, "empty_images/zero-width.bmp"); |
| 224 test_empty(r, "empty_images/zero-height.bmp"); | 238 test_empty(r, "empty_images/zero-height.bmp"); |
| 225 test_empty(r, "empty_images/zero-width.jpg"); | 239 test_empty(r, "empty_images/zero-width.jpg"); |
| 226 test_empty(r, "empty_images/zero-height.jpg"); | 240 test_empty(r, "empty_images/zero-height.jpg"); |
| 227 test_empty(r, "empty_images/zero-width.png"); | 241 test_empty(r, "empty_images/zero-width.png"); |
| 228 test_empty(r, "empty_images/zero-height.png"); | 242 test_empty(r, "empty_images/zero-height.png"); |
| 229 test_empty(r, "empty_images/zero-width.wbmp"); | 243 test_empty(r, "empty_images/zero-width.wbmp"); |
| 230 test_empty(r, "empty_images/zero-height.wbmp"); | 244 test_empty(r, "empty_images/zero-height.wbmp"); |
| 231 } | 245 } |
| OLD | NEW |