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

Side by Side Diff: ui/gfx/color_analysis_unittest.cc

Issue 2690513002: Port Android palette API for deriving a prominent color from an image. (Closed)
Patch Set: Created 3 years, 10 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 unified diff | Download patch
« ui/gfx/color_analysis.cc ('K') | « ui/gfx/color_analysis.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 uint8_t max_gl = 0; 493 uint8_t max_gl = 0;
494 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); 494 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl);
495 495
496 EXPECT_EQ(0, min_gl); 496 EXPECT_EQ(0, min_gl);
497 EXPECT_EQ(255, max_gl); 497 EXPECT_EQ(255, max_gl);
498 EXPECT_EQ(min_gl, SkColorGetA(result.getColor(0, 0))); 498 EXPECT_EQ(min_gl, SkColorGetA(result.getColor(0, 0)));
499 EXPECT_EQ(max_gl, SkColorGetA(result.getColor(299, 199))); 499 EXPECT_EQ(max_gl, SkColorGetA(result.getColor(299, 199)));
500 EXPECT_EQ(93U, SkColorGetA(result.getColor(150, 0))); 500 EXPECT_EQ(93U, SkColorGetA(result.getColor(150, 0)));
501 } 501 }
502 502
503 TEST_F(ColorAnalysisTest, ComputeProminentColor) {
504 int color_profiles[] = {
505 ColorFlags::DARK | ColorFlags::VIBRANT,
506 ColorFlags::NORMAL | ColorFlags::VIBRANT,
507 ColorFlags::LIGHT | ColorFlags::VIBRANT,
508 ColorFlags::DARK | ColorFlags::MUTED,
509 ColorFlags::NORMAL | ColorFlags::MUTED,
510 ColorFlags::LIGHT | ColorFlags::MUTED,
511 };
512
513 // A totally dark gray image, which yields no prominent color as it's too
514 // close to black.
515 gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, true);
516 canvas.FillRect(gfx::Rect(0, 0, 300, 200), SkColorSetRGB(10, 10, 10));
517 SkBitmap bitmap = skia::ReadPixels(canvas.sk_canvas());
518
519 // All expectations start at SK_ColorTRANSPARENT (i.e. 0).
520 SkColor expectations[arraysize(color_profiles)] = {};
521 for (size_t i = 0; i < arraysize(color_profiles); ++i) {
522 EXPECT_EQ(expectations[i],
523 CalculateProminentColorOfBitmap(bitmap, color_profiles[i]));
524 }
525
526 // Add a green that could hit a couple values.
527 const SkColor kVibrantGreen = SkColorSetRGB(25, 200, 25);
528 canvas.FillRect(gfx::Rect(0, 1, 300, 1), kVibrantGreen);
529 bitmap = skia::ReadPixels(canvas.sk_canvas());
530 expectations[0] = kVibrantGreen;
531 expectations[1] = kVibrantGreen;
532 for (size_t i = 0; i < arraysize(color_profiles); ++i) {
533 EXPECT_EQ(expectations[i],
534 CalculateProminentColorOfBitmap(bitmap, color_profiles[i]))
535 << i;
536 }
537
538 // Add a stripe of a dark, muted green (saturation .33, luma .29).
539 const SkColor kDarkGreen = SkColorSetRGB(50, 100, 50);
540 canvas.FillRect(gfx::Rect(0, 2, 300, 1), kDarkGreen);
541 bitmap = skia::ReadPixels(canvas.sk_canvas());
542 expectations[3] = kDarkGreen;
543 for (size_t i = 0; i < arraysize(color_profiles); ++i) {
544 EXPECT_EQ(expectations[i],
545 CalculateProminentColorOfBitmap(bitmap, color_profiles[i]));
546 }
547
548 // 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.
550 const SkColor kPureGreen = SkColorSetRGB(0, 255, 0);
551 canvas.FillRect(gfx::Rect(0, 3, 300, 1), kPureGreen);
552 bitmap = skia::ReadPixels(canvas.sk_canvas());
553 expectations[1] = kPureGreen;
554 for (size_t i = 0; i < arraysize(color_profiles); ++i) {
555 EXPECT_EQ(expectations[i],
556 CalculateProminentColorOfBitmap(bitmap, color_profiles[i]));
557 }
558 }
559
503 } // namespace color_utils 560 } // namespace color_utils
OLDNEW
« ui/gfx/color_analysis.cc ('K') | « ui/gfx/color_analysis.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698