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

		IShPixelBucketUtilities.h

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

		Author:	Guillaume
		Date:	09/24/1999

		Revision History

		when		who			what & why
		==========	==========	======================================================
		10/05/99	David		added a parameter doEMMS to PlanarToChunky and ChunkyToPlanar functions
		10/04/99	Nba			Added UsesMMX
******************************************************************************************/

#ifndef __ISHPIXELUTILITIES__
#define __ISHPIXELUTILITIES__

#if CP_PRAGMA_ONCE
#pragma once
#endif


#include "MCBasicTypes.h"
#include "MCCompObj.h"
#include "MCOSConfig.h"
#include "MCPixelBucket.h"


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

MCDEFINE_GUID_H(IID_IShPixelBucketUtilities);

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


/*****************************************************************************\
*                                                                             *
*  IShPixelBucketUtilities                                                    *
*                                                                             *
\*****************************************************************************/

struct IMCFile;
/// \addtogroup MCImage
/// \{

/// Pixel bucket utilities.
struct IShPixelBucketUtilities : public IMCUnknown
{
	// After calling those functions, be sure to call DoEMMS()

	// ****************************************************************************
	//								PlanarToChunkyOneAlpha
	// 
	/// Converts three planar pixel buckets to one chunky one.  Sets alpha channel to zeros.
	/// p1, p2, and p3 must be compatible (same size and bit depth).  Target must be big enough to hold
	/// all of them, and must be able to handle 4 planes.
	/// 
	/// \param p1      First pixel bucket
	/// \param p2      Second pixel bucket
	/// \param p3      Third pixel bucket
	/// \param target  Output pixel bucket
	/// \param doEMMS  If true, calls DoEMMS() at the end of the operation
	/// 
	virtual MCCOMErr MCCOMAPI PlanarToChunkyOneAlpha		(const TMCPixelBucket* p1, const TMCPixelBucket* p2, const TMCPixelBucket* p3, const TMCPixelBucket* target, boolean doEMMS) = 0;

	// ****************************************************************************
	//								PlanarToChunkyOneAlpha
	// 
	/// Converts three planar pixel buckets to one chunky one.  Sets alpha channel to zeros.
	/// Target must be big enough to hold four planes sized as inRect.  
	/// 
	/// \param p1      First pixel bucket
	/// \param p2      Second pixel bucket
	/// \param p3      Third pixel bucket
	/// \param target  Output pixel bucket
	/// \param inRect  Rectangle defining region to copy
	/// \param doEMMS  If true, calls DoEMMS() at the end of the operation
	/// 
	virtual MCCOMErr MCCOMAPI PlanarToChunkyOneAlpha		(const TMCPixelBucket* p1, const TMCPixelBucket* p2, const TMCPixelBucket* p3, const TMCPixelBucket* target, const TMCRect* inRect, boolean doEMMS) = 0;

	// version with different src and dst SubRect. Shoudl be the same size thought
	
	// ****************************************************************************
	//								PlanarToChunkyOneAlpha
	// 
	/// Converts three planar pixel buckets to one chunky one.  Sets alpha channel to zeros.
	/// Target must be big enough to hold four planes sized as srcRect.  Size of dstRect should
	/// equal size of srcRect.
	/// 
	/// \param p1      First pixel bucket
	/// \param p2      Second pixel bucket
	/// \param p3      Third pixel bucket
	/// \param dest    Output pixel bucket
	/// \param srcRect Source region to copy 
	/// \param dstRect destination region to copy to
	/// \param doEMMS  If true, calls DoEMMS() at the end of the operation
	/// 
	virtual MCCOMErr MCCOMAPI PlanarToChunkyOneAlpha		(const TMCPixelBucket* p1, const TMCPixelBucket* p2, const TMCPixelBucket* p3, const TMCPixelBucket* dest, const TMCRect* srcRect,const TMCRect* dstRect, boolean doEMMS) = 0;

	/// As PlanarToChunkyOneAlpha, but destination must be 8 bits, while input can be 8 or 16 bits.
	/// \see PlanarToChunkyOneAlpha
	virtual MCCOMErr MCCOMAPI PlanarToChunkyOneAlphaTo8		(const TMCPixelBucket* p1, const TMCPixelBucket* p2, const TMCPixelBucket* p3, const TMCPixelBucket* dest, boolean doEMMS) = 0;

	/// As PlanarToChunkyOneAlpha, but destination must be 8 bits, while input can be 8 or 16 bits.
	/// \see PlanarToChunkyOneAlpha
	virtual MCCOMErr MCCOMAPI PlanarToChunkyOneAlphaTo8		(const TMCPixelBucket* p1, const TMCPixelBucket* p2, const TMCPixelBucket* p3, const TMCPixelBucket* dest, const TMCRect* inRect, boolean doEMMS) = 0;

	/// As PlanarToChunkyOneAlpha, but destination must be 8 bits, while input can be 8 or 16 bits.
	/// \see PlanarToChunkyOneAlpha
	virtual MCCOMErr MCCOMAPI PlanarToChunkyOneAlphaTo8		(const TMCPixelBucket* p1, const TMCPixelBucket* p2, const TMCPixelBucket* p3, const TMCPixelBucket* dest, const TMCRect* srcRect,const TMCRect* dstRect, boolean doEMMS) = 0;

