/****************************************************************************************

		IShRasterLayer.h

		Copyright: (c) 2001 Eovia Corp. All rights reserved.

		Author:	Christy
		Date:	10/15/98

		Revision History

		when		who			what & why
		==========	==========	======================================================
		09/02/99	Gerald		Added the tile parameters to GenerateChunkyChannel
		06/04/99	Frh			Added couple Pixel access methods, speed up/fixed the existing
		06/01/99	del			Added GetGlobalCoordinates
		05/21/99	Frh			Added GetPixelRGB && GetPixelRGBA
		04/28/99	Nba			Added inTile parameter to GetTile
		04/19/99	dsm			modified PutTile
		04/14/99	dsm			added IShLayer members
		03/26/99	Mathieu		Color Types
		03/05/99	dsm			source rect local to tile
		03/04/99	dsm			access by tile index
		02/26/99	scooper		add GUID for channel iterator
		02/25/99	scooper		add IShRasterLayerChannelIterator
		2/17/99		psq			Channel/Bucket/Layer API changes
		12/18/98	Nba			Channel interfaces uses IShChannel and not TChannel (internal type)
		12/10/98	scooper		add GetChannelByID, AddChannel, RemoveChannel to interface
		12/04/98	Nba			removed duplicates from IShLayer
		12/02/98	cph			added ability to set bounds and get tile dimensions to API
		11/25/98	cph			changed APIRects to TMCRects
		11/19/98	tsh			changed PutData and PutTile to be passed TChannelDataBucket*
		11/17/98	Eml			removed obsolete IID_IShRasterLayerTileIterator 
								and forward declare IShLayerTileIterator
		11/12/98	cph			added ishlayer methods so all calls are avail from one QI 
		10/29/98	Nba			replaced pixel bucket by TChannelDataBucket
		10/29/98	cph			moved eInvalidIndex to MCImageStatusCode.h and change GetBitDepth return type

*****************************************************************************************/

#ifndef __IShRasterLayer__
#define __IShRasterLayer__

#if CP_PRAGMA_ONCE
#pragma once
#endif

#include "COMTypes.h"
#include "IShChannel.h"
#include "Vector2Fwd.h"


//*********************** Globally Unique Ids ********************************

MCDEFINE_GUID(IID_IShRasterLayer, 0x5fcfcd92, 0x67b7, 0x11d2, 0xb8, 0xa2, 0x0, 0x10, 0x4b, 0x2c, 0x90, 0x11);
MCDEFINE_GUID(IID_IShRasterLayerChannelIterator, 0xe231b7c0, 0xcda9, 0x11d2, 0x93, 0x1, 0x0, 0x10, 0x4b, 0xcd, 0x40, 0x9a);

MCDEFINE_GUID(IID_IShRasterLayerTileIterator, 0x4c23a50, 0x361e, 0x11d2, 0xb8, 0x7f, 0x0, 0x10, 0x4b, 0x2c, 0x90, 0x11);
MCDEFINE_GUID(IID_IShRasterLayerUpdateInfo, 0x57f13d40, 0x790d, 0x11d2, 0xbc, 0x3, 0x0, 0x10, 0x4b, 0x2d, 0x8e, 0x5d);

//****************************************************************************

// types

enum ELayerChannelKind
{
	kLayerChannelKindNone = 0,
	kLayerChannelKindRGB = 1,
	kLayerChannelKindAlpha = 2,
	kLayerChannelKindRGBA = 3,
	kLayerChannelKindCMYK = 4,
	kLayerChannelKindCMYKA = 5,
	kLayerChannelKindOther = 6
};

struct IYeildCallBackFunc
{
    // ****************************************************************************
	//							Yeild	
	// 
	/// Yield the thead
	/// \return true iff the calculation was aborted, may be called even after the result is true and must return the same result in that case
    virtual boolean MCCOMAPI Yeild() = 0;
};

typedef uint TLayerChannelKind;

