libcamera: pixel_format: Replace hex with format names

Print format names defined in formats namespace instead of the hex
values in toString() as they are easier to comprehend. For this add
a property of 'name' in PixelFormatInfo' so as to map the formats
with their names. Print fourcc for formats which are not used in
libcamera.

Signed-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Kaaira Gupta 2020-06-22 16:33:51 +05:30 committed by Laurent Pinchart
parent c2bfe003e7
commit 2129117df9
5 changed files with 125 additions and 5 deletions

View file

@ -46,6 +46,7 @@ public:
static const PixelFormatInfo &info(const PixelFormat &format); static const PixelFormatInfo &info(const PixelFormat &format);
/* \todo Add support for non-contiguous memory planes */ /* \todo Add support for non-contiguous memory planes */
const char *name;
PixelFormat format; PixelFormat format;
V4L2PixelFormat v4l2Format; V4L2PixelFormat v4l2Format;
unsigned int bitsPerPixel; unsigned int bitsPerPixel;

View file

@ -118,6 +118,10 @@ const std::map<unsigned int, std::vector<SizeRange>> &ImageFormats::data() const
* format. It facilitates handling of pixel formats by providing data commonly * format. It facilitates handling of pixel formats by providing data commonly
* used in pipeline handlers. * used in pipeline handlers.
* *
* \var PixelFormatInfo::name
* \brief The format name as a human-readable string, used as the test
* representation of the PixelFormat
*
* \var PixelFormatInfo::format * \var PixelFormatInfo::format
* \brief The PixelFormat described by this instance * \brief The PixelFormat described by this instance
* *
@ -169,6 +173,7 @@ namespace {
const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
/* RGB formats. */ /* RGB formats. */
{ formats::BGR888, { { formats::BGR888, {
.name = "BGR888",
.format = formats::BGR888, .format = formats::BGR888,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGB24), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGB24),
.bitsPerPixel = 24, .bitsPerPixel = 24,
@ -176,6 +181,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::RGB888, { { formats::RGB888, {
.name = "RGB888",
.format = formats::RGB888, .format = formats::RGB888,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_BGR24), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_BGR24),
.bitsPerPixel = 24, .bitsPerPixel = 24,
@ -183,6 +189,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::ABGR8888, { { formats::ABGR8888, {
.name = "ABGR8888",
.format = formats::ABGR8888, .format = formats::ABGR8888,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGBA32), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGBA32),
.bitsPerPixel = 32, .bitsPerPixel = 32,
@ -190,6 +197,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::ARGB8888, { { formats::ARGB8888, {
.name = "ARGB8888",
.format = formats::ARGB8888, .format = formats::ARGB8888,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_ABGR32), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_ABGR32),
.bitsPerPixel = 32, .bitsPerPixel = 32,
@ -197,6 +205,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::BGRA8888, { { formats::BGRA8888, {
.name = "BGRA8888",
.format = formats::BGRA8888, .format = formats::BGRA8888,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_ARGB32), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_ARGB32),
.bitsPerPixel = 32, .bitsPerPixel = 32,
@ -204,6 +213,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::RGBA8888, { { formats::RGBA8888, {
.name = "RGBA8888",
.format = formats::RGBA8888, .format = formats::RGBA8888,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_BGRA32), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_BGRA32),
.bitsPerPixel = 32, .bitsPerPixel = 32,
@ -213,6 +223,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
/* YUV packed formats. */ /* YUV packed formats. */
{ formats::YUYV, { { formats::YUYV, {
.name = "YUYV",
.format = formats::YUYV, .format = formats::YUYV,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUYV), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUYV),
.bitsPerPixel = 16, .bitsPerPixel = 16,
@ -220,6 +231,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::YVYU, { { formats::YVYU, {
.name = "YVYU",
.format = formats::YVYU, .format = formats::YVYU,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YVYU), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YVYU),
.bitsPerPixel = 16, .bitsPerPixel = 16,
@ -227,6 +239,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::UYVY, { { formats::UYVY, {
.name = "UYVY",
.format = formats::UYVY, .format = formats::UYVY,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_UYVY), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_UYVY),
.bitsPerPixel = 16, .bitsPerPixel = 16,
@ -234,6 +247,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::VYUY, { { formats::VYUY, {
.name = "VYUY",
.format = formats::VYUY, .format = formats::VYUY,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_VYUY), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_VYUY),
.bitsPerPixel = 16, .bitsPerPixel = 16,
@ -243,6 +257,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
/* YUV planar formats. */ /* YUV planar formats. */
{ formats::NV16, { { formats::NV16, {
.name = "NV16",
.format = formats::NV16, .format = formats::NV16,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV16), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV16),
.bitsPerPixel = 16, .bitsPerPixel = 16,
@ -250,6 +265,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::NV61, { { formats::NV61, {
.name = "NV61",
.format = formats::NV61, .format = formats::NV61,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV61), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV61),
.bitsPerPixel = 16, .bitsPerPixel = 16,
@ -257,6 +273,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::NV12, { { formats::NV12, {
.name = "NV12",
.format = formats::NV12, .format = formats::NV12,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV12), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV12),
.bitsPerPixel = 12, .bitsPerPixel = 12,
@ -264,6 +281,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::NV21, { { formats::NV21, {
.name = "NV21",
.format = formats::NV21, .format = formats::NV21,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV21), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV21),
.bitsPerPixel = 12, .bitsPerPixel = 12,
@ -271,6 +289,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::YUV420, { { formats::YUV420, {
.name = "YUV420",
.format = PixelFormat(formats::YUV420), .format = PixelFormat(formats::YUV420),
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUV420), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUV420),
.bitsPerPixel = 12, .bitsPerPixel = 12,
@ -278,6 +297,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::YUV422, { { formats::YUV422, {
.name = "YUV422",
.format = PixelFormat(formats::YUV422), .format = PixelFormat(formats::YUV422),
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUV422P), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUV422P),
.bitsPerPixel = 16, .bitsPerPixel = 16,
@ -287,6 +307,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
/* Greyscale formats. */ /* Greyscale formats. */
{ formats::R8, { { formats::R8, {
.name = "R8",
.format = formats::R8, .format = formats::R8,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_GREY), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_GREY),
.bitsPerPixel = 8, .bitsPerPixel = 8,
@ -296,6 +317,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
/* Bayer formats. */ /* Bayer formats. */
{ formats::SBGGR8, { { formats::SBGGR8, {
.name = "SBGGR8",
.format = formats::SBGGR8, .format = formats::SBGGR8,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8),
.bitsPerPixel = 8, .bitsPerPixel = 8,
@ -303,6 +325,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::SGBRG8, { { formats::SGBRG8, {
.name = "SGBRG8",
.format = formats::SGBRG8, .format = formats::SGBRG8,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8),
.bitsPerPixel = 8, .bitsPerPixel = 8,
@ -310,6 +333,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::SGRBG8, { { formats::SGRBG8, {
.name = "SGRBG8",
.format = formats::SGRBG8, .format = formats::SGRBG8,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8),
.bitsPerPixel = 8, .bitsPerPixel = 8,
@ -317,6 +341,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::SRGGB8, { { formats::SRGGB8, {
.name = "SRGGB8",
.format = formats::SRGGB8, .format = formats::SRGGB8,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8),
.bitsPerPixel = 8, .bitsPerPixel = 8,
@ -324,6 +349,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::SBGGR10, { { formats::SBGGR10, {
.name = "SBGGR10",
.format = formats::SBGGR10, .format = formats::SBGGR10,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10),
.bitsPerPixel = 10, .bitsPerPixel = 10,
@ -331,6 +357,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::SGBRG10, { { formats::SGBRG10, {
.name = "SGBRG10",
.format = formats::SGBRG10, .format = formats::SGBRG10,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10),
.bitsPerPixel = 10, .bitsPerPixel = 10,
@ -338,6 +365,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::SGRBG10, { { formats::SGRBG10, {
.name = "SGRBG10",
.format = formats::SGRBG10, .format = formats::SGRBG10,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10),
.bitsPerPixel = 10, .bitsPerPixel = 10,
@ -345,6 +373,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::SRGGB10, { { formats::SRGGB10, {
.name = "SRGGB10",
.format = formats::SRGGB10, .format = formats::SRGGB10,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10),
.bitsPerPixel = 10, .bitsPerPixel = 10,
@ -352,6 +381,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::SBGGR10_CSI2P, { { formats::SBGGR10_CSI2P, {
.name = "SBGGR10_CSI2P",
.format = formats::SBGGR10_CSI2P, .format = formats::SBGGR10_CSI2P,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P),
.bitsPerPixel = 10, .bitsPerPixel = 10,
@ -359,6 +389,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = true, .packed = true,
} }, } },
{ formats::SGBRG10_CSI2P, { { formats::SGBRG10_CSI2P, {
.name = "SGBRG10_CSI2P",
.format = formats::SGBRG10_CSI2P, .format = formats::SGBRG10_CSI2P,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P),
.bitsPerPixel = 10, .bitsPerPixel = 10,
@ -366,6 +397,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = true, .packed = true,
} }, } },
{ formats::SGRBG10_CSI2P, { { formats::SGRBG10_CSI2P, {
.name = "SGRBG10_CSI2P",
.format = formats::SGRBG10_CSI2P, .format = formats::SGRBG10_CSI2P,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P),
.bitsPerPixel = 10, .bitsPerPixel = 10,
@ -373,6 +405,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = true, .packed = true,
} }, } },
{ formats::SRGGB10_CSI2P, { { formats::SRGGB10_CSI2P, {
.name = "SRGGB10_CSI2P",
.format = formats::SRGGB10_CSI2P, .format = formats::SRGGB10_CSI2P,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P),
.bitsPerPixel = 10, .bitsPerPixel = 10,
@ -380,6 +413,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = true, .packed = true,
} }, } },
{ formats::SBGGR12, { { formats::SBGGR12, {
.name = "SBGGR12",
.format = formats::SBGGR12, .format = formats::SBGGR12,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12),
.bitsPerPixel = 12, .bitsPerPixel = 12,
@ -387,6 +421,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::SGBRG12, { { formats::SGBRG12, {
.name = "SGBRG12",
.format = formats::SGBRG12, .format = formats::SGBRG12,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12),
.bitsPerPixel = 12, .bitsPerPixel = 12,
@ -394,6 +429,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::SGRBG12, { { formats::SGRBG12, {
.name = "SGRBG12",
.format = formats::SGRBG12, .format = formats::SGRBG12,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12),
.bitsPerPixel = 12, .bitsPerPixel = 12,
@ -401,6 +437,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::SRGGB12, { { formats::SRGGB12, {
.name = "SRGGB12",
.format = formats::SRGGB12, .format = formats::SRGGB12,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12),
.bitsPerPixel = 12, .bitsPerPixel = 12,
@ -408,6 +445,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = false, .packed = false,
} }, } },
{ formats::SBGGR12_CSI2P, { { formats::SBGGR12_CSI2P, {
.name = "SBGGR12_CSI2P",
.format = formats::SBGGR12_CSI2P, .format = formats::SBGGR12_CSI2P,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P),
.bitsPerPixel = 12, .bitsPerPixel = 12,
@ -415,6 +453,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = true, .packed = true,
} }, } },
{ formats::SGBRG12_CSI2P, { { formats::SGBRG12_CSI2P, {
.name = "SGBRG12_CSI2P",
.format = formats::SGBRG12_CSI2P, .format = formats::SGBRG12_CSI2P,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P),
.bitsPerPixel = 12, .bitsPerPixel = 12,
@ -422,6 +461,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = true, .packed = true,
} }, } },
{ formats::SGRBG12_CSI2P, { { formats::SGRBG12_CSI2P, {
.name = "SGRBG12_CSI2P",
.format = formats::SGRBG12_CSI2P, .format = formats::SGRBG12_CSI2P,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P),
.bitsPerPixel = 12, .bitsPerPixel = 12,
@ -429,6 +469,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = true, .packed = true,
} }, } },
{ formats::SRGGB12_CSI2P, { { formats::SRGGB12_CSI2P, {
.name = "SRGGB12_CSI2P",
.format = formats::SRGGB12_CSI2P, .format = formats::SRGGB12_CSI2P,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P),
.bitsPerPixel = 12, .bitsPerPixel = 12,
@ -436,6 +477,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = true, .packed = true,
} }, } },
{ formats::SBGGR10_IPU3, { { formats::SBGGR10_IPU3, {
.name = "SBGGR10_IPU3",
.format = formats::SBGGR10_IPU3, .format = formats::SBGGR10_IPU3,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10),
.bitsPerPixel = 10, .bitsPerPixel = 10,
@ -443,6 +485,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = true, .packed = true,
} }, } },
{ formats::SGBRG10_IPU3, { { formats::SGBRG10_IPU3, {
.name = "SGBRG10_IPU3",
.format = formats::SGBRG10_IPU3, .format = formats::SGBRG10_IPU3,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10),
.bitsPerPixel = 10, .bitsPerPixel = 10,
@ -450,6 +493,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = true, .packed = true,
} }, } },
{ formats::SGRBG10_IPU3, { { formats::SGRBG10_IPU3, {
.name = "SGRBG10_IPU3",
.format = formats::SGRBG10_IPU3, .format = formats::SGRBG10_IPU3,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10),
.bitsPerPixel = 10, .bitsPerPixel = 10,
@ -457,6 +501,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.packed = true, .packed = true,
} }, } },
{ formats::SRGGB10_IPU3, { { formats::SRGGB10_IPU3, {
.name = "SRGGB10_IPU3",
.format = formats::SRGGB10_IPU3, .format = formats::SRGGB10_IPU3,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10),
.bitsPerPixel = 10, .bitsPerPixel = 10,
@ -466,6 +511,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
/* Compressed formats. */ /* Compressed formats. */
{ formats::MJPEG, { { formats::MJPEG, {
.name = "MJPEG",
.format = formats::MJPEG, .format = formats::MJPEG,
.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_MJPEG), .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_MJPEG),
.bitsPerPixel = 0, .bitsPerPixel = 0,
@ -495,8 +541,8 @@ const PixelFormatInfo &PixelFormatInfo::info(const PixelFormat &format)
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 " << "Unsupported pixel format 0x"
<< format.toString(); << utils::hex(format.fourcc());
return invalid; return invalid;
} }

View file

@ -8,6 +8,8 @@
#include <libcamera/formats.h> #include <libcamera/formats.h>
#include <libcamera/pixel_format.h> #include <libcamera/pixel_format.h>
#include "libcamera/internal/formats.h"
/** /**
* \file pixel_format.h * \file pixel_format.h
* \brief libcamera pixel format * \brief libcamera pixel format
@ -104,9 +106,28 @@ bool PixelFormat::operator<(const PixelFormat &other) const
*/ */
std::string PixelFormat::toString() const std::string PixelFormat::toString() const
{ {
char str[11]; const PixelFormatInfo &info = PixelFormatInfo::info(*this);
snprintf(str, 11, "0x%08x", fourcc_);
return str; if (!info.isValid()) {
if (*this == PixelFormat())
return "<INVALID>";
char fourcc[7] = { '<',
static_cast<char>(fourcc_),
static_cast<char>(fourcc_ >> 8),
static_cast<char>(fourcc_ >> 16),
static_cast<char>(fourcc_ >> 24),
'>' };
for (unsigned int i = 1; i < 5; i++) {
if (!isprint(fourcc[i]))
fourcc[i] = '.';
}
return fourcc;
}
return info.name;
} }
} /* namespace libcamera */ } /* namespace libcamera */

View file

@ -34,6 +34,7 @@ internal_tests = [
['message', 'message.cpp'], ['message', 'message.cpp'],
['object', 'object.cpp'], ['object', 'object.cpp'],
['object-invoke', 'object-invoke.cpp'], ['object-invoke', 'object-invoke.cpp'],
['pixel-format', 'pixel-format.cpp'],
['signal-threads', 'signal-threads.cpp'], ['signal-threads', 'signal-threads.cpp'],
['threads', 'threads.cpp'], ['threads', 'threads.cpp'],
['timer', 'timer.cpp'], ['timer', 'timer.cpp'],

51
test/pixel-format.cpp Normal file
View file

@ -0,0 +1,51 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2020, Kaaira Gupta
* libcamera pixel format handling test
*/
#include <iostream>
#include <vector>
#include <libcamera/formats.h>
#include <libcamera/pixel_format.h>
#include "libcamera/internal/utils.h"
#include "test.h"
using namespace std;
using namespace libcamera;
class PixelFormatTest : public Test
{
protected:
int run()
{
std::vector<std::pair<PixelFormat, const char *>> formatsMap{
{ formats::R8, "R8" },
{ formats::SRGGB10_CSI2P, "SRGGB10_CSI2P" },
{ PixelFormat(0, 0), "<INVALID>" },
{ PixelFormat(0x20203843), "<C8 >" }
};
for (const auto &format : formatsMap) {
if ((format.first).toString() != format.second) {
cerr << "Failed to convert PixelFormat "
<< utils::hex(format.first.fourcc()) << " to string"
<< endl;
return TestFail;
}
}
if (PixelFormat().toString() != "<INVALID>") {
cerr << "Failed to convert default PixelFormat to string"
<< endl;
return TestFail;
}
return TestPass;
}
};
TEST_REGISTER(PixelFormatTest)