[v3,4/7] libcamera: formats: Add PiSP specific image and config buffer formats
diff mbox series

Message ID 20240510100208.12188-5-naush@raspberrypi.com
State Accepted
Commit 8c93055043a522715f7bdc51af1b25cafa68e3d1
Headers show
Series
  • Pre Raspberry Pi 5 support changes
Related show

Commit Message

Naushir Patuck May 10, 2024, 10:02 a.m. UTC
Add the Raspberry Pi 5 PiSP specific compressed Bayer format types 1/2:
- V4L2_PIX_FMT_PISP_COMP1_xxx
- V4L2_PIX_FMT_PISP_COMP2_xxx

Add the Raspberry Pi 5 PiSP Frontend and Backend config formats:
- V4L2_META_FMT_RPI_FE_CFG
- V4L2_META_FMT_RPI_BE_CFG

Add the Raspberry Pi 5 PiSP Frontend statistics format:
- V4L2_META_FMT_RPI_FE_STATS

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 include/libcamera/internal/bayer_format.h |  2 +
 src/libcamera/bayer_format.cpp            | 18 ++++++++
 src/libcamera/formats.cpp                 | 51 ++++++++++++++++++++++-
 src/libcamera/formats.yaml                | 16 +++++++
 src/libcamera/v4l2_pixelformat.cpp        | 10 +++++
 5 files changed, 96 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h
index e2e69ecc3b49..5c14bb5fb2d5 100644
--- a/include/libcamera/internal/bayer_format.h
+++ b/include/libcamera/internal/bayer_format.h
@@ -34,6 +34,8 @@  public:
 		None = 0,
 		CSI2 = 1,
 		IPU3 = 2,
+		PISP1 = 3,
+		PISP2 = 4,
 	};
 
 	constexpr BayerFormat()
diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp
index e7ecadcee534..014f716d28f7 100644
--- a/src/libcamera/bayer_format.cpp
+++ b/src/libcamera/bayer_format.cpp
@@ -61,6 +61,10 @@  namespace libcamera {
  * \brief Format uses MIPI CSI-2 style packing
  * \var BayerFormat::Packing::IPU3
  * \brief Format uses IPU3 style packing
+ * \var BayerFormat::Packing::PISP1
+ * \brief Format uses PISP mode 1 compression
+ * \var BayerFormat::Packing::PISP2
+ * \brief Format uses PISP mode 2 compression
  */
 
 namespace {
@@ -164,6 +168,14 @@  const std::map<BayerFormat, Formats, BayerFormatComparator> bayerToFormat{
 		{ formats::SGRBG16, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16) } },
 	{ { BayerFormat::RGGB, 16, BayerFormat::Packing::None },
 		{ formats::SRGGB16, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16) } },
+	{ { BayerFormat::BGGR, 16, BayerFormat::Packing::PISP1 },
+		{ formats::BGGR_PISP_COMP1, V4L2PixelFormat(V4L2_PIX_FMT_PISP_COMP1_BGGR) } },
+	{ { BayerFormat::GBRG, 16, BayerFormat::Packing::PISP1 },
+		{ formats::GBRG_PISP_COMP1, V4L2PixelFormat(V4L2_PIX_FMT_PISP_COMP1_GBRG) } },
+	{ { BayerFormat::GRBG, 16, BayerFormat::Packing::PISP1 },
+		{ formats::GRBG_PISP_COMP1, V4L2PixelFormat(V4L2_PIX_FMT_PISP_COMP1_GRBG) } },
+	{ { BayerFormat::RGGB, 16, BayerFormat::Packing::PISP1 },
+		{ formats::RGGB_PISP_COMP1, V4L2PixelFormat(V4L2_PIX_FMT_PISP_COMP1_RGGB) } },
 	{ { BayerFormat::MONO, 8, BayerFormat::Packing::None },
 		{ formats::R8, V4L2PixelFormat(V4L2_PIX_FMT_GREY) } },
 	{ { BayerFormat::MONO, 10, BayerFormat::Packing::None },
@@ -174,6 +186,8 @@  const std::map<BayerFormat, Formats, BayerFormatComparator> bayerToFormat{
 		{ formats::R12, V4L2PixelFormat(V4L2_PIX_FMT_Y12) } },
 	{ { BayerFormat::MONO, 16, BayerFormat::Packing::None },
 		{ formats::R16, V4L2PixelFormat(V4L2_PIX_FMT_Y16) } },
+	{ { BayerFormat::MONO, 16, BayerFormat::Packing::PISP1 },
+		{ formats::MONO_PISP_COMP1, V4L2PixelFormat(V4L2_PIX_FMT_PISP_COMP1_MONO) } },
 };
 
 const std::unordered_map<unsigned int, BayerFormat> mbusCodeToBayer{
@@ -303,6 +317,10 @@  std::ostream &operator<<(std::ostream &out, const BayerFormat &f)
 		out << "-CSI2P";
 	else if (f.packing == BayerFormat::Packing::IPU3)
 		out << "-IPU3P";
+	else if (f.packing == BayerFormat::Packing::PISP1)
+		out << "-PISP1";
+	else if (f.packing == BayerFormat::Packing::PISP2)
+		out << "-PISP2";
 
 	return out;
 }
diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
index e2d292c232a5..cf41f2c261ed 100644
--- a/src/libcamera/formats.cpp
+++ b/src/libcamera/formats.cpp
@@ -547,6 +547,16 @@  const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
 		.pixelsPerGroup = 1,
 		.planes = {{ { 2, 1 }, { 0, 0 }, { 0, 0 } }},
 	} },
