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
|
/*
* C-type: unsigned char
* Scilab type: double or uint8 scalar
*/
%fragment(SWIG_AsVal_frag(unsigned char), "header", fragment="SWIG_SciUint8_AsUnsignedChar", fragment="<limits.h>") {
#define SWIG_AsVal_unsigned_SS_char(scilabValue, valuePointer) SWIG_SciUint8_AsUnsignedChar(pvApiCtx, scilabValue, valuePointer, fname)
}
%fragment("SWIG_SciUint8_AsUnsignedChar", "header") {
SWIGINTERN int
SWIG_SciUint8_AsUnsignedChar(void *_pvApiCtx, int iVar, unsigned char *pucValue, char *_fname) {
SciErr sciErr;
int iType = 0;
int iRows = 0;
int iCols = 0;
int iPrec = 0;
int *piAddrVar = NULL;
unsigned char *pucData = NULL;
sciErr = getVarAddressFromPosition(_pvApiCtx, iVar, &piAddrVar);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
sciErr = getVarType(_pvApiCtx, piAddrVar, &iType);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iType == sci_ints) {
if (pucValue) {
sciErr = getMatrixOfIntegerPrecision(_pvApiCtx, piAddrVar, &iPrec);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iPrec != SCI_UINT8) {
Scierror(999, _("%s: Wrong type for input argument #%d: A 8-bit unsigned integer or a double expected.\n"), _fname, iVar);
return SWIG_ERROR;
}
sciErr = getMatrixOfUnsignedInteger8(_pvApiCtx, piAddrVar, &iRows, &iCols, &pucData);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iRows * iCols != 1) {
Scierror(999, _("%s: Wrong size for input argument #%d: A 8-bit unsigned integer or a double expected.\n"), _fname, iVar);
return SWIG_ERROR;
}
*pucValue = *pucData;
}
}
else if (iType == sci_matrix) {
if (pucValue) {
double *pdData = NULL;
double dValue = 0.0f;
sciErr = getMatrixOfDouble(_pvApiCtx, piAddrVar, &iRows, &iCols, &pdData);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iRows * iCols != 1) {
Scierror(999, _("%s: Wrong size for input argument #%d: A 8-bit unsigned integer or a double expected.\n"), _fname, iVar);
return SWIG_TypeError;
}
dValue = *pdData;
if (dValue != floor(dValue)) {
Scierror(999, _("%s: Incorrect value for input argument #%d: The double value cannot be converted to a 8-bit unsigned integer.\n"), _fname, iVar);
return SWIG_ValueError;
}
if ((dValue < 0) || (dValue > UCHAR_MAX)) {
Scierror(999, _("%s: Overflow error for input argument #%d: The double value cannot be converted to a 8-bit unsigned integer.\n"), _fname, iVar);
return SWIG_OverflowError;
}
*pucValue = (unsigned char) dValue;
}
}
else {
Scierror(999, _("%s: Wrong type for input argument #%d: A 8-bit unsigned integer or a double expected.\n"), _fname, iVar);
return SWIG_ERROR;
}
return SWIG_OK;
}
}
%fragment(SWIG_From_frag(unsigned char), "header", fragment="SWIG_SciUint8_FromUnsignedChar") {
#define SWIG_From_unsigned_SS_char(value) SWIG_SciUint8_FromUnsignedChar(pvApiCtx, SWIG_Scilab_GetOutputPosition(), value)
}
%fragment("SWIG_SciUint8_FromUnsignedChar", "header") {
SWIGINTERN int
SWIG_SciUint8_FromUnsignedChar(void *_pvApiCtx, int iVarOut, unsigned char ucValue) {
if (createScalarDouble(pvApiCtx,
SWIG_NbInputArgument(_pvApiCtx) + iVarOut, (double) ucValue))
return SWIG_ERROR;
return SWIG_OK;
}
}
/*
* C-type: unsigned char[]
* Scilab type: uint8 vector
*/
%fragment("SWIG_SciUint8_AsUnsignedCharArrayAndSize", "header") {
SWIGINTERN int
SWIG_SciUint8_AsUnsignedCharArrayAndSize(void *_pvApiCtx, int iVar, int *iRows, int *iCols, unsigned char **pucValue, char *_fname) {
SciErr sciErr;
int iType = 0;
int iPrec = 0;
int *piAddrVar = NULL;
sciErr = getVarAddressFromPosition(_pvApiCtx, iVar, &piAddrVar);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
sciErr = getVarType(_pvApiCtx, piAddrVar, &iType);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iType == sci_matrix)
{
double *pdData = NULL;
int size = 0;
int i;
sciErr = getMatrixOfDouble(_pvApiCtx, piAddrVar, iRows, iCols, &pdData);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return SWIG_ERROR;
}
size = (*iRows) * (*iCols);
*pucValue = (unsigned char*) malloc(size * sizeof(int*));
for (i = 0; i < size; i++)
(*pucValue)[i] = (unsigned char) pdData[i];
}
else if (iType == sci_ints)
{
sciErr = getMatrixOfIntegerPrecision(_pvApiCtx, piAddrVar, &iPrec);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iPrec != SCI_UINT8)
{
Scierror(999, _("%s: Wrong type for input argument #%d: A 8-bit unsigned integer or a double vector expected.\n"), _fname, iVar);
return SWIG_ERROR;
}
sciErr = getMatrixOfUnsignedInteger8(_pvApiCtx, piAddrVar, iRows, iCols, pucValue);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return SWIG_ERROR;
}
}
else
{
Scierror(999, _("%s: Wrong type for input argument #%d: A 8-bit unsigned integer or a double vector expected.\n"), _fname, iVar);
return SWIG_ERROR;
}
return SWIG_OK;
}
}
%fragment("SWIG_SciUint8_FromUnsignedCharArrayAndSize", "header") {
SWIGINTERN int
SWIG_SciUint8_FromUnsignedCharArrayAndSize(void *_pvApiCtx, int iVarOut, int iRows, int iCols, const unsigned char *pucValues) {
SciErr sciErr;
double *pdValues = NULL;
int i;
pdValues = (double*) malloc(iRows * iCols * sizeof(double));
for (i=0; i<iRows * iCols; i++)
pdValues[i] = pucValues[i];
sciErr = createMatrixOfDouble(pvApiCtx, SWIG_NbInputArgument(_pvApiCtx) + iVarOut, iRows, iCols, pdValues);
if (sciErr.iErr)
{
printError(&sciErr, 0);
free(pdValues);
return SWIG_ERROR;
}
free(pdValues);
return SWIG_OK;
}
}
|