public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [raw2rgbpnm PATCH 0/2] 10-bit packed raw support
@ 2026-02-17 21:44 Sakari Ailus
  2026-02-17 21:44 ` [raw2rgbpnm PATCH 1/2] Add compiler options to avoid warnings Sakari Ailus
  2026-02-17 21:44 ` [raw2rgbpnm PATCH 2/2] Add 10-bit CSI-2 packed format support Sakari Ailus
  0 siblings, 2 replies; 5+ messages in thread
From: Sakari Ailus @ 2026-02-17 21:44 UTC (permalink / raw)
  To: linux-media; +Cc: Jacopo Mondi, Mehdi Djait, Tomi Valkeinen, laurent.pinchart

Hi all,

These patches add support for 10-bit packed raw formats. Adding support
for more bit depths would be trivial (at least up to 16 bits) but I only
needed 10. :-)

The code could be prettier.

Sakari Ailus (2):
  Add compiler options to avoid warnings
  Add 10-bit CSI-2 packed format support

 Makefile     |  2 +-
 raw2rgbpnm.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 1 deletion(-)

-- 
2.47.3


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [raw2rgbpnm PATCH 1/2] Add compiler options to avoid warnings
  2026-02-17 21:44 [raw2rgbpnm PATCH 0/2] 10-bit packed raw support Sakari Ailus
@ 2026-02-17 21:44 ` Sakari Ailus
  2026-02-17 23:59   ` Laurent Pinchart
  2026-02-17 21:44 ` [raw2rgbpnm PATCH 2/2] Add 10-bit CSI-2 packed format support Sakari Ailus
  1 sibling, 1 reply; 5+ messages in thread
From: Sakari Ailus @ 2026-02-17 21:44 UTC (permalink / raw)
  To: linux-media; +Cc: Jacopo Mondi, Mehdi Djait, Tomi Valkeinen, laurent.pinchart

Add -Wno-missing-field-initializers and -Wno-implicit-fallthrough options
to avoid warnings on modern GCC.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index ab363501a212..8a612710ee2e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 CROSS_COMPILE ?=
 
 CC	:= $(CROSS_COMPILE)gcc
-CFLAGS	?= -O2 -W -Wall -Iinclude
+CFLAGS	?= -O2 -W -Wall -Iinclude -Wno-missing-field-initializers -Wno-implicit-fallthrough
 LDFLAGS	?=
 
 %.o : %.c
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [raw2rgbpnm PATCH 2/2] Add 10-bit CSI-2 packed format support
  2026-02-17 21:44 [raw2rgbpnm PATCH 0/2] 10-bit packed raw support Sakari Ailus
  2026-02-17 21:44 ` [raw2rgbpnm PATCH 1/2] Add compiler options to avoid warnings Sakari Ailus
