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; |
| 12 | |
| 13 | /** |
| 14 | * Encapsulates an image difference metric algorithm that can be potentially run asynchronously. |
| 15 | */ |
| 16 | class SkImageDiffer { |
| 17 | public: |
| 18 | SkImageDiffer(); |
| 19 | virtual ~SkImageDiffer(); |
| 20 | |
| 21 | /** |
| 22 | * Gets a unique and descriptive name of this differ |
| 23 | * @return A statically allocated null terminated string that is the name of this differ |
| 24 | */ |
| 25 | virtual const char* getName() = 0; |
| 26 | |
| 27 | /** |
| 28 | * Gets if this differ is in a usable state |
| 29 | * @return True if this differ can be used, false otherwise |
| 30 | */ |
| 31 | bool isGood() { return fIsGood; } |
| 32 | |
| 33 | /** |
| 34 | * Wraps a call to queueDiff by loading the given filenames into SkBitmaps |
| 35 | * @param baseline The file path of the baseline image |
| 36 | * @param test The file path of the test image |
| 37 | * @return The results of queueDiff with the loaded bitmaps |
| 38 | */ |
| 39 | int queueDiffOfFile(const char baseline[], const char test[]); |
| 40 | |
| 41 | /** |
| 42 | * Queues a diff on a pair of bitmaps to be done at some future time. |
| 43 | * @param baseline The correct bitmap |
| 44 | * @param test The bitmap whose difference is being tested |
| 45 | * @return An non-negative diff ID on success, a negative integer on failure. |
| 46 | */ |
| 47 | virtual int queueDiff(SkBitmap* baseline, SkBitmap* test) = 0; |
| 48 | |
| 49 | /** |
| 50 | * Gets whether a queued diff of the given id has finished |
| 51 | * @param id The id of the queued diff to query |
| 52 | * @return True if the queued diff is finished and has results, false otherwise |
| 53 | */ |
| 54 | virtual bool isFinished(int id) = 0; |
| 55 | |
| 56 | /** |
| 57 | * Gets the results of the queued diff of the given id. The results are only meaningful after |
| 58 | * the queued diff has finished. |
| 59 | * @param id The id of the queued diff to query |
| 60 | * @return A score between of how different the compared images are, with lower numbers being |
| 61 | * more different. |
| 62 | */ |
| 63 | virtual double getResult(int id) = 0; |
| 64 | |
| 65 | protected: |
| 66 | bool fIsGood; |
| 67 | }; |
| 68 | |
| 69 | |
| 70 | #endif |