{"id":20099,"url":"https://patchwork.libcamera.org/api/patches/20099/?format=json","web_url":"https://patchwork.libcamera.org/patch/20099/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20240524135256.649406-3-kieran.bingham@ideasonboard.com>","date":"2024-05-24T13:52:56","name":"[v2,2/2] libipa: camera_sensor_helper: Fix rounding of gainCode","commit_ref":null,"pull_url":null,"state":"rejected","archived":false,"hash":"72b1b43e7046895a6c954f8a0cf53f38b1d9a69b","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/?format=json","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/20099/mbox/","series":[{"id":4325,"url":"https://patchwork.libcamera.org/api/series/4325/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4325","date":"2024-05-24T13:52:54","name":"libipa: Fix CameraSensorHelper gain helpers","version":2,"mbox":"https://patchwork.libcamera.org/series/4325/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/20099/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/20099/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 731CDBD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 24 May 2024 13:53:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 61BBB634B1;\n\tFri, 24 May 2024 15:53:07 +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 22028634AA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 May 2024 15:53:01 +0200 (CEST)","from Monstersaurus.local\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 DA5D1150E;\n\tFri, 24 May 2024 15:52:46 +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=\"Lcglayvb\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1716558767;\n\tbh=/3x9cfYUt/GOVWzCJbu4F/Y7UbYEi5cGg8i6XoXpTRE=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Lcglayvb8xuw2vphV5rD/7LoNzIBG5SDsHFQSNLfLkCprGYiCV1VC64KpE5FF+9Ni\n\tWiP2cVxTtvNYB3XSPGLY4vu7LQoO2tFgBBsJc2XqCvTsB0bN7TaJDWuD122Z2TJUMF\n\trrKypY6si72uhSwWHwIn4LivUos7bDgdoWZcLU5w=","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"libcamera devel <libcamera-devel@lists.libcamera.org>","Cc":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Subject":"[PATCH v2 2/2] libipa: camera_sensor_helper: Fix rounding of\n\tgainCode","Date":"Fri, 24 May 2024 14:52:56 +0100","Message-Id":"<20240524135256.649406-3-kieran.bingham@ideasonboard.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20240524135256.649406-1-kieran.bingham@ideasonboard.com>","References":"<20240524135256.649406-1-kieran.bingham@ideasonboard.com>","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":"The implementation of gainCode for both Exponential and Linear gain\nmodels does not generate a gainCode that matches the result of the\nreverse operation.\n\nThis can be seen by converting sequential gainCodes to a gain\nand converting that back to the gainCode. The values do not\ntranslate back due to only rounding down, rather than to the closest\ninteger.\n\nCorrect the rounding error and ensure that gainCode translation\nproduces accurate bi-directional conversions from the perspective\nof the gainCode.\n\nThis fixes the IMX290, IMX296, IMX327 and IMX335 which use the\nExponential gain model helpers, as well as IMX219, IMX258, IMX283, and\nIMX477 which use the Linear gain model helpers.\n\nThis updates the corresponding test which was previously marked as\nexpected to fail.\n\nFixes: 8ad9249fb09d (\"libipa: camera_sensor_helper: Implement exponential gain model\")\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/ipa/libipa/camera_sensor_helper.cpp | 6 +++---\n test/ipa/meson.build                    | 3 +--\n 2 files changed, 4 insertions(+), 5 deletions(-)","diff":"diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp\nindex 2cd61fccfbb9..4a92ead88b23 100644\n--- a/src/ipa/libipa/camera_sensor_helper.cpp\n+++ b/src/ipa/libipa/camera_sensor_helper.cpp\n@@ -64,13 +64,13 @@ uint32_t CameraSensorHelper::gainCode(double gain) const\n \tcase AnalogueGainLinear:\n \t\tASSERT(k.linear.m0 == 0 || k.linear.m1 == 0);\n \n-\t\treturn (k.linear.c0 - k.linear.c1 * gain) /\n-\t\t       (k.linear.m1 * gain - k.linear.m0);\n+\t\treturn std::round((k.linear.c0 - k.linear.c1 * gain) /\n+\t\t\t\t  (k.linear.m1 * gain - k.linear.m0));\n \n \tcase AnalogueGainExponential:\n \t\tASSERT(k.exp.a != 0 && k.exp.m != 0);\n \n-\t\treturn std::log2(gain / k.exp.a) / k.exp.m;\n+\t\treturn std::round(std::log2(gain / k.exp.a) / k.exp.m);\n \n \tdefault:\n \t\tASSERT(false);\ndiff --git a/test/ipa/meson.build b/test/ipa/meson.build\nindex abc2456fc341..0b22c7576e56 100644\n--- a/test/ipa/meson.build\n+++ b/test/ipa/meson.build\n@@ -1,8 +1,7 @@\n # SPDX-License-Identifier: CC0-1.0\n \n ipa_test = [\n-    {'name': 'camera_sensor_helper', 'sources': ['camera_sensor_helper.cpp'],\n-     'should_fail': true},\n+    {'name': 'camera_sensor_helper', 'sources': ['camera_sensor_helper.cpp']},\n     {'name': 'ipa_module_test', 'sources': ['ipa_module_test.cpp']},\n     {'name': 'ipa_interface_test', 'sources': ['ipa_interface_test.cpp']},\n ]\n","prefixes":["v2","2/2"]}