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

Side by Side Diff: tools/image_expectations.cpp

Issue 283123002: render_pictures: add --mismatchPath flag (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix SkDebuggerGUI Created 6 years, 7 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
« no previous file with comments | « tools/image_expectations.h ('k') | tools/picture_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 bool ImageResultsAndExpectations::readExpectationsFile(const char *jsonPath) { 97 bool ImageResultsAndExpectations::readExpectationsFile(const char *jsonPath) {
98 if (Parse(jsonPath, &fExpectedJsonRoot)) { 98 if (Parse(jsonPath, &fExpectedJsonRoot)) {
99 fExpectedResults = fExpectedJsonRoot[kJsonKey_ExpectedResults]; 99 fExpectedResults = fExpectedJsonRoot[kJsonKey_ExpectedResults];
100 return true; 100 return true;
101 } else { 101 } else {
102 return false; 102 return false;
103 } 103 }
104 } 104 }
105 105
106 void ImageResultsAndExpectations::add(const char *sourceName, const char *fi leName, 106 void ImageResultsAndExpectations::add(const char *sourceName, const char *fi leName,
107 const ImageDigest &digest, const int *tileNumb er) { 107 const ImageDigest &digest, const int * tileNumber) {
108 // Get expectation, if any. 108 // Get expectation, if any.
109 Json::Value expectedImage; 109 Json::Value expectedImage;
110 if (!fExpectedResults.isNull()) { 110 if (!fExpectedResults.isNull()) {
111 if (NULL == tileNumber) { 111 if (NULL == tileNumber) {
112 expectedImage = fExpectedResults[sourceName][kJsonKey_Source_Who leImage]; 112 expectedImage = fExpectedResults[sourceName][kJsonKey_Source_Who leImage];
113 } else { 113 } else {
114 expectedImage = fExpectedResults[sourceName][kJsonKey_Source_Til edImages] 114 expectedImage = fExpectedResults[sourceName][kJsonKey_Source_Til edImages]
115 [*tileNumber]; 115 [*tileNumber];
116 } 116 }
117 } 117 }
(...skipping 21 matching lines...) Expand all
139 actualImage[kJsonKey_Image_ComparisonResult] = comparisonResult; 139 actualImage[kJsonKey_Image_ComparisonResult] = comparisonResult;
140 140
141 // Add this actual result to our collection. 141 // Add this actual result to our collection.
142 if (NULL == tileNumber) { 142 if (NULL == tileNumber) {
143 fActualResults[sourceName][kJsonKey_Source_WholeImage] = actualImage ; 143 fActualResults[sourceName][kJsonKey_Source_WholeImage] = actualImage ;
144 } else { 144 } else {
145 fActualResults[sourceName][kJsonKey_Source_TiledImages][*tileNumber] = actualImage; 145 fActualResults[sourceName][kJsonKey_Source_TiledImages][*tileNumber] = actualImage;
146 } 146 }
147 } 147 }
148 148
149 bool ImageResultsAndExpectations::matchesExpectation(const char *sourceName,
150 const ImageDigest &dige st,
151 const int *tileNumber) {
152 if (fExpectedResults.isNull()) {
153 return false;
154 }
155
156 Json::Value expectedImage;
157 if (NULL == tileNumber) {
158 expectedImage = fExpectedResults[sourceName][kJsonKey_Source_WholeIm age];
159 } else {
160 expectedImage = fExpectedResults[sourceName][kJsonKey_Source_TiledIm ages][*tileNumber];
161 }
162 if (expectedImage.isNull()) {
163 return false;
164 }
165
166 Json::Value actualChecksumAlgorithm = digest.getHashType().c_str();
167 Json::Value actualChecksumValue = Json::UInt64(digest.getHashValue());
168 return ((actualChecksumAlgorithm == expectedImage[kJsonKey_Image_Checksu mAlgorithm]) &&
169 (actualChecksumValue == expectedImage[kJsonKey_Image_ChecksumVal ue]));
170 }
171
149 void ImageResultsAndExpectations::writeToFile(const char *filename) const { 172 void ImageResultsAndExpectations::writeToFile(const char *filename) const {
150 Json::Value header; 173 Json::Value header;
151 header[kJsonKey_Header_Type] = kJsonValue_Header_Type; 174 header[kJsonKey_Header_Type] = kJsonValue_Header_Type;
152 header[kJsonKey_Header_Revision] = kJsonValue_Header_Revision; 175 header[kJsonKey_Header_Revision] = kJsonValue_Header_Revision;
153 Json::Value root; 176 Json::Value root;
154 root[kJsonKey_Header] = header; 177 root[kJsonKey_Header] = header;
155 root[kJsonKey_ActualResults] = fActualResults; 178 root[kJsonKey_ActualResults] = fActualResults;
156 std::string jsonStdString = root.toStyledString(); 179 std::string jsonStdString = root.toStyledString();
157 SkFILEWStream stream(filename); 180 SkFILEWStream stream(filename);
158 stream.write(jsonStdString.c_str(), jsonStdString.length()); 181 stream.write(jsonStdString.c_str(), jsonStdString.length());
(...skipping 12 matching lines...) Expand all
171 Json::Reader reader; 194 Json::Reader reader;
172 if (!reader.parse(bytes, bytes+size, *jsonRoot)) { 195 if (!reader.parse(bytes, bytes+size, *jsonRoot)) {
173 SkDebugf("error parsing JSON file %s\n", jsonPath); 196 SkDebugf("error parsing JSON file %s\n", jsonPath);
174 return false; 197 return false;
175 } 198 }
176 199
177 return true; 200 return true;
178 } 201 }
179 202
180 } // namespace sk_tools 203 } // namespace sk_tools
OLDNEW
« no previous file with comments | « tools/image_expectations.h ('k') | tools/picture_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698