From patchwork Fri Mar 22 13:14:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Scally X-Patchwork-Id: 19786 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 AAFCAC3272 for ; Fri, 22 Mar 2024 13:15:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7609363097; Fri, 22 Mar 2024 14:15:09 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="G3oJXN4J"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4559961C45 for ; Fri, 22 Mar 2024 14:15:07 +0100 (CET) Received: from mail.ideasonboard.com (cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 26A5D842; Fri, 22 Mar 2024 14:14:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1711113278; bh=5j/atG6eDn795uXolt3wlIvNnN4mqiwi+rpX3oN6AnI=; h=From:To:Cc:Subject:Date:From; b=G3oJXN4JH4J8HrUknRt/mngvAJHBrvRzzw8PTa8CTiY1kbre8kwmBKoVsiQQOosD9 4xJqIKB2QOhx5glVsnnaFPy5BNIdSPbCiVuxtPDhc3OIz9TXHpWlIi8YeB+VkaL4vJ IHFzJHJjHQ5yekbhcP4VWUjelCFgNZ7RCpsntn8M= From: Daniel Scally To: libcamera-devel@lists.libcamera.org Cc: Daniel Scally Subject: [PATCH 00/10] Centralise Agc into libipa Date: Fri, 22 Mar 2024 13:14:41 +0000 Message-Id: <20240322131451.3092931-1-dan.scally@ideasonboard.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Hello all The IPU3 and RkISP1 IPAs do Agc the same way (following the Rpi method closely), but the implementations are wholly separate. This introduces the potential for divergence and also makes both maintenance and improvement more difficult. This series unifies them as derivations of a new MeanLuminanceAgc class within libipa. The algorithm itself is done through functions of the base class with the IPA's derived classes providing a function through which the mean luminance input to the algorithm can be calculated from their specific stats formats. The old implementations effectively hard coded values for the AeConstraintMode and AeExposureMode controls; they adhered to a single lower-bound constraint of 0.5 across the top 2% of a Histogram and acted as though the AeExposureMode expected shutter time to be driven to its maximum before touching gain at all. The base class additionally adds infrastructure to discover the supported values for AeConstraintMode and AeExposureMode controls from a camera sensor tuning file and uses the values defined in those files with the algorithm instead, though as no tuning files are modified in this series the behaviour currently remains as it was before. The series **does** alter the calculated shutter time and gain for both the IPU3 and RkISP1 compared to their bespoke implementations, for two reasons: 1. A bug in the way they were implemented meant that an over-exposed image was corrected more slowly than an under-exposed one. This is fixed and will improve both IPAs' response to a too-bright image. 2. The default kRelativeLuminanceTarget is centrally set to 0.16 which matches the value from the IPU3 implementation. In the RkISP1 implementation that value was set to 0.4 with a \todo to see why they were different. My belief is that they were different because they were implemented in different lighting conditions. In my very imperfect testing setup the 0.16 target produced reasonable images on both. Without those two changes, the shutter time and gain calculated after this series matches those calculated by their independent implementations. Thanks Dan Daniel Scally (9): ipa: libipa: Allow creation of empty Histogram libcamera: controls: Generate enum value-name maps ipa: libipa: Add MeanLuminanceAgc base class ipa: ipu3: Parse and store Agc stats ipa: ipu3: Derive ipu3::algorithms::Agc from MeanLuminanceAgc ipa: ipu3: Remove bespoke AGC functions from IPU3 ipa: rkisp1: Add parseStatistics() to Agc ipa: rkisp1: Derive rkisp1::algorithms::Agc from MeanLuminanceAgc ipa: rkisp1: Remove bespoke Agc functions Paul Elder (1): ipa: libipa: Add ExposureModeHelper include/libcamera/control_ids.h.in | 2 + include/libcamera/property_ids.h.in | 2 + src/ipa/ipu3/algorithms/agc.cpp | 306 ++++---------- src/ipa/ipu3/algorithms/agc.h | 27 +- src/ipa/ipu3/ipa_context.cpp | 3 + src/ipa/ipu3/ipa_context.h | 5 + src/ipa/ipu3/ipu3.cpp | 2 +- src/ipa/libipa/agc.cpp | 526 ++++++++++++++++++++++++ src/ipa/libipa/agc.h | 82 ++++ src/ipa/libipa/exposure_mode_helper.cpp | 307 ++++++++++++++ src/ipa/libipa/exposure_mode_helper.h | 61 +++ src/ipa/libipa/histogram.h | 1 + src/ipa/libipa/meson.build | 4 + src/ipa/rkisp1/algorithms/agc.cpp | 303 ++++---------- src/ipa/rkisp1/algorithms/agc.h | 19 +- src/ipa/rkisp1/ipa_context.h | 5 + src/ipa/rkisp1/rkisp1.cpp | 2 +- utils/gen-controls.py | 19 + 18 files changed, 1219 insertions(+), 457 deletions(-) create mode 100644 src/ipa/libipa/agc.cpp create mode 100644 src/ipa/libipa/agc.h create mode 100644 src/ipa/libipa/exposure_mode_helper.cpp create mode 100644 src/ipa/libipa/exposure_mode_helper.h