X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=dev5%2Fpsychlops%2Fextension%2Fstandard%2FCIEColor.cs;fp=dev5%2Fpsychlops%2Fextension%2Fstandard%2FCIEColor.cs;h=bf08e3afb3884788c93d19104ff4dcbf2c0ca578;hb=c3b559a9144300352379e8d80dd71131b45f4d99;hp=50df53c071fa453a9d02df424750e0ecc3dc6eb4;hpb=995fc1b91f005c8ca430dd8f2bcca0d676907f06;p=psychlops%2Fsilverlight.git diff --git a/dev5/psychlops/extension/standard/CIEColor.cs b/dev5/psychlops/extension/standard/CIEColor.cs index 50df53c..bf08e3a 100644 --- a/dev5/psychlops/extension/standard/CIEColor.cs +++ b/dev5/psychlops/extension/standard/CIEColor.cs @@ -4,6 +4,45 @@ namespace Psychlops { namespace ColorSpaces { + public struct HSV + { + public double H, S, V, A; + + public Color toRGB() + { + if (S == 0.0) return new Color(V, V, V, A); + int hi = (int)Math.floor(H/60.0); + double f = (H / 60.0) - (double)hi, + p = V*(1.0-S), + q = V*(1.0-f*S), + t = V*(1.0-(1.0-f)*S); + if (hi == 0) { return new Color(V, t, p, A); } + else if (hi == 1) { return new Color(q, V, p, A); } + else if (hi == 2) { return new Color(p, V, t, A); } + else if (hi == 3) { return new Color(p, q, V, A); } + else if (hi == 4) { return new Color(t, p, V, A); } + else if (hi == 5) { return new Color(V, p, q, A); } + else return Color.transparent; + } + + public void fromRGB(Color o) { + double MAX = Math.max(Math.max(o.r, o.g), o.b); + double MIN = Math.min(Math.min(o.r, o.g), o.b); + double h; + if(MAX==MIN) { h=0.0; } + else if(o.r>o.g && o.r>o.b) { h=60.0*(o.g-o.b)/(MAX-MIN)+360.0; } + else if(o.g>o.b) { h=60.0*(o.b-o.r)/(MAX-MIN)+120.0; } + else { h=60.0*(o.r-o.g)/(MAX-MIN)+240.0; } + h = Math.mod(h, 360.0); + double v = MAX, s; + if(MAX==MIN) { s=0.0; } else { s=(MAX-MIN)/MAX; } + H = h; + S = s; + V = v; + A = o.a; + } + } + /* * CIE 1931 * R: 700 nm