/*****************************************************************************\
*                                                                             *
*  TMCLayerDataReader                                                         *
*                                                                             *
\*****************************************************************************/

/// Undocumented
///
template <int Tsize> class TMCLayerDataReader {
protected:
	TMCLayerDataReader() {}
	~TMCLayerDataReader() {}
public:
	MCCOMErr GetErrorResult()	 const {return fErr;}
	const	 TChannelDataBucket* const* Get	() const {MCAssert(fErr == MC_S_OK); return fBuckets;}
	const	 TChannelDataBucket* const& operator[](uint8 idx) const {return fBuckets[idx];}
protected:
	const TChannelDataBucket* fBuckets[Tsize];
	MCCOMErr fErr;
};


/*****************************************************************************\
*                                                                             *
*  IShRasterLayerTileIterator                                                 *
*                                                                             *
\*****************************************************************************/

/// This iterator takes a large target rect, splits it into sub-rects that overlap with tiles
/// in the layer, and iterates over the sub-rects.
///
struct IShRasterLayerTileIterator : IMCUnknown
{
public:
	virtual void			MCCOMAPI First				() = 0;
	virtual void			MCCOMAPI Next				() = 0;
	virtual boolean			MCCOMAPI More				() = 0;

	virtual const TMCRect&	MCCOMAPI GetRectInTarget	() = 0;
	virtual const TMCRect&	MCCOMAPI GetRectInBounds	() = 0;
	virtual const TMCRect&	MCCOMAPI GetRectInTile		() = 0;
	virtual uint			MCCOMAPI GetTileIndex		() const = 0;
	
	virtual		  MCCOMErr  MCCOMAPI GetTile			(const TChannelDataBucket* bucket[], ETileAccess flags, TMCRect* out_localSource = NULL)=0;
	virtual		  MCCOMErr  MCCOMAPI UnGetTile			(const TChannelDataBucket* bucket[], boolean dirty)=0;

	/// Undocumented
	template <int Tsize> class TTileReader : public TMCLayerDataReader<Tsize> {
	public:
		TTileReader(IShRasterLayerTileIterator& iter) : fIterator(iter) {this->fErr = fIterator.GetTile(this->fBuckets, eTileRead);}
		~TTileReader() {if (this->fErr == MC_S_OK) fIterator.UnGetTile(this->fBuckets, false);}
	protected:
		IShRasterLayerTileIterator& fIterator;
	};
};


/*****************************************************************************\
*                                                                             *
*  IShRasterLayerChannelIterator                                              *
*                                                                             *
\*****************************************************************************/

/// Iterates over the component (color and/or alpha) channel of a raster layer
///
struct IShRasterLayerChannelIterator : IMCUnknown
{
	virtual void	MCCOMAPI First	(IShChannel** ioChannel)=0;
	virtual void	MCCOMAPI Next	(IShChannel** ioChannel)=0;
	virtual boolean MCCOMAPI More	()=0;
};


class TMCImageTileParameters;

/// \addtogroup MCImage 
/// \{

/// IShRasterLayer is an interface to manipulate the different channels of an image.
/// An image is divided in rectangles called tiles than can be swapped on the hard drive to keep the memory usage low.
/// So when accessing them, you must lock and unlock the tiles that interest you 
/// by calling GetTile() and then UnGetTile() when you're done.
///
/// For rectangles that do not match a tile, you need to allocate one or more buffers, 
/// call GetData() and then UnGetData() when you are done. Note that the image data might NOT be copied into your buffers,
/// so you must use the TChannelDataBucket to access the pixels.
///
/// When you work in read-write mode and UnGet data or tiles, 
/// you need to pass true for the "dirty" argument to cmomit your changes.
///
struct IShRasterLayer : public IMCUnknown
{
	enum ELayerMode
	{
		kNormalMode		= 'norm',
		kAdditionMode	= 'add ',
		kDifferenceMode	= 'diff',
		kMultiplyMode	= 'mult',
		kScreenMode		= 'scrn',
		kHardLightMode	= 'hLit',
		kUnknownMode	= '****',
	};