@ 2026-02-17 21:44 ` Sakari Ailus
  1 sibling, 0 replies; 5+ messages in thread
From: Sakari Ailus @ 2026-02-17 21:44 UTC (permalink / raw)
  To: linux-media; +Cc: Jacopo Mondi, Mehdi Djait, Tomi Valkeinen, laurent.pinchart

Add support for the 10-bit CSI-2 packed raw formats.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 raw2rgbpnm.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)

diff --git a/raw2rgbpnm.c b/raw2rgbpnm.c
index baeb8efc863a..eb711ce5ba6c 100644
--- a/raw2rgbpnm.c
+++ b/raw2rgbpnm.c
@@ -25,6 +25,7 @@
 
 #include <ctype.h>
 #include <stdio.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
@@ -56,6 +57,7 @@ static const struct format_info {
 	unsigned int cb_pos;
 	unsigned int cr_pos;
 	unsigned int planes;
+	__u32 compat_fmt;
 } v4l2_pix_fmt_str[] = {
 	{ V4L2_PIX_FMT_RGB332,	8,  0,  "RGB332 (8 RGB-3-3-2)", 0, 0, 0, 1 },
 	{ V4L2_PIX_FMT_RGB555,	16, 5,  "RGB555 (16 RGB-5-5-5)", 0, 0, 0, 1 },
@@ -98,6 +100,10 @@ static const struct format_info {
 	{ V4L2_PIX_FMT_SGBRG10,	16, 10, "SGBRG10 (10 GBGB.. RGRG..)", 0, 0, 0, 1 },
 	{ V4L2_PIX_FMT_SGRBG10,	16, 10, "SGRBG10 (10 GRGR.. BGBG..)", 0, 0, 0, 1 },
 	{ V4L2_PIX_FMT_SRGGB10,	16, 10, "SRGGB10 (10 RGRG.. GBGB..)", 0, 0, 0, 1 },
+	{ V4L2_PIX_FMT_SBGGR10P, 10, 10, "SBGGR10P (10 BGBG.. GRGR..)", 0, 0, 0, 1, V4L2_PIX_FMT_SBGGR10 },
+	{ V4L2_PIX_FMT_SGBRG10P, 10, 10, "SGBRG10P (10 GBGB.. RGRG..)", 0, 0, 0, 1, V4L2_PIX_FMT_SGBRG10 },
+	{ V4L2_PIX_FMT_SGRBG10P, 10, 10, "SGRBG10P (10 GRGR.. BGBG..)", 0, 0, 0, 1, V4L2_PIX_FMT_SGRBG10 },
+	{ V4L2_PIX_FMT_SRGGB10P, 10, 10, "SRGGB10P (10 RGRG.. GBGB..)", 0, 0, 0, 1, V4L2_PIX_FMT_SRGGB10 },
 	{ V4L2_PIX_FMT_SBGGR12,	16, 12, "SBGGR12 (12 BGBG.. GRGR..)", 0, 0, 0, 1 },
 	{ V4L2_PIX_FMT_SGBRG12,	16, 12, "SGBRG12 (12 GBGB.. RGRG..)", 0, 0, 0, 1 },
 	{ V4L2_PIX_FMT_SGRBG12,	16, 12, "SGRBG12 (12 GRGR.. BGBG..)", 0, 0, 0, 1 },
@@ -186,6 +192,45 @@ static unsigned char *read_raw_data(char *filename, int width, int height,
 	return b;
 }
 
+static inline uint16_t raw_get(uint8_t bpp, uint8_t bpc, unsigned char *ptr,
+			       unsigned int stride, unsigned int x, unsigned int y)
+{
+	switch ((bpp << 8) | bpc) {
+	case 0x0a0a: {
+		unsigned char *base = ptr + y * stride + (x & ~3U) / 4 * 5;
+		unsigned int idx = x & 3U;
+
+		return (base[idx] << 2) | ((base[4] >> (idx << 1)) & 3U);
+	}
+	default:
+		error("getting %u/%u not supported", bpp, bpc);
+	}
+
+	return 0;
+}
+
+static inline void raw_put(uint8_t bpp, uint8_t bpc, unsigned char *ptr,
+			   unsigned int stride, unsigned int x, unsigned int y,
+			   uint16_t value)
+{
+	switch ((bpp << 8) | bpc) {
+	case 0x100a: {
+		unsigned char *base = ptr + y * stride + (x & ~3U) / 4 * 5;
+		unsigned int idx = x & 3U;
+
+		base[idx] = value >> 2;
+		base[4] &= ~(3 << (idx << 1));
+		base[4] |= (value & 3) << (idx << 1);
+		break;
+	}
+	case 0x1010:
+		*(uint16_t *)&ptr[y * stride + x * 2] = value;
+		break;
+	default:
+		error("putting %u/%u not supported", bpp, bpc);
+	}
+}
+
 static int raw_layout_to_grbg(const struct format_info *info, unsigned char *src,
 			      int src_width, int src_height, unsigned int src_stride)
 {
@@ -283,6 +328,7 @@ static int raw_layout_to_grbg(const struct format_info *info, unsigned char *src
 static void raw_to_rgb(const struct format_info *info,
 		       unsigned char *src, int src_width, int src_height, unsigned char *rgb)
 {
+	unsigned char *tmp_src = NULL;
 	unsigned int src_stride = src_width * info->bpp / 8;
 	unsigned int rgb_stride = src_width * 3;
 	unsigned char *src_luma, *src_chroma;
@@ -298,6 +344,37 @@ static void raw_to_rgb(const struct format_info *info,
 	int cr_pos;
 	int shift;
 
+	switch (info->fmt) {
+	case V4L2_PIX_FMT_SBGGR10P:
+	case V4L2_PIX_FMT_SGBRG10P:
+	case V4L2_PIX_FMT_SRGGB10P:
+	case V4L2_PIX_FMT_SGRBG10P: {
+		unsigned int new_stride = src_width * 2;
+
+		tmp_src = malloc(new_stride * src_height);
+		if (!tmp_src)
+			error("can't allocate memory for the temporary buffer");
+
+		for (src_y = 0; src_y < src_height; src_y++)
+			for (src_x = 0; src_x < src_width; src_x++)
+				raw_put(16, 16, tmp_src, new_stride, src_x, src_y,
+					raw_get(info->bpp, info->bpc, src, src_stride, src_x, src_y));
+
+		src_stride = new_stride;
+		src = tmp_src;
+
+		for (unsigned int i = 0; i < SIZE(v4l2_pix_fmt_str); i++) {
+			if (v4l2_pix_fmt_str[i].fmt == info->compat_fmt) {
+				info = &v4l2_pix_fmt_str[i];
+				break;
+			}
+		}
+
+		if (info->compat_fmt)
+			error("no supported format found");
+	}
+	}
+
 	switch (info->fmt) {
 	case V4L2_PIX_FMT_VYUY:
 	case V4L2_PIX_FMT_YVYU:
@@ -734,6 +811,8 @@ static void raw_to_rgb(const struct format_info *info,
 		}
 		break;
 	}
+
+	free(tmp_src);
 }
 
 static int parse_format(const char *p, int *w, int *h)
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [raw2rgbpnm PATCH 1/2] Add compiler options to avoid warnings
  2026-02-17 21:44 ` [raw2rgbpnm PATCH 1/2] Add compiler options to avoid warnings Sakari Ailus
