From patchwork Thu Oct 27 22:41:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Dufresne via libcamera-devel X-Patchwork-Id: 17702 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 50222BDB16 for ; Thu, 27 Oct 2022 22:41:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DA6FF62FB3; Fri, 28 Oct 2022 00:41:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1666910506; bh=KWL/Gsut2winiwjuDaIMQfAIE6R+nge1tS6vEQwVGqw=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=d8cZicGMYl0KT9o6pTmI/PKpcvxEvHfqcYllFuToyfHbU7C5kHLpl3Fyi0Nw6tcXt PI9sINJ35Euff2hHdxC8XPtgMMvcAteIkEDB1fiMhFVNKk03D935BR3GEacpZSb+bW GA3OZf2jQsTGsmlw21mPT0tDTLhtnYzIgbzRj2pXWYNUFFoqNLmIHhYVG/3FGcPsPF BKdodx57xloE9A/4565GMDx0I4ZWckbO/bY+N4SwjzOX/nGbBc2GDoRz56YaiX1JxT is4xcufRx63okOrU0QUBNcfFEHZLlhSjyKfSEDTqI3tQdbrazk34X5WszuJLj9UeQR v65nGTNKv9Adg== Received: from mail-oa1-x31.google.com (mail-oa1-x31.google.com [IPv6:2001:4860:4864:20::31]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AED7562FA0 for ; Fri, 28 Oct 2022 00:41:42 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=rothemail-net.20210112.gappssmtp.com header.i=@rothemail-net.20210112.gappssmtp.com header.b="RO17LY5J"; dkim-atps=neutral Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-13b103a3e5dso4315376fac.2 for ; Thu, 27 Oct 2022 15:41:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rothemail-net.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=uDW5dvSvOk67QVcuydLzLD48wSWjb/FyOIOUWFCTpuM=; b=RO17LY5J+MsUYZk5CUIOWWO1GMQvzXFjDdhuKbH75gADWGdNM1fejI47MZW0ZeNn7X Q/BMvmdH5gsW8Zo0bQO6FxgT+FXA+TC9bovIrHzgzRntDTvB9zTX5zFZ3Etzvox1wwsk +qbUs/BGNr+YWG+nfRk4Rn7NGJXcU+MKnZJisK/zS1RYaZPT8zA1nBaDRGOLfoM3BbF1 Qrd9aWNK0nzgIa1ayZA9qB6MJxsWkGu0ZtdAV5vEtQgR6LqRm/qy7HxmwaefHgjz8Ej3 ndQKyln39cmV+yagNBW1qa9eobcDwV+/P/1K9uXH+9P7+R/Yf2srFbglkZgK6nDmMZRt 8ziQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=uDW5dvSvOk67QVcuydLzLD48wSWjb/FyOIOUWFCTpuM=; b=AnH1FNkA0MgEo8kPzCVYFj/HxQlxfFhVb6q8vu6zPTaMqa6tHPx5FMJ7L0pgaY0/va Vpx7nKE2t7vv/e/pghLOME6lA/tpEYhjSW/v+stQ0FFDNV6vwsvoAeUdgR0SEoMfRnSp 5Jlu7WIL3ZCtJ497clPzIhROB0IH+JUOPj9LoR4crzgBoj5rtq/erqc/rr2octClSyJL pf4zWGFxfk00JT5z0JcTtoFBFf2z4YB2cDt8bsInKKX+d/ZZpYLjAgsnnGaFaQVYN9dQ EyFM0qT/TASWYfHRvcKTT41alwNCBs2v03gXEzUOfddMXEjk8oSfTAZvMkbc2nhta2aB 0tBA== X-Gm-Message-State: ACrzQf0kMPakCBne6DNODQRjBEqh6xp1ZE/cqZuInxXDxSHbGS6iq2Ij sAZfU/ujMAH3PRjbgiaE+w1oR314GdA8hMbG X-Google-Smtp-Source: AMsMyM7xsMlYcmEtvlblhITYO4TjwC9ZtlZf5pKInXLQXv37Zjs7d9VfjLVwi9D4UF7t/g5VhvHjSA== X-Received: by 2002:a05:6870:2417:b0:127:be13:2d1 with SMTP id n23-20020a056870241700b00127be1302d1mr7002288oap.268.1666910500835; Thu, 27 Oct 2022 15:41:40 -0700 (PDT) Received: from nroth-pc.attlocal.net ([2600:1700:20:20c0:6a4b:7aa7:dda2:75cb]) by smtp.gmail.com with ESMTPSA id r20-20020a056830419400b006619533d1ddsm976825otu.76.2022.10.27.15.41.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 15:41:40 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 27 Oct 2022 17:41:26 -0500 Message-Id: <20221027224135.348115-2-nicholas@rothemail.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221027224135.348115-1-nicholas@rothemail.net> References: <20221027224135.348115-1-nicholas@rothemail.net> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 01/10] ipa: workaround libcxx duration limitation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Nicholas Roth via libcamera-devel From: Nicolas Dufresne via libcamera-devel Reply-To: libcamera-devel@lists.libcamera.org Cc: nicholas@rothemail.net Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Nicholas Roth A bug in libcxx [0] used by clang version 11.0.2 is prevalent when building libcamera for Android SDK30. This has been fixed and integrated upstream with [1]. As a workaround, directly cast libcamera::utils::Duration objects to std::chrono::duration when dividing. Alternatives evaluated: Considered: Enable public inheritance of std::chrono::duration and override operator/ in the class. Outcome: Does not fix the original compiler error. Considered: Enable public inheritance of std::chrono::duration and override operator/ in the libcamera namespace. Outcome: new compiler error: ld.lld: error: duplicate symbol: libcamera::operator/ (libcamera::utils::Duration const&, libcamera::utils::Duration const&) Considered: Use private inheritance of std::chrono::duration and re-implement a pass-through version of each std::chrono::duration operator within libcamera::utils::Duration and use template metaprogramming to fix the division operator. Outcome: Testing shows that this would introduce substantial limitations, i.e. requring the Duration object to be on the LHS of any arithmetic operation with other numeric types. This also substantially increases implementation complexity. Considered: Extract double values from libcamera::utils::Duration objects and use those to divide. Outcome: This creates substantial readability and unit-safety issues. [0] https://github.com/llvm/llvm-project/issues/40475 [1] https://github.com/llvm/llvm-project/commit/efa6d803c624f9251d0ab7881122501bb9d27368 Bug: https://bugs.libcamera.org/show_bug.cgi?id=156 Signed-off-by: Nicholas Roth --- src/ipa/ipu3/algorithms/agc.cpp | 16 ++++++++++------ src/ipa/raspberrypi/cam_helper.cpp | 6 +++--- src/ipa/raspberrypi/cam_helper_imx296.cpp | 3 ++- src/ipa/raspberrypi/controller/rpi/.agc.cpp.swp | Bin 0 -> 45056 bytes src/ipa/raspberrypi/controller/rpi/agc.cpp | 12 ++++++++---- src/ipa/raspberrypi/controller/rpi/lux.cpp | 3 ++- src/ipa/rkisp1/algorithms/agc.cpp | 12 ++++++++---- 7 files changed, 33 insertions(+), 19 deletions(-) create mode 100644 src/ipa/raspberrypi/controller/rpi/.agc.cpp.swp diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index a1a3c38f..f1650468 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -100,7 +100,8 @@ int Agc::configure(IPAContext &context, /* Configure the default exposure and gain. */ activeState.agc.gain = std::max(minAnalogueGain_, kMinAnalogueGain); - activeState.agc.exposure = 10ms / configuration.sensor.lineDuration; + activeState.agc.exposure = 10ms / + std::chrono::duration(configuration.sensor.lineDuration); frameCount_ = 0; return 0; @@ -240,17 +241,20 @@ void Agc::computeExposure(IPAContext &context, IPAFrameContext &frameContext, * increase the gain. */ utils::Duration shutterTime = - std::clamp(exposureValue / minAnalogueGain_, - minShutterSpeed_, maxShutterSpeed_); - double stepGain = std::clamp(exposureValue / shutterTime, - minAnalogueGain_, maxAnalogueGain_); + std::clamp(std::chrono::duration(exposureValue) / + minAnalogueGain_, + minShutterSpeed_, maxShutterSpeed_); + double stepGain = std::clamp(std::chrono::duration(exposureValue) / + std::chrono::duration(shutterTime), + minAnalogueGain_, maxAnalogueGain_); LOG(IPU3Agc, Debug) << "Divided up shutter and gain are " << shutterTime << " and " << stepGain; IPAActiveState &activeState = context.activeState; /* Update the estimated exposure and gain. */ - activeState.agc.exposure = shutterTime / configuration.sensor.lineDuration; + activeState.agc.exposure = std::chrono::duration(shutterTime) / + std::chrono::duration(configuration.sensor.lineDuration); activeState.agc.gain = stepGain; } diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp index d90ac1de..48a8a068 100644 --- a/src/ipa/raspberrypi/cam_helper.cpp +++ b/src/ipa/raspberrypi/cam_helper.cpp @@ -63,7 +63,7 @@ void CamHelper::process([[maybe_unused]] StatisticsPtr &stats, uint32_t CamHelper::exposureLines(const Duration exposure, const Duration lineLength) const { - return exposure / lineLength; + return std::chrono::duration(exposure) / std::chrono::duration(lineLength); } Duration CamHelper::exposure(uint32_t exposureLines, const Duration lineLength) const @@ -85,8 +85,8 @@ std::pair CamHelper::getBlanking(Duration &exposure, * frameLengthMax gets calculated on the smallest line length as we do * not want to extend that unless absolutely necessary. */ - frameLengthMin = minFrameDuration / mode_.minLineLength; - frameLengthMax = maxFrameDuration / mode_.minLineLength; + frameLengthMin = std::chrono::duration(minFrameDuration) / std::chrono::duration(mode_.minLineLength); + frameLengthMax = std::chrono::duration(maxFrameDuration) / std::chrono::duration(mode_.minLineLength); /* * Watch out for (exposureLines + frameIntegrationDiff_) overflowing a diff --git a/src/ipa/raspberrypi/cam_helper_imx296.cpp b/src/ipa/raspberrypi/cam_helper_imx296.cpp index ecb845e7..c5180de5 100644 --- a/src/ipa/raspberrypi/cam_helper_imx296.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx296.cpp @@ -57,7 +57,8 @@ double CamHelperImx296::gain(uint32_t gainCode) const uint32_t CamHelperImx296::exposureLines(const Duration exposure, [[maybe_unused]] const Duration lineLength) const { - return std::max(minExposureLines, (exposure - 14.26us) / timePerLine); + return std::max(minExposureLines, std::chrono::duration(exposure - 14.26us) / + std::chrono::duration(timePerLine)); } Duration CamHelperImx296::exposure(uint32_t exposureLines, diff --git a/src/ipa/raspberrypi/controller/rpi/.agc.cpp.swp b/src/ipa/raspberrypi/controller/rpi/.agc.cpp.swp new file mode 100644 index 0000000000000000000000000000000000000000..7b26d5511f7338b4cd3f28246243c9110c39aab0 GIT binary patch literal 45056 zcmeI536xw{dFMN9rT}9CHiWP}w{5vv>aLdLC3b7^X-O?vi6jfPY$3}!#p|lq-4E5~ zdQ~kovLS#68xzI^90m>v8Eg&=Gi+f8*qi}|Ng#wZW*IXB%1 z%~isB)D9<;c4abdg_G?tY0X9L_HrwptTY>)cC%KC+LLX*h6|NarPVrB<*WBsDe!NZ z0^QF1#3iSXT(EJ&dLhF(qh|+?d+e3}mMOB@_f-n4Qec$=s}xwJz$yh+DX>a`RSNu@ zqd=!s7dKipow z#(sXk=YGLnFWb*Ow!yCaN7(D3{roRI_a9=f&)LsMJ=px=-nU;ze$(D>^xU_XS3g!M zuu6ed3anCKl>)02Sf#)!1y(7rN`X}htWsc=0{>4^AgqpzoJ-4JD)ut*e`o)H_KcB{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}*|9DJCdfg6|swV2&dB1M_csuWnw!RFlK zGlLVbJYXi6p+#CVJ9?D0+)rAo-H}VwSAT<+sH%nVp$idMw+pjf4p}2+#t%+7Glw}Y zkE*%LP7|t;?0+pse@Q|-A=os`D~|M#=BR8jyBpC4suALW>{hl+a2AG3`!)2ET|#tF zw>>2_(Wv3(n)rjXNP>(U%N?1+n57LUMiM5jVz`K(sG%9P;w_?(Q59QkQfNw35L2cp z_UDeQ_EN=#pzS3`H?>gRK_^;_dcA8L2hP+pQ?}Dy7CA?`hB_J1rI$G&3fG6EK%y!vGKUd>dNvy+129SjSO%)4vE`o-nm>VaZGuddL zx(u0^xnm9J>nTn{u;MEBmTImxBm03JhTtFE+qccdRwXn{bzL`ERoFcM!M1`>qt9ZW z+Of|s^nT9ZgZ{7dsAhqT={t#E`jPwbm;!l&Lsuk`Q~7mly8pKWCBB7u7FJKsgmE$B(KB!^_nrk=ej$Pb zQq|50bHgFKnXu?L!@_jg&Nscr#d|4Hjri{5AN>NO6 zW94ST%6jQZoVwYuBX(gtsOwa!33`IkXn{H-MS&Ugain[stage] * shutterTime >= exposureValue) { - analogueGain = exposureValue / shutterTime; + analogueGain = std::chrono::duration(exposureValue) / + std::chrono::duration(shutterTime); break; } analogueGain = exposureMode_->gain[stage]; @@ -838,10 +840,12 @@ void Agc::divideUpExposure() */ if (!status_.fixedShutter && !status_.fixedAnalogueGain && status_.flickerPeriod) { - int flickerPeriods = shutterTime / status_.flickerPeriod; + int flickerPeriods = std::chrono::duration(shutterTime) / + std::chrono::duration(status_.flickerPeriod); if (flickerPeriods) { Duration newShutterTime = flickerPeriods * status_.flickerPeriod; - analogueGain *= shutterTime / newShutterTime; + analogueGain *= std::chrono::duration(shutterTime) / + std::chrono::duration(newShutterTime); /* * We should still not allow the ag to go over the * largest value in the exposure mode. Note that this diff --git a/src/ipa/raspberrypi/controller/rpi/lux.cpp b/src/ipa/raspberrypi/controller/rpi/lux.cpp index 9759186a..410f6f44 100644 --- a/src/ipa/raspberrypi/controller/rpi/lux.cpp +++ b/src/ipa/raspberrypi/controller/rpi/lux.cpp @@ -94,7 +94,8 @@ void Lux::process(StatisticsPtr &stats, Metadata *imageMetadata) double currentY = sum / (double)num + .5; double gainRatio = referenceGain_ / currentGain; double shutterSpeedRatio = - referenceShutterSpeed_ / deviceStatus.shutterSpeed; + std::chrono::duration(referenceShutterSpeed_) / + std::chrono::duration(deviceStatus.shutterSpeed); double apertureRatio = referenceAperture_ / currentAperture; double yRatio = currentY * (65536 / numBins) / referenceY_; double estimatedLux = shutterSpeedRatio * gainRatio * diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp index 04062a36..bb874356 100644 --- a/src/ipa/rkisp1/algorithms/agc.cpp +++ b/src/ipa/rkisp1/algorithms/agc.cpp @@ -74,7 +74,8 @@ int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo) { /* Configure the default exposure and gain. */ context.activeState.agc.gain = std::max(context.configuration.agc.minAnalogueGain, kMinAnalogueGain); - context.activeState.agc.exposure = 10ms / context.configuration.sensor.lineDuration; + context.activeState.agc.exposure = 10ms / + std::chrono::duration(context.configuration.sensor.lineDuration); /* * According to the RkISP1 documentation: @@ -212,16 +213,19 @@ void Agc::computeExposure(IPAContext &context, IPAFrameContext &frameContext, * Push the shutter time up to the maximum first, and only then * increase the gain. */ - utils::Duration shutterTime = std::clamp(exposureValue / minAnalogueGain, + utils::Duration shutterTime = std::clamp(std::chrono::duration(exposureValue) / + minAnalogueGain, minShutterSpeed, maxShutterSpeed); - double stepGain = std::clamp(exposureValue / shutterTime, + double stepGain = std::clamp(std::chrono::duration(exposureValue) / + std::chrono::duration(shutterTime), minAnalogueGain, maxAnalogueGain); LOG(RkISP1Agc, Debug) << "Divided up shutter and gain are " << shutterTime << " and " << stepGain; /* Update the estimated exposure and gain. */ - activeState.agc.exposure = shutterTime / configuration.sensor.lineDuration; + activeState.agc.exposure = std::chrono::duration(shutterTime) / + std::chrono::duration(configuration.sensor.lineDuration); activeState.agc.gain = stepGain; }