blob: f041f3a9b89bbc2cfc516b71c5912203bf881c46 [file] [log] [blame]
bungeman@google.come3c8ddf2012-12-05 20:13:12 +00001/*
2 * Copyright 2012 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
8#ifndef skdiff_utils_DEFINED
9#define skdiff_utils_DEFINED
10
11#include "skdiff.h"
bungeman@google.come3c8ddf2012-12-05 20:13:12 +000012
13class SkBitmap;
14class SkData;
15class SkString;
16
halcanary96fcdcc2015-08-27 07:41:13 -070017/** Returns true if the two buffers passed in are both non-nullptr,
bungeman@google.come3c8ddf2012-12-05 20:13:12 +000018 * have the same length, and contain exactly the same byte values.
19 */
20bool are_buffers_equal(SkData* skdata1, SkData* skdata2);
21
22/** Reads the file at the given path and returns its complete contents as an
halcanary96fcdcc2015-08-27 07:41:13 -070023 * SkData object (or returns nullptr on error).
bungeman@google.come3c8ddf2012-12-05 20:13:12 +000024 */
bungeman38d909e2016-08-02 14:40:46 -070025sk_sp<SkData> read_file(const char* file_path);
bungeman@google.come3c8ddf2012-12-05 20:13:12 +000026
27/** Decodes the fileBits into the resource.fBitmap. Returns false on failure. */
Brian Osman9889c242018-07-17 16:45:40 -040028bool get_bitmap(sk_sp<SkData> fileBits, DiffResource& resource, bool sizeOnly,
29 bool ignoreColorSpace);
bungeman@google.come3c8ddf2012-12-05 20:13:12 +000030
31/** Writes the bitmap as a PNG to the path specified. */
32bool write_bitmap(const SkString& path, const SkBitmap& bitmap);
33
34/** Given an image filename, returns the name of the file containing
35 * the associated difference image.
36 */
37SkString filename_to_diff_filename(const SkString& filename);
38
39/** Given an image filename, returns the name of the file containing
40 * the "white" difference image.
41 */
42SkString filename_to_white_filename(const SkString& filename);
43
44/** Calls compute_diff and handles the difference and white diff resources.
45 * If !outputDir.isEmpty(), writes out difference and white images.
46 */
47void create_and_write_diff_image(DiffRecord* drp,
48 DiffMetricProc dmp,
49 const int colorThreshold,
50 const SkString& outputDir,
51 const SkString& filename);
52
53#endif