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

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

Issue 2716213002: ui: Fix cc/paint skia type mismatches (Closed)
Patch Set: 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
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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 {LumaRange::NORMAL, SaturationRange::VIBRANT}, 507 {LumaRange::NORMAL, SaturationRange::VIBRANT},
508 {LumaRange::LIGHT, SaturationRange::VIBRANT}, 508 {LumaRange::LIGHT, SaturationRange::VIBRANT},
509 {LumaRange::DARK, SaturationRange::MUTED}, 509 {LumaRange::DARK, SaturationRange::MUTED},
510 {LumaRange::NORMAL, SaturationRange::MUTED}, 510 {LumaRange::NORMAL, SaturationRange::MUTED},
511 {LumaRange::LIGHT, SaturationRange::MUTED}}; 511 {LumaRange::LIGHT, SaturationRange::MUTED}};
512 512
513 // A totally dark gray image, which yields no prominent color as it's too 513 // A totally dark gray image, which yields no prominent color as it's too
514 // close to black. 514 // close to black.
515 gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, true); 515 gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, true);
516 canvas.FillRect(gfx::Rect(0, 0, 300, 200), SkColorSetRGB(10, 10, 10)); 516 canvas.FillRect(gfx::Rect(0, 0, 300, 200), SkColorSetRGB(10, 10, 10));
517 SkBitmap bitmap = skia::ReadPixels(canvas.sk_canvas()); 517 SkBitmap bitmap = canvas.ToBitmap();
518 518
519 // All expectations start at SK_ColorTRANSPARENT (i.e. 0). 519 // All expectations start at SK_ColorTRANSPARENT (i.e. 0).
520 SkColor expectations[arraysize(color_profiles)] = {}; 520 SkColor expectations[arraysize(color_profiles)] = {};
521 for (size_t i = 0; i < arraysize(color_profiles); ++i) { 521 for (size_t i = 0; i < arraysize(color_profiles); ++i) {
522 EXPECT_EQ(expectations[i], 522 EXPECT_EQ(expectations[i],
523 CalculateProminentColorOfBitmap(bitmap, color_profiles[i].luma, 523 CalculateProminentColorOfBitmap(bitmap, color_profiles[i].luma,
524 color_profiles[i].saturation)); 524 color_profiles[i].saturation));
525 } 525 }
526 526
527 // Add a green that could hit a couple values. 527 // Add a green that could hit a couple values.
528 const SkColor kVibrantGreen = SkColorSetRGB(25, 200, 25); 528 const SkColor kVibrantGreen = SkColorSetRGB(25, 200, 25);
529 canvas.FillRect(gfx::Rect(0, 1, 300, 1), kVibrantGreen); 529 canvas.FillRect(gfx::Rect(0, 1, 300, 1), kVibrantGreen);
530 bitmap = skia::ReadPixels(canvas.sk_canvas()); 530 bitmap = canvas.ToBitmap();
531 expectations[0] = kVibrantGreen; 531 expectations[0] = kVibrantGreen;
532 expectations[1] = kVibrantGreen; 532 expectations[1] = kVibrantGreen;
533 for (size_t i = 0; i < arraysize(color_profiles); ++i) { 533 for (size_t i = 0; i < arraysize(color_profiles); ++i) {
534 EXPECT_EQ(expectations[i], 534 EXPECT_EQ(expectations[i],
535 CalculateProminentColorOfBitmap(bitmap, color_profiles[i].luma, 535 CalculateProminentColorOfBitmap(bitmap, color_profiles[i].luma,
536 color_profiles[i].saturation)); 536 color_profiles[i].saturation));
537 } 537 }
538 538
539 // Add a stripe of a dark, muted green (saturation .33, luma .29). 539 // Add a stripe of a dark, muted green (saturation .33, luma .29).
540 const SkColor kDarkGreen = SkColorSetRGB(50, 100, 50); 540 const SkColor kDarkGreen = SkColorSetRGB(50, 100, 50);
541 canvas.FillRect(gfx::Rect(0, 2, 300, 1), kDarkGreen); 541 canvas.FillRect(gfx::Rect(0, 2, 300, 1), kDarkGreen);
542 bitmap = skia::ReadPixels(canvas.sk_canvas()); 542 bitmap = canvas.ToBitmap();
543 expectations[3] = kDarkGreen; 543 expectations[3] = kDarkGreen;
544 for (size_t i = 0; i < arraysize(color_profiles); ++i) { 544 for (size_t i = 0; i < arraysize(color_profiles); ++i) {
545 EXPECT_EQ(expectations[i], 545 EXPECT_EQ(expectations[i],
546 CalculateProminentColorOfBitmap(bitmap, color_profiles[i].luma, 546 CalculateProminentColorOfBitmap(bitmap, color_profiles[i].luma,
547 color_profiles[i].saturation)); 547 color_profiles[i].saturation));
548 } 548 }
549 549
550 // Now draw a little bit of pure green. That should be closer to the goal for 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. 551 // normal vibrant, but is out of range for other color profiles.
552 const SkColor kPureGreen = SkColorSetRGB(0, 255, 0); 552 const SkColor kPureGreen = SkColorSetRGB(0, 255, 0);
553 canvas.FillRect(gfx::Rect(0, 3, 300, 1), kPureGreen); 553 canvas.FillRect(gfx::Rect(0, 3, 300, 1), kPureGreen);
554 bitmap = skia::ReadPixels(canvas.sk_canvas()); 554 bitmap = canvas.ToBitmap();
555 expectations[1] = kPureGreen; 555 expectations[1] = kPureGreen;
556 for (size_t i = 0; i < arraysize(color_profiles); ++i) { 556 for (size_t i = 0; i < arraysize(color_profiles); ++i) {
557 EXPECT_EQ(expectations[i], 557 EXPECT_EQ(expectations[i],
558 CalculateProminentColorOfBitmap(bitmap, color_profiles[i].luma, 558 CalculateProminentColorOfBitmap(bitmap, color_profiles[i].luma,
559 color_profiles[i].saturation)); 559 color_profiles[i].saturation));
560 } 560 }
561 } 561 }
562 562
563 } // namespace color_utils 563 } // namespace color_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698