[{"id":4275,"web_url":"https://patchwork.libcamera.org/comment/4275/","msgid":"<20200325104435.cnnr5di4mlj7tmfg@uno.localdomain>","date":"2020-03-25T10:44:35","subject":"Re: [libcamera-devel] [RFC 3/6] [DNI] include: drm_fourcc: Add\n\tBayer FourCC and modifiers","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"HI Niklas,\n\nOn Mon, Mar 16, 2020 at 03:41:43AM +0100, Niklas Söderlund wrote:\n> Add Bayer format and modifiers for patch submitted for upstream\n> inclusion. The formats have not been accepted upstream yet so should not\n> yet be merged i libcamera.\n>\n> The formats is however needed to demonstrate RAW capture on the IPU3\n> pipeline.\n>\n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  include/linux/drm_fourcc.h | 94 ++++++++++++++++++++++++++++++++++++++\n>  1 file changed, 94 insertions(+)\n>\n> diff --git a/include/linux/drm_fourcc.h b/include/linux/drm_fourcc.h\n> index 4bb1bfe93d5f4390..69240dfe1df0df28 100644\n> --- a/include/linux/drm_fourcc.h\n> +++ b/include/linux/drm_fourcc.h\n> @@ -288,6 +288,62 @@ extern \"C\" {\n>  /* Compressed formats */\n>  #define DRM_FORMAT_MJPEG\tfourcc_code('M', 'J', 'P', 'G') /* Motion-JPEG */\n>\n> +/*\n> + * Bayer formats\n> + *\n> + * Bayer formats contain green, red and blue components, with alternating lines\n> + * of red and green, and blue and green pixels in different orders. For each\n\n\"alternating lines of red and green samples and lines of blue and green samples\"\nI would leave \"different orders\" out\n\n> + * block of 2x2 pixels there is one pixel with a red filter, two with a green\n> + * filter, and one with a blue filter. The filters can be arranged in different\n> + * patterns.\n> + *\n> + * For example, RGGB:\n> + *\trow0: RGRGRGRG...\n> + *\trow1: GBGBGBGB...\n> + *\trow3: RGRGRGRG...\n> + *\trow4: GBGBGBGB...\n> + *\t...\n> + *\n> + * Vendors have different methods to pack the sampling formats to increase data\n\ns/sampling formats/pixels samples/\n\n> + * density. For this reason the fourcc only describes pixel sample size and the\n> + * filter pattern for each block of 2x2 pixels. A modifier is needed to\n> + * describe the memory layout.\n> + *\n> + * In addition to vendor modifiers for memory layout DRM_FORMAT_MOD_LINEAR may\n> + * be used to describe a layout where all samples are placed consecutively in\n> + * memory. If the sample does not fit inside a single byte, the sample storage\n> + * is extended to the minimum number of (little endian) bytes that can hold the\n> + * sample and any unused most-significant bits are defined as padding.\n> + *\n> + * For example, SRGGB10:\n> + * Each 10-bit sample is contained in 2 consecutive little endian bytes, where\n> + * the 6 most-significant bits are unused.\n\nRepeating the same question, is it necessary to specify the bit order ?\n\n        +  -  -  -  -  -  -  -  -  +  -  -  -  -  -  -  -  -  +\n        |  b0 b1 b2 b3 b4 b5 b6 b7 | b8 b9 b10 x  x  x  x  x  |\n        +  -  -  -  -  -  -  -  -  +  -  -  -  -  -  -  -  -  +\n\n                                   vs\n\n        +  -  -  -  -  -  -  -  -  +  -  -  -  -  -  -  -  -  +\n        |  b7 b6 b5 b4 b3 b2 b1 b0 |  x  x  x b10 b9 b8 b7 b6 |\n        +  -  -  -  -  -  -  -  -  +  -  -  -  -  -  -  -  -  +\n\n                                   vs\n\n        +  -  -  -  -  -  -  -  -  +  -  -  -  -  -  -  -  -  +\n        |  b0 b1 b2 b3 b4 b5 b6 b7 |  b8 b9 b10 x x  x  x  x  |\n        +  -  -  -  -  -  -  -  -  +  -  -  -  -  -  -  -  -  +\n\n        etc\n\n\n> + */\n> +\n> +/* 8-bit Bayer formats */\n\nnit: 8-bits ?\n\n> +#define DRM_FORMAT_SRGGB8\tfourcc_code('R', 'G', 'G', 'B')\n> +#define DRM_FORMAT_SGRBG8\tfourcc_code('G', 'R', 'B', 'G')\n> +#define DRM_FORMAT_SGBRG8\tfourcc_code('G', 'B', 'R', 'G')\n> +#define DRM_FORMAT_SBGGR8\tfourcc_code('B', 'A', '8', '1')\n> +\n> +/* 10-bit Bayer formats */\n> +#define DRM_FORMAT_SRGGB10\tfourcc_code('R', 'G', '1', '0')\n> +#define DRM_FORMAT_SGRBG10\tfourcc_code('B', 'A', '1', '0')\n> +#define DRM_FORMAT_SGBRG10\tfourcc_code('G', 'B', '1', '0')\n> +#define DRM_FORMAT_SBGGR10\tfourcc_code('B', 'G', '1', '0')\n> +\n> +/* 12-bit Bayer formats */\n> +#define DRM_FORMAT_SRGGB12\tfourcc_code('R', 'G', '1', '2')\n> +#define DRM_FORMAT_SGRBG12\tfourcc_code('B', 'A', '1', '2')\n> +#define DRM_FORMAT_SGBRG12\tfourcc_code('G', 'B', '1', '2')\n> +#define DRM_FORMAT_SBGGR12\tfourcc_code('B', 'G', '1', '2')\n> +\n> +/* 14-bit Bayer formats */\n> +#define DRM_FORMAT_SRGGB14\tfourcc_code('R', 'G', '1', '4')\n> +#define DRM_FORMAT_SGRBG14\tfourcc_code('B', 'A', '1', '4')\n> +#define DRM_FORMAT_SGBRG14\tfourcc_code('G', 'B', '1', '4')\n> +#define DRM_FORMAT_SBGGR14\tfourcc_code('B', 'G', '1', '4')\n> +\n>  /*\n>   * Format Modifiers:\n>   *\n> @@ -311,6 +367,7 @@ extern \"C\" {\n>  #define DRM_FORMAT_MOD_VENDOR_BROADCOM 0x07\n>  #define DRM_FORMAT_MOD_VENDOR_ARM     0x08\n>  #define DRM_FORMAT_MOD_VENDOR_ALLWINNER 0x09\n> +#define DRM_FORMAT_MOD_VENDOR_MIPI 0x0a\n>\n>  /* add more to the end as needed */\n>\n> @@ -412,6 +469,16 @@ extern \"C\" {\n>  #define I915_FORMAT_MOD_Y_TILED_CCS\tfourcc_mod_code(INTEL, 4)\n>  #define I915_FORMAT_MOD_Yf_TILED_CCS\tfourcc_mod_code(INTEL, 5)\n>\n> +/*\n> + * IPU3 Bayer packing layout\n> + *\n> + * The IPU3 raw Bayer formats use a custom packing layout where there are no\n> + * gaps between each 10-bit sample. It packs 25 pixels into 32 bytes leaving\n> + * the 6 most significant bits in the last byte unused. The format is little\n> + * endian.\n\nHere I think it is necessary to provide a visual description of the\npacking method as it's all but trivial how color component samples are\narranged, or at least refer the readed to the V4L2 documentation of the\nV4L2_PIX_FMT_IPU3_SBGGR10 format.\n\nIf I got it right it looks like :\n\n 0                                                                                                        31\n +  -  -  -  -  -  -  -  -  +  -  -  -  -  -  -  -  -  +  -  -  -  -  -  -  -  - +  -  -  -  -  -  -  -  -  +\n | b0 b1 b2 b3 b4 b5 b6 b7  | g0 g1 g2 g3 g4 g5 b8 b9  | b0 b1 b2 b3 g6 g7 g8 g9 | g0 g1 b4 b5 b6 b7 b8 b9  |\n +  -  -  -  -  -  -  -  -  +  -  -  -  -  -  -  -  -  +  -  -  -  -  -  -  -  - +  -  -  -  -  -  -  -  -  +\n\n32                                                                                                        63\n +  -  -  -  -  -  -  -  -  +  -  -  -  -  -  -  -  -  + -  -  -  -  -  -  -  - +  -  -  -  -  -  -  -  -  +\n | g2 g3 g4 g5 g6 g7 g8 g9  | b0 b1 b2 b3 b4 b5 b6 b7 | g0 g1 g2 g3 g4 g5 b8 b9 | b0 b1 b2 b3 g6 b7 g8 g9  |\n +  -  -  -  -  -  -  -  -  +  -  -  -  -  -  -  -  -  + -  -  -  -  -  -  -  - +  -  -  -  -  -  -  -  -  +\n\nWhich expressed in bytes looks like\n\n | B0L[7:0] | G0L[7:2] B0H[1:0] | B1L[7:4] G0H[3:0] | G1L[7:5] B1H[4:0] |\n | G1H[7:0] | B2L[7:0] | G2L[7:2] B2H[1:0] | B3L[7:4] B3H[4:0] G2H[3:0] |\n\nOr, with a simpler visualization:\n\n |   B0L[7]   |   G0L[5] B0H[2]  |  B1L[3] G0H[4]  |  G1L[2] B1H[5]  |\n |   G1H[7]   |       B2L[7]     |  G2L[5] B2H[2]  |  B3L[3] G2H[4]  |\n\n\nI would like this comment to be recorded and at least discussed with\nupstream DRM if you don't agree it is necessary to provide a visual\nrepresentation.\n\n> + */\n> +#define IPU3_FORMAT_MOD_PACKED fourcc_mod_code(INTEL, 8)\n> +\n>  /*\n>   * Tiled, NV12MT, grouped in 64 (pixels) x 32 (lines) -sized macroblocks\n>   *\n> @@ -758,6 +825,33 @@ extern \"C\" {\n>   */\n>  #define DRM_FORMAT_MOD_ALLWINNER_TILED fourcc_mod_code(ALLWINNER, 1)\n>\n> +/* Mobile Industry Processor Interface (MIPI) modifiers */\n> +\n> +/*\n> + * MIPI CSI-2 packing layout\n> + *\n> + * The CSI-2 RAW formats (for example Bayer) use a different packing layout\n> + * depenindg on the sample size.\n> + *\n> + * - 10-bits per sample\n> + *   Every four consecutive samples are packed into 5 bytes. Each of the first 4\n> + *   bytes contain the 8 high order bits of the pixels, and the 5th byte\n> + *   contains the 2 least-significant bits of each pixel, in the same order.\n> + *\n> + * - 12-bits per sample\n> + *   Every two consecutive samples are packed into three bytes. Each of the\n> + *   first two bytes contain the 8 high order bits of the pixels, and the third\n> + *   byte contains the four least-significant bits of each pixel, in the same\n> + *   order.\n> + *\n> + * - 14-bits per sample\n> + *   Every four consecutive samples are packed into seven bytes. Each of the\n> + *   first four bytes contain the eight high order bits of the pixels, and the\n> + *   three following bytes contains the six least-significant bits of each\n> + *   pixel, in the same order.\n\nThis is clear enough without visualizations, and match what I can read\nout of the CSI-2 specs, where anyway the visualization really helps.\n\nIf you feel like to, as an ascii-art addicted, I would provide\ndiagrams here as well, otherwise people have to turn to the CSI-2\nspecs.\n\nThanks\n   j\n\n> + */\n> +#define MIPI_FORMAT_MOD_CSI2_PACKED fourcc_mod_code(MIPI, 1)\n> +\n>  #if defined(__cplusplus)\n>  }\n>  #endif\n> --\n> 2.25.1\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay10.mail.gandi.net (relay10.mail.gandi.net\n\t[217.70.178.230])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4A7E660412\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 25 Mar 2020 11:41:37 +0100 (CET)","from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay10.mail.gandi.net (Postfix) with ESMTPSA id 8D535240014;\n\tWed, 25 Mar 2020 10:41:36 +0000 (UTC)"],"Date":"Wed, 25 Mar 2020 11:44:35 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200325104435.cnnr5di4mlj7tmfg@uno.localdomain>","References":"<20200316024146.2474424-1-niklas.soderlund@ragnatech.se>\n\t<20200316024146.2474424-4-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200316024146.2474424-4-niklas.soderlund@ragnatech.se>","Subject":"Re: [libcamera-devel] [RFC 3/6] [DNI] include: drm_fourcc: Add\n\tBayer FourCC and modifiers","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":"Wed, 25 Mar 2020 10:41:37 -0000"}}]