	virtual MCCOMErr MCCOMAPI	GetBounds						(TMCRect& out_bounds)=0;
	virtual MCCOMErr MCCOMAPI	SetBounds						(const TMCRect& in_bounds)=0;
	virtual MCCOMErr MCCOMAPI	GetExtendedBounds				(TMCRect& out_bounds)=0; // adjusted using wrap around

	// resizing
	virtual MCCOMErr MCCOMAPI	ExtendBounds					(int32 top, int32 left, int32 right, int32 bottom)=0; 

	// misc informations
	virtual uint32   MCCOMAPI	GetMemorySizeForColorChannel	(uint32 width, uint32 height)=0; // includes alpha channel
	virtual uint16   MCCOMAPI	GetColorBitDepth				()=0;

	// misc operation
	virtual	MCCOMErr MCCOMAPI	Clone							(IShRasterLayer** clone)=0;
	virtual	MCCOMErr MCCOMAPI	CopyFrom						(IShRasterLayer* copy)=0;
	virtual	boolean	 MCCOMAPI	IsEqual							(IShRasterLayer* other)=0;

	// iterators
	// target is clipped if the layer does not support wrap-around
	virtual MCCOMErr MCCOMAPI	GetLayerTileIteratorRGB			(IShRasterLayerTileIterator** out_iter, const TMCRect& in_target)=0;
	virtual MCCOMErr MCCOMAPI	GetLayerTileIteratorRGBA		(IShRasterLayerTileIterator** out_iter, const TMCRect& in_target)=0;
	virtual MCCOMErr MCCOMAPI	GetLayerTileIteratorCMYK		(IShRasterLayerTileIterator** out_iter, const TMCRect& in_target)=0;
	virtual MCCOMErr MCCOMAPI	GetLayerTileIteratorCMYKA		(IShRasterLayerTileIterator** out_iter, const TMCRect& in_target)=0;

	// tile information
	virtual MCCOMErr MCCOMAPI	GetTileSize						(TMCRect& out_size)=0; // maximum size for iterating over layer

	virtual uint32   MCCOMAPI	GetTileIndexFromPoint			(const TMCPoint& point, TMCPoint* out_offset = NULL) const = 0;
	virtual MCCOMErr MCCOMAPI	GetRectFromTileIndex			(uint32 index, TMCRect &outTileBounds, const TMCRect* inTileBounds = NULL) const = 0;
	virtual MCCOMErr MCCOMAPI	GetGlobalCoordinates			(uint32 tileIndex, const TMCRect& rectInTile, TMCRect& rectInGlobal) const = 0;

	// --------------------- coordinate transformation --------
	// not guarenteed to stay inside layer; in and out rect can be the same
	virtual MCCOMErr MCCOMAPI	GlobalToLocal					(const TMCRect& global, TMCRect& local) const =0; 
	virtual MCCOMErr MCCOMAPI	GlobalToLocal					(const TMCPoint& global, TMCPoint& local) const =0;

	// Rect access, can do wrap around, does not need to
	// be within tiles (will copy to the provided buffer in case it needs to)
	virtual	MCCOMErr MCCOMAPI	GetRGBData						(const TMCRect& in_source, TChannelDataBucket dest[3], void* in_buffer[3], TDataAccessFlags flags)=0; 
	virtual	MCCOMErr MCCOMAPI	GetRGBAData						(const TMCRect& in_source, TChannelDataBucket dest[4], void* in_buffer[4], TDataAccessFlags flags)=0; 
	virtual	MCCOMErr MCCOMAPI	GetCMYKData						(const TMCRect& in_source, TChannelDataBucket dest[4], void* in_buffer[4], TDataAccessFlags flags)=0; 
	virtual	MCCOMErr MCCOMAPI	GetCMYKAData					(const TMCRect& in_source, TChannelDataBucket dest[5], void* in_buffer[5], TDataAccessFlags flags)=0; 

