/**************************************************************
FastExternals Plug-in Interface Header

Copyright John Paul Chacha. All Rights Reserved.

This source code file, which has been provided by one
John Paul Chacha as part of his software product for use only
by licensed users of that product, includes proprietary
information of John Paul Chacha.

USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
OF THE LICENSE AGREEMENT FURNISHED WITH THE PRODUCT.

IN PARTICULAR, JOHN PAUL CHACHA SHALL BE FREE FROM ANY CLAIMS
OR LIABILITIES ARISING OUT OF THE USE OR MISUSE OF THIS FILE
AND/OR ITS CONTENTS.

Latest revision date: 26-Jan-2012
**************************************************************/

#pragma once

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////



/**************************************************************
Global Defines
**************************************************************/

#define PLUGIN_INTERFACE_VERSION	((2<<16)+45)// 2 rev 45
#define PLUGIN_INTERFACE_VERSION$	L"2 rev 45"

//-------------------------------------------------------------

#define PLG_TYPE_INVALID						0x00000000

#define PLG_TYPE_FILE_FILTER					0x00000001
#define PLG_TYPE_IMAGE_DEVICE					0x00000002
#define PLG_TYPE_IMAGE_EFFECT					0x00000004

#define PLG_TYPE_GRAPH_ENGINE					0x00000010
#define PLG_TYPE_RESIDENT_DEV					0x00000020

#define FLT_FLAG_IMGTYPE_LAYERED				0x00000000
#define FLT_FLAG_IMGTYPE_IMAGELIST				0x00000001
#define FLT_FLAG_IMGTYPE_ANIMATION				0x00000002
#define FLT_FLAG_IMGTYPE_xxx					0x0000000f

#define GENERIC_XFORM_ROTATE_090				0x00000001
#define GENERIC_XFORM_ROTATE_180				0x00000002
#define GENERIC_XFORM_ROTATE_270				0x00000003
#define GENERIC_XFORM_FLIP_H					0x00000004
#define GENERIC_XFORM_FLIP_V					0x00000005
#define GENERIC_XFORM_TRANSPOSE					0x00000006
#define GENERIC_XFORM_TRANSVERSE				0x00000007

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////



/**************************************************************
Basic Interface Structs
**************************************************************/

//-------------------------------------------------------------
//pi_BasicImage
//-------------------------------------------------------------

#define PI_BASICIMAGE_VERSION					0x00010004

struct pibi_IMAGE
{
	unsigned long width;
	unsigned long height;
	unsigned long pitch;
	unsigned long unused;
	unsigned long *p_pix;
	void		  *reserved;
};

struct pi_BASICIMAGE
{
	unsigned long version;
	int (__cdecl* create)(pibi_IMAGE* img,int width,int height);
	int (__cdecl* virtualize)(pibi_IMAGE* img,
		int width,int height,int pitch,unsigned long* p_pix);
	int (__cdecl* destroy)(pibi_IMAGE* img);
//16
	int (__cdecl* lock)(pibi_IMAGE* img);
	int (__cdecl* unlock)(pibi_IMAGE* img);
//24
	HDC (__cdecl* gdi_getDC)(pibi_IMAGE* img);
	int (__cdecl* gdi_freeDC)(pibi_IMAGE* img,HDC hdc);
	HBITMAP (__cdecl* gdi_makeHBMP)(pibi_IMAGE* img);
	void* reserved_1;
//40
	int (__cdecl* blit)(
		pibi_IMAGE* dst,int dx0,int dy0,int dx1,int dy1,
		pibi_IMAGE* src,int sx0,int sy0,int sx1,int sy1,
		unsigned long options,unsigned long param);
	int (__cdecl* fill)(
		pibi_IMAGE* img,int x0,int y0,int x1,int y1,
		unsigned long color1,unsigned long color2,
		unsigned long color3,unsigned long color4,
		unsigned long options,int param1,int param2);
	int (__cdecl* blitToDC)(
		HDC hdc,int dx0,int dy0,int dx1,int dy1,
		pibi_IMAGE* src,int sx0,int sy0,int sx1,int sy1,
		unsigned long options,unsigned long param);
	void* reserved_2;
//56
	int (__cdecl* translate)(
		pibi_IMAGE* img,int x0,int y0,int x1,int y1,
		unsigned char *lut_r,unsigned char *lut_g,
		unsigned char *lut_b,unsigned char *lut_a,
		unsigned long options,void* param);

	int (__cdecl* transform)(
		pibi_IMAGE* img,int x0,int y0,int x1,int y1,
		double *matrix_5x4,unsigned long options);

