/******************************************************************************
 * $Id: gfx_tga.hh,v 1.14 2006/11/15 18:34:51 devel Exp $
 * @file
 * @brief	Loader for Truevision Targa images
 * @author	Dan Maas <dmaas@dcine.com>,
 *          Piotr Pawlow <pp@siedziba.pl>,
 *          Jim E. Brooks http://www.jimbrooks.org
 * @remarks	Modifications by Jim Brooks:
 *          - Added Targa wrapper C++ class around C code.
 *//*
 * LEGAL:	THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE (GPL).
 ******************************************************************************/

#ifndef GFX_TGA_HH
#define GFX_TGA_HH

namespace gfx {

// A function can be specified to filter RGBAs from Targa image.
typedef void(*TargaFilterFuncType)( uint8* p, uint8 r, uint8 g, uint8 b, uint8 a );
void DefaultTargaFilterFunc( uint8* p, uint8 r, uint8 g, uint8 b, uint8 a );

// Low-level function.
uint8* tga_load( const uint8* const ibuf, uint ibufLen, uint* olen, uint* w, uint* h, TargaFilterFuncType filterFunc );

////////////////////////////////////////////////////////////////////////////////
/// Wrapper class around tga_load().
/// Construct Targa object from buffer containing a TGA file (ibuf).
///
class Targa
{
PREVENT_COPYING(Targa)
public:
				Targa( const uint8* const ibuf, uint ibufLen, TargaFilterFuncType filterFunc = DefaultTargaFilterFunc );
				~Targa();
	bool		IfValid( void ) const       { return mBuf != NULL; }
	uint        GetWidth( void ) const      { ASSERT( mWidth ); return mWidth; }
	uint        GetHeight( void ) const     { ASSERT( mHeight ); return mHeight; }
	uint8*      GetBuf( void )              { ASSERT( mBuf ); return mBuf; }
	const uint8* GetConstBuf( void ) const  { ASSERT( mBuf ); return mBuf; }
	uint        GetBufLen( void ) const     { ASSERT( mBufLen ); return mBufLen; }
	uint8       ReadBuf( uint i ) const		{ ASSERT( mBuf && i < mBufLen ); return mBuf[i]; }
	void		WriteBuf( uint i, uint8 c )	{ ASSERT( mBuf && i < mBufLen ); mBuf[i] = c; }

private:
	uint	mWidth;
	uint	mHeight;
	uint8*  mBuf;
	uint	mBufLen;
};

} // namespace gfx

#endif // GFX_TGA_HH
