Skip to content

Instantly share code, notes, and snippets.

@emoon
Created May 26, 2012 18:23
Show Gist options
  • Save emoon/2794856 to your computer and use it in GitHub Desktop.
Save emoon/2794856 to your computer and use it in GitHub Desktop.
const char* s_mapPixelKernelSource = "\n" \
"__kernel void mapPixel( \n" \
" __global uchar* output, \n" \
" __global uchar4* input, \n" \
" __constant float4* pal, \n" \
" const unsigned int palCount, \n" \
" const unsigned int width) \n" \
"{ \n" \
" const int xOut = get_global_id(0); \n" \
" const int yOut = get_global_id(1); \n" \
" const int offset = (yOut * width) + xOut; \n" \
" uint i, bestIndex = 0; \n" \
" float bestDist = MAXFLOAT; \n" \
" \n" \
" float4 pixel = convert_float4(input[offset]); \n" \
" for (i = 0; i < palCount; ++i) \n" \
" { \n" \
" float4 diff = pixel - pal[i]; \n" \
" float dist = dot(diff, diff); \n" \
" if (dist < bestDist) \n" \
" { \n" \
" bestDist = dist; \n" \
" bestIndex = i; \n" \
" } \n" \
" } \n" \
" \n" \
" output[offset] = (uchar)bestIndex; \n" \
"} \n" \
"\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment