- Main Page
- Data Structures
- Files

- File List

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

    00001 //-----------------------------------------------------------------------------
    00002 //
    00003 // ImageLib Sources
    00004 // Copyright (C) 2000-2008 by Denton Woods
    00005 // Last modified: 10/10/2006
    00006 //
    00007 // Filename: src-IL/src/il_cut.c
    00008 //
    00009 // Description: Reads a Dr. Halo .cut file
    00010 //
    00011 //-----------------------------------------------------------------------------
    00012
    00013
    00014 #include "il_internal.h"
    00015 #ifndef IL_NO_CUT
    00016 #include "il_manip.h"
    00017 #include "il_pal.h"
    00018 #include "il_bits.h"
    00019
    00020
    00021 // Wrap it just in case...
    00022 #ifdef _MSC_VER
    00023 #pragma pack(push, packed_struct, 1)
    00024 #endif
    00025 typedef struct CUT_HEAD
    00026 {
    00027         ILushort        Width;
    00028         ILushort        Height;
    00029         ILint           Dummy;
    00030 } IL_PACKSTRUCT CUT_HEAD;
    00031 #ifdef _MSC_VER
    00032 #pragma pack(pop,  packed_struct)
    00033 #endif
    00034
    00035 ILboolean iLoadCutInternal();
    00036
    00038 ILboolean ilLoadCut(ILconst_string FileName)
    00039 {
    00040         ILHANDLE        CutFile;
    00041         ILboolean       bCut = IL_FALSE;
    00042
    00043         CutFile = iopenr(FileName);
    00044         if (CutFile == NULL) {
    00045                 ilSetError(IL_COULD_NOT_OPEN_FILE);
    00046                 return bCut;
    00047         }
    00048
    00049         bCut = ilLoadCutF(CutFile);
    00050         icloser(CutFile);
    00051
    00052         return bCut;
    00053 }
    00054
    00055
    00057 ILboolean ilLoadCutF(ILHANDLE File)
    00058 {
    00059         ILuint          FirstPos;
    00060         ILboolean       bRet;
    00061
    00062         iSetInputFile(File);
    00063         FirstPos = itell();
    00064         bRet = iLoadCutInternal();
    00065         iseek(FirstPos, IL_SEEK_SET);
    00066
    00067         return bRet;
    00068 }
    00069
    00070
    00072 ILboolean ilLoadCutL(const void *Lump, ILuint Size)
    00073 {
    00074         iSetInputLump(Lump, Size);
    00075         return iLoadCutInternal();
    00076 }
    00077
    00078
    00079 //      Note:  .Cut support has not been tested yet!
    00080 // A .cut can only have 1 bpp.
    00081 //      We need to add support for the .pal's PSP outputs with these...
    00082 ILboolean iLoadCutInternal()
    00083 {
    00084         CUT_HEAD        Header;
    00085         ILuint          Size, i = 0, j;
    00086         ILubyte         Count, Run;
    00087
    00088         if (iCurImage == NULL) {
    00089                 ilSetError(IL_ILLEGAL_OPERATION);
    00090                 return IL_FALSE;
    00091         }
    00092
    00093         Header.Width = GetLittleShort();
    00094         Header.Height = GetLittleShort();
    00095         Header.Dummy = GetLittleInt();
    00096
    00097         if (Header.Width == 0 || Header.Height == 0) {
    00098                 ilSetError(IL_INVALID_FILE_HEADER);
    00099                 return IL_FALSE;
    00100         }
    00101
    00102         if (!ilTexImage(Header.Width, Header.Height, 1, 1, IL_COLOUR_INDEX, IL_UNSIGNED_BYTE, NULL)) {  // always 1 bpp
    00103                 return IL_FALSE;
    00104         }
    00105         iCurImage->Origin = IL_ORIGIN_LOWER_LEFT;
    00106
    00107         Size = Header.Width * Header.Height;
    00108
    00109         while (i < Size) {
    00110                 Count = igetc();
    00111                 if (Count == 0) { // end of row
    00112                         igetc();  // Not supposed to be here, but
    00113                         igetc();  //  PSP is putting these two bytes here...WHY?!
    00114                         continue;
    00115                 }
    00116                 if (Count & BIT_7) {  // rle-compressed
    00117                         ClearBits(Count, BIT_7);
    00118                         Run = igetc();
    00119                         for (j = 0; j < Count; j++) {
    00120                                 iCurImage->Data[i++] = Run;
    00121                         }
    00122                 }
    00123                 else {  // run of pixels
    00124                         for (j = 0; j < Count; j++) {
    00125                                 iCurImage->Data[i++] = igetc();
    00126                         }
    00127                 }
    00128         }
    00129
    00130         iCurImage->Origin = IL_ORIGIN_UPPER_LEFT;  // Not sure
    00131
    00132         /*iCurImage->Pal.Palette = SharedPal.Palette;
    00133         iCurImage->Pal.PalSize = SharedPal.PalSize;
    00134         iCurImage->Pal.PalType = SharedPal.PalType;*/
    00135
    00136         return ilFixImage();
    00137 }
    00138
    00139 /* ?????????
    00140 void ilPopToast() {
    00141         ILstring flipCode = IL_TEXT("#flipCode and www.flipCode.com rule you all.");
    00142         flipCode[0] = flipCode[0];
    00143 }
    00144 */
    00145
    00146
    00147
    00148 #endif//IL_NO_CUT