blob: 157518cbabd0850f1afc64d75bbdfc75dbb11257 [file] [log] [blame]
Mike Klein735c7ba2019-03-25 12:57:58 -05001// 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 Kleinc0bd9f92019-04-23 12:05:21 -05006#include "include/core/SkBitmap.h"
7#include "include/core/SkStream.h"
8#include "tools/flags/CommandLineFlags.h"
Mike Klein735c7ba2019-03-25 12:57:58 -05009
Mike Klein989f5bf2020-10-07 10:11:50 -050010// 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 Lubick00398742020-10-08 10:05:07 -040012// images from different backends or configurations, using feedHash() for
Mike Klein989f5bf2020-10-07 10:11:50 -050013// direct content-based hashing, or encodePNG() for visual comparison.
Mike Klein735c7ba2019-03-25 12:57:58 -050014class HashAndEncode {
15public:
16 explicit HashAndEncode(const SkBitmap&);
17
Mike Klein989f5bf2020-10-07 10:11:50 -050018 // Feed uncompressed pixel data into a hash function like MD5.
19 void feedHash(SkWStream*) const;
Mike Klein735c7ba2019-03-25 12:57:58 -050020
Mike Klein989f5bf2020-10-07 10:11:50 -050021 // 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 Klein735c7ba2019-03-25 12:57:58 -050026
27private:
28 const SkISize fSize;
Mike Klein989f5bf2020-10-07 10:11:50 -050029 std::unique_ptr<uint64_t[]> fPixels; // In our standard format mentioned above.
Mike Klein735c7ba2019-03-25 12:57:58 -050030};
31