From patchwork Thu Apr 21 17:25:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Utkarsh Tiwari X-Patchwork-Id: 15700 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 C69EDC3256 for ; Thu, 21 Apr 2022 17:26:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 25C8865644; Thu, 21 Apr 2022 19:26:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1650561970; bh=+urxSG/E5xvwO2xYJBZRCVQxtKl08cBhx9+Mfj7iAOU=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=T5QBD0YrjLiCuq8U82FO85os1g55zCJKj3DyVN1ozQraTzpxfLmzbtX66TNORrl28 VEqBQlzqs4aHCbXwe18NGHftwSziBnGcU5/F9kHlJ8/1+bdHq+htfCoPrPekBm65q/ UfXNqGLQa2cyTAXoVXsilu3N3UDoDVDiYwIpLUb/mgMcEklvwtl7np/y4QeKe1CGF0 8illYDa1EChgyTxvRtUi13BpiYsGIGEHCQVeaDzxoM+I6PH4zp1h7Y4DhHOdpG3Mge C8hQGDtdz5U55kShOKkFAaORLdarLIr6mWOaMhpHgdhdUBcb1avmPQRxRxZAApunYy dtoG4z2xAVmhA== Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C9118604AE for ; Thu, 21 Apr 2022 19:26:08 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Jw268Wp4"; dkim-atps=neutral Received: by mail-pj1-x1032.google.com with SMTP id ga4-20020a17090b038400b001d4b33c74ccso4451976pjb.1 for ; Thu, 21 Apr 2022 10:26:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=X0ZT5Pa+tAD/jLffaQn9PdWfu656Nph7ctdc2G4fb38=; b=Jw268Wp45T0FloBcLF73JI0SW2vqxlaWVVQHb5oEGkdX5dGHEh2SGPxCsBV0H3NiKc cUFCtAUP8crG4czsPOCIGpx7F+fANpB4uedmS8a0JHHldoEJgNjh+SL79mx7xG/fOWhN vrUDHyqsbCSgXKNHrt7F7ClDRUgigYB4DIoDvXarfqP/W4szBvkZ7tvBo/E9b6M/wtz4 9wblWZ9unY61bt+BR5ndGmHSQ+Mo4Oq5r43QQIleRbSnOO7xHHmPHfP0DylMi6VTAQ56 p1I5ZlNCNW0sevMSxGql//Ov90ibG3Z3JqxNdo0KTzm+/65aLrazju7vIwJocBA6g+em lj1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=X0ZT5Pa+tAD/jLffaQn9PdWfu656Nph7ctdc2G4fb38=; b=yp3k5gcGMQYXoNKR1CdUwDGKxPrcJSKMRU05Pnk/HKtoACHbRKSEKkFDOGP6serkhs CTEi6RGkUyzvflzF0NojTInw5KV8rlZ0laG5zN1hUw026Jqxy8JOyNFhC4XicxeJAwaA 5DTuAGwmji4czaJTBM488ZM3eHf+hIxWMLMPX9OrOXdVDuh/pOlwZEqnk6Kl1396yYuK DiiQoA10LYb7Ot6viVMxWv6kDQJxx42ibQLCU0CxKB+GaYVdkoufjnz4qfOcqkUngrIx qQAiPb3sGlThxoaUsDvHdumu77iMIY91+ft6v0CbsW1zi7SjB0B7zFYdpy6u6C3+aVPI TKGQ== X-Gm-Message-State: AOAM532uukPYFGHIQGk1PLmdO2wnigkSVfY5/i9BElS81WB3uTJNCT0g l2NpblrJ+UBXr5s6XlKgJPIIdab6Cps9Eg== X-Google-Smtp-Source: ABdhPJxA2jSj/sy4weAUwj1ZhKAmH8gcChLWRAwlVcXI+ulwmBxwRJEinUGtRDu7O8bPyb1kuDYx+g== X-Received: by 2002:a17:903:1205:b0:151:8ae9:93ea with SMTP id l5-20020a170903120500b001518ae993eamr461023plh.37.1650561966865; Thu, 21 Apr 2022 10:26:06 -0700 (PDT) Received: from localhost.localdomain ([2404:bd00:3:db75:9357:7a99:9595:33ae]) by smtp.gmail.com with ESMTPSA id iy2-20020a17090b16c200b001d75aabe050sm1080174pjb.34.2022.04.21.10.26.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Apr 2022 10:26:06 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 21 Apr 2022 22:55:48 +0530 Message-Id: <20220421172549.138360-1-utkarsh02t@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] Support float data type in options 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: Utkarsh Tiwari via libcamera-devel From: Utkarsh Tiwari Reply-To: Utkarsh Tiwari Cc: Utkarsh Tiwari Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" --- src/cam/options.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++-- src/cam/options.h | 6 +++++ 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/src/cam/options.cpp b/src/cam/options.cpp index 4f7e8691..759328fc 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -6,9 +6,11 @@ */ #include +#include #include #include #include +#include #include #include "options.h" @@ -43,6 +45,9 @@ * * \var OptionType::OptionKeyValue * \brief key=value list argument + * + * \var OptionType::OptionFloat + * \brief Float argument */ /* ----------------------------------------------------------------------------- @@ -129,6 +134,9 @@ const char *Option::typeName() const case OptionKeyValue: return "key=value"; + + case OptionFloat: + return "float"; } return "unknown"; @@ -256,14 +264,14 @@ bool OptionsBase::parseValue(const T &opt, const Option &option, integer = 0; } - value = OptionValue(integer); + value = OptionValue(static_cast(integer)); break; case OptionString: value = OptionValue(arg ? arg : ""); break; - case OptionKeyValue: + case OptionKeyValue: { KeyValueParser *kvParser = option.keyValueParser; KeyValueParser::Options keyValues = kvParser->parse(arg); if (!keyValues.valid()) @@ -273,6 +281,21 @@ bool OptionsBase::parseValue(const T &opt, const Option &option, break; } + case OptionFloat: + float float_val; + + if (arg) { + char *endptr; + float_val = strtof(arg, &endptr); + if (*endptr != '\0' || !std::isfinite(float_val)) + return false; + } else { + float_val = 0; + } + value = OptionValue(float_val); + break; + } + if (option.isArray) values_[opt].addValue(value); else @@ -283,6 +306,7 @@ bool OptionsBase::parseValue(const T &opt, const Option &option, template class OptionsBase; template class OptionsBase; +template class OptionsBase; /* ----------------------------------------------------------------------------- * KeyValueParser @@ -505,6 +529,9 @@ void KeyValueParser::usage(int indent) * * \var OptionValue::ValueType::ValueArray * \brief Array value + * + * \var OptionValue::ValueType::ValueFloat + * \brief Float value (float) */ /** @@ -561,6 +588,17 @@ OptionValue::OptionValue(const KeyValueParser::Options &value) { } +/** + * \brief Construct an float OptionValue instance + * \param[in] value The float value + * + * The value type is set to ValueType::ValueFloat. + */ +OptionValue::OptionValue(const float value) + : type_(ValueFloat), integer_(0), float_(value) +{ +} + /** * \brief Add an entry to an array value * \param[in] value The entry value @@ -600,6 +638,16 @@ OptionValue::operator int() const return toInteger(); } +/** + * \brief Cast the value to an int + * \return The option value as an int, or 0 if the value type isn't + * ValueType::ValueInteger + */ +OptionValue::operator float() const +{ + return toFloat(); +} + /** * \brief Cast the value to a std::string * \return The option value as an std::string, or an empty string if the value @@ -662,6 +710,19 @@ const std::vector &OptionValue::toArray() const return array_; } +/** + * \brief Retrieve the value as an float + * \return The option value as an int, or signaling not-a-number if the value type isn't + * ValueType::ValueFloat + */ +float OptionValue::toFloat() const +{ + if (type_ != ValueFloat) + return std::numeric_limits::signaling_NaN(); + + return float_; +} + /** * \brief Retrieve the list of child values * \return The list of child values diff --git a/src/cam/options.h b/src/cam/options.h index 4ddd4987..f0636f82 100644 --- a/src/cam/options.h +++ b/src/cam/options.h @@ -28,6 +28,7 @@ enum OptionType { OptionInteger, OptionString, OptionKeyValue, + OptionFloat, }; template @@ -124,6 +125,7 @@ public: ValueString, ValueKeyValue, ValueArray, + ValueFloat, }; OptionValue(); @@ -131,6 +133,7 @@ public: OptionValue(const char *value); OptionValue(const std::string &value); OptionValue(const KeyValueParser::Options &value); + OptionValue(const float value); void addValue(const OptionValue &value); @@ -139,11 +142,13 @@ public: operator int() const; operator std::string() const; + operator float() const; int toInteger() const; std::string toString() const; const KeyValueParser::Options &toKeyValues() const; const std::vector &toArray() const; + float toFloat() const; const OptionsParser::Options &children() const; @@ -153,5 +158,6 @@ private: std::string string_; KeyValueParser::Options keyValues_; std::vector array_; + float float_; OptionsParser::Options children_; }; From patchwork Thu Apr 21 17:25:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Utkarsh Tiwari X-Patchwork-Id: 15701 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 06B04C3256 for ; Thu, 21 Apr 2022 17:26:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B1C0465647; Thu, 21 Apr 2022 19:26:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1650561972; bh=B605x6FDZziCnsyZtxZl3XDoBxUCCH++SlJRlt2ed9k=; 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=Em71KWjvbly/nWhL/y9EEfNj74hA2BB+HkneMucuVViQABifYeK4IIRJRSAv/FzNR 872E3DNCmhpVQYE02WNiw2Sk7dFcIJ0lp1TtokxrjtTg9k2Jg8Sih5F9ojTTAloX6u ZLIZBjOg8VrKwlUUMs5tyoXaY3mg0lJuP+ztPMM68kIFwu4p3WQIGRttFKgx0IvrYx NHLPH3tjnhvZPrslrk7i6LfTPjTt0cI4J/O4zxhJ6yZqYnNhvkSTYpx2A2vfIbFnOu HUiOFMzOV7E2Zk26dJcENuwZEGH8loCpRkziUHnoqSTBvSOmsNfcfZ0ISJWxmAN5jS /ozC4Hu7wL3YA== Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 27B4A6563D for ; Thu, 21 Apr 2022 19:26:11 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="RH1W+V3b"; dkim-atps=neutral Received: by mail-pl1-x62c.google.com with SMTP id q1so4324742plx.13 for ; Thu, 21 Apr 2022 10:26:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tjDgSZHigoB2liOF7pVd99zsUk3oR30dd+oovknN5ac=; b=RH1W+V3bK4XkJ8bZA9Bsyn2QHVFww5i1JsAmGgq7OD+Txwl9iTNooA607XXWN1KqnX I5UlzukPiXDWihsfWLNFx8Jo3Am5TB7wYDTju1fwXXCZb0YDVd5AmIqmouA8NMFjPOyK E6C3pemp2oOt6KHT1oQoc412v3MgOx83bPodCCBnFgwRw2x9d5DbGRN6BJ0OQe6ckTY2 du8H419vifYgFVFmysBjpjl01O9uNSKSEprGZZgg/bQPc69GY2sojCXgGWGQUsSzoa3W nUxAFhta8HTDYtDSwwz5lpWyHkN0lh9g58fy56YzTNAX3vvoFJMZmcfjZZKRrPw2nEVb ywPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tjDgSZHigoB2liOF7pVd99zsUk3oR30dd+oovknN5ac=; b=0R9qTyNBv8umvcNR397AGr7/C5tHmcw2g1tiMCa4ThCM2ODYGcV+WC2Ka4VTHBWODd y1hSYX5SAMwTH3XEqZoThsC+XlTfeaO/ansWYkZIwqZ96iPXuSxjUhq5X+RppzaUrLQf xKcAqsygTWI1NAsDZMFpb9iBGlKpFR/MGXUyYNbobstk24Ee1nsWCnrIPna3GGNXICjV y5rwdnK9CJPI/yl+0WmPqhcTWOR0EkyurmfzNuG+HCHxDjj5aAwX1sJuOHYHjYuPadNz UpIxAYK34YY0Nfkc3p1+460sggkkD74SfThE4RZBwCTOOflRU5Fzzqw970BGEN29m6ka GDGA== X-Gm-Message-State: AOAM532Fb6/k9fVMgp5KjVYujHCUPgJYbEB+8mGTGT9MlbLgyogWFoJy CYIRmSTzpQskDQaYioZDyy8ym4CbILT4ow== X-Google-Smtp-Source: ABdhPJx1UYeyvACvx2SXunOEwWrCwoET/Zj6x8nyy2P8fnrrjdPaIE3uMddLu7qRxdWY+WtdMlwQSQ== X-Received: by 2002:a17:903:2cf:b0:151:a932:f1f0 with SMTP id s15-20020a17090302cf00b00151a932f1f0mr564719plk.130.1650561968553; Thu, 21 Apr 2022 10:26:08 -0700 (PDT) Received: from localhost.localdomain ([2404:bd00:3:db75:9357:7a99:9595:33ae]) by smtp.gmail.com with ESMTPSA id iy2-20020a17090b16c200b001d75aabe050sm1080174pjb.34.2022.04.21.10.26.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Apr 2022 10:26:08 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 21 Apr 2022 22:55:49 +0530 Message-Id: <20220421172549.138360-2-utkarsh02t@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220421172549.138360-1-utkarsh02t@gmail.com> References: <20220421172549.138360-1-utkarsh02t@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] Explicit cast to int 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: Utkarsh Tiwari via libcamera-devel From: Utkarsh Tiwari Reply-To: Utkarsh Tiwari Cc: Utkarsh Tiwari Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" After introduction of float values to options the conversion of unsigned int to int or vice versa is regarded as the same rank as conversion to and from float. Fix this by using an explicit cast Signed-off-by: tag. --- src/cam/stream_options.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cam/stream_options.cpp b/src/cam/stream_options.cpp index 150bd27c..83d216b7 100644 --- a/src/cam/stream_options.cpp +++ b/src/cam/stream_options.cpp @@ -90,8 +90,8 @@ int StreamKeyValueParser::updateConfiguration(CameraConfiguration *config, StreamConfiguration &cfg = config->at(i++); if (opts.isSet("width") && opts.isSet("height")) { - cfg.size.width = opts["width"]; - cfg.size.height = opts["height"]; + cfg.size.width = static_cast(opts["width"]); + cfg.size.height = static_cast(opts["height"]); } if (opts.isSet("pixelformat"))