Ejemplo n.º 1
0
 public static ColorHSV RGBToHSV(ColorRGB colorRGB)
 {
     double val1_1 = (double)colorRGB.R / 256.0;
     double val1_2 = (double)colorRGB.G / 256.0;
     double val2 = (double)colorRGB.B / 256.0;
     double num1 = Math.Max(val1_1, Math.Max(val1_2, val2));
     double num2 = Math.Min(val1_1, Math.Min(val1_2, val2));
     double num3 = num1;
     double num4 = num1 != 0.0 ? (num1 - num2) / num1 : 0.0;
     double num5;
     if (num4 == 0.0)
     {
         num5 = 0.0;
     }
     else
     {
         num5 = (val1_1 != num1 ? (val1_2 != num1 ? 4.0 + (val1_1 - val1_2) / (num1 - num2) : 2.0 + (val2 - val1_1) / (num1 - num2)) : (val1_2 - val2) / (num1 - num2)) / 6.0;
         if (num5 < 0.0)
             ++num5;
     }
     ColorHSV colorHsv;
     colorHsv.H = (int)(num5 * (double)byte.MaxValue);
     colorHsv.S = (int)(num4 * (double)byte.MaxValue);
     colorHsv.V = (int)(num3 * (double)byte.MaxValue);
     return colorHsv;
 }
Ejemplo n.º 2
0
 public static ColorHSL RGBToHSL(ColorRGB colorRGB)
 {
     double val1_1 = (double)colorRGB.R / 256.0;
     double val1_2 = (double)colorRGB.G / 256.0;
     double val2 = (double)colorRGB.B / 256.0;
     double num1 = Math.Max(val1_1, Math.Max(val1_2, val2));
     double num2 = Math.Min(val1_1, Math.Min(val1_2, val2));
     double num3;
     double num4;
     double num5;
     if (num2 == num1)
     {
         num3 = 0.0;
         num4 = 0.0;
         num5 = val1_1;
     }
     else
     {
         num5 = (num2 + num1) / 2.0;
         num4 = num5 >= 0.5 ? (num1 - num2) / (2.0 - num1 - num2) : (num1 - num2) / (num1 + num2);
         num3 = (val1_1 != num1 ? (val1_2 != num1 ? 4.0 + (val1_1 - val1_2) / (num1 - num2) : 2.0 + (val2 - val1_1) / (num1 - num2)) : (val1_2 - val2) / (num1 - num2)) / 6.0;
         if (num3 < 0.0)
             ++num3;
     }
     ColorHSL colorHsl;
     colorHsl.H = (int)(num3 * (double)byte.MaxValue);
     colorHsl.S = (int)(num4 * (double)byte.MaxValue);
     colorHsl.L = (int)(num5 * (double)byte.MaxValue);
     return colorHsl;
 }