Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Unified Diff: ui/gfx/color_analysis_unittest.cc

Issue 12220123: Adds a function computing image color covariance. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed a performance remark. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/color_analysis.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/color_analysis_unittest.cc
diff --git a/ui/gfx/color_analysis_unittest.cc b/ui/gfx/color_analysis_unittest.cc
index b92deb4a903d57b1eb114c1ee4b8d80291a55c25..d8953698c3a291403a37354ba4738a98cbb838fd 100644
--- a/ui/gfx/color_analysis_unittest.cc
+++ b/ui/gfx/color_analysis_unittest.cc
@@ -9,6 +9,8 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
+#include "ui/gfx/canvas.h"
+#include "ui/gfx/rect.h"
using color_utils::FindClosestColor;
@@ -257,3 +259,37 @@ TEST_F(ColorAnalysisTest, CalculateKMeanColorOfBitmap) {
EXPECT_TRUE(ChannelApproximatelyEqual(150, SkColorGetG(color)));
EXPECT_TRUE(ChannelApproximatelyEqual(200, SkColorGetB(color)));
}
+
+TEST_F(ColorAnalysisTest, ComputeColorCovarianceTrivial) {
+ SkBitmap bitmap;
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 200);
+
+ EXPECT_EQ(gfx::Matrix3F::Zeros(),
+ color_utils::ComputeColorCovariance(bitmap));
+ bitmap.allocPixels();
+ bitmap.eraseRGB(50, 150, 200);
+ gfx::Matrix3F covariance = color_utils::ComputeColorCovariance(bitmap);
+ // The answer should be all zeros.
+ EXPECT_TRUE(covariance == gfx::Matrix3F::Zeros());
+}
+
+TEST_F(ColorAnalysisTest, ComputeColorCovarianceWithCanvas) {
+ gfx::Canvas canvas(gfx::Size(250, 200), ui::SCALE_FACTOR_100P, true);
+ // The image consists of vertical stripes, with color bands set to 100
+ // in overlapping stripes 150 pixels wide.
+ canvas.FillRect(gfx::Rect(0, 0, 50, 200), SkColorSetRGB(100, 0, 0));
+ canvas.FillRect(gfx::Rect(50, 0, 50, 200), SkColorSetRGB(100, 100, 0));
+ canvas.FillRect(gfx::Rect(100, 0, 50, 200), SkColorSetRGB(100, 100, 100));
+ canvas.FillRect(gfx::Rect(150, 0, 50, 200), SkColorSetRGB(0, 100, 100));
+ canvas.FillRect(gfx::Rect(200, 0, 50, 200), SkColorSetRGB(0, 0, 100));
+
+ SkBitmap bitmap =
+ skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false);
+ gfx::Matrix3F covariance = color_utils::ComputeColorCovariance(bitmap);
+
+ gfx::Matrix3F expected_covariance = gfx::Matrix3F::Zeros();
+ expected_covariance.set(2400, 400, -1600,
+ 400, 2400, 400,
+ -1600, 400, 2400);
+ EXPECT_EQ(expected_covariance, covariance);
+}
« no previous file with comments | « ui/gfx/color_analysis.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698