~ubuntu-branches/ubuntu/hoary/devil/hoary

« back to all changes in this revision

Viewing changes to test/old/testil.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Marcelo E. Magallon
  • Date: 2005-01-03 19:57:42 UTC
  • Revision ID: james.westby@ubuntu.com-20050103195742-4ipkplcwygu3irv0
Tags: upstream-1.6.7
ImportĀ upstreamĀ versionĀ 1.6.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// TestIL.cpp : Defines the entry point for the console application.
 
2
//
 
3
 
 
4
#define IL_NO_GIF  // Just for right now...
 
5
 
 
6
#include <stdio.h>
 
7
#include <il/il.h>
 
8
#include <il/ilu.h>
 
9
#include <il/ilut.h>
 
10
 
 
11
void NewTest(void);
 
12
void MemTest(void);
 
13
void RegTest(void);
 
14
void DoomTest(void);
 
15
void IcoCurTest(void);
 
16
void BitTest(void);
 
17
// In doom.cpp
 
18
FILE *TestOpenWad(char *WadName);
 
19
GLboolean TestLocateLump(char *LumpName);
 
20
GLvoid TestCloseWad();
 
21
 
 
22
 
 
23
int main(int argc, char* argv[])
 
24
{
 
25
        ILimage *Image, *Flipped, *SubImage, *JpegImage, *BmpImage, *PcxImage, *PpmImage, *PgmImage;
 
26
        ILimage *PngImage;
 
27
 
 
28
        ilEnable(IL_ORIGIN_SET);
 
29
        ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
 
30
 
 
31
        ilEnable(IL_FILE_OVERWRITE);  // Will now overwrite existing files
 
32
 
 
33
        MemTest();
 
34
        NewTest();
 
35
        RegTest();
 
36
        DoomTest();
 
37
        IcoCurTest();
 
38
        BitTest();
 
39
 
 
40
        Image = ilLoadTarga("default1.tga");
 
41
 
 
42
        ilSaveCHeader("header.h", Image, "Default");
 
43
 
 
44
 
 
45
        ilPushAttrib(IL_ALL_ATTRIB_BITS);
 
46
        ilOriginFunc(IL_ORIGIN_UPPER_LEFT);
 
47
        Flipped = ilLoadTarga("default1.tga");
 
48
        ilSaveTarga("default2.tga", Flipped, NULL);
 
49
        ilCloseImage(Flipped);
 
50
        ilPopAttrib();
 
51
 
 
52
 
 
53
        SubImage = ilTexSubImage2d(Image, 0, 0, 16, 16);
 
54
        ilSaveTarga("default3.tga", SubImage, NULL);
 
55
 
 
56
 
 
57
        ilCloseImage(SubImage);
 
58
 
 
59
 
 
60
        // Fux0red
 
61
/*      RotImage = iluRotateImage(Image, 45, 169);
 
62
        ilSaveTarga("default4.tga", RotImage, NULL);
 
63
        ilCloseImage(RotImage);*/
 
64
 
 
65
        JpegImage = ilLoadJpeg("default1.jpg");
 
66
        ilSaveTarga("jpeg.tga", JpegImage, NULL);
 
67
        ilCloseImage(JpegImage);
 
68
 
 
69
        // Need to convert in here from 8-bit to 24-bit!
 
70
        //ilSaveJpeg("default5.jpg", Image, 99);
 
71
 
 
72
        PcxImage = ilLoadPcx("default1.pcx");
 
73
        ilSaveTarga("pcx.tga", PcxImage, NULL);
 
74
        ilCloseImage(PcxImage);
 
75
 
 
76
        
 
77
        BmpImage = ilLoadBitmap("default1.bmp");
 
78
        ilSaveTarga("bitmap.tga", BmpImage, NULL);
 
79
        ilCloseImage(BmpImage);
 
80
 
 
81
        PpmImage = ilLoadPpm("default1.ppm");
 
82
        ilSaveTarga("ppm1.tga", PpmImage, NULL);
 
83
        ilCloseImage(PpmImage);
 
84
 
 
85
        PpmImage = ilLoadPpm("default2.ppm");
 
86
        ilSaveTarga("ppm2.tga", PpmImage, NULL);
 
87
        ilCloseImage(PpmImage);
 
88
 
 
89
        PgmImage = ilLoadPgm("default1.pgm");
 
90
        ilSaveTarga("pgm1.tga", PgmImage, NULL);
 
91
        ilCloseImage(PgmImage);
 
92
 
 
93
        PgmImage = ilLoadPgm("default2.pgm");
 
94
        ilSaveTarga("pgm2.tga", PgmImage, NULL);
 
95
        ilCloseImage(PgmImage);
 
96
 
 
97
 
 
98
        PngImage = ilLoadPng("default1.png");
 
99
        ilSaveTarga("png1.tga", PngImage, NULL);
 
100
        ilCloseImage(PngImage);
 
101
 
 
102
        PngImage = ilLoadPng("test1.png");
 
103
        ilSaveTarga("testpng1.tga", PngImage, NULL);
 
104
        ilCloseImage(PngImage);
 
105
 
 
106
        PngImage = ilLoadPng("test2.png");
 
107
        ilSaveTarga("testpng2.tga", PngImage, NULL);
 
108
        ilCloseImage(PngImage);
 
109
 
 
110
        PngImage = ilLoadPng("test256.png");
 
111
        ilSaveTarga("testpng256.tga", PngImage, NULL);
 
112
        ilCloseImage(PngImage);
 
113
 
 
114
        PngImage = ilLoadPng("testpnggrey.png");
 
115
        ilSaveTarga("testpnggrey.tga", PngImage, NULL);
 
116
        ilCloseImage(PngImage);
 
117
 
 
118
 
 
119
 
 
120
 
 
121
        GLenum Error;
 
122
        while (Error = ilGetError()) {
 
123
                printf("Error: %s\n", iluErrorString(Error));
 
124
        }
 
125
 
 
126
 
 
127
 
 
128
        ilCloseImage(Image);
 
129
        
 
130
 
 
131
/*      Image = ilLoadGif("default1.gif");
 
132
        printf("\nGif\n---");
 
133
        printf("Width: %d  Height: %d  Bpp: %d\n", Image->Width, Image->Height, Image->Bpp);
 
134
        if (Image->Pal)
 
135
                printf("Pal: %d %d %d   %d %d %d   %d %d %d\n", Image->Pal[0], Image->Pal[1], Image->Pal[2],
 
136
                Image->Pal[3], Image->Pal[4], Image->Pal[5], Image->Pal[6], Image->Pal[7], Image->Pal[8]);
 
137
        printf("Data: %d %d   %d", Image->Data[0], Image->Data[1], Image->Data[8]);
 
138
 
 
139
        ilCloseImage(Image);*/
 
140
 
 
141
 
 
142
 
 
143
        return 0;
 
144
}
 
