
#ifndef _CTGA_IMG_
#define _CTGA_IMG_

// This class setting describes a simple tga file handler that
// can handle uncompressed , non color coded tga files.

// Most of the code seen here has been reimplemented from the tutorial 
// available at lighthouse3d.com by  Antonio Ramires Fernandes ajbrf@yahoo.com
// i have mainly refined the code, put in a class structure and 
// also the memory handling has been modified and antiquated code replaced.

// Note, while the basic "true" image data is stored in m_ImgData,
// For all our purposes we require only the modified data, hence to
// accomadate that we store all the data (reg of rgb or gscale )
// in m_GrayScaleData

#define	TGA_ERROR_FILE_OPEN				-4
#define TGA_ERROR_READING_FILE			-3
#define TGA_ERROR_INDEXED_COLOR			-2
#define TGA_ERROR_COMPRESSED_FILE		-1
#define TGA_OK							 0

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fstream>

class CTgaImg
{
	
public:
	// default constructor , do nothing
	CTgaImg();
	// default destructor , clear up memory
	~CTgaImg();
	// basic function, parses the given tga image file
	int						loadTGAImg( const char* );
	// access methods
	unsigned char			getImgType();
	unsigned char			getImgPixelDepth();
	int						getImgWidth();
	int						getImgHeight();
	unsigned char*			getImgPixelData();
	unsigned char*			getGrayScaleData();

	// member data, provides all basic info needed for getting a workable tga texture
public:
	int						m_status;				// returns error status (if any), else 0 (success)
	unsigned char			m_ImgType;				// tells if the image is grayscale/RGB/uncompresssed
	unsigned char			m_ImgPixelDepth;		// 8 - grayscale , 24/32 for RGB(A)
	int						m_ImgWidth;				// image width
	int						m_ImgHeight;			// image height
	unsigned char*			m_ImgData;				// This array contains all the pixel info
	unsigned char*			m_GrayScaleData;		// for storing grayscale data in case file is rgb
	int*					m_PointIndexArray;		// For storing the list of indices
	const char*				m_ImgFileName;

private:
	void					tgaLoadHeader(FILE* );
	void					tgaLoadImageData(FILE* );
	void					tgaRGBtoGreyscale();
};


#endif
