#ifndef GFX_IMAGE_IMAGECHANNEL_H__
#define GFX_IMAGE_IMAGECHANNEL_H__

#include "maxon/gfx_image_bits.h"
#include "maxon/gfx_image_colorspace.h"
#include "maxon/half.h"
#include "maxon/objectbase.h"



namespace maxon
{

/// @addtogroup Graphics
/// @{

using Pix = UChar;		///< unspecified pixel format depth.
using Pix8u = UChar;	///< pixel format with 8 bit unsigned integer values (0..255).
using Pix8s = Char;	///< pixel format with 8 bit signed integer values (-128..127).
using Pix16u = UInt16; ///< pixel format with 16 bit unsigned integer values (0..65535).
using Pix16s = Int16; ///< pixel format with 16 bit signed integer values (-32768..32767).
using Pix32u = UInt32; ///< pixel format with 32 bit unsigned integer values (0..0xFFFFFFFF).
using Pix32s = Int32; ///< pixel format with 32 bit signed integer values (-0x7FFFFFFF..0x7FFFFFFF).
using Pix32f = Float32; ///< pixel format with 32 bit floating point values.
using Pix64f = Float64; ///< pixel format with 64 bit floating point values.
using Pix16f = HalfFloat; ///< pixel format with 16 bit floating point values (half float).



class ImageChannelType;
class ImageChannel;

//----------------------------------------------------------------------------------------
/// ImageChannelTypes define how a pixel channel should be interpreted.
//----------------------------------------------------------------------------------------
class ImageChannelTypeInterface : MAXON_INTERFACE_BASES(ObjectInterface)
{
	MAXON_INTERFACE(ImageChannelTypeInterface, MAXON_REFERENCE_CONST, "net.maxon.image.interface.imagechanneltype");

public:
	//----------------------------------------------------------------------------------------
	/// Returns the default fill value for this type of channel. (e.g. Alpha returns 255 but other channel types may return 0).
	//----------------------------------------------------------------------------------------
	MAXON_METHOD Pix8u GetDefaultFillValue() const;

	//----------------------------------------------------------------------------------------
	/// Returns the color space to which the channel type belongs to.
	//----------------------------------------------------------------------------------------
	MAXON_METHOD ColorSpace GetColorSpace() const;

	//----------------------------------------------------------------------------------------
	/// Returns the ImageChannel for the given data type.
	//----------------------------------------------------------------------------------------
	MAXON_METHOD ImageChannel GetChannel(const DataType& pixelType) const;

	//----------------------------------------------------------------------------------------
	/// Returns the ImageChannel for the given data type.
	//----------------------------------------------------------------------------------------
	template <typename PIXELDEPTH> MAXON_FUNCTION ImageChannel GetChannel() const;
};




class ImageChannelInterface : MAXON_INTERFACE_BASES(ObjectInterface)
{
	MAXON_INTERFACE(ImageChannelInterface, MAXON_REFERENCE_CONST, "net.maxon.image.interface.imagechannel");

public:
	//----------------------------------------------------------------------------------------
	/// Returns the size in bits of each component.
	//----------------------------------------------------------------------------------------
	MAXON_METHOD BITS GetChannelBits() const;

	//----------------------------------------------------------------------------------------
	/// Returns true if the channel is a alpha channel.
	//----------------------------------------------------------------------------------------
	MAXON_METHOD ImageChannelType GetChannelType() const;

	//----------------------------------------------------------------------------------------
	/// Returns the data type of the pixel format.
	//----------------------------------------------------------------------------------------
	MAXON_METHOD const DataType& GetDataType() const;

	//----------------------------------------------------------------------------------------
	/// Compares two components.
	/// @param[in] a									Component buffer 1.
	/// @param[in] b									Component buffer 2.
	/// @param[in] oneTolerance				Pixel difference related to 0..255 range.
	/// @return												Returns true is the pixel is within the given tolerance.
	//----------------------------------------------------------------------------------------
	MAXON_METHOD Bool IsIdenticalComponent(const void* a, const void* b, Int oneTolerance) const;
};



// include autogenerated headerfile here
#include "gfx_image_imagechannel1.hxx"

// include autogenerated headerfile here
#include "gfx_image_imagechannel2.hxx"


template <typename PIXELDEPTH> ImageChannel ImageChannelTypeInterface::GetChannel() const
{
	return GetChannel(GetDataType<PIXELDEPTH>());
}

/// @}

} // namespace maxon


#endif // GFX_IMAGE_IMAGECHANNEL_H__
