/*=========================================================================
* Vignette.c : Load and display vignette
* This is a part of the Game project.
*
* Version              1.0
* Creation date        06/06/97
* Revision date
*
* That file needs to be compatible for all platforms.
*
* (c) Ubi Studios 1997
*=======================================================================*/
 
#pragma warning(disable:4032) /** formal parameter 1 has different type when promoted **/
#pragma warning(disable:4115) /** named type definition in parentheses **/
#pragma warning(disable:4127) /** conditional expression is constant **/
#pragma warning(disable:4201) /** nonstandard extension used : nameless struct/union **/
#pragma warning(disable:4214) /** nonstandard extension used : bit field types other than int **/
#pragma warning(disable:4514) /** unreferenced inline function has been removed **/
 
/**************************************************************************/
 
#define D_VIG_Input_VariableDefine
 
#define HieFriend
#include "ACP_Base.h"
#include "CPA_Expt.h"
#include "CPA_Std.h"
 
#include "DPT.h"
#include "GMT.h"
#include "GEO.h"
#include "GLI.h"
#include "LST.h"
#include "TMP.h"
#if !defined(U64)
#include "FIL.h"
#include "sna.h"
#endif /* U64 */
 
#include "VIG_Def.h"
#include "ErrVIG.h"
#include "acp_opfi.h"

extern void GLI_vWrite16bBitmapToBackBuffer( void *, long, long, long, long, long, long );
 
/**************************************************************************/
#define M_IsTitle         (_eAction==SCR_EA_Anl_BeginSection)
#define M_IsEnd           (_eAction==SCR_EA_Anl_EndSection)
#define M_IsBegSubSection (_eAction==SCR_EA_Anl_BeginSubSection)
#define M_IsEndSubSection (_eAction==SCR_EA_Anl_EndSubSection)
#define M_IsEntry         (_eAction==SCR_EA_Anl_Entry)
 
#define M_ActionIs(szActionAsked) (!strcmpi(_p_szName,szActionAsked))
 
#define M_CheckScriptParamNumber(ulNumber) \
{ \
 if (SCR_fn_uc_RdL0_GetNumberOfParameters(_ap_szParams)!=ulNumber) \
  M_VIGFatalError(E_uwVIGScriptBadNumberOfArg); \
}
 
#if defined( WIN32 )
#define M_WIN32_WaitDrawSem()       WaitForSingleObject(VIG_g_hDrawSem, INFINITE);
#define M_WIN32_ReleaseDrawSem()    ReleaseSemaphore(VIG_g_hDrawSem,1, NULL);
#else
#define M_WIN32_WaitDrawSem()
#define M_WIN32_ReleaseDrawSem()
#endif
 
/**************************************************************************/
 
GLD_tdhDevice    VIG_g_hGLDDevice = 0;
GLD_tdhViewport  VIG_g_hGLDViewport = 0;
void *           VIG_g_hDrawSem = NULL;
unsigned char   *VIG_g_p_ucTmpBuffer = NULL;
 
#if !defined(U64)
FIL_tdxHandleToConcatFile VIG_g_hConcatVignetteFile = NULL;
#endif /* U64 */
 
/**************************************************************************/
struct VIG_tdstVignetteStructure_ *fn_p_stCreateVignette(void)
{
    struct VIG_tdstVignetteStructure_ *p_stVignette=NULL;
 
    MMG_fn_vAddMemoryInfo (MMG_C_lTypeVignette , MMG_C_lSubTypeVignette , NULL);
    p_stVignette = (struct VIG_tdstVignetteStructure_ *)TMP_M_p_Malloc(sizeof(struct VIG_tdstVignetteStructure_));
    p_stVignette->p_ucMemoryBuffer = NULL;
    p_stVignette->ulMemoryBufferSize = 0;
 
    return(p_stVignette);
}
 
/**************************************************************************/
void VIG_fn_vFirstInit(void)
{
    Erm_M_InitErrMsg(VIG);
}
 
/**************************************************************************/
void VIG_fn_vInitVignette(void)
{
    GLD_tdstViewportAttributes stViewportAttr;
 
    M_WIN32_WaitDrawSem();
    FIL_fn_vInitGlobalHandleToFileInConcatFile();
    GLD_bGetViewportAttributes ( VIG_g_hGLDDevice, VIG_g_hGLDViewport, &stViewportAttr );
 
    /* VIG_g_stActualVignette.ulMemoryBufferSize = stViewportAttr.dwWidth*stViewportAttr.dwHeight*2; /* a la porcho   */
    /*VIG_g_stActualVignette.ulMemoryBufferSize = 640 * 480 * 2; /* c'est moi le plus porcho, nananère !   */
    VIG_g_stActualVignette.ulMemoryBufferSize = 640 * 480 * 3; /* je peux faire pire */
 
    MMG_fn_vAddMemoryInfo (MMG_C_lTypeVignette , MMG_C_lSubTypeVignette , NULL);
    VIG_g_stActualVignette.p_ucMemoryBuffer = (unsigned char *)TMP_M_p_Malloc(VIG_g_stActualVignette.ulMemoryBufferSize);
    VIG_g_stActualVignette.ulWidth = 640;   /*stViewportAttr.dwWidth;*/
    VIG_g_stActualVignette.ulHeight = 480; /*stViewportAttr.dwHeight;*/
 
    M_WIN32_ReleaseDrawSem();
}
 
#if !defined(U64)
/**************************************************************************/
void VIG_fn_vOpenBigFileVignette(char *p_szFileName)
{
    /* Multi-install and Multi-language Open file */
    ACP_M_OPENFILE(FIL_fn_vOpenConcatFile,VIG_g_hConcatVignetteFile,NULL,p_szFileName,(p_szFileName));
}
 
/**************************************************************************/
void VIG_fn_vCloseBigFileVignette(void)
{
    FIL_fn_vCloseConcatFile(&VIG_g_hConcatVignetteFile);
    FIL_fn_vFreeGlobalHandleToFileInConcatFile();
}
#endif /* U64 */
 
/**************************************************************************/
void VIG_fn_vInitDeviceVignette(GLD_tdhDevice _hGLDDevice,GLD_tdhViewport  _hGLDViewport, void * _hDrawSem)
{
    VIG_g_hGLDDevice   = _hGLDDevice;
    VIG_g_hGLDViewport = _hGLDViewport;
    VIG_g_hDrawSem     = _hDrawSem;
}
 
/**************************************************************************/
void VIG_fn_vRegisterSection(void)
{
#if !defined(U64)
    SCR_fn_v_RdL0_RegisterCallback(VIG_C_SectionLoadVignettesDescription,VIG_fn_eScriptCallBackVignettesDescription,SCR_CRC_c_RdL0_ForSection);
#endif /* U64 */
}
 
