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

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: another comment update Created 3 years, 9 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
« no previous file with comments | « 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 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 uint8_t max_gl = 0; 492 uint8_t max_gl = 0;
493 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); 493 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl);
494 494
495 EXPECT_EQ(0, min_gl); 495 EXPECT_EQ(0, min_gl);
496 EXPECT_EQ(255, max_gl); 496 EXPECT_EQ(255, max_gl);
497 EXPECT_EQ(min_gl, SkColorGetA(result.getColor(0, 0))); 497 EXPECT_EQ(min_gl, SkColorGetA(result.getColor(0, 0)));
498 EXPECT_EQ(max_gl, SkColorGetA(result.getColor(299, 199))); 498 EXPECT_EQ(max_gl, SkColorGetA(result.getColor(299, 199)));
499 EXPECT_EQ(93U, SkColorGetA(result.getColor(150, 0))); 499 EXPECT_EQ(93U, SkColorGetA(result.getColor(150, 0)));
500 } 500 }
501 501
502 TEST_F(ColorAnalysisTest, ComputeProminentColor) {
503 struct {
504 LumaRange luma;
505 SaturationRange saturation;
506 } color_profiles[] = {{LumaRange::DARK, SaturationRange::VIBRANT},
507 {LumaRange::NORMAL, SaturationRange::VIBRANT},
508 {LumaRange::LIGHT, SaturationRange::VIBRANT},
509 {LumaRange::DARK, SaturationRange::MUTED},
510 {LumaRange::NORMAL, SaturationRange::MUTED},
511 {LumaRange::LIGHT, SaturationRange::MUTED}};
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].luma,
524 color_profiles[i].saturation));
525 }
526
527 // Add a green that could hit a couple values.
528 const SkColor kVibrantGreen = SkColorSetRGB(25, 200, 25);
529 canvas.FillRect(gfx::Rect(0, 1, 300, 1), kVibrantGreen);
530 bitmap = skia::ReadPixels(canvas.sk_canvas());
531 expectations[0] = kVibrantGreen;
532 expectations[1] = kVibrantGreen;
533 for (size_t i = 0; i < arraysize(color_profiles); ++i) {
534 EXPECT_EQ(expectations[i],
535 CalculateProminentColorOfBitmap(bitmap, color_profiles[i].luma,
536 color_profiles[i].saturation));
537 }
538
539 // Add a stripe of a dark, muted green (saturation .33, luma .29).
540 const SkColor kDarkGreen = SkColorSetRGB(50, 100, 50);
541 canvas.FillRect(gfx::Rect(0, 2, 300, 1), kDarkGreen);
542 bitmap = skia::ReadPixels(canvas.sk_canvas());
543 expectations[3] = kDarkGreen;
544 for (size_t i = 0; i < arraysize(color_profiles); ++i) {
545 EXPECT_EQ(expectations[i],
546 CalculateProminentColorOfBitmap(bitmap, color_profiles[i].luma,
547 color_profiles[i].saturation));
548 }
549
550 // Now draw a little bit of pure green. That should be closer to the goal for
551 // normal vibrant, but is out of range for other color profiles.
552 const SkColor kPureGreen = SkColorSetRGB(0, 255, 0);
553 canvas.FillRect(gfx::Rect(0, 3, 300, 1), kPureGreen);
554 bitmap = skia::ReadPixels(canvas.sk_canvas());
555 expectations[1] = kPureGreen;
556 for (size_t i = 0; i < arraysize(color_profiles); ++i) {
557 EXPECT_EQ(expectations[i],
558 CalculateProminentColorOfBitmap(bitmap, color_profiles[i].luma,
559 color_profiles[i].saturation));
560 }
561 }
562
502 } // namespace color_utils 563 } // namespace color_utils
OLDNEW
« no previous file with comments | « ui/gfx/color_analysis.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698