@@ -200,6 +200,16 @@ details::StringSplitter split(const std::string &str, const std::string &delim);
std::string libcameraBuildPath();
std::string libcameraSourcePath();
+constexpr unsigned int alignDown(unsigned int value, unsigned int alignment)
+{
+ return value / alignment * alignment;
+}
+
+constexpr unsigned int alignUp(unsigned int value, unsigned int alignment)
+{
+ return (value + alignment - 1) / alignment * alignment;
+}
+
} /* namespace utils */
} /* namespace libcamera */
@@ -444,6 +444,22 @@ std::string libcameraSourcePath()
return path + "/";
}
+/**
+ * \fn alignDown(unsigned int value, unsigned int alignment)
+ * \brief Align \a value down to \a alignment
+ * \param[in] value The value to align
+ * \param[in] alignment The alignment
+ * \return The value rounded down to the nearest multiple of \a alignment
+ */
+
+/**
+ * \fn alignUp(unsigned int value, unsigned int alignment)
+ * \brief Align \a value up to \a alignment
+ * \param[in] value The value to align
+ * \param[in] alignment The alignment
+ * \return The value rounded up to the nearest multiple of \a alignment
+ */
+
} /* namespace utils */
} /* namespace libcamera */
@@ -166,6 +166,17 @@ protected:
return TestFail;
}
+ /* utils::alignUp() and utils::alignDown() tests. */
+ if (utils::alignDown(6, 3) != 6 || utils::alignDown(7, 3) != 6) {
+ cerr << "utils::alignDown test failed" << endl;
+ return TestFail;
+ }
+
+ if (utils::alignUp(6, 3) != 6 || utils::alignUp(7, 3) != 9) {
+ cerr << "utils::alignUp test failed" << endl;
+ return TestFail;
+ }
+
return TestPass;
}
};