Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __kernel void sepiaFilterKernel(
- __global const unsigned char* in,
- __global unsigned char* out,
- int count)
- {
- int i = get_global_id(0);
- if(i < count) {
- unsigned char b = in[i * 4];
- unsigned char g = in[i * 4 + 1];
- unsigned char r = in[i * 4 + 2];
- double sepiaR = (r * 0.393) + (g * 0.769) + (b * 0.189);
- double sepiaG = (r * 0.349) + (g * 0.686) + (b * 0.168);
- double sepiaB = (r * 0.272) + (g * 0.534) + (b * 0.131);
- if (sepiaR > 255) sepiaR = 255;
- if (sepiaG > 255) sepiaG = 255;
- if (sepiaB > 255) sepiaB = 255;
- if (sepiaR < 0) sepiaR = 0;
- if (sepiaG < 0) sepiaG = 0;
- if (sepiaB < 0) sepiaB = 0;
- out[i * 4] = (char)sepiaB;
- out[i * 4 + 1] = (char)sepiaG;
- out[i * 4 + 2] = (char)sepiaR;
- out[i * 4 + 3] = in[i * 4 + 3];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement