summaryrefslogtreecommitdiff
path: root/DevIL/bindings/Mathematica/DevIL Interface.c
blob: 7dc3f1b8effef16d66f9c3eac7b4ecde604275f6 (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
#include <IL/IL.h>
#include <IL/ILU.h>
#include <IL/ILUT.h>
#include <mathlink.h>

int main(int argc, char *argv[])
{
	int retval;
	int image;

	ilInit();
	iluInit();
	ilutInit();

	ilGenImages(1, &image);
	ilBindImage(image);
	ilOriginFunc(IL_ORIGIN_LOWER_LEFT);

	retval = MLMain(argc, argv);

	ilDeleteImages(1, &image);

	ilShutDown();  // Only need to shut down DevIL, not ILU or ILUT

	return retval;
}

/*int f(int x, int y)
{
	return x+y;
}


void bits(int i)
{
	int a[32], k;
	for(k=0; k<32; k++) {
		a[k] = i%2;
		i >>= 1;
		if (i==0) break;
	}

	if (k<32) k++;
	MLPutInteger32List(stdlink, a, k);
	return;
}*/

int mlLoad(char *Filename)
{
	int ret = ilLoadImage(Filename);
	if (ilGetInteger(IL_ORIGIN_MODE) != IL_ORIGIN_UPPER_LEFT)
		iluFlipImage();
	ilConvertImage(IL_RGBA, IL_DOUBLE);
	return ret;
}

int mlWidth(void)
{
	return ilGetInteger(IL_IMAGE_WIDTH);
}

int mlHeight(void)
{
	return ilGetInteger(IL_IMAGE_HEIGHT);
}

void mlData(void)
{
	/*int		x, y, c;
	int		*Data;
	ILubyte	*OrigData = ilGetData();

	Data = malloc(ilGetInteger(IL_IMAGE_WIDTH) * ilGetInteger(IL_IMAGE_HEIGHT) * 4 * sizeof(int));
	for (y = 0; y < ilGetInteger(IL_IMAGE_HEIGHT); y++) {
		for (x = 0; x < ilGetInteger(IL_IMAGE_WIDTH); x++) {
			for (c = 0; c < 4; c++) {
				Data[y * ilGetInteger(IL_IMAGE_WIDTH) * 4 + x * 4 + c] = OrigData[y * ilGetInteger(IL_IMAGE_WIDTH) * 4 + x * 4 + c];
			}
		}
	}

	MLPutInteger32List(stdlink, Data, ilGetInteger(IL_IMAGE_WIDTH) * ilGetInteger(IL_IMAGE_HEIGHT) * 4);

	free(Data);*/

	MLPutReal64List(stdlink, (ILdouble*)ilGetData(), ilGetInteger(IL_IMAGE_WIDTH) * ilGetInteger(IL_IMAGE_HEIGHT) * 4);

	return;
}