Ejemplo n.º 1
0
        public override ImgProps Process(ImgProps input)
        {
            double centerX     = input.Width / 2;
            double centerY     = input.Height / 2;
            double maxDistance = Math.Sqrt(Math.Pow(centerX, 2) + Math.Pow(centerY, 2));

            double distX;
            double distY;
            double distance;

            double brightness;

            ImgProps vignetteImage = new ImgProps(input.Width, input.Height);

            for (int i = 0; i < input.Width; i++)
            {
                for (int j = 0; j < input.Height; j++)
                {
                    distX = centerX - i;
                    distY = centerY - j;

                    distance = (int)(Math.Sqrt(Math.Pow(distX, 2) + Math.Pow(distY, 2)));

                    brightness = Math.Pow(((maxDistance - distance) / maxDistance), 2);

                    vignetteImage[i, j] = new Rgba32(
                        ImageUtility.RestrictOverflow((int)(input[i, j].R * brightness)),
                        ImageUtility.RestrictOverflow((int)(input[i, j].G * brightness)),
                        ImageUtility.RestrictOverflow((int)(input[i, j].B * brightness)),
                        input[i, j].A
                        );
                }
            }

            return(vignetteImage);
        }