From patchwork Mon Jun 13 14:28:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Michel Hautbois X-Patchwork-Id: 16215 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 04E2BC3278 for ; Mon, 13 Jun 2022 14:29:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6B0806564A; Mon, 13 Jun 2022 16:29:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655130549; bh=L0NjK6mBDyCL2ThmuccyDqBNjZ8Igse88Op1rmrJkK0=; 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=Po31hqHw94zpesI5L95cP+tXY61SAD6Fa/TFQ7lsot1OIT2WXPF3jrQYqYMBnZHDc KzOueWYiPmKxn1C2ivVFNRrsxo+XqixOs0cfKYwQZfr29NMwTBsmjPay5zkr20gTNT s54WLNglOrfWHE/hnS0viZJytFj8B503+TZ18xgursidz2QZ4QAUjjp+xMwZDxSH5T kQzM42AvaaYewv9q18Pk27W7KbUPeC5GYqnlT4dWghu9eARY4+NGBTZk4qx/CuiuDF GFz72bZx/9o51rsKNkpo49LVaszll+0fj4aHEJ8ORxkGJTC+gokfgDaTxsuGLw2Nbk z6rlAK9ULIMcw== 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 4BA226563A for ; Mon, 13 Jun 2022 16:29:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="b1emh2kn"; dkim-atps=neutral Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:a1c7:c28c:7720:9b30]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E8050835; Mon, 13 Jun 2022 16:29:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655130541; bh=L0NjK6mBDyCL2ThmuccyDqBNjZ8Igse88Op1rmrJkK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b1emh2knyX0to0UU2/15ZqmSg9YNCfW2AKlJrLQAjV1eDICVfuqdbJqqmhSvwlM9b DxeE+MSMrRneg7i/9Qq9N3f+ESAAXw6GOqD0Dy7VOf+5s4dE2ry54h1kBP8Cv5PHcA bOZpqHdabQUFwvBq39/t3yChcPd+xiICEZlFGHIQ= To: libcamera-devel@lists.libcamera.org Date: Mon, 13 Jun 2022 16:28:49 +0200 Message-Id: <20220613142853.98484-7-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220613142853.98484-1-jeanmichel.hautbois@ideasonboard.com> References: <20220613142853.98484-1-jeanmichel.hautbois@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 06/10] ipa: raspberrypi: Add AfMode control 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: Jean-Michel Hautbois via libcamera-devel From: Jean-Michel Hautbois Reply-To: Jean-Michel Hautbois Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Implement the AfMode control to allow the user to switch between manual, auto or continuous mode. As the mode changes, the AfState value is updated and lets the user follow the algorithm state. Signed-off-by: Jean-Michel Hautbois --- include/libcamera/ipa/raspberrypi.h | 3 ++- src/ipa/raspberrypi/controller/iob/af.cpp | 24 ++++++++++++++++------- src/ipa/raspberrypi/raspberrypi.cpp | 15 ++++++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/include/libcamera/ipa/raspberrypi.h b/include/libcamera/ipa/raspberrypi.h index 519f7160..5bc14f4e 100644 --- a/include/libcamera/ipa/raspberrypi.h +++ b/include/libcamera/ipa/raspberrypi.h @@ -46,7 +46,8 @@ static const ControlInfoMap Controls({ { &controls::ScalerCrop, ControlInfo(Rectangle{}, Rectangle(65535, 65535, 65535, 65535), Rectangle{}) }, { &controls::FrameDurationLimits, ControlInfo(INT64_C(1000), INT64_C(1000000000)) }, { &controls::draft::NoiseReductionMode, ControlInfo(controls::draft::NoiseReductionModeValues) }, - { &controls::AfState, ControlInfo(controls::AfStateValues) } + { &controls::AfMode, ControlInfo(controls::AfModeValues) }, + { &controls::AfState, ControlInfo(controls::AfStateValues) }, }, controls::controls); } /* namespace RPi */ diff --git a/src/ipa/raspberrypi/controller/iob/af.cpp b/src/ipa/raspberrypi/controller/iob/af.cpp index b03e52c5..e09514c4 100644 --- a/src/ipa/raspberrypi/controller/iob/af.cpp +++ b/src/ipa/raspberrypi/controller/iob/af.cpp @@ -40,7 +40,7 @@ Af::Af(Controller *controller) : AfAlgorithm(controller), focus_(0), bestFocus_(0), currentContrast_(0.0), previousContrast_(0.0), maxContrast_(0.0), maxStep_(0), coarseCompleted_(false), fineCompleted_(false), - mode_(0) + mode_(libcamera::controls::AfModeManual) { } @@ -49,9 +49,13 @@ char const *Af::Name() const return NAME; } -void Af::SetMode([[maybe_unused]] const uint32_t &mode) +void Af::SetMode(const uint32_t &mode) { - mode_ = mode; + if (mode != mode_) { + LOG(IoBAf, Debug) << "Switched AF mode from " << mode_ + << " to " << mode; + mode_ = mode; + } } void Af::Trigger() @@ -78,7 +82,7 @@ void Af::Initialise() { status_.lensPosition = 0.0; maxContrast_ = 0.0; - status_.state = libcamera::controls::AfStateScanning; + status_.state = libcamera::controls::AfStateIdle; } void Af::Prepare(Metadata *image_metadata) @@ -162,7 +166,7 @@ void Af::afReset() LOG(IoBAf, Debug) << "Reset AF parameters"; status_.lensPosition = 0; focus_ = 0; - status_.state = libcamera::controls::AfStateIdle; + status_.state = libcamera::controls::AfStateScanning; previousContrast_ = 0.0; coarseCompleted_ = false; fineCompleted_ = false; @@ -195,12 +199,18 @@ void Af::Process(StatisticsPtr &stats, [[maybe_unused]] Metadata *image_metadata currentContrast_ += stats->focus_stats[i].contrast_val[1][1] / stats->focus_stats[i].contrast_val_num[1][1]; + /* Depending on the mode, we may or may not process the stats */ + if (status_.state == libcamera::controls::AfStateIdle) + return; + if (status_.state != libcamera::controls::AfStateFocused) { afCoarseScan(); afFineScan(); } else { - if (afIsOutOfFocus()) - afReset(); + /* We can re-start the scan at any moment in AfModeContinuous */ + if (mode_ == libcamera::controls::AfModeContinuous) + if (afIsOutOfFocus()) + afReset(); } } diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index a4e1c834..226388a7 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -30,6 +30,7 @@ #include "libcamera/internal/mapped_framebuffer.h" +#include "af_algorithm.hpp" #include "af_status.h" #include "agc_algorithm.hpp" #include "agc_status.h" @@ -956,6 +957,20 @@ void IPARPi::queueRequest(const ControlList &controls) break; } + case controls::AF_MODE: { + RPiController::AfAlgorithm *af = dynamic_cast( + controller_.GetAlgorithm("iob.af")); + if (!af) { + LOG(IPARPI, Warning) + << "Could not set AF_MODE - no AF algorithm"; + break; + } + + int32_t idx = ctrl.second.get(); + af->SetMode(idx); + break; + } + default: LOG(IPARPI, Warning) << "Ctrl " << controls::controls.at(ctrl.first)->name()