#if !defined(__FIL_Pub_h__)
#define __FIL_Pub_h__
 
/******************************************/
#if _MSC_VER >= 1000
#pragma once
#endif /* _MSC_VER >= 1000 */
/******************************************/
 
#include "CPA_Expt.h"
 
#undef EXTERN
#undef extern
#if !defined(D_FIL_Globals)
#define EXTERN extern
#define D_FIL_Globals
#else
#define EXTERN
#endif /* D_FIL_Globals */
 
 
#define GF_FORMAT_RGB_565               0xa
#define GF_FORMAT_ARGB_1555             0xb
#define GF_FORMAT_ARGB_4444             0xc
#define GF_FORMAT_PALETTE               0x5
#define GF_VERSION						1
 
#if defined(__cplusplus)
extern "C"
{
#endif /* __cplusplus */
 
typedef struct FIL_tdstFileNameListElement_ *FIL_tdxHandleToFileNameListElement;
typedef struct FIL_tdstFileNameList_ *FIL_tdxHandleToFileNameList;
typedef struct FIL_tdstConcatFileElement_ *FIL_tdxHandleToConcatFileElement;
typedef struct FIL_tdstConcatFile_ *FIL_tdxHandleToConcatFile;
typedef struct FIL_tdstFileInConcatFile_ *FIL_tdxHandleToFileInConcatFile;
 
LST2_M_DynamicUseListOf(FIL_tdxHandleToFileNameListElement);
 
#if defined(D_FIL_StructureDefine)
typedef struct FIL_tdstFileNameListElement_
{
 LST2_M_DynamicElementDeclaration(FIL_tdxHandleToFileNameListElement)
 char *szFileName;
} FIL_tdstFileNameListElement_;
 
typedef struct FIL_tdstFileNameList_
{
 LST2_M_DynamicAnchorDeclaration(FIL_tdxHandleToFileNameListElement) hFileNameListAnchor;
} FIL_tdstFileNameList;
 
typedef struct FIL_tdstConcatFileElement_
{
 char *p_szFileName;
 long lPathNumber; /**** -1 : No path (current path) ****/
 long lOffset;
 unsigned long ulFileLength;
 unsigned long ulXorCode;
 unsigned long ulCheckSum;
} FIL_tdstConcatFileElement;
 
typedef struct FIL_tdstConcatFile_
{
 FILE *p_stFile;
 
 unsigned long ulNumberOfPath;
 unsigned long ulNumberOfFile;
 unsigned char bUseXorCode;
 unsigned char bUseCheckSum;
 
 unsigned char ucPathXorCode;
 unsigned char ucPathCheckSum;
 char **d_szPathList;
 
 FIL_tdstConcatFileElement *d_stConcatFileElement;
} FIL_tdstConcatFile;
 
typedef struct FIL_tdstFileInConcatFile_
{
 unsigned char bUseConcatFile;
 FILE *p_stFile;
 
 unsigned long ulFileActualSeek;
 unsigned long ulFileEndSeek;
 unsigned long ulFileXorCode;
 unsigned long ulFileCheckSum;
 
 unsigned long ulCacheSeek;
 unsigned long ulCacheSize;
 unsigned long ulCacheCheckSum;
 unsigned char *p_ucCache;
} FIL_tdstFileInConcatFile;
 
 
#endif /* D_FIL_StructureDefine */
 
typedef struct FIL_tdstFileHeader_ 
{
    unsigned long	ulWidth;
    unsigned long	ulHeight;
    unsigned long	ulImageSize; 
    long			lChromakeyIndex; 
    unsigned short	uwNbColorInPalette; /*uwPaletteSize; */
    unsigned char	ucBpcInPalette; /*ucPaletteEntrySize; */
    unsigned char	ucBpp; /*ucNumberOfBits*/
    unsigned char	ucRLECode;
    unsigned char	ucRed; 
    unsigned char	ucGreen; 
    unsigned char	ucBlue; 
    unsigned char	ucFormat; 
    unsigned char	ucVersion; 
} FIL_tdstFileHeader;
 
/* Oliv' - Portage v15*/
#ifndef U64
	#pragma pack(push,1)
#endif
/* EndOfOliv'*/
 
typedef struct FIL_tdstRealGFFileHeader_
{
    unsigned long ulFormat;
    unsigned long ulWidth;
    unsigned long ulHeight;
    unsigned char ucBpp;
    unsigned char ucRLECode;
} FIL_tdstRealGFFileHeader;
 
typedef struct FIL_tdstGF_
{
 struct FIL_tdstFileHeader_		stFileHeader;
 unsigned char					*p_ucBitMap;
 unsigned char					*p_ucPalette; 
} FIL_tdstGF;
 
/* Oliv' - Portage v15*/
#ifndef U64
	#pragma pack(pop)
#endif
/* EndOfOliv'*/
 
 
#if !defined(U64)
EXTERN CPA_EXPORT void FIL_fn_vFirstInit(void);
EXTERN CPA_EXPORT void FIL_fn_vDisplayInformationError(unsigned char bValue);
 
/**** Files management ****/
EXTERN CPA_EXPORT unsigned long FIL_fn_ulGetFileSize(char *_szFileName);
EXTERN CPA_EXPORT unsigned char FIL_fn_bDestroyFileOrDirectory(char *_szFileName);
EXTERN CPA_EXPORT FIL_tdxHandleToFileNameList FIL_fn_hSearchFile(char *_szFileName,unsigned long ulAttrib);
EXTERN CPA_EXPORT FIL_tdxHandleToFileNameList FIL_fn_hSearchRecurseFile(char *_szFileName,unsigned long ulAttrib);
EXTERN CPA_EXPORT void FIL_fn_vContinueSearchRecurseFile(char *_szFileName,unsigned long ulAttrib,FIL_tdxHandleToFileNameList hFileNameList);
EXTERN CPA_EXPORT void FIL_fn_vDestroySearchedFile(FIL_tdxHandleToFileNameList _hFileNameList);
EXTERN CPA_EXPORT void FIL_fn_vDestroyOnElementInFileNameList(FIL_tdxHandleToFileNameListElement hFileNameListElement);
EXTERN CPA_EXPORT unsigned long FIL_fn_ulGetNumberOfFiles(FIL_tdxHandleToFileNameList hHandleToFileNameList);
EXTERN CPA_EXPORT unsigned char FIL_fn_bIsFileExist(char *_szFileName);
EXTERN CPA_EXPORT unsigned char FIL_fn_bValidatePath(char *_p_szStartPath, char *_p_szFileName);
EXTERN CPA_EXPORT unsigned long FIL_fn_ulGetFileSize(char *_szFileName);
 
/**** Concat files ****/
EXTERN CPA_EXPORT FIL_tdxHandleToConcatFile FIL_fn_hCreateConcatFileHandle(unsigned long ulNumberOfPath,unsigned long ulNumberOfFiles);
EXTERN CPA_EXPORT void fn_vDestroyConcatFileHandle(FIL_tdxHandleToConcatFile hConcatFile);
EXTERN CPA_EXPORT unsigned char FIL_fn_bSetConcatPathElement(FIL_tdxHandleToConcatFile hConcatFile,unsigned long ulPathNumber,char *p_szPathName);
EXTERN CPA_EXPORT unsigned char FIL_fn_bSetConcatFileElement(FIL_tdxHandleToConcatFile hConcatFile,unsigned long ulFileNumber,char *p_szFileName);
EXTERN CPA_EXPORT void FIL_fn_vBuildConcatCompleteFileName(char *szCompleteFilename,FIL_tdxHandleToConcatFile hConcatFile,unsigned long ulIndex);
EXTERN CPA_EXPORT FIL_tdxHandleToConcatFile FIL_fn_vOpenConcatFile(char *p_szFilename);
EXTERN CPA_EXPORT void FIL_fn_vCloseConcatFile(FIL_tdxHandleToConcatFile *hConcatFile);
EXTERN CPA_EXPORT FIL_tdxHandleToFileInConcatFile FIL_fn_hOpenFileInConcatFile(FIL_tdxHandleToConcatFile hConcatFile,char *p_szPath,char *p_szFilename);
EXTERN CPA_EXPORT void FIL_fn_vCloseFileInConcatFile(FIL_tdxHandleToFileInConcatFile *hHandleToFile);
EXTERN CPA_EXPORT long FIL_fn_lReadFileInConcatFile(void *p_vBuffer,long lSize,long lNumber,FIL_tdxHandleToFileInConcatFile hHandleToFile);
 
/**** BMP pictures files ****/
EXTERN CPA_EXPORT void FIL_fn_vSaveBMPInFile(char *p_szFileName,unsigned char *p_ucSource,unsigned long ulWidth,unsigned long ulHeight,unsigned char ucNumberOfBytesInFile,unsigned char ucNumberOfBytesInSource);
EXTERN CPA_EXPORT void FIL_fn_vLoadBMPInformationFromFile(char *p_szPath,char *p_szFileName,unsigned char *p_ucNumberOfBytesInDest,unsigned long *p_ulWidth,unsigned long *p_ulHeight);
EXTERN CPA_EXPORT void FIL_fn_vLoadBMPFromFileWithInvertPicture(char *p_szPath,char *p_szFileName,FIL_tdstGF *_p_stHeader);
EXTERN CPA_EXPORT void FIL_fn_vLoadBMPFromFileWithoutInvertPicture(char *p_szPath,char *p_szFileName,unsigned char **pp_ucDest,unsigned char *p_ucNumberOfBytesInDest,unsigned long *p_ulWidth,unsigned long *p_ulHeight);
EXTERN CPA_EXPORT void FIL_fn_vLoadBMPInformationFromConcatFile(FIL_tdxHandleToConcatFile hConcatFile,char *p_szPath,char *p_szFileName,unsigned char *p_ucNumberOfBytesInDest,unsigned long *p_ulWidth,unsigned long *p_ulHeight);
EXTERN CPA_EXPORT void FIL_fn_vLoadBMPFromConcatFileWithInvertPicture(FIL_tdxHandleToConcatFile hConcatFile,char *p_szPath,char *p_szFileName,unsigned char **pp_ucDest,unsigned char *p_ucNumberOfBytesInDest,unsigned long *p_ulWidth,unsigned long *p_ulHeight);
EXTERN CPA_EXPORT void FIL_fn_vLoadBMPFromConcatFileWithoutInvertPicture(FIL_tdxHandleToConcatFile hConcatFile,char *p_szPath,char *p_szFileName,unsigned char **pp_ucDest,unsigned char *p_ucNumberOfBytesInDest,unsigned long *p_ulWidth,unsigned long *p_ulHeight);
EXTERN CPA_EXPORT void FIL_fn_vFreeBMP(unsigned char **pp_ucMemory);
EXTERN CPA_EXPORT void FIL_fn_vInvertBMP(unsigned char *p_ucDest,unsigned char ucNumberOfBytesInDest,unsigned long ulWidth,unsigned long ulHeight);
 
 
EXTERN CPA_EXPORT void FIL_fn_vTGASaveInFile                            (char *p_szFileName, unsigned char ucNumberOfBytesInFile,FIL_tdstGF	*_p_stSource);
EXTERN CPA_EXPORT void FIL_fn_vTGALoadInformationFromFile               (char *p_szPath,char *p_szFileName, FIL_tdstGF *_p_stHeader );
EXTERN CPA_EXPORT void FIL_fn_vTGALoadInformationFromConcatFile         (FIL_tdxHandleToConcatFile hConcatFile,char *p_szPath,char *p_szFileName, FIL_tdstGF *_p_stHeader);
#ifndef RETAIL
EXTERN CPA_EXPORT void FIL_fn_vTGALoadFromFileWithInvertPicture         (char *p_szPath,char *p_szFileName, FIL_tdstGF *_p_stHeader );
#endif
EXTERN CPA_EXPORT void FIL_fn_vTGALoadFromFileWithoutInvertPicture			(char *p_szPath, char *p_szFileName, FIL_tdstGF	*_p_stHeader);
EXTERN CPA_EXPORT void FIL_fn_vTGALoadFromConcatFileWithInvertPicture   (FIL_tdxHandleToConcatFile hConcatFile,char *p_szPath,char *p_szFileName, FIL_tdstGF *_p_stHeader );
EXTERN CPA_EXPORT void FIL_fn_vTGALoadFromConcatFileWithoutInvertPicture(FIL_tdxHandleToConcatFile hConcatFile,char *p_szPath,char *p_szFileName,  FIL_tdstGF *_p_stHeader );
EXTERN CPA_EXPORT void FIL_fn_vTGAInvert                                (FIL_tdstGF *_p_stHeader );
 
EXTERN CPA_EXPORT void FIL_fn_vTGAFree                                  (unsigned char **pp_ucMemory);
 
/**** GF pictures files ****/
EXTERN CPA_EXPORT void FIL_fn_vSaveGFInFile(char *p_szFileName, unsigned char	ucNumberOfBytesInSource, FIL_tdstGF	*_p_stSrcGF);
EXTERN CPA_EXPORT void FIL_fn_vLoadGFInformationFromFile(char	*p_szPath, char	*p_szFileName, ACP_tdxBool *p_bTextureInPalette, FIL_tdstGF *_p_stGF);
EXTERN CPA_EXPORT void FIL_fn_vLoadGFFromFileWithInvertPicture(char *p_szPath, char *p_szFileName,FIL_tdstGF *_p_stGF);
EXTERN CPA_EXPORT void FIL_fn_vLoadGFFromFileWithoutInvertPicture(char *p_szPath, char *p_szFileName, FIL_tdstGF *_p_stGF);
EXTERN CPA_EXPORT void FIL_fn_vOldLoadGFInformationFromConcatFile(FIL_tdxHandleToConcatFile hConcatFile, char *p_szPath, char *p_szFileName, ACP_tdxBool *p_bTextureInPalette, FIL_tdstGF *_p_stGF);
EXTERN CPA_EXPORT void FIL_fn_vLoadGFInformationFromConcatFile(FIL_tdxHandleToConcatFile hConcatFile, char *p_szPath, char *p_szFileName, ACP_tdxBool *p_bTextureInPalette, FIL_tdstGF *_p_stGF);
EXTERN CPA_EXPORT void FIL_fn_vLoadGFFromConcatFileWithInvertPicture(FIL_tdxHandleToConcatFile hConcatFile, char *p_szPath, char *p_szFileName, FIL_tdstGF *_p_stGF);
EXTERN CPA_EXPORT void FIL_fn_vLoadGFFromConcatFileWithoutInvertPicture(FIL_tdxHandleToConcatFile hConcatFile, char *p_szPath, char *p_szFileName, FIL_tdstGF *_p_stGF);
EXTERN CPA_EXPORT void FIL_fn_vInvertGF( unsigned char *p_ucDest, unsigned char ucNumberOfBytesInDest, unsigned long ulWidth, unsigned long ulHeight);
EXTERN CPA_EXPORT void FIL_fn_vInitGlobalHandleToFileInConcatFile(void);
EXTERN CPA_EXPORT void FIL_fn_vFreeGlobalHandleToFileInConcatFile(void);
EXTERN CPA_EXPORT void FIL_fn_vGFLoadInformationFromConcatFile(FIL_tdxHandleToConcatFile hConcatFile, char *p_szPath, char *p_szFileName, FIL_tdstGF *_p_stGF);
 
 
EXTERN CPA_EXPORT unsigned char FIL_fn_bIsValidPath(char *_szFileName);
 
/*EXTERN CPA_EXPORT void FIL_fn_vLoadGFFromConcatFileWithoutInvertPicture (FIL_tdxHandleToConcatFile hConcatFile,char *p_szPath,char *p_szFileName,unsigned char **pp_ucDest,unsigned char *p_ucNumberOfBytesInDest,unsigned long *p_ulWidth,unsigned long *p_ulHeight);*/
#endif /* U64 */
 
#if defined(__cplusplus)
}
#endif /* __cplusplus */
 
#endif /* __FIL_Pub_h__ */