145
 
 
146
 
 
147
void NewTest()
 
148
{
 
149
        ILimage *Image;
 
150
 
 
151
        FILE *f = fopen("in\\rgb32.tga", "rb");
 
152
        Image = ilLoadTargaF(f);
 
153
        ilSaveTarga("out/rgb32.tga", Image, NULL);
 
154
        ilCloseImage(Image);
 
155
        fclose(f);
 
156
 
 
157
        ILimage *Scaled;
 
158
        Image = ilLoadTarga("in/rgb32rle.tga");
 
159
        Scaled = iluScaleImage(Image, 100, 100);
 
160
        ilSaveTarga("out/scaled small.tga", Scaled, NULL);
 
161
        ilCloseImage(Scaled);
 
162
        Scaled = iluScaleImage(Image, 400, 400);
 
163
        ilSaveTarga("out/scaled large.tga", Scaled, NULL);
 
164
        ilCloseImage(Scaled);
 
165
        ilSaveTarga("out/rgb32rle.tga", Image, NULL);
 
166
        ilCloseImage(Image);
 
167
 
 
168
        Image = ilLoadTarga("in/rgb24.tga");
 
169
        ilSaveTarga("out/rgb24.tga", Image, NULL);
 
170
        ilCloseImage(Image);
 
171
 
 
172
        Image = ilLoadTarga("in/rgb24rle.tga");
 
173
        ilSaveTarga("out/rgb24rle.tga", Image, NULL);
 
174
        ilCloseImage(Image);
 
175
 
 
176
 
 
177
        //Image = ilLoadTarga("in/rgb8.tga");
 
178
        //Image = ilLoadTarga("default1.tga");
 
179
        Image = ilLoadTarga("in/hardrle.tga");
 
180
        GLubyte *Verbatim = Image->Data, *Rle = (GLubyte*)malloc(Image->SizeOfData * 2);
 
181
        GLuint RleLen = 0, LineLen, OldSOD;
 
182
        for (GLuint i = 0; i < Image->SizeOfData; i += Image->Bps) {
 
183
                ilRleCompress(Image->Data + i, Image->Width, Image->Bpp, Rle + RleLen, &LineLen, IL_TGACOMP);
 
184
                RleLen += LineLen;
 
185
        }
 
186
        //ilRleCompress(Image->Data, Image->SizeOfData, 1, Rle, &LineLen, IL_TGACOMP);
 
187
        Image->Data = Rle;
 
188
        OldSOD = Image->SizeOfData;
 
189
        Image->SizeOfData = RleLen;
 
190
        ilSaveTarga("out/rlecomp.tga", Image, NULL);
 
191
        free(Image->Data);
 
192
        
 
193
        Image->Data = Verbatim;
 
194
        Image->SizeOfData = OldSOD;
 
195
 
 
196
 
 
197
        ilSaveTarga("out/rgb8.tga", Image, NULL);
 
198
        ilCloseImage(Image);
 
199
 
 
200
        Image = ilLoadTarga("in/grey.tga");
 
201
        ilSaveTarga("out/grey.tga", Image, NULL);
 
202
        ilCloseImage(Image);
 
203
 
 
204
        Image = ilLoadJpeg("default1.jpg");
 
205
        ilSaveJpeg("out/rgb24.jpg", Image, 99);
 
206
        ilSaveTarga("out/rgb24jpg.tga", Image, NULL);  // lossless, just to make sure of what it loaded
 
207
        ilCloseImage(Image);
 
208
 
 
209
        Image = ilCreateDefaultTex();
 
210
        ilSaveTarga("out/default.tga", Image, NULL);
 
211
        ilCloseImage(Image);
 
212
 
 
213
        ilPushAttrib(IL_ALL_ATTRIB_BITS);
 
214
        ilDisable(IL_ORIGIN_SET);
 
215
 
 
216
        Image = ilLoadPcx("in/rgb8.pcx");
 
217
        ilSaveTarga("out/rgb8pcx.tga", Image, NULL);
 
218
        ilCloseImage(Image);
 
219
 
 
220
        Image = ilLoadPcx("in/rgb24.pcx");
 
221
        ilSaveTarga("out/rgb24pcx.tga", Image, NULL);
 
222
        ilCloseImage(Image);
 
223
 
 
224
        Image = ilLoadSgi("in/jp_poster.tiny.rgb");
 
225
        ilSaveTarga("out/jp_poster.tga", Image, NULL);
 
226
        ilCloseImage(Image);
 
227
 
 
228
        ilPopAttrib();
 
229
 
 
230
 
 
231
        return;
 
232
}
 
