- Main Page
- Data Structures
- Files

- File List

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

    00001 //-----------------------------------------------------------------------------
    00002 //
    00003 // ImageLib Sources
    00004 // Copyright (C) 2000-2009 by Denton Woods
    00005 // Last modified: 01/30/2009
    00006 //
    00007 // Filename: src-IL/src/il_states.c
    00008 //
    00009 // Description: State machine
    00010 //
    00011 //
    00012 // 20040223 XIX : now has a ilPngAlphaIndex member, so we can spit out png files with a transparent index, set to -1 for none
    00013 //
    00014 //-----------------------------------------------------------------------------
    00015
    00016
    00017 #include "il_internal.h"
    00018 #include "il_states.h"
    00019 //#include <malloc.h>
    00020 #include <stdlib.h>
    00021
    00022 ILconst_string _ilVendor                = IL_TEXT("Abysmal Software");
    00023 ILconst_string _ilVersion               = IL_TEXT("Developer's Image Library (DevIL) 1.7.5");
    00024
    00025
    00026 char* _ilLoadExt                = "" IL_BMP_EXT IL_CUT_EXT IL_DCX_EXT IL_DDS_EXT
    00027                                                                         IL_EXR_EXT IL_GIF_EXT IL_HDR_EXT IL_ICNS_EXT
    00028                                                                         IL_ICO_EXT IL_IFF_EXT IL_JPG_EXT IL_JP2_EXT
    00029                                                                         IL_LIF_EXT IL_MDL_EXT IL_MNG_EXT IL_PCD_EXT
    00030                                                                         IL_PCX_EXT IL_PIC_EXT IL_PIX_EXT IL_PNG_EXT
    00031                                                                         IL_PNM_EXT IL_PSD_EXT IL_PSP_EXT IL_PXR_EXT
    00032                                                                         IL_RAW_EXT IL_SGI_EXT IL_SUN_EXT IL_TGA_EXT
    00033                                                                         IL_TIF_EXT IL_VTF_EXT IL_WAL_EXT IL_XPM_EXT;
    00034
    00035 char* _ilSaveExt                = "" IL_BMP_EXT IL_CHEAD_EXT IL_DDS_EXT IL_EXR_EXT
    00036                                                                         IL_HDR_EXT IL_JP2_EXT IL_JPG_EXT IL_PCX_EXT
    00037                                                                         IL_PNG_EXT IL_PNM_EXT IL_PSD_EXT IL_RAW_EXT
    00038                                                                         IL_SGI_EXT IL_TGA_EXT IL_TIF_EXT IL_WBMP_EXT;
    00039
    00040
    00042 void ilDefaultStates()
    00043 {
    00044         ilStates[ilCurrentPos].ilOriginSet = IL_FALSE;
    00045         ilStates[ilCurrentPos].ilOriginMode = IL_ORIGIN_LOWER_LEFT;
    00046         ilStates[ilCurrentPos].ilFormatSet = IL_FALSE;
    00047         ilStates[ilCurrentPos].ilFormatMode = IL_BGRA;
    00048         ilStates[ilCurrentPos].ilTypeSet = IL_FALSE;
    00049         ilStates[ilCurrentPos].ilTypeMode = IL_UNSIGNED_BYTE;
    00050         ilStates[ilCurrentPos].ilOverWriteFiles = IL_FALSE;
    00051         ilStates[ilCurrentPos].ilAutoConvPal = IL_FALSE;
    00052         ilStates[ilCurrentPos].ilDefaultOnFail = IL_FALSE;
    00053         ilStates[ilCurrentPos].ilUseKeyColour = IL_FALSE;
    00054         ilStates[ilCurrentPos].ilBlitBlend = IL_TRUE;
    00055         ilStates[ilCurrentPos].ilCompression = IL_COMPRESS_ZLIB;
    00056         ilStates[ilCurrentPos].ilInterlace = IL_FALSE;
    00057
    00058         ilStates[ilCurrentPos].ilTgaCreateStamp = IL_FALSE;
    00059         ilStates[ilCurrentPos].ilJpgQuality = 99;
    00060         ilStates[ilCurrentPos].ilPngInterlace = IL_FALSE;
    00061         ilStates[ilCurrentPos].ilTgaRle = IL_FALSE;
    00062         ilStates[ilCurrentPos].ilBmpRle = IL_FALSE;
    00063         ilStates[ilCurrentPos].ilSgiRle = IL_FALSE;
    00064         ilStates[ilCurrentPos].ilJpgFormat = IL_JFIF;
    00065         ilStates[ilCurrentPos].ilJpgProgressive = IL_FALSE;
    00066         ilStates[ilCurrentPos].ilDxtcFormat = IL_DXT1;
    00067         ilStates[ilCurrentPos].ilPcdPicNum = 2;
    00068         ilStates[ilCurrentPos].ilPngAlphaIndex = -1;
    00069
    00070         ilStates[ilCurrentPos].ilTgaId = NULL;
    00071         ilStates[ilCurrentPos].ilTgaAuthName = NULL;
    00072         ilStates[ilCurrentPos].ilTgaAuthComment = NULL;
    00073         ilStates[ilCurrentPos].ilPngAuthName = NULL;
    00074         ilStates[ilCurrentPos].ilPngTitle = NULL;
    00075         ilStates[ilCurrentPos].ilPngDescription = NULL;
    00076
    00077         //2003-09-01: added tiff strings
    00078         ilStates[ilCurrentPos].ilTifDescription = NULL;
    00079         ilStates[ilCurrentPos].ilTifHostComputer = NULL;
    00080         ilStates[ilCurrentPos].ilTifDocumentName = NULL;
    00081         ilStates[ilCurrentPos].ilTifAuthName = NULL;
    00082         ilStates[ilCurrentPos].ilCHeader = NULL;
    00083
    00084         ilStates[ilCurrentPos].ilQuantMode = IL_WU_QUANT;
    00085         ilStates[ilCurrentPos].ilNeuSample = 15;
    00086         ilStates[ilCurrentPos].ilQuantMaxIndexs = 256;
    00087
    00088         ilStates[ilCurrentPos].ilKeepDxtcData = IL_FALSE;
    00089         ilStates[ilCurrentPos].ilUseNVidiaDXT = IL_FALSE;
    00090         ilStates[ilCurrentPos].ilUseSquishDXT = IL_FALSE;
    00091
    00092
    00093
    00094
    00095         ilHints.MemVsSpeedHint = IL_FASTEST;
    00096         ilHints.CompressHint = IL_USE_COMPRESSION;
    00097
    00098         while (ilGetError() != IL_NO_ERROR);
    00099
    00100         return;
    00101 }
    00102
    00103
    00105 ILconst_string ILAPIENTRY ilGetString(ILenum StringName)
    00106 {
    00107         switch (StringName)
    00108         {
    00109                 case IL_VENDOR:
    00110                         return (ILconst_string)_ilVendor;
    00111                 case IL_VERSION_NUM: //changed 2003-08-30: IL_VERSION changes                                                                   //switch define ;-)
    00112                         return (ILconst_string)_ilVersion;
    00113                 case IL_LOAD_EXT:
    00114                         return (ILconst_string)_ilLoadExt;
    00115                 case IL_SAVE_EXT:
    00116                         return (ILconst_string)_ilSaveExt;
    00117                 case IL_TGA_ID_STRING:
    00118                         return (ILconst_string)ilStates[ilCurrentPos].ilTgaId;
    00119                 case IL_TGA_AUTHNAME_STRING:
    00120                         return (ILconst_string)ilStates[ilCurrentPos].ilTgaAuthName;
    00121                 case IL_TGA_AUTHCOMMENT_STRING:
    00122                         return (ILconst_string)ilStates[ilCurrentPos].ilTgaAuthComment;
    00123                 case IL_PNG_AUTHNAME_STRING:
    00124                         return (ILconst_string)ilStates[ilCurrentPos].ilPngAuthName;
    00125                 case IL_PNG_TITLE_STRING:
    00126                         return (ILconst_string)ilStates[ilCurrentPos].ilPngTitle;
    00127                 case IL_PNG_DESCRIPTION_STRING:
    00128                         return (ILconst_string)ilStates[ilCurrentPos].ilPngDescription;
    00129                 //2003-08-31: added tif strings
    00130                 case IL_TIF_DESCRIPTION_STRING:
    00131                         return (ILconst_string)ilStates[ilCurrentPos].ilTifDescription;
    00132                 case IL_TIF_HOSTCOMPUTER_STRING:
    00133                         return (ILconst_string)ilStates[ilCurrentPos].ilTifHostComputer;
    00134                 case IL_TIF_DOCUMENTNAME_STRING:
    00135                         return (ILconst_string)ilStates[ilCurrentPos].ilTifDocumentName;
    00136                 case IL_TIF_AUTHNAME_STRING:
    00137                         return (ILconst_string)ilStates[ilCurrentPos].ilTifAuthName;
    00138                 case IL_CHEAD_HEADER_STRING:
    00139                         return (ILconst_string)ilStates[ilCurrentPos].ilCHeader;
    00140                 default:
    00141                         ilSetError(IL_INVALID_ENUM);
    00142                         break;
    00143         }
    00144         return NULL;
    00145 }
    00146
    00147
    00148 // Clips a string to a certain length and returns a new string.
    00149 char *iClipString(char *String, ILuint MaxLen)
    00150 {
    00151         char    *Clipped;
    00152         ILuint  Length;
    00153
    00154         if (String == NULL)
    00155                 return NULL;
    00156
    00157         Length = ilCharStrLen(String);  //ilStrLen(String);
    00158
    00159         Clipped = (char*)ialloc((MaxLen + 1) * sizeof(char) /*sizeof(ILchar)*/);  // Terminating NULL makes it +1.
    00160         if (Clipped == NULL) {
    00161                 return NULL;
    00162         }
    00163
    00164         memcpy(Clipped, String, MaxLen * sizeof(char) /*sizeof(ILchar)*/);
    00165         Clipped[Length] = 0;
    00166
    00167         return Clipped;
    00168 }
    00169
    00170
    00171 // Returns format-specific strings, truncated to MaxLen (not counting the terminating NULL).
    00172 char *iGetString(ILenum StringName)
    00173 {
    00174         switch (StringName)
    00175         {
    00176                 case IL_TGA_ID_STRING:
    00177                         return iClipString(ilStates[ilCurrentPos].ilTgaId, 254);
    00178                 case IL_TGA_AUTHNAME_STRING:
    00179                         return iClipString(ilStates[ilCurrentPos].ilTgaAuthName, 40);
    00180                 case IL_TGA_AUTHCOMMENT_STRING:
    00181                         return iClipString(ilStates[ilCurrentPos].ilTgaAuthComment, 80);
    00182                 case IL_PNG_AUTHNAME_STRING:
    00183                         return iClipString(ilStates[ilCurrentPos].ilPngAuthName, 255);
    00184                 case IL_PNG_TITLE_STRING:
    00185                         return iClipString(ilStates[ilCurrentPos].ilPngTitle, 255);
    00186                 case IL_PNG_DESCRIPTION_STRING:
    00187                         return iClipString(ilStates[ilCurrentPos].ilPngDescription, 255);
    00188
    00189                 //changed 2003-08-31...here was a serious copy and paste bug ;-)
    00190                 case IL_TIF_DESCRIPTION_STRING:
    00191                         return iClipString(ilStates[ilCurrentPos].ilTifDescription, 255);
    00192                 case IL_TIF_HOSTCOMPUTER_STRING:
    00193                         return iClipString(ilStates[ilCurrentPos].ilTifHostComputer, 255);
    00194                 case IL_TIF_DOCUMENTNAME_STRING:
    00195                         return iClipString(ilStates[ilCurrentPos].ilTifDocumentName, 255);
    00196                 case IL_TIF_AUTHNAME_STRING:
    00197                         return iClipString(ilStates[ilCurrentPos].ilTifAuthName, 255);
    00198                 case IL_CHEAD_HEADER_STRING:
    00199                         return iClipString(ilStates[ilCurrentPos].ilCHeader, 32);
    00200                 default:
    00201                         ilSetError(IL_INVALID_ENUM);
    00202         }
    00203         return NULL;
    00204 }
    00205
    00206
    00208 ILboolean ILAPIENTRY ilEnable(ILenum Mode)
    00209 {
    00210         return ilAble(Mode, IL_TRUE);
    00211 }
    00212
    00213
    00215 ILboolean ILAPIENTRY ilDisable(ILenum Mode)
    00216 {
    00217         return ilAble(Mode, IL_FALSE);
    00218 }
    00219
    00220
    00221 // Internal function that sets the Mode equal to Flag
    00222 ILboolean ilAble(ILenum Mode, ILboolean Flag)
    00223 {
    00224         switch (Mode)
    00225         {
    00226                 case IL_ORIGIN_SET:
    00227                         ilStates[ilCurrentPos].ilOriginSet = Flag;
    00228                         break;
    00229                 case IL_FORMAT_SET:
    00230                         ilStates[ilCurrentPos].ilFormatSet = Flag;
    00231                         break;
    00232                 case IL_TYPE_SET:
    00233                         ilStates[ilCurrentPos].ilTypeSet = Flag;
    00234                         break;
    00235                 case IL_FILE_OVERWRITE:
    00236                         ilStates[ilCurrentPos].ilOverWriteFiles = Flag;
    00237                         break;
    00238                 case IL_CONV_PAL:
    00239                         ilStates[ilCurrentPos].ilAutoConvPal = Flag;
    00240                         break;
    00241                 case IL_DEFAULT_ON_FAIL:
    00242                         ilStates[ilCurrentPos].ilDefaultOnFail = Flag;
    00243                         break;
    00244                 case IL_USE_KEY_COLOUR:
    00245                         ilStates[ilCurrentPos].ilUseKeyColour = Flag;
    00246                         break;
    00247                 case IL_BLIT_BLEND:
    00248                         ilStates[ilCurrentPos].ilBlitBlend = Flag;
    00249                         break;
    00250                 case IL_SAVE_INTERLACED:
    00251                         ilStates[ilCurrentPos].ilInterlace = Flag;
    00252                         break;
    00253                 case IL_JPG_PROGRESSIVE:
    00254                         ilStates[ilCurrentPos].ilJpgProgressive = Flag;
    00255                         break;
    00256                 case IL_NVIDIA_COMPRESS:
    00257                         ilStates[ilCurrentPos].ilUseNVidiaDXT = Flag;
    00258                         break;
    00259                 case IL_SQUISH_COMPRESS:
    00260                         ilStates[ilCurrentPos].ilUseSquishDXT = Flag;
    00261                         break;
    00262
    00263                 default:
    00264                         ilSetError(IL_INVALID_ENUM);
    00265                         return IL_FALSE;
    00266         }
    00267
    00268         return IL_TRUE;
    00269 }
    00270
    00271
    00273 ILboolean ILAPIENTRY ilIsEnabled(ILenum Mode)
    00274 {
    00275         switch (Mode)
    00276         {
    00277                 case IL_ORIGIN_SET:
    00278                         return ilStates[ilCurrentPos].ilOriginSet;
    00279                 case IL_FORMAT_SET:
    00280                         return ilStates[ilCurrentPos].ilFormatSet;
    00281                 case IL_TYPE_SET:
    00282                         return ilStates[ilCurrentPos].ilTypeSet;
    00283                 case IL_FILE_OVERWRITE:
    00284                         return ilStates[ilCurrentPos].ilOverWriteFiles;
    00285                 case IL_CONV_PAL:
    00286                         return ilStates[ilCurrentPos].ilAutoConvPal;
    00287                 case IL_DEFAULT_ON_FAIL:
    00288                         return ilStates[ilCurrentPos].ilDefaultOnFail;
    00289                 case IL_USE_KEY_COLOUR:
    00290                         return ilStates[ilCurrentPos].ilUseKeyColour;
    00291                 case IL_BLIT_BLEND:
    00292                         return ilStates[ilCurrentPos].ilBlitBlend;
    00293                 case IL_SAVE_INTERLACED:
    00294                         return ilStates[ilCurrentPos].ilInterlace;
    00295                 case IL_JPG_PROGRESSIVE:
    00296                         return ilStates[ilCurrentPos].ilJpgProgressive;
    00297                 case IL_NVIDIA_COMPRESS:
    00298                         return ilStates[ilCurrentPos].ilUseNVidiaDXT;
    00299                 case IL_SQUISH_COMPRESS:
    00300                         return ilStates[ilCurrentPos].ilUseSquishDXT;
    00301
    00302                 default:
    00303                         ilSetError(IL_INVALID_ENUM);
    00304         }
    00305
    00306         return IL_FALSE;
    00307 }
    00308
    00309
    00311 ILboolean ILAPIENTRY ilIsDisabled(ILenum Mode)
    00312 {
    00313         return !ilIsEnabled(Mode);
    00314 }
    00315
    00316
    00318 void ILAPIENTRY ilGetBooleanv(ILenum Mode, ILboolean *Param)
    00319 {
    00320         if (Param == NULL) {
    00321                 ilSetError(IL_INVALID_PARAM);
    00322                 return;
    00323         }
    00324
    00325         *Param = ilGetInteger(Mode);
    00326
    00327         return;
    00328 }
    00329
    00330
    00332 ILboolean ILAPIENTRY ilGetBoolean(ILenum Mode)
    00333 {
    00334         ILboolean Temp;
    00335         Temp = IL_FALSE;
    00336         ilGetBooleanv(Mode, &Temp);
    00337         return Temp;
    00338 }
    00339
    00340
    00341 ILimage *iGetBaseImage(void);
    00342
    00344 //@TODO: This may get much more complex with mipmaps under faces, etc.
    00345 ILuint iGetActiveNum(ILenum Type)
    00346 {
    00347         ILimage *BaseImage;
    00348         ILuint Num = 0;
    00349
    00350         if (iCurImage == NULL) {
    00351                 ilSetError(IL_ILLEGAL_OPERATION);
    00352                 return 0;
    00353         }
    00354
    00355         BaseImage = iGetBaseImage();
    00356         if (BaseImage == iCurImage)
    00357                 return 0;
    00358
    00359         switch (Type)
    00360         {
    00361                 case IL_ACTIVE_IMAGE:
    00362                         BaseImage = BaseImage->Next;
    00363                         do {
    00364                                 if (BaseImage == NULL)
    00365                                         return 0;
    00366                                 Num++;
    00367                                 if (BaseImage == iCurImage)
    00368                                         return Num;
    00369                         } while ((BaseImage = BaseImage->Next));
    00370                         break;
    00371                 case IL_ACTIVE_MIPMAP:
    00372                         BaseImage = BaseImage->Mipmaps;
    00373                         do {
    00374                                 if (BaseImage == NULL)
    00375                                         return 0;
    00376                                 Num++;
    00377                                 if (BaseImage == iCurImage)
    00378                                         return Num;
    00379                         } while ((BaseImage = BaseImage->Mipmaps));
    00380                         break;
    00381                 case IL_ACTIVE_LAYER:
    00382                         BaseImage = BaseImage->Layers;
    00383                         do {
    00384                                 if (BaseImage == NULL)
    00385                                         return 0;
    00386                                 Num++;
    00387                                 if (BaseImage == iCurImage)
    00388                                         return Num;
    00389                         } while ((BaseImage = BaseImage->Layers));
    00390                         break;
    00391                 case IL_ACTIVE_FACE:
    00392                         BaseImage = BaseImage->Faces;
    00393                         do {
    00394                                 if (BaseImage == NULL)
    00395                                         return 0;
    00396                                 Num++;
    00397                                 if (BaseImage == iCurImage)
    00398                                         return Num;
    00399                         } while ((BaseImage = BaseImage->Faces));
    00400                         break;
    00401         }
    00402
    00403         //@TODO: Any error needed here?
    00404
    00405         return 0;
    00406 }
    00407
    00408
    00410 void ILAPIENTRY ilGetIntegerv(ILenum Mode, ILint *Param)
    00411 {
    00412         if (Param == NULL) {
    00413                 ilSetError(IL_INVALID_PARAM);
    00414                 return;
    00415         }
    00416
    00417         *Param = 0;
    00418
    00419         switch (Mode) {
    00420                 // Integer values
    00421                 case IL_COMPRESS_MODE:
    00422                         *Param = ilStates[ilCurrentPos].ilCompression;
    00423                         break;
    00424                 case IL_CUR_IMAGE:
    00425                         if (iCurImage == NULL) {
    00426                                 ilSetError(IL_ILLEGAL_OPERATION);
    00427                                 break;
    00428                         }
    00429                         *Param = ilGetCurName();
    00430                         break;
    00431                 case IL_FORMAT_MODE:
    00432                         *Param = ilStates[ilCurrentPos].ilFormatMode;
    00433                         break;
    00434                 case IL_INTERLACE_MODE:
    00435                         *Param = ilStates[ilCurrentPos].ilInterlace;
    00436                         break;
    00437                 case IL_KEEP_DXTC_DATA:
    00438                         *Param = ilStates[ilCurrentPos].ilKeepDxtcData;
    00439                         break;
    00440                 case IL_ORIGIN_MODE:
    00441                         *Param = ilStates[ilCurrentPos].ilOriginMode;
    00442                         break;
    00443                 case IL_MAX_QUANT_INDICES:
    00444                         *Param = ilStates[ilCurrentPos].ilQuantMaxIndexs;
    00445                         break;
    00446                 case IL_NEU_QUANT_SAMPLE:
    00447                         *Param = ilStates[ilCurrentPos].ilNeuSample;
    00448                         break;
    00449                 case IL_QUANTIZATION_MODE:
    00450                         *Param = ilStates[ilCurrentPos].ilQuantMode;
    00451                         break;
    00452                 case IL_TYPE_MODE:
    00453                         *Param = ilStates[ilCurrentPos].ilTypeMode;
    00454                         break;
    00455                 case IL_VERSION_NUM:
    00456                         *Param = IL_VERSION;
    00457                         break;
    00458
    00459                 // Image specific values
    00460                 case IL_ACTIVE_IMAGE:
    00461                 case IL_ACTIVE_MIPMAP:
    00462                 case IL_ACTIVE_LAYER:
    00463                         *Param = iGetActiveNum(Mode);
    00464                         break;
    00465
    00466                 // Format-specific values
    00467                 case IL_BMP_RLE:
    00468                         *Param = ilStates[ilCurrentPos].ilBmpRle;
    00469                         break;
    00470                 case IL_DXTC_FORMAT:
    00471                         *Param = ilStates[ilCurrentPos].ilDxtcFormat;
    00472                         break;
    00473                 case IL_JPG_QUALITY:
    00474                         *Param = ilStates[ilCurrentPos].ilJpgQuality;
    00475                         break;
    00476                 case IL_JPG_SAVE_FORMAT:
    00477                         *Param = ilStates[ilCurrentPos].ilJpgFormat;
    00478                         break;
    00479                 case IL_PCD_PICNUM:
    00480                         *Param = ilStates[ilCurrentPos].ilPcdPicNum;
    00481                         break;
    00482                 case IL_PNG_ALPHA_INDEX:
    00483                         *Param = ilStates[ilCurrentPos].ilPngAlphaIndex;
    00484                         break;
    00485                 case IL_PNG_INTERLACE:
    00486                         *Param = ilStates[ilCurrentPos].ilPngInterlace;
    00487                         break;
    00488                 case IL_SGI_RLE:
    00489                         *Param = ilStates[ilCurrentPos].ilSgiRle;
    00490                         break;
    00491                 case IL_TGA_CREATE_STAMP:
    00492                         *Param = ilStates[ilCurrentPos].ilTgaCreateStamp;
    00493                         break;
    00494                 case IL_TGA_RLE:
    00495                         *Param = ilStates[ilCurrentPos].ilTgaRle;
    00496                         break;
    00497
    00498                 // Boolean values
    00499                 case IL_CONV_PAL:
    00500                         *Param = ilStates[ilCurrentPos].ilAutoConvPal;
    00501                         break;
    00502                 case IL_DEFAULT_ON_FAIL:
    00503                         *Param = ilStates[ilCurrentPos].ilDefaultOnFail;
    00504                         break;
    00505                 case IL_FILE_MODE:
    00506                         *Param = ilStates[ilCurrentPos].ilOverWriteFiles;
    00507                         break;
    00508                 case IL_FORMAT_SET:
    00509                         *Param = ilStates[ilCurrentPos].ilFormatSet;
    00510                         break;
    00511                 case IL_ORIGIN_SET:
    00512                         *Param = ilStates[ilCurrentPos].ilOriginSet;
    00513                         break;
    00514                 case IL_TYPE_SET:
    00515                         *Param = ilStates[ilCurrentPos].ilTypeSet;
    00516                         break;
    00517                 case IL_USE_KEY_COLOUR:
    00518                         *Param = ilStates[ilCurrentPos].ilUseKeyColour;
    00519                         break;
    00520                 case IL_BLIT_BLEND:
    00521                         *Param = ilStates[ilCurrentPos].ilBlitBlend;
    00522                         break;
    00523                 case IL_JPG_PROGRESSIVE:
    00524                         *Param = ilStates[ilCurrentPos].ilJpgProgressive;
    00525                         break;
    00526                 case IL_NVIDIA_COMPRESS:
    00527                         *Param = ilStates[ilCurrentPos].ilUseNVidiaDXT;
    00528                         break;
    00529                 case IL_SQUISH_COMPRESS:
    00530                         *Param = ilStates[ilCurrentPos].ilUseSquishDXT;
    00531                         break;
    00532
    00533                 default:
    00534             iGetIntegervImage(iCurImage, Mode, Param);
    00535         }
    00536
    00537         return;
    00538 }
    00539
    00540 //@TODO rename to ilGetImageIntegerv for 1.6.9 and make it public
    00542 void ILAPIENTRY iGetIntegervImage(ILimage *Image, ILenum Mode, ILint *Param)
    00543 {
    00544     ILimage *SubImage;
    00545     if (Image == NULL) {
    00546         ilSetError(IL_ILLEGAL_OPERATION);
    00547         return;
    00548     }
    00549     if (Param == NULL) {
    00550         ilSetError(IL_INVALID_PARAM);
    00551         return;
    00552     }
    00553     *Param = 0;
    00554
    00555     switch (Mode)
    00556     {
    00557         case IL_DXTC_DATA_FORMAT:
    00558             if (Image->DxtcData == NULL || Image->DxtcSize == 0) {
    00559                  *Param = IL_DXT_NO_COMP;
    00560                  break;
    00561             }
    00562             *Param = Image->DxtcFormat;
    00563             break;
    00565         case IL_IMAGE_BITS_PER_PIXEL:
    00566             //changed 20040610 to channel count (Bpp) times Bytes per channel
    00567             *Param = (Image->Bpp << 3)*Image->Bpc;
    00568             break;
    00569         case IL_IMAGE_BYTES_PER_PIXEL:
    00570             //changed 20040610 to channel count (Bpp) times Bytes per channel
    00571             *Param = Image->Bpp*Image->Bpc;
    00572             break;
    00573         case IL_IMAGE_BPC:
    00574             *Param = Image->Bpc;
    00575             break;
    00576         case IL_IMAGE_CHANNELS:
    00577             *Param = Image->Bpp;
    00578             break;
    00579         case IL_IMAGE_CUBEFLAGS:
    00580             *Param = Image->CubeFlags;
    00581             break;
    00582         case IL_IMAGE_DEPTH:
    00583             *Param = Image->Depth;
    00584             break;
    00585         case IL_IMAGE_DURATION:
    00586             *Param = Image->Duration;
    00587             break;
    00588         case IL_IMAGE_FORMAT:
    00589             *Param = Image->Format;
    00590             break;
    00591         case IL_IMAGE_HEIGHT:
    00592             *Param = Image->Height;
    00593             break;
    00594         case IL_IMAGE_SIZE_OF_DATA:
    00595             *Param = Image->SizeOfData;
    00596
    00597             break;
    00598         case IL_IMAGE_OFFX:
    00599             *Param = Image->OffX;
    00600             break;
    00601         case IL_IMAGE_OFFY:
    00602             *Param = Image->OffY;
    00603             break;
    00604         case IL_IMAGE_ORIGIN:
    00605             *Param = Image->Origin;
    00606             break;
    00607         case IL_IMAGE_PLANESIZE:
    00608             *Param = Image->SizeOfPlane;
    00609             break;
    00610         case IL_IMAGE_TYPE:
    00611             *Param = Image->Type;
    00612             break;
    00613         case IL_IMAGE_WIDTH:
    00614             *Param = Image->Width;
    00615             break;
    00616         case IL_NUM_FACES:
    00617             for (SubImage = Image->Faces; SubImage; SubImage = SubImage->Faces)
    00618                 (*Param)++;
    00619             break;
    00620         case IL_NUM_IMAGES:
    00621             for (SubImage = Image->Next; SubImage; SubImage = SubImage->Next)
    00622                 (*Param)++;
    00623             break;
    00624         case IL_NUM_LAYERS:
    00625             for (SubImage = Image->Layers; SubImage; SubImage = SubImage->Layers)
    00626                 (*Param)++;
    00627             break;
    00628         case IL_NUM_MIPMAPS:
    00629                         for (SubImage = Image->Mipmaps; SubImage; SubImage = SubImage->Mipmaps)
    00630                 (*Param)++;
    00631             break;
    00632
    00633         case IL_PALETTE_TYPE:
    00634              *Param = Image->Pal.PalType;
    00635              break;
    00636         case IL_PALETTE_BPP:
    00637              *Param = ilGetBppPal(Image->Pal.PalType);
    00638              break;
    00639         case IL_PALETTE_NUM_COLS:
    00640              if (!Image->Pal.Palette || !Image->Pal.PalSize || Image->Pal.PalType == IL_PAL_NONE)
    00641                   *Param = 0;
    00642              else
    00643                   *Param = Image->Pal.PalSize / ilGetBppPal(Image->Pal.PalType);
    00644              break;
    00645         case IL_PALETTE_BASE_TYPE:
    00646              switch (Image->Pal.PalType)
    00647              {
    00648                   case IL_PAL_RGB24:
    00649                       *Param = IL_RGB;
    00650                   case IL_PAL_RGB32:
    00651                       *Param = IL_RGBA; // Not sure
    00652                   case IL_PAL_RGBA32:
    00653                       *Param = IL_RGBA;
    00654                   case IL_PAL_BGR24:
    00655                       *Param = IL_BGR;
    00656                   case IL_PAL_BGR32:
    00657                       *Param = IL_BGRA; // Not sure
    00658                   case IL_PAL_BGRA32:
    00659                       *Param = IL_BGRA;
    00660              }
    00661              break;
    00662         default:
    00663              ilSetError(IL_INVALID_ENUM);
    00664     }
    00665 }
    00666
    00667
    00668
    00670 ILint ILAPIENTRY ilGetInteger(ILenum Mode)
    00671 {
    00672         ILint Temp;
    00673         Temp = 0;
    00674         ilGetIntegerv(Mode, &Temp);
    00675         return Temp;
    00676 }
    00677
    00678
    00680 ILboolean ILAPIENTRY ilOriginFunc(ILenum Mode)
    00681 {
    00682         switch (Mode)
    00683         {
    00684                 case IL_ORIGIN_LOWER_LEFT:
    00685                 case IL_ORIGIN_UPPER_LEFT:
    00686                         ilStates[ilCurrentPos].ilOriginMode = Mode;
    00687                         break;
    00688                 default:
    00689                         ilSetError(IL_INVALID_PARAM);
    00690                         return IL_FALSE;
    00691         }
    00692         return IL_TRUE;
    00693 }
    00694
    00695
    00697 ILboolean ILAPIENTRY ilFormatFunc(ILenum Mode)
    00698 {
    00699         switch (Mode)
    00700         {
    00701                 //case IL_COLOUR_INDEX:
    00702                 case IL_RGB:
    00703                 case IL_RGBA:
    00704                 case IL_BGR:
    00705                 case IL_BGRA:
    00706                 case IL_LUMINANCE:
    00707                 case IL_LUMINANCE_ALPHA:
    00708                         ilStates[ilCurrentPos].ilFormatMode = Mode;
    00709                         break;
    00710                 default:
    00711                         ilSetError(IL_INVALID_PARAM);
    00712                         return IL_FALSE;
    00713         }
    00714         return IL_TRUE;
    00715 }
    00716
    00717
    00719 ILboolean ILAPIENTRY ilTypeFunc(ILenum Mode)
    00720 {
    00721         switch (Mode)
    00722         {
    00723                 case IL_BYTE:
    00724                 case IL_UNSIGNED_BYTE:
    00725                 case IL_SHORT:
    00726                 case IL_UNSIGNED_SHORT:
    00727                 case IL_INT:
    00728                 case IL_UNSIGNED_INT:
    00729                 case IL_FLOAT:
    00730                 case IL_DOUBLE:
    00731                         ilStates[ilCurrentPos].ilTypeMode = Mode;
    00732                         break;
    00733                 default:
    00734                         ilSetError(IL_INVALID_PARAM);
    00735                         return IL_FALSE;
    00736         }
    00737         return IL_TRUE;
    00738 }
    00739
    00740
    00741 ILboolean ILAPIENTRY ilCompressFunc(ILenum Mode)
    00742 {
    00743         switch (Mode)
    00744         {
    00745                 case IL_COMPRESS_NONE:
    00746                 case IL_COMPRESS_RLE:
    00747                 //case IL_COMPRESS_LZO:
    00748                 case IL_COMPRESS_ZLIB:
    00749                         ilStates[ilCurrentPos].ilCompression = Mode;
    00750                         break;
    00751                 default:
    00752                         ilSetError(IL_INVALID_PARAM);
    00753                         return IL_FALSE;
    00754         }
    00755         return IL_TRUE;
    00756 }
    00757
    00758
    00760 void ILAPIENTRY ilPushAttrib(ILuint Bits)
    00761 {
    00762         // Should we check here to see if ilCurrentPos is negative?
    00763
    00764         if (ilCurrentPos >= IL_ATTRIB_STACK_MAX - 1) {
    00765                 ilCurrentPos = IL_ATTRIB_STACK_MAX - 1;
    00766                 ilSetError(IL_STACK_OVERFLOW);
    00767                 return;
    00768         }
    00769
    00770         ilCurrentPos++;
    00771
    00772         //      memcpy(&ilStates[ilCurrentPos], &ilStates[ilCurrentPos - 1], sizeof(IL_STATES));
    00773
    00774         ilDefaultStates();
    00775
    00776         if (Bits & IL_ORIGIN_BIT) {
    00777                 ilStates[ilCurrentPos].ilOriginMode = ilStates[ilCurrentPos-1].ilOriginMode;
    00778                 ilStates[ilCurrentPos].ilOriginSet  = ilStates[ilCurrentPos-1].ilOriginSet;
    00779         }
    00780         if (Bits & IL_FORMAT_BIT) {
    00781                 ilStates[ilCurrentPos].ilFormatMode = ilStates[ilCurrentPos-1].ilFormatMode;
    00782                 ilStates[ilCurrentPos].ilFormatSet  = ilStates[ilCurrentPos-1].ilFormatSet;
    00783         }
    00784         if (Bits & IL_TYPE_BIT) {
    00785                 ilStates[ilCurrentPos].ilTypeMode = ilStates[ilCurrentPos-1].ilTypeMode;
    00786                 ilStates[ilCurrentPos].ilTypeSet  = ilStates[ilCurrentPos-1].ilTypeSet;
    00787         }
    00788         if (Bits & IL_FILE_BIT) {
    00789                 ilStates[ilCurrentPos].ilOverWriteFiles = ilStates[ilCurrentPos-1].ilOverWriteFiles;
    00790         }
    00791         if (Bits & IL_PAL_BIT) {
    00792                 ilStates[ilCurrentPos].ilAutoConvPal = ilStates[ilCurrentPos-1].ilAutoConvPal;
    00793         }
    00794         if (Bits & IL_LOADFAIL_BIT) {
    00795                 ilStates[ilCurrentPos].ilDefaultOnFail = ilStates[ilCurrentPos-1].ilDefaultOnFail;
    00796         }
    00797         if (Bits & IL_COMPRESS_BIT) {
    00798                 ilStates[ilCurrentPos].ilCompression = ilStates[ilCurrentPos-1].ilCompression;
    00799         }
    00800         if (Bits & IL_FORMAT_SPECIFIC_BIT) {
    00801                 ilStates[ilCurrentPos].ilTgaCreateStamp = ilStates[ilCurrentPos-1].ilTgaCreateStamp;
    00802                 ilStates[ilCurrentPos].ilJpgQuality = ilStates[ilCurrentPos-1].ilJpgQuality;
    00803                 ilStates[ilCurrentPos].ilPngInterlace = ilStates[ilCurrentPos-1].ilPngInterlace;
    00804                 ilStates[ilCurrentPos].ilTgaRle = ilStates[ilCurrentPos-1].ilTgaRle;
    00805                 ilStates[ilCurrentPos].ilBmpRle = ilStates[ilCurrentPos-1].ilBmpRle;
    00806                 ilStates[ilCurrentPos].ilSgiRle = ilStates[ilCurrentPos-1].ilSgiRle;
    00807                 ilStates[ilCurrentPos].ilJpgFormat = ilStates[ilCurrentPos-1].ilJpgFormat;
    00808                 ilStates[ilCurrentPos].ilDxtcFormat = ilStates[ilCurrentPos-1].ilDxtcFormat;
    00809                 ilStates[ilCurrentPos].ilPcdPicNum = ilStates[ilCurrentPos-1].ilPcdPicNum;
    00810
    00811                 ilStates[ilCurrentPos].ilPngAlphaIndex = ilStates[ilCurrentPos-1].ilPngAlphaIndex;
    00812
    00813                 // Strings
    00814                 if (ilStates[ilCurrentPos].ilTgaId)
    00815                         ifree(ilStates[ilCurrentPos].ilTgaId);
    00816                 if (ilStates[ilCurrentPos].ilTgaAuthName)
    00817                         ifree(ilStates[ilCurrentPos].ilTgaAuthName);
    00818                 if (ilStates[ilCurrentPos].ilTgaAuthComment)
    00819                         ifree(ilStates[ilCurrentPos].ilTgaAuthComment);
    00820                 if (ilStates[ilCurrentPos].ilPngAuthName)
    00821                         ifree(ilStates[ilCurrentPos].ilPngAuthName);
    00822                 if (ilStates[ilCurrentPos].ilPngTitle)
    00823                         ifree(ilStates[ilCurrentPos].ilPngTitle);
    00824                 if (ilStates[ilCurrentPos].ilPngDescription)
    00825                         ifree(ilStates[ilCurrentPos].ilPngDescription);
    00826
    00827                 //2003-09-01: added tif strings
    00828                 if (ilStates[ilCurrentPos].ilTifDescription)
    00829                         ifree(ilStates[ilCurrentPos].ilTifDescription);
    00830                 if (ilStates[ilCurrentPos].ilTifHostComputer)
    00831                         ifree(ilStates[ilCurrentPos].ilTifHostComputer);
    00832                 if (ilStates[ilCurrentPos].ilTifDocumentName)
    00833                         ifree(ilStates[ilCurrentPos].ilTifDocumentName);
    00834                 if (ilStates[ilCurrentPos].ilTifAuthName)
    00835                         ifree(ilStates[ilCurrentPos].ilTifAuthName);
    00836
    00837                 if (ilStates[ilCurrentPos].ilCHeader)
    00838                         ifree(ilStates[ilCurrentPos].ilCHeader);
    00839
    00840                 ilStates[ilCurrentPos].ilTgaId = strdup(ilStates[ilCurrentPos-1].ilTgaId);
    00841                 ilStates[ilCurrentPos].ilTgaAuthName = strdup(ilStates[ilCurrentPos-1].ilTgaAuthName);
    00842                 ilStates[ilCurrentPos].ilTgaAuthComment = strdup(ilStates[ilCurrentPos-1].ilTgaAuthComment);
    00843                 ilStates[ilCurrentPos].ilPngAuthName = strdup(ilStates[ilCurrentPos-1].ilPngAuthName);
    00844                 ilStates[ilCurrentPos].ilPngTitle = strdup(ilStates[ilCurrentPos-1].ilPngTitle);
    00845                 ilStates[ilCurrentPos].ilPngDescription = strdup(ilStates[ilCurrentPos-1].ilPngDescription);
    00846
    00847                 //2003-09-01: added tif strings
    00848                 ilStates[ilCurrentPos].ilTifDescription = strdup(ilStates[ilCurrentPos-1].ilTifDescription);
    00849                 ilStates[ilCurrentPos].ilTifHostComputer = strdup(ilStates[ilCurrentPos-1].ilTifHostComputer);
    00850                 ilStates[ilCurrentPos].ilTifDocumentName = strdup(ilStates[ilCurrentPos-1].ilTifDocumentName);
    00851                 ilStates[ilCurrentPos].ilTifAuthName = strdup(ilStates[ilCurrentPos-1].ilTifAuthName);
    00852
    00853                 ilStates[ilCurrentPos].ilCHeader = strdup(ilStates[ilCurrentPos-1].ilCHeader);
    00854         }
    00855
    00856         return;
    00857 }
    00858
    00859
    00860 // @TODO:  Find out how this affects strings!!!
    00861
    00863 void ILAPIENTRY ilPopAttrib()
    00864 {
    00865         if (ilCurrentPos <= 0) {
    00866                 ilCurrentPos = 0;
    00867                 ilSetError(IL_STACK_UNDERFLOW);
    00868                 return;
    00869         }
    00870
    00871         // Should we check here to see if ilCurrentPos is too large?
    00872         ilCurrentPos--;
    00873
    00874         return;
    00875 }
    00876
    00877
    00879 void ILAPIENTRY ilHint(ILenum Target, ILenum Mode)
    00880 {
    00881         switch (Target)
    00882         {
    00883                 case IL_MEM_SPEED_HINT:
    00884                         switch (Mode)
    00885                         {
    00886                                 case IL_FASTEST:
    00887                                         ilHints.MemVsSpeedHint = Mode;
    00888                                         break;
    00889                                 case IL_LESS_MEM:
    00890                                         ilHints.MemVsSpeedHint = Mode;
    00891                                         break;
    00892                                 case IL_DONT_CARE:
    00893                                         ilHints.MemVsSpeedHint = IL_FASTEST;
    00894                                         break;
    00895                                 default:
    00896                                         ilSetError(IL_INVALID_ENUM);
    00897                                         return;
    00898                         }
    00899                         break;
    00900
    00901                 case IL_COMPRESSION_HINT:
    00902                         switch (Mode)
    00903                         {
    00904                                 case IL_USE_COMPRESSION:
    00905                                         ilHints.CompressHint = Mode;
    00906                                         break;
    00907                                 case IL_NO_COMPRESSION:
    00908                                         ilHints.CompressHint = Mode;
    00909                                         break;
    00910                                 case IL_DONT_CARE:
    00911                                         ilHints.CompressHint = IL_NO_COMPRESSION;
    00912                                         break;
    00913                                 default:
    00914                                         ilSetError(IL_INVALID_ENUM);
    00915                                         return;
    00916                         }
    00917                         break;
    00918
    00919
    00920                 default:
    00921                         ilSetError(IL_INVALID_ENUM);
    00922                         return;
    00923         }
    00924
    00925         return;
    00926 }
    00927
    00928
    00929 ILenum iGetHint(ILenum Target)
    00930 {
    00931         switch (Target)
    00932         {
    00933                 case IL_MEM_SPEED_HINT:
    00934                         return ilHints.MemVsSpeedHint;
    00935                 case IL_COMPRESSION_HINT:
    00936                         return ilHints.CompressHint;
    00937                 default:
    00938                         ilSetError(IL_INTERNAL_ERROR);
    00939                         return 0;
    00940         }
    00941 }
    00942
    00943
    00944 void ILAPIENTRY ilSetString(ILenum Mode, const char *String)
    00945 {
    00946         if (String == NULL) {
    00947                 ilSetError(IL_INVALID_PARAM);
    00948                 return;
    00949         }
    00950
    00951         switch (Mode)
    00952         {
    00953                 case IL_TGA_ID_STRING:
    00954                         if (ilStates[ilCurrentPos].ilTgaId)
    00955                                 ifree(ilStates[ilCurrentPos].ilTgaId);
    00956                         ilStates[ilCurrentPos].ilTgaId = strdup(String);
    00957                         break;
    00958                 case IL_TGA_AUTHNAME_STRING:
    00959                         if (ilStates[ilCurrentPos].ilTgaAuthName)
    00960                                 ifree(ilStates[ilCurrentPos].ilTgaAuthName);
    00961                         ilStates[ilCurrentPos].ilTgaAuthName = strdup(String);
    00962                         break;
    00963                 case IL_TGA_AUTHCOMMENT_STRING:
    00964                         if (ilStates[ilCurrentPos].ilTgaAuthComment)
    00965                                 ifree(ilStates[ilCurrentPos].ilTgaAuthComment);
    00966                         ilStates[ilCurrentPos].ilTgaAuthComment = strdup(String);
    00967                         break;
    00968                 case IL_PNG_AUTHNAME_STRING:
    00969                         if (ilStates[ilCurrentPos].ilPngAuthName)
    00970                                 ifree(ilStates[ilCurrentPos].ilPngAuthName);
    00971                         ilStates[ilCurrentPos].ilPngAuthName = strdup(String);
    00972                         break;
    00973                 case IL_PNG_TITLE_STRING:
    00974                         if (ilStates[ilCurrentPos].ilPngTitle)
    00975                                 ifree(ilStates[ilCurrentPos].ilPngTitle);
    00976                         ilStates[ilCurrentPos].ilPngTitle = strdup(String);
    00977                         break;
    00978                 case IL_PNG_DESCRIPTION_STRING:
    00979                         if (ilStates[ilCurrentPos].ilPngDescription)
    00980                                 ifree(ilStates[ilCurrentPos].ilPngDescription);
    00981                         ilStates[ilCurrentPos].ilPngDescription = strdup(String);
    00982                         break;
    00983
    00984                 //2003-09-01: added tif strings
    00985                 case IL_TIF_DESCRIPTION_STRING:
    00986                         if (ilStates[ilCurrentPos].ilTifDescription)
    00987                                 ifree(ilStates[ilCurrentPos].ilTifDescription);
    00988                         ilStates[ilCurrentPos].ilTifDescription = strdup(String);
    00989                         break;
    00990                 case IL_TIF_HOSTCOMPUTER_STRING:
    00991                         if (ilStates[ilCurrentPos].ilTifHostComputer)
    00992                                 ifree(ilStates[ilCurrentPos].ilTifHostComputer);
    00993                         ilStates[ilCurrentPos].ilTifHostComputer = strdup(String);
    00994                         break;
    00995                 case IL_TIF_DOCUMENTNAME_STRING:
    00996                                                 if (ilStates[ilCurrentPos].ilTifDocumentName)
    00997                                 ifree(ilStates[ilCurrentPos].ilTifDocumentName);
    00998                         ilStates[ilCurrentPos].ilTifDocumentName = strdup(String);
    00999                         break;
    01000                 case IL_TIF_AUTHNAME_STRING:
    01001                         if (ilStates[ilCurrentPos].ilTifAuthName)
    01002                                 ifree(ilStates[ilCurrentPos].ilTifAuthName);
    01003                         ilStates[ilCurrentPos].ilTifAuthName = strdup(String);
    01004                         break;
    01005
    01006                 case IL_CHEAD_HEADER_STRING:
    01007                         if (ilStates[ilCurrentPos].ilCHeader)
    01008                                 ifree(ilStates[ilCurrentPos].ilCHeader);
    01009                         ilStates[ilCurrentPos].ilCHeader = strdup(String);
    01010                         break;
    01011
    01012                 default:
    01013                         ilSetError(IL_INVALID_ENUM);
    01014         }
    01015
    01016         return;
    01017 }
    01018
    01019
    01020 void ILAPIENTRY ilSetInteger(ILenum Mode, ILint Param)
    01021 {
    01022         switch (Mode)
    01023         {
    01024                 // Integer values
    01025                 case IL_FORMAT_MODE:
    01026                         ilFormatFunc(Param);
    01027                         return;
    01028                 case IL_KEEP_DXTC_DATA:
    01029                         if (Param == IL_FALSE || Param == IL_TRUE) {
    01030                                 ilStates[ilCurrentPos].ilKeepDxtcData = Param;
    01031                                 return;
    01032                         }
    01033                         break;
    01034                 case IL_MAX_QUANT_INDICES:
    01035                         if (Param >= 2 && Param <= 256) {
    01036                                 ilStates[ilCurrentPos].ilQuantMaxIndexs = Param;
    01037                                 return;
    01038                         }
    01039                         break;
    01040                 case IL_NEU_QUANT_SAMPLE:
    01041                         if (Param >= 1 && Param <= 30) {
    01042                                 ilStates[ilCurrentPos].ilNeuSample = Param;
    01043                                 return;
    01044                         }
    01045                         break;
    01046                 case IL_ORIGIN_MODE:
    01047                         ilOriginFunc(Param);
    01048                         return;
    01049                 case IL_QUANTIZATION_MODE:
    01050                         if (Param == IL_WU_QUANT || Param == IL_NEU_QUANT) {
    01051                                 ilStates[ilCurrentPos].ilQuantMode = Param;
    01052                                 return;
    01053                         }
    01054                         break;
    01055                 case IL_TYPE_MODE:
    01056                         ilTypeFunc(Param);
    01057                         return;
    01058
    01059                 // Image specific values
    01060                 case IL_IMAGE_DURATION:
    01061                         if (iCurImage == NULL) {
    01062                                 ilSetError(IL_ILLEGAL_OPERATION);
    01063                                 break;
    01064                         }
    01065                         iCurImage->Duration = Param;
    01066                         return;
    01067                 case IL_IMAGE_OFFX:
    01068                         if (iCurImage == NULL) {
    01069                                 ilSetError(IL_ILLEGAL_OPERATION);
    01070                                 break;
    01071                         }
    01072                         iCurImage->OffX = Param;
    01073                         return;
    01074                 case IL_IMAGE_OFFY:
    01075                         if (iCurImage == NULL) {
    01076                                 ilSetError(IL_ILLEGAL_OPERATION);
    01077                                 break;
    01078                         }
    01079                         iCurImage->OffY = Param;
    01080                         return;
    01081                 case IL_IMAGE_CUBEFLAGS:
    01082                         if (iCurImage == NULL) {
    01083                                 ilSetError(IL_ILLEGAL_OPERATION);
    01084                                 break;
    01085                         }
    01086                         iCurImage->CubeFlags = Param;
    01087                         break;
    01088
    01089                 // Format specific values
    01090                 case IL_BMP_RLE:
    01091                         if (Param == IL_FALSE || Param == IL_TRUE) {
    01092                                 ilStates[ilCurrentPos].ilBmpRle = Param;
    01093                                 return;
    01094                         }
    01095                         break;
    01096                 case IL_DXTC_FORMAT:
    01097                         if (Param >= IL_DXT1 || Param <= IL_DXT5 || Param == IL_DXT1A) {
    01098                                 ilStates[ilCurrentPos].ilDxtcFormat = Param;
    01099                                 return;
    01100                         }
    01101                         break;
    01102                 case IL_JPG_SAVE_FORMAT:
    01103                         if (Param == IL_JFIF || Param == IL_EXIF) {
    01104                                 ilStates[ilCurrentPos].ilJpgFormat = Param;
    01105                                 return;
    01106                         }
    01107                         break;
    01108                 case IL_JPG_QUALITY:
    01109                         if (Param >= 0 && Param <= 99) {
    01110                                 ilStates[ilCurrentPos].ilJpgQuality = Param;
    01111                                 return;
    01112                         }
    01113                         break;
    01114                 case IL_PNG_INTERLACE:
    01115                         if (Param == IL_FALSE || Param == IL_TRUE) {
    01116                                 ilStates[ilCurrentPos].ilPngInterlace = Param;
    01117                                 return;
    01118                         }
    01119                         break;
    01120                 case IL_PCD_PICNUM:
    01121                         if (Param >= 0 || Param <= 2) {
    01122                                 ilStates[ilCurrentPos].ilPcdPicNum = Param;
    01123                                 return;
    01124                         }
    01125                         break;
    01126                 case IL_PNG_ALPHA_INDEX:
    01127                         if (Param >= -1 || Param <= 255) {
    01128                                 ilStates[ilCurrentPos].ilPngAlphaIndex=Param;
    01129                                 return;
    01130                         }
    01131                         break;
    01132                 case IL_SGI_RLE:
    01133                         if (Param == IL_FALSE || Param == IL_TRUE) {
    01134                                 ilStates[ilCurrentPos].ilSgiRle = Param;
    01135                                 return;
    01136                         }
    01137                         break;
    01138                 case IL_TGA_CREATE_STAMP:
    01139                         if (Param == IL_FALSE || Param == IL_TRUE) {
    01140                                 ilStates[ilCurrentPos].ilTgaCreateStamp = Param;
    01141                                 return;
    01142                         }
    01143                         break;
    01144                 case IL_TGA_RLE:
    01145                         if (Param == IL_FALSE || Param == IL_TRUE) {
    01146                                 ilStates[ilCurrentPos].ilTgaRle = Param;
    01147                                 return;
    01148                         }
    01149                         break;
    01150
    01151                 default:
    01152                         ilSetError(IL_INVALID_ENUM);
    01153                         return;
    01154         }
    01155
    01156         ilSetError(IL_INVALID_PARAM);  // Parameter not in valid bounds.
    01157         return;
    01158 }
    01159
    01160
    01161
    01162 ILint iGetInt(ILenum Mode)
    01163 {
    01164         //like ilGetInteger(), but sets another error on failure
    01165
    01166         //call ilGetIntegerv() for more robust code
    01167         ILenum err;
    01168         ILint r = -1;
    01169
    01170         ilGetIntegerv(Mode, &r);
    01171
    01172         //check if an error occured, set another error
    01173         err = ilGetError();
    01174         if (r == -1 && err == IL_INVALID_ENUM)
    01175                 ilSetError(IL_INTERNAL_ERROR);
    01176         else
    01177                 ilSetError(err); //restore error
    01178
    01179         return r;
    01180 }