- Main Page
- Data Structures
- Files

- File List

# E:/DevIL/src-IL/src/il_pxr.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_pxr.c
    00008 //
    00009 // Description: Reads from a Pxrar (.pxr) file.
    00010 //
    00011 //-----------------------------------------------------------------------------
    00012
    00013
    00014 #include "il_internal.h"
    00015 #ifndef IL_NO_PXR
    00016 #include "il_manip.h"
    00017 #include "il_endian.h"
    00018
    00019
    00020 #ifdef _MSC_VER
    00021 #pragma pack(push, pxr_struct, 1)
    00022 #endif
    00023 typedef struct PIXHEAD
    00024 {
    00025         ILushort        Signature;
    00026         ILubyte         Reserved1[413];
    00027         ILushort        Height;
    00028         ILushort        Width;
    00029         ILubyte         Reserved2[4];
    00030         ILubyte         BppInfo;
    00031         ILubyte         Reserved3[598];
    00032 } IL_PACKSTRUCT PIXHEAD;
    00033 #ifdef _MSC_VER
    00034 #pragma pack(pop, pxr_struct)
    00035 #endif
    00036
    00037 ILboolean iLoadPxrInternal(void);
    00038
    00039
    00041 ILboolean ilLoadPxr(ILconst_string FileName)
    00042 {
    00043         ILHANDLE        PxrFile;
    00044         ILboolean       bPxr = IL_FALSE;
    00045
    00046         PxrFile = iopenr(FileName);
    00047         if (PxrFile == NULL) {
    00048                 ilSetError(IL_COULD_NOT_OPEN_FILE);
    00049                 return bPxr;
    00050         }
    00051
    00052         bPxr = ilLoadPxrF(PxrFile);
    00053         icloser(PxrFile);
    00054
    00055         return bPxr;
    00056 }
    00057
    00058
    00060 ILboolean ilLoadPxrF(ILHANDLE File)
    00061 {
    00062         ILuint          FirstPos;
    00063         ILboolean       bRet;
    00064
    00065         iSetInputFile(File);
    00066         FirstPos = itell();
    00067         bRet = iLoadPxrInternal();
    00068         iseek(FirstPos, IL_SEEK_SET);
    00069
    00070         return bRet;
    00071 }
    00072
    00073
    00075 ILboolean ilLoadPxrL(const void *Lump, ILuint Size)
    00076 {
    00077         iSetInputLump(Lump, Size);
    00078         return iLoadPxrInternal();
    00079 }
    00080
    00081
    00082 // Internal function used to load the Pxr.
    00083 ILboolean iLoadPxrInternal()
    00084 {
    00085         ILushort        Width, Height;
    00086         ILubyte         Bpp;
    00087
    00088         Width = sizeof(PIXHEAD);
    00089
    00090         iseek(416, IL_SEEK_SET);
    00091         Height = GetLittleUShort();
    00092         Width = GetLittleUShort();
    00093         iseek(424, IL_SEEK_SET);
    00094         Bpp = (ILubyte)igetc();
    00095
    00096         switch (Bpp)
    00097         {
    00098                 case 0x08:
    00099                         ilTexImage(Width, Height, 1, 1, IL_LUMINANCE, IL_UNSIGNED_BYTE, NULL);
    00100                         break;
    00101                 case 0x0E:
    00102                         ilTexImage(Width, Height, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, NULL);
    00103                         break;
    00104                 case 0x0F:
    00105                         ilTexImage(Width, Height, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, NULL);
    00106                         break;
    00107                 default:
    00108                         ilSetError(IL_INVALID_FILE_HEADER);
    00109                         return IL_FALSE;
    00110         }
    00111
    00112         iseek(1024, IL_SEEK_SET);
    00113         iread(iCurImage->Data, 1, iCurImage->SizeOfData);
    00114         iCurImage->Origin = IL_ORIGIN_UPPER_LEFT;
    00115
    00116         return IL_TRUE;
    00117 }
    00118
    00119
    00120 #endif//IL_NO_PXR