You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
2.0 KiB
100 lines
2.0 KiB
// #define TEST
|
|
#define X 100
|
|
#define Y 100
|
|
|
|
//#define USE_DBL
|
|
#ifdef USE_DBL
|
|
#define TYPE_FLT double
|
|
#define TYPE_INT long
|
|
#define MASK 0xFFFF
|
|
#define SHIFT 16
|
|
#define EPSILSON 4.94065645841247E-324
|
|
#else
|
|
#define TYPE_FLT float
|
|
#define TYPE_INT int
|
|
#define MASK 0x00FF
|
|
#define SHIFT 8
|
|
#define EPSILSON 1.401298E-45
|
|
#endif
|
|
|
|
constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE |
|
|
CLK_ADDRESS_CLAMP_TO_EDGE |
|
|
CLK_FILTER_LINEAR;
|
|
|
|
|
|
struct input {
|
|
int tint_map_selector;
|
|
};
|
|
|
|
|
|
kernel void TintMap(read_only image2d_t input_frame, read_write image2d_t output_frame, struct input params)
|
|
{
|
|
int2 gid = (int2)(get_global_id(0), get_global_id(1));
|
|
uint4 pixel = read_imageui(input_frame, sampler, gid);
|
|
|
|
private float r_step, g_step, b_step;
|
|
private int r_base, g_base, b_base;
|
|
|
|
switch(params.tint_map_selector)
|
|
{
|
|
//gray
|
|
case 0:
|
|
r_base = g_base = b_base = 0;
|
|
r_step = g_step = b_step = 1.0;
|
|
break;
|
|
//blue
|
|
case 1:
|
|
r_base = g_base = b_base = 0;
|
|
r_step = g_step = 0 ;
|
|
b_step = 1.0f;
|
|
break;
|
|
//cool blue
|
|
case 2:
|
|
r_base = 0;
|
|
g_base = b_base = 255;
|
|
r_step = 1.0f;
|
|
g_step = -1.0f;
|
|
b_step = 0;
|
|
break;
|
|
//copper
|
|
case 3:
|
|
r_base = g_base = b_base = 0;
|
|
r_step = 1.0f;
|
|
g_step = 0.7812f;
|
|
b_step = 0.4975f;
|
|
break;
|
|
//otherwise
|
|
case 4:
|
|
r_base = g_base = b_base = 0;
|
|
r_step = g_step = b_step = 1.0f;
|
|
break;
|
|
}
|
|
|
|
uchar data = pixel.x;
|
|
if(data > 0)
|
|
{
|
|
float r = r_base + data * r_step;
|
|
if(r < 0) r = 0;
|
|
if(r > 255) r = 255;
|
|
|
|
float g = g_base + data * g_step;
|
|
if(g < 0) g = 0;
|
|
if(g > 255) g = 255;
|
|
|
|
float b = b_base + data * b_step;
|
|
if(b < 0) b = 0;
|
|
if(b > 255) b = 255;
|
|
|
|
#ifdef TEST
|
|
if(gid.x == X && gid.y == Y)
|
|
printf("%u ---", out);
|
|
#endif
|
|
|
|
pixel.x = (uchar)b;
|
|
pixel.y = (uchar)g;
|
|
pixel.z = (uchar)r;
|
|
}
|
|
|
|
write_imageui(output_frame, gid, pixel);
|
|
}
|
|
|
|
|