private static JSColor FromValue(string p) { JSColor c = new JSColor(); c.Value = p; return(c); }
public static JSColor FromRGB(byte r, byte g, byte b) { JSColor n = new JSColor(); n.R = r; n.G = g; n.B = b; return(n); }
/// <summary> /// returns color by HLS /// </summary> /// <param name="h">up to 240</param> /// <param name="l">up to 120</param> /// <param name="s">up to 240</param> /// <returns></returns> public static JSColor FromHLS(byte h, byte l, byte s) { JSColor n = new JSColor(); n.H = h; n.L = l; n.S = s; n.isHLS = true; return(n); }
public override string ToString() { JSColor z = this; if (z.Value != null) { return(z.Value); } if (z.isHLS) { z = z.ToRGB(); } return("RGB(" + z.R + ", " + z.G + ", " + z.B + ")"); }
public JSColor ToRGB() { JSColor c = new JSColor(); if (this.S == 0) { /* achromatic case */ // compiler bug: multiple assignments not supported var v = (byte)((this.L * RGBMAX) / HLSMAX); c.R = v; c.G = v; c.B = v; if (this.H != UNDEFINED) { /* ERROR */ } } else { /* chromatic case */ int Magic1, Magic2; /* set up magic numbers */ if (this.L <= (HLSMAX / 2)) { Magic2 = (this.L * (HLSMAX + this.S) + (HLSMAX / 2)) / HLSMAX; } else { Magic2 = this.L + this.S - ((this.L * this.S) + (HLSMAX / 2)) / HLSMAX; } Magic1 = 2 * this.L - Magic2; /* get RGB, change units from HLSMAX to RGBMAX */ c.R = global::System.Convert.ToByte((HueToRGB(Magic1, Magic2, this.H + (HLSMAX / 3)) * RGBMAX + (HLSMAX / 2)) / HLSMAX); c.G = global::System.Convert.ToByte((HueToRGB(Magic1, Magic2, this.H) * RGBMAX + (HLSMAX / 2)) / HLSMAX); c.B = global::System.Convert.ToByte((HueToRGB(Magic1, Magic2, this.H - (HLSMAX / 3)) * RGBMAX + (HLSMAX / 2)) / HLSMAX); } return(c); }
public static JSColor FromRGB(byte r, byte g, byte b) { JSColor n = new JSColor(); n.R = r; n.G = g; n.B = b; return n; }
/// <summary> /// returns color by HLS /// </summary> /// <param name="h">up to 240</param> /// <param name="l">up to 120</param> /// <param name="s">up to 240</param> /// <returns></returns> public static JSColor FromHLS(byte h, byte l, byte s) { JSColor n = new JSColor(); n.H = h; n.L = l; n.S = s; n.isHLS = true; return n; }
public JSColor ToHLS() { JSColor c = new JSColor(); c.isHLS = true; int cMax = Native.Math.max(Native.Math.max(R, G), B); int cMin = Native.Math.min(Native.Math.min(R, G), B); int H, L, S; L = (((cMax + cMin) * HLSMAX) + RGBMAX) / (2 * RGBMAX); if (cMax == cMin) { /* r=g=b --> achromatic case */ S = 0; /* saturation */ H = UNDEFINED; /* hue */ } else { /* saturation */ if (L <= (HLSMAX / 2)) S = (((cMax - cMin) * HLSMAX) + ((cMax + cMin) / 2)) / (cMax + cMin); else S = (((cMax - cMin) * HLSMAX) + ((2 * RGBMAX - cMax - cMin) / 2)) / (2 * RGBMAX - cMax - cMin); /* hue */ int Rdelta = (((cMax - R) * (HLSMAX / 6)) + ((cMax - cMin) / 2)) / (cMax - cMin); int Gdelta = (((cMax - G) * (HLSMAX / 6)) + ((cMax - cMin) / 2)) / (cMax - cMin); int Bdelta = (((cMax - B) * (HLSMAX / 6)) + ((cMax - cMin) / 2)) / (cMax - cMin); if (R == cMax) H = Bdelta - Gdelta; else if (G == cMax) H = (HLSMAX / 3) + Rdelta - Bdelta; else /* B == cMax */ H = ((2 * HLSMAX) / 3) + Gdelta - Rdelta; if (H < 0) H += HLSMAX; if (H > HLSMAX) H -= HLSMAX; } c.H = Convert.ToByte(H); c.L = Convert.ToByte(L); c.S = Convert.ToByte(S); return c; }
public JSColor ToRGB() { JSColor c = new JSColor(); if (this.S == 0) { /* achromatic case */ // compiler bug: multiple assignments not supported var v = (byte)((this.L * RGBMAX) / HLSMAX); c.R = v; c.G = v; c.B = v; if (this.H != UNDEFINED) { /* ERROR */ } } else { /* chromatic case */ int Magic1, Magic2; /* set up magic numbers */ if (this.L <= (HLSMAX / 2)) Magic2 = (this.L * (HLSMAX + this.S) + (HLSMAX / 2)) / HLSMAX; else Magic2 = this.L + this.S - ((this.L * this.S) + (HLSMAX / 2)) / HLSMAX; Magic1 = 2 * this.L - Magic2; /* get RGB, change units from HLSMAX to RGBMAX */ c.R = global::System.Convert.ToByte((HueToRGB(Magic1, Magic2, this.H + (HLSMAX / 3)) * RGBMAX + (HLSMAX / 2)) / HLSMAX); c.G = global::System.Convert.ToByte((HueToRGB(Magic1, Magic2, this.H) * RGBMAX + (HLSMAX / 2)) / HLSMAX); c.B = global::System.Convert.ToByte((HueToRGB(Magic1, Magic2, this.H - (HLSMAX / 3)) * RGBMAX + (HLSMAX / 2)) / HLSMAX); } return c; }
private static JSColor FromValue(string p) { JSColor c = new JSColor(); c.Value = p; return c; }
public JSColor ToHLS() { JSColor c = new JSColor(); c.isHLS = true; int cMax = Native.Math.max(Native.Math.max(R, G), B); int cMin = Native.Math.min(Native.Math.min(R, G), B); int H, L, S; L = (((cMax + cMin) * HLSMAX) + RGBMAX) / (2 * RGBMAX); if (cMax == cMin) { /* r=g=b --> achromatic case */ S = 0; /* saturation */ H = UNDEFINED; /* hue */ } else { /* saturation */ if (L <= (HLSMAX / 2)) { S = (((cMax - cMin) * HLSMAX) + ((cMax + cMin) / 2)) / (cMax + cMin); } else { S = (((cMax - cMin) * HLSMAX) + ((2 * RGBMAX - cMax - cMin) / 2)) / (2 * RGBMAX - cMax - cMin); } /* hue */ int Rdelta = (((cMax - R) * (HLSMAX / 6)) + ((cMax - cMin) / 2)) / (cMax - cMin); int Gdelta = (((cMax - G) * (HLSMAX / 6)) + ((cMax - cMin) / 2)) / (cMax - cMin); int Bdelta = (((cMax - B) * (HLSMAX / 6)) + ((cMax - cMin) / 2)) / (cMax - cMin); if (R == cMax) { H = Bdelta - Gdelta; } else if (G == cMax) { H = (HLSMAX / 3) + Rdelta - Bdelta; } else /* B == cMax */ { H = ((2 * HLSMAX) / 3) + Gdelta - Rdelta; } if (H < 0) { H += HLSMAX; } if (H > HLSMAX) { H -= HLSMAX; } } c.H = Convert.ToByte(H); c.L = Convert.ToByte(L); c.S = Convert.ToByte(S); return(c); }