/**************************************************************************/
void VIG_fn_vRefreshActualVignette(void)
{
/*    if (VIG_g_stActualVignette.bDisplayBar)*/
	if (VIG_g_stActualVignette.p_ucMemoryBuffer)
		VIG_fn_vDisplayVignette(&VIG_g_stActualVignette);
}
/**************************************************************************/
void VIG_fn_vDisplayVignette(struct VIG_tdstVignetteStructure_ *_p_stVignette) 
{
	GLD_tdstViewportAttributes stViewportAttr;
	
	if (stricmp(_p_stVignette->szVignetteFileName,VIG_g_stActualVignette.szVignetteFileName))
		VIG_fn_vLoadVignetteInStructure(_p_stVignette,_p_stVignette->szVignetteFileName,_p_stVignette->eFormat);
	
    M_WIN32_WaitDrawSem();
	GLD_bGetViewportAttributes(VIG_g_hGLDDevice,VIG_g_hGLDViewport,&stViewportAttr);
    GLI_vWrite16bBitmapToBackBuffer
        ( 
            _p_stVignette->p_ucMemoryBuffer, 
            _p_stVignette->ulWidth,
            _p_stVignette->ulHeight,
            stViewportAttr.dwLeftInPixForClip,
            stViewportAttr.dwTopInPixForClip,
            stViewportAttr.dwRightInPixForClip,
            stViewportAttr.dwBottomInPixForClip
        );
    GLD_bFlipDevice ( VIG_g_hGLDDevice );

    M_WIN32_ReleaseDrawSem();
}
 
/**************************************************************************/
void VIG_fn_vDisplayBarToVignette(struct VIG_tdstVignetteStructure_ *_p_stVignette)
{
    unsigned char ucBytesNumber = 0;
    GLD_tdstViewportAttributes stViewportAttr;
    
    if (stricmp(_p_stVignette->szVignetteFileName,VIG_g_stActualVignette.szVignetteFileName))
        VIG_fn_vLoadVignetteInStructure(_p_stVignette,_p_stVignette->szVignetteFileName,_p_stVignette->eFormat);
    
    switch(_p_stVignette->eFormat)
    {
        case GLI_EVF_BGR1555_UL:
        case GLI_EVF_BGR565_UL:
            ucBytesNumber = 2;
            break;
        case GLI_EVF_RGB888_DL:
            ucBytesNumber = 3;
            break;
        case GLI_EVF_BGRA8888_UL:
            ucBytesNumber = 4;
            break;
    }
    
    if (_p_stVignette->bDisplayBar&&_p_stVignette->ulNewBarValue>_p_stVignette->ulOldBarValue)
    {
        M_WIN32_WaitDrawSem();
        GLD_bGetViewportAttributes(VIG_g_hGLDDevice,VIG_g_hGLDViewport,&stViewportAttr);
        GLI_vWrite16bBitmapToBackBuffer
        ( 
            _p_stVignette->p_ucMemoryBuffer, 
            _p_stVignette->ulWidth,
            _p_stVignette->ulHeight,
            stViewportAttr.dwLeftInPixForClip,
            stViewportAttr.dwTopInPixForClip,
            stViewportAttr.dwRightInPixForClip,
            stViewportAttr.dwBottomInPixForClip
        );
        GLD_bFlipDevice ( VIG_g_hGLDDevice );

        M_WIN32_ReleaseDrawSem();
    }
}
/**************************************************************************/
void VIG_fn_vCopyVignetteToBackBuffer(struct VIG_tdstVignetteStructure_ *_p_stVignette)
{
	GLD_tdstViewportAttributes stViewportAttr;
	
	if (stricmp(_p_stVignette->szVignetteFileName,VIG_g_stActualVignette.szVignetteFileName))
		VIG_fn_vLoadVignetteInStructure(_p_stVignette,_p_stVignette->szVignetteFileName,_p_stVignette->eFormat);
	
	GLD_bGetViewportAttributes(VIG_g_hGLDDevice,VIG_g_hGLDViewport,&stViewportAttr);
	
    GLI_vWrite16bBitmapToBackBuffer
        ( 
            _p_stVignette->p_ucMemoryBuffer, 
            _p_stVignette->ulWidth,
            _p_stVignette->ulHeight,
            stViewportAttr.dwLeftInPixForClip,
            stViewportAttr.dwTopInPixForClip,
            stViewportAttr.dwRightInPixForClip,
            stViewportAttr.dwBottomInPixForClip
        );
}
 
