From 6c0afb8b33a1586b2e5bb5543edca5103769af0e Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 10 Jul 2020 11:23:25 +0300 Subject: libcamera: geometry: Add helper functions to the Size class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Jacopo Mondi Reviewed-by: Kieran Bingham Reviewed-by: Niklas Söderlund --- include/libcamera/geometry.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'include') 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 #include 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); -- cgit v1.2.1