Пример #1
0
        public static WriteableBitmap ChangeHue1(this WriteableBitmap target, double amount)
        {
            IBufferExtensions.PixelBufferInfo pixels = IBufferExtensions.GetPixels(target.PixelBuffer);
            int index = 0;

            while (index < pixels.Bytes.Length)
            {
                if ((int)pixels.Bytes[index + 3] > 0)
                {
                    double   num1 = (double)pixels.Bytes[index + 2];
                    double   num2 = (double)pixels.Bytes[index + 1];
                    double   num3 = (double)pixels.Bytes[index];
                    ColorRGB colorRGB;
                    colorRGB.R = (int)num1;
                    colorRGB.G = (int)num2;
                    colorRGB.B = (int)num3;
                    ColorHSL colorHSL = ColorExtensions.RGBToHSL(colorRGB);
                    colorHSL.H              = (int)(amount * 1.0);
                    colorHSL.H             %= (int)byte.MaxValue;
                    colorRGB                = ColorExtensions.HSLToRGB(colorHSL);
                    pixels.Bytes[index]     = (byte)colorRGB.B;
                    pixels.Bytes[index + 1] = (byte)colorRGB.G;
                    pixels.Bytes[index + 2] = (byte)colorRGB.R;
                }
                index += 4;
            }
            pixels.UpdateFromBytes();
            target.Invalidate();
            return(target);
        }
Пример #2
0
        public static ColorRGB HSLToRGB(ColorHSL colorHSL)
        {
            double num1 = (double)colorHSL.H / 256.0;
            double num2 = (double)colorHSL.S / 256.0;
            double num3 = (double)colorHSL.L / 256.0;
            double num4;
            double num5;
            double num6;

            if (num2 == 0.0)
            {
                double num7;
                num4 = num7 = num3;
                num5 = num7;
                num6 = num7;
            }
            else
            {
                double num7 = num3 >= 0.5 ? num3 + num2 - num3 * num2 : num3 * (1.0 + num2);
                double num8 = 2.0 * num3 - num7;
                double num9 = num1 + 1.0 / 3.0;
                if (num9 > 1.0)
                {
                    --num9;
                }
                double num10 = num1;
                double num11 = num1 - 1.0 / 3.0;
                if (num11 < 0.0)
                {
                    ++num11;
                }
                num6 = num9 >= 1.0 / 6.0 ? (num9 >= 0.5 ? (num9 >= 2.0 / 3.0 ? num8 : num8 + (num7 - num8) * (2.0 / 3.0 - num9) * 6.0) : num7) : num8 + (num7 - num8) * 6.0 * num9;
                num5 = num10 >= 1.0 / 6.0 ? (num10 >= 0.5 ? (num10 >= 2.0 / 3.0 ? num8 : num8 + (num7 - num8) * (2.0 / 3.0 - num10) * 6.0) : num7) : num8 + (num7 - num8) * 6.0 * num10;
                num4 = num11 >= 1.0 / 6.0 ? (num11 >= 0.5 ? (num11 >= 2.0 / 3.0 ? num8 : num8 + (num7 - num8) * (2.0 / 3.0 - num11) * 6.0) : num7) : num8 + (num7 - num8) * 6.0 * num11;
            }
            ColorRGB colorRgb;

            colorRgb.R = (int)(num6 * (double)byte.MaxValue);
            colorRgb.G = (int)(num5 * (double)byte.MaxValue);
            colorRgb.B = (int)(num4 * (double)byte.MaxValue);
            return(colorRgb);
        }
Пример #3
0
 public static ColorRGB HSLToRGB(ColorHSL colorHSL)
 {
     double num1 = (double)colorHSL.H / 256.0;
     double num2 = (double)colorHSL.S / 256.0;
     double num3 = (double)colorHSL.L / 256.0;
     double num4;
     double num5;
     double num6;
     if (num2 == 0.0)
     {
         double num7;
         num4 = num7 = num3;
         num5 = num7;
         num6 = num7;
     }
     else
     {
         double num7 = num3 >= 0.5 ? num3 + num2 - num3 * num2 : num3 * (1.0 + num2);
         double num8 = 2.0 * num3 - num7;
         double num9 = num1 + 1.0 / 3.0;
         if (num9 > 1.0)
             --num9;
         double num10 = num1;
         double num11 = num1 - 1.0 / 3.0;
         if (num11 < 0.0)
             ++num11;
         num6 = num9 >= 1.0 / 6.0 ? (num9 >= 0.5 ? (num9 >= 2.0 / 3.0 ? num8 : num8 + (num7 - num8) * (2.0 / 3.0 - num9) * 6.0) : num7) : num8 + (num7 - num8) * 6.0 * num9;
         num5 = num10 >= 1.0 / 6.0 ? (num10 >= 0.5 ? (num10 >= 2.0 / 3.0 ? num8 : num8 + (num7 - num8) * (2.0 / 3.0 - num10) * 6.0) : num7) : num8 + (num7 - num8) * 6.0 * num10;
         num4 = num11 >= 1.0 / 6.0 ? (num11 >= 0.5 ? (num11 >= 2.0 / 3.0 ? num8 : num8 + (num7 - num8) * (2.0 / 3.0 - num11) * 6.0) : num7) : num8 + (num7 - num8) * 6.0 * num11;
     }
     ColorRGB colorRgb;
     colorRgb.R = (int)(num6 * (double)byte.MaxValue);
     colorRgb.G = (int)(num5 * (double)byte.MaxValue);
     colorRgb.B = (int)(num4 * (double)byte.MaxValue);
     return colorRgb;
 }