	virtual	MCCOMErr MCCOMAPI	UnGetRGBData					(TChannelDataBucket dest[3], boolean dirty)=0;
	virtual	MCCOMErr MCCOMAPI	UnGetRGBAData					(TChannelDataBucket dest[4], boolean dirty)=0;
	virtual	MCCOMErr MCCOMAPI	UnGetCMYKData					(TChannelDataBucket dest[4], boolean dirty)=0;
	virtual	MCCOMErr MCCOMAPI	UnGetCMYKAData					(TChannelDataBucket dest[5], boolean dirty)=0;

	virtual MCCOMErr MCCOMAPI	PutRGBData						(TChannelDataBucket source_array[3], const TMCRect& dest, TDataAccessFlags flags)=0;
	virtual MCCOMErr MCCOMAPI	PutRGBAData						(TChannelDataBucket source_array[4], const TMCRect& dest, TDataAccessFlags flags)=0;
	virtual MCCOMErr MCCOMAPI	PutCMYKData						(TChannelDataBucket source_array[4], const TMCRect& dest, TDataAccessFlags flags)=0;
	virtual MCCOMErr MCCOMAPI	PutCMYKAData					(TChannelDataBucket source_array[5], const TMCRect& dest, TDataAccessFlags flags)=0;

	// tile access
	virtual	MCCOMErr MCCOMAPI	GetRGBTile						(const TMCRect& in_source, const TChannelDataBucket* bucket[3], ETileAccess flags, TMCRect* out_localSource = NULL)=0;
	virtual	MCCOMErr MCCOMAPI	GetRGBATile						(const TMCRect& in_source, const TChannelDataBucket* bucket[4], ETileAccess flags, TMCRect* out_localSource = NULL)=0;
	virtual	MCCOMErr MCCOMAPI	GetCMYKTile						(const TMCRect& in_source, const TChannelDataBucket* bucket[4], ETileAccess flags, TMCRect* out_localSource = NULL)=0;
	virtual	MCCOMErr MCCOMAPI	GetCMYKATile					(const TMCRect& in_source, const TChannelDataBucket* bucket[5], ETileAccess flags, TMCRect* out_localSource = NULL)=0;
	virtual	MCCOMErr MCCOMAPI	GetRGBTile						(uint32 in_tileIndex, const TChannelDataBucket* bucket[3], ETileAccess flags, const TMCRect& inTile)=0;
	virtual	MCCOMErr MCCOMAPI	GetRGBATile						(uint32 in_tileIndex, const TChannelDataBucket* bucket[4], ETileAccess flags, const TMCRect& inTile)=0;
	virtual	MCCOMErr MCCOMAPI	GetCMYKTile						(uint32 in_tileIndex, const TChannelDataBucket* bucket[4], ETileAccess flags, const TMCRect& inTile)=0;
	virtual	MCCOMErr MCCOMAPI	GetCMYKATile					(uint32 in_tileIndex, const TChannelDataBucket* bucket[5], ETileAccess flags, const TMCRect& inTile)=0;
	virtual	MCCOMErr MCCOMAPI	UnGetRGBTile					(const TChannelDataBucket* const bucket[3], boolean dirty)=0;
	virtual	MCCOMErr MCCOMAPI	UnGetRGBATile					(const TChannelDataBucket* const bucket[4], boolean dirty)=0;
	virtual	MCCOMErr MCCOMAPI	UnGetCMYKTile					(const TChannelDataBucket* const bucket[4], boolean dirty)=0;
	virtual	MCCOMErr MCCOMAPI	UnGetCMYKATile					(const TChannelDataBucket* const bucket[5], boolean dirty)=0;