/**************************************************************************/
void VIG_fn_vSetPointToMemoryBuffer(struct VIG_tdstVignetteStructure_ *_p_stVignette,long _lX,long _lY,struct GEO_tdstColor_ *p_stColor)
{
    struct GEO_tdstColor_ stColor;
    unsigned char a_ucColor16[2];
    GLD_tdpstPixelFormat p_stVignetteFormat;
    unsigned short usMonPixel;
    unsigned short usRed;
    unsigned short usGreen;
    unsigned short usBlue;
    long lRedSrcShift;
    long lGreenSrcShift;
    long lBlueSrcShift;
    
    /**** Clipping ****/
    if (_lX>=0&&_lX<(long)_p_stVignette->ulWidth&&_lY>=0&&_lY<(long)_p_stVignette->ulHeight)
    {
        if (_p_stVignette->eFormat==GLI_EVF_BGRA8888_UL)
        {
            stColor.xR = (GEO_tdxColorValue)(p_stColor->xR*(1-p_stColor->xA)+((GEO_tdxColorValue)_p_stVignette->p_ucMemoryBuffer[4*(_lX+_p_stVignette->ulWidth*_lY)+0]/255.0)*p_stColor->xA);
            stColor.xG = (GEO_tdxColorValue)(p_stColor->xG*(1-p_stColor->xA)+((GEO_tdxColorValue)_p_stVignette->p_ucMemoryBuffer[4*(_lX+_p_stVignette->ulWidth*_lY)+1]/255.0)*p_stColor->xA);
            stColor.xB = (GEO_tdxColorValue)(p_stColor->xB*(1-p_stColor->xA)+((GEO_tdxColorValue)_p_stVignette->p_ucMemoryBuffer[4*(_lX+_p_stVignette->ulWidth*_lY)+2]/255.0)*p_stColor->xA);
            _p_stVignette->p_ucMemoryBuffer[4*(_lX+_p_stVignette->ulWidth*_lY)+0] = (unsigned char)(stColor.xR*255);
            _p_stVignette->p_ucMemoryBuffer[4*(_lX+_p_stVignette->ulWidth*_lY)+1] = (unsigned char)(stColor.xG*255);
            _p_stVignette->p_ucMemoryBuffer[4*(_lX+_p_stVignette->ulWidth*_lY)+2] = (unsigned char)(stColor.xB*255);
        }
        else if (_p_stVignette->eFormat==GLI_EVF_BGR565_UL)
        {
            p_stVignetteFormat = &(_p_stVignette->stVignetteFormat);
            
            lRedSrcShift = 8-p_stVignetteFormat->lRedNbBits;
            lGreenSrcShift = 8-p_stVignetteFormat->lGreenNbBits;
            lBlueSrcShift = 8-p_stVignetteFormat->lBlueNbBits;
            
            usMonPixel = ((unsigned short *)(_p_stVignette->p_ucMemoryBuffer))[_lX+_p_stVignette->ulWidth*_lY];
            
            usBlue = (unsigned short)((usMonPixel & (unsigned short)(p_stVignetteFormat->ulBlueMask)) >> p_stVignetteFormat->lBlueShift);
            usBlue = (unsigned short)(usBlue << lBlueSrcShift);
            
            usGreen = (unsigned short)((usMonPixel & (unsigned short)(p_stVignetteFormat->ulGreenMask)) >> p_stVignetteFormat->lGreenShift);
            usGreen = (unsigned short)(usGreen << lGreenSrcShift);
            
            usRed = (unsigned short)((usMonPixel & (unsigned short)(p_stVignetteFormat->ulRedMask)) >> p_stVignetteFormat->lRedShift);
            usRed = (unsigned short)(usRed << lRedSrcShift);
            
            stColor.xR = (GEO_tdxColorValue)(255.0*p_stColor->xR*(1.0-p_stColor->xA)+usRed*p_stColor->xA);
            stColor.xG = (GEO_tdxColorValue)(255.0*p_stColor->xG*(1.0-p_stColor->xA)+usGreen*p_stColor->xA);
            stColor.xB = (GEO_tdxColorValue)(255.0*p_stColor->xB*(1.0-p_stColor->xA)+usBlue*p_stColor->xA);
            
            usBlue = ((unsigned char)(stColor.xB));
            usBlue = (unsigned short)(usBlue >> lBlueSrcShift);
            
            usGreen = ((unsigned char)(stColor.xG));
            usGreen = (unsigned short)(usGreen >> lGreenSrcShift);
            
            usRed = ((unsigned char)(stColor.xR));
            usRed = (unsigned short)(usRed >> lRedSrcShift);
            
            usMonPixel = (unsigned short)((usRed << p_stVignetteFormat->lRedShift)
                | (usGreen << p_stVignetteFormat->lGreenShift)
                | (usBlue << p_stVignetteFormat->lBlueShift));
            
            ((unsigned short *)(_p_stVignette->p_ucMemoryBuffer))[_lX+_p_stVignette->ulWidth*_lY] = usMonPixel;
        }
        else if (_p_stVignette->eFormat==GLI_EVF_BGR1555_UL)
        {
            a_ucColor16[0] = _p_stVignette->p_ucMemoryBuffer[2*(_lX+_p_stVignette->ulWidth*_lY)+0];
            a_ucColor16[1] = _p_stVignette->p_ucMemoryBuffer[2*(_lX+_p_stVignette->ulWidth*_lY)+1];
            
            stColor.xB = (GEO_tdxColorValue)((GEO_tdxColorValue)(((*((unsigned short*)a_ucColor16))&0x7c00)>>7)/255.0);
            stColor.xG = (GEO_tdxColorValue)((GEO_tdxColorValue)(((*((unsigned short*)a_ucColor16))&0x03e0)>>3)/255.0);
            stColor.xR = (GEO_tdxColorValue)((GEO_tdxColorValue)(((*((unsigned short*)a_ucColor16))&0x001f)<<3)/255.0);
            
            stColor.xR = (GEO_tdxColorValue)(p_stColor->xR*(1-p_stColor->xA)+stColor.xR*p_stColor->xA);
            stColor.xG = (GEO_tdxColorValue)(p_stColor->xG*(1-p_stColor->xA)+stColor.xG*p_stColor->xA);
            stColor.xB = (GEO_tdxColorValue)(p_stColor->xB*(1-p_stColor->xA)+stColor.xB*p_stColor->xA);
            
            *((unsigned short*)(a_ucColor16)) = (unsigned short)((((unsigned char)(stColor.xB*255)>>3)<<10)+(((unsigned char)(stColor.xG*255)>>3)<<5)+((unsigned char)(stColor.xR*255)>>3));
            _p_stVignette->p_ucMemoryBuffer[2*(_lX+_p_stVignette->ulWidth*_lY)+0] = a_ucColor16[0];
            _p_stVignette->p_ucMemoryBuffer[2*(_lX+_p_stVignette->ulWidth*_lY)+1] = a_ucColor16[1];
        }
    }
}
/**************************************************************************/
void VIG_fn_vAddBarToVignette(struct VIG_tdstVignetteStructure_ *_p_stVignette)
{
    unsigned long x,y;
    
    if(VIG_g_stActualVignette.ulMaxBarValue==0)
        VIG_g_stActualVignette.ulMaxBarValue = 100;
    
    /**** Fill the inside ****/
    for (y=_p_stVignette->ulBarYMinPos;y<=_p_stVignette->ulBarYMaxPos;y++)
        for (x=_p_stVignette->ulBarXMinPos;x<=_p_stVignette->ulBarXMaxPos;x++)
            VIG_fn_vSetPointToMemoryBuffer(_p_stVignette,x,y,&_p_stVignette->stInsideColor);
        
    /**** Draw the outline ****/
    for (x=_p_stVignette->ulBarXMinPos+1;x<=_p_stVignette->ulBarXMaxPos-1;x++)
    {
        VIG_fn_vSetPointToMemoryBuffer(_p_stVignette,x,_p_stVignette->ulBarYMinPos,&_p_stVignette->stOutsideColor);
        VIG_fn_vSetPointToMemoryBuffer(_p_stVignette,x,_p_stVignette->ulBarYMaxPos,&_p_stVignette->stOutsideColor);
    }
    for (y=_p_stVignette->ulBarYMinPos;y<=_p_stVignette->ulBarYMaxPos;y++)
    {
        VIG_fn_vSetPointToMemoryBuffer(_p_stVignette,_p_stVignette->ulBarXMinPos,y,&_p_stVignette->stOutsideColor);
        VIG_fn_vSetPointToMemoryBuffer(_p_stVignette,_p_stVignette->ulBarXMaxPos,y,&_p_stVignette->stOutsideColor);
    }
        
    VIG_fn_vRefreshBarToVignette(&VIG_g_stActualVignette,0,VIG_g_stActualVignette.ulNewBarValue);
}
 
