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

Copyright © John Paul Chacha. All Rights Reserved.

This source code file, which has been provided by 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
***************************************************************************************************/
#pragma once

//--------------------------------------------------------------------------------------------------
#include "../common/imagedefs.h"
#include "../common/layerdefs.h"
#include "../common/metadefs.h"


//==================================================================================================



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

                                          GLOBAL DEFINES

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



//==================================================================================================

#define PLUGIN_INTERFACE_NAME					L"FastExternals™"
#define PLUGIN_INTERFACE_VERSION				((3<<16)+43) // 04-Jan-2022
#define PLUGIN_INTERFACE_VERSION$				L"3 rev 43"
#define PLUGIN_INTERFACE_MIN_VER				((3<<16)+43) // 04-Jan-2022

#define PLUGIN_APITYPE_INVALID					0x00000000
#define PLUGIN_APITYPE_FILE						0x00000001
#define PLUGIN_APITYPE_DEVICE					0x00000002
#define PLUGIN_APITYPE_EFFECT					0x00000004
#define PLUGIN_APITYPE_ENGINE					0x00000100

#define PLUGIN_IMGTYPE_COMPOSITE				0x0000
#define PLUGIN_IMGTYPE_IMAGELIST				0x0001
#define PLUGIN_IMGTYPE_FRAMEANIM				0x0002
#define PLUGIN_IMGTYPE_OBJECTANIM				0x0003

#define PLUGIN_IMGSUBTYPE_NORMAL				0x0000
#define PLUGIN_IMGSUBTYPE_CLIPPED				0x0001
#define PLUGIN_IMGSUBTYPE_MULTIRES				0x0001
#define PLUGIN_IMGSUBTYPE_ONIONSKIN				0x0001

#define PLUGIN_HOSTFLAG_RESIZE					0x0001 //host may return resized image if necessary
#define PLUGIN_HOSTFLAG_NO_SAVE					0x0002 //ask host to treat file format as read-only
#define PLUGIN_HOSTFLAG_MORE_TIME				0x0004 //ask host to defer time-out (e.g. plug-in was showing UI)
#define PLUGIN_HOSTFLAG_WANT_THUMB				0x0100 //plug-in may return a thumbnail
#define PLUGIN_HOSTFLAG_SKIP_META				0x0200 //plug-in may omit metadata
#define PLUGIN_HOSTFLAG_SKIP_ANIM				0x0400 //plug-in may omit animation

#define PLUGIN_WARN_LAYER_COUNT					0x0001 //layers exceed allowed maximum
#define PLUGIN_WARN_LAYER_TYPE					0x0002 //bad or unknown layer type found
#define PLUGIN_WARN_BLEND_MODE					0x0004 //bad or unknown blend mode found
#define PLUGIN_WARN_IMAGE_DATA					0x0008 //bad or unknown image data found
#define PLUGIN_WARN_ALPHA_DROP					0x0010 //transparency info removed
#define PLUGIN_WARN_THUMB_ONLY					0x0020 //thumbnail only, no other data
#define PLUGIN_WARN_NONSTANDARD					0x0080 //non-standard extension/feature used
#define PLUGIN_WARN_TIMEOUT						0x0100 //the operation timed out

//--------------------------------------------------------------------------------------------------
#define PLUGIN_MAX_SURF_WIDTH					(64*1024)
#define PLUGIN_MAX_LAYER_COUNT					1024

//--------------------------------------------------------------------------------------------------
#define PLUGIN_OKAY								  1 //success

#define PLUGIN_ERR_FAILED						  0 //general failure

#define PLUGIN_ERR_NO_SUPPORT					 -1 //not supported
#define PLUGIN_ERR_NO_FEATURE					 -2 //feature not implemented
#define PLUGIN_ERR_NO_IMAGE						 -3 //file doesn't contain image
#define PLUGIN_ERR_NO_COMPONENT					 -4 //external component not found
#define PLUGIN_ERR_COMPONENT_FAIL				 -5 //failure in external component
#define PLUGIN_ERR_SYS_REQ						 -6 //system requirements
#define PLUGIN_ERR_DEVICE						 -7 //I/O device error

#define PLUGIN_ERR_BAD_HOST						-10 //host service not found
#define PLUGIN_ERR_BAD_PARAM					-11 //host parameter invalid
#define PLUGIN_ERR_BAD_IMAGE					-12 //invalid image
#define PLUGIN_ERR_BAD_WIDTH					-13 //unsupported image size
#define PLUGIN_ERR_BAD_MODE						-14 //unsupported image mode
#define PLUGIN_ERR_NOT_FLAT						-15 //image not flat (has layers)

