Chromium Code Reviews| Index: cc/test/pixel_comparator.h |
| diff --git a/cc/test/pixel_comparator.h b/cc/test/pixel_comparator.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6b3b77f9691b1b56634e10ebc4dafe7bcf4d4f08 |
| --- /dev/null |
| +++ b/cc/test/pixel_comparator.h |
| @@ -0,0 +1,65 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CC_TEST_PIXEL_COMPARATOR_H_ |
| +#define CC_TEST_PIXEL_COMPARATOR_H_ |
| + |
| +#include "third_party/skia/include/core/SkBitmap.h" |
| + |
| +namespace cc { |
| + |
| +// Interface for pixel comparators. |
| +class PixelComparator { |
| + public: |
| + virtual bool Compare(const SkBitmap& actual_bmp, |
| + const SkBitmap& expected_bmp) const = 0; |
| + |
| + protected: |
| + virtual ~PixelComparator() {}; |
|
reveman
2013/03/07 21:41:25
don't need a ; after a }
ernstm
2013/03/08 00:14:46
Done.
|
| + // Returns true if the two bitmaps have the same dimensions. Otherwise returns |
| + // false and outputs a message on LOG(ERROR) |
| + bool CompareSize(const SkBitmap& actual_bmp, |
| + const SkBitmap& expected_bmp) const; |
|
reveman
2013/03/07 21:41:25
To keep this as clean as possible, I'd prefer to k
ernstm
2013/03/08 00:14:46
Done.
|
| +}; |
| + |
| +// Exact pixel comparator. Counts the number of pixel with an error. |
| +class ExactPixelComparator : public PixelComparator { |
| + public: |
| + // Returns true if the two bitmaps are identical. Otherwise, returns false |
| + // and report the number of pixels with an error on LOG(ERROR). |
| + bool Compare(const SkBitmap& actual_bmp, const SkBitmap& expected_bmp) const; |
| +}; |
| + |
| +// Fuzzy pixel comparator. Counts small and arbitrary errors separately and |
| +// computes average and maximum absolute errors per color channel. |
| +class FuzzyPixelComparator : public PixelComparator { |
| + public: |
| + // Default values for constructor make comparator tolareate an arbitrary |
| + // number of off-by-one errors. |
| + FuzzyPixelComparator(const float error_pixels_percentage_limit = 100.0f, |
| + const float small_error_pixels_percentage_limit = 100.0f, |
| + const float avg_abs_error_limit = 1.0f, |
| + const unsigned int max_abs_error_limit = 1, |
| + const unsigned int small_error_threshold = 1); |
|
reveman
2013/03/07 21:41:25
Style guide doesn't allow default function paramet
ernstm
2013/03/08 00:14:46
Done.
|
| + // Computes error metrics and returns true if the errors don't exceed the |
| + // specified limits. Otherwise, returns false and reports the error metrics on |
| + // LOG(ERROR). |
| + bool Compare(const SkBitmap& actual_bmp, const SkBitmap& expected_bmp) const; |
| + |
| + private: |
| + // Limit for percentage of pixels with an error |
| + float error_pixels_percentage_limit_; |
| + // Limit for percentage of pixels with a small error |
| + float small_error_pixels_percentage_limit_; |
| + // Limit for average absolute error (excluding identical pixels) |
| + float avg_abs_error_limit_; |
| + // Limit for largest absolute error |
| + unsigned int max_abs_error_limit_; |
| + // Threshold for small errors |
| + unsigned int small_error_threshold_; |
| +}; |
| + |
| +} // namespace cc |
| + |
| +#endif // CC_TEST_PIXEL_COMPARATOR_H_ |