[libcamera-devel] libcamera: bayer_format: Turn BayerFormat::Packing into scoped enum
diff mbox series

Message ID 20211027123619.16640-1-laurent.pinchart@ideasonboard.com
State Accepted
Commit 364ae3b78d3f0fc18c9bf1c2c3ee9fee1d80e68a
Headers show
Series
  • [libcamera-devel] libcamera: bayer_format: Turn BayerFormat::Packing into scoped enum
Related show

Commit Message

Laurent Pinchart Oct. 27, 2021, 12:36 p.m. UTC
The unscoped enum BayerFormat::Packing leads to usage of the ambiguous
BayerFormat::None enumerator. Turn the enumeration into a scoped enum to
force usage of BayerFormat::Packing::None, and drop the now redundant
"Packed" suffix for the CSI2 and IPU3 packing.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 include/libcamera/internal/bayer_format.h |   6 +-
 src/libcamera/bayer_format.cpp            | 138 +++++++++++-----------
 test/bayer-format.cpp                     |  28 ++---
 3 files changed, 86 insertions(+), 86 deletions(-)


base-commit: 4d4694cd9f4ea73586dcb75d19905a1860356d9f

Comments

Naushir Patuck Oct. 27, 2021, 12:48 p.m. UTC | #1
Hi Laurent,

Thank you for your patch.

On Wed, 27 Oct 2021 at 13:36, Laurent Pinchart <
laurent.pinchart@ideasonboard.com> wrote:

> The unscoped enum BayerFormat::Packing leads to usage of the ambiguous
> BayerFormat::None enumerator. Turn the enumeration into a scoped enum to
> force usage of BayerFormat::Packing::None, and drop the now redundant
> "Packed" suffix for the CSI2 and IPU3 packing.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>

This is going to conflict badly with my series :-)
I definitely prefer scoped enums, but do you think we ought to do the
same with the Order enum in this change?

Regards,
Naush


