summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2011-01-21 19:44:51 +0000
committerVincent Sanders <vince@netsurf-browser.org>2011-01-21 19:44:51 +0000
commit2175aef41031b1e09f52136ae42eb81d2d579232 (patch)
tree1758e43ce57171a5c93e5f2f1b5be7e49084f7e0 /src
parentde706a2d638bd34c9685d24f659acc95edcdaa6f (diff)
downloadlibcss-2175aef41031b1e09f52136ae42eb81d2d579232.tar.gz
libcss-2175aef41031b1e09f52136ae42eb81d2d579232.tar.bz2
integer based HSL to RGB
svn path=/trunk/libcss/; revision=11432
Diffstat (limited to 'src')
-rw-r--r--src/parse/properties/utils.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/parse/properties/utils.c b/src/parse/properties/utils.c
index a036cdd..13a2082 100644
--- a/src/parse/properties/utils.c
+++ b/src/parse/properties/utils.c
@@ -314,6 +314,9 @@ static void HSL_to_RGB(int32_t hue, int32_t sat, int32_t lit, uint8_t *r, uint8_
}
#else
+
+#define ORGB(R, G, B) *r = ((R) * 255) / 100; *g = ((G) * 255) / 100; *b= ((B) * 255) / 100
+
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;
@@ -326,18 +329,21 @@ static void HSL_to_RGB(int32_t hue, int32_t sat, int32_t lit, uint8_t *r, uint8_
m2 = (((lit + sat) * 100) - lit * sat) / 100;
}
-
- m1 = lit * 2 - m2;
+ /* check m2 is in range */
+ if (m2 == 0) {
+ ORGB(0,0,0);
+ return;
+ }
+
+ m1 = (lit * 2) - m2;
sextant = (hue * 6) / 360;
- fract = (hue * 6) - (sextant * 360);
- vsf = (m2 * fract * ((m2 - m1) / m2)) / 100 ;
+ fract = (((hue * 6) - (sextant * 360)) * 100) /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;
@@ -347,8 +353,10 @@ static void HSL_to_RGB(int32_t hue, int32_t sat, int32_t lit, uint8_t *r, uint8_
case 5: ORGB(m2, m1, mid2); break;
}
-#undef ORGB
}
+
+#undef ORGB
+
#endif
/**