| 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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 // the black one in the image. | 289 // the black one in the image. |
| 290 uint32_t* pixel = bitmap.getAddr32(0, 0); | 290 uint32_t* pixel = bitmap.getAddr32(0, 0); |
| 291 *pixel = SK_ColorBLACK; | 291 *pixel = SK_ColorBLACK; |
| 292 color = FindClosestColor(static_cast<uint8_t*>(bitmap.getPixels()), | 292 color = FindClosestColor(static_cast<uint8_t*>(bitmap.getPixels()), |
| 293 bitmap.width(), | 293 bitmap.width(), |
| 294 bitmap.height(), | 294 bitmap.height(), |
| 295 SK_ColorDKGRAY); | 295 SK_ColorDKGRAY); |
| 296 EXPECT_EQ(SK_ColorBLACK, color); | 296 EXPECT_EQ(SK_ColorBLACK, color); |
| 297 } | 297 } |
| 298 | 298 |
| 299 TEST_F(ColorAnalysisTest, CalculateKMeanColorOfBitmap) { | 299 #if defined(OS_ANDROID) |
| 300 #define MAYBE_CalculateKMeanColorOfBitmap DISABLED_CalculateKMeanColorOfBitmap |
| 301 #else |
| 302 #define MAYBE_CalculateKMeanColorOfBitmap CalculateKMeanColorOfBitmap |
| 303 #endif |
| 304 |
| 305 TEST_F(ColorAnalysisTest, MAYBE_CalculateKMeanColorOfBitmap) { |
| 300 // Create a 16x16 bitmap to represent a favicon. | 306 // Create a 16x16 bitmap to represent a favicon. |
| 301 SkBitmap bitmap; | 307 SkBitmap bitmap; |
| 302 bitmap.allocN32Pixels(16, 16); | 308 bitmap.allocN32Pixels(16, 16); |
| 303 bitmap.eraseARGB(255, 100, 150, 200); | 309 bitmap.eraseARGB(255, 100, 150, 200); |
| 304 | 310 |
| 305 SkColor color = CalculateKMeanColorOfBitmap(bitmap); | 311 SkColor color = CalculateKMeanColorOfBitmap(bitmap); |
| 306 EXPECT_EQ(255u, SkColorGetA(color)); | 312 EXPECT_EQ(255u, SkColorGetA(color)); |
| 307 // Color values are not exactly equal due to reversal of premultiplied alpha. | 313 // Color values are not exactly equal due to reversal of premultiplied alpha. |
| 308 EXPECT_TRUE(ChannelApproximatelyEqual(100, SkColorGetR(color))); | 314 EXPECT_TRUE(ChannelApproximatelyEqual(100, SkColorGetR(color))); |
| 309 EXPECT_TRUE(ChannelApproximatelyEqual(150, SkColorGetG(color))); | 315 EXPECT_TRUE(ChannelApproximatelyEqual(150, SkColorGetG(color))); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); | 352 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); |
| 347 gfx::Matrix3F covariance = ComputeColorCovariance(bitmap); | 353 gfx::Matrix3F covariance = ComputeColorCovariance(bitmap); |
| 348 | 354 |
| 349 gfx::Matrix3F expected_covariance = gfx::Matrix3F::Zeros(); | 355 gfx::Matrix3F expected_covariance = gfx::Matrix3F::Zeros(); |
| 350 expected_covariance.set(2400, 400, -1600, | 356 expected_covariance.set(2400, 400, -1600, |
| 351 400, 2400, 400, | 357 400, 2400, 400, |
| 352 -1600, 400, 2400); | 358 -1600, 400, 2400); |
| 353 EXPECT_EQ(expected_covariance, covariance); | 359 EXPECT_EQ(expected_covariance, covariance); |
| 354 } | 360 } |
| 355 | 361 |
| 356 TEST_F(ColorAnalysisTest, ApplyColorReductionSingleColor) { | 362 #if defined(OS_ANDROID) |
| 363 #define MAYBE_ApplyColorReductionSingleColor \ |
| 364 DISABLED_ApplyColorReductionSingleColor |
| 365 #else |
| 366 #define MAYBE_ApplyColorReductionSingleColor ApplyColorReductionSingleColor |
| 367 #endif |
| 368 |
| 369 TEST_F(ColorAnalysisTest, MAYBE_ApplyColorReductionSingleColor) { |
| 357 // The test runs color reduction on a single-colot image, where results are | 370 // The test runs color reduction on a single-colot image, where results are |
| 358 // bound to be uninteresting. This is an important edge case, though. | 371 // bound to be uninteresting. This is an important edge case, though. |
| 359 SkBitmap source, result; | 372 SkBitmap source, result; |
| 360 source.allocN32Pixels(300, 200); | 373 source.allocN32Pixels(300, 200); |
| 361 result.allocPixels(SkImageInfo::MakeA8(300, 200)); | 374 result.allocPixels(SkImageInfo::MakeA8(300, 200)); |
| 362 | 375 |
| 363 source.eraseARGB(255, 50, 150, 200); | 376 source.eraseARGB(255, 50, 150, 200); |
| 364 | 377 |
| 365 gfx::Vector3dF transform(1.0f, .5f, 0.1f); | 378 gfx::Vector3dF transform(1.0f, .5f, 0.1f); |
| 366 // This transform, if not scaled, should result in GL=145. | 379 // This transform, if not scaled, should result in GL=145. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 min_gl = 0; | 436 min_gl = 0; |
| 424 max_gl = 0; | 437 max_gl = 0; |
| 425 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); | 438 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); |
| 426 | 439 |
| 427 EXPECT_EQ(0, min_gl); | 440 EXPECT_EQ(0, min_gl); |
| 428 EXPECT_EQ(255, max_gl); | 441 EXPECT_EQ(255, max_gl); |
| 429 EXPECT_EQ(max_gl, SkColorGetA(result.getColor(0, 0))); | 442 EXPECT_EQ(max_gl, SkColorGetA(result.getColor(0, 0))); |
| 430 EXPECT_EQ(min_gl, SkColorGetA(result.getColor(299, 199))); | 443 EXPECT_EQ(min_gl, SkColorGetA(result.getColor(299, 199))); |
| 431 } | 444 } |
| 432 | 445 |
| 446 #if defined(OS_ANDROID) |
| 447 #define MAYBE_ApplyColorReductionMultiColor \ |
| 448 DISABLED_ApplyColorReductionMultiColor |
| 449 #else |
| 450 #define MAYBE_ApplyColorReductionMultiColor ApplyColorReductionMultiColor |
| 451 #endif |
| 452 |
| 433 TEST_F(ColorAnalysisTest, ApplyColorReductionMultiColor) { | 453 TEST_F(ColorAnalysisTest, ApplyColorReductionMultiColor) { |
| 434 // Check with images with multiple colors. This is really different only when | 454 // Check with images with multiple colors. This is really different only when |
| 435 // the result is scaled. | 455 // the result is scaled. |
| 436 gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, true); | 456 gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, true); |
| 437 | 457 |
| 438 // The image consists of vertical non-overlapping stripes 100 pixels wide. | 458 // The image consists of vertical non-overlapping stripes 100 pixels wide. |
| 439 canvas.FillRect(gfx::Rect(0, 0, 100, 200), SkColorSetRGB(100, 0, 0)); | 459 canvas.FillRect(gfx::Rect(0, 0, 100, 200), SkColorSetRGB(100, 0, 0)); |
| 440 canvas.FillRect(gfx::Rect(100, 0, 100, 200), SkColorSetRGB(0, 255, 0)); | 460 canvas.FillRect(gfx::Rect(100, 0, 100, 200), SkColorSetRGB(0, 255, 0)); |
| 441 canvas.FillRect(gfx::Rect(200, 0, 100, 200), SkColorSetRGB(0, 0, 128)); | 461 canvas.FillRect(gfx::Rect(200, 0, 100, 200), SkColorSetRGB(0, 0, 128)); |
| 442 SkBitmap source = | 462 SkBitmap source = |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); | 515 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); |
| 496 | 516 |
| 497 EXPECT_EQ(0, min_gl); | 517 EXPECT_EQ(0, min_gl); |
| 498 EXPECT_EQ(255, max_gl); | 518 EXPECT_EQ(255, max_gl); |
| 499 EXPECT_EQ(min_gl, SkColorGetA(result.getColor(0, 0))); | 519 EXPECT_EQ(min_gl, SkColorGetA(result.getColor(0, 0))); |
| 500 EXPECT_EQ(max_gl, SkColorGetA(result.getColor(299, 199))); | 520 EXPECT_EQ(max_gl, SkColorGetA(result.getColor(299, 199))); |
| 501 EXPECT_EQ(93U, SkColorGetA(result.getColor(150, 0))); | 521 EXPECT_EQ(93U, SkColorGetA(result.getColor(150, 0))); |
| 502 } | 522 } |
| 503 | 523 |
| 504 } // namespace color_utils | 524 } // namespace color_utils |
| OLD | NEW |