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

Side by Side Diff: tools/image_expectations.h

Issue 273783004: add --readJsonSummaryPath to render_pictures (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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
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 #ifndef image_expectations_DEFINED 8 #ifndef image_expectations_DEFINED
9 #define image_expectations_DEFINED 9 #define image_expectations_DEFINED
10 10
11 #include "SkBitmap.h" 11 #include "SkBitmap.h"
12 #include "SkJSONCPP.h" 12 #include "SkJSONCPP.h"
13 13
14 namespace sk_tools { 14 namespace sk_tools {
15 15
16 /** 16 /**
17 * Class for collecting image results (checksums) as we go. 17 * The digest of an image (either an image we have generated locally, or an image expectation).
18 *
19 * Currently, this is always a uint64_t hash digest of an SkBitmap.
20 */
21 class ImageDigest {
22 public:
23 /**
24 * Create an ImageDigest of a bitmap.
25 *
26 * Note that this is an expensive operation, because it has to examine a ll pixels in
27 * the bitmap. You may wish to consider using the BitmapAndDigest class , which will
28 * compute the ImageDigest lazily.
29 *
30 * @param bitmap image to get the digest of
31 */
32 explicit ImageDigest(const SkBitmap &bitmap);
33
34 /**
35 * Create an ImageDigest using a hashType/hashValue pair.
36 *
37 * @param hashType the algorithm used to generate the hash; for now, onl y
38 * kJsonValue_Image_ChecksumAlgorithm_Bitmap64bitMD5 is allowed.
39 * @param hashValue the value generated by the hash algorithm for a part icular image.
40 */
41 explicit ImageDigest(const SkString &hashType, uint64_t hashValue);
42
43 /**
44 * Returns the hash digest type as an SkString.
45 *
46 * For now, this always returns kJsonValue_Image_ChecksumAlgorithm_Bitma p64bitMD5 .
47 */
48 SkString getHashType() const;
49
50 /**
51 * Returns the hash digest value as a uint64_t.
52 */
53 uint64_t getHashValue() const;
54
55 private:
56 uint64_t fHashValue;
57 };
58
59 /**
60 * Container that holds a reference to an SkBitmap and computes its ImageDig est lazily.
61 */
62 class BitmapAndDigest {
63 public:
64 explicit BitmapAndDigest(const SkBitmap &bitmap);
65
66 const ImageDigest *getImageDigestPtr();
67 const SkBitmap *getBitmapPtr() const;
68 private:
69 const SkBitmap fBitmap;
70 // EPOGER: before committing, implement this properly so that digest is computed lazily
epoger 2014/05/09 15:37:13 something I will fix before committing the CL...
71 ImageDigest fEPOGERImageDigest;
72 };
73
74 /**
75 * Collects ImageDigests of actually rendered images, perhaps comparing to e xpectations.
18 */ 76 */
19 class ImageResultsSummary { 77 class ImageResultsSummary {
borenet 2014/05/09 15:54:01 Should we rename this class now that it contains b
epoger 2014/05/09 16:06:25 Done.
20 public: 78 public:
21 /** 79 /**
22 * Adds this image to the summary of results. 80 * Adds expectations from a JSON file, returning true if successful.
23 *
24 * @param sourceName name of the source file that generated this result
25 * @param fileName relative path to the image output file on local disk
26 * @param hash hash to store
27 * @param tileNumber if not NULL, ptr to tile number
28 */ 81 */
29 void add(const char *sourceName, const char *fileName, uint64_t hash, 82 bool readExpectationsFile(const char *jsonPath);
30 const int *tileNumber=NULL);
31 83
32 /** 84 /**
33 * Adds this image to the summary of results. 85 * Adds this image to the summary of results.
34 * 86 *
35 * @param sourceName name of the source file that generated this result 87 * @param sourceName name of the source file that generated this result
36 * @param fileName relative path to the image output file on local disk 88 * @param fileName relative path to the image output file on local disk
37 * @param bitmap bitmap to store the hash of 89 * @param digest description of the image's contents
38 * @param tileNumber if not NULL, ptr to tile number 90 * @param tileNumber if not NULL, ptr to tile number
39 */ 91 */
40 void add(const char *sourceName, const char *fileName, const SkBitmap& b itmap, 92 void add(const char *sourceName, const char *fileName, const ImageDigest &digest,
41 const int *tileNumber=NULL); 93 const int *tileNumber=NULL);
42 94
43 /** 95 /**
44 * Writes the summary (as constructed so far) to a file. 96 * Writes the summary (as constructed so far) to a file.
45 * 97 *
46 * @param filename path to write the summary to 98 * @param filename path to write the summary to
47 */ 99 */
48 void writeToFile(const char *filename); 100 void writeToFile(const char *filename) const;
49 101
50 private: 102 private:
103
104 /**
105 * Read the file contents from jsonPath and parse them into jsonRoot.
106 *
107 * Returns true if successful.
108 */
109 static bool Parse(const char *jsonPath, Json::Value *jsonRoot);
110
51 Json::Value fActualResults; 111 Json::Value fActualResults;
112 Json::Value fExpectedJsonRoot;
113 Json::Value fExpectedResults;
52 }; 114 };
53 115
54 } // namespace sk_tools 116 } // namespace sk_tools
55 117
56 #endif // image_expectations_DEFINED 118 #endif // image_expectations_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698