I am trying to implement a blur-function I wrote in c#. I want it to run in an openCL Kernel
The function is as follows:
private static int cSharpBlur(double[,] blur, int width, int height, int[,] imageToInt, int[,] outputImage, int i, int j)
{
int maskSize = 1;
double sum = 0.0f;
// Collect neighbor values and multiply with gaussian
for (int a = -maskSize; a < maskSize + 1; a++)
{
for (int b = -maskSize; b < maskSize + 1; b++)
{
sum += blur[a+1, b+1] * imageToInt[Clamp(i+a,0,width-1), Clamp(j+b,0,height-1)];
}
}
byte[] values = BitConverter.GetBytes(imageToInt[i,j]);
int alpha = values[3];
int alphasum = alpha * (int)sum;
values[3] = (byte)alphasum;
int newValue = BitConverter.ToInt32(values,0);
return newValue;
}
Now I obviously don't have .GetBytes and BitConverter.ToInt32 in openCL. Neither do I have a 2 dimensional array.
I solved this via __kernel void gaussianBlur(__global int* imageToInt, int width, int height, __global double* blurBuffer, int blurBufferSize, __global int* outputBuffer){ int col = get_global_id(0); int row = get_global_id(1);
double sum = 0.0f;
for (int a = -1; a < 2; a++)
{
for (int b = -1; b < 2; b++)
{
sum += blurBuffer[a+b+2] * imageToInt[col+width*row];
}
}
outputBuffer[col + width * row] = sum;
What's missing is the entire getBytes and ToInt stuff.
How can I do that in openCL?
Thanks in advance and have a great weekend!