Skip to content

Commit

Permalink
+add Base implementation of function BgrToYuv422pV2.
Browse files Browse the repository at this point in the history
  • Loading branch information
ermig1979 committed Sep 18, 2023
1 parent fa7b55b commit 2062da4
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/2023.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ <h4>Algorithms</h4>
<h5>New features</h5>
<ul>
<li>Base implementation, SSE4.1, AVX2, AVX-512BW optimizations of function BgrToYuv420pV2.</li>
<li>Base implementation of function BgrToYuv422pV2.</li>
</ul>
<ul>
<li>Error in AVX-512BW optimizations of function SynetSoftmaxLayerForward.</li>
Expand All @@ -47,6 +48,7 @@ <h4>Test framework</h4>
<h5>New features</h5>
<ul>
<li>Tests for verifying functionality of function BgrToYuv420pV2.</li>
<li>Tests for verifying functionality of function BgrToYuv422pV2.</li>
</ul>

<a href="#HOME">Home</a>
Expand Down
104 changes: 104 additions & 0 deletions docs/help/group__bgr__conversion.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Simd/SimdBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ namespace Simd

void BgrToYuv422p(const uint8_t * bgr, size_t width, size_t height, size_t bgrStride, uint8_t * y, size_t yStride, uint8_t * u, size_t uStride, uint8_t * v, size_t vStride);

void BgrToYuv422pV2(const uint8_t* bgr, size_t bgrStride, size_t width, size_t height,
uint8_t* y, size_t yStride, uint8_t* u, size_t uStride, uint8_t* v, size_t vStride, SimdYuvType yuvType);

void BgrToYuv444p(const uint8_t * bgr, size_t width, size_t height, size_t bgrStride, uint8_t * y, size_t yStride, uint8_t * u, size_t uStride, uint8_t * v, size_t vStride);

void Binarization(const uint8_t * src, size_t srcStride, size_t width, size_t height,
Expand Down
45 changes: 45 additions & 0 deletions src/Simd/SimdBaseBgrToYuv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,50 @@ namespace Simd
assert(0);
}
}

//-------------------------------------------------------------------------------------------------

template <class YuvType> SIMD_INLINE void BgrToYuv422pV2(const uint8_t* bgr, uint8_t* y, uint8_t* u, uint8_t* v)
{
y[0] = BgrToY<YuvType>(bgr[0], bgr[1], bgr[2]);
y[1] = BgrToY<YuvType>(bgr[3], bgr[4], bgr[5]);

int blue = Average(bgr[0], bgr[3]);
int green = Average(bgr[1], bgr[4]);
int red = Average(bgr[2], bgr[5]);

u[0] = BgrToU<YuvType>(blue, green, red);
v[0] = BgrToV<YuvType>(blue, green, red);
}

template <class YuvType> void BgrToYuv422pV2(const uint8_t* bgr, size_t bgrStride, size_t width, size_t height,
uint8_t* y, size_t yStride, uint8_t* u, size_t uStride, uint8_t* v, size_t vStride)
{
assert((width % 2 == 0) && (width >= 2));

for (size_t row = 0; row < height; row += 1)
{
for (size_t colUV = 0, colY = 0, colBgr = 0; colY < width; colY += 2, colUV++, colBgr += 6)
BgrToYuv422pV2<YuvType>(bgr + colBgr, y + colY, u + colUV, v + colUV);
y += yStride;
u += uStride;
v += vStride;
bgr += bgrStride;
}
}

void BgrToYuv422pV2(const uint8_t* bgr, size_t bgrStride, size_t width, size_t height,
uint8_t* y, size_t yStride, uint8_t* u, size_t uStride, uint8_t* v, size_t vStride, SimdYuvType yuvType)
{
switch (yuvType)
{
case SimdYuvBt601: BgrToYuv422pV2<Bt601>(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride); break;
case SimdYuvBt709: BgrToYuv422pV2<Bt709>(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride); break;
case SimdYuvBt2020: BgrToYuv422pV2<Bt2020>(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride); break;
case SimdYuvTrect871: BgrToYuv422pV2<Trect871>(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride); break;
default:
assert(0);
}
}
}
}
27 changes: 27 additions & 0 deletions src/Simd/SimdLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,33 @@ SIMD_API void SimdBgrToYuv422p(const uint8_t * bgr, size_t width, size_t height,
Base::BgrToYuv422p(bgr, width, height, bgrStride, y, yStride, u, uStride, v, vStride);
}

SIMD_API void SimdBgrToYuv422pV2(const uint8_t* bgr, size_t bgrStride, size_t width, size_t height,
uint8_t* y, size_t yStride, uint8_t* u, size_t uStride, uint8_t* v, size_t vStride, SimdYuvType yuvType)
{
SIMD_EMPTY();
//#ifdef SIMD_AVX512BW_ENABLE
// if (Avx512bw::Enable)
// Avx512bw::BgrToYuv422pV2(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride, yuvType);
// else
//#endif
//#ifdef SIMD_AVX2_ENABLE
// if (Avx2::Enable && width >= Avx2::DA)
// Avx2::BgrToYuv422pV2(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride, yuvType);
// else
//#endif
//#ifdef SIMD_SSE41_ENABLE
// if (Sse41::Enable && width >= Sse41::DA)
// Sse41::BgrToYuv422pV2(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride, yuvType);
// else
//#endif
//#ifdef SIMD_NEON_ENABLE
// if (Neon::Enable && width >= Neon::DA)
// Neon::BgrToYuv420pV2(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride, yuvType);
// else
//#endif
Base::BgrToYuv422pV2(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride, yuvType);
}

