Commit b644bbc7 authored by calamity@chromium.org's avatar calamity@chromium.org

Put color util and color analysis tests into color_utils namespace.

This CL is a precursor for https://codereview.chromium.org/289283004/.

BUG=376613

Review URL: https://codereview.chromium.org/309773002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274343 0039d316-1c4b-4281-b951-d872f2087c98
parent da5886de
...@@ -12,9 +12,7 @@ ...@@ -12,9 +12,7 @@
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/rect.h" #include "ui/gfx/rect.h"
using color_utils::FindClosestColor; namespace color_utils {
namespace {
const unsigned char k1x1White[] = { const unsigned char k1x1White[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
...@@ -87,7 +85,7 @@ const unsigned char k1x3BlueRed[] = { ...@@ -87,7 +85,7 @@ const unsigned char k1x3BlueRed[] = {
0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
}; };
class MockKMeanImageSampler : public color_utils::KMeanImageSampler { class MockKMeanImageSampler : public KMeanImageSampler {
public: public:
MockKMeanImageSampler() : current_result_index_(0) { MockKMeanImageSampler() : current_result_index_(0) {
} }
...@@ -147,8 +145,6 @@ void Calculate8bitBitmapMinMax(const SkBitmap& bitmap, ...@@ -147,8 +145,6 @@ void Calculate8bitBitmapMinMax(const SkBitmap& bitmap,
} }
} }
} // namespace
class ColorAnalysisTest : public testing::Test { class ColorAnalysisTest : public testing::Test {
}; };
...@@ -162,8 +158,7 @@ TEST_F(ColorAnalysisTest, CalculatePNGKMeanAllWhite) { ...@@ -162,8 +158,7 @@ TEST_F(ColorAnalysisTest, CalculatePNGKMeanAllWhite) {
k1x1White, k1x1White,
k1x1White + sizeof(k1x1White) / sizeof(unsigned char)))); k1x1White + sizeof(k1x1White) / sizeof(unsigned char))));
SkColor color = SkColor color = CalculateKMeanColorOfPNG(png, 100, 600, &test_sampler);
color_utils::CalculateKMeanColorOfPNG(png, 100, 600, &test_sampler);
EXPECT_EQ(color, SK_ColorWHITE); EXPECT_EQ(color, SK_ColorWHITE);
} }
...@@ -180,8 +175,7 @@ TEST_F(ColorAnalysisTest, CalculatePNGKMeanIgnoreWhite) { ...@@ -180,8 +175,7 @@ TEST_F(ColorAnalysisTest, CalculatePNGKMeanIgnoreWhite) {
k1x3BlueWhite, k1x3BlueWhite,
k1x3BlueWhite + sizeof(k1x3BlueWhite) / sizeof(unsigned char)))); k1x3BlueWhite + sizeof(k1x3BlueWhite) / sizeof(unsigned char))));
SkColor color = SkColor color = CalculateKMeanColorOfPNG(png, 100, 600, &test_sampler);
color_utils::CalculateKMeanColorOfPNG(png, 100, 600, &test_sampler);
EXPECT_EQ(color, SkColorSetARGB(0xFF, 0x00, 0x00, 0xFF)); EXPECT_EQ(color, SkColorSetARGB(0xFF, 0x00, 0x00, 0xFF));
} }
...@@ -198,14 +192,13 @@ TEST_F(ColorAnalysisTest, CalculatePNGKMeanPickMostCommon) { ...@@ -198,14 +192,13 @@ TEST_F(ColorAnalysisTest, CalculatePNGKMeanPickMostCommon) {
k1x3BlueRed, k1x3BlueRed,
k1x3BlueRed + sizeof(k1x3BlueRed) / sizeof(unsigned char)))); k1x3BlueRed + sizeof(k1x3BlueRed) / sizeof(unsigned char))));
SkColor color = SkColor color = CalculateKMeanColorOfPNG(png, 100, 600, &test_sampler);
color_utils::CalculateKMeanColorOfPNG(png, 100, 600, &test_sampler);
EXPECT_EQ(color, SkColorSetARGB(0xFF, 0xFF, 0x00, 0x00)); EXPECT_EQ(color, SkColorSetARGB(0xFF, 0xFF, 0x00, 0x00));
} }
TEST_F(ColorAnalysisTest, GridSampler) { TEST_F(ColorAnalysisTest, GridSampler) {
color_utils::GridSampler sampler; GridSampler sampler;
const int kWidth = 16; const int kWidth = 16;
const int kHeight = 16; const int kHeight = 16;
// Sample starts at 1,1. // Sample starts at 1,1.
...@@ -254,7 +247,7 @@ TEST_F(ColorAnalysisTest, CalculateKMeanColorOfBitmap) { ...@@ -254,7 +247,7 @@ TEST_F(ColorAnalysisTest, CalculateKMeanColorOfBitmap) {
bitmap.allocPixels(); bitmap.allocPixels();
bitmap.eraseARGB(255, 100, 150, 200); bitmap.eraseARGB(255, 100, 150, 200);
SkColor color = color_utils::CalculateKMeanColorOfBitmap(bitmap); SkColor color = CalculateKMeanColorOfBitmap(bitmap);
EXPECT_EQ(255u, SkColorGetA(color)); EXPECT_EQ(255u, SkColorGetA(color));
// Color values are not exactly equal due to reversal of premultiplied alpha. // Color values are not exactly equal due to reversal of premultiplied alpha.
EXPECT_TRUE(ChannelApproximatelyEqual(100, SkColorGetR(color))); EXPECT_TRUE(ChannelApproximatelyEqual(100, SkColorGetR(color)));
...@@ -263,7 +256,7 @@ TEST_F(ColorAnalysisTest, CalculateKMeanColorOfBitmap) { ...@@ -263,7 +256,7 @@ TEST_F(ColorAnalysisTest, CalculateKMeanColorOfBitmap) {
// Test a bitmap with an alpha channel. // Test a bitmap with an alpha channel.
bitmap.eraseARGB(128, 100, 150, 200); bitmap.eraseARGB(128, 100, 150, 200);
color = color_utils::CalculateKMeanColorOfBitmap(bitmap); color = CalculateKMeanColorOfBitmap(bitmap);
// Alpha channel should be ignored for dominant color calculation. // Alpha channel should be ignored for dominant color calculation.
EXPECT_EQ(255u, SkColorGetA(color)); EXPECT_EQ(255u, SkColorGetA(color));
...@@ -276,11 +269,10 @@ TEST_F(ColorAnalysisTest, ComputeColorCovarianceTrivial) { ...@@ -276,11 +269,10 @@ TEST_F(ColorAnalysisTest, ComputeColorCovarianceTrivial) {
SkBitmap bitmap; SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 200); bitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 200);
EXPECT_EQ(gfx::Matrix3F::Zeros(), EXPECT_EQ(gfx::Matrix3F::Zeros(), ComputeColorCovariance(bitmap));
color_utils::ComputeColorCovariance(bitmap));
bitmap.allocPixels(); bitmap.allocPixels();
bitmap.eraseARGB(255, 50, 150, 200); bitmap.eraseARGB(255, 50, 150, 200);
gfx::Matrix3F covariance = color_utils::ComputeColorCovariance(bitmap); gfx::Matrix3F covariance = ComputeColorCovariance(bitmap);
// The answer should be all zeros. // The answer should be all zeros.
EXPECT_TRUE(covariance == gfx::Matrix3F::Zeros()); EXPECT_TRUE(covariance == gfx::Matrix3F::Zeros());
} }
...@@ -297,7 +289,7 @@ TEST_F(ColorAnalysisTest, ComputeColorCovarianceWithCanvas) { ...@@ -297,7 +289,7 @@ TEST_F(ColorAnalysisTest, ComputeColorCovarianceWithCanvas) {
SkBitmap bitmap = SkBitmap bitmap =
skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false);
gfx::Matrix3F covariance = color_utils::ComputeColorCovariance(bitmap); gfx::Matrix3F covariance = ComputeColorCovariance(bitmap);
gfx::Matrix3F expected_covariance = gfx::Matrix3F::Zeros(); gfx::Matrix3F expected_covariance = gfx::Matrix3F::Zeros();
expected_covariance.set(2400, 400, -1600, expected_covariance.set(2400, 400, -1600,
...@@ -319,8 +311,7 @@ TEST_F(ColorAnalysisTest, ApplyColorReductionSingleColor) { ...@@ -319,8 +311,7 @@ TEST_F(ColorAnalysisTest, ApplyColorReductionSingleColor) {
gfx::Vector3dF transform(1.0f, .5f, 0.1f); gfx::Vector3dF transform(1.0f, .5f, 0.1f);
// This transform, if not scaled, should result in GL=145. // This transform, if not scaled, should result in GL=145.
EXPECT_TRUE(color_utils::ApplyColorReduction( EXPECT_TRUE(ApplyColorReduction(source, transform, false, &result));
source, transform, false, &result));
uint8_t min_gl = 0; uint8_t min_gl = 0;
uint8_t max_gl = 0; uint8_t max_gl = 0;
...@@ -329,24 +320,21 @@ TEST_F(ColorAnalysisTest, ApplyColorReductionSingleColor) { ...@@ -329,24 +320,21 @@ TEST_F(ColorAnalysisTest, ApplyColorReductionSingleColor) {
EXPECT_EQ(145, max_gl); EXPECT_EQ(145, max_gl);
// Now scan requesting rescale. Expect all 0. // Now scan requesting rescale. Expect all 0.
EXPECT_TRUE(color_utils::ApplyColorReduction( EXPECT_TRUE(ApplyColorReduction(source, transform, true, &result));
source, transform, true, &result));
Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); Calculate8bitBitmapMinMax(result, &min_gl, &max_gl);
EXPECT_EQ(0, min_gl); EXPECT_EQ(0, min_gl);
EXPECT_EQ(0, max_gl); EXPECT_EQ(0, max_gl);
// Test cliping to upper limit. // Test cliping to upper limit.
transform.set_z(1.1f); transform.set_z(1.1f);
EXPECT_TRUE(color_utils::ApplyColorReduction( EXPECT_TRUE(ApplyColorReduction(source, transform, false, &result));
source, transform, false, &result));
Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); Calculate8bitBitmapMinMax(result, &min_gl, &max_gl);
EXPECT_EQ(0xFF, min_gl); EXPECT_EQ(0xFF, min_gl);
EXPECT_EQ(0xFF, max_gl); EXPECT_EQ(0xFF, max_gl);
// Test cliping to upper limit. // Test cliping to upper limit.
transform.Scale(-1.0f); transform.Scale(-1.0f);
EXPECT_TRUE(color_utils::ApplyColorReduction( EXPECT_TRUE(ApplyColorReduction(source, transform, false, &result));
source, transform, false, &result));
Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); Calculate8bitBitmapMinMax(result, &min_gl, &max_gl);
EXPECT_EQ(0x0, min_gl); EXPECT_EQ(0x0, min_gl);
EXPECT_EQ(0x0, max_gl); EXPECT_EQ(0x0, max_gl);
...@@ -367,8 +355,7 @@ TEST_F(ColorAnalysisTest, ApplyColorReductionBlackAndWhite) { ...@@ -367,8 +355,7 @@ TEST_F(ColorAnalysisTest, ApplyColorReductionBlackAndWhite) {
result.allocPixels(); result.allocPixels();
gfx::Vector3dF transform(1.0f, 0.5f, 0.1f); gfx::Vector3dF transform(1.0f, 0.5f, 0.1f);
EXPECT_TRUE(color_utils::ApplyColorReduction( EXPECT_TRUE(ApplyColorReduction(source, transform, true, &result));
source, transform, true, &result));
uint8_t min_gl = 0; uint8_t min_gl = 0;
uint8_t max_gl = 0; uint8_t max_gl = 0;
Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); Calculate8bitBitmapMinMax(result, &min_gl, &max_gl);
...@@ -380,8 +367,7 @@ TEST_F(ColorAnalysisTest, ApplyColorReductionBlackAndWhite) { ...@@ -380,8 +367,7 @@ TEST_F(ColorAnalysisTest, ApplyColorReductionBlackAndWhite) {
// Reverse test. // Reverse test.
transform.Scale(-1.0f); transform.Scale(-1.0f);
EXPECT_TRUE(color_utils::ApplyColorReduction( EXPECT_TRUE(ApplyColorReduction(source, transform, true, &result));
source, transform, true, &result));
min_gl = 0; min_gl = 0;
max_gl = 0; max_gl = 0;
Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); Calculate8bitBitmapMinMax(result, &min_gl, &max_gl);
...@@ -408,8 +394,7 @@ TEST_F(ColorAnalysisTest, ApplyColorReductionMultiColor) { ...@@ -408,8 +394,7 @@ TEST_F(ColorAnalysisTest, ApplyColorReductionMultiColor) {
result.allocPixels(); result.allocPixels();
gfx::Vector3dF transform(1.0f, 0.5f, 0.1f); gfx::Vector3dF transform(1.0f, 0.5f, 0.1f);
EXPECT_TRUE(color_utils::ApplyColorReduction( EXPECT_TRUE(ApplyColorReduction(source, transform, false, &result));
source, transform, false, &result));
uint8_t min_gl = 0; uint8_t min_gl = 0;
uint8_t max_gl = 0; uint8_t max_gl = 0;
Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); Calculate8bitBitmapMinMax(result, &min_gl, &max_gl);
...@@ -419,8 +404,7 @@ TEST_F(ColorAnalysisTest, ApplyColorReductionMultiColor) { ...@@ -419,8 +404,7 @@ TEST_F(ColorAnalysisTest, ApplyColorReductionMultiColor) {
EXPECT_EQ(max_gl, SkColorGetA(result.getColor(150, 0))); EXPECT_EQ(max_gl, SkColorGetA(result.getColor(150, 0)));
EXPECT_EQ(100U, SkColorGetA(result.getColor(0, 0))); EXPECT_EQ(100U, SkColorGetA(result.getColor(0, 0)));
EXPECT_TRUE(color_utils::ApplyColorReduction( EXPECT_TRUE(ApplyColorReduction(source, transform, true, &result));
source, transform, true, &result));
Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); Calculate8bitBitmapMinMax(result, &min_gl, &max_gl);
EXPECT_EQ(0, min_gl); EXPECT_EQ(0, min_gl);
EXPECT_EQ(255, max_gl); EXPECT_EQ(255, max_gl);
...@@ -439,7 +423,7 @@ TEST_F(ColorAnalysisTest, ComputePrincipalComponentImageNotComputable) { ...@@ -439,7 +423,7 @@ TEST_F(ColorAnalysisTest, ComputePrincipalComponentImageNotComputable) {
source.eraseARGB(255, 50, 150, 200); source.eraseARGB(255, 50, 150, 200);
// This computation should fail since all colors always vary together. // This computation should fail since all colors always vary together.
EXPECT_FALSE(color_utils::ComputePrincipalComponentImage(source, &result)); EXPECT_FALSE(ComputePrincipalComponentImage(source, &result));
} }
TEST_F(ColorAnalysisTest, ComputePrincipalComponentImage) { TEST_F(ColorAnalysisTest, ComputePrincipalComponentImage) {
...@@ -456,7 +440,7 @@ TEST_F(ColorAnalysisTest, ComputePrincipalComponentImage) { ...@@ -456,7 +440,7 @@ TEST_F(ColorAnalysisTest, ComputePrincipalComponentImage) {
result.allocPixels(); result.allocPixels();
// This computation should fail since all colors always vary together. // This computation should fail since all colors always vary together.
EXPECT_TRUE(color_utils::ComputePrincipalComponentImage(source, &result)); EXPECT_TRUE(ComputePrincipalComponentImage(source, &result));
uint8_t min_gl = 0; uint8_t min_gl = 0;
uint8_t max_gl = 0; uint8_t max_gl = 0;
...@@ -468,3 +452,5 @@ TEST_F(ColorAnalysisTest, ComputePrincipalComponentImage) { ...@@ -468,3 +452,5 @@ TEST_F(ColorAnalysisTest, ComputePrincipalComponentImage) {
EXPECT_EQ(max_gl, SkColorGetA(result.getColor(299, 199))); EXPECT_EQ(max_gl, SkColorGetA(result.getColor(299, 199)));
EXPECT_EQ(93U, SkColorGetA(result.getColor(150, 0))); EXPECT_EQ(93U, SkColorGetA(result.getColor(150, 0)));
} }
} // namespace color_utils
...@@ -9,17 +9,19 @@ ...@@ -9,17 +9,19 @@
#include "third_party/skia/include/core/SkColorPriv.h" #include "third_party/skia/include/core/SkColorPriv.h"
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
namespace color_utils {
TEST(ColorUtils, SkColorToHSLRed) { TEST(ColorUtils, SkColorToHSLRed) {
color_utils::HSL hsl = { 0, 0, 0 }; HSL hsl = {0, 0, 0};
color_utils::SkColorToHSL(SK_ColorRED, &hsl); SkColorToHSL(SK_ColorRED, &hsl);
EXPECT_DOUBLE_EQ(hsl.h, 0); EXPECT_DOUBLE_EQ(hsl.h, 0);
EXPECT_DOUBLE_EQ(hsl.s, 1); EXPECT_DOUBLE_EQ(hsl.s, 1);
EXPECT_DOUBLE_EQ(hsl.l, 0.5); EXPECT_DOUBLE_EQ(hsl.l, 0.5);
} }
TEST(ColorUtils, SkColorToHSLGrey) { TEST(ColorUtils, SkColorToHSLGrey) {
color_utils::HSL hsl = { 0, 0, 0 }; HSL hsl = {0, 0, 0};
color_utils::SkColorToHSL(SkColorSetARGB(255, 128, 128, 128), &hsl); SkColorToHSL(SkColorSetARGB(255, 128, 128, 128), &hsl);
EXPECT_DOUBLE_EQ(hsl.h, 0); EXPECT_DOUBLE_EQ(hsl.h, 0);
EXPECT_DOUBLE_EQ(hsl.s, 0); EXPECT_DOUBLE_EQ(hsl.s, 0);
EXPECT_EQ(static_cast<int>(hsl.l * 100), EXPECT_EQ(static_cast<int>(hsl.l * 100),
...@@ -28,8 +30,8 @@ TEST(ColorUtils, SkColorToHSLGrey) { ...@@ -28,8 +30,8 @@ TEST(ColorUtils, SkColorToHSLGrey) {
TEST(ColorUtils, HSLToSkColorWithAlpha) { TEST(ColorUtils, HSLToSkColorWithAlpha) {
SkColor red = SkColorSetARGB(128, 255, 0, 0); SkColor red = SkColorSetARGB(128, 255, 0, 0);
color_utils::HSL hsl = { 0, 1, 0.5 }; HSL hsl = {0, 1, 0.5};
SkColor result = color_utils::HSLToSkColor(hsl, 128); SkColor result = HSLToSkColor(hsl, 128);
EXPECT_EQ(SkColorGetA(red), SkColorGetA(result)); EXPECT_EQ(SkColorGetA(red), SkColorGetA(result));
EXPECT_EQ(SkColorGetR(red), SkColorGetR(result)); EXPECT_EQ(SkColorGetR(red), SkColorGetR(result));
EXPECT_EQ(SkColorGetG(red), SkColorGetG(result)); EXPECT_EQ(SkColorGetG(red), SkColorGetG(result));
...@@ -43,9 +45,9 @@ TEST(ColorUtils, RGBtoHSLRoundTrip) { ...@@ -43,9 +45,9 @@ TEST(ColorUtils, RGBtoHSLRoundTrip) {
for (int g = 0; g < 10; ++g) { for (int g = 0; g < 10; ++g) {
for (int b = 0; b < 10; ++b) { for (int b = 0; b < 10; ++b) {
SkColor rgb = SkColorSetARGB(255, r, g, b); SkColor rgb = SkColorSetARGB(255, r, g, b);
color_utils::HSL hsl = { 0, 0, 0 }; HSL hsl = {0, 0, 0};
color_utils::SkColorToHSL(rgb, &hsl); SkColorToHSL(rgb, &hsl);
SkColor out = color_utils::HSLToSkColor(hsl, 255); SkColor out = HSLToSkColor(hsl, 255);
EXPECT_EQ(SkColorGetR(out), SkColorGetR(rgb)); EXPECT_EQ(SkColorGetR(out), SkColorGetR(rgb));
EXPECT_EQ(SkColorGetG(out), SkColorGetG(rgb)); EXPECT_EQ(SkColorGetG(out), SkColorGetG(rgb));
EXPECT_EQ(SkColorGetB(out), SkColorGetB(rgb)); EXPECT_EQ(SkColorGetB(out), SkColorGetB(rgb));
...@@ -56,9 +58,9 @@ TEST(ColorUtils, RGBtoHSLRoundTrip) { ...@@ -56,9 +58,9 @@ TEST(ColorUtils, RGBtoHSLRoundTrip) {
for (int g = 240; g < 256; ++g) { for (int g = 240; g < 256; ++g) {
for (int b = 240; b < 256; ++b) { for (int b = 240; b < 256; ++b) {
SkColor rgb = SkColorSetARGB(255, r, g, b); SkColor rgb = SkColorSetARGB(255, r, g, b);
color_utils::HSL hsl = { 0, 0, 0 }; HSL hsl = {0, 0, 0};
color_utils::SkColorToHSL(rgb, &hsl); SkColorToHSL(rgb, &hsl);
SkColor out = color_utils::HSLToSkColor(hsl, 255); SkColor out = HSLToSkColor(hsl, 255);
EXPECT_EQ(SkColorGetR(out), SkColorGetR(rgb)); EXPECT_EQ(SkColorGetR(out), SkColorGetR(rgb));
EXPECT_EQ(SkColorGetG(out), SkColorGetG(rgb)); EXPECT_EQ(SkColorGetG(out), SkColorGetG(rgb));
EXPECT_EQ(SkColorGetB(out), SkColorGetB(rgb)); EXPECT_EQ(SkColorGetB(out), SkColorGetB(rgb));
...@@ -71,8 +73,8 @@ TEST(ColorUtils, ColorToHSLRegisterSpill) { ...@@ -71,8 +73,8 @@ TEST(ColorUtils, ColorToHSLRegisterSpill) {
// In a opt build on Linux, this was causing a register spill on my laptop // In a opt build on Linux, this was causing a register spill on my laptop
// (Pentium M) when converting from SkColor to HSL. // (Pentium M) when converting from SkColor to HSL.
SkColor input = SkColorSetARGB(255, 206, 154, 89); SkColor input = SkColorSetARGB(255, 206, 154, 89);
color_utils::HSL hsl = { -1, -1, -1 }; HSL hsl = {-1, -1, -1};
SkColor result = color_utils::HSLShift(input, hsl); SkColor result = HSLShift(input, hsl);
// |result| should be the same as |input| since we passed in a value meaning // |result| should be the same as |input| since we passed in a value meaning
// no color shift. // no color shift.
EXPECT_EQ(SkColorGetA(input), SkColorGetA(result)); EXPECT_EQ(SkColorGetA(input), SkColorGetA(result));
...@@ -85,16 +87,16 @@ TEST(ColorUtils, AlphaBlend) { ...@@ -85,16 +87,16 @@ TEST(ColorUtils, AlphaBlend) {
SkColor fore = SkColorSetARGB(255, 200, 200, 200); SkColor fore = SkColorSetARGB(255, 200, 200, 200);
SkColor back = SkColorSetARGB(255, 100, 100, 100); SkColor back = SkColorSetARGB(255, 100, 100, 100);
EXPECT_TRUE(color_utils::AlphaBlend(fore, back, 255) == EXPECT_TRUE(AlphaBlend(fore, back, 255) == fore);
fore); EXPECT_TRUE(AlphaBlend(fore, back, 0) == back);
EXPECT_TRUE(color_utils::AlphaBlend(fore, back, 0) ==
back);
// One is fully transparent, result is partially transparent. // One is fully transparent, result is partially transparent.
back = SkColorSetA(back, 0); back = SkColorSetA(back, 0);
EXPECT_EQ(136U, SkColorGetA(color_utils::AlphaBlend(fore, back, 136))); EXPECT_EQ(136U, SkColorGetA(AlphaBlend(fore, back, 136)));
// Both are fully transparent, result is fully transparent. // Both are fully transparent, result is fully transparent.
fore = SkColorSetA(fore, 0); fore = SkColorSetA(fore, 0);
EXPECT_EQ(0U, SkColorGetA(color_utils::AlphaBlend(fore, back, 255))); EXPECT_EQ(0U, SkColorGetA(AlphaBlend(fore, back, 255)));
} }
} // namespace color_utils
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment