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

Unified Diff: ui/gfx/color_analysis_unittest.cc

Issue 309773002: Put color util and color analysis tests into color_utils namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | « no previous file | ui/gfx/color_utils_unittest.cc » ('j') | 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 9592d0d38cd496aed15936997d1cdf122ce491bf..3912c912d3e56c32655fc00b5e28aad24ebc983e 100644
--- a/ui/gfx/color_analysis_unittest.cc
+++ b/ui/gfx/color_analysis_unittest.cc
@@ -12,9 +12,7 @@
#include "ui/gfx/canvas.h"
#include "ui/gfx/rect.h"
-using color_utils::FindClosestColor;
-
-namespace {
+namespace color_utils {
const unsigned char k1x1White[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
@@ -87,7 +85,7 @@ const unsigned char k1x3BlueRed[] = {
0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
};
-class MockKMeanImageSampler : public color_utils::KMeanImageSampler {
+class MockKMeanImageSampler : public KMeanImageSampler {
public:
MockKMeanImageSampler() : current_result_index_(0) {
}
@@ -147,8 +145,6 @@ void Calculate8bitBitmapMinMax(const SkBitmap& bitmap,
}
}
-} // namespace
-
class ColorAnalysisTest : public testing::Test {
};
@@ -162,8 +158,7 @@ TEST_F(ColorAnalysisTest, CalculatePNGKMeanAllWhite) {
k1x1White,
k1x1White + sizeof(k1x1White) / sizeof(unsigned char))));
- SkColor color =
- color_utils::CalculateKMeanColorOfPNG(png, 100, 600, &test_sampler);
+ SkColor color = CalculateKMeanColorOfPNG(png, 100, 600, &test_sampler);
EXPECT_EQ(color, SK_ColorWHITE);
}
@@ -180,8 +175,7 @@ TEST_F(ColorAnalysisTest, CalculatePNGKMeanIgnoreWhite) {
k1x3BlueWhite,
k1x3BlueWhite + sizeof(k1x3BlueWhite) / sizeof(unsigned char))));
- SkColor color =
- color_utils::CalculateKMeanColorOfPNG(png, 100, 600, &test_sampler);
+ SkColor color = CalculateKMeanColorOfPNG(png, 100, 600, &test_sampler);
EXPECT_EQ(color, SkColorSetARGB(0xFF, 0x00, 0x00, 0xFF));
}
@@ -198,14 +192,13 @@ TEST_F(ColorAnalysisTest, CalculatePNGKMeanPickMostCommon) {
k1x3BlueRed,
k1x3BlueRed + sizeof(k1x3BlueRed) / sizeof(unsigned char))));
- SkColor color =
- color_utils::CalculateKMeanColorOfPNG(png, 100, 600, &test_sampler);
+ SkColor color = CalculateKMeanColorOfPNG(png, 100, 600, &test_sampler);
EXPECT_EQ(color, SkColorSetARGB(0xFF, 0xFF, 0x00, 0x00));
}
TEST_F(ColorAnalysisTest, GridSampler) {
- color_utils::GridSampler sampler;
+ GridSampler sampler;
const int kWidth = 16;
const int kHeight = 16;
// Sample starts at 1,1.
@@ -254,7 +247,7 @@ TEST_F(ColorAnalysisTest, CalculateKMeanColorOfBitmap) {
bitmap.allocPixels();
bitmap.eraseARGB(255, 100, 150, 200);
- SkColor color = color_utils::CalculateKMeanColorOfBitmap(bitmap);
+ SkColor color = CalculateKMeanColorOfBitmap(bitmap);
EXPECT_EQ(255u, SkColorGetA(color));
// Color values are not exactly equal due to reversal of premultiplied alpha.
EXPECT_TRUE(ChannelApproximatelyEqual(100, SkColorGetR(color)));
@@ -263,7 +256,7 @@ TEST_F(ColorAnalysisTest, CalculateKMeanColorOfBitmap) {
// Test a bitmap with an alpha channel.
bitmap.eraseARGB(128, 100, 150, 200);
- color = color_utils::CalculateKMeanColorOfBitmap(bitmap);
+ color = CalculateKMeanColorOfBitmap(bitmap);
// Alpha channel should be ignored for dominant color calculation.
EXPECT_EQ(255u, SkColorGetA(color));
@@ -276,11 +269,10 @@ TEST_F(ColorAnalysisTest, ComputeColorCovarianceTrivial) {
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 200);
- EXPECT_EQ(gfx::Matrix3F::Zeros(),
- color_utils::ComputeColorCovariance(bitmap));
+ EXPECT_EQ(gfx::Matrix3F::Zeros(), ComputeColorCovariance(bitmap));
bitmap.allocPixels();
bitmap.eraseARGB(255, 50, 150, 200);
- gfx::Matrix3F covariance = color_utils::ComputeColorCovariance(bitmap);
+ gfx::Matrix3F covariance = ComputeColorCovariance(bitmap);
// The answer should be all zeros.
EXPECT_TRUE(covariance == gfx::Matrix3F::Zeros());
}
@@ -297,7 +289,7 @@ TEST_F(ColorAnalysisTest, ComputeColorCovarianceWithCanvas) {
SkBitmap bitmap =
skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false);
- gfx::Matrix3F covariance = color_utils::ComputeColorCovariance(bitmap);
+ gfx::Matrix3F covariance = ComputeColorCovariance(bitmap);
gfx::Matrix3F expected_covariance = gfx::Matrix3F::Zeros();
expected_covariance.set(2400, 400, -1600,
@@ -319,8 +311,7 @@ TEST_F(ColorAnalysisTest, ApplyColorReductionSingleColor) {
gfx::Vector3dF transform(1.0f, .5f, 0.1f);
// This transform, if not scaled, should result in GL=145.
- EXPECT_TRUE(color_utils::ApplyColorReduction(
- source, transform, false, &result));
+ EXPECT_TRUE(ApplyColorReduction(source, transform, false, &result));
uint8_t min_gl = 0;
uint8_t max_gl = 0;
@@ -329,24 +320,21 @@ TEST_F(ColorAnalysisTest, ApplyColorReductionSingleColor) {
EXPECT_EQ(145, max_gl);
// Now scan requesting rescale. Expect all 0.
- EXPECT_TRUE(color_utils::ApplyColorReduction(
- source, transform, true, &result));
+ EXPECT_TRUE(ApplyColorReduction(source, transform, true, &result));
Calculate8bitBitmapMinMax(result, &min_gl, &max_gl);
EXPECT_EQ(0, min_gl);
EXPECT_EQ(0, max_gl);
// Test cliping to upper limit.
transform.set_z(1.1f);
- EXPECT_TRUE(color_utils::ApplyColorReduction(
- source, transform, false, &result));
+ EXPECT_TRUE(ApplyColorReduction(source, transform, false, &result));
Calculate8bitBitmapMinMax(result, &min_gl, &max_gl);
EXPECT_EQ(0xFF, min_gl);
EXPECT_EQ(0xFF, max_gl);
// Test cliping to upper limit.
transform.Scale(-1.0f);
- EXPECT_TRUE(color_utils::ApplyColorReduction(
- source, transform, false, &result));
+ EXPECT_TRUE(ApplyColorReduction(source, transform, false, &result));
Calculate8bitBitmapMinMax(result, &min_gl, &max_gl);
EXPECT_EQ(0x0, min_gl);
EXPECT_EQ(0x0, max_gl);
@@ -367,8 +355,7 @@ TEST_F(ColorAnalysisTest, ApplyColorReductionBlackAndWhite) {
result.allocPixels();
gfx::Vector3dF transform(1.0f, 0.5f, 0.1f);
- EXPECT_TRUE(color_utils::ApplyColorReduction(
- source, transform, true, &result));
+ EXPECT_TRUE(ApplyColorReduction(source, transform, true, &result));
uint8_t min_gl = 0;
uint8_t max_gl = 0;
Calculate8bitBitmapMinMax(result, &min_gl, &max_gl);
@@ -380,8 +367,7 @@ TEST_F(ColorAnalysisTest, ApplyColorReductionBlackAndWhite) {
// Reverse test.
transform.Scale(-1.0f);
- EXPECT_TRUE(color_utils::ApplyColorReduction(
- source, transform, true, &result));
+ EXPECT_TRUE(ApplyColorReduction(source, transform, true, &result));
min_gl = 0;
max_gl = 0;
Calculate8bitBitmapMinMax(result, &min_gl, &max_gl);
@@ -408,8 +394,7 @@ TEST_F(ColorAnalysisTest, ApplyColorReductionMultiColor) {
result.allocPixels();
gfx::Vector3dF transform(1.0f, 0.5f, 0.1f);
- EXPECT_TRUE(color_utils::ApplyColorReduction(
- source, transform, false, &result));
+ EXPECT_TRUE(ApplyColorReduction(source, transform, false, &result));
uint8_t min_gl = 0;
uint8_t max_gl = 0;
Calculate8bitBitmapMinMax(result, &min_gl, &max_gl);
@@ -419,8 +404,7 @@ TEST_F(ColorAnalysisTest, ApplyColorReductionMultiColor) {
EXPECT_EQ(max_gl, SkColorGetA(result.getColor(150, 0)));
EXPECT_EQ(100U, SkColorGetA(result.getColor(0, 0)));
- EXPECT_TRUE(color_utils::ApplyColorReduction(
- source, transform, true, &result));
+ EXPECT_TRUE(ApplyColorReduction(source, transform, true, &result));
Calculate8bitBitmapMinMax(result, &min_gl, &max_gl);
EXPECT_EQ(0, min_gl);
EXPECT_EQ(255, max_gl);
@@ -439,7 +423,7 @@ TEST_F(ColorAnalysisTest, ComputePrincipalComponentImageNotComputable) {
source.eraseARGB(255, 50, 150, 200);
// This computation should fail since all colors always vary together.
- EXPECT_FALSE(color_utils::ComputePrincipalComponentImage(source, &result));
+ EXPECT_FALSE(ComputePrincipalComponentImage(source, &result));
}
TEST_F(ColorAnalysisTest, ComputePrincipalComponentImage) {
@@ -456,7 +440,7 @@ TEST_F(ColorAnalysisTest, ComputePrincipalComponentImage) {
result.allocPixels();
// This computation should fail since all colors always vary together.
- EXPECT_TRUE(color_utils::ComputePrincipalComponentImage(source, &result));
+ EXPECT_TRUE(ComputePrincipalComponentImage(source, &result));
uint8_t min_gl = 0;
uint8_t max_gl = 0;
@@ -468,3 +452,5 @@ TEST_F(ColorAnalysisTest, ComputePrincipalComponentImage) {
EXPECT_EQ(max_gl, SkColorGetA(result.getColor(299, 199)));
EXPECT_EQ(93U, SkColorGetA(result.getColor(150, 0)));
}
+
+} // namespace color_utils
« no previous file with comments | « no previous file | ui/gfx/color_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698