Ejemplo n.º 1
0
        public static Color[] CreateBlurredGrayscaleTexture(Color[] srcData, int width, int height, double deviation = 1)
        {
            var destData = new Color[width * height];
            var matrix   = new double[width, height];

            // first we calculate the grayscale and store it in matrix
            for (var i = 0; i < width; i++)
            {
                for (var j = 0; j < height; j++)
                {
                    matrix[i, j] = srcData[i + j * width].Grayscale().R;
                }
            }

            matrix = GaussianBlur.GaussianConvolution(matrix, deviation);
            for (var i = 0; i < width; i++)
            {
                for (var j = 0; j < height; j++)
                {
                    var val = (int)Math.Min(255, matrix[i, j]);
                    destData[i + j * width] = new Color(val, val, val, srcData[i + j * width].A);
                }
            }

            return(destData);
        }
Ejemplo n.º 2
0
        public static Color[] CreateBlurredTexture(Color[] srcData, int width, int height, double deviation = 1)
        {
            var matrixR = new double[width, height];
            var matrixG = new double[width, height];
            var matrixB = new double[width, height];
            var matrixA = new double[width, height];

            var destData = new Color[width * height];

            // first we calculate the grayscale and store it in matrix
            for (var i = 0; i < width; i++)
            {
                for (var j = 0; j < height; j++)
                {
                    matrixR[i, j] = srcData[i + j * width].R;
                    matrixG[i, j] = srcData[i + j * width].G;
                    matrixB[i, j] = srcData[i + j * width].B;
                    matrixA[i, j] = srcData[i + j * width].A;
                }
            }

            matrixR = GaussianBlur.GaussianConvolution(matrixR, deviation);
            matrixG = GaussianBlur.GaussianConvolution(matrixG, deviation);
            matrixB = GaussianBlur.GaussianConvolution(matrixB, deviation);
            matrixA = GaussianBlur.GaussianConvolution(matrixA, deviation);

            for (var i = 0; i < width; i++)
            {
                for (var j = 0; j < height; j++)
                {
                    var r = (int)Math.Min(255, matrixR[i, j]);
                    var g = (int)Math.Min(255, matrixG[i, j]);
                    var b = (int)Math.Min(255, matrixB[i, j]);
                    var a = (int)Math.Min(255, matrixA[i, j]);
                    destData[i + j * width] = new Color(r, g, b, a);
                }
            }

            return(destData);
        }