blob: c06538df1766f769d99f786f27aea0303493d178 [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
22 /**
23 * Gets a unique and descriptive name of this differ
24 * @return A statically allocated null terminated string that is the name of this differ
25 */
26 virtual const char* getName() = 0;
27
28 /**
29 * Gets if this differ is in a usable state
30 * @return True if this differ can be used, false otherwise
31 */
32 bool isGood() { return fIsGood; }
33
34 /**
35 * Wraps a call to queueDiff by loading the given filenames into SkBitmaps
36 * @param baseline The file path of the baseline image
37 * @param test The file path of the test image
38 * @return The results of queueDiff with the loaded bitmaps
39 */
40 int queueDiffOfFile(const char baseline[], const char test[]);
41
42 /**
43 * Queues a diff on a pair of bitmaps to be done at some future time.
44 * @param baseline The correct bitmap
45 * @param test The bitmap whose difference is being tested
46 * @return An non-negative diff ID on success, a negative integer on failure.
47 */
48 virtual int queueDiff(SkBitmap* baseline, SkBitmap* test) = 0;
49
50 /**
51 * Gets whether a queued diff of the given id has finished
52 * @param id The id of the queued diff to query
53 * @return True if the queued diff is finished and has results, false otherwise
54 */
55 virtual bool isFinished(int id) = 0;
56
57 /**
zachr@google.com572b54d2013-06-28 16:27:33 +000058 * Deletes memory associated with a diff and its results. This may block execution until the
59 * diff is finished,
60 * @param id The id of the diff to query
61 */
62 virtual void deleteDiff(int id) = 0;
63
64 /**
commit-bot@chromium.orgbe19b9e2013-06-14 17:26:54 +000065 * Gets the results of the queued diff of the given id. The results are only meaningful after
66 * the queued diff has finished.
67 * @param id The id of the queued diff to query
commit-bot@chromium.orgbe19b9e2013-06-14 17:26:54 +000068 */
69 virtual double getResult(int id) = 0;
70
zachr@google.com572b54d2013-06-28 16:27:33 +000071 /**
72 * Gets the number of points of interest for the diff of the given id. The results are only
73 * meaningful after the queued diff has finished.
74 * @param id The id of the queued diff to query
75 */
76 virtual int getPointsOfInterestCount(int id) = 0;
77
78 /**
79 * Gets an array of the points of interest for the diff of the given id. The results are only
80 * meaningful after the queued diff has finished.
81 * @param id The id of the queued diff to query
82 */
83 virtual SkIPoint* getPointsOfInterest(int id) = 0;
84
85
86
commit-bot@chromium.orgbe19b9e2013-06-14 17:26:54 +000087protected:
88 bool fIsGood;
89};
90
91
92#endif