{"id":25824,"url":"https://patchwork.libcamera.org/api/1.1/patches/25824/?format=json","web_url":"https://patchwork.libcamera.org/patch/25824/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260116121658.215712-1-stefan.klug@ideasonboard.com>","date":"2026-01-16T12:16:14","name":"[v1] ipa: rkisp1: cproc: Fix brightness and contrast value handling","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"1aa71b8b306b3d82d7003a8ae4eb46bb5fc30c3f","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/1.1/people/184/?format=json","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/25824/mbox/","series":[{"id":5711,"url":"https://patchwork.libcamera.org/api/1.1/series/5711/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5711","date":"2026-01-16T12:16:14","name":"[v1] ipa: rkisp1: cproc: Fix brightness and contrast value handling","version":1,"mbox":"https://patchwork.libcamera.org/series/5711/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/25824/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/25824/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 C0B73C3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 16 Jan 2026 12:17:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F177861FA3;\n\tFri, 16 Jan 2026 13:17:04 +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 264F6615B2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 16 Jan 2026 13:17:04 +0100 (CET)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:cc1c:cb5b:bc84:204])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id C3CE54B3;\n\tFri, 16 Jan 2026 13:16: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=\"GxisCiqR\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1768565795;\n\tbh=0dsJCDBn3y6kCF1ZOdFVXYrXMKd33tDo8KbNS4P40jg=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=GxisCiqRAX8QnVyvc+LWW1NAUOXNncIWeOB77L5ox5h/7tsJX8H7PHAhWZN723gNW\n\t+s31+dgruEupcYPV8ghJZ+z94XDyyymCyKQaufFbpSZKvMvL6Lcd7PzVofDfU1CTsT\n\tVcYPuDWCqKPQXRqhBDh2l7meEu8cbhBWYEGnKFfA=","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","Subject":"[PATCH v1] ipa: rkisp1: cproc: Fix brightness and contrast value\n\thandling","Date":"Fri, 16 Jan 2026 13:16:14 +0100","Message-ID":"<20260116121658.215712-1-stefan.klug@ideasonboard.com>","X-Mailer":"git-send-email 2.51.0","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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>"},"content":"By reverse engineering it was discovered that the transfer curve applied\nby the CPROC module is\n\nYout = Yin * contrast + brightness/2.\n\nHowever the most common expectation on contrast is to not change the\nmiddle gray of an image. So the expected curve is:\n\nYout = (Yin - 0.5) * contrast + 0.5 + brightness\n\nMap the user expectation to the hardware by changing the brightness\nvalue written to the hardware. This also includes multiplying the\nrequested brightness value by two.\n\nNote: The limits of the brightness control are left as is even though\nthey can not be reached without changing the contrast. But limiting them\nto [0.5, 0.5] would cut off parts of the combined control space of\ncontrast + brightness.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\n---\n\nThis patch needs to be applied on top of the quantization series:\nhttps://patchwork.libcamera.org/project/libcamera/list/?series=5708\n---\n src/ipa/rkisp1/algorithms/cproc.cpp | 38 +++++++++++++++++++++++------\n src/ipa/rkisp1/ipa_context.h        |  1 +\n 2 files changed, 31 insertions(+), 8 deletions(-)","diff":"diff --git a/src/ipa/rkisp1/algorithms/cproc.cpp b/src/ipa/rkisp1/algorithms/cproc.cpp\nindex 7484e4780094..ec2b264a79b9 100644\n--- a/src/ipa/rkisp1/algorithms/cproc.cpp\n+++ b/src/ipa/rkisp1/algorithms/cproc.cpp\n@@ -100,13 +100,9 @@ void ColorProcessing::queueRequest(IPAContext &context,\n \n \tconst auto &brightness = controls.get(controls::Brightness);\n \tif (brightness) {\n-\t\tBrightnessQ value = *brightness;\n-\t\tif (cproc.brightness != value) {\n-\t\t\tcproc.brightness = value;\n-\t\t\tupdate = true;\n-\t\t}\n-\n-\t\tLOG(RkISP1CProc, Debug) << \"Set brightness to \" << value;\n+\t\tcproc.requestedBrightness = *brightness;\n+\t\tLOG(RkISP1CProc, Debug) << \"Set brightness to \" << *brightness;\n+\t\tupdate = true;\n \t}\n \n \tconst auto &contrast = controls.get(controls::Contrast);\n@@ -120,6 +116,24 @@ void ColorProcessing::queueRequest(IPAContext &context,\n \t\tLOG(RkISP1CProc, Debug) << \"Set contrast to \" << value;\n \t}\n \n+\t/*\n+\t * The CPROC module applies the transfer function\n+\t *\n+\t * Yout = Yin * contrast + brightness/2\n+\t *\n+\t * Most users expect that changing contrast doesn't change the middle\n+\t * gray and that the brightness value is normalized to one. So they\n+\t * expect a transfer function of\n+\t *\n+\t * Yout = (Yin - 0.5) * contrast + 0.5 + brightness\n+\t *\n+\t * To implement that with the given hardware we need to correct the\n+\t * brightness value.\n+\t */\n+\tif (update) {\n+\t\tcproc.brightness = (1 - cproc.contrast.value()) + 2 * cproc.requestedBrightness;\n+\t}\n+\n \tconst auto &hue = controls.get(controls::Hue);\n \tif (hue) {\n \t\t/* Scale the Hue from ]-90, +90] */\n@@ -179,7 +193,15 @@ void ColorProcessing::process([[maybe_unused]] IPAContext &context,\n \t\t\t      [[maybe_unused]] const rkisp1_stat_buffer *stats,\n \t\t\t      ControlList &metadata)\n {\n-\tmetadata.set(controls::Brightness, frameContext.cproc.brightness.value());\n+\t/*\n+\t * Report the actually applied brightness value. See queueRequest() for\n+\t * more details.\n+\t */\n+\tfloat actualBrightness = (frameContext.cproc.brightness.value() -\n+\t\t\t\t  (1 - frameContext.cproc.contrast.value())) /\n+\t\t\t\t 2;\n+\n+\tmetadata.set(controls::Brightness, actualBrightness);\n \tmetadata.set(controls::Contrast, frameContext.cproc.contrast.value());\n \tmetadata.set(controls::Hue, frameContext.cproc.hue.value() * kHueScale);\n \tmetadata.set(controls::Saturation, frameContext.cproc.saturation.value());\ndiff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\nindex 80b035044cda..309567858b64 100644\n--- a/src/ipa/rkisp1/ipa_context.h\n+++ b/src/ipa/rkisp1/ipa_context.h\n@@ -122,6 +122,7 @@ struct IPAActiveState {\n \t} ccm;\n \n \tstruct {\n+\t\tfloat requestedBrightness;\n \t\tBrightnessQ brightness;\n \t\tContrastQ contrast;\n \t\tHueQ hue;\n","prefixes":["v1"]}