#define PLUGIN_ERR_OUT_OF_MEM					-20 //out of memory
#define PLUGIN_ERR_BITMAP_ERR					-25 //bitmap error, unknown
#define PLUGIN_ERR_BITMAP_NUL					-26 //bitmap error, empty
#define PLUGIN_ERR_BITMAP_BIG					-27 //bitmap error, too big

#define PLUGIN_ERR_INTERNAL_U 					-30 //internal error, unspecified
#define PLUGIN_ERR_INTERNAL_1 					-31 //internal error, type #1
#define PLUGIN_ERR_INTERNAL_2 					-32 //internal error, type #2
#define PLUGIN_ERR_INTERNAL_3 					-33 //internal error, type #3
#define PLUGIN_ERR_INTERNAL_4 					-34 //internal error, type #4

#define PLUGIN_ERR_FILE_OPEN_R					-40 //cannot open for read
#define PLUGIN_ERR_FILE_OPEN_W					-41 //cannot open for write
#define PLUGIN_ERR_FILE_READ					-42 //error reading data
#define PLUGIN_ERR_FILE_WRITE					-43 //error writing data
#define PLUGIN_ERR_FILE_CORRUPT					-44 //invalid data in file

#define PLUGIN_ERR_TIMEOUT						-98 //cancelled by timeout
#define PLUGIN_ERR_USER_CANCEL					-99 //cancelled by the user

//--------------------------------------------------------------------------------------------------
#define PLG_DIALOG_ABOUT						0x00000000
#define PLG_DIALOG_CONFIG						0x00000001
#define PLG_DIALOG_HELP 						0x00000002

//--------------------------------------------------------------------------------------------------
#define PLG_FLT_XFORM_ROTATE_090				0x00000001
#define PLG_FLT_XFORM_ROTATE_180				0x00000002
#define PLG_FLT_XFORM_ROTATE_270				0x00000003
#define PLG_FLT_XFORM_FLIP_H					0x00000004
#define PLG_FLT_XFORM_FLIP_V					0x00000005
#define PLG_FLT_XFORM_TRANSPOSE					0x00000006
#define PLG_FLT_XFORM_TRANSVERSE				0x00000007

#define PLG_EFX_FLAGS_HIDE_GUI					0x00000001


//==================================================================================================



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

                                          HELPER MACROS

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



//==================================================================================================

//--------------------------------------------------------------------------------------------------
//Macro for converting pixels between ARGB and ABGR
#define plg_swap_rgb(c)				((c&0xff00ff00)|((c>>16)&0x000000ff)|((c<<16)&0x00ff0000))

//--------------------------------------------------------------------------------------------------
//Macro for restricting a value to a given set of limits
#define plg_limit_value(a,lo,hi)	{ if((a)<(lo)){a=(lo);} else if((a)>(hi)){a=(hi);} }

//--------------------------------------------------------------------------------------------------
//Macro for checking a value against a given set of limits
#define plg_not_in_range(a,lo,hi)	((a<(lo))||(a>(hi)))


//==================================================================================================



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

                         CALLBACK SUITE STRUCTS FOR "BASIC PI" INTERFACES 

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



//==================================================================================================
	
//--------------------------------------------------------------------------------------------------
//pi_StateStore
//--------------------------------------------------------------------------------------------------
#define PI_STATESTORE_VERSION					0x00020002 // 04 Jan 2022

#ifndef __cplusplus
	typedef	struct pi_STATESTORE				pi_STATESTORE;
#endif

#pragma pack(push)
#pragma pack(1)
	struct pi_STATESTORE
	{
		unsigned long	version;
		unsigned long	unused_1;
		int (__cdecl*	temp_read )(const wchar_t* name,void* data,int size);
		int (__cdecl*	temp_write)(const wchar_t* name,void* data,int size);
		int (__cdecl*	temp_size )(const wchar_t* name);
		int (__cdecl*	perm_read )(const wchar_t* name,void* data,int size);
		int (__cdecl*	perm_write)(const wchar_t* name,void* data,int size);
		int (__cdecl*	perm_size )(const wchar_t* name);
	//32
		unsigned char	reserved_x[1024-32]; //do not touch
	};
#pragma pack(pop)



//--------------------------------------------------------------------------------------------------
//pi_BasicQuery
//--------------------------------------------------------------------------------------------------
#define PI_BASICQUERY_VERSION					0x00010003 // 04 Jan 2022

#ifndef __cplusplus
	typedef	struct pi_BASICQUERY				pi_BASICQUERY;
#endif

#pragma pack(push)
#pragma pack(1)
	struct pi_BASICQUERY
	{
		unsigned long	version;
		unsigned long	unused_1;
		void* (__cdecl* get_PI  )(const wchar_t* name);
		int   (__cdecl* get_data)(const wchar_t* name,void* data,int size);
		int   (__cdecl* set_data)(const wchar_t* name,void* data,int size);
	//20
		unsigned char reserved_x[1024-20]; //do not touch
	};
