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

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

Powered by Google App Engine
This is Rietveld 408576698