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

Side by Side Diff: tools/image_expectations.cpp

Issue 278633002: reland "extract some common code from PictureRenderer" (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: the fix 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
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkBitmap.h"
9 #include "SkBitmapHasher.h"
10 #include "SkJSONCPP.h"
11 #include "SkOSFile.h"
12 #include "SkStream.h"
13 #include "SkTypes.h"
14
15 #include "image_expectations.h"
16
17 /*
18 * TODO(epoger): Make constant strings consistent instead of mixing hypenated an d camel-caps.
19 *
20 * TODO(epoger): Similar constants are already maintained in 2 other places:
21 * gm/gm_json.py and gm/gm_expectations.cpp. We shouldn't add yet a third place.
22 * Figure out a way to share the definitions instead.
23 *
24 * Note that, as of https://codereview.chromium.org/226293002 , the JSON
25 * schema used here has started to differ from the one in gm_expectations.cpp .
26 * TODO(epoger): Consider getting GM and render_pictures to use the same JSON
27 * output module.
28 */
29 const static char kJsonKey_ActualResults[] = "actual-results";
30 const static char kJsonKey_Header[] = "header";
31 const static char kJsonKey_Header_Type[] = "type";
32 const static char kJsonKey_Header_Revision[] = "revision"; // unique within Typ e
33 const static char kJsonKey_Image_ChecksumAlgorithm[] = "checksumAlgorithm";
34 const static char kJsonKey_Image_ChecksumValue[] = "checksumValue";
35 const static char kJsonKey_Image_ComparisonResult[] = "comparisonResult";
36 const static char kJsonKey_Image_Filepath[] = "filepath";
37 const static char kJsonKey_Source_TiledImages[] = "tiled-images";
38 const static char kJsonKey_Source_WholeImage[] = "whole-image";
39 // Values (not keys) that are written out by this JSON generator
40 const static char kJsonValue_Header_Type[] = "ChecksummedImages";
41 const static int kJsonValue_Header_Revision = 1;
42 const static char kJsonValue_Image_ChecksumAlgorithm_Bitmap64bitMD5[] = "bitmap- 64bitMD5";
43 const static char kJsonValue_Image_ComparisonResult_NoComparison[] = "no-compari son";
44
45 namespace sk_tools {
46
47 void ImageResultsSummary::add(const char *sourceName, const char *fileName, uint64_t hash,
48 const int *tileNumber) {
49 Json::Value image;
50 image[kJsonKey_Image_ChecksumAlgorithm] = kJsonValue_Image_ChecksumAlgor ithm_Bitmap64bitMD5;
51 image[kJsonKey_Image_ChecksumValue] = Json::UInt64(hash);
52 image[kJsonKey_Image_ComparisonResult] = kJsonValue_Image_ComparisonResu lt_NoComparison;
53 image[kJsonKey_Image_Filepath] = fileName;
54 if (NULL == tileNumber) {
55 fActualResults[sourceName][kJsonKey_Source_WholeImage] = image;
56 } else {
57 fActualResults[sourceName][kJsonKey_Source_TiledImages][*tileNumber] = image;
58 }
59 }
60
61 void ImageResultsSummary::add(const char *sourceName, const char *fileName, const SkBitmap& bitmap,
62 const int *tileNumber) {
63 uint64_t hash;
64 SkAssertResult(SkBitmapHasher::ComputeDigest(bitmap, &hash));
65 this->add(sourceName, fileName, hash, tileNumber);
66 }
67
68 void ImageResultsSummary::writeToFile(const char *filename) {
69 Json::Value header;
70 header[kJsonKey_Header_Type] = kJsonValue_Header_Type;
71 header[kJsonKey_Header_Revision] = kJsonValue_Header_Revision;
72 Json::Value root;
73 root[kJsonKey_Header] = header;
74 root[kJsonKey_ActualResults] = fActualResults;
75 std::string jsonStdString = root.toStyledString();
76 SkFILEWStream stream(filename);
77 stream.write(jsonStdString.c_str(), jsonStdString.length());
78 }
79
80 } // namespace sk_tools
OLDNEW
« gyp/tools.gyp ('K') | « tools/image_expectations.h ('k') | tools/render_pictures_main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698