#pragma pack(pop)



//--------------------------------------------------------------------------------------------------
//pi_BasicImage
//--------------------------------------------------------------------------------------------------
#define PI_BASICIMAGE_VERSION					0x00010012 // 04 Jan 2022

#ifndef __cplusplus
	typedef	struct pibi_IMAGE					pibi_IMAGE;
	typedef	struct pibi_RECT					pibi_RECT;
	typedef	struct pibi_FILEINFO				pibi_FILEINFO;
	typedef	struct pi_BASICIMAGE				pi_BASICIMAGE;
#endif

#pragma pack(push)
#pragma pack(1)
	struct pibi_IMAGE
	{
		unsigned long	width;
		unsigned long	height;
		unsigned long	pitch;
		unsigned long	unused;
		unsigned long	*p_pix;
		void			*reserved;
	};
	struct pibi_RECT
	{
		long	x0;
		long	y0;
		long	x1;
		long	y1;
		bool	valid;
	};
	struct pibi_FILEINFO
	{
		HWND			hwnd;
		const wchar_t*	file;
		void*			memfile_data;
		unsigned long	memfile_size;
		wchar_t*		memfile_type_hint;
		bool			get_metadata;
		void*			metadata_ptr;
		unsigned long	metadata_size;
		bool			is_known;
		bool			bad_host;
	};
#pragma pack(pop)

#pragma pack(push)
#pragma pack(1)
	struct pi_BASICIMAGE
	{
		unsigned long	version;
		unsigned long	unused_1;
	//8
		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);
		int (__cdecl*	resize)(pibi_IMAGE* img,int width,int height);
	//24
		int (__cdecl*	lock)(pibi_IMAGE* img);
		int (__cdecl*	unlock)(pibi_IMAGE* img);
	//32
		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; //do not touch
	//48
		int (__cdecl*	load_file)(pibi_IMAGE* img,pibi_FILEINFO* info);
		int (__cdecl*	save_file)(pibi_IMAGE* img,pibi_FILEINFO* info);
		void*			reserved_2; //do not touch
		void*			reserved_3; //do not touch
	//64
		int (__cdecl*	flip)(pibi_IMAGE* img,int vertical);
		int (__cdecl*	rotate)(pibi_IMAGE* img,int direction);
		void*			reserved_4; //do not touch
		void*			reserved_5; //do not touch
	//80
		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*	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 rop_param);
		int (__cdecl*	quad_blit)(
							pibi_IMAGE* dst,int x0,int y0,int x1,int y1,int x2,int y2,int x3,int y3,
							pibi_IMAGE* src,int sx0,int sy0,int sx1,int sy1,
							unsigned long options,unsigned long rop_param);
		int (__cdecl*	blit_DC)(
							HDC hdc,int dx0,int dy0,int dx1,int dy1,
							pibi_IMAGE* src,int sx0,int sy0,int sx1,int sy1,
							unsigned long options);
	//96
		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*	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* i_new,pibi_IMAGE* i_org,pibi_RECT *rt_diff);
		void*			reserved_6; //do not touch
	//112
		int (__cdecl*	polar)(
							pibi_IMAGE* dst,int x0,int y0,int x1,int y1,
							pibi_IMAGE* src,int center_x,int center_y,unsigned long options);
		void*			reserved_7; //do not touch
		void*			reserved_8; //do not touch
		void*			reserved_9; //do not touch
	//128
		unsigned char	reserved_x[1024-128];//do not touch
	};
#pragma pack(pop)

