#ifndef PIPLIBH
#define PIPLIBH
/******************************************************************************
 * pip_lib.h
 * Functions and stuff needed to interface with a pip.
 * Nils L. Corneliusen, PCTVnet ASA
 ******************************************************************************/

/*****
 * The library has a set of generic commands that should work for all pips.
 * However, the pip on v1.x boxes is somewhat special:
 * - it can only have four different sizes (see below)
 * - it has only lores resolution on the y position
 * - it has a lot of other cool features :-)
 * This means that the following points should be observed when pip_exists()
 * returns PIP_TYPE_SIEMENS:
 * pip_setsize() on not supported sizes will be rounded down according to x-size (NOTE!)
 * pip_setpos() supports hires coords but odd y-coordinates will be rounded down.
 * pip_siemens_set() is added for better control of special features.
 *****/


/******************************************************************************
 * Siemens specific stuff
 ******************************************************************************/

// HUGE   = 1/4 size  (288x252)
// BIG    = 1/9 size  (192x168)
// MEDIUM = 1/16 size (144x126)
// SMALL  = 1/36 size (96x84)

// WIDE   = wide screen pip on 4:3 tv
// ONWIDE = 4:3 pip on wide screen tv

#define SDA9189_MODE_1X1_HUGE			0
#define SDA9189_MODE_1X1_BIG			1
#define SDA9189_MODE_1X1_MEDIUM			2
#define SDA9189_MODE_1X1_SMALL			3

#define SDA9189_MODE_2X2_MEDIUM			4
#define SDA9189_MODE_4X1				5
#define SDA9189_MODE_1X4				6
#define SDA9189_MODE_3X3				7
#define SDA9189_MODE_2X1				8
#define SDA9189_MODE_4X2				10
#define SDA9189_MODE_1X2				11
#define SDA9189_MODE_2X4				13
#define SDA9189_MODE_2X2_SMALL			14

#define SDA9189_MODE_1X1_BIG_ONWIDE		15
#define SDA9189_MODE_1X1_MEDIUM_WIDE	16
#define SDA9189_MODE_1X3_BIG_ONWIDE		17
#define SDA9189_MODE_1X1_HUGE_ONWIDE	18
#define SDA9189_MODE_1X1_BIG_WIDE		19

//#define BOOL int
typedef int BOOL;

// Same structure used for input and output
// Default values after reset are in the first comment field
typedef struct _sda9189
{
	// These affect the entire pip display
	BOOL pip_on;				// 0  turn pip on/off
	int  pip_xpos;				// 0  x position, hires pixels
	int  pip_ypos;				// 0  y position, lores pixels
	int  pip_mode;				// 0  see above
	BOOL pip_wipe_on;			// 0  use wipe when pip_on is toggled?
	int  pip_wipe_speed;		// 0  how fast? (0 = 1/3sec -> 3 = 4/3sec)
	int  pip_target;			// 0  which pip to update, 0 if 1x1
	int  pip_intensity;			// 0  adjust intensity (0-15)
	int  pip_fillmode;			// 0  0 = view pip as normal, 1 = fill all pips with frame color

	// These affect the current pip in multipip mode
	// and the entire pip in single pip mode
	BOOL cpip_frozen;			// 0  freeze current pip
	BOOL cpip_fillmode;			// 0  0 = view pip picture, 1 = view bkgd_y color
	
	// These affect the background (the HomePilot display)
	BOOL bkgd_on;				// 0  if on, fill according to bkgd_fillmode
	BOOL bkgd_fillmode;			// 0  0 = fill with background color, 1 = fill with frame color
	BOOL bkgd_y;				// 0  0-3
	BOOL bkgd_u;				// 0  0-3
	BOOL bkgd_v;				// 0  0-3

	// These affect the surrounding frame and/or fill
	int frame_horiz;			// 3  horizontal frame size (0-7)
	int frame_vert;				// 1  vertical frame size (0-3)
	int frame_y;				// 1  frame luminance color (0-15)
	int frame_u;				// 0  frame u color (0-15)
	int frame_v;				// 0  frame v color (0-15)

	// These affect the inner frame in multipip mode
	BOOL iframe_on;				// 0  insert inner frame spacing?

} sda9189;


/******************************************************************************
 * Types, as returned by pip_exists()
 ******************************************************************************/
#define PIP_TYPE_NONE      0
#define PIP_TYPE_SIEMENS   1
#define PIP_TYPE_CPRO      2

/******************************************************************************
 * Error return values
 ******************************************************************************/
#define PIP_ERROR_NO_ELANSERVER -1  // This pip requires that the elanserver is running.
#define PIP_ERROR_TOO_BIG     -501  // setsize: no buffer memory, reduce size!
#define PIP_ERROR_WRONG_TYPE  -502  // all:     action not supported on current pip
#define PIP_ERROR			  -503  // yep, that's wrong!

#ifdef __cplusplus
extern "C" {
#endif

int pip_exists( void );		// returns pip_type
int pip_reset( void );
int pip_on( void );
int pip_off( void );
int pip_setsize( int sx, int sy );
int pip_setpos( int x, int y );
int pip_siemens_set( sda9189 *buf );

#ifdef __cplusplus
};
#endif

#endif