	virtual MCCOMErr MCCOMAPI	PutRGBTile						(const TMCRect& dest, const TChannelDataBucket* const source_array[3], ETileAccess flags)=0;
	virtual MCCOMErr MCCOMAPI	PutRGBATile						(const TMCRect& dest, const TChannelDataBucket* const source_array[4], ETileAccess flags)=0;
	virtual MCCOMErr MCCOMAPI	PutCMYKTile						(const TMCRect& dest, const TChannelDataBucket* const source_array[4], ETileAccess flags)=0;
	virtual MCCOMErr MCCOMAPI	PutCMYKATile					(const TMCRect& dest, const TChannelDataBucket* const source_array[5], ETileAccess flags)=0;
	virtual MCCOMErr MCCOMAPI	PutRGBTile						(uint32 tileIndex, const TChannelDataBucket* const source_array[3], ETileAccess flags, const TMCRect& inTile)=0;
	virtual MCCOMErr MCCOMAPI	PutRGBATile						(uint32 tileIndex, const TChannelDataBucket* const source_array[4], ETileAccess flags, const TMCRect& inTile)=0;
	virtual MCCOMErr MCCOMAPI	PutCMYKTile						(uint32 tileIndex, const TChannelDataBucket* const source_array[4], ETileAccess flags, const TMCRect& inTile)=0;
	virtual MCCOMErr MCCOMAPI	PutCMYKATile					(uint32 tileIndex, const TChannelDataBucket* const source_array[5], ETileAccess flags, const TMCRect& inTile)=0;

	// span access
	virtual MCCOMErr MCCOMAPI	GetRgbSpan						(int32 x, int32 y, int32 w, void* buf, uint8 bitdepth)=0;  
	virtual MCCOMErr MCCOMAPI	PutRgbSpan						(int32 x, int32 y, int32 w, void* buf, uint8 bitdepth)=0;

	virtual MCCOMErr MCCOMAPI	GetAlphaTileUniformValue		(const TMCRect& in_rect, boolean& is_uniform, uint32& value)=0;
	
	// point access
	virtual MCCOMErr MCCOMAPI	GetPixelRGB						(const TMCPoint inPoint, TArrayRGB& pixel) = 0;
	virtual MCCOMErr MCCOMAPI	GetPixelRGBA					(const TMCPoint inPoint, TArrayRGBA& pixel) = 0;

	// Those functions assume that if GetPixelRGB is overriden, they will be, too.
	virtual MCCOMErr MCCOMAPI	GetPixelRGBList					(const TMCPoint* inPointList, TArrayRGB* pixelList, int32 howMany) = 0;
	virtual MCCOMErr MCCOMAPI	GetPixelRGBAList				(const TMCPoint* inPointList, TArrayRGBA* pixelList, int32 howMany) = 0;
	virtual MCCOMErr MCCOMAPI	GetMedian						(TMCPoint inPoint, uint16 radius, TArrayRGB& pixel) = 0;
	virtual MCCOMErr MCCOMAPI	GetInterpolatedPixelRGB			(const TVector2& inVector, TArrayRGB& pixel) = 0;
	virtual MCCOMErr MCCOMAPI	GetInterpolatedPixelRGBA		(const TVector2& inVector, TArrayRGBA& pixel) = 0;
	virtual MCCOMErr MCCOMAPI	GetInterpolatedPixelRGBList		(const TVector2* inVectorList, TArrayRGB* pixelList, int32 howMany) = 0;
	virtual MCCOMErr MCCOMAPI	GetInterpolatedPixelRGBAList	(const TVector2* inVectorList, TArrayRGBA* pixelList, int32 howMany) = 0;

	// invalidation/change manager
	virtual MCCOMErr MCCOMAPI	GetContentChangeChannel			(IChangeChannel** changeChannel) = 0;
	virtual MCCOMErr MCCOMAPI	GetPropertyChangeChannel		(IChangeChannel** changeChannel) = 0;

	virtual MCCOMErr MCCOMAPI	PrepareOperation				(void)=0;
	virtual MCCOMErr MCCOMAPI	EndOperation					(void)=0;

	virtual	MCCOMErr MCCOMAPI	Invalidate						(const TMCRect& invalRect, uint32 channelSetMask)=0;