233
 
 
234
 
 
235
void MemTest()
 
236
{
 
237
        ILimage *Image;
 
238
        char *Data;
 
239
        long FileLen;
 
240
        FILE *f = fopen("default1.tga", "rb");
 
241
 
 
242
        if (f == NULL)
 
243
                return;
 
244
 
 
245
        fseek(f, 0, SEEK_END);
 
246
        FileLen = ftell(f);
 
247
        Data = new char[FileLen];
 
248
        if (Data == NULL) {
 
249
                fclose(f);
 
250
                return;
 
251
        }
 
252
        fseek(f, 0, SEEK_SET);
 
253
        fread(Data, 1, FileLen, f);
 
254
        fclose(f);
 
255
 
 
256
        Image = ilLoadTargaL(Data, FileLen);
 
257
        ilSaveTarga("out/memtga.tga", Image, NULL);
 
258
 
 
259
        return;
 
260
}
 
261
 
 
262
 
 
263
ILimage* ILAPIENTRY LoadTest(char *FileName)
 
264
{
 
265
        printf("Load Test Function Ran\n");
 
266
        return NULL;
 
267
}
 
268
 
 
269
 
 
270
ILimage* ILAPIENTRY SaveTest(char *FileName, void *Data)
 
271
{
 
272
        printf("Save Test Function Ran\n");
 
273
        return NULL;
 
274
}
 
