[{"id":38724,"web_url":"https://patchwork.libcamera.org/comment/38724/","msgid":"<85zf2e2ga2.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","date":"2026-05-05T12:27:01","subject":"Re: [PATCH] ipa: simple: adjust: Support gamma, contrast,\n\tsaturation defaults from YAML","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"d3vv3 <devve.3@gmail.com> writes:\n\n> Read default values for gamma, contrast, and saturation from the tuning\n> file so sensors can specify different image processing defaults without\n> code changes. Falls back to prior defaults (gamma 2.2, contrast 1.0,\n> saturation 1.0) when not specified in YAML.\n>\n> Signed-off-by: d3vv3 <devve.3@gmail.com>\n> ---\n>  src/ipa/simple/algorithms/adjust.cpp | 26 ++++++++++++++++----------\n>  src/ipa/simple/algorithms/adjust.h   |  4 ++++\n>  2 files changed, 20 insertions(+), 10 deletions(-)\n>\n> diff --git a/src/ipa/simple/algorithms/adjust.cpp b/src/ipa/simple/algorithms/adjust.cpp\n> index 8bf39c4c..2f70519c 100644\n> --- a/src/ipa/simple/algorithms/adjust.cpp\n> +++ b/src/ipa/simple/algorithms/adjust.cpp\n> @@ -14,6 +14,7 @@\n>  #include <libcamera/control_ids.h>\n>  \n>  #include \"libcamera/internal/matrix.h\"\n> +#include \"libcamera/internal/yaml_parser.h\"\n>  \n>  namespace libcamera {\n>  \n> @@ -24,24 +25,29 @@ constexpr float kDefaultSaturation = 1.0f;\n>  \n>  LOG_DEFINE_CATEGORY(IPASoftAdjust)\n>  \n> -int Adjust::init(IPAContext &context, [[maybe_unused]] const ValueNode &tuningData)\n> +int Adjust::init(IPAContext &context, const ValueNode &tuningData)\n>  {\n> +\tdefaultGamma_ = tuningData[\"gamma\"].get<float>().value_or(kDefaultGamma);\n> +\tdefaultContrast_ = tuningData[\"contrast\"].get<float>().value_or(kDefaultContrast);\n> +\tdefaultSaturation_ = tuningData[\"saturation\"].get<float>().value_or(kDefaultSaturation);\n> +\n>  \tcontext.ctrlMap[&controls::Gamma] =\n> -\t\tControlInfo(0.1f, 10.0f, kDefaultGamma);\n> +\t\tControlInfo(0.1f, 10.0f, defaultGamma_);\n>  \tcontext.ctrlMap[&controls::Contrast] =\n> -\t\tControlInfo(0.0f, 2.0f, kDefaultContrast);\n> +\t\tControlInfo(0.0f, 2.0f, defaultContrast_);\n>  \tif (context.ccmEnabled)\n>  \t\tcontext.ctrlMap[&controls::Saturation] =\n> -\t\t\tControlInfo(0.0f, 2.0f, kDefaultSaturation);\n> +\t\t\tControlInfo(0.0f, 2.0f, defaultSaturation_);\n> +\n>  \treturn 0;\n>  }\n>  \n>  int Adjust::configure(IPAContext &context,\n>  \t\t      [[maybe_unused]] const IPAConfigInfo &configInfo)\n>  {\n> -\tcontext.activeState.knobs.gamma = kDefaultGamma;\n> -\tcontext.activeState.knobs.contrast = std::optional<float>();\n> -\tcontext.activeState.knobs.saturation = std::optional<float>();\n> +\tcontext.activeState.knobs.gamma = defaultGamma_;\n> +\tcontext.activeState.knobs.contrast = defaultContrast_;\n> +\tcontext.activeState.knobs.saturation = defaultSaturation_;\n\nThen the given variables shouldn't be std::optional any more, right?\n\n>  \treturn 0;\n>  }\n> @@ -107,7 +113,7 @@ void Adjust::prepare(IPAContext &context,\n>  \t}\n>  \n>  \tparams->gamma = 1.0 / context.activeState.knobs.gamma;\n> -\tconst float contrast = context.activeState.knobs.contrast.value_or(kDefaultContrast);\n> +\tconst float contrast = context.activeState.knobs.contrast.value_or(defaultContrast_);\n\nAnd this value_or doesn't make sense as the value is always set?\n\n>  \tparams->contrastExp = tan(std::clamp(contrast * M_PI_4, 0.0, M_PI_2 - 0.00001));\n>  }\n>  \n> @@ -121,10 +127,10 @@ void Adjust::process([[maybe_unused]] IPAContext &context,\n>  \tmetadata.set(controls::Gamma, gamma);\n>  \n>  \tconst auto &contrast = frameContext.contrast;\n> -\tmetadata.set(controls::Contrast, contrast.value_or(kDefaultContrast));\n> +\tmetadata.set(controls::Contrast, contrast.value_or(defaultContrast_));\n>  \n>  \tconst auto &saturation = frameContext.saturation;\n> -\tmetadata.set(controls::Saturation, saturation.value_or(kDefaultSaturation));\n> +\tmetadata.set(controls::Saturation, saturation.value_or(defaultSaturation_));\n\nAre these also always set?\n\n>  }\n>  \n>  REGISTER_IPA_ALGORITHM(Adjust, \"Adjust\")\n> diff --git a/src/ipa/simple/algorithms/adjust.h b/src/ipa/simple/algorithms/adjust.h\n> index 49c1f26c..a836b51b 100644\n> --- a/src/ipa/simple/algorithms/adjust.h\n> +++ b/src/ipa/simple/algorithms/adjust.h\n> @@ -43,6 +43,10 @@ public:\n>  \n>  private:\n>  \tvoid applySaturation(Matrix<float, 3, 3> &ccm, float saturation);\n> +\n> +\tfloat defaultGamma_;\n> +\tfloat defaultContrast_;\n> +\tfloat defaultSaturation_;\n>  };\n>  \n>  } /* namespace ipa::soft::algorithms */","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 7C9A3BDCB5\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  5 May 2026 12:27:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2A7B26302A;\n\tTue,  5 May 2026 14:27:12 +0200 (CEST)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5F8A562E9D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  5 May 2026 14:27:10 +0200 (CEST)","from mail-wm1-f72.google.com (mail-wm1-f72.google.com\n\t[209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-541-tbGAsY2jMPmvqxx8nQQn_w-1; Tue, 05 May 2026 08:27:07 -0400","by mail-wm1-f72.google.com with SMTP id\n\t5b1f17b1804b1-488c2cc0cbaso46431585e9.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 05 May 2026 05:27:04 -0700 (PDT)","from mzamazal-thinkpadp1gen7.tpbc.csb ([213.175.37.14])\n\tby smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-48a8eba8487sm344511835e9.11.2026.05.05.05.27.02\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 05 May 2026 05:27:02 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"L1WPAx6q\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1777984029;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=thQJtoExQVntrX30EjS/V1tHJwPBwqginorz4VW2QQY=;\n\tb=L1WPAx6qnZq9UeZZ5ppDegQhXvTGEdX1s/LGABTv7xHivfcmxM3LLSjgDf6hG1BsEIOPAd\n\t4itW8DCl+nSkjAkV+0CnAWTvsbOaCG7Y55/MT/DzFBVpAUxw3tIlF4Girh3aTgLCCKMwLp\n\tSk1CS3AEsdnKk0ULwHSyckeAiWdbAC0=","X-MC-Unique":"tbGAsY2jMPmvqxx8nQQn_w-1","X-Mimecast-MFC-AGG-ID":"tbGAsY2jMPmvqxx8nQQn_w_1777984024","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20251104; t=1777984023; x=1778588823;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject\n\t:date:message-id:reply-to;\n\tbh=thQJtoExQVntrX30EjS/V1tHJwPBwqginorz4VW2QQY=;\n\tb=HKQtV9qQhJ6fug5fPBKiqIQ7eXmPq1pAz3tAitJqFbiDEXixvwrEp2ycnv0xPR5Zik\n\txePxltLNcfTLY86hePOGB214YNiPqo54kQn/AYKuoMqbRIj9fjihCEt9hYqsybjU5jfn\n\t8osAbiz4hXwZRd7ipRQ466lN4LAZdR6iNGILHb5bu35c9cYrqpWhQWFqOLuGM5NsBC3T\n\tmixeS3niAbCKRTCGLYQOES1j7L8R1XdPYYCQXltJAlBIoIDiclY2vFX0LnpoBVa4sQ5j\n\tp4v9Oz76vvS8C9PCPe4v5GlZvbZGGa04p2Zfe/1qn9W2xJsQ018sBvMJyMoNN/ATO5EG\n\th9wg==","X-Gm-Message-State":"AOJu0YwwGEig/fwSwnBywJt88o6NUFiwoG/CuAFmvokQ9CrrNDOCgLDK\n\tpZLvnLgB4jlg9Dza7zFXvuv5Ap/ggbPCKVWgR2LhGIxKJOydjXhUPQpc7WeLhv9IwyLSLA0roNL\n\tVrOCSBjdBxN94LeJOHhqmCG59AxW0QK0uSSkofgZ/CGojlqHxm9IUl5Brdd7g8qL/rI+J/3D7oJ\n\ti32PXqDbEU2iIGpm/ckEHKpe9b8sqGv9mmanCZza+UaNPJp4puNPyiW/4TEq0=","X-Gm-Gg":"AeBDievF6jbGI6HOaJLorMsI+Ent9w+ldxF/62GA/cB4Qfs+Q4kh4tp/DTVg/3UuwZe\n\timGq0nHZrIRiqTYSO4y2fz9ztQTUmG/f7jpvSQWzILk9jCX0LW/fAELa+NJIuoTBQgYicP1SMZA\n\tCQG5FhVLaQ5rqc32eZSrGVy+aAeHabcDQiAK/5wPI4bPQXSut2HHEiC8ha/CE2Ya9FYOCHUJfy4\n\tl6OFqlAslMplInk8M4wHVE/lLCilEVzQqYTsWgtivvY0OyszFP5A0460HFm99dQIayKqy6Kn3VB\n\tJaXlKq0aJrlkZ6wEwAGU2+OjxCxt6Lgqd6M54mFm8qv/y+mNsllEK1F/i8gLvzAyL1aIuQ8hwVn\n\ti7DAFDyCehqKioU2yO3oye53pYR3Oc3RrWyGAP/6Cqg/9mYJj","X-Received":["by 2002:a05:600c:8710:b0:489:1cd2:610a with SMTP id\n\t5b1f17b1804b1-48a9887194dmr220243975e9.9.1777984023404; \n\tTue, 05 May 2026 05:27:03 -0700 (PDT)","by 2002:a05:600c:8710:b0:489:1cd2:610a with SMTP id\n\t5b1f17b1804b1-48a9887194dmr220243325e9.9.1777984022898; \n\tTue, 05 May 2026 05:27:02 -0700 (PDT)"],"From":"Milan Zamazal <mzamazal@redhat.com>","To":"d3vv3 <devve.3@gmail.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH] ipa: simple: adjust: Support gamma, contrast,\n\tsaturation defaults from YAML","In-Reply-To":"<20260501191400.985920-2-devve.3@gmail.com> (d3vv3's message of\n\t\"Fri, 1 May 2026 21:13:10 +0200\")","References":"<20260501191400.985920-1-devve.3@gmail.com>\n\t<20260501191400.985920-2-devve.3@gmail.com>","Date":"Tue, 05 May 2026 14:27:01 +0200","Message-ID":"<85zf2e2ga2.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"9HQE1Qb8US6Kie8721PuLIWGpbLTdTjV5VoAInTJECU_1777984024","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","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>"}}]