	// attached information handling
	virtual MCCOMErr MCCOMAPI	GetName							(TMCString& name) const = 0;
	virtual MCCOMErr MCCOMAPI	SetName							(const TMCString& name) = 0;
	virtual boolean  MCCOMAPI	GetVisibility					() const = 0;
	virtual MCCOMErr MCCOMAPI	SetVisibility					(boolean visibility) = 0;
	virtual boolean  MCCOMAPI	GetLock							() const = 0;
	virtual MCCOMErr MCCOMAPI	SetLock							(boolean lock) = 0;
	virtual boolean  MCCOMAPI	GetPreserveTransparency			() const = 0;
	virtual MCCOMErr MCCOMAPI	SetPreserveTransparency			(boolean preserve) = 0;
	virtual real	 MCCOMAPI	GetOpacity						() const = 0;
	virtual MCCOMErr MCCOMAPI	SetOpacity						(real opacity) = 0;
	virtual real	 MCCOMAPI	GetDPI							() const = 0;
	virtual MCCOMErr MCCOMAPI	SetDPI							(real dpi) = 0;
	virtual ELayerMode	MCCOMAPI	GetLayerMode				() const = 0;
	virtual void		MCCOMAPI	SetLayerMode				(ELayerMode mode) = 0;

	// ---------------- Channel
	virtual uint16   MCCOMAPI	GetChannelCount					()=0;
	virtual MCCOMErr MCCOMAPI	GetIShChannel					(uint16 index, IShChannel** out_channel)=0;
	virtual MCCOMErr MCCOMAPI	CreateChannel					(IShChannel** channel, const TChannelID &id, uint32 bitDepth)=0;
	virtual void	 MCCOMAPI	AddChannel						(IShChannel* channel)=0;
	virtual void	 MCCOMAPI	RemoveChannel					(IShChannel* channel)=0;
	virtual MCCOMErr MCCOMAPI	GetRasterLayerChannelIterator	(IShRasterLayerChannelIterator** outIter)=0;
	// ---------------- Channel IDs
	virtual uint16	 MCCOMAPI	GetChannelCountByID				(const TChannelID& in_id)=0;
	virtual MCCOMErr MCCOMAPI	GetChannelByID					(const TChannelID& id, IShChannel** out_channel)=0;
	virtual MCCOMErr MCCOMAPI	MatchChannelID2Index			(const TChannelID in_ids[], uint16 indexes[], uint16 channel_count)=0;
	// ---------------- Data Access
	virtual	MCCOMErr MCCOMAPI	GetData							(const TMCRect& source, TChannelDataBucket dest_array[], void* buffer[], uint16 indexes[], uint16 numChannels, TDataAccessFlags flags, IYeildCallBackFunc* callBack)=0; 
	virtual	MCCOMErr MCCOMAPI	UnGetData						(TChannelDataBucket dest_array[], uint16 indexes[], uint16 numChannels, boolean dirty)=0;
	virtual MCCOMErr MCCOMAPI	PutData							(TChannelDataBucket source_array[], const TMCRect& dest, uint16 indexes[], uint16 numChannels, TDataAccessFlags flags)=0;
	// ---------------- Tile Access
								// target is clipped if the layer does not support wrap-around
	virtual MCCOMErr MCCOMAPI	GetRasterLayerTileIterator		(IShRasterLayerTileIterator** iter, uint16 indexes[], 
																 uint16 numChannels, const TMCRect& target)=0;
								 // index access for faster multiple access to the same tile
	virtual	MCCOMErr MCCOMAPI	GetTile							(const TMCRect& source, const TChannelDataBucket* bucket[], uint16 indexes[], uint16 numChannels, ETileAccess flags, TMCRect* out_localSource = NULL)=0;
	virtual	MCCOMErr MCCOMAPI	GetTile							(uint32 in_tileIndex, const TChannelDataBucket* bucket[], uint16 indexes[], uint16 numChannels, ETileAccess flags, const TMCRect &inTile)=0;
	virtual	MCCOMErr MCCOMAPI	UnGetTile						(const TChannelDataBucket* bucket[], uint16 indexes[], uint16 numChannels, boolean dirty)=0;
	virtual MCCOMErr MCCOMAPI	PutTile							(const TMCRect& dest, const TChannelDataBucket* const source_array[], uint16 indexes[], uint16 numChannels, ETileAccess flags)=0;
	virtual MCCOMErr MCCOMAPI	PutTile							(uint32 tileIndex, const TChannelDataBucket* const source_array[], uint16 indexes[], uint16 numChannels, ETileAccess flags, const TMCRect &inTile)=0;
	virtual MCCOMErr MCCOMAPI	GetTileRect						(int32 x, int32 y, TMCRect& out_neiborhood)=0; // given a point, gives the surrounding tile

