//
// Asura_Chunk_PSP_Blur.cpp
//
// Created by Richard Rice - 11/01/2006
// 
// Copyright (C) 2006 Rebellion, All Rights Reserved.
//

#include "Core/Asura.h"
#include "ChunkSystem/Asura_Chunk_PSP_Blur.h"

#ifdef ASURA_USE_PSP_BLUR

#include "ChunkSystem/Asura_Chunk_Stream.h"
#include "ChunkSystem/Asura_SaveBlock.h"
#include "FileAccess/Asura_FileAccess.h"


#ifdef ASURA_TOOLS
#include "PSP/Tools_PSP_Blur.h"
#else
#include "Rendering/Asura_PSP_Blur.h"
#endif

#define ASURA_CHUNK_PSP_BLUR_VERSION 0

bool Asura_Chunk_PSP_Blur::Process (Asura_Chunk_Stream& xStream) const
{
	// Is this the correct version?

	if (Version > ASURA_CHUNK_PSP_BLUR_VERSION)
	{
		Asura_Assertf	(false, ("Unknown chunk version %d for psp blur",Version));
		return			(false);
	}

	
	u_int uEnabled;
	float fBrightness;

	xStream >> uEnabled;
	xStream >> fBrightness;

	//copy into tools , or psp settings as required
	#ifdef ASURA_TOOLS
	Tools_PSP_Blur::s_bEnabled = uEnabled ? true : false;
	Tools_PSP_Blur::s_fBrightness = fBrightness;
	#else

	Asura_PSP_Blur::SetEnabled(uEnabled);
	Asura_PSP_Blur::SetBrightness(fBrightness);

	#endif

	return								(true);
}

bool Asura_Chunk_PSP_Blur::Process(Asura_Handle iFileHandle) const
{
	Asura_Chunk_File_Stream	xStream (iFileHandle);

	// Call the other process function...

	return	(Process(xStream));
}

#ifdef ASURA_TOOLS
void Asura_Chunk_PSP_Blur::Create (Asura_Chunk_Stream& xStream)
{
	
	// Write the data...

	xStream.WriteChunk_Start	(ASURA_CHUNK_PSP_BLUR, ASURA_CHUNK_PSP_BLUR_VERSION, 0);

	u_int uEnabled = Tools_PSP_Blur::s_bEnabled ? 1 : 0;

	xStream << uEnabled;
	xStream << Tools_PSP_Blur::s_fBrightness;

	xStream.WriteChunk_End	();
}

void Asura_Chunk_PSP_Blur::Create(Asura_SaveBlock* pxSaveBlock)
{
	Asura_Chunk_SaveBlock_Stream	xStream (pxSaveBlock);


	// Call the other version...

	Create	(xStream);
}
#endif // ASURA_TOOLS



#endif //ASURA_USE_PSP_BLUR

