var rgb = this.toRgb();
var RsRGB, GsRGB, BsRGB, R, G, B;
RsRGB = rgb.r/255;
GsRGB = rgb.g/255;
BsRGB = rgb.b/255;
if (RsRGB <= 0.03928) {R = RsRGB / 12.92;} else {R = Math.pow(((RsRGB + 0.055) / 1.055), 2.4);}
if (GsRGB <= 0.03928) {G = GsRGB / 12.92;} else {G = Math.pow(((GsRGB + 0.055) / 1.055), 2.4);}
if (BsRGB <= 0.03928) {B = BsRGB / 12.92;} else {B = Math.pow(((BsRGB + 0.055) / 1.055), 2.4);}
return (0.2126 * R) + (0.7152 * G) + (0.0722 * B);
},
setAlpha: function(value) {
this._a = boundAlpha(value);
this._roundA = mathRound(100*this._a) / 100;
return this;
},
toHsv: function() {
var hsv = rgbToHsv(this._r, this._g, this._b);
return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a };
},
toHsvString: function() {
var hsv = rgbToHsv(this._r, this._g, this._b);
var h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100);
return (this._a == 1) ?
"hsv(" + h + ", " + s + "%, " + v + "%)" :
"hsva(" + h + ", " + s + "%, " + v + "%, "+ this._roundA + ")";
},
toHsl: function() {
var hsl = rgbToHsl(this._r, this._g, this._b);
return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a };
},
toHslString: function() {
var hsl = rgbToHsl(this._r, this._g, this._b);
var h = mathRound(hsl.h * 360), s = mathRound(hsl.s * 100), l = mathRound(hsl.l * 100);
return (this._a == 1) ?
"hsl(" + h + ", " + s + "%, " + l + "%)" :
"hsla(" + h + ", " + s + "%, " + l + "%, "+ this._roundA + ")";
},
toHex: function(allow3Char) {
return rgbToHex(this._r, this._g, this._b, allow3Char);
},
toHexString: function(allow3Char) {
return '#' + this.toHex(allow3Char);
},
toHex8: function(allow4Char) {
return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
},
toHex8String: function(allow4Char) {
return '#' + this.toHex8(allow4Char);
},
toRgb: function() {
return { r: mathRound(this._r), g: mathRound(this._g), b: mathRound(this._b), a: this._a };
},
toRgbString: function() {
return (this._a == 1) ?
"rgb(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ")" :
"rgba(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ", " + this._roundA + ")";
},
toPercentageRgb: function() {
return { r: mathRound(bound01(this._r, 255) * 100) + "%", g: mathRound(bound01(this._g, 255) * 100) + "%", b: mathRound(bound01(this._b, 255) * 100) + "%", a: this._a };
},
toPercentageRgbString: function() {
return (this._a == 1) ?
"rgb(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%)" :
"rgba(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
},
toCmy: function() {
var cmy = rgbToCmy(this._r, this._g, this._b);
return { c: cmy.c * 100, m: cmy.m * 100, y: cmy.y * 100 };
},
toCmyString: function() {
var cmy = rgbToCmy(this._r, this._g, this._b),
c = mathRound(cmy.c * 100), m = mathRound(cmy.m * 100), y = mathRound(cmy.y * 100);
return "cmy(" + c + "%, " + m + "%, " + y + "%)";
},
toCmyk: function() {
var cmyk = rgbToCmyk(this._r, this._g, this._b);
return { c: cmyk.c * 100, m: cmyk.m * 100, y: cmyk.y * 100, k: cmyk.k * 100 };
},
toCmykString: function() {
var cmyk = rgbToCmyk(this._r, this._g, this._b),
c = mathRound(cmyk.c * 100), m = mathRound(cmyk.m * 100), y = mathRound(cmyk.y * 100), k = mathRound(cmyk.k * 100);
return "cmyk(" + c + "%, " + m + "%, " + y + "%, " + k + "%)";
},
toHwb: function() {
var hwb = rgbToHwb(this._r, this._g, this._b);
return { h: hwb.h * 360, w: hwb.w, b: hwb.b, a: this._a };
},
toHwbString: function() {
var hwb = rgbToHwb(this._r, this._g, this._b);
var h = mathRound(hwb.h * 360), w = mathRound(hwb.w * 100), b = mathRound(hwb.b * 100);
return (this._a == 1) ?
"hwb(" + h + ", " + w + "%, " + b + "%)" :
"hwba(" + h + ", " + w + "%, " + b + "%, "+ this._roundA + ")";
},
toNcol: function() {
var ncol = rgbToNcol(this._r, this._g, this._b);
return { n: ncol.n, w: ncol.w, b: ncol.b, a: this._a };
},
toNcolString: function() {
var ncol = rgbToNcol(this._r, this._g, this._b);
var n = ncol.n, w = mathRound(ncol.w * 100), b = mathRound(ncol.b * 100);
return (this._a == 1) ?
n + ", " + w + "%, " + b + "%" :
n + ", " + w + "%, " + b + "%, "+ this._roundA;
},
toNcs: function() {
var ncs = rgbToNcs(this._r, this._g, this._b);
return { s: ncs.s, c: ncs.c, n: ncs.n.toUpperCase() };
},
toNcsString: function() {
var ncs = rgbToNcs(this._r, this._g, this._b);
return ncsToString(ncs.s, ncs.c, ncs.n);
},
toXyz: function() {
var xyz = rgbToXyz(this._r, this._g, this._b);
return { x: xyz.x * 100, y: xyz.y * 100, z: xyz.z * 100 };
},
toXyzString: function() {
var xyz = rgbToXyz(this._r, this._g, this._b),
x = (xyz.x * 100).toFixed(2), y = (xyz.y * 100).toFixed(2), z = (xyz.z * 100).toFixed(2);
return "xyz(" + x + ", " + y + ", " + z + ")";
},
toLab: function() {
var lab = rgbToLab(this._r, this._g, this._b);
return { l: lab.l, a: lab.a, b: lab.b };
},
toLabString: function() {
var lab = rgbToLab(this._r, this._g, this._b),
l = lab.l.toFixed(2), a = lab.a.toFixed(2), b = lab.b.toFixed(2);
return "lab(" + l + ", " + a + ", " + b + ")";
},
toName: function() {
if (this._a === 0) {
return "transparent";
}
if (this._a < 1) {
return false;
}
return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
},
toFilter: function(secondColor) {
var hex8String = '#' + rgbaToArgbHex(this._r, this._g, this._b, this._a);
var secondHex8String = hex8String;
var gradientType = this._gradientType ? "GradientType = 1, " : "";
if (secondColor) {
var s = tinycolor(secondColor);
secondHex8String = '#' + rgbaToArgbHex(s._r, s._g, s._b, s._a);
}
return "progid:DXImageTransform.Microsoft.gradient("+gradientType+"startColorstr="+hex8String+",endColorstr="+secondHex8String+")";
},
toString: function(format) {
var formatSet = !!format;
format = format || this._format;
var formattedString = false;
var hasAlpha = this._a < 1 && this._a >= 0;
var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
if (needsAlphaFormat) {