Example #1
0
 public static CMYK FromRGB(RGB value)
 {
     double
         c = 1.0 - value.R,
         m = 1.0 - value.G,
         y = 1.0 - value.B,
         k = 1.0;
     if (c < k) k = c;
     if (m < k) k = m;
     if (y < k) k = y;
     if (k == 1.0) //black
     {
         c = m = y = 0.0;
     }
     else {
         c = (c - k)/(1.0 - k);
         m = (m - k)/(1.0 - k);
         y = (y - k)/(1.0 - k);
     }
     return new CMYK(c, m, y, k);
 }
Example #2
0
 public static XYZ FromRGB(RGB value)
 {
     double
         r=GammaCorrection(value.R),
         g=GammaCorrection(value.G),
         b=GammaCorrection(value.B);
     //Observer. = 2°, Illuminant = D65
     return new XYZ(
         r*41.24+g*35.76+b*18.05,//multiplicated by 100
         r*21.26+g*71.52+b*7.22,
         r*1.93+g*11.92+b*95.05);
 }
Example #3
0
        public static HSV FromRGB(RGB col)
        {
            double
                min = Math.Min( Math.Min(col.R,col.G),col.B),
                max = Math.Max( Math.Max(col.R,col.G),col.B),
                delta_max = max-min;

            HSV ret=new HSV(0,0,0);
            ret._v=max;

            if (delta_max==0.0)
            {
                ret._h=0.0;
                ret._s=0.0;
            }
            else
            {
                ret._s=delta_max/max;

                double del_R=(((max-col.R)/6.0)+(delta_max/2.0))/delta_max;
                double del_G=(((max-col.G)/6.0)+(delta_max/2.0))/delta_max;
                double del_B=(((max-col.B)/6.0)+(delta_max/2.0))/delta_max;

                if      (col.R==max) ret._h = del_B-del_G;
                else if (col.G==max) ret._h = (1.0/3.0)+del_R-del_B;
                else if (col.B==max) ret._h = (2.0/3.0)+del_G-del_R;

                if (ret._h<0.0)ret._h+=1.0;
                if (ret._h>1.0)ret._h-=1.0;
            }
            return ret;
        }
Example #4
0
 private void panelColor_Click(object sender, EventArgs e)
 {
     if (_discreteColors)
     {
         using (DiscreteColorPicker dcp = new DiscreteColorPicker())
         {
             dcp.ValidColors = _validDiscreteColors;
             dcp.SingleColorOnly = true;
             dcp.SelectedColors = new List<Color> { Color };
             DialogResult result = dcp.ShowDialog();
             if (result == DialogResult.OK)
             {
                 if (dcp.SelectedColors.Count() == 0)
                 {
                     Color = Color.White;
                 }
                 else
                 {
                     RGBColor = dcp.SelectedColors.First();
                 }
             }
         }
     }
     else
     {
         using (ColorPicker cp = new ColorPicker())
         {
             cp.LockValue_V = false;
             cp.Color = XYZ.FromRGB(Color);
             DialogResult result = cp.ShowDialog();
             if (result == DialogResult.OK)
             {
                 RGBColor = cp.Color.ToRGB();
             }
         }
     }
 }
Example #5
0
		public SetLevelData()
		{
			level = 1;
			color = Color.White;
		}
Example #6
0
 public static HSV FromRGB(RGB col)
 {
     return(FromRGB(col.R, col.G, col.B));
 }
Example #7
0
        public static double VFromRgb(RGB col)
        {
            double max = Math.Max(Math.Max(col.R, col.G), col.B);

            return(max);
        }
Example #8
0
 public static double VFromRgb(RGB col)
 {
     double max = Math.Max(Math.Max(col.R, col.G), col.B);
     return max;
 }
Example #9
0
        public static void FromRGB(RGB col, out double hue, out double saturation, out double value)
        {
            double
                min = Math.Min(Math.Min(col.R, col.G), col.B),
                max = Math.Max(Math.Max(col.R, col.G), col.B),
                delta_max = max - min;

            var s = 0.0d;
            var h = 0.0d;

            if (delta_max != 0.0)
            {
                s = delta_max / max;

                double del_R = (((max - col.R) / 6.0) + (delta_max / 2.0)) / delta_max;
                double del_G = (((max - col.G) / 6.0) + (delta_max / 2.0)) / delta_max;
                double del_B = (((max - col.B) / 6.0) + (delta_max / 2.0)) / delta_max;

                if (col.R == max) h = del_B - del_G;
                else if (col.G == max) h = (1.0 / 3.0) + del_R - del_B;
                else if (col.B == max) h = (2.0 / 3.0) + del_G - del_R;

                if (h < 0.0) h += 1.0;
                if (h > 1.0) h -= 1.0;

            }

            hue = h;
            saturation = s;
            value = max;
        }
Example #10
0
 public static HSV FromRGB(RGB col)
 {
     return FromRGB(col.R, col.G, col.B);
 }