| Index: tools/image_expectations.h
|
| diff --git a/tools/image_expectations.h b/tools/image_expectations.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..74964e9ea5be1bf6c829dfb1ce0287c07d6d39e6
|
| --- /dev/null
|
| +++ b/tools/image_expectations.h
|
| @@ -0,0 +1,123 @@
|
| +/*
|
| + * Copyright 2014 Google Inc.
|
| + *
|
| + * Use of this source code is governed by a BSD-style license that can be
|
| + * found in the LICENSE file.
|
| + *
|
| + * Information about the images we actually generated, and the images we expected to see.
|
| + *
|
| + * TODO(epoger): Combine this with gm/gm_expectations.h, or eliminate one of the two.
|
| + */
|
| +#ifndef image_expectations_DEFINED
|
| +#define image_expectations_DEFINED
|
| +
|
| +#include "SkBitmap.h"
|
| +#include "SkJSONCPP.h"
|
| +
|
| +// EPOGER: Before committing, add unittests for all of these things
|
| +
|
| +namespace sk_tools {
|
| +
|
| + /**
|
| + * 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 ImageDigest {
|
| + public:
|
| + /**
|
| + * Create an ImageDigest of a bitmap.
|
| + *
|
| + * 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
|
| + */
|
| + 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
|
| + ImageDigest fEPOGERImageDigest;
|
| + };
|
| +
|
| + /**
|
| + * Collects ImageDigests of actually rendered images, perhaps comparing to expectations.
|
| + */
|
| + class ImageResultsSummary {
|
| + 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 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 ImageDigest &digest,
|
| + const int *tileNumber=NULL);
|
| +
|
| + /**
|
| + * Writes the summary (as constructed so far) to a file.
|
| + *
|
| + * @param filename path to write the summary to
|
| + */
|
| + 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
|
| +#endif // image_expectations_DEFINED
|
|
|