	/// As PlanarToChunkyOneAlpha, but destination must be 8 bits, while input is 16 bits.
	/// \see PlanarToChunkyOneAlpha
	virtual MCCOMErr MCCOMAPI PlanarToChunkyOneAlphaTo8_w16	(const TMCPixelBucket* p1, const TMCPixelBucket* p2, const TMCPixelBucket* p3, const TMCPixelBucket* dest, boolean doEMMS) = 0;

	/// As PlanarToChunkyOneAlpha, but destination must be 8 bits, while input is 16 bits.
	/// \see PlanarToChunkyOneAlpha
	virtual MCCOMErr MCCOMAPI PlanarToChunkyOneAlphaTo8_w16	(const TMCPixelBucket* p1, const TMCPixelBucket* p2, const TMCPixelBucket* p3, const TMCPixelBucket* dest, const TMCRect* inRect, boolean doEMMS) = 0;

	/// As PlanarToChunkyOneAlpha, but destination must be 8 bits, while input is 16 bits.
	/// \see PlanarToChunkyOneAlpha
	virtual MCCOMErr MCCOMAPI PlanarToChunkyOneAlphaTo8_w16	(const TMCPixelBucket* p1, const TMCPixelBucket* p2, const TMCPixelBucket* p3, const TMCPixelBucket* dest, const TMCRect* srcRect,const TMCRect* dstRect, boolean doEMMS) = 0;

	// ****************************************************************************
	//								ChunkyToPlanarNoAlpha
	// 
	/// As PlanarToChunkyOneAlpha, but no alpha channel in destination pixel bucket.
	/// 
	virtual MCCOMErr MCCOMAPI ChunkyToPlanarNoAlpha			(const TMCPixelBucket* source, const TMCPixelBucket* p1, const TMCPixelBucket* p2, const TMCPixelBucket* p3, boolean doEMMS) = 0;

	/// convert a 8 bit channel to a 16 bit channel
	virtual MCCOMErr MCCOMAPI Convert8To16					(const TMCPixelBucket* src, const TMCPixelBucket* dest) = 0;

	/// downsample from 16 to 8 bit a channel
	virtual MCCOMErr MCCOMAPI Convert16To8					(const TMCPixelBucket* src, const TMCPixelBucket* dest) = 0;

	/// copy a bucket to an other
	virtual MCCOMErr MCCOMAPI CopyBucket					(const TMCPixelBucket* src, const TMCPixelBucket* dest) = 0;

	virtual boolean	 MCCOMAPI SameSize						(const TMCPixelBucket* p1, const TMCPixelBucket* p2) = 0;
		
	virtual boolean  MCCOMAPI SameSize						(const TMCPixelBucket* p1, const TMCPixelBucket* p2, const TMCPixelBucket* p3) = 0;

	virtual boolean  MCCOMAPI InSize						(const TMCPixelBucket* p1, const TMCPixelBucket* p2) = 0;

	/// fills a subrect fillArea of a given pixel bucket using the given 16 bit fillValue
	virtual void	 MCCOMAPI FillRect16					(TMCPixelBucket* destBucket, const TMCRect& fillArea, uint16 fillValue) = 0;

	/// fills a subrect fillArea of a given pixel bucket using the given fillValue (of any size)
	virtual void	 MCCOMAPI FillRectAny					(TMCPixelBucket* destBucket, const TMCRect& fillArea, uint8* fillValuePtr, int16 size) = 0;

	/// duplicates the data around source_area inside the pixel bucket
	virtual void	 MCCOMAPI ExpandRect					(TMCPixelBucket* destBucket, const TMCRect& source_area) = 0;

	/// returns true if the processor supports the MMX instruction set
	virtual boolean  MCCOMAPI UsesMMX						() = 0;

	/// Import/Export of images to/from simple TMCPixelBucket
	virtual MCCOMErr MCCOMAPI LoadPixelBucket				(TMCPixelBucket*& bucketOut, IMCFile* aFile, IDType format) = 0;
	virtual MCCOMErr MCCOMAPI SavePixelBucket				(const TMCPixelBucket* bucket, IMCFile* aFile, IDType format, boolean displayOptions = true, void* pluginOptions = nil) = 0;

	// ****************************************************************************
	//								PlanarToChunkyTo8
	// 
	/// convert a layered image composed of 4 planes (RGBA) into a chunky image.
	/// 
	/// \param p1      First pixel bucket
	/// \param p2      Second pixel bucket
	/// \param p3      Third pixel bucket
	/// \param p4      Fourth pixel bucket
	/// \param target  Output Bucket
	/// \param inRect  Rectangle bounds to copy
	/// 
	virtual MCCOMErr MCCOMAPI PlanarToChunkyTo8(const TMCPixelBucket* p1,		const TMCPixelBucket* p2,
												const TMCPixelBucket* p3,		const TMCPixelBucket* p4,
												const TMCPixelBucket* target,	const TMCRect* inRect)=0;
	
};

/// \}

#endif