{"id":3632,"url":"https://patchwork.libcamera.org/api/patches/3632/?format=json","web_url":"https://patchwork.libcamera.org/patch/3632/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200430030723.8908-7-laurent.pinchart@ideasonboard.com>","date":"2020-04-30T03:07:23","name":"[libcamera-devel,v2,6/6] libcamera: formats: Add additional data to PixelFormatInfo","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"36feb6d4143e80efd91cd2f55c8f2875f7425df8","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/3632/mbox/","series":[{"id":858,"url":"https://patchwork.libcamera.org/api/series/858/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=858","date":"2020-04-30T03:07:17","name":"libcamera: Improve conversion between DRM and V4L2 formats","version":2,"mbox":"https://patchwork.libcamera.org/series/858/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3632/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3632/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 83D2261411\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Apr 2020 05:07:31 +0200 (CEST)","from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0C9D4503\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Apr 2020 05:07:30 +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=\"u+cZ7HEL\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1588216050;\n\tbh=NgUpLsOv+F0clvwhzzfEWbhyRn1ITcVQjxRceQC1U5s=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=u+cZ7HELZ7ygt40D7MU5D95jPEl8b1TRQqZxEUwH7XKzAd7TprGTVsMIKXMkZvs1H\n\tNcr7fF1AxlmQ72Hv8mBigMCR2ANaWGprC07+Y49xOJDqXURksnM3swBEHhp28ntVyu\n\tyXC9L93Ye7iZ0L/xjbmSCiBf3SOCge+KvcJt8bHE=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 30 Apr 2020 06:07:23 +0300","Message-Id":"<20200430030723.8908-7-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.25.3","In-Reply-To":"<20200430030723.8908-1-laurent.pinchart@ideasonboard.com>","References":"<20200430030723.8908-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 6/6] libcamera: formats: Add additional\n\tdata to PixelFormatInfo","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":"Thu, 30 Apr 2020 03:07:33 -0000"},"content":"Add three additional fields to PixelFormatInfo to report the number of\nbits per pixel, the colour encoding, and the data packing.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/formats.cpp       | 127 ++++++++++++++++++++++++++++++++\n src/libcamera/include/formats.h |   9 +++\n 2 files changed, 136 insertions(+)","diff":"diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp\nindex f6f8bc1202c2..331affe9fb25 100644\n--- a/src/libcamera/formats.cpp\n+++ b/src/libcamera/formats.cpp\n@@ -121,6 +121,45 @@ const std::map<unsigned int, std::vector<SizeRange>> &ImageFormats::data() const\n  *\n  * \\var PixelFormatInfo::v4l2Format\n  * \\brief The V4L2 pixel format corresponding to the PixelFormat\n+ *\n+ * \\var PixelFormatInfo::bitsPerPixel\n+ * \\brief The average number of bits per pixel\n+ *\n+ * The number per pixel averages the total number of bits for all colour\n+ * components over the whole image, excluding any padding bits or padding\n+ * pixels.\n+ *\n+ * For formats that store pixels with bit padding within words, only the\n+ * effective bits are taken into account. For instance, 12-bit Bayer data\n+ * stored in two bytes per pixel report 12, not 16, in this field.\n+ *\n+ * Formats that don't have a fixed number of bits per pixel, such as compressed\n+ * formats, report 0 in this field.\n+ *\n+ * \\var PixelFormatInfo::colourEncoding\n+ * \\brief The colour encoding type\n+ *\n+ * \\var PixelFormatInfo::packed\n+ * \\brief Tell if multiple pixels are packed in the same bytes\n+ *\n+ * Packed formats are defined as storing data from multiple pixels in the same\n+ * bytes. For instance, 12-bit Bayer data with two pixels stored in three bytes\n+ * is packed, while the same data stored with 4 bits of padding in two bytes\n+ * per pixel is not packed.\n+ */\n+\n+/**\n+ * \\enum PixelFormatInfo::ColourEncoding\n+ * \\brief The colour encoding type\n+ *\n+ * \\var PixelFormatInfo::ColourEncodingRGB\n+ * \\brief RGB colour encoding\n+ *\n+ * \\var PixelFormatInfo::ColourEncodingYUV\n+ * \\brief YUV colour encoding\n+ *\n+ * \\var PixelFormatInfo::ColourEncodingRAW\n+ * \\brief RAW colour encoding\n  */\n \n namespace {\n@@ -130,156 +169,244 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n \t{ PixelFormat(DRM_FORMAT_BGR888), {\n \t\t.format = PixelFormat(DRM_FORMAT_BGR888),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGB24),\n+\t\t.bitsPerPixel = 24,\n+\t\t.colourEncoding = PixelFormatInfo::ColourEncodingRGB,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_RGB888), {\n \t\t.format = PixelFormat(DRM_FORMAT_RGB888),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_BGR24),\n+\t\t.bitsPerPixel = 24,\n+\t\t.colourEncoding = PixelFormatInfo::ColourEncodingRGB,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_ABGR8888), {\n \t\t.format = PixelFormat(DRM_FORMAT_ABGR8888),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGBA32),\n+\t\t.bitsPerPixel = 32,\n+\t\t.colourEncoding = PixelFormatInfo::ColourEncodingRGB,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_ARGB8888), {\n \t\t.format = PixelFormat(DRM_FORMAT_ARGB8888),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_ABGR32),\n+\t\t.bitsPerPixel = 32,\n+\t\t.colourEncoding = PixelFormatInfo::ColourEncodingRGB,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_BGRA8888), {\n \t\t.format = PixelFormat(DRM_FORMAT_BGRA8888),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_ARGB32),\n+\t\t.bitsPerPixel = 32,\n+\t\t.colourEncoding = PixelFormatInfo::ColourEncodingRGB,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_RGBA8888), {\n \t\t.format = PixelFormat(DRM_FORMAT_RGBA8888),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_BGRA32),\n+\t\t.bitsPerPixel = 32,\n+\t\t.colourEncoding = PixelFormatInfo::ColourEncodingRGB,\n+\t\t.packed = false,\n \t} },\n \n \t/* YUV packed formats. */\n \t{ PixelFormat(DRM_FORMAT_YUYV), {\n \t\t.format = PixelFormat(DRM_FORMAT_YUYV),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUYV),\n+\t\t.bitsPerPixel = 16,\n+\t\t.colourEncoding = PixelFormatInfo::ColourEncodingYUV,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_YVYU), {\n \t\t.format = PixelFormat(DRM_FORMAT_YVYU),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YVYU),\n+\t\t.bitsPerPixel = 16,\n+\t\t.colourEncoding = PixelFormatInfo::ColourEncodingYUV,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_UYVY), {\n \t\t.format = PixelFormat(DRM_FORMAT_UYVY),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_UYVY),\n+\t\t.bitsPerPixel = 16,\n+\t\t.colourEncoding = PixelFormatInfo::ColourEncodingYUV,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_VYUY), {\n \t\t.format = PixelFormat(DRM_FORMAT_VYUY),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_VYUY),\n+\t\t.bitsPerPixel = 16,\n+\t\t.colourEncoding = PixelFormatInfo::ColourEncodingYUV,\n+\t\t.packed = false,\n \t} },\n \n \t/* YUV planar formats. */\n \t{ PixelFormat(DRM_FORMAT_NV16), {\n \t\t.format = PixelFormat(DRM_FORMAT_NV16),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV16),\n+\t\t.bitsPerPixel = 16,\n+\t\t.colourEncoding = PixelFormatInfo::ColourEncodingYUV,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_NV61), {\n \t\t.format = PixelFormat(DRM_FORMAT_NV61),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV61),\n+\t\t.bitsPerPixel = 16,\n+\t\t.colourEncoding = PixelFormatInfo::ColourEncodingYUV,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_NV12), {\n \t\t.format = PixelFormat(DRM_FORMAT_NV12),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV12),\n+\t\t.bitsPerPixel = 12,\n+\t\t.colourEncoding = PixelFormatInfo::ColourEncodingYUV,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_NV21), {\n \t\t.format = PixelFormat(DRM_FORMAT_NV21),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV21),\n+\t\t.bitsPerPixel = 12,\n+\t\t.colourEncoding = PixelFormatInfo::ColourEncodingYUV,\n+\t\t.packed = false,\n \t} },\n \n \t/* Greyscale formats. */\n \t{ PixelFormat(DRM_FORMAT_R8), {\n \t\t.format = PixelFormat(DRM_FORMAT_R8),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_GREY),\n+\t\t.bitsPerPixel = 8,\n+\t\t.colourEncoding = PixelFormatInfo::ColourEncodingYUV,\n+\t\t.packed = false,\n \t} },\n \n \t/* Bayer formats. */\n \t{ PixelFormat(DRM_FORMAT_SBGGR8), {\n \t\t.format = PixelFormat(DRM_FORMAT_SBGGR8),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8),\n+\t\t.bitsPerPixel = 8,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_SGBRG8), {\n \t\t.format = PixelFormat(DRM_FORMAT_SGBRG8),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8),\n+\t\t.bitsPerPixel = 8,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_SGRBG8), {\n \t\t.format = PixelFormat(DRM_FORMAT_SGRBG8),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8),\n+\t\t.bitsPerPixel = 8,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_SRGGB8), {\n \t\t.format = PixelFormat(DRM_FORMAT_SRGGB8),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8),\n+\t\t.bitsPerPixel = 8,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_SBGGR10), {\n \t\t.format = PixelFormat(DRM_FORMAT_SBGGR10),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10),\n+\t\t.bitsPerPixel = 10,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_SGBRG10), {\n \t\t.format = PixelFormat(DRM_FORMAT_SGBRG10),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10),\n+\t\t.bitsPerPixel = 10,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_SGRBG10), {\n \t\t.format = PixelFormat(DRM_FORMAT_SGRBG10),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10),\n+\t\t.bitsPerPixel = 10,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_SRGGB10), {\n \t\t.format = PixelFormat(DRM_FORMAT_SRGGB10),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10),\n+\t\t.bitsPerPixel = 10,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_SBGGR10, MIPI_FORMAT_MOD_CSI2_PACKED), {\n \t\t.format = PixelFormat(DRM_FORMAT_SBGGR10, MIPI_FORMAT_MOD_CSI2_PACKED),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P),\n+\t\t.bitsPerPixel = 10,\n+\t\t.packed = true,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_SGBRG10, MIPI_FORMAT_MOD_CSI2_PACKED), {\n \t\t.format = PixelFormat(DRM_FORMAT_SGBRG10, MIPI_FORMAT_MOD_CSI2_PACKED),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P),\n+\t\t.bitsPerPixel = 10,\n+\t\t.packed = true,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_SGRBG10, MIPI_FORMAT_MOD_CSI2_PACKED), {\n \t\t.format = PixelFormat(DRM_FORMAT_SGRBG10, MIPI_FORMAT_MOD_CSI2_PACKED),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P),\n+\t\t.bitsPerPixel = 10,\n+\t\t.packed = true,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_SRGGB10, MIPI_FORMAT_MOD_CSI2_PACKED), {\n \t\t.format = PixelFormat(DRM_FORMAT_SRGGB10, MIPI_FORMAT_MOD_CSI2_PACKED),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P),\n+\t\t.bitsPerPixel = 10,\n+\t\t.packed = true,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_SBGGR12), {\n \t\t.format = PixelFormat(DRM_FORMAT_SBGGR12),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12),\n+\t\t.bitsPerPixel = 12,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_SGBRG12), {\n \t\t.format = PixelFormat(DRM_FORMAT_SGBRG12),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12),\n+\t\t.bitsPerPixel = 12,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_SGRBG12), {\n \t\t.format = PixelFormat(DRM_FORMAT_SGRBG12),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12),\n+\t\t.bitsPerPixel = 12,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_SRGGB12), {\n \t\t.format = PixelFormat(DRM_FORMAT_SRGGB12),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12),\n+\t\t.bitsPerPixel = 12,\n+\t\t.packed = false,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_SBGGR12, MIPI_FORMAT_MOD_CSI2_PACKED), {\n \t\t.format = PixelFormat(DRM_FORMAT_SBGGR12, MIPI_FORMAT_MOD_CSI2_PACKED),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P),\n+\t\t.bitsPerPixel = 12,\n+\t\t.packed = true,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_SGBRG12, MIPI_FORMAT_MOD_CSI2_PACKED), {\n \t\t.format = PixelFormat(DRM_FORMAT_SGBRG12, MIPI_FORMAT_MOD_CSI2_PACKED),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P),\n+\t\t.bitsPerPixel = 12,\n+\t\t.packed = true,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_SGRBG12, MIPI_FORMAT_MOD_CSI2_PACKED), {\n \t\t.format = PixelFormat(DRM_FORMAT_SGRBG12, MIPI_FORMAT_MOD_CSI2_PACKED),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P),\n+\t\t.bitsPerPixel = 12,\n+\t\t.packed = true,\n \t} },\n \t{ PixelFormat(DRM_FORMAT_SRGGB12, MIPI_FORMAT_MOD_CSI2_PACKED), {\n \t\t.format = PixelFormat(DRM_FORMAT_SRGGB12, MIPI_FORMAT_MOD_CSI2_PACKED),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P),\n+\t\t.bitsPerPixel = 12,\n+\t\t.packed = true,\n \t} },\n \n \t/* Compressed formats. */\n \t{ PixelFormat(DRM_FORMAT_MJPEG), {\n \t\t.format = PixelFormat(DRM_FORMAT_MJPEG),\n \t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_MJPEG),\n+\t\t.bitsPerPixel = 0,\n+\t\t.colourEncoding = PixelFormatInfo::ColourEncodingYUV,\n+\t\t.packed = false,\n \t} },\n };\n \ndiff --git a/src/libcamera/include/formats.h b/src/libcamera/include/formats.h\nindex 560df07c4451..291a1108aa33 100644\n--- a/src/libcamera/include/formats.h\n+++ b/src/libcamera/include/formats.h\n@@ -35,6 +35,12 @@ private:\n class PixelFormatInfo\n {\n public:\n+\tenum ColourEncoding {\n+\t\tColourEncodingRGB,\n+\t\tColourEncodingYUV,\n+\t\tColourEncodingRAW,\n+\t};\n+\n \tbool isValid() const { return format.isValid(); }\n \n \tstatic const PixelFormatInfo &info(const PixelFormat &format);\n@@ -42,6 +48,9 @@ public:\n \t/* \\todo Add support for non-contiguous memory planes */\n \tPixelFormat format;\n \tV4L2PixelFormat v4l2Format;\n+\tunsigned int bitsPerPixel;\n+\tenum ColourEncoding colourEncoding;\n+\tbool packed;\n };\n \n } /* namespace libcamera */\n","prefixes":["libcamera-devel","v2","6/6"]}