-
Notifications
You must be signed in to change notification settings - Fork 1
/
xiProc.cs
369 lines (348 loc) · 10.2 KB
/
xiProc.cs
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
using System;
using System.Text;
using System.Runtime.InteropServices;
using xiApi;
namespace XimeaWrapper
{
/// <summary>
/// Contains function definitions for the offline processing xiAPI.NET class.
/// </summary>
public class xiProc
{
private const int XI_OK = 0;
private UIntPtr handle;
/// <summary>
/// Class contructor, initializes class variables.
/// </summary>
public xiProc()
{
handle = UIntPtr.Zero;
}
/// <summary>
/// Class destructor, unitializes class variables.
/// </summary>
~xiProc()
{
}
/// <summary>
/// Opens new instance for Image Processing entity
/// </summary>
public unsafe void ProcOpen()
{
int num = 0;
try
{
void* value = null;
num = ximeaApi.xiProcOpen(&value);
handle = new UIntPtr(value);
}
catch
{
num = 1;
}
if (num != 0)
{
throw new xiExc(num, "xiProcOpen");
}
}
/// <summary>
/// Closes instance for Image Processing entity
/// </summary>
public unsafe void ProcClose()
{
int num = 0;
try
{
num = ximeaApi.xiProcClose((void*)handle);
}
catch
{
num = 0;
}
handle = UIntPtr.Zero;
if (num != 0)
{
throw new xiExc(num, "xiProcOpen");
}
}
/// <summary>
/// Sets the selected parameter to processing
/// </summary>
/// <param name="prm">Parameter name string. Use class PRM to set parameters.</param>
/// <param name="val">String value to be set.</param>
public unsafe void ProcSetParam(string prm, string val)
{
int num = 0;
if (val.Length == 0)
{
throw new xiExc(101, "ProcSetParam " + prm);
}
try
{
byte[] bytes = Encoding.ASCII.GetBytes(val);
IntPtr intPtr = Marshal.UnsafeAddrOfPinnedArrayElement(bytes, 0);
num = ximeaApi.xiProcSetParam((void*)handle, prm, intPtr.ToPointer(), val.Length, PRM_TYPE.TypeString);
}
catch
{
num = 1;
}
if (num != 0)
{
throw new xiExc(num, "ProcSetParam " + prm);
}
}
/// <summary>
/// Sets the selected parameter to processing
/// </summary>
/// <param name="prm">Parameter name string. Use class PRM to set parameters.</param>
/// <param name="val">Integer value to be set.</param>
public unsafe void ProcSetParamInt(string prm, int val)
{
int num = 0;
try
{
num = ximeaApi.xiProcSetParam((void*)handle, prm, &val, 4, PRM_TYPE.TypeInteger);
}
catch
{
num = 1;
}
if (num != 0)
{
throw new xiExc(num, "ProcSetParamInt " + prm);
}
}
/// <summary>
/// Sets the selected parameter to processing
/// </summary>
/// <param name="prm">Parameter name string. Use class PRM to set parameters.</param>
/// <param name="val">Float value to be set.</param>
public unsafe void ProcSetParamFloat(string prm, int val)
{
int num = 0;
try
{
num = ximeaApi.xiProcSetParam((void*)handle, prm, &val, 4, PRM_TYPE.TypeFloat);
}
catch
{
num = 1;
}
if (num != 0)
{
throw new xiExc(num, "ProcSetParamFloat " + prm);
}
}
/// <summary>
/// Gets the selected parameter from processing.
/// </summary>
/// <param name="prm">Parameter name string. Use class PRM to get parameters.</param>
/// <returns>String value to be returned.</returns>
public unsafe string ProcGetParam(string prm)
{
int num = 0;
PRM_TYPE pRM_TYPE = PRM_TYPE.TypeString;
int num2 = 1;
string result = string.Empty;
try
{
ximeaApi.xiProcGetParam((void*)handle, prm, null, &num2, &pRM_TYPE);
switch (pRM_TYPE)
{
case PRM_TYPE.TypeString:
{
num2 += 10;
byte[] array = new byte[num2];
try
{
byte[] array2 = array;
fixed (byte* val = array2)
{
num = ximeaApi.xiProcGetParam((void*)handle, prm, val, &num2, &pRM_TYPE);
result = ((num != 0) ? "" : Encoding.ASCII.GetString(array, 0, num2));
}
}
finally
{
}
break;
}
case PRM_TYPE.TypeFloat:
{
float num4 = 0f;
num = ximeaApi.xiProcGetParam((void*)handle, prm, &num4, &num2, &pRM_TYPE);
result = num4.ToString();
break;
}
case PRM_TYPE.TypeInteger:
case PRM_TYPE.TypeBoolean:
case PRM_TYPE.TypeCommand:
{
int num3 = 0;
num = ximeaApi.xiProcGetParam((void*)handle, prm, &num3, &num2, &pRM_TYPE);
result = num3.ToString();
break;
}
default:
num = 103;
break;
}
}
catch
{
num = 1;
}
if (num != 0)
{
throw new xiExc(num, "xiProcGetParam " + prm);
}
return result;
}
/// <summary>
/// Gets the selected parameter from processing.
/// </summary>
/// <param name="prm">Parameter name string. Use class PRM to get parameters.</param>
/// <returns>Integer value to be returned.</returns>
public unsafe int ProcGetParamInt(string prm)
{
PRM_TYPE pRM_TYPE = PRM_TYPE.TypeInteger;
int num = 0;
int num2 = 4;
int result = 0;
try
{
num = ximeaApi.xiProcGetParam((void*)handle, prm, &result, &num2, &pRM_TYPE);
}
catch
{
num = 1;
}
if (num != 0)
{
throw new xiExc(num, "xiProcGetParamInt " + prm);
}
return result;
}
/// <summary>
/// Gets the selected parameter from processing.
/// </summary>
/// <param name="prm">Parameter name string. Use class PRM to get parameters.</param>
/// <returns>Integer value to be returned.</returns>
public unsafe float ProcGetParamFloat(string prm)
{
int num = 0;
PRM_TYPE pRM_TYPE = PRM_TYPE.TypeFloat;
int num2 = 4;
float result = 0f;
try
{
num = ximeaApi.xiProcGetParam((void*)handle, prm, &result, &num2, &pRM_TYPE);
}
catch
{
num = 1;
}
if (num != 0)
{
throw new xiExc(num, "xiProcGetParamFloat " + prm);
}
return result;
}
/// <summary>
/// Set unprocessed image to processing chain, only pointer to data in XI_IMG will be used.
/// </summary>
/// <param name="image">Byte array of pixels of image to be processed.</param>
public unsafe void ProcPushImage(XI_IMG image)
{
int num = 0;
num = ximeaApi.xiProcPushImage((void*)handle, image.bp);
if (num != 0)
{
throw new xiExc(num, "xiProcPushImage ");
}
}
/// <summary>
/// Set unprocessed image to processing chain, XI_IMG members will be used in processing chain.
/// </summary>
/// <param name="image">XI_IMG structure with image data.</param>
public unsafe void ProcPushXiImg(XI_IMG image)
{
int num = 0;
num = ximeaApi.xiProcPushXiImg((void*)handle, &image);
if (num != 0)
{
throw new xiExc(num, "xiProcPushXiImg ");
}
}
/// <summary>
/// Internal handler of xiProcPullImage for all instances in class.
/// </summary>
/// <param name="img">XI_IMG struct to be filled.</param>
/// <param name="timeout">Time interval required to wait for the image (in milliseconds)</param>
internal unsafe void ProcPullImageInternal(out XI_IMG img, int timeout)
{
int num = 0;
XI_IMG xI_IMG = default(XI_IMG);
xI_IMG.Clear();
num = ximeaApi.xiProcPullImage((void*)handle, timeout, &xI_IMG);
if (num != 0)
{
throw new xiExc(num, "xiProcPushImage ");
}
img = xI_IMG;
}
///// <summary>
///// Gets processed image from processing chain.
///// </summary>
///// <param name="image">Bitmap image to be returned.</param>
///// <param name="timeout">Time interval required to wait for the image (in milliseconds)</param>
//public void ProcPullImage(out Bitmap image, int timeout)
//{
// XI_IMG img = default(XI_IMG);
// img.Clear();
// ProcPullImageInternal(out img, timeout);
// xiImg xiImg = new xiImg(img);
// xiImg.GetBitmapByRef(out image);
//}
///// <summary>
///// Gets processed image from processing chain.
///// </summary>
///// <param name="image">BitmapSource image to be returned.</param>
///// <param name="timeout">Time interval required to wait for the image (in milliseconds)</param>
//public void ProcPullImage(out BitmapSource image, int timeout)
//{
// XI_IMG img = default(XI_IMG);
// img.Clear();
// ProcPullImageInternal(out img, timeout);
// xiImg xiImg = new xiImg(img);
// xiImg.GetBitmapSourceByRef(out image);
//}
///// <summary>
///// Gets processed image from processing chain.
///// </summary>
///// <param name="val">WriteableBitmap image to be returned.</param>
///// <param name="timeout">Time interval required to wait for the image (in milliseconds)</param>
//public void ProcPullImage(out WriteableBitmap image, int timeout)
//{
// XI_IMG img = default(XI_IMG);
// img.Clear();
// ProcPullImageInternal(out img, timeout);
// xiImg xiImg = new xiImg(img);
// xiImg.GetWriteableBitmapByRef(out image);
//}
/// <summary>
/// Gets processed image from processing chain.
/// </summary>
/// <param name="img_arr">Byte array image data to be returned.</param>
/// <param name="timeout">Time interval required to wait for the image (in milliseconds)</param>
public void ProcPullImage(out byte[] img_arr, int timeout)
{
XI_IMG img = default(XI_IMG);
img.Clear();
ProcPullImageInternal(out img, timeout);
xiImg xiImg = new xiImg(img);
xiImg.GetByteArrayByRef(out img_arr);
}
}
}