summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2020-07-13 15:05:23 +0200
committerJacopo Mondi <jacopo@jmondi.org>2020-08-03 11:16:16 +0200
commitd405d1fd5e791b3ebc45dc980be2fce9ac0f3529 (patch)
tree3bc5e3d5849c1f8dba012b7ced7bf3570e26a41a /include
parent4383252d9315b3a282d220f30ac1a5594cd66d7c (diff)
libcamera: utils: Add alignUp and alignDown functions
Add to libcamera utils library two functions to round up or down a value to an alignment and add a test in test/utils.cpp for the two new functions. Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'include')
-rw-r--r--include/libcamera/internal/utils.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/include/libcamera/internal/utils.h b/include/libcamera/internal/utils.h
index 8d026cc6..45cd6f12 100644
--- a/include/libcamera/internal/utils.h
+++ b/include/libcamera/internal/utils.h
@@ -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 */