OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkColor.h" | 10 #include "SkColor.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 REPORTER_ASSERT(reporter, 0 == da); | 132 REPORTER_ASSERT(reporter, 0 == da); |
133 | 133 |
134 // Color components may not match exactly due to rounding error. | 134 // Color components may not match exactly due to rounding error. |
135 REPORTER_ASSERT(reporter, dr <= 1); | 135 REPORTER_ASSERT(reporter, dr <= 1); |
136 REPORTER_ASSERT(reporter, dg <= 1); | 136 REPORTER_ASSERT(reporter, dg <= 1); |
137 REPORTER_ASSERT(reporter, db <= 1); | 137 REPORTER_ASSERT(reporter, db <= 1); |
138 } | 138 } |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
142 // Create a fake ImageDecoder to test setPrefConfigTable for | |
143 // backwards compatibility. | |
144 class PrefConfigTestingImageDecoder : public SkImageDecoder { | |
145 public: | |
146 void testPrefConfigTable(skiatest::Reporter* reporter) { | |
147 // Arbitrary list of Configs. The important thing about | |
148 // the list is that each one is different, so we can test | |
149 // to make sure the correct config is chosen. | |
150 const SkBitmap::Config configs[] = { | |
151 SkBitmap::kA8_Config, | |
152 SkBitmap::kA8_Config, | |
153 SkBitmap::kIndex8_Config, | |
154 SkBitmap::kRGB_565_Config, | |
155 SkBitmap::kARGB_4444_Config, | |
156 SkBitmap::kARGB_8888_Config, | |
157 }; | |
158 this->setPrefConfigTable(configs); | |
159 REPORTER_ASSERT(reporter, configs[0] == this->getPrefConfig(kIndex_SrcDe
pth, false)); | |
160 REPORTER_ASSERT(reporter, configs[1] == this->getPrefConfig(kIndex_SrcDe
pth, true)); | |
161 REPORTER_ASSERT(reporter, configs[4] == this->getPrefConfig(k32Bit_SrcDe
pth, false)); | |
162 REPORTER_ASSERT(reporter, configs[5] == this->getPrefConfig(k32Bit_SrcDe
pth, true)); | |
163 } | |
164 | |
165 protected: | |
166 virtual bool onDecode(SkStream*, SkBitmap* bitmap, Mode) SK_OVERRIDE { | |
167 return false; | |
168 } | |
169 }; | |
170 | |
171 static void test_pref_config_table(skiatest::Reporter* reporter) { | |
172 PrefConfigTestingImageDecoder decoder; | |
173 decoder.testPrefConfigTable(reporter); | |
174 } | |
175 | |
176 static void test_unpremul(skiatest::Reporter* reporter) { | 142 static void test_unpremul(skiatest::Reporter* reporter) { |
177 // This test cannot run if there is no resource path. | 143 // This test cannot run if there is no resource path. |
178 SkString resourcePath = skiatest::Test::GetResourcePath(); | 144 SkString resourcePath = skiatest::Test::GetResourcePath(); |
179 if (resourcePath.isEmpty()) { | 145 if (resourcePath.isEmpty()) { |
180 SkDebugf("Could not run unpremul test because resourcePath not specified
."); | 146 SkDebugf("Could not run unpremul test because resourcePath not specified
."); |
181 return; | 147 return; |
182 } | 148 } |
183 SkOSFile::Iter iter(resourcePath.c_str()); | 149 SkOSFile::Iter iter(resourcePath.c_str()); |
184 SkString basename; | 150 SkString basename; |
185 if (iter.next(&basename)) { | 151 if (iter.next(&basename)) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 } | 223 } |
258 } | 224 } |
259 | 225 |
260 // Test inside SkScaledBitmapSampler.cpp | 226 // Test inside SkScaledBitmapSampler.cpp |
261 extern void test_row_proc_choice(); | 227 extern void test_row_proc_choice(); |
262 | 228 |
263 #endif // SK_DEBUG | 229 #endif // SK_DEBUG |
264 | 230 |
265 static void test_imageDecodingTests(skiatest::Reporter* reporter) { | 231 static void test_imageDecodingTests(skiatest::Reporter* reporter) { |
266 test_unpremul(reporter); | 232 test_unpremul(reporter); |
267 test_pref_config_table(reporter); | |
268 #ifdef SK_DEBUG | 233 #ifdef SK_DEBUG |
269 test_stream_life(); | 234 test_stream_life(); |
270 test_row_proc_choice(); | 235 test_row_proc_choice(); |
271 #endif | 236 #endif |
272 } | 237 } |
273 | 238 |
274 #include "TestClassDef.h" | 239 #include "TestClassDef.h" |
275 DEFINE_TESTCLASS("ImageDecoding", ImageDecodingTestClass, | 240 DEFINE_TESTCLASS("ImageDecoding", ImageDecodingTestClass, |
276 test_imageDecodingTests) | 241 test_imageDecodingTests) |
OLD | NEW |