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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 uint8_t max_gl = 0; | 490 uint8_t max_gl = 0; |
491 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); | 491 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); |
492 | 492 |
493 EXPECT_EQ(0, min_gl); | 493 EXPECT_EQ(0, min_gl); |
494 EXPECT_EQ(255, max_gl); | 494 EXPECT_EQ(255, max_gl); |
495 EXPECT_EQ(min_gl, SkColorGetA(result.getColor(0, 0))); | 495 EXPECT_EQ(min_gl, SkColorGetA(result.getColor(0, 0))); |
496 EXPECT_EQ(max_gl, SkColorGetA(result.getColor(299, 199))); | 496 EXPECT_EQ(max_gl, SkColorGetA(result.getColor(299, 199))); |
497 EXPECT_EQ(93U, SkColorGetA(result.getColor(150, 0))); | 497 EXPECT_EQ(93U, SkColorGetA(result.getColor(150, 0))); |
498 } | 498 } |
499 | 499 |
500 TEST_F(ColorAnalysisTest, ComputeProminentColor) { | 500 TEST_F(ColorAnalysisTest, ComputeProminentColors) { |
501 struct { | 501 LumaRange lumas[] = {LumaRange::DARK, LumaRange::NORMAL, LumaRange::LIGHT}; |
502 LumaRange luma; | 502 SaturationRange saturations[] = {SaturationRange::VIBRANT, |
503 SaturationRange saturation; | 503 SaturationRange::MUTED}; |
504 } color_profiles[] = {{LumaRange::DARK, SaturationRange::VIBRANT}, | 504 ColorProfiles color_profiles; |
505 {LumaRange::NORMAL, SaturationRange::VIBRANT}, | 505 for (auto s : saturations) { |
506 {LumaRange::LIGHT, SaturationRange::VIBRANT}, | 506 for (auto l : lumas) |
507 {LumaRange::DARK, SaturationRange::MUTED}, | 507 color_profiles.push_back(ColorProfile(l, s)); |
danakj
2017/06/20 23:22:03
nit: .emplace_back(l, s)
Qiang(Joe) Xu
2017/06/21 01:10:52
Done.
| |
508 {LumaRange::NORMAL, SaturationRange::MUTED}, | 508 } |
509 {LumaRange::LIGHT, SaturationRange::MUTED}}; | |
510 | 509 |
511 // A totally dark gray image, which yields no prominent color as it's too | 510 // A totally dark gray image, which yields no prominent color as it's too |
512 // close to black. | 511 // close to black. |
513 gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, true); | 512 gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, true); |
514 canvas.FillRect(gfx::Rect(0, 0, 300, 200), SkColorSetRGB(10, 10, 10)); | 513 canvas.FillRect(gfx::Rect(0, 0, 300, 200), SkColorSetRGB(10, 10, 10)); |
515 SkBitmap bitmap = canvas.GetBitmap(); | 514 SkBitmap bitmap = canvas.GetBitmap(); |
516 | 515 |
517 // All expectations start at SK_ColorTRANSPARENT (i.e. 0). | 516 // All expectations start at SK_ColorTRANSPARENT (i.e. 0). |
518 SkColor expectations[arraysize(color_profiles)] = {}; | 517 std::vector<SkColor> expectations(color_profiles.size(), 0); |
519 for (size_t i = 0; i < arraysize(color_profiles); ++i) { | 518 std::vector<SkColor> computations = |
520 EXPECT_EQ(expectations[i], | 519 CalculateProminentColorsOfBitmap(bitmap, color_profiles); |
521 CalculateProminentColorOfBitmap(bitmap, color_profiles[i].luma, | 520 EXPECT_EQ(expectations, computations); |
522 color_profiles[i].saturation)); | |
523 } | |
524 | 521 |
525 // Add a green that could hit a couple values. | 522 // Add a green that could hit a couple values. |
526 const SkColor kVibrantGreen = SkColorSetRGB(25, 200, 25); | 523 const SkColor kVibrantGreen = SkColorSetRGB(25, 200, 25); |
527 canvas.FillRect(gfx::Rect(0, 1, 300, 1), kVibrantGreen); | 524 canvas.FillRect(gfx::Rect(0, 1, 300, 1), kVibrantGreen); |
528 bitmap = canvas.GetBitmap(); | 525 bitmap = canvas.GetBitmap(); |
529 expectations[0] = kVibrantGreen; | 526 expectations[0] = kVibrantGreen; |
530 expectations[1] = kVibrantGreen; | 527 expectations[1] = kVibrantGreen; |
531 for (size_t i = 0; i < arraysize(color_profiles); ++i) { | 528 computations = CalculateProminentColorsOfBitmap(bitmap, color_profiles); |
532 EXPECT_EQ(expectations[i], | 529 EXPECT_EQ(expectations, computations); |
533 CalculateProminentColorOfBitmap(bitmap, color_profiles[i].luma, | |
534 color_profiles[i].saturation)); | |
535 } | |
536 | 530 |
537 // Add a stripe of a dark, muted green (saturation .33, luma .29). | 531 // Add a stripe of a dark, muted green (saturation .33, luma .29). |
538 const SkColor kDarkGreen = SkColorSetRGB(50, 100, 50); | 532 const SkColor kDarkGreen = SkColorSetRGB(50, 100, 50); |
539 canvas.FillRect(gfx::Rect(0, 2, 300, 1), kDarkGreen); | 533 canvas.FillRect(gfx::Rect(0, 2, 300, 1), kDarkGreen); |
540 bitmap = canvas.GetBitmap(); | 534 bitmap = canvas.GetBitmap(); |
541 expectations[3] = kDarkGreen; | 535 expectations[3] = kDarkGreen; |
542 for (size_t i = 0; i < arraysize(color_profiles); ++i) { | 536 computations = CalculateProminentColorsOfBitmap(bitmap, color_profiles); |
543 EXPECT_EQ(expectations[i], | 537 EXPECT_EQ(expectations, computations); |
544 CalculateProminentColorOfBitmap(bitmap, color_profiles[i].luma, | |
545 color_profiles[i].saturation)); | |
546 } | |
547 | 538 |
548 // Now draw a little bit of pure green. That should be closer to the goal for | 539 // Now draw a little bit of pure green. That should be closer to the goal for |
549 // normal vibrant, but is out of range for other color profiles. | 540 // normal vibrant, but is out of range for other color profiles. |
550 const SkColor kPureGreen = SkColorSetRGB(0, 255, 0); | 541 const SkColor kPureGreen = SkColorSetRGB(0, 255, 0); |
551 canvas.FillRect(gfx::Rect(0, 3, 300, 1), kPureGreen); | 542 canvas.FillRect(gfx::Rect(0, 3, 300, 1), kPureGreen); |
552 bitmap = canvas.GetBitmap(); | 543 bitmap = canvas.GetBitmap(); |
553 expectations[1] = kPureGreen; | 544 expectations[1] = kPureGreen; |
554 for (size_t i = 0; i < arraysize(color_profiles); ++i) { | 545 computations = CalculateProminentColorsOfBitmap(bitmap, color_profiles); |
555 EXPECT_EQ(expectations[i], | 546 EXPECT_EQ(expectations, computations); |
556 CalculateProminentColorOfBitmap(bitmap, color_profiles[i].luma, | |
557 color_profiles[i].saturation)); | |
558 } | |
559 } | 547 } |
560 | 548 |
561 } // namespace color_utils | 549 } // namespace color_utils |
OLD | NEW |