From patchwork Thu Jan 26 13:45:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 18198 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 5C4F2C3242 for ; Thu, 26 Jan 2023 13:46:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D8A56625E6; Thu, 26 Jan 2023 14:46:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1674740767; bh=RKcH0YAhfSyo/V95nouLl+95faYvYp3ElcdEXCr9GuQ=; 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=GewIuTy6o1yB1fmJC1dKqwmSmZhJFKeHqhD0dhQiu6daWdL/X96C0lKK6iLFAOl0f AbCWut9zH58YrzT1aLqiI6VS11M+MO2dWr0g53DjXsMnnksTBWsf0y9Y0UcxahGs19 zvsXrQDNbbV8yRrugHEzw26yqB1NuDqbJiYgNhNTzGzOkHCBVUte/s9MRWbxv7OpSc JWB4eiAji30YEpg78xDDfZfGw2hGsDpoQ/T/Yjlc3NG152rIhLZTRgApp7Jsu1SoRS qywgJFHsYbtukAX6z3H3W9IO3JcBMnUkAxX6Aq13Gi0bGPGZ+Yi7DLcufU3ckLWzUq gkyR/iLIOjhUg== Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DEF5661EFB for ; Thu, 26 Jan 2023 14:46:04 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="qL3bdzmI"; dkim-atps=neutral Received: by mail-wm1-x32d.google.com with SMTP id o17-20020a05600c511100b003db021ef437so1138149wms.4 for ; Thu, 26 Jan 2023 05:46:04 -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=aJca/RVkc3lNXZ6N3PB60KX1Xz4s8woT2pulzG8SZxU=; b=qL3bdzmIJTh+41Jayuv82B4WN9rrvejh0on4moT3EQT4rEsCj6QTpq04/BtcKJ5xd1 zi3LHTNLZ5fqhlRsuc/8Qmn8fRHeuhKfnU/G4SkEMV9Dy2nUuGLOCfVlnAo5yTHmfZM5 Xiuqll+YsM8+mstEe0PIbGZVhOE/caRKZw2uCqI0cnfdyF+CrkO40FE8hDI+SXexwza8 1aVY9n5bsKMXL/JYzrxO/BzG2WqtE4TkUAna93atouzNkcu9KSeK7XLl8YtAHiVjiETm bfst9NRd45n52+CncqWPRFnGQpV/HdBoWEXg3zv7WYd/+HPDbRQmRwT4rELelZoCzk81 nOmQ== 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=aJca/RVkc3lNXZ6N3PB60KX1Xz4s8woT2pulzG8SZxU=; b=zr3ckAEmVKn3d9YE5IdLk7izziqDkDZKdx2GHkIR8tTq1ZQIcxZMZvlRrsyx5WCtXM xyZXTa6QsYLLEaKghVSPdRa/THgTIff/IsrsxDbDFgX+LjCYY/g3R6YdjqQyGM5IM6b1 ISuqQtE52FI195ePGGVmEACTUw9DN+mXW7LNHhWXFbuVLSMBS1ytfshImrqChKOZTVYc laLBbyuQfH3J+8Md1IeWgHHEgS9VZekrpJiGqb1cirTFE8mC/jIUYON4+cZ5TQW3SiKG hjkhq1MbGdSO7n4hhmjT2KbpZqCI4wKmxmJzucrB0FOVLWYQetzhBdeBmojYWnwR0Toh wskA== X-Gm-Message-State: AFqh2krL8QpdhCeqk8r/D+qS3eLFNIv8TeWoB7mHWxs9rpdZit+DHBDN L6Ux6QSXguTCnkysX5R+6/2kNpSrWty4ed9F X-Google-Smtp-Source: AMrXdXulyimo8rAb5ESaxhfzEvsqInA4WoPrj75MepZgPGzj+bnhP/Y3K3GYRY2GSbH532u9wmDeIg== X-Received: by 2002:a05:600c:a11:b0:3db:f1f:bc31 with SMTP id z17-20020a05600c0a1100b003db0f1fbc31mr32800989wmp.16.1674740764294; Thu, 26 Jan 2023 05:46:04 -0800 (PST) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:e4a2:3070:eea4:e434]) by smtp.gmail.com with ESMTPSA id m2-20020a056000180200b002bfb5618ee7sm1370567wrh.91.2023.01.26.05.46.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 05:46:03 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Thu, 26 Jan 2023 13:45:58 +0000 Message-Id: <20230126134559.3323-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230126134559.3323-1-david.plowman@raspberrypi.com> References: <20230126134559.3323-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/2] libcamera: controls: Add controls for AEC/AGC flicker avoidance 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: David Plowman via libcamera-devel From: David Plowman Reply-To: David Plowman Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Flicker is the term used to describe brightness banding or oscillation of images caused typically by artificial lighting driven by a 50 or 60Hz mains supply. We add two controls intended to be used by AEC/AGC algorithms: AeFlickerMode to determine whether flicker avoidance is active or not. AeFlickerPeriod to specify a custom flicker period when the period is other than 50 or 60Hz. Signed-off-by: David Plowman --- src/libcamera/control_ids.yaml | 69 +++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/src/libcamera/control_ids.yaml b/src/libcamera/control_ids.yaml index adea5f90..8093ab75 100644 --- a/src/libcamera/control_ids.yaml +++ b/src/libcamera/control_ids.yaml @@ -14,6 +14,58 @@ controls: \sa ExposureTime AnalogueGain + - AeFlickerMode: + type: int32_t + description: | + Set the flicker mode, which determines whether, and how, the AGC/AEC + algorithm attempts to hide flicker effects caused by the duty cycle of + artificial lighting. + + Although implementation dependent, many algorithms for "flicker + avoidance" work by restricting the exposure time to integer multiples + of this cycle period, wherever possible. + + Implementations may not support all of the flicker modes listed below. + + enum: + - name: FlickerOff + value: 0 + description: No flicker avoidance is performed. + - name: FlickerFreq50Hz + value: 1 + description: 50Hz flicker avoidance. + Suppress flicker effects caused by lighting runing with a + 100Hz period (such as produced by 50Hz mains electricity). + - name: FlickerFreq60Hz + value: 2 + description: 60Hz flicker avoidance. + Suppress flicker effects caused by lighting running with a + 120Hz period (such as produced by 60Hz mains electricity). + - name: FlickerCustom + value: 3 + description: Custom flicker avoidance. + Suppress flicker effects caused by lighting running with a + period specified by AeFlickerPeriod. + + \sa AeFlickerPeriod + - name: FlickerAuto + value: 4 + description: Automatic flicker period detection and avoidance. + The system will automatically determine the most likely value + of the flicker period, and avoid flicker of this frequency. + + - AeFlickerPeriod: + type: int32_t + description: Custom flicker period in microseconds. + This value is taken as the current flicker period to avoid. It + is used when the AeFlickerMode is set to FlickerCustom. + + For example, to avoid 50Hz mains flicker, you could set the period + to 10000, corresponding to 10ms (twice the mains frequency), and + AeFlickerMode to FlickerCustom. + + \sa AeFlickerMode + - AeLocked: type: bool description: | @@ -843,23 +895,6 @@ controls: value: 1 description: The lens shading map mode is available. - - SceneFlicker: - type: int32_t - draft: true - description: | - Control to report the detected scene light frequency. Currently - identical to ANDROID_STATISTICS_SCENE_FLICKER. - enum: - - name: SceneFickerOff - value: 0 - description: No flickering detected. - - name: SceneFicker50Hz - value: 1 - description: 50Hz flickering detected. - - name: SceneFicker60Hz - value: 2 - description: 60Hz flickering detected. - - PipelineDepth: type: int32_t draft: true From patchwork Thu Jan 26 13:45:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 18199 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 672D3BDC71 for ; Thu, 26 Jan 2023 13:46:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 96104625EB; Thu, 26 Jan 2023 14:46:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1674740768; bh=uC9Wltj2m2gSKP/fun7dbaUcLSWVuEKVtB40k/yyRfA=; 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=QVhPzCZMmaGVpf5Dff7+j6DqJwxLsaIfgbqzZW3nz7um2vJMLwLbIPqwb+Pph/CIj Ls9YuYtc4jKClreeXHSk6U6wAmm1Op6nBzyS7u9tQb0CvZ+qrWIIOAofNdXQfL8F8D 2wh6dOhCwAR4kLlX3HTGBpJ4Pcy/Tdj3dy3sW6uK5ZVgNAhJf8Hsf7s96hiDUQgqH6 PBKWkgD12lDTyfEnZ8C9gALLBxTgBC/g7SEvdZUg3a8Wrc/fhqP5WDPzH0s2WX+rW2 gLLddp+TPvbXAz7HQTMR8x8p+/2ElYd2WeVYrLeR9c4/RSms+AvVWy2o5aoFn/bI4J ZI4wFSAu9qF2Q== Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B79D461EFB for ; Thu, 26 Jan 2023 14:46:05 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="kvXQgABF"; dkim-atps=neutral Received: by mail-wr1-x433.google.com with SMTP id m14so1362446wrg.13 for ; Thu, 26 Jan 2023 05:46:05 -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=T0St15xM0OQiiLGtya1glBR/W5nvGUy3/1PW9Rvrxyk=; b=kvXQgABF03g1ka1Re+FW+WDBHyVgz9AAqLR9W9QnKRNlnEj6c8UbaiI2tFIJrx4IoB T6ljccde4N2OXrzDxNBldYVmeUBZOieJTGDAMj5DB6AbnkA6fhSB/JRn2RDqvGHqEEDu X0SGSZ9geAOXhHC+tgGNeTpCLvOnKjYj4jFphqpE02YMhm866PHy+zC/aT9O39UvlA4T 7xM0T9VVyZEmhujJtUdDMVcY/W0CwTq/MF0qr/7kwImTw0cYRUQPUfqCDFjV0x9TUuyT JAKfo+cHIvY/3tx3toLFNezkW6LOaaDTPME/1Au21VP2+mGpcgGY6MDAjVg3WTxV1Ond 09MA== 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=T0St15xM0OQiiLGtya1glBR/W5nvGUy3/1PW9Rvrxyk=; b=7ewfJy4gfoFcJUiGEq7gb4ejTidQj+YMvuGLaLqQbXvo9b9VBh+KO54/OKeMrGk75W yF1flSHxpjRZDfC472/p3qU+kR1T+L2upp5Ng8nF95I1p3KZxIfvetpaPMqI2q16c5/C 9axDTpNdxxu7LYIdhditJNHFEpVhnkwNgOA6lLDySMzK/BfFOBK3HmAF6NeILgq2MeVr tICfjhE9Hk4WlnssBYA0QM7GjcwQhv4P9AzweXNruNafupGIHswQHFaXIgqMd5pgdTu+ M2iV5YIsjQgHQtgCmkl2l55b+S0VhOzso94tRSZBhSnbmBnUu/WiKceJGtxhZjiyyBID KuRQ== X-Gm-Message-State: AO0yUKXYEEA0ZI/Ct7jE6LWVA4MCs6Q//rJ5UNp8Qc1raKkB0lZsSzaw nJN+ZdGY2xcLztlJj1QHArNq4IL8tnOVVLhY X-Google-Smtp-Source: AK7set9py7eNzR4hklTGPP1A2bLEOQbKfG34afTnz8wW3OVbvNiEOHfskMMgFaCJ2LefvmvKqnuhXQ== X-Received: by 2002:a5d:4c41:0:b0:2bf:b3c5:cf54 with SMTP id n1-20020a5d4c41000000b002bfb3c5cf54mr7218345wrt.60.1674740765165; Thu, 26 Jan 2023 05:46:05 -0800 (PST) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:e4a2:3070:eea4:e434]) by smtp.gmail.com with ESMTPSA id m2-20020a056000180200b002bfb5618ee7sm1370567wrh.91.2023.01.26.05.46.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 05:46:04 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Thu, 26 Jan 2023 13:45:59 +0000 Message-Id: <20230126134559.3323-3-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230126134559.3323-1-david.plowman@raspberrypi.com> References: <20230126134559.3323-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/2] ipa: raspberrypi: Handle AEC/AGC flicker controls 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: David Plowman via libcamera-devel From: David Plowman Reply-To: David Plowman Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" We handle the flicker modes by passing the correct period to the AEC/AGC algorithm which already contains the necessary code. The "Auto" mode is currently unsupported. Signed-off-by: David Plowman Reviewed-by: Kieran Bingham Reviewed-by: Naushir Patuck --- src/ipa/raspberrypi/raspberrypi.cpp | 80 +++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 5f7397e2..477d72ba 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -86,6 +86,8 @@ static const ControlInfoMap::Map ipaControls{ { &controls::AeConstraintMode, ControlInfo(controls::AeConstraintModeValues) }, { &controls::AeExposureMode, ControlInfo(controls::AeExposureModeValues) }, { &controls::ExposureValue, ControlInfo(-8.0f, 8.0f, 0.0f) }, + { &controls::AeFlickerMode, ControlInfo(controls::AeFlickerModeValues) }, + { &controls::AeFlickerPeriod, ControlInfo(0, 1000000) }, { &controls::AwbEnable, ControlInfo(false, true) }, { &controls::ColourGains, ControlInfo(0.0f, 32.0f) }, { &controls::AwbMode, ControlInfo(controls::AwbModeValues) }, @@ -218,6 +220,12 @@ private: /* Maximum gain code for the sensor. */ uint32_t maxSensorGainCode_; + + /* The current state of flicker avoidance. */ + struct FlickerState { + int32_t mode; + Duration period; + } flickerState_; }; int IPARPi::init(const IPASettings &settings, bool lensPresent, IPAInitResult *result) @@ -946,6 +954,78 @@ void IPARPi::queueRequest(const ControlList &controls) break; } + case controls::AE_FLICKER_MODE: { + RPiController::AgcAlgorithm *agc = dynamic_cast( + controller_.getAlgorithm("agc")); + if (!agc) { + LOG(IPARPI, Warning) + << "Could not set AE_FLICKER_MODE - no AGC algorithm"; + break; + } + + int32_t mode = ctrl.second.get(); + bool modeValid = true; + + switch (mode) { + case controls::FlickerOff: { + agc->setFlickerPeriod(0us); + + break; + } + + case controls::FlickerFreq50Hz: { + agc->setFlickerPeriod(10000 * 1.0us); + + break; + } + + case controls::FlickerFreq60Hz: { + agc->setFlickerPeriod(8333.333 * 1.0us); + + break; + } + + case controls::FlickerCustom: { + agc->setFlickerPeriod(flickerState_.period); + + break; + } + + default: + LOG(IPARPI, Error) << "Flicker mode " << mode << " is not supported"; + modeValid = false; + + break; + } + + if (modeValid) + flickerState_.mode = mode; + + break; + } + + case controls::AE_FLICKER_PERIOD: { + RPiController::AgcAlgorithm *agc = dynamic_cast( + controller_.getAlgorithm("agc")); + if (!agc) { + LOG(IPARPI, Warning) + << "Could not set AE_FLICKER_PERIOD - no AGC algorithm"; + break; + } + + uint32_t period = ctrl.second.get(); + flickerState_.period = period * 1.0us; + + /* + * We note that it makes no difference if the mode gets set to "custom" + * first, and the period updated after, or vice versa. + */ + if (flickerState_.mode == controls::FlickerCustom) + agc->setFlickerPeriod(flickerState_.period); + + break; + } + case controls::AWB_ENABLE: { RPiController::AwbAlgorithm *awb = dynamic_cast( controller_.getAlgorithm("awb"));