/**************************************************************************/
void VIG_fn_vRefreshBarToVignette(struct VIG_tdstVignetteStructure_ *_p_stVignette,unsigned long ulXMin,unsigned long ulXMax)
{
    struct GEO_tdstColor_ stColor;
    unsigned long ulXFactor,ulYFactor;
    unsigned long ulDeltaXLeft;
    unsigned long ulDeltaXRight;
    unsigned long ulDeltaYUp;
    unsigned long ulDeltaYDown;
    
    unsigned long x,y;
    
    if (ulXMin<ulXMax)
    {
        ulXFactor = _p_stVignette->ulBarXMaxPos-_p_stVignette->ulBarXMinPos;
        ulYFactor = _p_stVignette->ulBarYMaxPos-_p_stVignette->ulBarYMinPos;
        
        for (y=_p_stVignette->ulBarYMinPos+2;y<=_p_stVignette->ulBarYMaxPos-2;y++)
        { 
            ulDeltaYUp   = y - _p_stVignette->ulBarYMinPos;
            ulDeltaYDown = _p_stVignette->ulBarYMaxPos - y;
            for (x=_p_stVignette->ulBarXMinPos+ulXMin+2;x<=_p_stVignette->ulBarXMinPos+ulXMax+1;x++)
            {
                ulDeltaXLeft  = x - _p_stVignette->ulBarXMinPos;
                ulDeltaXRight = _p_stVignette->ulBarXMaxPos - x;
                stColor.xR = (GEO_tdxColorValue)(
                    _p_stVignette->stUpLeftColor.xR*((ulXFactor-ulDeltaXLeft)*(ulYFactor-ulDeltaYUp))/(ulXFactor*ulYFactor)
                    +_p_stVignette->stUpRightColor.xR*((ulXFactor-ulDeltaXRight)*(ulYFactor-ulDeltaYUp))/(ulXFactor*ulYFactor)
                    +_p_stVignette->stDownLeftColor.xR*((ulXFactor-ulDeltaXLeft)*(ulYFactor-ulDeltaYDown))/(ulXFactor*ulYFactor)
                    +_p_stVignette->stDownRightColor.xR*((ulXFactor-ulDeltaXRight)*(ulYFactor-ulDeltaYDown))/(ulXFactor*ulYFactor));
                
                stColor.xG = (GEO_tdxColorValue)(
                    _p_stVignette->stUpLeftColor.xG*((ulXFactor-ulDeltaXLeft)*(ulYFactor-ulDeltaYUp))/(ulXFactor*ulYFactor)
                    +_p_stVignette->stUpRightColor.xG*((ulXFactor-ulDeltaXRight)*(ulYFactor-ulDeltaYUp))/(ulXFactor*ulYFactor)
                    +_p_stVignette->stDownLeftColor.xG*((ulXFactor-ulDeltaXLeft)*(ulYFactor-ulDeltaYDown))/(ulXFactor*ulYFactor)
                    +_p_stVignette->stDownRightColor.xG*((ulXFactor-ulDeltaXRight)*(ulYFactor-ulDeltaYDown))/(ulXFactor*ulYFactor));
                
                stColor.xB = (GEO_tdxColorValue)(
                    _p_stVignette->stUpLeftColor.xB*((ulXFactor-ulDeltaXLeft)*(ulYFactor-ulDeltaYUp))/(ulXFactor*ulYFactor)
                    +_p_stVignette->stUpRightColor.xB*((ulXFactor-ulDeltaXRight)*(ulYFactor-ulDeltaYUp))/(ulXFactor*ulYFactor)
                    +_p_stVignette->stDownLeftColor.xB*((ulXFactor-ulDeltaXLeft)*(ulYFactor-ulDeltaYDown))/(ulXFactor*ulYFactor)
                    +_p_stVignette->stDownRightColor.xB*((ulXFactor-ulDeltaXRight)*(ulYFactor-ulDeltaYDown))/(ulXFactor*ulYFactor));
                
                stColor.xA = (GEO_tdxColorValue)(
                    _p_stVignette->stUpLeftColor.xA*((ulXFactor-ulDeltaXLeft)*(ulYFactor-ulDeltaYUp))/(ulXFactor*ulYFactor)
                    +_p_stVignette->stUpRightColor.xA*((ulXFactor-ulDeltaXRight)*(ulYFactor-ulDeltaYUp))/(ulXFactor*ulYFactor)
                    +_p_stVignette->stDownLeftColor.xA*((ulXFactor-ulDeltaXLeft)*(ulYFactor-ulDeltaYDown))/(ulXFactor*ulYFactor)
                    +_p_stVignette->stDownRightColor.xA*((ulXFactor-ulDeltaXRight)*(ulYFactor-ulDeltaYDown))/(ulXFactor*ulYFactor));
                
                if (x<=_p_stVignette->ulBarXMaxPos-2)
                    VIG_fn_vSetPointToMemoryBuffer(_p_stVignette,x,y,&stColor);
            }
        }
    }
}
/**************************************************************************/
void VIG_fn_vAddToProgressBar(unsigned long _ulInc)
{
	unsigned long ulStep = VIG_g_stActualVignette.ulBarXMaxPos-VIG_g_stActualVignette.ulBarXMinPos-3;
	
	if (VIG_g_stActualVignette.bDisplayBar)
	{
		VIG_g_stActualVignette.ulActualBarValue += _ulInc; 
		VIG_g_stActualVignette.ulNewBarValue = (VIG_g_stActualVignette.ulActualBarValue * ulStep)/VIG_g_stActualVignette.ulMaxBarValue;
		if (VIG_g_stActualVignette.ulNewBarValue > VIG_g_stActualVignette.ulOldBarValue)
		{
			if (VIG_g_stActualVignette.ulNewBarValue - VIG_g_stActualVignette.ulOldBarValue > ulStep / 10)
			{
				VIG_fn_vRefreshBarToVignette(&VIG_g_stActualVignette,VIG_g_stActualVignette.ulOldBarValue,VIG_g_stActualVignette.ulNewBarValue);
				VIG_fn_vDisplayBarToVignette(&VIG_g_stActualVignette);
				VIG_g_stActualVignette.ulOldBarValue = VIG_g_stActualVignette.ulNewBarValue;
			}
		}
	}
}
/**************************************************************************/
void VIG_fn_vLoadBMPVignette(struct VIG_tdstVignetteStructure_ *_p_stVignette,char *_szFileName,GLI_tdeVignetteFormat _eFormat)
{
#if !defined(U64)		
	GLD_tdstPixelFormat stDevicePixelFormat;
	
	char szCompleteName[_MAX_PATH];
	struct FIL_tdstGF_		stGF;
	
	if (_eFormat!=GLI_EVF_BGRA8888_UL&&_eFormat!=GLI_EVF_BGR565_UL&&_eFormat!=GLI_EVF_BGR1555_UL)
		M_VIGFatalError(E_uwVIGBadConvertFormat);
	
	strcpy(szCompleteName,_szFileName);
	strcpy(strrchr(szCompleteName,'.'),".gf");
 
	FIL_fn_vLoadGFFromConcatFileWithoutInvertPicture( VIG_g_hConcatVignetteFile, fn_szGetVignettesDataPath(), szCompleteName, &stGF);
	if (stGF.p_ucBitMap != NULL)
	{
		VIG_g_p_ucTmpBuffer = stGF.p_ucBitMap;
 
#ifndef RETAIL
		if (  stGF.stFileHeader.ulWidth!=640 || stGF.stFileHeader.ulHeight!=480 || stGF.stFileHeader.ucBpp!=3 )
		    M_VIGFatalError(E_uwVIGBadFormatBmp);
    }
	else
	{
		unsigned char ucNumberOfBytesInBMPFile;
		unsigned long ulWidth,ulHeight;
 
		FIL_fn_vLoadBMPFromConcatFileWithoutInvertPicture(VIG_g_hConcatVignetteFile,fn_szGetVignettesDataPath(),_szFileName,&VIG_g_p_ucTmpBuffer,&ucNumberOfBytesInBMPFile,&ulWidth,&ulHeight);	
	
		if (VIG_g_p_ucTmpBuffer==NULL)
			M_VIGFatalError(E_uwVIGCantLoadBmp);
		
		if (  ulWidth!=640 ||ulHeight!=480 ||ucNumberOfBytesInBMPFile!=3 )
			M_VIGFatalError(E_uwVIGBadFormatBmp);
#endif /* RETAIL	*/
	}
 
    _p_stVignette->p_ucMemoryBuffer = VIG_g_stActualVignette.p_ucMemoryBuffer;
    strcpy (VIG_g_stActualVignette.szVignetteFileName, _szFileName);
        
    GLD_vYInvertBitmap24b ( VIG_g_p_ucTmpBuffer, 640, 480 );
 
    GLD_bGetPixelFormatOfDevice ( &stDevicePixelFormat, VIG_g_hGLDDevice, VIG_g_hGLDViewport );
    if (stDevicePixelFormat.lPixelNbBits == 32)
    {
        VIG_g_stActualVignette.eFormat = GLI_EVF_RGB888_DL;
        GLD_vSetDefinedPixelFormat ( &(VIG_g_stActualVignette.stVignetteFormat), GLD_C_xB8G8R8PixelFormat );
        memcpy( VIG_g_stActualVignette.p_ucMemoryBuffer, VIG_g_p_ucTmpBuffer, VIG_g_stActualVignette.ulMemoryBufferSize );
    }
    else if (stDevicePixelFormat.lPixelNbBits == 16)
    {
	    if ( ( VIG_g_stActualVignette.ulWidth == 640 ) && ( VIG_g_stActualVignette.ulHeight == 480 ) )
	        GLD_vBitmapConvert24bTo16bPixelFormat ( (unsigned short *)(VIG_g_stActualVignette.p_ucMemoryBuffer), VIG_g_p_ucTmpBuffer, 640, 480 );
        else
	        GLD_vBitmapConvert24bTo16bPixelFormatAndFiltre ( (unsigned short *)(VIG_g_stActualVignette.p_ucMemoryBuffer), VIG_g_stActualVignette.ulWidth, VIG_g_stActualVignette.ulHeight, VIG_g_p_ucTmpBuffer, 640, 480 );
 
 
	    VIG_g_stActualVignette.eFormat = GLI_EVF_BGR565_UL;
	    GLD_vSetDefinedPixelFormat ( &(VIG_g_stActualVignette.stVignetteFormat), GLD_C_xB5G6R5PixelFormat );
	
	    GLD_vBitmapConvert16bPixelFormat ( &stDevicePixelFormat, &(VIG_g_stActualVignette.stVignetteFormat), (unsigned short *)(VIG_g_stActualVignette.p_ucMemoryBuffer), VIG_g_stActualVignette.ulMemoryBufferSize );
    }
 
    GLD_vCopyPixelFormat ( &(VIG_g_stActualVignette.stVignetteFormat), &stDevicePixelFormat );
	memcpy(_p_stVignette,&VIG_g_stActualVignette,sizeof(struct VIG_tdstVignetteStructure_));
	
	FIL_fn_vFreeBMP(&VIG_g_p_ucTmpBuffer);
 
#endif /* U64 */
}
/**************************************************************************/
void VIG_fn_vLoadVignetteInStructure(struct VIG_tdstVignetteStructure_ *_p_stVignette,char *_szFileName,GLI_tdeVignetteFormat _eFormat)
{
    VIG_fn_vFreeVignette(_p_stVignette);
    VIG_fn_vLoadBMPVignette(_p_stVignette,_szFileName,_eFormat);
}
/**************************************************************************/
void VIG_fn_vPreLoadVignetteInStructure(struct VIG_tdstVignetteStructure_ *_p_stVignette,char *_szFileName,GLI_tdeVignetteFormat _eFormat) 
{
	if (stricmp(_p_stVignette->szVignetteFileName,_szFileName)) 
    {
		VIG_fn_vFreeVignette(_p_stVignette);
		strcpy (_p_stVignette->szVignetteFileName, _szFileName);
		_p_stVignette->eFormat = _eFormat;
	}
}
/**************************************************************************/
void VIG_fn_vFreeVignette(struct VIG_tdstVignetteStructure_ *_p_stVignette) {
	_p_stVignette->bDisplayBar = FALSE;
	*VIG_g_stActualVignette.szVignetteFileName = 0;
}
/**************************************************************************/
void VIG_fn_vFreeMemoryVignette(struct VIG_tdstVignetteStructure_ *_p_stVignette) {
	_p_stVignette->bDisplayBar = FALSE;
    MMG_fn_vAddMemoryInfo (MMG_C_lTypeVignette , MMG_C_lSubTypeVignette , NULL);
	TMP_M_Free(_p_stVignette->p_ucMemoryBuffer);
	*VIG_g_stActualVignette.szVignetteFileName = 0;
}
/**************************************************************************/
#if !defined(U64)
/* Modif CuS 98/08/08 for binarization
 * Les initialisations faites lors du parsing doivent etre les memes
 * ici et dans SnaNoScr.c (projet SNA). 
 * Si vous modifiez VIG_fn_eScriptCallBackVignettesDescription
 * il faudra aussi modifier SNA_fn_vReadVignetteDescFromFile.
 */ 
