diff options
author | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-28 04:17:59 +0000 |
---|---|---|
committer | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-28 04:17:59 +0000 |
commit | a0669d0100750d2629de8fb552ec39512a752a69 (patch) | |
tree | 9b1286f7cd1f949c93d50730fd910933f9d30295 /skia/ext/skia_utils_unittest.cc | |
parent | 6dfed102065bda2e23541a5bf871b97258174fe3 (diff) | |
download | chromium_src-a0669d0100750d2629de8fb552ec39512a752a69.zip chromium_src-a0669d0100750d2629de8fb552ec39512a752a69.tar.gz chromium_src-a0669d0100750d2629de8fb552ec39512a752a69.tar.bz2 |
Add bitmap manipulation functions in advance of themes.
HSLToSkColor premultiplies its output, should this instead live in the ImageOperations bitmap munging code?
Review URL: http://codereview.chromium.org/79082
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14712 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/ext/skia_utils_unittest.cc')
-rw-r--r-- | skia/ext/skia_utils_unittest.cc | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/skia/ext/skia_utils_unittest.cc b/skia/ext/skia_utils_unittest.cc new file mode 100644 index 0000000..f7b00b1 --- /dev/null +++ b/skia/ext/skia_utils_unittest.cc @@ -0,0 +1,47 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <stdlib.h> + +#include "skia/ext/skia_utils.h" +#include "skia/include/SkColorPriv.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "SkBitmap.h" + +TEST(SkiaUtils, SkColorToHSLRed) { + SkColor red = SkColorSetARGB(255, 255, 0, 0); + SkScalar hsl[3]; + skia::SkColorToHSL(red, hsl); + EXPECT_EQ(hsl[0], 0); + EXPECT_EQ(hsl[1], 1); + EXPECT_EQ(hsl[2], 0.5); +} + +TEST(SkiaUtils, SkColorToHSLGrey) { + SkColor red = SkColorSetARGB(255, 128, 128, 128); + SkScalar hsl[3]; + skia::SkColorToHSL(red, hsl); + EXPECT_EQ(hsl[0], 0); + EXPECT_EQ(hsl[1], 0); + EXPECT_EQ(static_cast<int>(hsl[2] * 100), + static_cast<int>(0.5 * 100)); // Accurate to two decimal places. +} + +TEST(SkiaUtils, HSLToSkColorWithAlpha) { + // Premultiplied alpha - this is full red. + SkColor red = SkColorSetARGB(128, 128, 0, 0); + + SkScalar hsl[3] = { + SkDoubleToScalar(0), + SkDoubleToScalar(1), + SkDoubleToScalar(0.5), + }; + + SkColor result = skia::HSLToSKColor(128, hsl); + EXPECT_EQ(SkColorGetA(red), SkColorGetA(result)); + EXPECT_EQ(SkColorGetR(red), SkColorGetR(result)); + EXPECT_EQ(SkColorGetG(red), SkColorGetG(result)); + EXPECT_EQ(SkColorGetB(red), SkColorGetB(result)); +} + |