From patchwork Thu Jan 19 10:45:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18157 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 828A6C3297 for ; Thu, 19 Jan 2023 10:46:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1FEC16260A; Thu, 19 Jan 2023 11:46:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1674125166; bh=hOUZPXIlhEQqFR0RsMcg2Z/jh8tJtOT052B+m706PIo=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Anhrv8RgSuDh0Yi69aHfVUwHYpJ64DocAf6FyYtrnx03/855C5tqukJQhjcqoeHPj uClNM7cq2Oo/rVVSEFAcgZaXDOq5q8VTxtEcMWtZBqGzARR+VRIxnG1YeEggl13Dn1 THbwT51p1qd84yA7MBdEemvbgpMtUmpdSKXK9griYwXxup9Wdp1c+kc4+/cGO0nDps BtBgiHOFR7w5womKayicziIEqKX+nRV6cjI4pakAdDo5J1Omi3kDjEC/LWaRz0srea rzEBA/x79ZT+53jd3hqD2anceyVRnoNyDqMB7/kREQE8QQx8//znSkE6CNmB6EKAnG qx/P/zmrx7Z4A== Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DCAE261EFC for ; Thu, 19 Jan 2023 11:45:59 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="PVoU519i"; dkim-atps=neutral Received: by mail-wm1-x32e.google.com with SMTP id m15so1149941wms.4 for ; Thu, 19 Jan 2023 02:45:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=daQ5WIrNK17AMNTB2uJujU/y+E4tht6Eh2qZ398InRs=; b=PVoU519iVZfUgbPhfFPg/GgjI7M74yM3uwhCzg/Y7arPh1JVlXU8V2NZjRxA4kmUKM 7GXAbBgrjpz0/2S/s1BUz8r65tIlxSy4tyKcQfxZIY36KuhWK854ooLfhFZAMNcTMyPx Wul9T1rg1tzA5xe6+44Mr8onzK/TBqFY6A1h15mEvPobaj4T3mmgHt1AhXAnv0T1Z3RE zYI8aufYISBC670emaWmGguPE4h/J2mOcf3MZ/16xg9Rms6tLdr1xQhU23ak/23/kk2g myYY2ApCLMURkt7Ps8FI4eDjpIo4tfExfuPVdxDT9u5j4/zvM7Yv00k7gnj+Po7N2YSG b4jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=daQ5WIrNK17AMNTB2uJujU/y+E4tht6Eh2qZ398InRs=; b=SEn5ILcwXpZOJ4Klsx/W9kUSwuAmEtLTY+fQjpmtU5UmqjcTriNiV4YSoi7CS5E/hP Jx2tZsREVOhaWK3cKOyrUYp72KK0qzSF44Z4yTBEb2Ivh3JBB6iiMwOqq4c8EFuFO0f7 IWXIQxeJPX26HBuiRf7mxAL6949ebjM7Irxrj4KedujhcNBNUnNLyjAxNY/6Wk5oVPgn uYLvpPoIODwFIfxRHPrNDETT+LY2Ke25ci8lviMDkyUdAQyzM5v9BQOpm8KPeqE8OAzl A2IVz35Ta4/Mf29P2obmBWq0QagK6T6g7TbB637G/ZYOH1vmDICBV3dpk6JGsycGX6/d umcQ== X-Gm-Message-State: AFqh2kqiETvQYWSYCfyicnYfRc98ToMHn2UpoUjrFyzZFH/77GW/tdZ6 mt/xejae8IUUg4RI5zbc1r8PbKpNNcxS6F7mNLo= X-Google-Smtp-Source: AMrXdXvdv6yAespsxgkMihXttyWTfmOghiWkIcIPsZi8jLa0SDJu8X/dfRrENAoNmyr6UpaeIxcIGA== X-Received: by 2002:a05:600c:5028:b0:3db:1dea:75c9 with SMTP id n40-20020a05600c502800b003db1dea75c9mr2033501wmr.28.1674125159098; Thu, 19 Jan 2023 02:45:59 -0800 (PST) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id be12-20020a05600c1e8c00b003db06224953sm5332029wmb.41.2023.01.19.02.45.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jan 2023 02:45:58 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Thu, 19 Jan 2023 10:45:40 +0000 Message-Id: <20230119104544.9456-11-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230119104544.9456-1-naush@raspberrypi.com> References: <20230119104544.9456-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 10/14] ipa: raspberrypi: Handle autofocus algorithm results 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: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Nick Hollinghurst Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Nick Hollinghurst Handle the results returned from the autofocus algorithm by updating lens actuator position to the desired value. Update the Request metadata with the algorithm status to provide back to the application. Signed-off-by: Nick Hollinghurst Signed-off-by: Naushir Patuck Reviewed-by: Naushir Patuck Reviewed-by: David Plowman --- src/ipa/raspberrypi/raspberrypi.cpp | 48 +++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 0eb55ed605b6..fbace14b1afe 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -32,6 +32,7 @@ #include "libcamera/internal/mapped_framebuffer.h" #include "af_algorithm.h" +#include "af_status.h" #include "agc_algorithm.h" #include "agc_status.h" #include "alsc_status.h" @@ -164,6 +165,7 @@ private: void applySharpen(const struct SharpenStatus *sharpenStatus, ControlList &ctrls); void applyDPC(const struct DpcStatus *dpcStatus, ControlList &ctrls); void applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls); + void applyAF(const struct AfStatus *afStatus, ControlList &lensCtrls); void resampleTable(uint16_t dest[], double const src[12][16], int destW, int destH); std::map buffers_; @@ -629,6 +631,36 @@ void IPARPi::reportMetadata(unsigned int ipaContext) m[i] = ccmStatus->matrix[i]; libcameraMetadata_.set(controls::ColourCorrectionMatrix, m); } + + const AfStatus *afStatus = rpiMetadata.getLocked("af.status"); + if (afStatus) { + int32_t s, p; + switch (afStatus->state) { + case AfState::Scanning: + s = controls::AfStateScanning; + break; + case AfState::Focused: + s = controls::AfStateFocused; + break; + case AfState::Failed: + s = controls::AfStateFailed; + break; + default: + s = controls::AfStateIdle; + } + switch (afStatus->pauseState) { + case AfPauseState::Pausing: + p = controls::AfPauseStatePausing; + break; + case AfPauseState::Paused: + p = controls::AfPauseStatePaused; + break; + default: + p = controls::AfPauseStateRunning; + } + libcameraMetadata_.set(controls::AfState, s); + libcameraMetadata_.set(controls::AfPauseState, p); + } } bool IPARPi::validateSensorControls() @@ -1294,6 +1326,14 @@ void IPARPi::prepareISP(const ISPConfig &data) if (dpcStatus) applyDPC(dpcStatus, ctrls); + const AfStatus *afStatus = rpiMetadata.getLocked("af.status"); + if (afStatus) { + ControlList lensctrls(lensCtrls_); + applyAF(afStatus, lensctrls); + if (!lensctrls.empty()) + setLensControls.emit(lensctrls); + } + if (!ctrls.empty()) setIspControls.emit(ctrls); } @@ -1619,6 +1659,14 @@ void IPARPi::applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls) ctrls.set(V4L2_CID_USER_BCM2835_ISP_LENS_SHADING, c); } +void IPARPi::applyAF(const struct AfStatus *afStatus, ControlList &lensCtrls) +{ + if (afStatus->lensSetting) { + ControlValue v(afStatus->lensSetting.value()); + lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE, v); + } +} + /* * Resamples a 16x12 table with central sampling to destW x destH with corner * sampling.