SCR_tde_Anl_ReturnValue VIG_fn_eScriptCallBackVignettesDescription(SCR_tdst_File_Description *_p_stFile,char *_p_szName,char *_ap_szParams[],SCR_tde_Anl_Action	_eAction)
{
	SCR_tde_Anl_ReturnValue eReturnValue = SCR_ERV_Anl_NormalReturn;
 
 _p_stFile = _p_stFile;
 
 if ( M_IsTitle )
 {
#ifndef RETAIL
     if ( SNA_M_bTestSaveGameDesc() || SNA_M_bTestSaveLevelDesc() )
         SNA_fn_vWriteNoParamEntryToCurrentDscFile( SNA_C_ul_VignetteDescTitle );
#endif
 }
 else
 if (M_IsEntry)
 {
  if (M_ActionIs("LoadLevelVignette"))
  {
   strcpy(VIG_g_stActualVignette.szLevelVignetteFileName,_ap_szParams[0]);
   VIG_fn_vLoadVignetteInStructure(&VIG_g_stActualVignette,_ap_szParams[0],GLI_EVF_BGR565_UL);
#ifndef RETAIL
   if ( SNA_M_bTestSaveLevelDesc() )
        SNA_fn_vWriteStringEntryToCurrentDscFile( SNA_C_ul_LoadLevelVignette, _ap_szParams[0] );
#endif
  }
  else   if (M_ActionIs("LoadVignette"))
  {
   VIG_fn_vFreeVignette(&VIG_g_stActualVignette);
   VIG_fn_vLoadVignetteInStructure(&VIG_g_stActualVignette,_ap_szParams[0],GLI_EVF_BGR565_UL);
#ifndef RETAIL
   if ( SNA_M_bTestSaveGameDesc() )
        SNA_fn_vWriteStringEntryToCurrentDscFile( SNA_C_ul_LoadVignette, _ap_szParams[0] );
#endif
  }
  else   if (M_ActionIs("InitVignette"))
  {
   VIG_fn_vInitVignette();
 
#ifndef RETAIL
   if ( SNA_M_bTestSaveGameDesc() || SNA_M_bTestSaveLevelDesc() )
        SNA_fn_vWriteNoParamEntryToCurrentDscFile( SNA_C_ul_InitVignette );
#endif
  }
  else   if (M_ActionIs("FreeVignette"))
  {
/*   VIG_fn_vFreeMemoryVignette(&VIG_g_stActualVignette);*/
 
#ifndef RETAIL
      if ( SNA_M_bTestSaveGameDesc() || SNA_M_bTestSaveLevelDesc() )
        SNA_fn_vWriteNoParamEntryToCurrentDscFile( SNA_C_ul_FreeVignette );
#endif
  }
  else if (M_ActionIs("DisplayVignette"))
  {
   /**** To front buffer ****/
   VIG_fn_vDisplayVignette(&VIG_g_stActualVignette);
   /**** To back buffer ****/
   /*VIG_fn_vDisplayVignette(&VIG_g_stActualVignette);*/
 
#ifndef RETAIL
   if ( SNA_M_bTestSaveGameDesc() || SNA_M_bTestSaveLevelDesc() )
        SNA_fn_vWriteNoParamEntryToCurrentDscFile( SNA_C_ul_DisplayVignette );
#endif
  }
  else if (M_ActionIs("InitBarOutlineColor"))
  {
   M_CheckScriptParamNumber(4);
   VIG_g_stActualVignette.stOutsideColor.xR = (GEO_tdxColorValue)(atof(_ap_szParams[0])/255.0);
   VIG_g_stActualVignette.stOutsideColor.xG = (GEO_tdxColorValue)(atof(_ap_szParams[1])/255.0);
   VIG_g_stActualVignette.stOutsideColor.xB = (GEO_tdxColorValue)(atof(_ap_szParams[2])/255.0);
   VIG_g_stActualVignette.stOutsideColor.xA = (GEO_tdxColorValue)(atof(_ap_szParams[3])/255.0);
 
#ifndef RETAIL
   if ( SNA_M_bTestSaveGameDesc() || SNA_M_bTestSaveLevelDesc() )
   {
        SNA_fn_vWriteNoParamEntryToCurrentDscFile( SNA_C_ul_InitBarOutlineColor );
        SNA_fn_vWriteBlockToCurrentDscFile
        ( 
            (char *)&VIG_g_stActualVignette.stOutsideColor,
            sizeof( GEO_tdstColor )
        );
   }
#endif
 
  }
  else if (M_ActionIs("InitBarInsideColor"))
  {
   M_CheckScriptParamNumber(4);
   VIG_g_stActualVignette.stInsideColor.xR = (GEO_tdxColorValue)(atof(_ap_szParams[0])/255.0);
   VIG_g_stActualVignette.stInsideColor.xG = (GEO_tdxColorValue)(atof(_ap_szParams[1])/255.0);
   VIG_g_stActualVignette.stInsideColor.xB = (GEO_tdxColorValue)(atof(_ap_szParams[2])/255.0);
   VIG_g_stActualVignette.stInsideColor.xA = (GEO_tdxColorValue)(atof(_ap_szParams[3])/255.0);
 
#ifndef RETAIL
   if ( SNA_M_bTestSaveGameDesc() || SNA_M_bTestSaveLevelDesc() )
   {
        SNA_fn_vWriteNoParamEntryToCurrentDscFile( SNA_C_ul_InitBarInsideColor );
        SNA_fn_vWriteBlockToCurrentDscFile
            ( (char *)&VIG_g_stActualVignette.stInsideColor, sizeof( GEO_tdstColor ) );
   }
#endif
 
 
  }
  else if (M_ActionIs("InitBarColor"))
  {
   M_CheckScriptParamNumber(4*4);
   VIG_g_stActualVignette.stUpLeftColor.xR = (GEO_tdxColorValue)(atof(_ap_szParams[0])/255.0);
   VIG_g_stActualVignette.stUpLeftColor.xG = (GEO_tdxColorValue)(atof(_ap_szParams[1])/255.0);
   VIG_g_stActualVignette.stUpLeftColor.xB = (GEO_tdxColorValue)(atof(_ap_szParams[2])/255.0);
   VIG_g_stActualVignette.stUpLeftColor.xA = (GEO_tdxColorValue)(atof(_ap_szParams[3])/255.0);
   VIG_g_stActualVignette.stUpRightColor.xR = (GEO_tdxColorValue)(atof(_ap_szParams[4])/255.0);
   VIG_g_stActualVignette.stUpRightColor.xG = (GEO_tdxColorValue)(atof(_ap_szParams[5])/255.0);
   VIG_g_stActualVignette.stUpRightColor.xB = (GEO_tdxColorValue)(atof(_ap_szParams[6])/255.0);
   VIG_g_stActualVignette.stUpRightColor.xA = (GEO_tdxColorValue)(atof(_ap_szParams[7])/255.0);
   VIG_g_stActualVignette.stDownLeftColor.xR = (GEO_tdxColorValue)(atof(_ap_szParams[8])/255.0);
   VIG_g_stActualVignette.stDownLeftColor.xG = (GEO_tdxColorValue)(atof(_ap_szParams[9])/255.0);
   VIG_g_stActualVignette.stDownLeftColor.xB = (GEO_tdxColorValue)(atof(_ap_szParams[10])/255.0);
   VIG_g_stActualVignette.stDownLeftColor.xA = (GEO_tdxColorValue)(atof(_ap_szParams[11])/255.0);
   VIG_g_stActualVignette.stDownRightColor.xR = (GEO_tdxColorValue)(atof(_ap_szParams[12])/255.0);
   VIG_g_stActualVignette.stDownRightColor.xG = (GEO_tdxColorValue)(atof(_ap_szParams[13])/255.0);
   VIG_g_stActualVignette.stDownRightColor.xB = (GEO_tdxColorValue)(atof(_ap_szParams[14])/255.0);
   VIG_g_stActualVignette.stDownRightColor.xA = (GEO_tdxColorValue)(atof(_ap_szParams[15])/255.0);
#ifndef RETAIL
   if ( SNA_M_bTestSaveGameDesc() || SNA_M_bTestSaveLevelDesc() )
   {
        SNA_fn_vWriteNoParamEntryToCurrentDscFile( SNA_C_ul_InitBarColor );
        SNA_fn_vWriteBlockToCurrentDscFile
            ( (char *)&VIG_g_stActualVignette.stUpLeftColor, sizeof( GEO_tdstColor ) );
        SNA_fn_vWriteBlockToCurrentDscFile
            ( (char *)&VIG_g_stActualVignette.stUpRightColor, sizeof( GEO_tdstColor ) );
        SNA_fn_vWriteBlockToCurrentDscFile
            ( (char *)&VIG_g_stActualVignette.stDownLeftColor, sizeof( GEO_tdstColor ) );
        SNA_fn_vWriteBlockToCurrentDscFile
            ( (char *)&VIG_g_stActualVignette.stDownRightColor, sizeof( GEO_tdstColor ) );
   }
#endif
  }
  else if (M_ActionIs("CreateBar"))
  {
   VIG_g_stActualVignette.ulOldBarValue = 0;
   VIG_g_stActualVignette.ulNewBarValue = 0;
   VIG_g_stActualVignette.ulBarXMinPos = (VIG_g_stActualVignette.ulWidth*atoi(_ap_szParams[0]))/640;
   VIG_g_stActualVignette.ulBarYMinPos = (VIG_g_stActualVignette.ulHeight*atoi(_ap_szParams[1]))/480;
   VIG_g_stActualVignette.ulBarXMaxPos = (VIG_g_stActualVignette.ulWidth*atoi(_ap_szParams[2]))/640;
   VIG_g_stActualVignette.ulBarYMaxPos = (VIG_g_stActualVignette.ulHeight*atoi(_ap_szParams[3]))/480;
 
#ifndef RETAIL
   if ( SNA_M_bTestSaveGameDesc() || SNA_M_bTestSaveLevelDesc() )
   {
        SNA_fn_vWriteNoParamEntryToCurrentDscFile( SNA_C_ul_CreateBar );
        SNA_fn_vWriteLongToCurrentDscFile( atoi(_ap_szParams[0]) );
        SNA_fn_vWriteLongToCurrentDscFile( atoi(_ap_szParams[1]) );
        SNA_fn_vWriteLongToCurrentDscFile( atoi(_ap_szParams[2]) );
        SNA_fn_vWriteLongToCurrentDscFile( atoi(_ap_szParams[3]) );
   }
#endif
  }
  else if (M_ActionIs("AddBar"))
  {
   VIG_fn_vAddBarToVignette(&VIG_g_stActualVignette);
   VIG_g_stActualVignette.bDisplayBar = TRUE;
#ifndef RETAIL
   if ( SNA_M_bTestSaveGameDesc() || SNA_M_bTestSaveLevelDesc() )
        SNA_fn_vWriteNoParamEntryToCurrentDscFile( SNA_C_ul_AddBar );
#endif
  }
  else if (M_ActionIs("MaxValueBar"))
  {
   VIG_g_stActualVignette.ulMaxBarValue = atoi(_ap_szParams[0]);
   VIG_g_stActualVignette.ulActualBarValue = 0;
#ifndef RETAIL
   if ( SNA_M_bTestSaveGameDesc() || SNA_M_bTestSaveLevelDesc() )
        SNA_fn_vWriteLongEntryToCurrentDscFile( SNA_C_ul_MaxValueBar, atoi(_ap_szParams[0]) );
#endif
  }
 }
 else if ( M_IsEnd )
 {
#ifndef RETAIL
     if ( SNA_M_bTestSaveGameDesc() || SNA_M_bTestSaveLevelDesc() )
         SNA_fn_vWriteNoParamEntryToCurrentDscFile( SNA_C_ulEndOfDescSection );
#endif
 }
 
 return(eReturnValue);
}
#endif /* U64 */
 
 
 
