summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-07-10 11:23:25 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-07-15 00:27:26 +0300
commit6c0afb8b33a1586b2e5bb5543edca5103769af0e (patch)
tree8da986dd0f86674627de431c0abd0636dcc1dade /include
parent74c8b508338ccdd0780aa1e067a1e8fcb9ee326b (diff)
libcamera: geometry: Add helper functions to the Size class
Pipeline handlers commonly have to calculate the minimum or maximum of multiple sizes, or align a size's width and height. Add helper functions to the Size class to perform those tasks. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'include')
-rw-r--r--include/libcamera/geometry.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h
index 7d4b8bcf..d217cfd5 100644
--- a/include/libcamera/geometry.h
+++ b/include/libcamera/geometry.h
@@ -8,6 +8,7 @@
#ifndef __LIBCAMERA_GEOMETRY_H__
#define __LIBCAMERA_GEOMETRY_H__
+#include <algorithm>
#include <string>
namespace libcamera {
@@ -43,6 +44,38 @@ struct Size {
bool isNull() const { return !width && !height; }
const std::string toString() const;
+
+ Size alignedDownTo(unsigned int hAlignment, unsigned int vAlignment) const
+ {
+ return {
+ width / hAlignment * hAlignment,
+ height / vAlignment * vAlignment
+ };
+ }
+
+ Size alignedUpTo(unsigned int hAlignment, unsigned int vAlignment) const
+ {
+ return {
+ (width + hAlignment - 1) / hAlignment * hAlignment,
+ (height + vAlignment - 1) / vAlignment * vAlignment
+ };
+ }
+
+ Size boundedTo(const Size &bound) const
+ {
+ return {
+ std::min(width, bound.width),
+ std::min(height, bound.height)
+ };
+ }
+
+ Size expandedTo(const Size &expand) const
+ {
+ return {
+ std::max(width, expand.width),
+ std::max(height, expand.height)
+ };
+ }
};
bool operator==(const Size &lhs, const Size &rhs);