Ejemplo n.º 1
0
        public override void ApplyFilter(int[] pixels, int width, int height, Vector[,] field)
        {
            double minBrightness = Double.PositiveInfinity;
            double maxBrightness = Double.NegativeInfinity;

            for (int i = 0; i < pixels.Length; i++)
            {
                int x = i % width;
                int y = i / width;

                int argb       = pixels[i];
                var color      = HsbColor.FromArgb(argb);
                var brightness = color.Brightness;

                if (brightness < minBrightness)
                {
                    minBrightness = brightness;
                }
                if (brightness > maxBrightness)
                {
                    maxBrightness = brightness;
                }
            }

            for (int i = 0; i < pixels.Length; i++)
            {
                int argb       = pixels[i];
                var color      = HsbColor.FromArgb(argb);
                var brightness = color.Brightness;

                double ratio = (brightness - minBrightness) / (maxBrightness - minBrightness);
                color.Brightness = ratio;
                pixels[i]        = color.ToArgb();
            }
        }
Ejemplo n.º 2
0
        public override int[] ApplyFilter(int[] pixels, int width, int height, Vector[,] field)
        {
            double maxLength = Double.NegativeInfinity;
            double minLength = Double.PositiveInfinity;

            // determine min and max length
            // this works faster than parallel enumerable version.
            for (int ix = 0; ix < width; ix++)
            {
                for (int iy = 0; iy < height; iy++)
                {
                    var length = field[ix, iy].Length;
                    if (length > maxLength)
                    {
                        maxLength = length;
                    }
                    if (length < minLength)
                    {
                        minLength = length;
                    }
                }
            }

            int[] resultPixels = new int[width * height];
            pixels.CopyTo(resultPixels, 0);

            // attempt to avoid exception on line
            // 'HsbColor color = HsbColor.FromArgb(pixels[i]);'
            if (pixels.Length == 0)
            {
                return(pixels);
            }

            Parallel.For(0, width * height, i =>
            {
                HsbColor color = HsbColor.FromArgb(pixels[i]);

                int ix     = i % width;
                int iy     = i / width;
                var length = field[ix, height - 1 - iy].Length;

                var ratio = (length - minLength) / (maxLength - minLength);
                if (ratio.IsNaN())
                {
                    ratio = 0;
                }

                var paletteColor = Palette.GetColor(ratio).ToHsbColor();

                color.Hue        = paletteColor.Hue;
                color.Saturation = paletteColor.Saturation;

                resultPixels[i] = color.ToArgb();
            });

            return(resultPixels);
        }
Ejemplo n.º 3
0
        public override void ApplyFilter(int[] pixels, int width, int height, Vector[,] field)
        {
            double maxLength = Double.NegativeInfinity;
            double minLength = Double.PositiveInfinity;

            for (int ix = 0; ix < width; ix++)
            {
                for (int iy = 0; iy < height; iy++)
                {
                    var length = field[ix, iy].Length;
                    if (length > maxLength)
                    {
                        maxLength = length;
                    }
                    if (length < minLength)
                    {
                        minLength = length;
                    }
                }
            }

            for (int i = 0; i < width * height; i++)
            {
                HsbColor color = HsbColor.FromArgb(pixels[i]);

                int ix     = i % width;
                int iy     = i / width;
                var length = field[ix, iy].Length;

                var ratio = (length - minLength) / (maxLength - minLength);
                if (ratio.IsNaN())
                {
                    ratio = 0;
                }

                var paletteColor = Palette.GetColor(ratio).ToHsbColor();

                color.Hue        = paletteColor.Hue;
                color.Saturation = paletteColor.Saturation;

                pixels[i] = color.ToArgb();
            }
        }
Ejemplo n.º 4
0
        public override int[] ApplyFilter(int[] pixels, int width, int height, Vector[,] field)
        {
            double minBrightness = Double.PositiveInfinity;
            double maxBrightness = Double.NegativeInfinity;

            for (int i = 0; i < pixels.Length; i++)
            {
                int argb       = pixels[i];
                var color      = HsbColor.FromArgb(argb);
                var brightness = color.Brightness;

                if (brightness < minBrightness)
                {
                    minBrightness = brightness;
                }
                if (brightness > maxBrightness)
                {
                    maxBrightness = brightness;
                }
            }

            if (minBrightness == 0 || maxBrightness == 1)
            {
                return(pixels);
            }

            Parallel.For(0, pixels.Length, i =>
            {
                int argb       = pixels[i];
                var color      = HsbColor.FromArgb(argb);
                var brightness = color.Brightness;

                double ratio     = (brightness - minBrightness) / (maxBrightness - minBrightness);
                color.Brightness = ratio;
                pixels[i]        = color.ToArgb();
            });

            return(pixels);
        }