I am using Cudafy as c# wrapper
I need to get colour info InputBitmap0.GetPixel(x, y)
of a bitmap and make an new bitmap for output .
I need the following work to be done in GPU.
IN CPU
OutputBitmap.SetPixel(object_point_x, object_point_y, InputBitmap0.GetPixel(x, y));
In short:
How to GetPixel() for each pixel point of the input Bitmap, SetPixel() for each pixel point of the outputbitmap Bitmap in GPU.
It took time but finally, I , cracked my case.
We have two
Bitmap
: one for outputOutputBitmap
and another for inputInputBitmap0
Lets divide this task into parts:
InputBitmap0.GetPixel()
forx
,y
coordinateOutputBitmap.SetPixel()
for a different coordinateobject_point_x, object_point_y
Cudafy does not support
Bitmap
orColor
type data. So I converted the Bitmaps tobyte
type.We have copied the content of the
InputBitmap0
to thergbValues
array. Now we need to do the work ofGetPixel()
(get the values of R,G,B,A).We need to do the above work ( make array) for
OutputBitmap
too because we will be doingSetPixel()
in GPU but we will copy the array back to the bitmap later.Its GPU time for calculation. Lets initialize gpu.
Now send
input_ragba_color
andoutput_ragba
to the gpu because we can iterate the array and do any calculation.Now inside GPU(kernel)
We now know that gpu has populated an array(
dev_output_rgba_color
) for ourOutputBitmap
.Copy the result back to the
OutputBitmap
using the memory pointer and unlock it from the memory.Now the
OutputBitmap
contains the updated values.