[{"id":36354,"web_url":"https://patchwork.libcamera.org/comment/36354/","msgid":"<176095405961.336133.6969223934708244720@localhost>","date":"2025-10-20T09:54:19","subject":"Re: [PATCH 2/5] ipa: rpi: lux: Handle camera mode sensitivity\n\tcorrectly","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"content":"Hi David,\n\nQuoting David Plowman (2025-10-17 12:05:38)\n> The camera mode sensitivity needs to be taken into account for the lux\n> calculation. For example, the IMX708 binned mode (with a sensitivity\n> of 2.0) would otherwise show double the correct lux value.\n\nThat makes a lot of sense and we need to port that over to other\npipeline handlers as well. On the imx708 I see a heuristic to decide on\nthe sensitivity based on the image width. That doesn't go too well with\narbitrary cropping in the upcoming raw sensor models. Do you envision a\ngeneric way to carry that information?\n\nMaybe something that could tie into my thoughts here?\nhttps://lore.kernel.org/linux-media/176009169065.211618.2319574445990293219@localhost/\n\nI would love to hear your opinion on that.\n\n> \n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n\nThe patch itself looks good to me.\n\nReviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\nBest regards,\nStefan\n\n> ---\n>  src/ipa/rpi/controller/rpi/lux.cpp | 13 +++++++++++--\n>  src/ipa/rpi/controller/rpi/lux.h   |  3 +++\n>  2 files changed, 14 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/ipa/rpi/controller/rpi/lux.cpp b/src/ipa/rpi/controller/rpi/lux.cpp\n> index 27b89a8f..acaa6e57 100644\n> --- a/src/ipa/rpi/controller/rpi/lux.cpp\n> +++ b/src/ipa/rpi/controller/rpi/lux.cpp\n> @@ -20,7 +20,7 @@ LOG_DEFINE_CATEGORY(RPiLux)\n>  #define NAME \"rpi.lux\"\n>  \n>  Lux::Lux(Controller *controller)\n> -       : Algorithm(controller)\n> +       : Algorithm(controller), sensitivity_(1.0)\n>  {\n>         /*\n>          * Put in some defaults as there will be no meaningful values until\n> @@ -68,6 +68,13 @@ void Lux::setCurrentAperture(double aperture)\n>         currentAperture_ = aperture;\n>  }\n>  \n> +void Lux::switchMode(CameraMode const &cameraMode, [[maybe_unused]] Metadata *metadata)\n> +{\n> +       /* We will need to compensate for the camera sensitivity. */\n> +       ASSERT(cameraMode.sensitivity);\n> +       sensitivity_ = cameraMode.sensitivity;\n> +}\n> +\n>  void Lux::prepare(Metadata *imageMetadata)\n>  {\n>         std::unique_lock<std::mutex> lock(mutex_);\n> @@ -88,10 +95,12 @@ void Lux::process(StatisticsPtr &stats, Metadata *imageMetadata)\n>                 double yRatio = currentY * (65536 / stats->yHist.bins()) / referenceY_;\n>                 double estimatedLux = exposureTimeRatio * gainRatio *\n>                                       apertureRatio * apertureRatio *\n> -                                     yRatio * referenceLux_;\n> +                                     yRatio * referenceLux_ / sensitivity_;\n> +\n>                 LuxStatus status;\n>                 status.lux = estimatedLux;\n>                 status.aperture = currentAperture;\n> +\n>                 LOG(RPiLux, Debug) << \": estimated lux \" << estimatedLux;\n>                 {\n>                         std::unique_lock<std::mutex> lock(mutex_);\n> diff --git a/src/ipa/rpi/controller/rpi/lux.h b/src/ipa/rpi/controller/rpi/lux.h\n> index da007fe9..db2227e4 100644\n> --- a/src/ipa/rpi/controller/rpi/lux.h\n> +++ b/src/ipa/rpi/controller/rpi/lux.h\n> @@ -10,6 +10,7 @@\n>  \n>  #include <libcamera/base/utils.h>\n>  \n> +#include \"../camera_mode.h\"\n>  #include \"../lux_status.h\"\n>  #include \"../algorithm.h\"\n>  \n> @@ -23,6 +24,7 @@ public:\n>         Lux(Controller *controller);\n>         char const *name() const override;\n>         int read(const libcamera::YamlObject &params) override;\n> +       void switchMode(CameraMode const &cameraMode, Metadata *metadata) override;\n>         void prepare(Metadata *imageMetadata) override;\n>         void process(StatisticsPtr &stats, Metadata *imageMetadata) override;\n>         void setCurrentAperture(double aperture);\n> @@ -40,6 +42,7 @@ private:\n>         double currentAperture_;\n>         LuxStatus status_;\n>         std::mutex mutex_;\n> +       double sensitivity_;\n>  };\n>  \n>  } /* namespace RPiController */\n> -- \n> 2.47.3\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 2062EBE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 20 Oct 2025 09:54:25 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1E8F86070A;\n\tMon, 20 Oct 2025 11:54:24 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C3D90606FC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 20 Oct 2025 11:54:22 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:9f50:5b33:d3ec:e1ea])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id ED52BF52;\n\tMon, 20 Oct 2025 11:52:39 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Y7eDKvk1\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1760953960;\n\tbh=TWNbyiPO3w7L/kTuG7wJ58MX88BRER+b92ykSJcYpbM=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=Y7eDKvk1fTcRqTfl/3dEjCg40mKpQ++UgOfbsJmld49GPgnCCli9sGMNKreE1RoDD\n\tO4Xh2tKW6diaPNJjcgYCTR2jwHzmoFHaUdJwiK4zJrqqSS/MEUQsOOOJUfd7Md+X6T\n\t5+0OJJcok3DJFuGmkomLEIbtPjgKm8SOXgG3CO3c=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20251017102704.3887-3-david.plowman@raspberrypi.com>","References":"<20251017102704.3887-1-david.plowman@raspberrypi.com>\n\t<20251017102704.3887-3-david.plowman@raspberrypi.com>","Subject":"Re: [PATCH 2/5] ipa: rpi: lux: Handle camera mode sensitivity\n\tcorrectly","From":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"David Plowman <david.plowman@raspberrypi.com>","To":"David Plowman <david.plowman@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 20 Oct 2025 11:54:19 +0200","Message-ID":"<176095405961.336133.6969223934708244720@localhost>","User-Agent":"alot/0.12.dev8+g2c003385c862.d20250602","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>"}},{"id":36396,"web_url":"https://patchwork.libcamera.org/comment/36396/","msgid":"<CAEmqJPp1NknRdS4iZtoVMuo06ROtKW0BkT-ocvVs4PJGkmo+qQ@mail.gmail.com>","date":"2025-10-23T07:34:18","subject":"Re: [PATCH 2/5] ipa: rpi: lux: Handle camera mode sensitivity\n\tcorrectly","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi David,\n\n\nOn Fri, 17 Oct 2025 at 11:27, David Plowman <david.plowman@raspberrypi.com>\nwrote:\n\n> The camera mode sensitivity needs to be taken into account for the lux\n> calculation. For example, the IMX708 binned mode (with a sensitivity\n> of 2.0) would otherwise show double the correct lux value.\n>\n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n>\n\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n\n\n> ---\n>  src/ipa/rpi/controller/rpi/lux.cpp | 13 +++++++++++--\n>  src/ipa/rpi/controller/rpi/lux.h   |  3 +++\n>  2 files changed, 14 insertions(+), 2 deletions(-)\n>\n> diff --git a/src/ipa/rpi/controller/rpi/lux.cpp\n> b/src/ipa/rpi/controller/rpi/lux.cpp\n> index 27b89a8f..acaa6e57 100644\n> --- a/src/ipa/rpi/controller/rpi/lux.cpp\n> +++ b/src/ipa/rpi/controller/rpi/lux.cpp\n> @@ -20,7 +20,7 @@ LOG_DEFINE_CATEGORY(RPiLux)\n>  #define NAME \"rpi.lux\"\n>\n>  Lux::Lux(Controller *controller)\n> -       : Algorithm(controller)\n> +       : Algorithm(controller), sensitivity_(1.0)\n>  {\n>         /*\n>          * Put in some defaults as there will be no meaningful values until\n> @@ -68,6 +68,13 @@ void Lux::setCurrentAperture(double aperture)\n>         currentAperture_ = aperture;\n>  }\n>\n> +void Lux::switchMode(CameraMode const &cameraMode, [[maybe_unused]]\n> Metadata *metadata)\n> +{\n> +       /* We will need to compensate for the camera sensitivity. */\n> +       ASSERT(cameraMode.sensitivity);\n> +       sensitivity_ = cameraMode.sensitivity;\n> +}\n> +\n>  void Lux::prepare(Metadata *imageMetadata)\n>  {\n>         std::unique_lock<std::mutex> lock(mutex_);\n> @@ -88,10 +95,12 @@ void Lux::process(StatisticsPtr &stats, Metadata\n> *imageMetadata)\n>                 double yRatio = currentY * (65536 / stats->yHist.bins()) /\n> referenceY_;\n>                 double estimatedLux = exposureTimeRatio * gainRatio *\n>                                       apertureRatio * apertureRatio *\n> -                                     yRatio * referenceLux_;\n> +                                     yRatio * referenceLux_ /\n> sensitivity_;\n> +\n>                 LuxStatus status;\n>                 status.lux = estimatedLux;\n>                 status.aperture = currentAperture;\n> +\n>                 LOG(RPiLux, Debug) << \": estimated lux \" << estimatedLux;\n>                 {\n>                         std::unique_lock<std::mutex> lock(mutex_);\n> diff --git a/src/ipa/rpi/controller/rpi/lux.h\n> b/src/ipa/rpi/controller/rpi/lux.h\n> index da007fe9..db2227e4 100644\n> --- a/src/ipa/rpi/controller/rpi/lux.h\n> +++ b/src/ipa/rpi/controller/rpi/lux.h\n> @@ -10,6 +10,7 @@\n>\n>  #include <libcamera/base/utils.h>\n>\n> +#include \"../camera_mode.h\"\n>  #include \"../lux_status.h\"\n>  #include \"../algorithm.h\"\n>\n> @@ -23,6 +24,7 @@ public:\n>         Lux(Controller *controller);\n>         char const *name() const override;\n>         int read(const libcamera::YamlObject &params) override;\n> +       void switchMode(CameraMode const &cameraMode, Metadata *metadata)\n> override;\n>         void prepare(Metadata *imageMetadata) override;\n>         void process(StatisticsPtr &stats, Metadata *imageMetadata)\n> override;\n>         void setCurrentAperture(double aperture);\n> @@ -40,6 +42,7 @@ private:\n>         double currentAperture_;\n>         LuxStatus status_;\n>         std::mutex mutex_;\n> +       double sensitivity_;\n>  };\n>\n>  } /* namespace RPiController */\n> --\n> 2.47.3\n>\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 7184AC3259\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 23 Oct 2025 07:34:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3D8B8607A6;\n\tThu, 23 Oct 2025 09:34:57 +0200 (CEST)","from mail-vs1-xe31.google.com (mail-vs1-xe31.google.com\n\t[IPv6:2607:f8b0:4864:20::e31])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3071360763\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Oct 2025 09:34:56 +0200 (CEST)","by mail-vs1-xe31.google.com with SMTP id\n\tada2fe7eead31-5c3cd705475so25477137.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Oct 2025 00:34:56 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"dfG2uPCk\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1761204895; x=1761809695;\n\tdarn=lists.libcamera.org; \n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=kW5UY9nG68AbLXeW/fsTh5eDbhQ1vG8F/F5lEYT7li8=;\n\tb=dfG2uPCkq9rZGdVslg3G092YX1hAMhDDu8FxPKsBx0snvs1FvbOTIHswyCKbE44Hr0\n\tuGIN0q1cKtncY6ApOxuMmgSW1an7KIJIg8tErgbRL4wDC6J2keqE3UH/L7pCONL0hXSn\n\tCrUmlLdM93MZvP7j9dlPGE9ICYh2LullxbqnPf0aMPfaM1Ze0semHG52qeyq8zG0jO+I\n\ttSB5WBQOrNewfOs31L0jwKU+QsxZCkbQsWQsy3OYnCGBvzjhBayjRlQmzwciqL940Mlz\n\tyw0E9WjyrXHPka1VlLvCLZVJTfTXI7p93Js2dMR+j68U1LNVmspB/tvMkfzBmHSnMMpr\n\t5Dhw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1761204895; x=1761809695;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=kW5UY9nG68AbLXeW/fsTh5eDbhQ1vG8F/F5lEYT7li8=;\n\tb=Xfmv84+LAOGnUlNrveKBSd351InFHfiavLYdkR5eEKARKo4eFke620Hnwmn+ezdIw0\n\t2bIWyn9V05l73SKet4XIfYEkCy+uVZdSQHEwzOY2MC+H4HW5KJOrvHYe9hOInRlYAsOh\n\tN4X2KlPAww4TbFjj8leEcdFItSmjmchHs+7BDvn+zJSZ8sb91pGw5F9Y4w5zLmHE/VMF\n\tz06w0hfoaaTlQxlIbaRLsudSkDQx1xvyWIA5RqA0eqkAB2gjr0FGbiIUc0CIyq2Hc1im\n\tZl7NFaQ5bDq5Vk6nHtOdWJJpAMvvnsIbpYxwbauMlRP0RieoKq+t2AFNJ5fr8Ci2riQL\n\tWEIw==","X-Gm-Message-State":"AOJu0YzIN3UPuLCLRtmW7yP8u8wCRGVhvMyhLsL9+KN16615NN9NVlWV\n\t+tIGAV9XM31xpGhzgc9ZYr+AMXtRXHUXWFphj8VWuTTDLYANqwy6uKYoi0Bq77P8GkAZdHyV3jh\n\tOtzd3ClIOptdC66zY3m1GYY9ltgBt3FLGEbgDclr3mqA5DNDR5Xx02Fo=","X-Gm-Gg":"ASbGncu+4CKABiUjoYAtZq1Cptmj1pTL53zmkPHizK1cVTMBIwrlw6ZtiHXGXapqzT5\n\tKnkYbSLRfAhGUreSmwYR3FMRwT950EWP+FMIpijArBubeYtHQn4pW7E1S+OMCIYH4AQ2A7EcyZg\n\tFJj0LAAl3i7YyX0+QRxm1IXAxa1l+DxnupHEjnbmAWSySlG3UKxcDVQFN8kSvV9ggUBt03kliSM\n\tR47yzsN8gk4Pourdxqlj6nUefAPQxP8sB9KhWbo8lnNJB5LaoZSZyqAj7saFq0JaLgNFf7iPVlV\n\tLInnPWWt4C8EzJg=","X-Google-Smtp-Source":"AGHT+IGWZArTirlDbgx3TZSWvg5fBrm8kBqjyNjXPDrtm5TaXAQcyI/b3xwqUEHj7eQcm13utKVsnEQ6FqADxfvmJFE=","X-Received":"by 2002:a05:6102:418f:b0:5d5:dcc1:3bb1 with SMTP id\n\tada2fe7eead31-5db0e157916mr1401716137.7.1761204894926;\n\tThu, 23 Oct 2025 00:34:54 -0700 (PDT)","MIME-Version":"1.0","References":"<20251017102704.3887-1-david.plowman@raspberrypi.com>\n\t<20251017102704.3887-3-david.plowman@raspberrypi.com>","In-Reply-To":"<20251017102704.3887-3-david.plowman@raspberrypi.com>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Thu, 23 Oct 2025 08:34:18 +0100","X-Gm-Features":"AWmQ_bmwux6aWha1_Y2fv73KUJDo9Tti9tpxIh7538LeAVLS9om6R25m404GsAw","Message-ID":"<CAEmqJPp1NknRdS4iZtoVMuo06ROtKW0BkT-ocvVs4PJGkmo+qQ@mail.gmail.com>","Subject":"Re: [PATCH 2/5] ipa: rpi: lux: Handle camera mode sensitivity\n\tcorrectly","To":"David Plowman <david.plowman@raspberrypi.com>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"multipart/alternative; boundary=\"000000000000239d920641ce7892\"","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>"}}]