[{"id":27764,"web_url":"https://patchwork.libcamera.org/comment/27764/","msgid":"<wh7vvp3ixqiyuqutdv67vuezc765gkkyxvwshz4elfctmantbk@fb6ay3rnh44x>","date":"2023-09-12T15:07:55","subject":"Re: [libcamera-devel] [PATCH v3 4/5] ipa: rpi: agc: Add\n\tAgcChannelConstraint class","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi David\n\nOn Tue, Sep 12, 2023 at 11:24:41AM +0100, David Plowman via libcamera-devel wrote:\n> A channel constraint is somewhat similar to the upper/lower bound\n> constraints that we use elsewhere, but these constraints apply between\n> multiple AGC channels. For example, it lets you say things like \"don't\n> let the channel 1 total exposure be more than 8x that of channel 0\",\n> and so on. By using both an upper and lower bound constraint, you\n> could fix one AGC channel always to be a fixed ratio of another.\n>\n> Also read a vector of them (if present) when loading the tuning file.\n>\n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n> Reviewed-by: Naushir Patuck <naush@raspberrypi.com>\n\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\nThanks\n  j\n\n> ---\n>  src/ipa/rpi/controller/rpi/agc_channel.cpp | 49 ++++++++++++++++++++++\n>  src/ipa/rpi/controller/rpi/agc_channel.h   | 10 +++++\n>  2 files changed, 59 insertions(+)\n>\n> diff --git a/src/ipa/rpi/controller/rpi/agc_channel.cpp b/src/ipa/rpi/controller/rpi/agc_channel.cpp\n> index f1f19598..7fce35b0 100644\n> --- a/src/ipa/rpi/controller/rpi/agc_channel.cpp\n> +++ b/src/ipa/rpi/controller/rpi/agc_channel.cpp\n> @@ -170,6 +170,49 @@ readConstraintModes(std::map<std::string, AgcConstraintMode> &constraintModes,\n>  \treturn { 0, first };\n>  }\n>\n> +int AgcChannelConstraint::read(const libcamera::YamlObject &params)\n> +{\n> +\tauto channelValue = params[\"channel\"].get<unsigned int>();\n> +\tif (!channelValue) {\n> +\t\tLOG(RPiAgc, Error) << \"AGC channel constraint must have a channel\";\n> +\t\treturn -EINVAL;\n> +\t}\n> +\tchannel = *channelValue;\n> +\n> +\tstd::string boundString = params[\"bound\"].get<std::string>(\"\");\n> +\ttransform(boundString.begin(), boundString.end(),\n> +\t\t  boundString.begin(), ::toupper);\n> +\tif (boundString != \"UPPER\" && boundString != \"LOWER\") {\n> +\t\tLOG(RPiAgc, Error) << \"AGC channel constraint type should be UPPER or LOWER\";\n> +\t\treturn -EINVAL;\n> +\t}\n> +\tbound = boundString == \"UPPER\" ? Bound::UPPER : Bound::LOWER;\n> +\n> +\tauto factorValue = params[\"factor\"].get<double>();\n> +\tif (!factorValue) {\n> +\t\tLOG(RPiAgc, Error) << \"AGC channel constraint must have a factor\";\n> +\t\treturn -EINVAL;\n> +\t}\n> +\tfactor = *factorValue;\n> +\n> +\treturn 0;\n> +}\n> +\n> +static int readChannelConstraints(std::vector<AgcChannelConstraint> &channelConstraints,\n> +\t\t\t\t  const libcamera::YamlObject &params)\n> +{\n> +\tfor (const auto &p : params.asList()) {\n> +\t\tAgcChannelConstraint constraint;\n> +\t\tint ret = constraint.read(p);\n> +\t\tif (ret)\n> +\t\t\treturn ret;\n> +\n> +\t\tchannelConstraints.push_back(constraint);\n> +\t}\n> +\n> +\treturn 0;\n> +}\n> +\n>  int AgcConfig::read(const libcamera::YamlObject &params)\n>  {\n>  \tLOG(RPiAgc, Debug) << \"AgcConfig\";\n> @@ -188,6 +231,12 @@ int AgcConfig::read(const libcamera::YamlObject &params)\n>  \tif (ret)\n>  \t\treturn ret;\n>\n> +\tif (params.contains(\"channel_constraints\")) {\n> +\t\tret = readChannelConstraints(channelConstraints, params[\"channel_constraints\"]);\n> +\t\tif (ret)\n> +\t\t\treturn ret;\n> +\t}\n> +\n>  \tret = yTarget.read(params[\"y_target\"]);\n>  \tif (ret)\n>  \t\treturn ret;\n> diff --git a/src/ipa/rpi/controller/rpi/agc_channel.h b/src/ipa/rpi/controller/rpi/agc_channel.h\n> index 24ee3491..5d2d8a11 100644\n> --- a/src/ipa/rpi/controller/rpi/agc_channel.h\n> +++ b/src/ipa/rpi/controller/rpi/agc_channel.h\n> @@ -44,11 +44,21 @@ struct AgcConstraint {\n>\n>  typedef std::vector<AgcConstraint> AgcConstraintMode;\n>\n> +struct AgcChannelConstraint {\n> +\tenum class Bound { LOWER = 0,\n> +\t\t\t   UPPER = 1 };\n> +\tBound bound;\n> +\tunsigned int channel;\n> +\tdouble factor;\n> +\tint read(const libcamera::YamlObject &params);\n> +};\n> +\n>  struct AgcConfig {\n>  \tint read(const libcamera::YamlObject &params);\n>  \tstd::map<std::string, AgcMeteringMode> meteringModes;\n>  \tstd::map<std::string, AgcExposureMode> exposureModes;\n>  \tstd::map<std::string, AgcConstraintMode> constraintModes;\n> +\tstd::vector<AgcChannelConstraint> channelConstraints;\n>  \tPwl yTarget;\n>  \tdouble speed;\n>  \tuint16_t startupFrames;\n> --\n> 2.30.2\n>","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 0175CBD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 12 Sep 2023 15:08:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AC3F7628F2;\n\tTue, 12 Sep 2023 17:08:00 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 47E7561DF5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 12 Sep 2023 17:07:59 +0200 (CEST)","from ideasonboard.com (mob-5-90-67-213.net.vodafone.it\n\t[5.90.67.213])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D181B512;\n\tTue, 12 Sep 2023 17:06:27 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1694531280;\n\tbh=R5pe8gcM7M5InLAQ6EW86qmMU0betV9Co9pUZoz/0rk=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=gxz6XGAjCvUhH1Fc/UAk7toUfCbUmqsrKR8dyOzSHlQ68JRF2CwY1yGucqthRLtIY\n\tsaLh6g8EDyJDXr2zF7Kl4tMzgOHtCnAvCu/um54DyropR7ouuBkZ8HrJSol5xPOuNI\n\tX5tCjMQhDK8GrAp5iIEh9qlRtHNU7IrUdQLAt1zj1qUNCETGR9Ah7equpukAAoc2eN\n\t2k4eEXp2w3oB8+TNVg4B/Lk2OwAt/ElNBHBi48NUNUZUvL8Ba1MG/okgJCU3Rv6W1d\n\tJcYSscVfSLFaQeVzEu0migpz3CjawN7+LNjmFjinlf+V21o53ktfA8alw3OgjFAOmB\n\twzBdNVjPfV/Mw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1694531188;\n\tbh=R5pe8gcM7M5InLAQ6EW86qmMU0betV9Co9pUZoz/0rk=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=nB8DarbuqQhN040770Z32ZdLBjcLkp8XdhZskka9BwF7vlgWR7MvkbKtdudfzwxRM\n\t/ubahIli8VdkT1tujSn3Cy6NljRv69L0e0Q1Xc/78RZAVUXxu4RhcIE6H7lgSYqDP3\n\teW1bO+tIHJVa+Xf0zhj+wBvwQkSPuga+36ue6nTw="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"nB8Darbu\"; dkim-atps=neutral","Date":"Tue, 12 Sep 2023 17:07:55 +0200","To":"David Plowman <david.plowman@raspberrypi.com>","Message-ID":"<wh7vvp3ixqiyuqutdv67vuezc765gkkyxvwshz4elfctmantbk@fb6ay3rnh44x>","References":"<20230912102442.169001-1-david.plowman@raspberrypi.com>\n\t<20230912102442.169001-5-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20230912102442.169001-5-david.plowman@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH v3 4/5] ipa: rpi: agc: Add\n\tAgcChannelConstraint class","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>","From":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]