public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Daniel Gomez <daniel@qtec.com>
To: linux-media@vger.kernel.org
Cc: ricardo@ribalda.com, daniel@qtec.com
Subject: [PATCH 2/2] libv4lconvert: add support for BAYER16
Date: Wed, 27 Feb 2019 15:47:10 +0100	[thread overview]
Message-ID: <20190227144710.32427-2-daniel@qtec.com> (raw)
In-Reply-To: <20190227144710.32427-1-daniel@qtec.com>

Add support for 16 bit Bayer formats:
	-V4L2_PIX_FMT_SBGGR16
	-V4L2_PIX_FMT_SGBRG16
	-V4L2_PIX_FMT_SGRBG16
	-V4L2_PIX_FMT_SRGGB16

Tested using vivid included in linux v5.0-rc8.

Signed-off-by: Daniel Gomez <daniel@qtec.com>
---
 lib/libv4lconvert/bayer.c              |  9 ++++++
 lib/libv4lconvert/libv4lconvert-priv.h |  3 ++
 lib/libv4lconvert/libv4lconvert.c      | 45 ++++++++++++++++++++++++++
 3 files changed, 57 insertions(+)

diff --git a/lib/libv4lconvert/bayer.c b/lib/libv4lconvert/bayer.c
index 96d26cce..7748e68d 100644
--- a/lib/libv4lconvert/bayer.c
+++ b/lib/libv4lconvert/bayer.c
@@ -662,3 +662,12 @@ void v4lconvert_bayer10p_to_bayer8(unsigned char *bayer10p,
 		bayer8 += 4;
 	}
 }
+
+void v4lconvert_bayer16_to_bayer8(unsigned char *bayer16,
+		unsigned char *bayer8, int width, int height)
+{
+	int i;
+
+	for (i = 0; i < width * height; i++)
+		bayer8[i] = bayer16[2*i+1];
+}
diff --git a/lib/libv4lconvert/libv4lconvert-priv.h b/lib/libv4lconvert/libv4lconvert-priv.h
index 44d2d32e..a8046ce2 100644
--- a/lib/libv4lconvert/libv4lconvert-priv.h
+++ b/lib/libv4lconvert/libv4lconvert-priv.h
@@ -270,6 +270,9 @@ void v4lconvert_bayer10_to_bayer8(void *bayer10,
 void v4lconvert_bayer10p_to_bayer8(unsigned char *bayer10p,
 		unsigned char *bayer8, int width, int height);
 
+void v4lconvert_bayer16_to_bayer8(unsigned char *bayer16,
+		unsigned char *bayer8, int width, int height);
+
 void v4lconvert_hm12_to_rgb24(const unsigned char *src,
 		unsigned char *dst, int width, int height);
 
diff --git a/lib/libv4lconvert/libv4lconvert.c b/lib/libv4lconvert/libv4lconvert.c
index a8cf856a..7dc409f2 100644
--- a/lib/libv4lconvert/libv4lconvert.c
+++ b/lib/libv4lconvert/libv4lconvert.c
@@ -140,6 +140,10 @@ static const struct v4lconvert_pixfmt supported_src_pixfmts[] = {
 	{ V4L2_PIX_FMT_SGBRG10,		16,	 8,	 8,	1 },
 	{ V4L2_PIX_FMT_SGRBG10,		16,	 8,	 8,	1 },
 	{ V4L2_PIX_FMT_SRGGB10,		16,	 8,	 8,	1 },
+	{ V4L2_PIX_FMT_SBGGR16,		16,	 8,	 8,	1 },
+	{ V4L2_PIX_FMT_SGBRG16,		16,	 8,	 8,	1 },
+	{ V4L2_PIX_FMT_SGRBG16,		16,	 8,	 8,	1 },
+	{ V4L2_PIX_FMT_SRGGB16,		16,	 8,	 8,	1 },
 	/* compressed bayer */
 	{ V4L2_PIX_FMT_SPCA561,		 0,	 9,	 9,	1 },
 	{ V4L2_PIX_FMT_SN9C10X,		 0,	 9,	 9,	1 },
@@ -702,6 +706,10 @@ static int v4lconvert_processing_needs_double_conversion(
 	case V4L2_PIX_FMT_SGBRG10:
 	case V4L2_PIX_FMT_SGRBG10:
 	case V4L2_PIX_FMT_SRGGB10:
+	case V4L2_PIX_FMT_SBGGR16:
+	case V4L2_PIX_FMT_SGBRG16:
+	case V4L2_PIX_FMT_SGRBG16:
+	case V4L2_PIX_FMT_SRGGB16:
 	case V4L2_PIX_FMT_STV0680:
 		return 0;
 	}
@@ -1052,6 +1060,43 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data,
 		}
 	}
 
+	case V4L2_PIX_FMT_SBGGR16:
+	case V4L2_PIX_FMT_SGBRG16:
+	case V4L2_PIX_FMT_SGRBG16:
+	case V4L2_PIX_FMT_SRGGB16: {
+		int b16format = 1;
+
+		switch (src_pix_fmt) {
+		case V4L2_PIX_FMT_SBGGR16:
+			src_pix_fmt = V4L2_PIX_FMT_SBGGR8;
+			break;
+		case V4L2_PIX_FMT_SGBRG16:
+			src_pix_fmt = V4L2_PIX_FMT_SGBRG8;
+			break;
+		case V4L2_PIX_FMT_SGRBG16:
+			src_pix_fmt = V4L2_PIX_FMT_SGRBG8;
+			break;
+		case V4L2_PIX_FMT_SRGGB16:
+			src_pix_fmt = V4L2_PIX_FMT_SRGGB8;
+			break;
+		default:
+			b16format = 0;
+			break;
+		}
+
+		if (b16format) {
+			if (src_size < ((width * height * 2))) {
+				V4LCONVERT_ERR
+					("short raw bayer16 data frame\n");
+				errno = EPIPE;
+				result = -1;
+				break;
+			}
+			v4lconvert_bayer16_to_bayer8(src, src, width, height);
+			bytesperline = width;
+		}
+	}
+
 	/* Fall-through*/
 	case V4L2_PIX_FMT_SBGGR8:
 	case V4L2_PIX_FMT_SGBRG8:
-- 
2.20.1


  reply	other threads:[~2019-02-27 14:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-27 14:47 [PATCH 1/2] libv4lconvert: add support for BAYER10 Daniel Gomez
2019-02-27 14:47 ` Daniel Gomez [this message]
2019-02-27 15:15   ` [PATCH 2/2] libv4lconvert: add support for BAYER16 Ricardo Ribalda Delgado
2019-02-27 15:15 ` [PATCH 1/2] libv4lconvert: add support for BAYER10 Ricardo Ribalda Delgado

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190227144710.32427-2-daniel@qtec.com \
    --to=daniel@qtec.com \
    --cc=linux-media@vger.kernel.org \
    --cc=ricardo@ribalda.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox