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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 rect.sort(); | 73 rect.sort(); |
| 74 } while (rect.isEmpty()); | 74 } while (rect.isEmpty()); |
| 75 return rect; | 75 return rect; |
| 76 } | 76 } |
| 77 | 77 |
| 78 static void check(skiatest::Reporter* r, | 78 static void check(skiatest::Reporter* r, |
| 79 const char path[], | 79 const char path[], |
| 80 SkISize size, | 80 SkISize size, |
| 81 bool supportsScanlineDecoding, | 81 bool supportsScanlineDecoding, |
| 82 bool supportsSubsetDecoding, | 82 bool supportsSubsetDecoding, |
| 83 bool supports565 = true) { | 83 bool supports565 = true) { |
|
scroggo
2015/09/18 18:35:30
Do all the callers just use the default value of t
msarett
2015/09/18 18:59:26
We can almost remove this.
CMYK.jpg still needs t
| |
| 84 SkAutoTDelete<SkStream> stream(resource(path)); | 84 SkAutoTDelete<SkStream> stream(resource(path)); |
| 85 if (!stream) { | 85 if (!stream) { |
| 86 SkDebugf("Missing resource '%s'\n", path); | 86 SkDebugf("Missing resource '%s'\n", path); |
| 87 return; | 87 return; |
| 88 } | 88 } |
| 89 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); | 89 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); |
| 90 if (!codec) { | 90 if (!codec) { |
| 91 ERRORF(r, "Unable to decode '%s'", path); | 91 ERRORF(r, "Unable to decode '%s'", path); |
| 92 return; | 92 return; |
| 93 } | 93 } |
| 94 | 94 |
| 95 // This test is used primarily to verify rewinding works properly. Using kN 32 allows | 95 // This test is used primarily to verify rewinding works properly. Using kN 32 allows |
| 96 // us to test this without the added overhead of creating different bitmaps depending | 96 // us to test this without the added overhead of creating different bitmaps depending |
| 97 // on the color type (ex: building a color table for kIndex8). DM is where we test | 97 // on the color type (ex: building a color table for kIndex8). DM is where we test |
| 98 // decodes to all possible destination color types. | 98 // decodes to all possible destination color types. |
| 99 SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType); | 99 SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType); |
| 100 REPORTER_ASSERT(r, info.dimensions() == size); | 100 REPORTER_ASSERT(r, info.dimensions() == size); |
| 101 | 101 |
| 102 { | |
| 103 // Test decoding to 565 | |
| 104 SkImageInfo info565 = info.makeColorType(kRGB_565_SkColorType); | |
| 105 SkCodec::Result expected = (supports565 && info.alphaType() == kOpaque_S kAlphaType) ? | |
| 106 SkCodec::kSuccess : SkCodec::kInvalidConversion; | |
| 107 test_info(r, codec, info565, expected, nullptr); | |
| 108 } | |
| 109 | |
| 110 SkBitmap bm; | 102 SkBitmap bm; |
| 111 bm.allocPixels(info); | 103 bm.allocPixels(info); |
| 112 SkAutoLockPixels autoLockPixels(bm); | 104 SkAutoLockPixels autoLockPixels(bm); |
| 113 SkCodec::Result result = | 105 SkCodec::Result result = |
| 114 codec->getPixels(info, bm.getPixels(), bm.rowBytes(), nullptr, nullptr, nullptr); | 106 codec->getPixels(info, bm.getPixels(), bm.rowBytes(), nullptr, nullptr, nullptr); |
| 115 REPORTER_ASSERT(r, result == SkCodec::kSuccess); | 107 REPORTER_ASSERT(r, result == SkCodec::kSuccess); |
| 116 | 108 |
| 117 SkMD5::Digest digest; | 109 SkMD5::Digest digest; |
| 118 md5(bm, &digest); | 110 md5(bm, &digest); |
| 119 | 111 |
| 120 // verify that re-decoding gives the same result. | 112 { |
| 113 // Test decoding to 565 | |
| 114 SkImageInfo info565 = info.makeColorType(kRGB_565_SkColorType); | |
| 115 SkCodec::Result expected = (supports565 && info.alphaType() == kOpaque_S kAlphaType) ? | |
| 116 SkCodec::kSuccess : SkCodec::kInvalidConversion; | |
| 117 test_info(r, codec, info565, expected, nullptr); | |
| 118 } | |
| 119 | |
| 120 // Verify that re-decoding gives the same result. It is interesting to chec k this after | |
| 121 // a decode to 565, since choosing to decode to 565 may result in some of th e decode | |
| 122 // options being modified. These options should return to their defaults on another | |
| 123 // decode to kN32, so the new digest should match the old digest. | |
| 121 test_info(r, codec, info, SkCodec::kSuccess, &digest); | 124 test_info(r, codec, info, SkCodec::kSuccess, &digest); |
| 122 | 125 |
| 123 { | 126 { |
| 124 // Check alpha type conversions | 127 // Check alpha type conversions |
| 125 if (info.alphaType() == kOpaque_SkAlphaType) { | 128 if (info.alphaType() == kOpaque_SkAlphaType) { |
| 126 test_info(r, codec, info.makeAlphaType(kUnpremul_SkAlphaType), | 129 test_info(r, codec, info.makeAlphaType(kUnpremul_SkAlphaType), |
| 127 SkCodec::kInvalidConversion, nullptr); | 130 SkCodec::kInvalidConversion, nullptr); |
| 128 test_info(r, codec, info.makeAlphaType(kPremul_SkAlphaType), | 131 test_info(r, codec, info.makeAlphaType(kPremul_SkAlphaType), |
| 129 SkCodec::kInvalidConversion, nullptr); | 132 SkCodec::kInvalidConversion, nullptr); |
| 130 } else { | 133 } else { |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result); | 390 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result); |
| 388 result = decoder->start( | 391 result = decoder->start( |
| 389 decoder->getInfo().makeColorType(kIndex_8_SkColorType)); | 392 decoder->getInfo().makeColorType(kIndex_8_SkColorType)); |
| 390 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result); | 393 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result); |
| 391 } | 394 } |
| 392 | 395 |
| 393 DEF_TEST(Codec_Params, r) { | 396 DEF_TEST(Codec_Params, r) { |
| 394 test_invalid_parameters(r, "index8.png"); | 397 test_invalid_parameters(r, "index8.png"); |
| 395 test_invalid_parameters(r, "mandrill.wbmp"); | 398 test_invalid_parameters(r, "mandrill.wbmp"); |
| 396 } | 399 } |
| OLD | NEW |