libcamera: formats: PixelFormatInfo: Add v4l2 lookup function
Add a lookup function for PixelFormatInfo that takes a V4L2PixelFormat. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
f1b449476c
commit
fad0314bc9
2 changed files with 23 additions and 3 deletions
|
@ -51,6 +51,7 @@ public:
|
||||||
bool isValid() const { return format.isValid(); }
|
bool isValid() const { return format.isValid(); }
|
||||||
|
|
||||||
static const PixelFormatInfo &info(const PixelFormat &format);
|
static const PixelFormatInfo &info(const PixelFormat &format);
|
||||||
|
static const PixelFormatInfo &info(const V4L2PixelFormat &format);
|
||||||
|
|
||||||
/* \todo Add support for non-contiguous memory planes */
|
/* \todo Add support for non-contiguous memory planes */
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include "libcamera/internal/formats.h"
|
#include "libcamera/internal/formats.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <libcamera/formats.h>
|
#include <libcamera/formats.h>
|
||||||
|
@ -228,6 +229,8 @@ const std::map<unsigned int, std::vector<SizeRange>> &ImageFormats::data() const
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
const PixelFormatInfo pixelFormatInfoInvalid{};
|
||||||
|
|
||||||
const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
|
const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
|
||||||
/* RGB formats. */
|
/* RGB formats. */
|
||||||
{ formats::BGR888, {
|
{ formats::BGR888, {
|
||||||
|
@ -699,17 +702,33 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
|
||||||
*/
|
*/
|
||||||
const PixelFormatInfo &PixelFormatInfo::info(const PixelFormat &format)
|
const PixelFormatInfo &PixelFormatInfo::info(const PixelFormat &format)
|
||||||
{
|
{
|
||||||
static const PixelFormatInfo invalid{};
|
|
||||||
|
|
||||||
const auto iter = pixelFormatInfo.find(format);
|
const auto iter = pixelFormatInfo.find(format);
|
||||||
if (iter == pixelFormatInfo.end()) {
|
if (iter == pixelFormatInfo.end()) {
|
||||||
LOG(Formats, Warning)
|
LOG(Formats, Warning)
|
||||||
<< "Unsupported pixel format 0x"
|
<< "Unsupported pixel format 0x"
|
||||||
<< utils::hex(format.fourcc());
|
<< utils::hex(format.fourcc());
|
||||||
return invalid;
|
return pixelFormatInfoInvalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
return iter->second;
|
return iter->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Retrieve information about a pixel format
|
||||||
|
* \param[in] format The V4L2 pixel format
|
||||||
|
* \return The PixelFormatInfo describing the V4L2 \a format if known, or an
|
||||||
|
* invalid PixelFormatInfo otherwise
|
||||||
|
*/
|
||||||
|
const PixelFormatInfo &PixelFormatInfo::info(const V4L2PixelFormat &format)
|
||||||
|
{
|
||||||
|
const auto &info = std::find_if(pixelFormatInfo.begin(), pixelFormatInfo.end(),
|
||||||
|
[format](auto pair) {
|
||||||
|
return pair.second.v4l2Format == format;
|
||||||
|
});
|
||||||
|
if (info == pixelFormatInfo.end())
|
||||||
|
return pixelFormatInfoInvalid;
|
||||||
|
|
||||||
|
return info->second;
|
||||||
|
}
|
||||||
|
|
||||||
} /* namespace libcamera */
|
} /* namespace libcamera */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue