[libcamera-devel] [PATCH 1/4] libcamera: Use PixelFormat instead of unsigned int where appropriate
Niklas Söderlund
niklas.soderlund at ragnatech.se
Mon Mar 16 03:40:33 CET 2020
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>
---
src/cam/main.cpp | 2 +-
src/gstreamer/gstlibcamera-utils.cpp | 10 +++++-----
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 ++++--
9 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/src/cam/main.cpp b/src/cam/main.cpp
index ea6f7914839c703e..af516f1cbf23974a 100644
--- a/src/cam/main.cpp
+++ b/src/cam/main.cpp
@@ -303,7 +303,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/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp
index 44a993fa6b6f4da1..3b3973bcea3dc759 100644
--- a/src/gstreamer/gstlibcamera-utils.cpp
+++ b/src/gstreamer/gstlibcamera-utils.cpp
@@ -79,16 +79,16 @@ gst_libcamera_stream_formats_to_caps(const StreamFormats &formats)
{
GstCaps *caps = gst_caps_new_empty();
- for (unsigned int fourcc : formats.pixelformats()) {
- g_autoptr(GstStructure) bare_s = bare_structure_from_fourcc(fourcc);
+ for (PixelFormat pixelformat : formats.pixelformats()) {
+ g_autoptr(GstStructure) bare_s = bare_structure_from_fourcc(pixelformat);
if (!bare_s) {
GST_WARNING("Unsupported DRM format %" GST_FOURCC_FORMAT,
- GST_FOURCC_ARGS(fourcc));
+ GST_FOURCC_ARGS(pixelformat));
continue;
}
- for (const Size &size : formats.sizes(fourcc)) {
+ for (const Size &size : formats.sizes(pixelformat)) {
GstStructure *s = gst_structure_copy(bare_s);
gst_structure_set(s,
"width", G_TYPE_INT, size.width,
@@ -97,7 +97,7 @@ gst_libcamera_stream_formats_to_caps(const StreamFormats &formats)
gst_caps_append_structure(caps, s);
}
- const SizeRange &range = formats.range(fourcc);
+ const SizeRange &range = formats.range(pixelformat);
if (range.hStep && range.vStep) {
GstStructure *s = gst_structure_copy(bare_s);
GValue val = G_VALUE_INIT;
diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
index 6b93c50978a76630..0c2a217c9ea8f6ba 100644
--- a/src/libcamera/pipeline/ipu3/ipu3.cpp
+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
@@ -348,7 +348,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 40cc3ee7d0987ba9..320da2685795c041 100644
--- a/src/libcamera/pipeline/uvcvideo.cpp
+++ b/src/libcamera/pipeline/uvcvideo.cpp
@@ -105,10 +105,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 eceb16d5586acf09..8792dfe48ed8db31 100644
--- a/src/libcamera/pipeline/vimc.cpp
+++ b/src/libcamera/pipeline/vimc.cpp
@@ -175,7 +175,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_;
--
2.25.1
More information about the libcamera-devel
mailing list