	int (__cdecl* convolute)(
		pibi_IMAGE* dst,int x0,int y0,int x1,int y1,
		pibi_IMAGE* src,double *matrix,int mat_cols,int mat_rows,
		unsigned long mask,unsigned long options);

	int (__cdecl* compare)(
		pibi_IMAGE* img1,pibi_IMAGE* img2,RECT *rt_diff);
//72
	unsigned char	reserved_x[1024-72];//do not touch
};

//flags for the "options" parameter of ::blit()
#define PI_BI_BLIT_STRETCH						0x00000001
#define PI_BI_BLIT_HQ_STRETCH					0x00000002
#define PI_BI_BLIT_ALPHABLEND					0x00000010
#define PI_BI_BLIT_TILE_xxx						0x00030000
	#define PI_BI_BLIT_TILE_NORMAL				0x00010000
	#define PI_BI_BLIT_TILE_INVERT				0x00020000

//flags for the "options" parameter of ::fill()
#define PI_BI_FILL_SHAPE_xxx					0x0000000f
	#define PI_BI_FILL_RECTANGLE				0x00000000
	#define PI_BI_FILL_ELLIPSE					0x00000001
	#define PI_BI_FILL_ROUNDRECT				0x00000002
#define PI_BI_FILL_ALPHABLEND					0x00000010
#define PI_BI_FILL_GRADIENT						0x00000020
#define PI_BI_FILL_RASTEROP_xxx					0x000f0000
	#define PI_BI_FILL_RASTEROP_OR  			0x00010000
	#define PI_BI_FILL_RASTEROP_AND 			0x00020000
	#define PI_BI_FILL_RASTEROP_XOR 			0x00030000
	#define PI_BI_FILL_RASTEROP_ADD 			0x00040000
	#define PI_BI_FILL_RASTEROP_SUB 			0x00050000
	#define PI_BI_FILL_RASTEROP_DEC 			0x00060000
	#define PI_BI_FILL_RASTEROP_MUL 			0x00070000
	#define PI_BI_FILL_RASTEROP_OUT 			0x00080000
	#define PI_BI_FILL_RASTEROP_OVER			0x00090000
	#define PI_BI_FILL_RASTEROP_HUE 			0x000a0000
	#define PI_BI_FILL_RASTEROP_CLR 			0x000b0000
	#define PI_BI_FILL_RASTEROP_LUM 			0x000c0000
	#define PI_BI_FILL_RASTEROP_SCRN			0x000d0000
	#define PI_BI_FILL_RASTEROP_MASK			0x000e0000
	#define PI_BI_FILL_RASTEROP_TEX 			0x000f0000

//macro for inter-converting pixels between ARGB and ABGR
#define my_swap_rgb(c) \
	((c&0xff00ff00)|((c>>16)&0xff)|((c<<16)&0xff0000))

//-------------------------------------------------------------
//pi_StateStore
//-------------------------------------------------------------

#define PI_STATESTORE_VERSION					0x00010001

struct pi_STATESTORE
{
	unsigned long	version;
	int (__cdecl*	read )(wchar_t* name,void* data,int size);
	int (__cdecl*	write)(wchar_t* name,void* data,int size);
	int (__cdecl*	size )(wchar_t* name);
//16
	unsigned char	reserved_x[64-16];//do not touch
};


//-------------------------------------------------------------
//pi_BasicColor
//-------------------------------------------------------------

#define PI_BASICCOLOR_VERSION					0x00010001

struct pi_BASICCOLOR
{
	unsigned long	version;
	int	(__cdecl*	convert)(unsigned long *colors,
		int count,int cp_in,int cp_out,unsigned long flags);
	unsigned long	reserved_1;//do not touch
	unsigned long	reserved_2;//do not touch
//16
	unsigned char	reserved_x[64-16];//do not touch
};

//flags for "cp_in" and "cp_out" in ::convert()
#define PI_BC_COLORSPACE_RGB					0x00000000
#define PI_BC_COLORSPACE_BGR					0x00000001
#define PI_BC_COLORSPACE_YUV					0x00000002
#define PI_BC_COLORSPACE_CMY					0x00000003
#define PI_BC_COLORSPACE_CMYK					0x00000004
#define PI_BC_COLORSPACE_HSL					0x00000005
#define PI_BC_COLORSPACE_HSV					0x00000006

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////



/**************************************************************
FastExternals Structs
**************************************************************/

struct plg_INFO
{
	unsigned long	api_type;			//interfaces
	unsigned long	api_version;		//interface version
	unsigned long	plugin_version;		//version of plugin
	unsigned long	plugin_options;		//unused
//16
	wchar_t			plugin_name[64];	//display name
//144
	unsigned char	reserved_1[1024-144];//do not touch
};

