blob: 1f9ffd1886b52e5eb2feba7f1b0c5ab32c8adfd1 [file] [log] [blame]
commit-bot@chromium.orgbe19b9e2013-06-14 17:26:54 +00001/*
2 * Copyright 2013 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 SkImageDiffer_DEFINED
9#define SkImageDiffer_DEFINED
10
djsollen@google.comefc51b72013-11-12 18:29:17 +000011#include "SkBitmap.h"
commit-bot@chromium.orgbe19b9e2013-06-14 17:26:54 +000012
13/**
14 * Encapsulates an image difference metric algorithm that can be potentially run asynchronously.
15 */
16class SkImageDiffer {
17public:
18 SkImageDiffer();
19 virtual ~SkImageDiffer();
20
djsollen@google.com2761b30d2013-11-07 19:40:35 +000021 static const double RESULT_CORRECT;
22 static const double RESULT_INCORRECT;
djsollen@google.com513a7bf2013-11-07 19:24:06 +000023
djsollen@google.comefc51b72013-11-12 18:29:17 +000024 struct Result {
25 double result;
26 int poiCount;
epoger54f1ad82014-07-02 07:43:04 -070027 // TODO(djsollen): Figure out a way that the differ can report which of the
28 // optional fields it has filled in. See http://skbug.com/2712 ('allow
29 // skpdiff to report different sets of result fields for different comparison algorithms')
djsollen@google.comefc51b72013-11-12 18:29:17 +000030 SkBitmap poiAlphaMask; // optional
epoger54f1ad82014-07-02 07:43:04 -070031 SkBitmap rgbDiffBitmap; // optional
32 SkBitmap whiteDiffBitmap; // optional
33 int maxRedDiff; // optional
34 int maxGreenDiff; // optional
35 int maxBlueDiff; // optional
djsollen@google.comefc51b72013-11-12 18:29:17 +000036 double timeElapsed; // optional
37 };
38
epoger54f1ad82014-07-02 07:43:04 -070039 // A bitfield indicating which bitmap types we want a differ to create.
40 //
41 // TODO(epoger): Remove whiteDiffBitmap, because alphaMask can provide
42 // the same functionality and more.
43 // It will be a little bit tricky, because the rebaseline_server client
44 // and server side code will both need to change to use the alphaMask.
45 struct BitmapsToCreate {
46 bool alphaMask;
47 bool rgbDiff;
48 bool whiteDiff;
49 };
50
commit-bot@chromium.orgbe19b9e2013-06-14 17:26:54 +000051 /**
52 * Gets a unique and descriptive name of this differ
53 * @return A statically allocated null terminated string that is the name of this differ
54 */
djsollen@google.comefc51b72013-11-12 18:29:17 +000055 virtual const char* getName() const = 0;
commit-bot@chromium.orgbe19b9e2013-06-14 17:26:54 +000056
57 /**
zachr@google.comd6585682013-07-17 19:29:19 +000058 * Gets if this differ needs to be initialized with and OpenCL device and context.
59 */
djsollen@google.comefc51b72013-11-12 18:29:17 +000060 virtual bool requiresOpenCL() const { return false; }
zachr@google.comd6585682013-07-17 19:29:19 +000061
62 /**
djsollen@google.comefc51b72013-11-12 18:29:17 +000063 * diff on a pair of bitmaps.
64 * @param baseline The correct bitmap
65 * @param test The bitmap whose difference is being tested
epoger54f1ad82014-07-02 07:43:04 -070066 * @param bitmapsToCreate Which bitmaps the differ should attempt to create
djsollen@google.comefc51b72013-11-12 18:29:17 +000067 * @return true on success, and false in the case of failure
djsollen@google.com513a7bf2013-11-07 19:24:06 +000068 */
epoger54f1ad82014-07-02 07:43:04 -070069 virtual bool diff(SkBitmap* baseline, SkBitmap* test, const BitmapsToCreate& bitmapsToCreate,
djsollen@google.comefc51b72013-11-12 18:29:17 +000070 Result* result) const = 0;
commit-bot@chromium.orgbe19b9e2013-06-14 17:26:54 +000071};
72
commit-bot@chromium.orgbe19b9e2013-06-14 17:26:54 +000073#endif