[libcamera-devel,v3,04/16] libcamera: geometry: SizeRange: Add contains()

Message ID 20190616133402.21934-5-niklas.soderlund@ragnatech.se
State Superseded
Headers show
Series
  • libcamera: Add support for format information and validation
Related show

Commit Message

Niklas Söderlund June 16, 2019, 1:33 p.m. UTC
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>
---
 include/libcamera/geometry.h |  2 ++
 src/libcamera/geometry.cpp   | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)

Comments

Laurent Pinchart June 18, 2019, 10:27 p.m. UTC | #1
Hi Niklas,

Thank you for the patch.

On Sun, Jun 16, 2019 at 03:33:50PM +0200, Niklas Söderlund wrote:
> 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.

Aren't step values guaranteed to be non-zero now ?

Apart from that,

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> ---
>  include/libcamera/geometry.h |  2 ++
>  src/libcamera/geometry.cpp   | 16 ++++++++++++++++
>  2 files changed, 18 insertions(+)
> 
> diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h
> index 03962d7d09fac2b0..52f4d010de76f840 100644
> --- a/include/libcamera/geometry.h
> +++ b/include/libcamera/geometry.h
> @@ -92,6 +92,8 @@ public:
>  	{
>  	}
>  
> +	bool contains(const Size &size) const;
> +
>  	std::string toString() const;
>  
>  	Size min;
> diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp
> index 895861eb0678181b..ef919cb6beb19864 100644
> --- a/src/libcamera/geometry.cpp
> +++ b/src/libcamera/geometry.cpp
> @@ -261,6 +261,22 @@ bool operator<(const Size &lhs, const Size &rhs)
>   * \brief The vertical step
>   */
>  
> +/**
> + * \brief Test if a size is contained in the range
> + * \param[in] size Size to check
> + * \returns True if \a size can be contained

"True if \a size is contained in the range"

> + */
> +bool SizeRange::contains(const Size &size) const
> +{
> +	if (size.width < min.width || size.width > max.width ||
> +	    size.height < min.height || size.height > max.height ||
> +	    (hStep && (size.width - min.width) % hStep) ||
> +	    (vStep && (size.height - min.height) % vStep))
> +		return false;
> +
> +	return true;
> +}
> +
>  /**
>   * \brief Assemble and return a string describing the size range
>   * \return A string describing the SizeRange
Laurent Pinchart June 18, 2019, 11:39 p.m. UTC | #2
Hi Niklas,

On Wed, Jun 19, 2019 at 01:27:09AM +0300, Laurent Pinchart wrote:
> On Sun, Jun 16, 2019 at 03:33:50PM +0200, Niklas Söderlund wrote:
> > 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.
> 
> Aren't step values guaranteed to be non-zero now ?

No they're not. Please disregard this comment.

> Apart from that,
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> > ---
> >  include/libcamera/geometry.h |  2 ++
> >  src/libcamera/geometry.cpp   | 16 ++++++++++++++++
> >  2 files changed, 18 insertions(+)
> > 
> > diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h
> > index 03962d7d09fac2b0..52f4d010de76f840 100644
> > --- a/include/libcamera/geometry.h
> > +++ b/include/libcamera/geometry.h
> > @@ -92,6 +92,8 @@ public:
> >  	{
> >  	}
> >  
> > +	bool contains(const Size &size) const;
> > +
> >  	std::string toString() const;
> >  
> >  	Size min;
> > diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp
> > index 895861eb0678181b..ef919cb6beb19864 100644
> > --- a/src/libcamera/geometry.cpp
> > +++ b/src/libcamera/geometry.cpp
> > @@ -261,6 +261,22 @@ bool operator<(const Size &lhs, const Size &rhs)
> >   * \brief The vertical step
> >   */
> >  
> > +/**
> > + * \brief Test if a size is contained in the range
> > + * \param[in] size Size to check
> > + * \returns True if \a size can be contained
> 
> "True if \a size is contained in the range"
> 
> > + */
> > +bool SizeRange::contains(const Size &size) const
> > +{
> > +	if (size.width < min.width || size.width > max.width ||
> > +	    size.height < min.height || size.height > max.height ||
> > +	    (hStep && (size.width - min.width) % hStep) ||
> > +	    (vStep && (size.height - min.height) % vStep))
> > +		return false;
> > +
> > +	return true;
> > +}
> > +
> >  /**
> >   * \brief Assemble and return a string describing the size range
> >   * \return A string describing the SizeRange

Patch

diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h
index 03962d7d09fac2b0..52f4d010de76f840 100644
--- a/include/libcamera/geometry.h
+++ b/include/libcamera/geometry.h
@@ -92,6 +92,8 @@  public:
 	{
 	}
 
+	bool contains(const Size &size) const;
+
 	std::string toString() const;
 
 	Size min;
diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp
index 895861eb0678181b..ef919cb6beb19864 100644
--- a/src/libcamera/geometry.cpp
+++ b/src/libcamera/geometry.cpp
@@ -261,6 +261,22 @@  bool operator<(const Size &lhs, const Size &rhs)
  * \brief The vertical step
  */
 
+/**
+ * \brief Test if a size is contained in the range
+ * \param[in] size Size to check
+ * \returns True if \a size can be contained
+ */
+bool SizeRange::contains(const Size &size) const
+{
+	if (size.width < min.width || size.width > max.width ||
+	    size.height < min.height || size.height > max.height ||
+	    (hStep && (size.width - min.width) % hStep) ||
+	    (vStep && (size.height - min.height) % vStep))
+		return false;
+
+	return true;
+}
+
 /**
  * \brief Assemble and return a string describing the size range
  * \return A string describing the SizeRange