[{"id":5337,"web_url":"https://patchwork.libcamera.org/comment/5337/","msgid":"<20200622234000.GM5852@pendragon.ideasonboard.com>","date":"2020-06-22T23:40:00","subject":"Re: [libcamera-devel] [PATCH v6] libcamera:PixelFormat: Replace hex\n\twith format names","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kaaira,\n\nThank you for the patch.\n\nOne small comment, the subject line should be\n\nlibcamera: pixel_format: Replace hex with format names\n\n(space after libcamera:, and following the convention to use file names\ninstead of classes).\n\nOn Mon, Jun 22, 2020 at 04:33:51PM +0530, Kaaira Gupta wrote:\n> Print format names defined in formats namespace instead of the hex\n> values in toString() as they are easier to comprehend. For this add\n> a property of 'name' in PixelFormatInfo' so as to map the formats\n> with their names. Print fourcc for formats which are not used in\n> libcamera.\n> \n> Signed-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n> Resending due to typo in mailing list address.\n> \n> Changes since v5:\n> \t- formatting changes.\n> \t- based on top of [PATCH v2] libcamera: add support\n> \t for planar YUV422 and YUV420 formats\n\nI was ready to have to fix this, and to my surprise the compiler didn't\ncomplain. Very good initiative :-)\n\n> Changes since v4:\n>         -Print libcamera defined names instead of fourcc.\n> \n> Changes since v3:\n>         -shortened the texts.\n>         -Removed default case as well.\n>         -changed commit message and tests to reflect the changes.\n> \n> Changes since v2:\n>         - Remove description for all vendors except for MIPI\n>         - Change commit message to reflect this change.\n>         - Change tests accordingly.\n> \n> Changes since v1:\n>         - Replaced magic numbers with expressive values.\n>         - Re-wrote ARM vendor's modifiers\n>         - Re-wrote the vendors' map with a macro.\n>         - Changed the copyrights in test file.\n>         - Changed the tests.\n> \n>  include/libcamera/internal/formats.h |  1 +\n>  src/libcamera/formats.cpp            | 42 +++++++++++++++++++++--\n>  src/libcamera/pixel_format.cpp       | 27 +++++++++++++--\n>  test/meson.build                     |  1 +\n>  test/pixel-format.cpp                | 51 ++++++++++++++++++++++++++++\n>  5 files changed, 117 insertions(+), 5 deletions(-)\n>  create mode 100644 test/pixel-format.cpp\n> \n> diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h\n> index 4b172ef..f59ac8f 100644\n> --- a/include/libcamera/internal/formats.h\n> +++ b/include/libcamera/internal/formats.h\n> @@ -46,6 +46,7 @@ public:\n>  \tstatic const PixelFormatInfo &info(const PixelFormat &format);\n>  \n>  \t/* \\todo Add support for non-contiguous memory planes */\n> +\tconst char *name;\n\nThis field isn't documented. Hasn't doxygen warned you ?\n\nI've added\n\n * \\var PixelFormatInfo::name\n * \\brief The format name as a human-readable string, used as the test\n * representation of the PixelFormat\n\nI'll push the patch tomorrow with those small changes unless someone has\nfurther comments.\n\n>  \tPixelFormat format;\n>  \tV4L2PixelFormat v4l2Format;\n>  \tunsigned int bitsPerPixel;\n> diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp\n> index c0b53ce..9de1434 100644\n> --- a/src/libcamera/formats.cpp\n> +++ b/src/libcamera/formats.cpp\n> @@ -169,6 +169,7 @@ namespace {\n>  const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t/* RGB formats. */\n>  \t{ formats::BGR888, {\n> +\t\t.name = \"BGR888\",\n>  \t\t.format = formats::BGR888,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGB24),\n>  \t\t.bitsPerPixel = 24,\n> @@ -176,6 +177,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::RGB888, {\n> +\t\t.name = \"RGB888\",\n>  \t\t.format = formats::RGB888,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_BGR24),\n>  \t\t.bitsPerPixel = 24,\n> @@ -183,6 +185,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::ABGR8888, {\n> +\t\t.name = \"ABGR8888\",\n>  \t\t.format = formats::ABGR8888,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGBA32),\n>  \t\t.bitsPerPixel = 32,\n> @@ -190,6 +193,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::ARGB8888, {\n> +\t\t.name = \"ARGB8888\",\n>  \t\t.format = formats::ARGB8888,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_ABGR32),\n>  \t\t.bitsPerPixel = 32,\n> @@ -197,6 +201,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::BGRA8888, {\n> +\t\t.name = \"BGRA8888\",\n>  \t\t.format = formats::BGRA8888,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_ARGB32),\n>  \t\t.bitsPerPixel = 32,\n> @@ -204,6 +209,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::RGBA8888, {\n> +\t\t.name = \"RGBA8888\",\n>  \t\t.format = formats::RGBA8888,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_BGRA32),\n>  \t\t.bitsPerPixel = 32,\n> @@ -213,6 +219,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \n>  \t/* YUV packed formats. */\n>  \t{ formats::YUYV, {\n> +\t\t.name = \"YUYV\",\n>  \t\t.format = formats::YUYV,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUYV),\n>  \t\t.bitsPerPixel = 16,\n> @@ -220,6 +227,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::YVYU, {\n> +\t\t.name = \"YVYU\",\n>  \t\t.format = formats::YVYU,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YVYU),\n>  \t\t.bitsPerPixel = 16,\n> @@ -227,6 +235,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::UYVY, {\n> +\t\t.name = \"UYVY\",\n>  \t\t.format = formats::UYVY,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_UYVY),\n>  \t\t.bitsPerPixel = 16,\n> @@ -234,6 +243,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::VYUY, {\n> +\t\t.name = \"VYUY\",\n>  \t\t.format = formats::VYUY,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_VYUY),\n>  \t\t.bitsPerPixel = 16,\n> @@ -243,6 +253,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \n>  \t/* YUV planar formats. */\n>  \t{ formats::NV16, {\n> +\t\t.name = \"NV16\",\n>  \t\t.format = formats::NV16,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV16),\n>  \t\t.bitsPerPixel = 16,\n> @@ -250,6 +261,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::NV61, {\n> +\t\t.name = \"NV61\",\n>  \t\t.format = formats::NV61,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV61),\n>  \t\t.bitsPerPixel = 16,\n> @@ -257,6 +269,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::NV12, {\n> +\t\t.name = \"NV12\",\n>  \t\t.format = formats::NV12,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV12),\n>  \t\t.bitsPerPixel = 12,\n> @@ -264,6 +277,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::NV21, {\n> +\t\t.name = \"NV21\",\n>  \t\t.format = formats::NV21,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV21),\n>  \t\t.bitsPerPixel = 12,\n> @@ -271,6 +285,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::YUV420, {\n> +\t\t.name = \"YUV420\",\n>  \t\t.format = PixelFormat(formats::YUV420),\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUV420),\n>  \t\t.bitsPerPixel = 12,\n> @@ -278,6 +293,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::YUV422, {\n> +\t\t.name = \"YUV422\",\n>  \t\t.format = PixelFormat(formats::YUV422),\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUV422P),\n>  \t\t.bitsPerPixel = 16,\n> @@ -287,6 +303,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \n>  \t/* Greyscale formats. */\n>  \t{ formats::R8, {\n> +\t\t.name = \"R8\",\n>  \t\t.format = formats::R8,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_GREY),\n>  \t\t.bitsPerPixel = 8,\n> @@ -296,6 +313,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \n>  \t/* Bayer formats. */\n>  \t{ formats::SBGGR8, {\n> +\t\t.name = \"SBGGR8\",\n>  \t\t.format = formats::SBGGR8,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8),\n>  \t\t.bitsPerPixel = 8,\n> @@ -303,6 +321,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::SGBRG8, {\n> +\t\t.name = \"SGBRG8\",\n>  \t\t.format = formats::SGBRG8,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8),\n>  \t\t.bitsPerPixel = 8,\n> @@ -310,6 +329,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::SGRBG8, {\n> +\t\t.name = \"SGRBG8\",\n>  \t\t.format = formats::SGRBG8,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8),\n>  \t\t.bitsPerPixel = 8,\n> @@ -317,6 +337,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::SRGGB8, {\n> +\t\t.name = \"SRGGB8\",\n>  \t\t.format = formats::SRGGB8,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8),\n>  \t\t.bitsPerPixel = 8,\n> @@ -324,6 +345,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::SBGGR10, {\n> +\t\t.name = \"SBGGR10\",\n>  \t\t.format = formats::SBGGR10,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10),\n>  \t\t.bitsPerPixel = 10,\n> @@ -331,6 +353,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::SGBRG10, {\n> +\t\t.name = \"SGBRG10\",\n>  \t\t.format = formats::SGBRG10,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10),\n>  \t\t.bitsPerPixel = 10,\n> @@ -338,6 +361,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::SGRBG10, {\n> +\t\t.name = \"SGRBG10\",\n>  \t\t.format = formats::SGRBG10,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10),\n>  \t\t.bitsPerPixel = 10,\n> @@ -345,6 +369,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::SRGGB10, {\n> +\t\t.name = \"SRGGB10\",\n>  \t\t.format = formats::SRGGB10,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10),\n>  \t\t.bitsPerPixel = 10,\n> @@ -352,6 +377,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::SBGGR10_CSI2P, {\n> +\t\t.name = \"SBGGR10_CSI2P\",\n>  \t\t.format = formats::SBGGR10_CSI2P,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P),\n>  \t\t.bitsPerPixel = 10,\n> @@ -359,6 +385,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = true,\n>  \t} },\n>  \t{ formats::SGBRG10_CSI2P, {\n> +\t\t.name = \"SGBRG10_CSI2P\",\n>  \t\t.format = formats::SGBRG10_CSI2P,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P),\n>  \t\t.bitsPerPixel = 10,\n> @@ -366,6 +393,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = true,\n>  \t} },\n>  \t{ formats::SGRBG10_CSI2P, {\n> +\t\t.name = \"SGRBG10_CSI2P\",\n>  \t\t.format = formats::SGRBG10_CSI2P,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P),\n>  \t\t.bitsPerPixel = 10,\n> @@ -373,6 +401,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = true,\n>  \t} },\n>  \t{ formats::SRGGB10_CSI2P, {\n> +\t\t.name = \"SRGGB10_CSI2P\",\n>  \t\t.format = formats::SRGGB10_CSI2P,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P),\n>  \t\t.bitsPerPixel = 10,\n> @@ -380,6 +409,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = true,\n>  \t} },\n>  \t{ formats::SBGGR12, {\n> +\t\t.name = \"SBGGR12\",\n>  \t\t.format = formats::SBGGR12,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12),\n>  \t\t.bitsPerPixel = 12,\n> @@ -387,6 +417,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::SGBRG12, {\n> +\t\t.name = \"SGBRG12\",\n>  \t\t.format = formats::SGBRG12,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12),\n>  \t\t.bitsPerPixel = 12,\n> @@ -394,6 +425,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::SGRBG12, {\n> +\t\t.name = \"SGRBG12\",\n>  \t\t.format = formats::SGRBG12,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12),\n>  \t\t.bitsPerPixel = 12,\n> @@ -401,6 +433,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::SRGGB12, {\n> +\t\t.name = \"SRGGB12\",\n>  \t\t.format = formats::SRGGB12,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12),\n>  \t\t.bitsPerPixel = 12,\n> @@ -408,6 +441,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = false,\n>  \t} },\n>  \t{ formats::SBGGR12_CSI2P, {\n> +\t\t.name = \"SBGGR12_CSI2P\",\n>  \t\t.format = formats::SBGGR12_CSI2P,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P),\n>  \t\t.bitsPerPixel = 12,\n> @@ -415,6 +449,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = true,\n>  \t} },\n>  \t{ formats::SGBRG12_CSI2P, {\n> +\t\t.name = \"SGBRG12_CSI2P\",\n>  \t\t.format = formats::SGBRG12_CSI2P,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P),\n>  \t\t.bitsPerPixel = 12,\n> @@ -422,6 +457,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = true,\n>  \t} },\n>  \t{ formats::SGRBG12_CSI2P, {\n> +\t\t.name = \"SGRBG12_CSI2P\",\n>  \t\t.format = formats::SGRBG12_CSI2P,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P),\n>  \t\t.bitsPerPixel = 12,\n> @@ -429,6 +465,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \t\t.packed = true,\n>  \t} },\n>  \t{ formats::SRGGB12_CSI2P, {\n> +\t\t.name = \"SRGGB12_CSI2P\",\n>  \t\t.format = formats::SRGGB12_CSI2P,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P),\n>  \t\t.bitsPerPixel = 12,\n> @@ -438,6 +475,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n>  \n>  \t/* Compressed formats. */\n>  \t{ formats::MJPEG, {\n> +\t\t.name = \"MJPEG\",\n>  \t\t.format = formats::MJPEG,\n>  \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_MJPEG),\n>  \t\t.bitsPerPixel = 0,\n> @@ -467,8 +505,8 @@ const PixelFormatInfo &PixelFormatInfo::info(const PixelFormat &format)\n>  \tconst auto iter = pixelFormatInfo.find(format);\n>  \tif (iter == pixelFormatInfo.end()) {\n>  \t\tLOG(Formats, Warning)\n> -\t\t\t<< \"Unsupported pixel format \"\n> -\t\t\t<< format.toString();\n> +\t\t\t<< \"Unsupported pixel format 0x\"\n> +\t\t\t<< utils::hex(format.fourcc());\n>  \t\treturn invalid;\n>  \t}\n>  \n> diff --git a/src/libcamera/pixel_format.cpp b/src/libcamera/pixel_format.cpp\n> index f191851..14addb5 100644\n> --- a/src/libcamera/pixel_format.cpp\n> +++ b/src/libcamera/pixel_format.cpp\n> @@ -8,6 +8,8 @@\n>  #include <libcamera/formats.h>\n>  #include <libcamera/pixel_format.h>\n>  \n> +#include \"libcamera/internal/formats.h\"\n> +\n>  /**\n>   * \\file pixel_format.h\n>   * \\brief libcamera pixel format\n> @@ -104,9 +106,28 @@ bool PixelFormat::operator<(const PixelFormat &other) const\n>   */\n>  std::string PixelFormat::toString() const\n>  {\n> -\tchar str[11];\n> -\tsnprintf(str, 11, \"0x%08x\", fourcc_);\n> -\treturn str;\n> +\tconst PixelFormatInfo &info = PixelFormatInfo::info(*this);\n> +\n> +\tif (!info.isValid()) {\n> +\t\tif (*this == PixelFormat())\n> +\t\t\treturn \"<INVALID>\";\n> +\n> +\t\tchar fourcc[7] = { '<',\n> +\t\t\t\t   static_cast<char>(fourcc_),\n> +\t\t\t\t   static_cast<char>(fourcc_ >> 8),\n> +\t\t\t\t   static_cast<char>(fourcc_ >> 16),\n> +\t\t\t\t   static_cast<char>(fourcc_ >> 24),\n> +\t\t\t\t   '>' };\n> +\n> +\t\tfor (unsigned int i = 1; i < 5; i++) {\n> +\t\t\tif (!isprint(fourcc[i]))\n> +\t\t\t\tfourcc[i] = '.';\n> +\t\t}\n> +\n> +\t\treturn fourcc;\n> +\t}\n> +\n> +\treturn info.name;\n>  }\n>  \n>  } /* namespace libcamera */\n> diff --git a/test/meson.build b/test/meson.build\n> index a868813..7808a26 100644\n> --- a/test/meson.build\n> +++ b/test/meson.build\n> @@ -34,6 +34,7 @@ internal_tests = [\n>      ['message',                         'message.cpp'],\n>      ['object',                          'object.cpp'],\n>      ['object-invoke',                   'object-invoke.cpp'],\n> +    ['pixel-format',                    'pixel-format.cpp'],\n>      ['signal-threads',                  'signal-threads.cpp'],\n>      ['threads',                         'threads.cpp'],\n>      ['timer',                           'timer.cpp'],\n> diff --git a/test/pixel-format.cpp b/test/pixel-format.cpp\n> new file mode 100644\n> index 0000000..c4a08f4\n> --- /dev/null\n> +++ b/test/pixel-format.cpp\n> @@ -0,0 +1,51 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2020, Kaaira Gupta\n> + * libcamera pixel format handling test\n> + */\n> +\n> +#include <iostream>\n> +#include <vector>\n> +\n> +#include <libcamera/formats.h>\n> +#include <libcamera/pixel_format.h>\n> +\n> +#include \"libcamera/internal/utils.h\"\n> +\n> +#include \"test.h\"\n> +\n> +using namespace std;\n> +using namespace libcamera;\n> +\n> +class PixelFormatTest : public Test\n> +{\n> +protected:\n> +\tint run()\n> +\t{\n> +\t\tstd::vector<std::pair<PixelFormat, const char *>> formatsMap{\n> +\t\t\t{ formats::R8, \"R8\" },\n> +\t\t\t{ formats::SRGGB10_CSI2P, \"SRGGB10_CSI2P\" },\n> +\t\t\t{ PixelFormat(0, 0), \"<INVALID>\" },\n> +\t\t\t{ PixelFormat(0x20203843), \"<C8  >\" }\n> +\t\t};\n> +\n> +\t\tfor (const auto &format : formatsMap) {\n> +\t\t\tif ((format.first).toString() != format.second) {\n> +\t\t\t\tcerr << \"Failed to convert PixelFormat \"\n> +\t\t\t\t     << utils::hex(format.first.fourcc()) << \" to string\"\n> +\t\t\t\t     << endl;\n> +\t\t\t\treturn TestFail;\n> +\t\t\t}\n> +\t\t}\n> +\n> +\t\tif (PixelFormat().toString() != \"<INVALID>\") {\n> +\t\t\tcerr << \"Failed to convert default PixelFormat to string\"\n> +\t\t\t     << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +};\n> +\n> +TEST_REGISTER(PixelFormatTest)","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E4CC4603BE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 23 Jun 2020 01:40:25 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 51880327;\n\tTue, 23 Jun 2020 01:40:25 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"G997DXhi\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1592869225;\n\tbh=5QBYieN0vnhSL/2ptt5i7+znoi7Y1AD1NtTnQrIpsbk=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=G997DXhidKrmv/HCXb/yZfYuhd/4SPZaH383VcjkbL2ck54QoYmRBGUwGFK+Byhag\n\tSQh/GhALN18xMBxKDTxV6LWx7IlrjXWzPbX7Yhi4q2QEYf1Hbgy3LNdaIxRSTbMqLG\n\tJhyGyXasOARE2YJHHlCx3G+p+xPtzwCJfAcmSrq8=","Date":"Tue, 23 Jun 2020 02:40:00 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kaaira Gupta <kgupta@es.iitr.ac.in>","Cc":"libcamera-devel@lists.libcamera.org,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<20200622234000.GM5852@pendragon.ideasonboard.com>","References":"<20200622110351.GA14836@kaaira-HP-Pavilion-Notebook>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200622110351.GA14836@kaaira-HP-Pavilion-Notebook>","Subject":"Re: [libcamera-devel] [PATCH v6] libcamera:PixelFormat: Replace hex\n\twith format names","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Mon, 22 Jun 2020 23:40:26 -0000"}}]