summaryrefslogtreecommitdiff
path: root/include/libcamera/geometry.h
AgeCommit message (Collapse)Author
2021-02-04libcamera: geometry: Mark const functions with __nodiscardLaurent Pinchart
Geometry classes generally have two sets of functions, one that operates on the object and modifies it (e.g. Rectangle::scaleBy()), and one that performs the same operations by instead return a modified copy of the object, leaving the original untouched (e.g.Rectangle::scaledBy()). As the names are close, they can easily be mistaken, with the const version used instead of the in-place version. To catch these errors at compile time, mark the const versions with __nodiscard, as there is no use case for calling them without using the result of the call. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-10-27libcamera: Add geometry helper functionsDavid Plowman
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>
2020-08-03libcamera: geometry: Add isNull() function to Rectangle classJacopo Mondi
It's common for code to check if a rectangle is null. Add a helper function to do so and test the function in test/geometry.cpp Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-07-15libcamera: geometry: Provide in-place versions of the Size helpersLaurent Pinchart
Add alignDownTo(), alignUpTo(), boundTo() and expandTo() helper functions to the Size class. These are in-place versions of the existing alignedDownTo(), alignedUpTo(), boundedTo() and expandedTo() functions. The new helpers return a reference to the size, to allow chaining the functions. One can thus write size.alignDownTo(16, 16).alignUpTo(32, 32) .boundTo({ 40, 80 }).expandTo({ 16, 80 }); instead of size.alignDownTo(16, 16); size.alignUpTo(32, 32); size.boundTo({ 40, 80 }); size.expandTo({ 16, 80 }); Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-07-15libcamera: geometry: Make Size and Rectangle usable as constexprLaurent Pinchart
There are use cases for declaring constexpr Size and Rectangle instances. Make it possible. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-07-15libcamera: geometry: Turn Size and Rectangle into classesLaurent Pinchart
SizeRange is defined as a class while Size and Rectangle are defined as struct. This is confusing for users in forward declarations. Simplify it by turning both structures into classes. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-07-15libcamera: geometry: Give constructors to RectangleLaurent Pinchart
Rectangle, unlike Size, has no constructor, requiring the users to explicitly initialize the instances. This is error-prone, add constructors. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-07-15libcamera: geometry: Define Rectangle after SizeLaurent Pinchart
A subsequent change to the Rectangle will require the definition of the Size to be available. Define Rectangle after Size to ease review of that change. No code change is included. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-07-15libcamera: geometry: Add helper functions to the Size classLaurent Pinchart
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>
2020-06-29libcamera: geometry: Add isNull() function to Size classLaurent Pinchart
It's common for code to check if a size is null. Add a helper function to do so. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Umang Jain <email@uajain.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-05-22libcamera: geometry: Set steps to 0 in default SizeRange constructorLaurent Pinchart
The default SizeRange constructor initializes the min and max members, but leaves the hStep and vStep members uninitialized. Fix it. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Umang Jain <email@uajain.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-04-26libcamera: geometry: Rename Rectangle fieldsJacopo Mondi
The Rectangle class members that represents the rectangle horizontal and vertical sizes are named 'w' and 'h', in contrast with the Size and SizeRange classes which use 'width' and 'height', resulting in having to look at class definition every time to know which names to use. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-03-19libcamera: geometry: Construct SizeRange from SizeLaurent Pinchart
The SizeRange constructors take minimum and maximum width and height values as separate arguments. We have a Size class to convey size information, use it in the constructors, and update the callers. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-06-19libcamera: geometry: SizeRange: Add contains()Niklas Söderlund
Add a method to check if a Size can fit inside a SizeRange. When determining if a size is containable take step values into account if they are not set to 0. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-06-19libcamera: geometry: SizeRange: Add toString()Niklas Söderlund
It's useful to be able to print a string representation of a SizeRange to the log or console, add a toString() method. While at it turn the structure into a class as it contains functions as well as data. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-06-19libcamera: geometry: SizeRange: Extend with step informationNiklas Söderlund
The size range described might be subject to certain step limitations. Make it possible to record this information. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-06-19libcamera: geometry: SizeRange: Add constructor for a single sizeNiklas Söderlund
The SizeRange can describe a single size where min == max. Add a constructor to help create such a description. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-04-30libcamera: Use the Size class through libcameraLaurent Pinchart
Several of our structures include width and height fields that model a size while we have a Size class for that purpose. Use the Size class through libcamera, and give it a toString() method like other geometry and format classes. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-04-18libcamera: geometry: Add comparison operators to geometry classesLaurent Pinchart
Add equality and inequality comparison operators for the Rectangle, Size and SizeRange classes. For the Size class, also add ordering operators. Sizes are first compared on combined width and height, then on area, and finally on width only to achieve a stable ordering. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-04-18libcamera: geometry: Use Size to store min and max in SizeRangeLaurent Pinchart
Instead of storing four integers for the minimum and maximum width and height in the SizeRange class, use two instance of the Size class for the minimum and maximum sizes. While it at replace the mention of image size with size in the SizeRange documentation, as the Size class isn't limited to image sizes. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-04-18libcamera: geometry: Sort classes alphabeticallyLaurent Pinchart
Move the Size class before the SizeRange class. No functional change. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-04-05libcamera: Make geometry.h a public headerNiklas Söderlund
Make the geometry header public so it can be used by the API facing applications. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>