mirror of
https://github.com/opencv/opencv.git
synced 2024-11-29 22:00:25 +08:00
cvtColor
This commit is contained in:
parent
5522c14efc
commit
2a051a124f
@ -692,7 +692,7 @@ int cv::countNonZero( InputArray _src )
|
||||
|
||||
Mat src = _src.getMat();
|
||||
|
||||
#if defined HAVE_IPP && !defined HAVE_IPP_ICV_ONLY
|
||||
#if defined HAVE_IPP && !defined HAVE_IPP_ICV_ONLY && 0
|
||||
if (src.dims <= 2 || src.isContinuous())
|
||||
{
|
||||
IppiSize roiSize = { src.cols, src.rows };
|
||||
|
@ -374,6 +374,18 @@ static ippiGeneralFunc ippiHLS2RGBTab[] =
|
||||
0, (ippiGeneralFunc)ippiHLSToRGB_32f_C3R, 0, 0
|
||||
};
|
||||
|
||||
static ippiGeneralFunc ippiRGBToLUVTab[] =
|
||||
{
|
||||
(ippiGeneralFunc)ippiRGBToLUV_8u_C3R, 0, (ippiGeneralFunc)ippiRGBToLUV_16u_C3R, 0,
|
||||
0, (ippiGeneralFunc)ippiRGBToLUV_32f_C3R, 0, 0
|
||||
};
|
||||
|
||||
static ippiGeneralFunc ippiLUVToRGBTab[] =
|
||||
{
|
||||
(ippiGeneralFunc)ippiLUVToRGB_8u_C3R, 0, (ippiGeneralFunc)ippiLUVToRGB_16u_C3R, 0,
|
||||
0, (ippiGeneralFunc)ippiLUVToRGB_32f_C3R, 0, 0
|
||||
};
|
||||
|
||||
struct IPPGeneralFunctor
|
||||
{
|
||||
IPPGeneralFunctor(ippiGeneralFunc _func) : func(_func){}
|
||||
@ -3323,6 +3335,34 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
|
||||
_dst.create(sz, CV_8UC2);
|
||||
dst = _dst.getMat();
|
||||
|
||||
#if defined HAVE_IPP
|
||||
CV_SUPPRESS_DEPRECATED_START
|
||||
if (code == CV_BGR2BGR565 && scn == 3)
|
||||
{
|
||||
if (CvtColorIPPLoop(src, dst, IPPGeneralFunctor((ippiGeneralFunc)ippiBGRToBGR565_8u16u_C3R)))
|
||||
return;
|
||||
}
|
||||
else if (code == CV_BGRA2BGR565)
|
||||
{
|
||||
if (CvtColorIPPLoopCopy(src, dst, IPPReorderGeneralFunctor(ippiSwapChannelsC4C3RTab[depth],
|
||||
(ippiGeneralFunc)ippiBGRToBGR565_8u16u_C3R, 0, 1, 2, depth)))
|
||||
return;
|
||||
}
|
||||
else if (code == CV_RGB2BGR565)
|
||||
{
|
||||
if( CvtColorIPPLoopCopy(src, dst, IPPReorderGeneralFunctor(ippiSwapChannelsC3RTab[depth],
|
||||
(ippiGeneralFunc)ippiBGRToBGR565_8u16u_C3R, 2, 1, 0, depth)) )
|
||||
return;
|
||||
}
|
||||
else if (code == CV_RGBA2BGR565)
|
||||
{
|
||||
if( CvtColorIPPLoopCopy(src, dst, IPPReorderGeneralFunctor(ippiSwapChannelsC4C3RTab[depth],
|
||||
(ippiGeneralFunc)ippiBGRToBGR565_8u16u_C3R, 2, 1, 0, depth)) )
|
||||
return;
|
||||
}
|
||||
CV_SUPPRESS_DEPRECATED_END
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TEGRA_OPTIMIZATION
|
||||
if(code == CV_BGR2BGR565 || code == CV_BGRA2BGR565 || code == CV_RGB2BGR565 || code == CV_RGBA2BGR565)
|
||||
if(tegra::cvtRGB2RGB565(src, dst, code == CV_RGB2BGR565 || code == CV_RGBA2BGR565 ? 0 : 2))
|
||||
@ -3344,6 +3384,34 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
|
||||
_dst.create(sz, CV_MAKETYPE(depth, dcn));
|
||||
dst = _dst.getMat();
|
||||
|
||||
#ifdef HAVE_IPP
|
||||
CV_SUPPRESS_DEPRECATED_START
|
||||
if (code == CV_BGR5652BGR)
|
||||
{
|
||||
if (CvtColorIPPLoop(src, dst, IPPGeneralFunctor((ippiGeneralFunc)ippiBGR565ToBGR_16u8u_C3R)))
|
||||
return;
|
||||
}
|
||||
else if (code == CV_BGR5652RGB)
|
||||
{
|
||||
if (CvtColorIPPLoop(src, dst, IPPGeneralReorderFunctor((ippiGeneralFunc)ippiBGR565ToBGR_16u8u_C3R,
|
||||
ippiSwapChannelsC3RTab[depth], 2, 1, 0, depth)))
|
||||
return;
|
||||
}
|
||||
if (code == CV_BGR5652BGRA)
|
||||
{
|
||||
if (CvtColorIPPLoop(src, dst, IPPGeneralReorderFunctor((ippiGeneralFunc)ippiBGR565ToBGR_16u8u_C3R,
|
||||
ippiSwapChannelsC3C4RTab[depth], 0, 1, 2, depth)))
|
||||
return;
|
||||
}
|
||||
else if (code == CV_BGR5652RGBA)
|
||||
{
|
||||
if (CvtColorIPPLoop(src, dst, IPPGeneralReorderFunctor((ippiGeneralFunc)ippiBGR565ToBGR_16u8u_C3R,
|
||||
ippiSwapChannelsC3C4RTab[depth], 2, 1, 0, depth)))
|
||||
return;
|
||||
}
|
||||
CV_SUPPRESS_DEPRECATED_END
|
||||
#endif
|
||||
|
||||
CvtColorLoop(src, dst, RGB5x52RGB(dcn,
|
||||
code == CV_BGR5652BGR || code == CV_BGR5552BGR ||
|
||||
code == CV_BGR5652BGRA || code == CV_BGR5552BGRA ? 0 : 2, // blue idx
|
||||
@ -3457,6 +3525,32 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
|
||||
_dst.create(sz, CV_MAKETYPE(depth, 3));
|
||||
dst = _dst.getMat();
|
||||
|
||||
#if defined HAVE_IPP && 0
|
||||
if (code == CV_RGB2YUV && scn == 3 && depth == CV_8U)
|
||||
{
|
||||
if (CvtColorIPPLoop(src, dst, IPPGeneralFunctor((ippiGeneralFunc)ippiRGBToYUV_8u_C3R)))
|
||||
return;
|
||||
}
|
||||
else if (code == CV_BGR2YUV && scn == 3 && depth == CV_8U)
|
||||
{
|
||||
if (CvtColorIPPLoop(src, dst, IPPReorderGeneralFunctor(ippiSwapChannelsC3RTab[depth],
|
||||
(ippiGeneralFunc)ippiRGBToYUV_8u_C3R, 2, 1, 0, depth)))
|
||||
return;
|
||||
}
|
||||
else if (code == CV_RGB2YUV && scn == 4 && depth == CV_8U)
|
||||
{
|
||||
if (CvtColorIPPLoop(src, dst, IPPReorderGeneralFunctor(ippiSwapChannelsC4C3RTab[depth],
|
||||
(ippiGeneralFunc)ippiRGBToYUV_8u_C3R, 0, 1, 2, depth)))
|
||||
return;
|
||||
}
|
||||
else if (code == CV_BGR2YUV && scn == 4 && depth == CV_8U)
|
||||
{
|
||||
if (CvtColorIPPLoop(src, dst, IPPReorderGeneralFunctor(ippiSwapChannelsC4C3RTab[depth],
|
||||
(ippiGeneralFunc)ippiRGBToYUV_8u_C3R, 2, 1, 0, depth)))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if( depth == CV_8U )
|
||||
{
|
||||
#ifdef HAVE_TEGRA_OPTIMIZATION
|
||||
@ -3486,6 +3580,32 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
|
||||
_dst.create(sz, CV_MAKETYPE(depth, dcn));
|
||||
dst = _dst.getMat();
|
||||
|
||||
#if defined HAVE_IPP && 0
|
||||
if (code == CV_YUV2RGB && dcn == 3 && depth == CV_8U)
|
||||
{
|
||||
if (CvtColorIPPLoop(src, dst, IPPGeneralFunctor((ippiGeneralFunc)ippiYUVToRGB_8u_C3R)))
|
||||
return;
|
||||
}
|
||||
else if (code == CV_YUV2BGR && dcn == 3 && depth == CV_8U)
|
||||
{
|
||||
if (CvtColorIPPLoop(src, dst, IPPGeneralReorderFunctor((ippiGeneralFunc)ippiYUVToRGB_8u_C3R,
|
||||
ippiSwapChannelsC3RTab[depth], 2, 1, 0, depth)))
|
||||
return;
|
||||
}
|
||||
else if (code == CV_YUV2RGB && dcn == 4 && depth == CV_8U)
|
||||
{
|
||||
if (CvtColorIPPLoop(src, dst, IPPGeneralReorderFunctor((ippiGeneralFunc)ippiYUVToRGB_8u_C3R,
|
||||
ippiSwapChannelsC3C4RTab[depth], 0, 1, 2, depth)))
|
||||
return;
|
||||
}
|
||||
else if (code == CV_YUV2BGR && dcn == 4 && depth == CV_8U)
|
||||
{
|
||||
if (CvtColorIPPLoop(src, dst, IPPGeneralReorderFunctor((ippiGeneralFunc)ippiYUVToRGB_8u_C3R,
|
||||
ippiSwapChannelsC3C4RTab[depth], 2, 1, 0, depth)))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if( depth == CV_8U )
|
||||
CvtColorLoop(src, dst, YCrCb2RGB_i<uchar>(dcn, bidx, coeffs_i));
|
||||
else if( depth == CV_16U )
|
||||
@ -3741,6 +3861,55 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
|
||||
_dst.create(sz, CV_MAKETYPE(depth, 3));
|
||||
dst = _dst.getMat();
|
||||
|
||||
#ifdef HAVE_IPP
|
||||
if (code == CV_LBGR2Lab && scn == 3 && depth == CV_8U)
|
||||
{
|
||||
if (CvtColorIPPLoop(src, dst, IPPGeneralFunctor((ippiGeneralFunc)ippiBGRToLab_8u_C3R)))
|
||||
return;
|
||||
}
|
||||
else if (code == CV_LBGR2Lab && scn == 4 && depth == CV_8U)
|
||||
{
|
||||
if (CvtColorIPPLoop(src, dst, IPPReorderGeneralFunctor(ippiSwapChannelsC4C3RTab[depth],
|
||||
(ippiGeneralFunc)ippiBGRToLab_8u_C3R, 0, 1, 2, depth)))
|
||||
return;
|
||||
}
|
||||
else if (code == CV_LRGB2Lab && scn == 3 && depth == CV_8U)
|
||||
{
|
||||
if (CvtColorIPPLoop(src, dst, IPPReorderGeneralFunctor(ippiSwapChannelsC3RTab[depth],
|
||||
(ippiGeneralFunc)ippiBGRToLab_8u_C3R, 2, 1, 0, depth)))
|
||||
return;
|
||||
}
|
||||
else if (code == CV_LRGB2Lab && scn == 4 && depth == CV_8U)
|
||||
{
|
||||
if (CvtColorIPPLoop(src, dst, IPPReorderGeneralFunctor(ippiSwapChannelsC4C3RTab[depth],
|
||||
(ippiGeneralFunc)ippiBGRToLab_8u_C3R, 2, 1, 0, depth)))
|
||||
return;
|
||||
}
|
||||
else if (code == CV_LRGB2Luv && scn == 3)
|
||||
{
|
||||
if (CvtColorIPPLoop(src, dst, IPPGeneralFunctor(ippiRGBToLUVTab[depth])))
|
||||
return;
|
||||
}
|
||||
else if (code == CV_LRGB2Luv && scn == 4)
|
||||
{
|
||||
if (CvtColorIPPLoop(src, dst, IPPReorderGeneralFunctor(ippiSwapChannelsC4C3RTab[depth],
|
||||
ippiRGBToLUVTab[depth], 0, 1, 2, depth)))
|
||||
return;
|
||||
}
|
||||
else if (code == CV_LBGR2Luv && scn == 3)
|
||||
{
|
||||
if (CvtColorIPPLoop(src, dst, IPPReorderGeneralFunctor(ippiSwapChannelsC3RTab[depth],
|
||||
ippiRGBToLUVTab[depth], 2, 1, 0, depth)))
|
||||
return;
|
||||
}
|
||||
else if (code == CV_LBGR2Luv && scn == 4)
|
||||
{
|
||||
if (CvtColorIPPLoop(src, dst, IPPReorderGeneralFunctor(ippiSwapChannelsC4C3RTab[depth],
|
||||
ippiRGBToLUVTab[depth], 2, 1, 0, depth)))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if( code == CV_BGR2Lab || code == CV_RGB2Lab ||
|
||||
code == CV_LBGR2Lab || code == CV_LRGB2Lab )
|
||||
{
|
||||
@ -3772,6 +3941,57 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
|
||||
_dst.create(sz, CV_MAKETYPE(depth, dcn));
|
||||
dst = _dst.getMat();
|
||||
|
||||
#if defined (HAVE_IPP)
|
||||
#if 0
|
||||
if( code == CV_Lab2LBGR && dcn == 3 && depth == CV_8U)
|
||||
{
|
||||
if( CvtColorIPPLoop(src, dst, IPPGeneralFunctor((ippiGeneralFunc)ippiLabToBGR_8u_C3R)) )
|
||||
return;
|
||||
}
|
||||
else if( code == CV_Lab2LBGR && dcn == 4 && depth == CV_8U )
|
||||
{
|
||||
if( CvtColorIPPLoop(src, dst, IPPGeneralReorderFunctor((ippiGeneralFunc)ippiLabToBGR_8u_C3R,
|
||||
ippiSwapChannelsC3C4RTab[depth], 0, 1, 2, depth)) )
|
||||
return;
|
||||
}
|
||||
if( code == CV_Lab2LRGB && dcn == 3 && depth == CV_8U )
|
||||
{
|
||||
if( CvtColorIPPLoop(src, dst, IPPGeneralReorderFunctor((ippiGeneralFunc)ippiLabToBGR_8u_C3R,
|
||||
ippiSwapChannelsC3RTab[depth], 2, 1, 0, depth)) )
|
||||
return;
|
||||
}
|
||||
else if( code == CV_Lab2LRGB && dcn == 4 && depth == CV_8U )
|
||||
{
|
||||
if( CvtColorIPPLoop(src, dst, IPPGeneralReorderFunctor((ippiGeneralFunc)ippiLabToBGR_8u_C3R,
|
||||
ippiSwapChannelsC3C4RTab[depth], 2, 1, 0, depth)) )
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if( code == CV_Luv2LRGB && dcn == 3 )
|
||||
{
|
||||
if( CvtColorIPPLoop(src, dst, IPPGeneralFunctor(ippiLUVToRGBTab[depth])) )
|
||||
return;
|
||||
}
|
||||
else if( code == CV_Luv2LRGB && dcn == 4 )
|
||||
{
|
||||
if( CvtColorIPPLoop(src, dst, IPPGeneralReorderFunctor(ippiLUVToRGBTab[depth],
|
||||
ippiSwapChannelsC3C4RTab[depth], 0, 1, 2, depth)) )
|
||||
return;
|
||||
}
|
||||
if( code == CV_Luv2LBGR && dcn == 3 )
|
||||
{
|
||||
if( CvtColorIPPLoop(src, dst, IPPGeneralReorderFunctor(ippiLUVToRGBTab[depth],
|
||||
ippiSwapChannelsC3RTab[depth], 2, 1, 0, depth)) )
|
||||
return;
|
||||
}
|
||||
else if( code == CV_Luv2LBGR && dcn == 4 )
|
||||
{
|
||||
if( CvtColorIPPLoop(src, dst, IPPGeneralReorderFunctor(ippiLUVToRGBTab[depth],
|
||||
ippiSwapChannelsC3C4RTab[depth], 2, 1, 0, depth)) )
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if( code == CV_Lab2BGR || code == CV_Lab2RGB ||
|
||||
code == CV_Lab2LBGR || code == CV_Lab2LRGB )
|
||||
{
|
||||
@ -3968,7 +4188,13 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
|
||||
dst = _dst.getMat();
|
||||
|
||||
if( depth == CV_8U )
|
||||
{
|
||||
#ifdef HAVE_IPP
|
||||
if (CvtColorIPPLoop(src, dst, IPPGeneralFunctor((ippiGeneralFunc)ippiAlphaPremul_8u_AC4R)))
|
||||
return;
|
||||
#endif
|
||||
CvtColorLoop(src, dst, RGBA2mRGBA<uchar>());
|
||||
}
|
||||
else
|
||||
{
|
||||
CV_Error( CV_StsBadArg, "Unsupported image depth" );
|
||||
|
@ -158,7 +158,7 @@ OCL_TEST_P(CvtColor, YCrCb2BGRA) { performTest(3, 4, CVTCODE(YCrCb2BGR)); }
|
||||
#if IPP_VERSION_X100 > 0
|
||||
#define IPP_EPS depth <= CV_32S ? 1 : 4e-5
|
||||
#else
|
||||
#define IPP_EPS 0
|
||||
#define IPP_EPS 1e-3
|
||||
#endif
|
||||
|
||||
OCL_TEST_P(CvtColor, RGB2XYZ) { performTest(3, 3, CVTCODE(RGB2XYZ), IPP_EPS); }
|
||||
@ -261,19 +261,27 @@ OCL_TEST_P(CvtColor8u, GRAY2BGR555) { performTest(1, 2, CVTCODE(GRAY2BGR555)); }
|
||||
|
||||
// RGBA <-> mRGBA
|
||||
|
||||
OCL_TEST_P(CvtColor8u, RGBA2mRGBA) { performTest(4, 4, CVTCODE(RGBA2mRGBA)); }
|
||||
#if IPP_VERSION_X100 > 0
|
||||
#define IPP_EPS depth <= CV_32S ? 1 : 1e-3
|
||||
#else
|
||||
#define IPP_EPS 1e-3
|
||||
#endif
|
||||
|
||||
OCL_TEST_P(CvtColor8u, RGBA2mRGBA) { performTest(4, 4, CVTCODE(RGBA2mRGBA), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor8u, mRGBA2RGBA) { performTest(4, 4, CVTCODE(mRGBA2RGBA)); }
|
||||
|
||||
// RGB <-> Lab
|
||||
|
||||
OCL_TEST_P(CvtColor8u32f, BGR2Lab) { performTest(3, 3, CVTCODE(BGR2Lab)); }
|
||||
OCL_TEST_P(CvtColor8u32f, RGB2Lab) { performTest(3, 3, CVTCODE(RGB2Lab)); }
|
||||
OCL_TEST_P(CvtColor8u32f, LBGR2Lab) { performTest(3, 3, CVTCODE(LBGR2Lab)); }
|
||||
OCL_TEST_P(CvtColor8u32f, LRGB2Lab) { performTest(3, 3, CVTCODE(LRGB2Lab)); }
|
||||
OCL_TEST_P(CvtColor8u32f, LBGR2Lab) { performTest(3, 3, CVTCODE(LBGR2Lab), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor8u32f, LRGB2Lab) { performTest(3, 3, CVTCODE(LRGB2Lab), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor8u32f, BGRA2Lab) { performTest(4, 3, CVTCODE(BGR2Lab)); }
|
||||
OCL_TEST_P(CvtColor8u32f, RGBA2Lab) { performTest(4, 3, CVTCODE(RGB2Lab)); }
|
||||
OCL_TEST_P(CvtColor8u32f, LBGRA2Lab) { performTest(4, 3, CVTCODE(LBGR2Lab)); }
|
||||
OCL_TEST_P(CvtColor8u32f, LRGBA2Lab) { performTest(4, 3, CVTCODE(LRGB2Lab)); }
|
||||
OCL_TEST_P(CvtColor8u32f, LBGRA2Lab) { performTest(4, 3, CVTCODE(LBGR2Lab), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor8u32f, LRGBA2Lab) { performTest(4, 3, CVTCODE(LRGB2Lab), IPP_EPS); }
|
||||
|
||||
#undef IPP_EPS
|
||||
|
||||
OCL_TEST_P(CvtColor8u32f, Lab2BGR) { performTest(3, 3, CVTCODE(Lab2BGR), depth == CV_8U ? 1 : 1e-5); }
|
||||
OCL_TEST_P(CvtColor8u32f, Lab2RGB) { performTest(3, 3, CVTCODE(Lab2RGB), depth == CV_8U ? 1 : 1e-5); }
|
||||
|
Loading…
Reference in New Issue
Block a user