Skip to content

Commit

Permalink
+add Base implementation of function BgrToYuv444pV2.
Browse files Browse the repository at this point in the history
  • Loading branch information
ermig1979 committed Sep 19, 2023
1 parent 657e54c commit 1ac70e2
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 5 deletions.
2 changes: 2 additions & 0 deletions docs/2023.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ <h5>New features</h5>
<ul>
<li>Base implementation, SSE4.1, AVX2, AVX-512BW optimizations of function BgrToYuv420pV2.</li>
<li>Base implementation, SSE4.1, AVX2 optimizations of function BgrToYuv422pV2.</li>
<li>Base implementation of function BgrToYuv444pV2.</li>
</ul>
<ul>
<li>Error in AVX-512BW optimizations of function SynetSoftmaxLayerForward.</li>
Expand All @@ -49,6 +50,7 @@ <h5>New features</h5>
<ul>
<li>Tests for verifying functionality of function BgrToYuv420pV2.</li>
<li>Tests for verifying functionality of function BgrToYuv422pV2.</li>
<li>Tests for verifying functionality of function BgrToYuv444pV2.</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 @@ -178,6 +178,9 @@ namespace Simd

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 BgrToYuv444pV2(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 Binarization(const uint8_t * src, size_t srcStride, size_t width, size_t height,
uint8_t value, uint8_t positive, uint8_t negative, uint8_t * dst, size_t dstStride, SimdCompareType compareType);

Expand Down
38 changes: 38 additions & 0 deletions src/Simd/SimdBaseBgrToYuv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,43 @@ namespace Simd
assert(0);
}
}

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

template <class YuvType> SIMD_INLINE void BgrToYuv444pV2(const uint8_t* bgr, uint8_t* y, uint8_t* u, uint8_t* v)
{
const int blue = bgr[0], green = bgr[1], red = bgr[2];
y[0] = BgrToY<YuvType>(blue, green, red);
u[0] = BgrToU<YuvType>(blue, green, red);
v[0] = BgrToV<YuvType>(blue, green, red);
}

template <class YuvType> void BgrToYuv444pV2(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)
{
for (size_t row = 0; row < height; row += 1)
{
for (size_t col = 0; col < width; col++)
BgrToYuv444pV2<YuvType>(bgr + col * 3, y + col, u + col, v + col);
y += yStride;
u += uStride;
v += vStride;
bgr += bgrStride;
}
}

void BgrToYuv444pV2(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: BgrToYuv444pV2<Bt601>(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride); break;
case SimdYuvBt709: BgrToYuv444pV2<Bt709>(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride); break;
case SimdYuvBt2020: BgrToYuv444pV2<Bt2020>(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride); break;
case SimdYuvTrect871: BgrToYuv444pV2<Trect871>(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride); break;
default:
assert(0);
}
}
}
}
29 changes: 28 additions & 1 deletion src/Simd/SimdLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,7 @@ SIMD_API void SimdBgrToYuv422pV2(const uint8_t* bgr, size_t bgrStride, size_t wi
#endif
//#ifdef SIMD_NEON_ENABLE
// if (Neon::Enable && width >= Neon::DA)
// Neon::BgrToYuv420pV2(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride, yuvType);
// Neon::BgrToYuv422pV2(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);
Expand Down Expand Up @@ -1708,6 +1708,33 @@ SIMD_API void SimdBgrToYuv444p(const uint8_t * bgr, size_t width, size_t height,
Base::BgrToYuv444p(bgr, width, height, bgrStride, y, yStride, u, uStride, v, vStride);
}

SIMD_API void SimdBgrToYuv444pV2(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::BgrToYuv444pV2(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride, yuvType);
// else
//#endif
//#ifdef SIMD_AVX2_ENABLE
// if (Avx2::Enable && width >= Avx2::A)
// Avx2::BgrToYuv444pV2(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride, yuvType);
// else
//#endif
//#ifdef SIMD_SSE41_ENABLE
// if (Sse41::Enable && width >= Sse41::A)
// Sse41::BgrToYuv444pV2(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride, yuvType);
// else
//#endif
//#ifdef SIMD_NEON_ENABLE
// if (Neon::Enable && width >= Neon::A)
// Neon::BgrToYuv444pV2(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride, yuvType);
// else
//#endif
Base::BgrToYuv444pV2(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride, yuvType);
}

SIMD_API void SimdBinarization(const uint8_t * src, size_t srcStride, size_t width, size_t height,
uint8_t value, uint8_t positive, uint8_t negative, uint8_t * dst, size_t dstStride, SimdCompareType compareType)
{
Expand Down
22 changes: 22 additions & 0 deletions src/Simd/SimdLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -2241,6 +2241,28 @@ extern "C"
*/
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);

/*! @ingroup bgr_conversion

\fn void SimdBgrToYuv444pV2(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 YUV444P.

The input BGR and output Y, U and V images must have the same width and height.

\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 SimdBgrToYuv444pV2(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 binarization

\fn void SimdBinarization(const uint8_t * src, size_t srcStride, size_t width, size_t height, uint8_t value, uint8_t positive, uint8_t negative, uint8_t * dst, size_t dstStride, SimdCompareType compareType);
Expand Down
1 change: 1 addition & 0 deletions src/Test/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ namespace Test
TEST_ADD_GROUP_A0(BgrToYuv422p);
TEST_ADD_GROUP_A0(BgrToYuv422pV2);
TEST_ADD_GROUP_A0(BgrToYuv444p);
TEST_ADD_GROUP_A0(BgrToYuv444pV2);
TEST_ADD_GROUP_A0(Uyvy422ToYuv420p);
TEST_ADD_GROUP_A0(BgraToYuva420p);
TEST_ADD_GROUP_A0(BgraToYuva420pV2);
Expand Down
37 changes: 33 additions & 4 deletions src/Test/TestAnyToYuv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,10 +549,39 @@ namespace Test
// 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
//#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;
}

bool BgrToYuv444pV2AutoTest()
{
bool result = true;

result = result && AnyToYuvV2AutoTest(View::Bgr24, 1, 1, FUNC_YUV2(Simd::Base::BgrToYuv444pV2), FUNC_YUV2(SimdBgrToYuv444pV2));

//#ifdef SIMD_SSE41_ENABLE
// if (Simd::Sse41::Enable)
// result = result && AnyToYuvV2AutoTest(View::Bgr24, 1, 1, FUNC_YUV2(Simd::Sse41::BgrToYuv444pV2), FUNC_YUV2(SimdBgrToYuv444pV2));
//#endif
//
//#ifdef SIMD_AVX2_ENABLE
// if (Simd::Avx2::Enable)
// result = result && AnyToYuvV2AutoTest(View::Bgr24, 1, 1, FUNC_YUV2(Simd::Avx2::BgrToYuv444pV2), FUNC_YUV2(SimdBgrToYuv444pV2));
//#endif

//#ifdef SIMD_AVX512BW_ENABLE
// if (Simd::Avx512bw::Enable)
// result = result && AnyToYuvV2AutoTest(View::Bgr24, 1, 1, FUNC_YUV2(Simd::Avx512bw::BgrToYuv444pV2), FUNC_YUV2(SimdBgrToYuv444pV2));
//#endif

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

return result;
}
Expand Down

0 comments on commit 1ac70e2

Please sign in to comment.