{"id":19037,"url":"https://patchwork.libcamera.org/api/patches/19037/?format=json","web_url":"https://patchwork.libcamera.org/patch/19037/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20230915155844.2388-5-david.plowman@raspberrypi.com>","date":"2023-09-15T15:58:43","name":"[libcamera-devel,v5,4/5] ipa: rpi: agc: Add AgcChannelConstraint class","commit_ref":"7927c4473529dc5a469cf6c707f1989e86792896","pull_url":null,"state":"accepted","archived":false,"hash":"e2ff1544b98cf0431a1c8b8000e8d00e3ea5debd","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/?format=json","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/19037/mbox/","series":[{"id":4026,"url":"https://patchwork.libcamera.org/api/series/4026/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4026","date":"2023-09-15T15:58:39","name":"Multi-channel AGC","version":5,"mbox":"https://patchwork.libcamera.org/series/4026/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/19037/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/19037/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 0C138BD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 15 Sep 2023 15:58:59 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2FC1162922;\n\tFri, 15 Sep 2023 17:58:58 +0200 (CEST)","from mail-wm1-x332.google.com (mail-wm1-x332.google.com\n\t[IPv6:2a00:1450:4864:20::332])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7B7AF6291C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 15 Sep 2023 17:58:55 +0200 (CEST)","by mail-wm1-x332.google.com with SMTP id\n\t5b1f17b1804b1-402d499580dso25007765e9.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 15 Sep 2023 08:58:55 -0700 (PDT)","from localhost.localdomain ([195.180.61.40])\n\tby smtp.gmail.com with ESMTPSA id\n\tl13-20020a7bc44d000000b00401c595fcc7sm7810618wmi.11.2023.09.15.08.58.54\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 15 Sep 2023 08:58:54 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1694793538;\n\tbh=5PzYmMOI5wAtHa3mMKkYWwZMOkHBy0H98iLwtngsCZI=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=DFQsLOIpqqsFZ9/Z9bspGHH5olGi7KIwZ5vWmMT/UJ/3rGJSvj59frOkXXUGHXHmH\n\tcKBIbHIH5WFq1AS0FYiJrKxK4AimLz+rds1iemvnGHscfa/9UQ9JbzJythw8C9bslL\n\tNXNcsNcnKy5zD4eSFiAZoYLT6LeN1z8xrqMn+SYlbKG+XgQYPztmN9eUZNgh9Ox48p\n\tKvQnUavgxUQGagEoOqtffd1dug3nLS6bClVTnI6qfWDHf6hXmN5fAFxWdn3L8igsn+\n\tSYFKntxSTMeI3bPThXc7pDidSsszxl00+eVgStqB0BSi3x57g5bMwnd5HA056ORQ18\n\tkrz0jJvbEWqWw==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1694793535; x=1695398335;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=L5ti10stfJGjHOx0NZCJZ7ipLRVCzaFb97PYLKAMgso=;\n\tb=C4KMXmcvDjDn1dQcfMhF5yqzECNpJoyzX4L0n116h/ZZO/Jm4X6foERnApE0OtJ+QL\n\t1prY3OvNr9/7EdRzyXVCR3ydL2sCDcXfKIr+lh+1BTz2yd8V3IBATuFvVyp9LOgm2oT2\n\tH6daYKS9JvD2aA+0WUl4VmDRPgiJcGrk9X/E7Nuc6UxDFe2fPjgmgOQof/wQZzGerEUH\n\tPF5qniIq6zT9Pm9nq5W5i3NDIDVuiL/QxfPPD8M0PUP35RmNm07vcnxARHc8YY/GhK1P\n\t/C0QuqW08BsN6rZniQm64HXFWfGf0zM9CnPQ2gcC2l2H4CPRDrHYNEk0MXXuasBcCZH9\n\t9LxA=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"C4KMXmcv\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1694793535; x=1695398335;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=L5ti10stfJGjHOx0NZCJZ7ipLRVCzaFb97PYLKAMgso=;\n\tb=VVKj75qVJbaOFP5z1FyJdwxYLnxEgEuq6Z+R5eWF7ywmMyK53suzVfNX/0DHUSxgjV\n\ts9qt8zYrrrnYG7Yza5nNOYtz+X0moqKGtVYvorpi4JBvPO9JxAOpRYZ79bclg2Fltk0Z\n\tIe+ZBAQCo6+d2E9cMVXsCuDVRMv/EEM6R8hKkUMGStx7iyZv4Lv61LikcD+mPIrp/RvX\n\tuypEMJRd9J7dQkUlSHqwxkIEsaOISII3EUCKJ5x68gOfgeNk6aG3r+DLjZDhit4K/E6m\n\tvD88LkjwJMnlL4VGs+DFzK5OYCShuu9pCxiRDAIUhpBXPDzU3SCfT/QExXxC6I90N5fO\n\tAbDg==","X-Gm-Message-State":"AOJu0YzpPSRIxBicEGMLgHIjWeh96bc6DjgKYCWZY70eW/96NMMr3QPD\n\tCXf4iV/K7GY5tedNuQc0BfMrTMzqV/tiVknuem8=","X-Google-Smtp-Source":"AGHT+IGLeC++Kp1wkV7LzaDbMCZwk9g48Mhc4qdfpHUbcG5BG1LnKTbcpoymWuEpg+ofjoRc274qjg==","X-Received":"by 2002:a1c:7706:0:b0:401:2ee0:754a with SMTP id\n\tt6-20020a1c7706000000b004012ee0754amr2109767wmi.13.1694793534728; \n\tFri, 15 Sep 2023 08:58:54 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 15 Sep 2023 16:58:43 +0100","Message-Id":"<20230915155844.2388-5-david.plowman@raspberrypi.com>","X-Mailer":"git-send-email 2.30.2","In-Reply-To":"<20230915155844.2388-1-david.plowman@raspberrypi.com>","References":"<20230915155844.2388-1-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v5 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":"David Plowman via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"David Plowman <david.plowman@raspberrypi.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"A channel constraint is somewhat similar to the upper/lower bound\nconstraints that we use elsewhere, but these constraints apply between\nmultiple AGC channels. For example, it lets you say things like \"don't\nlet the channel 1 total exposure be more than 8x that of channel 0\",\nand so on. By using both an upper and lower bound constraint, you\ncould fix one AGC channel always to be a fixed ratio of another.\n\nAlso read a vector of them (if present) when loading the tuning file.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\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(+)","diff":"diff --git a/src/ipa/rpi/controller/rpi/agc_channel.cpp b/src/ipa/rpi/controller/rpi/agc_channel.cpp\nindex 84eafe7d..dfe363ff 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;\ndiff --git a/src/ipa/rpi/controller/rpi/agc_channel.h b/src/ipa/rpi/controller/rpi/agc_channel.h\nindex b2f554db..ceaab12f 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","prefixes":["libcamera-devel","v5","4/5"]}