	virtual boolean  MCCOMAPI	IsRGB							() const = 0;
	virtual boolean  MCCOMAPI	IsCMYK							() const = 0;
	virtual MCCOMErr MCCOMAPI	CreateRGBChannelsFromCMYK		() = 0;
	virtual MCCOMErr MCCOMAPI	CreateCMYKChannelsFromRGB		() = 0;
	virtual MCCOMErr MCCOMAPI	GetRGBChannelSetMask			(uint32& channelSetMask) = 0;
	virtual MCCOMErr MCCOMAPI	GetCMYKChannelSetMask			(uint32& channelSetMask) = 0;
	virtual MCCOMErr MCCOMAPI	GetAlphaChannelSetMask			(uint32& channelSetMask) = 0;
	virtual MCCOMErr MCCOMAPI	GetRGBIndices					(uint16 indices[3]) = 0;
	virtual MCCOMErr MCCOMAPI	GetRGBAIndices					(uint16 indices[4]) = 0;
	virtual MCCOMErr MCCOMAPI	GetCMYKIndices					(uint16 indices[4]) = 0;
	virtual MCCOMErr MCCOMAPI	GetCMYKAIndices					(uint16 indices[5]) = 0;
	virtual ELayerColorType MCCOMAPI GetColorType				() const = 0;
	virtual void SetColorType(ELayerColorType cType) = 0;
	virtual MCCOMErr MCCOMAPI	GenerateChunkyChannel			(IShChannel** channel, const TMCImageTileParameters* params = NULL ) = 0;
	
	// ****************************************************************************
	//								SetUsePreMultipliedAlpha
	// 
	/// Sets whether this layer contains color channel with premultiplied alpha or not
	/// 
	/// \param usePreMultipliedAlpha  true if the alpha is already multiplied in the color (this is the default)
	/// 
	virtual void			MCCOMAPI SetUsePreMultipliedAlpha(boolean usePreMultipliedAlpha)=0;

	// ****************************************************************************
	//								UsePreMultipliedAlpha
	// 
	/// Returns true if the layer contains color channels with premultiplied alpha, false otherwhise.
	/// 
	virtual boolean			MCCOMAPI UsePreMultipliedAlpha()=0;

	// ****************************************************************************
	//								BlendLayer
	// 
	/// Blend a layer on top of this one.
	/// 
	/// \param layer	The layer to blend on top
	/// \param mode		Blend mode.
	/// \param opacity	Opacity.
	/// 
	virtual void			MCCOMAPI BlendLayer(IShRasterLayer* layer, ELayerMode mode, real32 opacity)=0;

	/// Undocumented
	class TRGBTileReader : public TMCLayerDataReader<3> {
	public:
		TRGBTileReader(IShRasterLayer& layer, const TMCRect& in_source) : fLayer(layer) {fErr = fLayer.GetRGBTile(in_source, fBuckets, eTileRead, &fLocalSource);}
		TRGBTileReader(IShRasterLayer& layer, uint32 in_tileIndex, const TMCRect& inTile) : fLayer(layer) {fErr = fLayer.GetRGBTile(in_tileIndex, fBuckets, eTileRead, inTile);}
		~TRGBTileReader() {if (fErr == MC_S_OK) fLayer.UnGetRGBTile(fBuckets, false);}

