gaussianConvolution() static private method

static private gaussianConvolution ( double matrix, double deviation ) : ].double[
matrix double
deviation double
return ].double[
Esempio 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);
        }
Esempio 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);
        }