From patchwork Wed Mar 22 13:06:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18435 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 4CDDBC32A1 for ; Wed, 22 Mar 2023 13:06:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C8EF76273D; Wed, 22 Mar 2023 14:06:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1679490390; bh=vly+N8kD070ySftpvX91l+mQboT8yWAuvyihR8zCM34=; 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=aV59BNqEI8iuNUQnhZIv1NY0sSsjA/OTOii03Ge+WT+YrVav/1PZhJAlRJzTcGw0D OJElfp/sDLhkjpXlclBqgl+DNbn0T/c6RSU6T3sjsfrmWZW7AK1cbAn19hSiUwvhXY C/on0DqaKYB9TnhP8eqVTeaotl8627HSH8RHzdt/kqNckCcAwKALPT5Vsc4lnO0IR4 mqqjPsCqM+lf3NK+w5v+g0HPezz/vPNWE1nQONfcDGJGUa9FobRkBjSwF9cHOt4Eyj RQos0exCsB1wCTWhtV1tfUodFnVWXptvmml0kXdjcLyUUyWEwxwLYtUW8ST1GAZZfs iVF4TDkANh0eg== Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CCA0B62716 for ; Wed, 22 Mar 2023 14:06:26 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="pd246ll/"; dkim-atps=neutral Received: by mail-io1-xd32.google.com with SMTP id s4so8386058ioj.11 for ; Wed, 22 Mar 2023 06:06:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1679490386; 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=VTK7RKvARCpPhRDMEiuWMbT7meHOFDF62AOEWuoNos8=; b=pd246ll/74pNccmnICdWx6Jm4G0Y0+Irarb3wx3Sze12V7FSCnk1mHr8z+xG6QSaEX qPIW3QqOZXJQJwgBOI/+kXGVV/PfD40qly+jUjj/z1VOAio2wbgEa1xB4/7R12Idc6zD u5dxiYT7Fd3y117eOoOqwPYILkMnM7Bs/upnxWixfEiv8Zb2RajjUIiMi8sFCvKZyrqF xvj1TV5QW6rwrCpDPnH+YOkPcqqyttqNAai79KlE96tjGxt2Hew62agqGxoKrAlheQK6 3y7AVyvt8PUiZ+PCH7kKKGZ8bJp2pYUhFHIU3UcP51U93snhfqOEFwMchQn0sbbdjzR+ AZMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679490386; 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=VTK7RKvARCpPhRDMEiuWMbT7meHOFDF62AOEWuoNos8=; b=XnBeoi2nBoCo3vzWfaYvjQsSvlg3/jqqxIwgOsYPw8fGOMr0kxSIL8yNnFTC/Y/uxF 0WzVQeuIebSsiU8wjIHYoVuPAJ4ca4P7tRlBwb9p/I8dMArxdFaJcL5kgu7S8ExdmfDA FhyXV3BmFMFR7PDNSFwxRloeaGVUg46u+sqFQCjBre+v4sg+OPdrMpWEecVpw3FFdAQv ZQNiQqHhG47B3jnrEo7AZj5tLg7OyaECJe634XCKMhusf4wIJfH7ufmfOP1o0OI1fJUn Jzcc3m4FGbCq0NlUVUAdFCwUyAcTfoHvXqsqIgwSETxMdOpfIW4RELXaiTTuM9WJXeC8 myFA== X-Gm-Message-State: AO0yUKWx8IrId0zG/4PH4yTEYfj82aVFcv4a++S5U26AqACrHyi0Onp2 e+eq65VDzGAsuvoulkzGzRhxdQZC4XcEUVbX4cWsbA== X-Google-Smtp-Source: AK7set+cjpe2x/LRyuaMf/dDNdqDoD3bC5YsNufoGxaKAceILUGhko88mBp9gnE7n55sI7G8xbCsjw== X-Received: by 2002:a5e:db02:0:b0:746:1c75:233a with SMTP id q2-20020a5edb02000000b007461c75233amr4547901iop.20.1679490386244; Wed, 22 Mar 2023 06:06:26 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id l6-20020a026646000000b003c488204c6fsm4927960jaf.76.2023.03.22.06.06.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 06:06:25 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 22 Mar 2023 13:06:10 +0000 Message-Id: <20230322130612.5208-9-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230322130612.5208-1-naush@raspberrypi.com> References: <20230322130612.5208-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 08/10] ipa: raspberrypi: Generalise the focus algorithm 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 Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Generalise the focus reporting algorithm code by removing any hard-coded assumptions about the target hardware platform. Instead, the algorithm code uses the generalised statistics structure to determine focus region sizes. Remove focus_status.h as it is no longer needed with this change. Signed-off-by: Naushir Patuck Reviewed-by: Jacopo Mondi --- src/ipa/raspberrypi/controller/focus_status.h | 20 ------------------- src/ipa/raspberrypi/controller/rpi/focus.cpp | 12 ++--------- src/ipa/raspberrypi/raspberrypi.cpp | 11 ++++++---- 3 files changed, 9 insertions(+), 34 deletions(-) delete mode 100644 src/ipa/raspberrypi/controller/focus_status.h diff --git a/src/ipa/raspberrypi/controller/focus_status.h b/src/ipa/raspberrypi/controller/focus_status.h deleted file mode 100644 index 8b74e59840c1..000000000000 --- a/src/ipa/raspberrypi/controller/focus_status.h +++ /dev/null @@ -1,20 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2020, Raspberry Pi Ltd - * - * focus_status.h - focus measurement status - */ -#pragma once - -#include - -/* - * The focus algorithm should post the following structure into the image's - * "focus.status" metadata. Recall that it's only reporting focus (contrast) - * measurements, it's not driving any kind of auto-focus algorithm! - */ - -struct FocusStatus { - unsigned int num; - uint32_t focusMeasures[FOCUS_REGIONS]; -}; diff --git a/src/ipa/raspberrypi/controller/rpi/focus.cpp b/src/ipa/raspberrypi/controller/rpi/focus.cpp index ea3cc00e42c3..683d460ad6f7 100644 --- a/src/ipa/raspberrypi/controller/rpi/focus.cpp +++ b/src/ipa/raspberrypi/controller/rpi/focus.cpp @@ -8,7 +8,6 @@ #include -#include "../focus_status.h" #include "focus.h" using namespace RPiController; @@ -30,15 +29,8 @@ char const *Focus::name() const void Focus::process(StatisticsPtr &stats, Metadata *imageMetadata) { - FocusStatus status; - for (unsigned int i = 0; i < stats->focusRegions.numRegions(); i++) - status.focusMeasures[i] = stats->focusRegions.get(i).val; - status.num = stats->focusRegions.numRegions(); - imageMetadata->set("focus.status", status); - - LOG(RPiFocus, Debug) - << "Focus contrast measure: " - << (status.focusMeasures[5] + status.focusMeasures[6]) / 10; + /* Pass the stats directly to the IPA to report out to the application */ + imageMetadata->set("focus.status", stats->focusRegions); } /* Register algorithm with the system. */ diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index b6e5465ca32a..181512de74ad 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -50,7 +50,6 @@ #include "denoise_algorithm.h" #include "denoise_status.h" #include "dpc_status.h" -#include "focus_status.h" #include "geq_status.h" #include "lux_status.h" #include "metadata.h" @@ -640,14 +639,18 @@ void IPARPi::reportMetadata(unsigned int ipaContext) static_cast(blackLevelStatus->blackLevelG), static_cast(blackLevelStatus->blackLevelB) }); - FocusStatus *focusStatus = rpiMetadata.getLocked("focus.status"); - if (focusStatus && focusStatus->num == 12) { + RPiController::FocusRegions *focusStatus = + rpiMetadata.getLocked("focus.status"); + if (focusStatus) { + libcamera::Size size = focusStatus->size(); /* * We get a 4x3 grid of regions by default. Calculate the average * FoM over the central two positions to give an overall scene FoM. * This can change later if it is not deemed suitable. */ - int32_t focusFoM = (focusStatus->focusMeasures[5] + focusStatus->focusMeasures[6]) / 2; + ASSERT(size == Size(4, 3)); + int32_t focusFoM = (focusStatus->get({ 1, 1 }).val + + focusStatus->get({ 2, 1 }).val) / 2; libcameraMetadata_.set(controls::FocusFoM, focusFoM); }