SIMD_API void SimdBgrToYuv444p(const uint8_t * bgr, size_t width, size_t height, size_t bgrStride, uint8_t * y, size_t yStride, uint8_t * u, size_t uStride, uint8_t * v, size_t vStride)
{
SIMD_EMPTY();
Expand Down
24 changes: 24 additions & 0 deletions src/Simd/SimdLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -2194,6 +2194,30 @@ extern "C"
*/
SIMD_API void SimdBgrToYuv422p(const uint8_t * bgr, size_t width, size_t height, size_t bgrStride, uint8_t * y, size_t yStride, uint8_t * u, size_t uStride, uint8_t * v, size_t vStride);

/*! @ingroup bgr_conversion

\fn void SimdBgrToYuv422pV2(const uint8_t * bgr, size_t bgrStride, size_t width, size_t height, uint8_t * y, size_t yStride, uint8_t * u, size_t uStride, uint8_t * v, size_t vStride, SimdYuvType yuvType);

\short Converts 24-bit BGR image to YUV422P.

The input BGR and output Y images must have the same width and height.
The input U and V images must have the same width and height (their width is equal to half width of Y component).

\param [in] bgr - a pointer to pixels data of input 24-bit BGR image.
\param [in] bgrStride - a row size of the BGR image.
\param [in] width - an image width.
\param [in] height - an image height.
\param [out] y - a pointer to pixels data of output 8-bit image with Y color plane.
\param [in] yStride - a row size of the y image.
\param [out] u - a pointer to pixels data of output 8-bit image with U color plane.
\param [in] uStride - a row size of the u image.
\param [out] v - a pointer to pixels data of output 8-bit image with V color plane.
\param [in] vStride - a row size of the v image.
\param [in] yuvType - a type of output YUV image (see descriprion of ::SimdYuvType).
*/
SIMD_API void SimdBgrToYuv422pV2(const uint8_t* bgr, size_t bgrStride, size_t width, size_t height, uint8_t* y, size_t yStride, uint8_t* u, size_t uStride, uint8_t* v, size_t vStride, SimdYuvType yuvType);


/*! @ingroup bgr_conversion

\fn void SimdBgrToYuv444p(const uint8_t * bgr, size_t width, size_t height, size_t bgrStride, uint8_t * y, size_t yStride, uint8_t * u, size_t uStride, uint8_t * v, size_t vStride);
Expand Down
1 change: 1 addition & 0 deletions src/Test/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ namespace Test
TEST_ADD_GROUP_A0(BgrToYuv420p);
TEST_ADD_GROUP_A0(BgrToYuv420pV2);
TEST_ADD_GROUP_A0(BgrToYuv422p);
TEST_ADD_GROUP_A0(BgrToYuv422pV2);
TEST_ADD_GROUP_A0(BgrToYuv444p);
TEST_ADD_GROUP_A0(Uyvy422ToYuv420p);
TEST_ADD_GROUP_A0(BgraToYuva420p);
Expand Down
29 changes: 29 additions & 0 deletions src/Test/TestAnyToYuv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,35 @@ namespace Test
return result;
}

bool BgrToYuv422pV2AutoTest()
{
bool result = true;

result = result && AnyToYuvV2AutoTest(View::Bgr24, 2, 1, FUNC_YUV2(Simd::Base::BgrToYuv422pV2), FUNC_YUV2(SimdBgrToYuv422pV2));

//#ifdef SIMD_SSE41_ENABLE
// if (Simd::Sse41::Enable)
// result = result && AnyToYuvV2AutoTest(View::Bgr24, 2, 1, FUNC_YUV2(Simd::Sse41::BgrToYuv422pV2), FUNC_YUV2(SimdBgrToYuv422pV2));
//#endif
//
//#ifdef SIMD_AVX2_ENABLE
// if (Simd::Avx2::Enable)
// result = result && AnyToYuvV2AutoTest(View::Bgr24, 2, 1, FUNC_YUV2(Simd::Avx2::BgrToYuv422pV2), FUNC_YUV2(SimdBgrToYuv422pV2));
//#endif
//
//#ifdef SIMD_AVX512BW_ENABLE
// if (Simd::Avx512bw::Enable)
// result = result && AnyToYuvV2AutoTest(View::Bgr24, 2, 1, FUNC_YUV2(Simd::Avx512bw::BgrToYuv422pV2), FUNC_YUV2(SimdBgrToYuv422pV2));
//#endif

//#ifdef SIMD_NEON_ENABLE
// if (Simd::Neon::Enable)
// result = result && AnyToYuvV2AutoTest(View::Bgr24, 2, 1, FUNC_YUV2(Simd::Neon::BgrToYuv422pV2), FUNC_YUV2(SimdBgrToYuv422pV2));
//#endif

return result;
}

//-------------------------------------------------------------------------------------------------

namespace
Expand Down

0 comments on commit 2062da4

Please sign in to comment.