From patchwork Thu Jun 22 15:00:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 18758 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id A6ABDC3237 for ; Thu, 22 Jun 2023 15:00:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E51A261E40; Thu, 22 Jun 2023 17:00:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1687446025; bh=Gt8hRRf0GwbtN9l75y8QWn9T+BUARiLInQzIIEvmLmI=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=btCe082hjvpOZ4sHQOJQFq0JePATDXIfHUm5D7099ccCPRih5GQYnaEW6SkA876Wf m2x+VtiDXfbOV7HHKrwj2oT1Ul3xrAFi6HDW9WQA/3d51DNpSDwNijQu4rdoa91Y04 b+BiR3WpbdPX4WrpAk7GJps3iSkLr9y8xuI6rZQOPNm4NVv2KdW9UDGTGv99Gerlf1 ksbGCfzVS3tX4LLBQAfMiqN/Mr0YfkqOoKglC924gTRHjrzLg0n3rhVUEqa+nlLXhf H1gF6WHcRaO41wY7dlmlBk/v6RIcxP3xgbH9cdZbEVIl1vyhesRQO4bG8Q/anSN5bl +6FTCoZWaQy7g== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 37ACD6002B for ; Thu, 22 Jun 2023 17:00:24 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ddVDverM"; dkim-atps=neutral Received: from umang.jainideasonboard.com (unknown [103.95.123.182]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8E60D4DE; Thu, 22 Jun 2023 16:59:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1687445987; bh=Gt8hRRf0GwbtN9l75y8QWn9T+BUARiLInQzIIEvmLmI=; h=From:To:Cc:Subject:Date:From; b=ddVDverMSixHgpRv3JdMBckBzP9zJOOmDjZJbgt6FEMqmn5yPkMd5Vo5DtrtKwMB1 XRqD9kXZNKUfNP1rNugBcjUaeynNNN0Ot9GbnOul5sTlEL383iOgguic/xjIaYyekU W6W43vYroLQw4c2kwYV8p7bqWPVg+LHXv9NafvBY= To: libcamera-devel@lists.libcamera.org Date: Thu, 22 Jun 2023 20:30:15 +0530 Message-Id: <20230622150015.45888-1-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3] ipa: rpi: cam_helper: PDAF support for IMX519 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-Patchwork-Original-From: Umang Jain via libcamera-devel From: Umang Jain Reply-To: Umang Jain Cc: Lee Jackson Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Lee Jackson Adds the PDAF support for IMX519 camera module by Arducam. Tested-by: Umang Jain Signed-off-by: Umang Jain Signed-off-by: Lee Jackson --- Changes in v3: - Collect author's S-o-B from v2. --- src/ipa/rpi/cam_helper/cam_helper_imx519.cpp | 50 ++++++++++++++++++++ src/ipa/rpi/vc4/data/imx519.json | 40 ++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp b/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp index c7262aa0..6d032082 100644 --- a/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp +++ b/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp @@ -15,9 +15,13 @@ #include +#include "controller/pdaf_data.h" + #include "cam_helper.h" #include "md_parser.h" +#define ALIGN_UP(x, a) (((x) + (a)-1) & ~(a - 1)) + using namespace RPiController; using namespace libcamera; using libcamera::utils::Duration; @@ -66,8 +70,13 @@ private: /* Largest long exposure scale factor given as a left shift on the frame length. */ static constexpr int longExposureShiftMax = 7; + static constexpr int pdafStatsRows = 12; + static constexpr int pdafStatsCols = 16; + void populateMetadata(const MdParser::RegisterMap ®isters, Metadata &metadata) const override; + static bool parsePdafData(const uint8_t *ptr, size_t len, unsigned bpp, + PdafRegions &pdaf); }; CamHelperImx519::CamHelperImx519() @@ -90,6 +99,11 @@ void CamHelperImx519::prepare(libcamera::Span buffer, Metadata &m MdParser::RegisterMap registers; DeviceStatus deviceStatus; + LOG(IPARPI, Debug) << "Embedded buffer size: " << buffer.size(); + + size_t bytesPerLine = (mode_.width * mode_.bitdepth) >> 3; + bytesPerLine = ALIGN_UP(bytesPerLine, 16); + if (metadata.get("device.status", deviceStatus)) { LOG(IPARPI, Error) << "DeviceStatus not found from DelayedControls"; return; @@ -97,6 +111,14 @@ void CamHelperImx519::prepare(libcamera::Span buffer, Metadata &m parseEmbeddedData(buffer, metadata); + if (buffer.size() > 2 * bytesPerLine) { + PdafRegions pdaf; + parsePdafData(&buffer[2 * bytesPerLine], + buffer.size() - 2 * bytesPerLine, + mode_.bitdepth, pdaf); + metadata.set("pdaf.data", pdaf); + } + /* * The DeviceStatus struct is first populated with values obtained from * DelayedControls. If this reports frame length is > frameLengthMax, @@ -188,6 +210,34 @@ void CamHelperImx519::populateMetadata(const MdParser::RegisterMap ®isters, metadata.set("device.status", deviceStatus); } +bool CamHelperImx519::parsePdafData(const uint8_t *ptr, size_t len, + unsigned bpp, PdafRegions &pdaf) +{ + size_t step = bpp >> 1; /* bytes per PDAF grid entry */ + + if (bpp < 10 || bpp > 12 || len < 194 * step || ptr[0] != 0 || ptr[1] >= 0x40) { + LOG(IPARPI, Error) << "PDAF data in unsupported format"; + return false; + } + + pdaf.init({ pdafStatsCols, pdafStatsRows }); + + ptr += 2 * step; + for (unsigned i = 0; i < pdafStatsRows; ++i) { + for (unsigned j = 0; j < pdafStatsCols; ++j) { + unsigned c = (ptr[0] << 3) | (ptr[1] >> 5); + int p = (((ptr[1] & 0x0F) - (ptr[1] & 0x10)) << 6) | (ptr[2] >> 2); + PdafData pdafData; + pdafData.conf = c; + pdafData.phase = c ? p : 0; + pdaf.set(libcamera::Point(j, i), { pdafData, 1, 0 }); + ptr += step; + } + } + + return true; +} + static CamHelper *create() { return new CamHelperImx519(); diff --git a/src/ipa/rpi/vc4/data/imx519.json b/src/ipa/rpi/vc4/data/imx519.json index 1b0a7747..0733d97e 100644 --- a/src/ipa/rpi/vc4/data/imx519.json +++ b/src/ipa/rpi/vc4/data/imx519.json @@ -350,6 +350,46 @@ ] } }, + { + "rpi.af": + { + "ranges": + { + "normal": + { + "min": 0.0, + "max": 12.0, + "default": 1.0 + }, + "macro": + { + "min": 3.0, + "max": 15.0, + "default": 4.0 + } + }, + "speeds": + { + "normal": + { + "step_coarse": 1.0, + "step_fine": 0.25, + "contrast_ratio": 0.75, + "pdaf_gain": -0.02, + "pdaf_squelch": 0.125, + "max_slew": 2.0, + "pdaf_frames": 20, + "dropout_frames": 6, + "step_frames": 4 + } + }, + "conf_epsilon": 8, + "conf_thresh": 16, + "conf_clip": 512, + "skip_frames": 5, + "map": [ 0.0, 0.0, 15.0, 4095 ] + } + }, { "rpi.ccm": {