From patchwork Thu Jan 19 08:41:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 18144 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 C8DD0C3240 for ; Thu, 19 Jan 2023 08:42:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 333C0625FE; Thu, 19 Jan 2023 09:42:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1674117735; bh=gscmoJ/hmm/k0IzEqmPI5QVJOjA+vf+JMdzx/ZsIgbo=; 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=Iv0FHxHyMOvXNwKQiwEkE50tE5fkVmJ3cCPze2wt+m62OYDuRqr6fNfXGRTBtCbk2 a+spnWjsGwVC3Ut+GXqnVNp9TBke1RD7vWoz1m3Jna4BPt7QEawGKX2BN8SOj9XM9x 4636YrHA+EQdfRt0sCnvOnvVG7b3uJltG9/8O9LSu6YOSdJl65FCnER2Rpd/l7PN6S B5ei2dOLGg1i3iFsFvPG/OImVuWRePzxo2cr68ucA+1N9kRvnjHniqg1b/1WGOOOMo F0TcWStx73G/1MQba6bzQGRlUNQCl9lGgJNzf+9Fm3liVW1LJwV4AGmDn0Qwqzj9mx d8et4B5dGFF7A== Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D2DC4625EA for ; Thu, 19 Jan 2023 09:42:11 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=thaumatec-com.20210112.gappssmtp.com header.i=@thaumatec-com.20210112.gappssmtp.com header.b="ryhjO1PV"; dkim-atps=neutral Received: by mail-wm1-x32a.google.com with SMTP id m5-20020a05600c4f4500b003db03b2559eso679426wmq.5 for ; Thu, 19 Jan 2023 00:42:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; 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=kprmtRGy07+WJsHQiGi/OEpWYVBfWR8o/DjLzEG6T0c=; b=ryhjO1PV1mUiTqRiFrQuMEUV5l3eOgd0aK1Upw6EC9MCFEi9WdJppZr/c7rqZy+W/8 C7vE8WKwD+fBbCcG0kVyBunXXqwpJ+udZa9eiTHHk3ePESb5g/myaBlHoZmuzc+BQcVU bu56ENSQsNPQ0tsb4UsVwdxjUnyw9ItKYJQfPEgNQHEjN55Jh8fyw8TC9Rg4HE5iNpVA Tp476tWVCrSMankxF75ulIsuOssp9fTNRPUQ4cAZk/iDgU12AZi2S7rnVrezemhG3vbK 3z8STqEMxR81Ap4z37eA5QrrapwxwRDMm/pLNyVM2iqtQyqzmoBHpUUqVJrZMsn/me7w tgAg== 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=kprmtRGy07+WJsHQiGi/OEpWYVBfWR8o/DjLzEG6T0c=; b=FlRiFsaj/chSTcuZTNiJ434cUenijaRQmK/MVx4VQX9o9gPLqPfuEK84vHGzyTWl0M F0aJoqHm1e7prJxTJzUsZ2ac5L9DuAYQdP17/hgUNx34htTv1dNHMwwUEHeGS8LZBuVo nQ3iUIShDZnsAv7DVQhwl9cB/V3Zhn71wQXi21mS5fJ6n3zicbIqAH5dz6WDdaNgXBNC AhlgxV81FXJG3VCEpBVjNXEhlIPCSiXZwNo+DFKH5QJPNpeSTjmiWcl2W1zaZlPO1d7e A8Vn2mCeYXyJE3yxbCn4J0LclBTwksQlZWSuQQ2frPFwWMVCuv61zRRWGs2jIR8XyYwt 1zIw== X-Gm-Message-State: AFqh2kp3vcbvy+H4O+0lhdrHZDv4j2WREwCAvH4+6pa/a6Tlhoce1Vd4 wmn8XfP+sOhKqaVpXuCqTknf+8k04pvSL07wt1Q= X-Google-Smtp-Source: AMrXdXuiHsxfnR/BDIKAbQakqOzseeiNHabpbpwFENhtVX1w5SPPlXYX/kcqYlFot+MW6Vd8zehnDw== X-Received: by 2002:a05:600c:1c83:b0:3da:fbd8:59a0 with SMTP id k3-20020a05600c1c8300b003dafbd859a0mr9484212wms.11.1674117731561; Thu, 19 Jan 2023 00:42:11 -0800 (PST) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id j10-20020a05600c074a00b003db0ee277b2sm3935754wmn.5.2023.01.19.00.42.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jan 2023 00:42:11 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Thu, 19 Jan 2023 09:41:09 +0100 Message-Id: <20230119084112.20564-6-dse@thaumatec.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230119084112.20564-1-dse@thaumatec.com> References: <20230119084112.20564-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 5/8] ipa: rkisp1: Add AF algorithm basing on common AfHillClimbing 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: Daniel Semkowicz via libcamera-devel From: Daniel Semkowicz Reply-To: Daniel Semkowicz Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Rockchip ISP AF block allows calculation of sharpness and luminance in up to three user defined windows. If no windows are set, there are some default settings applied for the first window and exposed through the driver. For each frame, use the sharpness value calculated for this default window and feed the hill climbing algorithm with them. Then set the lens position to value calculated by the algorithm. Signed-off-by: Daniel Semkowicz --- src/ipa/rkisp1/algorithms/af.cpp | 101 ++++++++++++++++++++++++++ src/ipa/rkisp1/algorithms/af.h | 42 +++++++++++ src/ipa/rkisp1/algorithms/meson.build | 1 + 3 files changed, 144 insertions(+) create mode 100644 src/ipa/rkisp1/algorithms/af.cpp create mode 100644 src/ipa/rkisp1/algorithms/af.h diff --git a/src/ipa/rkisp1/algorithms/af.cpp b/src/ipa/rkisp1/algorithms/af.cpp new file mode 100644 index 00000000..c2a321cd --- /dev/null +++ b/src/ipa/rkisp1/algorithms/af.cpp @@ -0,0 +1,101 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Theobroma Systems + * + * af.cpp - RkISP1 AF hill climbing based control algorithm + */ + +#include "af.h" + +/** + * \file af.h + */ + +namespace libcamera::ipa::rkisp1::algorithms { + +/** + * \class Af + * \brief AF control algorithm + */ + +LOG_DEFINE_CATEGORY(RkISP1Af) + +/** + * \copydoc libcamera::ipa::Algorithm::init + */ +int Af::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData) +{ + waitFramesLens_ = tuningData["wait-frames-lens"].get(1); + + LOG(RkISP1Af, Debug) << "waitFramesLens_: " << waitFramesLens_; + + return initBase(tuningData); +} + +/** + * \copydoc libcamera::ipa::Algorithm::configure + */ +int Af::configure([[maybe_unused]] IPAContext &context, + [[maybe_unused]] const IPACameraSensorInfo &configInfo) +{ + return 0; +} + +/** + * \copydoc libcamera::ipa::Algorithm::queueRequest + */ +void Af::queueRequest([[maybe_unused]] IPAContext &context, + const uint32_t frame, + [[maybe_unused]] IPAFrameContext &frameContext, + const ControlList &controls) +{ + queueRequestBase(frame, controls); +} + +/** + * \copydoc libcamera::ipa::Algorithm::prepare + */ +void Af::prepare([[maybe_unused]] IPAContext &context, + [[maybe_unused]] const uint32_t frame, + [[maybe_unused]] IPAFrameContext &frameContext, + [[maybe_unused]] rkisp1_params_cfg *params) +{ +} + +/** + * \copydoc libcamera::ipa::Algorithm::process + */ +void Af::process(IPAContext &context, [[maybe_unused]] const uint32_t frame, + [[maybe_unused]] IPAFrameContext &frameContext, + const rkisp1_stat_buffer *stats, + [[maybe_unused]] ControlList &metadata) +{ + uint32_t sharpness = stats->params.af.window[0].sum; + uint32_t luminance = stats->params.af.window[0].lum; + + LOG(RkISP1Af, Debug) << "lensPosition: " << context.activeState.af.lensPosition + << ", Sharpness: " << sharpness + << ", Luminance: " << luminance; + + uint32_t lensPosition = processAutofocus(sharpness); + + if (lensPosition != context.activeState.af.lensPosition) { + context.activeState.af.lensPosition = lensPosition; + context.activeState.af.applyLensCtrls = true; + setFramesToSkip(waitFramesLens_); + } +} + +void Af::setMeteringMode([[maybe_unused]] controls::AfMeteringEnum metering) +{ + LOG(RkISP1Af, Error) << __FUNCTION__ << " not implemented!"; +} + +void Af::setWindows([[maybe_unused]] Span windows) +{ + LOG(RkISP1Af, Error) << __FUNCTION__ << " not implemented!"; +} + +REGISTER_IPA_ALGORITHM(Af, "Af") + +} /* namespace libcamera::ipa::rkisp1::algorithms */ diff --git a/src/ipa/rkisp1/algorithms/af.h b/src/ipa/rkisp1/algorithms/af.h new file mode 100644 index 00000000..882be952 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/af.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Theobroma Systems + * + * af.h - RkISP1 AF hill climbing based control algorithm + */ + +#pragma once + +#include + +#include "libipa/algorithms/af_hill_climbing.h" + +#include "algorithm.h" + +namespace libcamera::ipa::rkisp1::algorithms { + +class Af : public ipa::common::algorithms::AfHillClimbing, public Algorithm +{ +public: + Af() = default; + ~Af() = default; + + int init(IPAContext &context, const YamlObject &tuningData) override; + int configure(IPAContext &context, const IPACameraSensorInfo &configInfo) override; + void queueRequest(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, const ControlList &controls) override; + void prepare(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, rkisp1_params_cfg *params) override; + void process(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, const rkisp1_stat_buffer *stats, + ControlList &metadata) override; + +private: + void setMeteringMode(controls::AfMeteringEnum metering) final; + void setWindows(Span windows) final; + + /* Wait number of frames after changing lens position */ + uint32_t waitFramesLens_; +}; + +} /* namespace libcamera::ipa::rkisp1::algorithms */ diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build index 93a48329..ab7e44f3 100644 --- a/src/ipa/rkisp1/algorithms/meson.build +++ b/src/ipa/rkisp1/algorithms/meson.build @@ -1,6 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 rkisp1_ipa_algorithms = files([ + 'af.cpp', 'agc.cpp', 'awb.cpp', 'blc.cpp',