//! Checks if the file specified in FileName is a valid .jpg file. ILboolean ilIsValid_JPEG(ILconst_string FileName) { ILHANDLE JpegFile; ILboolean bJpeg = IL_FALSE; if (!iCheckExtension(FileName, IL_TEXT("jpg")) && !iCheckExtension(FileName, IL_TEXT("jpe")) && !iCheckExtension(FileName, IL_TEXT("jpeg")) && !iCheckExtension(FileName, IL_TEXT("jif")) && !iCheckExtension(FileName, IL_TEXT("jfif"))) { ilSetError(IL_INVALID_EXTENSION); return bJpeg; } JpegFile = iopenr(FileName); if (JpegFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return bJpeg; } bJpeg = ilIsValidF_JPEG(JpegFile); icloser(JpegFile); return bJpeg; }
ILboolean ilisValidTiffExtension(ILconst_string FileName) { if (!iCheckExtension((ILstring)FileName, IL_TEXT("tif")) && !iCheckExtension((ILstring)FileName, IL_TEXT("tiff"))) return IL_FALSE; else return IL_TRUE; }
//! Loads a palette from FileName into the current image's palette. ILboolean ILAPIENTRY ilLoadPal(ILconst_string FileName) { FILE *f; ILboolean IsPsp; char Head[8]; if (FileName == NULL) { ilSetError(IL_INVALID_PARAM); return IL_FALSE; } if (iCheckExtension(FileName, IL_TEXT("col"))) { return ilLoadColPal(FileName); } if (iCheckExtension(FileName, IL_TEXT("act"))) { return ilLoadActPal(FileName); } if (iCheckExtension(FileName, IL_TEXT("plt"))) { return ilLoadPltPal(FileName); } #ifndef _UNICODE f = fopen(FileName, "rt"); #else f = _wfopen(FileName, L"rt"); #endif//_UNICODE if (f == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return IL_FALSE; } fread(Head, 1, 8, f); if (!strncmp(Head, "JASC-PAL", 8)) IsPsp = IL_TRUE; else IsPsp = IL_FALSE; fclose(f); if (IsPsp) return ilLoadJascPal(FileName); return ilLoadHaloPal(FileName); }
//! Checks if the file specified in FileName is a valid DICOM file. ILboolean ilIsValidDicom(ILconst_string FileName) { ILHANDLE DicomFile; ILboolean bDicom = IL_FALSE; if (!iCheckExtension(FileName, IL_TEXT("dicom")) && !iCheckExtension(FileName, IL_TEXT("dcm"))) { ilSetError(IL_INVALID_EXTENSION); return bDicom; } DicomFile = iopenr(FileName); if (DicomFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return bDicom; } bDicom = ilIsValidDicomF(DicomFile); icloser(DicomFile); return bDicom; }
//! Checks if the file specified in FileName is a valid .jp2 file. ILboolean ilIsValid_JP2(ILconst_string FileName) { ILHANDLE Jp2File; ILboolean bJp2 = IL_FALSE; if (!iCheckExtension(FileName, IL_TEXT("jp2")) && !iCheckExtension(FileName, IL_TEXT("jpx")) && !iCheckExtension(FileName, IL_TEXT("j2k")) && !iCheckExtension(FileName, IL_TEXT("j2c"))) { ilSetError(IL_INVALID_EXTENSION); return bJp2; } Jp2File = iopenr(FileName); if (Jp2File == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return bJp2; } bJp2 = ilIsValidF_JP2(Jp2File); icloser(Jp2File); return bJp2; }
//! Checks if the file specified in FileName is a valid Psd file. ILboolean ilIsValidPsd(ILconst_string FileName) { ILHANDLE PsdFile; ILboolean bPsd = IL_FALSE; if (!iCheckExtension(FileName, IL_TEXT("psd")) && !iCheckExtension(FileName, IL_TEXT("pdd"))) { ilSetError(IL_INVALID_EXTENSION); return bPsd; } PsdFile = iopenr(FileName); if (PsdFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return bPsd; } bPsd = ilIsValidPsdF(PsdFile); icloser(PsdFile); return bPsd; }
//! Checks if the file specified in FileName is a valid .pnm file. ILboolean ilIsValidPnm(const ILstring FileName) { ILHANDLE PnmFile; ILboolean bPnm = IL_FALSE; if ( !iCheckExtension(FileName, IL_TEXT("pbm")) && !iCheckExtension(FileName, IL_TEXT("pgm")) && !iCheckExtension(FileName, IL_TEXT("ppm")) && !iCheckExtension(FileName, IL_TEXT("pnm"))) { ilSetError(IL_INVALID_EXTENSION); return bPnm; } PnmFile = iopenr(FileName); if (PnmFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return bPnm; } bPnm = ilIsValidPnmF(PnmFile); icloser(PnmFile); return bPnm; }
ILboolean ilIsValidIlbm(ILconst_string FileName) { ILHANDLE f; ILboolean bIlbm = IL_FALSE; if (!iCheckExtension(FileName, IL_TEXT("iff")) && !iCheckExtension(FileName, IL_TEXT("ilbm")) && !iCheckExtension(FileName, IL_TEXT("lbm")) && !iCheckExtension(FileName, IL_TEXT("ham")) ) { ilSetError(IL_INVALID_EXTENSION); return bIlbm; } f = iopenr(FileName); if (f == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return bIlbm; } bIlbm = ilIsValidIlbmF(f); icloser(f); return bIlbm; }
//! Loads an .plt palette file. ILboolean ilLoadPltPal(ILconst_string FileName) { ILHANDLE PltFile; if (!iCheckExtension(FileName, IL_TEXT("plt"))) { ilSetError(IL_INVALID_EXTENSION); return IL_FALSE; } if (iCurImage == NULL) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } PltFile = iopenr(FileName); if (PltFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return IL_FALSE; } if (iCurImage->Pal.Palette && iCurImage->Pal.PalSize > 0 && iCurImage->Pal.PalType != IL_PAL_NONE) { ifree(iCurImage->Pal.Palette); iCurImage->Pal.Palette = NULL; } iCurImage->Pal.PalSize = GetLittleUInt(); if (iCurImage->Pal.PalSize == 0) { ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; } iCurImage->Pal.PalType = IL_PAL_RGB24; iCurImage->Pal.Palette = (ILubyte*)ialloc(iCurImage->Pal.PalSize); if (!iCurImage->Pal.Palette) { icloser(PltFile); return IL_FALSE; } if (iread(iCurImage->Pal.Palette, iCurImage->Pal.PalSize, 1) != 1) { ifree(iCurImage->Pal.Palette); iCurImage->Pal.Palette = NULL; icloser(PltFile); return IL_FALSE; } icloser(PltFile); return IL_TRUE; }
//! Loads an .act palette file. ILboolean ilLoadActPal(ILconst_string FileName) { ILHANDLE ActFile; if (!iCheckExtension(FileName, IL_TEXT("act"))) { ilSetError(IL_INVALID_EXTENSION); return IL_FALSE; } if (iCurImage == NULL) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } ActFile = iopenr(FileName); if (ActFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return IL_FALSE; } if (iCurImage->Pal.Palette && iCurImage->Pal.PalSize > 0 && iCurImage->Pal.PalType != IL_PAL_NONE) { ifree(iCurImage->Pal.Palette); iCurImage->Pal.Palette = NULL; } iCurImage->Pal.PalType = IL_PAL_RGB24; iCurImage->Pal.PalSize = 768; iCurImage->Pal.Palette = (ILubyte*)ialloc(768); if (!iCurImage->Pal.Palette) { icloser(ActFile); return IL_FALSE; } if (iread(iCurImage->Pal.Palette, 1, 768) != 768) { icloser(ActFile); return IL_FALSE; } icloser(ActFile); return IL_TRUE; }
//! Checks if the file specified in FileName is a valid .icns file. ILboolean ilIsValidIcns(ILconst_string FileName) { ILHANDLE IcnsFile; ILboolean bIcns = IL_FALSE; if (!iCheckExtension(FileName, IL_TEXT("icns"))) { ilSetError(IL_INVALID_EXTENSION); return bIcns; } IcnsFile = iopenr(FileName); if (IcnsFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return bIcns; } bIcns = ilIsValidIcnsF(IcnsFile); icloser(IcnsFile); return bIcns; }
//! Checks if the file specified in FileName is a valid .pcx file. ILboolean ilIsValidPcx(const ILstring FileName) { ILHANDLE PcxFile; ILboolean bPcx = IL_FALSE; if (!iCheckExtension(FileName, IL_TEXT("pcx"))) { ilSetError(IL_INVALID_EXTENSION); return bPcx; } PcxFile = iopenr(FileName); if (PcxFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return bPcx; } bPcx = ilIsValidPcxF(PcxFile); icloser(PcxFile); return bPcx; }
//! Checks if the file specified in FileName is a valid BLP file. ILboolean ilIsValidBlp(ILconst_string FileName) { ILHANDLE BlpFile; ILboolean bBlp = IL_FALSE; if (!iCheckExtension(FileName, IL_TEXT("blp"))) { ilSetError(IL_INVALID_EXTENSION); return bBlp; } BlpFile = iopenr(FileName); if (BlpFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return bBlp; } bBlp = ilIsValidBlpF(BlpFile); icloser(BlpFile); return bBlp; }
//! Checks if the file specified in FileName is a valid Gif file. ILboolean ilIsValidGif(const ILstring FileName) { ILHANDLE GifFile; ILboolean bGif = IL_FALSE; if (!iCheckExtension(FileName, IL_TEXT("gif"))) { ilSetError(IL_INVALID_EXTENSION); return bGif; } GifFile = iopenr(FileName); if (GifFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return bGif; } bGif = ilIsValidGifF(GifFile); icloser(GifFile); return bGif; }
//! Checks if the file specified in FileName is a valid MDL file. ILboolean ilIsValidMdl(ILconst_string FileName) { ILHANDLE MdlFile; ILboolean bMdl = IL_FALSE; if (!iCheckExtension(FileName, IL_TEXT("mdl"))) { ilSetError(IL_INVALID_EXTENSION); return bMdl; } MdlFile = iopenr(FileName); if (MdlFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return bMdl; } bMdl = ilIsValidMdlF(MdlFile); icloser(MdlFile); return bMdl; }
ILboolean ilIsValidKtx(ILconst_string FileName) { ILHANDLE KtxFile; ILboolean bKtx = IL_FALSE; if (!iCheckExtension(FileName, IL_TEXT("ktx"))) { ilSetError(IL_INVALID_EXTENSION); return bKtx; } KtxFile = iopenr(FileName); if (KtxFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return bKtx; } bKtx = ilIsValidKtxF(KtxFile); icloser(KtxFile); return bKtx; }
//! Checks if the file specified in FileName is a valid .bmp file. ILboolean ilIsValidBmp(ILconst_string CONST_RESTRICT FileName) { ILHANDLE BitmapFile; ILboolean bBitmap = IL_FALSE; if (!iCheckExtension(FileName, IL_TEXT("bmp"))) { ilSetError(IL_INVALID_EXTENSION); return bBitmap; } BitmapFile = iopenr(FileName); if (BitmapFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return bBitmap; } bBitmap = ilIsValidBmpF(BitmapFile); icloser(BitmapFile); return bBitmap; }
//! Checks if the file specified in FileName is a valid XPM file. ILboolean ilIsValidXpm(ILconst_string FileName) { ILHANDLE XpmFile; ILboolean bXpm = IL_FALSE; if (!iCheckExtension(FileName, IL_TEXT("xpm"))) { ilSetError(IL_INVALID_EXTENSION); return bXpm; } XpmFile = iopenr(FileName); if (XpmFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return bXpm; } bXpm = ilIsValidXpmF(XpmFile); icloser(XpmFile); return bXpm; }
//! Checks if the file specified in FileName is a valid .hdr file. ILboolean ilIsValidHdr(ILconst_string FileName) { ILHANDLE HdrFile; ILboolean bHdr = IL_FALSE; if (!iCheckExtension(FileName, IL_TEXT("hdr"))) { ilSetError(IL_INVALID_EXTENSION); return bHdr; } HdrFile = iopenr(FileName); if (HdrFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return bHdr; } bHdr = ilIsValidHdrF(HdrFile); icloser(HdrFile); return bHdr; }
/*! Checks if the file specified in FileName is a valid .sgi file. */ ILboolean ilIsValidSgi(ILconst_string FileName) { ILHANDLE SgiFile; ILboolean bSgi = IL_FALSE; if (!iCheckExtension(FileName, IL_TEXT("sgi"))) { ilSetError(IL_INVALID_EXTENSION); return bSgi; } FName = (char*)FileName; SgiFile = iopenr(FileName); if (SgiFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return bSgi; } bSgi = ilIsValidSgiF(SgiFile); icloser(SgiFile); return bSgi; }
//! Checks if the file specified in FileName is a valid Sun file. ILboolean ilIsValid_SUN(ILconst_string FileName) { ILHANDLE SunFile; ILboolean bSun = IL_FALSE; if (!iCheckExtension(FileName, IL_TEXT("sun")) && !iCheckExtension(FileName, IL_TEXT("ras")) && !iCheckExtension(FileName, IL_TEXT("im1")) && !iCheckExtension(FileName, IL_TEXT("im8")) && !iCheckExtension(FileName, IL_TEXT("im24")) && !iCheckExtension(FileName, IL_TEXT("im32")) && !iCheckExtension(FileName, IL_TEXT("rs"))) { // Lots of names possible... ilSetError(IL_INVALID_EXTENSION); return bSun; } SunFile = iopenr(FileName); if (SunFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return bSun; } bSun = ilIsValidF_SUN(SunFile); icloser(SunFile); return bSun; }
// Description: State machine // // // 20040223 XIX : now has a ilPngAlphaIndex member, so we can spit out png files with a transparent index, set to -1 for none // //----------------------------------------------------------------------------- #include "il_internal.h" #include "il_states.h" #include "il_stack.h" //#include <malloc.h> #include <stdlib.h> // Global variables ILconst_string _ilVendor = IL_TEXT("Abysmal Software"); ILconst_string _ilVersion = IL_TEXT("Developer's Image Library (DevIL) 1.7.8"); char* _ilLoadExt = "" IL_BLP_EXT IL_BMP_EXT IL_CUT_EXT IL_DCX_EXT IL_DDS_EXT IL_DCM_EXT IL_DPX_EXT IL_EXR_EXT IL_FITS_EXT IL_FTX_EXT IL_GIF_EXT IL_HDR_EXT IL_ICNS_EXT IL_ICO_EXT IL_IFF_EXT IL_IWI_EXT IL_JPG_EXT IL_JP2_EXT IL_LIF_EXT IL_MDL_EXT IL_MNG_EXT IL_MP3_EXT IL_PCD_EXT IL_PCX_EXT IL_PIC_EXT IL_PIX_EXT IL_PNG_EXT IL_PNM_EXT IL_PSD_EXT IL_PSP_EXT IL_PXR_EXT IL_RAW_EXT IL_ROT_EXT IL_SGI_EXT IL_SUN_EXT IL_TEX_EXT IL_TGA_EXT IL_TIF_EXT IL_TPL_EXT IL_UTX_EXT IL_VTF_EXT IL_WAL_EXT IL_WDP_EXT IL_XPM_EXT; char* _ilSaveExt = "" IL_BMP_EXT IL_CHEAD_EXT IL_DDS_EXT IL_EXR_EXT IL_HDR_EXT IL_JP2_EXT IL_JPG_EXT IL_PCX_EXT
// Filename: src-IL/src/il_states.c // // Description: State machine // // // 20040223 XIX : now has a ilPngAlphaIndex member, so we can spit out png files with a transparent index, set to -1 for none // //----------------------------------------------------------------------------- #include "il_internal.h" #include "il_states.h" //#include <malloc.h> #include <stdlib.h> ILstring _ilVendor = IL_TEXT("Abysmal Software"); ILstring _ilVersion = IL_TEXT("Developer's Image Library (DevIL) 1.6.8pre " __DATE__); ILstring _ilLoadExt = "" IL_BMP_EXT IL_CUT_EXT IL_DCX_EXT IL_DDS_EXT IL_GIF_EXT IL_HDR_EXT IL_ICO_EXT IL_JPG_EXT IL_LIF_EXT IL_MDL_EXT IL_MNG_EXT IL_PCX_EXT IL_PIC_EXT IL_PIX_EXT IL_PNG_EXT IL_PNM_EXT IL_PSD_EXT IL_PSP_EXT IL_PXR_EXT IL_SGI_EXT IL_TGA_EXT IL_TIF_EXT IL_WAL_EXT IL_XPM_EXT; ILstring _ilSaveExt = "" IL_BMP_EXT IL_CHEAD_EXT IL_DDS_EXT IL_JPG_EXT IL_PCX_EXT IL_PNG_EXT IL_PNM_EXT IL_PSD_EXT IL_SGI_EXT IL_TGA_EXT IL_TIF_EXT; //! Set all states to their defaults.
//! Generates a C-style header file for the current image. ILboolean ilSaveCHeader(ILconst_string FileName, char *InternalName) { FILE *HeadFile; ILuint i = 0, j; ILimage *TempImage; const char *Name; if (iCurImage == NULL) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } Name = iGetString(IL_CHEAD_HEADER_STRING); if (Name == NULL) Name = InternalName; if (FileName == NULL || Name == NULL || ilStrLen(FileName) < 1 || ilCharStrLen(Name) < 1) { ilSetError(IL_INVALID_VALUE); return IL_FALSE; } if (!iCheckExtension(FileName, IL_TEXT("h"))) { ilSetError(IL_INVALID_EXTENSION); return IL_FALSE; } if (ilGetBoolean(IL_FILE_MODE) == IL_FALSE) { if (iFileExists(FileName)) { ilSetError(IL_FILE_ALREADY_EXISTS); return IL_FALSE; } } if (iCurImage->Bpc > 1) { TempImage = iConvertImage(iCurImage, iCurImage->Format, IL_UNSIGNED_BYTE); if (TempImage == NULL) return IL_FALSE; } else { TempImage = iCurImage; } #ifndef _UNICODE HeadFile = fopen(FileName, "wb"); #else HeadFile = _wfopen(FileName, L"rb"); #endif//_UNICODE if (HeadFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return IL_FALSE; } fprintf(HeadFile, "//#include <il/il.h>\n"); fprintf(HeadFile, "// C Image Header:\n\n\n"); fprintf(HeadFile, "// IMAGE_BPP is in bytes per pixel, *not* bits\n"); fprintf(HeadFile, "#define IMAGE_BPP %d\n",iCurImage->Bpp); fprintf(HeadFile, "#define IMAGE_WIDTH %d\n", iCurImage->Width); fprintf(HeadFile, "#define IMAGE_HEIGHT %d\n", iCurImage->Height); fprintf(HeadFile, "#define IMAGE_DEPTH %d\n\n\n", iCurImage->Depth); fprintf(HeadFile, "#define IMAGE_TYPE 0x%X\n", iCurImage->Type); fprintf(HeadFile, "#define IMAGE_FORMAT 0x%X\n\n\n", iCurImage->Format); fprintf(HeadFile, "ILubyte %s[] = {\n", Name); for (; i < TempImage->SizeOfData; i += MAX_LINE_WIDTH) { fprintf(HeadFile, "\t"); for (j = 0; j < MAX_LINE_WIDTH; j++) { if (i + j >= TempImage->SizeOfData - 1) { fprintf(HeadFile, "%4d", TempImage->Data[i+j]); break; } else fprintf(HeadFile, "%4d,", TempImage->Data[i+j]); } fprintf(HeadFile, "\n"); } if (TempImage != iCurImage) ilCloseImage(TempImage); fprintf(HeadFile, "};\n"); if (iCurImage->Pal.Palette && iCurImage->Pal.PalSize && iCurImage->Pal.PalType != IL_PAL_NONE) { fprintf(HeadFile, "\n\n"); fprintf(HeadFile, "#define IMAGE_PALSIZE %u\n\n", iCurImage->Pal.PalSize); fprintf(HeadFile, "#define IMAGE_PALTYPE 0x%X\n\n", iCurImage->Pal.PalType); fprintf(HeadFile, "ILubyte %sPal[] = {\n", Name); for (i = 0; i < iCurImage->Pal.PalSize; i += MAX_LINE_WIDTH) { fprintf(HeadFile, "\t"); for (j = 0; j < MAX_LINE_WIDTH; j++) { if (i + j >= iCurImage->Pal.PalSize - 1) { fprintf(HeadFile, " %4d", iCurImage->Pal.Palette[i+j]); break; } else fprintf(HeadFile, " %4d,", iCurImage->Pal.Palette[i+j]); } fprintf(HeadFile, "\n"); } fprintf(HeadFile, "};\n"); } fclose(HeadFile); return IL_TRUE; }
ILboolean ILAPIENTRY ilSavePal(ILconst_string FileName) { ILstring Ext = iGetExtension(FileName); if (iCurImage == NULL) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } #ifndef _UNICODE if (FileName == NULL || strlen(FileName) < 1 || Ext == NULL) { #else if (FileName == NULL || wcslen(FileName) < 1 || Ext == NULL) { #endif//_UNICODE ilSetError(IL_INVALID_PARAM); return IL_FALSE; } if (!iCurImage->Pal.Palette || !iCurImage->Pal.PalSize || iCurImage->Pal.PalType == IL_PAL_NONE) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } if (!iStrCmp(Ext, IL_TEXT("pal"))) { return ilSaveJascPal(FileName); } ilSetError(IL_INVALID_EXTENSION); return IL_FALSE; } //! Saves a Paint Shop Pro formatted palette (.pal) file. ILboolean ilSaveJascPal(ILconst_string FileName) { FILE *PalFile; ILuint i, PalBpp, NumCols = ilGetInteger(IL_PALETTE_NUM_COLS); ILubyte *CurPal; if (iCurImage == NULL || NumCols == 0 || NumCols > 256) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } #ifndef _UNICODE if (FileName == NULL || strlen(FileName) < 5) { #else if (FileName == NULL || wcslen(FileName) < 5) { #endif//_UNICODE ilSetError(IL_INVALID_VALUE); return IL_FALSE; } if (!iCheckExtension(FileName, IL_TEXT("pal"))) { ilSetError(IL_INVALID_EXTENSION); return IL_FALSE; } if (ilGetBoolean(IL_FILE_MODE) == IL_FALSE) { if (iFileExists(FileName)) { ilSetError(IL_FILE_ALREADY_EXISTS); return IL_FALSE; } } // Create a copy of the current palette and convert it to RGB24 format. CurPal = iCurImage->Pal.Palette; iCurImage->Pal.Palette = (ILubyte*)ialloc(iCurImage->Pal.PalSize); if (!iCurImage->Pal.Palette) { iCurImage->Pal.Palette = CurPal; return IL_FALSE; } memcpy(iCurImage->Pal.Palette, CurPal, iCurImage->Pal.PalSize); if (!ilConvertPal(IL_PAL_RGB24)) { ifree(iCurImage->Pal.Palette); iCurImage->Pal.Palette = CurPal; return IL_FALSE; } #ifndef _UNICODE PalFile = fopen(FileName, "wt"); #else PalFile = _wfopen(FileName, L"wt"); #endif//_UNICODE if (!PalFile) { ilSetError(IL_COULD_NOT_OPEN_FILE); return IL_FALSE; } // Header needed on all .pal files fputs("JASC-PAL\n0100\n256\n", PalFile); PalBpp = ilGetBppPal(iCurImage->Pal.PalType); for (i = 0; i < iCurImage->Pal.PalSize; i += PalBpp) { fprintf(PalFile, "%d %d %d\n", iCurImage->Pal.Palette[i], iCurImage->Pal.Palette[i+1], iCurImage->Pal.Palette[i+2]); } NumCols = 256 - NumCols; for (i = 0; i < NumCols; i++) { fprintf(PalFile, "0 0 0\n"); } ifree(iCurImage->Pal.Palette); iCurImage->Pal.Palette = CurPal; fclose(PalFile); return IL_TRUE; } //! Loads a Halo formatted palette (.pal) file. ILboolean ilLoadHaloPal(ILconst_string FileName) { ILHANDLE HaloFile; HALOHEAD HaloHead; ILushort *TempPal; ILuint i, Size; if (!iCheckExtension(FileName, IL_TEXT("pal"))) { ilSetError(IL_INVALID_EXTENSION); return IL_FALSE; } if (iCurImage == NULL) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } HaloFile = iopenr(FileName); if (HaloFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return IL_FALSE; } if (iread(&HaloHead, sizeof(HALOHEAD), 1) != 1) return IL_FALSE; if (HaloHead.Id != 'A' + ('H' << 8) || HaloHead.Version != 0xe3) { icloser(HaloFile); ilSetError(IL_ILLEGAL_FILE_VALUE); return IL_FALSE; } Size = (HaloHead.MaxIndex + 1) * 3; TempPal = (ILushort*)ialloc(Size * sizeof(ILushort)); if (TempPal == NULL) { icloser(HaloFile); return IL_FALSE; } if (iread(TempPal, sizeof(ILushort), Size) != Size) { icloser(HaloFile); ifree(TempPal); return IL_FALSE; } if (iCurImage->Pal.Palette && iCurImage->Pal.PalSize > 0 && iCurImage->Pal.PalType != IL_PAL_NONE) { ifree(iCurImage->Pal.Palette); iCurImage->Pal.Palette = NULL; } iCurImage->Pal.PalType = IL_PAL_RGB24; iCurImage->Pal.PalSize = Size; iCurImage->Pal.Palette = (ILubyte*)ialloc(iCurImage->Pal.PalSize); if (iCurImage->Pal.Palette == NULL) { icloser(HaloFile); return IL_FALSE; } for (i = 0; i < iCurImage->Pal.PalSize; i++, TempPal++) { iCurImage->Pal.Palette[i] = (ILubyte)*TempPal; } TempPal -= iCurImage->Pal.PalSize; ifree(TempPal); icloser(HaloFile); return IL_TRUE; }
// Internal function used to save the Pnm. ILboolean iSavePnmInternal() { ILuint Bpp, MaxVal = UCHAR_MAX, i = 0, j, k; ILenum Type = 0; ILuint LinePos = 0; // Cannot exceed 70 for pnm's! ILboolean Binary; ILimage *TempImage; ILubyte *TempData; if (iCurImage == NULL) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } if (iCheckExtension(FName, IL_TEXT("pbm"))) Type = IL_PBM_ASCII; else if (iCheckExtension(FName, IL_TEXT("pgm"))) Type = IL_PGM_ASCII; else if (iCheckExtension(FName, IL_TEXT("ppm"))) Type = IL_PPM_ASCII; else Type = IL_PPM_ASCII; /*if (!Type) { ilSetError(IL_INVALID_EXTENSION); return IL_FALSE; }*/ if (iGetHint(IL_COMPRESSION_HINT) == IL_USE_COMPRESSION) { Type += 3; Binary = IL_TRUE; } else { Binary = IL_FALSE; } if (iCurImage->Type == IL_UNSIGNED_BYTE) { MaxVal = UCHAR_MAX; } else if (iCurImage->Type == IL_UNSIGNED_SHORT) { MaxVal = USHRT_MAX; } else { ilSetError(IL_FORMAT_NOT_SUPPORTED); return IL_FALSE; } if (MaxVal > UCHAR_MAX && Type >= IL_PBM_BINARY) { // binary cannot be higher than 255 ilSetError(IL_FORMAT_NOT_SUPPORTED); return IL_FALSE; } switch (Type) { case IL_PBM_ASCII: Bpp = 1; ilprintf("P1\n"); TempImage = iConvertImage(iCurImage, IL_LUMINANCE, IL_UNSIGNED_BYTE); break; //case IL_PBM_BINARY: // Don't want to mess with saving bits just yet... //Bpp = 1; //ilprintf("P4\n"); //break; case IL_PBM_BINARY: ilSetError(IL_FORMAT_NOT_SUPPORTED); return IL_FALSE; case IL_PGM_ASCII: Bpp = 1; ilprintf("P2\n"); TempImage = iConvertImage(iCurImage, IL_COLOUR_INDEX, IL_UNSIGNED_BYTE); break; case IL_PGM_BINARY: Bpp = 1; ilprintf("P5\n"); TempImage = iConvertImage(iCurImage, IL_COLOUR_INDEX, IL_UNSIGNED_BYTE); break; case IL_PPM_ASCII: Bpp = 3; ilprintf("P3\n"); TempImage = iConvertImage(iCurImage, IL_RGB, IL_UNSIGNED_BYTE); break; case IL_PPM_BINARY: Bpp = 3; ilprintf("P6\n"); TempImage = iConvertImage(iCurImage, IL_RGB, IL_UNSIGNED_BYTE); break; default: ilSetError(IL_INTERNAL_ERROR); return IL_FALSE; } if (TempImage == NULL) return IL_FALSE; if (Bpp != TempImage->Bpp) { ilSetError(IL_INVALID_CONVERSION); return IL_FALSE; } if (TempImage->Origin != IL_ORIGIN_UPPER_LEFT) { TempData = iGetFlipped(TempImage); if (TempData == NULL) { ilCloseImage(TempImage); return IL_FALSE; } } else { TempData = TempImage->Data; } ilprintf("%d %d\n", TempImage->Width, TempImage->Height); if (Type != IL_PBM_BINARY && Type != IL_PBM_ASCII) // not needed for .pbm's (only 0 and 1) ilprintf("%d\n", MaxVal); while (i < TempImage->SizeOfPlane) { for (j = 0; j < Bpp; j++) { if (Binary) { if (Type == IL_PBM_BINARY) { iputc((ILubyte)(TempData[i] > 127 ? 1 : 0)); } else { iputc(TempData[i]); } } else { if (TempImage->Type == IL_UNSIGNED_BYTE) k = TempData[i]; else // IL_UNSIGNED_SHORT k = *((ILushort*)TempData + i); if (Type == IL_PBM_ASCII) { LinePos += ilprintf("%d ", TempData[i] > 127 ? 1 : 0); } else { LinePos += ilprintf("%d ", TempData[i]); } } if (TempImage->Type == IL_UNSIGNED_SHORT) i++; i++; } if (LinePos > 65) { // Just a good number =] ilprintf("\n"); LinePos = 0; } } if (TempImage->Origin != IL_ORIGIN_UPPER_LEFT) ifree(TempData); ilCloseImage(TempImage); return IL_TRUE; }
//! Loads a Paint Shop Pro formatted palette (.pal) file. ILboolean ilLoadJascPal(ILconst_string FileName) { FILE *PalFile; ILuint NumColours, i, c; ILubyte Buff[BUFFLEN]; ILboolean Error = IL_FALSE; ILpal *Pal = &iCurImage->Pal; if (!iCheckExtension(FileName, IL_TEXT("pal"))) { ilSetError(IL_INVALID_EXTENSION); return IL_FALSE; } if (iCurImage == NULL) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } #ifndef _UNICODE PalFile = fopen(FileName, "rt"); #else PalFile = _wfopen(FileName, L"rt"); #endif//_UNICODE if (PalFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return IL_FALSE; } if (iCurImage->Pal.Palette && iCurImage->Pal.PalSize > 0 && iCurImage->Pal.PalType != IL_PAL_NONE) { ifree(iCurImage->Pal.Palette); iCurImage->Pal.Palette = NULL; } iFgetw(Buff, BUFFLEN, PalFile); if (stricmp((const char*)Buff, "JASC-PAL")) { Error = IL_TRUE; } iFgetw(Buff, BUFFLEN, PalFile); if (stricmp((const char*)Buff, "0100")) { Error = IL_TRUE; } iFgetw(Buff, BUFFLEN, PalFile); NumColours = atoi((const char*)Buff); if (NumColours == 0 || Error) { ilSetError(IL_INVALID_FILE_HEADER); fclose(PalFile); return IL_FALSE; } Pal->PalSize = NumColours * PALBPP; Pal->PalType = IL_PAL_RGB24; Pal->Palette = (ILubyte*)ialloc(NumColours * PALBPP); if (Pal->Palette == NULL) { fclose(PalFile); return IL_FALSE; } for (i = 0; i < NumColours; i++) { for (c = 0; c < PALBPP; c++) { iFgetw(Buff, BUFFLEN, PalFile); Pal->Palette[i * PALBPP + c] = atoi((const char*)Buff); } } fclose(PalFile); return IL_TRUE; }
// ImageLib Utility Sources // Copyright (C) 2000-2009 by Denton Woods // Last modified: 03/07/2009 // // Filename: src-ILU/src/ilu_states.c // // Description: The state machine // //----------------------------------------------------------------------------- #include "ilu_internal.h" #include "ilu_states.h" ILconst_string _iluVendor = IL_TEXT("Abysmal Software"); ILconst_string _iluVersion = IL_TEXT("Developer's Image Library Utilities (ILU) 1.7.8");// IL_TEXT(__DATE__)); ILstring ILAPIENTRY iluGetString(ILenum StringName) { switch (StringName) { case ILU_VENDOR: return (ILstring)_iluVendor; //changed 2003-09-04 case ILU_VERSION_NUM: return (ILstring)_iluVersion; default: ilSetError(ILU_INVALID_PARAM); break;
snprintf(tmp, sizeof(tmp), " %4d", image->Pal.Palette[i+j]); SIOputs(io, tmp); break; } else { snprintf(tmp, sizeof(tmp), " %4d,", image->Pal.Palette[i+j]); SIOputs(io, tmp); } } SIOputs(io, "\n"); } SIOputs(io, "};\n"); } return IL_TRUE; } static ILconst_string iFormatExtsCHEAD[] = { IL_TEXT("h"), NULL }; ILformat iFormatCHEAD = { /* .Validate = */ NULL, /* .Load = */ NULL, /* .Save = */ iSaveCHEADInternal, /* .Exts = */ iFormatExtsCHEAD }; #endif//IL_NO_CHEAD
//! Loads a .col palette file ILboolean ilLoadColPal(ILconst_string FileName) { ILuint RealFileSize, FileSize; ILushort Version; ILHANDLE ColFile; if (!iCheckExtension(FileName, IL_TEXT("col"))) { ilSetError(IL_INVALID_EXTENSION); return IL_FALSE; } if (iCurImage == NULL) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } ColFile = iopenr(FileName); if (ColFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return IL_FALSE; } if (iCurImage->Pal.Palette && iCurImage->Pal.PalSize > 0 && iCurImage->Pal.PalType != IL_PAL_NONE) { ifree(iCurImage->Pal.Palette); iCurImage->Pal.Palette = NULL; } iseek(0, IL_SEEK_END); RealFileSize = ftell((FILE*)ColFile); iseek(0, IL_SEEK_SET); if (RealFileSize > 768) { // has a header fread(&FileSize, 4, 1, (FILE*)ColFile); if ((FileSize - 8) % 3 != 0) { // check to make sure an even multiple of 3! icloser(ColFile); ilSetError(IL_ILLEGAL_FILE_VALUE); return IL_FALSE; } if (iread(&Version, 2, 1) != 1) { icloser(ColFile); return IL_FALSE; } if (Version != 0xB123) { icloser(ColFile); ilSetError(IL_ILLEGAL_FILE_VALUE); return IL_FALSE; } if (iread(&Version, 2, 1) != 1) { icloser(ColFile); return IL_FALSE; } if (Version != 0) { icloser(ColFile); ilSetError(IL_ILLEGAL_FILE_VALUE); return IL_FALSE; } } iCurImage->Pal.Palette = (ILubyte*)ialloc(768); if (iCurImage->Pal.Palette == NULL) { icloser(ColFile); return IL_FALSE; } if (iread(iCurImage->Pal.Palette, 1, 768) != 768) { icloser(ColFile); ifree(iCurImage->Pal.Palette); iCurImage->Pal.Palette = NULL; return IL_FALSE; } iCurImage->Pal.PalSize = 768; iCurImage->Pal.PalType = IL_PAL_RGB24; icloser(ColFile); return IL_TRUE; }