{"id":1436,"url":"https://patchwork.libcamera.org/api/1.1/patches/1436/?format=json","web_url":"https://patchwork.libcamera.org/patch/1436/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190616133402.21934-6-niklas.soderlund@ragnatech.se>","date":"2019-06-16T13:33:51","name":"[libcamera-devel,v3,05/16] libcamera: formats: Add ImageFormats","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"f36d9d9bf058f7d7776a852c2f35cf7e4f99a32e","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/1.1/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1436/mbox/","series":[{"id":358,"url":"https://patchwork.libcamera.org/api/1.1/series/358/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=358","date":"2019-06-16T13:33:46","name":"libcamera: Add support for format information and validation","version":3,"mbox":"https://patchwork.libcamera.org/series/358/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1436/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1436/checks/","tags":{},"headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net\n\t[195.74.38.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EBD3F6477F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 16 Jun 2019 15:35:34 +0200 (CEST)","from bismarck.berto.se (unknown [89.233.230.99])\n\tby bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA\n\tid 96a85828-903b-11e9-8ab4-005056917a89;\n\tSun, 16 Jun 2019 15:35:21 +0200 (CEST)"],"X-Halon-ID":"96a85828-903b-11e9-8ab4-005056917a89","Authorized-sender":"niklas@soderlund.pp.se","From":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","To":"libcamera-devel@lists.libcamera.org","Date":"Sun, 16 Jun 2019 15:33:51 +0200","Message-Id":"<20190616133402.21934-6-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20190616133402.21934-1-niklas.soderlund@ragnatech.se>","References":"<20190616133402.21934-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 05/16] libcamera: formats: Add\n\tImageFormats","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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>","X-List-Received-Date":"Sun, 16 Jun 2019 13:35:35 -0000"},"content":"Add a new class to hold format information for v4l2 devices and\nsubdevices. The object describes the relationship between either pixel\nformats (v4l2 devices) or media bus codes (v4l2 subdevice) and a list of\nimage sizes which can be produced with that format.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/libcamera/formats.cpp       | 80 +++++++++++++++++++++++++++++++++\n src/libcamera/include/formats.h | 14 ++++++\n 2 files changed, 94 insertions(+)","diff":"diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp\nindex 56f4ddb51ffad4d3..2fd0c5480324ce33 100644\n--- a/src/libcamera/formats.cpp\n+++ b/src/libcamera/formats.cpp\n@@ -24,4 +24,84 @@ namespace libcamera {\n  * resolutions represented by SizeRange items.\n  */\n \n+/**\n+ * \\class ImageFormats\n+ * \\brief Describe V4L2Device and V4L2SubDevice image formats\n+ *\n+ * The class describes information about image formats and supported sizes. If\n+ * the ImageFormat describe a V4L2Device the image formats are described with a\n+ * fourcc pixel format code, while if it describes a V4L2SubDevice the formats\n+ * are described with media bus codes, both defined by the V4L2 specification.\n+ */\n+\n+/**\n+ * \\brief Add a format and sizes to the description\n+ * \\param[in] format Pixel format or media bus code to describe\n+ * \\param[in] sizes List of supported sizes for the format\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ * \\retval -EBUSY The format is already described\n+ */\n+int ImageFormats::addFormat(unsigned int format, const std::vector<SizeRange> &sizes)\n+{\n+\tif (data_.find(format) != data_.end())\n+\t\treturn -EBUSY;\n+\n+\tdata_[format] = sizes;\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Check if the list of devices supported formats is empty\n+ * \\return True if the list of supported formats is empty\n+ */\n+bool ImageFormats::isEmpty() const\n+{\n+\treturn data_.empty();\n+}\n+\n+/**\n+ * \\brief Retrieve a list of all supported image formats\n+ * \\return List of pixel formats or media bus codes\n+ */\n+std::vector<unsigned int> ImageFormats::formats() const\n+{\n+\tstd::vector<unsigned int> formats;\n+\tformats.reserve(data_.size());\n+\n+\tfor (auto const &it : data_)\n+\t\tformats.push_back(it.first);\n+\n+\treturn formats;\n+}\n+\n+/**\n+ * \\brief Retrieve all sizes for a specific format\n+ * \\param[in] format A pixelformat or mbus code\n+ *\n+ * Retrieve all SizeRanges for a specific format. For V4L2Device \\a format is a\n+ * pixel format while for a V4L2Subdevice \\a format is a media bus code.\n+ *\n+ * \\return he list of image sizes produced using \\a format, or an empty list if\n+ * format is not supported\n+ */\n+std::vector<SizeRange> ImageFormats::sizes(unsigned int format) const\n+{\n+\tauto const &it = data_.find(format);\n+\tif (it == data_.end())\n+\t\treturn {};\n+\n+\treturn it->second;\n+}\n+\n+/**\n+ * \\brief Retrieve the map that associates formats to image sizes\n+ * \\return Map that associates formats to image sizes\n+ */\n+const std::map<unsigned int, std::vector<SizeRange>> &ImageFormats::data() const\n+{\n+\treturn data_;\n+}\n+\n } /* namespace libcamera */\ndiff --git a/src/libcamera/include/formats.h b/src/libcamera/include/formats.h\nindex a73772b1eda068b4..a49f83f3d8d60621 100644\n--- a/src/libcamera/include/formats.h\n+++ b/src/libcamera/include/formats.h\n@@ -17,6 +17,20 @@ namespace libcamera {\n \n typedef std::map<unsigned int, std::vector<SizeRange>> FormatEnum;\n \n+class ImageFormats\n+{\n+public:\n+\tint addFormat(unsigned int format, const std::vector<SizeRange> &sizes);\n+\n+\tbool isEmpty() const;\n+\tstd::vector<unsigned int> formats() const;\n+\tstd::vector<SizeRange> sizes(unsigned int format) const;\n+\tconst std::map<unsigned int, std::vector<SizeRange>> &data() const;\n+\n+private:\n+\tstd::map<unsigned int, std::vector<SizeRange>> data_;\n+};\n+\n } /* namespace libcamera */\n \n #endif /* __LIBCAMERA_FORMATS_H__ */\n","prefixes":["libcamera-devel","v3","05/16"]}