+	{ formats::MONO_PISP_COMP1, {
+		.name = "MONO_PISP_COMP1",
+		.format = formats::MONO_PISP_COMP1,
+		.v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_PISP_COMP1_MONO), },
+		.bitsPerPixel = 8,
+		.colourEncoding = PixelFormatInfo::ColourEncodingYUV,
+		.packed = true,
+		.pixelsPerGroup = 1,
+		.planes = {{ { 1, 1 }, { 0, 0 }, { 0, 0 } }},
+	} },
 
 	/* Bayer formats. */
 	{ formats::SBGGR8, {
@@ -910,7 +920,46 @@  const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
 		.pixelsPerGroup = 25,
 		.planes = {{ { 32, 1 }, { 0, 0 }, { 0, 0 } }},
 	} },
-
+	{ formats::BGGR_PISP_COMP1, {
+		.name = "BGGR_PISP_COMP1",
+		.format = formats::BGGR_PISP_COMP1,
+		.v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_PISP_COMP1_BGGR), },
+		.bitsPerPixel = 8,
+		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
+		.packed = true,
+		.pixelsPerGroup = 2,
+		.planes = {{ { 2, 1 }, { 0, 0 }, { 0, 0 } }},
+	} },
+	{ formats::GBRG_PISP_COMP1, {
+		.name = "GBRG_PISP_COMP1",
+		.format = formats::GBRG_PISP_COMP1,
+		.v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_PISP_COMP1_GBRG), },
+		.bitsPerPixel = 8,
+		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
+		.packed = true,
+		.pixelsPerGroup = 2,
+		.planes = {{ { 2, 1 }, { 0, 0 }, { 0, 0 } }},
+	} },
+	{ formats::GRBG_PISP_COMP1, {
+		.name = "GRBG_PISP_COMP1",
+		.format = formats::GRBG_PISP_COMP1,
+		.v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_PISP_COMP1_GRBG), },
+		.bitsPerPixel = 8,
+		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
+		.packed = true,
+		.pixelsPerGroup = 2,
+		.planes = {{ { 2, 1 }, { 0, 0 }, { 0, 0 } }},
+	} },
+	{ formats::RGGB_PISP_COMP1, {
+		.name = "RGGB_PISP_COMP1",
+		.format = formats::RGGB_PISP_COMP1,
+		.v4l2Formats = { V4L2PixelFormat(V4L2_PIX_FMT_PISP_COMP1_RGGB), },
+		.bitsPerPixel = 8,
+		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
+		.packed = true,
+		.pixelsPerGroup = 2,
+		.planes = {{ { 2, 1 }, { 0, 0 }, { 0, 0 } }},
+	} },
 	/* Compressed formats. */
 	{ formats::MJPEG, {
 		.name = "MJPEG",
diff --git a/src/libcamera/formats.yaml b/src/libcamera/formats.yaml
index bde2cc803b98..fe027a7cce70 100644
--- a/src/libcamera/formats.yaml
+++ b/src/libcamera/formats.yaml
@@ -190,4 +190,20 @@  formats:
   - SBGGR10_IPU3:
       fourcc: DRM_FORMAT_SBGGR10
       mod: IPU3_FORMAT_MOD_PACKED
+
+  - RGGB_PISP_COMP1:
+      fourcc: DRM_FORMAT_SRGGB16
+      mod: PISP_FORMAT_MOD_COMPRESS_MODE1
+  - GRBG_PISP_COMP1:
+      fourcc: DRM_FORMAT_SGRBG16
+      mod: PISP_FORMAT_MOD_COMPRESS_MODE1
+  - GBRG_PISP_COMP1:
+      fourcc: DRM_FORMAT_SGBRG16
+      mod: PISP_FORMAT_MOD_COMPRESS_MODE1
+  - BGGR_PISP_COMP1:
+      fourcc: DRM_FORMAT_SBGGR16
+      mod: PISP_FORMAT_MOD_COMPRESS_MODE1
+  - MONO_PISP_COMP1:
+      fourcc: DRM_FORMAT_R16
+      mod: PISP_FORMAT_MOD_COMPRESS_MODE1
 ...
diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp
index d3a882dc69a5..70568335b266 100644
--- a/src/libcamera/v4l2_pixelformat.cpp
+++ b/src/libcamera/v4l2_pixelformat.cpp
@@ -207,6 +207,16 @@  const std::map<V4L2PixelFormat, V4L2PixelFormat::Info> vpf2pf{
 		{ formats::SGRBG16, "16-bit Bayer GRGR/BGBG" } },
 	{ V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16),
 		{ formats::SRGGB16, "16-bit Bayer RGRG/GBGB" } },
+	{ V4L2PixelFormat(V4L2_PIX_FMT_PISP_COMP1_BGGR),
+		{ formats::BGGR_PISP_COMP1, "16-bit Bayer BGBG/GRGR PiSP Compress Mode 1" } },
+	{ V4L2PixelFormat(V4L2_PIX_FMT_PISP_COMP1_GBRG),
+		{ formats::GBRG_PISP_COMP1, "16-bit Bayer GBGB/RGRG PiSP Compress Mode 1" } },
+	{ V4L2PixelFormat(V4L2_PIX_FMT_PISP_COMP1_GRBG),
+		{ formats::GRBG_PISP_COMP1, "16-bit Bayer GRGR/BGBG PiSP Compress Mode 1" } },
+	{ V4L2PixelFormat(V4L2_PIX_FMT_PISP_COMP1_RGGB),
+		{ formats::RGGB_PISP_COMP1, "16-bit Bayer RGRG/GBGB PiSP Compress Mode 1" } },
+	{ V4L2PixelFormat(V4L2_PIX_FMT_PISP_COMP1_MONO),
+		{ formats::MONO_PISP_COMP1, "16-bit Mono PiSP Compress Mode 1" } },
 
 	/* Compressed formats. */
 	{ V4L2PixelFormat(V4L2_PIX_FMT_MJPEG),