[{"id":35923,"web_url":"https://patchwork.libcamera.org/comment/35923/","msgid":"<175828086809.3174118.7587180219195932112@neptunite.rasen.tech>","date":"2025-09-19T11:21:08","subject":"Re: [PATCH v5 01/19] ipa: rkisp1: Add basic compression algorithm","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Hi Stefan,\n\nThanks for the patch.\n\nQuoting Stefan Klug (2025-09-19 18:40:16)\n> The i.MX8 M Plus has a compression curve inside the compand block.  This\n> curve is necessary to process HDR stitched data and is useful for other\n> aspects like applying a digital gain to the incoming sensor data.\n> \n> Add a basic algorithm for the compression curve. This algorithm has a\n> hardcoded input width of 20bit and output width of 12bit which matches\n> the imx8mp pipeline. Only a static gain is supported in this version.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> ---\n> \n> Changes in v5:\n> - Removed unnecessary include\n> - Added check for compress.supported in prepare()\n> - Collected tag\n> \n> Changes in v4:\n> - Moved activeState.compress.supported to\n>   configuration.compress.supported\n> - Added documentation\n> - Fixed typo in documentation\n> - Replaced constant with RKISP1_CIF_ISP_COMPAND_NUM_POINTS\n> \n> Changes in v3:\n> - Removed unused member\n> - Fixed comment referencing copy-paste source\n> - Ensure activeState.compress.supported stays false if unsupported\n> ---\n>  src/ipa/rkisp1/algorithms/compress.cpp | 103 +++++++++++++++++++++++++\n>  src/ipa/rkisp1/algorithms/compress.h   |  30 +++++++\n>  src/ipa/rkisp1/algorithms/meson.build  |   1 +\n>  src/ipa/rkisp1/ipa_context.cpp         |  19 +++++\n>  src/ipa/rkisp1/ipa_context.h           |   9 +++\n>  5 files changed, 162 insertions(+)\n>  create mode 100644 src/ipa/rkisp1/algorithms/compress.cpp\n>  create mode 100644 src/ipa/rkisp1/algorithms/compress.h\n> \n> diff --git a/src/ipa/rkisp1/algorithms/compress.cpp b/src/ipa/rkisp1/algorithms/compress.cpp\n> new file mode 100644\n> index 000000000000..6445cd14bae3\n> --- /dev/null\n> +++ b/src/ipa/rkisp1/algorithms/compress.cpp\n> @@ -0,0 +1,103 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2025, Ideas On Board\n> + *\n> + * RkISP1 Compression curve\n> + */\n> +#include \"compress.h\"\n> +\n> +#include <linux/videodev2.h>\n> +\n> +#include <libcamera/base/log.h>\n> +#include <libcamera/base/utils.h>\n> +\n> +#include \"linux/rkisp1-config.h\"\n> +\n> +/**\n> + * \\file compress.h\n> + */\n> +\n> +namespace libcamera {\n> +\n> +namespace ipa::rkisp1::algorithms {\n> +\n> +/**\n> + * \\class Compress\n> + * \\brief RkISP1 Compress curve\n> + *\n> + * This algorithm implements support for the compression curve in the compand\n> + * block available in the i.MX8 M Plus\n> + *\n> + * In its current version it only supports a static gain. This is useful for\n> + * the agc algorithm to compensate for exposure/gain quantization effects.\n> + *\n> + * This algorithm doesn't have any configuration options. It needs to be\n> + * configured per frame by other algorithms.\n> + *\n> + * Other algorithms can check configuration.compress.supported to see if\n> + * compression is available. If it is available they can configure it per frame\n> + * using frameContext.compress.enable and frameContext.compress.gain.\n> + */\n> +\n> +LOG_DEFINE_CATEGORY(RkISP1Compress)\n> +\n> +constexpr static int kRkISP1CompressInBits = 20;\n> +constexpr static int kRkISP1CompressOutBits = 12;\n> +\n> +/**\n> + * \\copydoc libcamera::ipa::Algorithm::configure\n> + */\n> +int Compress::configure(IPAContext &context,\n> +                       [[maybe_unused]] const IPACameraSensorInfo &configInfo)\n> +{\n> +       if (context.configuration.paramFormat != V4L2_META_FMT_RK_ISP1_EXT_PARAMS ||\n> +           !context.hw->compand) {\n> +               LOG(RkISP1Compress, Warning)\n> +                       << \"Compression is not supported by the hardware or kernel.\";\n> +               return 0;\n> +       }\n> +\n> +       context.configuration.compress.supported = true;\n> +       return 0;\n> +}\n> +\n> +/**\n> + * \\copydoc libcamera::ipa::Algorithm::prepare\n> + */\n> +void Compress::prepare([[maybe_unused]] IPAContext &context,\n> +                      [[maybe_unused]] const uint32_t frame,\n> +                      IPAFrameContext &frameContext,\n> +                      RkISP1Params *params)\n> +{\n> +       if (!context.configuration.compress.supported)\n> +               return;\n> +\n> +       auto comp = params->block<BlockType::CompandCompress>();\n> +       comp.setEnabled(frameContext.compress.enable);\n> +\n> +       if (!frameContext.compress.enable)\n> +               return;\n> +\n> +       int xmax = (1 << kRkISP1CompressInBits);\n> +       int ymax = (1 << kRkISP1CompressOutBits);\n> +       int inLogStep = std::log2(xmax / RKISP1_CIF_ISP_COMPAND_NUM_POINTS);\n> +\n> +       for (unsigned int i = 0; i < RKISP1_CIF_ISP_COMPAND_NUM_POINTS; i++) {\n> +               double x = (i + 1) * (1.0 / RKISP1_CIF_ISP_COMPAND_NUM_POINTS);\n> +               double y = x * frameContext.compress.gain;\n> +\n> +               comp->px[i] = inLogStep;\n> +               comp->x[i] = std::min<int>(x * xmax, xmax - 1);\n> +               comp->y[i] = std::min<int>(y * ymax, ymax - 1);\n> +       }\n> +\n> +       LOG(RkISP1Compress, Debug) << \"Compression: \" << kRkISP1CompressInBits\n> +                                  << \" bits to \" << kRkISP1CompressOutBits\n> +                                  << \" bits gain: \" << frameContext.compress.gain;\n> +}\n> +\n> +REGISTER_IPA_ALGORITHM(Compress, \"Compress\")\n> +\n> +} /* namespace ipa::rkisp1::algorithms */\n> +\n> +} /* namespace libcamera */\n> diff --git a/src/ipa/rkisp1/algorithms/compress.h b/src/ipa/rkisp1/algorithms/compress.h\n> new file mode 100644\n> index 000000000000..87797b8ebcc5\n> --- /dev/null\n> +++ b/src/ipa/rkisp1/algorithms/compress.h\n> @@ -0,0 +1,30 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2025, Ideas On Board\n> + *\n> + * RkISP1 Compression curve\n> + */\n> +\n> +#pragma once\n> +\n> +#include \"algorithm.h\"\n> +\n> +namespace libcamera {\n> +\n> +namespace ipa::rkisp1::algorithms {\n> +\n> +class Compress : public Algorithm\n> +{\n> +public:\n> +       Compress() = default;\n> +       ~Compress() = default;\n> +\n> +       int configure(IPAContext &context,\n> +                     const IPACameraSensorInfo &configInfo) override;\n> +       void prepare(IPAContext &context, const uint32_t frame,\n> +                    IPAFrameContext &frameContext,\n> +                    RkISP1Params *params) override;\n> +};\n> +\n> +} /* namespace ipa::rkisp1::algorithms */\n> +} /* namespace libcamera */\n> diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build\n> index c66b0b70b82f..2e42a80cf99d 100644\n> --- a/src/ipa/rkisp1/algorithms/meson.build\n> +++ b/src/ipa/rkisp1/algorithms/meson.build\n> @@ -5,6 +5,7 @@ rkisp1_ipa_algorithms = files([\n>      'awb.cpp',\n>      'blc.cpp',\n>      'ccm.cpp',\n> +    'compress.cpp',\n>      'cproc.cpp',\n>      'dpcc.cpp',\n>      'dpf.cpp',\n> diff --git a/src/ipa/rkisp1/ipa_context.cpp b/src/ipa/rkisp1/ipa_context.cpp\n> index 6509610573c0..15cb0afe9fe8 100644\n> --- a/src/ipa/rkisp1/ipa_context.cpp\n> +++ b/src/ipa/rkisp1/ipa_context.cpp\n> @@ -66,6 +66,14 @@ namespace libcamera::ipa::rkisp1 {\n>   * operates in manual or automatic mode.\n>   */\n>  \n> +/**\n> + * \\var IPASessionConfiguration::compress\n> + * \\brief Compress parameters configuration of the IPA\n> + *\n> + * \\var IPASessionConfiguration::agc.supported\n\ns/agc/compress/ ? :)\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> + * \\brief true if compression is supported and the algorithm is loaded\n> + */\n> +\n>  /**\n>   * \\var IPASessionConfiguration::lsc\n>   * \\brief Lens Shading Correction configuration of the IPA\n> @@ -377,6 +385,17 @@ namespace libcamera::ipa::rkisp1 {\n>   * \\brief Colour Correction Matrix\n>   */\n>  \n> +/**\n> + * \\var IPAFrameContext::compress\n> + * \\brief Compress parameters for this frame\n> + *\n> + * \\struct IPAFrameContext::compress.enable\n> + * \\brief True if compression is enabled\n> + *\n> + * \\var IPAFrameContext::compress.gain\n> + * \\brief The gain applied with the compression curve\n> + */\n> +\n>  /**\n>   * \\var IPAFrameContext::cproc\n>   * \\brief Color Processing parameters for this frame\n> diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\n> index 7ccc7b501aff..a723c79b04d9 100644\n> --- a/src/ipa/rkisp1/ipa_context.h\n> +++ b/src/ipa/rkisp1/ipa_context.h\n> @@ -49,6 +49,10 @@ struct IPASessionConfiguration {\n>                 bool enabled;\n>         } awb;\n>  \n> +       struct {\n> +               bool supported;\n> +       } compress;\n> +\n>         struct {\n>                 bool enabled;\n>         } lsc;\n> @@ -158,6 +162,11 @@ struct IPAFrameContext : public FrameContext {\n>                 bool update;\n>         } cproc;\n>  \n> +       struct {\n> +               bool enable;\n> +               double gain;\n> +       } compress;\n> +\n>         struct {\n>                 bool denoise;\n>                 bool update;\n> -- \n> 2.48.1\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 DEA39BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 19 Sep 2025 11:21:16 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C0BC76B597;\n\tFri, 19 Sep 2025 13:21:15 +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 5A7D562C35\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 19 Sep 2025 13:21:14 +0200 (CEST)","from neptunite.rasen.tech (unknown\n\t[IPv6:2404:7a81:160:2100:ae7e:60b0:e249:fbe5])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 95D2E50A;\n\tFri, 19 Sep 2025 13:19:53 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"hPC9DXOT\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1758280794;\n\tbh=TcoAdMattoV49iBwcw0V9zgcSCt+dHUQqjdjdTSI3N4=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=hPC9DXOTiRaeaIbUFQUvjlQAmw2fS5wjqkR+ZUbAvBXPPDTggEPqzODmguSR1PnAE\n\taNt4jEGtNjggBmchY5plr5avFuclSmx2DzwDf5OAtJaegyT5JdLOdg/XdiSNmoSUHS\n\t/Ijh8zSrWxzLFhTvkR0jaIkm69YxtK3Zy6Kq8e6U=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250919094041.183031-2-stefan.klug@ideasonboard.com>","References":"<20250919094041.183031-1-stefan.klug@ideasonboard.com>\n\t<20250919094041.183031-2-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v5 01/19] ipa: rkisp1: Add basic compression algorithm","From":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Fri, 19 Sep 2025 20:21:08 +0900","Message-ID":"<175828086809.3174118.7587180219195932112@neptunite.rasen.tech>","User-Agent":"alot/0.0.0","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>"}}]