From 68de1189df409539c432f4f5731e974af8a068f8 Mon Sep 17 00:00:00 2001 From: Patrick Gehrsitz Date: Sun, 8 Jun 2025 17:34:29 +0200 Subject: [PATCH] libcamera: fix compilation errors for libcamera v0.3.2+rpt20241119 (#168) * libcamera: add support for ControlTypePoint Signed-off-by: Patrick Gehrsitz * libcamera: fix compile error on missing ControlType This adds a runtime error for missing ControlTypes to fix compilation errors if there are new ControlTypes that are not implemented yet. Signed-off-by: Patrick Gehrsitz * chore: remove whitespaces Signed-off-by: Patrick Gehrsitz * libcamera: only use ControlTypePoint for libcamera>=0.3.2 Signed-off-by: Patrick Gehrsitz * fix: add version check to second switch case Signed-off-by: Patrick Gehrsitz * fix: add version check to libcamera_parse_point Signed-off-by: Patrick Gehrsitz --------- Signed-off-by: Patrick Gehrsitz --- device/libcamera/options.cc | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/device/libcamera/options.cc b/device/libcamera/options.cc index 33ed83d..7420c61 100644 --- a/device/libcamera/options.cc +++ b/device/libcamera/options.cc @@ -217,6 +217,16 @@ static int libcamera_device_dump_control_option(device_option_fn fn, void *opaqu case libcamera::ControlTypeString: opt.type = device_option_type_string; break; + +#if LIBCAMERA_VERSION_MAJOR == 0 && LIBCAMERA_VERSION_MINOR > 3 && LIBCAMERA_VERSION_PATCH >= 2 // Support for older libcamera versions + case libcamera::ControlTypePoint: + opt.type = device_option_type_float; + opt.elems = 2; + break; +#endif + + default: + throw std::runtime_error("ControlType unsupported or not implemented"); } auto named_values = libcamera_find_control_ids(control_id.id()); @@ -349,6 +359,29 @@ static libcamera::Size libcamera_parse_size(const char *value) return libcamera::Size(); } +#if LIBCAMERA_VERSION_MAJOR == 0 && LIBCAMERA_VERSION_MINOR > 3 && LIBCAMERA_VERSION_PATCH >= 2 // Support for older libcamera versions +static libcamera::Point libcamera_parse_point(const char *value) +{ + static const char *POINT_PATTERNS[] = + { + "(%d,%d)", + "%d,%d", + NULL + }; + + for (int i = 0; POINT_PATTERNS[i]; i++) { + libcamera::Point point; + + if (2 == sscanf(value, POINT_PATTERNS[i], + &point.x, &point.y)) { + return point; + } + } + + return libcamera::Point(); +} +#endif + template static bool libcamera_parse_control_value(libcamera::ControlValue &control_value, const char *value, const F &fn) { @@ -436,6 +469,16 @@ int libcamera_device_set_option(device_t *dev, const char *keyp, const char *val case libcamera::ControlTypeString: break; + +#if LIBCAMERA_VERSION_MAJOR == 0 && LIBCAMERA_VERSION_MINOR > 3 && LIBCAMERA_VERSION_PATCH >= 2 // Support for older libcamera versions + case libcamera::ControlTypePoint: + libcamera_parse_control_value( + control_value, value, libcamera_parse_point); + break; +#endif + + default: + throw std::runtime_error("ControlType unsupported or not implemented"); } if (control_value.isNone()) {