#define TYPE int
#define FILTERSIZE 1000
#define MAX FILTERSIZE
void quickSort(int *array, int length)//non-recursive algorithm
{
int piv, begin[MAX], end[MAX];
int i=0 ;
....
//quick sort
}
void Sort(TYPE *tab, int tailleTableau){ //bubble sort
int i, k;
TYPE temp;
for(k = 0; k < (tailleTableau/2)+1; k++) {
for(i = 0; i < tailleTableau-1; i++) {
if(tab[i] > tab[i+1])
{
temp=tab[i];
tab[i]=tab[i+1];
tab[i+1]=temp;
}
}
}
}
__kernel void median(__global const TYPE *inputBuffer,
__global TYPE *outputBuffer,
__global const int *filterIndex,
const int filterIndexSize,
const int InputBufferSize)
{
unsigned int x = get_global_id(0);
TYPE pixel;
unsigned int i;
long offsetIndex;
TYPE neighborhood[FILTERSIZE];
pixel = 0;
for(i=0; i< filterIndexSize; i++)
{
offsetIndex = x + filterIndex[i];
if(offsetIndex >= 0 && offsetIndex < InputBufferSize ) // in image buffer bound
{
neighborhood[i] = inputBuffer[offsetIndex];
}
}
// Sort(neighborhood, filterIndexSize);
quickSort(neighborhood, filterIndexSize);
pixel = neighborhood[(int)(filterIndexSize/2)];
outputBuffer[x] = pixel;
}