From patchwork Fri Jun 30 12:03:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 18771 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 4B95ABE175 for ; Fri, 30 Jun 2023 12:03:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0F294628C5; Fri, 30 Jun 2023 14:03:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1688126593; bh=vQpye2Y9OwiLOppoOXQEwyz1zqAHufpJ5KTWofakVN0=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=p5AsvjIPFEAoXECJLb0ySAof9lUp0rLi4ySAB/6PZQR6ovNUj1qCw18SyEHjuVrz+ qc+NZjanE+rvv5ZiwlfZO3fteQSxmjecawj6A5Uc/CmA8iwr+y2QKAaaNtM5dVd1op jsHsHYauYzoUI3Z7O531c3l0pPKIEfv17XuPQimznL8Qa7l/oE8p2qe7nUoWtozOlm OySbWiGa7eiW3/eRZ/NJfQs3xA8GLh7v7HMpUZHujdSgHzvQ89nXpwm17R+TtVEROr XZla3Ovz42dwoHb3VixCU2Wy8Gemx6h8QVq0nMlny7JfhFc03Ni8+h46JZTR0zIQnv Ip8jstAPQ9gMw== 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 00DEB628BE for ; Fri, 30 Jun 2023 14:03:09 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Go/HsFXz"; dkim-atps=neutral Received: from umang.jainideasonboard.com.praguecc.cz (unknown [193.85.242.128]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 79CF4DE2; Fri, 30 Jun 2023 14:02:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1688126547; bh=vQpye2Y9OwiLOppoOXQEwyz1zqAHufpJ5KTWofakVN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Go/HsFXz31Z5mrr/cXLPGh/0JQIVRX8TGE2Xb+t8o9T1P+/W6mCF/DUjuBgxtyrVc sHu9WmoLb9XLhK9PVQ/hPSbVuOaKG1h2VahwMLn9u2Oyq4HaBjkI97PAYMEkpHcscN VhcFKhCFX92eBqmpmBZeL33iAbeHlfmadWtWVZD0= To: libcamera-devel@lists.libcamera.org Date: Fri, 30 Jun 2023 14:03:00 +0200 Message-Id: <20230630120303.33023-3-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230630120303.33023-1-umang.jain@ideasonboard.com> References: <20230630120303.33023-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 2/5] ipa: rpi: Make parsePdafData() available in the CamHelper class 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 Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" parsePdafData() parses the PDAF section of the sensor's embedded data and the parsing logic is generic to all PDAF-supported sensors. Once the PDAF-specific buffer section is identified correctly, any sensor should be able to use this helper in order parse its PDAF data. No functional changes intended in this patch. Signed-off-by: Umang Jain --- src/ipa/rpi/cam_helper/cam_helper.cpp | 29 +++++++++++++++ src/ipa/rpi/cam_helper/cam_helper.h | 6 ++++ src/ipa/rpi/cam_helper/cam_helper_imx708.cpp | 37 -------------------- 3 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/ipa/rpi/cam_helper/cam_helper.cpp b/src/ipa/rpi/cam_helper/cam_helper.cpp index ddd5e9a4..e9e0c496 100644 --- a/src/ipa/rpi/cam_helper/cam_helper.cpp +++ b/src/ipa/rpi/cam_helper/cam_helper.cpp @@ -253,6 +253,35 @@ void CamHelper::parseEmbeddedData(Span buffer, metadata.set("device.status", deviceStatus); } +bool CamHelper::parsePdafData(Span &data, unsigned bpp, PdafRegions &pdaf) +{ + const uint8_t *ptr = data.data(); + unsigned int len = data.size(); + 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; +} + void CamHelper::populateMetadata([[maybe_unused]] const MdParser::RegisterMap ®isters, [[maybe_unused]] Metadata &metadata) const { diff --git a/src/ipa/rpi/cam_helper/cam_helper.h b/src/ipa/rpi/cam_helper/cam_helper.h index 58a4b202..705796a2 100644 --- a/src/ipa/rpi/cam_helper/cam_helper.h +++ b/src/ipa/rpi/cam_helper/cam_helper.h @@ -16,6 +16,7 @@ #include "controller/camera_mode.h" #include "controller/controller.h" #include "controller/metadata.h" +#include "controller/pdaf_data.h" #include "md_parser.h" #include "libcamera/internal/v4l2_videodevice.h" @@ -101,11 +102,16 @@ public: virtual unsigned int mistrustFramesModeSwitch() const; protected: + static bool parsePdafData(libcamera::Span &pdafData, unsigned bpp, + PdafRegions &pdaf); void parseEmbeddedData(libcamera::Span buffer, Metadata &metadata); virtual void populateMetadata(const MdParser::RegisterMap ®isters, Metadata &metadata) const; + static constexpr int pdafStatsRows = 12; + static constexpr int pdafStatsCols = 16; + std::unique_ptr parser_; CameraMode mode_; diff --git a/src/ipa/rpi/cam_helper/cam_helper_imx708.cpp b/src/ipa/rpi/cam_helper/cam_helper_imx708.cpp index b24ee643..d0382d63 100644 --- a/src/ipa/rpi/cam_helper/cam_helper_imx708.cpp +++ b/src/ipa/rpi/cam_helper/cam_helper_imx708.cpp @@ -12,8 +12,6 @@ #include -#include "controller/pdaf_data.h" - #include "cam_helper.h" #include "md_parser.h" @@ -72,15 +70,9 @@ 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(libcamera::Span &pdafData, unsigned bpp, - PdafRegions &pdaf); - bool parseAEHist(const uint8_t *ptr, size_t len, unsigned bpp); void putAGCStatistics(StatisticsPtr stats); @@ -243,35 +235,6 @@ void CamHelperImx708::populateMetadata(const MdParser::RegisterMap ®isters, metadata.set("device.status", deviceStatus); } -bool CamHelperImx708::parsePdafData(Span &data, unsigned bpp, PdafRegions &pdaf) -{ - const uint8_t *ptr = data.data(); - unsigned int len = data.size(); - 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; -} - bool CamHelperImx708::parseAEHist(const uint8_t *ptr, size_t len, unsigned bpp) { static constexpr unsigned int PipelineBits = Statistics::NormalisationFactorPow2;