#ifndef __image_h__
#define __image_h__

#include <string>

using namespace std;

namespace hm
{

	/**
		Used by the surface class for drawing images. 
	*/
	class Image
   {
		
	public:
		
		/** Constructor. Loads a 24bpp bmp from disk.
			\param filename file to load
			\throws <string> if the file can't be openend
		*/
		Image(string filename);

		/** Constructor. Creates a new image object in memory.
			\param w width
			\param h height
		*/
		Image(int w,int h);
		
		/**
			Destructor
		*/
		~Image();

		/** \returns <unsigned char*> an pointer to an array of width*height*3 bytes containing the image contents. 
			Format is 24bpp.
		*/
		unsigned char* getPixels();
		
		/** \returns <int> image width */
		int getWidth();

		/** \returns <int> image height */
		int getHeight();

		/** \returns <Image*> an Image object representing a subsection of this image */
		Image* subImage(int x,int y,int w,int h);

		/** \returns true if the image has an alpha channel */
		bool hasAlpha();

#ifdef IMAGE_BMP_SUPPORT
	private:
		typedef struct BMP_HEADER {
			unsigned short bfType;
			unsigned int bfSize;
			unsigned short bfReserved1;
			unsigned short bfReserved2;
			unsigned int bfBitmapOffset;
			// info header
			unsigned int biSize;
			unsigned int biWidth;
			unsigned int biHeight;
			unsigned short biPlanes;
			unsigned short biBitCount;
			unsigned int biCompression;
			unsigned int biSizeImage;
			unsigned int biXPelsPerMeter;
			unsigned int biYPelsPerMeter;
			unsigned int biClrUsed;
			unsigned int biClrImportant; 		
		} __attribute__ ((aligned (1), packed)) BMP_HEADER;
		
		void loadBMPFromMem(unsigned char *data);
#endif //IMAGE_BMP_SUPPORT
        void loadPNGFromMem(FILE *fp);
		
		int width,height;
		unsigned char *pixels;
		bool hasAlphaChannel;
	};

};


#endif

