// Native GDI+ Bitmap! internal static Image Render1(Bitmap image, ConvolutionFilter filter) { var width = image.Width; var height = image.Height; var source = new FastBitmap(image); var result = new FastBitmap(image.Width, image.Height); Parallel.For(0, height, y => { for (var x = 0; x < width; ++x) { var neighbours = GetNeighbours(x, y, width, height, (nx, ny, i) => (nx >= 0 && nx < width && ny >= 0 && ny < height) == false ? Color.FromArgb(0, 0, 0) : source.GetPixel(nx, ny)); result.SetPixel(x, y, filter.Compute(neighbours)); } }); return(result.Bitmap); }
// 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)); }