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 24 matching lines...) Expand all Loading... | |
| 35 * @param goodDigest The known good digest to compare to. | 35 * @param goodDigest The known good digest to compare to. |
| 36 * @param bm The bitmap to test. | 36 * @param bm The bitmap to test. |
| 37 */ | 37 */ |
| 38 static void compare_to_good_digest(skiatest::Reporter* r, const SkMD5::Digest& g oodDigest, | 38 static void compare_to_good_digest(skiatest::Reporter* r, const SkMD5::Digest& g oodDigest, |
| 39 const SkBitmap& bm) { | 39 const SkBitmap& bm) { |
| 40 SkMD5::Digest digest; | 40 SkMD5::Digest digest; |
| 41 md5(bm, &digest); | 41 md5(bm, &digest); |
| 42 REPORTER_ASSERT(r, digest == goodDigest); | 42 REPORTER_ASSERT(r, digest == goodDigest); |
| 43 } | 43 } |
| 44 | 44 |
| 45 /** | |
| 46 * Test decoding an SkCodec to a particular SkImageInfo. | |
| 47 * | |
| 48 * Calling getPixels(info) should return expectedResult, and if goodDigest is n on NULL, | |
| 49 * the resulting decode should match. | |
| 50 */ | |
| 51 static void test_info(skiatest::Reporter* r, SkCodec* codec, const SkImageInfo& info, | |
| 52 SkCodec::Result expectedResult, const SkMD5::Digest* goodD igest) { | |
| 53 SkBitmap bm; | |
| 54 bm.allocPixels(info); | |
| 55 SkAutoLockPixels autoLockPixels(bm); | |
| 56 | |
| 57 SkCodec::Result result = codec->getPixels(info, bm.getPixels(), bm.rowBytes( )); | |
| 58 REPORTER_ASSERT(r, result == expectedResult); | |
| 59 | |
| 60 if (goodDigest) { | |
| 61 compare_to_good_digest(r, *goodDigest, bm); | |
| 62 } | |
| 63 } | |
| 64 | |
| 45 SkIRect generate_random_subset(SkRandom* rand, int w, int h) { | 65 SkIRect generate_random_subset(SkRandom* rand, int w, int h) { |
| 46 SkIRect rect; | 66 SkIRect rect; |
| 47 do { | 67 do { |
| 48 rect.fLeft = rand->nextRangeU(0, w); | 68 rect.fLeft = rand->nextRangeU(0, w); |
| 49 rect.fTop = rand->nextRangeU(0, h); | 69 rect.fTop = rand->nextRangeU(0, h); |
| 50 rect.fRight = rand->nextRangeU(0, w); | 70 rect.fRight = rand->nextRangeU(0, w); |
| 51 rect.fBottom = rand->nextRangeU(0, h); | 71 rect.fBottom = rand->nextRangeU(0, h); |
| 52 rect.sort(); | 72 rect.sort(); |
| 53 } while (rect.isEmpty()); | 73 } while (rect.isEmpty()); |
| 54 return rect; | 74 return rect; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 79 SkBitmap bm; | 99 SkBitmap bm; |
| 80 bm.allocPixels(info); | 100 bm.allocPixels(info); |
| 81 SkAutoLockPixels autoLockPixels(bm); | 101 SkAutoLockPixels autoLockPixels(bm); |
| 82 SkCodec::Result result = | 102 SkCodec::Result result = |
| 83 codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); | 103 codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); |
| 84 REPORTER_ASSERT(r, result == SkCodec::kSuccess); | 104 REPORTER_ASSERT(r, result == SkCodec::kSuccess); |
| 85 | 105 |
| 86 SkMD5::Digest digest; | 106 SkMD5::Digest digest; |
| 87 md5(bm, &digest); | 107 md5(bm, &digest); |
| 88 | 108 |
| 89 bm.eraseColor(SK_ColorYELLOW); | 109 // verify that re-decoding gives the same result. |
| 110 test_info(r, codec, info, SkCodec::kSuccess, &digest); | |
| 90 | 111 |
| 91 result = | 112 { |
| 92 codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); | 113 // Check alpha type conversions |
| 114 if (info.alphaType() == kOpaque_SkAlphaType) { | |
|
scroggo_chromium
2015/08/07 23:16:31
When I started writing this CL, I expected that an
msarett
2015/08/10 13:51:12
I would guess that most clients would just use the
scroggo_chromium
2015/08/12 14:55:31
Sticking with the existing decision sounds good to
| |
| 115 } else { | |
| 116 // Decoding to opaque should fail | |
| 117 test_info(r, codec, info.makeAlphaType(kOpaque_SkAlphaType), | |
| 118 SkCodec::kInvalidConversion, NULL); | |
| 119 SkAlphaType otherAt = info.alphaType(); | |
| 120 if (kPremul_SkAlphaType == otherAt) { | |
| 121 otherAt = kUnpremul_SkAlphaType; | |
| 122 } else { | |
| 123 otherAt = kPremul_SkAlphaType; | |
| 124 } | |
| 125 // The other non-opaque alpha type should always succeed, but not ma tch. | |
| 126 test_info(r, codec, info.makeAlphaType(otherAt), SkCodec::kSuccess, NULL); | |
| 127 } | |
| 128 } | |
| 93 | 129 |
| 94 REPORTER_ASSERT(r, result == SkCodec::kSuccess); | 130 // Scanline decoding follows. |
| 95 // verify that re-decoding gives the same result. | |
| 96 compare_to_good_digest(r, digest, bm); | |
| 97 | 131 |
| 98 stream.reset(resource(path)); | 132 stream.reset(resource(path)); |
| 99 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder( | 133 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder( |
| 100 SkScanlineDecoder::NewFromStream(stream.detach())); | 134 SkScanlineDecoder::NewFromStream(stream.detach())); |
| 101 if (supportsScanlineDecoding) { | 135 if (supportsScanlineDecoding) { |
| 102 bm.eraseColor(SK_ColorYELLOW); | 136 bm.eraseColor(SK_ColorYELLOW); |
| 103 REPORTER_ASSERT(r, scanlineDecoder); | 137 REPORTER_ASSERT(r, scanlineDecoder); |
| 104 | 138 |
| 105 REPORTER_ASSERT(r, scanlineDecoder->start(info) == SkCodec::kSuccess); | 139 REPORTER_ASSERT(r, scanlineDecoder->start(info) == SkCodec::kSuccess); |
| 106 | 140 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result); | 351 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result); |
| 318 result = decoder->start( | 352 result = decoder->start( |
| 319 decoder->getInfo().makeColorType(kIndex_8_SkColorType)); | 353 decoder->getInfo().makeColorType(kIndex_8_SkColorType)); |
| 320 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result); | 354 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result); |
| 321 } | 355 } |
| 322 | 356 |
| 323 DEF_TEST(Codec_Params, r) { | 357 DEF_TEST(Codec_Params, r) { |
| 324 test_invalid_parameters(r, "index8.png"); | 358 test_invalid_parameters(r, "index8.png"); |
| 325 test_invalid_parameters(r, "mandrill.wbmp"); | 359 test_invalid_parameters(r, "mandrill.wbmp"); |
| 326 } | 360 } |
| OLD | NEW |