[libcamera-devel] [PATCH 2/5] libcamera: Add operator<<() for pixel format classes

Kieran Bingham kieran.bingham at ideasonboard.com
Wed May 4 10:56:01 CEST 2022


Quoting Laurent Pinchart via libcamera-devel (2022-04-29 22:23:45)
> Implement the stream output operator<<() for the PixelFormat and
> V4L2PixelFormat classes to simplify printing them.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>

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

> ---
>  include/libcamera/internal/v4l2_pixelformat.h |  3 +++
>  include/libcamera/pixel_format.h              |  3 +++
>  src/libcamera/pixel_format.cpp                | 12 ++++++++++++
>  src/libcamera/v4l2_pixelformat.cpp            | 13 +++++++++++++
>  4 files changed, 31 insertions(+)
> 
> diff --git a/include/libcamera/internal/v4l2_pixelformat.h b/include/libcamera/internal/v4l2_pixelformat.h
> index 886d534d8c91..fb2d5d0b93df 100644
> --- a/include/libcamera/internal/v4l2_pixelformat.h
> +++ b/include/libcamera/internal/v4l2_pixelformat.h
> @@ -8,6 +8,7 @@
>  
>  #pragma once
>  
> +#include <ostream>
>  #include <stdint.h>
>  #include <string>
>  
> @@ -50,4 +51,6 @@ private:
>         uint32_t fourcc_;
>  };
>  
> +std::ostream &operator<<(std::ostream &out, const V4L2PixelFormat &f);
> +
>  } /* namespace libcamera */
> diff --git a/include/libcamera/pixel_format.h b/include/libcamera/pixel_format.h
> index a9d7c03de851..d49c5f784118 100644
> --- a/include/libcamera/pixel_format.h
> +++ b/include/libcamera/pixel_format.h
> @@ -7,6 +7,7 @@
>  
>  #pragma once
>  
> +#include <ostream>
>  #include <set>
>  #include <stdint.h>
>  #include <string>
> @@ -45,4 +46,6 @@ private:
>         uint64_t modifier_;
>  };
>  
> +std::ostream &operator<<(std::ostream &out, const PixelFormat &f);
> +
>  } /* namespace libcamera */
> diff --git a/src/libcamera/pixel_format.cpp b/src/libcamera/pixel_format.cpp
> index 997aeb8a9290..80c22072b072 100644
> --- a/src/libcamera/pixel_format.cpp
> +++ b/src/libcamera/pixel_format.cpp
> @@ -140,4 +140,16 @@ PixelFormat PixelFormat::fromString(const std::string &name)
>         return PixelFormatInfo::info(name).format;
>  }
>  
> +/**
> + * \brief Insert a text representation of a PixelFormat into an output stream
> + * \param[in] out The output stream
> + * \param[in] f The PixelFormat
> + * \return The output stream \a out
> + */
> +std::ostream &operator<<(std::ostream &out, const PixelFormat &f)
> +{
> +       out << f.toString();
> +       return out;
> +}
> +
>  } /* namespace libcamera */
> diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp
> index 0e0da3f0df07..1dd93baa7a64 100644
> --- a/src/libcamera/v4l2_pixelformat.cpp
> +++ b/src/libcamera/v4l2_pixelformat.cpp
> @@ -316,4 +316,17 @@ V4L2PixelFormat V4L2PixelFormat::fromPixelFormat(const PixelFormat &pixelFormat,
>         return multiplanar ? info.v4l2Formats.multi : info.v4l2Formats.single;
>  }
>  
> +/**
> + * \brief Insert a text representation of a V4L2PixelFormat into an output
> + * stream
> + * \param[in] out The output stream
> + * \param[in] f The V4L2PixelFormat
> + * \return The output stream \a out
> + */
> +std::ostream &operator<<(std::ostream &out, const V4L2PixelFormat &f)
> +{
> +       out << f.toString();
> +       return out;
> +}
> +
>  } /* namespace libcamera */
> -- 
> Regards,
> 
> Laurent Pinchart
>


More information about the libcamera-devel mailing list