[{"id":36598,"web_url":"https://patchwork.libcamera.org/comment/36598/","msgid":"<176202080460.3925733.11870065195214555843@ping.linuxembedded.co.uk>","date":"2025-11-01T18:13:24","subject":"Re: [PATCH v1 07/17] ipa: rkisp1: algorithms: dpf: refactor Dpf init\n\tfor tuning","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Rui Wang (2025-10-28 21:17:40)\n> Replace the inline parsing in init() with a call to parseConfig(). This\n> simplifies init() and allows the parsing logic to be reused. The refactor\n> also adds logging of the parsed base tuning and preserves the base config\n> for manual mode restoration.\n> \n> The init method now:\n> - Calls parseConfig() to load tuning data\n> - Logs the parsed base configuration\n> - Caches base config for manual mode restore\n> - Logs ISO level count if present\n> - Registers controls via getControlMap()\n\nI think the clue is 'refactor' but if we're refactoring by patch 7 then\nsome of the earlier patches should be rethought.\n\n> Signed-off-by: Rui Wang <rui.wang@ideasonboard.com>\n> ---\n>  src/ipa/rkisp1/algorithms/dpf.cpp | 141 +++++-------------------------\n>  1 file changed, 24 insertions(+), 117 deletions(-)\n> \n> diff --git a/src/ipa/rkisp1/algorithms/dpf.cpp b/src/ipa/rkisp1/algorithms/dpf.cpp\n> index d1b89691..a5059741 100644\n> --- a/src/ipa/rkisp1/algorithms/dpf.cpp\n> +++ b/src/ipa/rkisp1/algorithms/dpf.cpp\n> @@ -8,6 +8,7 @@\n>  #include \"dpf.h\"\n>  \n>  #include <algorithm>\n> +#include <array>\n>  #include <string>\n>  #include <vector>\n>  \n> @@ -47,127 +48,33 @@ Dpf::Dpf()\n>  int Dpf::init([[maybe_unused]] IPAContext &context,\n>               const YamlObject &tuningData)\n>  {\n> -       std::vector<uint8_t> values;\n> -\n> -       /*\n> -        * The domain kernel is configured with a 9x9 kernel for the green\n> -        * pixels, and a 13x9 or 9x9 kernel for red and blue pixels.\n> -        */\n> -       const YamlObject &dFObject = tuningData[\"DomainFilter\"];\n> -\n> -       /*\n> -        * For the green component, we have the 9x9 kernel specified\n> -        * as 6 coefficients:\n> -        *    Y\n> -        *    ^\n> -        *  4 | 6   5   4   5   6\n> -        *  3 |   5   3   3   5\n> -        *  2 | 5   3   2   3   5\n> -        *  1 |   3   1   1   3\n> -        *  0 - 4   2   0   2   4\n> -        * -1 |   3   1   1   3\n> -        * -2 | 5   3   2   3   5\n> -        * -3 |   5   3   3   5\n> -        * -4 | 6   5   4   5   6\n> -        *    +---------|--------> X\n> -        *     -4....-1 0 1 2 3 4\n> -        */\n> -       values = dFObject[\"g\"].getList<uint8_t>().value_or(std::vector<uint8_t>{});\n> -       if (values.size() != RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS) {\n> -               LOG(RkISP1Dpf, Error)\n> -                       << \"Invalid 'DomainFilter:g': expected \"\n> -                       << RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS\n> -                       << \" elements, got \" << values.size();\n\nIf a series is adding all this code and then removing it then something\nhas gone wrong.\n\n\n\n> +       /* Parse tuning block */\n> +       if (!parseConfig(tuningData))\n>                 return -EINVAL;\n> -       }\n>  \n> -       std::copy_n(values.begin(), values.size(),\n> -                   std::begin(config_.g_flt.spatial_coeff));\n> -\n> -       config_.g_flt.gr_enable = true;\n> -       config_.g_flt.gb_enable = true;\n> -\n> -       /*\n> -        * For the red and blue components, we have the 13x9 kernel specified\n> -        * as 6 coefficients:\n> -        *\n> -        *    Y\n> -        *    ^\n> -        *  4 | 6   5   4   3   4   5   6\n> -        *    |\n> -        *  2 | 5   4   2   1   2   4   5\n> -        *    |\n> -        *  0 - 5   3   1   0   1   3   5\n> -        *    |\n> -        * -2 | 5   4   2   1   2   4   5\n> -        *    |\n> -        * -4 | 6   5   4   3   4   5   6\n> -        *    +-------------|------------> X\n> -        *     -6  -4  -2   0   2   4   6\n> -        *\n> -        * For a 9x9 kernel, columns -6 and 6 are dropped, so coefficient\n> -        * number 6 is not used.\n> -        */\n> -       values = dFObject[\"rb\"].getList<uint8_t>().value_or(std::vector<uint8_t>{});\n> -       if (values.size() != RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS &&\n> -           values.size() != RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS - 1) {\n> -               LOG(RkISP1Dpf, Error)\n> -                       << \"Invalid 'DomainFilter:rb': expected \"\n> -                       << RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS - 1\n> -                       << \" or \" << RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS\n> -                       << \" elements, got \" << values.size();\n> -               return -EINVAL;\n> -       }\n> -\n> -       config_.rb_flt.fltsize = values.size() == RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS\n> -                              ? RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_13x9\n> -                              : RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_9x9;\n> -\n> -       std::copy_n(values.begin(), values.size(),\n> -                   std::begin(config_.rb_flt.spatial_coeff));\n> -\n> -       config_.rb_flt.r_enable = true;\n> -       config_.rb_flt.b_enable = true;\n> -\n> -       /*\n> -        * The range kernel is configured with a noise level lookup table (NLL)\n> -        * which stores a piecewise linear function that characterizes the\n> -        * sensor noise profile as a noise level function curve (NLF).\n> -        */\n> -       const YamlObject &rFObject = tuningData[\"NoiseLevelFunction\"];\n> -\n> -       std::vector<uint16_t> nllValues;\n> -       nllValues = rFObject[\"coeff\"].getList<uint16_t>().value_or(std::vector<uint16_t>{});\n> -       if (nllValues.size() != RKISP1_CIF_ISP_DPF_MAX_NLF_COEFFS) {\n> -               LOG(RkISP1Dpf, Error)\n> -                       << \"Invalid 'RangeFilter:coeff': expected \"\n> -                       << RKISP1_CIF_ISP_DPF_MAX_NLF_COEFFS\n> -                       << \" elements, got \" << nllValues.size();\n> -               return -EINVAL;\n> -       }\n> +       /* Log parsed base tuning (counts are always full-sized for base). */\n> +       LOG(RkISP1Dpf, Info)\n> +               << \"DPF init: base tuning parsed, G coeffs=\"\n> +               << RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS\n> +               << \", RB fltsize=\"\n> +               << (config_.rb_flt.fltsize == RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_13x9 ? \"13x9\" : \"9x9\")\n> +               << \", NLL coeffs=\" << RKISP1_CIF_ISP_DPF_MAX_NLF_COEFFS\n> +               << \", NLL scale=\"\n> +               << (config_.nll.scale_mode == RKISP1_CIF_ISP_NLL_SCALE_LOGARITHMIC ? \"log\" : \"linear\")\n> +               << \", Strength (r,g,b)=\"\n> +               << (int)strengthConfig_.r << \",\" << (int)strengthConfig_.g\n> +               << \",\" << (int)strengthConfig_.b;\n> +\n> +       /* Preserve base (non-ISO) YAML configuration for restoration after manual mode. */\n> +       baseConfig_ = config_;\n> +       baseStrengthConfig_ = strengthConfig_;\n>  \n> -       std::copy_n(nllValues.begin(), nllValues.size(),\n> -                   std::begin(config_.nll.coeff));\n> -\n> -       std::string scaleMode = rFObject[\"scale-mode\"].get<std::string>(\"\");\n> -       if (scaleMode == \"linear\") {\n> -               config_.nll.scale_mode = RKISP1_CIF_ISP_NLL_SCALE_LINEAR;\n> -       } else if (scaleMode == \"logarithmic\") {\n> -               config_.nll.scale_mode = RKISP1_CIF_ISP_NLL_SCALE_LOGARITHMIC;\n> -       } else {\n> -               LOG(RkISP1Dpf, Error)\n> -                       << \"Invalid 'RangeFilter:scale-mode': expected \"\n> -                       << \"'linear' or 'logarithmic' value, got \"\n> -                       << scaleMode;\n> -               return -EINVAL;\n> +       /* Optional ISO-banded tuning */\n> +       if (useIsoLevels_) {\n> +               LOG(RkISP1Dpf, Info)\n> +                       << \"DPF init: loaded \" << isoLevels_.size()\n> +                       << \" ISO level(s) from tuning\";\n>         }\n> -\n> -       const YamlObject &fSObject = tuningData[\"FilterStrength\"];\n> -\n> -       strengthConfig_.r = fSObject[\"r\"].get<uint16_t>(64);\n> -       strengthConfig_.g = fSObject[\"g\"].get<uint16_t>(64);\n> -       strengthConfig_.b = fSObject[\"b\"].get<uint16_t>(64);\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 CD8CEBDE4C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat,  1 Nov 2025 18:13:29 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 22D016086F;\n\tSat,  1 Nov 2025 19:13:29 +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 799D2606D5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  1 Nov 2025 19:13:27 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DC6AD236;\n\tSat,  1 Nov 2025 19:11:35 +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=\"UspqVJWK\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1762020695;\n\tbh=2RqCoVHLyPdifUBFQ64q+CJ5xqhOlTW8Wq/ynbNYhIg=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=UspqVJWKSPI8xcOpQKjhPKSZP3AyWYGmsmdlpqCy6Nh3kS2pxyQVCbF8N1KX2DNQ3\n\t8ga57s48AmVEbiUDd+Asxc5zK7ozaK4EcW3y70S/fBnS6AiHe4hEXXfWVaLukIoPmQ\n\tR0tLDHP9ac+GLbjNp7oShAX8PuGUsH8Humt+q8uA=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20251028211751.2761420-7-rui.wang@ideasonboard.com>","References":"<20251028211751.2761420-1-rui.wang@ideasonboard.com>\n\t<20251028211751.2761420-7-rui.wang@ideasonboard.com>","Subject":"Re: [PATCH v1 07/17] ipa: rkisp1: algorithms: dpf: refactor Dpf init\n\tfor tuning","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Rui Wang <rui.wang@ideasonboard.com>","To":"Rui Wang <rui.wang@ideasonboard.com>, libcamera-devel@lists.libcamera.org","Date":"Sat, 01 Nov 2025 18:13:24 +0000","Message-ID":"<176202080460.3925733.11870065195214555843@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","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>"}}]