Show a patch.

GET /api/1.1/patches/17692/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 17692,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/17692/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/17692/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20221027055515.321791-2-nicholas@rothemail.net>",
    "date": "2022-10-27T05:55:06",
    "name": "[libcamera-devel,01/10] ipa: workaround libcxx duration limitation",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "53b1db400e56aeac536ad8e118566eb5fded6d22",
    "submitter": {
        "id": 97,
        "url": "https://patchwork.libcamera.org/api/1.1/people/97/?format=api",
        "name": "Nicolas Dufresne via libcamera-devel",
        "email": "libcamera-devel@lists.libcamera.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/17692/mbox/",
    "series": [
        {
            "id": 3579,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3579/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3579",
            "date": "2022-10-27T05:55:08",
            "name": "[libcamera-devel,01/10] ipa: workaround libcxx duration limitation",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/3579/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/17692/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/17692/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 24ECEBD16B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 27 Oct 2022 05:55:28 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6167062F7D;\n\tThu, 27 Oct 2022 07:55:27 +0200 (CEST)",
            "from mail-oa1-x2c.google.com (mail-oa1-x2c.google.com\n\t[IPv6:2001:4860:4864:20::2c])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 93BCD62F69\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 27 Oct 2022 07:55:24 +0200 (CEST)",
            "by mail-oa1-x2c.google.com with SMTP id\n\t586e51a60fabf-1322d768ba7so686318fac.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 26 Oct 2022 22:55:24 -0700 (PDT)",
            "from nroth-pc.attlocal.net\n\t([2600:1700:20:20c0:6406:fc7a:e46d:1666])\n\tby smtp.gmail.com with ESMTPSA id\n\t9-20020a9d0c09000000b00661a05691fasm140021otr.79.2022.10.26.22.55.22\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 26 Oct 2022 22:55:22 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1666850127;\n\tbh=PKFj24OOKVRuMKh0SSDIrf1PFnhIUyu7RiecwNokwWg=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=QGJT2zUstZkJ3o84+7tkBRMiWD4V4r70ce93I9k5qlUQqxSp+h8UxuZfMbrVJG8Q8\n\tQIgIok1wsXgekhZ146/u793SgD61o5T8svlGDhr7J8osL4zHJsX232n3VarMaV4VJ8\n\toqstJjTqgZngMiBhAXlapbk4DeeIR3Gxc+/o9pWLaBKRsX8jRY1mCyoKem9Q2B8zRA\n\tqqg/X0+cUHakwS+5fJq0KFk7Ju0ZTpv3pfJUM+pjGi8MnueDcF9PYxvKcZDZQhY57b\n\tir3TZslRl6EJHiyYqyEF2BfwuHm4LNZE59H7TSX09ZhgE5evPivFoYCIcMIrDz0LTf\n\tBcFJ41bwQZBTw==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=rothemail-net.20210112.gappssmtp.com; s=20210112;\n\th=content-transfer-encoding:mime-version:reply-to:references\n\t:in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject\n\t:date:message-id:reply-to;\n\tbh=Yq83/qBYhE/+rL6g+mTb35qh4EgpgtRGPtAyUBE/vcY=;\n\tb=ijRGPi6MDVJ8Mn1A5t7UEXJ905DiXc3iR70NNYAnpdW48NPA/SugRyCuAUdJ5jvCGA\n\t8t81ywpv1iDmtjnMXn56zUsPCJLsXijsIty1Nv3yVnYY3embrwbTjh1CU7jMVlHLeKKD\n\tqWJDdg4SInmr+t5vqW4Tx0zJd+I7xzYbmZf45ebQ5v3uSg7ggBMxwkv94qLuYdMPOOd6\n\tXtwTGjdlVAksqKXAJhvAwYdMAPWq9EraIQ7z0zlb3n5MT2XL+jLVpGkUKTH1yrwvPsLo\n\t6RdxkNm+D8bqyOZsZ/Czb3/dRCf7+aLcHnaUzDDUUheYw2A1qEElcEW7p+Yp0bgORgEG\n\tZ+Nw=="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=rothemail-net.20210112.gappssmtp.com\n\theader.i=@rothemail-net.20210112.gappssmtp.com header.b=\"ijRGPi6M\"; \n\tdkim-atps=neutral",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=content-transfer-encoding:mime-version:reply-to:references\n\t:in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state\n\t:from:to:cc:subject:date:message-id:reply-to;\n\tbh=Yq83/qBYhE/+rL6g+mTb35qh4EgpgtRGPtAyUBE/vcY=;\n\tb=CQ1DVALA2/R+/+nYcOvJXIZSD4V+rZNhbCzogvJFEkB49zTvtVb/nFHfWy1cuBg2OR\n\tWqVnRUCsC8LpZCDEPc8vR9yZKnbrNQH8ZVGTFUrIHxoOXSqfA8Wc06WQO1tkLOdcR6Vr\n\td8axJy9kZQYlDoCC8QhIDn3vHEpC/z58FPYnvkb0LCLiJbBhtzSol6KwC8WfUzXwTRt/\n\tAzdqCfQc9r0O6Ngu1SSUhgXUBDNuuR7C7yZO0O5AkWgKjqatUy+/yYqse46N9HyKO4+c\n\tEWSMvgzzDQ/6VfcgW0BcyCesiEE/dZjrtK5dtP2KNl4yM7meG58maO1ST6Z66y3+igfZ\n\tWkGA==",
        "X-Gm-Message-State": "ACrzQf1Z4Naw25OpuctZxs/+xfUsxjpDV5VU49V2tfUSb2D9ZwHDDbqC\n\tGlfLqApyYE5TbuezVvCNicD74vF+Cm04hUXO",
        "X-Google-Smtp-Source": "AMsMyM5hoqAOtkphOZxtcV9kVaWGwsRAulx87LY9wDxID86lBWoWafi2aQP8siE99L8fjYHXgIRgvQ==",
        "X-Received": "by 2002:a05:6870:d186:b0:132:4315:1d28 with SMTP id\n\ta6-20020a056870d18600b0013243151d28mr4573633oac.147.1666850122668; \n\tWed, 26 Oct 2022 22:55:22 -0700 (PDT)",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu, 27 Oct 2022 00:55:06 -0500",
        "Message-Id": "<20221027055515.321791-2-nicholas@rothemail.net>",
        "X-Mailer": "git-send-email 2.34.1",
        "In-Reply-To": "<20221027055515.321791-1-nicholas@rothemail.net>",
        "References": "<libcamera Android Enhancements>\n\t<20221027055515.321791-1-nicholas@rothemail.net>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 01/10] ipa: workaround libcxx duration\n\tlimitation",
        "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>",
        "From": "Nicholas Roth via libcamera-devel <libcamera-devel@lists.libcamera.org>",
        "Reply-To": "libcamera-devel@lists.libcamera.org",
        "Cc": "nicholas@rothemail.net",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "From: Nicholas Roth <nicholas@rothemail.net>\n\nA bug in libcxx [0] used by clang version 11.0.2 is prevalent when\nbuilding libcamera for Android SDK30. This has been fixed and\nintegrated upstream with [1].\n\nAs a workaround, directly cast libcamera::utils::Duration objects to\nstd::chrono::duration when dividing.\n\nAlternatives evaluated:\nConsidered: Enable public inheritance of std::chrono::duration and\noverride operator/ in the class.\nOutcome: Does not fix the original compiler error.\n\nConsidered: Enable public inheritance of std::chrono::duration and\noverride operator/ in the libcamera namespace.\nOutcome: new compiler error:\nld.lld: error: duplicate symbol: libcamera::operator/\n(libcamera::utils::Duration const&, libcamera::utils::Duration const&)\n\nConsidered: Use private inheritance of std::chrono::duration and\nre-implement a pass-through version of each std::chrono::duration\noperator within libcamera::utils::Duration and use template\nmetaprogramming to fix the division operator.\nOutcome: Testing shows that this would introduce substantial\nlimitations, i.e. requring the Duration object to be on the LHS of any\narithmetic operation with other numeric types. This also substantially\nincreases implementation complexity.\n\nConsidered: Extract double values from libcamera::utils::Duration\nobjects and use those to divide.\nOutcome: This creates substantial readability and unit-safety issues.\n\n[0] https://github.com/llvm/llvm-project/issues/40475\n[1] https://github.com/llvm/llvm-project/commit/efa6d803c624f9251d0ab7881122501bb9d27368\nBug: https://bugs.libcamera.org/show_bug.cgi?id=156\n\nSigned-off-by: Nicholas Roth <nicholas@rothemail.net>\n---\n src/ipa/ipu3/algorithms/agc.cpp            | 16 ++++++++++------\n src/ipa/raspberrypi/cam_helper.cpp         |  6 +++---\n src/ipa/raspberrypi/cam_helper_imx296.cpp  |  3 ++-\n src/ipa/raspberrypi/controller/rpi/agc.cpp | 12 ++++++++----\n src/ipa/raspberrypi/controller/rpi/lux.cpp |  3 ++-\n src/ipa/rkisp1/algorithms/agc.cpp          | 12 ++++++++----\n 6 files changed, 33 insertions(+), 19 deletions(-)",
    "diff": "diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\nindex a1a3c38f..9b09ac94 100644\n--- a/src/ipa/ipu3/algorithms/agc.cpp\n+++ b/src/ipa/ipu3/algorithms/agc.cpp\n@@ -100,7 +100,8 @@ int Agc::configure(IPAContext &context,\n \n \t/* Configure the default exposure and gain. */\n \tactiveState.agc.gain = std::max(minAnalogueGain_, kMinAnalogueGain);\n-\tactiveState.agc.exposure = 10ms / configuration.sensor.lineDuration;\n+\tactiveState.agc.exposure = 10ms /\n+\t\tstd::chrono::duration(configuration.sensor.lineDuration);\n \n \tframeCount_ = 0;\n \treturn 0;\n@@ -240,17 +241,20 @@ void Agc::computeExposure(IPAContext &context, IPAFrameContext &frameContext,\n \t * increase the gain.\n \t */\n \tutils::Duration shutterTime =\n-\t\tstd::clamp<utils::Duration>(exposureValue / minAnalogueGain_,\n-\t\t\t\t\t    minShutterSpeed_, maxShutterSpeed_);\n-\tdouble stepGain = std::clamp(exposureValue / shutterTime,\n-\t\t\t\t     minAnalogueGain_, maxAnalogueGain_);\n+\t\tstd::clamp<utils::Duration>(std::chrono::duration(exposureValue) /\n+\t\t\t\t\tminAnalogueGain_,\n+\t\t\t\t    minShutterSpeed_, maxShutterSpeed_);\n+\tdouble stepGain = std::clamp(std::chrono::duration(exposureValue) /\n+\t\t\t\tstd::chrono::duration(shutterTime),\n+\t\t\t\tminAnalogueGain_, maxAnalogueGain_);\n \tLOG(IPU3Agc, Debug) << \"Divided up shutter and gain are \"\n \t\t\t    << shutterTime << \" and \"\n \t\t\t    << stepGain;\n \n \tIPAActiveState &activeState = context.activeState;\n \t/* Update the estimated exposure and gain. */\n-\tactiveState.agc.exposure = shutterTime / configuration.sensor.lineDuration;\n+\tactiveState.agc.exposure = std::chrono::duration(shutterTime) /\n+\t\t\t\tstd::chrono::duration(configuration.sensor.lineDuration);\n \tactiveState.agc.gain = stepGain;\n }\n \ndiff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp\nindex d90ac1de..48a8a068 100644\n--- a/src/ipa/raspberrypi/cam_helper.cpp\n+++ b/src/ipa/raspberrypi/cam_helper.cpp\n@@ -63,7 +63,7 @@ void CamHelper::process([[maybe_unused]] StatisticsPtr &stats,\n \n uint32_t CamHelper::exposureLines(const Duration exposure, const Duration lineLength) const\n {\n-\treturn exposure / lineLength;\n+\treturn std::chrono::duration(exposure) / std::chrono::duration(lineLength);\n }\n \n Duration CamHelper::exposure(uint32_t exposureLines, const Duration lineLength) const\n@@ -85,8 +85,8 @@ std::pair<uint32_t, uint32_t> CamHelper::getBlanking(Duration &exposure,\n \t * frameLengthMax gets calculated on the smallest line length as we do\n \t * not want to extend that unless absolutely necessary.\n \t */\n-\tframeLengthMin = minFrameDuration / mode_.minLineLength;\n-\tframeLengthMax = maxFrameDuration / mode_.minLineLength;\n+\tframeLengthMin = std::chrono::duration(minFrameDuration) / std::chrono::duration(mode_.minLineLength);\n+\tframeLengthMax = std::chrono::duration(maxFrameDuration) / std::chrono::duration(mode_.minLineLength);\n \n \t/*\n \t * Watch out for (exposureLines + frameIntegrationDiff_) overflowing a\ndiff --git a/src/ipa/raspberrypi/cam_helper_imx296.cpp b/src/ipa/raspberrypi/cam_helper_imx296.cpp\nindex ecb845e7..65f76c3c 100644\n--- a/src/ipa/raspberrypi/cam_helper_imx296.cpp\n+++ b/src/ipa/raspberrypi/cam_helper_imx296.cpp\n@@ -57,7 +57,8 @@ double CamHelperImx296::gain(uint32_t gainCode) const\n uint32_t CamHelperImx296::exposureLines(const Duration exposure,\n \t\t\t\t\t[[maybe_unused]] const Duration lineLength) const\n {\n-\treturn std::max<uint32_t>(minExposureLines, (exposure - 14.26us) / timePerLine);\n+\treturn std::max<uint32_t>(minExposureLines, std::chrono::duration(exposure - 14.26us) /\n+\t\t\t\tstd::chrono::duration(timePerLine));\n }\n \n Duration CamHelperImx296::exposure(uint32_t exposureLines,\ndiff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp\nindex bd54a639..cfa5ed90 100644\n--- a/src/ipa/raspberrypi/controller/rpi/agc.cpp\n+++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp\n@@ -418,7 +418,8 @@ void Agc::prepare(Metadata *imageMetadata)\n \t\t\tDuration actualExposure = deviceStatus.shutterSpeed *\n \t\t\t\t\t\t  deviceStatus.analogueGain;\n \t\t\tif (actualExposure) {\n-\t\t\t\tstatus_.digitalGain = status_.totalExposureValue / actualExposure;\n+\t\t\t\tstatus_.digitalGain = std::chrono::duration(status_.totalExposureValue) /\n+\t\t\t\t\t\t\tstd::chrono::duration(actualExposure);\n \t\t\t\tLOG(RPiAgc, Debug) << \"Want total exposure \" << status_.totalExposureValue;\n \t\t\t\t/*\n \t\t\t\t * Never ask for a gain < 1.0, and also impose\n@@ -823,7 +824,8 @@ void Agc::divideUpExposure()\n \t\t\t}\n \t\t\tif (status_.fixedAnalogueGain == 0.0) {\n \t\t\t\tif (exposureMode_->gain[stage] * shutterTime >= exposureValue) {\n-\t\t\t\t\tanalogueGain = exposureValue / shutterTime;\n+\t\t\t\t\tanalogueGain = std::chrono::duration(exposureValue) /\n+\t\t\t\t\t\t\t\tstd::chrono::duration(shutterTime);\n \t\t\t\t\tbreak;\n \t\t\t\t}\n \t\t\t\tanalogueGain = exposureMode_->gain[stage];\n@@ -838,10 +840,12 @@ void Agc::divideUpExposure()\n \t */\n \tif (!status_.fixedShutter && !status_.fixedAnalogueGain &&\n \t    status_.flickerPeriod) {\n-\t\tint flickerPeriods = shutterTime / status_.flickerPeriod;\n+\t\tint flickerPeriods = std::chrono::duration(shutterTime) /\n+\t\t\t\t\tstd::chrono::duration(status_.flickerPeriod);\n \t\tif (flickerPeriods) {\n \t\t\tDuration newShutterTime = flickerPeriods * status_.flickerPeriod;\n-\t\t\tanalogueGain *= shutterTime / newShutterTime;\n+\t\t\tanalogueGain *= std::chrono::duration(shutterTime) /\n+\t\t\t\t\t\tstd::chrono::duration(newShutterTime);\n \t\t\t/*\n \t\t\t * We should still not allow the ag to go over the\n \t\t\t * largest value in the exposure mode. Note that this\ndiff --git a/src/ipa/raspberrypi/controller/rpi/lux.cpp b/src/ipa/raspberrypi/controller/rpi/lux.cpp\nindex 9759186a..430642f0 100644\n--- a/src/ipa/raspberrypi/controller/rpi/lux.cpp\n+++ b/src/ipa/raspberrypi/controller/rpi/lux.cpp\n@@ -94,7 +94,8 @@ void Lux::process(StatisticsPtr &stats, Metadata *imageMetadata)\n \t\tdouble currentY = sum / (double)num + .5;\n \t\tdouble gainRatio = referenceGain_ / currentGain;\n \t\tdouble shutterSpeedRatio =\n-\t\t\treferenceShutterSpeed_ / deviceStatus.shutterSpeed;\n+\t\t\tstd::chrono::duration(referenceShutterSpeed_) /\n+\t\t\t\t\t\tstd::chrono::duration(deviceStatus.shutterSpeed);\n \t\tdouble apertureRatio = referenceAperture_ / currentAperture;\n \t\tdouble yRatio = currentY * (65536 / numBins) / referenceY_;\n \t\tdouble estimatedLux = shutterSpeedRatio * gainRatio *\ndiff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\nindex 04062a36..660f8327 100644\n--- a/src/ipa/rkisp1/algorithms/agc.cpp\n+++ b/src/ipa/rkisp1/algorithms/agc.cpp\n@@ -74,7 +74,8 @@ int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo)\n {\n \t/* Configure the default exposure and gain. */\n \tcontext.activeState.agc.gain = std::max(context.configuration.agc.minAnalogueGain, kMinAnalogueGain);\n-\tcontext.activeState.agc.exposure = 10ms / context.configuration.sensor.lineDuration;\n+\tcontext.activeState.agc.exposure = 10ms /\n+\t\t\t\tstd::chrono::duration(context.configuration.sensor.lineDuration);\n \n \t/*\n \t * According to the RkISP1 documentation:\n@@ -212,16 +213,19 @@ void Agc::computeExposure(IPAContext &context, IPAFrameContext &frameContext,\n \t * Push the shutter time up to the maximum first, and only then\n \t * increase the gain.\n \t */\n-\tutils::Duration shutterTime = std::clamp<utils::Duration>(exposureValue / minAnalogueGain,\n+\tutils::Duration shutterTime = std::clamp<utils::Duration>(std::chrono::duration(exposureValue) /\n+\t\t\t\t\t\t\t\t\t\t\tminAnalogueGain,\n \t\t\t\t\t\t\t\t  minShutterSpeed, maxShutterSpeed);\n-\tdouble stepGain = std::clamp(exposureValue / shutterTime,\n+\tdouble stepGain = std::clamp(std::chrono::duration(exposureValue) /\n+\t\t\t\t\t\t\t\tstd::chrono::duration(shutterTime),\n \t\t\t\t     minAnalogueGain, maxAnalogueGain);\n \tLOG(RkISP1Agc, Debug) << \"Divided up shutter and gain are \"\n \t\t\t      << shutterTime << \" and \"\n \t\t\t      << stepGain;\n \n \t/* Update the estimated exposure and gain. */\n-\tactiveState.agc.exposure = shutterTime / configuration.sensor.lineDuration;\n+\tactiveState.agc.exposure = std::chrono::duration(shutterTime) /\n+\t\t\t\tstd::chrono::duration(configuration.sensor.lineDuration);\n \tactiveState.agc.gain = stepGain;\n }\n \n",
    "prefixes": [
        "libcamera-devel",
        "01/10"
    ]
}