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.
94 lines
2.3 KiB
94 lines
2.3 KiB
5 years ago
|
// #define TEST
|
||
|
#define X 95
|
||
|
#define Y 22
|
||
5 years ago
|
|
||
5 years ago
|
//#define USE_DBL
|
||
5 years ago
|
#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;
|
||
|
|
||
5 years ago
|
|
||
|
struct input {
|
||
|
int filter_width;
|
||
|
int filter_height;
|
||
|
int width;
|
||
|
int height;
|
||
|
};
|
||
|
|
||
5 years ago
|
TYPE_FLT read_data(image2d_t input_frame, int x, int z)
|
||
|
{
|
||
|
int2 gid = (int2)(x, z);
|
||
|
uint4 pixel = read_imageui(input_frame, sampler, gid);
|
||
|
TYPE_INT temp = (TYPE_INT)((TYPE_INT)pixel.x & MASK) |
|
||
|
(TYPE_INT)(((TYPE_INT)pixel.y & MASK) << SHIFT) |
|
||
|
(TYPE_INT)(((TYPE_INT)pixel.z & MASK) << (SHIFT * 2)) |
|
||
|
(TYPE_INT)(((TYPE_INT)pixel.w & MASK) << (SHIFT * 3));
|
||
|
TYPE_FLT raw_data = *((TYPE_FLT*)(&temp));
|
||
|
return raw_data;
|
||
|
}
|
||
|
|
||
|
|
||
5 years ago
|
kernel void Enhance(read_only image2d_t input_frame, read_write image2d_t output_frame, global TYPE_FLT* filter, struct input params)
|
||
|
{
|
||
5 years ago
|
int2 gid = (int2)(get_global_id(0), get_global_id(1));
|
||
|
TYPE_FLT input = read_data(input_frame, gid.x, gid.y);
|
||
5 years ago
|
TYPE_FLT output_data = 0;
|
||
5 years ago
|
|
||
5 years ago
|
int p = params.filter_height;
|
||
|
int q = params.filter_width;
|
||
5 years ago
|
|
||
5 years ago
|
int lag1 = (p - 1) / 2;
|
||
|
int lag2 = (q - 1) / 2;
|
||
5 years ago
|
|
||
5 years ago
|
if(gid.x >= lag2 && gid.x < params.width - lag2 && gid.y >= lag1 && gid.y < params.height - lag1)
|
||
|
{
|
||
|
for(int i = -lag1; i <= lag1 ; i++)
|
||
5 years ago
|
{
|
||
5 years ago
|
for(int j = -lag2; j <= lag2 ; j++)
|
||
|
{
|
||
|
if(gid.x == 947 && gid.y == 1)
|
||
|
{
|
||
|
printf("input: %f; ", output_data);
|
||
|
}
|
||
5 years ago
|
|
||
5 years ago
|
output_data += read_data(input_frame, gid.x + j, gid.y + i) * filter[(i + lag1) * q + (j + lag2)];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
5 years ago
|
{
|
||
5 years ago
|
output_data = input;
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
if(output_data < 0)
|
||
|
output_data = 0;
|
||
|
|
||
|
if(output_data > 255)
|
||
|
output_data = 255;
|
||
|
|
||
|
|
||
5 years ago
|
TYPE_INT out = *((TYPE_INT*)(&output_data));
|
||
|
uint4 pixel;
|
||
|
pixel.x = (TYPE_INT)(out & MASK);
|
||
|
pixel.y = (TYPE_INT)((out >> SHIFT) & MASK);
|
||
|
pixel.z = (TYPE_INT)((out >> (SHIFT *2)) & MASK);
|
||
|
pixel.w = (TYPE_INT)((out >> (SHIFT * 3)) & MASK);
|
||
|
|
||
|
write_imageui(output_frame, gid, pixel);
|
||
|
}
|
||
|
|