[{"id":35958,"web_url":"https://patchwork.libcamera.org/comment/35958/","msgid":"<85qzvwmfob.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","date":"2025-09-24T08:13:24","subject":"Re: [PATCH 4/5] ipa: software_isp: AGC: Only use integers for\n\texposure calculations","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Hi Hans,\n\nthank you for the patch.\n\nHans de Goede <hansg@kernel.org> writes:\n\n> Exposure is an integer, instead of re-using the \"double next\" used\n> for again calculations, doing intermediate calculations with double\n> precision, use a local next variable of an integer type.\n\nUsing separate locals is cleaner anyway.\n\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n\n> Signed-off-by: Hans de Goede <hansg@kernel.org>\n> ---\n>  src/ipa/simple/algorithms/agc.cpp | 9 ++++-----\n>  1 file changed, 4 insertions(+), 5 deletions(-)\n>\n> diff --git a/src/ipa/simple/algorithms/agc.cpp b/src/ipa/simple/algorithms/agc.cpp\n> index 230616e62..cdde56ba2 100644\n> --- a/src/ipa/simple/algorithms/agc.cpp\n> +++ b/src/ipa/simple/algorithms/agc.cpp\n> @@ -51,19 +51,18 @@ void Agc::updateExposure(IPAContext &context, IPAFrameContext &frameContext, dou\n>  \tstatic constexpr uint8_t kExpNumeratorUp = kExpDenominator + 1;\n>  \tstatic constexpr uint8_t kExpNumeratorDown = kExpDenominator - 1;\n>  \n> -\tdouble next;\n>  \tint32_t &exposure = frameContext.sensor.exposure;\n>  \tdouble &again = frameContext.sensor.gain;\n>  \n>  \tif (exposureMSV < kExposureOptimal - kExposureSatisfactory) {\n>  \t\tif (exposure < context.configuration.agc.exposureMax) {\n> -\t\t\tnext = exposure * kExpNumeratorUp / kExpDenominator;\n> +\t\t\tint32_t next = exposure * kExpNumeratorUp / kExpDenominator;\n>  \t\t\tif (next - exposure < 1)\n>  \t\t\t\texposure += 1;\n>  \t\t\telse\n>  \t\t\t\texposure = next;\n>  \t\t} else {\n> -\t\t\tnext = again * kExpNumeratorUp / kExpDenominator;\n> +\t\t\tdouble next = again * kExpNumeratorUp / kExpDenominator;\n>  \t\t\tif (next - again < context.configuration.agc.againMinStep)\n>  \t\t\t\tagain += context.configuration.agc.againMinStep;\n>  \t\t\telse\n> @@ -73,13 +72,13 @@ void Agc::updateExposure(IPAContext &context, IPAFrameContext &frameContext, dou\n>  \n>  \tif (exposureMSV > kExposureOptimal + kExposureSatisfactory) {\n>  \t\tif (again > context.configuration.agc.againDef) {\n> -\t\t\tnext = again * kExpNumeratorDown / kExpDenominator;\n> +\t\t\tdouble next = again * kExpNumeratorDown / kExpDenominator;\n>  \t\t\tif (again - next < context.configuration.agc.againMinStep)\n>  \t\t\t\tagain -= context.configuration.agc.againMinStep;\n>  \t\t\telse\n>  \t\t\t\tagain = next;\n>  \t\t} else {\n> -\t\t\tnext = exposure * kExpNumeratorDown / kExpDenominator;\n> +\t\t\tint32_t next = exposure * kExpNumeratorDown / kExpDenominator;\n>  \t\t\tif (exposure - next < 1)\n>  \t\t\t\texposure -= 1;\n>  \t\t\telse","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 7114DBDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 24 Sep 2025 08:15:37 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F33246B5F9;\n\tWed, 24 Sep 2025 10:15:35 +0200 (CEST)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8A46D6B5C2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 24 Sep 2025 10:13:35 +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-392-r3rHCEodPSeohlzUwxe-Iw-1; Wed, 24 Sep 2025 04:13:27 -0400","by mail-wm1-f72.google.com with SMTP id\n\t5b1f17b1804b1-46d8ef3526dso18423035e9.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 24 Sep 2025 01:13:27 -0700 (PDT)","from mzamazal-thinkpadp1gen7.tpbc.csb ([85.93.96.130])\n\tby smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-46e2ab4897bsm20599775e9.17.2025.09.24.01.13.24\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 24 Sep 2025 01:13:24 -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=\"RjcWo6oA\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1758701609;\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=V/ErcMBsxp1WCQfUWWNszhFHrLgx/8pX8IqGhZwT06A=;\n\tb=RjcWo6oAyjaDw6GzzDqdFdnpzmTf3Vpgy3ov5vJs0NztFj0uwtpBF4clQ6AwjQGFF0Ku97\n\tDhq4y8SECYP7O9ktNA7akJSLZwKIpiBpWHQKEAXvTO7xT+RYDgf5yvfOTidNWbnbyJ4lWI\n\t8Cx6dK9gXsTw/bqhpo2QVckAOSWRRB0=","X-MC-Unique":"r3rHCEodPSeohlzUwxe-Iw-1","X-Mimecast-MFC-AGG-ID":"r3rHCEodPSeohlzUwxe-Iw_1758701606","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1758701606; x=1759306406;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=V/ErcMBsxp1WCQfUWWNszhFHrLgx/8pX8IqGhZwT06A=;\n\tb=IlUpGlclmXe3XJG7jCb8Q6LmGEfpyLfmtOEHQeFZQMRWIvxUpAwwX/lH4p2pDkmy96\n\tAHHAiG22k+hWsIllKDu9tVMFJi7lFoFNQhf4/+olPnYb9umvQzzVPxfO9/ikwYR4s1/Y\n\tbmVUalBXh7FJME9LUOl/9rcOsB8PfZF4x4uJDP/FFATI+VnvQpL5VSFwwL8D6lpktARr\n\thWfg5qiAQU2iKE/l2CIpBIk7xyc6iApUsBI/l6T+uPNU0miZeUOegu3i4Fedhh88D7kV\n\tzX2ToRj2ajgckupNclYvmnXoxoenIl0pft4o8I1D5u1XBCQa07qUGHPs+OBKriF82NQz\n\t29gA==","X-Gm-Message-State":"AOJu0YxIN31jMhdRpiVdNWK0u+WnO5AF0+9MdMgOWiIkvm3K6i7nv6kD\n\t09lqNeydva9sCbBP4o1kw2LbuVTmhtdElvKDkuJJNif7gRqaYPt9eiLyb4D79TRSxv6YlMUJWom\n\t3Voph/3Tfhp7I9LyReq0/iUasZT25lE29EqiWcQzx9JxNQRfCnJOUesX8vbZG62+NTEOA5Ig482\n\tzKkksn+Pmf6c0pVjBHQCpyL9vcoBHlZI0oMl2vfwhDaYuYbCFPPhUCMVjBWsM=","X-Gm-Gg":"ASbGncs6fQjkY0v67oGIrlenJWfIkz2hTaWLlImxRzxuj/NjTmV4r+6qm+MpyV9k8df\n\t9kgPGreI6oBIGcJKTJfoDI/eTUA5XYnY2Cf6eu8VJFsV7Xz9MGxsi4apETQV+P6IAu6b2a125XL\n\tz/H9EoW0Ij4jigsVk+AaZ4TLfOtn9jk3B/W0oXq8OekEQj9dDsXrGdD8svCcxrvnqdGnkt8fxxI\n\t29tfjz/lWYMnIWb7McrzdOZ9jpXpE1r9Yki5sbYVAPAfsBmQmD/V3i9MG9LjMcvCj/NLmkWGyGR\n\t7Gh9As7iYy7IsbHsNKD0f7rI4ZcAA6SgTUiYTVkUgKRlQsFQy8lFiqoSC8kXwDtanA==","X-Received":["by 2002:a05:600c:3b11:b0:45d:e4ff:b642 with SMTP id\n\t5b1f17b1804b1-46e1dac5378mr53446045e9.25.1758701605735; \n\tWed, 24 Sep 2025 01:13:25 -0700 (PDT)","by 2002:a05:600c:3b11:b0:45d:e4ff:b642 with SMTP id\n\t5b1f17b1804b1-46e1dac5378mr53445765e9.25.1758701605304; \n\tWed, 24 Sep 2025 01:13:25 -0700 (PDT)"],"X-Google-Smtp-Source":"AGHT+IFGZp8k6qZIYfsFGQm3X2jGKgaCVsJUvHxHMD5s0Xch1/gs+RND0GIZWNTdxKT/qfN9UnlzkQ==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Hans de Goede <hansg@kernel.org>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH 4/5] ipa: software_isp: AGC: Only use integers for\n\texposure calculations","In-Reply-To":"<20250923190657.21453-5-hansg@kernel.org> (Hans de Goede's\n\tmessage of \"Tue, 23 Sep 2025 21:06:56 +0200\")","References":"<20250923190657.21453-1-hansg@kernel.org>\n\t<20250923190657.21453-5-hansg@kernel.org>","Date":"Wed, 24 Sep 2025 10:13:24 +0200","Message-ID":"<85qzvwmfob.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":"CPL56CmnwonWhwDMjxB-62HFlcLw4IWASdNf2tc1zWE_1758701606","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>"}},{"id":35968,"web_url":"https://patchwork.libcamera.org/comment/35968/","msgid":"<175879474062.88644.6168530041117078525@isaac-ThinkPad-T16-Gen-2>","date":"2025-09-25T10:05:40","subject":"Re: [PATCH 4/5] ipa: software_isp: AGC: Only use integers for\n\texposure calculations","submitter":{"id":215,"url":"https://patchwork.libcamera.org/api/people/215/","name":"Isaac Scott","email":"isaac.scott@ideasonboard.com"},"content":"Hi Hans,\n\nThank you for the patch!\n\nQuoting Hans de Goede (2025-09-23 20:06:56)\n> Exposure is an integer, instead of re-using the \"double next\" used\n> for again calculations, doing intermediate calculations with double\n> precision, use a local next variable of an integer type.\n> \n> Signed-off-by: Hans de Goede <hansg@kernel.org>\n> ---\n>  src/ipa/simple/algorithms/agc.cpp | 9 ++++-----\n>  1 file changed, 4 insertions(+), 5 deletions(-)\n> \n> diff --git a/src/ipa/simple/algorithms/agc.cpp b/src/ipa/simple/algorithms/agc.cpp\n> index 230616e62..cdde56ba2 100644\n> --- a/src/ipa/simple/algorithms/agc.cpp\n> +++ b/src/ipa/simple/algorithms/agc.cpp\n> @@ -51,19 +51,18 @@ void Agc::updateExposure(IPAContext &context, IPAFrameContext &frameContext, dou\n>         static constexpr uint8_t kExpNumeratorUp = kExpDenominator + 1;\n>         static constexpr uint8_t kExpNumeratorDown = kExpDenominator - 1;\n>  \n> -       double next;\n>         int32_t &exposure = frameContext.sensor.exposure;\n>         double &again = frameContext.sensor.gain;\n>  \n>         if (exposureMSV < kExposureOptimal - kExposureSatisfactory) {\n>                 if (exposure < context.configuration.agc.exposureMax) {\n> -                       next = exposure * kExpNumeratorUp / kExpDenominator;\n> +                       int32_t next = exposure * kExpNumeratorUp / kExpDenominator;\n>                         if (next - exposure < 1)\n>                                 exposure += 1;\n>                         else\n>                                 exposure = next;\n>                 } else {\n> -                       next = again * kExpNumeratorUp / kExpDenominator;\n> +                       double next = again * kExpNumeratorUp / kExpDenominator;\n\nReviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>\n\nBest wishes,\nIsaac\n\n>                         if (next - again < context.configuration.agc.againMinStep)\n>                                 again += context.configuration.agc.againMinStep;\n>                         else\n> @@ -73,13 +72,13 @@ void Agc::updateExposure(IPAContext &context, IPAFrameContext &frameContext, dou\n>  \n>         if (exposureMSV > kExposureOptimal + kExposureSatisfactory) {\n>                 if (again > context.configuration.agc.againDef) {\n> -                       next = again * kExpNumeratorDown / kExpDenominator;\n> +                       double next = again * kExpNumeratorDown / kExpDenominator;\n>                         if (again - next < context.configuration.agc.againMinStep)\n>                                 again -= context.configuration.agc.againMinStep;\n>                         else\n>                                 again = next;\n>                 } else {\n> -                       next = exposure * kExpNumeratorDown / kExpDenominator;\n> +                       int32_t next = exposure * kExpNumeratorDown / kExpDenominator;\n>                         if (exposure - next < 1)\n>                                 exposure -= 1;\n>                         else\n> -- \n> 2.51.0\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 27EE4C328C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 25 Sep 2025 10:05:47 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3127F6B5F3;\n\tThu, 25 Sep 2025 12:05:46 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6762869318\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 25 Sep 2025 12:05:44 +0200 (CEST)","from thinkpad.ideasonboard.com\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 B1BC9142;\n\tThu, 25 Sep 2025 12:04:19 +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=\"IpnamSVG\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1758794659;\n\tbh=ZfwDvm+rf3sJKfl6TECXHx4ImeKvfyyU1I7H8qSyXEo=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=IpnamSVGocoI9C8DefOHNhFeUQ7CvyQJn4LhYV4ONA0WK+i4nbAQq4MHN1/5/tNIX\n\t7ChuaLwR3h9ums6cCoQFuUF2D3L4m64uiuxNt5gtTZGZrsFVrTT/PSfz3kubVoQWcY\n\t3kNgN4q6Gc7s7F1WCydLB+TF95cYuuRzG+2qeIbs=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250923190657.21453-5-hansg@kernel.org>","References":"<20250923190657.21453-1-hansg@kernel.org>\n\t<20250923190657.21453-5-hansg@kernel.org>","Subject":"Re: [PATCH 4/5] ipa: software_isp: AGC: Only use integers for\n\texposure calculations","From":"Isaac Scott <isaac.scott@ideasonboard.com>","Cc":"Hans de Goede <hansg@kernel.org>","To":"Hans de Goede <hansg@kernel.org>, libcamera-devel@lists.libcamera.org","Date":"Thu, 25 Sep 2025 11:05:40 +0100","Message-ID":"<175879474062.88644.6168530041117078525@isaac-ThinkPad-T16-Gen-2>","User-Agent":"alot/0.10","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>"}}]