summaryrefslogtreecommitdiff
path: root/src/parse
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2011-01-21 18:17:53 +0000
committerVincent Sanders <vince@netsurf-browser.org>2011-01-21 18:17:53 +0000
commitde706a2d638bd34c9685d24f659acc95edcdaa6f (patch)
tree5f9884182749f692fc851373cb0a3929a6f4ea2f /src/parse
parent0fdc32cccf29bc650d48f00d4370dc34c4d4b650 (diff)
downloadlibcss-de706a2d638bd34c9685d24f659acc95edcdaa6f.tar.gz
libcss-de706a2d638bd34c9685d24f659acc95edcdaa6f.tar.bz2
mostly working integer implementation
svn path=/trunk/libcss/; revision=11431
Diffstat (limited to 'src/parse')
-rw-r--r--src/parse/properties/utils.c56
1 files changed, 49 insertions, 7 deletions
diff --git a/src/parse/properties/utils.c b/src/parse/properties/utils.c
index aba3fc2..a036cdd 100644
--- a/src/parse/properties/utils.c
+++ b/src/parse/properties/utils.c
@@ -248,7 +248,7 @@ css__parse_border_side_cleanup:
return error;
}
-
+#if 1
/* CSS standard definition
HOW TO RETURN hsl.to.rgb(h, s, l):
@@ -271,16 +271,20 @@ css__parse_border_side_cleanup:
*/
static inline int hue_to_RGB(float m1, float m2, int h)
{
+ float r;
+
h = (h < 0) ? h + 360 : h;
h = (h > 360) ? h - 360 : h;
if (h < 60)
- return (m1 + (m2 - m1) * (h / 60.0)) * 255.5;
- if (h < 180)
- return (m2 * 255.5);
- if (h < 240)
- return (m1 + (m2 - m1) * ((240 - h) / 60.0)) * 255.5;
- return m1 * 255.5;
+ r = m1 + (m2 - m1) * (h / 60.0);
+ else if (h < 180)
+ r = m2;
+ else if (h < 240)
+ r = m1 + (m2 - m1) * ((240 - h) / 60.0);
+ else r = m1;
+
+ return r * 255.5;
}
/**
@@ -309,6 +313,44 @@ static void HSL_to_RGB(int32_t hue, int32_t sat, int32_t lit, uint8_t *r, uint8_
*b = hue_to_RGB(m1, m2, hue - 120);
}
+#else
+static void HSL_to_RGB(int32_t hue, int32_t sat, int32_t lit, uint8_t *r, uint8_t *g, uint8_t *b)
+{
+ int m1,m2;
+ int sextant; /* which of the six sextants the hue is in */
+ int fract, vsf, mid1, mid2;
+
+ if (lit <= 50) {
+ m2 = (lit * (sat + 100)) / 100 ;
+ } else {
+ m2 = (((lit + sat) * 100) - lit * sat) / 100;
+ }
+
+
+ m1 = lit * 2 - m2;
+
+ sextant = (hue * 6) / 360;
+
+ fract = (hue * 6) - (sextant * 360);
+ vsf = (m2 * fract * ((m2 - m1) / m2)) / 100 ;
+ mid1 = m1 + vsf;
+ mid2 = m2 - vsf;
+
+#define ORGB(R, G, B) *r = ((R) * 255) / 100; *g = ((G) * 255) / 100; *b= ((B) * 255) / 100
+
+ switch (sextant) {
+ case 0: ORGB(m2, mid1, m1); break;
+ case 1: ORGB(mid2, m2, m1); break;
+ case 2: ORGB(m1, m2, mid1); break;
+ case 3: ORGB(m1, mid2, m2); break;
+ case 4: ORGB(mid1, m1, m2); break;
+ case 5: ORGB(m2, m1, mid2); break;
+ }
+
+#undef ORGB
+}
+#endif
+
/**
* Parse a colour specifier
*