| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/color_analysis.h" | 5 #include "ui/gfx/color_analysis.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 EXPECT_TRUE(ChannelApproximatelyEqual(200, SkColorGetB(color))); | 272 EXPECT_TRUE(ChannelApproximatelyEqual(200, SkColorGetB(color))); |
| 273 } | 273 } |
| 274 | 274 |
| 275 TEST_F(ColorAnalysisTest, ComputeColorCovarianceTrivial) { | 275 TEST_F(ColorAnalysisTest, ComputeColorCovarianceTrivial) { |
| 276 SkBitmap bitmap; | 276 SkBitmap bitmap; |
| 277 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 200); | 277 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 200); |
| 278 | 278 |
| 279 EXPECT_EQ(gfx::Matrix3F::Zeros(), | 279 EXPECT_EQ(gfx::Matrix3F::Zeros(), |
| 280 color_utils::ComputeColorCovariance(bitmap)); | 280 color_utils::ComputeColorCovariance(bitmap)); |
| 281 bitmap.allocPixels(); | 281 bitmap.allocPixels(); |
| 282 bitmap.eraseRGB(50, 150, 200); | 282 bitmap.eraseARGB(255, 50, 150, 200); |
| 283 gfx::Matrix3F covariance = color_utils::ComputeColorCovariance(bitmap); | 283 gfx::Matrix3F covariance = color_utils::ComputeColorCovariance(bitmap); |
| 284 // The answer should be all zeros. | 284 // The answer should be all zeros. |
| 285 EXPECT_TRUE(covariance == gfx::Matrix3F::Zeros()); | 285 EXPECT_TRUE(covariance == gfx::Matrix3F::Zeros()); |
| 286 } | 286 } |
| 287 | 287 |
| 288 TEST_F(ColorAnalysisTest, ComputeColorCovarianceWithCanvas) { | 288 TEST_F(ColorAnalysisTest, ComputeColorCovarianceWithCanvas) { |
| 289 gfx::Canvas canvas(gfx::Size(250, 200), 1.0f, true); | 289 gfx::Canvas canvas(gfx::Size(250, 200), 1.0f, true); |
| 290 // The image consists of vertical stripes, with color bands set to 100 | 290 // The image consists of vertical stripes, with color bands set to 100 |
| 291 // in overlapping stripes 150 pixels wide. | 291 // in overlapping stripes 150 pixels wide. |
| 292 canvas.FillRect(gfx::Rect(0, 0, 50, 200), SkColorSetRGB(100, 0, 0)); | 292 canvas.FillRect(gfx::Rect(0, 0, 50, 200), SkColorSetRGB(100, 0, 0)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 308 | 308 |
| 309 TEST_F(ColorAnalysisTest, ApplyColorReductionSingleColor) { | 309 TEST_F(ColorAnalysisTest, ApplyColorReductionSingleColor) { |
| 310 // The test runs color reduction on a single-colot image, where results are | 310 // The test runs color reduction on a single-colot image, where results are |
| 311 // bound to be uninteresting. This is an important edge case, though. | 311 // bound to be uninteresting. This is an important edge case, though. |
| 312 SkBitmap source, result; | 312 SkBitmap source, result; |
| 313 source.setConfig(SkBitmap::kARGB_8888_Config, 300, 200); | 313 source.setConfig(SkBitmap::kARGB_8888_Config, 300, 200); |
| 314 result.setConfig(SkBitmap::kA8_Config, 300, 200); | 314 result.setConfig(SkBitmap::kA8_Config, 300, 200); |
| 315 | 315 |
| 316 source.allocPixels(); | 316 source.allocPixels(); |
| 317 result.allocPixels(); | 317 result.allocPixels(); |
| 318 source.eraseRGB(50, 150, 200); | 318 source.eraseARGB(255, 50, 150, 200); |
| 319 | 319 |
| 320 gfx::Vector3dF transform(1.0f, .5f, 0.1f); | 320 gfx::Vector3dF transform(1.0f, .5f, 0.1f); |
| 321 // This transform, if not scaled, should result in GL=145. | 321 // This transform, if not scaled, should result in GL=145. |
| 322 EXPECT_TRUE(color_utils::ApplyColorReduction( | 322 EXPECT_TRUE(color_utils::ApplyColorReduction( |
| 323 source, transform, false, &result)); | 323 source, transform, false, &result)); |
| 324 | 324 |
| 325 uint8_t min_gl = 0; | 325 uint8_t min_gl = 0; |
| 326 uint8_t max_gl = 0; | 326 uint8_t max_gl = 0; |
| 327 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); | 327 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); |
| 328 EXPECT_EQ(145, min_gl); | 328 EXPECT_EQ(145, min_gl); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 EXPECT_EQ(193U, SkColorGetA(result.getColor(0, 0))); | 429 EXPECT_EQ(193U, SkColorGetA(result.getColor(0, 0))); |
| 430 } | 430 } |
| 431 | 431 |
| 432 TEST_F(ColorAnalysisTest, ComputePrincipalComponentImageNotComputable) { | 432 TEST_F(ColorAnalysisTest, ComputePrincipalComponentImageNotComputable) { |
| 433 SkBitmap source, result; | 433 SkBitmap source, result; |
| 434 source.setConfig(SkBitmap::kARGB_8888_Config, 300, 200); | 434 source.setConfig(SkBitmap::kARGB_8888_Config, 300, 200); |
| 435 result.setConfig(SkBitmap::kA8_Config, 300, 200); | 435 result.setConfig(SkBitmap::kA8_Config, 300, 200); |
| 436 | 436 |
| 437 source.allocPixels(); | 437 source.allocPixels(); |
| 438 result.allocPixels(); | 438 result.allocPixels(); |
| 439 source.eraseRGB(50, 150, 200); | 439 source.eraseARGB(255, 50, 150, 200); |
| 440 | 440 |
| 441 // This computation should fail since all colors always vary together. | 441 // This computation should fail since all colors always vary together. |
| 442 EXPECT_FALSE(color_utils::ComputePrincipalComponentImage(source, &result)); | 442 EXPECT_FALSE(color_utils::ComputePrincipalComponentImage(source, &result)); |
| 443 } | 443 } |
| 444 | 444 |
| 445 TEST_F(ColorAnalysisTest, ComputePrincipalComponentImage) { | 445 TEST_F(ColorAnalysisTest, ComputePrincipalComponentImage) { |
| 446 gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, true); | 446 gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, true); |
| 447 | 447 |
| 448 // The image consists of vertical non-overlapping stripes 100 pixels wide. | 448 // The image consists of vertical non-overlapping stripes 100 pixels wide. |
| 449 canvas.FillRect(gfx::Rect(0, 0, 100, 200), SkColorSetRGB(10, 10, 10)); | 449 canvas.FillRect(gfx::Rect(0, 0, 100, 200), SkColorSetRGB(10, 10, 10)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 461 uint8_t min_gl = 0; | 461 uint8_t min_gl = 0; |
| 462 uint8_t max_gl = 0; | 462 uint8_t max_gl = 0; |
| 463 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); | 463 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); |
| 464 | 464 |
| 465 EXPECT_EQ(0, min_gl); | 465 EXPECT_EQ(0, min_gl); |
| 466 EXPECT_EQ(255, max_gl); | 466 EXPECT_EQ(255, max_gl); |
| 467 EXPECT_EQ(min_gl, SkColorGetA(result.getColor(0, 0))); | 467 EXPECT_EQ(min_gl, SkColorGetA(result.getColor(0, 0))); |
| 468 EXPECT_EQ(max_gl, SkColorGetA(result.getColor(299, 199))); | 468 EXPECT_EQ(max_gl, SkColorGetA(result.getColor(299, 199))); |
| 469 EXPECT_EQ(93U, SkColorGetA(result.getColor(150, 0))); | 469 EXPECT_EQ(93U, SkColorGetA(result.getColor(150, 0))); |
| 470 } | 470 } |
| OLD | NEW |