summaryrefslogtreecommitdiff
path: root/src/libcamera
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-03-15 18:22:46 +0100
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-03-18 18:02:40 +0100
commit8c0bbcd3d3751a716eb8bf03e703aa6fdbe1bd3f (patch)
tree579d0822f08b07770329800b07a219aad6723803 /src/libcamera
parent4bc262ecaa736b956cf8878d8f3459c9caf7c37e (diff)
libcamera: PixelFormat: Turn into a class
Create a class to represent a pixel format. This is done to add support for modifiers for the formats. So far no modifiers are added by any pipeline handler, all plumbing to deal with them is however in place. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/libcamera')
-rw-r--r--src/libcamera/pipeline/uvcvideo.cpp5
-rw-r--r--src/libcamera/pipeline/vimc.cpp2
-rw-r--r--src/libcamera/pixelformats.cpp96
-rw-r--r--src/libcamera/stream.cpp4
-rw-r--r--src/libcamera/v4l2_videodevice.cpp3
5 files changed, 98 insertions, 12 deletions
diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp
index 5ff29240..9876d8c9 100644
--- a/src/libcamera/pipeline/uvcvideo.cpp
+++ b/src/libcamera/pipeline/uvcvideo.cpp
@@ -115,8 +115,9 @@ CameraConfiguration::Status UVCCameraConfiguration::validate()
if (iter == pixelFormats.end()) {
cfg.pixelFormat = pixelFormats.front();
LOG(UVC, Debug)
- << "Adjusting pixel format from " << pixelFormat
- << " to " << cfg.pixelFormat;
+ << "Adjusting pixel format from "
+ << pixelFormat.toString() << " to "
+ << cfg.pixelFormat.toString();
status = Adjusted;
}
diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp
index 82649952..00cb7389 100644
--- a/src/libcamera/pipeline/vimc.cpp
+++ b/src/libcamera/pipeline/vimc.cpp
@@ -105,7 +105,7 @@ private:
namespace {
-constexpr std::array<PixelFormat, 3> pixelformats{
+static const std::array<PixelFormat, 3> pixelformats{
DRM_FORMAT_RGB888,
DRM_FORMAT_BGR888,
DRM_FORMAT_BGRA8888,
diff --git a/src/libcamera/pixelformats.cpp b/src/libcamera/pixelformats.cpp
index c0333540..87557d98 100644
--- a/src/libcamera/pixelformats.cpp
+++ b/src/libcamera/pixelformats.cpp
@@ -15,14 +15,102 @@
namespace libcamera {
/**
- * \typedef PixelFormat
+ * \class PixelFormat
* \brief libcamera image pixel format
*
* The PixelFormat type describes the format of images in the public libcamera
- * API. It stores a FourCC value as a 32-bit unsigned integer. The values are
- * defined in the Linux kernel DRM/KMS API (see linux/drm_fourcc.h).
+ * API. It stores a FourCC value as a 32-bit unsigned integer and a set of
+ * modifiers. The FourCC and modifiers values are defined in the Linux kernel
+ * DRM/KMS API (see linux/drm_fourcc.h).
+ */
+
+/**
+ * \brief Construct a PixelFormat with an invalid format
+ *
+ * PixelFormat instances constructed with the default constructor are
+ * invalid, calling the isValid() function returns false.
+ */
+PixelFormat::PixelFormat()
+ : fourcc_(0)
+{
+}
+
+/**
+ * \brief Construct a PixelFormat from a DRM FourCC and a set of modifiers
+ * \param[in] fourcc A DRM FourCC
+ * \param[in] modifiers A set of DRM FourCC modifiers
+ */
+PixelFormat::PixelFormat(uint32_t fourcc, const std::set<uint64_t> &modifiers)
+ : fourcc_(fourcc), modifiers_(modifiers)
+{
+}
+
+/**
+ * \brief Compare pixel formats for equality
+ * \return True if the two pixel formats are equal, false otherwise
+ */
+bool PixelFormat::operator==(const PixelFormat &other) const
+{
+ return fourcc_ == other.fourcc() && modifiers_ == other.modifiers_;
+}
+
+/**
+ * \fn bool PixelFormat::operator!=(const PixelFormat &other) const
+ * \brief Compare pixel formats for inequality
+ * \return True if the two pixel formats are not equal, false otherwise
+ */
+
+/**
+ * \brief Compare pixel formats for smaller than order
+ * \return True if \a this is smaller than \a other, false otherwise
+ */
+bool PixelFormat::operator<(const PixelFormat &other) const
+{
+ if (fourcc_ < other.fourcc_)
+ return true;
+ if (fourcc_ > other.fourcc_)
+ return false;
+ return modifiers_ < modifiers_;
+}
+
+/**
+ * \fn bool PixelFormat::isValid() const
+ * \brief Check if the pixel format is valid
+ *
+ * PixelFormat instances constructed with the default constructor are
+ * invalid. Instances constructed with a FourCC defined in the DRM API
+ * are valid. The behaviour is undefined otherwise.
*
- * \todo Add support for format modifiers
+ * \return True if the pixel format is valid, false otherwise
+ */
+
+/**
+ * \fn PixelFormat::operator uint32_t() const
+ * \brief Convert the the pixel format numerical value
+ * \return The pixel format numerical value
+ */
+
+/**
+ * \fn PixelFormat::fourcc() const
+ * \brief Retrieve the pixel format FourCC
+ * \return DRM FourCC
+ */
+
+/**
+ * \fn PixelFormat::modifiers() const
+ * \brief Retrieve the pixel format modifiers
+ * \return Set of DRM modifiers
+ */
+
+/**
+ * \brief Assemble and return a string describing the pixel format
+ * \return A string describing the pixel format
*/
+std::string PixelFormat::toString() const
+{
+ char str[11];
+ snprintf(str, 11, "0x%08x", fourcc_);
+ return str;
+}
} /* namespace libcamera */
diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp
index 13789e9e..0716de38 100644
--- a/src/libcamera/stream.cpp
+++ b/src/libcamera/stream.cpp
@@ -347,9 +347,7 @@ StreamConfiguration::StreamConfiguration(const StreamFormats &formats)
*/
std::string StreamConfiguration::toString() const
{
- std::stringstream ss;
- ss << size.toString() << "-" << utils::hex(pixelFormat);
- return ss.str();
+ return size.toString() + "-" + pixelFormat.toString();
}
/**
diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index ca0d147f..ce67e04c 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -1551,8 +1551,7 @@ uint32_t V4L2VideoDevice::toV4L2Fourcc(PixelFormat pixelFormat, bool multiplanar
* class. Until we fix the logger, work around it.
*/
libcamera::_log(__FILE__, __LINE__, _LOG_CATEGORY(V4L2)(), LogError).stream()
- << "Unsupported V4L2 pixel format "
- << utils::hex(pixelFormat);
+ << "Unsupported V4L2 pixel format " << pixelFormat.toString();
return 0;
}