@ 2026-02-17 23:59   ` Laurent Pinchart
  2026-02-18  8:18     ` Sakari Ailus
  0 siblings, 1 reply; 5+ messages in thread
From: Laurent Pinchart @ 2026-02-17 23:59 UTC (permalink / raw)
  To: Sakari Ailus; +Cc: linux-media, Jacopo Mondi, Mehdi Djait, Tomi Valkeinen

On Tue, Feb 17, 2026 at 11:44:34PM +0200, Sakari Ailus wrote:
> Add -Wno-missing-field-initializers and -Wno-implicit-fallthrough options

How about fixing the implicit fallthrough occurrences ? :-)

> to avoid warnings on modern GCC.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> ---
>  Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/Makefile b/Makefile
> index ab363501a212..8a612710ee2e 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1,7 +1,7 @@
>  CROSS_COMPILE ?=
>  
>  CC	:= $(CROSS_COMPILE)gcc
> -CFLAGS	?= -O2 -W -Wall -Iinclude
> +CFLAGS	?= -O2 -W -Wall -Iinclude -Wno-missing-field-initializers -Wno-implicit-fallthrough
>  LDFLAGS	?=
>  
>  %.o : %.c

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [raw2rgbpnm PATCH 1/2] Add compiler options to avoid warnings
  2026-02-17 23:59   ` Laurent Pinchart
@ 2026-02-18  8:18     ` Sakari Ailus
  0 siblings, 0 replies; 5+ messages in thread
From: Sakari Ailus @ 2026-02-18  8:18 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: linux-media, Jacopo Mondi, Mehdi Djait, Tomi Valkeinen

On Wed, Feb 18, 2026 at 12:59:33AM +0100, Laurent Pinchart wrote:
> On Tue, Feb 17, 2026 at 11:44:34PM +0200, Sakari Ailus wrote:
> > Add -Wno-missing-field-initializers and -Wno-implicit-fallthrough options
> 
> How about fixing the implicit fallthrough occurrences ? :-)

Well, at this time of day it seems a more plausible approach. :-) But it
introduces a compiler dependency which I guess is fine nowadays though.

-- 
Sakari Ailus

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-02-18  8:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-17 21:44 [raw2rgbpnm PATCH 0/2] 10-bit packed raw support Sakari Ailus
2026-02-17 21:44 ` [raw2rgbpnm PATCH 1/2] Add compiler options to avoid warnings Sakari Ailus
2026-02-17 23:59   ` Laurent Pinchart
2026-02-18  8:18     ` Sakari Ailus
2026-02-17 21:44 ` [raw2rgbpnm PATCH 2/2] Add 10-bit CSI-2 packed format support Sakari Ailus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox