Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: tools/image_expectations.cpp

Issue 466153006: add --descriptions flag to render_pictures tool (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 "SkBitmapHasher.h" 9 #include "SkBitmapHasher.h"
10 #include "SkData.h" 10 #include "SkData.h"
(...skipping 10 matching lines...) Expand all
21 * TODO(epoger): Similar constants are already maintained in 2 other places: 21 * TODO(epoger): Similar constants are already maintained in 2 other places:
22 * gm/gm_json.py and gm/gm_expectations.cpp. We shouldn't add yet a third place. 22 * gm/gm_json.py and gm/gm_expectations.cpp. We shouldn't add yet a third place.
23 * Figure out a way to share the definitions instead. 23 * Figure out a way to share the definitions instead.
24 * 24 *
25 * Note that, as of https://codereview.chromium.org/226293002 , the JSON 25 * Note that, as of https://codereview.chromium.org/226293002 , the JSON
26 * schema used here has started to differ from the one in gm_expectations.cpp . 26 * schema used here has started to differ from the one in gm_expectations.cpp .
27 * TODO(epoger): Consider getting GM and render_pictures to use the same JSON 27 * TODO(epoger): Consider getting GM and render_pictures to use the same JSON
28 * output module. 28 * output module.
29 */ 29 */
30 const static char kJsonKey_ActualResults[] = "actual-results"; 30 const static char kJsonKey_ActualResults[] = "actual-results";
31 const static char kJsonKey_Descriptions[] = "descriptions";
31 const static char kJsonKey_ExpectedResults[] = "expected-results"; 32 const static char kJsonKey_ExpectedResults[] = "expected-results";
32 const static char kJsonKey_Header[] = "header"; 33 const static char kJsonKey_Header[] = "header";
33 const static char kJsonKey_Header_Type[] = "type"; 34 const static char kJsonKey_Header_Type[] = "type";
34 const static char kJsonKey_Header_Revision[] = "revision"; 35 const static char kJsonKey_Header_Revision[] = "revision";
35 const static char kJsonKey_Image_ChecksumAlgorithm[] = "checksumAlgorithm"; 36 const static char kJsonKey_Image_ChecksumAlgorithm[] = "checksumAlgorithm";
36 const static char kJsonKey_Image_ChecksumValue[] = "checksumValue"; 37 const static char kJsonKey_Image_ChecksumValue[] = "checksumValue";
37 const static char kJsonKey_Image_ComparisonResult[] = "comparisonResult"; 38 const static char kJsonKey_Image_ComparisonResult[] = "comparisonResult";
38 const static char kJsonKey_Image_Filepath[] = "filepath"; 39 const static char kJsonKey_Image_Filepath[] = "filepath";
39 const static char kJsonKey_Image_IgnoreFailure[] = "ignoreFailure"; 40 const static char kJsonKey_Image_IgnoreFailure[] = "ignoreFailure";
40 const static char kJsonKey_Source_TiledImages[] = "tiled-images"; 41 const static char kJsonKey_Source_TiledImages[] = "tiled-images";
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 actualImage[kJsonKey_Image_ComparisonResult] = comparisonResult; 171 actualImage[kJsonKey_Image_ComparisonResult] = comparisonResult;
171 172
172 // Add this actual result to our collection. 173 // Add this actual result to our collection.
173 if (NULL == tileNumber) { 174 if (NULL == tileNumber) {
174 fActualResults[sourceName][kJsonKey_Source_WholeImage] = actualImage ; 175 fActualResults[sourceName][kJsonKey_Source_WholeImage] = actualImage ;
175 } else { 176 } else {
176 fActualResults[sourceName][kJsonKey_Source_TiledImages][*tileNumber] = actualImage; 177 fActualResults[sourceName][kJsonKey_Source_TiledImages][*tileNumber] = actualImage;
177 } 178 }
178 } 179 }
179 180
181 void ImageResultsAndExpectations::addDescription(const char *key, const char *value) {
182 fDescriptions[key] = value;
183 }
184
180 bool ImageResultsAndExpectations::matchesExpectation(const char *sourceName, 185 bool ImageResultsAndExpectations::matchesExpectation(const char *sourceName,
181 const ImageDigest &dige st, 186 const ImageDigest &dige st,
182 const int *tileNumber) { 187 const int *tileNumber) {
183 if (fExpectedResults.isNull()) { 188 if (fExpectedResults.isNull()) {
184 return false; 189 return false;
185 } 190 }
186 191
187 Json::Value expectedImage; 192 Json::Value expectedImage;
188 if (NULL == tileNumber) { 193 if (NULL == tileNumber) {
189 expectedImage = fExpectedResults[sourceName][kJsonKey_Source_WholeIm age]; 194 expectedImage = fExpectedResults[sourceName][kJsonKey_Source_WholeIm age];
190 } else { 195 } else {
191 expectedImage = fExpectedResults[sourceName][kJsonKey_Source_TiledIm ages][*tileNumber]; 196 expectedImage = fExpectedResults[sourceName][kJsonKey_Source_TiledIm ages][*tileNumber];
192 } 197 }
193 if (expectedImage.isNull()) { 198 if (expectedImage.isNull()) {
194 return false; 199 return false;
195 } 200 }
196 201
197 Json::Value actualChecksumAlgorithm = digest.getHashType().c_str(); 202 Json::Value actualChecksumAlgorithm = digest.getHashType().c_str();
198 Json::Value actualChecksumValue = Json::UInt64(digest.getHashValue()); 203 Json::Value actualChecksumValue = Json::UInt64(digest.getHashValue());
199 return ((actualChecksumAlgorithm == expectedImage[kJsonKey_Image_Checksu mAlgorithm]) && 204 return ((actualChecksumAlgorithm == expectedImage[kJsonKey_Image_Checksu mAlgorithm]) &&
200 (actualChecksumValue == expectedImage[kJsonKey_Image_ChecksumVal ue])); 205 (actualChecksumValue == expectedImage[kJsonKey_Image_ChecksumVal ue]));
201 } 206 }
202 207
203 void ImageResultsAndExpectations::writeToFile(const char *filename) const { 208 void ImageResultsAndExpectations::writeToFile(const char *filename) const {
204 Json::Value header; 209 Json::Value header;
205 header[kJsonKey_Header_Type] = kJsonValue_Header_Type; 210 header[kJsonKey_Header_Type] = kJsonValue_Header_Type;
206 header[kJsonKey_Header_Revision] = kJsonValue_Header_Revision; 211 header[kJsonKey_Header_Revision] = kJsonValue_Header_Revision;
207 Json::Value root; 212 Json::Value root;
213 root[kJsonKey_ActualResults] = fActualResults;
214 root[kJsonKey_Descriptions] = fDescriptions;
208 root[kJsonKey_Header] = header; 215 root[kJsonKey_Header] = header;
209 root[kJsonKey_ActualResults] = fActualResults;
210 std::string jsonStdString = root.toStyledString(); 216 std::string jsonStdString = root.toStyledString();
211 SkFILEWStream stream(filename); 217 SkFILEWStream stream(filename);
212 stream.write(jsonStdString.c_str(), jsonStdString.length()); 218 stream.write(jsonStdString.c_str(), jsonStdString.length());
213 } 219 }
214 220
215 /*static*/ bool ImageResultsAndExpectations::Parse(SkFILE *filePtr, 221 /*static*/ bool ImageResultsAndExpectations::Parse(SkFILE *filePtr,
216 Json::Value *jsonRoot) { 222 Json::Value *jsonRoot) {
217 SkAutoDataUnref dataRef(SkData::NewFromFILE(filePtr)); 223 SkAutoDataUnref dataRef(SkData::NewFromFILE(filePtr));
218 if (NULL == dataRef.get()) { 224 if (NULL == dataRef.get()) {
219 return false; 225 return false;
220 } 226 }
221 227
222 const char *bytes = reinterpret_cast<const char *>(dataRef.get()->data() ); 228 const char *bytes = reinterpret_cast<const char *>(dataRef.get()->data() );
223 size_t size = dataRef.get()->size(); 229 size_t size = dataRef.get()->size();
224 Json::Reader reader; 230 Json::Reader reader;
225 if (!reader.parse(bytes, bytes+size, *jsonRoot)) { 231 if (!reader.parse(bytes, bytes+size, *jsonRoot)) {
226 return false; 232 return false;
227 } 233 }
228 234
229 return true; 235 return true;
230 } 236 }
231 237
232 } // namespace sk_tools 238 } // namespace sk_tools
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698