Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 1 | // Copyright 2019 Google LLC. |
| 2 | // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
| 3 | |
| 4 | #pragma once |
| 5 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 6 | #include "include/core/SkBitmap.h" |
| 7 | #include "include/core/SkStream.h" |
| 8 | #include "tools/flags/CommandLineFlags.h" |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 9 | |
Mike Klein | 989f5bf | 2020-10-07 10:11:50 -0500 | [diff] [blame] | 10 | // HashAndEncode transforms any SkBitmap into a standard format, currently |
| 11 | // 16-bit unpremul RGBA in the Rec. 2020 color space. This lets us compare |
Kevin Lubick | 0039874 | 2020-10-08 10:05:07 -0400 | [diff] [blame] | 12 | // images from different backends or configurations, using feedHash() for |
Mike Klein | 989f5bf | 2020-10-07 10:11:50 -0500 | [diff] [blame] | 13 | // direct content-based hashing, or encodePNG() for visual comparison. |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 14 | class HashAndEncode { |
| 15 | public: |
| 16 | explicit HashAndEncode(const SkBitmap&); |
| 17 | |
Mike Klein | 989f5bf | 2020-10-07 10:11:50 -0500 | [diff] [blame] | 18 | // Feed uncompressed pixel data into a hash function like MD5. |
| 19 | void feedHash(SkWStream*) const; |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 20 | |
Mike Klein | 989f5bf | 2020-10-07 10:11:50 -0500 | [diff] [blame] | 21 | // Encode pixels as a PNG in our standard format, with md5 and key/properties as metadata. |
| 22 | bool encodePNG(SkWStream*, |
| 23 | const char* md5, |
| 24 | CommandLineFlags::StringArray key, |
| 25 | CommandLineFlags::StringArray properties) const; |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 26 | |
| 27 | private: |
| 28 | const SkISize fSize; |
Mike Klein | 989f5bf | 2020-10-07 10:11:50 -0500 | [diff] [blame] | 29 | std::unique_ptr<uint64_t[]> fPixels; // In our standard format mentioned above. |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 30 | }; |
| 31 | |