OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkImageDiffer_DEFINED | 8 #ifndef SkImageDiffer_DEFINED |
9 #define SkImageDiffer_DEFINED | 9 #define SkImageDiffer_DEFINED |
10 | 10 |
11 class SkBitmap; | 11 #include "SkBitmap.h" |
12 struct SkIPoint; | |
13 | 12 |
14 /** | 13 /** |
15 * Encapsulates an image difference metric algorithm that can be potentially run asynchronously. | 14 * Encapsulates an image difference metric algorithm that can be potentially run asynchronously. |
16 */ | 15 */ |
17 class SkImageDiffer { | 16 class SkImageDiffer { |
18 public: | 17 public: |
19 SkImageDiffer(); | 18 SkImageDiffer(); |
20 virtual ~SkImageDiffer(); | 19 virtual ~SkImageDiffer(); |
21 | 20 |
22 static const double RESULT_CORRECT; | 21 static const double RESULT_CORRECT; |
23 static const double RESULT_INCORRECT; | 22 static const double RESULT_INCORRECT; |
24 | 23 |
24 struct Result { | |
25 double result; | |
26 int poiCount; | |
27 SkBitmap poiAlphaMask; // optional | |
28 double timeElapsed; // optional | |
29 }; | |
30 | |
25 /** | 31 /** |
26 * Gets a unique and descriptive name of this differ | 32 * Gets a unique and descriptive name of this differ |
27 * @return A statically allocated null terminated string that is the name of this differ | 33 * @return A statically allocated null terminated string that is the name of this differ |
28 */ | 34 */ |
29 virtual const char* getName() = 0; | 35 virtual const char* getName() = 0; |
mtklein
2013/11/08 15:06:13
Make this const?
djsollen
2013/11/12 16:40:43
Done.
| |
30 | 36 |
31 /** | 37 /** |
32 * Gets if this differ is in a usable state | 38 * Gets if this differ is in a usable state |
33 * @return True if this differ can be used, false otherwise | 39 * @return True if this differ can be used, false otherwise |
34 */ | 40 */ |
35 bool isGood() { return fIsGood; } | 41 bool isGood() { return fIsGood; } |
mtklein
2013/11/08 15:06:13
Can go away now?
djsollen
2013/11/12 16:40:43
Done.
| |
36 | 42 |
37 /** | 43 /** |
38 * Gets if this differ needs to be initialized with and OpenCL device and co ntext. | 44 * Gets if this differ needs to be initialized with and OpenCL device and co ntext. |
39 */ | 45 */ |
40 virtual bool requiresOpenCL() { return false; } | 46 virtual bool requiresOpenCL() { return false; } |
mtklein
2013/11/08 15:06:13
const?
djsollen
2013/11/12 16:40:43
Done.
| |
41 | 47 |
42 /** | 48 /** |
43 * Enables the generation of an alpha mask for all points of interest. | 49 * 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 ot herwise. | 50 * @return True if the differ supports generating an alpha mask and false ot herwise. |
45 */ | 51 */ |
46 virtual bool enablePOIAlphaMask() { return false; } | 52 virtual bool enablePOIAlphaMask() { return false; } |
mtklein
2013/11/08 15:06:13
Param to diff?
djsollen
2013/11/12 16:40:43
Done.
| |
47 | 53 |
48 /** | 54 /** |
49 * Wraps a call to queueDiff by loading the given filenames into SkBitmaps | 55 * diff on a pair of bitmaps. |
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 | 56 * @param baseline The correct bitmap |
59 * @param test The bitmap whose difference is being tested | 57 * @param test The bitmap whose difference is being tested |
60 * @return An non-negative diff ID on success, a negative integer o n failure. | 58 * @return true on success, and false in the case of failure |
61 */ | 59 */ |
62 virtual int queueDiff(SkBitmap* baseline, SkBitmap* test) = 0; | 60 virtual bool diff(SkBitmap* baseline, SkBitmap* test, Result* result) = 0; |
mtklein
2013/11/08 15:06:13
can this be const? if not, it's a fairly good sig
mtklein
2013/11/08 15:06:13
do these bitmaps need to be SkBitmap*? const SkBi
djsollen
2013/11/12 16:40:43
the function is now const but the input params can
mtklein
2013/11/12 17:00:19
gotcha. seems fine as-is.
| |
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 oth erwise | |
68 */ | |
69 virtual bool isFinished(int id) = 0; | |
70 | |
71 /** | |
72 * Deletes memory associated with a diff and its results. This may block exe cution 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 /** | |
79 * 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 | |
82 */ | |
83 virtual double getResult(int id) = 0; | |
84 | |
85 /** | |
86 * Gets the number of points of interest for the diff of the given id. The r esults 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 | |
99 /* | |
100 * Gets a bitmap containing an alpha mask containing transparent pixels at t he points of | |
101 * interest for the diff of the given id. The results are only meaningful af ter 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; } | |
106 | |
107 | 61 |
108 protected: | 62 protected: |
109 bool fIsGood; | 63 bool fIsGood; |
mtklein
2013/11/08 15:06:13
Can die?
| |
110 }; | 64 }; |
111 | 65 |
112 | 66 |
113 #endif | 67 #endif |
OLD | NEW |