{"id":4032,"url":"https://patchwork.libcamera.org/api/1.1/patches/4032/?format=json","web_url":"https://patchwork.libcamera.org/patch/4032/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20200611183956.92926-1-niklas.soderlund@ragnatech.se>","date":"2020-06-11T18:39:56","name":"[libcamera-devel,v3] qcam: dng_writer: Add support for IPU3 Bayer formats","commit_ref":"5a3cfc33db235dd33aa7bdee02390a9e74437108","pull_url":null,"state":"accepted","archived":false,"hash":"66477785832dcb3b14f1e083a99031c18d1a0641","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/1.1/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/4032/mbox/","series":[{"id":995,"url":"https://patchwork.libcamera.org/api/1.1/series/995/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=995","date":"2020-06-11T18:39:56","name":"[libcamera-devel,v3] qcam: dng_writer: Add support for IPU3 Bayer formats","version":3,"mbox":"https://patchwork.libcamera.org/series/995/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/4032/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/4032/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 CE09561027\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 11 Jun 2020 20:40:01 +0200 (CEST)","from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de\n\t[79.202.46.202]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA\n\tid ec76285f-ac12-11ea-86ee-0050569116f7;\n\tThu, 11 Jun 2020 20:39:48 +0200 (CEST)"],"X-Halon-ID":"ec76285f-ac12-11ea-86ee-0050569116f7","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 20:39:56 +0200","Message-Id":"<20200611183956.92926-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 v3] 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 18:40:02 -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>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n* Changes since v2\n- Use return instead of break in packScanlineIPU3()\n- Shift 10 instead of 8 in thumbScanlineIPU3()\n- Fixup style.\n---\n src/qcam/dng_writer.cpp | 122 ++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 122 insertions(+)","diff":"diff --git a/src/qcam/dng_writer.cpp b/src/qcam/dng_writer.cpp\nindex cbd8bed3e6d02269..8470908816e3e408 100644\n--- a/src/qcam/dng_writer.cpp\n+++ b/src/qcam/dng_writer.cpp\n@@ -82,6 +82,104 @@ 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\treturn;\n+\n+\t\t\t*out++ = (in[2] & 0x0f) << 12 | (in[1] & 0xfc) << 4;\n+\t\t\tif (++x >= width)\n+\t\t\t\treturn;\n+\n+\t\t\t*out++ = (in[3] & 0x3f) << 10 | (in[2] & 0xf0) << 2;\n+\t\t\tif (++x >= width)\n+\t\t\t\treturn;\n+\n+\t\t\t*out++ = (in[4] & 0xff) <<  8 | (in[3] & 0xc0) << 0;\n+\t\t\tif (++x >= width)\n+\t\t\t\treturn;\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\treturn;\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\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\tbreak;\n+\t\t}\n+\n+\t\tuint8_t value = (val1 + val2 + val3 + val4) >> 10;\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 +229,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","v3"]}