2 ensureNS("jQuery.mobile.tizen.clrlib");
4 jQuery.extend( jQuery.mobile.tizen.clrlib,
6 nearestInt: function(val) {
7 var theFloor = Math.floor(val);
9 return (((val - theFloor) > 0.5) ? (theFloor + 1) : theFloor);
13 * Converts html color string to rgb array.
15 * Input: string clr_str, where
16 * clr_str is of the form "#aabbcc"
18 * Returns: [ r, g, b ], where
23 HTMLToRGB: function(clr_str) {
24 clr_str = (('#' == clr_str.charAt(0)) ? clr_str.substring(1) : clr_str);
27 clr_str.substring(0, 2),
28 clr_str.substring(2, 4),
29 clr_str.substring(4, 6)
31 return parseInt(val, 16) / 255.0;
36 * Converts rgb array to html color string.
38 * Input: [ r, g, b ], where
43 * Returns: string of the form "#aabbcc"
45 RGBToHTML: function(rgb) {
47 rgb.map(function(val) {
49 theFloor = Math.floor(ret);
51 ret = ((ret - theFloor > 0.5) ? (theFloor + 1) : theFloor);
52 ret = (((ret < 16) ? "0" : "") + (ret & 0xff).toString(16));
59 * Converts hsl to rgb.
61 * From http://130.113.54.154/~monger/hsl-rgb.html
63 * Input: [ h, s, l ], where
68 * Returns: [ r, g, b ], where
73 HSLToRGB: function(hsl) {
74 var h = hsl[0] / 360.0, s = hsl[1], l = hsl[2];
79 var temp2 = ((l < 0.5)
82 temp1 = 2.0 * l - temp2,
89 temp3.r = ((temp3.r < 0) ? (temp3.r + 1.0) : ((temp3.r > 1) ? (temp3.r - 1.0) : temp3.r));
90 temp3.g = ((temp3.g < 0) ? (temp3.g + 1.0) : ((temp3.g > 1) ? (temp3.g - 1.0) : temp3.g));
91 temp3.b = ((temp3.b < 0) ? (temp3.b + 1.0) : ((temp3.b > 1) ? (temp3.b - 1.0) : temp3.b));
94 (((6.0 * temp3.r) < 1) ? (temp1 + (temp2 - temp1) * 6.0 * temp3.r) :
95 (((2.0 * temp3.r) < 1) ? temp2 :
96 (((3.0 * temp3.r) < 2) ? (temp1 + (temp2 - temp1) * ((2.0 / 3.0) - temp3.r) * 6.0) :
98 (((6.0 * temp3.g) < 1) ? (temp1 + (temp2 - temp1) * 6.0 * temp3.g) :
99 (((2.0 * temp3.g) < 1) ? temp2 :
100 (((3.0 * temp3.g) < 2) ? (temp1 + (temp2 - temp1) * ((2.0 / 3.0) - temp3.g) * 6.0) :
102 (((6.0 * temp3.b) < 1) ? (temp1 + (temp2 - temp1) * 6.0 * temp3.b) :
103 (((2.0 * temp3.b) < 1) ? temp2 :
104 (((3.0 * temp3.b) < 2) ? (temp1 + (temp2 - temp1) * ((2.0 / 3.0) - temp3.b) * 6.0) :
111 * Converts hsv to rgb.
113 * Input: [ h, s, v ], where
118 * Returns: [ r, g, b ], where
123 HSVToRGB: function(hsv) {
124 return $.mobile.tizen.clrlib.HSLToRGB($.mobile.tizen.clrlib.HSVToHSL(hsv));
128 * Converts rgb to hsv.
130 * from http://coecsl.ece.illinois.edu/ge423/spring05/group8/FinalProject/HSV_writeup.pdf
132 * Input: [ r, g, b ], where
137 * Returns: [ h, s, v ], where
142 RGBToHSV: function(rgb) {
143 var min, max, delta, h, s, v, r = rgb[0], g = rgb[1], b = rgb[2];
145 min = Math.min(r, Math.min(g, b));
146 max = Math.max(r, Math.max(g, b));
153 if (delta > 0.00001) {
157 h = (g - b) / delta ;
160 h = 2 + (b - r) / delta ;
162 h = 4 + (r - g) / delta ;
174 * Converts hsv to hsl.
176 * Input: [ h, s, v ], where
181 * Returns: [ h, s, l ], where
186 HSVToHSL: function(hsv) {
188 delta = hsv[1] * max,
192 s_divisor = ((half_sum < 0.5) ? sum : (2 - max - min));
194 return [ hsv[0], ((0 == s_divisor) ? 0 : (delta / s_divisor)), half_sum ];
198 * Converts rgb to hsl
200 * Input: [ r, g, b ], where
205 * Returns: [ h, s, l ], where
210 RGBToHSL: function(rgb) {
211 return $.mobile.tizen.clrlib.HSVToHSL($.mobile.tizen.clrlib.RGBToHSV(rgb));