<div dir="ltr"><div dir="ltr">Hi Kieran,<div><br></div><div>Thank you for your feedback.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 27 Oct 2021 at 11:41, Kieran Bingham <<a href="mailto:kieran.bingham@ideasonboard.com">kieran.bingham@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">Quoting Naushir Patuck (2021-10-27 10:27:57)<br>
> Rename the bayerToV4l2 conversion table to bayerToFormat. Update the table to<br>
> hold both the PixelFormat and V4L2PixelFormat conversions for a given<br>
> BayerFormat. This will allow converting between BayerFormat and PixelFormat<br>
> types in a subsequent change.<br>
> <br>
> Signed-off-by: Naushir Patuck <<a href="mailto:naush@raspberrypi.com" target="_blank">naush@raspberrypi.com</a>><br>
> ---<br>
>  src/libcamera/bayer_format.cpp | 110 ++++++++++++++++++++++-----------<br>
>  1 file changed, 73 insertions(+), 37 deletions(-)<br>
> <br>
> diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp<br>
> index 11355f144f66..94e2294d7f6c 100644<br>
> --- a/src/libcamera/bayer_format.cpp<br>
> +++ b/src/libcamera/bayer_format.cpp<br>
> @@ -13,6 +13,7 @@<br>
>  <br>
>  #include <linux/media-bus-format.h><br>
>  <br>
> +#include <libcamera/formats.h><br>
>  #include <libcamera/transform.h><br>
>  <br>
>  /**<br>
> @@ -84,37 +85,72 @@ struct BayerFormatComparator {<br>
>         }<br>
>  };<br>
>  <br>
> -const std::map<BayerFormat, V4L2PixelFormat, BayerFormatComparator> bayerToV4l2{<br>
> -       { { BayerFormat::BGGR, 8, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8) },<br>
> -       { { BayerFormat::GBRG, 8, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8) },<br>
> -       { { BayerFormat::GRBG, 8, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8) },<br>
> -       { { BayerFormat::RGGB, 8, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8) },<br>
> -       { { BayerFormat::BGGR, 10, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10) },<br>
> -       { { BayerFormat::GBRG, 10, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10) },<br>
> -       { { BayerFormat::GRBG, 10, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10) },<br>
> -       { { BayerFormat::RGGB, 10, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10) },<br>
> -       { { BayerFormat::BGGR, 10, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P) },<br>
> -       { { BayerFormat::GBRG, 10, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P) },<br>
> -       { { BayerFormat::GRBG, 10, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P) },<br>
> -       { { BayerFormat::RGGB, 10, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P) },<br>
> -       { { BayerFormat::BGGR, 10, BayerFormat::IPU3Packed }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10) },<br>
> -       { { BayerFormat::GBRG, 10, BayerFormat::IPU3Packed }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10) },<br>
> -       { { BayerFormat::GRBG, 10, BayerFormat::IPU3Packed }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10) },<br>
> -       { { BayerFormat::RGGB, 10, BayerFormat::IPU3Packed }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10) },<br>
> -       { { BayerFormat::BGGR, 12, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12) },<br>
> -       { { BayerFormat::GBRG, 12, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12) },<br>
> -       { { BayerFormat::GRBG, 12, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12) },<br>
> -       { { BayerFormat::RGGB, 12, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12) },<br>
> -       { { BayerFormat::BGGR, 12, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P) },<br>
> -       { { BayerFormat::GBRG, 12, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P) },<br>
> -       { { BayerFormat::GRBG, 12, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P) },<br>
> -       { { BayerFormat::RGGB, 12, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P) },<br>
> -       { { BayerFormat::BGGR, 16, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16) },<br>
> -       { { BayerFormat::GBRG, 16, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16) },<br>
> -       { { BayerFormat::GRBG, 16, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16) },<br>
> -       { { BayerFormat::RGGB, 16, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16) },<br>
> -       { { BayerFormat::MONO, 8, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_GREY) },<br>
> -       { { BayerFormat::MONO, 10, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_Y10P) },<br>
> +struct Formats {<br>
> +       PixelFormat pixelFormat;<br>
> +       V4L2PixelFormat v4l2Format;<br>
> +};<br>
> +<br>
> +const std::map<BayerFormat, Formats, BayerFormatComparator> bayerToFormat{<br>
> +       { { BayerFormat::BGGR, 8, BayerFormat::None },<br>
> +               { formats::SBGGR8, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8) } },<br>
<br>
Personally, I think tables should be kept tabular, disregarding the<br>
usual coding style line lengths.<br>
<br>
A table is much more readable with long lines to me ... but ... It may<br>
not be preferred to everyone. So no need to change this just for me.<br>
Just voicing my opinion ;-)<br></blockquote><div><br></div><div>I fully agree with the above!</div><div>I set it this way as we would go over the 120 char limit.  Happy to format it as a single line per row</div><div>as an exception.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
<br>
> +       { { BayerFormat::GBRG, 8, BayerFormat::None },<br>
> +               { formats::SGBRG8, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8) } },<br>
> +       { { BayerFormat::GRBG, 8, BayerFormat::None },<br>
> +               { formats::SGRBG8, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8) } },<br>
> +       { { BayerFormat::RGGB, 8, BayerFormat::None },<br>
> +               { formats::SRGGB8, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8) } },<br>
> +       { { BayerFormat::BGGR, 10, BayerFormat::None },<br>
> +               { formats::SBGGR10, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10) } },<br>
> +       { { BayerFormat::GBRG, 10, BayerFormat::None },<br>
> +               { formats::SGBRG10, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10) } },<br>
> +       { { BayerFormat::GRBG, 10, BayerFormat::None },<br>
> +               { formats::SGRBG10, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10) } },<br>
> +       { { BayerFormat::RGGB, 10, BayerFormat::None },<br>
> +               { formats::SRGGB10, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10) } },<br>
> +       { { BayerFormat::BGGR, 10, BayerFormat::CSI2Packed },<br>
> +               { formats::SBGGR10_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P) } },<br>
> +       { { BayerFormat::GBRG, 10, BayerFormat::CSI2Packed },<br>
> +               { formats::SGBRG10_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P) } },<br>
> +       { { BayerFormat::GRBG, 10, BayerFormat::CSI2Packed },<br>
> +               { formats::SGRBG10_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P) } },<br>
> +       { { BayerFormat::RGGB, 10, BayerFormat::CSI2Packed },<br>
> +               { formats::SRGGB10_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P) } },<br>
> +       { { BayerFormat::BGGR, 10, BayerFormat::IPU3Packed },<br>
> +               { formats::SBGGR10_IPU3, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10) } },<br>
> +       { { BayerFormat::GBRG, 10, BayerFormat::IPU3Packed },<br>
> +               { formats::SGBRG10_IPU3, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10) } },<br>
> +       { { BayerFormat::GRBG, 10, BayerFormat::IPU3Packed },<br>
> +               { formats::SGRBG10_IPU3, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10) } },<br>
> +       { { BayerFormat::RGGB, 10, BayerFormat::IPU3Packed },<br>
> +               { formats::SRGGB10_IPU3, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10) } },<br>
> +       { { BayerFormat::BGGR, 12, BayerFormat::None },<br>
> +               { formats::SBGGR12, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12) } },<br>
> +       { { BayerFormat::GBRG, 12, BayerFormat::None },<br>
> +               { formats::SGBRG12, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12) } },<br>
> +       { { BayerFormat::GRBG, 12, BayerFormat::None },<br>
> +               { formats::SGRBG12, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12) } },<br>
> +       { { BayerFormat::RGGB, 12, BayerFormat::None },<br>
> +               { formats::SRGGB12, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12) } },<br>
> +       { { BayerFormat::BGGR, 12, BayerFormat::CSI2Packed },<br>
> +               { formats::SBGGR12_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P) } },<br>
> +       { { BayerFormat::GBRG, 12, BayerFormat::CSI2Packed },<br>
> +               { formats::SGBRG12_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P) } },<br>
> +       { { BayerFormat::GRBG, 12, BayerFormat::CSI2Packed },<br>
> +               { formats::SGRBG12_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P) } },<br>
> +       { { BayerFormat::RGGB, 12, BayerFormat::CSI2Packed },<br>
> +               { formats::SRGGB12_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P) } },<br>
> +       { { BayerFormat::BGGR, 16, BayerFormat::None },<br>
> +               { formats::SBGGR16, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16) } },<br>
> +       { { BayerFormat::GBRG, 16, BayerFormat::None },<br>
> +               { formats::SGBRG16, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16) } },<br>
> +       { { BayerFormat::GRBG, 16, BayerFormat::None },<br>
> +               { formats::SGRBG16, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16) } },<br>
> +       { { BayerFormat::RGGB, 16, BayerFormat::None },<br>
> +               { formats::SRGGB16, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16) } },<br>
> +       { { BayerFormat::MONO, 8, BayerFormat::None },<br>
> +               { formats::R8, V4L2PixelFormat(V4L2_PIX_FMT_GREY) } },<br>
> +       { { BayerFormat::MONO, 10, BayerFormat::CSI2Packed },<br>
> +               { formats::R10, V4L2PixelFormat(V4L2_PIX_FMT_Y10P) } },<br>
<br>
In [2/9] formats::R10 gets added with V4L2_PIX_FMT_Y10, but here we have<br>
V4L2_PIX_FMT_Y10P. will that cause any issues?<br></blockquote><div><br></div><div>Quite right, this should not be assigned as a packed format. Will fix this.</div><div><br></div><div>Naush</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
<br>
>  };<br>
>  <br>
>  const std::unordered_map<unsigned int, BayerFormat> mbusCodeToBayer{<br>
> @@ -245,9 +281,9 @@ bool operator==(const BayerFormat &lhs, const BayerFormat &rhs)<br>
>   */<br>
>  V4L2PixelFormat BayerFormat::toV4L2PixelFormat() const<br>
>  {<br>
> -       const auto it = bayerToV4l2.find(*this);<br>
> -       if (it != bayerToV4l2.end())<br>
> -               return it->second;<br>
> +       const auto it = bayerToFormat.find(*this);<br>
> +       if (it != bayerToFormat.end())<br>
> +               return it->second.v4l2Format;<br>
>  <br>
>         return V4L2PixelFormat();<br>
>  }<br>
> @@ -259,11 +295,11 @@ V4L2PixelFormat BayerFormat::toV4L2PixelFormat() const<br>
>   */<br>
>  BayerFormat BayerFormat::fromV4L2PixelFormat(V4L2PixelFormat v4l2Format)<br>
>  {<br>
> -       auto it = std::find_if(bayerToV4l2.begin(), bayerToV4l2.end(),<br>
> +       auto it = std::find_if(bayerToFormat.begin(), bayerToFormat.end(),<br>
>                                [v4l2Format](const auto &i) {<br>
> -                                      return i.second == v4l2Format;<br>
> +                                      return i.second.v4l2Format == v4l2Format;<br>
>                                });<br>
> -       if (it != bayerToV4l2.end())<br>
> +       if (it != bayerToFormat.end())<br>
>                 return it->first;<br>
>  <br>
>         return BayerFormat();<br>
> -- <br>
> 2.25.1<br>
><br>
</blockquote></div></div>