[libcamera-devel,v5,04/19] libcamera: geometry: Add toString to Rectangle

Message ID 20190326083902.26121-5-jacopo@jmondi.org
State Superseded
Headers show
Series
  • libcamera: ipu3: Add ImgU support
Related show

Commit Message

Jacopo Mondi March 26, 2019, 8:38 a.m. UTC
Add toString() helpers to pretty print out the sizes of a Rectangle.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/libcamera/geometry.cpp       | 16 ++++++++++++++++
 src/libcamera/include/geometry.h |  4 ++++
 2 files changed, 20 insertions(+)

Comments

Laurent Pinchart April 1, 2019, 9:57 p.m. UTC | #1
Hi Jacopo,

Thank you for the patch.

On Tue, Mar 26, 2019 at 09:38:47AM +0100, Jacopo Mondi wrote:
> Add toString() helpers to pretty print out the sizes of a Rectangle.
> 
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>

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

> ---
>  src/libcamera/geometry.cpp       | 16 ++++++++++++++++
>  src/libcamera/include/geometry.h |  4 ++++
>  2 files changed, 20 insertions(+)
> 
> diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp
> index dbc37ca8e3f4..f76001d94562 100644
> --- a/src/libcamera/geometry.cpp
> +++ b/src/libcamera/geometry.cpp
> @@ -5,6 +5,8 @@
>   * geometry.cpp - Geometry-related structures
>   */
>  
> +#include <sstream>
> +
>  #include "geometry.h"
>  
>  /**
> @@ -46,6 +48,20 @@ namespace libcamera {
>   * \brief The distance between the top and bottom sides
>   */
>  
> +/**
> + * \brief Assemble and return a string describing the rectangle
> + *
> + * \return A string describing the Rectangle
> + */
> +const std::string Rectangle::toString() const
> +{
> +	std::stringstream ss;
> +
> +	ss << "(" << x << "x" << y << ")/" << w << "x" << h;
> +
> +	return ss.str();
> +}
> +
>  /**
>   * \struct SizeRange
>   * \brief Describe a range of image sizes
> diff --git a/src/libcamera/include/geometry.h b/src/libcamera/include/geometry.h
> index 749746495204..567a54299b24 100644
> --- a/src/libcamera/include/geometry.h
> +++ b/src/libcamera/include/geometry.h
> @@ -8,6 +8,8 @@
>  #ifndef __LIBCAMERA_GEOMETRY_H__
>  #define __LIBCAMERA_GEOMETRY_H__
>  
> +#include <string>
> +
>  namespace libcamera {
>  
>  struct Rectangle {
> @@ -15,6 +17,8 @@ struct Rectangle {
>  	int y;
>  	unsigned int w;
>  	unsigned int h;
> +
> +	const std::string toString() const;
>  };
>  
>  struct SizeRange {

Patch

diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp
index dbc37ca8e3f4..f76001d94562 100644
--- a/src/libcamera/geometry.cpp
+++ b/src/libcamera/geometry.cpp
@@ -5,6 +5,8 @@ 
  * geometry.cpp - Geometry-related structures
  */
 
+#include <sstream>
+
 #include "geometry.h"
 
 /**
@@ -46,6 +48,20 @@  namespace libcamera {
  * \brief The distance between the top and bottom sides
  */
 
+/**
+ * \brief Assemble and return a string describing the rectangle
+ *
+ * \return A string describing the Rectangle
+ */
+const std::string Rectangle::toString() const
+{
+	std::stringstream ss;
+
+	ss << "(" << x << "x" << y << ")/" << w << "x" << h;
+
+	return ss.str();
+}
+
 /**
  * \struct SizeRange
  * \brief Describe a range of image sizes
diff --git a/src/libcamera/include/geometry.h b/src/libcamera/include/geometry.h
index 749746495204..567a54299b24 100644
--- a/src/libcamera/include/geometry.h
+++ b/src/libcamera/include/geometry.h
@@ -8,6 +8,8 @@ 
 #ifndef __LIBCAMERA_GEOMETRY_H__
 #define __LIBCAMERA_GEOMETRY_H__
 
+#include <string>
+
 namespace libcamera {
 
 struct Rectangle {
@@ -15,6 +17,8 @@  struct Rectangle {
 	int y;
 	unsigned int w;
 	unsigned int h;
+
+	const std::string toString() const;
 };
 
 struct SizeRange {