Пример #1
0
        unsafe public static KernelMap <T> MakeBlurMap(uint size, double radius, uint colorChannels, bool alphaChannel)
        {
            double[] blurkernel = new MathUtil.GaussianFactory(radius).MakeKernel();
            int      blurdist   = Math.Min(blurkernel.Length, (int)size);
            int      channels   = (int)colorChannels + (alphaChannel ? 1 : 0);

            var map = new KernelMap <T>((int)size, (int)size, blurdist, channels);

            fixed(byte *mstart = map.Map.Array)
            fixed(double *kstart = blurkernel)
            {
                int *   mp = (int *)mstart;
                double *kp = kstart;

                for (int i = 0; i < size; i++)
                {
                    int start = i - blurdist / 2;
                    *mp++ = start;

                    for (int j = 0; j < blurdist; j++)
                    {
                        T w = convertWeight(kp[j]);
                        for (int k = 0; k < channels; k++)
                        {
                            Unsafe.Write(mp++, w);
                        }
                    }
                }
            }

            return(map.clamp());
        }
Пример #2
0
        unsafe public static KernelMap MakeBlurMap(uint size, double radius)
        {
            int[] blurkernel = new MathUtil.GaussianFactory(radius).MakeKernel().Select(f => MathUtil.ScaleToInt32(f)).ToArray();
            int   blurdist   = blurkernel.Length;

            var map = new KernelMap((int)size, (int)size, blurdist);

            fixed(int *mstart = map.Map, kstart = blurkernel)
            {
                int *mp = mstart, kp = kstart;

                for (int i = 0; i < size; i++)
                {
                    int end   = i + blurdist / 2;
                    int start = end - blurdist + 1;

                    *mp++ = start;

                    for (int j = 0; j < blurdist; j++)
                    {
                        *mp++ = kp[j];
                    }
                }
            }

            return(map.clamp());
        }