{"id":13038,"url":"https://patchwork.libcamera.org/api/1.1/patches/13038/?format=json","web_url":"https://patchwork.libcamera.org/patch/13038/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210718185125.17472-3-david.plowman@raspberrypi.com>","date":"2021-07-18T18:51:25","name":"[libcamera-devel,v4,2/2] ipa: raspberrypi: AGC: handle modes with different sensitivities","commit_ref":"abaa45d627122205e838b1bd1f8c621efba2bbb0","pull_url":null,"state":"accepted","archived":false,"hash":"a8ce2caf6cd7694f6234a3b92aafa889451866d6","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/1.1/people/42/?format=json","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/13038/mbox/","series":[{"id":2251,"url":"https://patchwork.libcamera.org/api/1.1/series/2251/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2251","date":"2021-07-18T18:51:23","name":"Raspberrypi: support per-mode camera sensitivities","version":4,"mbox":"https://patchwork.libcamera.org/series/2251/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/13038/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13038/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 36FE8C3229\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 18 Jul 2021 18:51:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6F0FB68543;\n\tSun, 18 Jul 2021 20:51:32 +0200 (CEST)","from mail-wm1-x331.google.com (mail-wm1-x331.google.com\n\t[IPv6:2a00:1450:4864:20::331])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 79CC368521\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 18 Jul 2021 20:51:31 +0200 (CEST)","by mail-wm1-x331.google.com with SMTP id f190so7389877wmf.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 18 Jul 2021 11:51:31 -0700 (PDT)","from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72])\n\tby smtp.gmail.com with ESMTPSA id\n\to19sm17459634wmc.12.2021.07.18.11.51.30\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSun, 18 Jul 2021 11:51:30 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"VGLrKUJK\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=0bO8wlqoaF3DO4FeBDhDlKGfNfhap7UA/slY9vWYmm8=;\n\tb=VGLrKUJKkmAKk3BUsRM7pl7Wk2+MJklb2s/GEr4ZQK9h2KF3Ti6OyMr/NdvoCsrdrp\n\thCCiVN9fjJCG/YDg6Jhc/17eJ3Tw4beRsxOU3IAD3Cw35OaKSAGtGpMZ4nRgtd9SWiUf\n\txrkdFS8GDhdUw5VuZA3z3CcznHGgzqr2Nbi+nZNVUFCLfzai56tqE490cTbN6dYtl+3F\n\tS1I4zLqqUFNnEp7LpNLyolmxjMguJd4Sw6Nm2BJ/yX3f32r+1vVukkZ1bEu8aMbaHyih\n\tXrW2A4iY5d2d1ddQgyDxA/H95JqmwqQFSJqS4YEZERau01DjBsd9BWnJ0KZSIbW+sBKT\n\tOe2g==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=0bO8wlqoaF3DO4FeBDhDlKGfNfhap7UA/slY9vWYmm8=;\n\tb=mSCDIyZDmgEGk5otDwVU8GW0vhNUSh82qzq3l+KYn9vJNKICl2Ufb0vk9Orioi9HW+\n\t9X8YZ0SF82PSo7K0RsXduN/MfnGJ/3mhutBNMlPWWQtOstdE/lMXf2D/7/3t9GYkVAsW\n\tq6ocHH54af71BZJAihUizgtPc9P0R5BD5nTyVFmpqQnW41xsC+dc7YLQKIX4EZX2uCLF\n\tI5rxzQnL2hpnBJhUyuprRgxhae6XnWva8W5swmehn2S4ipaluy85CxqUcjYBJDZ8kSiF\n\tgT872UF67jeK5DR1VYYsA302a6pfrlk+OktYO9A8C60M9vI5ujO9fF6JATJ3C+Yo32qS\n\tC90A==","X-Gm-Message-State":"AOAM5332l+Ous1N39enX9NIfnaCJb7EPTBh4RMHlGrmjFGNb4fbceP4E\n\thwB3F9EkxG8C7+3OME2rpAiimA2vTgkoFYsi","X-Google-Smtp-Source":"ABdhPJzSXUc6dx85PM8NQBqkn1EGSmONDO8lTtDEcxxNTnaoodLfdFhXec+bTDR0lps1FjI3lVkR1Q==","X-Received":"by 2002:a7b:c850:: with SMTP id\n\tc16mr12592442wml.177.1626634291079; \n\tSun, 18 Jul 2021 11:51:31 -0700 (PDT)","From":"David Plowman <david.plowman@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Sun, 18 Jul 2021 19:51:25 +0100","Message-Id":"<20210718185125.17472-3-david.plowman@raspberrypi.com>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20210718185125.17472-1-david.plowman@raspberrypi.com>","References":"<20210718185125.17472-1-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 2/2] ipa: raspberrypi: AGC: handle\n\tmodes with different sensitivities","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"When the sensor is switched to a mode with a different sensitivity,\nthe target exposure values need to be adjusted proportionately to\nmaintain the same image brightness.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n---\n src/ipa/raspberrypi/controller/rpi/agc.cpp | 27 ++++++++++++++++++----\n src/ipa/raspberrypi/controller/rpi/agc.hpp |  1 +\n 2 files changed, 23 insertions(+), 5 deletions(-)","diff":"diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp\nindex f57783f8..1cfdd3bb 100644\n--- a/src/ipa/raspberrypi/controller/rpi/agc.cpp\n+++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp\n@@ -163,7 +163,7 @@ Agc::Agc(Controller *controller)\n \t: AgcAlgorithm(controller), metering_mode_(nullptr),\n \t  exposure_mode_(nullptr), constraint_mode_(nullptr),\n \t  frame_count_(0), lock_count_(0),\n-\t  last_target_exposure_(0s),\n+\t  last_target_exposure_(0s), last_sensitivity_(0.0),\n \t  ev_(1.0), flicker_period_(0s),\n \t  max_shutter_(0s), fixed_shutter_(0s), fixed_analogue_gain_(0.0)\n {\n@@ -268,9 +268,12 @@ void Agc::SetConstraintMode(std::string const &constraint_mode_name)\n \tconstraint_mode_name_ = constraint_mode_name;\n }\n \n-void Agc::SwitchMode([[maybe_unused]] CameraMode const &camera_mode,\n+void Agc::SwitchMode(CameraMode const &camera_mode,\n \t\t     Metadata *metadata)\n {\n+\t/* AGC expects the mode sensitivity always to be non-zero. */\n+\tASSERT(camera_mode.sensitivity);\n+\n \thousekeepConfig();\n \n \tDuration fixed_shutter = clipShutter(fixed_shutter_);\n@@ -292,9 +295,20 @@ void Agc::SwitchMode([[maybe_unused]] CameraMode const &camera_mode,\n \t\tfiltered_.shutter = fixed_shutter;\n \t\tfiltered_.analogue_gain = fixed_analogue_gain_;\n \t} else if (status_.total_exposure_value) {\n-\t\t// On a mode switch, it's possible the exposure profile could change,\n-\t\t// or a fixed exposure/gain might be set so we divide up the exposure/\n-\t\t// gain again, but we don't change any target values.\n+\t\t// On a mode switch, various things could happen:\n+\t\t// - the exposure profile might change\n+\t\t// - a fixed exposure or gain might be set\n+\t\t// - the new mode's sensitivity might be different\n+\t\t// We cope with the last of these by scaling the target values. After\n+\t\t// that we just need to re-divide the exposure/gain according to the\n+\t\t// current exposure profile, which takes care of everything else.\n+\n+\t\tdouble ratio = last_sensitivity_ / camera_mode.sensitivity;\n+\t\ttarget_.total_exposure_no_dg *= ratio;\n+\t\ttarget_.total_exposure *= ratio;\n+\t\tfiltered_.total_exposure_no_dg *= ratio;\n+\t\tfiltered_.total_exposure *= ratio;\n+\n \t\tdivideUpExposure();\n \t} else {\n \t\t// We come through here on startup, when at least one of the shutter\n@@ -308,6 +322,9 @@ void Agc::SwitchMode([[maybe_unused]] CameraMode const &camera_mode,\n \t}\n \n \twriteAndFinish(metadata, false);\n+\n+\t// We must remember the sensitivity of this mode for the next SwitchMode.\n+\tlast_sensitivity_ = camera_mode.sensitivity;\n }\n \n void Agc::Prepare(Metadata *image_metadata)\ndiff --git a/src/ipa/raspberrypi/controller/rpi/agc.hpp b/src/ipa/raspberrypi/controller/rpi/agc.hpp\nindex 85067dc6..82063636 100644\n--- a/src/ipa/raspberrypi/controller/rpi/agc.hpp\n+++ b/src/ipa/raspberrypi/controller/rpi/agc.hpp\n@@ -126,6 +126,7 @@ private:\n \tint lock_count_;\n \tDeviceStatus last_device_status_;\n \tlibcamera::utils::Duration last_target_exposure_;\n+\tdouble last_sensitivity_; // sensitivity of the previous camera mode\n \t// Below here the \"settings\" that applications can change.\n \tstd::string metering_mode_name_;\n \tstd::string exposure_mode_name_;\n","prefixes":["libcamera-devel","v4","2/2"]}