{"id":19241,"url":"https://patchwork.libcamera.org/api/patches/19241/?format=json","web_url":"https://patchwork.libcamera.org/patch/19241/","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":"<20231124163742.54660-1-david.plowman@raspberrypi.com>","date":"2023-11-24T16:37:42","name":"[libcamera-devel] ipa: rpi: cac: Minor code improvements and tidying","commit_ref":"8e215127c195b61a7cc787103b129a3af8e5ad2c","pull_url":null,"state":"accepted","archived":false,"hash":"380e8704fa684f036ba5f4d0a5ece424ef90bfc1","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/19241/mbox/","series":[{"id":4085,"url":"https://patchwork.libcamera.org/api/series/4085/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4085","date":"2023-11-24T16:37:42","name":"[libcamera-devel] ipa: rpi: cac: Minor code improvements and tidying","version":1,"mbox":"https://patchwork.libcamera.org/series/4085/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/19241/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/19241/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 25E52C3220\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 24 Nov 2023 16:37:49 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 778EB629AF;\n\tFri, 24 Nov 2023 17:37:48 +0100 (CET)","from mail-wm1-x335.google.com (mail-wm1-x335.google.com\n\t[IPv6:2a00:1450:4864:20::335])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 74E4461DAB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Nov 2023 17:37:46 +0100 (CET)","by mail-wm1-x335.google.com with SMTP id\n\t5b1f17b1804b1-40a4848c6e1so14420835e9.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Nov 2023 08:37:46 -0800 (PST)","from localhost.localdomain ([194.233.231.115])\n\tby smtp.gmail.com with ESMTPSA id\n\tu4-20020a05600c138400b004065e235417sm6267970wmf.21.2023.11.24.08.37.44\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 24 Nov 2023 08:37:45 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1700843868;\n\tbh=QLhvlBoYetsRjFQH4aRRlc00zTNY4i7v3mj4vM25FLU=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:From;\n\tb=WzaU+VqOp+cyLGCKBKtEwM8R4ZpYdYhunE0S0S8PgFAXqCPDCegdXUKSMT2IBPY3u\n\t57I9l4HyHwaKMip9aer8d6XWu8UqB1rChXzRM4+55HlI2pe2CCmAJOMECqiculW82X\n\tSFJD5SOdqVYI4/9Gn94pz0KFAXkcOwb+LXCieSPTSUZsVJSry0gRqzr0BA474l+jCt\n\t+Ys73P18EFQXfNYqF6gwfIlXRRfPXLBTsxselIOAy78zBfcnaetSLxGrOw29ru2+af\n\tPZ++dFK+9OEOlhj5/HL+pjIJ6Tp48P9vEGALU+cPOR7prIqwvjQWCNJX5BvQsR21Vg\n\tI7HOQ0Cqy+9sg==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1700843865; x=1701448665;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:from:to:cc:subject:date:message-id:reply-to;\n\tbh=hZFq6vFD/WOJzp80m0vTYWwTxXPgobt6HfOVapjjSHs=;\n\tb=sYDlAhg/1L9CUYdxumaNZVd9zPzxabSo8RQ18yK8t7nLVZ0/lFkqbx4T9Ylfc4+xV9\n\tJFIYZbjyBdo/2g0lhbMr8+ht0D8URbwi965HmmsbowFzJwaPcwvFIiML+/j4yq4iOARb\n\txk+RUoq5IlcRt9r185sqlWkyD6B3JpZRr4QBlXrdS7Ff2RoPKl3QBLXk/5OoM7DzQW6j\n\t88UgoxWoQXK9wlN6TNfhLFxLANUieOwrcbYwXzXEytS48pggQSGUyyFj8vQF4htjbOat\n\t7aMeNqoEbtIWKIqJw+2aEApl+w4rgqIpk40JYlkHjfFJCO5ySQ+y2gbEW1frnWj0Pymp\n\tBbjg=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"sYDlAhg/\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1700843865; x=1701448665;\n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=hZFq6vFD/WOJzp80m0vTYWwTxXPgobt6HfOVapjjSHs=;\n\tb=SfwAkgsl/MO7sdnt8vdqORo+94z/ywu9uyb/Bp8lVIUIYJHj1nj0Tug2kUM3e/Qv+w\n\tP+nh/JroaEMtxOww1HzuWb/y2V+hKUvYl1UOLBRsf7j3yjxM2SH2pD6iFAwF3FYXhLCL\n\t9IZfNvKoXkrkXpeJ4+YdPAPq6zTAfy9H3uKR/uCvPTKqcsaSwbg77o7vPxdy5AUE54hP\n\tkOvjrTGvtB8AELS/fOkmZk7kv/swdmBmJ17fNsWnM4b/hdWuX9LbsxHrwDHqwu/lnkkR\n\tOXLmEpEfa3ey9ssiHnzwBv7J+1NjniTZzeNewhq5pApDkitAZ1a0qW3lqwc1ZaKQj3MR\n\t0tGA==","X-Gm-Message-State":"AOJu0YwtMe6JT7v2O4k2vyS73WN7LQ+UI76EqKPWxgHjQbqRIkZZjVGl\n\tD6tRROX4RakB3UOADvp6tm3M13C7XuYVOAwFoHE=","X-Google-Smtp-Source":"AGHT+IGk/qPyDVVjCWvqqeUU8IVdhay2u8PjFAxN4I6sVMUoflxBjnZJkUAmPkQDs20uXl8ahCw1dQ==","X-Received":"by 2002:a05:600c:1d89:b0:407:4944:76d1 with SMTP id\n\tp9-20020a05600c1d8900b00407494476d1mr2810795wms.17.1700843865400; \n\tFri, 24 Nov 2023 08:37:45 -0800 (PST)","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 24 Nov 2023 16:37:42 +0000","Message-Id":"<20231124163742.54660-1-david.plowman@raspberrypi.com>","X-Mailer":"git-send-email 2.39.2","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH] ipa: rpi: cac: Minor code improvements\n\tand tidying","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"We make a few small improvements to the code:\n\n* The arrayToSet method is prevented from overwriting the end of the\n  array if there are too many values in the input table. If you supply\n  a table, it will force you to put the correct number of elements in\n  it.\n\n* The arrayToSet and setStrength member functions are turned into\n  static functions. (There may be a different public setStrength\n  member function in future.)\n\n* When no tables at all are given, the configuration is flagged as\n  being disabled, so that we can avoid copying tables full of zeroes\n  around. As a consequence, the pipeline handler too will disable this\n  hardware block rather than run it needlessly. (Note that the tuning\n  tool will put in a completely empty \"rpi.cac\" block if no CAC tuning\n  images are supplied, benefiting from this behaviour.)\n\n* The initialise member function is removed as it does nothing.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n src/ipa/rpi/controller/rpi/cac.cpp | 82 ++++++++++++++++++++----------\n src/ipa/rpi/controller/rpi/cac.h   |  5 +-\n 2 files changed, 55 insertions(+), 32 deletions(-)","diff":"diff --git a/src/ipa/rpi/controller/rpi/cac.cpp b/src/ipa/rpi/controller/rpi/cac.cpp\nindex 7c123da1..f2c8d282 100644\n--- a/src/ipa/rpi/controller/rpi/cac.cpp\n+++ b/src/ipa/rpi/controller/rpi/cac.cpp\n@@ -27,40 +27,23 @@ char const *Cac::name() const\n \treturn NAME;\n }\n \n-int Cac::read(const libcamera::YamlObject &params)\n-{\n-\tarrayToSet(params[\"lut_rx\"], config_.lutRx);\n-\tarrayToSet(params[\"lut_ry\"], config_.lutRy);\n-\tarrayToSet(params[\"lut_bx\"], config_.lutBx);\n-\tarrayToSet(params[\"lut_by\"], config_.lutBy);\n-\tcacStatus_.lutRx = config_.lutRx;\n-\tcacStatus_.lutRy = config_.lutRy;\n-\tcacStatus_.lutBx = config_.lutBx;\n-\tcacStatus_.lutBy = config_.lutBy;\n-\tdouble strength = params[\"strength\"].get<double>(1);\n-\tsetStrength(config_.lutRx, cacStatus_.lutRx, strength);\n-\tsetStrength(config_.lutBx, cacStatus_.lutBx, strength);\n-\tsetStrength(config_.lutRy, cacStatus_.lutRy, strength);\n-\tsetStrength(config_.lutBy, cacStatus_.lutBy, strength);\n-\treturn 0;\n-}\n-\n-void Cac::initialise()\n-{\n-}\n-\n-void Cac::arrayToSet(const libcamera::YamlObject &params, std::vector<double> &inputArray)\n+static bool arrayToSet(const libcamera::YamlObject &params, std::vector<double> &inputArray, const Size &size)\n {\n \tint num = 0;\n-\tconst Size &size = getHardwareConfig().cacRegions;\n-\tinputArray.resize((size.width + 1) * (size.height + 1));\n+\tint max_num = (size.width + 1) * (size.height + 1);\n+\tinputArray.resize(max_num);\n+\n \tfor (const auto &p : params.asList()) {\n+\t\tif (num == max_num)\n+\t\t\treturn false;\n \t\tinputArray[num++] = p.get<double>(0);\n \t}\n+\n+\treturn num == max_num;\n }\n \n-void Cac::setStrength(std::vector<double> &inputArray, std::vector<double> &outputArray,\n-\t\t      double strengthFactor)\n+static void setStrength(std::vector<double> &inputArray, std::vector<double> &outputArray,\n+\t\t\tdouble strengthFactor)\n {\n \tint num = 0;\n \tfor (const auto &p : inputArray) {\n@@ -68,9 +51,52 @@ void Cac::setStrength(std::vector<double> &inputArray, std::vector<double> &outp\n \t}\n }\n \n+int Cac::read(const libcamera::YamlObject &params)\n+{\n+\tconfig_.enabled = params.contains(\"lut_rx\") && params.contains(\"lut_ry\") &&\n+\t\t\t  params.contains(\"lut_bx\") && params.contains(\"lut_by\");\n+\tif (!config_.enabled)\n+\t\treturn 0;\n+\n+\tconst Size &size = getHardwareConfig().cacRegions;\n+\n+\tif (!arrayToSet(params[\"lut_rx\"], config_.lutRx, size)) {\n+\t\tLOG(RPiCac, Error) << \"Bad CAC lut_rx table\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (!arrayToSet(params[\"lut_ry\"], config_.lutRy, size)) {\n+\t\tLOG(RPiCac, Error) << \"Bad CAC lut_ry table\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (!arrayToSet(params[\"lut_bx\"], config_.lutBx, size)) {\n+\t\tLOG(RPiCac, Error) << \"Bad CAC lut_bx table\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (!arrayToSet(params[\"lut_by\"], config_.lutBy, size)) {\n+\t\tLOG(RPiCac, Error) << \"Bad CAC lut_by table\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tdouble strength = params[\"strength\"].get<double>(1);\n+\tcacStatus_.lutRx = config_.lutRx;\n+\tcacStatus_.lutRy = config_.lutRy;\n+\tcacStatus_.lutBx = config_.lutBx;\n+\tcacStatus_.lutBy = config_.lutBy;\n+\tsetStrength(config_.lutRx, cacStatus_.lutRx, strength);\n+\tsetStrength(config_.lutBx, cacStatus_.lutBx, strength);\n+\tsetStrength(config_.lutRy, cacStatus_.lutRy, strength);\n+\tsetStrength(config_.lutBy, cacStatus_.lutBy, strength);\n+\n+\treturn 0;\n+}\n+\n void Cac::prepare(Metadata *imageMetadata)\n {\n-\timageMetadata->set(\"cac.status\", cacStatus_);\n+\tif (config_.enabled)\n+\t\timageMetadata->set(\"cac.status\", cacStatus_);\n }\n \n // Register algorithm with the system.\ndiff --git a/src/ipa/rpi/controller/rpi/cac.h b/src/ipa/rpi/controller/rpi/cac.h\nindex 419180ab..a7b14c00 100644\n--- a/src/ipa/rpi/controller/rpi/cac.h\n+++ b/src/ipa/rpi/controller/rpi/cac.h\n@@ -12,6 +12,7 @@\n namespace RPiController {\n \n struct CacConfig {\n+\tbool enabled;\n \tstd::vector<double> lutRx;\n \tstd::vector<double> lutRy;\n \tstd::vector<double> lutBx;\n@@ -24,15 +25,11 @@ public:\n \tCac(Controller *controller = NULL);\n \tchar const *name() const override;\n \tint read(const libcamera::YamlObject &params) override;\n-\tvoid initialise() override;\n \tvoid prepare(Metadata *imageMetadata) override;\n-\tvoid setStrength(std::vector<double> &inputArray, std::vector<double> &outputArray,\n-\t\t\t double strengthFactor);\n \n private:\n \tCacConfig config_;\n \tCacStatus cacStatus_;\n-\tvoid arrayToSet(const libcamera::YamlObject &params, std::vector<double> &inputArray);\n };\n \n } // namespace RPiController\n","prefixes":["libcamera-devel"]}