commit-bot@chromium.org | be19b9e | 2013-06-14 17:26:54 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 11 | class SkBitmap; |
zachr@google.com | 572b54d | 2013-06-28 16:27:33 +0000 | [diff] [blame] | 12 | struct SkIPoint; |
commit-bot@chromium.org | be19b9e | 2013-06-14 17:26:54 +0000 | [diff] [blame] | 13 | |
| 14 | /** |
| 15 | * Encapsulates an image difference metric algorithm that can be potentially run asynchronously. |
| 16 | */ |
| 17 | class SkImageDiffer { |
| 18 | public: |
| 19 | SkImageDiffer(); |
| 20 | virtual ~SkImageDiffer(); |
| 21 | |
djsollen@google.com | 513a7bf | 2013-11-07 19:24:06 +0000 | [diff] [blame^] | 22 | static const double RESULT_CORRECT = 1.0f; |
| 23 | static const double RESULT_INCORRECT = 0.0f; |
| 24 | |
commit-bot@chromium.org | be19b9e | 2013-06-14 17:26:54 +0000 | [diff] [blame] | 25 | /** |
| 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.com | d658568 | 2013-07-17 19:29:19 +0000 | [diff] [blame] | 38 | * 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.com | 513a7bf | 2013-11-07 19:24:06 +0000 | [diff] [blame^] | 43 | * 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.org | be19b9e | 2013-06-14 17:26:54 +0000 | [diff] [blame] | 49 | * 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.com | 572b54d | 2013-06-28 16:27:33 +0000 | [diff] [blame] | 72 | * 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.org | be19b9e | 2013-06-14 17:26:54 +0000 | [diff] [blame] | 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 |
commit-bot@chromium.org | be19b9e | 2013-06-14 17:26:54 +0000 | [diff] [blame] | 82 | */ |
| 83 | virtual double getResult(int id) = 0; |
| 84 | |
zachr@google.com | 572b54d | 2013-06-28 16:27:33 +0000 | [diff] [blame] | 85 | /** |
| 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.com | 513a7bf | 2013-11-07 19:24:06 +0000 | [diff] [blame^] | 99 | /* |
| 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.com | 572b54d | 2013-06-28 16:27:33 +0000 | [diff] [blame] | 106 | |
| 107 | |
commit-bot@chromium.org | be19b9e | 2013-06-14 17:26:54 +0000 | [diff] [blame] | 108 | protected: |
| 109 | bool fIsGood; |
| 110 | }; |
| 111 | |
| 112 | |
| 113 | #endif |