Skip to content

Commit

Permalink
+add Base implementation of function BgrToYuv420pV2.
Browse files Browse the repository at this point in the history
  • Loading branch information
ermig1979 committed Sep 14, 2023
1 parent 8fc3a6e commit 70a6eb4
Show file tree
Hide file tree
Showing 9 changed files with 248 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/2023.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,20 @@ <h1>Simd Library Release Notes (2023).</h1>
<hr/>
<h3 id="R130">October X, 2023 (version X.X.130)</h3>
<h4>Algorithms</h4>
<h5>New features</h5>
<ul>
<li>Base implementation of function BgrToYuv420pV2.</li>
</ul>
<ul>
<li>Error in AVX-512BW optimizations of function SynetSoftmaxLayerForward.</li>
</ul>

<h4>Test framework</h4>
<h5>New features</h5>
<ul>
<li>Tests for verifying functionality of function BgrToYuv420pV2.</li>
</ul>

<a href="#HOME">Home</a>
<hr/>
<h3 id="R129">September 4, 2023 (version 5.3.129)</h3>
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 @@ -168,6 +168,9 @@ namespace Simd

void BgrToYuv420p(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 BgrToYuv420pV2(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 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 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);
Expand Down
51 changes: 51 additions & 0 deletions src/Simd/SimdBaseBgrToYuv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* SOFTWARE.
*/
#include "Simd/SimdConversion.h"
#include "Simd/SimdYuvToBgr.h"

namespace Simd
{
Expand Down Expand Up @@ -114,5 +115,55 @@ namespace Simd
bgr += bgrStride;
}
}

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

template <class YuvType> SIMD_INLINE void BgrToYuv420pV2(const uint8_t* bgr0, size_t bgrStride, uint8_t* y0, size_t yStride, uint8_t* u, uint8_t* v)
{
const uint8_t* bgr1 = bgr0 + bgrStride;
uint8_t* y1 = y0 + yStride;

y0[0] = BgrToY<YuvType>(bgr0[0], bgr0[1], bgr0[2]);
y0[1] = BgrToY<YuvType>(bgr0[2], bgr0[4], bgr0[5]);
y1[0] = BgrToY<YuvType>(bgr1[0], bgr1[1], bgr1[2]);
y1[1] = BgrToY<YuvType>(bgr1[3], bgr1[4], bgr1[5]);

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

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

template <class YuvType> void BgrToYuv420pV2(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) && (height % 2 == 0) && (width >= 2) && (height >= 2));

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

void BgrToYuv420pV2(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: BgrToYuv420pV2<Bt601>(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride); break;
case SimdYuvBt709: BgrToYuv420pV2<Bt709>(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride); break;
case SimdYuvBt2020: BgrToYuv420pV2<Bt2020>(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride); break;
case SimdYuvTrect871: BgrToYuv420pV2<Trect871>(bgr, bgrStride, width, height, y, yStride, u, uStride, v, vStride); break;
default:
assert(0);
}
}
}
}
1 change: 0 additions & 1 deletion src/Simd/SimdBaseBgraToYuv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,5 @@ namespace Simd
assert(0);
}
}

}
}
27 changes: 27 additions & 0 deletions src/Simd/SimdLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,33 @@ SIMD_API void SimdBgrToYuv420p(const uint8_t * bgr, size_t width, size_t height,
Base::BgrToYuv420p(bgr, width, height, bgrStride, y, yStride, u, uStride, v, vStride);
}

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

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)
{
SIMD_EMPTY();
Expand Down
23 changes: 23 additions & 0 deletions src/Simd/SimdLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -2147,6 +2147,29 @@ extern "C"
*/
SIMD_API void SimdBgrToYuv420p(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 SimdBgrToYuv420pV2(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 YUV420P.

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 (half size relative to 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 SimdBgrToYuv420pV2(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 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);
Expand Down
1 change: 1 addition & 0 deletions src/Test/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ namespace Test
TEST_ADD_GROUP_A0(BgraToYuv444p);
TEST_ADD_GROUP_A0(BgraToYuv444pV2);
TEST_ADD_GROUP_A0(BgrToYuv420p);
TEST_ADD_GROUP_A0(BgrToYuv420pV2);
TEST_ADD_GROUP_A0(BgrToYuv422p);
TEST_ADD_GROUP_A0(BgrToYuv444p);
TEST_ADD_GROUP_A0(Uyvy422ToYuv420p);
Expand Down
29 changes: 29 additions & 0 deletions src/Test/TestAnyToYuv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,35 @@ namespace Test
return result;
}

bool BgrToYuv420pV2AutoTest()
{
bool result = true;

result = result && AnyToYuvV2AutoTest(View::Bgr24, 2, 2, FUNC_YUV2(Simd::Base::BgrToYuv420pV2), FUNC_YUV2(SimdBgrToYuv420pV2));

//#ifdef SIMD_SSE41_ENABLE
// if (Simd::Sse41::Enable)
// result = result && AnyToYuvV2AutoTest(View::Bgr24, 2, 2, FUNC_YUV2(Simd::Sse41::BgrToYuv420pV2), FUNC_YUV2(SimdBgrToYuv420pV2));
//#endif
//
//#ifdef SIMD_AVX2_ENABLE
// if (Simd::Avx2::Enable)
// result = result && AnyToYuvV2AutoTest(View::Bgr24, 2, 2, FUNC_YUV2(Simd::Avx2::BgrToYuv420pV2), FUNC_YUV2(SimdBgrToYuv420pV2));
//#endif
//
//#ifdef SIMD_AVX512BW_ENABLE
// if (Simd::Avx512bw::Enable)
// result = result && AnyToYuvV2AutoTest(View::Bgr24, 2, 2, FUNC_YUV2(Simd::Avx512bw::BgrToYuv420pV2), FUNC_YUV2(SimdBgrToYuv420pV2));
//#endif
//
//#ifdef SIMD_NEON_ENABLE
// if (Simd::Neon::Enable)
// result = result && AnyToYuvV2AutoTest(View::Bgr24, 2, 2, FUNC_YUV2(Simd::Neon::BgrToYuv420pV2), FUNC_YUV2(SimdBgrToYuv420pV2));
//#endif

return result;
}

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

namespace
Expand Down

0 comments on commit 70a6eb4

Please sign in to comment.