From patchwork Sun May 3 00:27:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 3678 Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E7130603F4 for ; Sun, 3 May 2020 02:27:59 +0200 (CEST) X-Halon-ID: ed441b3d-8cd4-11ea-89d0-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2392.dip0.t-ipconnect.de [79.202.35.146]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id ed441b3d-8cd4-11ea-89d0-0050569116f7; Sun, 03 May 2020 02:27:55 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sun, 3 May 2020 02:27:55 +0200 Message-Id: <20200503002755.1367555-1-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] qcam: dng_writer: Add support for IPU3 Bayer formats X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 May 2020 00:28:00 -0000 Add support for the Bayer formats produced on the IPU3. The format uses a memory layout that is hard to repack and keep the 10-bit sample size, therefore scale the samples to 16-bit when creating the scanlines. Signed-off-by: Niklas Söderlund --- src/qcam/dng_writer.cpp | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/qcam/dng_writer.cpp b/src/qcam/dng_writer.cpp index f0d6f5f473e3d680..7ad52592d4449929 100644 --- a/src/qcam/dng_writer.cpp +++ b/src/qcam/dng_writer.cpp @@ -56,6 +56,31 @@ void packScanlineSBGGR12P(void *output, const void *input, unsigned int width) } } +void packScanlineIPU3(void *output, const void *input, unsigned int width) +{ + const uint8_t *in = static_cast(input); + uint16_t *out = static_cast(output); + + /* + * Upsacle the 10-bit format to 16-bit as it's none trivial to pack it + * it as 10-bits without gaps. + * + * \todo Improve packig to keep the 10-bit sample size. + */ + for (unsigned int x = 0; x < width; x += 25) { + for (unsigned int i = 0; i < 6; i++) { + *out++ = ((in[1] & 0x02) << 8 | in[0]) << 6; + *out++ = ((in[2] & 0x0f) << 6 | in[1] >> 2) << 6; + *out++ = ((in[3] & 0x3f) << 4 | in[2] >> 4) << 6; + *out++ = ((in[4] & 0xff) << 2 | in[3] >> 6) << 6; + in += 5; + } + + *out++ = ((in[1] & 0x02) << 8 | in[0]) << 6; + in += 2; + } +} + static const std::map formatInfo = { { PixelFormat(DRM_FORMAT_SBGGR10, MIPI_FORMAT_MOD_CSI2_PACKED), { .bitsPerSample = 10, @@ -97,6 +122,26 @@ static const std::map formatInfo = { .pattern = { CFAPatternRed, CFAPatternGreen, CFAPatternGreen, CFAPatternBlue }, .packScanline = packScanlineSBGGR12P, } }, + { PixelFormat(DRM_FORMAT_SBGGR10, IPU3_FORMAT_MOD_PACKED), { + .bitsPerSample = 16, + .pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed }, + .packScanline = packScanlineIPU3, + } }, + { PixelFormat(DRM_FORMAT_SGBRG10, IPU3_FORMAT_MOD_PACKED), { + .bitsPerSample = 16, + .pattern = { CFAPatternGreen, CFAPatternBlue, CFAPatternRed, CFAPatternGreen }, + .packScanline = packScanlineIPU3, + } }, + { PixelFormat(DRM_FORMAT_SGRBG10, IPU3_FORMAT_MOD_PACKED), { + .bitsPerSample = 16, + .pattern = { CFAPatternGreen, CFAPatternRed, CFAPatternBlue, CFAPatternGreen }, + .packScanline = packScanlineIPU3, + } }, + { PixelFormat(DRM_FORMAT_SRGGB10, IPU3_FORMAT_MOD_PACKED), { + .bitsPerSample = 16, + .pattern = { CFAPatternRed, CFAPatternGreen, CFAPatternGreen, CFAPatternBlue }, + .packScanline = packScanlineIPU3, + } }, }; int DNGWriter::write(const char *filename, const Camera *camera,