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

Unified Diff: ui/gfx/color_analysis_unittest.cc

Issue 2690513002: Port Android palette API for deriving a prominent color from an image. (Closed)
Patch Set: Created 3 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
« ui/gfx/color_analysis.cc ('K') | « 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 821c3eae09dadcb05fe120bd7ba8f1a300437a75..79e4fd4b6c4f1483b8321319b0ac941963a4f239 100644
--- a/ui/gfx/color_analysis_unittest.cc
+++ b/ui/gfx/color_analysis_unittest.cc
@@ -500,4 +500,61 @@ TEST_F(ColorAnalysisTest, ComputePrincipalComponentImage) {
EXPECT_EQ(93U, SkColorGetA(result.getColor(150, 0)));
}
+TEST_F(ColorAnalysisTest, ComputeProminentColor) {
+ int color_profiles[] = {
+ ColorFlags::DARK | ColorFlags::VIBRANT,
+ ColorFlags::NORMAL | ColorFlags::VIBRANT,
+ ColorFlags::LIGHT | ColorFlags::VIBRANT,
+ ColorFlags::DARK | ColorFlags::MUTED,
+ ColorFlags::NORMAL | ColorFlags::MUTED,
+ ColorFlags::LIGHT | ColorFlags::MUTED,
+ };
+
+ // A totally dark gray image, which yields no prominent color as it's too
+ // close to black.
+ gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, true);
+ canvas.FillRect(gfx::Rect(0, 0, 300, 200), SkColorSetRGB(10, 10, 10));
+ SkBitmap bitmap = skia::ReadPixels(canvas.sk_canvas());
+
+ // All expectations start at SK_ColorTRANSPARENT (i.e. 0).
+ SkColor expectations[arraysize(color_profiles)] = {};
+ for (size_t i = 0; i < arraysize(color_profiles); ++i) {
+ EXPECT_EQ(expectations[i],
+ CalculateProminentColorOfBitmap(bitmap, color_profiles[i]));
+ }
+
+ // Add a green that could hit a couple values.
+ const SkColor kVibrantGreen = SkColorSetRGB(25, 200, 25);
+ canvas.FillRect(gfx::Rect(0, 1, 300, 1), kVibrantGreen);
+ bitmap = skia::ReadPixels(canvas.sk_canvas());
+ expectations[0] = kVibrantGreen;
+ expectations[1] = kVibrantGreen;
+ for (size_t i = 0; i < arraysize(color_profiles); ++i) {
+ EXPECT_EQ(expectations[i],
+ CalculateProminentColorOfBitmap(bitmap, color_profiles[i]))
+ << i;
+ }
+
+ // Add a stripe of a dark, muted green (saturation .33, luma .29).
+ const SkColor kDarkGreen = SkColorSetRGB(50, 100, 50);
+ canvas.FillRect(gfx::Rect(0, 2, 300, 1), kDarkGreen);
+ bitmap = skia::ReadPixels(canvas.sk_canvas());
+ expectations[3] = kDarkGreen;
+ for (size_t i = 0; i < arraysize(color_profiles); ++i) {
+ EXPECT_EQ(expectations[i],
+ CalculateProminentColorOfBitmap(bitmap, color_profiles[i]));
+ }
+
+ // Now draw a little bit of pure green. That should be closer to the goal for
+ // normal vibrant, but is out of range for other color profiles.
+ const SkColor kPureGreen = SkColorSetRGB(0, 255, 0);
+ canvas.FillRect(gfx::Rect(0, 3, 300, 1), kPureGreen);
+ bitmap = skia::ReadPixels(canvas.sk_canvas());
+ expectations[1] = kPureGreen;
+ for (size_t i = 0; i < arraysize(color_profiles); ++i) {
+ EXPECT_EQ(expectations[i],
+ CalculateProminentColorOfBitmap(bitmap, color_profiles[i]));
+ }
+}
+
} // namespace color_utils
« ui/gfx/color_analysis.cc ('K') | « ui/gfx/color_analysis.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698