{"id":4019,"url":"https://patchwork.libcamera.org/api/patches/4019/?format=json","web_url":"https://patchwork.libcamera.org/patch/4019/","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":"<20200611014536.1683233-1-niklas.soderlund@ragnatech.se>","date":"2020-06-11T01:45:36","name":"[libcamera-devel,v2] qcam: dng_writer: Add support for IPU3 Bayer formats","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"42931dde7f3e796793e25f9f09d3ce4587acc133","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/4019/mbox/","series":[{"id":988,"url":"https://patchwork.libcamera.org/api/series/988/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=988","date":"2020-06-11T01:45:36","name":"[libcamera-devel,v2] qcam: dng_writer: Add support for IPU3 Bayer formats","version":2,"mbox":"https://patchwork.libcamera.org/series/988/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/4019/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/4019/checks/","tags":{},"headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net\n\t[195.74.38.228])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2C24C600F7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 11 Jun 2020 03:45:43 +0200 (CEST)","from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de\n\t[79.202.46.202]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA\n\tid 3ccd0c61-ab85-11ea-933e-005056917a89;\n\tThu, 11 Jun 2020 03:45:36 +0200 (CEST)"],"X-Halon-ID":"3ccd0c61-ab85-11ea-933e-005056917a89","Authorized-sender":"niklas@soderlund.pp.se","From":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 11 Jun 2020 03:45:36 +0200","Message-Id":"<20200611014536.1683233-1-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.27.0","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2] qcam: dng_writer: Add support for IPU3\n\tBayer formats","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, 11 Jun 2020 01:45:43 -0000"},"content":"Add support for the Bayer formats produced on the IPU3. The format uses\na memory layout that is hard to repack and keep the 10-bit sample size,\ntherefore scale the samples to 16-bit when creating the scanlines.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/qcam/dng_writer.cpp | 121 ++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 121 insertions(+)","diff":"diff --git a/src/qcam/dng_writer.cpp b/src/qcam/dng_writer.cpp\nindex cbd8bed3e6d02269..330b169af25b7ac7 100644\n--- a/src/qcam/dng_writer.cpp\n+++ b/src/qcam/dng_writer.cpp\n@@ -82,6 +82,103 @@ void thumbScanlineSBGGRxxP(const FormatInfo &info, void *output,\n \t}\n }\n \n+void packScanlineIPU3(void *output, const void *input, unsigned int width)\n+{\n+\tconst uint8_t *in = static_cast<const uint8_t *>(input);\n+\tuint16_t *out = static_cast<uint16_t *>(output);\n+\n+\t/*\n+\t * Upscale the 10-bit format to 16-bit as it's not trivial to pack it\n+\t * as 10-bit without gaps.\n+\t *\n+\t * \\todo Improve packing to keep the 10-bit sample size.\n+\t */\n+\tunsigned int x = 0;\n+\twhile (true) {\n+\t\tfor (unsigned int i = 0; i < 6; i++) {\n+\t\t\t*out++ = (in[1] & 0x03) << 14 | (in[0] & 0xff) << 6;\n+\t\t\tif (++x >= width)\n+\t\t\t\tbreak;\n+\n+\t\t\t*out++ = (in[2] & 0x0f) << 12 | (in[1] & 0xfc) << 4;\n+\t\t\tif (++x >= width)\n+\t\t\t\tbreak;\n+\n+\t\t\t*out++ = (in[3] & 0x3f) << 10 | (in[2] & 0xf0) << 2;\n+\t\t\tif (++x >= width)\n+\t\t\t\tbreak;\n+\n+\t\t\t*out++ = (in[4] & 0xff) <<  8 | (in[3] & 0xc0) << 0;\n+\t\t\tif (++x >= width)\n+\t\t\t\tbreak;\n+\n+\t\t\tin += 5;\n+\t\t}\n+\n+\t\t*out++ = (in[1] & 0x03) << 14 | (in[0] & 0xff) << 6;\n+\t\tif (++x >= width)\n+\t\t\tbreak;\n+\n+\t\tin += 2;\n+\t}\n+}\n+\n+void thumbScanlineIPU3(const FormatInfo &info, void *output,\n+\t\t       const void *input, unsigned int width,\n+\t\t       unsigned int stride)\n+{\n+\tuint8_t *out = static_cast<uint8_t *>(output);\n+\n+\tfor (unsigned int x = 0; x < width; x++) {\n+\t\tunsigned int pixel = x * 16;\n+\t\tunsigned int block = pixel / 25;\n+\t\tunsigned int pixelInBlock = pixel - block * 25;\n+\n+\t\t/*\n+\t\t * If the pixel is the last in the block cheat a little and\n+\t\t * move one pixel backward to avoid reading between two blocks\n+\t\t * and having to deal with the padding bits.\n+\t\t */\n+\t\tif (pixelInBlock == 24)\n+\t\t\tpixelInBlock--;\n+\n+\t\tconst uint8_t *in = static_cast<const uint8_t *>(input)\n+\t\t\t+ block * 32 + (pixelInBlock / 4) * 5;\n+\n+\t\tuint16_t val1, val2, val3, val4;\n+\t\tswitch (pixelInBlock % 4) {\n+\t\tcase 0:\n+\t\t\tval1 = (in[1] & 0x03) << 14 | (in[0] & 0xff) << 6;\n+\t\t\tval2 = (in[2] & 0x0f) << 12 | (in[1] & 0xfc) << 4;\n+\t\t\tval3 = (in[stride + 1] & 0x03) << 14 | (in[stride + 0] & 0xff) << 6;\n+\t\t\tval4 = (in[stride + 2] & 0x0f) << 12 | (in[stride + 1] & 0xfc) << 4;\n+\t\t\tbreak;\n+\t\tcase 1:\n+\t\t\tval1 = (in[2] & 0x0f) << 12 | (in[1] & 0xfc) << 4;\n+\t\t\tval2 = (in[3] & 0x3f) << 10 | (in[2] & 0xf0) << 2;\n+\t\t\tval3 = (in[stride + 2] & 0x0f) << 12 | (in[stride + 1] & 0xfc) << 4;\n+\t\t\tval4 = (in[stride + 3] & 0x3f) << 10 | (in[stride + 2] & 0xf0) << 2;\n+\t\t\tbreak;\n+\t\tcase 2:\n+\t\t\tval1 = (in[3] & 0x3f) << 10 | (in[2] & 0xf0) << 2;\n+\t\t\tval2 = (in[4] & 0xff) <<  8 | (in[3] & 0xc0) << 0;\n+\t\t\tval3 = (in[stride + 3] & 0x3f) << 10 | (in[stride + 2] & 0xf0) << 2;\n+\t\t\tval4 = (in[stride + 4] & 0xff) <<  8 | (in[stride + 3] & 0xc0) << 0;\n+\t\t\tbreak;\n+\t\tcase 3:\n+\t\t\tval1 = (in[4] & 0xff) <<  8 | (in[3] & 0xc0) << 0;\n+\t\t\tval2 = (in[6] & 0x03) << 14 | (in[5] & 0xff) << 6;\n+\t\t\tval3 = (in[stride + 4] & 0xff) <<  8 | (in[stride + 3] & 0xc0) << 0;\n+\t\t\tval4 = (in[stride + 6] & 0x03) << 14 | (in[stride + 5] & 0xff) << 6;\n+\t\t}\n+\n+\t\tuint8_t value = (val1 + val2 + val3 + val4) >> 8;\n+\t\t*out++ = value;\n+\t\t*out++ = value;\n+\t\t*out++ = value;\n+\t}\n+}\n+\n static const std::map<PixelFormat, FormatInfo> formatInfo = {\n \t{ PixelFormat(DRM_FORMAT_SBGGR10, MIPI_FORMAT_MOD_CSI2_PACKED), {\n \t\t.bitsPerSample = 10,\n@@ -131,6 +228,30 @@ static const std::map<PixelFormat, FormatInfo> formatInfo = {\n \t\t.packScanline = packScanlineSBGGR12P,\n \t\t.thumbScanline = thumbScanlineSBGGRxxP,\n \t} },\n+\t{ PixelFormat(DRM_FORMAT_SBGGR10, IPU3_FORMAT_MOD_PACKED), {\n+\t\t.bitsPerSample = 16,\n+\t\t.pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed },\n+\t\t.packScanline = packScanlineIPU3,\n+\t\t.thumbScanline = thumbScanlineIPU3,\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_SGBRG10, IPU3_FORMAT_MOD_PACKED), {\n+\t\t.bitsPerSample = 16,\n+\t\t.pattern = { CFAPatternGreen, CFAPatternBlue, CFAPatternRed, CFAPatternGreen },\n+\t\t.packScanline = packScanlineIPU3,\n+\t\t.thumbScanline = thumbScanlineIPU3,\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_SGRBG10, IPU3_FORMAT_MOD_PACKED), {\n+\t\t.bitsPerSample = 16,\n+\t\t.pattern = { CFAPatternGreen, CFAPatternRed, CFAPatternBlue, CFAPatternGreen },\n+\t\t.packScanline = packScanlineIPU3,\n+\t\t.thumbScanline = thumbScanlineIPU3,\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_SRGGB10, IPU3_FORMAT_MOD_PACKED), {\n+\t\t.bitsPerSample = 16,\n+\t\t.pattern = { CFAPatternRed, CFAPatternGreen, CFAPatternGreen, CFAPatternBlue },\n+\t\t.packScanline = packScanlineIPU3,\n+\t\t.thumbScanline = thumbScanlineIPU3,\n+\t} },\n };\n \n int DNGWriter::write(const char *filename, const Camera *camera,\n","prefixes":["libcamera-devel","v2"]}