mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
RGB[A] <-> XYZ
This commit is contained in:
@@ -2784,6 +2784,102 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
|
||||
format("-D depth=%d -D scn=%d -D dcn=%d -D bidx=%d", depth, scn, dcn, bidx));
|
||||
break;
|
||||
}
|
||||
case COLOR_BGR2XYZ: case COLOR_RGB2XYZ:
|
||||
{
|
||||
CV_Assert(scn == 3 || scn == 4);
|
||||
bidx = code == COLOR_BGR2XYZ ? 0 : 2;
|
||||
|
||||
UMat c;
|
||||
if (depth == CV_32F)
|
||||
{
|
||||
float coeffs[] =
|
||||
{
|
||||
0.412453f, 0.357580f, 0.180423f,
|
||||
0.212671f, 0.715160f, 0.072169f,
|
||||
0.019334f, 0.119193f, 0.950227f
|
||||
};
|
||||
if (bidx == 0)
|
||||
{
|
||||
std::swap(coeffs[0], coeffs[2]);
|
||||
std::swap(coeffs[3], coeffs[5]);
|
||||
std::swap(coeffs[6], coeffs[8]);
|
||||
}
|
||||
Mat(1, 9, CV_32FC1, &coeffs[0]).copyTo(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
int coeffs[] =
|
||||
{
|
||||
1689, 1465, 739,
|
||||
871, 2929, 296,
|
||||
79, 488, 3892
|
||||
};
|
||||
if (bidx == 0)
|
||||
{
|
||||
std::swap(coeffs[0], coeffs[2]);
|
||||
std::swap(coeffs[3], coeffs[5]);
|
||||
std::swap(coeffs[6], coeffs[8]);
|
||||
}
|
||||
Mat(1, 9, CV_32SC1, &coeffs[0]).copyTo(c);
|
||||
}
|
||||
|
||||
_dst.create(dstSz, CV_MAKETYPE(depth, 3));
|
||||
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));
|
||||
k.args(ocl::KernelArg::ReadOnlyNoSize(src), ocl::KernelArg::WriteOnly(dst), ocl::KernelArg::ReadOnlyNoSize(c));
|
||||
return k.run(2, globalsize, 0, false);
|
||||
}
|
||||
case COLOR_XYZ2BGR: case COLOR_XYZ2RGB:
|
||||
{
|
||||
if (dcn <= 0)
|
||||
dcn = 3;
|
||||
CV_Assert(scn == 3 && (dcn == 3 || dcn == 4));
|
||||
bidx = code == COLOR_XYZ2BGR ? 0 : 2;
|
||||
|
||||
UMat c;
|
||||
if (depth == CV_32F)
|
||||
{
|
||||
float coeffs[] =
|
||||
{
|
||||
3.240479f, -1.53715f, -0.498535f,
|
||||
-0.969256f, 1.875991f, 0.041556f,
|
||||
0.055648f, -0.204043f, 1.057311f
|
||||
};
|
||||
if (bidx == 0)
|
||||
{
|
||||
std::swap(coeffs[0], coeffs[6]);
|
||||
std::swap(coeffs[1], coeffs[7]);
|
||||
std::swap(coeffs[2], coeffs[8]);
|
||||
}
|
||||
Mat(1, 9, CV_32FC1, &coeffs[0]).copyTo(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
int coeffs[] =
|
||||
{
|
||||
13273, -6296, -2042,
|
||||
-3970, 7684, 170,
|
||||
228, -836, 4331
|
||||
};
|
||||
if (bidx == 0)
|
||||
{
|
||||
std::swap(coeffs[0], coeffs[6]);
|
||||
std::swap(coeffs[1], coeffs[7]);
|
||||
std::swap(coeffs[2], coeffs[8]);
|
||||
}
|
||||
Mat(1, 9, CV_32SC1, &coeffs[0]).copyTo(c);
|
||||
}
|
||||
|
||||
_dst.create(dstSz, CV_MAKETYPE(depth, 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));
|
||||
k.args(ocl::KernelArg::ReadOnlyNoSize(src), ocl::KernelArg::WriteOnly(dst), ocl::KernelArg::ReadOnlyNoSize(c));
|
||||
return k.run(2, globalsize, 0, false);
|
||||
}
|
||||
/*
|
||||
case COLOR_BGR5652GRAY: case COLOR_BGR5552GRAY:
|
||||
case COLOR_GRAY2BGR565: case COLOR_GRAY2BGR555:
|
||||
|
||||
Reference in New Issue
Block a user