1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "gfx/color_utils.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/skia/include/core/SkBitmap.h"
10 #include "third_party/skia/include/core/SkColorPriv.h"
12 TEST(ColorUtils
, SkColorToHSLRed
) {
13 color_utils::HSL hsl
= { 0, 0, 0 };
14 color_utils::SkColorToHSL(SK_ColorRED
, &hsl
);
17 EXPECT_EQ(hsl
.l
, 0.5);
20 TEST(ColorUtils
, SkColorToHSLGrey
) {
21 color_utils::HSL hsl
= { 0, 0, 0 };
22 color_utils::SkColorToHSL(SkColorSetARGB(255, 128, 128, 128), &hsl
);
25 EXPECT_EQ(static_cast<int>(hsl
.l
* 100),
26 static_cast<int>(0.5 * 100)); // Accurate to two decimal places.
29 TEST(ColorUtils
, HSLToSkColorWithAlpha
) {
30 SkColor red
= SkColorSetARGB(128, 255, 0, 0);
31 color_utils::HSL hsl
= { 0, 1, 0.5 };
32 SkColor result
= color_utils::HSLToSkColor(hsl
, 128);
33 EXPECT_EQ(SkColorGetA(red
), SkColorGetA(result
));
34 EXPECT_EQ(SkColorGetR(red
), SkColorGetR(result
));
35 EXPECT_EQ(SkColorGetG(red
), SkColorGetG(result
));
36 EXPECT_EQ(SkColorGetB(red
), SkColorGetB(result
));
39 TEST(ColorUtils
, ColorToHSLRegisterSpill
) {
40 // In a opt build on Linux, this was causing a register spill on my laptop
41 // (Pentium M) when converting from SkColor to HSL.
42 SkColor input
= SkColorSetARGB(255, 206, 154, 89);
43 color_utils::HSL hsl
= { -1, -1, -1 };
44 SkColor result
= color_utils::HSLShift(input
, hsl
);
45 EXPECT_EQ(255U, SkColorGetA(result
));
46 EXPECT_EQ(206U, SkColorGetR(result
));
47 EXPECT_EQ(153U, SkColorGetG(result
));
48 EXPECT_EQ(88U, SkColorGetB(result
));