[libcamera-devel] [PATCH] libcamera: ColorSpace: Helper to check for standard colorspaces
Umang Jain
umang.jain at ideasonboard.com
Tue Jul 12 07:56:09 CEST 2022
Provide a convenience helper to check is the given colorspace
belongs to a set of standard colorspace or not.
Signed-off-by: Umang Jain <umang.jain at ideasonboard.com>
---
include/libcamera/color_space.h | 1 +
src/libcamera/color_space.cpp | 31 +++++++++++++++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/include/libcamera/color_space.h b/include/libcamera/color_space.h
index 086c56c1..43786d2a 100644
--- a/include/libcamera/color_space.h
+++ b/include/libcamera/color_space.h
@@ -59,6 +59,7 @@ public:
std::string toString() const;
static std::string toString(const std::optional<ColorSpace> &colorSpace);
+ bool isStandardColorSpace();
};
bool operator==(const ColorSpace &lhs, const ColorSpace &rhs);
diff --git a/src/libcamera/color_space.cpp b/src/libcamera/color_space.cpp
index 895e5c8e..004346f5 100644
--- a/src/libcamera/color_space.cpp
+++ b/src/libcamera/color_space.cpp
@@ -212,6 +212,37 @@ std::string ColorSpace::toString(const std::optional<ColorSpace> &colorSpace)
return colorSpace->toString();
}
+/**
+ * brief Checks whether the colorspace is a standard colorspace or not
+ *
+ * This is convenience helper to check whether the given colorspace is
+ * a standard colorspace or not.
+ *
+ * \return True if it is a standard colorspace, false otherwise
+ */
+bool ColorSpace::isStandardColorSpace()
+{
+ bool isStdColorSpace = false;
+
+ static const std::vector<ColorSpace> stdColorSpaces = {
+ ColorSpace::Raw,
+ ColorSpace::Jpeg,
+ ColorSpace::Srgb,
+ ColorSpace::Smpte170m,
+ ColorSpace::Rec709,
+ ColorSpace::Rec2020
+ };
+
+ auto it = std::find_if(stdColorSpaces.begin(), stdColorSpaces.end(),
+ [this](const auto &item) {
+ return *this == item;
+ });
+ if (it != stdColorSpaces.end())
+ isStdColorSpace = true;
+
+ return isStdColorSpace;
+}
+
/**
* \var ColorSpace::primaries
* \brief The color primaries of this color space
--
2.31.1
More information about the libcamera-devel
mailing list