/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2014 Raytrix GmbH. All rights reserved.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma once

#ifndef RX_STATIC
    #ifdef RXFILEIO_EXPORTS
		#define RXFILEIO_API __declspec(dllexport)
    #else
		#define RXFILEIO_API __declspec(dllimport)
    #endif
#else
	#define RXFILEIO_API
#endif

// To use the class you don't need to import all the codecs,
// thus we use a forward declaration to simplify and reduce include chain clutter
namespace Rx
{
	class CRxString;
	namespace Codec
	{
		class IImageCodec;
		class CBmp;
		class CJ2k;
		class CJpg;
		class CPng;
		class CTiff;
		class CDng;
	}
	namespace Interop
	{
		namespace Runtime28
		{
			class IImage;
		}
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// namespace: Rx.FileIO
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace Rx
{
	namespace FileIO
	{
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>
		/// 	GZip file.
		/// </summary>
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		class RXFILEIO_API CImage
		{
		public:

			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			/// <summary>
			/// 	Default constructor.
			/// </summary>
			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			CImage();

			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			/// <summary>
			/// 	Destructor.
			/// </summary>
			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			~CImage();

		public:

			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			/// <summary>
			/// 	Reads the given file and stores the decoded image into target image.
			/// </summary>
			///
			/// <param name="pTrgImg">    [out] The target image. </param>
			/// <param name="sxFilename"> Filename. </param>
			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			void Read(Interop::Runtime28::IImage* pTrgImg, const CRxString& sxFilename);

			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			/// <summary>
			/// 	Writes the given source image encoded to given file. The codec is determined by filename extension.
			/// </summary>
			///
			/// <param name="pSrcImg">   	Source image. </param>
			/// <param name="sxFilename">	Filename. </param>
			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			void Write(const Interop::Runtime28::IImage* pSrcImg, const CRxString& sxFilename);

		public:

			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			/// <summary>
			/// 	Gets the JPEG codec.
			/// </summary>
			///
			/// <returns>	The JPEG codec. </returns>
			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			Codec::CJpg& GetCodecJpg()
			{
				return *m_pxJpg;
			}

		private:

			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			/// <summary>
			/// 	Gets the codec from filename.
			/// </summary>
			///
			/// <param name="sxFilename"> Filename. </param>
			///
			/// <returns> The codec from filename. </returns>
			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			Codec::IImageCodec* _GetCodecFromFilename(const CRxString& sxFilename);

		private:

			Codec::CBmp* m_pxBmp;
			Codec::CJ2k* m_pxJ2k;
			Codec::CJpg* m_pxJpg;
			Codec::CPng* m_pxPng;
			Codec::CTiff* m_pxTiff;
			Codec::CDng* m_pxDng;
		};
	}
}
