[PATCH 2/2] libcamera: pipeline: Use isRaw() helper to check RAW pixel formats

Umang Jain umang.jain at ideasonboard.com
Mon Sep 30 17:20:39 CEST 2024


Use the isRaw() helper provided by the PixelFormat class in order to
determine if the given pixel format is a raw format or not.

Signed-off-by: Umang Jain <umang.jain at ideasonboard.com>
---
 src/ipa/rkisp1/rkisp1.cpp                     |  3 +--
 src/libcamera/pipeline/imx8-isi/imx8-isi.cpp  | 13 ++++--------
 src/libcamera/pipeline/ipu3/ipu3.cpp          |  6 ++----
 src/libcamera/pipeline/mali-c55/mali-c55.cpp  | 20 +++++--------------
 src/libcamera/pipeline/rkisp1/rkisp1.cpp      |  9 +++------
 src/libcamera/pipeline/rkisp1/rkisp1_path.cpp | 13 +++++-------
 6 files changed, 20 insertions(+), 44 deletions(-)

diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp
index 9e161cab..d0917c19 100644
--- a/src/ipa/rkisp1/rkisp1.cpp
+++ b/src/ipa/rkisp1/rkisp1.cpp
@@ -273,8 +273,7 @@ int IPARkISP1::configure(const IPAConfigInfo &ipaConfig,
 	context_.configuration.raw = std::any_of(streamConfig.begin(), streamConfig.end(),
 		[](auto &cfg) -> bool {
 			PixelFormat pixelFormat{ cfg.second.pixelFormat };
-			const PixelFormatInfo &format = PixelFormatInfo::info(pixelFormat);
-			return format.colourEncoding == PixelFormatInfo::ColourEncodingRAW;
+			return pixelFormat.isRaw();
 		});
 
 	for (auto const &a : algorithms()) {
diff --git a/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp b/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp
index 72aa6c75..e531ff5e 100644
--- a/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp
+++ b/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp
@@ -313,8 +313,7 @@ unsigned int ISICameraData::getYuvMediaBusFormat(const PixelFormat &pixelFormat)
 
 unsigned int ISICameraData::getMediaBusFormat(PixelFormat *pixelFormat) const
 {
-	if (PixelFormatInfo::info(*pixelFormat).colourEncoding ==
-	    PixelFormatInfo::ColourEncodingRAW)
+	if (pixelFormat->isRaw())
 		return getRawMediaBusFormat(pixelFormat);
 
 	return getYuvMediaBusFormat(*pixelFormat);
@@ -453,8 +452,7 @@ ISICameraConfiguration::validateYuv(std::set<Stream *> &availableStreams,
 		LOG(ISI, Debug) << "Stream " << i << ": " << cfg.toString();
 
 		/* If the stream is RAW or not supported default it to YUYV. */
-		const PixelFormatInfo &cfgInfo = PixelFormatInfo::info(cfg.pixelFormat);
-		if (cfgInfo.colourEncoding == PixelFormatInfo::ColourEncodingRAW ||
+		if (cfg.pixelFormat.isRaw() ||
 		    !formatsMap_.count(cfg.pixelFormat)) {
 
 			LOG(ISI, Debug) << "Stream " << i << " format: "
@@ -522,10 +520,8 @@ CameraConfiguration::Status ISICameraConfiguration::validate()
 		maxResolution.width = std::min(2048U, maxResolution.width);
 
 	/* Validate streams according to the format of the first one. */
-	const PixelFormatInfo info = PixelFormatInfo::info(config_[0].pixelFormat);
-
 	Status validationStatus;
-	if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW)
+	if (config_[0].pixelFormat.isRaw())
 		validationStatus = validateRaw(availableStreams, maxResolution);
 	else
 		validationStatus = validateYuv(availableStreams, maxResolution);
@@ -652,8 +648,7 @@ StreamConfiguration PipelineHandlerISI::generateYUVConfiguration(Camera *camera,
 	std::map<PixelFormat, std::vector<SizeRange>> streamFormats;
 
 	for (const auto &[pixFmt, pipeFmt] : ISICameraConfiguration::formatsMap_) {
-		const PixelFormatInfo &info = PixelFormatInfo::info(pixFmt);
-		if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW)
+		if (pixFmt.isRaw())
 			continue;
 
 		streamFormats[pixFmt] = { { kMinISISize, sensorSize } };
diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
index 430aa902..4e7f43ac 100644
--- a/src/libcamera/pipeline/ipu3/ipu3.cpp
+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
@@ -215,9 +215,7 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate()
 	Size rawSize;
 
 	for (const StreamConfiguration &cfg : config_) {
-		const PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat);
-
-		if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW) {
+		if (cfg.pixelFormat.isRaw()) {
 			rawCount++;
 			rawSize = std::max(rawSize, cfg.size);
 		} else {
@@ -285,7 +283,7 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate()
 
 		LOG(IPU3, Debug) << "Validating stream: " << config_[i].toString();
 
-		if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW) {
+		if (config_[i].pixelFormat.isRaw()) {
 			/* Initialize the RAW stream with the CIO2 configuration. */
 			cfg->size = cio2Configuration_.size;
 			cfg->pixelFormat = cio2Configuration_.pixelFormat;
diff --git a/src/libcamera/pipeline/mali-c55/mali-c55.cpp b/src/libcamera/pipeline/mali-c55/mali-c55.cpp
index 45c71c1d..a659a99c 100644
--- a/src/libcamera/pipeline/mali-c55/mali-c55.cpp
+++ b/src/libcamera/pipeline/mali-c55/mali-c55.cpp
@@ -31,16 +31,6 @@
 #include "libcamera/internal/v4l2_subdevice.h"
 #include "libcamera/internal/v4l2_videodevice.h"
 
-namespace {
-
-bool isFormatRaw(const libcamera::PixelFormat &pixFmt)
-{
-	return libcamera::PixelFormatInfo::info(pixFmt).colourEncoding ==
-	       libcamera::PixelFormatInfo::ColourEncodingRAW;
-}
-
-} /* namespace */
-
 namespace libcamera {
 
 LOG_DEFINE_CATEGORY(MaliC55)
@@ -227,7 +217,7 @@ PixelFormat MaliC55CameraData::bestRawFormat() const
 	 */
 	for (const auto &maliFormat : maliC55FmtToCode) {
 		PixelFormat pixFmt = maliFormat.first;
-		if (!isFormatRaw(pixFmt))
+		if (!pixFmt.isRaw())
 			continue;
 
 		unsigned int rawCode = maliFormat.second;
@@ -330,7 +320,7 @@ CameraConfiguration::Status MaliC55CameraConfiguration::validate()
 	bool frPipeAvailable = true;
 	StreamConfiguration *rawConfig = nullptr;
 	for (StreamConfiguration &config : config_) {
-		if (!isFormatRaw(config.pixelFormat))
+		if (!config.pixelFormat.isRaw())
 			continue;
 
 		if (rawConfig) {
@@ -375,7 +365,7 @@ CameraConfiguration::Status MaliC55CameraConfiguration::validate()
 	/* Adjust processed streams. */
 	Size maxYuvSize;
 	for (StreamConfiguration &config : config_) {
-		if (isFormatRaw(config.pixelFormat))
+		if (config.pixelFormat.isRaw())
 			continue;
 
 		/* Adjust format and size for processed streams. */
@@ -599,7 +589,7 @@ PipelineHandlerMaliC55::generateConfiguration(Camera *camera,
 		std::map<PixelFormat, std::vector<SizeRange>> formats;
 		for (const auto &maliFormat : maliC55FmtToCode) {
 			PixelFormat pixFmt = maliFormat.first;
-			bool isRaw = isFormatRaw(pixFmt);
+			bool isRaw = pixFmt.isRaw();
 
 			/* RAW formats are only supported on the FR pipe. */
 			if (pipe != &pipes_[MaliC55FR] && isRaw)
@@ -795,7 +785,7 @@ int PipelineHandlerMaliC55::configure(Camera *camera,
 		Stream *stream = streamConfig.stream();
 		MaliC55Pipe *pipe = pipeFromStream(data, stream);
 
-		if (isFormatRaw(streamConfig.pixelFormat))
+		if (streamConfig.pixelFormat.isRaw())
 			ret = configureRawStream(data, streamConfig, subdevFormat);
 		else
 			ret = configureProcessedStream(data, streamConfig, subdevFormat);
diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
index c02c7cf3..6cee7893 100644
--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp
+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
@@ -485,8 +485,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()
 	 */
 	if (config_.size() > 1) {
 		for (const auto &cfg : config_) {
-			if (PixelFormatInfo::info(cfg.pixelFormat).colourEncoding ==
-			    PixelFormatInfo::ColourEncodingRAW) {
+			if (cfg.pixelFormat.isRaw()) {
 				config_.resize(1);
 				status = Adjusted;
 				break;
@@ -566,8 +565,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()
 	Size maxSize;
 
 	for (const StreamConfiguration &cfg : config_) {
-		const PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat);
-		if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW)
+		if (cfg.pixelFormat.isRaw())
 			rawFormat = cfg.pixelFormat;
 
 		maxSize = std::max(maxSize, cfg.size);
@@ -749,8 +747,7 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)
 		<< " crop " << rect;
 
 	const PixelFormat &streamFormat = config->at(0).pixelFormat;
-	const PixelFormatInfo &info = PixelFormatInfo::info(streamFormat);
-	isRaw_ = info.colourEncoding == PixelFormatInfo::ColourEncodingRAW;
+	isRaw_ = streamFormat.isRaw();
 
 	/* YUYV8_2X8 is required on the ISP source path pad for YUV output. */
 	if (!isRaw_)
diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
index da8d25c3..cb6117b9 100644
--- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
+++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
@@ -182,10 +182,8 @@ RkISP1Path::generateConfiguration(const CameraSensor *sensor, const Size &size,
 	PixelFormat rawFormat;
 
 	for (const auto &format : streamFormats_) {
-		const PixelFormatInfo &info = PixelFormatInfo::info(format);
-
 		/* Populate stream formats for non-RAW configurations. */
-		if (info.colourEncoding != PixelFormatInfo::ColourEncodingRAW) {
+		if (!format.isRaw()) {
 			if (role == StreamRole::Raw)
 				continue;
 
@@ -217,6 +215,7 @@ RkISP1Path::generateConfiguration(const CameraSensor *sensor, const Size &size,
 		 * Store the raw format with the highest bits per pixel for
 		 * later usage.
 		 */
+		const PixelFormatInfo &info = PixelFormatInfo::info(format);
 		if (info.bitsPerPixel > rawBitsPerPixel) {
 			rawBitsPerPixel = info.bitsPerPixel;
 			rawFormat = format;
@@ -272,9 +271,7 @@ CameraConfiguration::Status RkISP1Path::validate(const CameraSensor *sensor,
 	bool found = false;
 
 	for (const auto &format : streamFormats_) {
-		const PixelFormatInfo &info = PixelFormatInfo::info(format);
-
-		if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW) {
+		if (format.isRaw()) {
 			/* Skip raw formats not supported by the sensor. */
 			uint32_t mbusCode = formatToMediaBus.at(format);
 			if (std::find(mbusCodes.begin(), mbusCodes.end(), mbusCode) ==
@@ -285,6 +282,7 @@ CameraConfiguration::Status RkISP1Path::validate(const CameraSensor *sensor,
 			 * Store the raw format with the highest bits per pixel
 			 * for later usage.
 			 */
+			const PixelFormatInfo &info = PixelFormatInfo::info(format);
 			if (info.bitsPerPixel > rawBitsPerPixel) {
 				rawBitsPerPixel = info.bitsPerPixel;
 				rawFormat = format;
@@ -297,8 +295,7 @@ CameraConfiguration::Status RkISP1Path::validate(const CameraSensor *sensor,
 		}
 	}
 
-	bool isRaw = PixelFormatInfo::info(cfg->pixelFormat).colourEncoding ==
-		     PixelFormatInfo::ColourEncodingRAW;
+	bool isRaw = cfg->pixelFormat.isRaw();
 
 	/*
 	 * If no raw format supported by the sensor has been found, use a
-- 
2.45.2



More information about the libcamera-devel mailing list