merged all the latest changes from 2.4 to trunk

This commit is contained in:
Vadim Pisarevsky
2012-04-13 21:50:59 +00:00
parent 020f9a6047
commit 2fd1e2ea57
416 changed files with 12852 additions and 6070 deletions

View File

@@ -1767,26 +1767,26 @@ public:
__m128i r1 = _mm_loadu_si128((const __m128i*)(bayer+bayer_step));
__m128i r2 = _mm_loadu_si128((const __m128i*)(bayer+bayer_step*2));
__m128i b1 = _mm_add_epi16(_mm_srli_epi16(_mm_slli_epi16(r0, 8), 8),
_mm_srli_epi16(_mm_slli_epi16(r2, 8), 8));
__m128i b1 = _mm_add_epi16(_mm_srli_epi16(_mm_slli_epi16(r0, 8), 7),
_mm_srli_epi16(_mm_slli_epi16(r2, 8), 7));
__m128i b0 = _mm_add_epi16(b1, _mm_srli_si128(b1, 2));
b1 = _mm_slli_epi16(_mm_srli_si128(b1, 2), 1);
__m128i g0 = _mm_add_epi16(_mm_srli_epi16(r0, 8), _mm_srli_epi16(r2, 8));
__m128i g1 = _mm_srli_epi16(_mm_slli_epi16(r1, 8), 8);
__m128i g0 = _mm_add_epi16(_mm_srli_epi16(r0, 7), _mm_srli_epi16(r2, 7));
__m128i g1 = _mm_srli_epi16(_mm_slli_epi16(r1, 8), 7);
g0 = _mm_add_epi16(g0, _mm_add_epi16(g1, _mm_srli_si128(g1, 2)));
g1 = _mm_slli_epi16(_mm_srli_si128(g1, 2), 2);
r0 = _mm_srli_epi16(r1, 8);
r1 = _mm_slli_epi16(_mm_add_epi16(r0, _mm_srli_si128(r0, 2)), 1);
r0 = _mm_slli_epi16(r0, 2);
r1 = _mm_slli_epi16(_mm_add_epi16(r0, _mm_srli_si128(r0, 2)), 2);
r0 = _mm_slli_epi16(r0, 3);
g0 = _mm_add_epi16(_mm_mulhi_epi16(b0, _b2y), _mm_mulhi_epi16(g0, _g2y));
g1 = _mm_add_epi16(_mm_mulhi_epi16(b1, _b2y), _mm_mulhi_epi16(g1, _g2y));
g0 = _mm_add_epi16(g0, _mm_mulhi_epi16(r0, _r2y));
g1 = _mm_add_epi16(g1, _mm_mulhi_epi16(r1, _r2y));
g0 = _mm_srli_epi16(g0, 1);
g1 = _mm_srli_epi16(g1, 1);
g0 = _mm_srli_epi16(g0, 2);
g1 = _mm_srli_epi16(g1, 2);
g0 = _mm_packus_epi16(g0, g0);
g1 = _mm_packus_epi16(g1, g1);
g0 = _mm_unpacklo_epi8(g0, g1);
@@ -2667,6 +2667,13 @@ static void Bayer2RGB_VNG_8u( const Mat& srcmat, Mat& dstmat, int code )
///////////////////////////////////// YUV420 -> RGB /////////////////////////////////////
const int ITUR_BT_601_CY = 1220542;
const int ITUR_BT_601_CUB = 2116026;
const int ITUR_BT_601_CUG = -409993;
const int ITUR_BT_601_CVG = -852492;
const int ITUR_BT_601_CVR = 1673527;
const int ITUR_BT_601_SHIFT = 20;
template<int bIdx, int uIdx>
struct YUV420sp2RGB888Invoker
{
@@ -2690,13 +2697,6 @@ struct YUV420sp2RGB888Invoker
//G = (1220542(Y - 16) - 852492(V - 128) - 409993(U - 128) + (1 << 19)) >> 20
//B = (1220542(Y - 16) + 2116026(U - 128) + (1 << 19)) >> 20
const int cY = 1220542;
const int cUB = 2116026;
const int cUG = -409993;
const int cVG = -852492;
const int cVR = 1673527;
const int YUV420_SHIFT = 20;
const uchar* y1 = my1 + rangeBegin * stride, *uv = muv + rangeBegin * stride / 2;
#ifdef HAVE_TEGRA_OPTIMIZATION
@@ -2715,29 +2715,29 @@ struct YUV420sp2RGB888Invoker
int u = int(uv[i + 0 + uIdx]) - 128;
int v = int(uv[i + 1 - uIdx]) - 128;
int ruv = (1 << (YUV420_SHIFT - 1)) + cVR * v;
int guv = (1 << (YUV420_SHIFT - 1)) + cVG * v + cUG * u;
int buv = (1 << (YUV420_SHIFT - 1)) + cUB * u;
int ruv = (1 << (ITUR_BT_601_SHIFT - 1)) + ITUR_BT_601_CVR * v;
int guv = (1 << (ITUR_BT_601_SHIFT - 1)) + ITUR_BT_601_CVG * v + ITUR_BT_601_CUG * u;
int buv = (1 << (ITUR_BT_601_SHIFT - 1)) + ITUR_BT_601_CUB * u;
int y00 = std::max(0, int(y1[i]) - 16) * cY;
row1[2-bIdx] = saturate_cast<uchar>((y00 + ruv) >> YUV420_SHIFT);
row1[1] = saturate_cast<uchar>((y00 + guv) >> YUV420_SHIFT);
row1[bIdx] = saturate_cast<uchar>((y00 + buv) >> YUV420_SHIFT);
int y00 = std::max(0, int(y1[i]) - 16) * ITUR_BT_601_CY;
row1[2-bIdx] = saturate_cast<uchar>((y00 + ruv) >> ITUR_BT_601_SHIFT);
row1[1] = saturate_cast<uchar>((y00 + guv) >> ITUR_BT_601_SHIFT);
row1[bIdx] = saturate_cast<uchar>((y00 + buv) >> ITUR_BT_601_SHIFT);
int y01 = std::max(0, int(y1[i + 1]) - 16) * cY;
row1[5-bIdx] = saturate_cast<uchar>((y01 + ruv) >> YUV420_SHIFT);
row1[4] = saturate_cast<uchar>((y01 + guv) >> YUV420_SHIFT);
row1[3+bIdx] = saturate_cast<uchar>((y01 + buv) >> YUV420_SHIFT);
int y01 = std::max(0, int(y1[i + 1]) - 16) * ITUR_BT_601_CY;
row1[5-bIdx] = saturate_cast<uchar>((y01 + ruv) >> ITUR_BT_601_SHIFT);
row1[4] = saturate_cast<uchar>((y01 + guv) >> ITUR_BT_601_SHIFT);
row1[3+bIdx] = saturate_cast<uchar>((y01 + buv) >> ITUR_BT_601_SHIFT);
int y10 = std::max(0, int(y2[i]) - 16) * cY;
row2[2-bIdx] = saturate_cast<uchar>((y10 + ruv) >> YUV420_SHIFT);
row2[1] = saturate_cast<uchar>((y10 + guv) >> YUV420_SHIFT);
row2[bIdx] = saturate_cast<uchar>((y10 + buv) >> YUV420_SHIFT);
int y10 = std::max(0, int(y2[i]) - 16) * ITUR_BT_601_CY;
row2[2-bIdx] = saturate_cast<uchar>((y10 + ruv) >> ITUR_BT_601_SHIFT);
row2[1] = saturate_cast<uchar>((y10 + guv) >> ITUR_BT_601_SHIFT);
row2[bIdx] = saturate_cast<uchar>((y10 + buv) >> ITUR_BT_601_SHIFT);
int y11 = std::max(0, int(y2[i + 1]) - 16) * cY;
row2[5-bIdx] = saturate_cast<uchar>((y11 + ruv) >> YUV420_SHIFT);
row2[4] = saturate_cast<uchar>((y11 + guv) >> YUV420_SHIFT);
row2[3+bIdx] = saturate_cast<uchar>((y11 + buv) >> YUV420_SHIFT);
int y11 = std::max(0, int(y2[i + 1]) - 16) * ITUR_BT_601_CY;
row2[5-bIdx] = saturate_cast<uchar>((y11 + ruv) >> ITUR_BT_601_SHIFT);
row2[4] = saturate_cast<uchar>((y11 + guv) >> ITUR_BT_601_SHIFT);
row2[3+bIdx] = saturate_cast<uchar>((y11 + buv) >> ITUR_BT_601_SHIFT);
}
}
}
@@ -2766,13 +2766,6 @@ struct YUV420sp2RGBA8888Invoker
//G = (1220542(Y - 16) - 852492(V - 128) - 409993(U - 128) + (1 << 19)) >> 20
//B = (1220542(Y - 16) + 2116026(U - 128) + (1 << 19)) >> 20
const int cY = 1220542;
const int cUB = 2116026;
const int cUG = -409993;
const int cVG = -852492;
const int cVR = 1673527;
const int YUV420_SHIFT = 20;
const uchar* y1 = my1 + rangeBegin * stride, *uv = muv + rangeBegin * stride / 2;
#ifdef HAVE_TEGRA_OPTIMIZATION
@@ -2791,32 +2784,32 @@ struct YUV420sp2RGBA8888Invoker
int u = int(uv[i + 0 + uIdx]) - 128;
int v = int(uv[i + 1 - uIdx]) - 128;
int ruv = (1 << (YUV420_SHIFT - 1)) + cVR * v;
int guv = (1 << (YUV420_SHIFT - 1)) + cVG * v + cUG * u;
int buv = (1 << (YUV420_SHIFT - 1)) + cUB * u;
int ruv = (1 << (ITUR_BT_601_SHIFT - 1)) + ITUR_BT_601_CVR * v;
int guv = (1 << (ITUR_BT_601_SHIFT - 1)) + ITUR_BT_601_CVG * v + ITUR_BT_601_CUG * u;
int buv = (1 << (ITUR_BT_601_SHIFT - 1)) + ITUR_BT_601_CUB * u;
int y00 = std::max(0, int(y1[i]) - 16) * cY;
row1[2-bIdx] = saturate_cast<uchar>((y00 + ruv) >> YUV420_SHIFT);
row1[1] = saturate_cast<uchar>((y00 + guv) >> YUV420_SHIFT);
row1[bIdx] = saturate_cast<uchar>((y00 + buv) >> YUV420_SHIFT);
int y00 = std::max(0, int(y1[i]) - 16) * ITUR_BT_601_CY;
row1[2-bIdx] = saturate_cast<uchar>((y00 + ruv) >> ITUR_BT_601_SHIFT);
row1[1] = saturate_cast<uchar>((y00 + guv) >> ITUR_BT_601_SHIFT);
row1[bIdx] = saturate_cast<uchar>((y00 + buv) >> ITUR_BT_601_SHIFT);
row1[3] = uchar(0xff);
int y01 = std::max(0, int(y1[i + 1]) - 16) * cY;
row1[6-bIdx] = saturate_cast<uchar>((y01 + ruv) >> YUV420_SHIFT);
row1[5] = saturate_cast<uchar>((y01 + guv) >> YUV420_SHIFT);
row1[4+bIdx] = saturate_cast<uchar>((y01 + buv) >> YUV420_SHIFT);
int y01 = std::max(0, int(y1[i + 1]) - 16) * ITUR_BT_601_CY;
row1[6-bIdx] = saturate_cast<uchar>((y01 + ruv) >> ITUR_BT_601_SHIFT);
row1[5] = saturate_cast<uchar>((y01 + guv) >> ITUR_BT_601_SHIFT);
row1[4+bIdx] = saturate_cast<uchar>((y01 + buv) >> ITUR_BT_601_SHIFT);
row1[7] = uchar(0xff);
int y10 = std::max(0, int(y2[i]) - 16) * cY;
row2[2-bIdx] = saturate_cast<uchar>((y10 + ruv) >> YUV420_SHIFT);
row2[1] = saturate_cast<uchar>((y10 + guv) >> YUV420_SHIFT);
row2[bIdx] = saturate_cast<uchar>((y10 + buv) >> YUV420_SHIFT);
int y10 = std::max(0, int(y2[i]) - 16) * ITUR_BT_601_CY;
row2[2-bIdx] = saturate_cast<uchar>((y10 + ruv) >> ITUR_BT_601_SHIFT);
row2[1] = saturate_cast<uchar>((y10 + guv) >> ITUR_BT_601_SHIFT);
row2[bIdx] = saturate_cast<uchar>((y10 + buv) >> ITUR_BT_601_SHIFT);
row2[3] = uchar(0xff);
int y11 = std::max(0, int(y2[i + 1]) - 16) * cY;
row2[6-bIdx] = saturate_cast<uchar>((y11 + ruv) >> YUV420_SHIFT);
row2[5] = saturate_cast<uchar>((y11 + guv) >> YUV420_SHIFT);
row2[4+bIdx] = saturate_cast<uchar>((y11 + buv) >> YUV420_SHIFT);
int y11 = std::max(0, int(y2[i + 1]) - 16) * ITUR_BT_601_CY;
row2[6-bIdx] = saturate_cast<uchar>((y11 + ruv) >> ITUR_BT_601_SHIFT);
row2[5] = saturate_cast<uchar>((y11 + guv) >> ITUR_BT_601_SHIFT);
row2[4+bIdx] = saturate_cast<uchar>((y11 + buv) >> ITUR_BT_601_SHIFT);
row2[7] = uchar(0xff);
}
}
@@ -2842,13 +2835,6 @@ struct YUV420p2RGB888Invoker
size_t uvsteps[2] = {width/2, stride - width/2};
int usIdx = ustepIdx, vsIdx = vstepIdx;
const int cY = 1220542;
const int cUB = 2116026;
const int cUG = -409993;
const int cVG = -852492;
const int cVR = 1673527;
const int YUV420_SHIFT = 20;
const uchar* y1 = my1 + rangeBegin * stride;
const uchar* u1 = mu + (range.begin() / 2) * stride;
const uchar* v1 = mv + (range.begin() / 2) * stride;
@@ -2870,29 +2856,29 @@ struct YUV420p2RGB888Invoker
int u = int(u1[i]) - 128;
int v = int(v1[i]) - 128;
int ruv = (1 << (YUV420_SHIFT - 1)) + cVR * v;
int guv = (1 << (YUV420_SHIFT - 1)) + cVG * v + cUG * u;
int buv = (1 << (YUV420_SHIFT - 1)) + cUB * u;
int ruv = (1 << (ITUR_BT_601_SHIFT - 1)) + ITUR_BT_601_CVR * v;
int guv = (1 << (ITUR_BT_601_SHIFT - 1)) + ITUR_BT_601_CVG * v + ITUR_BT_601_CUG * u;
int buv = (1 << (ITUR_BT_601_SHIFT - 1)) + ITUR_BT_601_CUB * u;
int y00 = std::max(0, int(y1[2 * i]) - 16) * cY;
row1[2-bIdx] = saturate_cast<uchar>((y00 + ruv) >> YUV420_SHIFT);
row1[1] = saturate_cast<uchar>((y00 + guv) >> YUV420_SHIFT);
row1[bIdx] = saturate_cast<uchar>((y00 + buv) >> YUV420_SHIFT);
int y00 = std::max(0, int(y1[2 * i]) - 16) * ITUR_BT_601_CY;
row1[2-bIdx] = saturate_cast<uchar>((y00 + ruv) >> ITUR_BT_601_SHIFT);
row1[1] = saturate_cast<uchar>((y00 + guv) >> ITUR_BT_601_SHIFT);
row1[bIdx] = saturate_cast<uchar>((y00 + buv) >> ITUR_BT_601_SHIFT);
int y01 = std::max(0, int(y1[2 * i + 1]) - 16) * cY;
row1[5-bIdx] = saturate_cast<uchar>((y01 + ruv) >> YUV420_SHIFT);
row1[4] = saturate_cast<uchar>((y01 + guv) >> YUV420_SHIFT);
row1[3+bIdx] = saturate_cast<uchar>((y01 + buv) >> YUV420_SHIFT);
int y01 = std::max(0, int(y1[2 * i + 1]) - 16) * ITUR_BT_601_CY;
row1[5-bIdx] = saturate_cast<uchar>((y01 + ruv) >> ITUR_BT_601_SHIFT);
row1[4] = saturate_cast<uchar>((y01 + guv) >> ITUR_BT_601_SHIFT);
row1[3+bIdx] = saturate_cast<uchar>((y01 + buv) >> ITUR_BT_601_SHIFT);
int y10 = std::max(0, int(y2[2 * i]) - 16) * cY;
row2[2-bIdx] = saturate_cast<uchar>((y10 + ruv) >> YUV420_SHIFT);
row2[1] = saturate_cast<uchar>((y10 + guv) >> YUV420_SHIFT);
row2[bIdx] = saturate_cast<uchar>((y10 + buv) >> YUV420_SHIFT);
int y10 = std::max(0, int(y2[2 * i]) - 16) * ITUR_BT_601_CY;
row2[2-bIdx] = saturate_cast<uchar>((y10 + ruv) >> ITUR_BT_601_SHIFT);
row2[1] = saturate_cast<uchar>((y10 + guv) >> ITUR_BT_601_SHIFT);
row2[bIdx] = saturate_cast<uchar>((y10 + buv) >> ITUR_BT_601_SHIFT);
int y11 = std::max(0, int(y2[2 * i + 1]) - 16) * cY;
row2[5-bIdx] = saturate_cast<uchar>((y11 + ruv) >> YUV420_SHIFT);
row2[4] = saturate_cast<uchar>((y11 + guv) >> YUV420_SHIFT);
row2[3+bIdx] = saturate_cast<uchar>((y11 + buv) >> YUV420_SHIFT);
int y11 = std::max(0, int(y2[2 * i + 1]) - 16) * ITUR_BT_601_CY;
row2[5-bIdx] = saturate_cast<uchar>((y11 + ruv) >> ITUR_BT_601_SHIFT);
row2[4] = saturate_cast<uchar>((y11 + guv) >> ITUR_BT_601_SHIFT);
row2[3+bIdx] = saturate_cast<uchar>((y11 + buv) >> ITUR_BT_601_SHIFT);
}
}
}
@@ -2914,13 +2900,6 @@ struct YUV420p2RGBA8888Invoker
int rangeBegin = range.begin() * 2;
int rangeEnd = range.end() * 2;
const int cY = 1220542;
const int cUB = 2116026;
const int cUG = -409993;
const int cVG = -852492;
const int cVR = 1673527;
const int YUV420_SHIFT = 20;
size_t uvsteps[2] = {width/2, stride - width/2};
int usIdx = ustepIdx, vsIdx = vstepIdx;
@@ -2945,32 +2924,32 @@ struct YUV420p2RGBA8888Invoker
int u = int(u1[i]) - 128;
int v = int(v1[i]) - 128;
int ruv = (1 << (YUV420_SHIFT - 1)) + cVR * v;
int guv = (1 << (YUV420_SHIFT - 1)) + cVG * v + cUG * u;
int buv = (1 << (YUV420_SHIFT - 1)) + cUB * u;
int ruv = (1 << (ITUR_BT_601_SHIFT - 1)) + ITUR_BT_601_CVR * v;
int guv = (1 << (ITUR_BT_601_SHIFT - 1)) + ITUR_BT_601_CVG * v + ITUR_BT_601_CUG * u;
int buv = (1 << (ITUR_BT_601_SHIFT - 1)) + ITUR_BT_601_CUB * u;
int y00 = std::max(0, int(y1[2 * i]) - 16) * cY;
row1[2-bIdx] = saturate_cast<uchar>((y00 + ruv) >> YUV420_SHIFT);
row1[1] = saturate_cast<uchar>((y00 + guv) >> YUV420_SHIFT);
row1[bIdx] = saturate_cast<uchar>((y00 + buv) >> YUV420_SHIFT);
int y00 = std::max(0, int(y1[2 * i]) - 16) * ITUR_BT_601_CY;
row1[2-bIdx] = saturate_cast<uchar>((y00 + ruv) >> ITUR_BT_601_SHIFT);
row1[1] = saturate_cast<uchar>((y00 + guv) >> ITUR_BT_601_SHIFT);
row1[bIdx] = saturate_cast<uchar>((y00 + buv) >> ITUR_BT_601_SHIFT);
row1[3] = uchar(0xff);
int y01 = std::max(0, int(y1[2 * i + 1]) - 16) * cY;
row1[6-bIdx] = saturate_cast<uchar>((y01 + ruv) >> YUV420_SHIFT);
row1[5] = saturate_cast<uchar>((y01 + guv) >> YUV420_SHIFT);
row1[4+bIdx] = saturate_cast<uchar>((y01 + buv) >> YUV420_SHIFT);
int y01 = std::max(0, int(y1[2 * i + 1]) - 16) * ITUR_BT_601_CY;
row1[6-bIdx] = saturate_cast<uchar>((y01 + ruv) >> ITUR_BT_601_SHIFT);
row1[5] = saturate_cast<uchar>((y01 + guv) >> ITUR_BT_601_SHIFT);
row1[4+bIdx] = saturate_cast<uchar>((y01 + buv) >> ITUR_BT_601_SHIFT);
row1[7] = uchar(0xff);
int y10 = std::max(0, int(y2[2 * i]) - 16) * cY;
row2[2-bIdx] = saturate_cast<uchar>((y10 + ruv) >> YUV420_SHIFT);
row2[1] = saturate_cast<uchar>((y10 + guv) >> YUV420_SHIFT);
row2[bIdx] = saturate_cast<uchar>((y10 + buv) >> YUV420_SHIFT);
int y10 = std::max(0, int(y2[2 * i]) - 16) * ITUR_BT_601_CY;
row2[2-bIdx] = saturate_cast<uchar>((y10 + ruv) >> ITUR_BT_601_SHIFT);
row2[1] = saturate_cast<uchar>((y10 + guv) >> ITUR_BT_601_SHIFT);
row2[bIdx] = saturate_cast<uchar>((y10 + buv) >> ITUR_BT_601_SHIFT);
row2[3] = uchar(0xff);
int y11 = std::max(0, int(y2[2 * i + 1]) - 16) * cY;
row2[6-bIdx] = saturate_cast<uchar>((y11 + ruv) >> YUV420_SHIFT);
row2[5] = saturate_cast<uchar>((y11 + guv) >> YUV420_SHIFT);
row2[4+bIdx] = saturate_cast<uchar>((y11 + buv) >> YUV420_SHIFT);
int y11 = std::max(0, int(y2[2 * i + 1]) - 16) * ITUR_BT_601_CY;
row2[6-bIdx] = saturate_cast<uchar>((y11 + ruv) >> ITUR_BT_601_SHIFT);
row2[5] = saturate_cast<uchar>((y11 + guv) >> ITUR_BT_601_SHIFT);
row2[4+bIdx] = saturate_cast<uchar>((y11 + buv) >> ITUR_BT_601_SHIFT);
row2[7] = uchar(0xff);
}
}
@@ -3027,6 +3006,128 @@ inline void cvtYUV420p2RGBA(Mat& _dst, int _stride, const uchar* _y1, const ucha
converter(BlockedRange(0, _dst.rows/2));
}
///////////////////////////////////// YUV422 -> RGB /////////////////////////////////////
template<int bIdx, int uIdx, int yIdx>
struct YUV422toRGB888Invoker
{
Mat* dst;
const uchar* src;
int width, stride;
YUV422toRGB888Invoker(Mat* _dst, int _stride, const uchar* _yuv)
: dst(_dst), src(_yuv), width(_dst->cols), stride(_stride) {}
void operator()(const BlockedRange& range) const
{
int rangeBegin = range.begin();
int rangeEnd = range.end();
const int uidx = 1 - yIdx + uIdx * 2;
const int vidx = (2 + uidx) % 4;
const uchar* yuv_src = src + rangeBegin * stride;
for (int j = rangeBegin; j < rangeEnd; j++, yuv_src += stride)
{
uchar* row = dst->ptr<uchar>(j);
for (int i = 0; i < 2 * width; i += 4, row += 6)
{
int u = int(yuv_src[i + uidx]) - 128;
int v = int(yuv_src[i + vidx]) - 128;
int ruv = (1 << (ITUR_BT_601_SHIFT - 1)) + ITUR_BT_601_CVR * v;
int guv = (1 << (ITUR_BT_601_SHIFT - 1)) + ITUR_BT_601_CVG * v + ITUR_BT_601_CUG * u;
int buv = (1 << (ITUR_BT_601_SHIFT - 1)) + ITUR_BT_601_CUB * u;
int y00 = std::max(0, int(yuv_src[i + yIdx]) - 16) * ITUR_BT_601_CY;
row[2-bIdx] = saturate_cast<uchar>((y00 + ruv) >> ITUR_BT_601_SHIFT);
row[1] = saturate_cast<uchar>((y00 + guv) >> ITUR_BT_601_SHIFT);
row[bIdx] = saturate_cast<uchar>((y00 + buv) >> ITUR_BT_601_SHIFT);
int y01 = std::max(0, int(yuv_src[i + yIdx + 2]) - 16) * ITUR_BT_601_CY;
row[5-bIdx] = saturate_cast<uchar>((y01 + ruv) >> ITUR_BT_601_SHIFT);
row[4] = saturate_cast<uchar>((y01 + guv) >> ITUR_BT_601_SHIFT);
row[3+bIdx] = saturate_cast<uchar>((y01 + buv) >> ITUR_BT_601_SHIFT);
}
}
}
};
template<int bIdx, int uIdx, int yIdx>
struct YUV422toRGBA8888Invoker
{
Mat* dst;
const uchar* src;
int width, stride;
YUV422toRGBA8888Invoker(Mat* _dst, int _stride, const uchar* _yuv)
: dst(_dst), src(_yuv), width(_dst->cols), stride(_stride) {}
void operator()(const BlockedRange& range) const
{
int rangeBegin = range.begin();
int rangeEnd = range.end();
const int uidx = 1 - yIdx + uIdx * 2;
const int vidx = (2 + uidx) % 4;
const uchar* yuv_src = src + rangeBegin * stride;
for (int j = rangeBegin; j < rangeEnd; j++, yuv_src += stride)
{
uchar* row = dst->ptr<uchar>(j);
for (int i = 0; i < 2 * width; i += 4, row += 8)
{
int u = int(yuv_src[i + uidx]) - 128;
int v = int(yuv_src[i + vidx]) - 128;
int ruv = (1 << (ITUR_BT_601_SHIFT - 1)) + ITUR_BT_601_CVR * v;
int guv = (1 << (ITUR_BT_601_SHIFT - 1)) + ITUR_BT_601_CVG * v + ITUR_BT_601_CUG * u;
int buv = (1 << (ITUR_BT_601_SHIFT - 1)) + ITUR_BT_601_CUB * u;
int y00 = std::max(0, int(yuv_src[i + yIdx]) - 16) * ITUR_BT_601_CY;
row[2-bIdx] = saturate_cast<uchar>((y00 + ruv) >> ITUR_BT_601_SHIFT);
row[1] = saturate_cast<uchar>((y00 + guv) >> ITUR_BT_601_SHIFT);
row[bIdx] = saturate_cast<uchar>((y00 + buv) >> ITUR_BT_601_SHIFT);
row[3] = uchar(0xff);
int y01 = std::max(0, int(yuv_src[i + yIdx + 2]) - 16) * ITUR_BT_601_CY;
row[6-bIdx] = saturate_cast<uchar>((y01 + ruv) >> ITUR_BT_601_SHIFT);
row[5] = saturate_cast<uchar>((y01 + guv) >> ITUR_BT_601_SHIFT);
row[4+bIdx] = saturate_cast<uchar>((y01 + buv) >> ITUR_BT_601_SHIFT);
row[7] = uchar(0xff);
}
}
}
};
#define MIN_SIZE_FOR_PARALLEL_YUV422_CONVERSION (320*240)
template<int bIdx, int uIdx, int yIdx>
inline void cvtYUV422toRGB(Mat& _dst, int _stride, const uchar* _yuv)
{
YUV422toRGB888Invoker<bIdx, uIdx, yIdx> converter(&_dst, _stride, _yuv);
#ifdef HAVE_TBB
if (_dst.total() >= MIN_SIZE_FOR_PARALLEL_YUV422_CONVERSION)
parallel_for(BlockedRange(0, _dst.rows), converter);
else
#endif
converter(BlockedRange(0, _dst.rows));
}
template<int bIdx, int uIdx, int yIdx>
inline void cvtYUV422toRGBA(Mat& _dst, int _stride, const uchar* _yuv)
{
YUV422toRGBA8888Invoker<bIdx, uIdx, yIdx> converter(&_dst, _stride, _yuv);
#ifdef HAVE_TBB
if (_dst.total() >= MIN_SIZE_FOR_PARALLEL_YUV422_CONVERSION)
parallel_for(BlockedRange(0, _dst.rows), converter);
else
#endif
converter(BlockedRange(0, _dst.rows));
}
}//namespace cv
//////////////////////////////////////////////////////////////////////////////////////////
@@ -3484,11 +3585,56 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
src(Range(0, dstSz.height), Range::all()).copyTo(dst);
}
break;
case COLOR_YUV2RGB_UYVY: case COLOR_YUV2BGR_UYVY: case COLOR_YUV2RGBA_UYVY: case COLOR_YUV2BGRA_UYVY:
case COLOR_YUV2RGB_YUY2: case COLOR_YUV2BGR_YUY2: case COLOR_YUV2RGB_YVYU: case COLOR_YUV2BGR_YVYU:
case COLOR_YUV2RGBA_YUY2: case COLOR_YUV2BGRA_YUY2: case COLOR_YUV2RGBA_YVYU: case COLOR_YUV2BGRA_YVYU:
case COLOR_YUV2GRAY_UYVY: case COLOR_YUV2GRAY_YUY2:
CV_Error(CV_StsUnsupportedFormat, "This format is not supported yet");
case CV_YUV2RGB_UYVY: case CV_YUV2BGR_UYVY: case CV_YUV2RGBA_UYVY: case CV_YUV2BGRA_UYVY:
case CV_YUV2RGB_YUY2: case CV_YUV2BGR_YUY2: case CV_YUV2RGB_YVYU: case CV_YUV2BGR_YVYU:
case CV_YUV2RGBA_YUY2: case CV_YUV2BGRA_YUY2: case CV_YUV2RGBA_YVYU: case CV_YUV2BGRA_YVYU:
{
//http://www.fourcc.org/yuv.php#UYVY
//http://www.fourcc.org/yuv.php#YUY2
//http://www.fourcc.org/yuv.php#YVYU
if (dcn <= 0) dcn = (code==CV_YUV2RGBA_UYVY || code==CV_YUV2BGRA_UYVY || code==CV_YUV2RGBA_YUY2 || code==CV_YUV2BGRA_YUY2 || code==CV_YUV2RGBA_YVYU || code==CV_YUV2BGRA_YVYU) ? 4 : 3;
const int bidx = (code==CV_YUV2BGR_UYVY || code==CV_YUV2BGRA_UYVY || code==CV_YUV2BGR_YUY2 || code==CV_YUV2BGRA_YUY2 || code==CV_YUV2BGR_YVYU || code==CV_YUV2BGRA_YVYU) ? 0 : 2;
const int ycn = (code==CV_YUV2RGB_UYVY || code==CV_YUV2BGR_UYVY || code==CV_YUV2RGBA_UYVY || code==CV_YUV2BGRA_UYVY) ? 1 : 0;
const int uidx = (code==CV_YUV2RGB_YVYU || code==CV_YUV2BGR_YVYU || code==CV_YUV2RGBA_YVYU || code==CV_YUV2BGRA_YVYU) ? 1 : 0;
CV_Assert( dcn == 3 || dcn == 4 );
CV_Assert( scn == 2 && depth == CV_8U );
_dst.create(sz, CV_8UC(dcn));
dst = _dst.getMat();
switch(dcn*1000 + bidx*100 + uidx*10 + ycn)
{
case 3000: cvtYUV422toRGB<0,0,0>(dst, (int)src.step, src.ptr<uchar>()); break;
case 3001: cvtYUV422toRGB<0,0,1>(dst, (int)src.step, src.ptr<uchar>()); break;
case 3010: cvtYUV422toRGB<0,1,0>(dst, (int)src.step, src.ptr<uchar>()); break;
case 3011: cvtYUV422toRGB<0,1,1>(dst, (int)src.step, src.ptr<uchar>()); break;
case 3200: cvtYUV422toRGB<2,0,0>(dst, (int)src.step, src.ptr<uchar>()); break;
case 3201: cvtYUV422toRGB<2,0,1>(dst, (int)src.step, src.ptr<uchar>()); break;
case 3210: cvtYUV422toRGB<2,1,0>(dst, (int)src.step, src.ptr<uchar>()); break;
case 3211: cvtYUV422toRGB<2,1,1>(dst, (int)src.step, src.ptr<uchar>()); break;
case 4000: cvtYUV422toRGBA<0,0,0>(dst, (int)src.step, src.ptr<uchar>()); break;
case 4001: cvtYUV422toRGBA<0,0,1>(dst, (int)src.step, src.ptr<uchar>()); break;
case 4010: cvtYUV422toRGBA<0,1,0>(dst, (int)src.step, src.ptr<uchar>()); break;
case 4011: cvtYUV422toRGBA<0,1,1>(dst, (int)src.step, src.ptr<uchar>()); break;
case 4200: cvtYUV422toRGBA<2,0,0>(dst, (int)src.step, src.ptr<uchar>()); break;
case 4201: cvtYUV422toRGBA<2,0,1>(dst, (int)src.step, src.ptr<uchar>()); break;
case 4210: cvtYUV422toRGBA<2,1,0>(dst, (int)src.step, src.ptr<uchar>()); break;
case 4211: cvtYUV422toRGBA<2,1,1>(dst, (int)src.step, src.ptr<uchar>()); break;
default: CV_Error( CV_StsBadFlag, "Unknown/unsupported color conversion code" ); break;
};
}
break;
case CV_YUV2GRAY_UYVY: case CV_YUV2GRAY_YUY2:
{
if (dcn <= 0) dcn = 1;
CV_Assert( dcn == 1 );
CV_Assert( scn == 2 && depth == CV_8U );
extractChannel(_src, _dst, code == CV_YUV2GRAY_UYVY ? 1 : 0);
}
break;
default:
CV_Error( CV_StsBadFlag, "Unknown/unsupported color conversion code" );

