Author: pyaschenko
Date: 2009-04-09 10:54:28 -0400 (Thu, 09 Apr 2009)
New Revision: 13471
Modified:
trunk/ui/colorPicker/src/main/resources/org/richfaces/renderkit/html/scripts/ui.colorpicker.js
Log:
https://jira.jboss.org/jira/browse/RF-6699
Modified:
trunk/ui/colorPicker/src/main/resources/org/richfaces/renderkit/html/scripts/ui.colorpicker.js
===================================================================
---
trunk/ui/colorPicker/src/main/resources/org/richfaces/renderkit/html/scripts/ui.colorpicker.js 2009-04-09
14:40:39 UTC (rev 13470)
+++
trunk/ui/colorPicker/src/main/resources/org/richfaces/renderkit/html/scripts/ui.colorpicker.js 2009-04-09
14:54:28 UTC (rev 13471)
@@ -390,21 +390,22 @@
return this._RGBToHSB(this._HexToRGB(hex));
},
_RGBToHSB: function(rgb) {
- var hsb = {};
- hsb.b = Math.max(Math.max(rgb.r,rgb.g),rgb.b);
- hsb.s = (hsb.b <= 0) ? 0 : Math.round(100*(hsb.b -
Math.min(Math.min(rgb.r,rgb.g),rgb.b))/hsb.b);
- hsb.b = Math.round((hsb.b /255)*100);
- if((rgb.r==rgb.g) && (rgb.g==rgb.b)) hsb.h = 0;
- else if(rgb.r>=rgb.g && rgb.g>=rgb.b) hsb.h =
60*(rgb.g-rgb.b)/(rgb.r-rgb.b);
- else if(rgb.g>=rgb.r && rgb.r>=rgb.b) hsb.h = 60 +
60*(rgb.g-rgb.r)/(rgb.g-rgb.b);
- else if(rgb.g>=rgb.b && rgb.b>=rgb.r) hsb.h = 120 +
60*(rgb.b-rgb.r)/(rgb.g-rgb.r);
- else if(rgb.b>=rgb.g && rgb.g>=rgb.r) hsb.h = 180 +
60*(rgb.b-rgb.g)/(rgb.b-rgb.r);
- else if(rgb.b>=rgb.r && rgb.r>=rgb.g) hsb.h = 240 +
60*(rgb.r-rgb.g)/(rgb.b-rgb.g);
- else if(rgb.r>=rgb.b && rgb.b>=rgb.g) hsb.h = 300 +
60*(rgb.r-rgb.b)/(rgb.r-rgb.g);
- else hsb.h = 0;
- hsb.h = Math.round(hsb.h);
+ var r = rgb.r, g = rgb.g, b = rgb.b;
+ var low = Math.min(r,Math.min(g,b));
+ var high = Math.max(r,Math.max(g,b));
+ var hsb = {b: high*100/255};
+ var diff = high-low;
+ if (diff){
+ hsb.s = Math.round(100*(diff/high));
+ if(r == high) hsb.h = Math.round(((g-b)/diff)*60);
+ else if(g == high) hsb.h = Math.round((2 + (b-r)/diff)*60);
+ else hsb.h = Math.round((4 + (r-g)/diff)*60);
+ if (hsb.h > 360) hsb.h -= 360;
+ else if (hsb.h < 0) hsb.h += 360;
+ }else hsb.h = hsb.s = 0;
+ hsb.b = Math.round(hsb.b);
return hsb;
- },
+ },
_HSBToRGB: function(hsb) {
var rgb = {};
var h = Math.round(hsb.h);