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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: tools/image_expectations.h
diff --git a/tools/image_expectations.h b/tools/image_expectations.h
index 432cf6d3a80bd3f4cbe2e563c2c0d4116a47d7a5..aaf750fe303c5ed1c8146269fe945853f33394c2 100644
--- a/tools/image_expectations.h
+++ b/tools/image_expectations.h
@@ -14,30 +14,82 @@
namespace sk_tools {
/**
- * Class for collecting image results (checksums) as we go.
+ * The digest of an image (either an image we have generated locally, or an image expectation).
+ *
+ * Currently, this is always a uint64_t hash digest of an SkBitmap.
*/
- class ImageResultsSummary {
+ class ImageDigest {
public:
/**
- * Adds this image to the summary of results.
+ * Create an ImageDigest of a bitmap.
*
- * @param sourceName name of the source file that generated this result
- * @param fileName relative path to the image output file on local disk
- * @param hash hash to store
- * @param tileNumber if not NULL, ptr to tile number
+ * Note that this is an expensive operation, because it has to examine all pixels in
+ * the bitmap. You may wish to consider using the BitmapAndDigest class, which will
+ * compute the ImageDigest lazily.
+ *
+ * @param bitmap image to get the digest of
*/
- void add(const char *sourceName, const char *fileName, uint64_t hash,
- const int *tileNumber=NULL);
+ explicit ImageDigest(const SkBitmap &bitmap);
+
+ /**
+ * Create an ImageDigest using a hashType/hashValue pair.
+ *
+ * @param hashType the algorithm used to generate the hash; for now, only
+ * kJsonValue_Image_ChecksumAlgorithm_Bitmap64bitMD5 is allowed.
+ * @param hashValue the value generated by the hash algorithm for a particular image.
+ */
+ explicit ImageDigest(const SkString &hashType, uint64_t hashValue);
+
+ /**
+ * Returns the hash digest type as an SkString.
+ *
+ * For now, this always returns kJsonValue_Image_ChecksumAlgorithm_Bitmap64bitMD5 .
+ */
+ SkString getHashType() const;
+
+ /**
+ * Returns the hash digest value as a uint64_t.
+ */
+ uint64_t getHashValue() const;
+
+ private:
+ uint64_t fHashValue;
+ };
+
+ /**
+ * Container that holds a reference to an SkBitmap and computes its ImageDigest lazily.
+ */
+ class BitmapAndDigest {
+ public:
+ explicit BitmapAndDigest(const SkBitmap &bitmap);
+
+ const ImageDigest *getImageDigestPtr();
+ const SkBitmap *getBitmapPtr() const;
+ private:
+ const SkBitmap fBitmap;
+ // 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...
+ ImageDigest fEPOGERImageDigest;
+ };
+
+ /**
+ * Collects ImageDigests of actually rendered images, perhaps comparing to expectations.
+ */
+ 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.
+ public:
+ /**
+ * Adds expectations from a JSON file, returning true if successful.
+ */
+ bool readExpectationsFile(const char *jsonPath);
/**
* Adds this image to the summary of results.
*
* @param sourceName name of the source file that generated this result
* @param fileName relative path to the image output file on local disk
- * @param bitmap bitmap to store the hash of
+ * @param digest description of the image's contents
* @param tileNumber if not NULL, ptr to tile number
*/
- void add(const char *sourceName, const char *fileName, const SkBitmap& bitmap,
+ void add(const char *sourceName, const char *fileName, const ImageDigest &digest,
const int *tileNumber=NULL);
/**
@@ -45,10 +97,20 @@ namespace sk_tools {
*
* @param filename path to write the summary to
*/
- void writeToFile(const char *filename);
+ void writeToFile(const char *filename) const;
private:
+
+ /**
+ * Read the file contents from jsonPath and parse them into jsonRoot.
+ *
+ * Returns true if successful.
+ */
+ static bool Parse(const char *jsonPath, Json::Value *jsonRoot);
+
Json::Value fActualResults;
+ Json::Value fExpectedJsonRoot;
+ Json::Value fExpectedResults;
};
} // namespace sk_tools

Powered by Google App Engine
This is Rietveld 408576698