Show a patch.

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

{
    "id": 17712,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/17712/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/17712/",
    "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": "<20221027224434.348469-1-nicholas@rothemail.net>",
    "date": "2022-10-27T22:44:25",
    "name": "[libcamera-devel,v4,01/10] ipa: workaround libcxx duration limitation",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "ab7e2b59a6d5a2e3fd512d58c53fb228bbb2e4dd",
    "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/17712/mbox/",
    "series": [
        {
            "id": 3582,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3582/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3582",
            "date": "2022-10-27T22:44:25",
            "name": "[libcamera-devel,v4,01/10] ipa: workaround libcxx duration limitation",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/3582/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/17712/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/17712/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 23686BDB16\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 27 Oct 2022 22:44:50 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C126A62FA9;\n\tFri, 28 Oct 2022 00:44:48 +0200 (CEST)",
            "from mail-oa1-x33.google.com (mail-oa1-x33.google.com\n\t[IPv6:2001:4860:4864:20::33])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DA24662FA3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 28 Oct 2022 00:44:46 +0200 (CEST)",
            "by mail-oa1-x33.google.com with SMTP id\n\t586e51a60fabf-13c2cfd1126so4294880fac.10\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 27 Oct 2022 15:44:46 -0700 (PDT)",
            "from nroth-pc.attlocal.net\n\t([2600:1700:20:20c0:6a4b:7aa7:dda2:75cb])\n\tby smtp.gmail.com with ESMTPSA id\n\ta16-20020a05687073d000b00131c3d4d38fsm1246674oan.39.2022.10.27.15.44.44\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 27 Oct 2022 15:44:44 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1666910688;\n\tbh=KAG6VBvMLEaE+uQzo38FS9tf6GUTOandZ8YYv21Fh6o=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:Cc:From;\n\tb=2/cIVbN/NOmKD+g0a4YNOWM3yXlA9dNAw7FDSwP23N/P9yTSkTe++y30mDY6vXIrZ\n\taK1aDCxFNDLBARFzE7yDmf9TOyVWUM7JIh+w+RG1DpKTV/aweXJfC9UusYpDMkEvz+\n\t9BBZt3+ozFBihqWRsZK2OrdgxSf8YRgJ1YfJHjshylv6yYL6729RsPPy7tMgNgzbno\n\tQqlJAGXy3GZPyN6V5o7/6rGo1kkxdO7CpjgBH2p29omcYdxFdnsEML8Mfu7PWJCafU\n\tT2akJDjtPOWYdJtOar15pbOYJgmgd9zxASvph/JZCPK5Gq0jouOsEHSG3xnLeBCWCI\n\tYdYqIawrC+ZCw==",
            "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:message-id:date\n\t:subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to;\n\tbh=vPPTrdE8P8aEZNt9QylvzE1IoIY92ZIoPAxBlN/CeEU=;\n\tb=mCQlxUcZ2Ty+EZSimbwqpiZRe58ySl+QHvwajQk4og/Wk41xAc96Vz/eCIXZJrMv+6\n\tuQaU+ZJkH7vEbxj9T3g3fZiQn4ao0mMjnDrUY4Rri6KsIIVtzISYawaQfyRpdNWQBj22\n\tMn8o5TFGZTc5f35ieuWO3AJdqQCwFDHQwpXcvBDOqAyENBtvMs4vlE47JnxUbsPv0Cfn\n\tQv8/iW8TvgjHvy+UfXH9ZV9K8woTI0Ki2f9zoBFPauo8Hp/kMrL+cRVT0mqjqXnXGtlW\n\tMOg/5GASShhRWKgHOotqe/cuvLnQdvWClcPexDvQy7sjPxnKXP3kt5XD5Ps5n0fNLc4h\n\tH5sA=="
        ],
        "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=\"mCQlxUcZ\"; \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:message-id:date\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=vPPTrdE8P8aEZNt9QylvzE1IoIY92ZIoPAxBlN/CeEU=;\n\tb=HzLlDdt5xcMm0u3R7WFOHSgCGs1OsQOSqjlBzUIBvHytfgwxZeMBOgc5DwDgQFRpPK\n\tBlo4HzbQ8H+tmn3LLajIXZqtsgZFAHbheANOQ4Wa3lO1JS5/4ty7HVNuSv4hEx/ZiRl8\n\tJBKk5BPd48KIXHk4VYEHFKweB5GasT7BfYnuO+jHFAtVmDF9uW4002vLe3tMtT/HKs55\n\taahsuowUNFmPEBZDuJnGs9hA5gYIvpyOCl+qv37YcAG2ckfF9RTmUyKV8aBrdYcNm6zV\n\tct3m0zkHtnAWOVgtz3m8mAzyeHkThZxMnZhhCGtXS7UEQIXJjnhhsZX/l3DhWTTCsOht\n\txfnw==",
        "X-Gm-Message-State": "ACrzQf369b9eMJE5+wPqdFvbdFmNyRbZrVV+6qUQ6VjIA0bpUPl5QQ0i\n\t60doUIn9YTMsR54RXZ9rDLjLsOME8I/7l29q",
        "X-Google-Smtp-Source": "AMsMyM6Boi9zeCLzIyDT22CBIg2tfiu/QcYJL4ge3+dQyJAi5J1bnXCSoL51qt60+AktuIkAXaKcvw==",
        "X-Received": "by 2002:a05:6871:1cf:b0:13c:12cf:2135 with SMTP id\n\tq15-20020a05687101cf00b0013c12cf2135mr7064627oad.121.1666910685223; \n\tThu, 27 Oct 2022 15:44:45 -0700 (PDT)",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu, 27 Oct 2022 17:44:25 -0500",
        "Message-Id": "<20221027224434.348469-1-nicholas@rothemail.net>",
        "X-Mailer": "git-send-email 2.34.1",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v4 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..f1650468 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\t\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\t\tminAnalogueGain_,\n+\t\t\t\t\tminShutterSpeed_, maxShutterSpeed_);\n+\tdouble stepGain = std::clamp(std::chrono::duration(exposureValue) /\n+\t\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..c5180de5 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\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..65baab99 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\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\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\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..410f6f44 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\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..bb874356 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\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\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\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",
        "v4",
        "01/10"
    ]
}