---
>  include/libcamera/internal/bayer_format.h |   6 +-
>  src/libcamera/bayer_format.cpp            | 138 +++++++++++-----------
>  test/bayer-format.cpp                     |  28 ++---
>  3 files changed, 86 insertions(+), 86 deletions(-)
>
> diff --git a/include/libcamera/internal/bayer_format.h
> b/include/libcamera/internal/bayer_format.h
> index 723382d4168d..d9a56d744a25 100644
> --- a/include/libcamera/internal/bayer_format.h
> +++ b/include/libcamera/internal/bayer_format.h
> @@ -27,10 +27,10 @@ public:
>                 MONO = 4
>         };
>
> -       enum Packing : uint16_t {
> +       enum class Packing : uint16_t {
>                 None = 0,
> -               CSI2Packed = 1,
> -               IPU3Packed = 2,
> +               CSI2 = 1,
> +               IPU3 = 2,
>         };
>
>         constexpr BayerFormat()
> diff --git a/src/libcamera/bayer_format.cpp
> b/src/libcamera/bayer_format.cpp
> index 11355f144f66..1c1e849a7e31 100644
> --- a/src/libcamera/bayer_format.cpp
> +++ b/src/libcamera/bayer_format.cpp
> @@ -53,11 +53,11 @@ namespace libcamera {
>   * \enum BayerFormat::Packing
>   * \brief Different types of packing that can be applied to a BayerFormat
>   *
> - * \var BayerFormat::None
> + * \var BayerFormat::Packing::None
>   * \brief No packing
> - * \var BayerFormat::CSI2Packed
> + * \var BayerFormat::Packing::CSI2
>   * \brief Format uses MIPI CSI-2 style packing
> - * \var BayerFormat::IPU3Packed
> + * \var BayerFormat::Packing::IPU3
>   * \brief Format uses IPU3 style packing
>   */
>
> @@ -85,73 +85,73 @@ struct BayerFormatComparator {
>  };
>
>  const std::map<BayerFormat, V4L2PixelFormat, BayerFormatComparator>
> bayerToV4l2{
> -       { { BayerFormat::BGGR, 8, BayerFormat::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8) },
> -       { { BayerFormat::GBRG, 8, BayerFormat::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8) },
> -       { { BayerFormat::GRBG, 8, BayerFormat::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8) },
> -       { { BayerFormat::RGGB, 8, BayerFormat::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8) },
> -       { { BayerFormat::BGGR, 10, BayerFormat::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10) },
> -       { { BayerFormat::GBRG, 10, BayerFormat::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10) },
> -       { { BayerFormat::GRBG, 10, BayerFormat::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10) },
> -       { { BayerFormat::RGGB, 10, BayerFormat::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10) },
> -       { { BayerFormat::BGGR, 10, BayerFormat::CSI2Packed },
> V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P) },
> -       { { BayerFormat::GBRG, 10, BayerFormat::CSI2Packed },
> V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P) },
> -       { { BayerFormat::GRBG, 10, BayerFormat::CSI2Packed },
> V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P) },
> -       { { BayerFormat::RGGB, 10, BayerFormat::CSI2Packed },
> V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P) },
> -       { { BayerFormat::BGGR, 10, BayerFormat::IPU3Packed },
> V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10) },
> -       { { BayerFormat::GBRG, 10, BayerFormat::IPU3Packed },
> V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10) },
> -       { { BayerFormat::GRBG, 10, BayerFormat::IPU3Packed },
> V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10) },
> -       { { BayerFormat::RGGB, 10, BayerFormat::IPU3Packed },
> V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10) },
> -       { { BayerFormat::BGGR, 12, BayerFormat::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12) },
> -       { { BayerFormat::GBRG, 12, BayerFormat::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12) },
> -       { { BayerFormat::GRBG, 12, BayerFormat::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12) },
> -       { { BayerFormat::RGGB, 12, BayerFormat::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12) },
> -       { { BayerFormat::BGGR, 12, BayerFormat::CSI2Packed },
> V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P) },
> -       { { BayerFormat::GBRG, 12, BayerFormat::CSI2Packed },
> V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P) },
> -       { { BayerFormat::GRBG, 12, BayerFormat::CSI2Packed },
> V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P) },
> -       { { BayerFormat::RGGB, 12, BayerFormat::CSI2Packed },
> V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P) },
> -       { { BayerFormat::BGGR, 16, BayerFormat::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16) },
> -       { { BayerFormat::GBRG, 16, BayerFormat::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16) },
> -       { { BayerFormat::GRBG, 16, BayerFormat::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16) },
> -       { { BayerFormat::RGGB, 16, BayerFormat::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16) },
> -       { { BayerFormat::MONO, 8, BayerFormat::None },
> V4L2PixelFormat(V4L2_PIX_FMT_GREY) },
> -       { { BayerFormat::MONO, 10, BayerFormat::CSI2Packed },
> V4L2PixelFormat(V4L2_PIX_FMT_Y10P) },
> +       { { BayerFormat::BGGR, 8, BayerFormat::Packing::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8) },
> +       { { BayerFormat::GBRG, 8, BayerFormat::Packing::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8) },
> +       { { BayerFormat::GRBG, 8, BayerFormat::Packing::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8) },
> +       { { BayerFormat::RGGB, 8, BayerFormat::Packing::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8) },
> +       { { BayerFormat::BGGR, 10, BayerFormat::Packing::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10) },
> +       { { BayerFormat::GBRG, 10, BayerFormat::Packing::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10) },
> +       { { BayerFormat::GRBG, 10, BayerFormat::Packing::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10) },
> +       { { BayerFormat::RGGB, 10, BayerFormat::Packing::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10) },
> +       { { BayerFormat::BGGR, 10, BayerFormat::Packing::CSI2 },
> V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P) },
> +       { { BayerFormat::GBRG, 10, BayerFormat::Packing::CSI2 },
> V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P) },
> +       { { BayerFormat::GRBG, 10, BayerFormat::Packing::CSI2 },
> V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P) },
> +       { { BayerFormat::RGGB, 10, BayerFormat::Packing::CSI2 },
> V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P) },
> +       { { BayerFormat::BGGR, 10, BayerFormat::Packing::IPU3 },
> V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10) },
> +       { { BayerFormat::GBRG, 10, BayerFormat::Packing::IPU3 },
> V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10) },
> +       { { BayerFormat::GRBG, 10, BayerFormat::Packing::IPU3 },
> V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10) },
> +       { { BayerFormat::RGGB, 10, BayerFormat::Packing::IPU3 },
> V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10) },
> +       { { BayerFormat::BGGR, 12, BayerFormat::Packing::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12) },
> +       { { BayerFormat::GBRG, 12, BayerFormat::Packing::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12) },
> +       { { BayerFormat::GRBG, 12, BayerFormat::Packing::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12) },
> +       { { BayerFormat::RGGB, 12, BayerFormat::Packing::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12) },
> +       { { BayerFormat::BGGR, 12, BayerFormat::Packing::CSI2 },
> V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P) },
> +       { { BayerFormat::GBRG, 12, BayerFormat::Packing::CSI2 },
> V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P) },
> +       { { BayerFormat::GRBG, 12, BayerFormat::Packing::CSI2 },
> V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P) },
> +       { { BayerFormat::RGGB, 12, BayerFormat::Packing::CSI2 },
> V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P) },
> +       { { BayerFormat::BGGR, 16, BayerFormat::Packing::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16) },
> +       { { BayerFormat::GBRG, 16, BayerFormat::Packing::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16) },
> +       { { BayerFormat::GRBG, 16, BayerFormat::Packing::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16) },
> +       { { BayerFormat::RGGB, 16, BayerFormat::Packing::None },
> V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16) },
> +       { { BayerFormat::MONO, 8, BayerFormat::Packing::None },
> V4L2PixelFormat(V4L2_PIX_FMT_GREY) },
> +       { { BayerFormat::MONO, 10, BayerFormat::Packing::CSI2 },
> V4L2PixelFormat(V4L2_PIX_FMT_Y10P) },
>  };
>
>  const std::unordered_map<unsigned int, BayerFormat> mbusCodeToBayer{
> -       { MEDIA_BUS_FMT_SBGGR8_1X8, { BayerFormat::BGGR, 8,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGBRG8_1X8, { BayerFormat::GBRG, 8,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGRBG8_1X8, { BayerFormat::GRBG, 8,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SRGGB8_1X8, { BayerFormat::RGGB, 8,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8, { BayerFormat::BGGR, 8,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8, { BayerFormat::GBRG, 8,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8, { BayerFormat::GRBG, 8,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8, { BayerFormat::RGGB, 8,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8, { BayerFormat::BGGR, 8,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8, { BayerFormat::GBRG, 8,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8, { BayerFormat::GRBG, 8,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8, { BayerFormat::RGGB, 8,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE, { BayerFormat::BGGR, 10,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE, { BayerFormat::BGGR, 10,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_BE, { BayerFormat::BGGR, 10,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_LE, { BayerFormat::BGGR, 10,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SBGGR10_1X10, { BayerFormat::BGGR, 10,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGBRG10_1X10, { BayerFormat::GBRG, 10,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGRBG10_1X10, { BayerFormat::GRBG, 10,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SRGGB10_1X10, { BayerFormat::RGGB, 10,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SBGGR12_1X12, { BayerFormat::BGGR, 12,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGBRG12_1X12, { BayerFormat::GBRG, 12,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGRBG12_1X12, { BayerFormat::GRBG, 12,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SRGGB12_1X12, { BayerFormat::RGGB, 12,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SBGGR14_1X14, { BayerFormat::BGGR, 14,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGBRG14_1X14, { BayerFormat::GBRG, 14,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGRBG14_1X14, { BayerFormat::GRBG, 14,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SRGGB14_1X14, { BayerFormat::RGGB, 14,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SBGGR16_1X16, { BayerFormat::BGGR, 16,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGBRG16_1X16, { BayerFormat::GBRG, 16,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGRBG16_1X16, { BayerFormat::GRBG, 16,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SRGGB16_1X16, { BayerFormat::RGGB, 16,
> BayerFormat::None } },
> -       { MEDIA_BUS_FMT_Y8_1X8, { BayerFormat::MONO, 8, BayerFormat::None
> } },
> -       { MEDIA_BUS_FMT_Y10_1X10, { BayerFormat::MONO, 10,
> BayerFormat::None } },
> +       { MEDIA_BUS_FMT_SBGGR8_1X8, { BayerFormat::BGGR, 8,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGBRG8_1X8, { BayerFormat::GBRG, 8,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGRBG8_1X8, { BayerFormat::GRBG, 8,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SRGGB8_1X8, { BayerFormat::RGGB, 8,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8, { BayerFormat::BGGR, 8,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8, { BayerFormat::GBRG, 8,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8, { BayerFormat::GRBG, 8,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8, { BayerFormat::RGGB, 8,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8, { BayerFormat::BGGR, 8,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8, { BayerFormat::GBRG, 8,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8, { BayerFormat::GRBG, 8,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8, { BayerFormat::RGGB, 8,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE, { BayerFormat::BGGR, 10,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE, { BayerFormat::BGGR, 10,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_BE, { BayerFormat::BGGR, 10,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_LE, { BayerFormat::BGGR, 10,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SBGGR10_1X10, { BayerFormat::BGGR, 10,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGBRG10_1X10, { BayerFormat::GBRG, 10,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGRBG10_1X10, { BayerFormat::GRBG, 10,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SRGGB10_1X10, { BayerFormat::RGGB, 10,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SBGGR12_1X12, { BayerFormat::BGGR, 12,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGBRG12_1X12, { BayerFormat::GBRG, 12,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGRBG12_1X12, { BayerFormat::GRBG, 12,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SRGGB12_1X12, { BayerFormat::RGGB, 12,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SBGGR14_1X14, { BayerFormat::BGGR, 14,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGBRG14_1X14, { BayerFormat::GBRG, 14,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGRBG14_1X14, { BayerFormat::GRBG, 14,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SRGGB14_1X14, { BayerFormat::RGGB, 14,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SBGGR16_1X16, { BayerFormat::BGGR, 16,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGBRG16_1X16, { BayerFormat::GBRG, 16,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGRBG16_1X16, { BayerFormat::GRBG, 16,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SRGGB16_1X16, { BayerFormat::RGGB, 16,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_Y8_1X8, { BayerFormat::MONO, 8,
> BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_Y10_1X10, { BayerFormat::MONO, 10,
> BayerFormat::Packing::None } },
>  };
>
>  } /* namespace */
> @@ -214,9 +214,9 @@ std::string BayerFormat::toString() const
>
>         result += "-" + std::to_string(bitDepth);
>
> -       if (packing == CSI2Packed)
> +       if (packing == Packing::CSI2)
>                 result += "-CSI2P";
> -       else if (packing == IPU3Packed)
> +       else if (packing == Packing::IPU3)
>                 result += "-IPU3P";
>
>         return result;
> diff --git a/test/bayer-format.cpp b/test/bayer-format.cpp
> index e396ee83ca91..135bcb5214c8 100644
> --- a/test/bayer-format.cpp
> +++ b/test/bayer-format.cpp
> @@ -30,7 +30,7 @@ protected:
>                 }
>
>                 /* A correct Bayer format has to be valid. */
> -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> BayerFormat::None);
> +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> BayerFormat::Packing::None);
>                 if (!bayerFmt.isValid()) {
>                         cerr << "A correct BayerFormat has to be valid."
>                              << endl;
> @@ -41,9 +41,9 @@ protected:
>                  * Two bayer formats created with the same order and bit
> depth
>                  * have to be equal.
>                  */
> -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> BayerFormat::None);
> +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> BayerFormat::Packing::None);
>                 BayerFormat bayerFmtExpect =
> BayerFormat(BayerFormat::BGGR, 8,
> -
> BayerFormat::None);
> +
> BayerFormat::Packing::None);
>                 if (bayerFmt != bayerFmtExpect) {
>                         cerr << "Comparison of identical formats failed."
>                              << endl;
> @@ -54,9 +54,9 @@ protected:
>                  * Two Bayer formats created with the same order but with a
>                  * different bitDepth are not equal.
>                  */
> -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> BayerFormat::None);
> +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> BayerFormat::Packing::None);
>                 bayerFmtExpect = BayerFormat(BayerFormat::BGGR, 12,
> -                                            BayerFormat::None);
> +                                            BayerFormat::Packing::None);
>                 if (bayerFmt == bayerFmtExpect) {
>                         cerr << "Comparison of different formats failed."
>                              << endl;
> @@ -96,7 +96,7 @@ protected:
>                  * to a Bayer format.
>                  */
>                 bayerFmtExpect = BayerFormat(BayerFormat::BGGR, 8,
> -                                            BayerFormat::None);
> +                                            BayerFormat::Packing::None);
>                 v4l2Fmt = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8);
>                 bayerFmt = BayerFormat::fromV4L2PixelFormat(v4l2Fmt);
>                 if (bayerFmt != bayerFmtExpect) {
> @@ -123,7 +123,7 @@ protected:
>                  * Test if a valid Bayer format can be converted to a
>                  * string representation.
>                  */
> -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> BayerFormat::None);
> +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> BayerFormat::Packing::None);
>                 if (bayerFmt.toString() != "BGGR-8") {
>                         cerr << "String representation != 'BGGR-8' (got: '"
>                              << bayerFmt.toString() << "' ) " << endl;
> @@ -145,9 +145,9 @@ protected:
>                  * Perform a horizontal Flip and make sure that the
>                  * order is adjusted accordingly.
>                  */
> -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> BayerFormat::None);
> +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> BayerFormat::Packing::None);
>                 bayerFmtExpect = BayerFormat(BayerFormat::GBRG, 8,
> -                                            BayerFormat::None);
> +                                            BayerFormat::Packing::None);
>                 BayerFormat hFlipFmt =
> bayerFmt.transform(Transform::HFlip);
>                 if (hFlipFmt != bayerFmtExpect) {
>                         cerr << "Horizontal flip of 'BGGR-8' should result
> in '"
> @@ -160,9 +160,9 @@ protected:
>                  * Perform a vertical Flip and make sure that
>                  * the order is adjusted accordingly.
>                  */
> -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> BayerFormat::None);
> +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> BayerFormat::Packing::None);
>                 bayerFmtExpect = BayerFormat(BayerFormat::GRBG, 8,
> -                                            BayerFormat::None);
> +                                            BayerFormat::Packing::None);
>                 BayerFormat vFlipFmt =
> bayerFmt.transform(Transform::VFlip);
>                 if (vFlipFmt != bayerFmtExpect) {
>                         cerr << "Vertical flip of 'BGGR-8' should result
> in '"
> @@ -176,7 +176,7 @@ protected:
>                  * pixels on the bottom left to top right diagonal and make
>                  * sure, that it doesn't change.
>                  */
> -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> BayerFormat::None);
> +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> BayerFormat::Packing::None);
>                 BayerFormat transposeFmt = bayerFmt.transform(
>                         Transform::Transpose);
>                 if (transposeFmt != bayerFmt) {
> @@ -192,9 +192,9 @@ protected:
>                  * on the bottom left to top right diagonal and make sure
>                  * that their positions are switched.
>                  */
> -               bayerFmt = BayerFormat(BayerFormat::GBRG, 8,
> BayerFormat::None);
> +               bayerFmt = BayerFormat(BayerFormat::GBRG, 8,
> BayerFormat::Packing::None);
>                 bayerFmtExpect = BayerFormat(BayerFormat::GRBG, 8,
> -                                            BayerFormat::None);
> +                                            BayerFormat::Packing::None);
>                 transposeFmt = bayerFmt.transform(Transform::Transpose);
>                 if (transposeFmt != bayerFmtExpect) {
>                         cerr << "Transpose with the red & blue pixels on
> the "
>
> base-commit: 4d4694cd9f4ea73586dcb75d19905a1860356d9f
> --
> Regards,
>
> Laurent Pinchart
>
>
Laurent Pinchart Oct. 27, 2021, 1:10 p.m. UTC | #2
Hi Naush,

On Wed, Oct 27, 2021 at 01:48:09PM +0100, Naushir Patuck wrote:
> On Wed, 27 Oct 2021 at 13:36, Laurent Pinchart wrote:
> 
> > The unscoped enum BayerFormat::Packing leads to usage of the ambiguous
> > BayerFormat::None enumerator. Turn the enumeration into a scoped enum to
> > force usage of BayerFormat::Packing::None, and drop the now redundant
> > "Packed" suffix for the CSI2 and IPU3 packing.
> >
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> This is going to conflict badly with my series :-)

Guess what gave me the idea ? :-)

> I definitely prefer scoped enums, but do you think we ought to do the
> same with the Order enum in this change?

It's less ambiguous for the Order, but I wouldn't mind. I can send a v2
with that change.

> ---
> >  include/libcamera/internal/bayer_format.h |   6 +-
> >  src/libcamera/bayer_format.cpp            | 138 +++++++++++-----------
> >  test/bayer-format.cpp                     |  28 ++---
> >  3 files changed, 86 insertions(+), 86 deletions(-)
> >
> > diff --git a/include/libcamera/internal/bayer_format.h
> > b/include/libcamera/internal/bayer_format.h
> > index 723382d4168d..d9a56d744a25 100644
> > --- a/include/libcamera/internal/bayer_format.h
> > +++ b/include/libcamera/internal/bayer_format.h
> > @@ -27,10 +27,10 @@ public:
> >                 MONO = 4
> >         };
> >
> > -       enum Packing : uint16_t {
> > +       enum class Packing : uint16_t {
> >                 None = 0,
> > -               CSI2Packed = 1,
> > -               IPU3Packed = 2,
> > +               CSI2 = 1,
> > +               IPU3 = 2,
> >         };
> >
> >         constexpr BayerFormat()
> > diff --git a/src/libcamera/bayer_format.cpp
> > b/src/libcamera/bayer_format.cpp
> > index 11355f144f66..1c1e849a7e31 100644
> > --- a/src/libcamera/bayer_format.cpp
> > +++ b/src/libcamera/bayer_format.cpp
> > @@ -53,11 +53,11 @@ namespace libcamera {
> >   * \enum BayerFormat::Packing
> >   * \brief Different types of packing that can be applied to a BayerFormat
> >   *
> > - * \var BayerFormat::None
> > + * \var BayerFormat::Packing::None
> >   * \brief No packing
> > - * \var BayerFormat::CSI2Packed
> > + * \var BayerFormat::Packing::CSI2
> >   * \brief Format uses MIPI CSI-2 style packing
> > - * \var BayerFormat::IPU3Packed
> > + * \var BayerFormat::Packing::IPU3
> >   * \brief Format uses IPU3 style packing
> >   */
> >
> > @@ -85,73 +85,73 @@ struct BayerFormatComparator {
> >  };
> >
> >  const std::map<BayerFormat, V4L2PixelFormat, BayerFormatComparator>
> > bayerToV4l2{
> > -       { { BayerFormat::BGGR, 8, BayerFormat::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8) },
> > -       { { BayerFormat::GBRG, 8, BayerFormat::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8) },
> > -       { { BayerFormat::GRBG, 8, BayerFormat::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8) },
> > -       { { BayerFormat::RGGB, 8, BayerFormat::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8) },
> > -       { { BayerFormat::BGGR, 10, BayerFormat::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10) },
> > -       { { BayerFormat::GBRG, 10, BayerFormat::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10) },
> > -       { { BayerFormat::GRBG, 10, BayerFormat::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10) },
> > -       { { BayerFormat::RGGB, 10, BayerFormat::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10) },
> > -       { { BayerFormat::BGGR, 10, BayerFormat::CSI2Packed },
> > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P) },
> > -       { { BayerFormat::GBRG, 10, BayerFormat::CSI2Packed },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P) },
> > -       { { BayerFormat::GRBG, 10, BayerFormat::CSI2Packed },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P) },
> > -       { { BayerFormat::RGGB, 10, BayerFormat::CSI2Packed },
> > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P) },
> > -       { { BayerFormat::BGGR, 10, BayerFormat::IPU3Packed },
> > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10) },
> > -       { { BayerFormat::GBRG, 10, BayerFormat::IPU3Packed },
> > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10) },
> > -       { { BayerFormat::GRBG, 10, BayerFormat::IPU3Packed },
> > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10) },
> > -       { { BayerFormat::RGGB, 10, BayerFormat::IPU3Packed },
> > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10) },
> > -       { { BayerFormat::BGGR, 12, BayerFormat::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12) },
> > -       { { BayerFormat::GBRG, 12, BayerFormat::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12) },
> > -       { { BayerFormat::GRBG, 12, BayerFormat::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12) },
> > -       { { BayerFormat::RGGB, 12, BayerFormat::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12) },
> > -       { { BayerFormat::BGGR, 12, BayerFormat::CSI2Packed },
> > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P) },
> > -       { { BayerFormat::GBRG, 12, BayerFormat::CSI2Packed },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P) },
> > -       { { BayerFormat::GRBG, 12, BayerFormat::CSI2Packed },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P) },
> > -       { { BayerFormat::RGGB, 12, BayerFormat::CSI2Packed },
> > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P) },
> > -       { { BayerFormat::BGGR, 16, BayerFormat::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16) },
> > -       { { BayerFormat::GBRG, 16, BayerFormat::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16) },
> > -       { { BayerFormat::GRBG, 16, BayerFormat::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16) },
> > -       { { BayerFormat::RGGB, 16, BayerFormat::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16) },
> > -       { { BayerFormat::MONO, 8, BayerFormat::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_GREY) },
> > -       { { BayerFormat::MONO, 10, BayerFormat::CSI2Packed },
> > V4L2PixelFormat(V4L2_PIX_FMT_Y10P) },
> > +       { { BayerFormat::BGGR, 8, BayerFormat::Packing::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8) },
> > +       { { BayerFormat::GBRG, 8, BayerFormat::Packing::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8) },
> > +       { { BayerFormat::GRBG, 8, BayerFormat::Packing::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8) },
> > +       { { BayerFormat::RGGB, 8, BayerFormat::Packing::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8) },
> > +       { { BayerFormat::BGGR, 10, BayerFormat::Packing::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10) },
> > +       { { BayerFormat::GBRG, 10, BayerFormat::Packing::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10) },
> > +       { { BayerFormat::GRBG, 10, BayerFormat::Packing::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10) },
> > +       { { BayerFormat::RGGB, 10, BayerFormat::Packing::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10) },
> > +       { { BayerFormat::BGGR, 10, BayerFormat::Packing::CSI2 },
> > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P) },
> > +       { { BayerFormat::GBRG, 10, BayerFormat::Packing::CSI2 },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P) },
> > +       { { BayerFormat::GRBG, 10, BayerFormat::Packing::CSI2 },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P) },
> > +       { { BayerFormat::RGGB, 10, BayerFormat::Packing::CSI2 },
> > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P) },
> > +       { { BayerFormat::BGGR, 10, BayerFormat::Packing::IPU3 },
> > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10) },
> > +       { { BayerFormat::GBRG, 10, BayerFormat::Packing::IPU3 },
> > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10) },
> > +       { { BayerFormat::GRBG, 10, BayerFormat::Packing::IPU3 },
> > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10) },
> > +       { { BayerFormat::RGGB, 10, BayerFormat::Packing::IPU3 },
> > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10) },
> > +       { { BayerFormat::BGGR, 12, BayerFormat::Packing::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12) },
> > +       { { BayerFormat::GBRG, 12, BayerFormat::Packing::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12) },
> > +       { { BayerFormat::GRBG, 12, BayerFormat::Packing::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12) },
> > +       { { BayerFormat::RGGB, 12, BayerFormat::Packing::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12) },
> > +       { { BayerFormat::BGGR, 12, BayerFormat::Packing::CSI2 },
> > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P) },
> > +       { { BayerFormat::GBRG, 12, BayerFormat::Packing::CSI2 },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P) },
> > +       { { BayerFormat::GRBG, 12, BayerFormat::Packing::CSI2 },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P) },
> > +       { { BayerFormat::RGGB, 12, BayerFormat::Packing::CSI2 },
> > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P) },
> > +       { { BayerFormat::BGGR, 16, BayerFormat::Packing::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16) },
> > +       { { BayerFormat::GBRG, 16, BayerFormat::Packing::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16) },
> > +       { { BayerFormat::GRBG, 16, BayerFormat::Packing::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16) },
> > +       { { BayerFormat::RGGB, 16, BayerFormat::Packing::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16) },
> > +       { { BayerFormat::MONO, 8, BayerFormat::Packing::None },
> > V4L2PixelFormat(V4L2_PIX_FMT_GREY) },
> > +       { { BayerFormat::MONO, 10, BayerFormat::Packing::CSI2 },
> > V4L2PixelFormat(V4L2_PIX_FMT_Y10P) },
> >  };
> >
> >  const std::unordered_map<unsigned int, BayerFormat> mbusCodeToBayer{
> > -       { MEDIA_BUS_FMT_SBGGR8_1X8, { BayerFormat::BGGR, 8,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SGBRG8_1X8, { BayerFormat::GBRG, 8,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SGRBG8_1X8, { BayerFormat::GRBG, 8,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SRGGB8_1X8, { BayerFormat::RGGB, 8,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8, { BayerFormat::BGGR, 8,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8, { BayerFormat::GBRG, 8,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8, { BayerFormat::GRBG, 8,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8, { BayerFormat::RGGB, 8,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8, { BayerFormat::BGGR, 8,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8, { BayerFormat::GBRG, 8,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8, { BayerFormat::GRBG, 8,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8, { BayerFormat::RGGB, 8,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE, { BayerFormat::BGGR, 10,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE, { BayerFormat::BGGR, 10,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_BE, { BayerFormat::BGGR, 10,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_LE, { BayerFormat::BGGR, 10,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SBGGR10_1X10, { BayerFormat::BGGR, 10,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SGBRG10_1X10, { BayerFormat::GBRG, 10,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SGRBG10_1X10, { BayerFormat::GRBG, 10,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SRGGB10_1X10, { BayerFormat::RGGB, 10,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SBGGR12_1X12, { BayerFormat::BGGR, 12,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SGBRG12_1X12, { BayerFormat::GBRG, 12,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SGRBG12_1X12, { BayerFormat::GRBG, 12,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SRGGB12_1X12, { BayerFormat::RGGB, 12,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SBGGR14_1X14, { BayerFormat::BGGR, 14,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SGBRG14_1X14, { BayerFormat::GBRG, 14,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SGRBG14_1X14, { BayerFormat::GRBG, 14,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SRGGB14_1X14, { BayerFormat::RGGB, 14,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SBGGR16_1X16, { BayerFormat::BGGR, 16,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SGBRG16_1X16, { BayerFormat::GBRG, 16,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SGRBG16_1X16, { BayerFormat::GRBG, 16,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_SRGGB16_1X16, { BayerFormat::RGGB, 16,
> > BayerFormat::None } },
> > -       { MEDIA_BUS_FMT_Y8_1X8, { BayerFormat::MONO, 8, BayerFormat::None
> > } },
> > -       { MEDIA_BUS_FMT_Y10_1X10, { BayerFormat::MONO, 10,
> > BayerFormat::None } },
> > +       { MEDIA_BUS_FMT_SBGGR8_1X8, { BayerFormat::BGGR, 8,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SGBRG8_1X8, { BayerFormat::GBRG, 8,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SGRBG8_1X8, { BayerFormat::GRBG, 8,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SRGGB8_1X8, { BayerFormat::RGGB, 8,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8, { BayerFormat::BGGR, 8,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8, { BayerFormat::GBRG, 8,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8, { BayerFormat::GRBG, 8,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8, { BayerFormat::RGGB, 8,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8, { BayerFormat::BGGR, 8,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8, { BayerFormat::GBRG, 8,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8, { BayerFormat::GRBG, 8,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8, { BayerFormat::RGGB, 8,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE, { BayerFormat::BGGR, 10,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE, { BayerFormat::BGGR, 10,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_BE, { BayerFormat::BGGR, 10,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_LE, { BayerFormat::BGGR, 10,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SBGGR10_1X10, { BayerFormat::BGGR, 10,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SGBRG10_1X10, { BayerFormat::GBRG, 10,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SGRBG10_1X10, { BayerFormat::GRBG, 10,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SRGGB10_1X10, { BayerFormat::RGGB, 10,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SBGGR12_1X12, { BayerFormat::BGGR, 12,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SGBRG12_1X12, { BayerFormat::GBRG, 12,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SGRBG12_1X12, { BayerFormat::GRBG, 12,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SRGGB12_1X12, { BayerFormat::RGGB, 12,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SBGGR14_1X14, { BayerFormat::BGGR, 14,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SGBRG14_1X14, { BayerFormat::GBRG, 14,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SGRBG14_1X14, { BayerFormat::GRBG, 14,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SRGGB14_1X14, { BayerFormat::RGGB, 14,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SBGGR16_1X16, { BayerFormat::BGGR, 16,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SGBRG16_1X16, { BayerFormat::GBRG, 16,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SGRBG16_1X16, { BayerFormat::GRBG, 16,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_SRGGB16_1X16, { BayerFormat::RGGB, 16,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_Y8_1X8, { BayerFormat::MONO, 8,
> > BayerFormat::Packing::None } },
> > +       { MEDIA_BUS_FMT_Y10_1X10, { BayerFormat::MONO, 10,
> > BayerFormat::Packing::None } },
> >  };
> >
> >  } /* namespace */
> > @@ -214,9 +214,9 @@ std::string BayerFormat::toString() const
> >
> >         result += "-" + std::to_string(bitDepth);
> >
> > -       if (packing == CSI2Packed)
> > +       if (packing == Packing::CSI2)
> >                 result += "-CSI2P";
> > -       else if (packing == IPU3Packed)
> > +       else if (packing == Packing::IPU3)
> >                 result += "-IPU3P";
> >
> >         return result;
> > diff --git a/test/bayer-format.cpp b/test/bayer-format.cpp
> > index e396ee83ca91..135bcb5214c8 100644
> > --- a/test/bayer-format.cpp
> > +++ b/test/bayer-format.cpp
> > @@ -30,7 +30,7 @@ protected:
> >                 }
> >
> >                 /* A correct Bayer format has to be valid. */
> > -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > BayerFormat::None);
> > +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > BayerFormat::Packing::None);
> >                 if (!bayerFmt.isValid()) {
> >                         cerr << "A correct BayerFormat has to be valid."
> >                              << endl;
> > @@ -41,9 +41,9 @@ protected:
> >                  * Two bayer formats created with the same order and bit
> > depth
> >                  * have to be equal.
> >                  */
> > -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > BayerFormat::None);
> > +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > BayerFormat::Packing::None);
> >                 BayerFormat bayerFmtExpect =
> > BayerFormat(BayerFormat::BGGR, 8,
> > -
> > BayerFormat::None);
> > +
> > BayerFormat::Packing::None);
> >                 if (bayerFmt != bayerFmtExpect) {
> >                         cerr << "Comparison of identical formats failed."
> >                              << endl;
> > @@ -54,9 +54,9 @@ protected:
> >                  * Two Bayer formats created with the same order but with a
> >                  * different bitDepth are not equal.
> >                  */
> > -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > BayerFormat::None);
> > +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > BayerFormat::Packing::None);
> >                 bayerFmtExpect = BayerFormat(BayerFormat::BGGR, 12,
> > -                                            BayerFormat::None);
> > +                                            BayerFormat::Packing::None);
> >                 if (bayerFmt == bayerFmtExpect) {
> >                         cerr << "Comparison of different formats failed."
> >                              << endl;
> > @@ -96,7 +96,7 @@ protected:
> >                  * to a Bayer format.
> >                  */
> >                 bayerFmtExpect = BayerFormat(BayerFormat::BGGR, 8,
> > -                                            BayerFormat::None);
> > +                                            BayerFormat::Packing::None);
> >                 v4l2Fmt = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8);
> >                 bayerFmt = BayerFormat::fromV4L2PixelFormat(v4l2Fmt);
> >                 if (bayerFmt != bayerFmtExpect) {
> > @@ -123,7 +123,7 @@ protected:
> >                  * Test if a valid Bayer format can be converted to a
> >                  * string representation.
> >                  */
> > -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > BayerFormat::None);
> > +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > BayerFormat::Packing::None);
> >                 if (bayerFmt.toString() != "BGGR-8") {
> >                         cerr << "String representation != 'BGGR-8' (got: '"
> >                              << bayerFmt.toString() << "' ) " << endl;
> > @@ -145,9 +145,9 @@ protected:
> >                  * Perform a horizontal Flip and make sure that the
> >                  * order is adjusted accordingly.
> >                  */
> > -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > BayerFormat::None);
> > +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > BayerFormat::Packing::None);
> >                 bayerFmtExpect = BayerFormat(BayerFormat::GBRG, 8,
> > -                                            BayerFormat::None);
> > +                                            BayerFormat::Packing::None);
> >                 BayerFormat hFlipFmt =
> > bayerFmt.transform(Transform::HFlip);
> >                 if (hFlipFmt != bayerFmtExpect) {
> >                         cerr << "Horizontal flip of 'BGGR-8' should result
> > in '"
> > @@ -160,9 +160,9 @@ protected:
> >                  * Perform a vertical Flip and make sure that
> >                  * the order is adjusted accordingly.
> >                  */
> > -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > BayerFormat::None);
> > +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > BayerFormat::Packing::None);
> >                 bayerFmtExpect = BayerFormat(BayerFormat::GRBG, 8,
> > -                                            BayerFormat::None);
> > +                                            BayerFormat::Packing::None);
> >                 BayerFormat vFlipFmt =
> > bayerFmt.transform(Transform::VFlip);
> >                 if (vFlipFmt != bayerFmtExpect) {
> >                         cerr << "Vertical flip of 'BGGR-8' should result
> > in '"
> > @@ -176,7 +176,7 @@ protected:
> >                  * pixels on the bottom left to top right diagonal and make
> >                  * sure, that it doesn't change.
> >                  */
> > -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > BayerFormat::None);
> > +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > BayerFormat::Packing::None);
> >                 BayerFormat transposeFmt = bayerFmt.transform(
> >                         Transform::Transpose);
> >                 if (transposeFmt != bayerFmt) {
> > @@ -192,9 +192,9 @@ protected:
> >                  * on the bottom left to top right diagonal and make sure
> >                  * that their positions are switched.
> >                  */
> > -               bayerFmt = BayerFormat(BayerFormat::GBRG, 8,
> > BayerFormat::None);
> > +               bayerFmt = BayerFormat(BayerFormat::GBRG, 8,
> > BayerFormat::Packing::None);
> >                 bayerFmtExpect = BayerFormat(BayerFormat::GRBG, 8,
> > -                                            BayerFormat::None);
> > +                                            BayerFormat::Packing::None);
> >                 transposeFmt = bayerFmt.transform(Transform::Transpose);
> >                 if (transposeFmt != bayerFmtExpect) {
> >                         cerr << "Transpose with the red & blue pixels on
> > the "
> >
> > base-commit: 4d4694cd9f4ea73586dcb75d19905a1860356d9f
Naushir Patuck Oct. 27, 2021, 1:15 p.m. UTC | #3
On Wed, 27 Oct 2021 at 14:10, Laurent Pinchart <
laurent.pinchart@ideasonboard.com> wrote:

> Hi Naush,
>
> On Wed, Oct 27, 2021 at 01:48:09PM +0100, Naushir Patuck wrote:
> > On Wed, 27 Oct 2021 at 13:36, Laurent Pinchart wrote:
> >
> > > The unscoped enum BayerFormat::Packing leads to usage of the ambiguous
> > > BayerFormat::None enumerator. Turn the enumeration into a scoped enum
> to
> > > force usage of BayerFormat::Packing::None, and drop the now redundant
> > > "Packed" suffix for the CSI2 and IPU3 packing.
> > >
> > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> >
> > This is going to conflict badly with my series :-)
>
> Guess what gave me the idea ? :-)
>
> > I definitely prefer scoped enums, but do you think we ought to do the
> > same with the Order enum in this change?
>
> It's less ambiguous for the Order, but I wouldn't mind. I can send a v2
> with that change.
>

Great, I'll wait for that and add it to this series.


>
> > ---
> > >  include/libcamera/internal/bayer_format.h |   6 +-
> > >  src/libcamera/bayer_format.cpp            | 138 +++++++++++-----------
> > >  test/bayer-format.cpp                     |  28 ++---
> > >  3 files changed, 86 insertions(+), 86 deletions(-)
> > >
> > > diff --git a/include/libcamera/internal/bayer_format.h
> > > b/include/libcamera/internal/bayer_format.h
> > > index 723382d4168d..d9a56d744a25 100644
> > > --- a/include/libcamera/internal/bayer_format.h
> > > +++ b/include/libcamera/internal/bayer_format.h
> > > @@ -27,10 +27,10 @@ public:
> > >                 MONO = 4
> > >         };
> > >
> > > -       enum Packing : uint16_t {
> > > +       enum class Packing : uint16_t {
> > >                 None = 0,
> > > -               CSI2Packed = 1,
> > > -               IPU3Packed = 2,
> > > +               CSI2 = 1,
> > > +               IPU3 = 2,
> > >         };
> > >
> > >         constexpr BayerFormat()
> > > diff --git a/src/libcamera/bayer_format.cpp
> > > b/src/libcamera/bayer_format.cpp
> > > index 11355f144f66..1c1e849a7e31 100644
> > > --- a/src/libcamera/bayer_format.cpp
> > > +++ b/src/libcamera/bayer_format.cpp
> > > @@ -53,11 +53,11 @@ namespace libcamera {
> > >   * \enum BayerFormat::Packing
> > >   * \brief Different types of packing that can be applied to a
> BayerFormat
> > >   *
> > > - * \var BayerFormat::None
> > > + * \var BayerFormat::Packing::None
> > >   * \brief No packing
> > > - * \var BayerFormat::CSI2Packed
> > > + * \var BayerFormat::Packing::CSI2
> > >   * \brief Format uses MIPI CSI-2 style packing
> > > - * \var BayerFormat::IPU3Packed
> > > + * \var BayerFormat::Packing::IPU3
> > >   * \brief Format uses IPU3 style packing
> > >   */
> > >
> > > @@ -85,73 +85,73 @@ struct BayerFormatComparator {
> > >  };
> > >
> > >  const std::map<BayerFormat, V4L2PixelFormat, BayerFormatComparator>
> > > bayerToV4l2{
> > > -       { { BayerFormat::BGGR, 8, BayerFormat::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8) },
> > > -       { { BayerFormat::GBRG, 8, BayerFormat::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8) },
> > > -       { { BayerFormat::GRBG, 8, BayerFormat::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8) },
> > > -       { { BayerFormat::RGGB, 8, BayerFormat::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8) },
> > > -       { { BayerFormat::BGGR, 10, BayerFormat::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10) },
> > > -       { { BayerFormat::GBRG, 10, BayerFormat::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10) },
> > > -       { { BayerFormat::GRBG, 10, BayerFormat::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10) },
> > > -       { { BayerFormat::RGGB, 10, BayerFormat::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10) },
> > > -       { { BayerFormat::BGGR, 10, BayerFormat::CSI2Packed },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P) },
> > > -       { { BayerFormat::GBRG, 10, BayerFormat::CSI2Packed },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P) },
> > > -       { { BayerFormat::GRBG, 10, BayerFormat::CSI2Packed },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P) },
> > > -       { { BayerFormat::RGGB, 10, BayerFormat::CSI2Packed },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P) },
> > > -       { { BayerFormat::BGGR, 10, BayerFormat::IPU3Packed },
> > > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10) },
> > > -       { { BayerFormat::GBRG, 10, BayerFormat::IPU3Packed },
> > > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10) },
> > > -       { { BayerFormat::GRBG, 10, BayerFormat::IPU3Packed },
> > > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10) },
> > > -       { { BayerFormat::RGGB, 10, BayerFormat::IPU3Packed },
> > > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10) },
> > > -       { { BayerFormat::BGGR, 12, BayerFormat::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12) },
> > > -       { { BayerFormat::GBRG, 12, BayerFormat::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12) },
> > > -       { { BayerFormat::GRBG, 12, BayerFormat::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12) },
> > > -       { { BayerFormat::RGGB, 12, BayerFormat::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12) },
> > > -       { { BayerFormat::BGGR, 12, BayerFormat::CSI2Packed },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P) },
> > > -       { { BayerFormat::GBRG, 12, BayerFormat::CSI2Packed },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P) },
> > > -       { { BayerFormat::GRBG, 12, BayerFormat::CSI2Packed },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P) },
> > > -       { { BayerFormat::RGGB, 12, BayerFormat::CSI2Packed },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P) },
> > > -       { { BayerFormat::BGGR, 16, BayerFormat::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16) },
> > > -       { { BayerFormat::GBRG, 16, BayerFormat::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16) },
> > > -       { { BayerFormat::GRBG, 16, BayerFormat::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16) },
> > > -       { { BayerFormat::RGGB, 16, BayerFormat::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16) },
> > > -       { { BayerFormat::MONO, 8, BayerFormat::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_GREY) },
> > > -       { { BayerFormat::MONO, 10, BayerFormat::CSI2Packed },
> > > V4L2PixelFormat(V4L2_PIX_FMT_Y10P) },
> > > +       { { BayerFormat::BGGR, 8, BayerFormat::Packing::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8) },
> > > +       { { BayerFormat::GBRG, 8, BayerFormat::Packing::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8) },
> > > +       { { BayerFormat::GRBG, 8, BayerFormat::Packing::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8) },
> > > +       { { BayerFormat::RGGB, 8, BayerFormat::Packing::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8) },
> > > +       { { BayerFormat::BGGR, 10, BayerFormat::Packing::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10) },
> > > +       { { BayerFormat::GBRG, 10, BayerFormat::Packing::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10) },
> > > +       { { BayerFormat::GRBG, 10, BayerFormat::Packing::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10) },
> > > +       { { BayerFormat::RGGB, 10, BayerFormat::Packing::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10) },
> > > +       { { BayerFormat::BGGR, 10, BayerFormat::Packing::CSI2 },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P) },
> > > +       { { BayerFormat::GBRG, 10, BayerFormat::Packing::CSI2 },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P) },
> > > +       { { BayerFormat::GRBG, 10, BayerFormat::Packing::CSI2 },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P) },
> > > +       { { BayerFormat::RGGB, 10, BayerFormat::Packing::CSI2 },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P) },
> > > +       { { BayerFormat::BGGR, 10, BayerFormat::Packing::IPU3 },
> > > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10) },
> > > +       { { BayerFormat::GBRG, 10, BayerFormat::Packing::IPU3 },
> > > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10) },
> > > +       { { BayerFormat::GRBG, 10, BayerFormat::Packing::IPU3 },
> > > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10) },
> > > +       { { BayerFormat::RGGB, 10, BayerFormat::Packing::IPU3 },
> > > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10) },
> > > +       { { BayerFormat::BGGR, 12, BayerFormat::Packing::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12) },
> > > +       { { BayerFormat::GBRG, 12, BayerFormat::Packing::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12) },
> > > +       { { BayerFormat::GRBG, 12, BayerFormat::Packing::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12) },
> > > +       { { BayerFormat::RGGB, 12, BayerFormat::Packing::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12) },
> > > +       { { BayerFormat::BGGR, 12, BayerFormat::Packing::CSI2 },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P) },
> > > +       { { BayerFormat::GBRG, 12, BayerFormat::Packing::CSI2 },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P) },
> > > +       { { BayerFormat::GRBG, 12, BayerFormat::Packing::CSI2 },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P) },
> > > +       { { BayerFormat::RGGB, 12, BayerFormat::Packing::CSI2 },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P) },
> > > +       { { BayerFormat::BGGR, 16, BayerFormat::Packing::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16) },
> > > +       { { BayerFormat::GBRG, 16, BayerFormat::Packing::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16) },
> > > +       { { BayerFormat::GRBG, 16, BayerFormat::Packing::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16) },
> > > +       { { BayerFormat::RGGB, 16, BayerFormat::Packing::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16) },
> > > +       { { BayerFormat::MONO, 8, BayerFormat::Packing::None },
> > > V4L2PixelFormat(V4L2_PIX_FMT_GREY) },
> > > +       { { BayerFormat::MONO, 10, BayerFormat::Packing::CSI2 },
> > > V4L2PixelFormat(V4L2_PIX_FMT_Y10P) },
> > >  };
> > >
> > >  const std::unordered_map<unsigned int, BayerFormat> mbusCodeToBayer{
> > > -       { MEDIA_BUS_FMT_SBGGR8_1X8, { BayerFormat::BGGR, 8,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SGBRG8_1X8, { BayerFormat::GBRG, 8,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SGRBG8_1X8, { BayerFormat::GRBG, 8,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SRGGB8_1X8, { BayerFormat::RGGB, 8,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8, { BayerFormat::BGGR, 8,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8, { BayerFormat::GBRG, 8,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8, { BayerFormat::GRBG, 8,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8, { BayerFormat::RGGB, 8,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8, { BayerFormat::BGGR, 8,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8, { BayerFormat::GBRG, 8,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8, { BayerFormat::GRBG, 8,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8, { BayerFormat::RGGB, 8,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE, { BayerFormat::BGGR, 10,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE, { BayerFormat::BGGR, 10,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_BE, { BayerFormat::BGGR, 10,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_LE, { BayerFormat::BGGR, 10,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SBGGR10_1X10, { BayerFormat::BGGR, 10,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SGBRG10_1X10, { BayerFormat::GBRG, 10,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SGRBG10_1X10, { BayerFormat::GRBG, 10,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SRGGB10_1X10, { BayerFormat::RGGB, 10,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SBGGR12_1X12, { BayerFormat::BGGR, 12,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SGBRG12_1X12, { BayerFormat::GBRG, 12,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SGRBG12_1X12, { BayerFormat::GRBG, 12,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SRGGB12_1X12, { BayerFormat::RGGB, 12,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SBGGR14_1X14, { BayerFormat::BGGR, 14,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SGBRG14_1X14, { BayerFormat::GBRG, 14,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SGRBG14_1X14, { BayerFormat::GRBG, 14,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SRGGB14_1X14, { BayerFormat::RGGB, 14,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SBGGR16_1X16, { BayerFormat::BGGR, 16,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SGBRG16_1X16, { BayerFormat::GBRG, 16,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SGRBG16_1X16, { BayerFormat::GRBG, 16,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_SRGGB16_1X16, { BayerFormat::RGGB, 16,
> > > BayerFormat::None } },
> > > -       { MEDIA_BUS_FMT_Y8_1X8, { BayerFormat::MONO, 8,
> BayerFormat::None
> > > } },
> > > -       { MEDIA_BUS_FMT_Y10_1X10, { BayerFormat::MONO, 10,
> > > BayerFormat::None } },
> > > +       { MEDIA_BUS_FMT_SBGGR8_1X8, { BayerFormat::BGGR, 8,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SGBRG8_1X8, { BayerFormat::GBRG, 8,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SGRBG8_1X8, { BayerFormat::GRBG, 8,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SRGGB8_1X8, { BayerFormat::RGGB, 8,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8, { BayerFormat::BGGR, 8,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8, { BayerFormat::GBRG, 8,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8, { BayerFormat::GRBG, 8,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8, { BayerFormat::RGGB, 8,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8, { BayerFormat::BGGR, 8,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8, { BayerFormat::GBRG, 8,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8, { BayerFormat::GRBG, 8,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8, { BayerFormat::RGGB, 8,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE, { BayerFormat::BGGR, 10,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE, { BayerFormat::BGGR, 10,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_BE, { BayerFormat::BGGR, 10,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_LE, { BayerFormat::BGGR, 10,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SBGGR10_1X10, { BayerFormat::BGGR, 10,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SGBRG10_1X10, { BayerFormat::GBRG, 10,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SGRBG10_1X10, { BayerFormat::GRBG, 10,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SRGGB10_1X10, { BayerFormat::RGGB, 10,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SBGGR12_1X12, { BayerFormat::BGGR, 12,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SGBRG12_1X12, { BayerFormat::GBRG, 12,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SGRBG12_1X12, { BayerFormat::GRBG, 12,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SRGGB12_1X12, { BayerFormat::RGGB, 12,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SBGGR14_1X14, { BayerFormat::BGGR, 14,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SGBRG14_1X14, { BayerFormat::GBRG, 14,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SGRBG14_1X14, { BayerFormat::GRBG, 14,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SRGGB14_1X14, { BayerFormat::RGGB, 14,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SBGGR16_1X16, { BayerFormat::BGGR, 16,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SGBRG16_1X16, { BayerFormat::GBRG, 16,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SGRBG16_1X16, { BayerFormat::GRBG, 16,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_SRGGB16_1X16, { BayerFormat::RGGB, 16,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_Y8_1X8, { BayerFormat::MONO, 8,
> > > BayerFormat::Packing::None } },
> > > +       { MEDIA_BUS_FMT_Y10_1X10, { BayerFormat::MONO, 10,
> > > BayerFormat::Packing::None } },
> > >  };
> > >
> > >  } /* namespace */
> > > @@ -214,9 +214,9 @@ std::string BayerFormat::toString() const
> > >
> > >         result += "-" + std::to_string(bitDepth);
> > >
> > > -       if (packing == CSI2Packed)
> > > +       if (packing == Packing::CSI2)
> > >                 result += "-CSI2P";
> > > -       else if (packing == IPU3Packed)
> > > +       else if (packing == Packing::IPU3)
> > >                 result += "-IPU3P";
> > >
> > >         return result;
> > > diff --git a/test/bayer-format.cpp b/test/bayer-format.cpp
> > > index e396ee83ca91..135bcb5214c8 100644
> > > --- a/test/bayer-format.cpp
> > > +++ b/test/bayer-format.cpp
> > > @@ -30,7 +30,7 @@ protected:
> > >                 }
> > >
> > >                 /* A correct Bayer format has to be valid. */
> > > -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > BayerFormat::None);
> > > +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > BayerFormat::Packing::None);
> > >                 if (!bayerFmt.isValid()) {
> > >                         cerr << "A correct BayerFormat has to be
> valid."
> > >                              << endl;
> > > @@ -41,9 +41,9 @@ protected:
> > >                  * Two bayer formats created with the same order and
> bit
> > > depth
> > >                  * have to be equal.
> > >                  */
> > > -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > BayerFormat::None);
> > > +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > BayerFormat::Packing::None);
> > >                 BayerFormat bayerFmtExpect =
> > > BayerFormat(BayerFormat::BGGR, 8,
> > > -
> > > BayerFormat::None);
> > > +
> > > BayerFormat::Packing::None);
> > >                 if (bayerFmt != bayerFmtExpect) {
> > >                         cerr << "Comparison of identical formats
> failed."
> > >                              << endl;
> > > @@ -54,9 +54,9 @@ protected:
> > >                  * Two Bayer formats created with the same order but
> with a
> > >                  * different bitDepth are not equal.
> > >                  */
> > > -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > BayerFormat::None);
> > > +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > BayerFormat::Packing::None);
> > >                 bayerFmtExpect = BayerFormat(BayerFormat::BGGR, 12,
> > > -                                            BayerFormat::None);
> > > +
> BayerFormat::Packing::None);
> > >                 if (bayerFmt == bayerFmtExpect) {
> > >                         cerr << "Comparison of different formats
> failed."
> > >                              << endl;
> > > @@ -96,7 +96,7 @@ protected:
> > >                  * to a Bayer format.
> > >                  */
> > >                 bayerFmtExpect = BayerFormat(BayerFormat::BGGR, 8,
> > > -                                            BayerFormat::None);
> > > +
> BayerFormat::Packing::None);
> > >                 v4l2Fmt = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8);
> > >                 bayerFmt = BayerFormat::fromV4L2PixelFormat(v4l2Fmt);
> > >                 if (bayerFmt != bayerFmtExpect) {
> > > @@ -123,7 +123,7 @@ protected:
> > >                  * Test if a valid Bayer format can be converted to a
> > >                  * string representation.
> > >                  */
> > > -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > BayerFormat::None);
> > > +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > BayerFormat::Packing::None);
> > >                 if (bayerFmt.toString() != "BGGR-8") {
> > >                         cerr << "String representation != 'BGGR-8'
> (got: '"
> > >                              << bayerFmt.toString() << "' ) " << endl;
> > > @@ -145,9 +145,9 @@ protected:
> > >                  * Perform a horizontal Flip and make sure that the
> > >                  * order is adjusted accordingly.
> > >                  */
> > > -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > BayerFormat::None);
> > > +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > BayerFormat::Packing::None);
> > >                 bayerFmtExpect = BayerFormat(BayerFormat::GBRG, 8,
> > > -                                            BayerFormat::None);
> > > +
> BayerFormat::Packing::None);
> > >                 BayerFormat hFlipFmt =
> > > bayerFmt.transform(Transform::HFlip);
> > >                 if (hFlipFmt != bayerFmtExpect) {
> > >                         cerr << "Horizontal flip of 'BGGR-8' should
> result
> > > in '"
> > > @@ -160,9 +160,9 @@ protected:
> > >                  * Perform a vertical Flip and make sure that
> > >                  * the order is adjusted accordingly.
> > >                  */
> > > -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > BayerFormat::None);
> > > +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > BayerFormat::Packing::None);
> > >                 bayerFmtExpect = BayerFormat(BayerFormat::GRBG, 8,
> > > -                                            BayerFormat::None);
> > > +
> BayerFormat::Packing::None);
> > >                 BayerFormat vFlipFmt =
> > > bayerFmt.transform(Transform::VFlip);
> > >                 if (vFlipFmt != bayerFmtExpect) {
> > >                         cerr << "Vertical flip of 'BGGR-8' should
> result
> > > in '"
> > > @@ -176,7 +176,7 @@ protected:
> > >                  * pixels on the bottom left to top right diagonal and
> make
> > >                  * sure, that it doesn't change.
> > >                  */
> > > -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > BayerFormat::None);
> > > +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > BayerFormat::Packing::None);
> > >                 BayerFormat transposeFmt = bayerFmt.transform(
> > >                         Transform::Transpose);
> > >                 if (transposeFmt != bayerFmt) {
> > > @@ -192,9 +192,9 @@ protected:
> > >                  * on the bottom left to top right diagonal and make
> sure
> > >                  * that their positions are switched.
> > >                  */
> > > -               bayerFmt = BayerFormat(BayerFormat::GBRG, 8,
> > > BayerFormat::None);
> > > +               bayerFmt = BayerFormat(BayerFormat::GBRG, 8,
> > > BayerFormat::Packing::None);
> > >                 bayerFmtExpect = BayerFormat(BayerFormat::GRBG, 8,
> > > -                                            BayerFormat::None);
> > > +
> BayerFormat::Packing::None);
> > >                 transposeFmt =
> bayerFmt.transform(Transform::Transpose);
> > >                 if (transposeFmt != bayerFmtExpect) {
> > >                         cerr << "Transpose with the red & blue pixels
> on
> > > the "
> > >
> > > base-commit: 4d4694cd9f4ea73586dcb75d19905a1860356d9f
>
> --
> Regards,
>
> Laurent Pinchart
>
Kieran Bingham Oct. 27, 2021, 1:19 p.m. UTC | #4
Quoting Laurent Pinchart (2021-10-27 13:36:19)
> The unscoped enum BayerFormat::Packing leads to usage of the ambiguous
> BayerFormat::None enumerator. Turn the enumeration into a scoped enum to
> force usage of BayerFormat::Packing::None, and drop the now redundant
> "Packed" suffix for the CSI2 and IPU3 packing.

Well this clears up the ambiguities I had reviewing Naushs patches ;-)

I have to admit, when I saw the tables added in Naushs series, I had to
go look up to check that BayerFormat::None was valid along side
BayerFormat::RGGB, so I think as much as I dislike the longer lines -
this is a good change to make.


Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  include/libcamera/internal/bayer_format.h |   6 +-
>  src/libcamera/bayer_format.cpp            | 138 +++++++++++-----------
>  test/bayer-format.cpp                     |  28 ++---
>  3 files changed, 86 insertions(+), 86 deletions(-)
> 
> diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h
> index 723382d4168d..d9a56d744a25 100644
> --- a/include/libcamera/internal/bayer_format.h
> +++ b/include/libcamera/internal/bayer_format.h
> @@ -27,10 +27,10 @@ public:
>                 MONO = 4
>         };
>  
> -       enum Packing : uint16_t {
> +       enum class Packing : uint16_t {
>                 None = 0,
> -               CSI2Packed = 1,
> -               IPU3Packed = 2,
> +               CSI2 = 1,
> +               IPU3 = 2,
>         };
>  
>         constexpr BayerFormat()
> diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp
> index 11355f144f66..1c1e849a7e31 100644
> --- a/src/libcamera/bayer_format.cpp
> +++ b/src/libcamera/bayer_format.cpp
> @@ -53,11 +53,11 @@ namespace libcamera {
>   * \enum BayerFormat::Packing
>   * \brief Different types of packing that can be applied to a BayerFormat
>   *
> - * \var BayerFormat::None
> + * \var BayerFormat::Packing::None
>   * \brief No packing
> - * \var BayerFormat::CSI2Packed
> + * \var BayerFormat::Packing::CSI2
>   * \brief Format uses MIPI CSI-2 style packing
> - * \var BayerFormat::IPU3Packed
> + * \var BayerFormat::Packing::IPU3
>   * \brief Format uses IPU3 style packing
>   */
>  
> @@ -85,73 +85,73 @@ struct BayerFormatComparator {
>  };
>  
>  const std::map<BayerFormat, V4L2PixelFormat, BayerFormatComparator> bayerToV4l2{
> -       { { BayerFormat::BGGR, 8, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8) },
> -       { { BayerFormat::GBRG, 8, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8) },
> -       { { BayerFormat::GRBG, 8, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8) },
> -       { { BayerFormat::RGGB, 8, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8) },
> -       { { BayerFormat::BGGR, 10, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10) },
> -       { { BayerFormat::GBRG, 10, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10) },
> -       { { BayerFormat::GRBG, 10, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10) },
> -       { { BayerFormat::RGGB, 10, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10) },
> -       { { BayerFormat::BGGR, 10, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P) },
> -       { { BayerFormat::GBRG, 10, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P) },
> -       { { BayerFormat::GRBG, 10, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P) },
> -       { { BayerFormat::RGGB, 10, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P) },
> -       { { BayerFormat::BGGR, 10, BayerFormat::IPU3Packed }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10) },
> -       { { BayerFormat::GBRG, 10, BayerFormat::IPU3Packed }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10) },
> -       { { BayerFormat::GRBG, 10, BayerFormat::IPU3Packed }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10) },
> -       { { BayerFormat::RGGB, 10, BayerFormat::IPU3Packed }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10) },
> -       { { BayerFormat::BGGR, 12, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12) },
> -       { { BayerFormat::GBRG, 12, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12) },
> -       { { BayerFormat::GRBG, 12, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12) },
> -       { { BayerFormat::RGGB, 12, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12) },
> -       { { BayerFormat::BGGR, 12, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P) },
> -       { { BayerFormat::GBRG, 12, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P) },
> -       { { BayerFormat::GRBG, 12, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P) },
> -       { { BayerFormat::RGGB, 12, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P) },
> -       { { BayerFormat::BGGR, 16, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16) },
> -       { { BayerFormat::GBRG, 16, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16) },
> -       { { BayerFormat::GRBG, 16, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16) },
> -       { { BayerFormat::RGGB, 16, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16) },
> -       { { BayerFormat::MONO, 8, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_GREY) },
> -       { { BayerFormat::MONO, 10, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_Y10P) },
> +       { { BayerFormat::BGGR, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8) },
> +       { { BayerFormat::GBRG, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8) },
> +       { { BayerFormat::GRBG, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8) },
> +       { { BayerFormat::RGGB, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8) },
> +       { { BayerFormat::BGGR, 10, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10) },
> +       { { BayerFormat::GBRG, 10, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10) },
> +       { { BayerFormat::GRBG, 10, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10) },
> +       { { BayerFormat::RGGB, 10, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10) },
> +       { { BayerFormat::BGGR, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P) },
> +       { { BayerFormat::GBRG, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P) },
> +       { { BayerFormat::GRBG, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P) },
> +       { { BayerFormat::RGGB, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P) },
> +       { { BayerFormat::BGGR, 10, BayerFormat::Packing::IPU3 }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10) },
> +       { { BayerFormat::GBRG, 10, BayerFormat::Packing::IPU3 }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10) },
> +       { { BayerFormat::GRBG, 10, BayerFormat::Packing::IPU3 }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10) },
> +       { { BayerFormat::RGGB, 10, BayerFormat::Packing::IPU3 }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10) },
> +       { { BayerFormat::BGGR, 12, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12) },
> +       { { BayerFormat::GBRG, 12, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12) },
> +       { { BayerFormat::GRBG, 12, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12) },
> +       { { BayerFormat::RGGB, 12, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12) },
> +       { { BayerFormat::BGGR, 12, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P) },
> +       { { BayerFormat::GBRG, 12, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P) },
> +       { { BayerFormat::GRBG, 12, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P) },
> +       { { BayerFormat::RGGB, 12, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P) },
> +       { { BayerFormat::BGGR, 16, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16) },
> +       { { BayerFormat::GBRG, 16, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16) },
> +       { { BayerFormat::GRBG, 16, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16) },
> +       { { BayerFormat::RGGB, 16, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16) },
> +       { { BayerFormat::MONO, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_GREY) },
> +       { { BayerFormat::MONO, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_Y10P) },
>  };
>  
>  const std::unordered_map<unsigned int, BayerFormat> mbusCodeToBayer{
> -       { MEDIA_BUS_FMT_SBGGR8_1X8, { BayerFormat::BGGR, 8, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGBRG8_1X8, { BayerFormat::GBRG, 8, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGRBG8_1X8, { BayerFormat::GRBG, 8, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SRGGB8_1X8, { BayerFormat::RGGB, 8, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8, { BayerFormat::BGGR, 8, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8, { BayerFormat::GBRG, 8, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8, { BayerFormat::GRBG, 8, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8, { BayerFormat::RGGB, 8, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8, { BayerFormat::BGGR, 8, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8, { BayerFormat::GBRG, 8, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8, { BayerFormat::GRBG, 8, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8, { BayerFormat::RGGB, 8, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE, { BayerFormat::BGGR, 10, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE, { BayerFormat::BGGR, 10, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_BE, { BayerFormat::BGGR, 10, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_LE, { BayerFormat::BGGR, 10, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SBGGR10_1X10, { BayerFormat::BGGR, 10, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGBRG10_1X10, { BayerFormat::GBRG, 10, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGRBG10_1X10, { BayerFormat::GRBG, 10, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SRGGB10_1X10, { BayerFormat::RGGB, 10, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SBGGR12_1X12, { BayerFormat::BGGR, 12, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGBRG12_1X12, { BayerFormat::GBRG, 12, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGRBG12_1X12, { BayerFormat::GRBG, 12, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SRGGB12_1X12, { BayerFormat::RGGB, 12, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SBGGR14_1X14, { BayerFormat::BGGR, 14, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGBRG14_1X14, { BayerFormat::GBRG, 14, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGRBG14_1X14, { BayerFormat::GRBG, 14, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SRGGB14_1X14, { BayerFormat::RGGB, 14, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SBGGR16_1X16, { BayerFormat::BGGR, 16, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGBRG16_1X16, { BayerFormat::GBRG, 16, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SGRBG16_1X16, { BayerFormat::GRBG, 16, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_SRGGB16_1X16, { BayerFormat::RGGB, 16, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_Y8_1X8, { BayerFormat::MONO, 8, BayerFormat::None } },
> -       { MEDIA_BUS_FMT_Y10_1X10, { BayerFormat::MONO, 10, BayerFormat::None } },
> +       { MEDIA_BUS_FMT_SBGGR8_1X8, { BayerFormat::BGGR, 8, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGBRG8_1X8, { BayerFormat::GBRG, 8, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGRBG8_1X8, { BayerFormat::GRBG, 8, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SRGGB8_1X8, { BayerFormat::RGGB, 8, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8, { BayerFormat::BGGR, 8, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8, { BayerFormat::GBRG, 8, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8, { BayerFormat::GRBG, 8, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8, { BayerFormat::RGGB, 8, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8, { BayerFormat::BGGR, 8, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8, { BayerFormat::GBRG, 8, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8, { BayerFormat::GRBG, 8, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8, { BayerFormat::RGGB, 8, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE, { BayerFormat::BGGR, 10, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE, { BayerFormat::BGGR, 10, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_BE, { BayerFormat::BGGR, 10, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_LE, { BayerFormat::BGGR, 10, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SBGGR10_1X10, { BayerFormat::BGGR, 10, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGBRG10_1X10, { BayerFormat::GBRG, 10, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGRBG10_1X10, { BayerFormat::GRBG, 10, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SRGGB10_1X10, { BayerFormat::RGGB, 10, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SBGGR12_1X12, { BayerFormat::BGGR, 12, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGBRG12_1X12, { BayerFormat::GBRG, 12, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGRBG12_1X12, { BayerFormat::GRBG, 12, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SRGGB12_1X12, { BayerFormat::RGGB, 12, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SBGGR14_1X14, { BayerFormat::BGGR, 14, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGBRG14_1X14, { BayerFormat::GBRG, 14, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGRBG14_1X14, { BayerFormat::GRBG, 14, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SRGGB14_1X14, { BayerFormat::RGGB, 14, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SBGGR16_1X16, { BayerFormat::BGGR, 16, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGBRG16_1X16, { BayerFormat::GBRG, 16, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SGRBG16_1X16, { BayerFormat::GRBG, 16, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_SRGGB16_1X16, { BayerFormat::RGGB, 16, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_Y8_1X8, { BayerFormat::MONO, 8, BayerFormat::Packing::None } },
> +       { MEDIA_BUS_FMT_Y10_1X10, { BayerFormat::MONO, 10, BayerFormat::Packing::None } },
>  };
>  
>  } /* namespace */
> @@ -214,9 +214,9 @@ std::string BayerFormat::toString() const
>  
>         result += "-" + std::to_string(bitDepth);
>  
> -       if (packing == CSI2Packed)
> +       if (packing == Packing::CSI2)
>                 result += "-CSI2P";
> -       else if (packing == IPU3Packed)
> +       else if (packing == Packing::IPU3)

These read quite nicely

>                 result += "-IPU3P";
>  
>         return result;
> diff --git a/test/bayer-format.cpp b/test/bayer-format.cpp
> index e396ee83ca91..135bcb5214c8 100644
> --- a/test/bayer-format.cpp
> +++ b/test/bayer-format.cpp
> @@ -30,7 +30,7 @@ protected:
>                 }
>  
>                 /* A correct Bayer format has to be valid. */
> -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None);
> +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::Packing::None);
>                 if (!bayerFmt.isValid()) {
>                         cerr << "A correct BayerFormat has to be valid."
>                              << endl;
> @@ -41,9 +41,9 @@ protected:
>                  * Two bayer formats created with the same order and bit depth
>                  * have to be equal.
>                  */
> -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None);
> +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::Packing::None);
>                 BayerFormat bayerFmtExpect = BayerFormat(BayerFormat::BGGR, 8,
> -                                                        BayerFormat::None);
> +                                                        BayerFormat::Packing::None);
>                 if (bayerFmt != bayerFmtExpect) {
>                         cerr << "Comparison of identical formats failed."
>                              << endl;
> @@ -54,9 +54,9 @@ protected:
>                  * Two Bayer formats created with the same order but with a
>                  * different bitDepth are not equal.
>                  */
> -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None);
> +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::Packing::None);
>                 bayerFmtExpect = BayerFormat(BayerFormat::BGGR, 12,
> -                                            BayerFormat::None);
> +                                            BayerFormat::Packing::None);
>                 if (bayerFmt == bayerFmtExpect) {
>                         cerr << "Comparison of different formats failed."
>                              << endl;
> @@ -96,7 +96,7 @@ protected:
>                  * to a Bayer format.
>                  */
>                 bayerFmtExpect = BayerFormat(BayerFormat::BGGR, 8,
> -                                            BayerFormat::None);
> +                                            BayerFormat::Packing::None);
>                 v4l2Fmt = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8);
>                 bayerFmt = BayerFormat::fromV4L2PixelFormat(v4l2Fmt);
>                 if (bayerFmt != bayerFmtExpect) {
> @@ -123,7 +123,7 @@ protected:
>                  * Test if a valid Bayer format can be converted to a
>                  * string representation.
>                  */
> -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None);
> +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::Packing::None);
>                 if (bayerFmt.toString() != "BGGR-8") {
>                         cerr << "String representation != 'BGGR-8' (got: '"
>                              << bayerFmt.toString() << "' ) " << endl;
> @@ -145,9 +145,9 @@ protected:
>                  * Perform a horizontal Flip and make sure that the
>                  * order is adjusted accordingly.
>                  */
> -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None);
> +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::Packing::None);
>                 bayerFmtExpect = BayerFormat(BayerFormat::GBRG, 8,
> -                                            BayerFormat::None);
> +                                            BayerFormat::Packing::None);
>                 BayerFormat hFlipFmt = bayerFmt.transform(Transform::HFlip);
>                 if (hFlipFmt != bayerFmtExpect) {
>                         cerr << "Horizontal flip of 'BGGR-8' should result in '"
> @@ -160,9 +160,9 @@ protected:
>                  * Perform a vertical Flip and make sure that
>                  * the order is adjusted accordingly.
>                  */
> -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None);
> +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::Packing::None);
>                 bayerFmtExpect = BayerFormat(BayerFormat::GRBG, 8,
> -                                            BayerFormat::None);
> +                                            BayerFormat::Packing::None);
>                 BayerFormat vFlipFmt = bayerFmt.transform(Transform::VFlip);
>                 if (vFlipFmt != bayerFmtExpect) {
>                         cerr << "Vertical flip of 'BGGR-8' should result in '"
> @@ -176,7 +176,7 @@ protected:
>                  * pixels on the bottom left to top right diagonal and make
>                  * sure, that it doesn't change.
>                  */
> -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None);
> +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::Packing::None);
>                 BayerFormat transposeFmt = bayerFmt.transform(
>                         Transform::Transpose);
>                 if (transposeFmt != bayerFmt) {
> @@ -192,9 +192,9 @@ protected:
>                  * on the bottom left to top right diagonal and make sure
>                  * that their positions are switched.
>                  */
> -               bayerFmt = BayerFormat(BayerFormat::GBRG, 8, BayerFormat::None);
> +               bayerFmt = BayerFormat(BayerFormat::GBRG, 8, BayerFormat::Packing::None);
>                 bayerFmtExpect = BayerFormat(BayerFormat::GRBG, 8,
> -                                            BayerFormat::None);
> +                                            BayerFormat::Packing::None);
>                 transposeFmt = bayerFmt.transform(Transform::Transpose);
>                 if (transposeFmt != bayerFmtExpect) {
>                         cerr << "Transpose with the red & blue pixels on the "
> 
> base-commit: 4d4694cd9f4ea73586dcb75d19905a1860356d9f
> -- 
> Regards,
> 
> Laurent Pinchart
>
Kieran Bingham Oct. 27, 2021, 1:23 p.m. UTC | #5
Quoting Naushir Patuck (2021-10-27 14:15:02)
> On Wed, 27 Oct 2021 at 14:10, Laurent Pinchart <
> laurent.pinchart@ideasonboard.com> wrote:
> 
> > Hi Naush,
> >
> > On Wed, Oct 27, 2021 at 01:48:09PM +0100, Naushir Patuck wrote:
> > > On Wed, 27 Oct 2021 at 13:36, Laurent Pinchart wrote:
> > >
> > > > The unscoped enum BayerFormat::Packing leads to usage of the ambiguous
> > > > BayerFormat::None enumerator. Turn the enumeration into a scoped enum
> > to
> > > > force usage of BayerFormat::Packing::None, and drop the now redundant
> > > > "Packed" suffix for the CSI2 and IPU3 packing.
> > > >
> > > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > >
> > > This is going to conflict badly with my series :-)
> >
> > Guess what gave me the idea ? :-)
> >
> > > I definitely prefer scoped enums, but do you think we ought to do the
> > > same with the Order enum in this change?
> >
> > It's less ambiguous for the Order, but I wouldn't mind. I can send a v2
> > with that change.
> >
> 
> Great, I'll wait for that and add it to this series.

I won't object to the Order being scoped ... but I don't think that one
is needed.

The BayerFormat::None really threw me off when reviewing before, so that
really helps to have the scope.

However:
  BayerFormat::GBRG

Is somewhat more self documenting...


> > > ---
> > > >  include/libcamera/internal/bayer_format.h |   6 +-
> > > >  src/libcamera/bayer_format.cpp            | 138 +++++++++++-----------
> > > >  test/bayer-format.cpp                     |  28 ++---
> > > >  3 files changed, 86 insertions(+), 86 deletions(-)
> > > >
> > > > diff --git a/include/libcamera/internal/bayer_format.h
> > > > b/include/libcamera/internal/bayer_format.h
> > > > index 723382d4168d..d9a56d744a25 100644
> > > > --- a/include/libcamera/internal/bayer_format.h
> > > > +++ b/include/libcamera/internal/bayer_format.h
> > > > @@ -27,10 +27,10 @@ public:
> > > >                 MONO = 4
> > > >         };
> > > >
> > > > -       enum Packing : uint16_t {
> > > > +       enum class Packing : uint16_t {
> > > >                 None = 0,
> > > > -               CSI2Packed = 1,
> > > > -               IPU3Packed = 2,
> > > > +               CSI2 = 1,
> > > > +               IPU3 = 2,
> > > >         };
> > > >
> > > >         constexpr BayerFormat()
> > > > diff --git a/src/libcamera/bayer_format.cpp
> > > > b/src/libcamera/bayer_format.cpp
> > > > index 11355f144f66..1c1e849a7e31 100644
> > > > --- a/src/libcamera/bayer_format.cpp
> > > > +++ b/src/libcamera/bayer_format.cpp
> > > > @@ -53,11 +53,11 @@ namespace libcamera {
> > > >   * \enum BayerFormat::Packing
> > > >   * \brief Different types of packing that can be applied to a
> > BayerFormat
> > > >   *
> > > > - * \var BayerFormat::None
> > > > + * \var BayerFormat::Packing::None
> > > >   * \brief No packing
> > > > - * \var BayerFormat::CSI2Packed
> > > > + * \var BayerFormat::Packing::CSI2
> > > >   * \brief Format uses MIPI CSI-2 style packing
> > > > - * \var BayerFormat::IPU3Packed
> > > > + * \var BayerFormat::Packing::IPU3
> > > >   * \brief Format uses IPU3 style packing
> > > >   */
> > > >
> > > > @@ -85,73 +85,73 @@ struct BayerFormatComparator {
> > > >  };
> > > >
> > > >  const std::map<BayerFormat, V4L2PixelFormat, BayerFormatComparator>
> > > > bayerToV4l2{
> > > > -       { { BayerFormat::BGGR, 8, BayerFormat::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8) },
> > > > -       { { BayerFormat::GBRG, 8, BayerFormat::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8) },
> > > > -       { { BayerFormat::GRBG, 8, BayerFormat::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8) },
> > > > -       { { BayerFormat::RGGB, 8, BayerFormat::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8) },
> > > > -       { { BayerFormat::BGGR, 10, BayerFormat::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10) },
> > > > -       { { BayerFormat::GBRG, 10, BayerFormat::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10) },
> > > > -       { { BayerFormat::GRBG, 10, BayerFormat::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10) },
> > > > -       { { BayerFormat::RGGB, 10, BayerFormat::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10) },
> > > > -       { { BayerFormat::BGGR, 10, BayerFormat::CSI2Packed },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P) },
> > > > -       { { BayerFormat::GBRG, 10, BayerFormat::CSI2Packed },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P) },
> > > > -       { { BayerFormat::GRBG, 10, BayerFormat::CSI2Packed },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P) },
> > > > -       { { BayerFormat::RGGB, 10, BayerFormat::CSI2Packed },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P) },
> > > > -       { { BayerFormat::BGGR, 10, BayerFormat::IPU3Packed },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10) },
> > > > -       { { BayerFormat::GBRG, 10, BayerFormat::IPU3Packed },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10) },
> > > > -       { { BayerFormat::GRBG, 10, BayerFormat::IPU3Packed },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10) },
> > > > -       { { BayerFormat::RGGB, 10, BayerFormat::IPU3Packed },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10) },
> > > > -       { { BayerFormat::BGGR, 12, BayerFormat::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12) },
> > > > -       { { BayerFormat::GBRG, 12, BayerFormat::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12) },
> > > > -       { { BayerFormat::GRBG, 12, BayerFormat::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12) },
> > > > -       { { BayerFormat::RGGB, 12, BayerFormat::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12) },
> > > > -       { { BayerFormat::BGGR, 12, BayerFormat::CSI2Packed },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P) },
> > > > -       { { BayerFormat::GBRG, 12, BayerFormat::CSI2Packed },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P) },
> > > > -       { { BayerFormat::GRBG, 12, BayerFormat::CSI2Packed },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P) },
> > > > -       { { BayerFormat::RGGB, 12, BayerFormat::CSI2Packed },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P) },
> > > > -       { { BayerFormat::BGGR, 16, BayerFormat::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16) },
> > > > -       { { BayerFormat::GBRG, 16, BayerFormat::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16) },
> > > > -       { { BayerFormat::GRBG, 16, BayerFormat::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16) },
> > > > -       { { BayerFormat::RGGB, 16, BayerFormat::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16) },
> > > > -       { { BayerFormat::MONO, 8, BayerFormat::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_GREY) },
> > > > -       { { BayerFormat::MONO, 10, BayerFormat::CSI2Packed },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_Y10P) },
> > > > +       { { BayerFormat::BGGR, 8, BayerFormat::Packing::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8) },
> > > > +       { { BayerFormat::GBRG, 8, BayerFormat::Packing::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8) },
> > > > +       { { BayerFormat::GRBG, 8, BayerFormat::Packing::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8) },
> > > > +       { { BayerFormat::RGGB, 8, BayerFormat::Packing::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8) },
> > > > +       { { BayerFormat::BGGR, 10, BayerFormat::Packing::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10) },
> > > > +       { { BayerFormat::GBRG, 10, BayerFormat::Packing::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10) },
> > > > +       { { BayerFormat::GRBG, 10, BayerFormat::Packing::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10) },
> > > > +       { { BayerFormat::RGGB, 10, BayerFormat::Packing::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10) },
> > > > +       { { BayerFormat::BGGR, 10, BayerFormat::Packing::CSI2 },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P) },
> > > > +       { { BayerFormat::GBRG, 10, BayerFormat::Packing::CSI2 },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P) },
> > > > +       { { BayerFormat::GRBG, 10, BayerFormat::Packing::CSI2 },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P) },
> > > > +       { { BayerFormat::RGGB, 10, BayerFormat::Packing::CSI2 },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P) },
> > > > +       { { BayerFormat::BGGR, 10, BayerFormat::Packing::IPU3 },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10) },
> > > > +       { { BayerFormat::GBRG, 10, BayerFormat::Packing::IPU3 },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10) },
> > > > +       { { BayerFormat::GRBG, 10, BayerFormat::Packing::IPU3 },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10) },
> > > > +       { { BayerFormat::RGGB, 10, BayerFormat::Packing::IPU3 },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10) },
> > > > +       { { BayerFormat::BGGR, 12, BayerFormat::Packing::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12) },
> > > > +       { { BayerFormat::GBRG, 12, BayerFormat::Packing::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12) },
> > > > +       { { BayerFormat::GRBG, 12, BayerFormat::Packing::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12) },
> > > > +       { { BayerFormat::RGGB, 12, BayerFormat::Packing::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12) },
> > > > +       { { BayerFormat::BGGR, 12, BayerFormat::Packing::CSI2 },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P) },
> > > > +       { { BayerFormat::GBRG, 12, BayerFormat::Packing::CSI2 },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P) },
> > > > +       { { BayerFormat::GRBG, 12, BayerFormat::Packing::CSI2 },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P) },
> > > > +       { { BayerFormat::RGGB, 12, BayerFormat::Packing::CSI2 },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P) },
> > > > +       { { BayerFormat::BGGR, 16, BayerFormat::Packing::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16) },
> > > > +       { { BayerFormat::GBRG, 16, BayerFormat::Packing::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16) },
> > > > +       { { BayerFormat::GRBG, 16, BayerFormat::Packing::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16) },
> > > > +       { { BayerFormat::RGGB, 16, BayerFormat::Packing::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16) },
> > > > +       { { BayerFormat::MONO, 8, BayerFormat::Packing::None },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_GREY) },
> > > > +       { { BayerFormat::MONO, 10, BayerFormat::Packing::CSI2 },
> > > > V4L2PixelFormat(V4L2_PIX_FMT_Y10P) },
> > > >  };
> > > >
> > > >  const std::unordered_map<unsigned int, BayerFormat> mbusCodeToBayer{
> > > > -       { MEDIA_BUS_FMT_SBGGR8_1X8, { BayerFormat::BGGR, 8,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SGBRG8_1X8, { BayerFormat::GBRG, 8,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SGRBG8_1X8, { BayerFormat::GRBG, 8,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SRGGB8_1X8, { BayerFormat::RGGB, 8,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8, { BayerFormat::BGGR, 8,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8, { BayerFormat::GBRG, 8,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8, { BayerFormat::GRBG, 8,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8, { BayerFormat::RGGB, 8,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8, { BayerFormat::BGGR, 8,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8, { BayerFormat::GBRG, 8,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8, { BayerFormat::GRBG, 8,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8, { BayerFormat::RGGB, 8,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE, { BayerFormat::BGGR, 10,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE, { BayerFormat::BGGR, 10,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_BE, { BayerFormat::BGGR, 10,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_LE, { BayerFormat::BGGR, 10,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SBGGR10_1X10, { BayerFormat::BGGR, 10,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SGBRG10_1X10, { BayerFormat::GBRG, 10,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SGRBG10_1X10, { BayerFormat::GRBG, 10,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SRGGB10_1X10, { BayerFormat::RGGB, 10,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SBGGR12_1X12, { BayerFormat::BGGR, 12,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SGBRG12_1X12, { BayerFormat::GBRG, 12,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SGRBG12_1X12, { BayerFormat::GRBG, 12,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SRGGB12_1X12, { BayerFormat::RGGB, 12,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SBGGR14_1X14, { BayerFormat::BGGR, 14,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SGBRG14_1X14, { BayerFormat::GBRG, 14,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SGRBG14_1X14, { BayerFormat::GRBG, 14,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SRGGB14_1X14, { BayerFormat::RGGB, 14,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SBGGR16_1X16, { BayerFormat::BGGR, 16,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SGBRG16_1X16, { BayerFormat::GBRG, 16,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SGRBG16_1X16, { BayerFormat::GRBG, 16,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_SRGGB16_1X16, { BayerFormat::RGGB, 16,
> > > > BayerFormat::None } },
> > > > -       { MEDIA_BUS_FMT_Y8_1X8, { BayerFormat::MONO, 8,
> > BayerFormat::None
> > > > } },
> > > > -       { MEDIA_BUS_FMT_Y10_1X10, { BayerFormat::MONO, 10,
> > > > BayerFormat::None } },
> > > > +       { MEDIA_BUS_FMT_SBGGR8_1X8, { BayerFormat::BGGR, 8,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SGBRG8_1X8, { BayerFormat::GBRG, 8,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SGRBG8_1X8, { BayerFormat::GRBG, 8,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SRGGB8_1X8, { BayerFormat::RGGB, 8,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8, { BayerFormat::BGGR, 8,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8, { BayerFormat::GBRG, 8,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8, { BayerFormat::GRBG, 8,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8, { BayerFormat::RGGB, 8,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8, { BayerFormat::BGGR, 8,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8, { BayerFormat::GBRG, 8,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8, { BayerFormat::GRBG, 8,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8, { BayerFormat::RGGB, 8,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE, { BayerFormat::BGGR, 10,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE, { BayerFormat::BGGR, 10,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_BE, { BayerFormat::BGGR, 10,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_LE, { BayerFormat::BGGR, 10,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SBGGR10_1X10, { BayerFormat::BGGR, 10,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SGBRG10_1X10, { BayerFormat::GBRG, 10,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SGRBG10_1X10, { BayerFormat::GRBG, 10,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SRGGB10_1X10, { BayerFormat::RGGB, 10,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SBGGR12_1X12, { BayerFormat::BGGR, 12,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SGBRG12_1X12, { BayerFormat::GBRG, 12,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SGRBG12_1X12, { BayerFormat::GRBG, 12,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SRGGB12_1X12, { BayerFormat::RGGB, 12,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SBGGR14_1X14, { BayerFormat::BGGR, 14,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SGBRG14_1X14, { BayerFormat::GBRG, 14,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SGRBG14_1X14, { BayerFormat::GRBG, 14,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SRGGB14_1X14, { BayerFormat::RGGB, 14,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SBGGR16_1X16, { BayerFormat::BGGR, 16,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SGBRG16_1X16, { BayerFormat::GBRG, 16,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SGRBG16_1X16, { BayerFormat::GRBG, 16,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_SRGGB16_1X16, { BayerFormat::RGGB, 16,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_Y8_1X8, { BayerFormat::MONO, 8,
> > > > BayerFormat::Packing::None } },
> > > > +       { MEDIA_BUS_FMT_Y10_1X10, { BayerFormat::MONO, 10,
> > > > BayerFormat::Packing::None } },
> > > >  };
> > > >
> > > >  } /* namespace */
> > > > @@ -214,9 +214,9 @@ std::string BayerFormat::toString() const
> > > >
> > > >         result += "-" + std::to_string(bitDepth);
> > > >
> > > > -       if (packing == CSI2Packed)
> > > > +       if (packing == Packing::CSI2)
> > > >                 result += "-CSI2P";
> > > > -       else if (packing == IPU3Packed)
> > > > +       else if (packing == Packing::IPU3)
> > > >                 result += "-IPU3P";
> > > >
> > > >         return result;
> > > > diff --git a/test/bayer-format.cpp b/test/bayer-format.cpp
> > > > index e396ee83ca91..135bcb5214c8 100644
> > > > --- a/test/bayer-format.cpp
> > > > +++ b/test/bayer-format.cpp
> > > > @@ -30,7 +30,7 @@ protected:
> > > >                 }
> > > >
> > > >                 /* A correct Bayer format has to be valid. */
> > > > -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > > BayerFormat::None);
> > > > +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > > BayerFormat::Packing::None);
> > > >                 if (!bayerFmt.isValid()) {
> > > >                         cerr << "A correct BayerFormat has to be
> > valid."
> > > >                              << endl;
> > > > @@ -41,9 +41,9 @@ protected:
> > > >                  * Two bayer formats created with the same order and
> > bit
> > > > depth
> > > >                  * have to be equal.
> > > >                  */
> > > > -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > > BayerFormat::None);
> > > > +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > > BayerFormat::Packing::None);
> > > >                 BayerFormat bayerFmtExpect =
> > > > BayerFormat(BayerFormat::BGGR, 8,
> > > > -
> > > > BayerFormat::None);
> > > > +
> > > > BayerFormat::Packing::None);
> > > >                 if (bayerFmt != bayerFmtExpect) {
> > > >                         cerr << "Comparison of identical formats
> > failed."
> > > >                              << endl;
> > > > @@ -54,9 +54,9 @@ protected:
> > > >                  * Two Bayer formats created with the same order but
> > with a
> > > >                  * different bitDepth are not equal.
> > > >                  */
> > > > -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > > BayerFormat::None);
> > > > +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > > BayerFormat::Packing::None);
> > > >                 bayerFmtExpect = BayerFormat(BayerFormat::BGGR, 12,
> > > > -                                            BayerFormat::None);
> > > > +
> > BayerFormat::Packing::None);
> > > >                 if (bayerFmt == bayerFmtExpect) {
> > > >                         cerr << "Comparison of different formats
> > failed."
> > > >                              << endl;
> > > > @@ -96,7 +96,7 @@ protected:
> > > >                  * to a Bayer format.
> > > >                  */
> > > >                 bayerFmtExpect = BayerFormat(BayerFormat::BGGR, 8,
> > > > -                                            BayerFormat::None);
> > > > +
> > BayerFormat::Packing::None);
> > > >                 v4l2Fmt = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8);
> > > >                 bayerFmt = BayerFormat::fromV4L2PixelFormat(v4l2Fmt);
> > > >                 if (bayerFmt != bayerFmtExpect) {
> > > > @@ -123,7 +123,7 @@ protected:
> > > >                  * Test if a valid Bayer format can be converted to a
> > > >                  * string representation.
> > > >                  */
> > > > -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > > BayerFormat::None);
> > > > +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > > BayerFormat::Packing::None);
> > > >                 if (bayerFmt.toString() != "BGGR-8") {
> > > >                         cerr << "String representation != 'BGGR-8'
> > (got: '"
> > > >                              << bayerFmt.toString() << "' ) " << endl;
> > > > @@ -145,9 +145,9 @@ protected:
> > > >                  * Perform a horizontal Flip and make sure that the
> > > >                  * order is adjusted accordingly.
> > > >                  */
> > > > -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > > BayerFormat::None);
> > > > +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > > BayerFormat::Packing::None);
> > > >                 bayerFmtExpect = BayerFormat(BayerFormat::GBRG, 8,
> > > > -                                            BayerFormat::None);
> > > > +
> > BayerFormat::Packing::None);
> > > >                 BayerFormat hFlipFmt =
> > > > bayerFmt.transform(Transform::HFlip);
> > > >                 if (hFlipFmt != bayerFmtExpect) {
> > > >                         cerr << "Horizontal flip of 'BGGR-8' should
> > result
> > > > in '"
> > > > @@ -160,9 +160,9 @@ protected:
> > > >                  * Perform a vertical Flip and make sure that
> > > >                  * the order is adjusted accordingly.
> > > >                  */
> > > > -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > > BayerFormat::None);
> > > > +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > > BayerFormat::Packing::None);
> > > >                 bayerFmtExpect = BayerFormat(BayerFormat::GRBG, 8,
> > > > -                                            BayerFormat::None);
> > > > +
> > BayerFormat::Packing::None);
> > > >                 BayerFormat vFlipFmt =
> > > > bayerFmt.transform(Transform::VFlip);
> > > >                 if (vFlipFmt != bayerFmtExpect) {
> > > >                         cerr << "Vertical flip of 'BGGR-8' should
> > result
> > > > in '"
> > > > @@ -176,7 +176,7 @@ protected:
> > > >                  * pixels on the bottom left to top right diagonal and
> > make
> > > >                  * sure, that it doesn't change.
> > > >                  */
> > > > -               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > > BayerFormat::None);
> > > > +               bayerFmt = BayerFormat(BayerFormat::BGGR, 8,
> > > > BayerFormat::Packing::None);
> > > >                 BayerFormat transposeFmt = bayerFmt.transform(
> > > >                         Transform::Transpose);
> > > >                 if (transposeFmt != bayerFmt) {
> > > > @@ -192,9 +192,9 @@ protected:
> > > >                  * on the bottom left to top right diagonal and make
> > sure
> > > >                  * that their positions are switched.
> > > >                  */
> > > > -               bayerFmt = BayerFormat(BayerFormat::GBRG, 8,
> > > > BayerFormat::None);
> > > > +               bayerFmt = BayerFormat(BayerFormat::GBRG, 8,
> > > > BayerFormat::Packing::None);
> > > >                 bayerFmtExpect = BayerFormat(BayerFormat::GRBG, 8,
> > > > -                                            BayerFormat::None);
> > > > +
> > BayerFormat::Packing::None);
> > > >                 transposeFmt =
> > bayerFmt.transform(Transform::Transpose);
> > > >                 if (transposeFmt != bayerFmtExpect) {
> > > >                         cerr << "Transpose with the red & blue pixels
> > on
> > > > the "
> > > >
> > > > base-commit: 4d4694cd9f4ea73586dcb75d19905a1860356d9f
> >
> > --
> > Regards,
> >
> > Laurent Pinchart
> >

Patch
diff mbox series

diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h
index 723382d4168d..d9a56d744a25 100644
--- a/include/libcamera/internal/bayer_format.h
+++ b/include/libcamera/internal/bayer_format.h
@@ -27,10 +27,10 @@  public:
 		MONO = 4
 	};
 
-	enum Packing : uint16_t {
+	enum class Packing : uint16_t {
 		None = 0,
-		CSI2Packed = 1,
-		IPU3Packed = 2,
+		CSI2 = 1,
+		IPU3 = 2,
 	};
 
 	constexpr BayerFormat()
diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp
index 11355f144f66..1c1e849a7e31 100644
--- a/src/libcamera/bayer_format.cpp
+++ b/src/libcamera/bayer_format.cpp
@@ -53,11 +53,11 @@  namespace libcamera {
  * \enum BayerFormat::Packing
  * \brief Different types of packing that can be applied to a BayerFormat
  *
- * \var BayerFormat::None
+ * \var BayerFormat::Packing::None
  * \brief No packing
- * \var BayerFormat::CSI2Packed
+ * \var BayerFormat::Packing::CSI2
  * \brief Format uses MIPI CSI-2 style packing
- * \var BayerFormat::IPU3Packed
+ * \var BayerFormat::Packing::IPU3
  * \brief Format uses IPU3 style packing
  */
 
@@ -85,73 +85,73 @@  struct BayerFormatComparator {
 };
 
 const std::map<BayerFormat, V4L2PixelFormat, BayerFormatComparator> bayerToV4l2{
-	{ { BayerFormat::BGGR, 8, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8) },
-	{ { BayerFormat::GBRG, 8, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8) },
-	{ { BayerFormat::GRBG, 8, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8) },
-	{ { BayerFormat::RGGB, 8, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8) },
-	{ { BayerFormat::BGGR, 10, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10) },
-	{ { BayerFormat::GBRG, 10, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10) },
-	{ { BayerFormat::GRBG, 10, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10) },
-	{ { BayerFormat::RGGB, 10, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10) },
-	{ { BayerFormat::BGGR, 10, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P) },
-	{ { BayerFormat::GBRG, 10, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P) },
-	{ { BayerFormat::GRBG, 10, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P) },
-	{ { BayerFormat::RGGB, 10, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P) },
-	{ { BayerFormat::BGGR, 10, BayerFormat::IPU3Packed }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10) },
-	{ { BayerFormat::GBRG, 10, BayerFormat::IPU3Packed }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10) },
-	{ { BayerFormat::GRBG, 10, BayerFormat::IPU3Packed }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10) },
-	{ { BayerFormat::RGGB, 10, BayerFormat::IPU3Packed }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10) },
-	{ { BayerFormat::BGGR, 12, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12) },
-	{ { BayerFormat::GBRG, 12, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12) },
-	{ { BayerFormat::GRBG, 12, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12) },
-	{ { BayerFormat::RGGB, 12, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12) },
-	{ { BayerFormat::BGGR, 12, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P) },
-	{ { BayerFormat::GBRG, 12, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P) },
-	{ { BayerFormat::GRBG, 12, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P) },
-	{ { BayerFormat::RGGB, 12, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P) },
-	{ { BayerFormat::BGGR, 16, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16) },
-	{ { BayerFormat::GBRG, 16, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16) },
-	{ { BayerFormat::GRBG, 16, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16) },
-	{ { BayerFormat::RGGB, 16, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16) },
-	{ { BayerFormat::MONO, 8, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_GREY) },
-	{ { BayerFormat::MONO, 10, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_Y10P) },
+	{ { BayerFormat::BGGR, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8) },
+	{ { BayerFormat::GBRG, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8) },
+	{ { BayerFormat::GRBG, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8) },
+	{ { BayerFormat::RGGB, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8) },
+	{ { BayerFormat::BGGR, 10, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10) },
+	{ { BayerFormat::GBRG, 10, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10) },
+	{ { BayerFormat::GRBG, 10, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10) },
+	{ { BayerFormat::RGGB, 10, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10) },
+	{ { BayerFormat::BGGR, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P) },
+	{ { BayerFormat::GBRG, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P) },
+	{ { BayerFormat::GRBG, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P) },
+	{ { BayerFormat::RGGB, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P) },
+	{ { BayerFormat::BGGR, 10, BayerFormat::Packing::IPU3 }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10) },
+	{ { BayerFormat::GBRG, 10, BayerFormat::Packing::IPU3 }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10) },
+	{ { BayerFormat::GRBG, 10, BayerFormat::Packing::IPU3 }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10) },
+	{ { BayerFormat::RGGB, 10, BayerFormat::Packing::IPU3 }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10) },
+	{ { BayerFormat::BGGR, 12, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12) },
+	{ { BayerFormat::GBRG, 12, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12) },
+	{ { BayerFormat::GRBG, 12, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12) },
+	{ { BayerFormat::RGGB, 12, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12) },
+	{ { BayerFormat::BGGR, 12, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P) },
+	{ { BayerFormat::GBRG, 12, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P) },
+	{ { BayerFormat::GRBG, 12, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P) },
+	{ { BayerFormat::RGGB, 12, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P) },
+	{ { BayerFormat::BGGR, 16, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16) },
+	{ { BayerFormat::GBRG, 16, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16) },
+	{ { BayerFormat::GRBG, 16, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16) },
+	{ { BayerFormat::RGGB, 16, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16) },
+	{ { BayerFormat::MONO, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_GREY) },
+	{ { BayerFormat::MONO, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_Y10P) },
 };
 
 const std::unordered_map<unsigned int, BayerFormat> mbusCodeToBayer{
-	{ MEDIA_BUS_FMT_SBGGR8_1X8, { BayerFormat::BGGR, 8, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SGBRG8_1X8, { BayerFormat::GBRG, 8, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SGRBG8_1X8, { BayerFormat::GRBG, 8, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SRGGB8_1X8, { BayerFormat::RGGB, 8, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8, { BayerFormat::BGGR, 8, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8, { BayerFormat::GBRG, 8, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8, { BayerFormat::GRBG, 8, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8, { BayerFormat::RGGB, 8, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8, { BayerFormat::BGGR, 8, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8, { BayerFormat::GBRG, 8, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8, { BayerFormat::GRBG, 8, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8, { BayerFormat::RGGB, 8, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE, { BayerFormat::BGGR, 10, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE, { BayerFormat::BGGR, 10, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_BE, { BayerFormat::BGGR, 10, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_LE, { BayerFormat::BGGR, 10, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SBGGR10_1X10, { BayerFormat::BGGR, 10, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SGBRG10_1X10, { BayerFormat::GBRG, 10, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SGRBG10_1X10, { BayerFormat::GRBG, 10, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SRGGB10_1X10, { BayerFormat::RGGB, 10, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SBGGR12_1X12, { BayerFormat::BGGR, 12, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SGBRG12_1X12, { BayerFormat::GBRG, 12, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SGRBG12_1X12, { BayerFormat::GRBG, 12, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SRGGB12_1X12, { BayerFormat::RGGB, 12, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SBGGR14_1X14, { BayerFormat::BGGR, 14, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SGBRG14_1X14, { BayerFormat::GBRG, 14, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SGRBG14_1X14, { BayerFormat::GRBG, 14, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SRGGB14_1X14, { BayerFormat::RGGB, 14, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SBGGR16_1X16, { BayerFormat::BGGR, 16, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SGBRG16_1X16, { BayerFormat::GBRG, 16, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SGRBG16_1X16, { BayerFormat::GRBG, 16, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_SRGGB16_1X16, { BayerFormat::RGGB, 16, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_Y8_1X8, { BayerFormat::MONO, 8, BayerFormat::None } },
-	{ MEDIA_BUS_FMT_Y10_1X10, { BayerFormat::MONO, 10, BayerFormat::None } },
+	{ MEDIA_BUS_FMT_SBGGR8_1X8, { BayerFormat::BGGR, 8, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SGBRG8_1X8, { BayerFormat::GBRG, 8, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SGRBG8_1X8, { BayerFormat::GRBG, 8, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SRGGB8_1X8, { BayerFormat::RGGB, 8, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8, { BayerFormat::BGGR, 8, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8, { BayerFormat::GBRG, 8, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8, { BayerFormat::GRBG, 8, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8, { BayerFormat::RGGB, 8, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8, { BayerFormat::BGGR, 8, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8, { BayerFormat::GBRG, 8, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8, { BayerFormat::GRBG, 8, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8, { BayerFormat::RGGB, 8, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE, { BayerFormat::BGGR, 10, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE, { BayerFormat::BGGR, 10, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_BE, { BayerFormat::BGGR, 10, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_LE, { BayerFormat::BGGR, 10, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SBGGR10_1X10, { BayerFormat::BGGR, 10, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SGBRG10_1X10, { BayerFormat::GBRG, 10, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SGRBG10_1X10, { BayerFormat::GRBG, 10, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SRGGB10_1X10, { BayerFormat::RGGB, 10, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SBGGR12_1X12, { BayerFormat::BGGR, 12, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SGBRG12_1X12, { BayerFormat::GBRG, 12, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SGRBG12_1X12, { BayerFormat::GRBG, 12, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SRGGB12_1X12, { BayerFormat::RGGB, 12, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SBGGR14_1X14, { BayerFormat::BGGR, 14, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SGBRG14_1X14, { BayerFormat::GBRG, 14, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SGRBG14_1X14, { BayerFormat::GRBG, 14, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SRGGB14_1X14, { BayerFormat::RGGB, 14, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SBGGR16_1X16, { BayerFormat::BGGR, 16, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SGBRG16_1X16, { BayerFormat::GBRG, 16, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SGRBG16_1X16, { BayerFormat::GRBG, 16, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_SRGGB16_1X16, { BayerFormat::RGGB, 16, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_Y8_1X8, { BayerFormat::MONO, 8, BayerFormat::Packing::None } },
+	{ MEDIA_BUS_FMT_Y10_1X10, { BayerFormat::MONO, 10, BayerFormat::Packing::None } },
 };
 
 } /* namespace */
@@ -214,9 +214,9 @@  std::string BayerFormat::toString() const
 
 	result += "-" + std::to_string(bitDepth);
 
-	if (packing == CSI2Packed)
+	if (packing == Packing::CSI2)
 		result += "-CSI2P";
-	else if (packing == IPU3Packed)
+	else if (packing == Packing::IPU3)
 		result += "-IPU3P";
 
 	return result;
diff --git a/test/bayer-format.cpp b/test/bayer-format.cpp
index e396ee83ca91..135bcb5214c8 100644
--- a/test/bayer-format.cpp
+++ b/test/bayer-format.cpp
@@ -30,7 +30,7 @@  protected:
 		}
 
 		/* A correct Bayer format has to be valid. */
-		bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None);
+		bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::Packing::None);
 		if (!bayerFmt.isValid()) {
 			cerr << "A correct BayerFormat has to be valid."
 			     << endl;
@@ -41,9 +41,9 @@  protected:
 		 * Two bayer formats created with the same order and bit depth
 		 * have to be equal.
 		 */
-		bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None);
+		bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::Packing::None);
 		BayerFormat bayerFmtExpect = BayerFormat(BayerFormat::BGGR, 8,
-							 BayerFormat::None);
+							 BayerFormat::Packing::None);
 		if (bayerFmt != bayerFmtExpect) {
 			cerr << "Comparison of identical formats failed."
 			     << endl;
@@ -54,9 +54,9 @@  protected:
 		 * Two Bayer formats created with the same order but with a
 		 * different bitDepth are not equal.
 		 */
-		bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None);
+		bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::Packing::None);
 		bayerFmtExpect = BayerFormat(BayerFormat::BGGR, 12,
-					     BayerFormat::None);
+					     BayerFormat::Packing::None);
 		if (bayerFmt == bayerFmtExpect) {
 			cerr << "Comparison of different formats failed."
 			     << endl;
@@ -96,7 +96,7 @@  protected:
 		 * to a Bayer format.
 		 */
 		bayerFmtExpect = BayerFormat(BayerFormat::BGGR, 8,
-					     BayerFormat::None);
+					     BayerFormat::Packing::None);
 		v4l2Fmt = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8);
 		bayerFmt = BayerFormat::fromV4L2PixelFormat(v4l2Fmt);
 		if (bayerFmt != bayerFmtExpect) {
@@ -123,7 +123,7 @@  protected:
 		 * Test if a valid Bayer format can be converted to a
 		 * string representation.
 		 */
-		bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None);
+		bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::Packing::None);
 		if (bayerFmt.toString() != "BGGR-8") {
 			cerr << "String representation != 'BGGR-8' (got: '"
 			     << bayerFmt.toString() << "' ) " << endl;
@@ -145,9 +145,9 @@  protected:
 		 * Perform a horizontal Flip and make sure that the
 		 * order is adjusted accordingly.
 		 */
-		bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None);
+		bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::Packing::None);
 		bayerFmtExpect = BayerFormat(BayerFormat::GBRG, 8,
-					     BayerFormat::None);
+					     BayerFormat::Packing::None);
 		BayerFormat hFlipFmt = bayerFmt.transform(Transform::HFlip);
 		if (hFlipFmt != bayerFmtExpect) {
 			cerr << "Horizontal flip of 'BGGR-8' should result in '"
@@ -160,9 +160,9 @@  protected:
 		 * Perform a vertical Flip and make sure that
 		 * the order is adjusted accordingly.
 		 */
-		bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None);
+		bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::Packing::None);
 		bayerFmtExpect = BayerFormat(BayerFormat::GRBG, 8,
-					     BayerFormat::None);
+					     BayerFormat::Packing::None);
 		BayerFormat vFlipFmt = bayerFmt.transform(Transform::VFlip);
 		if (vFlipFmt != bayerFmtExpect) {
 			cerr << "Vertical flip of 'BGGR-8' should result in '"
@@ -176,7 +176,7 @@  protected:
 		 * pixels on the bottom left to top right diagonal and make
 		 * sure, that it doesn't change.
 		 */
-		bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None);
+		bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::Packing::None);
 		BayerFormat transposeFmt = bayerFmt.transform(
 			Transform::Transpose);
 		if (transposeFmt != bayerFmt) {
@@ -192,9 +192,9 @@  protected:
 		 * on the bottom left to top right diagonal and make sure
 		 * that their positions are switched.
 		 */
-		bayerFmt = BayerFormat(BayerFormat::GBRG, 8, BayerFormat::None);
+		bayerFmt = BayerFormat(BayerFormat::GBRG, 8, BayerFormat::Packing::None);
 		bayerFmtExpect = BayerFormat(BayerFormat::GRBG, 8,
-					     BayerFormat::None);
+					     BayerFormat::Packing::None);
 		transposeFmt = bayerFmt.transform(Transform::Transpose);
 		if (transposeFmt != bayerFmtExpect) {
 			cerr << "Transpose with the red & blue pixels on the "