From patchwork Mon Jan 23 15:49:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18185 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 2CF26C3297 for ; Mon, 23 Jan 2023 15:50:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D6C33625FE; Mon, 23 Jan 2023 16:50:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1674489000; 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=aWY35Nw2CisG/tLK+BHtSMm4kvjvVh8hdi7ZOlA2jiIYYZg8XzR8mkliNhQIrA3z5 lWDGI1lLLDPEfos558vJK2Sy7/WW8zyyzbUrmsgxAx74GJYUSz5Xc4wlRlILTRTeug h+SCk2bC6PIrc6x5XRDBY2XjpzUIvuvBn+/MMgNANufGNNoJ5bZDjikNYSNI1J4FTt Y8XRFMRQcKNS5B2JVHNFqPFexjZKqZXBblZi9o/YbvdLUkHwtI9D+j1QDODoox6T0v YRS/QYlKJ5wQSaMnCDnhLe+IMU+DM4J0tMeWRaTiv9a0p9bcwmEoq4bszl5z2zowBS 9tP416QWXfyPw== 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 5B0DF625FD for ; Mon, 23 Jan 2023 16:49:54 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="E34cAfg2"; dkim-atps=neutral Received: by mail-wm1-x32e.google.com with SMTP id c10-20020a05600c0a4a00b003db0636ff84so8924037wmq.0 for ; Mon, 23 Jan 2023 07:49:54 -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=E34cAfg2HUBLyIkEc+nAHpmSHnddtNHi1OiFySXJixcQA+7lftAelSdvC2pwYqP/AP 9XSaqj6dXNfgw0xPLmUxtXld8PcWqr+HTD1ovBXVjVmIV3tcA1HE96qkH5d9A3Z6nBHG FCqzmX9DrUvhaC8EQQ5PsRLTgpIY2jR6l130Fw31o8XqdreIZrh+DptB5KPJ7A424dyU D6bypEHbua+aRimC35e+j5O+PCUWqNLtY5GDGCCsrw5ibiw7TA8pQE/rKZPXxRdMLEqg 5P7tIlF3l3+5QXWd1qbyuKnhRlEJtfMm8GC+g8C3O7Xb+abGBl7zGLDQolN/384udt5J /m1Q== 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=fYz48b+FjMtn5s/9KxXk2Pzi9Ym35BoPRY5JhqzDxPSMOGGxqhnBUjKnwnhp5v8dET jQ9YLB7GXmVTNVrEfisnzOh4XQxg68eJ9Pjb9Je7HofLzI5k+OuUQsiV7wXg4ngiavx6 Lo76n5JQd/JNIZxACN+i7XbMZDjWFDsku+yn1kYBzHIoL+LIgHaa9iO1Vrro8OzjVqDc 2d3BQGeKTdKQhXZ5aPHuHBk4YP6fsmH+Sx/PZrbV0iSQvCcEduRy0EjfEQbNrCHv2PUv z08OcOZbf+sMQ8Cmcdy992ay9mS8850KY6b2Tm7zh4mTzOFvxn2aG8EVEmHHBYJH02z8 C7Dg== X-Gm-Message-State: AFqh2krd66pMICSwmDtVYlUlPHBO/o0sC/8sZa+1t2geORD/Gq9VKp3D bGhLxJ+XFSpk+jtZG7NH22NckQ+AN8rn3yvaEu4= X-Google-Smtp-Source: AMrXdXvVeGtpS5umNtSXdjoaF+GHGbbqxu0woJrXKcj35BlG1M5saeRRuKSQHXGoemO114lYg05quQ== X-Received: by 2002:a05:600c:5118:b0:3db:1e4f:7cdc with SMTP id o24-20020a05600c511800b003db1e4f7cdcmr16672016wms.15.1674488993894; Mon, 23 Jan 2023 07:49:53 -0800 (PST) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id n16-20020a05600c181000b003d1de805de5sm10339689wmp.16.2023.01.23.07.49.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 07:49:53 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Jan 2023 15:49:30 +0000 Message-Id: <20230123154934.27803-11-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230123154934.27803-1-naush@raspberrypi.com> References: <20230123154934.27803-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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.