|
|
|
@ -81,6 +81,7 @@ enum |
|
|
|
|
{ |
|
|
|
|
yuv_shift = 14, |
|
|
|
|
xyz_shift = 12, |
|
|
|
|
hsv_shift = 12, |
|
|
|
|
R2Y = 4899, |
|
|
|
|
G2Y = 9617, |
|
|
|
|
B2Y = 1868, |
|
|
|
@ -90,6 +91,14 @@ enum |
|
|
|
|
#define scnbytes ((int)sizeof(DATA_TYPE)*scn) |
|
|
|
|
#define dcnbytes ((int)sizeof(DATA_TYPE)*dcn) |
|
|
|
|
|
|
|
|
|
#ifndef hscale |
|
|
|
|
#define hscale 0 |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#ifndef hrange |
|
|
|
|
#define hrange 0 |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
///////////////////////////////////// RGB <-> GRAY ////////////////////////////////////// |
|
|
|
|
|
|
|
|
|
__kernel void RGB2Gray(__global const uchar* srcptr, int srcstep, int srcoffset, |
|
|
|
@ -352,7 +361,7 @@ __kernel void YCrCb2RGB(__global const uchar* src, int src_step, int src_offset, |
|
|
|
|
|
|
|
|
|
__kernel void RGB2XYZ(__global const uchar * srcptr, int src_step, int src_offset, |
|
|
|
|
__global uchar * dstptr, int dst_step, int dst_offset, |
|
|
|
|
int rows, int cols, __constant COEFF_TYPE * coeffs, int a1, int a2) |
|
|
|
|
int rows, int cols, __constant COEFF_TYPE * coeffs) |
|
|
|
|
{ |
|
|
|
|
int dx = get_global_id(0); |
|
|
|
|
int dy = get_global_id(1); |
|
|
|
@ -384,7 +393,7 @@ __kernel void RGB2XYZ(__global const uchar * srcptr, int src_step, int src_offse |
|
|
|
|
|
|
|
|
|
__kernel void XYZ2RGB(__global const uchar * srcptr, int src_step, int src_offset, |
|
|
|
|
__global uchar * dstptr, int dst_step, int dst_offset, |
|
|
|
|
int rows, int cols, __constant COEFF_TYPE * coeffs, int a1, int a2) |
|
|
|
|
int rows, int cols, __constant COEFF_TYPE * coeffs) |
|
|
|
|
{ |
|
|
|
|
int dx = get_global_id(0); |
|
|
|
|
int dy = get_global_id(1); |
|
|
|
@ -454,7 +463,6 @@ __kernel void RGB(__global const uchar* srcptr, int src_step, int src_offset, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////// RGB5x5 <-> RGB ////////////////////////////////////// |
|
|
|
|
|
|
|
|
|
__kernel void RGB5x52RGB(__global const uchar* src, int src_step, int src_offset, |
|
|
|
@ -562,7 +570,212 @@ __kernel void Gray2BGR5x5(__global const uchar* src, int src_step, int src_offse |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//////////////////////////////////// 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(__global const uchar* src, int src_step, int src_offset, |
|
|
|
|
__global uchar* dst, int dst_step, int dst_offset, |
|
|
|
|
int rows, int cols, |
|
|
|
|
__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) |
|
|
|
|
{ |
|
|
|
|
int src_idx = mad24(y, src_step, src_offset + x * scnbytes); |
|
|
|
|
int dst_idx = mad24(y, dst_step, dst_offset + x * dcnbytes); |
|
|
|
|
|
|
|
|
|
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(__global const uchar* src, int src_step, int src_offset, |
|
|
|
|
__global uchar* dst, int dst_step, int dst_offset, |
|
|
|
|
int rows, int cols) |
|
|
|
|
{ |
|
|
|
|
int x = get_global_id(0); |
|
|
|
|
int y = get_global_id(1); |
|
|
|
|
|
|
|
|
|
if (y < rows && x < cols) |
|
|
|
|
{ |
|
|
|
|
int src_idx = mad24(y, src_step, src_offset + x * scnbytes); |
|
|
|
|
int dst_idx = mad24(y, dst_step, dst_offset + x * dcnbytes); |
|
|
|
|
|
|
|
|
|
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(__global const uchar* srcptr, int src_step, int src_offset, |
|
|
|
|
__global uchar* dstptr, int dst_step, int dst_offset, |
|
|
|
|
int rows, int cols) |
|
|
|
|
{ |
|
|
|
|
int x = get_global_id(0); |
|
|
|
|
int y = get_global_id(1); |
|
|
|
|
|
|
|
|
|
if (y < rows && x < cols) |
|
|
|
|
{ |
|
|
|
|
int src_idx = mad24(y, src_step, src_offset + x * scnbytes); |
|
|
|
|
int dst_idx = mad24(y, dst_step, dst_offset + x * dcnbytes); |
|
|
|
|
|
|
|
|
|
__global const float * src = (__global const float *)(srcptr + src_idx); |
|
|
|
|
__global float * dst = (__global float *)(dstptr + dst_idx); |
|
|
|
|
|
|
|
|
|
float b = src[bidx], g = src[1], r = src[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[0] = h*hscale; |
|
|
|
|
dst[1] = s; |
|
|
|
|
dst[2] = v; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
__kernel void HSV2RGB(__global const uchar* srcptr, int src_step, int src_offset, |
|
|
|
|
__global uchar* dstptr, int dst_step, int dst_offset, |
|
|
|
|
int rows, int cols) |
|
|
|
|
{ |
|
|
|
|
int x = get_global_id(0); |
|
|
|
|
int y = get_global_id(1); |
|
|
|
|
|
|
|
|
|
if (y < rows && x < cols) |
|
|
|
|
{ |
|
|
|
|
int src_idx = mad24(y, src_step, src_offset + x * scnbytes); |
|
|
|
|
int dst_idx = mad24(y, dst_step, dst_offset + x * dcnbytes); |
|
|
|
|
|
|
|
|
|
__global const float * src = (__global const float *)(srcptr + src_idx); |
|
|
|
|
__global float * dst = (__global float *)(dstptr + dst_idx); |
|
|
|
|
|
|
|
|
|
float h = src[0], s = src[1], v = src[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[bidx] = b; |
|
|
|
|
dst[1] = g; |
|
|
|
|
dst[bidx^2] = r; |
|
|
|
|
#if dcn == 4 |
|
|
|
|
dst[3] = MAX_NUM; |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|