From patchwork Fri Nov 24 16:37:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 19241 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 25E52C3220 for ; Fri, 24 Nov 2023 16:37:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 778EB629AF; Fri, 24 Nov 2023 17:37:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1700843868; bh=QLhvlBoYetsRjFQH4aRRlc00zTNY4i7v3mj4vM25FLU=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=WzaU+VqOp+cyLGCKBKtEwM8R4ZpYdYhunE0S0S8PgFAXqCPDCegdXUKSMT2IBPY3u 57I9l4HyHwaKMip9aer8d6XWu8UqB1rChXzRM4+55HlI2pe2CCmAJOMECqiculW82X SFJD5SOdqVYI4/9Gn94pz0KFAXkcOwb+LXCieSPTSUZsVJSry0gRqzr0BA474l+jCt +Ys73P18EFQXfNYqF6gwfIlXRRfPXLBTsxselIOAy78zBfcnaetSLxGrOw29ru2+af PZ++dFK+9OEOlhj5/HL+pjIJ6Tp48P9vEGALU+cPOR7prIqwvjQWCNJX5BvQsR21Vg I7HOQ0Cqy+9sg== Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 74E4461DAB for ; Fri, 24 Nov 2023 17:37:46 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="sYDlAhg/"; dkim-atps=neutral Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-40a4848c6e1so14420835e9.1 for ; Fri, 24 Nov 2023 08:37:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1700843865; x=1701448665; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=hZFq6vFD/WOJzp80m0vTYWwTxXPgobt6HfOVapjjSHs=; b=sYDlAhg/1L9CUYdxumaNZVd9zPzxabSo8RQ18yK8t7nLVZ0/lFkqbx4T9Ylfc4+xV9 JFIYZbjyBdo/2g0lhbMr8+ht0D8URbwi965HmmsbowFzJwaPcwvFIiML+/j4yq4iOARb xk+RUoq5IlcRt9r185sqlWkyD6B3JpZRr4QBlXrdS7Ff2RoPKl3QBLXk/5OoM7DzQW6j 88UgoxWoQXK9wlN6TNfhLFxLANUieOwrcbYwXzXEytS48pggQSGUyyFj8vQF4htjbOat 7aMeNqoEbtIWKIqJw+2aEApl+w4rgqIpk40JYlkHjfFJCO5ySQ+y2gbEW1frnWj0Pymp Bbjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700843865; x=1701448665; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hZFq6vFD/WOJzp80m0vTYWwTxXPgobt6HfOVapjjSHs=; b=SfwAkgsl/MO7sdnt8vdqORo+94z/ywu9uyb/Bp8lVIUIYJHj1nj0Tug2kUM3e/Qv+w P+nh/JroaEMtxOww1HzuWb/y2V+hKUvYl1UOLBRsf7j3yjxM2SH2pD6iFAwF3FYXhLCL 9IZfNvKoXkrkXpeJ4+YdPAPq6zTAfy9H3uKR/uCvPTKqcsaSwbg77o7vPxdy5AUE54hP kOvjrTGvtB8AELS/fOkmZk7kv/swdmBmJ17fNsWnM4b/hdWuX9LbsxHrwDHqwu/lnkkR OXLmEpEfa3ey9ssiHnzwBv7J+1NjniTZzeNewhq5pApDkitAZ1a0qW3lqwc1ZaKQj3MR 0tGA== X-Gm-Message-State: AOJu0YwtMe6JT7v2O4k2vyS73WN7LQ+UI76EqKPWxgHjQbqRIkZZjVGl D6tRROX4RakB3UOADvp6tm3M13C7XuYVOAwFoHE= X-Google-Smtp-Source: AGHT+IGk/qPyDVVjCWvqqeUU8IVdhay2u8PjFAxN4I6sVMUoflxBjnZJkUAmPkQDs20uXl8ahCw1dQ== X-Received: by 2002:a05:600c:1d89:b0:407:4944:76d1 with SMTP id p9-20020a05600c1d8900b00407494476d1mr2810795wms.17.1700843865400; Fri, 24 Nov 2023 08:37:45 -0800 (PST) Received: from localhost.localdomain ([194.233.231.115]) by smtp.gmail.com with ESMTPSA id u4-20020a05600c138400b004065e235417sm6267970wmf.21.2023.11.24.08.37.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 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 Subject: [libcamera-devel] [PATCH] ipa: rpi: cac: Minor code improvements and tidying 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 make a few small improvements to the code: * The arrayToSet method is prevented from overwriting the end of the array if there are too many values in the input table. If you supply a table, it will force you to put the correct number of elements in it. * The arrayToSet and setStrength member functions are turned into static functions. (There may be a different public setStrength member function in future.) * When no tables at all are given, the configuration is flagged as being disabled, so that we can avoid copying tables full of zeroes around. As a consequence, the pipeline handler too will disable this hardware block rather than run it needlessly. (Note that the tuning tool will put in a completely empty "rpi.cac" block if no CAC tuning images are supplied, benefiting from this behaviour.) * The initialise member function is removed as it does nothing. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck Reviewed-by: Kieran Bingham --- src/ipa/rpi/controller/rpi/cac.cpp | 82 ++++++++++++++++++++---------- src/ipa/rpi/controller/rpi/cac.h | 5 +- 2 files changed, 55 insertions(+), 32 deletions(-) diff --git a/src/ipa/rpi/controller/rpi/cac.cpp b/src/ipa/rpi/controller/rpi/cac.cpp index 7c123da1..f2c8d282 100644 --- a/src/ipa/rpi/controller/rpi/cac.cpp +++ b/src/ipa/rpi/controller/rpi/cac.cpp @@ -27,40 +27,23 @@ char const *Cac::name() const return NAME; } -int Cac::read(const libcamera::YamlObject ¶ms) -{ - arrayToSet(params["lut_rx"], config_.lutRx); - arrayToSet(params["lut_ry"], config_.lutRy); - arrayToSet(params["lut_bx"], config_.lutBx); - arrayToSet(params["lut_by"], config_.lutBy); - cacStatus_.lutRx = config_.lutRx; - cacStatus_.lutRy = config_.lutRy; - cacStatus_.lutBx = config_.lutBx; - cacStatus_.lutBy = config_.lutBy; - double strength = params["strength"].get(1); - setStrength(config_.lutRx, cacStatus_.lutRx, strength); - setStrength(config_.lutBx, cacStatus_.lutBx, strength); - setStrength(config_.lutRy, cacStatus_.lutRy, strength); - setStrength(config_.lutBy, cacStatus_.lutBy, strength); - return 0; -} - -void Cac::initialise() -{ -} - -void Cac::arrayToSet(const libcamera::YamlObject ¶ms, std::vector &inputArray) +static bool arrayToSet(const libcamera::YamlObject ¶ms, std::vector &inputArray, const Size &size) { int num = 0; - const Size &size = getHardwareConfig().cacRegions; - inputArray.resize((size.width + 1) * (size.height + 1)); + int max_num = (size.width + 1) * (size.height + 1); + inputArray.resize(max_num); + for (const auto &p : params.asList()) { + if (num == max_num) + return false; inputArray[num++] = p.get(0); } + + return num == max_num; } -void Cac::setStrength(std::vector &inputArray, std::vector &outputArray, - double strengthFactor) +static void setStrength(std::vector &inputArray, std::vector &outputArray, + double strengthFactor) { int num = 0; for (const auto &p : inputArray) { @@ -68,9 +51,52 @@ void Cac::setStrength(std::vector &inputArray, std::vector &outp } } +int Cac::read(const libcamera::YamlObject ¶ms) +{ + config_.enabled = params.contains("lut_rx") && params.contains("lut_ry") && + params.contains("lut_bx") && params.contains("lut_by"); + if (!config_.enabled) + return 0; + + const Size &size = getHardwareConfig().cacRegions; + + if (!arrayToSet(params["lut_rx"], config_.lutRx, size)) { + LOG(RPiCac, Error) << "Bad CAC lut_rx table"; + return -EINVAL; + } + + if (!arrayToSet(params["lut_ry"], config_.lutRy, size)) { + LOG(RPiCac, Error) << "Bad CAC lut_ry table"; + return -EINVAL; + } + + if (!arrayToSet(params["lut_bx"], config_.lutBx, size)) { + LOG(RPiCac, Error) << "Bad CAC lut_bx table"; + return -EINVAL; + } + + if (!arrayToSet(params["lut_by"], config_.lutBy, size)) { + LOG(RPiCac, Error) << "Bad CAC lut_by table"; + return -EINVAL; + } + + double strength = params["strength"].get(1); + cacStatus_.lutRx = config_.lutRx; + cacStatus_.lutRy = config_.lutRy; + cacStatus_.lutBx = config_.lutBx; + cacStatus_.lutBy = config_.lutBy; + setStrength(config_.lutRx, cacStatus_.lutRx, strength); + setStrength(config_.lutBx, cacStatus_.lutBx, strength); + setStrength(config_.lutRy, cacStatus_.lutRy, strength); + setStrength(config_.lutBy, cacStatus_.lutBy, strength); + + return 0; +} + void Cac::prepare(Metadata *imageMetadata) { - imageMetadata->set("cac.status", cacStatus_); + if (config_.enabled) + imageMetadata->set("cac.status", cacStatus_); } // Register algorithm with the system. diff --git a/src/ipa/rpi/controller/rpi/cac.h b/src/ipa/rpi/controller/rpi/cac.h index 419180ab..a7b14c00 100644 --- a/src/ipa/rpi/controller/rpi/cac.h +++ b/src/ipa/rpi/controller/rpi/cac.h @@ -12,6 +12,7 @@ namespace RPiController { struct CacConfig { + bool enabled; std::vector lutRx; std::vector lutRy; std::vector lutBx; @@ -24,15 +25,11 @@ public: Cac(Controller *controller = NULL); char const *name() const override; int read(const libcamera::YamlObject ¶ms) override; - void initialise() override; void prepare(Metadata *imageMetadata) override; - void setStrength(std::vector &inputArray, std::vector &outputArray, - double strengthFactor); private: CacConfig config_; CacStatus cacStatus_; - void arrayToSet(const libcamera::YamlObject ¶ms, std::vector &inputArray); }; } // namespace RPiController