mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-26 18:15:06 +03:00
libcamera: bayer_format: Add the fromV4L2PixelFormat function
Add a static member function to get the corresponding BayerFormat from a given V4L2PixelFormat. The motivation behind this patch is to align the overall structure of the BayerFormat class with other parts of the code base, such as the V4L2PixelFormat class. The downside of this change is a slightly worse time complexity, but the upside is a smaller codebase and lower memory consumption. As the function is probably not used very frequently, I tend to favor the mentioned upsides. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Sebastian Fricke <sebastian.fricke@posteo.net> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
515211e8ef
commit
83e434b2dc
3 changed files with 21 additions and 2 deletions
|
@ -49,6 +49,7 @@ public:
|
||||||
std::string toString() const;
|
std::string toString() const;
|
||||||
|
|
||||||
V4L2PixelFormat toV4L2PixelFormat() const;
|
V4L2PixelFormat toV4L2PixelFormat() const;
|
||||||
|
static BayerFormat fromV4L2PixelFormat(V4L2PixelFormat v4l2Format);
|
||||||
BayerFormat transform(Transform t) const;
|
BayerFormat transform(Transform t) const;
|
||||||
|
|
||||||
Order order;
|
Order order;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include "libcamera/internal/bayer_format.h"
|
#include "libcamera/internal/bayer_format.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
@ -272,6 +273,23 @@ V4L2PixelFormat BayerFormat::toV4L2PixelFormat() const
|
||||||
return V4L2PixelFormat();
|
return V4L2PixelFormat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Convert \a v4l2Format to the corresponding BayerFormat
|
||||||
|
* \param[in] v4l2Format The raw format to convert into a BayerFormat
|
||||||
|
* \return The BayerFormat corresponding to \a v4l2Format
|
||||||
|
*/
|
||||||
|
BayerFormat BayerFormat::fromV4L2PixelFormat(V4L2PixelFormat v4l2Format)
|
||||||
|
{
|
||||||
|
auto it = std::find_if(bayerToV4l2.begin(), bayerToV4l2.end(),
|
||||||
|
[v4l2Format](const auto &i) {
|
||||||
|
return i.second == v4l2Format;
|
||||||
|
});
|
||||||
|
if (it != bayerToV4l2.end())
|
||||||
|
return it->first;
|
||||||
|
|
||||||
|
return BayerFormat();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Apply a transform to this BayerFormat
|
* \brief Apply a transform to this BayerFormat
|
||||||
* \param[in] t The transform to apply
|
* \param[in] t The transform to apply
|
||||||
|
|
|
@ -357,7 +357,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()
|
||||||
*/
|
*/
|
||||||
V4L2PixelFormat fourcc = sensorFormat.fourcc;
|
V4L2PixelFormat fourcc = sensorFormat.fourcc;
|
||||||
if (data_->flipsAlterBayerOrder_) {
|
if (data_->flipsAlterBayerOrder_) {
|
||||||
BayerFormat bayer(fourcc);
|
BayerFormat bayer = BayerFormat::fromV4L2PixelFormat(fourcc);
|
||||||
bayer.order = data_->nativeBayerOrder_;
|
bayer.order = data_->nativeBayerOrder_;
|
||||||
bayer = bayer.transform(combined);
|
bayer = bayer.transform(combined);
|
||||||
fourcc = bayer.toV4L2PixelFormat();
|
fourcc = bayer.toV4L2PixelFormat();
|
||||||
|
@ -1001,7 +1001,7 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator)
|
||||||
BayerFormat bayerFormat;
|
BayerFormat bayerFormat;
|
||||||
for (const auto &iter : dev->formats()) {
|
for (const auto &iter : dev->formats()) {
|
||||||
V4L2PixelFormat v4l2Format = iter.first;
|
V4L2PixelFormat v4l2Format = iter.first;
|
||||||
bayerFormat = BayerFormat(v4l2Format);
|
bayerFormat = BayerFormat::fromV4L2PixelFormat(v4l2Format);
|
||||||
if (bayerFormat.isValid())
|
if (bayerFormat.isValid())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue