{"id":17433,"url":"https://patchwork.libcamera.org/api/1.1/patches/17433/?format=json","web_url":"https://patchwork.libcamera.org/patch/17433/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20220927023642.12341-23-laurent.pinchart@ideasonboard.com>","date":"2022-09-27T02:36:31","name":"[libcamera-devel,v5,22/33] ipa: rkisp1: cproc: Store per-frame information in frame context","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"3fa7d99274c61157209268f43d655c3cbaacfc4f","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17433/mbox/","series":[{"id":3506,"url":"https://patchwork.libcamera.org/api/1.1/series/3506/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3506","date":"2022-09-27T02:36:09","name":"ipa: Frame context queue, IPU3 & RkISP consolidation, and RkISP1 improvements","version":5,"mbox":"https://patchwork.libcamera.org/series/3506/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17433/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17433/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 037B1C0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 27 Sep 2022 02:37:33 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A97E1622E3;\n\tTue, 27 Sep 2022 04:37:33 +0200 (CEST)","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 0FA7762273\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 27 Sep 2022 04:37:33 +0200 (CEST)","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 2E3C647C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 27 Sep 2022 04:37:31 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1664246253;\n\tbh=1Oxw78c4au4oiPhQy/oqLu6h/iNaB9uN1V5tPWQPJfM=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=pTLM6QG7txzUWww5vtdUNgYN+CtoJVxLaMDycYW3LJGipjatzVWciUQVpzVd6FTex\n\tYm2E8vfP9/x2oM1bHHHEhRBkjRySj2/4lSSiQZ/kqtYh/Y5mpexbH/DrE9iZXIMsup\n\tFIY3BkFb8r8eltIznWqOOsPiS8v52tZTx2J1qS7/PSWPJWieNT4H7lYTeqGVTyQY5y\n\tLnZFbxBOxin1HIYeWtGC/Q3nP/XxIOxA09hRSU+DooIyRyHhr3EMvWtBgsDamwUF1q\n\t2y9elCqtTnVtCYHOLnyLfKhXAobeuYARLDgHPp4hTwOjwTvurtcwdX91FbLrhENGXd\n\t6/I7lTXKzluUA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1664246252;\n\tbh=1Oxw78c4au4oiPhQy/oqLu6h/iNaB9uN1V5tPWQPJfM=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=t6p69Mr0WqlVed7FE4L/Eed2ZeH7vk+Qghpet9NvtBRkRdqxAKKrcqhOg3MYgXmOR\n\t86BDRjl1paOThneGpZ7GDss5CYjy46XeIRSEvNaVkG8EfkXEL7o/Aulf+NHS3nyWOI\n\ts5Oncj4PVygi5MuHFfpoeDHEpJaqoG7KasDI6lL4="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"t6p69Mr0\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 27 Sep 2022 05:36:31 +0300","Message-Id":"<20220927023642.12341-23-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.35.1","In-Reply-To":"<20220927023642.12341-1-laurent.pinchart@ideasonboard.com>","References":"<20220927023642.12341-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v5 22/33] ipa: rkisp1: cproc: Store\n\tper-frame information in frame context","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":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Rework the algorithm's usage of the active state, to store the value of\ncontrols for the last queued request in the queueRequest() function, and\nstore a copy of the values in the corresponding frame context. The\nlatter is used in the prepare() function to populate the ISP parameters\nwith values corresponding to the right frame.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/ipa/rkisp1/algorithms/cproc.cpp | 51 ++++++++++++++++++-----------\n src/ipa/rkisp1/ipa_context.cpp      | 21 ++++++++++--\n src/ipa/rkisp1/ipa_context.h        |  8 ++++-\n 3 files changed, 56 insertions(+), 24 deletions(-)","diff":"diff --git a/src/ipa/rkisp1/algorithms/cproc.cpp b/src/ipa/rkisp1/algorithms/cproc.cpp\nindex ea819b2acfcb..eaa56c37f2bb 100644\n--- a/src/ipa/rkisp1/algorithms/cproc.cpp\n+++ b/src/ipa/rkisp1/algorithms/cproc.cpp\n@@ -38,55 +38,66 @@ LOG_DEFINE_CATEGORY(RkISP1CProc)\n  */\n void ColorProcessing::queueRequest(IPAContext &context,\n \t\t\t\t   [[maybe_unused]] const uint32_t frame,\n-\t\t\t\t   [[maybe_unused]] IPAFrameContext &frameContext,\n+\t\t\t\t   IPAFrameContext &frameContext,\n \t\t\t\t   const ControlList &controls)\n {\n \tauto &cproc = context.activeState.cproc;\n+\tbool update = false;\n \n \tconst auto &brightness = controls.get(controls::Brightness);\n \tif (brightness) {\n-\t\tcproc.brightness = std::clamp<int>(std::lround(*brightness * 128), -128, 127);\n-\t\tcproc.updateParams = true;\n+\t\tint value = std::clamp<int>(std::lround(*brightness * 128), -128, 127);\n+\t\tif (cproc.brightness != value) {\n+\t\t\tcproc.brightness = value;\n+\t\t\tupdate = true;\n+\t\t}\n \n-\t\tLOG(RkISP1CProc, Debug) << \"Set brightness to \" << *brightness;\n+\t\tLOG(RkISP1CProc, Debug) << \"Set brightness to \" << value;\n \t}\n \n \tconst auto &contrast = controls.get(controls::Contrast);\n \tif (contrast) {\n-\t\tcproc.contrast = std::clamp<int>(std::lround(*contrast * 128), 0, 255);\n-\t\tcproc.updateParams = true;\n+\t\tint value = std::clamp<int>(std::lround(*contrast * 128), 0, 255);\n+\t\tif (cproc.contrast != value) {\n+\t\t\tcproc.contrast = value;\n+\t\t\tupdate = true;\n+\t\t}\n \n-\t\tLOG(RkISP1CProc, Debug) << \"Set contrast to \" << *contrast;\n+\t\tLOG(RkISP1CProc, Debug) << \"Set contrast to \" << value;\n \t}\n \n \tconst auto saturation = controls.get(controls::Saturation);\n \tif (saturation) {\n-\t\tcproc.saturation = std::clamp<int>(std::lround(*saturation * 128), 0, 255);\n-\t\tcproc.updateParams = true;\n+\t\tint value = std::clamp<int>(std::lround(*saturation * 128), 0, 255);\n+\t\tif (cproc.saturation != value) {\n+\t\t\tcproc.saturation = value;\n+\t\t\tupdate = true;\n+\t\t}\n \n-\t\tLOG(RkISP1CProc, Debug) << \"Set saturation to \" << *saturation;\n+\t\tLOG(RkISP1CProc, Debug) << \"Set saturation to \" << value;\n \t}\n+\n+\tframeContext.cproc.brightness = cproc.brightness;\n+\tframeContext.cproc.contrast = cproc.contrast;\n+\tframeContext.cproc.saturation = cproc.saturation;\n+\tframeContext.cproc.update = update;\n }\n \n /**\n  * \\copydoc libcamera::ipa::Algorithm::prepare\n  */\n-void ColorProcessing::prepare(IPAContext &context,\n+void ColorProcessing::prepare([[maybe_unused]] IPAContext &context,\n \t\t\t      [[maybe_unused]] const uint32_t frame,\n-\t\t\t      [[maybe_unused]] IPAFrameContext &frameContext,\n+\t\t\t      IPAFrameContext &frameContext,\n \t\t\t      rkisp1_params_cfg *params)\n {\n-\tauto &cproc = context.activeState.cproc;\n-\n \t/* Check if the algorithm configuration has been updated. */\n-\tif (!cproc.updateParams)\n+\tif (!frameContext.cproc.update)\n \t\treturn;\n \n-\tcproc.updateParams = false;\n-\n-\tparams->others.cproc_config.brightness = cproc.brightness;\n-\tparams->others.cproc_config.contrast = cproc.contrast;\n-\tparams->others.cproc_config.sat = cproc.saturation;\n+\tparams->others.cproc_config.brightness = frameContext.cproc.brightness;\n+\tparams->others.cproc_config.contrast = frameContext.cproc.contrast;\n+\tparams->others.cproc_config.sat = frameContext.cproc.saturation;\n \n \tparams->module_en_update |= RKISP1_CIF_ISP_MODULE_CPROC;\n \tparams->module_ens |= RKISP1_CIF_ISP_MODULE_CPROC;\ndiff --git a/src/ipa/rkisp1/ipa_context.cpp b/src/ipa/rkisp1/ipa_context.cpp\nindex ba80a0707ef7..fdc8e7df0b76 100644\n--- a/src/ipa/rkisp1/ipa_context.cpp\n+++ b/src/ipa/rkisp1/ipa_context.cpp\n@@ -160,9 +160,6 @@ namespace libcamera::ipa::rkisp1 {\n  *\n  * \\var IPAActiveState::cproc.saturation\n  * \\brief Saturation level\n- *\n- * \\var IPAActiveState::cproc.updateParams\n- * \\brief Indicates if ISP parameters need to be updated\n  */\n \n /**\n@@ -236,6 +233,24 @@ namespace libcamera::ipa::rkisp1 {\n  * \\brief Whether the Auto White Balance algorithm is enabled\n  */\n \n+/**\n+ * \\var IPAFrameContext::cproc\n+ * \\brief Color Processing parameters for this frame\n+ *\n+ * \\struct IPAFrameContext::cproc.brightness\n+ * \\brief Brightness level\n+ *\n+ * \\var IPAFrameContext::cproc.contrast\n+ * \\brief Contrast level\n+ *\n+ * \\var IPAFrameContext::cproc.saturation\n+ * \\brief Saturation level\n+ *\n+ * \\var IPAFrameContext::cproc.update\n+ * \\brief Indicates if the color processing parameters have been updated\n+ * compared to the previous frame\n+ */\n+\n /**\n  * \\var IPAFrameContext::sensor\n  * \\brief Sensor configuration that used been used for this frame\ndiff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\nindex f23ebb2c9004..cc217aec511a 100644\n--- a/src/ipa/rkisp1/ipa_context.h\n+++ b/src/ipa/rkisp1/ipa_context.h\n@@ -76,7 +76,6 @@ struct IPAActiveState {\n \t\tint8_t brightness;\n \t\tuint8_t contrast;\n \t\tuint8_t saturation;\n-\t\tbool updateParams;\n \t} cproc;\n \n \tstruct {\n@@ -108,6 +107,13 @@ struct IPAFrameContext : public FrameContext {\n \t\tbool autoEnabled;\n \t} awb;\n \n+\tstruct {\n+\t\tint8_t brightness;\n+\t\tuint8_t contrast;\n+\t\tuint8_t saturation;\n+\t\tbool update;\n+\t} cproc;\n+\n \tstruct {\n \t\tuint32_t exposure;\n \t\tdouble gain;\n","prefixes":["libcamera-devel","v5","22/33"]}