|
|
|
@ -91,206 +91,8 @@ enum |
|
|
|
|
BLOCK_SIZE = 256 |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
//////////////////////////////////// RGB <-> HSV ////////////////////////////////////// |
|
|
|
|
|
|
|
|
|
__constant int sector_data[][3] = { {1, 3, 0}, { 1, 0, 2 }, { 3, 0, 1 }, { 0, 2, 1 }, { 0, 1, 3 }, { 2, 1, 0 } }; |
|
|
|
|
|
|
|
|
|
#ifdef DEPTH_0 |
|
|
|
|
|
|
|
|
|
__kernel void RGB2HSV(int cols, int rows, int src_step, int dst_step, int bidx, |
|
|
|
|
__global const uchar * src, __global uchar * dst, |
|
|
|
|
int src_offset, int dst_offset, |
|
|
|
|
__constant int * sdiv_table, __constant int * hdiv_table) |
|
|
|
|
{ |
|
|
|
|
int x = get_global_id(0); |
|
|
|
|
int y = get_global_id(1); |
|
|
|
|
|
|
|
|
|
if (y < rows && x < cols) |
|
|
|
|
{ |
|
|
|
|
x <<= 2; |
|
|
|
|
int src_idx = mad24(y, src_step, src_offset + x); |
|
|
|
|
int dst_idx = mad24(y, dst_step, dst_offset + x); |
|
|
|
|
|
|
|
|
|
int b = src[src_idx + bidx], g = src[src_idx + 1], r = src[src_idx + (bidx^2)]; |
|
|
|
|
int h, s, v = b; |
|
|
|
|
int vmin = b, diff; |
|
|
|
|
int vr, vg; |
|
|
|
|
|
|
|
|
|
v = max( v, g ); |
|
|
|
|
v = max( v, r ); |
|
|
|
|
vmin = min( vmin, g ); |
|
|
|
|
vmin = min( vmin, r ); |
|
|
|
|
|
|
|
|
|
diff = v - vmin; |
|
|
|
|
vr = v == r ? -1 : 0; |
|
|
|
|
vg = v == g ? -1 : 0; |
|
|
|
|
|
|
|
|
|
s = (diff * sdiv_table[v] + (1 << (hsv_shift-1))) >> hsv_shift; |
|
|
|
|
h = (vr & (g - b)) + |
|
|
|
|
(~vr & ((vg & (b - r + 2 * diff)) + ((~vg) & (r - g + 4 * diff)))); |
|
|
|
|
h = (h * hdiv_table[diff] + (1 << (hsv_shift-1))) >> hsv_shift; |
|
|
|
|
h += h < 0 ? hrange : 0; |
|
|
|
|
|
|
|
|
|
dst[dst_idx] = convert_uchar_sat_rte(h); |
|
|
|
|
dst[dst_idx + 1] = (uchar)s; |
|
|
|
|
dst[dst_idx + 2] = (uchar)v; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
__kernel void HSV2RGB(int cols, int rows, int src_step, int dst_step, int bidx, |
|
|
|
|
__global const uchar * src, __global uchar * dst, |
|
|
|
|
int src_offset, int dst_offset) |
|
|
|
|
{ |
|
|
|
|
int x = get_global_id(0); |
|
|
|
|
int y = get_global_id(1); |
|
|
|
|
|
|
|
|
|
if (y < rows && x < cols) |
|
|
|
|
{ |
|
|
|
|
x <<= 2; |
|
|
|
|
int src_idx = mad24(y, src_step, src_offset + x); |
|
|
|
|
int dst_idx = mad24(y, dst_step, dst_offset + x); |
|
|
|
|
|
|
|
|
|
float h = src[src_idx], s = src[src_idx + 1]*(1/255.f), v = src[src_idx + 2]*(1/255.f); |
|
|
|
|
float b, g, r; |
|
|
|
|
|
|
|
|
|
if (s != 0) |
|
|
|
|
{ |
|
|
|
|
float tab[4]; |
|
|
|
|
int sector; |
|
|
|
|
h *= hscale; |
|
|
|
|
if( h < 0 ) |
|
|
|
|
do h += 6; while( h < 0 ); |
|
|
|
|
else if( h >= 6 ) |
|
|
|
|
do h -= 6; while( h >= 6 ); |
|
|
|
|
sector = convert_int_sat_rtn(h); |
|
|
|
|
h -= sector; |
|
|
|
|
if( (unsigned)sector >= 6u ) |
|
|
|
|
{ |
|
|
|
|
sector = 0; |
|
|
|
|
h = 0.f; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
tab[0] = v; |
|
|
|
|
tab[1] = v*(1.f - s); |
|
|
|
|
tab[2] = v*(1.f - s*h); |
|
|
|
|
tab[3] = v*(1.f - s*(1.f - h)); |
|
|
|
|
|
|
|
|
|
b = tab[sector_data[sector][0]]; |
|
|
|
|
g = tab[sector_data[sector][1]]; |
|
|
|
|
r = tab[sector_data[sector][2]]; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
b = g = r = v; |
|
|
|
|
|
|
|
|
|
dst[dst_idx + bidx] = convert_uchar_sat_rte(b*255.f); |
|
|
|
|
dst[dst_idx + 1] = convert_uchar_sat_rte(g*255.f); |
|
|
|
|
dst[dst_idx + (bidx^2)] = convert_uchar_sat_rte(r*255.f); |
|
|
|
|
#if dcn == 4 |
|
|
|
|
dst[dst_idx + 3] = MAX_NUM; |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#elif defined DEPTH_5 |
|
|
|
|
|
|
|
|
|
__kernel void RGB2HSV(int cols, int rows, int src_step, int dst_step, int bidx, |
|
|
|
|
__global const float * src, __global float * dst, |
|
|
|
|
int src_offset, int dst_offset) |
|
|
|
|
{ |
|
|
|
|
int x = get_global_id(0); |
|
|
|
|
int y = get_global_id(1); |
|
|
|
|
|
|
|
|
|
if (y < rows && x < cols) |
|
|
|
|
{ |
|
|
|
|
x <<= 2; |
|
|
|
|
int src_idx = mad24(y, src_step, src_offset + x); |
|
|
|
|
int dst_idx = mad24(y, dst_step, dst_offset + x); |
|
|
|
|
|
|
|
|
|
float b = src[src_idx + bidx], g = src[src_idx + 1], r = src[src_idx + (bidx^2)]; |
|
|
|
|
float h, s, v; |
|
|
|
|
|
|
|
|
|
float vmin, diff; |
|
|
|
|
|
|
|
|
|
v = vmin = r; |
|
|
|
|
if( v < g ) v = g; |
|
|
|
|
if( v < b ) v = b; |
|
|
|
|
if( vmin > g ) vmin = g; |
|
|
|
|
if( vmin > b ) vmin = b; |
|
|
|
|
|
|
|
|
|
diff = v - vmin; |
|
|
|
|
s = diff/(float)(fabs(v) + FLT_EPSILON); |
|
|
|
|
diff = (float)(60./(diff + FLT_EPSILON)); |
|
|
|
|
if( v == r ) |
|
|
|
|
h = (g - b)*diff; |
|
|
|
|
else if( v == g ) |
|
|
|
|
h = (b - r)*diff + 120.f; |
|
|
|
|
else |
|
|
|
|
h = (r - g)*diff + 240.f; |
|
|
|
|
|
|
|
|
|
if( h < 0 ) h += 360.f; |
|
|
|
|
|
|
|
|
|
dst[dst_idx] = h*hscale; |
|
|
|
|
dst[dst_idx + 1] = s; |
|
|
|
|
dst[dst_idx + 2] = v; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
__kernel void HSV2RGB(int cols, int rows, int src_step, int dst_step, int bidx, |
|
|
|
|
__global const float * src, __global float * dst, |
|
|
|
|
int src_offset, int dst_offset) |
|
|
|
|
{ |
|
|
|
|
int x = get_global_id(0); |
|
|
|
|
int y = get_global_id(1); |
|
|
|
|
|
|
|
|
|
if (y < rows && x < cols) |
|
|
|
|
{ |
|
|
|
|
x <<= 2; |
|
|
|
|
int src_idx = mad24(y, src_step, src_offset + x); |
|
|
|
|
int dst_idx = mad24(y, dst_step, dst_offset + x); |
|
|
|
|
|
|
|
|
|
float h = src[src_idx], s = src[src_idx + 1], v = src[src_idx + 2]; |
|
|
|
|
float b, g, r; |
|
|
|
|
|
|
|
|
|
if (s != 0) |
|
|
|
|
{ |
|
|
|
|
float tab[4]; |
|
|
|
|
int sector; |
|
|
|
|
h *= hscale; |
|
|
|
|
if(h < 0) |
|
|
|
|
do h += 6; while (h < 0); |
|
|
|
|
else if (h >= 6) |
|
|
|
|
do h -= 6; while (h >= 6); |
|
|
|
|
sector = convert_int_sat_rtn(h); |
|
|
|
|
h -= sector; |
|
|
|
|
if ((unsigned)sector >= 6u) |
|
|
|
|
{ |
|
|
|
|
sector = 0; |
|
|
|
|
h = 0.f; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
tab[0] = v; |
|
|
|
|
tab[1] = v*(1.f - s); |
|
|
|
|
tab[2] = v*(1.f - s*h); |
|
|
|
|
tab[3] = v*(1.f - s*(1.f - h)); |
|
|
|
|
|
|
|
|
|
b = tab[sector_data[sector][0]]; |
|
|
|
|
g = tab[sector_data[sector][1]]; |
|
|
|
|
r = tab[sector_data[sector][2]]; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
b = g = r = v; |
|
|
|
|
|
|
|
|
|
dst[dst_idx + bidx] = b; |
|
|
|
|
dst[dst_idx + 1] = g; |
|
|
|
|
dst[dst_idx + (bidx^2)] = r; |
|
|
|
|
#if dcn == 4 |
|
|
|
|
dst[dst_idx + 3] = MAX_NUM; |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
///////////////////////////////////// RGB <-> HLS ////////////////////////////////////// |
|
|
|
|
|
|
|
|
|
#ifdef DEPTH_0 |
|
|
|
|