Rearrange color converters to group by pairs.

This commit is contained in:
Jürg Lehni 2011-03-13 18:41:32 +01:00
parent d5fa3d7ae6
commit cd80db14d8

View file

@ -264,18 +264,6 @@ var Color = this.Color = Base.extend(new function() {
return new HSBColor(hue * 360, saturation, brightness, alpha); return new HSBColor(hue * 360, saturation, brightness, alpha);
}, },
'rgb-gray': function(color) {
// Using the standard NTSC conversion formula that is used for
// calculating the effective luminance of an RGB color:
// http://www.mathworks.com/support/solutions/en/data/1-1ASCU/index.html?solution=1-1ASCU
return new GrayColor(1 -
(color._red * 0.2989
+ color._green * 0.587
+ color._blue * 0.114),
color._alpha
);
},
'hsb-rgb': function(color) { 'hsb-rgb': function(color) {
var h = color._hue, var h = color._hue,
s = color._saturation, s = color._saturation,
@ -295,9 +283,16 @@ var Color = this.Color = Base.extend(new function() {
} }
}, },
'hsb-gray': function(color) { 'rgb-gray': function(color) {
var rgbColor = converters['hsb-rgb'](color); // Using the standard NTSC conversion formula that is used for
return converters['rgb-gray'](rgbColor); // calculating the effective luminance of an RGB color:
// http://www.mathworks.com/support/solutions/en/data/1-1ASCU/index.html?solution=1-1ASCU
return new GrayColor(1 -
(color._red * 0.2989
+ color._green * 0.587
+ color._blue * 0.114),
color._alpha
);
}, },
'gray-rgb': function(color) { 'gray-rgb': function(color) {
@ -305,6 +300,11 @@ var Color = this.Color = Base.extend(new function() {
return new RGBColor(component, component, component, color._alpha); return new RGBColor(component, component, component, color._alpha);
}, },
'hsb-gray': function(color) {
var rgbColor = converters['hsb-rgb'](color);
return converters['rgb-gray'](rgbColor);
},
'gray-hsb': function(color) { 'gray-hsb': function(color) {
return new HSBColor(0, 0, 1 - color._gray, color._alpha); return new HSBColor(0, 0, 1 - color._gray, color._alpha);
} }