//flags for the "options" parameter of ::blit()
#define PI_BI_BLIT_BLOCKY						0x00000000
#define PI_BI_BLIT_STRETCH						0x00000001
#define PI_BI_BLIT_MAXQUALITY					0x00000002
#define PI_BI_BLIT_ALPHABLEND					0x00000010
#define PI_BI_BLIT_RASTEROP  					0x00000020
#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()
//also used for "rop_param" for ::blit()+PI_BI_BLIT_RASTEROP
#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					0x00ff0000
	#define PI_BI_FILL_RASTEROP_NONE            0x00000000
	#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_INC             0x00060000
	#define PI_BI_FILL_RASTEROP_DEC             0x00070000
	#define PI_BI_FILL_RASTEROP_MUL             0x00080000
	#define PI_BI_FILL_RASTEROP_DIV             0x00090000
	#define PI_BI_FILL_RASTEROP_OFF             0x000a0000
	#define PI_BI_FILL_RASTEROP_MIN             0x000b0000
	#define PI_BI_FILL_RASTEROP_MAX             0x000c0000
	#define PI_BI_FILL_RASTEROP_DIFF            0x000d0000
	#define PI_BI_FILL_RASTEROP_OUT             0x000e0000
	#define PI_BI_FILL_RASTEROP_TEX1            0x000f0000
	#define PI_BI_FILL_RASTEROP_TEX2            0x00100000
	#define PI_BI_FILL_RASTEROP_SCRN            0x00110000
	#define PI_BI_FILL_RASTEROP_OVER            0x00120000
	#define PI_BI_FILL_RASTEROP_DODG            0x00130000
	#define PI_BI_FILL_RASTEROP_BURN            0x00140000
	#define PI_BI_FILL_RASTEROP_LUM             0x00150000
	#define PI_BI_FILL_RASTEROP_CLR             0x00160000
	#define PI_BI_FILL_RASTEROP_HUE             0x00170000
	#define PI_BI_FILL_RASTEROP_SAT             0x00180000
	#define PI_BI_FILL_RASTEROP_VAL             0x00190000
	#define PI_BI_FILL_RASTEROP_LIT             0x001a0000
	#define PI_BI_FILL_RASTEROP_MASK            0x007d0000

//flags for the "options" parameter of ::polar()
#define PI_BI_POLAR_XY_TO_RQ					0x00000000
#define PI_BI_POLAR_RQ_TO_XY					0x00000001
#define PI_BI_POLAR_INVERT_RQ					0x00000002
#define PI_BI_POLAR_ACCURATE					0x00004000



//--------------------------------------------------------------------------------------------------
//pi_BasicColor
//--------------------------------------------------------------------------------------------------
#define PI_BASICCOLOR_VERSION					0x00010005 //30 Sep 2021

#ifndef __cplusplus
	typedef	struct pi_BASICCOLOR				pi_BASICCOLOR;
#endif

#pragma pack(push)
#pragma pack(1)
	struct pi_BASICCOLOR
	{
		unsigned long	version;
		unsigned long	unused_1;
	//8
		int	(__cdecl*	convert)(unsigned long *p_pix,int count,
			unsigned long cp_in,unsigned long cp_out);
		int	(__cdecl*	read_rgb)(unsigned long* p_pix,unsigned char* p_rgb,
			int count,int bpp,unsigned long flags);
		int	(__cdecl*	transform)(unsigned long* p_pix,float* matrix_5x4);
	//20
		unsigned char	reserved_x[1024-20]; //do not touch
	};
#pragma pack(pop)

//flags for "cp_in" and "cp_out" in ::convert()
#define PI_BC_CONVERT_CS_RGB					0x00000000
#define PI_BC_CONVERT_CS_YUV					0x00000001
#define PI_BC_CONVERT_CS_CMY					0x00000002
#define PI_BC_CONVERT_CS_CMYK					0x00000003
#define PI_BC_CONVERT_CS_HSL					0x00000004
#define PI_BC_CONVERT_CS_HSV					0x00000005
#define PI_BC_CONVERT_CS_HHSL					0x00000006
#define PI_BC_CONVERT_CS_HHSV					0x00000007
#define PI_BC_CONVERT_CS_LAB					0x00000008
#define PI_BC_CONVERT_CS_XYZ					0x00000009
#define PI_BC_CONVERT_CS_xxxx					0x0000000f
#define PI_BC_CONVERT_OPT_INVT					0x00001000
#define PI_BC_CONVERT_OPT_xxxx					0x0000f000

//flags for "flags" in ::read_rgb()
#define PI_BC_READRGB_LSB_IS_RED				0x00000001
#define PI_BC_READRGB_ALPHA_KEEP				0x00000000
#define PI_BC_READRGB_ALPHA_DROP				0x00000010
#define PI_BC_READRGB_ALPHA_INVERT				0x00000020
#define PI_BC_READRGB_ALPHA_PREMUL				0x00000030
#define PI_BC_READRGB_ALPHA_UNMULT				0x00000040
#define PI_BC_READRGB_ALPHA_xxxx				0x000000f0



//--------------------------------------------------------------------------------------------------
//pi_MetaMarkup
//--------------------------------------------------------------------------------------------------
#define PI_METAMARKUP_VERSION					0x00010003

#ifndef __cplusplus
	typedef	struct pimm_MARK					pimm_MARK;
	typedef	struct pi_METAMARKUP				pi_METAMARKUP;
#endif

