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 "gm_expectations.h" | 8 #include "gm_expectations.h" |
| 9 #include "SkBitmapHasher.h" | 9 #include "SkBitmapHasher.h" |
| 10 #include "SkImageDecoder.h" | 10 #include "SkImageDecoder.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 Json::Value jsonValue; | 134 Json::Value jsonValue; |
| 135 jsonValue[kJsonKey_ExpectedResults_AllowedBitmapHashes] = allowedChecksu mArray; | 135 jsonValue[kJsonKey_ExpectedResults_AllowedBitmapHashes] = allowedChecksu mArray; |
| 136 jsonValue[kJsonKey_ExpectedResults_IgnoreFailure] = this->ignoreFailure( ); | 136 jsonValue[kJsonKey_ExpectedResults_IgnoreFailure] = this->ignoreFailure( ); |
| 137 return jsonValue; | 137 return jsonValue; |
| 138 } | 138 } |
| 139 | 139 |
| 140 | 140 |
| 141 // IndividualImageExpectationsSource class... | 141 // IndividualImageExpectationsSource class... |
| 142 | 142 |
| 143 Expectations IndividualImageExpectationsSource::get(const char *testName) { | 143 Expectations IndividualImageExpectationsSource::get(const char *testName) { |
| 144 SkString path = make_filename(fRootDir.c_str(), "", testName, | 144 SkString path = make_filename(fRootDir.c_str(), "", testName, kPNG_FileE xtension); |
| 145 "png"); | |
| 146 SkBitmap referenceBitmap; | 145 SkBitmap referenceBitmap; |
| 147 bool decodedReferenceBitmap = | 146 bool decodedReferenceBitmap = |
| 148 SkImageDecoder::DecodeFile(path.c_str(), &referenceBitmap, | 147 SkImageDecoder::DecodeFile(path.c_str(), &referenceBitmap, |
| 149 SkBitmap::kARGB_8888_Config, | 148 SkBitmap::kARGB_8888_Config, |
| 150 SkImageDecoder::kDecodePixels_Mode, | 149 SkImageDecoder::kDecodePixels_Mode, |
| 151 NULL); | 150 NULL); |
| 152 if (decodedReferenceBitmap) { | 151 if (decodedReferenceBitmap) { |
| 153 return Expectations(referenceBitmap); | 152 return Expectations(referenceBitmap); |
| 154 } else { | 153 } else { |
| 155 return Expectations(); | 154 return Expectations(); |
| 156 } | 155 } |
| 157 } | 156 } |
| 158 | 157 |
| 159 | 158 |
| 160 // JsonExpectationsSource class... | 159 // JsonExpectationsSource class... |
| 161 | 160 |
| 162 JsonExpectationsSource::JsonExpectationsSource(const char *jsonPath) { | 161 JsonExpectationsSource::JsonExpectationsSource(const char *jsonPath) { |
| 163 parse(jsonPath, &fJsonRoot); | 162 parse(jsonPath, &fJsonRoot); |
| 164 fJsonExpectedResults = fJsonRoot[kJsonKey_ExpectedResults]; | 163 fJsonExpectedResults = fJsonRoot[kJsonKey_ExpectedResults]; |
| 165 } | 164 } |
| 166 | 165 |
| 167 Expectations JsonExpectationsSource::get(const char *testName) { | 166 Expectations JsonExpectationsSource::get(const char *testName) { |
| 168 return Expectations(fJsonExpectedResults[testName]); | 167 SkString testNameWithExtension(testName); |
| 168 testNameWithExtension.append("."); | |
| 169 testNameWithExtension.append(kPNG_FileExtension); | |
|
scroggo
2013/05/08 20:39:45
This will break my use of this function in skimage
epoger
2013/05/09 14:20:07
Thanks for the early warning on that. Actually, i
scroggo
2013/05/09 14:28:48
Yes. Thanks!
| |
| 170 return Expectations(fJsonExpectedResults[testNameWithExtension.c_str()]) ; | |
| 169 } | 171 } |
| 170 | 172 |
| 171 /*static*/ SkData* JsonExpectationsSource::readIntoSkData(SkStream &stream, size_t maxBytes) { | 173 /*static*/ SkData* JsonExpectationsSource::readIntoSkData(SkStream &stream, size_t maxBytes) { |
| 172 if (0 == maxBytes) { | 174 if (0 == maxBytes) { |
| 173 return SkData::NewEmpty(); | 175 return SkData::NewEmpty(); |
| 174 } | 176 } |
| 175 char* bufStart = reinterpret_cast<char *>(sk_malloc_throw(maxBytes)); | 177 char* bufStart = reinterpret_cast<char *>(sk_malloc_throw(maxBytes)); |
| 176 char* bufPtr = bufStart; | 178 char* bufPtr = bufStart; |
| 177 size_t bytesRemaining = maxBytes; | 179 size_t bytesRemaining = maxBytes; |
| 178 while (bytesRemaining > 0) { | 180 while (bytesRemaining > 0) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 206 Json::Reader reader; | 208 Json::Reader reader; |
| 207 if (!reader.parse(bytes, bytes+size, *jsonRoot)) { | 209 if (!reader.parse(bytes, bytes+size, *jsonRoot)) { |
| 208 gm_fprintf(stderr, "error parsing JSON file %s\n", jsonPath); | 210 gm_fprintf(stderr, "error parsing JSON file %s\n", jsonPath); |
| 209 DEBUGFAIL_SEE_STDERR; | 211 DEBUGFAIL_SEE_STDERR; |
| 210 return false; | 212 return false; |
| 211 } | 213 } |
| 212 return true; | 214 return true; |
| 213 } | 215 } |
| 214 | 216 |
| 215 } | 217 } |
| OLD | NEW |