X-Git-Url: https://git.sesse.net/?p=bmusb;a=blobdiff_plain;f=fake_capture.cpp;h=e06ac3a098b4bf3e11b3b4649beae807c9f2a3b0;hp=c98e74cf3351f5063cad260001b236acc9870034;hb=HEAD;hpb=e85d7ee1c0541900c57dd505454289dfaab9e782 diff --git a/fake_capture.cpp b/fake_capture.cpp index c98e74c..e06ac3a 100644 --- a/fake_capture.cpp +++ b/fake_capture.cpp @@ -218,6 +218,23 @@ bool timespec_less_than(const timespec &a, const timespec &b) return make_pair(a.tv_sec, a.tv_nsec) < make_pair(b.tv_sec, b.tv_nsec); } +void fill_color_noninterleaved(uint8_t *dst, uint8_t y, uint8_t cb, uint8_t cr, const VideoFormat &video_format, bool ten_bit) +{ + if (ten_bit) { + // Just use the 8-bit-values shifted left by 2. + // It's not 100% correct, but it's close enough. + uint32_t pix[4]; + pix[0] = (cb << 2) | (y << 12) | (cr << 22); + pix[1] = (y << 2) | (cb << 12) | ( y << 22); + pix[2] = (cr << 2) | (y << 12) | (cb << 22); + pix[3] = (y << 2) | (cr << 12) | ( y << 22); + memset16(dst, pix, video_format.stride * video_format.height / sizeof(pix)); + } else { + uint8_t ycbcr[] = { cb, y, cr, y }; + memset4(dst, ycbcr, video_format.width * video_format.height / 2); + } +} + } // namespace void FakeCapture::producer_thread_func() @@ -285,19 +302,10 @@ void FakeCapture::producer_thread_func() memset2(video_frame.data, cbcr, width * height / 2); memset(video_frame.data2, y, width * height); } else { - if (current_pixel_format == PixelFormat_10BitYCbCr) { - // Just use the 8-bit-values shifted left by 2. - // It's not 100% correct, but it's close enough. - uint32_t pix[4]; - pix[0] = (cb << 2) | (y << 12) | (cr << 22); - pix[1] = (y << 2) | (cb << 12) | ( y << 22); - pix[2] = (cr << 2) | (y << 12) | (cb << 22); - pix[3] = (y << 2) | (cr << 12) | ( y << 22); - memset16(video_frame.data, pix, video_format.stride * height / sizeof(pix)); - } else { - uint8_t ycbcr[] = { y, cb, y, cr }; - memset4(video_frame.data, ycbcr, width * height / 2); - } + fill_color_noninterleaved(video_frame.data, y, cb, cr, video_format, current_pixel_format == PixelFormat_10BitYCbCr); + } + if (video_frame.data_copy != nullptr) { + fill_color_noninterleaved(video_frame.data_copy, y, cb, cr, video_format, current_pixel_format == PixelFormat_10BitYCbCr); } video_frame.len = video_format.stride * height; video_frame.received_timestamp = timestamp;