diff options
author | David Plowman <david.plowman@raspberrypi.com> | 2020-10-26 17:19:06 +0000 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-10-27 00:51:59 +0200 |
commit | 63624bc85a5f765dc3899d4b3b72ad875894ca04 (patch) | |
tree | 49d56f3e509bd5608fcc3ae3c7b7c4e8fa3d197e /include | |
parent | a16edeb3848c6e6693bfaa24c5eb1744c5d9c445 (diff) |
libcamera: Add geometry helper functions
These functions are aimed at making it easier to calculate cropping
rectangles, particularly in order to implement digital zoom.
Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/libcamera/geometry.h | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h index 02fb63c0..2f3a82e2 100644 --- a/include/libcamera/geometry.h +++ b/include/libcamera/geometry.h @@ -13,6 +13,38 @@ namespace libcamera { +class Rectangle; + +class Point +{ +public: + constexpr Point() + : x(0), y(0) + { + } + + constexpr Point(int xpos, int ypos) + : x(xpos), y(ypos) + { + } + + int x; + int y; + + const std::string toString() const; + + constexpr Point operator-() const + { + return { -x, -y }; + } +}; + +bool operator==(const Point &lhs, const Point &rhs); +static inline bool operator!=(const Point &lhs, const Point &rhs) +{ + return !(lhs == rhs); +} + class Size { public: @@ -93,6 +125,17 @@ public: std::max(height, expand.height) }; } + + Size boundedToAspectRatio(const Size &ratio) const; + Size expandedToAspectRatio(const Size &ratio) const; + + Rectangle centeredTo(const Point ¢er) const; + + Size operator*(float factor) const; + Size operator/(float factor) const; + + Size &operator*=(float factor); + Size &operator/=(float factor); }; bool operator==(const Size &lhs, const Size &rhs); @@ -176,6 +219,11 @@ public: { } + constexpr explicit Rectangle(const Size &size) + : x(0), y(0), width(size.width), height(size.height) + { + } + int x; int y; unsigned int width; @@ -183,6 +231,26 @@ public: bool isNull() const { return !width && !height; } const std::string toString() const; + + Point center() const; + + Size size() const + { + return { width, height }; + } + + Point topLeft() const + { + return { x, y }; + } + + Rectangle &scaleBy(const Size &numerator, const Size &denominator); + Rectangle &translateBy(const Point &point); + + Rectangle boundedTo(const Rectangle &bound) const; + Rectangle enclosedIn(const Rectangle &boundary) const; + Rectangle scaledBy(const Size &numerator, const Size &denominator) const; + Rectangle translatedBy(const Point &point) const; }; bool operator==(const Rectangle &lhs, const Rectangle &rhs); |