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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 EXPECT_EQ(gfx::Matrix3F::Zeros(), | 288 EXPECT_EQ(gfx::Matrix3F::Zeros(), |
289 color_utils::ComputeColorCovariance(bitmap)); | 289 color_utils::ComputeColorCovariance(bitmap)); |
290 bitmap.allocPixels(); | 290 bitmap.allocPixels(); |
291 bitmap.eraseRGB(50, 150, 200); | 291 bitmap.eraseRGB(50, 150, 200); |
292 gfx::Matrix3F covariance = color_utils::ComputeColorCovariance(bitmap); | 292 gfx::Matrix3F covariance = color_utils::ComputeColorCovariance(bitmap); |
293 // The answer should be all zeros. | 293 // The answer should be all zeros. |
294 EXPECT_TRUE(covariance == gfx::Matrix3F::Zeros()); | 294 EXPECT_TRUE(covariance == gfx::Matrix3F::Zeros()); |
295 } | 295 } |
296 | 296 |
297 TEST_F(ColorAnalysisTest, ComputeColorCovarianceWithCanvas) { | 297 TEST_F(ColorAnalysisTest, ComputeColorCovarianceWithCanvas) { |
298 gfx::Canvas canvas(gfx::Size(250, 200), ui::SCALE_FACTOR_100P, true); | 298 gfx::Canvas canvas(gfx::Size(250, 200), 1.0f, true); |
299 // The image consists of vertical stripes, with color bands set to 100 | 299 // The image consists of vertical stripes, with color bands set to 100 |
300 // in overlapping stripes 150 pixels wide. | 300 // in overlapping stripes 150 pixels wide. |
301 canvas.FillRect(gfx::Rect(0, 0, 50, 200), SkColorSetRGB(100, 0, 0)); | 301 canvas.FillRect(gfx::Rect(0, 0, 50, 200), SkColorSetRGB(100, 0, 0)); |
302 canvas.FillRect(gfx::Rect(50, 0, 50, 200), SkColorSetRGB(100, 100, 0)); | 302 canvas.FillRect(gfx::Rect(50, 0, 50, 200), SkColorSetRGB(100, 100, 0)); |
303 canvas.FillRect(gfx::Rect(100, 0, 50, 200), SkColorSetRGB(100, 100, 100)); | 303 canvas.FillRect(gfx::Rect(100, 0, 50, 200), SkColorSetRGB(100, 100, 100)); |
304 canvas.FillRect(gfx::Rect(150, 0, 50, 200), SkColorSetRGB(0, 100, 100)); | 304 canvas.FillRect(gfx::Rect(150, 0, 50, 200), SkColorSetRGB(0, 100, 100)); |
305 canvas.FillRect(gfx::Rect(200, 0, 50, 200), SkColorSetRGB(0, 0, 100)); | 305 canvas.FillRect(gfx::Rect(200, 0, 50, 200), SkColorSetRGB(0, 0, 100)); |
306 | 306 |
307 SkBitmap bitmap = | 307 SkBitmap bitmap = |
308 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); | 308 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 EXPECT_TRUE(color_utils::ApplyColorReduction( | 357 EXPECT_TRUE(color_utils::ApplyColorReduction( |
358 source, transform, false, &result)); | 358 source, transform, false, &result)); |
359 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); | 359 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); |
360 EXPECT_EQ(0x0, min_gl); | 360 EXPECT_EQ(0x0, min_gl); |
361 EXPECT_EQ(0x0, max_gl); | 361 EXPECT_EQ(0x0, max_gl); |
362 } | 362 } |
363 | 363 |
364 TEST_F(ColorAnalysisTest, ApplyColorReductionBlackAndWhite) { | 364 TEST_F(ColorAnalysisTest, ApplyColorReductionBlackAndWhite) { |
365 // Check with images with multiple colors. This is really different only when | 365 // Check with images with multiple colors. This is really different only when |
366 // the result is scaled. | 366 // the result is scaled. |
367 gfx::Canvas canvas(gfx::Size(300, 200), ui::SCALE_FACTOR_100P, true); | 367 gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, true); |
368 | 368 |
369 // The image consists of vertical non-overlapping stripes 150 pixels wide. | 369 // The image consists of vertical non-overlapping stripes 150 pixels wide. |
370 canvas.FillRect(gfx::Rect(0, 0, 150, 200), SkColorSetRGB(0, 0, 0)); | 370 canvas.FillRect(gfx::Rect(0, 0, 150, 200), SkColorSetRGB(0, 0, 0)); |
371 canvas.FillRect(gfx::Rect(150, 0, 150, 200), SkColorSetRGB(255, 255, 255)); | 371 canvas.FillRect(gfx::Rect(150, 0, 150, 200), SkColorSetRGB(255, 255, 255)); |
372 SkBitmap source = | 372 SkBitmap source = |
373 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); | 373 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); |
374 SkBitmap result; | 374 SkBitmap result; |
375 result.setConfig(SkBitmap::kA8_Config, 300, 200); | 375 result.setConfig(SkBitmap::kA8_Config, 300, 200); |
376 result.allocPixels(); | 376 result.allocPixels(); |
377 | 377 |
(...skipping 19 matching lines...) Expand all Loading... |
397 | 397 |
398 EXPECT_EQ(0, min_gl); | 398 EXPECT_EQ(0, min_gl); |
399 EXPECT_EQ(255, max_gl); | 399 EXPECT_EQ(255, max_gl); |
400 EXPECT_EQ(max_gl, SkColorGetA(result.getColor(0, 0))); | 400 EXPECT_EQ(max_gl, SkColorGetA(result.getColor(0, 0))); |
401 EXPECT_EQ(min_gl, SkColorGetA(result.getColor(299, 199))); | 401 EXPECT_EQ(min_gl, SkColorGetA(result.getColor(299, 199))); |
402 } | 402 } |
403 | 403 |
404 TEST_F(ColorAnalysisTest, ApplyColorReductionMultiColor) { | 404 TEST_F(ColorAnalysisTest, ApplyColorReductionMultiColor) { |
405 // Check with images with multiple colors. This is really different only when | 405 // Check with images with multiple colors. This is really different only when |
406 // the result is scaled. | 406 // the result is scaled. |
407 gfx::Canvas canvas(gfx::Size(300, 200), ui::SCALE_FACTOR_100P, true); | 407 gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, true); |
408 | 408 |
409 // The image consists of vertical non-overlapping stripes 100 pixels wide. | 409 // The image consists of vertical non-overlapping stripes 100 pixels wide. |
410 canvas.FillRect(gfx::Rect(0, 0, 100, 200), SkColorSetRGB(100, 0, 0)); | 410 canvas.FillRect(gfx::Rect(0, 0, 100, 200), SkColorSetRGB(100, 0, 0)); |
411 canvas.FillRect(gfx::Rect(100, 0, 100, 200), SkColorSetRGB(0, 255, 0)); | 411 canvas.FillRect(gfx::Rect(100, 0, 100, 200), SkColorSetRGB(0, 255, 0)); |
412 canvas.FillRect(gfx::Rect(200, 0, 100, 200), SkColorSetRGB(0, 0, 128)); | 412 canvas.FillRect(gfx::Rect(200, 0, 100, 200), SkColorSetRGB(0, 0, 128)); |
413 SkBitmap source = | 413 SkBitmap source = |
414 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); | 414 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); |
415 SkBitmap result; | 415 SkBitmap result; |
416 result.setConfig(SkBitmap::kA8_Config, 300, 200); | 416 result.setConfig(SkBitmap::kA8_Config, 300, 200); |
417 result.allocPixels(); | 417 result.allocPixels(); |
(...skipping 27 matching lines...) Expand all Loading... |
445 | 445 |
446 source.allocPixels(); | 446 source.allocPixels(); |
447 result.allocPixels(); | 447 result.allocPixels(); |
448 source.eraseRGB(50, 150, 200); | 448 source.eraseRGB(50, 150, 200); |
449 | 449 |
450 // This computation should fail since all colors always vary together. | 450 // This computation should fail since all colors always vary together. |
451 EXPECT_FALSE(color_utils::ComputePrincipalComponentImage(source, &result)); | 451 EXPECT_FALSE(color_utils::ComputePrincipalComponentImage(source, &result)); |
452 } | 452 } |
453 | 453 |
454 TEST_F(ColorAnalysisTest, ComputePrincipalComponentImage) { | 454 TEST_F(ColorAnalysisTest, ComputePrincipalComponentImage) { |
455 gfx::Canvas canvas(gfx::Size(300, 200), ui::SCALE_FACTOR_100P, true); | 455 gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, true); |
456 | 456 |
457 // The image consists of vertical non-overlapping stripes 100 pixels wide. | 457 // The image consists of vertical non-overlapping stripes 100 pixels wide. |
458 canvas.FillRect(gfx::Rect(0, 0, 100, 200), SkColorSetRGB(10, 10, 10)); | 458 canvas.FillRect(gfx::Rect(0, 0, 100, 200), SkColorSetRGB(10, 10, 10)); |
459 canvas.FillRect(gfx::Rect(100, 0, 100, 200), SkColorSetRGB(100, 100, 100)); | 459 canvas.FillRect(gfx::Rect(100, 0, 100, 200), SkColorSetRGB(100, 100, 100)); |
460 canvas.FillRect(gfx::Rect(200, 0, 100, 200), SkColorSetRGB(255, 255, 255)); | 460 canvas.FillRect(gfx::Rect(200, 0, 100, 200), SkColorSetRGB(255, 255, 255)); |
461 SkBitmap source = | 461 SkBitmap source = |
462 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); | 462 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); |
463 SkBitmap result; | 463 SkBitmap result; |
464 result.setConfig(SkBitmap::kA8_Config, 300, 200); | 464 result.setConfig(SkBitmap::kA8_Config, 300, 200); |
465 result.allocPixels(); | 465 result.allocPixels(); |
466 | 466 |
467 // This computation should fail since all colors always vary together. | 467 // This computation should fail since all colors always vary together. |
468 EXPECT_TRUE(color_utils::ComputePrincipalComponentImage(source, &result)); | 468 EXPECT_TRUE(color_utils::ComputePrincipalComponentImage(source, &result)); |
469 | 469 |
470 uint8_t min_gl = 0; | 470 uint8_t min_gl = 0; |
471 uint8_t max_gl = 0; | 471 uint8_t max_gl = 0; |
472 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); | 472 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); |
473 | 473 |
474 EXPECT_EQ(0, min_gl); | 474 EXPECT_EQ(0, min_gl); |
475 EXPECT_EQ(255, max_gl); | 475 EXPECT_EQ(255, max_gl); |
476 EXPECT_EQ(min_gl, SkColorGetA(result.getColor(0, 0))); | 476 EXPECT_EQ(min_gl, SkColorGetA(result.getColor(0, 0))); |
477 EXPECT_EQ(max_gl, SkColorGetA(result.getColor(299, 199))); | 477 EXPECT_EQ(max_gl, SkColorGetA(result.getColor(299, 199))); |
478 EXPECT_EQ(93U, SkColorGetA(result.getColor(150, 0))); | 478 EXPECT_EQ(93U, SkColorGetA(result.getColor(150, 0))); |
479 } | 479 } |
OLD | NEW |