[libcamera-devel,1/6] libcamera: bayer_format: Add toMbusCode method
diff mbox series

Message ID 20221110144556.7858-2-david.plowman@raspberrypi.com
State Superseded
Headers show
Series
  • Resolve invalid attempts to set sensor flip controls
Related show

Commit Message

David Plowman Nov. 10, 2022, 2:45 p.m. UTC
This makes it easier to perform transformations on Bayer type mbus
codes by converting them to a BayerFormat, doing the transform, and
then converting them back again.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
---
 include/libcamera/internal/bayer_format.h |  1 +
 src/libcamera/bayer_format.cpp            | 11 +++++++++++
 2 files changed, 12 insertions(+)

Comments

Jacopo Mondi Nov. 17, 2022, 10:32 a.m. UTC | #1
Hi David,

On Thu, Nov 10, 2022 at 02:45:51PM +0000, David Plowman via libcamera-devel wrote:
> This makes it easier to perform transformations on Bayer type mbus
> codes by converting them to a BayerFormat, doing the transform, and
> then converting them back again.
>
> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>


Extending the BayerFormat class with an mbusCode_ class member would
avoid the loopup.

As we have other methods that performs lookups already I can live with this.

Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>


> ---
>  include/libcamera/internal/bayer_format.h |  1 +
>  src/libcamera/bayer_format.cpp            | 11 +++++++++++
>  2 files changed, 12 insertions(+)
>
> diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h
> index 78ba3969..3601dccb 100644
> --- a/include/libcamera/internal/bayer_format.h
> +++ b/include/libcamera/internal/bayer_format.h
> @@ -47,6 +47,7 @@ public:
>  	}
>
>  	static const BayerFormat &fromMbusCode(unsigned int mbusCode);
> +	unsigned int toMbusCode() const;
>  	bool isValid() const { return bitDepth != 0; }
>
>  	std::string toString() const;
> diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp
> index f27cc166..fdbc4af1 100644
> --- a/src/libcamera/bayer_format.cpp
> +++ b/src/libcamera/bayer_format.cpp
> @@ -226,6 +226,17 @@ const BayerFormat &BayerFormat::fromMbusCode(unsigned int mbusCode)
>  		return it->second;
>  }
>
> +/**
> + * \brief Retrieve the media bus code corresponding this this BayerFormat
> + * \return The corresponding media bus code, or zero if none was found
> + */
> +unsigned int BayerFormat::toMbusCode() const
> +{
> +	auto it = std::find_if(mbusCodeToBayer.begin(), mbusCodeToBayer.end(),
> +			       [this](const auto &i) { return i.second == *this; });
> +	return it != mbusCodeToBayer.end() ? it->first : 0;
> +}
> +
>  /**
>   * \fn BayerFormat::isValid()
>   * \brief Return whether a BayerFormat is valid
> --
> 2.30.2
>

Patch
diff mbox series

diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h
index 78ba3969..3601dccb 100644
--- a/include/libcamera/internal/bayer_format.h
+++ b/include/libcamera/internal/bayer_format.h
@@ -47,6 +47,7 @@  public:
 	}
 
 	static const BayerFormat &fromMbusCode(unsigned int mbusCode);
+	unsigned int toMbusCode() const;
 	bool isValid() const { return bitDepth != 0; }
 
 	std::string toString() const;
diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp
index f27cc166..fdbc4af1 100644
--- a/src/libcamera/bayer_format.cpp
+++ b/src/libcamera/bayer_format.cpp
@@ -226,6 +226,17 @@  const BayerFormat &BayerFormat::fromMbusCode(unsigned int mbusCode)
 		return it->second;
 }
 
+/**
+ * \brief Retrieve the media bus code corresponding this this BayerFormat
+ * \return The corresponding media bus code, or zero if none was found
+ */
+unsigned int BayerFormat::toMbusCode() const
+{
+	auto it = std::find_if(mbusCodeToBayer.begin(), mbusCodeToBayer.end(),
+			       [this](const auto &i) { return i.second == *this; });
+	return it != mbusCodeToBayer.end() ? it->first : 0;
+}
+
 /**
  * \fn BayerFormat::isValid()
  * \brief Return whether a BayerFormat is valid