View File

@@ -185,7 +185,8 @@ void FilterEngine::init( const Ptr<BaseFilter>& _filter2D,
if( rowBorderType == BORDER_CONSTANT || columnBorderType == BORDER_CONSTANT )
{
constBorderValue.resize(srcElemSize*borderLength);
scalarToRawData(_borderValue, &constBorderValue[0], srcType,
int srcType1 = CV_MAKETYPE(CV_MAT_DEPTH(srcType), MIN(CV_MAT_CN(srcType), 4));
scalarToRawData(_borderValue, &constBorderValue[0], srcType1,
borderLength*CV_MAT_CN(srcType));
}
@@ -2804,6 +2805,8 @@ cv::Ptr<cv::BaseRowFilter> cv::getLinearRowFilter( int srcType, int bufType,
if( sdepth == CV_32F && ddepth == CV_32F )
return Ptr<BaseRowFilter>(new RowFilter<float, float, RowVec_32f>
(kernel, anchor, RowVec_32f(kernel)));
if( sdepth == CV_32F && ddepth == CV_64F )
return Ptr<BaseRowFilter>(new RowFilter<float, double, RowNoVec>(kernel, anchor));
if( sdepth == CV_64F && ddepth == CV_64F )
return Ptr<BaseRowFilter>(new RowFilter<double, double, RowNoVec>(kernel, anchor));

View File

@@ -2454,7 +2454,8 @@ void cv::remap( InputArray _src, OutputArray _dst,
_dst.create( map1.size(), src.type() );
Mat dst = _dst.getMat();
CV_Assert(dst.data != src.data);
if( dst.data == src.data )
src = src.clone();
int depth = src.depth(), map_depth = map1.depth();
RemapNNFunc nnfunc = 0;
@@ -2823,7 +2824,9 @@ void cv::warpAffine( InputArray _src, OutputArray _dst,
Mat src = _src.getMat(), M0 = _M0.getMat();
_dst.create( dsize.area() == 0 ? src.size() : dsize, src.type() );
Mat dst = _dst.getMat();
CV_Assert( dst.data != src.data && src.cols > 0 && src.rows > 0 );
CV_Assert( src.cols > 0 && src.rows > 0 );
if( dst.data == src.data )
src = src.clone();
const int BLOCK_SZ = 64;
short XY[BLOCK_SZ*BLOCK_SZ*2], A[BLOCK_SZ*BLOCK_SZ];
@@ -2966,7 +2969,9 @@ void cv::warpPerspective( InputArray _src, OutputArray _dst, InputArray _M0,
_dst.create( dsize.area() == 0 ? src.size() : dsize, src.type() );
Mat dst = _dst.getMat();
CV_Assert( dst.data != src.data && src.cols > 0 && src.rows > 0 );
CV_Assert( src.cols > 0 && src.rows > 0 );
if( dst.data == src.data )
src = src.clone();
const int BLOCK_SZ = 32;
short XY[BLOCK_SZ*BLOCK_SZ*2], A[BLOCK_SZ*BLOCK_SZ];

View File

@@ -75,6 +75,23 @@ template<typename T> struct MaxOp
template<> inline uchar MinOp<uchar>::operator ()(uchar a, uchar b) const { return CV_MIN_8U(a, b); }
template<> inline uchar MaxOp<uchar>::operator ()(uchar a, uchar b) const { return CV_MAX_8U(a, b); }
struct MorphRowNoVec
{
MorphRowNoVec(int, int) {}
int operator()(const uchar*, uchar*, int, int) const { return 0; }
};
struct MorphColumnNoVec
{
MorphColumnNoVec(int, int) {}
int operator()(const uchar**, uchar*, int, int, int) const { return 0; }
};
struct MorphNoVec
{
int operator()(uchar**, int, uchar*, int) const { return 0; }
};
#if CV_SSE2
template<class VecUpdate> struct MorphRowIVec
@@ -567,23 +584,6 @@ typedef MorphFVec<VMax32f> DilateVec32f;
#else
struct MorphRowNoVec
{
MorphRowNoVec(int, int) {}
int operator()(const uchar*, uchar*, int, int) const { return 0; }
};
struct MorphColumnNoVec
{
MorphColumnNoVec(int, int) {}
int operator()(const uchar**, uchar*, int, int, int) const { return 0; }
};
struct MorphNoVec
{
int operator()(uchar**, int, uchar*, int) const { return 0; }
};
#ifdef HAVE_TEGRA_OPTIMIZATION
using tegra::ErodeRowVec8u;
using tegra::DilateRowVec8u;
@@ -623,6 +623,13 @@ typedef MorphNoVec DilateVec32f;
#endif
typedef MorphRowNoVec ErodeRowVec64f;
typedef MorphRowNoVec DilateRowVec64f;
typedef MorphColumnNoVec ErodeColumnVec64f;
typedef MorphColumnNoVec DilateColumnVec64f;
typedef MorphNoVec ErodeVec64f;
typedef MorphNoVec DilateVec64f;
template<class Op, class VecOp> struct MorphRowFilter : public BaseRowFilter
{
@@ -861,6 +868,9 @@ cv::Ptr<cv::BaseRowFilter> cv::getMorphologyRowFilter(int op, int type, int ksiz
if( depth == CV_32F )
return Ptr<BaseRowFilter>(new MorphRowFilter<MinOp<float>,
ErodeRowVec32f>(ksize, anchor));
if( depth == CV_64F )
return Ptr<BaseRowFilter>(new MorphRowFilter<MinOp<double>,
ErodeRowVec64f>(ksize, anchor));
}
else
{
@@ -876,6 +886,9 @@ cv::Ptr<cv::BaseRowFilter> cv::getMorphologyRowFilter(int op, int type, int ksiz
if( depth == CV_32F )
return Ptr<BaseRowFilter>(new MorphRowFilter<MaxOp<float>,
DilateRowVec32f>(ksize, anchor));
if( depth == CV_64F )
return Ptr<BaseRowFilter>(new MorphRowFilter<MaxOp<double>,
DilateRowVec64f>(ksize, anchor));
}
CV_Error_( CV_StsNotImplemented, ("Unsupported data type (=%d)", type));
@@ -902,6 +915,9 @@ cv::Ptr<cv::BaseColumnFilter> cv::getMorphologyColumnFilter(int op, int type, in
if( depth == CV_32F )
return Ptr<BaseColumnFilter>(new MorphColumnFilter<MinOp<float>,
ErodeColumnVec32f>(ksize, anchor));
if( depth == CV_64F )
return Ptr<BaseColumnFilter>(new MorphColumnFilter<MinOp<double>,
ErodeColumnVec64f>(ksize, anchor));
}
else
{
@@ -917,6 +933,9 @@ cv::Ptr<cv::BaseColumnFilter> cv::getMorphologyColumnFilter(int op, int type, in
if( depth == CV_32F )
return Ptr<BaseColumnFilter>(new MorphColumnFilter<MaxOp<float>,
DilateColumnVec32f>(ksize, anchor));
if( depth == CV_64F )
return Ptr<BaseColumnFilter>(new MorphColumnFilter<MaxOp<double>,
DilateColumnVec64f>(ksize, anchor));
}
CV_Error_( CV_StsNotImplemented, ("Unsupported data type (=%d)", type));
@@ -940,6 +959,8 @@ cv::Ptr<cv::BaseFilter> cv::getMorphologyFilter(int op, int type, InputArray _ke
return Ptr<BaseFilter>(new MorphFilter<MinOp<short>, ErodeVec16s>(kernel, anchor));
if( depth == CV_32F )
return Ptr<BaseFilter>(new MorphFilter<MinOp<float>, ErodeVec32f>(kernel, anchor));
if( depth == CV_64F )
return Ptr<BaseFilter>(new MorphFilter<MinOp<double>, ErodeVec64f>(kernel, anchor));
}
else
{
@@ -951,6 +972,8 @@ cv::Ptr<cv::BaseFilter> cv::getMorphologyFilter(int op, int type, InputArray _ke
return Ptr<BaseFilter>(new MorphFilter<MaxOp<short>, DilateVec16s>(kernel, anchor));
if( depth == CV_32F )
return Ptr<BaseFilter>(new MorphFilter<MaxOp<float>, DilateVec32f>(kernel, anchor));
if( depth == CV_64F )
return Ptr<BaseFilter>(new MorphFilter<MaxOp<double>, DilateVec64f>(kernel, anchor));
}
CV_Error_( CV_StsNotImplemented, ("Unsupported data type (=%d)", type));
@@ -983,14 +1006,18 @@ cv::Ptr<cv::FilterEngine> cv::createMorphologyFilter( int op, int type, InputArr
borderValue == morphologyDefaultBorderValue() )
{
int depth = CV_MAT_DEPTH(type);
CV_Assert( depth == CV_8U || depth == CV_16U || depth == CV_16S || depth == CV_32F );
CV_Assert( depth == CV_8U || depth == CV_16U || depth == CV_16S ||
depth == CV_32F || depth == CV_64F );
if( op == MORPH_ERODE )
borderValue = Scalar::all( depth == CV_8U ? (double)UCHAR_MAX :
depth == CV_16U ? (double)USHRT_MAX :
depth == CV_16S ? (double)SHRT_MAX : (double)FLT_MAX );
depth == CV_16U ? (double)USHRT_MAX :
depth == CV_16S ? (double)SHRT_MAX :
depth == CV_32F ? (double)FLT_MAX : DBL_MAX);
else
borderValue = Scalar::all( depth == CV_8U || depth == CV_16U ? 0. :
depth == CV_16S ? (double)SHRT_MIN : (double)-FLT_MAX );
borderValue = Scalar::all( depth == CV_8U || depth == CV_16U ?
0. :
depth == CV_16S ? (double)SHRT_MIN :
depth == CV_32F ? (double)-FLT_MAX : -DBL_MAX);
}
return Ptr<FilterEngine>(new FilterEngine(filter2D, rowFilter, columnFilter,

View File

@@ -308,7 +308,7 @@ pyrDown_( const Mat& _src, Mat& _dst, int borderType )
template<class CastOp, class VecOp> void
pyrUp_( const Mat& _src, Mat& _dst, int borderType )
pyrUp_( const Mat& _src, Mat& _dst, int)
{
const int PU_SZ = 3;
typedef typename CastOp::type1 WT;

View File

@@ -58,7 +58,6 @@ void crossCorr( const Mat& img, const Mat& _templ, Mat& corr,
int cdepth = CV_MAT_DEPTH(ctype), ccn = CV_MAT_CN(ctype);
CV_Assert( img.dims <= 2 && templ.dims <= 2 && corr.dims <= 2 );
CV_Assert( depth == CV_8U || depth == CV_16U || depth == CV_32F || depth == CV_64F );
if( depth != tdepth && tdepth != std::max(CV_32F, depth) )
{
@@ -74,7 +73,7 @@ void crossCorr( const Mat& img, const Mat& _templ, Mat& corr,
corr.create(corrsize, ctype);
int maxDepth = depth > CV_8U ? CV_64F : std::max(std::max(CV_32F, tdepth), cdepth);
int maxDepth = depth > CV_8S ? CV_64F : std::max(std::max(CV_32F, tdepth), cdepth);
Size blocksize, dftsize;
blocksize.width = cvRound(templ.cols*blockScale);
@@ -228,14 +227,6 @@ void crossCorr( const Mat& img, const Mat& _templ, Mat& corr,
}
}
/*void
cv::crossCorr( const Mat& img, const Mat& templ, Mat& corr,
Point anchor, double delta, int borderType )
{
CvMat _img = img, _templ = templ, _corr = corr;
icvCrossCorr( &_img, &_templ, &_corr, anchor, delta, borderType );
}*/
}
/*****************************************************************************************/