Ejemplo n.º 1
0
        private void CalculateSaturationBrush()
        {
            LinearGradientBrush linearGradientBrush = new LinearGradientBrush();

            linearGradientBrush.StartPoint = new Point(0, 0);
            linearGradientBrush.EndPoint   = new Point(1, 0);
            GradientStop startGS = new GradientStop();
            HSL          hsl     = new HSL(Hue, 0, 0.5);
            RGB          rgb     = ColorModelConverter.HSLtoRGB(hsl);

            startGS.Color = new Color()
            {
                R = (byte)rgb.Red, G = (byte)rgb.Green, B = (byte)rgb.Blue, A = 255
            };
            startGS.Offset = 0.0;
            linearGradientBrush.GradientStops.Add(startGS);
            GradientStop endGS = new GradientStop();

            hsl         = new HSL(Hue, 1, 0.5);
            rgb         = ColorModelConverter.HSLtoRGB(hsl);
            endGS.Color = new Color()
            {
                R = (byte)rgb.Red, G = (byte)rgb.Green, B = (byte)rgb.Blue, A = 255
            };
            endGS.Offset = 1.0;
            linearGradientBrush.GradientStops.Add(endGS);
            SaturationBrush = linearGradientBrush;
        }
Ejemplo n.º 2
0
        public void Process()
        {
            Image.Source = backupImage.Source;
            foreach (Transform transform in transforms)
            {
                TransformedBitmap tb = new TransformedBitmap();
                tb.BeginInit();
                tb.Source    = (BitmapSource)Image.Source;
                tb.Transform = transform;
                tb.EndInit();
                Image.Source = tb;
            }

            WriteableBitmap source = new WriteableBitmap((BitmapSource)Image.Source);
            WriteableBitmap dest   = new WriteableBitmap((BitmapSource)Image.Source);

            try
            {
                dest.Lock();

                unsafe
                {
                    IntPtr sourceBuffer  = source.BackBuffer;
                    IntPtr destBuffer    = dest.BackBuffer;
                    byte * sourcepbuffer = (byte *)sourceBuffer.ToPointer();
                    byte * destpbuffer   = (byte *)destBuffer.ToPointer();
                    int    Stride        = dest.BackBufferStride;
                    int    height        = dest.PixelHeight;
                    Parallel.For(0, dest.PixelWidth, x =>
                    {
                        for (int y = 0; y < height; y++)
                        {
                            int loc = y * Stride + x * 4;

                            RGB rgb   = new RGB();
                            rgb.Blue  = sourcepbuffer[loc];
                            rgb.Green = sourcepbuffer[loc + 1];
                            rgb.Red   = sourcepbuffer[loc + 2];

                            HSL hsl = ColorModelConverter.RGBtoHSL(rgb);

                            SetHue(hsl);
                            SetLightness(hsl);
                            SetSaturation(hsl);

                            rgb = ColorModelConverter.HSLtoRGB(hsl);

                            SetContrast(rgb);

                            destpbuffer[loc]     = rgb.Blue;
                            destpbuffer[loc + 1] = rgb.Green;
                            destpbuffer[loc + 2] = rgb.Red;
                        }
                    });
                    dest.AddDirtyRect(new Int32Rect(0, 0, dest.PixelWidth, dest.PixelHeight));
                }
            }
            finally
            {
                dest.Unlock();
            }

            Image.Source = dest;
        }