summaryrefslogtreecommitdiff
path: root/DevIL/projects/fortran/fortran_wrapper.c
blob: 1acf154dbfcf2c878392b5302bb041220a56408c (plain)
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
#include <IL/il.h>
#include <string.h>
#include <malloc.h>

// NOTE!
//  The biggest problem about using DevIL from Fortran is the
//  fact that Fortran does arrays in column-major format.
//  This wrapper does no conversions between the two!
//
//  We are using DevIL return values as the first parameter.
//


// From http://www.ibiblio.org/pub/languages/fortran/ch1-11.html
//  This is how Fortran passes strings.
struct descriptor						/* VMS fixed length string    */
{										/* descriptor used in FORTRAN */
	unsigned short  length;
	unsigned char   data_type,			/* = 14      */
					dsc_class;			/* = 1       */
	char            *string_ptr;
}; 


void ilFActiveImage_(int *RetVal, int *Number)
{
	*RetVal = ilActiveImage((unsigned int)*Number);
	return;
}

void ilFActiveLayer_(int *RetVal, int *Number)
{
	*RetVal = ilActiveImage((unsigned int)*Number);
	return;
}

void ilFActiveMipmap_(int *RetVal, int *Number)
{
	*RetVal = ilActiveImage((unsigned int)*Number);
	return;
}

void ilFApplyPal_(int *RetVal, struct descriptor *Desc)
{
	char *Filename = malloc(Desc->length + 1);
	strncpy(Filename, Desc->string_ptr, Desc->length);
	Filename[Desc->length] = 0;  // Should really be NULL...getting a warning, though.
	*RetVal = ilApplyPal(Filename);

	free(Filename);
	return;
}

void ilFBindImage_(int *Image)
{
	ilBindImage((unsigned int)*Image);
	return;
}

void ilFBlit_(int *RetVal, int *Source, int *DestX, int *DestY, int *DestZ, int *SrcX, int *SrcY, int *SrcZ, int *Width, int *Height, int *Depth)
{
	*RetVal = ilBlit(*Source, *DestX, *DestY, *DestZ, *SrcX, *SrcY, *SrcZ, *Width, *Height, *Depth);
	return;
}

void ilFClearColour_(float *Red, float *Green, float *Blue, float *Alpha)
{
	ilClearColour(*Red, *Green, *Blue, *Alpha);
	return;
}

void ilFClearImage_(int *RetVal)
{
	*RetVal = ilClearImage();
	return;
}

void ilFCloneCurImage_(int *RetVal)
{
	*RetVal = ilCloneCurImage();
	return;
}

void ilFCompressFunc_(int *RetVal, int *Mode)
{
	*RetVal = ilCompressFunc(*Mode);
	return;
}

void ilFConvertImage_(int *RetVal, int *DestFormat, int *DestType)
{
	*RetVal = ilConvertImage(*DestFormat, *DestType);
	return;
}

void ilFConvertPal_(int *RetVal, int *DestFormat)
{
	*RetVal = ilConvertPal(*DestFormat);
}

void ilFCopyImage_(int *RetVal, int *Src)
{
	*RetVal = ilCopyImage(*Src);
	return;
}

void ilFCopyPixels_(int *RetVal, int *XOff, int *YOff, int *ZOff, int *Width, int *Height, int *Depth, int *Format, int *Type, void *Data)
{
	*RetVal = ilCopyPixels(*XOff, *YOff, *ZOff, *Width, *Height, *Depth, *Format, *Type, Data);
	return;
}

void ilFCreateSubImage_(int *RetVal, int *Type, int *Num)
{
	*RetVal = ilCreateSubImage(*Type, *Num);
	return;
}

void ilFDefaultImage_(int *RetVal)
{
	*RetVal = ilDefaultImage();
	return;
}

void ilFDeleteImage_(int *Num)
{
	ilDeleteImage(*Num);
	return;
}

// Not sure how to do the arrays properly.
//void ilFDeleteImages_(int *Num, int **Images)
//{
//	ilDeleteImages(*Num, *Images);
//}

void ilFDisable_(int *RetVal, int *Mode)
{
	*RetVal = ilDisable(*Mode);
	return;
}

void ilFEnable_(int *RetVal, int *Mode)
{
	*RetVal = ilEnable(*Mode);
	return;
}

void ilFFormatFunc_(int *RetVal, int *Mode)
{
	*RetVal = ilFormatFunc(*Mode);
	return;
}

// Not sure how to do the arrays properly.
//void ilFGenImages_(int *Num, int **Images)
//{
//	ilGenImages(*Num, *Images);
//}

void ilFGenImage_(int *RetVal)
{
	*RetVal = ilGenImage();
	return;
}

//void ilFGetAlpha_(

void ilFGetBoolean_(int *RetVal, int *Mode)
{
	*RetVal = ilGetBoolean(*Mode);
	return;
}

void ilFGetBooleanv_(int *Mode, int *Param)
{
	ilGetBooleanv(*Mode, Param);
	return;
}

void ilFGetData_(char *RetVal)
{
	RetVal = ilGetData();
	return;
}

// ilGetDXTCData

void ilFGetError_(int *RetVal)
{
	*RetVal = ilGetError();
	return;
}

void ilFGetInteger_(int *RetVal, int *Mode)
{
	*RetVal = ilGetInteger(*Mode);
	return;
}

void ilFGetIntegerv_(int *Mode, int *Param)
{
	ilGetIntegerv(*Mode, Param);
	return;
}

void ilFGetLumpPos_(int *RetVal)
{
	*RetVal = ilGetLumpPos();
	return;
}

void ilFGetPalette_(char *RetVal)
{
	RetVal = ilGetPalette();
	return;
}

//ilGetString

void ilFInit_()
{
	ilInit();
	return;
}

void ilFShutDown_()
{
	ilShutDown();
	return;
}

void ilFLoadImage_(int *RetVal, struct descriptor *Desc)
{
	char *Filename = malloc(Desc->length + 1);
	strncpy(Filename, Desc->string_ptr, Desc->length);
	Filename[Desc->length] = 0;  // Should really be NULL...getting a warning, though.
	*RetVal = ilLoadImage(Filename);

	free(Filename);
	return;
}

void ilFSave_(int *RetVal, int *Type, struct descriptor *Desc)
{
	char *Filename = malloc(Desc->length + 1);
	strncpy(Filename, Desc->string_ptr, Desc->length);
	Filename[Desc->length] = 0;  // Should really be NULL...getting a warning, though.
	*RetVal = ilSave(*Type, Filename);

	free(Filename);
	return;
}

void ilFSaveImage_(int *RetVal, struct descriptor *Desc)
{
	char *Filename = malloc(Desc->length + 1);
	strncpy(Filename, Desc->string_ptr, Desc->length);
	Filename[Desc->length] = 0;  // Should really be NULL...getting a warning, though.
	*RetVal = ilSaveImage(Filename);

	free(Filename);
	return;
}