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