[{"id":31170,"web_url":"https://patchwork.libcamera.org/comment/31170/","msgid":"<172607022536.1037309.4756369222241802228@ping.linuxembedded.co.uk>","date":"2024-09-11T15:57:05","subject":"Re: [PATCH 1/2] libcamera: controls: Add array information to\n\tControlId","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Paul Elder (2024-09-11 16:35:22)\n> Add to ControlId information on whether or not it is an array control,\n> and the size of the control if it is an array control.\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> ---\n>  include/libcamera/controls.h | 17 ++++++++++++++++-\n>  src/libcamera/controls.cpp   | 16 ++++++++++++++--\n>  2 files changed, 30 insertions(+), 3 deletions(-)\n> \n> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\n> index 8959dfcc2..b539159e1 100644\n> --- a/include/libcamera/controls.h\n> +++ b/include/libcamera/controls.h\n> @@ -46,50 +46,60 @@ struct control_type {\n>  template<>\n>  struct control_type<void> {\n>         static constexpr ControlType value = ControlTypeNone;\n> +       static constexpr std::size_t size = 0;\n>  };\n>  \n>  template<>\n>  struct control_type<bool> {\n>         static constexpr ControlType value = ControlTypeBool;\n> +       static constexpr std::size_t size = 0;\n>  };\n>  \n>  template<>\n>  struct control_type<uint8_t> {\n>         static constexpr ControlType value = ControlTypeByte;\n> +       static constexpr std::size_t size = 0;\n>  };\n>  \n>  template<>\n>  struct control_type<int32_t> {\n>         static constexpr ControlType value = ControlTypeInteger32;\n> +       static constexpr std::size_t size = 0;\n>  };\n>  \n>  template<>\n>  struct control_type<int64_t> {\n>         static constexpr ControlType value = ControlTypeInteger64;\n> +       static constexpr std::size_t size = 0;\n>  };\n>  \n>  template<>\n>  struct control_type<float> {\n>         static constexpr ControlType value = ControlTypeFloat;\n> +       static constexpr std::size_t size = 0;\n>  };\n>  \n>  template<>\n>  struct control_type<std::string> {\n>         static constexpr ControlType value = ControlTypeString;\n> +       static constexpr std::size_t size = 0;\n>  };\n>  \n>  template<>\n>  struct control_type<Rectangle> {\n>         static constexpr ControlType value = ControlTypeRectangle;\n> +       static constexpr std::size_t size = 0;\n>  };\n>  \n>  template<>\n>  struct control_type<Size> {\n>         static constexpr ControlType value = ControlTypeSize;\n> +       static constexpr std::size_t size = 0;\n>  };\n>  \n>  template<typename T, std::size_t N>\n>  struct control_type<Span<T, N>> : public control_type<std::remove_cv_t<T>> {\n> +       static constexpr std::size_t size = N;\n>  };\n>  \n>  } /* namespace details */\n> @@ -215,11 +225,14 @@ class ControlId\n>  {\n>  public:\n>         ControlId(unsigned int id, const std::string &name, ControlType type,\n> +                 std::size_t size = 0,\n>                   const std::map<std::string, int32_t> &enumStrMap = {});\n>  \n>         unsigned int id() const { return id_; }\n>         const std::string &name() const { return name_; }\n>         ControlType type() const { return type_; }\n> +       bool isArray() const { return size_ > 0; }\n> +       std::size_t size() const { return size_; }\n>         const std::map<std::string, int32_t> &enumStrMap() const { return enumStrMap_; }\n>         const std::string enumToString(int32_t value) const;\n>  \n> @@ -229,6 +242,7 @@ private:\n>         unsigned int id_;\n>         std::string name_;\n>         ControlType type_;\n> +       std::size_t size_;\n>         std::map<std::string, int32_t> enumStrMap_;\n>         std::map<int32_t, std::string> reverseMap_;\n>  };\n> @@ -260,7 +274,8 @@ public:\n>         using type = T;\n>  \n>         Control(unsigned int id, const char *name, const std::map<std::string, int32_t> &enumStrMap = {})\n> -               : ControlId(id, name, details::control_type<std::remove_cv_t<T>>::value, enumStrMap)\n> +               : ControlId(id, name, details::control_type<std::remove_cv_t<T>>::value,\n> +                           details::control_type<std::remove_cv_t<T>>::size, enumStrMap)\n>         {\n>         }\n>  \n> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\n> index 0f83139fb..1530bdb9c 100644\n> --- a/src/libcamera/controls.cpp\n> +++ b/src/libcamera/controls.cpp\n> @@ -394,8 +394,8 @@ void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElemen\n>   * \\param[in] enumStrMap The map from enum names to values (optional)\n>   */\n>  ControlId::ControlId(unsigned int id, const std::string &name, ControlType type,\n> -                    const std::map<std::string, int32_t> &enumStrMap)\n> -       : id_(id), name_(name), type_(type), enumStrMap_(enumStrMap)\n> +                    std::size_t size, const std::map<std::string, int32_t> &enumStrMap)\n> +       : id_(id), name_(name), type_(type), size_(size), enumStrMap_(enumStrMap)\n>  {\n>         for (const auto &pair : enumStrMap_)\n>                 reverseMap_[pair.second] = pair.first;\n> @@ -419,6 +419,18 @@ ControlId::ControlId(unsigned int id, const std::string &name, ControlType type,\n>   * \\return The control data type\n>   */\n>  \n> +/**\n> + * \\fn bool isArray() const\n> + * \\brief Determine if the control is an array control\n> + * \\return True if the control is an array control, false otherwise\n> + */\n> +\n> +/**\n> + * \\fn std::size_t size() const\n> + * \\brief Retrieve the size of the control if it is an array control\n> + * \\return The size of the array control, size_t::max for dynamic extend, or 0 for non-array\n> + */\n> +\n>  /**\n>   * \\brief Retrieve the name of an enum value\n>   * \\return The name of the enum value\n> -- \n> 2.39.2\n>","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 DCD2ABF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 11 Sep 2024 15:57:10 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 042E2618F2;\n\tWed, 11 Sep 2024 17:57:10 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4BF42618F2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 11 Sep 2024 17:57:08 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9444EBEB;\n\tWed, 11 Sep 2024 17:55:50 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"kT801qgD\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1726070150;\n\tbh=r547B40hSZTvxF4dKASGzOgoVPWzu1MbNzEn90ygQiA=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=kT801qgDHTXcsPXuZOu14VxfXumKcMfN11hLhCfUD39+qU9s92aEP/TqzhWnAniJD\n\tZNGoeaRV+BEp4llIlKbueM1bRe2ACu00gL0EiwimINr2SF3OWMT/LCYROsH27JaqCb\n\tvNP4vO3/7ESixtCBn0UtfBJD+xOeQz78/+hn9NYE=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20240911153523.1756554-2-paul.elder@ideasonboard.com>","References":"<20240911153523.1756554-1-paul.elder@ideasonboard.com>\n\t<20240911153523.1756554-2-paul.elder@ideasonboard.com>","Subject":"Re: [PATCH 1/2] libcamera: controls: Add array information to\n\tControlId","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Paul Elder <paul.elder@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 11 Sep 2024 16:57:05 +0100","Message-ID":"<172607022536.1037309.4756369222241802228@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]