#pragma pack(push)
#pragma pack(1)
	struct pimm_MARK
	{
		char*			data;
		unsigned long	size;
		char*			raw_data;
		unsigned long	raw_size;
	};
	struct pi_METAMARKUP
	{
		unsigned long	version;
		unsigned long	unused_1;
	//8
		int (__cdecl*	create )(pimm_MARK* mark);
		int (__cdecl*	import )(pimm_MARK* mark,void* data,int size);
		int (__cdecl*	destroy)(pimm_MARK* mark);
		int (__cdecl*	append )(pimm_MARK* mark,char* fragment);
		int (__cdecl*	get_tag)(pimm_MARK* mark,char* tag,char* value,int size);
		int (__cdecl*	set_tag)(pimm_MARK* mark,char* tag,char* value);
		int (__cdecl*	bpp_get)(pimm_MARK* mark,int* bpp);
		int (__cdecl*	bpp_set)(pimm_MARK* mark,int bpp);
		int (__cdecl*	exif_get)(pimm_MARK* mark,void** exif,int* sz_exif);
		int (__cdecl*	exif_set)(pimm_MARK* mark,void* exif,int sz_ex);
		int (__cdecl*	exif_loadXMP)(pimm_MARK* mark,char* xmp_str);
	//52
		unsigned char	reserved_x[1024-52]; //do not touch
	};
#pragma pack(pop)



//--------------------------------------------------------------------------------------------------
//pi_BasicUtils
//--------------------------------------------------------------------------------------------------
#define PI_BASICUTILS_VERSION					0x00010002 // 04 Jan 2022

#ifndef __cplusplus
	typedef	struct pi_BASICUTILS				pi_BASICUTILS;
#endif

#pragma pack(push)
#pragma pack(1)
	struct pi_BASICUTILS
	{
		unsigned long	version;
		unsigned long	unused_1;
	//8
		int (__cdecl*	lang_TranslateCore)(wchar_t* out,int size,const wchar_t* in);
		int (__cdecl*	lang_SetWindowText)(HWND hwnd,const wchar_t* str);
		int (__cdecl*	lang_TranslateWindow)(HWND hwnd);
	//20
		unsigned char	reserved_x[1024-20]; //do not touch
	};
#pragma pack(pop)



//--------------------------------------------------------------------------------------------------
//pi_BasicVideo
//--------------------------------------------------------------------------------------------------
#define PI_BASICVIDEO_VERSION					0x00010001 // 04 Jan 2022

#ifndef __cplusplus
	typedef	struct pibv_IMAGE					pibv_IMAGE;
	typedef	struct pi_BASICVIDEO				pi_BASICVIDEO;
#endif

#pragma pack(push)
#pragma pack(1)
	struct pibv_IMAGE
	{
		unsigned long	width;
		unsigned long	height;
		unsigned long	pitch;
		unsigned long*	lp_pix;
	};
	struct pi_BASICVIDEO
	{
		unsigned long	version;
		unsigned long	unused_1;
	//8
		void* (__cdecl*	load)(const wchar_t* path,int timeout_ms,int* error_code);
		int (__cdecl*	free)(void* context);
		int (__cdecl*	grab)(void* context,int frame_id,unsigned long flags,pibv_IMAGE* image);
		int (__cdecl*	keepalive)(void* context);
		int (__cdecl*	set_timeout)(void* context,int time_ms);
		int (__cdecl*	get_length)(void* context,int* time_ms);
		int (__cdecl*	get_frame_count)(void* context,int* count);
		int (__cdecl*	get_frame_rate)(void* context,double* rate);
	//40
		unsigned char	reserved_x[1024-40]; //do not touch
	};
#pragma pack(pop)

#define PI_BV_GRAB_PREVIEW						0x00000000
#define PI_BV_GRAB_ACCURATE_TIME				0x00000001



//==================================================================================================



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

                                 FastExternals(TM) CORE STRUCTS

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



//==================================================================================================

//--------------------------------------------------------------------------------------------------
//plg_INFO
//--------------------------------------------------------------------------------------------------
#ifndef __cplusplus
	typedef	struct plg_INFO						plg_INFO;
#endif

#pragma pack(push)
#pragma pack(1)
	struct plg_INFO
	{
		unsigned long	api_type;		// PLUGIN_APITYPE_* flags
		unsigned long	api_version;	// PLUGIN_INTERFACE_VERSION
		unsigned long	api_flags;		// do not touch
		unsigned long	api_extra;		// do not touch
	//16
		unsigned long	plg_version;	// plug-in's version number
		unsigned long	plg_options;	// plug-in's options
		unsigned long	plg_flags;		// do not touch
		unsigned long	plg_extra;		// do not touch
	//32
		wchar_t			plg_name[64];	// plug-in's name
		wchar_t			plg_author[64];	// plug-in's author 
	//288
		unsigned char	reserved_x[1024-288]; // do not touch
	};
#pragma pack(pop)



