From patchwork Sun Jan 18 20:29:51 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rui Wang X-Patchwork-Id: 25827 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 93910BDCBE for ; Sun, 18 Jan 2026 20:30:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4F4C861FC1; Sun, 18 Jan 2026 21:30:49 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="BCFtaLs7"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A144B61FB9 for ; Sun, 18 Jan 2026 21:30:47 +0100 (CET) Received: from rui-Precision-7560.local (unknown [209.216.103.65]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 65CCF1BA; Sun, 18 Jan 2026 21:30:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1768768217; bh=EN+gD+60+RQ71IAR2RSCziVEWdBfA3CuEyD0y+lE4Qc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BCFtaLs7LIjP+v40pOGmtlUyXsLfzgjXbFuCI+lWBI99in8Na2OEpmRCg75gfsCLm LnTQV9kC/EOrhs/iI7CLzrthu3BLOamw3WcRqjIhIfwSFDmB4TXtmVFWXFem/hmY/s zr9QstmpAJyL9T9y4wj1cz5vIzVOiY3AxZ9isxoE= From: Rui Wang To: libcamera-devel@lists.libcamera.org Cc: Rui Wang Subject: [PATCH v1 2/4] pa: rkisp1: algorithms: filter: Add helper fun and sharpness presets Date: Sun, 18 Jan 2026 15:29:51 -0500 Message-ID: <20260118202953.1554892-3-rui.wang@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260118202953.1554892-1-rui.wang@ideasonboard.com> References: <20260118202953.1554892-1-rui.wang@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Refactor the Filter algorithm to improve code organization and prepare for future sharpness control implementation. Add helper functions to separate concerns: - prepareDisabledMode(): Handle filter disable state - prepareEnabledMode(): Handle filter enable state with logging - logConfig(): Provide detailed filter configuration logging Introduce sharpness preset table (kSharpnessPresets) with 11 levels (0-10) defining sharpness factor combinations. These presets will be used in future commits to implement user-controllable sharpness levels. Move class documentation to follow the anonymous namespace for better code organization and consistency with other algorithms. No functional changes in this commit. Signed-off-by: Rui Wang --- src/ipa/rkisp1/algorithms/filter.cpp | 85 +++++++++++++++++++++++----- src/ipa/rkisp1/algorithms/filter.h | 7 +++ 2 files changed, 79 insertions(+), 13 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/filter.cpp b/src/ipa/rkisp1/algorithms/filter.cpp index 321e4122..eb4049fd 100644 --- a/src/ipa/rkisp1/algorithms/filter.cpp +++ b/src/ipa/rkisp1/algorithms/filter.cpp @@ -27,19 +27,6 @@ namespace libcamera { namespace ipa::rkisp1::algorithms { -/** - * \class Filter - * \brief RkISP1 Filter control - * - * Denoise and Sharpness filters will be applied by RkISP1 during the - * demosaicing step. The denoise filter is responsible for removing noise from - * the image, while the sharpness filter will enhance its acutance. - * - * \todo In current version the denoise and sharpness control is based on user - * controls. In a future version it should be controlled automatically by the - * algorithm. - */ - LOG_DEFINE_CATEGORY(RkISP1Filter) namespace { @@ -67,8 +54,44 @@ std::string modeName(int32_t mode) return "ReductionUnknown"; } + +struct SharpnessPreset { + uint32_t fac_sh0; + uint32_t fac_sh1; + uint32_t fac_mid; + uint32_t fac_bl0; + uint32_t fac_bl1; +}; + +/* + * Sharpness presets + * The presets are based on the following table. + */ +static constexpr SharpnessPreset kSharpnessPresets[] = { + { 0x04, 0x04, 0x04, 0x02, 0x00 }, /* Level 0 */ + { 0x07, 0x08, 0x06, 0x02, 0x00 }, /* Level 1 */ + { 0x0a, 0x0c, 0x08, 0x04, 0x00 }, /* Level 2 */ + { 0x0c, 0x10, 0x0a, 0x06, 0x02 }, /* Level 3 */ + { 0x10, 0x16, 0x0c, 0x08, 0x04 }, /* Level 4 */ + { 0x14, 0x1b, 0x10, 0x0a, 0x04 }, /* Level 5 */ + { 0x1a, 0x20, 0x13, 0x0c, 0x06 }, /* Level 6 */ + { 0x1e, 0x26, 0x17, 0x10, 0x08 }, /* Level 7 */ + { 0x24, 0x2c, 0x1d, 0x15, 0x0d }, /* Level 8 */ + { 0x2a, 0x30, 0x22, 0x1a, 0x14 }, /* Level 9 */ + { 0x30, 0x3f, 0x28, 0x24, 0x20 }, /* Level 10 */ +}; } /* namespace */ + +/** + * \class Filter + * \brief RkISP1 Filter control + * + * Denoise and Sharpness filters will be applied by RkISP1 during the + * demosaicing step. The denoise filter is responsible for removing noise from + * the image, while the sharpness filter will enhance its acutance. + */ + Filter::Filter() : noiseReductionModes_({}), activeMode_(noiseReductionModes_.end()) @@ -365,6 +388,42 @@ void Filter::prepare([[maybe_unused]] IPAContext &context, } } +void Filter::prepareDisabledMode(RkISP1Params *params) +{ + auto config = params->block(); + config.setEnabled(false); +} + +void Filter::prepareEnabledMode(const uint32_t frame, + IPAFrameContext &frameContext, + RkISP1Params *params) +{ + auto config = params->block(); + config.setEnabled(true); + + if (frameContext.filter.update || frame == 0) + logConfig(*config); +} + +void Filter::logConfig(const struct rkisp1_cif_isp_flt_config &config) +{ + LOG(RkISP1Filter, Debug) + << "Filter config: mode=" << config.mode + << " lum_weight=" << config.lum_weight + << " grn_stage1=" << (int)config.grn_stage1 + << " chr_h_mode=" << (int)config.chr_h_mode + << " chr_v_mode=" << (int)config.chr_v_mode + << " thresh_bl0=" << config.thresh_bl0 + << " thresh_bl1=" << config.thresh_bl1 + << " thresh_sh0=" << config.thresh_sh0 + << " thresh_sh1=" << config.thresh_sh1 + << " fac_sh1=" << config.fac_sh1 + << " fac_sh0=" << config.fac_sh0 + << " fac_mid=" << config.fac_mid + << " fac_bl0=" << config.fac_bl0 + << " fac_bl1=" << config.fac_bl1; +} + REGISTER_IPA_ALGORITHM(Filter, "Filter") } /* namespace ipa::rkisp1::algorithms */ diff --git a/src/ipa/rkisp1/algorithms/filter.h b/src/ipa/rkisp1/algorithms/filter.h index 3860adfd..19cf76d0 100644 --- a/src/ipa/rkisp1/algorithms/filter.h +++ b/src/ipa/rkisp1/algorithms/filter.h @@ -40,6 +40,13 @@ private: struct rkisp1_cif_isp_flt_config &config); bool loadConfig(int32_t mode); + + void logConfig(const struct rkisp1_cif_isp_flt_config &config); + void prepareDisabledMode(RkISP1Params *params); + void prepareEnabledMode(const uint32_t frame, + IPAFrameContext &frameContext, + RkISP1Params *params); + std::vector noiseReductionModes_; std::vector::const_iterator activeMode_; };