Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. __kernel void sepiaFilterKernel(
  2. __global const unsigned char* in,
  3. __global unsigned char* out,
  4. int count)
  5. {
  6. int i = get_global_id(0);
  7. if(i < count) {
  8.  
  9. unsigned char b = in[i * 4];
  10. unsigned char g = in[i * 4 + 1];
  11. unsigned char r = in[i * 4 + 2];
  12.  
  13. double sepiaR = (r * 0.393) + (g * 0.769) + (b * 0.189);
  14. double sepiaG = (r * 0.349) + (g * 0.686) + (b * 0.168);
  15. double sepiaB = (r * 0.272) + (g * 0.534) + (b * 0.131);
  16.  
  17. if (sepiaR > 255) sepiaR = 255;
  18. if (sepiaG > 255) sepiaG = 255;
  19. if (sepiaB > 255) sepiaB = 255;
  20. if (sepiaR < 0) sepiaR = 0;
  21. if (sepiaG < 0) sepiaG = 0;
  22. if (sepiaB < 0) sepiaB = 0;
  23.  
  24. out[i * 4] = (char)sepiaB;
  25. out[i * 4 + 1] = (char)sepiaG;
  26. out[i * 4 + 2] = (char)sepiaR;
  27. out[i * 4 + 3] = in[i * 4 + 3];
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement