blob: 3b50d5775d2e8f23bbcfd0acab0fd9ddf73a9c3a [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
11class SkBitmap;
zachr@google.com572b54d2013-06-28 16:27:33 +000012struct SkIPoint;
commit-bot@chromium.orgbe19b9e2013-06-14 17:26:54 +000013
14/**
15 * Encapsulates an image difference metric algorithm that can be potentially run asynchronously.
16 */
17class SkImageDiffer {
18public:
19 SkImageDiffer();
20 virtual ~SkImageDiffer();
21
djsollen@google.com513a7bf2013-11-07 19:24:06 +000022 static const double RESULT_CORRECT = 1.0f;
23 static const double RESULT_INCORRECT = 0.0f;
24
commit-bot@chromium.orgbe19b9e2013-06-14 17:26:54 +000025 /**
26 * Gets a unique and descriptive name of this differ
27 * @return A statically allocated null terminated string that is the name of this differ
28 */
29 virtual const char* getName() = 0;
30
31 /**
32 * Gets if this differ is in a usable state
33 * @return True if this differ can be used, false otherwise
34 */
35 bool isGood() { return fIsGood; }
36
37 /**
zachr@google.comd6585682013-07-17 19:29:19 +000038 * Gets if this differ needs to be initialized with and OpenCL device and context.
39 */
40 virtual bool requiresOpenCL() { return false; }
41
42 /**
djsollen@google.com513a7bf2013-11-07 19:24:06 +000043 * Enables the generation of an alpha mask for all points of interest.
44 * @return True if the differ supports generating an alpha mask and false otherwise.
45 */
46 virtual bool enablePOIAlphaMask() { return false; }
47
48 /**
commit-bot@chromium.orgbe19b9e2013-06-14 17:26:54 +000049 * Wraps a call to queueDiff by loading the given filenames into SkBitmaps
50 * @param baseline The file path of the baseline image
51 * @param test The file path of the test image
52 * @return The results of queueDiff with the loaded bitmaps
53 */
54 int queueDiffOfFile(const char baseline[], const char test[]);
55
56 /**
57 * Queues a diff on a pair of bitmaps to be done at some future time.
58 * @param baseline The correct bitmap
59 * @param test The bitmap whose difference is being tested
60 * @return An non-negative diff ID on success, a negative integer on failure.
61 */
62 virtual int queueDiff(SkBitmap* baseline, SkBitmap* test) = 0;
63
64 /**
65 * Gets whether a queued diff of the given id has finished
66 * @param id The id of the queued diff to query
67 * @return True if the queued diff is finished and has results, false otherwise
68 */
69 virtual bool isFinished(int id) = 0;
70
71 /**
zachr@google.com572b54d2013-06-28 16:27:33 +000072 * Deletes memory associated with a diff and its results. This may block execution until the
73 * diff is finished,
74 * @param id The id of the diff to query
75 */
76 virtual void deleteDiff(int id) = 0;
77
78 /**
commit-bot@chromium.orgbe19b9e2013-06-14 17:26:54 +000079 * Gets the results of the queued diff of the given id. The results are only meaningful after
80 * the queued diff has finished.
81 * @param id The id of the queued diff to query
commit-bot@chromium.orgbe19b9e2013-06-14 17:26:54 +000082 */
83 virtual double getResult(int id) = 0;
84
zachr@google.com572b54d2013-06-28 16:27:33 +000085 /**
86 * Gets the number of points of interest for the diff of the given id. The results are only
87 * meaningful after the queued diff has finished.
88 * @param id The id of the queued diff to query
89 */
90 virtual int getPointsOfInterestCount(int id) = 0;
91
92 /**
93 * Gets an array of the points of interest for the diff of the given id. The results are only
94 * meaningful after the queued diff has finished.
95 * @param id The id of the queued diff to query
96 */
97 virtual SkIPoint* getPointsOfInterest(int id) = 0;
98
djsollen@google.com513a7bf2013-11-07 19:24:06 +000099 /*
100 * Gets a bitmap containing an alpha mask containing transparent pixels at the points of
101 * interest for the diff of the given id. The results are only meaningful after the
102 * queued diff has finished.
103 * @param id The id of the queued diff to query
104 */
105 virtual SkBitmap* getPointsOfInterestAlphaMask(int id) { return NULL; }
zachr@google.com572b54d2013-06-28 16:27:33 +0000106
107
commit-bot@chromium.orgbe19b9e2013-06-14 17:26:54 +0000108protected:
109 bool fIsGood;
110};
111
112
113#endif