- Main Page
- Data Structures
- Files

- File List

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

    00001 //-----------------------------------------------------------------------------
    00002 //
    00003 // ImageLib Sources
    00004 // Copyright (C) 2000-2002 by Denton Woods
    00005 // Last modified: 05/26/2002 <--Y2K Compliant! =]
    00006 //
    00007 // Filename: src-IL/src/il_pix.c
    00008 //
    00009 // Description: Reads from an Alias | Wavefront .pix file.
    00010 //
    00011 //-----------------------------------------------------------------------------
    00012
    00013
    00014 #include "il_internal.h"
    00015 #ifndef IL_NO_PIX
    00016 #include "il_manip.h"
    00017 #include "il_endian.h"
    00018
    00019
    00020 #ifdef _MSC_VER
    00021 #pragma pack(push, pix_struct, 1)
    00022 #endif
    00023 typedef struct PIXHEAD
    00024 {
    00025         ILushort        Width;
    00026         ILushort        Height;
    00027         ILushort        OffX;
    00028         ILushort        OffY;
    00029         ILushort        Bpp;
    00030 } IL_PACKSTRUCT PIXHEAD;
    00031 #ifdef _MSC_VER
    00032 #pragma pack(pop, pix_struct)
    00033 #endif
    00034
    00035 ILboolean iCheckPix(PIXHEAD *Header);
    00036 ILboolean iLoadPixInternal(void);
    00037
    00038
    00039 // Internal function used to get the Pix header from the current file.
    00040 ILboolean iGetPixHead(PIXHEAD *Header)
    00041 {
    00042         Header->Width = GetBigUShort();
    00043         Header->Height = GetBigUShort();
    00044         Header->OffX = GetBigUShort();
    00045         Header->OffY = GetBigUShort();
    00046         Header->Bpp = GetBigUShort();
    00047
    00048         return IL_TRUE;
    00049 }
    00050
    00051
    00052 // Internal function to get the header and check it.
    00053 ILboolean iIsValidPix()
    00054 {
    00055         PIXHEAD Head;
    00056
    00057         if (!iGetPixHead(&Head))
    00058                 return IL_FALSE;
    00059         iseek(-(ILint)sizeof(PIXHEAD), IL_SEEK_CUR);
    00060
    00061         return iCheckPix(&Head);
    00062 }
    00063
    00064
    00065 // Internal function used to check if the HEADER is a valid Pix header.
    00066 ILboolean iCheckPix(PIXHEAD *Header)
    00067 {
    00068         if (Header->Width == 0 || Header->Height == 0)
    00069                 return IL_FALSE;
    00070         if (Header->Bpp != 24)
    00071                 return IL_FALSE;
    00072         //if (Header->OffY != Header->Height)
    00073         //      return IL_FALSE;
    00074
    00075         return IL_TRUE;
    00076 }
    00077
    00078
    00080 ILboolean ilLoadPix(ILconst_string FileName)
    00081 {
    00082         ILHANDLE        PixFile;
    00083         ILboolean       bPix = IL_FALSE;
    00084
    00085         PixFile = iopenr(FileName);
    00086         if (PixFile == NULL) {
    00087                 ilSetError(IL_COULD_NOT_OPEN_FILE);
    00088                 return bPix;
    00089         }
    00090
    00091         bPix = ilLoadPixF(PixFile);
    00092         icloser(PixFile);
    00093
    00094         return bPix;
    00095 }
    00096
    00097
    00099 ILboolean ilLoadPixF(ILHANDLE File)
    00100 {
    00101         ILuint          FirstPos;
    00102         ILboolean       bRet;
    00103
    00104         iSetInputFile(File);
    00105         FirstPos = itell();
    00106         bRet = iLoadPixInternal();
    00107         iseek(FirstPos, IL_SEEK_SET);
    00108
    00109         return bRet;
    00110 }
    00111
    00112
    00114 ILboolean ilLoadPixL(const void *Lump, ILuint Size)
    00115 {
    00116         iSetInputLump(Lump, Size);
    00117         return iLoadPixInternal();
    00118 }
    00119
    00120
    00121 // Internal function used to load the Pix.
    00122 ILboolean iLoadPixInternal()
    00123 {
    00124         PIXHEAD Header;
    00125         ILuint  i, j;
    00126         ILubyte ByteHead, Colour[3];
    00127
    00128         if (iCurImage == NULL) {
    00129                 ilSetError(IL_ILLEGAL_OPERATION);
    00130                 return IL_FALSE;
    00131         }
    00132
    00133         if (!iGetPixHead(&Header))
    00134                 return IL_FALSE;
    00135         if (!iCheckPix(&Header)) {
    00136                 ilSetError(IL_INVALID_FILE_HEADER);
    00137                 return IL_FALSE;
    00138         }
    00139
    00140         if (!ilTexImage(Header.Width, Header.Height, 1, 3, IL_BGR, IL_UNSIGNED_BYTE, NULL))
    00141                 return IL_FALSE;
    00142
    00143         for (i = 0; i < iCurImage->SizeOfData; ) {
    00144                 ByteHead = igetc();
    00145                 if (iread(Colour, 1, 3) != 3)
    00146                         return IL_FALSE;
    00147                 for (j = 0; j < ByteHead; j++) {
    00148                         iCurImage->Data[i++] = Colour[0];
    00149                         iCurImage->Data[i++] = Colour[1];
    00150                         iCurImage->Data[i++] = Colour[2];
    00151                 }
    00152         }
    00153
    00154         iCurImage->Origin = IL_ORIGIN_UPPER_LEFT;
    00155
    00156         ilFixImage();
    00157
    00158         return IL_TRUE;
    00159 }
    00160
    00161 #endif//IL_NO_PIX