//-------------------------------------------------------------

struct flt_IMAGE_L
{
	unsigned long	width;
	unsigned long	height;
	unsigned long	pitch;
	unsigned long*	lp_pix;
//16
	wchar_t*		file;
	HWND			hwnd;
	int				(__cdecl* create)(flt_IMAGE_L* self);
	unsigned long	flags;
//32
	unsigned long	layer_count;//usually ignored
	unsigned short	options;	//layer options
	unsigned short	unused_1;	//unused
	short			x_pos;		//x position relative to back
	short			y_pos;		//y position relative to back
	wchar_t			name[32];	//display name
	unsigned short	frame_delay;//animation frame delay
	unsigned short	sub_carrier;//unused
//112
	unsigned char*	meta_data;	//metadata
	int				(__cdecl* meta_write)
						(flt_IMAGE_L* self,char* type,int size);
//120
	unsigned long	timeout;	//operation timeout
	unsigned long	unused_2;	//unused
//128
	unsigned char	reserved_1[256-128];	//do not touch
//256
	pi_BASICIMAGE*	pi_BasicImage;//interface::BasicImage
	pi_STATESTORE*	pi_StateStore;//interface::StateStore
	pi_BASICCOLOR*	pi_BasicColor;//interface::BasicColor
//268
	unsigned char	reserved_x[1024-268];//do not touch
};

//-------------------------------------------------------------

struct flt_IMAGE_S
{
	unsigned long	width;
	unsigned long	height;
	unsigned long	pitch;
	unsigned long*	lp_pix;
//16
	wchar_t*		file;
	HWND			hwnd;
	int				(__cdecl* next)(flt_IMAGE_S* self);
	unsigned long	flags;
//32
	unsigned long	layer_count;//number of layers in image
	unsigned short	options;	//layer options
	unsigned short	unused_1;	//unused
	short			x_pos;		//x position relative to back
	short			y_pos;		//y position relative to back
	wchar_t			name[32];	//display name
	unsigned short	frame_delay;//animation frame delay
	unsigned short	sub_carrier;//unused
//112
	unsigned char*	meta_data;	//metadata
	int				(__cdecl* meta_read)
						(flt_IMAGE_S* self,char* type);
//120
	unsigned char	reserved_1[256-120];	//do not touch
//256
	pi_BASICIMAGE*	pi_BasicImage;//interface::BasicImage
	pi_STATESTORE*	pi_StateStore;//interface::StateStore
	pi_BASICCOLOR*	pi_BasicColor;//interface::BasicColor
//268
	unsigned char	reserved_x[1024-268];//do not touch
};

//-------------------------------------------------------------

struct flt_IMAGE_X
{
	wchar_t*		file;
	HWND			hwnd;
	unsigned long	xform_id;
	unsigned long	xform_id2;
//16
	unsigned char	reserved_1[256-16];	//do not touch
//256
	pi_BASICIMAGE*	pi_BasicImage;//interface::BasicImage
	pi_STATESTORE*	pi_StateStore;//interface::StateStore
	pi_BASICCOLOR*	pi_BasicColor;//interface::BasicColor
//268
	unsigned char	reserved_2[1024-268];//do not touch
};

//-------------------------------------------------------------

struct efx_IMAGE_T
{
	unsigned long	width;
	unsigned long	height;
	unsigned long	pitch;
	unsigned long*	lp_pix;
//16
	HWND			hwnd;
	int				(__cdecl* load   )(void);//load original
	int				(__cdecl* lock   )(void);//lock surface
	int				(__cdecl* unlock )(void);//unlock surface
//32
	unsigned long	flags;
	int				(__cdecl* realloc)(void);//resize buffer
	int				(__cdecl* refresh)(void);//refresh display
	int				(__cdecl* progress)(int done,int total);//progress
//48
	unsigned long	color_1;
	unsigned long	color_2;
	unsigned long	unused_1;
	unsigned long	unused_2;
//64
	unsigned char*	(__cdecl* mem_alloc)(unsigned long size);
	unsigned char*	(__cdecl* mem_resize)(unsigned char* mem,
						unsigned long size);
	int				(__cdecl* mem_free)(unsigned char* mem);
	unsigned long	unused_3;
//80
	unsigned char*	meta_data;
	unsigned long	(__cdecl* meta_query)
						(char* type,unsigned long size);
//88
	unsigned char	reserved_1[256-88];	//do not touch
//256
	pi_BASICIMAGE*	pi_BasicImage;//interface::BasicImage
	pi_STATESTORE*	pi_StateStore;//interface::StateStore
	pi_BASICCOLOR*	pi_BasicColor;//interface::BasicColor
//268
	unsigned char	reserved_2[1024-268];//do not touch
};

