|
|
|
@ -2716,6 +2716,8 @@ struct mRGBA2RGBA |
|
|
|
|
|
|
|
|
|
#ifdef HAVE_OPENCL |
|
|
|
|
|
|
|
|
|
#define DIVUP(total, grain) (((total) + (grain) - 1) / (grain)) |
|
|
|
|
|
|
|
|
|
static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) |
|
|
|
|
{ |
|
|
|
|
bool ok = false; |
|
|
|
@ -2729,6 +2731,17 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) |
|
|
|
|
if (depth != CV_8U && depth != CV_16U && depth != CV_32F) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
cv::String opts = format("-D depth=%d -D scn=%d ", depth, scn); |
|
|
|
|
|
|
|
|
|
ocl::Device dev = ocl::Device::getDefault(); |
|
|
|
|
int pxPerWIy = 1; |
|
|
|
|
if (dev.isIntel() && (dev.type() & ocl::Device::TYPE_GPU)) |
|
|
|
|
{ |
|
|
|
|
pxPerWIy = 4; |
|
|
|
|
} |
|
|
|
|
globalsize[1] = DIVUP(globalsize[1], pxPerWIy); |
|
|
|
|
opts += format("-D PIX_PER_WI_Y=%d ", pxPerWIy); |
|
|
|
|
|
|
|
|
|
switch (code) |
|
|
|
|
{ |
|
|
|
|
case COLOR_BGR2BGRA: case COLOR_RGB2BGRA: case COLOR_BGRA2BGR: |
|
|
|
@ -2738,7 +2751,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) |
|
|
|
|
dcn = code == COLOR_BGR2BGRA || code == COLOR_RGB2BGRA || code == COLOR_BGRA2RGBA ? 4 : 3; |
|
|
|
|
bool reverse = !(code == COLOR_BGR2BGRA || code == COLOR_BGRA2BGR); |
|
|
|
|
k.create("RGB", ocl::imgproc::cvtcolor_oclsrc, |
|
|
|
|
format("-D depth=%d -D scn=%d -D dcn=%d -D bidx=0 -D %s", depth, scn, dcn, |
|
|
|
|
opts + format("-D dcn=%d -D bidx=0 -D %s", dcn, |
|
|
|
|
reverse ? "REVERSE" : "ORDER")); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
@ -2752,7 +2765,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) |
|
|
|
|
int greenbits = code == COLOR_BGR5652BGR || code == COLOR_BGR5652RGB || |
|
|
|
|
code == COLOR_BGR5652BGRA || code == COLOR_BGR5652RGBA ? 6 : 5; |
|
|
|
|
k.create("RGB5x52RGB", ocl::imgproc::cvtcolor_oclsrc, |
|
|
|
|
format("-D depth=%d -D scn=2 -D dcn=%d -D bidx=%d -D greenbits=%d", depth, dcn, bidx, greenbits)); |
|
|
|
|
opts + format("-D dcn=%d -D bidx=%d -D greenbits=%d", dcn, bidx, greenbits)); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case COLOR_BGR2BGR565: case COLOR_BGR2BGR555: case COLOR_RGB2BGR565: case COLOR_RGB2BGR555: |
|
|
|
@ -2765,7 +2778,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) |
|
|
|
|
code == COLOR_BGRA2BGR565 || code == COLOR_RGBA2BGR565 ? 6 : 5; |
|
|
|
|
dcn = 2; |
|
|
|
|
k.create("RGB2RGB5x5", ocl::imgproc::cvtcolor_oclsrc, |
|
|
|
|
format("-D depth=%d -D scn=%d -D dcn=2 -D bidx=%d -D greenbits=%d", depth, scn, bidx, greenbits)); |
|
|
|
|
opts + format("-D dcn=2 -D bidx=%d -D greenbits=%d", bidx, greenbits)); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case COLOR_BGR5652GRAY: case COLOR_BGR5552GRAY: |
|
|
|
@ -2774,7 +2787,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) |
|
|
|
|
dcn = 1; |
|
|
|
|
int greenbits = code == COLOR_BGR5652GRAY ? 6 : 5; |
|
|
|
|
k.create("BGR5x52Gray", ocl::imgproc::cvtcolor_oclsrc, |
|
|
|
|
format("-D depth=%d -D scn=2 -D dcn=1 -D bidx=0 -D greenbits=%d", depth, greenbits)); |
|
|
|
|
opts + format("-D dcn=1 -D bidx=0 -D greenbits=%d", greenbits)); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case COLOR_GRAY2BGR565: case COLOR_GRAY2BGR555: |
|
|
|
@ -2783,7 +2796,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) |
|
|
|
|
dcn = 2; |
|
|
|
|
int greenbits = code == COLOR_GRAY2BGR565 ? 6 : 5; |
|
|
|
|
k.create("Gray2BGR5x5", ocl::imgproc::cvtcolor_oclsrc, |
|
|
|
|
format("-D depth=%d -D scn=1 -D dcn=2 -D bidx=0 -D greenbits=%d", depth, greenbits)); |
|
|
|
|
opts + format("-D dcn=2 -D bidx=0 -D greenbits=%d", greenbits)); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case COLOR_BGR2GRAY: case COLOR_BGRA2GRAY: |
|
|
|
@ -2793,8 +2806,8 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) |
|
|
|
|
bidx = code == COLOR_BGR2GRAY || code == COLOR_BGRA2GRAY ? 0 : 2; |
|
|
|
|
dcn = 1; |
|
|
|
|
k.create("RGB2Gray", ocl::imgproc::cvtcolor_oclsrc, |
|
|
|
|
format("-D depth=%d -D scn=%d -D dcn=1 -D bidx=%d -D STRIPE_SIZE=%d", |
|
|
|
|
depth, scn, bidx, stripeSize)); |
|
|
|
|
opts + format("-D dcn=1 -D bidx=%d -D STRIPE_SIZE=%d", |
|
|
|
|
bidx, stripeSize)); |
|
|
|
|
globalsize[0] = (src.cols + stripeSize-1)/stripeSize; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
@ -2804,7 +2817,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) |
|
|
|
|
CV_Assert(scn == 1); |
|
|
|
|
dcn = code == COLOR_GRAY2BGRA ? 4 : 3; |
|
|
|
|
k.create("Gray2RGB", ocl::imgproc::cvtcolor_oclsrc, |
|
|
|
|
format("-D depth=%d -D bidx=0 -D scn=1 -D dcn=%d", depth, dcn)); |
|
|
|
|
opts + format("-D bidx=0 -D dcn=%d", dcn)); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case COLOR_BGR2YUV: |
|
|
|
@ -2814,7 +2827,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) |
|
|
|
|
bidx = code == COLOR_RGB2YUV ? 0 : 2; |
|
|
|
|
dcn = 3; |
|
|
|
|
k.create("RGB2YUV", ocl::imgproc::cvtcolor_oclsrc, |
|
|
|
|
format("-D depth=%d -D scn=%d -D dcn=3 -D bidx=%d", depth, scn, bidx)); |
|
|
|
|
opts + format("-D dcn=3 -D bidx=%d", bidx)); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case COLOR_YUV2BGR: |
|
|
|
@ -2824,7 +2837,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) |
|
|
|
|
CV_Assert(dcn == 3 || dcn == 4); |
|
|
|
|
bidx = code == COLOR_YUV2RGB ? 0 : 2; |
|
|
|
|
k.create("YUV2RGB", ocl::imgproc::cvtcolor_oclsrc, |
|
|
|
|
format("-D depth=%d -D scn=3 -D dcn=%d -D bidx=%d", depth, dcn, bidx)); |
|
|
|
|
opts + format("-D dcn=%d -D bidx=%d", dcn, bidx)); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case COLOR_YUV2RGB_NV12: case COLOR_YUV2BGR_NV12: |
|
|
|
@ -2837,7 +2850,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) |
|
|
|
|
|
|
|
|
|
dstSz = Size(sz.width, sz.height * 2 / 3); |
|
|
|
|
k.create("YUV2RGB_NV12", ocl::imgproc::cvtcolor_oclsrc, |
|
|
|
|
format("-D depth=0 -D scn=1 -D dcn=%d -D bidx=%d", dcn, bidx)); |
|
|
|
|
opts + format("-D dcn=%d -D bidx=%d", dcn, bidx)); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case COLOR_BGR2YCrCb: |
|
|
|
@ -2847,7 +2860,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) |
|
|
|
|
bidx = code == COLOR_BGR2YCrCb ? 0 : 2; |
|
|
|
|
dcn = 3; |
|
|
|
|
k.create("RGB2YCrCb", ocl::imgproc::cvtcolor_oclsrc, |
|
|
|
|
format("-D depth=%d -D scn=%d -D dcn=3 -D bidx=%d", depth, scn, bidx)); |
|
|
|
|
opts + format("-D dcn=3 -D bidx=%d", bidx)); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case COLOR_YCrCb2BGR: |
|
|
|
@ -2858,7 +2871,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) |
|
|
|
|
CV_Assert(scn == 3 && (dcn == 3 || dcn == 4)); |
|
|
|
|
bidx = code == COLOR_YCrCb2BGR ? 0 : 2; |
|
|
|
|
k.create("YCrCb2RGB", ocl::imgproc::cvtcolor_oclsrc, |
|
|
|
|
format("-D depth=%d -D scn=%d -D dcn=%d -D bidx=%d", depth, scn, dcn, bidx)); |
|
|
|
|
opts + format("-D dcn=%d -D bidx=%d", dcn, bidx)); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case COLOR_BGR2XYZ: case COLOR_RGB2XYZ: |
|
|
|
@ -2904,7 +2917,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) |
|
|
|
|
dst = _dst.getUMat(); |
|
|
|
|
|
|
|
|
|
k.create("RGB2XYZ", ocl::imgproc::cvtcolor_oclsrc, |
|
|
|
|
format("-D depth=%d -D scn=%d -D dcn=3 -D bidx=%d", depth, scn, bidx)); |
|
|
|
|
opts + format("-D dcn=3 -D bidx=%d", bidx)); |
|
|
|
|
if (k.empty()) |
|
|
|
|
return false; |
|
|
|
|
k.args(ocl::KernelArg::ReadOnlyNoSize(src), ocl::KernelArg::WriteOnly(dst), ocl::KernelArg::PtrReadOnly(c)); |
|
|
|
@ -2955,7 +2968,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) |
|
|
|
|
dst = _dst.getUMat(); |
|
|
|
|
|
|
|
|
|
k.create("XYZ2RGB", ocl::imgproc::cvtcolor_oclsrc, |
|
|
|
|
format("-D depth=%d -D scn=3 -D dcn=%d -D bidx=%d", depth, dcn, bidx)); |
|
|
|
|
opts + format("-D dcn=%d -D bidx=%d", dcn, bidx)); |
|
|
|
|
if (k.empty()) |
|
|
|
|
return false; |
|
|
|
|
k.args(ocl::KernelArg::ReadOnlyNoSize(src), ocl::KernelArg::WriteOnly(dst), ocl::KernelArg::PtrReadOnly(c)); |
|
|
|
@ -3010,8 +3023,9 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) |
|
|
|
|
_dst.create(dstSz, CV_8UC3); |
|
|
|
|
dst = _dst.getUMat(); |
|
|
|
|
|
|
|
|
|
k.create("RGB2HSV", ocl::imgproc::cvtcolor_oclsrc, format("-D depth=%d -D hrange=%d -D bidx=%d -D dcn=3 -D scn=%d", |
|
|
|
|
depth, hrange, bidx, scn)); |
|
|
|
|
k.create("RGB2HSV", ocl::imgproc::cvtcolor_oclsrc, |
|
|
|
|
opts + format("-D hrange=%d -D bidx=%d -D dcn=3", |
|
|
|
|
hrange, bidx)); |
|
|
|
|
if (k.empty()) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
@ -3023,7 +3037,8 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
k.create(kernelName.c_str(), ocl::imgproc::cvtcolor_oclsrc, |
|
|
|
|
format("-D depth=%d -D hscale=%ff -D bidx=%d -D scn=%d -D dcn=3", depth, hrange*(1.f/360.f), bidx, scn)); |
|
|
|
|
opts + format("-D hscale=%ff -D bidx=%d -D dcn=3", |
|
|
|
|
hrange*(1.f/360.f), bidx)); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case COLOR_HSV2BGR: case COLOR_HSV2RGB: case COLOR_HSV2BGR_FULL: case COLOR_HSV2RGB_FULL: |
|
|
|
@ -3041,8 +3056,8 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) |
|
|
|
|
|
|
|
|
|
String kernelName = String(is_hsv ? "HSV" : "HLS") + "2RGB"; |
|
|
|
|
k.create(kernelName.c_str(), ocl::imgproc::cvtcolor_oclsrc, |
|
|
|
|
format("-D depth=%d -D dcn=%d -D scn=3 -D bidx=%d -D hrange=%d -D hscale=%ff", |
|
|
|
|
depth, dcn, bidx, hrange, 6.f/hrange)); |
|
|
|
|
opts + format("-D dcn=%d -D bidx=%d -D hrange=%d -D hscale=%ff", |
|
|
|
|
dcn, bidx, hrange, 6.f/hrange)); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case COLOR_RGBA2mRGBA: case COLOR_mRGBA2RGBA: |
|
|
|
@ -3051,7 +3066,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) |
|
|
|
|
dcn = 4; |
|
|
|
|
|
|
|
|
|
k.create(code == COLOR_RGBA2mRGBA ? "RGBA2mRGBA" : "mRGBA2RGBA", ocl::imgproc::cvtcolor_oclsrc, |
|
|
|
|
format("-D depth=%d -D dcn=4 -D scn=4 -D bidx=3", depth)); |
|
|
|
|
opts + "-D dcn=4 -D bidx=3"); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case CV_BGR2Lab: case CV_RGB2Lab: case CV_LBGR2Lab: case CV_LRGB2Lab: |
|
|
|
@ -3063,8 +3078,8 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) |
|
|
|
|
dcn = 3; |
|
|
|
|
|
|
|
|
|
k.create("BGR2Lab", ocl::imgproc::cvtcolor_oclsrc, |
|
|
|
|
format("-D depth=%d -D dcn=3 -D scn=%d -D bidx=%d%s", |
|
|
|
|
depth, scn, bidx, srgb ? " -D SRGB" : "")); |
|
|
|
|
opts + format("-D dcn=3 -D bidx=%d%s", |
|
|
|
|
bidx, srgb ? " -D SRGB" : "")); |
|
|
|
|
if (k.empty()) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
@ -3165,8 +3180,8 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) |
|
|
|
|
bool srgb = code == CV_Lab2BGR || code == CV_Lab2RGB; |
|
|
|
|
|
|
|
|
|
k.create("Lab2BGR", ocl::imgproc::cvtcolor_oclsrc, |
|
|
|
|
format("-D depth=%d -D dcn=%d -D scn=3 -D bidx=%d%s", |
|
|
|
|
depth, dcn, bidx, srgb ? " -D SRGB" : "")); |
|
|
|
|
opts + format("-D dcn=%d -D bidx=%d%s", |
|
|
|
|
dcn, bidx, srgb ? " -D SRGB" : "")); |
|
|
|
|
if (k.empty()) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|