275
 
 
276
 
 
277
 
 
278
void RegTest()
 
279
{
 
280
        IL_LOADPROC LoadProc;
 
281
        IL_SAVEPROC SaveProc;
 
282
 
 
283
        ilRegisterFormat("xxx", LoadTest, SaveTest);
 
284
 
 
285
        LoadProc = (IL_LOADPROC)ilGetLoadProc("xxx");
 
286
        SaveProc = (IL_SAVEPROC)ilGetSaveProc("xxx");
 
287
 
 
288
        /*LoadProc("test.xxx");
 
289
        SaveProc("test.xxx", NULL);*/
 
290
 
 
291
        ilLoadImage("test.xxx");
 
292
}
 
293
 
 
294
 
 
295
void DoomTest()
 
296
{
 
297
        FILE *WadFile;
 
298
        ILimage *Face, *Wall, *Floor;
 
299
        GLboolean Found;
 
300
 
 
301
        WadFile = TestOpenWad("in/doomtest.wad");
 
302
        if (WadFile == NULL)
 
303
                return;
 
304
 
 
305
        Found = TestLocateLump("STFKILL0");
 
306
        Face = ilLoadDoomF(WadFile);
 
307
        if (Face == NULL) {
 
308
                fclose(WadFile);
 
309
                return;
 
310
        }
 
311
 
 
312
        if (ilLoadJascPal("in/doomtest.pal", &Face->Pal))
 
313
                ilSetDoomPal(Face->Pal.Palette);
 
314
 
 
315
        Found = TestLocateLump("WALL78_1");
 
316
        Wall = ilLoadDoomF(WadFile);
 
317
        if (Wall == NULL) {
 
318
                fclose(WadFile);
 
319
                return;
 
320
        }
 
321
 
 
322
        Found = TestLocateLump("FLOOR5_2");
 
323
        Floor = ilLoadDoomFlatF(WadFile);
 
324
        if (Floor == NULL) {
 
325
                fclose(WadFile);
 
326
                return;
 
327
        }
 
328
 
 
329
        ilSaveTarga("out/doomfloor.tga", Floor, NULL);
 
330
        ilSaveTarga("out/doomface.tga", Face, NULL);
 
331
        
 
332
        GLubyte a = 247;
 
333
        ilOverlayImage(Wall, Face, 52, 49, 0, &a);
 
334
        ilSaveTarga("out/doommixed.tga", Wall, NULL);
 
335
 
 
336
        ilCloseImage(Face);
 
337
        ilCloseImage(Wall);
 
338
        ilCloseImage(Floor);
 
339
 
 
340
        TestCloseWad();
 
341
        
 
342
        fclose(WadFile);
 
343
 
 
344
        return;
 
345
}
 
346
 
 
347
 
 
348
void IcoCurTest(void)
 
349
{
 
350
        ILimage* Image;
 
351
 
 
352
        Image = ilLoadIcon("in/icontest.ico");
 
353
        ilSaveTarga("out/icontest.tga", Image, NULL);
 
354
 
 
355
        FILE *f = fopen("a.txt", "wt");
 
356
        for (int i = 0; i < 7000; i++) {
 
357
                fprintf(f, "%d\n", Image->Data[i]);
 
358
        }
 
359
        fclose(f);
 
360
        ilCloseImage(Image);
 
361
}
 
362
 
 
363
 
 
364
void BitTest(void)
 
365
{
 
366
        BITFILE *File;
 
367
        GLubyte Buff[32];
 
368
 
 
369
        File = bopen("in/bit test.bt", "rw");
 
370
        if (File == NULL)
 
371
                return;
 
372
 
 
373
        bread(Buff, 1, 32, File);
 
374
 
 
375
 
 
376
        bclose(File);
 
377
}
 
 
b'\\ No newline at end of file'