/*
 * $Id: imagecommon.h 4270 2016-11-06 11:02:47Z antonin.misek-skoda-auto.cz $
 *
 * Description  : One line description of file.
 * Author       : Vaclav Kyba <mail/Jabber: vaseo1@gmail.com>  <ICQ: 98576293>
 * 
 * Purpose      :
 *     Long description of what the file is for.
 */


#ifndef __IMAGECOMMON_H__
#define __IMAGECOMMON_H__

#include <memory>

#include <wx/image.h>
#include "image.h"
#include "VrutApi.h"
//#include "common.h"

namespace VRUT
{
	///Image container with support for many formats readable by \c wxImage
	class VRUT_CORE_API ImageCommon : public Image
	{
	protected:
		///\c wxImage instance
		std::unique_ptr<wxImage> image;
		std::unique_ptr<wxImage> images[5];

		wxImage* loadImage(const wxString & fname, int cubeSide=-1);
#ifndef VRUT_HPC
		static void BuildOneCubeSide(wxImage* image, const TEXTURE_SAMPLER_TYPE buildAsType, GLenum cubeSide, bool use_glu_for_mipmaps);
#endif
		void convertMaskToAlpha(wxImage* image);
		
	public:
		///Class constructor
		ImageCommon();
		///Copy constructor, creates an internal copy of passed wxImage
		ImageCommon(const ImageCommon &_image);
		///Class constructor, takes onwership of passed wxImage
		ImageCommon(wxImage *_image, bool cube = false);
		///Class destructor
		virtual ~ImageCommon();
		///Is image properly loaded? - \c Image overload
		virtual bool IsOk() const override;
		///Load image data from file - \c Image overload
		virtual bool Load(const wxString & fname, int cubeSide=-1, int flip=0) override;
		///Set image data from binary data. Creates an internal copy of passed wxImage.
		virtual bool SetImage(const wxImage *_image, int cubeSide=-1);
#ifndef VRUT_HPC
		///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=true) override;
		///Get the width of the image
		virtual int GetWidth() const override;
		///Get the height of the image
		virtual int GetHeight() const override;

		const wxImage* GetWxImage(int cubeSide=-1) const
		{
			if ((cubeSide<=0) || (cubeSide>5))
				return image.get();
			return images[cubeSide-1].get();
		}
		///Save the image to file
		virtual bool Save(wxString filename) const override;
	};
}

#endif
