From patchwork Wed Jun 12 00:43:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 1401 Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C706A61F72 for ; Wed, 12 Jun 2019 02:44:56 +0200 (CEST) X-Halon-ID: 35ddf7ca-8cab-11e9-8601-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 35ddf7ca-8cab-11e9-8601-0050569116f7; Wed, 12 Jun 2019 02:44:18 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Wed, 12 Jun 2019 02:43:48 +0200 Message-Id: <20190612004359.15772-6-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190612004359.15772-1-niklas.soderlund@ragnatech.se> References: <20190612004359.15772-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 05/16] libcamera: formats: Add ImageFormats X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Jun 2019 00:44:57 -0000 Add a new class to hold format information for v4l2 devices and subdevices. The object describes the relationship between either pixel formats (v4l2 devices) or media bus codes (v4l2 subdevice) and a list of image sizes which can be produced with that format. Signed-off-by: Niklas Söderlund --- src/libcamera/formats.cpp | 83 +++++++++++++++++++++++++++++++++ src/libcamera/include/formats.h | 17 +++++++ 2 files changed, 100 insertions(+) diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index 56f4ddb51ffad4d3..ab4bae0a5928d9ba 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -24,4 +24,87 @@ namespace libcamera { * resolutions represented by SizeRange items. */ +/** + * \class ImageFormats + * \brief Describe V4L2Device and V4L2SubDevice image formats + * + * The class describes information about image formats and supported sizes. If + * the ImageFormat describe a V4L2Device the formats described are pixel formats + * while if it describes a V4L2SubDevice the formats are media bus codes. + */ + +ImageFormats::ImageFormats() +{ +} + +/** + * \brief Add a format and sizes to the description + * \param[in] format Pixel format or media bus code to describe + * \param[in] sizes List of supported sizes for the format + * + * \return 0 on success or a negative error code otherwise + * \retval -EBUSY The format is already described + */ +int ImageFormats::addFormat(unsigned int format, const std::vector &sizes) +{ + if (data_.find(format) != data_.end()) + return -EBUSY; + + data_[format] = sizes; + + return 0; +} + +/** + * \brief Retrieve a list of all supported image formats + * \return List of pixel formats or media bus codes + */ +std::vector ImageFormats::formats() const +{ + std::vector formats; + formats.reserve(data_.size()); + + for (auto const &it : data_) + formats.push_back(it.first); + + return formats; +} + +/** + * \brief Retrieve all sizes for a specific format + * \param[in] format A pixelformat or mbus code + * + * Retrieve all SizeRanges for a specific format. For V4L2Device \a format is a + * pixel format while for a V4L2Subdevice \a format is a media bus code. + * + * \return he list of image sizes produced using \a format, or an empty list if + * format is not supported + */ +std::vector ImageFormats::sizes(unsigned int format) const +{ + auto const &it = data_.find(format); + if (it == data_.end()) + return {}; + + return it->second; +} + +/** + * \brief Check if the list of devices supported formats is empty + * \return True if the list of supported formats is empty + */ +bool ImageFormats::isEmpty() const +{ + return data_.empty(); +} + +/** + * \brief Retrieve the map that associates formats to image sizes + * \return Map that associates formats to image sizes + */ +const std::map> &ImageFormats::data() const +{ + return data_; +} + } /* namespace libcamera */ diff --git a/src/libcamera/include/formats.h b/src/libcamera/include/formats.h index a73772b1eda068b4..a31aa42bcb4742ac 100644 --- a/src/libcamera/include/formats.h +++ b/src/libcamera/include/formats.h @@ -17,6 +17,23 @@ namespace libcamera { typedef std::map> FormatEnum; +class ImageFormats +{ +public: + ImageFormats(); + + int addFormat(unsigned int format, const std::vector &sizes); + + std::vector formats() const; + std::vector sizes(unsigned int format) const; + + bool isEmpty() const; + const std::map> &data() const; + +private: + std::map> data_; +}; + } /* namespace libcamera */ #endif /* __LIBCAMERA_FORMATS_H__ */