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 "SkAndroidCodec.h" | 9 #include "SkAndroidCodec.h" |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 REPORTER_ASSERT(r, result == expectedResult); | 96 REPORTER_ASSERT(r, result == expectedResult); |
97 | 97 |
98 md5(bm, digest); | 98 md5(bm, digest); |
99 if (goodDigest) { | 99 if (goodDigest) { |
100 REPORTER_ASSERT(r, *digest == *goodDigest); | 100 REPORTER_ASSERT(r, *digest == *goodDigest); |
101 } | 101 } |
102 | 102 |
103 { | 103 { |
104 // Test decoding to 565 | 104 // Test decoding to 565 |
105 SkImageInfo info565 = info.makeColorType(kRGB_565_SkColorType); | 105 SkImageInfo info565 = info.makeColorType(kRGB_565_SkColorType); |
106 SkCodec::Result expected565 = info.alphaType() == kOpaque_SkAlphaType ? | 106 if (info.alphaType() == kOpaque_SkAlphaType) { |
107 expectedResult : SkCodec::kInvalidConversion; | 107 // Decoding to 565 should succeed. |
108 test_info(r, codec, info565, expected565, nullptr); | 108 SkBitmap bm565; |
| 109 bm565.allocPixels(info565); |
| 110 SkAutoLockPixels alp(bm565); |
| 111 |
| 112 // This will allow comparison even if the image is incomplete. |
| 113 bm565.eraseColor(SK_ColorBLACK); |
| 114 |
| 115 REPORTER_ASSERT(r, expectedResult == codec->getPixels(info565, |
| 116 bm565.getPixels(), bm565.rowBytes())); |
| 117 |
| 118 SkMD5::Digest digest565; |
| 119 md5(bm565, &digest565); |
| 120 |
| 121 // A dumb client's request for non-opaque should also succeed. |
| 122 for (auto alpha : { kPremul_SkAlphaType, kUnpremul_SkAlphaType }) { |
| 123 info565 = info565.makeAlphaType(alpha); |
| 124 test_info(r, codec, info565, expectedResult, &digest565); |
| 125 } |
| 126 } else { |
| 127 test_info(r, codec, info565, SkCodec::kInvalidConversion, nullptr); |
| 128 } |
| 129 } |
| 130 |
| 131 if (codec->getInfo().colorType() == kGray_8_SkColorType) { |
| 132 SkImageInfo grayInfo = codec->getInfo(); |
| 133 SkBitmap grayBm; |
| 134 grayBm.allocPixels(grayInfo); |
| 135 SkAutoLockPixels alp(grayBm); |
| 136 |
| 137 grayBm.eraseColor(SK_ColorBLACK); |
| 138 |
| 139 REPORTER_ASSERT(r, expectedResult == codec->getPixels(grayInfo, |
| 140 grayBm.getPixels(), grayBm.rowBytes())); |
| 141 |
| 142 SkMD5::Digest grayDigest; |
| 143 md5(grayBm, &grayDigest); |
| 144 |
| 145 for (auto alpha : { kPremul_SkAlphaType, kUnpremul_SkAlphaType }) { |
| 146 grayInfo = grayInfo.makeAlphaType(alpha); |
| 147 test_info(r, codec, grayInfo, expectedResult, &grayDigest); |
| 148 } |
109 } | 149 } |
110 | 150 |
111 // Verify that re-decoding gives the same result. It is interesting to chec
k this after | 151 // Verify that re-decoding gives the same result. It is interesting to chec
k this after |
112 // a decode to 565, since choosing to decode to 565 may result in some of th
e decode | 152 // a decode to 565, since choosing to decode to 565 may result in some of th
e decode |
113 // options being modified. These options should return to their defaults on
another | 153 // options being modified. These options should return to their defaults on
another |
114 // decode to kN32, so the new digest should match the old digest. | 154 // decode to kN32, so the new digest should match the old digest. |
115 test_info(r, codec, info, expectedResult, digest); | 155 test_info(r, codec, info, expectedResult, digest); |
116 | 156 |
117 { | 157 { |
118 // Check alpha type conversions | 158 // Check alpha type conversions |
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 // Now test an image which is too big. Any image with a larger header (i.e. | 1005 // Now test an image which is too big. Any image with a larger header (i.e. |
966 // has bigger width/height) is also too big. | 1006 // has bigger width/height) is also too big. |
967 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header | 1007 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header |
968 0x84, 0x80, 0x00, // W: 65536 | 1008 0x84, 0x80, 0x00, // W: 65536 |
969 0x84, 0x80, 0x00 }; // H: 65536 | 1009 0x84, 0x80, 0x00 }; // H: 65536 |
970 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false)); | 1010 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false)); |
971 codec.reset(SkCodec::NewFromStream(stream.release())); | 1011 codec.reset(SkCodec::NewFromStream(stream.release())); |
972 | 1012 |
973 REPORTER_ASSERT(r, !codec); | 1013 REPORTER_ASSERT(r, !codec); |
974 } | 1014 } |
OLD | NEW |