- Main Page
- Data Structures
- Files

- File List

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

    00001 //-----------------------------------------------------------------------------
    00002 //
    00003 // ImageLib Sources
    00004 // Copyright (C) 2000-2002 by Denton Woods
    00005 // Last modified: 03/15/2002 <--Y2K Compliant! =]
    00006 //
    00007 // Filename: src-IL/src/il_pal.c
    00008 //
    00009 // Description: Loads palettes from different file formats
    00010 //
    00011 //-----------------------------------------------------------------------------
    00012
    00013
    00014 #include "il_internal.h"
    00015 #include "il_pal.h"
    00016 #include <string.h>
    00017 #include <ctype.h>
    00018 #include <limits.h>
    00019
    00020
    00022 ILboolean ILAPIENTRY ilLoadPal(ILconst_string FileName)
    00023 {
    00024         FILE            *f;
    00025         ILboolean       IsPsp;
    00026         char            Head[8];
    00027
    00028         if (FileName == NULL) {
    00029                 ilSetError(IL_INVALID_PARAM);
    00030                 return IL_FALSE;
    00031         }
    00032
    00033         if (iCheckExtension(FileName, IL_TEXT("col"))) {
    00034                 return ilLoadColPal(FileName);
    00035         }
    00036         if (iCheckExtension(FileName, IL_TEXT("act"))) {
    00037                 return ilLoadActPal(FileName);
    00038         }
    00039         if (iCheckExtension(FileName, IL_TEXT("plt"))) {
    00040                 return ilLoadPltPal(FileName);
    00041         }
    00042
    00043 #ifndef _UNICODE
    00044         f = fopen(FileName, "rt");
    00045 #else
    00046         f = _wfopen(FileName, L"rt");
    00047 #endif//_UNICODE
    00048         if (f == NULL) {
    00049                 ilSetError(IL_COULD_NOT_OPEN_FILE);
    00050                 return IL_FALSE;
    00051         }
    00052
    00053         fread(Head, 1, 8, f);
    00054         if (!strncmp(Head, "JASC-PAL", 8))
    00055                 IsPsp = IL_TRUE;
    00056         else
    00057                 IsPsp = IL_FALSE;
    00058
    00059         fclose(f);
    00060
    00061         if (IsPsp)
    00062                 return ilLoadJascPal(FileName);
    00063         return ilLoadHaloPal(FileName);
    00064 }
    00065
    00066
    00068 ILboolean ilLoadJascPal(ILconst_string FileName)
    00069 {
    00070         FILE *PalFile;
    00071         ILuint NumColours, i, c;
    00072         ILubyte Buff[BUFFLEN];
    00073         ILboolean Error = IL_FALSE;
    00074         ILpal *Pal = &iCurImage->Pal;
    00075
    00076         if (!iCheckExtension(FileName, IL_TEXT("pal"))) {
    00077                 ilSetError(IL_INVALID_EXTENSION);
    00078                 return IL_FALSE;
    00079         }
    00080
    00081         if (iCurImage == NULL) {
    00082                 ilSetError(IL_ILLEGAL_OPERATION);
    00083                 return IL_FALSE;
    00084         }
    00085
    00086 #ifndef _UNICODE
    00087         PalFile = fopen(FileName, "rt");
    00088 #else
    00089         PalFile = _wfopen(FileName, L"rt");
    00090 #endif//_UNICODE
    00091         if (PalFile == NULL) {
    00092                 ilSetError(IL_COULD_NOT_OPEN_FILE);
    00093                 return IL_FALSE;
    00094         }
    00095
    00096         if (iCurImage->Pal.Palette && iCurImage->Pal.PalSize > 0 && iCurImage->Pal.PalType != IL_PAL_NONE) {
    00097                 ifree(iCurImage->Pal.Palette);
    00098                 iCurImage->Pal.Palette = NULL;
    00099         }
    00100
    00101         iFgetw(Buff, BUFFLEN, PalFile);
    00102         if (stricmp((const char*)Buff, "JASC-PAL")) {
    00103                 Error = IL_TRUE;
    00104         }
    00105         iFgetw(Buff, BUFFLEN, PalFile);
    00106         if (stricmp((const char*)Buff, "0100")) {
    00107                 Error = IL_TRUE;
    00108         }
    00109
    00110         iFgetw(Buff, BUFFLEN, PalFile);
    00111         NumColours = atoi((const char*)Buff);
    00112         if (NumColours == 0 || Error) {
    00113                 ilSetError(IL_INVALID_FILE_HEADER);
    00114                 fclose(PalFile);
    00115                 return IL_FALSE;
    00116         }
    00117
    00118         Pal->PalSize = NumColours * PALBPP;
    00119         Pal->PalType = IL_PAL_RGB24;
    00120         Pal->Palette = (ILubyte*)ialloc(NumColours * PALBPP);
    00121         if (Pal->Palette == NULL) {
    00122                 fclose(PalFile);
    00123                 return IL_FALSE;
    00124         }
    00125
    00126         for (i = 0; i < NumColours; i++) {
    00127                 for (c = 0; c < PALBPP; c++) {
    00128                         iFgetw(Buff, BUFFLEN, PalFile);
    00129                         Pal->Palette[i * PALBPP + c] = atoi((const char*)Buff);
    00130                 }
    00131         }
    00132
    00133         fclose(PalFile);
    00134
    00135         return IL_TRUE;
    00136 }
    00137
    00138
    00139 // File Get Word
    00140 //      MaxLen must be greater than 1, because the trailing NULL is always stored.
    00141 char *iFgetw(ILubyte *Buff, ILint MaxLen, FILE *File)
    00142 {
    00143         ILint Temp;
    00144         ILint i;
    00145
    00146         if (Buff == NULL || File == NULL || MaxLen < 2) {
    00147                 ilSetError(IL_INVALID_PARAM);
    00148                 return NULL;
    00149         }
    00150
    00151         for (i = 0; i < MaxLen - 1; i++) {
    00152                 Temp = fgetc(File);
    00153                 if (Temp == '\n' || Temp == '\0' || Temp == IL_EOF || feof(File)) {
    00154                         break;
    00155                 }
    00156
    00157                 if (Temp == ' ') {
    00158                         while (Temp == ' ') {  // Just to get rid of any extra spaces
    00159                                 Temp = fgetc(File);
    00160                         }
    00161                         fseek(File, -1, IL_SEEK_CUR);  // Go back one
    00162                         break;
    00163                 }
    00164
    00165                 if (!isprint(Temp)) {  // Skips any non-printing characters
    00166                         while (!isprint(Temp)) {
    00167                                 Temp = fgetc(File);
    00168                         }
    00169                         fseek(File, -1, IL_SEEK_CUR);
    00170                         break;
    00171                 }
    00172
    00173                 Buff[i] = Temp;
    00174         }
    00175
    00176         Buff[i] = '\0';
    00177         return (char *)Buff;
    00178 }
    00179
    00180
    00181 ILboolean ILAPIENTRY ilSavePal(ILconst_string FileName)
    00182 {
    00183         ILstring Ext = iGetExtension(FileName);
    00184
    00185         if (iCurImage == NULL) {
    00186                 ilSetError(IL_ILLEGAL_OPERATION);
    00187                 return IL_FALSE;
    00188         }
    00189
    00190 #ifndef _UNICODE
    00191         if (FileName == NULL || strlen(FileName) < 1 || Ext == NULL) {
    00192 #else
    00193         if (FileName == NULL || wcslen(FileName) < 1 || Ext == NULL) {
    00194 #endif//_UNICODE
    00195                 ilSetError(IL_INVALID_PARAM);
    00196                 return IL_FALSE;
    00197         }
    00198
    00199         if (!iCurImage->Pal.Palette || !iCurImage->Pal.PalSize || iCurImage->Pal.PalType == IL_PAL_NONE) {
    00200                 ilSetError(IL_ILLEGAL_OPERATION);
    00201                 return IL_FALSE;
    00202         }
    00203
    00204         if (!iStrCmp(Ext, IL_TEXT("pal"))) {
    00205                 return ilSaveJascPal(FileName);
    00206         }
    00207
    00208         ilSetError(IL_INVALID_EXTENSION);
    00209         return IL_FALSE;
    00210 }
    00211
    00212
    00214 ILboolean ilSaveJascPal(ILconst_string FileName)
    00215 {
    00216         FILE    *PalFile;
    00217         ILuint  i, PalBpp, NumCols = ilGetInteger(IL_PALETTE_NUM_COLS);
    00218         ILubyte *CurPal;
    00219
    00220         if (iCurImage == NULL || NumCols == 0 || NumCols > 256) {
    00221                 ilSetError(IL_ILLEGAL_OPERATION);
    00222                 return IL_FALSE;
    00223         }
    00224
    00225 #ifndef _UNICODE
    00226         if (FileName == NULL || strlen(FileName) < 5) {
    00227 #else
    00228         if (FileName == NULL || wcslen(FileName) < 5) {
    00229 #endif//_UNICODE
    00230                 ilSetError(IL_INVALID_VALUE);
    00231                 return IL_FALSE;
    00232         }
    00233
    00234         if (!iCheckExtension(FileName, IL_TEXT("pal"))) {
    00235                 ilSetError(IL_INVALID_EXTENSION);
    00236                 return IL_FALSE;
    00237         }
    00238
    00239         if (ilGetBoolean(IL_FILE_MODE) == IL_FALSE) {
    00240                 if (iFileExists(FileName)) {
    00241                         ilSetError(IL_FILE_ALREADY_EXISTS);
    00242                         return IL_FALSE;
    00243                 }
    00244         }
    00245
    00246         // Create a copy of the current palette and convert it to RGB24 format.
    00247         CurPal = iCurImage->Pal.Palette;
    00248         iCurImage->Pal.Palette = (ILubyte*)ialloc(iCurImage->Pal.PalSize);
    00249         if (!iCurImage->Pal.Palette) {
    00250                 iCurImage->Pal.Palette = CurPal;
    00251                 return IL_FALSE;
    00252         }
    00253
    00254         memcpy(iCurImage->Pal.Palette, CurPal, iCurImage->Pal.PalSize);
    00255         if (!ilConvertPal(IL_PAL_RGB24)) {
    00256                 ifree(iCurImage->Pal.Palette);
    00257                 iCurImage->Pal.Palette = CurPal;
    00258                 return IL_FALSE;
    00259         }
    00260
    00261 #ifndef _UNICODE
    00262         PalFile = fopen(FileName, "wt");
    00263 #else
    00264         PalFile = _wfopen(FileName, L"wt");
    00265 #endif//_UNICODE
    00266         if (!PalFile) {
    00267                 ilSetError(IL_COULD_NOT_OPEN_FILE);
    00268                 return IL_FALSE;
    00269         }
    00270
    00271         // Header needed on all .pal files
    00272         fputs("JASC-PAL\n0100\n256\n", PalFile);
    00273
    00274         PalBpp = ilGetBppPal(iCurImage->Pal.PalType);
    00275         for (i = 0; i < iCurImage->Pal.PalSize; i += PalBpp) {
    00276                 fprintf(PalFile, "%d %d %d\n",
    00277                         iCurImage->Pal.Palette[i], iCurImage->Pal.Palette[i+1], iCurImage->Pal.Palette[i+2]);
    00278         }
    00279
    00280         NumCols = 256 - NumCols;
    00281         for (i = 0; i < NumCols; i++) {
    00282                 fprintf(PalFile, "0 0 0\n");
    00283         }
    00284
    00285         ifree(iCurImage->Pal.Palette);
    00286         iCurImage->Pal.Palette = CurPal;
    00287
    00288         fclose(PalFile);
    00289
    00290         return IL_TRUE;
    00291 }
    00292
    00293
    00295 ILboolean ilLoadHaloPal(ILconst_string FileName)
    00296 {
    00297         ILHANDLE        HaloFile;
    00298         HALOHEAD        HaloHead;
    00299         ILushort        *TempPal;
    00300         ILuint          i, Size;
    00301
    00302         if (!iCheckExtension(FileName, IL_TEXT("pal"))) {
    00303                 ilSetError(IL_INVALID_EXTENSION);
    00304                 return IL_FALSE;
    00305         }
    00306
    00307         if (iCurImage == NULL) {
    00308                 ilSetError(IL_ILLEGAL_OPERATION);
    00309                 return IL_FALSE;
    00310         }
    00311
    00312         HaloFile = iopenr(FileName);
    00313         if (HaloFile == NULL) {
    00314                 ilSetError(IL_COULD_NOT_OPEN_FILE);
    00315                 return IL_FALSE;
    00316         }
    00317
    00318         if (iread(&HaloHead, sizeof(HALOHEAD), 1) != 1)
    00319                 return IL_FALSE;
    00320
    00321         if (HaloHead.Id != 'A' + ('H' << 8) || HaloHead.Version != 0xe3) {
    00322                 icloser(HaloFile);
    00323                 ilSetError(IL_ILLEGAL_FILE_VALUE);
    00324                 return IL_FALSE;
    00325         }
    00326
    00327         Size = (HaloHead.MaxIndex + 1) * 3;
    00328         TempPal = (ILushort*)ialloc(Size * sizeof(ILushort));
    00329         if (TempPal == NULL) {
    00330                 icloser(HaloFile);
    00331                 return IL_FALSE;
    00332         }
    00333
    00334         if (iread(TempPal, sizeof(ILushort), Size) != Size) {
    00335                 icloser(HaloFile);
    00336                 ifree(TempPal);
    00337                 return IL_FALSE;
    00338         }
    00339
    00340         if (iCurImage->Pal.Palette && iCurImage->Pal.PalSize > 0 && iCurImage->Pal.PalType != IL_PAL_NONE) {
    00341                 ifree(iCurImage->Pal.Palette);
    00342                 iCurImage->Pal.Palette = NULL;
    00343         }
    00344         iCurImage->Pal.PalType = IL_PAL_RGB24;
    00345         iCurImage->Pal.PalSize = Size;
    00346         iCurImage->Pal.Palette = (ILubyte*)ialloc(iCurImage->Pal.PalSize);
    00347         if (iCurImage->Pal.Palette == NULL) {
    00348                 icloser(HaloFile);
    00349                 return IL_FALSE;
    00350         }
    00351
    00352         for (i = 0; i < iCurImage->Pal.PalSize; i++, TempPal++) {
    00353                 iCurImage->Pal.Palette[i] = (ILubyte)*TempPal;
    00354         }
    00355         TempPal -= iCurImage->Pal.PalSize;
    00356         ifree(TempPal);
    00357
    00358         icloser(HaloFile);
    00359
    00360         return IL_TRUE;
    00361 }
    00362
    00363
    00364 // Hasn't been tested
    00365 //      @TODO: Test the thing!
    00366
    00368 ILboolean ilLoadColPal(ILconst_string FileName)
    00369 {
    00370         ILuint          RealFileSize, FileSize;
    00371         ILushort        Version;
    00372         ILHANDLE        ColFile;
    00373
    00374         if (!iCheckExtension(FileName, IL_TEXT("col"))) {
    00375                 ilSetError(IL_INVALID_EXTENSION);
    00376                 return IL_FALSE;
    00377         }
    00378
    00379         if (iCurImage == NULL) {
    00380                 ilSetError(IL_ILLEGAL_OPERATION);
    00381                 return IL_FALSE;
    00382         }
    00383
    00384         ColFile = iopenr(FileName);
    00385         if (ColFile == NULL) {
    00386                 ilSetError(IL_COULD_NOT_OPEN_FILE);
    00387                 return IL_FALSE;
    00388         }
    00389
    00390         if (iCurImage->Pal.Palette && iCurImage->Pal.PalSize > 0 && iCurImage->Pal.PalType != IL_PAL_NONE) {
    00391                 ifree(iCurImage->Pal.Palette);
    00392                 iCurImage->Pal.Palette = NULL;
    00393         }
    00394
    00395         iseek(0, IL_SEEK_END);
    00396         RealFileSize = ftell((FILE*)ColFile);
    00397         iseek(0, IL_SEEK_SET);
    00398
    00399         if (RealFileSize > 768) {  // has a header
    00400                 fread(&FileSize, 4, 1, (FILE*)ColFile);
    00401                 if ((FileSize - 8) % 3 != 0) {  // check to make sure an even multiple of 3!
    00402                         icloser(ColFile);
    00403                         ilSetError(IL_ILLEGAL_FILE_VALUE);
    00404                         return IL_FALSE;
    00405                 }
    00406                 if (iread(&Version, 2, 1) != 1) {
    00407                         icloser(ColFile);
    00408                         return IL_FALSE;
    00409                 }
    00410                 if (Version != 0xB123) {
    00411                         icloser(ColFile);
    00412                         ilSetError(IL_ILLEGAL_FILE_VALUE);
    00413                         return IL_FALSE;
    00414                 }
    00415                 if (iread(&Version, 2, 1) != 1) {
    00416                         icloser(ColFile);
    00417                         return IL_FALSE;
    00418                 }
    00419                 if (Version != 0) {
    00420                         icloser(ColFile);
    00421                         ilSetError(IL_ILLEGAL_FILE_VALUE);
    00422                         return IL_FALSE;
    00423                 }
    00424         }
    00425
    00426         iCurImage->Pal.Palette = (ILubyte*)ialloc(768);
    00427         if (iCurImage->Pal.Palette == NULL) {
    00428                 icloser(ColFile);
    00429                 return IL_FALSE;
    00430         }
    00431
    00432         if (iread(iCurImage->Pal.Palette, 1, 768) != 768) {
    00433                 icloser(ColFile);
    00434                 ifree(iCurImage->Pal.Palette);
    00435                 iCurImage->Pal.Palette = NULL;
    00436                 return IL_FALSE;
    00437         }
    00438
    00439         iCurImage->Pal.PalSize = 768;
    00440         iCurImage->Pal.PalType = IL_PAL_RGB24;
    00441
    00442         icloser(ColFile);
    00443
    00444         return IL_TRUE;
    00445 }
    00446
    00447
    00449 ILboolean ilLoadActPal(ILconst_string FileName)
    00450 {
    00451         ILHANDLE        ActFile;
    00452
    00453         if (!iCheckExtension(FileName, IL_TEXT("act"))) {
    00454                 ilSetError(IL_INVALID_EXTENSION);
    00455                 return IL_FALSE;
    00456         }
    00457
    00458         if (iCurImage == NULL) {
    00459                 ilSetError(IL_ILLEGAL_OPERATION);
    00460                 return IL_FALSE;
    00461         }
    00462
    00463         ActFile = iopenr(FileName);
    00464         if (ActFile == NULL) {
    00465                 ilSetError(IL_COULD_NOT_OPEN_FILE);
    00466                 return IL_FALSE;
    00467         }
    00468
    00469         if (iCurImage->Pal.Palette && iCurImage->Pal.PalSize > 0 && iCurImage->Pal.PalType != IL_PAL_NONE) {
    00470                 ifree(iCurImage->Pal.Palette);
    00471                 iCurImage->Pal.Palette = NULL;
    00472         }
    00473
    00474         iCurImage->Pal.PalType = IL_PAL_RGB24;
    00475         iCurImage->Pal.PalSize = 768;
    00476         iCurImage->Pal.Palette = (ILubyte*)ialloc(768);
    00477         if (!iCurImage->Pal.Palette) {
    00478                 icloser(ActFile);
    00479                 return IL_FALSE;
    00480         }
    00481
    00482         if (iread(iCurImage->Pal.Palette, 1, 768) != 768) {
    00483                 icloser(ActFile);
    00484                 return IL_FALSE;
    00485         }
    00486
    00487         icloser(ActFile);
    00488
    00489         return IL_TRUE;
    00490 }
    00491
    00492
    00494 ILboolean ilLoadPltPal(ILconst_string FileName)
    00495 {
    00496         ILHANDLE        PltFile;
    00497
    00498         if (!iCheckExtension(FileName, IL_TEXT("plt"))) {
    00499                 ilSetError(IL_INVALID_EXTENSION);
    00500                 return IL_FALSE;
    00501         }
    00502
    00503         if (iCurImage == NULL) {
    00504                 ilSetError(IL_ILLEGAL_OPERATION);
    00505                 return IL_FALSE;
    00506         }
    00507
    00508         PltFile = iopenr(FileName);
    00509         if (PltFile == NULL) {
    00510                 ilSetError(IL_COULD_NOT_OPEN_FILE);
    00511                 return IL_FALSE;
    00512         }
    00513
    00514         if (iCurImage->Pal.Palette && iCurImage->Pal.PalSize > 0 && iCurImage->Pal.PalType != IL_PAL_NONE) {
    00515                 ifree(iCurImage->Pal.Palette);
    00516                 iCurImage->Pal.Palette = NULL;
    00517         }
    00518
    00519         iCurImage->Pal.PalSize = GetLittleUInt();
    00520         if (iCurImage->Pal.PalSize == 0) {
    00521                 ilSetError(IL_INVALID_FILE_HEADER);
    00522                 return IL_FALSE;
    00523         }
    00524         iCurImage->Pal.PalType = IL_PAL_RGB24;
    00525         iCurImage->Pal.Palette = (ILubyte*)ialloc(iCurImage->Pal.PalSize);
    00526         if (!iCurImage->Pal.Palette) {
    00527                 icloser(PltFile);
    00528                 return IL_FALSE;
    00529         }
    00530
    00531         if (iread(iCurImage->Pal.Palette, iCurImage->Pal.PalSize, 1) != 1) {
    00532                 ifree(iCurImage->Pal.Palette);
    00533                 iCurImage->Pal.Palette = NULL;
    00534                 icloser(PltFile);
    00535                 return IL_FALSE;
    00536         }
    00537
    00538         icloser(PltFile);
    00539
    00540         return IL_TRUE;
    00541 }
    00542
    00543
    00544 ILAPI ILpal* ILAPIENTRY iCopyPal()
    00545 {
    00546         ILpal *Pal;
    00547
    00548         if (iCurImage == NULL || iCurImage->Pal.Palette == NULL ||
    00549                 iCurImage->Pal.PalSize == 0 || iCurImage->Pal.PalType == IL_PAL_NONE) {
    00550                 ilSetError(IL_ILLEGAL_OPERATION);
    00551                 return NULL;
    00552         }
    00553
    00554         Pal = (ILpal*)ialloc(sizeof(ILpal));
    00555         if (Pal == NULL) {
    00556                 return NULL;
    00557         }
    00558         Pal->Palette = (ILubyte*)ialloc(iCurImage->Pal.PalSize);
    00559         if (Pal->Palette == NULL) {
    00560                 ifree(Pal);
    00561                 return NULL;
    00562         }
    00563
    00564         memcpy(Pal->Palette, iCurImage->Pal.Palette, iCurImage->Pal.PalSize);
    00565         Pal->PalSize = iCurImage->Pal.PalSize;
    00566         Pal->PalType = iCurImage->Pal.PalType;
    00567
    00568         return Pal;
    00569 }
    00570
    00571
    00572 // Converts the palette to the DestFormat format.
    00573 ILAPI ILpal* ILAPIENTRY iConvertPal(ILpal *Pal, ILenum DestFormat)
    00574 {
    00575         ILpal   *NewPal = NULL;
    00576         ILuint  i, j, NewPalSize;
    00577
    00578         // Checks to see if the current image is valid and has a palette
    00579         if (Pal == NULL || Pal->PalSize == 0 || Pal->Palette == NULL || Pal->PalType == IL_PAL_NONE) {
    00580                 ilSetError(IL_ILLEGAL_OPERATION);
    00581                 return NULL;
    00582         }
    00583
    00584         /*if (Pal->PalType == DestFormat) {
    00585                 return NULL;
    00586         }*/
    00587
    00588         NewPal = (ILpal*)ialloc(sizeof(ILpal));
    00589         if (NewPal == NULL) {
    00590                 return NULL;
    00591         }
    00592         NewPal->PalSize = Pal->PalSize;
    00593         NewPal->PalType = Pal->PalType;
    00594
    00595         switch (DestFormat)
    00596         {
    00597                 case IL_PAL_RGB24:
    00598                 case IL_PAL_BGR24:
    00599                         switch (Pal->PalType)
    00600                         {
    00601                                 case IL_PAL_RGB24:
    00602                                         NewPal->Palette = (ILubyte*)ialloc(Pal->PalSize);
    00603                                         if (NewPal->Palette == NULL)
    00604                                                 goto alloc_error;
    00605                                         if (DestFormat == IL_PAL_BGR24) {
    00606                                                 j = ilGetBppPal(Pal->PalType);
    00607                                                 for (i = 0; i < Pal->PalSize; i += j) {
    00608                                                         NewPal->Palette[i] = Pal->Palette[i+2];
    00609                                                         NewPal->Palette[i+1] = Pal->Palette[i+1];
    00610                                                         NewPal->Palette[i+2] = Pal->Palette[i];
    00611                                                 }
    00612                                         }
    00613                                         else {
    00614                                                 memcpy(NewPal->Palette, Pal->Palette, Pal->PalSize);
    00615                                         }
    00616                                         NewPal->PalType = DestFormat;
    00617                                         break;
    00618
    00619                                 case IL_PAL_BGR24:
    00620                                         NewPal->Palette = (ILubyte*)ialloc(Pal->PalSize);
    00621                                         if (NewPal->Palette == NULL)
    00622                                                 goto alloc_error;
    00623                                         if (DestFormat == IL_PAL_RGB24) {
    00624                                                 j = ilGetBppPal(Pal->PalType);
    00625                                                 for (i = 0; i < Pal->PalSize; i += j) {
    00626                                                         NewPal->Palette[i] = Pal->Palette[i+2];
    00627                                                         NewPal->Palette[i+1] = Pal->Palette[i+1];
    00628                                                         NewPal->Palette[i+2] = Pal->Palette[i];
    00629                                                 }
    00630                                         }
    00631                                         else {
    00632                                                 memcpy(NewPal->Palette, Pal->Palette, Pal->PalSize);
    00633                                         }
    00634                                         NewPal->PalType = DestFormat;
    00635                                         break;
    00636
    00637                                 case IL_PAL_BGR32:
    00638                                 case IL_PAL_BGRA32:
    00639                                         NewPalSize = (ILuint)((ILfloat)Pal->PalSize * 3.0f / 4.0f);
    00640                                         NewPal->Palette = (ILubyte*)ialloc(NewPalSize);
    00641                                         if (NewPal->Palette == NULL)
    00642                                                 goto alloc_error;
    00643                                         if (DestFormat == IL_PAL_RGB24) {
    00644                                                 for (i = 0, j = 0; i < Pal->PalSize; i += 4, j += 3) {
    00645                                                         NewPal->Palette[j]   = Pal->Palette[i+2];
    00646                                                         NewPal->Palette[j+1] = Pal->Palette[i+1];
    00647                                                         NewPal->Palette[j+2] = Pal->Palette[i];
    00648                                                 }
    00649                                         }
    00650                                         else {
    00651                                                 for (i = 0, j = 0; i < Pal->PalSize; i += 4, j += 3) {
    00652                                                         NewPal->Palette[j]   = Pal->Palette[i];
    00653                                                         NewPal->Palette[j+1] = Pal->Palette[i+1];
    00654                                                         NewPal->Palette[j+2] = Pal->Palette[i+2];
    00655                                                 }
    00656                                         }
    00657                                         NewPal->PalSize = NewPalSize;
    00658                                         NewPal->PalType = DestFormat;
    00659                                         break;
    00660
    00661                                 case IL_PAL_RGB32:
    00662                                 case IL_PAL_RGBA32:
    00663                                         NewPalSize = (ILuint)((ILfloat)Pal->PalSize * 3.0f / 4.0f);
    00664                                         NewPal->Palette = (ILubyte*)ialloc(NewPalSize);
    00665                                         if (NewPal->Palette == NULL)
    00666                                                 goto alloc_error;
    00667                                         if (DestFormat == IL_PAL_RGB24) {
    00668                                                 for (i = 0, j = 0; i < Pal->PalSize; i += 4, j += 3) {
    00669                                                         NewPal->Palette[j]   = Pal->Palette[i];
    00670                                                         NewPal->Palette[j+1] = Pal->Palette[i+1];
    00671                                                         NewPal->Palette[j+2] = Pal->Palette[i+2];
    00672                                                 }
    00673                                         }
    00674                                         else {
    00675                                                 for (i = 0, j = 0; i < Pal->PalSize; i += 4, j += 3) {
    00676                                                         NewPal->Palette[j]   = Pal->Palette[i+2];
    00677                                                         NewPal->Palette[j+1] = Pal->Palette[i+1];
    00678                                                         NewPal->Palette[j+2] = Pal->Palette[i];
    00679                                                 }
    00680                                         }
    00681                                         NewPal->PalSize = NewPalSize;
    00682                                         NewPal->PalType = DestFormat;
    00683                                         break;
    00684
    00685                                 default:
    00686                                         ilSetError(IL_INVALID_PARAM);
    00687                                         return NULL;
    00688                         }
    00689                         break;
    00690
    00691                 case IL_PAL_RGB32:
    00692                 case IL_PAL_RGBA32:
    00693                 case IL_PAL_BGR32:
    00694                 case IL_PAL_BGRA32:
    00695                         switch (Pal->PalType)
    00696                         {
    00697                                 case IL_PAL_RGB24:
    00698                                 case IL_PAL_BGR24:
    00699                                         NewPalSize = Pal->PalSize * 4 / 3;
    00700                                         NewPal->Palette = (ILubyte*)ialloc(NewPalSize);
    00701                                         if (NewPal->Palette == NULL)
    00702                                                 goto alloc_error;
    00703                                         if ((Pal->PalType == IL_PAL_BGR24 && (DestFormat == IL_PAL_RGB32 || DestFormat == IL_PAL_RGBA32)) ||
    00704                                                 (Pal->PalType == IL_PAL_RGB24 && (DestFormat == IL_PAL_BGR32 || DestFormat == IL_PAL_BGRA32))) {
    00705                                                         for (i = 0, j = 0; i < Pal->PalSize; i += 3, j += 4) {
    00706                                                                 NewPal->Palette[j]   = Pal->Palette[i+2];
    00707                                                                 NewPal->Palette[j+1] = Pal->Palette[i+1];
    00708                                                                 NewPal->Palette[j+2] = Pal->Palette[i];
    00709                                                                 NewPal->Palette[j+3] = 255;
    00710                                                         }
    00711                                         }
    00712                                         else {
    00713                                                 for (i = 0, j = 0; i < Pal->PalSize; i += 3, j += 4) {
    00714                                                         NewPal->Palette[j]   = Pal->Palette[i];
    00715                                                         NewPal->Palette[j+1] = Pal->Palette[i+1];
    00716                                                         NewPal->Palette[j+2] = Pal->Palette[i+2];
    00717                                                         NewPal->Palette[j+3] = 255;
    00718                                                 }
    00719                                         }
    00720                                         NewPal->PalSize = NewPalSize;
    00721                                         NewPal->PalType = DestFormat;
    00722                                         break;
    00723
    00724                                 case IL_PAL_RGB32:
    00725                                         NewPal->Palette = (ILubyte*)ialloc(Pal->PalSize);
    00726                                         if (NewPal->Palette == NULL)
    00727                                                 goto alloc_error;
    00728
    00729                                         if (DestFormat == IL_PAL_BGR32 || DestFormat == IL_PAL_BGRA32) {
    00730                                                 for (i = 0; i < Pal->PalSize; i += 4) {
    00731                                                         NewPal->Palette[i]   = Pal->Palette[i+2];
    00732                                                         NewPal->Palette[i+1] = Pal->Palette[i+1];
    00733                                                         NewPal->Palette[i+2] = Pal->Palette[i];
    00734                                                         NewPal->Palette[i+3] = 255;
    00735                                                 }
    00736                                         }
    00737                                         else {
    00738                                                 for (i = 0; i < Pal->PalSize; i += 4) {
    00739                                                         NewPal->Palette[i]   = Pal->Palette[i];
    00740                                                         NewPal->Palette[i+1] = Pal->Palette[i+1];
    00741                                                         NewPal->Palette[i+2] = Pal->Palette[i+2];
    00742                                                         NewPal->Palette[i+3] = 255;
    00743                                                 }
    00744                                         }
    00745                                         NewPal->PalType = DestFormat;
    00746                                         break;
    00747
    00748                                 case IL_PAL_RGBA32:
    00749                                         NewPal->Palette = (ILubyte*)ialloc(Pal->PalSize);
    00750                                         if (NewPal->Palette == NULL)
    00751                                                 goto alloc_error;
    00752                                         if (DestFormat == IL_PAL_BGR32 || DestFormat == IL_PAL_BGRA32) {
    00753                                                 for (i = 0; i < Pal->PalSize; i += 4) {
    00754                                                         NewPal->Palette[i]   = Pal->Palette[i+2];
    00755                                                         NewPal->Palette[i+1] = Pal->Palette[i+1];
    00756                                                         NewPal->Palette[i+2] = Pal->Palette[i];
    00757                                                         NewPal->Palette[i+3] = Pal->Palette[i+3];
    00758                                                 }
    00759                                         }
    00760                                         else {
    00761                                                 memcpy(NewPal->Palette, Pal->Palette, Pal->PalSize);
    00762                                         }
    00763                                         NewPal->PalType = DestFormat;
    00764                                         break;
    00765
    00766                                 case IL_PAL_BGR32:
    00767                                         NewPal->Palette = (ILubyte*)ialloc(Pal->PalSize);
    00768                                         if (NewPal->Palette == NULL)
    00769                                                 goto alloc_error;
    00770                                         if (DestFormat == IL_PAL_RGB32 || DestFormat == IL_PAL_RGBA32) {
    00771                                                 for (i = 0; i < Pal->PalSize; i += 4) {
    00772                                                         NewPal->Palette[i]   = Pal->Palette[i+2];
    00773                                                         NewPal->Palette[i+1] = Pal->Palette[i+1];
    00774                                                         NewPal->Palette[i+2] = Pal->Palette[i];
    00775                                                         NewPal->Palette[i+3] = 255;
    00776                                                 }
    00777                                         }
    00778                                         else {
    00779                                                 for (i = 0; i < Pal->PalSize; i += 4) {
    00780                                                         NewPal->Palette[i]   = Pal->Palette[i];
    00781                                                         NewPal->Palette[i+1] = Pal->Palette[i+1];
    00782                                                         NewPal->Palette[i+2] = Pal->Palette[i+2];
    00783                                                         NewPal->Palette[i+3] = 255;
    00784                                                 }
    00785                                         }
    00786                                         NewPal->PalType = DestFormat;
    00787                                         break;
    00788
    00789                                 case IL_PAL_BGRA32:
    00790                                         NewPal->Palette = (ILubyte*)ialloc(Pal->PalSize);
    00791                                         if (NewPal->Palette == NULL)
    00792                                                 goto alloc_error;
    00793                                         if (DestFormat == IL_PAL_RGB32 || DestFormat == IL_PAL_RGBA32) {
    00794                                                 for (i = 0; i < Pal->PalSize; i += 4) {
    00795                                                         NewPal->Palette[i]   = Pal->Palette[i+2];
    00796                                                         NewPal->Palette[i+1] = Pal->Palette[i+1];
    00797                                                         NewPal->Palette[i+2] = Pal->Palette[i];
    00798                                                         NewPal->Palette[i+3] = Pal->Palette[i+3];
    00799                                                 }
    00800                                         }
    00801                                         else {
    00802                                                 memcpy(NewPal->Palette, Pal->Palette, Pal->PalSize);
    00803                                         }
    00804                                         NewPal->PalType = DestFormat;
    00805                                         break;
    00806
    00807                                 default:
    00808                                         ilSetError(IL_INVALID_PARAM);
    00809                                         return NULL;
    00810                         }
    00811                         break;
    00812
    00813
    00814                 default:
    00815                         ilSetError(IL_INVALID_PARAM);
    00816                         return NULL;
    00817         }
    00818
    00819         NewPal->PalType = DestFormat;
    00820
    00821         return NewPal;
    00822
    00823 alloc_error:
    00824         ifree(NewPal);
    00825         return NULL;
    00826 }
    00827
    00828
    00830 ILboolean ILAPIENTRY ilConvertPal(ILenum DestFormat)
    00831 {
    00832         ILpal *Pal;
    00833
    00834         if (iCurImage == NULL || iCurImage->Pal.Palette == NULL ||
    00835                 iCurImage->Pal.PalSize == 0 || iCurImage->Pal.PalType == IL_PAL_NONE) {
    00836                 ilSetError(IL_ILLEGAL_OPERATION);
    00837                 return IL_FALSE;
    00838         }
    00839
    00840         Pal = iConvertPal(&iCurImage->Pal, DestFormat);
    00841         if (Pal == NULL)
    00842                 return IL_FALSE;
    00843
    00844         ifree(iCurImage->Pal.Palette);
    00845         iCurImage->Pal.PalSize = Pal->PalSize;
    00846         iCurImage->Pal.PalType = Pal->PalType;
    00847
    00848         iCurImage->Pal.Palette = (ILubyte*)ialloc(Pal->PalSize);
    00849         if (iCurImage->Pal.Palette == NULL) {
    00850                 return IL_FALSE;
    00851         }
    00852         memcpy(iCurImage->Pal.Palette, Pal->Palette, Pal->PalSize);
    00853
    00854         ifree(Pal->Palette);
    00855         ifree(Pal);
    00856
    00857         return IL_TRUE;
    00858 }
    00859
    00860
    00861 // Sets the current palette.
    00862 ILAPI void ILAPIENTRY ilSetPal(ILpal *Pal)
    00863 {
    00864         if (iCurImage->Pal.Palette && iCurImage->Pal.PalSize && iCurImage->Pal.PalType != IL_PAL_NONE) {
    00865                 ifree(iCurImage->Pal.Palette);
    00866         }
    00867
    00868         if (Pal->Palette && Pal->PalSize && Pal->PalType != IL_PAL_NONE) {
    00869                 iCurImage->Pal.Palette = (ILubyte*)ialloc(Pal->PalSize);
    00870                 if (iCurImage->Pal.Palette == NULL)
    00871                         return;
    00872                 memcpy(iCurImage->Pal.Palette, Pal->Palette, Pal->PalSize);
    00873                 iCurImage->Pal.PalSize = Pal->PalSize;
    00874                 iCurImage->Pal.PalType = Pal->PalType;
    00875         }
    00876         else {
    00877                 iCurImage->Pal.Palette = NULL;
    00878                 iCurImage->Pal.PalSize = 0;
    00879                 iCurImage->Pal.PalType = IL_PAL_NONE;
    00880         }
    00881
    00882         return;
    00883 }
    00884
    00885
    00886 ILuint CurSort = 0;
    00887 typedef struct COL_CUBE
    00888 {
    00889         ILubyte Min[3];
    00890         ILubyte Val[3];
    00891         ILubyte Max[3];
    00892 } COL_CUBE;
    00893
    00894 int sort_func(void *e1, void *e2)
    00895 {
    00896         return ((COL_CUBE*)e1)->Val[CurSort] - ((COL_CUBE*)e2)->Val[CurSort];
    00897 }
    00898
    00899
    00900 ILboolean ILAPIENTRY ilApplyPal(ILconst_string FileName)
    00901 {
    00902         ILimage         Image, *CurImage = iCurImage;
    00903         ILubyte         *NewData;
    00904         ILuint          *PalInfo, NumColours, NumPix, MaxDist, DistEntry=0, i, j;
    00905         ILint           Dist1, Dist2, Dist3;
    00906         ILboolean       Same;
    00907         ILenum          Origin;
    00908 //      COL_CUBE        *Cubes;
    00909
    00910     if( iCurImage == NULL || (iCurImage->Format != IL_BYTE || iCurImage->Format != IL_UNSIGNED_BYTE) ) {
    00911         ilSetError(IL_ILLEGAL_OPERATION);
    00912         return IL_FALSE;
    00913     }
    00914
    00915         NewData = (ILubyte*)ialloc(iCurImage->Width * iCurImage->Height * iCurImage->Depth);
    00916         if (NewData == NULL) {
    00917                 return IL_FALSE;
    00918         }
    00919
    00920         iCurImage = &Image;
    00921         imemclear(&Image, sizeof(ILimage));
    00922         // IL_PAL_RGB24, because we don't want to make parts transparent that shouldn't be.
    00923         if (!ilLoadPal(FileName) || !ilConvertPal(IL_PAL_RGB24)) {
    00924                 ifree(NewData);
    00925                 iCurImage = CurImage;
    00926                 return IL_FALSE;
    00927         }
    00928
    00929         NumColours = Image.Pal.PalSize / 3;  // RGB24 is 3 bytes per entry.
    00930         PalInfo = (ILuint*)ialloc(NumColours * sizeof(ILuint));
    00931         if (PalInfo == NULL) {
    00932                 ifree(NewData);
    00933                 iCurImage = CurImage;
    00934                 return IL_FALSE;
    00935         }
    00936
    00937         NumPix = CurImage->SizeOfData / ilGetBppFormat(CurImage->Format);
    00938         switch (CurImage->Format)
    00939         {
    00940                 case IL_COLOUR_INDEX:
    00941                         iCurImage = CurImage;
    00942                         if (!ilConvertPal(IL_PAL_RGB24)) {
    00943                                 ifree(NewData);
    00944                                 ifree(PalInfo);
    00945                                 return IL_FALSE;
    00946                         }
    00947
    00948                         NumPix = iCurImage->Pal.PalSize / ilGetBppPal(iCurImage->Pal.PalType);
    00949                         for (i = 0; i < NumPix; i++) {
    00950                                 for (j = 0; j < Image.Pal.PalSize; j += 3) {
    00951                                         // No need to perform a sqrt.
    00952                                         Dist1 = (ILint)iCurImage->Pal.Palette[i] - (ILint)Image.Pal.Palette[j];
    00953                                         Dist2 = (ILint)iCurImage->Pal.Palette[i+1] - (ILint)Image.Pal.Palette[j+1];
    00954                                         Dist3 = (ILint)iCurImage->Pal.Palette[i+2] - (ILint)Image.Pal.Palette[j+2];
    00955                                         PalInfo[j / 3] = Dist1 * Dist1 + Dist2 * Dist2 + Dist3 * Dist3;
    00956                                 }
    00957                                 MaxDist = UINT_MAX;
    00958                                 DistEntry = 0;
    00959                                 for (j = 0; j < NumColours; j++) {
    00960                                         if (PalInfo[j] < MaxDist) {
    00961                                                 DistEntry = j;
    00962                                                 MaxDist = PalInfo[j];
    00963                                         }
    00964                                 }
    00965                                 iCurImage->Pal.Palette[i] = DistEntry;
    00966                         }
    00967
    00968                         for (i = 0; i < iCurImage->SizeOfData; i++) {
    00969                                 NewData[i] = iCurImage->Pal.Palette[iCurImage->Data[i]];
    00970                         }
    00971                         break;
    00972                 case IL_RGB:
    00973                 case IL_RGBA:
    00974                         /*Cube = (COL_CUBE*)ialloc(NumColours * sizeof(COL_CUBE));
    00975                         // @TODO:  Check if ialloc failed here!
    00976                         for (i = 0; i < NumColours; i++)
    00977                                 memcpy(&Cubes[i].Val, Image.Pal.Palette[i * 3], 3);
    00978                         for (j = 0; j < 3; j++) {
    00979                                 qsort(Cubes, NumColours, sizeof(COL_CUBE), sort_func);
    00980                                 Cubes[0].Min = 0;
    00981                                 Cubes[NumColours-1] = UCHAR_MAX;
    00982                                 NumColours--;
    00983                                 for (i = 1; i < NumColours; i++) {
    00984                                         Cubes[i].Min[CurSort] = Cubes[i-1].Val[CurSort] + 1;
    00985                                         Cubes[i-1].Max[CurSort] = Cubes[i].Val[CurSort] - 1;
    00986                                 }
    00987                                 CurSort++;
    00988                                 NumColours++;
    00989                         }*/
    00990                         for (i = 0; i < CurImage->SizeOfData; i += CurImage->Bpp) {
    00991                                 Same = IL_TRUE;
    00992                                 if (i != 0) {
    00993                                         for (j = 0; j < CurImage->Bpp; j++) {
    00994                                                 if (CurImage->Data[i-CurImage->Bpp+j] != CurImage->Data[i+j]) {
    00995                                                         Same = IL_FALSE;
    00996                                                         break;
    00997                                                 }
    00998                                         }
    00999                                 }
    01000                                 if (Same) {
    01001                                         NewData[i / CurImage->Bpp] = DistEntry;
    01002                                         continue;
    01003                                 }
    01004                                 for (j = 0; j < Image.Pal.PalSize; j += 3) {
    01005                                         // No need to perform a sqrt.
    01006                                         Dist1 = (ILint)CurImage->Data[i] - (ILint)Image.Pal.Palette[j];
    01007                                         Dist2 = (ILint)CurImage->Data[i+1] - (ILint)Image.Pal.Palette[j+1];
    01008                                         Dist3 = (ILint)CurImage->Data[i+2] - (ILint)Image.Pal.Palette[j+2];
    01009                                         PalInfo[j / 3] = Dist1 * Dist1 + Dist2 * Dist2 + Dist3 * Dist3;
    01010                                 }
    01011                                 MaxDist = UINT_MAX;
    01012                                 DistEntry = 0;
    01013                                 for (j = 0; j < NumColours; j++) {
    01014                                         if (PalInfo[j] < MaxDist) {
    01015                                                 DistEntry = j;
    01016                                                 MaxDist = PalInfo[j];
    01017                                         }
    01018                                 }
    01019                                 NewData[i / CurImage->Bpp] = DistEntry;
    01020                         }
    01021
    01022                         break;
    01023
    01024                 case IL_BGR:
    01025                 case IL_BGRA:
    01026                         for (i = 0; i < CurImage->SizeOfData; i += CurImage->Bpp) {
    01027                                 for (j = 0; j < NumColours; j++) {
    01028                                         // No need to perform a sqrt.
    01029                                         PalInfo[j] = ((ILint)CurImage->Data[i+2] - (ILint)Image.Pal.Palette[j * 3]) *
    01030                                                 ((ILint)CurImage->Data[i+2] - (ILint)Image.Pal.Palette[j * 3]) +
    01031                                                 ((ILint)CurImage->Data[i+1] - (ILint)Image.Pal.Palette[j * 3 + 1]) *
    01032                                                 ((ILint)CurImage->Data[i+1] - (ILint)Image.Pal.Palette[j * 3 + 1]) +
    01033                                                 ((ILint)CurImage->Data[i] - (ILint)Image.Pal.Palette[j * 3 + 2]) *
    01034                                                 ((ILint)CurImage->Data[i] - (ILint)Image.Pal.Palette[j * 3 + 2]);
    01035                                 }
    01036                                 MaxDist = UINT_MAX;
    01037                                 DistEntry = 0;
    01038                                 for (j = 0; j < NumColours; j++) {
    01039                                         if (PalInfo[j] < MaxDist) {
    01040                                                 DistEntry = j;
    01041                                                 MaxDist = PalInfo[j];
    01042                                         }
    01043                                 }
    01044                                 NewData[i / CurImage->Bpp] = DistEntry;
    01045                         }
    01046
    01047                         break;
    01048
    01049                 case IL_LUMINANCE:
    01050                 case IL_LUMINANCE_ALPHA:
    01051                         for (i = 0; i < CurImage->SizeOfData; i += CurImage->Bpp ) {
    01052                                 for (j = 0; j < NumColours; j++) {
    01053                                         // No need to perform a sqrt.
    01054                                         PalInfo[j] = ((ILuint)CurImage->Data[i] - (ILuint)Image.Pal.Palette[j * 3]) *
    01055                                                 ((ILuint)CurImage->Data[i] - (ILuint)Image.Pal.Palette[j * 3]) +
    01056                                                 ((ILuint)CurImage->Data[i] - (ILuint)Image.Pal.Palette[j * 3 + 1]) *
    01057                                                 ((ILuint)CurImage->Data[i] - (ILuint)Image.Pal.Palette[j * 3 + 1]) +
    01058                                                 ((ILuint)CurImage->Data[i] - (ILuint)Image.Pal.Palette[j * 3 + 2]) *
    01059                                                 ((ILuint)CurImage->Data[i] - (ILuint)Image.Pal.Palette[j * 3 + 2]);
    01060                                 }
    01061                                 MaxDist = UINT_MAX;
    01062                                 DistEntry = 0;
    01063                                 for (j = 0; j < NumColours; j++) {
    01064                                         if (PalInfo[j] < MaxDist) {
    01065                                                 DistEntry = j;
    01066                                                 MaxDist = PalInfo[j];
    01067                                         }
    01068                                 }
    01069                                 NewData[i] = DistEntry;
    01070                         }
    01071
    01072                         break;
    01073
    01074                 default:  // Should be no other!
    01075                         ilSetError(IL_INTERNAL_ERROR);
    01076                         return IL_FALSE;
    01077         }
    01078
    01079         iCurImage = CurImage;
    01080         Origin = iCurImage->Origin;
    01081         if (!ilTexImage(iCurImage->Width, iCurImage->Height, iCurImage->Depth, 1,
    01082                 IL_COLOUR_INDEX, IL_UNSIGNED_BYTE, NewData)) {
    01083                 ifree(Image.Pal.Palette);
    01084                 ifree(PalInfo);
    01085                 ifree(NewData);
    01086                 return IL_FALSE;
    01087         }
    01088         iCurImage->Origin = Origin;
    01089
    01090         iCurImage->Pal.Palette = Image.Pal.Palette;
    01091         iCurImage->Pal.PalSize = Image.Pal.PalSize;
    01092         iCurImage->Pal.PalType = Image.Pal.PalType;
    01093         ifree(PalInfo);
    01094         ifree(NewData);
    01095
    01096         return IL_TRUE;
    01097 }