1 //-----------------------------------------------------------------------------
2 //
3 // ImageLib Sources
4 // Copyright (C) 2000-2009 by Denton Woods
5 // Last modified: 02/12/2009
6 //
7 // Filename: src-IL/src/il_ftx.c
8 //
9 // Description: Reads from a Heavy Metal: FAKK2 (.ftx) file.
10 //
11 //-----------------------------------------------------------------------------
12
13 #include "il_internal.h"
14 #ifndef IL_NO_FTX
15
16 ILboolean iLoadFtxInternal(void);
17
18
19 //! Reads a FTX file
ilLoadFtx(ILconst_string FileName)20 ILboolean ilLoadFtx(ILconst_string FileName)
21 {
22 ILHANDLE FtxFile;
23 ILboolean bFtx = IL_FALSE;
24
25 FtxFile = iopenr(FileName);
26 if (FtxFile == NULL) {
27 ilSetError(IL_COULD_NOT_OPEN_FILE);
28 return bFtx;
29 }
30
31 bFtx = ilLoadFtxF(FtxFile);
32 icloser(FtxFile);
33
34 return bFtx;
35 }
36
37
38 //! Reads an already-opened FTX file
ilLoadFtxF(ILHANDLE File)39 ILboolean ilLoadFtxF(ILHANDLE File)
40 {
41 ILuint FirstPos;
42 ILboolean bRet;
43
44 iSetInputFile(File);
45 FirstPos = itell();
46 bRet = iLoadFtxInternal();
47 iseek(FirstPos, IL_SEEK_SET);
48
49 return bRet;
50 }
51
52
53 //! Reads from a memory "lump" that contains a FTX
ilLoadFtxL(const void * Lump,ILuint Size)54 ILboolean ilLoadFtxL(const void *Lump, ILuint Size)
55 {
56 iSetInputLump(Lump, Size);
57 return iLoadFtxInternal();
58 }
59
60
61 // Internal function used to load the FTX.
iLoadFtxInternal(void)62 ILboolean iLoadFtxInternal(void)
63 {
64 ILuint Width, Height, HasAlpha;
65
66 if (iCurImage == NULL) {
67 ilSetError(IL_ILLEGAL_OPERATION);
68 return IL_FALSE;
69 }
70
71 Width = GetLittleUInt();
72 Height = GetLittleUInt();
73 HasAlpha = GetLittleUInt(); // Kind of backwards from what I would think...
74
75 //@TODO: Right now, it appears that all images are in RGBA format. See if I can find specs otherwise
76 // or images that load incorrectly like this.
77 //if (HasAlpha == 0) { // RGBA format
78 if (!ilTexImage(Width, Height, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, NULL))
79 return IL_FALSE;
80 //}
81 //else if (HasAlpha == 1) { // RGB format
82 // if (!ilTexImage(Width, Height, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, NULL))
83 // return IL_FALSE;
84 //}
85 //else { // Unknown format
86 // ilSetError(IL_INVALID_FILE_HEADER);
87 // return IL_FALSE;
88 //}
89
90 // The origin will always be in the upper left.
91 iCurImage->Origin = IL_ORIGIN_UPPER_LEFT;
92
93 // All we have to do for this format is read the raw, uncompressed data.
94 if (iread(iCurImage->Data, 1, iCurImage->SizeOfData) != iCurImage->SizeOfData)
95 return IL_FALSE;
96
97 return ilFixImage();
98 }
99
100 #endif//IL_NO_FTX
101
102