[libcamera-devel] [RFC 1/6] libcamera: Use PixelFormat instead of unsigned int where appropriate
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Sat Feb 29 11:36:30 CET 2020
Hi Niklas,
Thank you for the patch.
On Fri, Feb 28, 2020 at 04:29:08AM +0100, Niklas Söderlund wrote:
> Use the PixelFormat instead of unsigned int where a pixel format is to
> be used. PixelFormat is defined as an unsigned int but is about to be
> turned into a class to add functionality.
>
> There is no functional change in this patch.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> ---
> src/cam/main.cpp | 2 +-
> src/libcamera/pipeline/ipu3/ipu3.cpp | 2 +-
> src/libcamera/pipeline/uvcvideo.cpp | 4 ++--
> src/libcamera/pipeline/vimc.cpp | 2 +-
> src/qcam/format_converter.cpp | 2 +-
> src/qcam/format_converter.h | 6 ++++--
> src/qcam/viewfinder.cpp | 2 +-
> src/qcam/viewfinder.h | 6 ++++--
> 8 files changed, 15 insertions(+), 11 deletions(-)
>
> diff --git a/src/cam/main.cpp b/src/cam/main.cpp
> index a38cca959aca05ff..ad4be55fc114fe22 100644
> --- a/src/cam/main.cpp
> +++ b/src/cam/main.cpp
> @@ -281,7 +281,7 @@ int CamApp::infoConfiguration()
> std::cout << index << ": " << cfg.toString() << std::endl;
>
> const StreamFormats &formats = cfg.formats();
> - for (unsigned int pixelformat : formats.pixelformats()) {
> + for (PixelFormat pixelformat : formats.pixelformats()) {
> std::cout << " * Pixelformat: 0x" << std::hex
> << std::setw(8) << pixelformat << " "
> << formats.range(pixelformat).toString()
> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
> index 387bb070b5050e77..33f97b340716abd0 100644
> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp
> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
> @@ -349,7 +349,7 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate()
>
> for (unsigned int i = 0; i < config_.size(); ++i) {
> StreamConfiguration &cfg = config_[i];
> - const unsigned int pixelFormat = cfg.pixelFormat;
> + const PixelFormat pixelFormat = cfg.pixelFormat;
> const Size size = cfg.size;
> const IPU3Stream *stream;
>
> diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp
> index 29afb121aa46d5d4..cf419e8b25a87389 100644
> --- a/src/libcamera/pipeline/uvcvideo.cpp
> +++ b/src/libcamera/pipeline/uvcvideo.cpp
> @@ -107,10 +107,10 @@ CameraConfiguration::Status UVCCameraConfiguration::validate()
>
> StreamConfiguration &cfg = config_[0];
> const StreamFormats &formats = cfg.formats();
> - const unsigned int pixelFormat = cfg.pixelFormat;
> + const PixelFormat pixelFormat = cfg.pixelFormat;
> const Size size = cfg.size;
>
> - const std::vector<unsigned int> pixelFormats = formats.pixelformats();
> + const std::vector<PixelFormat> pixelFormats = formats.pixelformats();
> auto iter = std::find(pixelFormats.begin(), pixelFormats.end(), pixelFormat);
> if (iter == pixelFormats.end()) {
> cfg.pixelFormat = pixelFormats.front();
> diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp
> index 5d3d12fef30b01b5..93d89729e1faa29f 100644
> --- a/src/libcamera/pipeline/vimc.cpp
> +++ b/src/libcamera/pipeline/vimc.cpp
> @@ -177,7 +177,7 @@ CameraConfiguration *PipelineHandlerVimc::generateConfiguration(Camera *camera,
>
> ImageFormats formats;
>
> - for (unsigned int pixelformat : pixelformats) {
> + for (PixelFormat pixelformat : pixelformats) {
> /* The scaler hardcodes a x3 scale-up ratio. */
> std::vector<SizeRange> sizes{
> SizeRange{ 48, 48, 4096, 2160 }
> diff --git a/src/qcam/format_converter.cpp b/src/qcam/format_converter.cpp
> index 383d482231400a44..368cb43fbf17ae4d 100644
> --- a/src/qcam/format_converter.cpp
> +++ b/src/qcam/format_converter.cpp
> @@ -27,7 +27,7 @@
> #define CLIP(x) CLAMP(x,0,255)
> #endif
>
> -int FormatConverter::configure(unsigned int format, unsigned int width,
> +int FormatConverter::configure(libcamera::PixelFormat format, unsigned int width,
> unsigned int height)
> {
> switch (format) {
> diff --git a/src/qcam/format_converter.h b/src/qcam/format_converter.h
> index 391e6a44d4ba7d4b..ff488b994ade3c3e 100644
> --- a/src/qcam/format_converter.h
> +++ b/src/qcam/format_converter.h
> @@ -9,12 +9,14 @@
>
> #include <stddef.h>
>
> +#include <libcamera/pixelformats.h>
> +
> class QImage;
>
> class FormatConverter
> {
> public:
> - int configure(unsigned int format, unsigned int width,
> + int configure(libcamera::PixelFormat format, unsigned int width,
> unsigned int height);
>
> void convert(const unsigned char *src, size_t size, QImage *dst);
> @@ -31,7 +33,7 @@ private:
> void convertRGB(const unsigned char *src, unsigned char *dst);
> void convertYUV(const unsigned char *src, unsigned char *dst);
>
> - unsigned int format_;
> + libcamera::PixelFormat format_;
> unsigned int width_;
> unsigned int height_;
>
> diff --git a/src/qcam/viewfinder.cpp b/src/qcam/viewfinder.cpp
> index d51eebb10aef8663..0ebb8edd49efd1b1 100644
> --- a/src/qcam/viewfinder.cpp
> +++ b/src/qcam/viewfinder.cpp
> @@ -44,7 +44,7 @@ QImage ViewFinder::getCurrentImage()
> return image_->copy();
> }
>
> -int ViewFinder::setFormat(unsigned int format, unsigned int width,
> +int ViewFinder::setFormat(libcamera::PixelFormat format, unsigned int width,
> unsigned int height)
> {
> int ret;
> diff --git a/src/qcam/viewfinder.h b/src/qcam/viewfinder.h
> index 2ba28b60345b0cb3..2668aa4457657ef9 100644
> --- a/src/qcam/viewfinder.h
> +++ b/src/qcam/viewfinder.h
> @@ -10,6 +10,8 @@
> #include <QMutex>
> #include <QWidget>
>
> +#include <libcamera/pixelformats.h>
> +
> #include "format_converter.h"
>
> class QImage;
> @@ -20,7 +22,7 @@ public:
> ViewFinder(QWidget *parent);
> ~ViewFinder();
>
> - int setFormat(unsigned int format, unsigned int width,
> + int setFormat(libcamera::PixelFormat format, unsigned int width,
> unsigned int height);
> void display(const unsigned char *rgb, size_t size);
>
> @@ -31,7 +33,7 @@ protected:
> QSize sizeHint() const override;
>
> private:
> - unsigned int format_;
> + libcamera::PixelFormat format_;
> unsigned int width_;
> unsigned int height_;
>
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list