/**************************************************************************/
void VIG_fn_vConvertAllVignette ( GLD_tdpstPixelFormat p_stDstPixelFormat )
{
    GLD_vBitmapConvert16bPixelFormat ( p_stDstPixelFormat, &(VIG_g_stActualVignette.stVignetteFormat), (unsigned short *)(VIG_g_stActualVignette.p_ucMemoryBuffer), VIG_g_stActualVignette.ulMemoryBufferSize );
    GLD_vCopyPixelFormat ( &(VIG_g_stActualVignette.stVignetteFormat), p_stDstPixelFormat );
}
 
 
/**************************************************************************/
 
/*
 =======================================================================================
    Saving progress bar information 
 =======================================================================================
 */
#if !defined(U64)
 
void VIG_fn_vSaveProgressBarInfo( struct VIG_tdstVignetteStructure_ *_p_stVignette, char *_szFileName, BOOL _bStandardProgressBar )
{
    SCR_tdst_File_Description stFile;
    char szText[200];
    int hFile;
 
    if (_p_stVignette->ulMaxBarValue == _p_stVignette->ulActualBarValue)
        return;
 
    _p_stVignette->ulMaxBarValue = _p_stVignette->ulActualBarValue;
 
    FIL_fn_bValidatePath(".",_szFileName);
    hFile = SCR_M_p_x_File_OpenWrite(_szFileName);
    if (hFile == -1)
        return;
 
    SCR_fn_v_File_InitFileDes(&stFile,_szFileName, hFile);
    if(stFile.p_stHandle == NULL)
        return;
 
    SCR_M_SvL0_SaveScriptFileHeader(&stFile);
 
    sprintf( szText, "%s:", VIG_C_SectionLoadVignettesDescription );
    SCR_M_SvL0_SaveBeginSection( &stFile, szText, SCR_CC_C_Cfg_EOL);
    
    if (_bStandardProgressBar)
    {
        SCR_M_SvL0_SaveEntry(&stFile,"LoadVignette",SCR_CC_C_Cfg_NoChar);
        SCR_fn_v_SvL0_SaveParameters_MP(&stFile, SCR_EF_SvL0_Normal,1,_p_stVignette->szVignetteFileName);
    }
    else
    {
        SCR_M_SvL0_SaveEntry( &stFile, "LoadLevelVignette", SCR_CC_C_Cfg_NoChar);
        SCR_fn_v_SvL0_SaveParameters_MP( &stFile, SCR_EF_SvL0_Normal, 1, _p_stVignette->szLevelVignetteFileName);
    }
 
    SCR_M_SvL0_SaveEntry( &stFile, "InitBarOutlineColor", SCR_CC_C_Cfg_NoChar);
    
    SCR_fn_v_SvL0_SaveParameters_MP
        (
            &stFile, SCR_EF_SvL0_Scanf,5,"%d,%d,%d,%d",
            (unsigned char)(_p_stVignette->stOutsideColor.xR*255.0),
            (unsigned char)(_p_stVignette->stOutsideColor.xG*255.0),
            (unsigned char)(_p_stVignette->stOutsideColor.xB*255.0),
            (unsigned char)(_p_stVignette->stOutsideColor.xA*255.0)
        );
    SCR_M_SvL0_SaveEntry( &stFile, "InitBarInsideColor", SCR_CC_C_Cfg_NoChar );
    SCR_fn_v_SvL0_SaveParameters_MP
            (
                &stFile, SCR_EF_SvL0_Scanf,5,"%d,%d,%d,%d",
                (unsigned char)(_p_stVignette->stInsideColor.xR*255.0),
                (unsigned char)(_p_stVignette->stInsideColor.xG*255.0),
                (unsigned char)(_p_stVignette->stInsideColor.xB*255.0),
                (unsigned char)(_p_stVignette->stInsideColor.xA*255.0)
            );
    SCR_M_SvL0_SaveEntry( &stFile, "InitBarColor", SCR_CC_C_Cfg_NoChar);
    SCR_fn_v_SvL0_SaveParameters_MP
        ( 
            &stFile, SCR_EF_SvL0_Scanf,17,
            "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
            (unsigned char)(_p_stVignette->stUpLeftColor.xR*255.0),
            (unsigned char)(_p_stVignette->stUpLeftColor.xG*255.0),
            (unsigned char)(_p_stVignette->stUpLeftColor.xB*255.0),
            (unsigned char)(_p_stVignette->stUpLeftColor.xA*255.0),
            (unsigned char)(_p_stVignette->stUpRightColor.xR*255.0),
            (unsigned char)(_p_stVignette->stUpRightColor.xG*255.0),
            (unsigned char)(_p_stVignette->stUpRightColor.xB*255.0),
            (unsigned char)(_p_stVignette->stUpRightColor.xA*255.0),
            (unsigned char)(_p_stVignette->stDownLeftColor.xR*255.0),
            (unsigned char)(_p_stVignette->stDownLeftColor.xG*255.0),
            (unsigned char)(_p_stVignette->stDownLeftColor.xB*255.0),
            (unsigned char)(_p_stVignette->stDownLeftColor.xA*255.0),
            (unsigned char)(_p_stVignette->stDownRightColor.xR*255.0),
            (unsigned char)(_p_stVignette->stDownRightColor.xG*255.0),
            (unsigned char)(_p_stVignette->stDownRightColor.xB*255.0),
            (unsigned char)(_p_stVignette->stDownRightColor.xA*255.0)
        );
    SCR_M_SvL0_SaveEntry( &stFile, "CreateBar", SCR_CC_C_Cfg_NoChar);
    SCR_fn_v_SvL0_SaveParameters_MP
        (
            &stFile, SCR_EF_SvL0_Scanf, 5, "%d,%d,%d,%d",
            (640*_p_stVignette->ulBarXMinPos)/_p_stVignette->ulWidth,
            (480*_p_stVignette->ulBarYMinPos)/_p_stVignette->ulHeight,
            (640*_p_stVignette->ulBarXMaxPos)/_p_stVignette->ulWidth,
            (480*_p_stVignette->ulBarYMaxPos)/_p_stVignette->ulHeight
        );
    SCR_M_SvL0_SaveEntry( &stFile, "MaxValueBar", SCR_CC_C_Cfg_NoChar);
    SCR_fn_v_SvL0_SaveParameters_MP( &stFile, SCR_EF_SvL0_Scanf, 2, "%d", _p_stVignette->ulMaxBarValue);
    SCR_M_SvL0_SaveEntry( &stFile, "AddBar", SCR_CC_C_Cfg_EOL);
    SCR_M_SvL0_SaveEntry( &stFile, "DisplayVignette", SCR_CC_C_Cfg_EOL);
 
    SCR_M_SvL0_SaveEndSection( &stFile, SCR_CC_C_Cfg_EOL )
    SCR_fn_v_File_CloseFileDes( &stFile );
}
 
void VIG_fn_vSaveProgressBarLevelInfo(struct VIG_tdstVignetteStructure_ *_p_stVignette,char *_szFileName)
{
    VIG_fn_vSaveProgressBarInfo( _p_stVignette, _szFileName, FALSE );
}
 
void VIG_fn_vSaveProgressBarStandardInfo(struct VIG_tdstVignetteStructure_ *_p_stVignette,char *_szFileName)
{
    VIG_fn_vSaveProgressBarInfo( _p_stVignette, _szFileName, TRUE );
}
 
#endif /* U64 */
