Closed trlsmax closed 2 years ago
In common case YUV to Gray conversion looks like:
g = (Y - 16) * 255 / 220
Or do I mistake?
P.S. Your optimization looks like valid. For example see function Simd::Neon::DeinterleaveUv .
You are right. But my application will ok for only Y. And finally come up with something like this:
template <bool align> void UyvyToGray8(const uint8_t * data, size_t uvStride, size_t width, size_t height, uint8_t * gray, size_t gStride)
{
assert(width >= A);
if (align)
{
assert(Aligned(data) && Aligned(uvStride));
}
size_t bodyWidth = AlignLo(width, A);
size_t tail = width - bodyWidth;
for (size_t row = 0; row < height; ++row)
{
for (size_t col = 0, offset = 0; col < bodyWidth; col += A, offset += DA)
{
uint8x16x2_t _uv = Load2<align>(data + offset);
Store<align>(gray + col, _uv.val[1]);
}
if (tail)
{
size_t col = width - A;
size_t offset = 2 * col;
uint8x16x2_t _uv = Load2<false>(data + offset);
Store<false>(gray + col, _uv.val[1]);
}
data += uvStride;
gray += gStride;
}
}
now it only use 5ms to process. Thank you.
I want to convert a uyvy buffer from v4l2 device to a gray8 View. this function used about 40ms on my RaspberryPi4
So I tried simd version:
this version cause program crash. Any idea?