//-------------------------------------------------------------

struct dev_IMAGE_R
{
	unsigned long	width;
	unsigned long	height;
	unsigned long	pitch;
	unsigned long*	lp_pix;
//16
	HWND			hwnd;
	int				(__cdecl* create)(dev_IMAGE_R* self);//allocate buffer
	unsigned long	flags;
	unsigned long	unused_1;	//unused for now
//32
	unsigned long	frame_count;//number of frames
	unsigned short	options;	//layer options
	unsigned short	unused_2;	//unused for now
	short			x_pos;		//x position relative to back
	short			y_pos;		//y position relative to back
	wchar_t			name[32];	//display name
	unsigned short	frame_delay;//animation frame delay
	unsigned short	sub_carrier;//unused
//112
	unsigned char*	meta_data;	//metadata
	int				(__cdecl* meta_write)
						(dev_IMAGE_R* self,char* type,int size);
//120
	unsigned char	reserved_1[256-120];	//do not touch
//256
	pi_BASICIMAGE*	pi_BasicImage;//interface::BasicImage
	pi_STATESTORE*	pi_StateStore;//interface::StateStore
	pi_BASICCOLOR*	pi_BasicColor;//interface::BasicColor
//268
	unsigned char	reserved_x[1024-268];//do not touch
};

//-------------------------------------------------------------

struct dev_IMAGE_S
{
	unsigned long	width;
	unsigned long	height;
	unsigned long	pitch;
	unsigned long*	lp_pix;
//16
	HWND			hwnd;
	int				(__cdecl* next )(dev_IMAGE_S* self);
	unsigned long	flags;
	unsigned long	unused_1;	//unused for now
//32
	unsigned long	frame_count;//number of frames
	unsigned short	options;	//layer options
	unsigned short	unused_2;	//unused for now
	short			x_pos;		//x position relative to back
	short			y_pos;		//y position relative to back
	wchar_t			name[32];	//display name
	unsigned short	frame_delay;//animation frame delay
	unsigned short	sub_carrier;//unused
//112
	unsigned char*	meta_data;	//metadata
	int				(__cdecl* meta_read)
						(dev_IMAGE_S* self,char* type);
//120
	unsigned char	reserved_1[256-120];	//do not touch
//256
	pi_BASICIMAGE*	pi_BasicImage;//interface::BasicImage
	pi_STATESTORE*	pi_StateStore;//interface::StateStore
	pi_BASICCOLOR*	pi_BasicColor;//interface::BasicColor
//268
	unsigned char	reserved_x[1024-268];//do not touch
};

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////



/**************************************************************
FastExternals Function Prototypes
**************************************************************/

//support functions
typedef int (__cdecl* FUNC_FLT_CREATE)(void*);

//-------------------------------------------------------------
//all plugins
typedef int (__cdecl* FUNC_PLG_ABOUT)(HWND);
typedef int (__cdecl* FUNC_PLG_CONFIG)(HWND);
typedef int (__cdecl* FUNC_PLG_HELP)(HWND);
typedef int (__cdecl* FUNC_PLG_INFO)(struct plg_INFO*);

//-------------------------------------------------------------
//new filter layer (FastExternals)
typedef int (__cdecl* FUNC_FLT_LOADIMAGE)(struct flt_IMAGE_L*);
typedef int (__cdecl* FUNC_FLT_SAVEIMAGE)(struct flt_IMAGE_S*);
typedef int (__cdecl* FUNC_FLT_SAVEEXTOK)(wchar_t*);
typedef int (__cdecl* FUNC_FLT_XFRMIMAGE)(struct flt_IMAGE_X*);

//-------------------------------------------------------------
//new device layer (FastExternals)
typedef int (__cdecl* FUNC_DEV_READIMAGE)(struct dev_IMAGE_R*);
typedef int (__cdecl* FUNC_DEV_SENDIMAGE)(struct dev_IMAGE_S*);

//-------------------------------------------------------------
//new effects layer (FastExternals)
typedef int (__cdecl* FUNC_EFX_DO_EFFECT)(struct efx_IMAGE_T*);

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////



/**************************************************************
Host Internals
**************************************************************/
pi_BASICIMAGE* plugin_GetPI_BasicImage(void);
pi_STATESTORE* plugin_GetPI_StateStore(void);
pi_BASICCOLOR* plugin_GetPI_BasicColor(void);

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
