Patch Detail
Show a patch.
GET /api/1.1/patches/17329/?format=api
{ "id": 17329, "url": "https://patchwork.libcamera.org/api/1.1/patches/17329/?format=api", "web_url": "https://patchwork.libcamera.org/patch/17329/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20220908014200.28728-21-laurent.pinchart@ideasonboard.com>", "date": "2022-09-08T01:41:48", "name": "[libcamera-devel,v4,20/32] ipa: rkisp1: awb: Store per-frame information in frame context", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "28b1f16b4505e530e893eae831054c385e215621", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/17329/mbox/", "series": [ { "id": 3476, "url": "https://patchwork.libcamera.org/api/1.1/series/3476/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3476", "date": "2022-09-08T01:41:28", "name": "ipa: Frame context queue, IPU3 & RkISP consolidation, and RkISP1 improvements", "version": 4, "mbox": "https://patchwork.libcamera.org/series/3476/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/17329/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/17329/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 C926AC327D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 8 Sep 2022 01:42:48 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 82A33620E8;\n\tThu, 8 Sep 2022 03:42:48 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0F7D3620DD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 8 Sep 2022 03:42:46 +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 8AE3D888\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 8 Sep 2022 03:42:45 +0200 (CEST)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1662601368;\n\tbh=m4uVtVyQVnfTsDWeTz9KqdBImnz4wr5OVhCYAgdQSI0=;\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=dOWdT+xt//He4HBwuU2yEFEBORdk1ONliotffr+gF5S/lXjEJ4xlxfc0SpG5SyKjw\n\ty0DHAkUXEfUf29YBuxULgU1KnlcMITtxGAV+BkhGLWAdlD0zdBEIObVCGBdaihv5dQ\n\tEGdxqdljZTAlS04OB7g0XlkOflCKCdot5oDXFAuxbzM4+jmVybEXr6gjW8tGjnAiC0\n\t0Y3ZHivmxV/yIy1eFKhwxw0M6AJ6CBj2OAkS9kCamDWD7NODHlyurg62qKMux7u0+Y\n\trSARfvliyXslseWKfkFjnWXxUM8BLYQ+MQC2nQKbuQhseZtobN+9e9WJEQ03OkVkvL\n\tcI9xvs87pWuiw==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1662601365;\n\tbh=m4uVtVyQVnfTsDWeTz9KqdBImnz4wr5OVhCYAgdQSI0=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=wSsCvzFeQo5njJipCFgXM4zRaLUCzRH/OFN2EAIKjpyEgUr3qqNkTbW5CNvXB6zhP\n\t+45OO66YoLouI/WYSuDtlrlm0wS0oRVpG8UkCffATzcu9yi0n8XrdsEekZbN4ENtpk\n\t4o4ACQF0BZ4pHTaQ9dWw/mVmeuktoxi/CB97rFSo=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"wSsCvzFe\"; dkim-atps=neutral", "To": "libcamera-devel@lists.libcamera.org", "Date": "Thu, 8 Sep 2022 04:41:48 +0300", "Message-Id": "<20220908014200.28728-21-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.35.1", "In-Reply-To": "<20220908014200.28728-1-laurent.pinchart@ideasonboard.com>", "References": "<20220908014200.28728-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v4 20/32] ipa: rkisp1: awb: 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 and frame context to\nstore data in the right place.\n\nThe active state stores two distinct categories of information:\n\n- The consolidated value of all algorithm controls. Requests passed to\n the queueRequest() function store values for controls that the\n application wants to modify for that particular frame, and the\n queueRequest() function updates the active state with those values.\n The active state thus contains a consolidated view of the value of all\n controls handled by the algorithm.\n\n- The value of parameters computed by the algorithm when running in auto\n mode. Algorithms running in auto mode compute new parameters every\n time statistics buffers are received (either synchronously, or\n possibly in a background thread). The latest computed value of those\n parameters is stored in the active state in the process() function.\n\nThe frame context also stores two categories of information:\n\n- The value of the controls to be applied to the frame. These values are\n typically set in the queueRequest() function, from the consolidated\n control values stored in the active state. The frame context thus\n stores values for all controls related to the algorithm, not limited\n to the controls specified in the corresponding request, but\n consolidated from all requests that have been queued so far.\n\n For controls that can be specified manually or computed by the\n algorithm depending on the operation mode (such as the colour gains),\n the control value will be stored in the frame context in\n queueRequest() only when operating in manual mode. When operating in\n auto mode, the values are computed by the algorithm and stored in the\n frame context in prepare(), just before being stored in the ISP\n parameters buffer.\n\n The queueRequest() function can also store ancillary data in the frame\n context, such as flags to indicate if (and what) control values have\n changed compared to the previous request.\n\n- Status information computed by the algorithm for a frame. For\n instance, the colour temperature estimated by the algorithm from ISP\n statistics calculated on a frame is stored in the frame context for\n that frame in the process() function.\n\nThe active state and frame context thus both contain identical members\nfor most control values, but store values that have a different meaning.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/ipa/rkisp1/algorithms/awb.cpp | 75 +++++++++++++++++++------------\n src/ipa/rkisp1/ipa_context.cpp | 51 +++++++++++++++++----\n src/ipa/rkisp1/ipa_context.h | 25 +++++++++--\n 3 files changed, 110 insertions(+), 41 deletions(-)", "diff": "diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp\nindex a0bbe5cb8afa..bb0f6c27fc7d 100644\n--- a/src/ipa/rkisp1/algorithms/awb.cpp\n+++ b/src/ipa/rkisp1/algorithms/awb.cpp\n@@ -36,9 +36,12 @@ LOG_DEFINE_CATEGORY(RkISP1Awb)\n int Awb::configure(IPAContext &context,\n \t\t const IPACameraSensorInfo &configInfo)\n {\n-\tcontext.activeState.awb.gains.red = 1.0;\n-\tcontext.activeState.awb.gains.blue = 1.0;\n-\tcontext.activeState.awb.gains.green = 1.0;\n+\tcontext.activeState.awb.gains.manual.red = 1.0;\n+\tcontext.activeState.awb.gains.manual.blue = 1.0;\n+\tcontext.activeState.awb.gains.manual.green = 1.0;\n+\tcontext.activeState.awb.gains.automatic.red = 1.0;\n+\tcontext.activeState.awb.gains.automatic.blue = 1.0;\n+\tcontext.activeState.awb.gains.automatic.green = 1.0;\n \tcontext.activeState.awb.autoEnabled = true;\n \n \t/*\n@@ -75,13 +78,22 @@ uint32_t Awb::estimateCCT(double red, double green, double blue)\n * \\copydoc libcamera::ipa::Algorithm::prepare\n */\n void Awb::prepare(IPAContext &context, const uint32_t frame,\n-\t\t [[maybe_unused]] RkISP1FrameContext &frameContext,\n-\t\t rkisp1_params_cfg *params)\n+\t\t RkISP1FrameContext &frameContext, rkisp1_params_cfg *params)\n {\n-\tparams->others.awb_gain_config.gain_green_b = 256 * context.activeState.awb.gains.green;\n-\tparams->others.awb_gain_config.gain_blue = 256 * context.activeState.awb.gains.blue;\n-\tparams->others.awb_gain_config.gain_red = 256 * context.activeState.awb.gains.red;\n-\tparams->others.awb_gain_config.gain_green_r = 256 * context.activeState.awb.gains.green;\n+\t/*\n+\t * This is the latest time we can read the active state. This is the\n+\t * most up-to-date automatic values we can read.\n+\t */\n+\tif (frameContext.awb.autoEnabled) {\n+\t\tframeContext.awb.gains.red = context.activeState.awb.gains.automatic.red;\n+\t\tframeContext.awb.gains.green = context.activeState.awb.gains.automatic.green;\n+\t\tframeContext.awb.gains.blue = context.activeState.awb.gains.automatic.blue;\n+\t}\n+\n+\tparams->others.awb_gain_config.gain_green_b = 256 * frameContext.awb.gains.green;\n+\tparams->others.awb_gain_config.gain_blue = 256 * frameContext.awb.gains.blue;\n+\tparams->others.awb_gain_config.gain_red = 256 * frameContext.awb.gains.red;\n+\tparams->others.awb_gain_config.gain_green_r = 256 * frameContext.awb.gains.green;\n \n \t/* Update the gains. */\n \tparams->module_cfg_update |= RKISP1_CIF_ISP_MODULE_AWB_GAIN;\n@@ -127,7 +139,7 @@ void Awb::prepare(IPAContext &context, const uint32_t frame,\n */\n void Awb::queueRequest(IPAContext &context,\n \t\t [[maybe_unused]] const uint32_t frame,\n-\t\t [[maybe_unused]] RkISP1FrameContext &frameContext,\n+\t\t RkISP1FrameContext &frameContext,\n \t\t const ControlList &controls)\n {\n \tauto &awb = context.activeState.awb;\n@@ -142,21 +154,29 @@ void Awb::queueRequest(IPAContext &context,\n \n \tconst auto &colourGains = controls.get(controls::ColourGains);\n \tif (colourGains && !awb.autoEnabled) {\n-\t\tawb.gains.red = (*colourGains)[0];\n-\t\tawb.gains.blue = (*colourGains)[1];\n+\t\tawb.gains.manual.red = (*colourGains)[0];\n+\t\tawb.gains.manual.blue = (*colourGains)[1];\n \n \t\tLOG(RkISP1Awb, Debug)\n-\t\t\t<< \"Set colour gains to red: \" << awb.gains.red\n-\t\t\t<< \", blue: \" << awb.gains.blue;\n+\t\t\t<< \"Set colour gains to red: \" << awb.gains.manual.red\n+\t\t\t<< \", blue: \" << awb.gains.manual.blue;\n+\t}\n+\n+\tframeContext.awb.autoEnabled = awb.autoEnabled;\n+\n+\tif (!awb.autoEnabled) {\n+\t\tframeContext.awb.gains.red = awb.gains.manual.red;\n+\t\tframeContext.awb.gains.green = 1.0;\n+\t\tframeContext.awb.gains.blue = awb.gains.manual.blue;\n \t}\n }\n \n /**\n * \\copydoc libcamera::ipa::Algorithm::process\n */\n-void Awb::process([[maybe_unused]] IPAContext &context,\n+void Awb::process(IPAContext &context,\n \t\t [[maybe_unused]] const uint32_t frame,\n-\t\t [[maybe_unused]] RkISP1FrameContext &frameCtx,\n+\t\t RkISP1FrameContext &frameContext,\n \t\t const rkisp1_stat_buffer *stats)\n {\n \tconst rkisp1_cif_isp_stat *params = &stats->params;\n@@ -187,30 +207,27 @@ void Awb::process([[maybe_unused]] IPAContext &context,\n \tdouble greenMean = 1.1636 * yMean - 0.4045 * cbMean - 0.7949 * crMean;\n \tdouble blueMean = 1.1636 * yMean + 1.9912 * cbMean - 0.0250 * crMean;\n \n+\tframeContext.awb.temperatureK = estimateCCT(redMean, greenMean, blueMean);\n+\n \t/* Estimate the red and blue gains to apply in a grey world. */\n \tdouble redGain = greenMean / (redMean + 1);\n \tdouble blueGain = greenMean / (blueMean + 1);\n \n \t/* Filter the values to avoid oscillations. */\n \tdouble speed = 0.2;\n-\tredGain = speed * redGain + (1 - speed) * activeState.awb.gains.red;\n-\tblueGain = speed * blueGain + (1 - speed) * activeState.awb.gains.blue;\n+\tredGain = speed * redGain + (1 - speed) * activeState.awb.gains.automatic.red;\n+\tblueGain = speed * blueGain + (1 - speed) * activeState.awb.gains.automatic.blue;\n \n \t/*\n \t * Gain values are unsigned integer value, range 0 to 4 with 8 bit\n-\t * fractional part.\n+\t * fractional part. Hardcode the green gain to 1.0.\n \t */\n-\tif (activeState.awb.autoEnabled) {\n-\t\tactiveState.awb.gains.red = std::clamp(redGain, 0.0, 1023.0 / 256);\n-\t\tactiveState.awb.gains.blue = std::clamp(blueGain, 0.0, 1023.0 / 256);\n-\t}\n-\t/* Hardcode the green gain to 1.0. */\n-\tactiveState.awb.gains.green = 1.0;\n+\tactiveState.awb.gains.automatic.red = std::clamp(redGain, 0.0, 1023.0 / 256);\n+\tactiveState.awb.gains.automatic.blue = std::clamp(blueGain, 0.0, 1023.0 / 256);\n+\tactiveState.awb.gains.automatic.green = 1.0;\n \n-\tactiveState.awb.temperatureK = estimateCCT(redMean, greenMean, blueMean);\n-\n-\tLOG(RkISP1Awb, Debug) << \"Gain found for red: \" << context.activeState.awb.gains.red\n-\t\t\t << \" and for blue: \" << context.activeState.awb.gains.blue;\n+\tLOG(RkISP1Awb, Debug) << \"Gain found for red: \" << activeState.awb.gains.automatic.red\n+\t\t\t << \" and for blue: \" << activeState.awb.gains.automatic.blue;\n }\n \n REGISTER_IPA_ALGORITHM(Awb, \"Awb\")\ndiff --git a/src/ipa/rkisp1/ipa_context.cpp b/src/ipa/rkisp1/ipa_context.cpp\nindex 88e0631c8d39..cd1443e1ed46 100644\n--- a/src/ipa/rkisp1/ipa_context.cpp\n+++ b/src/ipa/rkisp1/ipa_context.cpp\n@@ -120,17 +120,29 @@ namespace libcamera::ipa::rkisp1 {\n * \\struct IPAActiveState::awb.gains\n * \\brief White balance gains\n *\n- * \\var IPAActiveState::awb.gains.red\n- * \\brief White balance gain for R channel\n+ * \\struct IPAActiveState::awb.gains.manual\n+ * \\brief Manual white balance gains (set through requests)\n *\n- * \\var IPAActiveState::awb.gains.green\n- * \\brief White balance gain for G channel\n+ * \\var IPAActiveState::awb.gains.manual.red\n+ * \\brief Manual white balance gain for R channel\n *\n- * \\var IPAActiveState::awb.gains.blue\n- * \\brief White balance gain for B channel\n+ * \\var IPAActiveState::awb.gains.manual.green\n+ * \\brief Manual white balance gain for G channel\n *\n- * \\var IPAActiveState::awb.temperatureK\n- * \\brief Estimated color temperature\n+ * \\var IPAActiveState::awb.gains.manual.blue\n+ * \\brief Manual white balance gain for B channel\n+ *\n+ * \\struct IPAActiveState::awb.gains.automatic\n+ * \\brief Automatic white balance gains (computed by the algorithm)\n+ *\n+ * \\var IPAActiveState::awb.gains.automatic.red\n+ * \\brief Automatic white balance gain for R channel\n+ *\n+ * \\var IPAActiveState::awb.gains.automatic.green\n+ * \\brief Automatic white balance gain for G channel\n+ *\n+ * \\var IPAActiveState::awb.gains.automatic.blue\n+ * \\brief Automatic white balance gain for B channel\n *\n * \\var IPAActiveState::awb.autoEnabled\n * \\brief Whether the Auto White Balance algorithm is enabled\n@@ -201,6 +213,29 @@ namespace libcamera::ipa::rkisp1 {\n * The gain should be adapted to the sensor specific gain code before applying.\n */\n \n+/**\n+ * \\var RkISP1FrameContext::awb\n+ * \\brief Automatic White Balance parameters for this frame\n+ *\n+ * \\struct RkISP1FrameContext::awb.gains\n+ * \\brief White balance gains\n+ *\n+ * \\var RkISP1FrameContext::awb.gains.red\n+ * \\brief White balance gain for R channel\n+ *\n+ * \\var RkISP1FrameContext::awb.gains.green\n+ * \\brief White balance gain for G channel\n+ *\n+ * \\var RkISP1FrameContext::awb.gains.blue\n+ * \\brief White balance gain for B channel\n+ *\n+ * \\var RkISP1FrameContext::awb.temperatureK\n+ * \\brief Estimated color temperature\n+ *\n+ * \\var RkISP1FrameContext::awb.autoEnabled\n+ * \\brief Whether the Auto White Balance algorithm is enabled\n+ */\n+\n /**\n * \\var RkISP1FrameContext::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 ecf993cd22d7..d97aae9a97b4 100644\n--- a/src/ipa/rkisp1/ipa_context.h\n+++ b/src/ipa/rkisp1/ipa_context.h\n@@ -56,12 +56,18 @@ struct IPAActiveState {\n \n \tstruct {\n \t\tstruct {\n-\t\t\tdouble red;\n-\t\t\tdouble green;\n-\t\t\tdouble blue;\n+\t\t\tstruct {\n+\t\t\t\tdouble red;\n+\t\t\t\tdouble green;\n+\t\t\t\tdouble blue;\n+\t\t\t} manual;\n+\t\t\tstruct {\n+\t\t\t\tdouble red;\n+\t\t\t\tdouble green;\n+\t\t\t\tdouble blue;\n+\t\t\t} automatic;\n \t\t} gains;\n \n-\t\tdouble temperatureK;\n \t\tbool autoEnabled;\n \t} awb;\n \n@@ -90,6 +96,17 @@ struct RkISP1FrameContext : public FrameContext {\n \t\tdouble gain;\n \t} agc;\n \n+\tstruct {\n+\t\tstruct {\n+\t\t\tdouble red;\n+\t\t\tdouble green;\n+\t\t\tdouble blue;\n+\t\t} gains;\n+\n+\t\tdouble temperatureK;\n+\t\tbool autoEnabled;\n+\t} awb;\n+\n \tstruct {\n \t\tuint32_t exposure;\n \t\tdouble gain;\n", "prefixes": [ "libcamera-devel", "v4", "20/32" ] }