[libcamera-devel,v7,14/14] ipa: raspberrypi: agc: Use YamlObject::getList()
diff mbox series

Message ID 20220727023816.30008-15-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • Replace boost JSON parser with libyaml in Raspberry Pi IPA
Related show

Commit Message

Laurent Pinchart July 27, 2022, 2:38 a.m. UTC
Replace the manual implementation of the readList() functions with
YamlObject::getList().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/ipa/raspberrypi/controller/rpi/agc.cpp | 43 +++++++---------------
 1 file changed, 13 insertions(+), 30 deletions(-)

Comments

Naushir Patuck July 27, 2022, 12:40 p.m. UTC | #1
Hi Laurent,


On Wed, 27 Jul 2022 at 03:38, Laurent Pinchart <
laurent.pinchart@ideasonboard.com> wrote:

> Replace the manual implementation of the readList() functions with
> YamlObject::getList().
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>

This is a nice improvement!

Reviewed-by: Naushir Patuck <naush@raspberrypi.com>


> ---
>  src/ipa/raspberrypi/controller/rpi/agc.cpp | 43 +++++++---------------
>  1 file changed, 13 insertions(+), 30 deletions(-)
>
> diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp
> b/src/ipa/raspberrypi/controller/rpi/agc.cpp
> index 9fd339c6904e..b8eb5bc605a1 100644
> --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp
> +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp
> @@ -5,6 +5,7 @@
>   * agc.cpp - AGC/AEC control algorithm
>   */
>
> +#include <algorithm>
>  #include <map>
>  #include <tuple>
>
> @@ -71,44 +72,26 @@ readMeteringModes(std::map<std::string,
> AgcMeteringMode> &metering_modes,
>         return { 0, first };
>  }
>
> -static int readList(std::vector<double> &list,
> -                   const libcamera::YamlObject &params)
> -{
> -       for (const auto &p : params.asList()) {
> -               auto value = p.get<double>();
> -               if (!value)
> -                       return -EINVAL;
> -               list.push_back(*value);
> -       }
> -
> -       return list.size();
> -}
> -
> -static int readList(std::vector<Duration> &list,
> -                   const libcamera::YamlObject &params)
> -{
> -       for (const auto &p : params.asList()) {
> -               auto value = p.get<double>();
> -               if (!value)
> -                       return -EINVAL;
> -               list.push_back(*value * 1us);
> -       }
> -
> -       return list.size();
> -}
> -
>  int AgcExposureMode::read(const libcamera::YamlObject &params)
>  {
> -       int numShutters = readList(shutter, params["shutter"]);
> -       int numAgs = readList(gain, params["gain"]);
> +       auto value = params["shutter"].getList<double>();
> +       if (!value)
> +               return -EINVAL;
> +       std::transform(value->begin(), value->end(),
> std::back_inserter(shutter),
> +                      [](double v) { return v * 1us; });
>
> -       if (numShutters < 2 || numAgs < 2) {
> +       value = params["gain"].getList<double>();
> +       if (!value)
> +               return -EINVAL;
> +       gain = std::move(*value);
> +
> +       if (shutter.size() < 2 || gain.size() < 2) {
>                 LOG(RPiAgc, Error)
>                         << "AgcExposureMode: must have at least two
> entries in exposure profile";
>                 return -EINVAL;
>         }
>
> -       if (numShutters != numAgs) {
> +       if (shutter.size() != gain.size()) {
>                 LOG(RPiAgc, Error)
>                         << "AgcExposureMode: expect same number of
> exposure and gain entries in exposure profile";
>                 return -EINVAL;
> --
> Regards,
>
> Laurent Pinchart
>
>

Patch
diff mbox series

diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp
index 9fd339c6904e..b8eb5bc605a1 100644
--- a/src/ipa/raspberrypi/controller/rpi/agc.cpp
+++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp
@@ -5,6 +5,7 @@ 
  * agc.cpp - AGC/AEC control algorithm
  */
 
+#include <algorithm>
 #include <map>
 #include <tuple>
 
@@ -71,44 +72,26 @@  readMeteringModes(std::map<std::string, AgcMeteringMode> &metering_modes,
 	return { 0, first };
 }
 
-static int readList(std::vector<double> &list,
-		    const libcamera::YamlObject &params)
-{
-	for (const auto &p : params.asList()) {
-		auto value = p.get<double>();
-		if (!value)
-			return -EINVAL;
-		list.push_back(*value);
-	}
-
-	return list.size();
-}
-
-static int readList(std::vector<Duration> &list,
-		    const libcamera::YamlObject &params)
-{
-	for (const auto &p : params.asList()) {
-		auto value = p.get<double>();
-		if (!value)
-			return -EINVAL;
-		list.push_back(*value * 1us);
-	}
-
-	return list.size();
-}
-
 int AgcExposureMode::read(const libcamera::YamlObject &params)
 {
-	int numShutters = readList(shutter, params["shutter"]);
-	int numAgs = readList(gain, params["gain"]);
+	auto value = params["shutter"].getList<double>();
+	if (!value)
+		return -EINVAL;
+	std::transform(value->begin(), value->end(), std::back_inserter(shutter),
+		       [](double v) { return v * 1us; });
 
-	if (numShutters < 2 || numAgs < 2) {
+	value = params["gain"].getList<double>();
+	if (!value)
+		return -EINVAL;
+	gain = std::move(*value);
+
+	if (shutter.size() < 2 || gain.size() < 2) {
 		LOG(RPiAgc, Error)
 			<< "AgcExposureMode: must have at least two entries in exposure profile";
 		return -EINVAL;
 	}
 
-	if (numShutters != numAgs) {
+	if (shutter.size() != gain.size()) {
 		LOG(RPiAgc, Error)
 			<< "AgcExposureMode: expect same number of exposure and gain entries in exposure profile";
 		return -EINVAL;