- Main Page
- Data Structures
- Files

- File List

# E:/DevIL/src-IL/src/il_lif.c

    00001 //-----------------------------------------------------------------------------
    00002 //
    00003 // ImageLib Sources
    00004 // Copyright (C) 2000-2002 by Denton Woods
    00005 // Last modified: 05/25/2001 <--Y2K Compliant! =]
    00006 //
    00007 // Filename: src-IL/src/il_lif.c
    00008 //
    00009 // Description: Reads a Homeworld image.
    00010 //
    00011 //-----------------------------------------------------------------------------
    00012
    00013
    00014 #include "il_internal.h"
    00015 #ifndef IL_NO_LIF
    00016 #include "il_lif.h"
    00017
    00018
    00020 ILboolean ilIsValidLif(ILconst_string FileName)
    00021 {
    00022         ILHANDLE        LifFile;
    00023         ILboolean       bLif = IL_FALSE;
    00024
    00025         if (!iCheckExtension(FileName, IL_TEXT("lif"))) {
    00026                 ilSetError(IL_INVALID_EXTENSION);
    00027                 return bLif;
    00028         }
    00029
    00030         LifFile = iopenr(FileName);
    00031         if (LifFile == NULL) {
    00032                 ilSetError(IL_COULD_NOT_OPEN_FILE);
    00033                 return bLif;
    00034         }
    00035
    00036         bLif = ilIsValidLifF(LifFile);
    00037         icloser(LifFile);
    00038
    00039         return bLif;
    00040 }
    00041
    00042
    00044 ILboolean ilIsValidLifF(ILHANDLE File)
    00045 {
    00046         ILuint          FirstPos;
    00047         ILboolean       bRet;
    00048
    00049         iSetInputFile(File);
    00050         FirstPos = itell();
    00051         bRet = iIsValidLif();
    00052         iseek(FirstPos, IL_SEEK_SET);
    00053
    00054         return bRet;
    00055 }
    00056
    00057
    00059 ILboolean ilIsValidLifL(const void *Lump, ILuint Size)
    00060 {
    00061         iSetInputLump(Lump, Size);
    00062         return iIsValidLif();
    00063 }
    00064
    00065
    00066 // Internal function used to get the Lif header from the current file.
    00067 ILboolean iGetLifHead(LIF_HEAD *Header)
    00068 {
    00069
    00070         iread(Header->Id, 1, 8);
    00071
    00072         Header->Version = GetLittleUInt();
    00073
    00074         Header->Flags = GetLittleUInt();
    00075
    00076         Header->Width = GetLittleUInt();
    00077
    00078         Header->Height = GetLittleUInt();
    00079
    00080         Header->PaletteCRC = GetLittleUInt();
    00081
    00082         Header->ImageCRC = GetLittleUInt();
    00083
    00084         Header->PalOffset = GetLittleUInt();
    00085
    00086         Header->TeamEffect0 = GetLittleUInt();
    00087
    00088         Header->TeamEffect1 = GetLittleUInt();
    00089
    00090
    00091         return IL_TRUE;
    00092 }
    00093
    00094
    00095 // Internal function to get the header and check it.
    00096 ILboolean iIsValidLif()
    00097 {
    00098         LIF_HEAD        Head;
    00099
    00100         if (!iGetLifHead(&Head))
    00101                 return IL_FALSE;
    00102         iseek(-(ILint)sizeof(LIF_HEAD), IL_SEEK_CUR);
    00103
    00104         return iCheckLif(&Head);
    00105 }
    00106
    00107
    00108 // Internal function used to check if the HEADER is a valid Lif header.
    00109 ILboolean iCheckLif(LIF_HEAD *Header)
    00110 {
    00111         if (Header->Version != 260 || Header->Flags != 50)
    00112                 return IL_FALSE;
    00113         if (stricmp(Header->Id, "Willy 7"))
    00114                 return IL_FALSE;
    00115         return IL_TRUE;
    00116 }
    00117
    00118
    00120 ILboolean ilLoadLif(ILconst_string FileName)
    00121 {
    00122         ILHANDLE        LifFile;
    00123         ILboolean       bLif = IL_FALSE;
    00124
    00125         LifFile = iopenr(FileName);
    00126         if (LifFile == NULL) {
    00127                 ilSetError(IL_COULD_NOT_OPEN_FILE);
    00128                 return bLif;
    00129         }
    00130
    00131         bLif = ilLoadLifF(LifFile);
    00132         icloser(LifFile);
    00133
    00134         return bLif;
    00135 }
    00136
    00137
    00139 ILboolean ilLoadLifF(ILHANDLE File)
    00140 {
    00141         ILuint          FirstPos;
    00142         ILboolean       bRet;
    00143
    00144         iSetInputFile(File);
    00145         FirstPos = itell();
    00146         bRet = iLoadLifInternal();
    00147         iseek(FirstPos, IL_SEEK_SET);
    00148
    00149         return bRet;
    00150 }
    00151
    00152
    00154 ILboolean ilLoadLifL(const void *Lump, ILuint Size)
    00155 {
    00156         iSetInputLump(Lump, Size);
    00157         return iLoadLifInternal();
    00158 }
    00159
    00160
    00161 ILboolean iLoadLifInternal()
    00162 {
    00163         LIF_HEAD        LifHead;
    00164         ILuint          i;
    00165
    00166         if (iCurImage == NULL) {
    00167                 ilSetError(IL_ILLEGAL_OPERATION);
    00168                 return IL_FALSE;
    00169         }
    00170
    00171         if (!iGetLifHead(&LifHead))
    00172                 return IL_FALSE;
    00173
    00174         if (!ilTexImage(LifHead.Width, LifHead.Height, 1, 1, IL_COLOUR_INDEX, IL_UNSIGNED_BYTE, NULL)) {
    00175                 return IL_FALSE;
    00176         }
    00177         iCurImage->Origin = IL_ORIGIN_UPPER_LEFT;
    00178
    00179         iCurImage->Pal.Palette = (ILubyte*)ialloc(1024);
    00180         if (iCurImage->Pal.Palette == NULL)
    00181                 return IL_FALSE;
    00182         iCurImage->Pal.PalSize = 1024;
    00183         iCurImage->Pal.PalType = IL_PAL_RGBA32;
    00184
    00185         if (iread(iCurImage->Data, LifHead.Width * LifHead.Height, 1) != 1)
    00186                 return IL_FALSE;
    00187         if (iread(iCurImage->Pal.Palette, 1, 1024) != 1024)
    00188                 return IL_FALSE;
    00189
    00190         // Each data offset is offset by -1, so we add one.
    00191         for (i = 0; i < iCurImage->SizeOfData; i++) {
    00192                 iCurImage->Data[i]++;
    00193         }
    00194
    00195         ilFixImage();
    00196
    00197         return IL_TRUE;
    00198 }
    00199
    00200 #endif//IL_NO_LIF