forked from lit-robotics/libcamera-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrols.cpp
123 lines (98 loc) · 3.84 KB
/
controls.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "controls.h"
#include <libcamera/libcamera.h>
#include <string.h>
extern "C" {
const char *libcamera_control_name(enum libcamera_control_id id) {
auto it = libcamera::controls::controls.find(id);
if (it != libcamera::controls::controls.end())
return it->second->name().c_str();
else
return nullptr;
}
enum libcamera_control_type libcamera_control_type(enum libcamera_control_id id) {
auto it = libcamera::controls::controls.find(id);
if (it != libcamera::controls::controls.end())
return (enum libcamera_control_type)it->second->type();
else
return LIBCAMERA_CONTROL_TYPE_NONE;
}
const char *libcamera_property_name(enum libcamera_property_id id) {
auto it = libcamera::properties::properties.find(id);
if (it != libcamera::properties::properties.end())
return it->second->name().c_str();
else
return nullptr;
}
enum libcamera_control_type libcamera_property_type(enum libcamera_property_id id) {
auto it = libcamera::properties::properties.find(id);
if (it != libcamera::properties::properties.end())
return (enum libcamera_control_type)it->second->type();
else
return LIBCAMERA_CONTROL_TYPE_NONE;
}
libcamera_control_list_t *libcamera_control_list_create() {
return new libcamera::ControlList();
}
void libcamera_control_list_destroy(libcamera_control_list_t *list) {
delete list;
}
const libcamera_control_value_t *libcamera_control_list_get(libcamera_control_list_t *list, enum libcamera_property_id id) {
if (list->contains(id)) {
return &list->get(id);
} else {
return nullptr;
}
}
void libcamera_control_list_set(libcamera_control_list_t *list, enum libcamera_property_id id, const libcamera_control_value_t *val) {
// It would be nice to report status of this operation, however API does not provide any feedback
// and internally used `_validator` is private.
list->set(id, *val);
}
libcamera_control_list_iter_t *libcamera_control_list_iter(libcamera_control_list_t *list) {
auto it = list->begin();
return new libcamera_control_list_iter_t { list, it };
}
void libcamera_control_list_iter_destroy(libcamera_control_list_iter_t *iter) {
delete iter;
}
bool libcamera_control_list_iter_end(const libcamera_control_list_iter_t *iter) {
return iter->it == iter->list->end();
}
void libcamera_control_list_iter_next(libcamera_control_list_iter_t *iter) {
if (iter->it != iter->list->end()) {
++(iter->it);
}
}
unsigned int libcamera_control_list_iter_id(libcamera_control_list_iter_t *iter) {
return iter->it->first;
}
const libcamera_control_value_t *libcamera_control_list_iter_value(libcamera_control_list_iter_t *iter) {
return &iter->it->second;
}
libcamera_control_value_t *libcamera_control_value_create() {
return new libcamera::ControlValue();
}
void libcamera_control_value_destroy(libcamera_control_value_t *val) {
delete val;
}
enum libcamera_control_type libcamera_control_value_type(const libcamera_control_value_t *val) {
return (enum libcamera_control_type)val->type();
}
bool libcamera_control_value_is_none(const libcamera_control_value_t *val) {
return val->isNone();
}
bool libcamera_control_value_is_array(const libcamera_control_value_t *val) {
return val->isArray();
}
size_t libcamera_control_value_num_elements(const libcamera_control_value_t *val) {
return val->numElements();
}
const void *libcamera_control_value_get(const libcamera_control_value_t *val) {
return (const void*)val->data().data();
}
void libcamera_control_value_set(libcamera_control_value_t *val, enum libcamera_control_type type, const void *data, bool is_array, size_t num_elements) {
val->reserve((libcamera::ControlType)type, is_array, num_elements);
libcamera::Span<uint8_t> storage = val->data();
memcpy(storage.data(), data, storage.size());
}
}