Chromium Code Reviews| 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 "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
| 10 #include "SkForceLinking.h" | 10 #include "SkForceLinking.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 REPORTER_ASSERT(reporter, 0 == da); | 125 REPORTER_ASSERT(reporter, 0 == da); |
| 126 | 126 |
| 127 // Color components may not match exactly due to rounding error. | 127 // Color components may not match exactly due to rounding error. |
| 128 REPORTER_ASSERT(reporter, dr <= 1); | 128 REPORTER_ASSERT(reporter, dr <= 1); |
| 129 REPORTER_ASSERT(reporter, dg <= 1); | 129 REPORTER_ASSERT(reporter, dg <= 1); |
| 130 REPORTER_ASSERT(reporter, db <= 1); | 130 REPORTER_ASSERT(reporter, db <= 1); |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 } | 133 } |
| 134 | 134 |
| 135 static void test_imageDecodingTests(skiatest::Reporter* reporter) { | 135 // Create a fake ImageDecoder to test setPrefConfigTable for |
| 136 // backwards compatibility. | |
| 137 class PrefConfigTestingImageDecoder : public SkImageDecoder { | |
| 138 public: | |
| 139 void testPrefConfigTable(skiatest::Reporter* reporter) { | |
|
scroggo
2013/07/11 20:37:29
New test confirms that using the old API still beh
| |
| 140 // Arbitrary list of Configs. The important thing about | |
| 141 // the list is that each one is different, so we can test | |
| 142 // to make sure the correct config is chosen. | |
| 143 const SkBitmap::Config configs[] = { | |
| 144 SkBitmap::kA1_Config, | |
| 145 SkBitmap::kA8_Config, | |
| 146 SkBitmap::kIndex8_Config, | |
| 147 SkBitmap::kRGB_565_Config, | |
| 148 SkBitmap::kARGB_4444_Config, | |
| 149 SkBitmap::kARGB_8888_Config, | |
| 150 }; | |
| 151 this->setPrefConfigTable(configs); | |
| 152 REPORTER_ASSERT(reporter, configs[0] == this->getPrefConfig(kIndex_SrcDe pth, false)); | |
| 153 REPORTER_ASSERT(reporter, configs[1] == this->getPrefConfig(kIndex_SrcDe pth, true)); | |
| 154 REPORTER_ASSERT(reporter, configs[4] == this->getPrefConfig(k32Bit_SrcDe pth, false)); | |
| 155 REPORTER_ASSERT(reporter, configs[5] == this->getPrefConfig(k32Bit_SrcDe pth, true)); | |
| 156 } | |
| 157 | |
| 158 protected: | |
| 159 virtual bool onDecode(SkStream*, SkBitmap* bitmap, Mode) SK_OVERRIDE { | |
| 160 return false; | |
| 161 } | |
| 162 }; | |
| 163 | |
| 164 static void test_pref_config_table(skiatest::Reporter* reporter) { | |
| 165 PrefConfigTestingImageDecoder decoder; | |
| 166 decoder.testPrefConfigTable(reporter); | |
| 167 } | |
| 168 | |
| 169 static void test_unpremul(skiatest::Reporter* reporter) { | |
| 136 // This test cannot run if there is no resource path. | 170 // This test cannot run if there is no resource path. |
| 137 SkString resourcePath = skiatest::Test::GetResourcePath(); | 171 SkString resourcePath = skiatest::Test::GetResourcePath(); |
| 138 if (resourcePath.isEmpty()) { | 172 if (resourcePath.isEmpty()) { |
| 139 return; | 173 return; |
| 140 } | 174 } |
| 141 SkOSFile::Iter iter(resourcePath.c_str()); | 175 SkOSFile::Iter iter(resourcePath.c_str()); |
| 142 SkString basename; | 176 SkString basename; |
| 143 if (iter.next(&basename)) { | 177 if (iter.next(&basename)) { |
| 144 do { | 178 do { |
| 145 SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), basen ame.c_str()); | 179 SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), basen ame.c_str()); |
| 146 //SkDebugf("about to decode \"%s\"\n", filename.c_str()); | 180 //SkDebugf("about to decode \"%s\"\n", filename.c_str()); |
| 147 compare_unpremul(reporter, filename); | 181 compare_unpremul(reporter, filename); |
| 148 } while (iter.next(&basename)); | 182 } while (iter.next(&basename)); |
| 149 } else { | 183 } else { |
| 150 SkDebugf("Failed to find any files :(\n"); | 184 SkDebugf("Failed to find any files :(\n"); |
| 151 } | 185 } |
| 152 } | 186 } |
| 153 | 187 |
| 188 static void test_imageDecodingTests(skiatest::Reporter* reporter) { | |
| 189 test_unpremul(reporter); | |
| 190 test_pref_config_table(reporter); | |
| 191 } | |
| 192 | |
| 154 #include "TestClassDef.h" | 193 #include "TestClassDef.h" |
| 155 DEFINE_TESTCLASS("ImageDecoding", ImageDecodingTestClass, | 194 DEFINE_TESTCLASS("ImageDecoding", ImageDecodingTestClass, |
| 156 test_imageDecodingTests) | 195 test_imageDecodingTests) |
| OLD | NEW |