1 ensureNS("jQuery.mobile.tizen.clrlib");
3 jQuery.extend( jQuery.mobile.tizen.clrlib,
5 nearestInt: function(val) {
6 var theFloor = Math.floor(val);
8 return (((val - theFloor) > 0.5) ? (theFloor + 1) : theFloor);
12 * Converts html color string to rgb array.
14 * Input: string clr_str, where
15 * clr_str is of the form "#aabbcc"
17 * Returns: [ r, g, b ], where
22 HTMLToRGB: function(clr_str) {
23 clr_str = (('#' == clr_str.charAt(0)) ? clr_str.substring(1) : clr_str);
26 clr_str.substring(0, 2),
27 clr_str.substring(2, 4),
28 clr_str.substring(4, 6)
30 return parseInt(val, 16) / 255.0;
35 * Converts rgb array to html color string.
37 * Input: [ r, g, b ], where
42 * Returns: string of the form "#aabbcc"
44 RGBToHTML: function(rgb) {
46 rgb.map(function(val) {
48 theFloor = Math.floor(ret);
50 ret = ((ret - theFloor > 0.5) ? (theFloor + 1) : theFloor);
51 ret = (((ret < 16) ? "0" : "") + (ret & 0xff).toString(16));
58 * Converts hsl to rgb.
60 * From http://130.113.54.154/~monger/hsl-rgb.html
62 * Input: [ h, s, l ], where
67 * Returns: [ r, g, b ], where
72 HSLToRGB: function(hsl) {
73 var h = hsl[0] / 360.0, s = hsl[1], l = hsl[2];
78 var temp2 = ((l < 0.5)
81 temp1 = 2.0 * l - temp2,
88 temp3.r = ((temp3.r < 0) ? (temp3.r + 1.0) : ((temp3.r > 1) ? (temp3.r - 1.0) : temp3.r));
89 temp3.g = ((temp3.g < 0) ? (temp3.g + 1.0) : ((temp3.g > 1) ? (temp3.g - 1.0) : temp3.g));
90 temp3.b = ((temp3.b < 0) ? (temp3.b + 1.0) : ((temp3.b > 1) ? (temp3.b - 1.0) : temp3.b));
93 (((6.0 * temp3.r) < 1) ? (temp1 + (temp2 - temp1) * 6.0 * temp3.r) :
94 (((2.0 * temp3.r) < 1) ? temp2 :
95 (((3.0 * temp3.r) < 2) ? (temp1 + (temp2 - temp1) * ((2.0 / 3.0) - temp3.r) * 6.0) :
97 (((6.0 * temp3.g) < 1) ? (temp1 + (temp2 - temp1) * 6.0 * temp3.g) :
98 (((2.0 * temp3.g) < 1) ? temp2 :
99 (((3.0 * temp3.g) < 2) ? (temp1 + (temp2 - temp1) * ((2.0 / 3.0) - temp3.g) * 6.0) :
101 (((6.0 * temp3.b) < 1) ? (temp1 + (temp2 - temp1) * 6.0 * temp3.b) :
102 (((2.0 * temp3.b) < 1) ? temp2 :
103 (((3.0 * temp3.b) < 2) ? (temp1 + (temp2 - temp1) * ((2.0 / 3.0) - temp3.b) * 6.0) :
110 * Converts hsv to rgb.
112 * Input: [ h, s, v ], where
117 * Returns: [ r, g, b ], where
122 HSVToRGB: function(hsv) {
123 return $.mobile.tizen.clrlib.HSLToRGB($.mobile.tizen.clrlib.HSVToHSL(hsv));
127 * Converts rgb to hsv.
129 * from http://coecsl.ece.illinois.edu/ge423/spring05/group8/FinalProject/HSV_writeup.pdf
131 * Input: [ r, g, b ], where
136 * Returns: [ h, s, v ], where
141 RGBToHSV: function(rgb) {
142 var min, max, delta, h, s, v, r = rgb[0], g = rgb[1], b = rgb[2];
144 min = Math.min(r, Math.min(g, b));
145 max = Math.max(r, Math.max(g, b));
152 if (delta > 0.00001) {
156 h = (g - b) / delta ;
159 h = 2 + (b - r) / delta ;
161 h = 4 + (r - g) / delta ;
173 * Converts hsv to hsl.
175 * Input: [ h, s, v ], where
180 * Returns: [ h, s, l ], where
185 HSVToHSL: function(hsv) {
187 delta = hsv[1] * max,
191 s_divisor = ((half_sum < 0.5) ? sum : (2 - max - min));
193 return [ hsv[0], ((0 == s_divisor) ? 0 : (delta / s_divisor)), half_sum ];
197 * Converts rgb to hsl
199 * Input: [ r, g, b ], where
204 * Returns: [ h, s, l ], where
209 RGBToHSL: function(rgb) {
210 return $.mobile.tizen.clrlib.HSVToHSL($.mobile.tizen.clrlib.RGBToHSV(rgb));