From patchwork Tue Jul 5 09:55:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Rauch X-Patchwork-Id: 16543 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 05070BD1F1 for ; Tue, 5 Jul 2022 09:55:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3365163314; Tue, 5 Jul 2022 11:55:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657014955; bh=0RWRO+iLfz2rywTjOhEDFtBIjV12N/gFjMV6aYK3Ubg=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=eOzkUCaQDR7pSz0f39Rk/D1W4r9K5+NUGqELBcsG+xh8FcgIjh9pUuTL4SsYQE5Wj VRgH3HSBgtYgAz9eMIhi5BxOQ7qlsY93tNsnBZys1BYowv2ec75VAbx5371GLUcWDW AFcWPfT5vScgd1FyoJPQPfjOOFVaQhWLTFeymBsXjHnB4lLwn4IC5jfzxYgcI9lMIq KyQhYne9lIOz46CEHKbOWx2mE+u8AFSZ3jspNUn4DOETU63SGx+jpRf2xjzA1EfXnl VebOnaBHcY433qfFu3N4SWydM8z27l+og8LEpsTtdrxhTH6ul23D9fBUeUQppxkkeR h8WjpixfXAOpg== Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C00D66330C for ; Tue, 5 Jul 2022 11:55:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=gmx.net header.i=@gmx.net header.b="HKkNf/xy"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1657014953; bh=0RWRO+iLfz2rywTjOhEDFtBIjV12N/gFjMV6aYK3Ubg=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=HKkNf/xyHClHF94LjlZrjQWXWH+Cc68vu75iRmxDjmOLAsC/lO5MDvtl/++4W1EQi 2U7QxWuVrG85ZnEvbeftBLOzjQQ5opbgYe42/pYdOgFgAfm3pcchxSMcmO0SPeK3Qt ue56+Rm86qhHxq6pFun0nV/Hz8XESh+Nsvo6Tyrg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([92.18.80.244]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1Mwwdf-1nPVS60Rxb-00yPr9; Tue, 05 Jul 2022 11:55:53 +0200 To: libcamera-devel@lists.libcamera.org Date: Tue, 5 Jul 2022 10:55:48 +0100 Message-Id: <20220705095549.87466-2-Rauch.Christian@gmx.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220705095549.87466-1-Rauch.Christian@gmx.de> References: <20220705095549.87466-1-Rauch.Christian@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:+0RfU1Px5YXkpPn7rzCAOVS1w3QQxfpneCt82KfhzvtdC8jpyPL zQ543I20Aq/MUEnS2B/oDlW8OHVk20jHZjq7UCvp0U/3Ef5nFHxUMdA7zogVvLBgQDtzrxe Zez0Y8YBzYf9CLMG/NzXQSvXCo7KgqVI1By2jBKcSzOSXYcfGhl3JIT90Oca0rK0g0vUuW1 +Fak2FH5J+fA2BL2e/z+A== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:yJcITyJFyiU=:enhl0t3CgMIE/Crzh34+h9 zegNGfuyZ69WdLnnm+YeTjBNA3Tise/tC3Q+AUQiwZ2ZFBolE0/rRsvlAEIaJah0tFD2PU0su KS9YW3van0j7BIHkSvzwWRr0KQcnOR3MvqA0ftlL0SKHQhBj60VYZk5+gSJ+pXe/Z6aUYWLO+ 7LknX+xRtej2uic0gMKZ6C80pT0XH2v636KsYHItJQcQeJOf9jYwjSN8JsFAZ1MZ6SbsCRTIK 85P2B55xv6u0MdZRe/09wKnMqx1OADLNN2bDlk7xrWggrm3oUmeJ1g6UZiE5PrQuSTg/f1xF0 SRyjVxs76JccYLmDdCgJ6QjyaZ5lzY90DBNPVSqBtKm1vFfavMlZ4jE0IeUtnAj0xhMZt5/h2 C9Oo5ZKLUNVQOI2AJ2FWnUzg/K4uWodjDjcrrI6StKoY79bIEY5gLFg20FU9/vGgDhg7Xc5NL piL6btw1OLOUltUfNYiftfXkR4ZjY9Pq9dnuDaY1qlpkhFU2/MXBUdvlr27hfsvn2XVAw5pHP nEyVsyKWUjKyCy6V6NifQ5LBElaCEASG3TlzdcHiEzfEitI2mfNIDb9FF++3mZbm+L88inq4a OR536iNiMBaZhAXBn9nfQvoxqH0aM90oIdmJAIYj7GZw1WYXM3SHtkdwokCz3ro+QwqAaYqi1 Dq7r/m4Ho/DnvQ485JI5YwlDcRzUNtlO7B6Mdr/qPUcApa0W1npdqCAKNp5DqOKUsayFVZAOx w6wa8TPZ6INNxTanjBpczHJICYspB2FKnO41ey5vizUUVc4YiFSvoMMG6nQj7jX/xzVNv22w4 SR2yymMpZVm6bM8+dcFxF5KkaCLsF+oAC7QR+5Z/So0rsbKllrGWqcOJoDDjzcZ4GCdE/VYqD zgvZpjqMr1NHPPmGJBncgrwA2irpS8Wx+UCX4EhiSsFYiSFbpaJneKcqJI+6D8VHZz+xtN/sI uoHrGOYyqikZfo6sXOmzRcP203IGVLyxENt2pR7TT99gGO5NWR3GcWJ1eMXroHuc6h4KIkSDG LCd/PA7nXwSI1eSO/3sXH6csOa8p1UnMdcNg9RXIWNZb2wl0TcTwKfS2FDJ2/CT+wPFc+8EKy ehxp8fUZYQGfPWr/2O9y3iDsH3zkdW7PvQ+r53BQH2UlxOKUS+RDjoh1Q== Subject: [libcamera-devel] [PATCH v10 1/2] libcamera: controls: Use std::optional to handle invalid control values 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: Christian Rauch via libcamera-devel From: Christian Rauch Reply-To: Christian Rauch Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Previously, ControlList::get() would use default constructed objects to indicate that a ControlList does not have the requested Control. This has several disadvantages: 1) It requires types to be default constructible, 2) it does not differentiate between a default constructed object and an object that happens to have the same state as a default constructed object. std::optional additionally stores the information if the object is valid or not, and therefore is more expressive than a default constructed object. Signed-off-by: Christian Rauch Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- include/libcamera/controls.h | 5 +++-- src/android/camera_capabilities.cpp | 12 +++++----- src/android/camera_device.cpp | 21 +++++++++--------- src/android/camera_hal_manager.cpp | 2 +- src/cam/main.cpp | 4 ++-- src/gstreamer/gstlibcamerasrc.cpp | 2 +- src/ipa/raspberrypi/raspberrypi.cpp | 2 +- src/libcamera/pipeline/ipu3/ipu3.cpp | 9 ++++---- .../pipeline/raspberrypi/raspberrypi.cpp | 9 ++++---- src/qcam/dng_writer.cpp | 22 +++++++++---------- 10 files changed, 44 insertions(+), 44 deletions(-) -- 2.34.1 diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 665bcac1..192be784 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include #include #include @@ -373,11 +374,11 @@ public: bool contains(unsigned int id) const; template - T get(const Control &ctrl) const + std::optional get(const Control &ctrl) const { const ControlValue *val = find(ctrl.id()); if (!val) - return T{}; + return std::nullopt; return val->get(); } diff --git a/src/android/camera_capabilities.cpp b/src/android/camera_capabilities.cpp index 6f197eb8..5304b2da 100644 --- a/src/android/camera_capabilities.cpp +++ b/src/android/camera_capabilities.cpp @@ -1042,7 +1042,7 @@ int CameraCapabilities::initializeStaticMetadata() /* Sensor static metadata. */ std::array pixelArraySize; { - const Size &size = properties.get(properties::PixelArraySize); + const Size &size = properties.get(properties::PixelArraySize).value_or(Size{}); pixelArraySize[0] = size.width; pixelArraySize[1] = size.height; staticMetadata_->addEntry(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, @@ -1050,10 +1050,10 @@ int CameraCapabilities::initializeStaticMetadata() } if (properties.contains(properties::UnitCellSize)) { - const Size &cellSize = properties.get(properties::UnitCellSize); + const auto &cellSize = properties.get(properties::UnitCellSize); std::array physicalSize{ - cellSize.width * pixelArraySize[0] / 1e6f, - cellSize.height * pixelArraySize[1] / 1e6f + cellSize->width * pixelArraySize[0] / 1e6f, + cellSize->height * pixelArraySize[1] / 1e6f }; staticMetadata_->addEntry(ANDROID_SENSOR_INFO_PHYSICAL_SIZE, physicalSize); @@ -1061,7 +1061,7 @@ int CameraCapabilities::initializeStaticMetadata() { const Span &rects = - properties.get(properties::PixelArrayActiveAreas); + properties.get(properties::PixelArrayActiveAreas).value_or(Span{}); std::vector data{ static_cast(rects[0].x), static_cast(rects[0].y), @@ -1080,7 +1080,7 @@ int CameraCapabilities::initializeStaticMetadata() /* Report the color filter arrangement if the camera reports it. */ if (properties.contains(properties::draft::ColorFilterArrangement)) { - uint8_t filterArr = properties.get(properties::draft::ColorFilterArrangement); + uint8_t filterArr = *properties.get(properties::draft::ColorFilterArrangement); staticMetadata_->addEntry(ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT, filterArr); } diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 8c039fb9..46621232 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -306,7 +306,7 @@ int CameraDevice::initialize(const CameraConfigData *cameraConfigData) const ControlList &properties = camera_->properties(); if (properties.contains(properties::Location)) { - int32_t location = properties.get(properties::Location); + int32_t location = *properties.get(properties::Location); switch (location) { case properties::CameraLocationFront: facing_ = CAMERA_FACING_FRONT; @@ -356,7 +356,7 @@ int CameraDevice::initialize(const CameraConfigData *cameraConfigData) * metadata. */ if (properties.contains(properties::Rotation)) { - int rotation = properties.get(properties::Rotation); + int rotation = *properties.get(properties::Rotation); orientation_ = (360 - rotation) % 360; if (cameraConfigData && cameraConfigData->rotation != -1 && orientation_ != cameraConfigData->rotation) { @@ -1181,7 +1181,8 @@ void CameraDevice::requestComplete(Request *request) * as soon as possible, earlier than request completion time. */ uint64_t sensorTimestamp = static_cast(request->metadata() - .get(controls::SensorTimestamp)); + .get(controls::SensorTimestamp) + .value_or(0)); notifyShutter(descriptor->frameNumber_, sensorTimestamp); LOG(HAL, Debug) << "Request " << request->cookie() << " completed with " @@ -1560,29 +1561,28 @@ CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor) cons rolling_shutter_skew); /* Add metadata tags reported by libcamera. */ - const int64_t timestamp = metadata.get(controls::SensorTimestamp); + const int64_t timestamp = metadata.get(controls::SensorTimestamp).value_or(0); resultMetadata->addEntry(ANDROID_SENSOR_TIMESTAMP, timestamp); if (metadata.contains(controls::draft::PipelineDepth)) { - uint8_t pipeline_depth = - metadata.get(controls::draft::PipelineDepth); + uint8_t pipeline_depth = *metadata.get(controls::draft::PipelineDepth); resultMetadata->addEntry(ANDROID_REQUEST_PIPELINE_DEPTH, pipeline_depth); } if (metadata.contains(controls::ExposureTime)) { - int64_t exposure = metadata.get(controls::ExposureTime) * 1000ULL; + int64_t exposure = *metadata.get(controls::ExposureTime) * 1000ULL; resultMetadata->addEntry(ANDROID_SENSOR_EXPOSURE_TIME, exposure); } if (metadata.contains(controls::FrameDuration)) { - int64_t duration = metadata.get(controls::FrameDuration) * 1000; + int64_t duration = *metadata.get(controls::FrameDuration) * 1000; resultMetadata->addEntry(ANDROID_SENSOR_FRAME_DURATION, duration); } if (metadata.contains(controls::ScalerCrop)) { - Rectangle crop = metadata.get(controls::ScalerCrop); + Rectangle crop = *metadata.get(controls::ScalerCrop); int32_t cropRect[] = { crop.x, crop.y, static_cast(crop.width), static_cast(crop.height), @@ -1591,8 +1591,7 @@ CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor) cons } if (metadata.contains(controls::draft::TestPatternMode)) { - const int32_t testPatternMode = - metadata.get(controls::draft::TestPatternMode); + const int32_t testPatternMode = *metadata.get(controls::draft::TestPatternMode); resultMetadata->addEntry(ANDROID_SENSOR_TEST_PATTERN_MODE, testPatternMode); } diff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp index 5f7bfe26..0bffe96f 100644 --- a/src/android/camera_hal_manager.cpp +++ b/src/android/camera_hal_manager.cpp @@ -232,7 +232,7 @@ int32_t CameraHalManager::cameraLocation(const Camera *cam) if (!properties.contains(properties::Location)) return -1; - return properties.get(properties::Location); + return *properties.get(properties::Location); } CameraDevice *CameraHalManager::cameraDeviceFromHalId(unsigned int id) diff --git a/src/cam/main.cpp b/src/cam/main.cpp index 79875ed7..d8115cd8 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -301,7 +301,7 @@ std::string CamApp::cameraName(const Camera *camera) * is only used if the location isn't present or is set to External. */ if (props.contains(properties::Location)) { - switch (props.get(properties::Location)) { + switch (*props.get(properties::Location)) { case properties::CameraLocationFront: addModel = false; name = "Internal front camera "; @@ -321,7 +321,7 @@ std::string CamApp::cameraName(const Camera *camera) * If the camera location is not availble use the camera model * to build the camera name. */ - name = "'" + props.get(properties::Model) + "' "; + name = "'" + *props.get(properties::Model) + "' "; } name += "(" + camera->id() + ")"; diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index a7a0c440..3d3efc0c 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -234,7 +234,7 @@ GstLibcameraSrcState::requestCompleted(Request *request) } if (GST_ELEMENT_CLOCK(src_)) { - int64_t timestamp = request->metadata().get(controls::SensorTimestamp); + int64_t timestamp = request->metadata().get(controls::SensorTimestamp).value_or(0); GstClockTime gst_base_time = GST_ELEMENT(src_)->base_time; GstClockTime gst_now = gst_clock_get_time(GST_ELEMENT_CLOCK(src_)); diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index f8d37b87..c7492a77 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -993,7 +993,7 @@ void IPARPi::returnEmbeddedBuffer(unsigned int bufferId) void IPARPi::prepareISP(const ISPConfig &data) { - int64_t frameTimestamp = data.controls.get(controls::SensorTimestamp); + int64_t frameTimestamp = data.controls.get(controls::SensorTimestamp).value_or(0); RPiController::Metadata lastMetadata; Span embeddedBuffer; diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index b7dda282..43db7b68 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -1145,7 +1145,7 @@ int PipelineHandlerIPU3::registerCameras() /* Convert the sensor rotation to a transformation */ int32_t rotation = 0; if (data->properties_.contains(properties::Rotation)) - rotation = data->properties_.get(properties::Rotation); + rotation = *(data->properties_.get(properties::Rotation)); else LOG(IPU3, Warning) << "Rotation control not exposed by " << cio2->sensor()->id() @@ -1331,7 +1331,7 @@ void IPU3CameraData::imguOutputBufferReady(FrameBuffer *buffer) request->metadata().set(controls::draft::PipelineDepth, 3); /* \todo Actually apply the scaler crop region to the ImgU. */ if (request->controls().contains(controls::ScalerCrop)) - cropRegion_ = request->controls().get(controls::ScalerCrop); + cropRegion_ = *(request->controls().get(controls::ScalerCrop)); request->metadata().set(controls::ScalerCrop, cropRegion_); if (frameInfos_.tryComplete(info)) @@ -1424,7 +1424,7 @@ void IPU3CameraData::statBufferReady(FrameBuffer *buffer) return; } - ipa_->processStatsBuffer(info->id, request->metadata().get(controls::SensorTimestamp), + ipa_->processStatsBuffer(info->id, request->metadata().get(controls::SensorTimestamp).value_or(0), info->statBuffer->cookie(), info->effectiveSensorControls); } @@ -1458,8 +1458,7 @@ void IPU3CameraData::frameStart(uint32_t sequence) if (!request->controls().contains(controls::draft::TestPatternMode)) return; - const int32_t testPatternMode = request->controls().get( - controls::draft::TestPatternMode); + const int32_t testPatternMode = *(request->controls().get(controls::draft::TestPatternMode)); int ret = cio2_.sensor()->setTestPatternMode( static_cast(testPatternMode)); diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 66a84b1d..28f054cb 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -364,7 +364,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() * error means the platform can never run. Let's just print a warning * and continue regardless; the rotation is effectively set to zero. */ - int32_t rotation = data_->sensor_->properties().get(properties::Rotation); + int32_t rotation = data_->sensor_->properties().get(properties::Rotation).value_or(0); bool success; Transform rotationTransform = transformFromRotation(rotation, &success); if (!success) @@ -1717,7 +1717,8 @@ void RPiCameraData::statsMetadataComplete(uint32_t bufferId, const ControlList & * V4L2_CID_NOTIFY_GAINS control (which means notifyGainsUnity_ is set). */ if (notifyGainsUnity_ && controls.contains(libcamera::controls::ColourGains)) { - libcamera::Span colourGains = controls.get(libcamera::controls::ColourGains); + libcamera::Span colourGains = + *controls.get(libcamera::controls::ColourGains); /* The control wants linear gains in the order B, Gb, Gr, R. */ ControlList ctrls(sensor_->controls()); std::array gains{ @@ -2052,7 +2053,7 @@ Rectangle RPiCameraData::scaleIspCrop(const Rectangle &ispCrop) const void RPiCameraData::applyScalerCrop(const ControlList &controls) { if (controls.contains(controls::ScalerCrop)) { - Rectangle nativeCrop = controls.get(controls::ScalerCrop); + Rectangle nativeCrop = *controls.get(controls::ScalerCrop); if (!nativeCrop.width || !nativeCrop.height) nativeCrop = { 0, 0, 1, 1 }; @@ -2090,7 +2091,7 @@ void RPiCameraData::fillRequestMetadata(const ControlList &bufferControls, Request *request) { request->metadata().set(controls::SensorTimestamp, - bufferControls.get(controls::SensorTimestamp)); + bufferControls.get(controls::SensorTimestamp).value_or(0)); request->metadata().set(controls::ScalerCrop, scalerCrop_); } diff --git a/src/qcam/dng_writer.cpp b/src/qcam/dng_writer.cpp index 34c8df5a..4b5d8276 100644 --- a/src/qcam/dng_writer.cpp +++ b/src/qcam/dng_writer.cpp @@ -392,7 +392,7 @@ int DNGWriter::write(const char *filename, const Camera *camera, TIFFSetField(tif, TIFFTAG_MAKE, "libcamera"); if (cameraProperties.contains(properties::Model)) { - std::string model = cameraProperties.get(properties::Model); + std::string model = *cameraProperties.get(properties::Model); TIFFSetField(tif, TIFFTAG_MODEL, model.c_str()); /* \todo set TIFFTAG_UNIQUECAMERAMODEL. */ } @@ -438,16 +438,15 @@ int DNGWriter::write(const char *filename, const Camera *camera, const double eps = 1e-2; if (metadata.contains(controls::ColourGains)) { - Span const &colourGains = metadata.get(controls::ColourGains); - if (colourGains[0] > eps && colourGains[1] > eps) { - wbGain = Matrix3d::diag(colourGains[0], 1, colourGains[1]); - neutral[0] = 1.0 / colourGains[0]; /* red */ - neutral[2] = 1.0 / colourGains[1]; /* blue */ + const auto &colourGains = metadata.get(controls::ColourGains); + if ((*colourGains)[0] > eps && (*colourGains)[1] > eps) { + wbGain = Matrix3d::diag((*colourGains)[0], 1, (*colourGains)[1]); + neutral[0] = 1.0 / (*colourGains)[0]; /* red */ + neutral[2] = 1.0 / (*colourGains)[1]; /* blue */ } } if (metadata.contains(controls::ColourCorrectionMatrix)) { - Span const &coeffs = metadata.get(controls::ColourCorrectionMatrix); - Matrix3d ccmSupplied(coeffs); + Matrix3d ccmSupplied(*metadata.get(controls::ColourCorrectionMatrix)); if (ccmSupplied.determinant() > eps) ccm = ccmSupplied; } @@ -515,7 +514,8 @@ int DNGWriter::write(const char *filename, const Camera *camera, uint32_t whiteLevel = (1 << info->bitsPerSample) - 1; if (metadata.contains(controls::SensorBlackLevels)) { - Span levels = metadata.get(controls::SensorBlackLevels); + Span levels = + *metadata.get(controls::SensorBlackLevels); /* * The black levels control is specified in R, Gr, Gb, B order. @@ -593,13 +593,13 @@ int DNGWriter::write(const char *filename, const Camera *camera, TIFFSetField(tif, EXIFTAG_DATETIMEDIGITIZED, strTime); if (metadata.contains(controls::AnalogueGain)) { - float gain = metadata.get(controls::AnalogueGain); + float gain = *metadata.get(controls::AnalogueGain); uint16_t iso = std::min(std::max(gain * 100, 0.0f), 65535.0f); TIFFSetField(tif, EXIFTAG_ISOSPEEDRATINGS, 1, &iso); } if (metadata.contains(controls::ExposureTime)) { - float exposureTime = metadata.get(controls::ExposureTime) / 1e6; + float exposureTime = *metadata.get(controls::ExposureTime) / 1e6; TIFFSetField(tif, EXIFTAG_EXPOSURETIME, exposureTime); } From patchwork Tue Jul 5 09:55:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Rauch X-Patchwork-Id: 16544 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 C784ABD1F1 for ; Tue, 5 Jul 2022 09:55:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3D2CE63311; Tue, 5 Jul 2022 11:55:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657014956; bh=An9X0i6Ef9+rRDe3oEn6t2yOn94uiNIubfSZdYN6cTw=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=3zV8UGdQ4aKCUxFKethwLMLEdPeXA8ipU102dcMuNFRTICuG03dOxHDuiKM/5DN/+ urSp8+3aEwgfkbcd/oI0LSj4p17sA7uk3bCvjGMlQIHlt9rTPbKoZ/xSYYdm7RN5ak tKDpBe6aC0T8QYST4TmUCDktGJNCdE09Tlr0byGxeKvqtBt2S5wGPnviV3uXwnySjq DS5M1I4yA+NXBtkwZaqGR6DE3YUrxvzdeqUQM+hRlpLf37NJdlKB3elpNNaibbdmrQ r2RYKjAqI0r8y3i52eY/E0smVWnAk/xipKgBGB6Cv0570pNBMb4itvrWi8kk2HCaSp +4j31WU/bKqvA== Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EBCD66330E for ; Tue, 5 Jul 2022 11:55:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=gmx.net header.i=@gmx.net header.b="d/txw2Jz"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1657014953; bh=An9X0i6Ef9+rRDe3oEn6t2yOn94uiNIubfSZdYN6cTw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=d/txw2Jz9X5xJeQpSK/wNtqMrqH5YYyI1CXXW7p3EbyzEy20V+rl8JtzJAvMp6UgO PPTMokBIptbmKEj68j2uz4nPVzYe0jUY7HiYrLDZ6sMBTxpj6UC4DJCkHOdyfIidEv mwaIGg9ol+ExRMUcxTPv6lAB7LBsoNk7eSVCJECY= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([92.18.80.244]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MZCfJ-1o4f5U1jFZ-00V6RV; Tue, 05 Jul 2022 11:55:53 +0200 To: libcamera-devel@lists.libcamera.org Date: Tue, 5 Jul 2022 10:55:49 +0100 Message-Id: <20220705095549.87466-3-Rauch.Christian@gmx.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220705095549.87466-1-Rauch.Christian@gmx.de> References: <20220705095549.87466-1-Rauch.Christian@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:OP7huhtyEozc/c8BuhVCpa+GlF04X43VU4VFbMNmEWoF3va3mcV W5gq5NCcQKj4GpFzsHUrsSYcIM7O/UVQiT/+W38uX8ZqL1O8LQwNXVtyK5cPDYtK0UgXqO8 Kb+XrAIA0aCzvXw0iy5UFJhZoCoC8VtEyYe0X9UBUVRzX7og1bp+dk6OSx1OrzMymQjDQbz BVYqWM1/KLIN1rCqRxBwg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:G2okjdK9dcc=:HPznW9YatiPXZYWmK942aO 07vKilGjxysksVlGVbPNPgfjdsKYrz5+46R0zOAvN68a+/mzJkzweuKkGHJZ9PajYltP7WKGs 474IALRQUEEgKkH4VCYsXza4mYBsPck8CQRI/GHNAQY+S3Li1XMJ4B/a6yW3PgA3FEJWVt5a5 sK6xKGEEePb1KsT+vseNXLAd9D6mw0LejJugcOBGKWUPgpLaDoHXqRxPPawhTwMzvBHmPgUL/ 99P3762mP4frIVLpZPmUWbwPZW9+lDYzffJwwlI7tSPNLvXw/tMKgmNdaWsBWY3X7GulZgrRK H70QODjZFGzo3OEA+OIz8BuKB4LT7OMPv6rh/cjVJZ2YRDxNsl8DAK2dWJ/B3RmAqMAfIfx4Y l2qaaXp9Gj+6iYpOZg7g+8nNZ3djDkVoXbd4rl1wlX6xvMhgY94vmuFnFPefBX3Auyfi/++pb Dcoae8buS3/GmLtR/jupacfVxhSBeDaPuDYcvHyMyxls4ZxgC+fd4Y5i2AWJLkutD167+YIQf Ddm6yRx7Z0Um+Adc8mHYxG14n3XQNkqtVx5qY0QFGmwAraHbBDlF5ZyqZcaVZWCrJx+dA3BZR yY53uTH5gl6tdRBPe70Tgqq6hYTizqoRBI/9FbcnoT3HoJCEKHlN8rht5X8kFmM9fDnZkHLBE 2m1qyNYhxoK8JL7Frp9l0r8MN7XRECb7jqR66LiABad1bjm6QcbSh1P7waxjHspeJHNgefeP+ vL70vz5wNABGjPX8lnrgvJpvoeOuODXybqVqg6ddS3ZNOlm37ySlx+e9vB7x+u0mP34DBAdaO qOgtkGmm78mk8qwSirGXrxJqHz/7ipDqPWJh+yCQ8KT3aA6vYU58Fp3v5TLH7wIfNbOmm6Yy9 DY4UJr7cWWbHQM5Egy7Fkp/hgtUg9LdEv5XzOcMt4W3hBgC56WX5Ma8QKJabEPg3ylyXZzHvk NWlhk0BOwQDKfg5LW8rC4zr13o4ZCJSDkCjNIPTr9h1/9CGPJsK9Tk9FN4VXS6qEjXla3ZEnW a6sHaazW27xvjNKN5JxxuF7MctGvOLj/j9pMNl42KknMdDwPQsOh4aAFj63WGzu6hl3UvLXvb d7KMX1B8NpwG3Lm/E3VX7HNOtAOkGXNoVh6EXNO5Q7rXeYoW3PwYSYdeg== Subject: [libcamera-devel] [PATCH v10 2/2] libcamera: controls: Generate and use fixed-sized Span types 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: Christian Rauch via libcamera-devel From: Christian Rauch Reply-To: Christian Rauch Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Define Span types explicitly as either variable- or fixed-sized. This introduces a new convention for defining Span dimensions in the property and control value definitions and generates Span types as variable-sized Span or as fixed-sized Span. Signed-off-by: Christian Rauch Reviewed-by: Jacopo Mondi --- include/libcamera/controls.h | 2 +- src/ipa/raspberrypi/raspberrypi.cpp | 19 +++++------ src/libcamera/control_ids.yaml | 4 +-- .../pipeline/raspberrypi/raspberrypi.cpp | 2 +- src/libcamera/property_ids.yaml | 4 +-- src/qcam/dng_writer.cpp | 2 +- utils/gen-controls.py | 32 +++++++++++++------ 7 files changed, 39 insertions(+), 26 deletions(-) -- 2.34.1 diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 192be784..a19f1845 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -168,7 +168,7 @@ public: using V = typename T::value_type; const V *value = reinterpret_cast(data().data()); - return { value, numElements_ }; + return T{ value, numElements_ }; } #ifndef __DOXYGEN__ diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index c7492a77..baaa1e08 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -559,18 +559,19 @@ void IPARPi::reportMetadata() AwbStatus *awbStatus = rpiMetadata_.GetLocked("awb.status"); if (awbStatus) { - libcameraMetadata_.set(controls::ColourGains, { static_cast(awbStatus->gain_r), - static_cast(awbStatus->gain_b) }); + libcameraMetadata_.set(controls::ColourGains, + Span({ static_cast(awbStatus->gain_r), + static_cast(awbStatus->gain_b) })); libcameraMetadata_.set(controls::ColourTemperature, awbStatus->temperature_K); } BlackLevelStatus *blackLevelStatus = rpiMetadata_.GetLocked("black_level.status"); if (blackLevelStatus) libcameraMetadata_.set(controls::SensorBlackLevels, - { static_cast(blackLevelStatus->black_level_r), - static_cast(blackLevelStatus->black_level_g), - static_cast(blackLevelStatus->black_level_g), - static_cast(blackLevelStatus->black_level_b) }); + Span({ blackLevelStatus->black_level_r, + blackLevelStatus->black_level_g, + blackLevelStatus->black_level_g, + blackLevelStatus->black_level_b })); FocusStatus *focusStatus = rpiMetadata_.GetLocked("focus.status"); if (focusStatus && focusStatus->num == 12) { @@ -875,7 +876,7 @@ void IPARPi::queueRequest(const ControlList &controls) if (gains[0] != 0.0f && gains[1] != 0.0f) /* A gain of 0.0f will switch back to auto mode. */ libcameraMetadata_.set(controls::ColourGains, - { gains[0], gains[1] }); + Span({ gains[0], gains[1] })); break; } @@ -1159,8 +1160,8 @@ void IPARPi::applyFrameDurations(Duration minFrameDuration, Duration maxFrameDur /* Return the validated limits via metadata. */ libcameraMetadata_.set(controls::FrameDurationLimits, - { static_cast(minFrameDuration_.get()), - static_cast(maxFrameDuration_.get()) }); + Span({ static_cast(minFrameDuration_.get()), + static_cast(maxFrameDuration_.get()) })); /* * Calculate the maximum exposure time possible for the AGC to use. diff --git a/src/libcamera/control_ids.yaml b/src/libcamera/control_ids.yaml index ecab3ae9..5fa168c6 100644 --- a/src/libcamera/control_ids.yaml +++ b/src/libcamera/control_ids.yaml @@ -291,7 +291,7 @@ controls: transformation. The 3x3 matrix is stored in conventional reading order in an array of 9 floating point values. - size: [3x3] + size: [3,3] - ScalerCrop: type: Rectangle @@ -525,7 +525,7 @@ controls: the window where the focal distance for the objects shown in that part of the image are closest to the camera. - size: [n] + size: [] - AfTrigger: type: int32_t diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 28f054cb..d88aa256 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -1717,7 +1717,7 @@ void RPiCameraData::statsMetadataComplete(uint32_t bufferId, const ControlList & * V4L2_CID_NOTIFY_GAINS control (which means notifyGainsUnity_ is set). */ if (notifyGainsUnity_ && controls.contains(libcamera::controls::ColourGains)) { - libcamera::Span colourGains = + libcamera::Span colourGains = *controls.get(libcamera::controls::ColourGains); /* The control wants linear gains in the order B, Gb, Gr, R. */ ControlList ctrls(sensor_->controls()); diff --git a/src/libcamera/property_ids.yaml b/src/libcamera/property_ids.yaml index 11b7ebdc..a87485d7 100644 --- a/src/libcamera/property_ids.yaml +++ b/src/libcamera/property_ids.yaml @@ -497,7 +497,7 @@ controls: - PixelArrayOpticalBlackRectangles: type: Rectangle - size: [n] + size: [] description: | The pixel array region(s) which contain optical black pixels considered valid for calibration purposes. @@ -592,7 +592,7 @@ controls: - PixelArrayActiveAreas: type: Rectangle - size: [n] + size: [] description: | The PixelArrayActiveAreas property defines the (possibly multiple and overlapping) portions of the camera sensor readable pixel matrix diff --git a/src/qcam/dng_writer.cpp b/src/qcam/dng_writer.cpp index 4b5d8276..23612be0 100644 --- a/src/qcam/dng_writer.cpp +++ b/src/qcam/dng_writer.cpp @@ -514,7 +514,7 @@ int DNGWriter::write(const char *filename, const Camera *camera, uint32_t whiteLevel = (1 << info->bitsPerSample) - 1; if (metadata.contains(controls::SensorBlackLevels)) { - Span levels = + Span levels = *metadata.get(controls::SensorBlackLevels); /* diff --git a/utils/gen-controls.py b/utils/gen-controls.py index 3f99b5e2..46ba4394 100755 --- a/utils/gen-controls.py +++ b/utils/gen-controls.py @@ -7,6 +7,8 @@ # gen-controls.py - Generate control definitions from YAML import argparse +from functools import reduce +import operator import string import sys import yaml @@ -22,6 +24,24 @@ def format_description(description): return '\n'.join([(line and ' * ' or ' *') + line for line in description]) +def get_ctrl_type(ctrl): + ctrl_type = ctrl['type'] + ctrl_size_arr = ctrl.get('size') + + if ctrl_type == 'string': + return 'std::string' + elif ctrl_size_arr is not None: + if len(ctrl_size_arr) > 0: + # fixed-sized Span + ctrl_span_size = reduce(operator.mul, ctrl_size_arr) + return f"Span" + else: + # variable-sized Span + return f"Span" + else: + return ctrl_type + + def generate_cpp(controls): enum_doc_start_template = string.Template('''/** * \\enum ${name}Enum @@ -50,11 +70,7 @@ ${description} name, ctrl = ctrl.popitem() id_name = snake_case(name).upper() - ctrl_type = ctrl['type'] - if ctrl_type == 'string': - ctrl_type = 'std::string' - elif ctrl.get('size'): - ctrl_type = 'Span' % ctrl_type + ctrl_type = get_ctrl_type(ctrl) info = { 'name': name, @@ -135,11 +151,7 @@ def generate_h(controls): ids.append('\t' + id_name + ' = ' + str(id_value) + ',') - ctrl_type = ctrl['type'] - if ctrl_type == 'string': - ctrl_type = 'std::string' - elif ctrl.get('size'): - ctrl_type = 'Span' % ctrl_type + ctrl_type = get_ctrl_type(ctrl) info = { 'name': name,