//--------------------------------------------------------------------------------------------------
//plg_DIALOG
//--------------------------------------------------------------------------------------------------
#ifndef __cplusplus
	typedef	struct plg_DIALOG					plg_DIALOG;
#endif

#pragma pack(push)
#pragma pack(1)
	struct plg_DIALOG
	{
		HWND			hwnd;
		unsigned long	dialog_id;
		unsigned long	param_1;
		unsigned long	param_2;
	//16
		unsigned char	reserved_1[256-16]; //do not touch
	//256
		pi_STATESTORE*	pi_StateStore;
		pi_METAMARKUP*	pi_MetaMarkup;
		pi_BASICQUERY*	pi_BasicQuery;
		pi_BASICIMAGE*	pi_BasicImage;
		pi_BASICCOLOR*	pi_BasicColor;
		pi_BASICUTILS*	pi_BasicUtils;
	//280
		unsigned char	reserved_x[1024-280]; //do not touch
	};
#pragma pack(pop)



//--------------------------------------------------------------------------------------------------
//flt_IMAGE_L
//--------------------------------------------------------------------------------------------------
#ifndef __cplusplus
	typedef	struct flt_IMAGE_L					flt_IMAGE_L;
#endif

#pragma pack(push)
#pragma pack(1)
	struct flt_IMAGE_L
	{
		unsigned long	width;
		unsigned long	height;
		unsigned long	pitch;
		unsigned long*	lp_pix;
	//16
		const wchar_t*	file;
		HWND			hwnd;
		int				(__cdecl* create)(flt_IMAGE_L* self);
		unsigned short	host_flags;
		unsigned char	img_type;
		unsigned char	img_subtype;
	//32
		unsigned long	layer_count;
		short			x_pos;
		short			y_pos;
		wchar_t			name[32];
		unsigned short	options;
		unsigned short	frame_delay;
		unsigned char	group_id;
		unsigned char	transparency;
		unsigned char	unused_2[18];
	//128
		unsigned char*	meta_data;
		int				(__cdecl* meta_write)(flt_IMAGE_L* self,const char* type,int size);
	//136
		unsigned char	reserved_1[256-136-(4*4)]; //do not touch
		int				host_response;
		unsigned char	reserved_2[2]; //do not touch
		unsigned short	warnings;
		int				(__cdecl* set_err_info)(flt_IMAGE_L* self,const wchar_t* info);
		unsigned long	timeout;
	//256
		pi_STATESTORE*	pi_StateStore;
		pi_METAMARKUP*	pi_MetaMarkup;
		pi_BASICQUERY*	pi_BasicQuery;
		pi_BASICIMAGE*	pi_BasicImage;
		pi_BASICCOLOR*	pi_BasicColor;
		pi_BASICUTILS*	pi_BasicUtils;
	//280
		unsigned char	reserved_x[1024-280]; //do not touch
	};
#pragma pack(pop)



//--------------------------------------------------------------------------------------------------
//flt_CHECK_L
//--------------------------------------------------------------------------------------------------
#ifndef __cplusplus
	typedef	struct flt_CHECK_L					flt_CHECK_L;
#endif

#pragma pack(push)
#pragma pack(1)
	struct flt_CHECK_L
	{
		wchar_t			extension[32];
		unsigned char	hdr_data[32];
		unsigned long	hdr_size;
		unsigned char	reserved_x[128-4-100]; //do not touch
		unsigned char	level_image;
		unsigned char	level_layer;
		unsigned char	level_other;
		unsigned char	support_flags;
	};
#pragma pack(pop)

#define SUPPORT_FLAG_IS_BRIDGE					0x00000001
#define SUPPORT_FLAG_DEMOTE_ME					0x00000002



//--------------------------------------------------------------------------------------------------
//flt_IMAGE_S
//--------------------------------------------------------------------------------------------------
#ifndef __cplusplus
	typedef	struct flt_IMAGE_S					flt_IMAGE_S;
#endif

