From 0de093b62c556b59b751659295d38b43bea8f288 Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Wed, 11 Nov 2020 17:17:29 +0100 Subject: [PATCH] First pass of 10 bits quick debayer --- quickpreview.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/quickpreview.c b/quickpreview.c index b142b33..fbf8a6b 100644 --- a/quickpreview.c +++ b/quickpreview.c @@ -40,36 +40,72 @@ void quick_debayer(const uint8_t *source, uint8_t *destination, uint32_t pix_fmt, int width, int height, int skip, int blacklevel) { - int byteskip = 2 * skip; + int fragmentsize = 4; + int byteskip = fragmentsize * skip; int input_size = width * height; int i = 0, j = 0; int row_left = width; + switch (pix_fmt) { + case V4L2_PIX_FMT_SBGGR8: + case V4L2_PIX_FMT_SGBRG8: + case V4L2_PIX_FMT_SGRBG8: + case V4L2_PIX_FMT_SRGGB8: + break; + case V4L2_PIX_FMT_SBGGR10P: + case V4L2_PIX_FMT_SGBRG10P: + case V4L2_PIX_FMT_SGRBG10P: + case V4L2_PIX_FMT_SRGGB10P: + fragmentsize = 4; + byteskip = fragmentsize * skip; + break; + } + do { uint8_t b0 = srgb[source[i] - blacklevel]; uint8_t b1 = srgb[source[i + 1] - blacklevel]; uint8_t b2 = srgb[source[i + width + 1] - blacklevel]; + uint8_t b3 = srgb[source[i + 2] - blacklevel]; + uint8_t b4 = srgb[source[i + 3] - blacklevel]; + uint8_t b5 = srgb[source[i + width + 2] - blacklevel]; switch (pix_fmt) { case V4L2_PIX_FMT_SBGGR8: + case V4L2_PIX_FMT_SBGGR10P: quick_debayer_set_dst(&destination[j], b2, b1, b0); + j += 3; + quick_debayer_set_dst(&destination[j], + b5, b4, b3); break; case V4L2_PIX_FMT_SGBRG8: + case V4L2_PIX_FMT_SGBRG10P: quick_debayer_set_dst(&destination[j], b1, b2, b0); + j += 3; + quick_debayer_set_dst(&destination[j], + b4, b4, b3); break; case V4L2_PIX_FMT_SGRBG8: + case V4L2_PIX_FMT_SGRBG10P: quick_debayer_set_dst(&destination[j], b1, b0, b2); + j += 3; + quick_debayer_set_dst(&destination[j], + b4, b3, b5); break; case V4L2_PIX_FMT_SRGGB8: + case V4L2_PIX_FMT_SRGGB10P: /* fall through */ default: quick_debayer_set_dst(&destination[j], b0, b1, b2); + j += 3; + quick_debayer_set_dst(&destination[j], + b3, b4, b5); break; } + j += 3; i = i + byteskip;