libcamera: Use PixelFormat instead of unsigned int where appropriate

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@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Niklas Söderlund 2020-02-28 02:38:18 +01:00
parent 9a1e71b8a1
commit f28ca20960
10 changed files with 22 additions and 18 deletions

View file

@ -303,7 +303,7 @@ int CamApp::infoConfiguration()
std::cout << index << ": " << cfg.toString() << std::endl; std::cout << index << ": " << cfg.toString() << std::endl;
const StreamFormats &formats = cfg.formats(); const StreamFormats &formats = cfg.formats();
for (unsigned int pixelformat : formats.pixelformats()) { for (PixelFormat pixelformat : formats.pixelformats()) {
std::cout << " * Pixelformat: 0x" << std::hex std::cout << " * Pixelformat: 0x" << std::hex
<< std::setw(8) << pixelformat << " " << std::setw(8) << pixelformat << " "
<< formats.range(pixelformat).toString() << formats.range(pixelformat).toString()

View file

@ -79,16 +79,16 @@ gst_libcamera_stream_formats_to_caps(const StreamFormats &formats)
{ {
GstCaps *caps = gst_caps_new_empty(); GstCaps *caps = gst_caps_new_empty();
for (unsigned int fourcc : formats.pixelformats()) { for (PixelFormat pixelformat : formats.pixelformats()) {
g_autoptr(GstStructure) bare_s = bare_structure_from_fourcc(fourcc); g_autoptr(GstStructure) bare_s = bare_structure_from_fourcc(pixelformat);
if (!bare_s) { if (!bare_s) {
GST_WARNING("Unsupported DRM format %" GST_FOURCC_FORMAT, GST_WARNING("Unsupported DRM format %" GST_FOURCC_FORMAT,
GST_FOURCC_ARGS(fourcc)); GST_FOURCC_ARGS(pixelformat));
continue; continue;
} }
for (const Size &size : formats.sizes(fourcc)) { for (const Size &size : formats.sizes(pixelformat)) {
GstStructure *s = gst_structure_copy(bare_s); GstStructure *s = gst_structure_copy(bare_s);
gst_structure_set(s, gst_structure_set(s,
"width", G_TYPE_INT, size.width, "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); gst_caps_append_structure(caps, s);
} }
const SizeRange &range = formats.range(fourcc); const SizeRange &range = formats.range(pixelformat);
if (range.hStep && range.vStep) { if (range.hStep && range.vStep) {
GstStructure *s = gst_structure_copy(bare_s); GstStructure *s = gst_structure_copy(bare_s);
GValue val = G_VALUE_INIT; GValue val = G_VALUE_INIT;

View file

@ -349,7 +349,7 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate()
for (unsigned int i = 0; i < config_.size(); ++i) { for (unsigned int i = 0; i < config_.size(); ++i) {
StreamConfiguration &cfg = config_[i]; StreamConfiguration &cfg = config_[i];
const unsigned int pixelFormat = cfg.pixelFormat; const PixelFormat pixelFormat = cfg.pixelFormat;
const Size size = cfg.size; const Size size = cfg.size;
const IPU3Stream *stream; const IPU3Stream *stream;

View file

@ -433,7 +433,7 @@ RkISP1CameraConfiguration::RkISP1CameraConfiguration(Camera *camera,
CameraConfiguration::Status RkISP1CameraConfiguration::validate() CameraConfiguration::Status RkISP1CameraConfiguration::validate()
{ {
static const std::array<unsigned int, 8> formats{ static const std::array<PixelFormat, 8> formats{
DRM_FORMAT_YUYV, DRM_FORMAT_YUYV,
DRM_FORMAT_YVYU, DRM_FORMAT_YVYU,
DRM_FORMAT_VYUY, DRM_FORMAT_VYUY,

View file

@ -107,10 +107,10 @@ CameraConfiguration::Status UVCCameraConfiguration::validate()
StreamConfiguration &cfg = config_[0]; StreamConfiguration &cfg = config_[0];
const StreamFormats &formats = cfg.formats(); const StreamFormats &formats = cfg.formats();
const unsigned int pixelFormat = cfg.pixelFormat; const PixelFormat pixelFormat = cfg.pixelFormat;
const Size size = cfg.size; 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); auto iter = std::find(pixelFormats.begin(), pixelFormats.end(), pixelFormat);
if (iter == pixelFormats.end()) { if (iter == pixelFormats.end()) {
cfg.pixelFormat = pixelFormats.front(); cfg.pixelFormat = pixelFormats.front();

View file

@ -106,7 +106,7 @@ private:
namespace { namespace {
constexpr std::array<unsigned int, 3> pixelformats{ constexpr std::array<PixelFormat, 3> pixelformats{
DRM_FORMAT_RGB888, DRM_FORMAT_RGB888,
DRM_FORMAT_BGR888, DRM_FORMAT_BGR888,
DRM_FORMAT_BGRA8888, DRM_FORMAT_BGRA8888,
@ -177,7 +177,7 @@ CameraConfiguration *PipelineHandlerVimc::generateConfiguration(Camera *camera,
ImageFormats formats; ImageFormats formats;
for (unsigned int pixelformat : pixelformats) { for (PixelFormat pixelformat : pixelformats) {
/* The scaler hardcodes a x3 scale-up ratio. */ /* The scaler hardcodes a x3 scale-up ratio. */
std::vector<SizeRange> sizes{ std::vector<SizeRange> sizes{
SizeRange{ 48, 48, 4096, 2160 } SizeRange{ 48, 48, 4096, 2160 }

View file

@ -27,7 +27,7 @@
#define CLIP(x) CLAMP(x,0,255) #define CLIP(x) CLAMP(x,0,255)
#endif #endif
int FormatConverter::configure(unsigned int format, unsigned int width, int FormatConverter::configure(libcamera::PixelFormat format, unsigned int width,
unsigned int height) unsigned int height)
{ {
switch (format) { switch (format) {

View file

@ -9,12 +9,14 @@
#include <stddef.h> #include <stddef.h>
#include <libcamera/pixelformats.h>
class QImage; class QImage;
class FormatConverter class FormatConverter
{ {
public: public:
int configure(unsigned int format, unsigned int width, int configure(libcamera::PixelFormat format, unsigned int width,
unsigned int height); unsigned int height);
void convert(const unsigned char *src, size_t size, QImage *dst); 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 convertRGB(const unsigned char *src, unsigned char *dst);
void convertYUV(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 width_;
unsigned int height_; unsigned int height_;

View file

@ -44,7 +44,7 @@ QImage ViewFinder::getCurrentImage()
return image_->copy(); return image_->copy();
} }
int ViewFinder::setFormat(unsigned int format, unsigned int width, int ViewFinder::setFormat(libcamera::PixelFormat format, unsigned int width,
unsigned int height) unsigned int height)
{ {
int ret; int ret;

View file

@ -10,6 +10,8 @@
#include <QMutex> #include <QMutex>
#include <QWidget> #include <QWidget>
#include <libcamera/pixelformats.h>
#include "format_converter.h" #include "format_converter.h"
class QImage; class QImage;
@ -20,7 +22,7 @@ public:
ViewFinder(QWidget *parent); ViewFinder(QWidget *parent);
~ViewFinder(); ~ViewFinder();
int setFormat(unsigned int format, unsigned int width, int setFormat(libcamera::PixelFormat format, unsigned int width,
unsigned int height); unsigned int height);
void display(const unsigned char *rgb, size_t size); void display(const unsigned char *rgb, size_t size);
@ -31,7 +33,7 @@ protected:
QSize sizeHint() const override; QSize sizeHint() const override;
private: private:
unsigned int format_; libcamera::PixelFormat format_;
unsigned int width_; unsigned int width_;
unsigned int height_; unsigned int height_;