#pragma pack(push)
#pragma pack(1)
	struct flt_IMAGE_S
	{
		unsigned long	width;
		unsigned long	height;
		unsigned long	pitch;
		unsigned long*	lp_pix;
	//16
		const wchar_t*	file;
		HWND			hwnd;
		int				(__cdecl* select)(flt_IMAGE_S* self,int layer_id);
		unsigned short	host_flags;
		unsigned char	img_type;
		unsigned char	img_subtype;
	//32
		unsigned long	layer_count;
		short			x_pos;
		short			y_pos;
		wchar_t			name[32];
		unsigned short	options;
		unsigned short	frame_delay;
		unsigned char	group_id;
		unsigned char	transparency;
		unsigned char	unused_2[18];
	//128
		unsigned char*	meta_data;
		int				(__cdecl* meta_read)(flt_IMAGE_S* self,const char* type);
	//136
		unsigned char	reserved_1[256-136-(4*4)]; //do not touch
		int				host_response;
		unsigned char	reserved_2[2]; //do not touch
		unsigned short	warnings;
		int				(__cdecl* set_err_info)(flt_IMAGE_S* self,const wchar_t* info);
		unsigned long	timeout;
	//256
		pi_STATESTORE*	pi_StateStore;
		pi_METAMARKUP*	pi_MetaMarkup;
		pi_BASICQUERY*	pi_BasicQuery;
		pi_BASICIMAGE*	pi_BasicImage;
		pi_BASICCOLOR*	pi_BasicColor;
		pi_BASICUTILS*	pi_BasicUtils;
	//280
		unsigned char	reserved_x[1024-280]; //do not touch
	};
#pragma pack(pop)



//--------------------------------------------------------------------------------------------------
//flt_CHECK_S
//--------------------------------------------------------------------------------------------------
#ifndef __cplusplus
	typedef	struct flt_CHECK_S					flt_CHECK_S;
#endif

#pragma pack(push)
#pragma pack(1)
	struct flt_CHECK_S
	{
		wchar_t			extension[32];
		unsigned char	reserved_x[128-4-64]; //do not touch
		unsigned char	level_image;
		unsigned char	level_layer;
		unsigned char	level_other;
		unsigned char	support_flags;
	};
#pragma pack(pop)



//--------------------------------------------------------------------------------------------------
//flt_IMAGE_X
//--------------------------------------------------------------------------------------------------
#ifndef __cplusplus
	typedef	struct flt_IMAGE_X					flt_IMAGE_X;
#endif

#pragma pack(push)
#pragma pack(1)
	struct flt_IMAGE_X 
	{
		const wchar_t*	file;
		HWND			hwnd;
		unsigned long	xform_id;
		unsigned long	xform_id2;
	//16
		unsigned char	reserved_1[256-16-(4*4)]; //do not touch
		int				host_response;
		unsigned char	reserved_2[2]; //do not touch
		unsigned short	warnings;
		int				(__cdecl* set_err_info)(flt_IMAGE_X* self,const wchar_t* info);
		unsigned long	timeout;
	//256
		pi_STATESTORE*	pi_StateStore;
		pi_METAMARKUP*	pi_MetaMarkup;
		pi_BASICQUERY*	pi_BasicQuery;
		pi_BASICIMAGE*	pi_BasicImage;
		pi_BASICCOLOR*	pi_BasicColor;
		pi_BASICUTILS*	pi_BasicUtils;
	//280
		unsigned char	reserved_x[1024-280]; //do not touch
	};
#pragma pack(pop)



//--------------------------------------------------------------------------------------------------
//dev_IMAGE_R
//--------------------------------------------------------------------------------------------------
#ifndef __cplusplus
	typedef	struct dev_IMAGE_R					dev_IMAGE_R;
#endif

#pragma pack(push)
#pragma pack(1)
	struct dev_IMAGE_R
	{
		unsigned long	width;
		unsigned long	height;
		unsigned long	pitch;
		unsigned long*	lp_pix;
	//16
		unsigned long	unused_1;
		HWND			hwnd;
		int				(__cdecl* create)(dev_IMAGE_R* self);
		unsigned short	host_flags;
		unsigned char	img_type;
		unsigned char	img_subtype;
	//32
		unsigned long	layer_count;
		short			x_pos;
		short			y_pos;
		wchar_t			name[32];
		unsigned short	options;
		unsigned short	frame_delay;
		unsigned char	group_id;
		unsigned char	transparency;
		unsigned char	unused_3[18];
	//128
		unsigned char*	meta_data;
		int				(__cdecl* meta_write)(dev_IMAGE_R* self,const char* type,int size);
	//136
		unsigned char	reserved_1[256-136-(4*4)]; //do not touch
		int				host_response;
		unsigned char	reserved_2[2]; //do not touch
		unsigned short	warnings;
		int				(__cdecl* set_err_info)(dev_IMAGE_R* self,const wchar_t* info);
		unsigned long	timeout;
	//256
		pi_STATESTORE*	pi_StateStore;
		pi_METAMARKUP*	pi_MetaMarkup;
		pi_BASICQUERY*	pi_BasicQuery;
		pi_BASICIMAGE*	pi_BasicImage;
		pi_BASICCOLOR*	pi_BasicColor;
		pi_BASICUTILS*	pi_BasicUtils;
	//280
		unsigned char	reserved_x[1024-280]; //do not touch
	};
#pragma pack(pop)



