- Main Page
- Data Structures
- Files

- File List

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

    00001 //-----------------------------------------------------------------------------
    00002 //
    00003 // ImageLib Sources
    00004 // Copyright (C) 2000-2001 by Denton Woods
    00005 // Last modified: 05/25/2001 <--Y2K Compliant! =]
    00006 //
    00007 // Filename: src-IL/src/rawdata.c
    00008 //
    00009 // Description: "Raw" file functions
    00010 //
    00011 //-----------------------------------------------------------------------------
    00012
    00013
    00014 #include "il_internal.h"
    00015 //#ifndef IL_NO_DATA
    00016 #include "il_manip.h"
    00017
    00018
    00019 ILboolean iLoadDataInternal(ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp);
    00020
    00021
    00023 ILboolean ILAPIENTRY ilLoadData(ILconst_string FileName, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp)
    00024 {
    00025         ILHANDLE        RawFile;
    00026         ILboolean       bRaw = IL_FALSE;
    00027
    00028         // No need to check for raw data
    00029         /*if (!iCheckExtension(FileName, "raw")) {
    00030                 ilSetError(IL_INVALID_EXTENSION);
    00031                 return bRaw;
    00032         }*/
    00033
    00034         RawFile = iopenr(FileName);
    00035         if (RawFile == NULL) {
    00036                 ilSetError(IL_COULD_NOT_OPEN_FILE);
    00037                 return bRaw;
    00038         }
    00039
    00040         bRaw = ilLoadDataF(RawFile, Width, Height, Depth, Bpp);
    00041         icloser(RawFile);
    00042
    00043         return bRaw;
    00044 }
    00045
    00046
    00048 ILboolean ILAPIENTRY ilLoadDataF(ILHANDLE File, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp)
    00049 {
    00050         ILuint          FirstPos;
    00051         ILboolean       bRet;
    00052
    00053         iSetInputFile(File);
    00054         FirstPos = itell();
    00055         bRet = iLoadDataInternal(Width, Height, Depth, Bpp);
    00056         iseek(FirstPos, IL_SEEK_SET);
    00057
    00058         return bRet;
    00059 }
    00060
    00061
    00063 ILboolean ILAPIENTRY ilLoadDataL(void *Lump, ILuint Size, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp)
    00064 {
    00065         iSetInputLump(Lump, Size);
    00066         return iLoadDataInternal(Width, Height, Depth, Bpp);
    00067 }
    00068
    00069
    00070 // Internal function to load a raw data image
    00071 ILboolean iLoadDataInternal(ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp)
    00072 {
    00073         if (iCurImage == NULL || ((Bpp != 1) && (Bpp != 3) && (Bpp != 4))) {
    00074                 ilSetError(IL_ILLEGAL_OPERATION);
    00075                 return IL_FALSE;
    00076         }
    00077
    00078         if (!ilTexImage(Width, Height, Depth, Bpp, 0, IL_UNSIGNED_BYTE, NULL)) {
    00079                 return IL_FALSE;
    00080         }
    00081         iCurImage->Origin = IL_ORIGIN_UPPER_LEFT;
    00082
    00083         // Tries to read the correct amount of data
    00084         if (iread(iCurImage->Data, Width * Height * Depth * Bpp, 1) != 1)
    00085                 return IL_FALSE;
    00086
    00087         if (iCurImage->Bpp == 1)
    00088                 iCurImage->Format = IL_LUMINANCE;
    00089         else if (iCurImage->Bpp == 3)
    00090                 iCurImage->Format = IL_RGB;
    00091         else  // 4
    00092                 iCurImage->Format = IL_RGBA;
    00093
    00094         ilFixImage();
    00095
    00096         return IL_TRUE;
    00097 }
    00098
    00099
    00101 ILboolean ILAPIENTRY ilSaveData(ILconst_string FileName)
    00102 {
    00103         ILHANDLE DataFile;
    00104
    00105         if (iCurImage == NULL) {
    00106                 ilSetError(IL_ILLEGAL_OPERATION);
    00107                 return IL_FALSE;
    00108         }
    00109
    00110         DataFile = iopenr(FileName);
    00111         if (DataFile == NULL) {
    00112                 ilSetError(IL_COULD_NOT_OPEN_FILE);
    00113                 return IL_FALSE;
    00114         }
    00115
    00116         iwrite(iCurImage->Data, 1, iCurImage->SizeOfData);
    00117         icloser(DataFile);
    00118
    00119         return IL_TRUE;
    00120 }
    00121
    00122
    00123 //#endif//IL_NO_DATA