		const TMCRect& GetLocalSource() {return fLocalSource;}

	protected:
		IShRasterLayer& fLayer;
		TMCRect fLocalSource;
	};

	/// Undocumented
	class TRGBATileReader : public TMCLayerDataReader<4> {
	public:
		TRGBATileReader(IShRasterLayer& layer, const TMCRect& in_source) : fLayer(layer) {fErr = fLayer.GetRGBATile(in_source, fBuckets, eTileRead, &fLocalSource);}
		TRGBATileReader(IShRasterLayer& layer, uint32 in_tileIndex, const TMCRect& inTile) : fLayer(layer) {fErr = fLayer.GetRGBATile(in_tileIndex, fBuckets, eTileRead, inTile);}
		~TRGBATileReader() {if (fErr == MC_S_OK) fLayer.UnGetRGBATile(fBuckets, false);}

		const TMCRect& GetLocalSource() {return fLocalSource;}

	protected:
		IShRasterLayer& fLayer;
		TMCRect fLocalSource;
	};

	/// Undocumented
	class TCMYKTileReader : public TMCLayerDataReader<4> {
	public:
		TCMYKTileReader(IShRasterLayer& layer, const TMCRect& in_source) : fLayer(layer) {fErr = fLayer.GetCMYKTile(in_source, fBuckets, eTileRead, &fLocalSource);}
		TCMYKTileReader(IShRasterLayer& layer, uint32 in_tileIndex, const TMCRect& inTile) : fLayer(layer) {fErr = fLayer.GetCMYKTile(in_tileIndex, fBuckets, eTileRead, inTile);}
		~TCMYKTileReader() {if (fErr == MC_S_OK) fLayer.UnGetCMYKTile(fBuckets, false);}

		const TMCRect& GetLocalSource() {return fLocalSource;}

	protected:
		IShRasterLayer& fLayer;
		TMCRect fLocalSource;
	};

	/// Undocumented
	class TCMYKATileReader : public TMCLayerDataReader<5> {
	public:
		TCMYKATileReader(IShRasterLayer& layer, const TMCRect& in_source) : fLayer(layer) {fErr = fLayer.GetCMYKATile(in_source, fBuckets, eTileRead, &fLocalSource);}
		TCMYKATileReader(IShRasterLayer& layer, uint32 in_tileIndex, const TMCRect& inTile) : fLayer(layer) {fErr = fLayer.GetCMYKATile(in_tileIndex, fBuckets, eTileRead, inTile);}
		~TCMYKATileReader() {if (fErr == MC_S_OK) fLayer.UnGetCMYKATile(fBuckets, false);}

		const TMCRect& GetLocalSource() {return fLocalSource;}

	protected:
		IShRasterLayer& fLayer;
		TMCRect fLocalSource;
	};
};

/// \}


///////////////////////////////////////////////////////////////////////////////////////////
// class IShRasterLayerUpdateInfo
//////////////////////////////////////////////////////////////////////////////////////////

class TMCListenedChannelSet;

/// Undocumented
///
class IShRasterLayerUpdateInfo : public IMCUnknown
{
public:
	virtual MCCOMErr MCCOMAPI GetUpdatedRect			(TMCRect& out_rect) = 0;
	virtual MCCOMErr MCCOMAPI GetLayer					(IShRasterLayer** layer) = 0;
	virtual MCCOMErr MCCOMAPI GetChannel				(IShChannel** channel) = 0;
	virtual MCCOMErr MCCOMAPI ConcernChannels			(IDType changeKind, TMCListenedChannelSet& channelSet) = 0;
	virtual MCCOMErr MCCOMAPI GetChannelSetMask			(uint32& channelSetMask) = 0;
};

#endif
