[{"id":21951,"web_url":"https://patchwork.libcamera.org/comment/21951/","msgid":"<YdVws7JWUm0Heu5O@pendragon.ideasonboard.com>","date":"2022-01-05T10:19:31","subject":"Re: [libcamera-devel] [PATCH v2 3/3] libcamera: pipeline:\n\traspberrypi: Update sensor's V4L2_CID_NOTIFY_GAINS control","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi David,\n\nThank you for the patch.\n\nOn Wed, Jan 05, 2022 at 08:55:53AM +0000, David Plowman wrote:\n> If the sensor exposes the V4L2_CID_NOTIFY_GAINS control, assume it\n> means the sensor wants to be told the latest colour gains.\n> \n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n> ---\n>  .../pipeline/raspberrypi/raspberrypi.cpp      | 26 +++++++++++++++++++\n>  1 file changed, 26 insertions(+)\n> \n> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> index b5c687da..0d4b5a57 100644\n> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> @@ -1495,6 +1495,32 @@ void RPiCameraData::statsMetadataComplete(uint32_t bufferId, const ControlList &\n>  \tRequest *request = requestQueue_.front();\n>  \trequest->metadata().merge(controls);\n>  \n> +\t/*\n> +\t * If the sensor has the V4L2_CID_NOTIFY_GAIN control then it wants\n> +\t * to be notified of the latest colour gains.\n> +\t */\n> +\tauto it = sensor_->controls().find(V4L2_CID_NOTIFY_GAINS);\n\nAs this will not vary at runtime, this check could be done at init time,\nwith the unity value cached and a flag set to indicate notify gains\nsupport. Up to you.\n\n> +\tif (it != sensor_->controls().end()) {\n> +\t\tif (controls.contains(libcamera::controls::ColourGains)) {\n> +\t\t\tlibcamera::Span<const float> colourGains = controls.get(libcamera::controls::ColourGains);\n> +\t\t\t/*\n> +\t\t\t * This control is a linear gain value where the default is\n> +\t\t\t * defined to correspond to a gain of 1. The order of the gains\n> +\t\t\t * is always B, Gb, Gr, R.\n> +\t\t\t */\n> +\t\t\tint unity = it->second.def().get<int32_t>();\n> +\t\t\tControlList ctrls(sensor_->controls());\n> +\t\t\tint32_t gains[4] = { static_cast<int32_t>(colourGains[1] * unity),\n> +\t\t\t\t\t     unity, unity,\n> +\t\t\t\t\t     static_cast<int32_t>(colourGains[0] * unity) };\n\nstd::array could be used too, up to you.\n\n> +\t\t\tControlValue c(Span<const uint8_t>{ reinterpret_cast<uint8_t *>(gains),\n> +\t\t\t\t\t\t\t    sizeof(gains) });\n\nI'm a bit surprised that you have to cast this to a uint8_t array, as\nthe control uses 32-bit integer array. Would\n\n\t\t\tControlValue c(Span<const uint32_t>{ gains });\n\nwork ? It may even be possible to write\n\n\t\t\tctrls.set(V4L2_CID_NOTIFY_GAINS, Span<const uint32_t>{ gains });\n\nas the ControlValue constructor is implicit.\n\n> +\t\t\tctrls.set(V4L2_CID_NOTIFY_GAINS, c);\n> +\n> +\t\t\tsensor_->setControls(&ctrls);\n> +\t\t}\n> +\t}\n> +\n>  \tstate_ = State::IpaComplete;\n>  \thandleState();\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 2258EBE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  5 Jan 2022 10:19:39 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5F2C060921;\n\tWed,  5 Jan 2022 11:19:38 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B275D60115\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  5 Jan 2022 11:19:36 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 28561993;\n\tWed,  5 Jan 2022 11:19:36 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"L8vjmob8\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1641377976;\n\tbh=KMrIZPyLY3vO0kYDAxZ2g8s969t+k/dtFenH2CN7nbs=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=L8vjmob8uSoALmi3znznBu9zT+5VFnCJLHpc6ZBTo19bIF1GHRCgFYbmHRR+J+yXs\n\tbYvwQbPSP2xWv2Gbm8tPBdS/0zTx4rrRlSWjYGuuGfGLK3L/y5lIYohOJHV4FbK3bJ\n\txPrSOfglaD0gssAvMFFYHiUwpHGUIeUJQFTY6O9E=","Date":"Wed, 5 Jan 2022 12:19:31 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"David Plowman <david.plowman@raspberrypi.com>","Message-ID":"<YdVws7JWUm0Heu5O@pendragon.ideasonboard.com>","References":"<20220105085553.12092-1-david.plowman@raspberrypi.com>\n\t<20220105085553.12092-4-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220105085553.12092-4-david.plowman@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH v2 3/3] libcamera: pipeline:\n\traspberrypi: Update sensor's V4L2_CID_NOTIFY_GAINS control","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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":21954,"web_url":"https://patchwork.libcamera.org/comment/21954/","msgid":"<CAHW6GYKfUpFzXd=4g0S_nTYnjjibJzhGHmx1+MxZXPQ69wxM_Q@mail.gmail.com>","date":"2022-01-05T14:55:13","subject":"Re: [libcamera-devel] [PATCH v2 3/3] libcamera: pipeline:\n\traspberrypi: Update sensor's V4L2_CID_NOTIFY_GAINS control","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"content":"Hi Laurent\n\nThanks for the suggestions.\n\nOn Wed, 5 Jan 2022 at 10:19, Laurent Pinchart\n<laurent.pinchart@ideasonboard.com> wrote:\n>\n> Hi David,\n>\n> Thank you for the patch.\n>\n> On Wed, Jan 05, 2022 at 08:55:53AM +0000, David Plowman wrote:\n> > If the sensor exposes the V4L2_CID_NOTIFY_GAINS control, assume it\n> > means the sensor wants to be told the latest colour gains.\n> >\n> > Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n> > ---\n> >  .../pipeline/raspberrypi/raspberrypi.cpp      | 26 +++++++++++++++++++\n> >  1 file changed, 26 insertions(+)\n> >\n> > diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > index b5c687da..0d4b5a57 100644\n> > --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > @@ -1495,6 +1495,32 @@ void RPiCameraData::statsMetadataComplete(uint32_t bufferId, const ControlList &\n> >       Request *request = requestQueue_.front();\n> >       request->metadata().merge(controls);\n> >\n> > +     /*\n> > +      * If the sensor has the V4L2_CID_NOTIFY_GAIN control then it wants\n> > +      * to be notified of the latest colour gains.\n> > +      */\n> > +     auto it = sensor_->controls().find(V4L2_CID_NOTIFY_GAINS);\n>\n> As this will not vary at runtime, this check could be done at init time,\n> with the unity value cached and a flag set to indicate notify gains\n> support. Up to you.\n\nYes, I could do that. Actually, I can sense another std::optional\ncoming on so I think I'll try that!\n\n>\n> > +     if (it != sensor_->controls().end()) {\n> > +             if (controls.contains(libcamera::controls::ColourGains)) {\n> > +                     libcamera::Span<const float> colourGains = controls.get(libcamera::controls::ColourGains);\n> > +                     /*\n> > +                      * This control is a linear gain value where the default is\n> > +                      * defined to correspond to a gain of 1. The order of the gains\n> > +                      * is always B, Gb, Gr, R.\n> > +                      */\n> > +                     int unity = it->second.def().get<int32_t>();\n> > +                     ControlList ctrls(sensor_->controls());\n> > +                     int32_t gains[4] = { static_cast<int32_t>(colourGains[1] * unity),\n> > +                                          unity, unity,\n> > +                                          static_cast<int32_t>(colourGains[0] * unity) };\n>\n> std::array could be used too, up to you.\n\nPerhaps it's the modern C++ way these days, so yes, I'll do that.\n\n>\n> > +                     ControlValue c(Span<const uint8_t>{ reinterpret_cast<uint8_t *>(gains),\n> > +                                                         sizeof(gains) });\n>\n> I'm a bit surprised that you have to cast this to a uint8_t array, as\n> the control uses 32-bit integer array. Would\n>\n>                         ControlValue c(Span<const uint32_t>{ gains });\n>\n> work ? It may even be possible to write\n>\n>                         ctrls.set(V4L2_CID_NOTIFY_GAINS, Span<const uint32_t>{ gains });\n\nThanks for the tidy-ups there, that seems to work. I had probably\ncopied it from somewhere and been relieved when all the nasty template\nstuff just compiled! :)\n\nBest regards\nDavid\n\n>\n> as the ControlValue constructor is implicit.\n>\n> > +                     ctrls.set(V4L2_CID_NOTIFY_GAINS, c);\n> > +\n> > +                     sensor_->setControls(&ctrls);\n> > +             }\n> > +     }\n> > +\n> >       state_ = State::IpaComplete;\n> >       handleState();\n> >  }\n>\n> --\n> Regards,\n>\n> Laurent Pinchart","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 11E20BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  5 Jan 2022 14:55:28 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5102C608E6;\n\tWed,  5 Jan 2022 15:55:27 +0100 (CET)","from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com\n\t[IPv6:2a00:1450:4864:20::32a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 633C360868\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  5 Jan 2022 15:55:25 +0100 (CET)","by mail-wm1-x32a.google.com with SMTP id\n\tm14-20020a7bcb8e000000b00346da381d59so672758wmi.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 05 Jan 2022 06:55:25 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"Sj3tRc2O\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=2YGiFSAlzgK2S169ZAgBG/i1cVWIPbsHHLrBIuNqv48=;\n\tb=Sj3tRc2OGTi0QZwBQwqclrLX8ZEIOdvRa74h9jH8RXtVSoXdlm94G0wRjKIeyRQ2Mu\n\tKzNjCts2MIKdwG7sjEpbbpsN2vtGWU4oxPUshhWRuCwKYdmqlsRs7RUC77SDsPdvzT7H\n\tniEx/84//RLzy3Ey53C1qsoZ6w7vYWXoxiSCrEZe7I5aUv02eDGjD/arEvbPV5UPdfYr\n\txk6CfDkvuVClUrdygreCX4FpzvDM8YzDR9o3PtyHIFp56vJF7a1GQ4f4ln4udT9C5Pgr\n\thy/T1g8MGLzjtDFJC8ZyFENrA21QS/IAvsUL/GlKTcNDa4BgfcVI9AtLWU53s2Hc53fz\n\tMkiw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=2YGiFSAlzgK2S169ZAgBG/i1cVWIPbsHHLrBIuNqv48=;\n\tb=sA4pfhQYCrLsYejVOowQR0UBrOmcgnlkV19SXsGyoq6TwCsHuAs81sHv5SZmYtHxkd\n\tQ+VymMZc+Z82nWN4Ja8A9I/SC62H98YD92R/qRNMQ2JuErZ9/5vqnDJNIjzRbJCnyNX9\n\tUdIew/Ak4cGNS09UNLxn7c1yeK+1lD9XgMUhMdvBTGMQNWLjbwXcudiCXLu+10Xsdryt\n\tKnLpN4595cBlcbezhw5b4kZkhgKoO6gMEmElJz9Yb7z3X6cmraZ1Im/qUpymuLjRfi11\n\tZY+aMqNtsht68Ec+xzGjqVcizG2Zid2rakktNXasR+Bb4cLNETAnYrPoDxjVOOCaNBdb\n\tqP1g==","X-Gm-Message-State":"AOAM532rrgFWx0zUu0eWxCc9YVK/dAc1rmyV7e7KDVfDAdNWFuzBpKAO\n\tHQXEO5o13AO9OmHMjcUO0FY6aNkTjazLxywxEgGXv7zSQwH8hA==","X-Google-Smtp-Source":"ABdhPJwhA5ZV6nVnkLObEEbDgUth3r7sRea+xkY2plUotR9Bpt4PGIDJbybYawHSZQEcjF8C3cWQERUO76u23FB0Ry8=","X-Received":"by 2002:a05:600c:4fcc:: with SMTP id\n\to12mr3138021wmq.184.1641394524910; \n\tWed, 05 Jan 2022 06:55:24 -0800 (PST)","MIME-Version":"1.0","References":"<20220105085553.12092-1-david.plowman@raspberrypi.com>\n\t<20220105085553.12092-4-david.plowman@raspberrypi.com>\n\t<YdVws7JWUm0Heu5O@pendragon.ideasonboard.com>","In-Reply-To":"<YdVws7JWUm0Heu5O@pendragon.ideasonboard.com>","From":"David Plowman <david.plowman@raspberrypi.com>","Date":"Wed, 5 Jan 2022 14:55:13 +0000","Message-ID":"<CAHW6GYKfUpFzXd=4g0S_nTYnjjibJzhGHmx1+MxZXPQ69wxM_Q@mail.gmail.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH v2 3/3] libcamera: pipeline:\n\traspberrypi: Update sensor's V4L2_CID_NOTIFY_GAINS control","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>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]