[libcamera-devel] [PATCH 11/23] libcamera: controls: Add support for float controls

Niklas Söderlund niklas.soderlund at ragnatech.se
Wed Jan 15 00:25:10 CET 2020


Hi Jacopo,

Thanks for your patch.

On 2020-01-13 17:42:33 +0100, Jacopo Mondi wrote:
> Add support for float values in Control<> and ControlValue classes.
> 
> Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>

Reviewed-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>

> ---
>  include/libcamera/controls.h         |  3 +++
>  src/libcamera/control_serializer.cpp | 13 ++++++++++
>  src/libcamera/controls.cpp           | 36 ++++++++++++++++++++++++++++
>  3 files changed, 52 insertions(+)
> 
> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
> index 458b84e8fa8c..8fa33d93b088 100644
> --- a/include/libcamera/controls.h
> +++ b/include/libcamera/controls.h
> @@ -20,6 +20,7 @@ enum ControlType {
>  	ControlTypeBool,
>  	ControlTypeInteger32,
>  	ControlTypeInteger64,
> +	ControlTypeFloat,
>  };
>  
>  class ControlValue
> @@ -29,6 +30,7 @@ public:
>  	ControlValue(bool value);
>  	ControlValue(int32_t value);
>  	ControlValue(int64_t value);
> +	ControlValue(float value);
>  
>  	ControlType type() const { return type_; }
>  	bool isNone() const { return type_ == ControlTypeNone; }
> @@ -53,6 +55,7 @@ private:
>  		bool bool_;
>  		int32_t integer32_;
>  		int64_t integer64_;
> +		float float_;
>  	};
>  };
>  
> diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp
> index a5d6d875c76f..fd91baf15156 100644
> --- a/src/libcamera/control_serializer.cpp
> +++ b/src/libcamera/control_serializer.cpp
> @@ -34,6 +34,7 @@ static constexpr size_t ControlValueSize[] = {
>  	[ControlTypeBool]	= sizeof(bool),
>  	[ControlTypeInteger32]	= sizeof(int32_t),
>  	[ControlTypeInteger64]	= sizeof(int64_t),
> +	[ControlTypeFloat]	= sizeof(float),
>  };
>  
>  } /* namespace */
> @@ -176,6 +177,12 @@ void ControlSerializer::store(const ControlValue &value,
>  		break;
>  	}
>  
> +	case ControlTypeFloat: {
> +		float data = value.get<float>();
> +		buffer.write(&data);
> +		break;
> +	}
> +
>  	default:
>  		break;
>  	}
> @@ -348,6 +355,12 @@ ControlValue ControlSerializer::load<ControlValue>(ControlType type,
>  		return ControlValue(value);
>  	}
>  
> +	case ControlTypeFloat: {
> +		float value;
> +		b.read(&value);
> +		return ControlValue(value);
> +	}
> +
>  	default:
>  		return ControlValue();
>  	}
> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
> index 123a6f19974a..74ce5d0ba4f1 100644
> --- a/src/libcamera/controls.cpp
> +++ b/src/libcamera/controls.cpp
> @@ -58,6 +58,8 @@ LOG_DEFINE_CATEGORY(Controls)
>   * The control stores a 32-bit integer value
>   * \var ControlTypeInteger64
>   * The control stores a 64-bit integer value
> + * \var ControlTypeFloat
> + * The control stores a 32-bit floating point value
>   */
>  
>  /**
> @@ -100,6 +102,15 @@ ControlValue::ControlValue(int64_t value)
>  {
>  }
>  
> +/**
> + * \brief Construct a float ControlValue
> + * \param[in] value Float value to store
> + */
> +ControlValue::ControlValue(float value)
> +	: type_(ControlTypeFloat), float_(value)
> +{
> +}
> +
>  /**
>   * \fn ControlValue::type()
>   * \brief Retrieve the data type of the value
> @@ -153,6 +164,14 @@ const int64_t &ControlValue::get<int64_t>() const
>  	return integer64_;
>  }
>  
> +template<>
> +const float &ControlValue::get<float>() const
> +{
> +	ASSERT(type_ == ControlTypeFloat);
> +
> +	return float_;
> +}
> +
>  template<>
>  void ControlValue::set<bool>(const bool &value)
>  {
> @@ -173,6 +192,13 @@ void ControlValue::set<int64_t>(const int64_t &value)
>  	type_ = ControlTypeInteger64;
>  	integer64_ = value;
>  }
> +
> +template<>
> +void ControlValue::set<float>(const float &value)
> +{
> +	type_ = ControlTypeFloat;
> +	float_ = value;
> +}
>  #endif /* __DOXYGEN__ */
>  
>  /**
> @@ -190,6 +216,8 @@ std::string ControlValue::toString() const
>  		return std::to_string(integer32_);
>  	case ControlTypeInteger64:
>  		return std::to_string(integer64_);
> +	case ControlTypeFloat:
> +		return std::to_string(float_);
>  	}
>  
>  	return "<ValueType Error>";
> @@ -211,6 +239,8 @@ bool ControlValue::operator==(const ControlValue &other) const
>  		return integer32_ == other.integer32_;
>  	case ControlTypeInteger64:
>  		return integer64_ == other.integer64_;
> +	case ControlTypeFloat:
> +		return float_ == other.float_;
>  	default:
>  		return false;
>  	}
> @@ -341,6 +371,12 @@ Control<int64_t>::Control(unsigned int id, const char *name)
>  	: ControlId(id, name, ControlTypeInteger64)
>  {
>  }
> +
> +template<>
> +Control<float>::Control(unsigned int id, const char *name)
> +	: ControlId(id, name, ControlTypeFloat)
> +{
> +}
>  #endif /* __DOXYGEN__ */
>  
>  /**
> -- 
> 2.24.0
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel at lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

-- 
Regards,
Niklas Söderlund


More information about the libcamera-devel mailing list