diff options
author | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-28 05:05:53 +0000 |
---|---|---|
committer | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-28 05:05:53 +0000 |
commit | 7b441021461106603e4b7769305b8fce7db17294 (patch) | |
tree | 4b182c22eb74adcdd4ede2315062b991946b1005 /skia/ext/skia_utils.cc | |
parent | a0669d0100750d2629de8fb552ec39512a752a69 (diff) | |
download | chromium_src-7b441021461106603e4b7769305b8fce7db17294.zip chromium_src-7b441021461106603e4b7769305b8fce7db17294.tar.gz chromium_src-7b441021461106603e4b7769305b8fce7db17294.tar.bz2 |
Reverting 14712 on behalf of glen.
TBR=glen
Review URL: http://codereview.chromium.org/100097
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14713 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/ext/skia_utils.cc')
-rw-r--r-- | skia/ext/skia_utils.cc | 100 |
1 files changed, 0 insertions, 100 deletions
diff --git a/skia/ext/skia_utils.cc b/skia/ext/skia_utils.cc index 1424957..80386e6 100644 --- a/skia/ext/skia_utils.cc +++ b/skia/ext/skia_utils.cc @@ -3,7 +3,6 @@ // found in the LICENSE file. #include "skia/ext/skia_utils.h" -#include "skia/include/SkColorPriv.h" #include "SkGradientShader.h" @@ -22,104 +21,5 @@ SkShader* CreateGradientShader(int start_point, grad_points, grad_colors, NULL, 2, SkShader::kRepeat_TileMode); } -// Helper function for HSLToSKColor. -static inline double calcHue(double temp1, double temp2, double hueVal) { - if (hueVal < 0.0) - hueVal++; - else if (hueVal > 1.0) - hueVal--; - - if (hueVal * 6.0 < 1.0) - return temp1 + (temp2 - temp1) * hueVal * 6.0; - if (hueVal * 2.0 < 1.0) - return temp2; - if (hueVal * 3.0 < 2.0) - return temp1 + (temp2 - temp1) * (2.0 / 3.0 - hueVal) * 6.0; - - return temp1; -} - -SkPMColor HSLToSKColor(U8CPU alpha, float hsl[3]) { - double hue = SkScalarToDouble(hsl[0]); - double saturation = SkScalarToDouble(hsl[1]); - double lightness = SkScalarToDouble(hsl[2]); - double scaleFactor = 256.0; - - // If there's no color, we don't care about hue and can do everything based - // on brightness. - if (!saturation) { - U8CPU lightness; - - if (hsl[2] < 0) - lightness = 0; - else if (hsl[2] >= SK_Scalar1) - lightness = 255; - else - lightness = SkScalarToFixed(hsl[2]) >> 8; - - unsigned greyValue = SkAlphaMul(lightness, alpha); - return SkColorSetARGB(alpha, greyValue, greyValue, greyValue); - } - - double temp2 = (lightness < 0.5) ? - lightness * (1.0 + saturation) : - lightness + saturation - (lightness * saturation); - double temp1 = 2.0 * lightness - temp2; - - double rh = calcHue(temp1, temp2, hue + 1.0 / 3.0); - double gh = calcHue(temp1, temp2, hue); - double bh = calcHue(temp1, temp2, hue - 1.0 / 3.0); - - return SkColorSetARGB(alpha, - SkAlphaMul(static_cast<int>(rh * scaleFactor), alpha), - SkAlphaMul(static_cast<int>(gh * scaleFactor), alpha), - SkAlphaMul(static_cast<int>(bh * scaleFactor), alpha)); -} - -void SkColorToHSL(SkPMColor c, float hsl[3]) { - double r = SkColorGetR(c) / 255.0; - double g = SkColorGetG(c) / 255.0; - double b = SkColorGetB(c) / 255.0; - - double h, s, l; - - double vmax = r > g ? r : g; - vmax = vmax > b ? vmax : b; - double vmin = r < g ? r : g; - vmin = vmin < b ? vmin : b; - double delta = vmax - vmin; - - l = (vmax + vmin) / 2; - - if (delta == 0) { - h = 0; - s = 0; - } else { - if (l < 0.5) - s = delta / (vmax + vmin); - else - s = delta / (2 - vmax - vmin); - - double dr = (((vmax - r) / 6.0) + (delta / 2.0)) / delta; - double dg = (((vmax - g) / 6.0) + (delta / 2.0)) / delta; - double db = (((vmax - b) / 6.0) + (delta / 2.0)) / delta; - - if (r == vmax) - h = db - dg; - else if (g == vmax) - h = (1.0 / 3.0) + dr - db; - else if (b == vmax) - h = (2.0 / 3.0) + dg - dr; - - if (h < 0) h += 1; - if (h > 1) h -= 1; - } - - hsl[0] = h; - hsl[1] = s; - hsl[2] = l; -} - - } // namespace skia |