forked from AravisProject/aravis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharvgcfloatregnode.c
315 lines (261 loc) · 9.92 KB
/
arvgcfloatregnode.c
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/* Aravis - Digital camera library
*
* Copyright © 2009-2019 Emmanuel Pacaud
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* Author: Emmanuel Pacaud <[email protected]>
*/
#include <arvgcfloatregnode.h>
#include <arvgcpropertynode.h>
#include <arvgcfloat.h>
#include <arvgcregister.h>
#include <arvgcdefaultsprivate.h>
#include <arvgc.h>
#include <arvmiscprivate.h>
typedef struct {
ArvGcPropertyNode *endianness;
ArvGcPropertyNode *unit;
ArvGcPropertyNode *representation;
ArvGcPropertyNode *display_notation;
ArvGcPropertyNode *display_precision;
GSList *selecteds;
} ArvGcFloatRegNodePrivate;
static void arv_gc_float_reg_node_init (ArvGcFloatRegNode *self);
static void arv_gc_float_reg_node_float_interface_init (ArvGcFloatInterface *interface);
G_DEFINE_TYPE_WITH_CODE (ArvGcFloatRegNode, arv_gc_float_reg_node, ARV_TYPE_GC_REGISTER_NODE,
G_ADD_PRIVATE (ArvGcFloatRegNode)
G_IMPLEMENT_INTERFACE (ARV_TYPE_GC_FLOAT, arv_gc_float_reg_node_float_interface_init))
static const char *
arv_gc_float_reg_node_get_node_name (ArvDomNode *node)
{
return "FloatReg";
}
static void
arv_gc_float_reg_node_post_new_child (ArvDomNode *self, ArvDomNode *child)
{
ArvGcFloatRegNodePrivate *priv = arv_gc_float_reg_node_get_instance_private (ARV_GC_FLOAT_REG_NODE (self));
if (ARV_IS_GC_PROPERTY_NODE (child)) {
ArvGcPropertyNode *property_node = ARV_GC_PROPERTY_NODE (child);
switch (arv_gc_property_node_get_node_type (property_node)) {
case ARV_GC_PROPERTY_NODE_TYPE_ENDIANNESS:
priv->endianness = property_node;
break;
case ARV_GC_PROPERTY_NODE_TYPE_UNIT:
priv->unit = property_node;
break;
case ARV_GC_PROPERTY_NODE_TYPE_REPRESENTATION:
priv->representation = property_node;
break;
case ARV_GC_PROPERTY_NODE_TYPE_DISPLAY_NOTATION:
priv->display_notation = property_node;
break;
case ARV_GC_PROPERTY_NODE_TYPE_DISPLAY_PRECISION:
priv->display_precision = property_node;
break;
case ARV_GC_PROPERTY_NODE_TYPE_P_SELECTED:
priv->selecteds = g_slist_prepend (priv->selecteds, property_node);
break;
default:
ARV_DOM_NODE_CLASS (arv_gc_float_reg_node_parent_class)->post_new_child (self, child);
break;
}
} else {
ARV_DOM_NODE_CLASS (arv_gc_float_reg_node_parent_class)->post_new_child (self, child);
}
}
static gdouble
arv_gc_float_reg_node_get_float_value (ArvGcFloat *self, GError **error)
{
ArvGcFloatRegNodePrivate *priv = arv_gc_float_reg_node_get_instance_private (ARV_GC_FLOAT_REG_NODE (self));
GError *local_error = NULL;
guint endianness;
gint64 length;
double v_double = 0.0;
endianness = arv_gc_property_node_get_endianness (priv->endianness, G_LITTLE_ENDIAN);
length = arv_gc_register_get_length (ARV_GC_REGISTER (self), &local_error);
if (local_error == NULL) {
char *buffer;
buffer = g_malloc (length);
arv_gc_register_get (ARV_GC_REGISTER (self), buffer, length, &local_error);
if (local_error == NULL) {
if (length == 4) {
float v_float = 0.0;
arv_copy_memory_with_endianness (&v_float, sizeof (v_float), G_BYTE_ORDER,
buffer, length, endianness);
v_double = v_float;
} else if (length == 8) {
arv_copy_memory_with_endianness (&v_double, sizeof (v_double), G_BYTE_ORDER,
buffer, length, endianness);
} else {
g_set_error (&local_error, ARV_GC_ERROR, ARV_GC_ERROR_INVALID_LENGTH,
"Invalid register length for FloatReg node");
}
}
g_free (buffer);
}
if (local_error != NULL)
g_propagate_prefixed_error (error, local_error, "[%s] ",
arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (self)));
return v_double;
}
static void
arv_gc_float_reg_node_set_float_value (ArvGcFloat *self, gdouble value, GError **error)
{
ArvGcFloatRegNodePrivate *priv = arv_gc_float_reg_node_get_instance_private (ARV_GC_FLOAT_REG_NODE (self));
GError *local_error = NULL;
guint endianness;
gint64 length;
endianness = arv_gc_property_node_get_endianness (priv->endianness, G_LITTLE_ENDIAN);
length = arv_gc_register_get_length (ARV_GC_REGISTER (self), &local_error);
if (local_error == NULL) {
char *buffer;
buffer = g_malloc (length);
if (local_error == NULL) {
if (length == 4) {
float v_float = value;
arv_copy_memory_with_endianness (buffer, length, endianness, &v_float, sizeof (v_float), G_BYTE_ORDER);
} else if (length == 8) {
arv_copy_memory_with_endianness (buffer, length, endianness, &value, sizeof (value), G_BYTE_ORDER);
} else {
g_set_error (&local_error, ARV_GC_ERROR, ARV_GC_ERROR_INVALID_LENGTH,
"Invalid register length for FloatReg node");
}
}
if (local_error == NULL)
arv_gc_register_set (ARV_GC_REGISTER (self), buffer, length, &local_error);
g_free (buffer);
}
if (local_error != NULL)
g_propagate_prefixed_error (error, local_error, "[%s] ",
arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (self)));
}
static double
arv_gc_float_reg_node_get_min (ArvGcFloat *self, GError **error)
{
GError *local_error = NULL;
gint64 length;
length = arv_gc_register_get_length (ARV_GC_REGISTER (self), &local_error);
if (local_error != NULL) {
g_propagate_error (error, local_error);
return -G_MAXDOUBLE;
}
if (length == 4)
return -G_MAXFLOAT;
else if (length == 8)
return -G_MAXDOUBLE;
g_set_error (error, ARV_GC_ERROR, ARV_GC_ERROR_INVALID_LENGTH,
"[%s] Invalid register length for FloatReg node",
arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (self)));
return -G_MAXDOUBLE;
}
static double
arv_gc_float_reg_node_get_max (ArvGcFloat *self, GError **error)
{
GError *local_error = NULL;
gint64 length;
length = arv_gc_register_get_length (ARV_GC_REGISTER (self), &local_error);
if (local_error != NULL) {
g_propagate_error (error, local_error);
return G_MAXDOUBLE;
}
if (length == 4)
return G_MAXFLOAT;
else if (length == 8)
return G_MAXDOUBLE;
g_set_error (error, ARV_GC_ERROR, ARV_GC_ERROR_INVALID_LENGTH,
"[%s] Invalid register length for FloatReg node",
arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (self)));
return G_MAXDOUBLE;
}
static ArvGcRepresentation
arv_gc_float_reg_get_representation (ArvGcFloat *self)
{
ArvGcFloatRegNodePrivate *priv = arv_gc_float_reg_node_get_instance_private (ARV_GC_FLOAT_REG_NODE (self));
if (priv->representation == NULL)
return ARV_GC_REPRESENTATION_UNDEFINED;
return arv_gc_property_node_get_representation (priv->representation, ARV_GC_REPRESENTATION_UNDEFINED);
}
static const char *
arv_gc_float_reg_node_get_unit (ArvGcFloat *self)
{
ArvGcFloatRegNodePrivate *priv = arv_gc_float_reg_node_get_instance_private (ARV_GC_FLOAT_REG_NODE (self));
if (priv->unit == NULL)
return NULL;
return arv_gc_property_node_get_string (priv->unit, NULL);
}
static ArvGcDisplayNotation
arv_gc_float_reg_node_get_display_notation (ArvGcFloat *self)
{
ArvGcFloatRegNodePrivate *priv = arv_gc_float_reg_node_get_instance_private (ARV_GC_FLOAT_REG_NODE (self));
if (priv->display_notation == NULL)
return ARV_GC_DISPLAY_NOTATION_DEFAULT;
return arv_gc_property_node_get_display_notation (ARV_GC_PROPERTY_NODE (priv->display_notation), ARV_GC_DISPLAY_NOTATION_DEFAULT);
}
static gint64
arv_gc_float_reg_node_get_display_precision (ArvGcFloat *self)
{
ArvGcFloatRegNodePrivate *priv = arv_gc_float_reg_node_get_instance_private (ARV_GC_FLOAT_REG_NODE (self));
if (priv->display_precision == NULL)
return ARV_GC_DISPLAY_PRECISION_DEFAULT;
return arv_gc_property_node_get_display_precision (ARV_GC_PROPERTY_NODE (priv->display_precision), ARV_GC_DISPLAY_PRECISION_DEFAULT);
}
/**
* arv_gc_float_reg_node_new:
*
* Returns: a new FloatReg node
*
* Since:0.8.0
*/
ArvGcNode *
arv_gc_float_reg_node_new (void)
{
return g_object_new (ARV_TYPE_GC_FLOAT_REG_NODE, NULL);
}
static void
arv_gc_float_reg_node_float_interface_init (ArvGcFloatInterface *interface)
{
interface->get_value = arv_gc_float_reg_node_get_float_value;
interface->set_value = arv_gc_float_reg_node_set_float_value;
interface->get_min = arv_gc_float_reg_node_get_min;
interface->get_max = arv_gc_float_reg_node_get_max;
interface->get_representation = arv_gc_float_reg_get_representation;
interface->get_unit = arv_gc_float_reg_node_get_unit;
interface->get_display_notation = arv_gc_float_reg_node_get_display_notation;
interface->get_display_precision = arv_gc_float_reg_node_get_display_precision;
}
static void
arv_gc_float_reg_node_init (ArvGcFloatRegNode *self)
{
}
static void
arv_gc_float_reg_node_finalize (GObject *self)
{
ArvGcFloatRegNodePrivate *priv = arv_gc_float_reg_node_get_instance_private (ARV_GC_FLOAT_REG_NODE (self));
g_clear_pointer (&priv->selecteds, g_slist_free);
G_OBJECT_CLASS (arv_gc_float_reg_node_parent_class)->finalize (self);
}
static void
arv_gc_float_reg_node_class_init (ArvGcFloatRegNodeClass *this_class)
{
ArvGcRegisterNodeClass *gc_register_node_class = ARV_GC_REGISTER_NODE_CLASS (this_class);
ArvDomNodeClass *dom_node_class = ARV_DOM_NODE_CLASS (this_class);
GObjectClass *object_class = G_OBJECT_CLASS (this_class);
object_class->finalize = arv_gc_float_reg_node_finalize;
dom_node_class->get_node_name = arv_gc_float_reg_node_get_node_name;
dom_node_class->post_new_child = arv_gc_float_reg_node_post_new_child;
gc_register_node_class->default_cachable = ARV_GC_CACHABLE_WRITE_AROUND;
}