[{"id":36112,"web_url":"https://patchwork.libcamera.org/comment/36112/","msgid":"<CAHW6GYLsWbOfX8DJTb7=SSiunFn-8s_95+k-3cEOCYF8jjVnSA@mail.gmail.com>","date":"2025-10-03T14:30:24","subject":"Re: [PATCH v2 4/4] ipa: rpi: pisp: Allow an initial decompand curve\n\tto be set on the FE","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"content":"Hi Naush\n\nThanks for the patch.\n\nOn Fri, 3 Oct 2025 at 13:18, Naushir Patuck <naush@raspberrypi.com> wrote:\n>\n> In the current code, decompand will only set a curve in the prepare\n> phase, which will only run after 1-2 frames pass through the FE. This\n> is fixed by adding an initialValues() member function to the decompand\n> algorithm, which will be called in the IPA before we start the hardware\n> streaming.\n>\n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> Tested-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>\n> ---\n>  src/ipa/rpi/controller/decompand_algorithm.h |  2 ++\n>  src/ipa/rpi/controller/rpi/decompand.cpp     |  8 ++++++++\n>  src/ipa/rpi/controller/rpi/decompand.h       |  1 +\n>  src/ipa/rpi/pisp/pisp.cpp                    | 15 +++++++++++++++\n>  4 files changed, 26 insertions(+)\n>\n> diff --git a/src/ipa/rpi/controller/decompand_algorithm.h b/src/ipa/rpi/controller/decompand_algorithm.h\n> index f19f8c109323..6d2467490106 100644\n> --- a/src/ipa/rpi/controller/decompand_algorithm.h\n> +++ b/src/ipa/rpi/controller/decompand_algorithm.h\n> @@ -19,6 +19,8 @@ public:\n>                 : Algorithm(controller)\n>         {\n>         }\n> +       /* A decompand algorithm must provide the following: */\n> +       virtual void initialValues(libcamera::ipa::Pwl &decompandCurve) = 0;\n>  };\n>\n>  } /* namespace RPiController */\n> diff --git a/src/ipa/rpi/controller/rpi/decompand.cpp b/src/ipa/rpi/controller/rpi/decompand.cpp\n> index 5b4c2e5524af..2d457926c060 100644\n> --- a/src/ipa/rpi/controller/rpi/decompand.cpp\n> +++ b/src/ipa/rpi/controller/rpi/decompand.cpp\n> @@ -39,6 +39,14 @@ void Decompand::switchMode(CameraMode const &cameraMode,\n>         mode_ = cameraMode;\n>  }\n>\n> +void Decompand::initialValues(libcamera::ipa::Pwl &decompandCurve)\n> +{\n> +       if (config_.bitdepth == 0 || mode_.bitdepth == config_.bitdepth) {\n> +               decompandCurve = config_.decompandCurve;\n> +       } else\n> +               decompandCurve = {};\n> +}\n> +\n>\n\nI guess it makes me wonder a bit whether we could just return the PWL\nout of switchMode, could we then dispense with both initialValues and\nprepare? But I don't think any other algorithms do this, so what is\nhere seems fine too.\n\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\n\nThanks!\nDavid\n\n void Decompand::prepare(Metadata *imageMetadata)\n>  {\n>         DecompandStatus decompandStatus;\n> diff --git a/src/ipa/rpi/controller/rpi/decompand.h b/src/ipa/rpi/controller/rpi/decompand.h\n> index 0f2a9b3bbdc4..6db779c359a8 100644\n> --- a/src/ipa/rpi/controller/rpi/decompand.h\n> +++ b/src/ipa/rpi/controller/rpi/decompand.h\n> @@ -20,6 +20,7 @@ public:\n>         int read(const libcamera::YamlObject &params) override;\n>         void initialise() override;\n>         void switchMode(CameraMode const &cameraMode, Metadata *metadata) override;\n> +       void initialValues(libcamera::ipa::Pwl &decompandCurve) override;\n>         void prepare(Metadata *imageMetadata) override;\n>\n>  private:\n> diff --git a/src/ipa/rpi/pisp/pisp.cpp b/src/ipa/rpi/pisp/pisp.cpp\n> index f5be39aca5ee..01baebcd2bb6 100644\n> --- a/src/ipa/rpi/pisp/pisp.cpp\n> +++ b/src/ipa/rpi/pisp/pisp.cpp\n> @@ -32,6 +32,7 @@\n>  #include \"controller/cac_status.h\"\n>  #include \"controller/ccm_status.h\"\n>  #include \"controller/contrast_status.h\"\n> +#include \"controller/decompand_algorithm.h\"\n>  #include \"controller/decompand_status.h\"\n>  #include \"controller/denoise_algorithm.h\"\n>  #include \"controller/denoise_status.h\"\n> @@ -335,6 +336,20 @@ int32_t IpaPiSP::platformStart([[maybe_unused]] const ControlList &controls,\n>         /* Cause the stitch block to be reset correctly. */\n>         lastStitchHdrStatus_ = HdrStatus();\n>\n> +       /* Setup a default decompand curve on startup if needed. */\n> +       RPiController::DecompandAlgorithm *decompand = dynamic_cast<RPiController::DecompandAlgorithm *>(\n> +               controller_.getAlgorithm(\"decompand\"));\n> +       if (decompand) {\n> +               std::scoped_lock<FrontEnd> l(*fe_);\n> +               pisp_fe_global_config feGlobal;\n> +               DecompandStatus decompandStatus;\n> +\n> +               fe_->GetGlobal(feGlobal);\n> +               decompand->initialValues(decompandStatus.decompandCurve);\n> +               applyDecompand(&decompandStatus, feGlobal);\n> +               fe_->SetGlobal(feGlobal);\n> +       }\n> +\n>         return 0;\n>  }\n>\n> --\n> 2.43.0\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 88279BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  3 Oct 2025 14:30:39 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B2A5C6B5F3;\n\tFri,  3 Oct 2025 16:30:38 +0200 (CEST)","from mail-qt1-x834.google.com (mail-qt1-x834.google.com\n\t[IPv6:2607:f8b0:4864:20::834])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 451E169318\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  3 Oct 2025 16:30:37 +0200 (CEST)","by mail-qt1-x834.google.com with SMTP id\n\td75a77b69052e-4e2d2d764a3so18280801cf.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 03 Oct 2025 07:30:37 -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=\"jVTPwRKz\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1759501836; x=1760106636;\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=t/8st4709Ccc/9f+U/8OO0tIxJbDPGxv/k1IsJzV51g=;\n\tb=jVTPwRKzrTCZO8Ym8Gd4fVnACqdAIy8rv2ivAOeENasLryjO2T4W52YAd+sz3qTOBX\n\tpS82pY6+OBoQBYH/8FjXDTtU3giHzQFrYF28XlEhHpw4NmvVp9ogQ0h3kUuCDHW0oHOl\n\twbArdy2kOUrfAyxArGosKKvjkugIV1MOlG85D2vkRIBX105KMJxlP3iSBXc8I0j//ddT\n\tMK535kY2f8j+KEwBCzKTzcXZjZhSdISIZ6KYi5Cljd+yTbs7Shdy+18n2y00iM4oyK5Z\n\taKfpSRA13Mp+V43WdhcXY7KhJwS1U22YMF0MiAijXEi4Cm3BvoHPCevb9UsxanJLpUOx\n\tTvWw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1759501836; x=1760106636;\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=t/8st4709Ccc/9f+U/8OO0tIxJbDPGxv/k1IsJzV51g=;\n\tb=nBHtQCin7mhkrl1+dyM0N6giUGvi1rz2gNrXdtJRrYoKshVMzNM+0qCuSyiIYic5RX\n\tzGeag08p51VTmI9pk9vRukCbUqXQ6Hd2k2Pq2XC2XkN9EisVmotyJc/K/KFu+pmmXCLT\n\tP/NRDEl1u1K7zqszWQR0ukBYTEgDNeEYFGrOyz/6EUm3rSaLrduG4d//S1kT5HpAjbmP\n\tzR8+RnEe0aQ4aA2IS9wVyKnPawwKYAvs3+5g69QLYDubJFPPqCeUCXzCkJS/EtediBiY\n\tak+kmViZziz9K/X9wT7bGnEqw0BK9sGadW/w521uDAcSEmoZMXmNFSKILjtUCVAu71ub\n\tLGbg==","X-Gm-Message-State":"AOJu0YxkQ+MLPf/EfWnm4hqQ6ACzMopvDsZT3oASRqP86sSDGjaEMUrh\n\tlwZYni0Cg/PbKult/7N394uZ9dgFP4ccEuBNYvV4JzCR+8VqPR6EiY89+hlMXVHAFLMA1WTTaG6\n\ttBKsXkT9hi1c+Z3HfTvSvbBGdVUbp2cjdUPkpVETOCA==","X-Gm-Gg":"ASbGncscUf/t7cLaKRHGQFTmSeRjtSZFTb2+1grs2/wAoaAdq1TQJB/Dv6yNlWcB6sF\n\tcpuYM/l3jdnvTbBvUvwLwUMUAsOsflaLlL1EKmyPgPTlJV1+849N7LzsHZm7SO2bJPnaKkaOHd3\n\tsb/U/HCu1Es6YicppMsakExRNa30O7WpeHkvKCIV1HAMCeda3rvKZF9V+zGseWSA1O3Llml6aSt\n\taIIWpDOkHf7FWK9/H1ydWF03M1rNlNc29jQWJoNZGDOfW0/CjUPQnB4n9Ol7uLkpgN9DwSwUQ==","X-Google-Smtp-Source":"AGHT+IGiNl417VXhiY+3LTzsj0ueSnJ7CylXUqlf/bFj6A7/w0poWymR9OTbHH4rY0YO4FREn5lRm35tqfAK7wet/jQ=","X-Received":"by 2002:a05:622a:8607:b0:4e5:8088:e7c3 with SMTP id\n\td75a77b69052e-4e58088ea32mr1654111cf.9.1759501835811; Fri, 03 Oct 2025\n\t07:30:35 -0700 (PDT)","MIME-Version":"1.0","References":"<20251003121821.659081-1-naush@raspberrypi.com>\n\t<20251003121821.659081-5-naush@raspberrypi.com>","In-Reply-To":"<20251003121821.659081-5-naush@raspberrypi.com>","From":"David Plowman <david.plowman@raspberrypi.com>","Date":"Fri, 3 Oct 2025 15:30:24 +0100","X-Gm-Features":"AS18NWDjMHRYx4ikfU5xChX9-3EPiHHlmNEiH62qWjJGGaDiJLE9_Caap91j40U","Message-ID":"<CAHW6GYLsWbOfX8DJTb7=SSiunFn-8s_95+k-3cEOCYF8jjVnSA@mail.gmail.com>","Subject":"Re: [PATCH v2 4/4] ipa: rpi: pisp: Allow an initial decompand curve\n\tto be set on the FE","To":"Naushir Patuck <naush@raspberrypi.com>","Cc":"libcamera-devel@lists.libcamera.org, \n\tNick Hollinghurst <nick.hollinghurst@raspberrypi.com>","Content-Type":"text/plain; charset=\"UTF-8\"","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>"}}]