Esempio n. 1
0
        // Fixed Block Size!
        internal static Image Render3(Bitmap image, ConvolutionFilter filter)
        {
            var gpu = Gpu.Default;

            var width = image.Width;
            var array = BitmapUtility.ToColorArray(image);

            var mFilter = filter.Filter;
            var mFactor = filter.Factor;
            var mOffset = filter.Offset;

            var inputMemory = gpu.ArrayGetMemory(array, true, false);
            var inputDevPtr = new deviceptr <ColorRaw>(inputMemory.Handle);

            var resultLength = array.Length;
            var resultMemory = Gpu.Default.AllocateDevice <ColorRaw>(resultLength);
            var resultDevPtr = new deviceptr <ColorRaw>(resultMemory.Handle);

            var lp = new LaunchParam(256, 256);

            gpu.Launch(() =>
            {
                var i = blockDim.x * blockIdx.x + threadIdx.x;

                while (i < resultLength)
                {
                    ComputeEdgeDetectFilter0AtOffsetNapron(inputDevPtr, resultDevPtr, resultLength, mFilter, mFactor, mOffset, i, width);
                    i += blockDim.x * gridDim.x;
                }
            }, lp);

            return(BitmapUtility.FromColorArray(Gpu.CopyToHost(resultMemory), image.Width, image.Height));
        }
Esempio n. 2
0
        // Alea Parallel.For!
        internal static Image Render1(Bitmap image, ConvolutionFilter filter)
        {
            var gpu = Gpu.Default;

            var width = image.Width;
            var array = BitmapUtility.ToColorArray(image);

            var mFilter = filter.Filter;
            var mFactor = filter.Factor;
            var mOffset = filter.Offset;

            var inputMemory = gpu.ArrayGetMemory(array, true, false);
            var inputDevPtr = new deviceptr <ColorRaw>(inputMemory.Handle);

            var resultLength = array.Length;
            var resultMemory = Gpu.Default.AllocateDevice <ColorRaw>(resultLength);
            var resultDevPtr = new deviceptr <ColorRaw>(resultMemory.Handle);

            gpu.For(0, resultLength, i =>
            {
                if (i < resultLength)
                {
                    ComputeEdgeDetectFilter0AtOffsetNapron(inputDevPtr, resultDevPtr, resultLength, mFilter, mFactor, mOffset, i, width);
                }
            });

            return(BitmapUtility.FromColorArray(Gpu.CopyToHost(resultMemory), image.Width, image.Height));
        }
Esempio n. 3
0
        // Custom Array!
        internal static Image Render2(Bitmap image, ConvolutionFilter filter)
        {
            var width  = image.Width;
            var height = image.Height;

            var source = BitmapUtility.ToColorArray(image);
            var result = new ColorRaw[width * height];

            Parallel.For(0, height, y =>
            {
                for (var x = 0; x < width; ++x)
                {
                    var offset = y * width + x;

                    var neighbours = GetNeighbours(x, y, width, height, (nx, ny, i) => (nx >= 0 && nx < width && ny >= 0 && ny < height) == false
                        ? ColorRaw.FromRgb(0, 0, 0)
                        : source[i]);

                    result[offset] = filter.Compute(neighbours);
                }
            });

            return(BitmapUtility.FromColorArray(result, image.Width, image.Height));
        }