/*
 * ImageHDR.h
 *
 * Description  : One line description of file.
 * Author       :
 *
 * Purpose      :
 *     Long description of what the file is for.
 */
#ifndef __IMAGEHDR_H__
#define __IMAGEHDR_H__

#include "image.h"
#include "common.h"
#include "textparser.h"
#include "VrutApi.h"

//using namespace VRUT;

namespace VRUT
{
	class VRUT_CORE_API ImageHDR : public Image
	{
	protected:
		float *dataFloat;
		int subWidth, subHeight;

		struct
		{
			float gamma; /// gamma multiplier for all pixels
			float exposure; /// exposure multiplier for all pixels
			bool format; /// true = 32-bit_rle_rgbe or false = 32-bit_rle_xyze
			///	float	colorcorr [3]; // color corretion multiplier, given in three parts for the three primaries
			///	char	* software; // software used to creat hdr file / useless
			///	float	pixaspect;  ratio, expressed as a decimal fraction of the heigh of each pixel to its width
			///	float	primaries [8]; // coords of red, green, blue and white
		} headerHDR;

		struct
		{
			int width; /// size of image
			int height;
			bool signX; /// true = +1 or false = -1 for orientation of image
			bool signY; /// true = +1 or false = -1
			bool rotated; /// true => X was before Y in header => image has been rotated
		} resolution;

	public:
		///class constructor no param
		ImageHDR(void);
		//constructor for cluster
		ImageHDR(const char *data, unsigned long size);
		//constructor for ioosb
		ImageHDR(const float *data, int width, int height);
		///TODO
		///class constructor with param - no need
		///copy constructor
		ImageHDR(const ImageHDR & imageHDR);
		///class destructor
		~ImageHDR(void);
#ifndef VRUT_HPC
		void BuildOneCubeSide(float * dataFloat, const TEXTURE_SAMPLER_TYPE buildAsType, GLenum cubeSide, bool use_glu_for_mipmaps) const;
		///Updates tex_object texture from image in CURRENT OpenGL context. - \c Image overload
		virtual void UpdateOglTexture(GLuint tex_object, const TEXTURE_SAMPLER_TYPE buildAsType, bool create_mipmaps) const override;
#endif
		///Get \c true if image has alpha channel - \c Image overload
		virtual bool SetTransparencyAndSetAlphaUsage(bool testPixels) override;
		///Get the widht of the image
		virtual int GetWidth() const override;
		///Get the height of the image
		virtual int GetHeight() const override;
		///Get pointer to the data
		float * GetData() const;
		///check if the texture data are loaded or the pointer is NULL
		virtual bool IsOk() const override;
		/// load file, mainly call ParseImageHDR
		virtual bool Load(const wxString & fname, int cubeSide=-1, int flip=0) override;
		///parse header and then content
		bool ParseImageHDR(TextParser &textParser);
		///Save the image to file
		virtual bool Save(wxString filename) const override;

		///when parsing of header is done, we can proceed with scanline functions
		///scanlines is done by one of three functions bellow

		///uncompressed - NOT TESTED
		///return false if it is wrong function
		bool ParseUncompressedData(TextParser &textParser);
		///old run length encoded
		///return false if it is wrong function
		///this function was NOT tested! - there are currently no files with old rle
		bool ParseOldRLE(TextParser &textParser);
		///return false if it is wrong function
		///new run length encoded
		bool ParseNewRLE(TextParser &textParser);
		/// convert data to float form, suitable for openGL
		/// result is stored in dataFloat[]
		bool Rgb2Float(unsigned char *dataChar);
		/// test if the image is cross texture (zvc)
		/// return true if it is cross texture - the texture has to have homogenous unicolor areas
		bool TestCross() const;
		/// set subSizes
		void SetSubWidth(int w);
		void SetSubHeight(int h);

		Vector4 GetRGBA(int x, int y);
	};
}

#endif
