<div dir="ltr"><div dir="ltr">Hi Laurent,<div><br></div></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 26 Oct 2021 at 08:48, Naushir Patuck <<a href="mailto:naush@raspberrypi.com">naush@raspberrypi.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Hi Laurent,<div><br></div><div>Thank you for your feedback.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 25 Oct 2021 at 14:58, Laurent Pinchart <<a href="mailto:laurent.pinchart@ideasonboard.com" target="_blank">laurent.pinchart@ideasonboard.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Naush,<br>
<br>
Thank you for the patch.<br>
<br>
On Fri, Oct 22, 2021 at 03:39:02PM +0100, Naushir Patuck wrote:<br>
> Add a BayerFormat::toPixelFormat() member function to convert a BayerFormat to a<br>
> PixelFormat type. This conversion uses the existing bayerToV4l2 conversion<br>
> table.<br>
> <br>
> Signed-off-by: Naushir Patuck <<a href="mailto:naush@raspberrypi.com" target="_blank">naush@raspberrypi.com</a>><br>
> Reviewed-by: David Plowman <<a href="mailto:david.plowman@raspberrypi.com" target="_blank">david.plowman@raspberrypi.com</a>><br>
> ---<br>
> include/libcamera/internal/bayer_format.h | 3 +++<br>
> src/libcamera/bayer_format.cpp | 13 +++++++++++++<br>
> 2 files changed, 16 insertions(+)<br>
> <br>
> diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h<br>
> index 723382d4168d..247a60cf0e36 100644<br>
> --- a/include/libcamera/internal/bayer_format.h<br>
> +++ b/include/libcamera/internal/bayer_format.h<br>
> @@ -10,6 +10,8 @@<br>
> #include <stdint.h><br>
> #include <string><br>
> <br>
> +#include <libcamera/pixel_format.h><br>
> +<br>
> #include "libcamera/internal/v4l2_pixelformat.h"<br>
> <br>
> namespace libcamera {<br>
> @@ -50,6 +52,7 @@ public:<br>
> <br>
> V4L2PixelFormat toV4L2PixelFormat() const;<br>
> static BayerFormat fromV4L2PixelFormat(V4L2PixelFormat v4l2Format);<br>
> + PixelFormat toPixelFormat() const;<br>
> BayerFormat transform(Transform t) const;<br>
> <br>
> Order order;<br>
> diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp<br>
> index 11355f144f66..c662ba36604c 100644<br>
> --- a/src/libcamera/bayer_format.cpp<br>
> +++ b/src/libcamera/bayer_format.cpp<br>
> @@ -269,6 +269,19 @@ BayerFormat BayerFormat::fromV4L2PixelFormat(V4L2PixelFormat v4l2Format)<br>
> return BayerFormat();<br>
> }<br>
> <br>
> +/**<br>
> + * \brief Convert a BayerFormat into the corresponding PixelFormat<br>
> + * \return The PixelFormat corresponding to this BayerFormat<br>
> + */<br>
> +PixelFormat BayerFormat::toPixelFormat() const<br>
> +{<br>
> + const auto it = bayerToV4l2.find(*this);<br>
> + if (it != bayerToV4l2.end())<br>
> + return PixelFormat(it->second);<br>
<br>
Should we store the PixelFormat in the bayerToV4l2 map to avoid a double<br>
looking (one here, one in the PixelFormat constructor) ? The map should<br>
be renamed to bayerToFormat, and be stored as either<br>
<br>
std::map<BayerFormat, std::pair<PixelFormat, V4L2PixelFormat>, BayerFormatComparator><br>
<br>
or<br>
<br>
struct Formats {<br>
PixelFormat pixelFormat;<br>
V4L2PixelFormat v4l2Format;<br>
};<br>
<br>
std::map<BayerFormat, Formats, BayerFormatComparator><br></blockquote><div><br></div><div>This seems reasonable. I will update the table with a std::pair for 2-way conversion.</div></div></div></blockquote><div><br></div><div>Unfortunately this has hit an unexpected complication. DRM formats, and subsequently</div><div>PixelFormat types do not define Mono Bayer formats. The corresponding mbus codes</div>are MEDIA_BUS_FMT_Y8_1X8 and MEDIA_BUS_FMT_Y10_1X10.</div><div class="gmail_quote"><br></div><div class="gmail_quote">Would it be acceptable if the conversion regards these mono BayerFormat types as invalid</div><div class="gmail_quote">PixelFormat types with a todo to add appropriate support in the future? Mono sensor support</div><div class="gmail_quote">is still usable as we go from mbus code -> V4L2 4CC correctly, but the application can never</div><div class="gmail_quote">request a mono output - which it can't do today anyway!</div><div class="gmail_quote"><br></div><div class="gmail_quote">Naush</div></div>