//--------------------------------------------------------------------------------------------------
//dev_IMAGE_S
//--------------------------------------------------------------------------------------------------
#ifndef __cplusplus
	typedef	struct dev_IMAGE_S					dev_IMAGE_S;
#endif

#pragma pack(push)
#pragma pack(1)
	struct dev_IMAGE_S
	{
		unsigned long	width;
		unsigned long	height;
		unsigned long	pitch;
		unsigned long*	lp_pix;
	//16
		unsigned long	unused_1;
		HWND			hwnd;
		int				(__cdecl* select)(dev_IMAGE_S* self,int layer_id);
		unsigned short	host_flags;
		unsigned char	img_type;
		unsigned char	img_subtype;
	//32
		unsigned long	layer_count;
		short			x_pos;
		short			y_pos;
		wchar_t			name[32];
		unsigned short	options;
		unsigned short	frame_delay;
		unsigned char	group_id;
		unsigned char	transparency;
		unsigned char	unused_3[18];
	//128
		unsigned char*	meta_data;
		int				(__cdecl* meta_read)(dev_IMAGE_S* self,const char* type);
	//136
		unsigned char	reserved_1[256-136-(4*4)]; //do not touch
		int				host_response;
		unsigned char	reserved_2[2]; //do not touch
		unsigned short	warnings;
		int				(__cdecl* set_err_info)(dev_IMAGE_S* self,const wchar_t* info);
		unsigned long	timeout;
	//256
		pi_STATESTORE*	pi_StateStore;
		pi_METAMARKUP*	pi_MetaMarkup;
		pi_BASICQUERY*	pi_BasicQuery;
		pi_BASICIMAGE*	pi_BasicImage;
		pi_BASICCOLOR*	pi_BasicColor;
		pi_BASICUTILS*	pi_BasicUtils;
	//280
		unsigned char	reserved_x[1024-280]; //do not touch
	};
#pragma pack(pop)



//--------------------------------------------------------------------------------------------------
//efx_IMAGE_T
//--------------------------------------------------------------------------------------------------
#ifndef __cplusplus
	typedef	struct efx_IMAGE_T					efx_IMAGE_T;
#endif

#pragma pack(push)
#pragma pack(1)
	struct efx_IMAGE_T
	{
		unsigned long	width;
		unsigned long	height;
		unsigned long	pitch;
		unsigned long*	lp_pix;
	//16
		HWND			hwnd;
		unsigned long	flags;
	//24
		int				(__cdecl* lock   )(void);
		int				(__cdecl* unlock )(void);
		int				(__cdecl* load   )(void);
		int				(__cdecl* realloc)(void);
		int				(__cdecl* refresh)(void);
		int				(__cdecl* progress)(int done,int total);
	//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)(const char* type,unsigned long size);
	//88
		int				(__cdecl* dock)(HWND hwnd);
		unsigned long	unused_4;
	//96
		unsigned char	reserved_1[252-96]; //do not touch
		unsigned long	unused_5;
	//256
		pi_STATESTORE*	pi_StateStore;
		pi_METAMARKUP*	pi_MetaMarkup;
		pi_BASICQUERY*	pi_BasicQuery;
		pi_BASICIMAGE*	pi_BasicImage;
		pi_BASICCOLOR*	pi_BasicColor;
		pi_BASICUTILS*	pi_BasicUtils;
	//280
		unsigned char	reserved_x[1024-280]; //do not touch
	};
#pragma pack(pop)



//==================================================================================================



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

                           FastExternals(TM) CORE FUNCTION PROTOTYPES

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



//==================================================================================================

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

//--------------------------------------------------------------------------------------------------
//functions for all plug-ins
typedef int (__cdecl* FUNC_PLG_INFO  )(struct plg_INFO*  );
typedef int (__cdecl* FUNC_PLG_DIALOG)(struct plg_DIALOG*);

//--------------------------------------------------------------------------------------------------
//functions for file format plug-ins
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_CHECKLOAD)(struct flt_CHECK_L*);
typedef int (__cdecl* FUNC_FLT_CHECKSAVE)(struct flt_CHECK_S*);
typedef int (__cdecl* FUNC_FLT_XFRMIMAGE)(struct flt_IMAGE_X*);

//--------------------------------------------------------------------------------------------------
//functions for device plug-ins
typedef int (__cdecl* FUNC_DEV_READIMAGE)(struct dev_IMAGE_R*);
typedef int (__cdecl* FUNC_DEV_SENDIMAGE)(struct dev_IMAGE_S*);

//--------------------------------------------------------------------------------------------------
//functions for effects plug-ins
typedef int (__cdecl* FUNC_EFX_DO_EFFECT)(struct efx_IMAGE_T*);

//==================================================================================================



//==================================================================================================
//==================================================================================================
