[{"id":4663,"web_url":"https://patchwork.libcamera.org/comment/4663/","msgid":"<e6106c5d-22fc-43ef-b6ee-6f28b26fe1f7@ideasonboard.com>","date":"2020-04-30T09:00:03","subject":"Re: [libcamera-devel] [PATCH v2 1/6] libcamera: v4l2_pixelformat:\n\tMove V4L2PixelFormat to a new file","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"On 30/04/2020 04:07, Laurent Pinchart wrote:\n> Move the V4L2PixelFormat class to a new file to prepare for additional\n> changes that will make it grow. No functional modification is included.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nHi Laurent,\n\nI expect:\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nStill applies to this version.\n\n> ---\n>  src/libcamera/include/meson.build        |   1 +\n>  src/libcamera/include/v4l2_pixelformat.h |  45 ++++++++++\n>  src/libcamera/include/v4l2_videodevice.h |  24 +----\n>  src/libcamera/meson.build                |   1 +\n>  src/libcamera/v4l2_pixelformat.cpp       | 106 +++++++++++++++++++++++\n>  src/libcamera/v4l2_videodevice.cpp       |  77 ----------------\n>  6 files changed, 154 insertions(+), 100 deletions(-)\n>  create mode 100644 src/libcamera/include/v4l2_pixelformat.h\n>  create mode 100644 src/libcamera/v4l2_pixelformat.cpp\n> \n> diff --git a/src/libcamera/include/meson.build b/src/libcamera/include/meson.build\n> index 5aaa99472e4a..683d06133741 100644\n> --- a/src/libcamera/include/meson.build\n> +++ b/src/libcamera/include/meson.build\n> @@ -27,6 +27,7 @@ libcamera_headers = files([\n>      'utils.h',\n>      'v4l2_controls.h',\n>      'v4l2_device.h',\n> +    'v4l2_pixelformat.h',\n>      'v4l2_subdevice.h',\n>      'v4l2_videodevice.h',\n>  ])\n> diff --git a/src/libcamera/include/v4l2_pixelformat.h b/src/libcamera/include/v4l2_pixelformat.h\n> new file mode 100644\n> index 000000000000..4d277569cb8c\n> --- /dev/null\n> +++ b/src/libcamera/include/v4l2_pixelformat.h\n> @@ -0,0 +1,45 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2019, Google Inc.\n> + * Copyright (C) 2020, Raspberry Pi (Trading) Ltd.\n> + *\n> + * v4l2_pixelformat.h - V4L2 Pixel Format\n> + */\n> +#ifndef __LIBCAMERA_V4L2_PIXELFORMAT_H__\n> +#define __LIBCAMERA_V4L2_PIXELFORMAT_H__\n> +\n> +#include <stdint.h>\n> +#include <string>\n> +\n> +#include <linux/videodev2.h>\n> +\n> +#include <libcamera/pixelformats.h>\n> +\n> +namespace libcamera {\n> +\n> +class V4L2PixelFormat\n> +{\n> +public:\n> +\tV4L2PixelFormat()\n> +\t\t: fourcc_(0)\n> +\t{\n> +\t}\n> +\n> +\texplicit V4L2PixelFormat(uint32_t fourcc)\n> +\t\t: fourcc_(fourcc)\n> +\t{\n> +\t}\n> +\n> +\tbool isValid() const { return fourcc_ != 0; }\n> +\tuint32_t fourcc() const { return fourcc_; }\n> +\toperator uint32_t() const { return fourcc_; }\n> +\n> +\tstd::string toString() const;\n> +\n> +private:\n> +\tuint32_t fourcc_;\n> +};\n> +\n> +} /* namespace libcamera */\n> +\n> +#endif /* __LIBCAMERA_V4L2_PIXELFORMAT_H__ */\n> diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h\n> index 976ef9b6dc50..ff64bb357c7e 100644\n> --- a/src/libcamera/include/v4l2_videodevice.h\n> +++ b/src/libcamera/include/v4l2_videodevice.h\n> @@ -23,6 +23,7 @@\n>  #include \"formats.h\"\n>  #include \"log.h\"\n>  #include \"v4l2_device.h\"\n> +#include \"v4l2_pixelformat.h\"\n>  \n>  namespace libcamera {\n>  \n> @@ -149,29 +150,6 @@ private:\n>  \tunsigned int missCounter_;\n>  };\n>  \n> -class V4L2PixelFormat\n> -{\n> -public:\n> -\tV4L2PixelFormat()\n> -\t\t: fourcc_(0)\n> -\t{\n> -\t}\n> -\n> -\texplicit V4L2PixelFormat(uint32_t fourcc)\n> -\t\t: fourcc_(fourcc)\n> -\t{\n> -\t}\n> -\n> -\tbool isValid() const { return fourcc_ != 0; }\n> -\tuint32_t fourcc() const { return fourcc_; }\n> -\toperator uint32_t() const { return fourcc_; }\n> -\n> -\tstd::string toString() const;\n> -\n> -private:\n> -\tuint32_t fourcc_;\n> -};\n> -\n>  class V4L2DeviceFormat\n>  {\n>  public:\n> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\n> index 874d25904693..d8b4d7206aba 100644\n> --- a/src/libcamera/meson.build\n> +++ b/src/libcamera/meson.build\n> @@ -44,6 +44,7 @@ libcamera_sources = files([\n>      'utils.cpp',\n>      'v4l2_controls.cpp',\n>      'v4l2_device.cpp',\n> +    'v4l2_pixelformat.cpp',\n>      'v4l2_subdevice.cpp',\n>      'v4l2_videodevice.cpp',\n>  ])\n> diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp\n> new file mode 100644\n> index 000000000000..57d65c380b0d\n> --- /dev/null\n> +++ b/src/libcamera/v4l2_pixelformat.cpp\n> @@ -0,0 +1,106 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2019, Google Inc.\n> + * Copyright (C) 2020, Raspberry Pi (Trading) Ltd.\n> + *\n> + * v4l2_pixelformat.cpp - V4L2 Pixel Format\n> + */\n> +\n> +#include \"v4l2_pixelformat.h\"\n> +\n> +#include <ctype.h>\n> +#include <map>\n> +#include <string.h>\n> +\n> +#include <linux/drm_fourcc.h>\n> +\n> +#include <libcamera/pixelformats.h>\n> +\n> +#include \"log.h\"\n> +\n> +/**\n> + * \\file v4l2_pixelformat.h\n> + * \\brief V4L2 Pixel Format\n> + */\n> +namespace libcamera {\n> +\n> +LOG_DECLARE_CATEGORY(V4L2)\n> +\n> +/**\n> + * \\class V4L2PixelFormat\n> + * \\brief V4L2 pixel format FourCC wrapper\n> + *\n> + * The V4L2PixelFormat class describes the pixel format of a V4L2 buffer. It\n> + * wraps the V4L2 numerical FourCC, and shall be used in all APIs that deal with\n> + * V4L2 pixel formats. Its purpose is to prevent unintentional confusion of\n> + * V4L2 and DRM FourCCs in code by catching implicit conversion attempts at\n> + * compile time.\n> + *\n> + * To achieve this goal, construction of a V4L2PixelFormat from an integer value\n> + * is explicit. To retrieve the integer value of a V4L2PixelFormat, both the\n> + * explicit value() and implicit uint32_t conversion operators may be used.\n> + */\n> +\n> +/**\n> + * \\fn V4L2PixelFormat::V4L2PixelFormat()\n> + * \\brief Construct a V4L2PixelFormat with an invalid format\n> + *\n> + * V4L2PixelFormat instances constructed with the default constructor are\n> + * invalid, calling the isValid() function returns false.\n> + */\n> +\n> +/**\n> + * \\fn V4L2PixelFormat::V4L2PixelFormat(uint32_t fourcc)\n> + * \\brief Construct a V4L2PixelFormat from a FourCC value\n> + * \\param[in] fourcc The pixel format FourCC numerical value\n> + */\n> +\n> +/**\n> + * \\fn bool V4L2PixelFormat::isValid() const\n> + * \\brief Check if the pixel format is valid\n> + *\n> + * V4L2PixelFormat instances constructed with the default constructor are\n> + * invalid. Instances constructed with a FourCC defined in the V4L2 API are\n> + * valid. The behaviour is undefined otherwise.\n> + *\n> + * \\return True if the pixel format is valid, false otherwise\n> + */\n> +\n> +/**\n> + * \\fn uint32_t V4L2PixelFormat::fourcc() const\n> + * \\brief Retrieve the pixel format FourCC numerical value\n> + * \\return The pixel format FourCC numerical value\n> + */\n> +\n> +/**\n> + * \\fn V4L2PixelFormat::operator uint32_t() const\n> + * \\brief Convert to the pixel format FourCC numerical value\n> + * \\return The pixel format FourCC numerical value\n> + */\n> +\n> +/**\n> + * \\brief Assemble and return a string describing the pixel format\n> + * \\return A string describing the pixel format\n> + */\n> +std::string V4L2PixelFormat::toString() const\n> +{\n> +\tif (fourcc_ == 0)\n> +\t\treturn \"<INVALID>\";\n> +\n> +\tchar ss[8] = { static_cast<char>(fourcc_ & 0x7f),\n> +\t\t       static_cast<char>((fourcc_ >> 8) & 0x7f),\n> +\t\t       static_cast<char>((fourcc_ >> 16) & 0x7f),\n> +\t\t       static_cast<char>((fourcc_ >> 24) & 0x7f) };\n> +\n> +\tfor (unsigned int i = 0; i < 4; i++) {\n> +\t\tif (!isprint(ss[i]))\n> +\t\t\tss[i] = '.';\n> +\t}\n> +\n> +\tif (fourcc_ & (1 << 31))\n> +\t\tstrcat(ss, \"-BE\");\n> +\n> +\treturn ss;\n> +}\n> +\n> +} /* namespace libcamera */\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index e8d4f17dfdf1..21df4f524212 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -278,83 +278,6 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const\n>  \treturn true;\n>  }\n>  \n> -/**\n> - * \\class V4L2PixelFormat\n> - * \\brief V4L2 pixel format FourCC wrapper\n> - *\n> - * The V4L2PixelFormat class describes the pixel format of a V4L2 buffer. It\n> - * wraps the V4L2 numerical FourCC, and shall be used in all APIs that deal with\n> - * V4L2 pixel formats. Its purpose is to prevent unintentional confusion of\n> - * V4L2 and DRM FourCCs in code by catching implicit conversion attempts at\n> - * compile time.\n> - *\n> - * To achieve this goal, construction of a V4L2PixelFormat from an integer value\n> - * is explicit. To retrieve the integer value of a V4L2PixelFormat, both the\n> - * explicit value() and implicit uint32_t conversion operators may be used.\n> - */\n> -\n> -/**\n> - * \\fn V4L2PixelFormat::V4L2PixelFormat()\n> - * \\brief Construct a V4L2PixelFormat with an invalid format\n> - *\n> - * V4L2PixelFormat instances constructed with the default constructor are\n> - * invalid, calling the isValid() function returns false.\n> - */\n> -\n> -/**\n> - * \\fn V4L2PixelFormat::V4L2PixelFormat(uint32_t fourcc)\n> - * \\brief Construct a V4L2PixelFormat from a FourCC value\n> - * \\param[in] fourcc The pixel format FourCC numerical value\n> - */\n> -\n> -/**\n> - * \\fn bool V4L2PixelFormat::isValid() const\n> - * \\brief Check if the pixel format is valid\n> - *\n> - * V4L2PixelFormat instances constructed with the default constructor are\n> - * invalid. Instances constructed with a FourCC defined in the V4L2 API are\n> - * valid. The behaviour is undefined otherwise.\n> - *\n> - * \\return True if the pixel format is valid, false otherwise\n> - */\n> -\n> -/**\n> - * \\fn uint32_t V4L2PixelFormat::fourcc() const\n> - * \\brief Retrieve the pixel format FourCC numerical value\n> - * \\return The pixel format FourCC numerical value\n> - */\n> -\n> -/**\n> - * \\fn V4L2PixelFormat::operator uint32_t() const\n> - * \\brief Convert to the pixel format FourCC numerical value\n> - * \\return The pixel format FourCC numerical value\n> - */\n> -\n> -/**\n> - * \\brief Assemble and return a string describing the pixel format\n> - * \\return A string describing the pixel format\n> - */\n> -std::string V4L2PixelFormat::toString() const\n> -{\n> -\tif (fourcc_ == 0)\n> -\t\treturn \"<INVALID>\";\n> -\n> -\tchar ss[8] = { static_cast<char>(fourcc_ & 0x7f),\n> -\t\t       static_cast<char>((fourcc_ >> 8) & 0x7f),\n> -\t\t       static_cast<char>((fourcc_ >> 16) & 0x7f),\n> -\t\t       static_cast<char>((fourcc_ >> 24) & 0x7f) };\n> -\n> -\tfor (unsigned int i = 0; i < 4; i++) {\n> -\t\tif (!isprint(ss[i]))\n> -\t\t\tss[i] = '.';\n> -\t}\n> -\n> -\tif (fourcc_ & (1 << 31))\n> -\t\tstrcat(ss, \"-BE\");\n> -\n> -\treturn ss;\n> -}\n> -\n>  /**\n>   * \\class V4L2DeviceFormat\n>   * \\brief The V4L2 video device image format and sizes\n>","headers":{"Return-Path":"<kieran.bingham@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 85EB3613A7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Apr 2020 11:00:10 +0200 (CEST)","from [192.168.0.20]\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C1BD8503;\n\tThu, 30 Apr 2020 11:00:06 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"qiWWkc3W\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1588237207;\n\tbh=T9RE1IuS26zoXNXJxIIpyfod8ENfEMFHyBPaHYHVCHA=;\n\th=Reply-To:Subject:To:References:From:Date:In-Reply-To:From;\n\tb=qiWWkc3W/pXJ+gnI+RVGXhcWYaRHhwyK8T1K+eloapLoV+wCKDZGEqqjG+E98AARd\n\tsQ53Duis75c6TPAA5pQ4Vu+d9eQnmT/etobr2FJBWdNohw26EriTUlTNOW9n+2I1ou\n\teRv453RMD5TL3kuYdO9n6fU9i2jfGEeuzXRDNPEs=","Reply-To":"kieran.bingham@ideasonboard.com","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20200430030723.8908-1-laurent.pinchart@ideasonboard.com>\n\t<20200430030723.8908-2-laurent.pinchart@ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\tmQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat\n\tV/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC\n\trRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C\n\tpotzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07Xb2K99rjMwZVDgESKIzhsDB5GY465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EeRnIQpGH9BQJdizzIBQkLSKZiAAoJEKEeRnIQpGH9eYgQAJpjaWNgqNOnMTmD\n\tMJggbwjIotypzIXfhHNCeTkG7+qCDlSaBPclcPGYrTwCt0YWPU2TgGgJrVhYT20ierN8LUvj\n\t6qOPTd+Uk7NFzL65qkh80ZKNBFddx1AabQpSVQKbdcLb8OFs85kuSvFdgqZwgxA1vl4TFhNz\n\tPZ79NAmXLackAx3sOVFhk4WQaKRshCB7cSl+RIng5S/ThOBlwNlcKG7j7W2MC06BlTbdEkUp\n\tECzuuRBv8wX4OQl+hbWbB/VKIx5HKlLu1eypen/5lNVzSqMMIYkkZcjV2SWQyUGxSwq0O/sx\n\tS0A8/atCHUXOboUsn54qdxrVDaK+6jIAuo8JiRWctP16KjzUM7MO0/+4zllM8EY57rXrj48j\n\tsbEYX0YQnzaj+jO6kJtoZsIaYR7rMMq9aUAjyiaEZpmP1qF/2sYenDx0Fg2BSlLvLvXM0vU8\n\tpQk3kgDu7kb/7PRYrZvBsr21EIQoIjXbZxDz/o7z95frkP71EaICttZ6k9q5oxxA5WC6sTXc\n\tMW8zs8avFNuA9VpXt0YupJd2ijtZy2mpZNG02fFVXhIn4G807G7+9mhuC4XG5rKlBBUXTvPU\n\tAfYnB4JBDLmLzBFavQfvonSfbitgXwCG3vS+9HEwAjU30Bar1PEOmIbiAoMzuKeRm2LVpmq4\n\tWZw01QYHU/GUV/zHJSFk","Organization":"Ideas on Board","Message-ID":"<e6106c5d-22fc-43ef-b6ee-6f28b26fe1f7@ideasonboard.com>","Date":"Thu, 30 Apr 2020 10:00:03 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101\n\tThunderbird/68.7.0","MIME-Version":"1.0","In-Reply-To":"<20200430030723.8908-2-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH v2 1/6] libcamera: v4l2_pixelformat:\n\tMove V4L2PixelFormat to a new file","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>","X-List-Received-Date":"Thu, 30 Apr 2020 09:00:10 -0000"}},{"id":4667,"web_url":"https://patchwork.libcamera.org/comment/4667/","msgid":"<20200430095205.GB2092124@oden.dyn.berto.se>","date":"2020-04-30T09:52:05","subject":"Re: [libcamera-devel] [PATCH v2 1/6] libcamera: v4l2_pixelformat:\n\tMove V4L2PixelFormat to a new file","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nThanks for your work.\n\nOn 2020-04-30 06:07:18 +0300, Laurent Pinchart wrote:\n> Move the V4L2PixelFormat class to a new file to prepare for additional\n> changes that will make it grow. No functional modification is included.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  src/libcamera/include/meson.build        |   1 +\n>  src/libcamera/include/v4l2_pixelformat.h |  45 ++++++++++\n>  src/libcamera/include/v4l2_videodevice.h |  24 +----\n>  src/libcamera/meson.build                |   1 +\n>  src/libcamera/v4l2_pixelformat.cpp       | 106 +++++++++++++++++++++++\n>  src/libcamera/v4l2_videodevice.cpp       |  77 ----------------\n>  6 files changed, 154 insertions(+), 100 deletions(-)\n>  create mode 100644 src/libcamera/include/v4l2_pixelformat.h\n>  create mode 100644 src/libcamera/v4l2_pixelformat.cpp\n> \n> diff --git a/src/libcamera/include/meson.build b/src/libcamera/include/meson.build\n> index 5aaa99472e4a..683d06133741 100644\n> --- a/src/libcamera/include/meson.build\n> +++ b/src/libcamera/include/meson.build\n> @@ -27,6 +27,7 @@ libcamera_headers = files([\n>      'utils.h',\n>      'v4l2_controls.h',\n>      'v4l2_device.h',\n> +    'v4l2_pixelformat.h',\n>      'v4l2_subdevice.h',\n>      'v4l2_videodevice.h',\n>  ])\n> diff --git a/src/libcamera/include/v4l2_pixelformat.h b/src/libcamera/include/v4l2_pixelformat.h\n> new file mode 100644\n> index 000000000000..4d277569cb8c\n> --- /dev/null\n> +++ b/src/libcamera/include/v4l2_pixelformat.h\n> @@ -0,0 +1,45 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2019, Google Inc.\n> + * Copyright (C) 2020, Raspberry Pi (Trading) Ltd.\n> + *\n> + * v4l2_pixelformat.h - V4L2 Pixel Format\n> + */\n> +#ifndef __LIBCAMERA_V4L2_PIXELFORMAT_H__\n> +#define __LIBCAMERA_V4L2_PIXELFORMAT_H__\n> +\n> +#include <stdint.h>\n> +#include <string>\n> +\n> +#include <linux/videodev2.h>\n> +\n> +#include <libcamera/pixelformats.h>\n> +\n> +namespace libcamera {\n> +\n> +class V4L2PixelFormat\n> +{\n> +public:\n> +\tV4L2PixelFormat()\n> +\t\t: fourcc_(0)\n> +\t{\n> +\t}\n> +\n> +\texplicit V4L2PixelFormat(uint32_t fourcc)\n> +\t\t: fourcc_(fourcc)\n> +\t{\n> +\t}\n> +\n> +\tbool isValid() const { return fourcc_ != 0; }\n> +\tuint32_t fourcc() const { return fourcc_; }\n> +\toperator uint32_t() const { return fourcc_; }\n> +\n> +\tstd::string toString() const;\n> +\n> +private:\n> +\tuint32_t fourcc_;\n> +};\n> +\n> +} /* namespace libcamera */\n> +\n> +#endif /* __LIBCAMERA_V4L2_PIXELFORMAT_H__ */\n> diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h\n> index 976ef9b6dc50..ff64bb357c7e 100644\n> --- a/src/libcamera/include/v4l2_videodevice.h\n> +++ b/src/libcamera/include/v4l2_videodevice.h\n> @@ -23,6 +23,7 @@\n>  #include \"formats.h\"\n>  #include \"log.h\"\n>  #include \"v4l2_device.h\"\n> +#include \"v4l2_pixelformat.h\"\n>  \n>  namespace libcamera {\n>  \n> @@ -149,29 +150,6 @@ private:\n>  \tunsigned int missCounter_;\n>  };\n>  \n> -class V4L2PixelFormat\n> -{\n> -public:\n> -\tV4L2PixelFormat()\n> -\t\t: fourcc_(0)\n> -\t{\n> -\t}\n> -\n> -\texplicit V4L2PixelFormat(uint32_t fourcc)\n> -\t\t: fourcc_(fourcc)\n> -\t{\n> -\t}\n> -\n> -\tbool isValid() const { return fourcc_ != 0; }\n> -\tuint32_t fourcc() const { return fourcc_; }\n> -\toperator uint32_t() const { return fourcc_; }\n> -\n> -\tstd::string toString() const;\n> -\n> -private:\n> -\tuint32_t fourcc_;\n> -};\n> -\n>  class V4L2DeviceFormat\n>  {\n>  public:\n> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\n> index 874d25904693..d8b4d7206aba 100644\n> --- a/src/libcamera/meson.build\n> +++ b/src/libcamera/meson.build\n> @@ -44,6 +44,7 @@ libcamera_sources = files([\n>      'utils.cpp',\n>      'v4l2_controls.cpp',\n>      'v4l2_device.cpp',\n> +    'v4l2_pixelformat.cpp',\n>      'v4l2_subdevice.cpp',\n>      'v4l2_videodevice.cpp',\n>  ])\n> diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp\n> new file mode 100644\n> index 000000000000..57d65c380b0d\n> --- /dev/null\n> +++ b/src/libcamera/v4l2_pixelformat.cpp\n> @@ -0,0 +1,106 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2019, Google Inc.\n> + * Copyright (C) 2020, Raspberry Pi (Trading) Ltd.\n> + *\n> + * v4l2_pixelformat.cpp - V4L2 Pixel Format\n> + */\n> +\n> +#include \"v4l2_pixelformat.h\"\n> +\n> +#include <ctype.h>\n> +#include <map>\n> +#include <string.h>\n> +\n> +#include <linux/drm_fourcc.h>\n> +\n> +#include <libcamera/pixelformats.h>\n> +\n> +#include \"log.h\"\n> +\n> +/**\n> + * \\file v4l2_pixelformat.h\n> + * \\brief V4L2 Pixel Format\n> + */\n> +namespace libcamera {\n> +\n> +LOG_DECLARE_CATEGORY(V4L2)\n> +\n> +/**\n> + * \\class V4L2PixelFormat\n> + * \\brief V4L2 pixel format FourCC wrapper\n> + *\n> + * The V4L2PixelFormat class describes the pixel format of a V4L2 buffer. It\n> + * wraps the V4L2 numerical FourCC, and shall be used in all APIs that deal with\n> + * V4L2 pixel formats. Its purpose is to prevent unintentional confusion of\n> + * V4L2 and DRM FourCCs in code by catching implicit conversion attempts at\n> + * compile time.\n> + *\n> + * To achieve this goal, construction of a V4L2PixelFormat from an integer value\n> + * is explicit. To retrieve the integer value of a V4L2PixelFormat, both the\n> + * explicit value() and implicit uint32_t conversion operators may be used.\n> + */\n> +\n> +/**\n> + * \\fn V4L2PixelFormat::V4L2PixelFormat()\n> + * \\brief Construct a V4L2PixelFormat with an invalid format\n> + *\n> + * V4L2PixelFormat instances constructed with the default constructor are\n> + * invalid, calling the isValid() function returns false.\n> + */\n> +\n> +/**\n> + * \\fn V4L2PixelFormat::V4L2PixelFormat(uint32_t fourcc)\n> + * \\brief Construct a V4L2PixelFormat from a FourCC value\n> + * \\param[in] fourcc The pixel format FourCC numerical value\n> + */\n> +\n> +/**\n> + * \\fn bool V4L2PixelFormat::isValid() const\n> + * \\brief Check if the pixel format is valid\n> + *\n> + * V4L2PixelFormat instances constructed with the default constructor are\n> + * invalid. Instances constructed with a FourCC defined in the V4L2 API are\n> + * valid. The behaviour is undefined otherwise.\n> + *\n> + * \\return True if the pixel format is valid, false otherwise\n> + */\n> +\n> +/**\n> + * \\fn uint32_t V4L2PixelFormat::fourcc() const\n> + * \\brief Retrieve the pixel format FourCC numerical value\n> + * \\return The pixel format FourCC numerical value\n> + */\n> +\n> +/**\n> + * \\fn V4L2PixelFormat::operator uint32_t() const\n> + * \\brief Convert to the pixel format FourCC numerical value\n> + * \\return The pixel format FourCC numerical value\n> + */\n> +\n> +/**\n> + * \\brief Assemble and return a string describing the pixel format\n> + * \\return A string describing the pixel format\n> + */\n> +std::string V4L2PixelFormat::toString() const\n> +{\n> +\tif (fourcc_ == 0)\n> +\t\treturn \"<INVALID>\";\n> +\n> +\tchar ss[8] = { static_cast<char>(fourcc_ & 0x7f),\n> +\t\t       static_cast<char>((fourcc_ >> 8) & 0x7f),\n> +\t\t       static_cast<char>((fourcc_ >> 16) & 0x7f),\n> +\t\t       static_cast<char>((fourcc_ >> 24) & 0x7f) };\n> +\n> +\tfor (unsigned int i = 0; i < 4; i++) {\n> +\t\tif (!isprint(ss[i]))\n> +\t\t\tss[i] = '.';\n> +\t}\n> +\n> +\tif (fourcc_ & (1 << 31))\n> +\t\tstrcat(ss, \"-BE\");\n> +\n> +\treturn ss;\n> +}\n> +\n> +} /* namespace libcamera */\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index e8d4f17dfdf1..21df4f524212 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -278,83 +278,6 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const\n>  \treturn true;\n>  }\n>  \n> -/**\n> - * \\class V4L2PixelFormat\n> - * \\brief V4L2 pixel format FourCC wrapper\n> - *\n> - * The V4L2PixelFormat class describes the pixel format of a V4L2 buffer. It\n> - * wraps the V4L2 numerical FourCC, and shall be used in all APIs that deal with\n> - * V4L2 pixel formats. Its purpose is to prevent unintentional confusion of\n> - * V4L2 and DRM FourCCs in code by catching implicit conversion attempts at\n> - * compile time.\n> - *\n> - * To achieve this goal, construction of a V4L2PixelFormat from an integer value\n> - * is explicit. To retrieve the integer value of a V4L2PixelFormat, both the\n> - * explicit value() and implicit uint32_t conversion operators may be used.\n> - */\n> -\n> -/**\n> - * \\fn V4L2PixelFormat::V4L2PixelFormat()\n> - * \\brief Construct a V4L2PixelFormat with an invalid format\n> - *\n> - * V4L2PixelFormat instances constructed with the default constructor are\n> - * invalid, calling the isValid() function returns false.\n> - */\n> -\n> -/**\n> - * \\fn V4L2PixelFormat::V4L2PixelFormat(uint32_t fourcc)\n> - * \\brief Construct a V4L2PixelFormat from a FourCC value\n> - * \\param[in] fourcc The pixel format FourCC numerical value\n> - */\n> -\n> -/**\n> - * \\fn bool V4L2PixelFormat::isValid() const\n> - * \\brief Check if the pixel format is valid\n> - *\n> - * V4L2PixelFormat instances constructed with the default constructor are\n> - * invalid. Instances constructed with a FourCC defined in the V4L2 API are\n> - * valid. The behaviour is undefined otherwise.\n> - *\n> - * \\return True if the pixel format is valid, false otherwise\n> - */\n> -\n> -/**\n> - * \\fn uint32_t V4L2PixelFormat::fourcc() const\n> - * \\brief Retrieve the pixel format FourCC numerical value\n> - * \\return The pixel format FourCC numerical value\n> - */\n> -\n> -/**\n> - * \\fn V4L2PixelFormat::operator uint32_t() const\n> - * \\brief Convert to the pixel format FourCC numerical value\n> - * \\return The pixel format FourCC numerical value\n> - */\n> -\n> -/**\n> - * \\brief Assemble and return a string describing the pixel format\n> - * \\return A string describing the pixel format\n> - */\n> -std::string V4L2PixelFormat::toString() const\n> -{\n> -\tif (fourcc_ == 0)\n> -\t\treturn \"<INVALID>\";\n> -\n> -\tchar ss[8] = { static_cast<char>(fourcc_ & 0x7f),\n> -\t\t       static_cast<char>((fourcc_ >> 8) & 0x7f),\n> -\t\t       static_cast<char>((fourcc_ >> 16) & 0x7f),\n> -\t\t       static_cast<char>((fourcc_ >> 24) & 0x7f) };\n> -\n> -\tfor (unsigned int i = 0; i < 4; i++) {\n> -\t\tif (!isprint(ss[i]))\n> -\t\t\tss[i] = '.';\n> -\t}\n> -\n> -\tif (fourcc_ & (1 << 31))\n> -\t\tstrcat(ss, \"-BE\");\n> -\n> -\treturn ss;\n> -}\n> -\n>  /**\n>   * \\class V4L2DeviceFormat\n>   * \\brief The V4L2 video device image format and sizes\n> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lf1-x143.google.com (mail-lf1-x143.google.com\n\t[IPv6:2a00:1450:4864:20::143])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 64A31603F3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Apr 2020 11:52:07 +0200 (CEST)","by mail-lf1-x143.google.com with SMTP id l11so691800lfc.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Apr 2020 02:52:07 -0700 (PDT)","from localhost (h-209-203.A463.priv.bahnhof.se. [155.4.209.203])\n\tby smtp.gmail.com with ESMTPSA id\n\tj13sm4488326lfb.19.2020.04.30.02.52.05\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 30 Apr 2020 02:52:05 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=ragnatech-se.20150623.gappssmtp.com\n\theader.i=@ragnatech-se.20150623.gappssmtp.com header.b=\"iRrX0lqr\"; \n\tdkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to;\n\tbh=jRYsRq9lf5Jg94aCrf2pVrpQCfMjEsl7CV1phuolwLA=;\n\tb=iRrX0lqrtSi1BMc2I3KIQqNEEKL426BgjrDLdBQoqq2IOviBL2yxAA5fTofOUv2t0u\n\tOsziKqCUROiGI7GOhQYmEdAuzxxKzseSzdOgtTS4ffyLwZQph2D5Rs48Fo3NuR58hfz1\n\txbIJ8GHyNujUkwZySaQEeYg8C28Ax74hiRNq8QCeYYzbCVftg8gCMYWtN85gWTMv64Z3\n\tV45by1K1tc/GFRgZvRJpWgAu2Ooxh/vMuQt7Tdd3U30q9d5vCD+6cgmPTcMKbU9pGLGp\n\t2UxVkIQe9vmEzMrze/kPtMLWpZvnZgL8+AcnFTvx6dbX7j/buud8O1V+99F3CwWTBx/t\n\t76vA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to;\n\tbh=jRYsRq9lf5Jg94aCrf2pVrpQCfMjEsl7CV1phuolwLA=;\n\tb=YuBzEADg+yzlzwO4kEr/jsWFQni2j1U56BG2OGbHgNxDLJYJPklZKc8nNH87NBEpyv\n\tHuwKgmnWPof3bRun3UkEOjnabOu18sPtuMH+lU7BQAxHwZxx/gg/PpjkCbgLXBgYu6sx\n\tkdmJSaF2F3eAQRCbKqtrQNazjK12ETL1FuQhSrLJKu5Qm1I3Q5pY1N2cQ3qNjOljz7wI\n\tRmCX3drSIinMztuSF8aaeOUlfxG1jFcqAXcuNNdLY9JZwWrux6yiQKqDcnFSV90FKyOx\n\tDfM8l/i39BOKyxffUQq2VTdDCiUlcpPl5n8wVYk/V31RYLqDGlm1CVBqNeeIS7xI6hQa\n\tk9Hw==","X-Gm-Message-State":"AGi0PuaCE/cZ0sSwTQgN6DdKAnEi6uZKqs6jHmww0lN60LGtWqWdcsXl\n\tV4q/H4qZJLpWroT3AyUh9u1FnA==","X-Google-Smtp-Source":"APiQypKrmsLjspyIfJ8GrKusS6zV8pyd281AAWqjSVxEbpd8xKwMZVPImp/hg8arGBn5tUQoF5OQmw==","X-Received":"by 2002:ac2:5e65:: with SMTP id a5mr1577344lfr.189.1588240326628;\n\tThu, 30 Apr 2020 02:52:06 -0700 (PDT)","Date":"Thu, 30 Apr 2020 11:52:05 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200430095205.GB2092124@oden.dyn.berto.se>","References":"<20200430030723.8908-1-laurent.pinchart@ideasonboard.com>\n\t<20200430030723.8908-2-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200430030723.8908-2-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2 1/6] libcamera: v4l2_pixelformat:\n\tMove V4L2PixelFormat to a new file","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>","X-List-Received-Date":"Thu, 30 Apr 2020 09:52:07 -0000"}}]