/*
 mid2253.h
 The OSD types from the 2253 Windows SDK
*/

#ifndef MID2253_CONST_H
#define MID2253_CONST_H

#define MID2253_API extern



#define MID2253_OVERLAY_UPDATE_DISPLAY 1
#define MID2253_OVERLAY_UPDATE_POSITION 2
#define MID2253_OVERLAY_UPDATE_TRANSPARENT 4


typedef struct {
    unsigned char id;
    unsigned char transparent;
    unsigned char update;
    unsigned char reserved;
    int xOffset;
    int yOffset;
    unsigned int length;
} MID2253_OVL_STRUCT;


typedef char* LPSTR;

typedef enum mid2253_osd_type
{
	MID2253_OSDTYPE_TEXT = 1,  // text overlay
	MID2253_OSDTYPE_BMP, // BMP file overlay
    MID2253_OSDTYPE_LONGTEXT, // large text overlay
	MID2253_OSDTYPE_STYLEDTEXT, // styled text overlay
	MID2253_OSDTYPE_RECT, // rectangle overlay
} MID2253_OSD_TYPE;

#define MID2253_MAX_OSDTEXT 80

typedef struct mid2253_osd_text
{
    int osdOn;       //OSD on if != 0, 1=8x14 font, 2=16x16 font
    int osdChan;     // osd channel to update.  osdChan=0 for stream A, osdChan=1 for stream B, osdChan=2 for output
    int transparent; //transparent OSD if !=0, 1=100%, 2=50%, 3=25%
    int positionTop; //see xoff, yoff below
    int ddmm;     //date format 0=mm-dd 1=dd-mm 2=mmm-dd, 3=dd-mmm- 4=mmm dd, 5=ddmmm, 6=dd.mm.
    int year2;    // year display mode (year2 = 1 means 2 digits, year2=0 means 4 digits)
    int fraction; // whether to display fraction of seconds
    unsigned char line[MID2253_MAX_OSDTEXT]; // ascii string of text (null terminated)
    int xoffset; //x offset: if positionTop=1, relative to top. if positionTop=0, relative to bottom
    int yoffset; //y offset: if positionTop=1, relative to top. if positionTop=0, relative to bottom
} MID2253_OSD_TEXT;

#define MID2253_MAX_OSDLONGTEXT 160

typedef struct mid2253_osd_longtext
{
    int osdOn;       //OSD on if != 0, 1=8x14 font, 2=16x16 font
    int osdChan;     // osd channel to update.  osdChan=0 for stream A, osdChan=1 for stream B, osdChan=2 for output
    int transparent; //transparent OSD if !=0, 1=100%, 2=50%, 3=25%
    int positionTop; //see xoff, yoff below
    int ddmm;     //date format 0=mm-dd 1=dd-mm 2=mmm-dd, 3=dd-mmm- 4=mmm dd, 5=ddmmm, 6=dd.mm.
    int year2;    // year display mode (year2 = 1 means 2 digits, year2=0 means 4 digits)
    int fraction; // whether to display fraction of seconds
    int xoffset; //x offset: if positionTop=1, relative to top. if positionTop=0, relative to bottom
    int yoffset; //y offset: if positionTop=1, relative to top. if positionTop=0, relative to bottom
    unsigned char line[MID2253_MAX_OSDLONGTEXT]; // ascii string of text (null terminated)
} MID2253_OSD_LONGTEXT;

typedef struct mid2253_osd_styledtext
{
	int osdOn;		// OSD on if != 0
	int osdChan;	// osd channel to update.  osdChan=0 for stream A, osdChan=1 for stream B, osdChan=2 for output
	int id;			// region id: 0..7
	int xoffset;	// x offset: relative to left
	int yoffset;	// y offset: relative to top
	LPSTR font;     // font name
	int size;       // point size of text
	int style;		// bit[0]: bold, bit[1]: italic, bit[2]: outline, bit[3]: underline, bit[4]: shadow
	int outline;	// outline style: 0=transparent, 1..7=shaded, 8=black
	int background; // background style: 0=transparent, 1..7=shaded, 8=black
	int color;      // RGB888 color for text (only used for osdChan=2 or background=8)
	LPSTR line;     // pointer to UTF8 text (null terminated) (pointer may be NULL, which will update xoffset and yoffset only)
} MID2253_OSD_STYLEDTEXT;

#define MID2253_STYLE_BOLD 1
#define MID2253_STYLE_ITALIC 2
#define MID2253_STYLE_OUTLINE 4
#define MID2253_STYLE_UNDERLINE 8 
#define MID2253_STYLE_SHADOW 16

typedef struct mid2253_osd_rect
{
	int osdOn;		// OSD on if != 0
	int osdChan;	// osd channel to update.  osdChan=0 for stream A, osdChan=1 for stream B, osdChan=2 for output
	int id;			// region id: 0..15
	int xoffset;	// x offset: relative to left
	int yoffset;	// y offset: relative to top
	int width;		// width of rectangle
	int height;		// height of rectangle
	int color;      // RGB888 color for rectangle (only used for osdChan=2)
} MID2253_OSD_RECT;


typedef struct mid2253_osd_bmp
{
	int osdOn;		// OSD on if != 0
	int osdChan;	// osd channel to update.  osdChan=0 for stream A, osdChan=1 for stream B, osdChan=2 for output, osdChan=3 for both streams
	int id;			// region id: 0..15
	int xoffset;	// x offset: relative to left
	int yoffset;	// y offset: relative to top
	void *bmp;		// pointer to bitmap image data (as loaded from file)
} MID2253_OSD_BMP;

typedef union mid2253_osd_data
{
    struct mid2253_osd_text osdtext; // text structure
	struct mid2253_osd_longtext osdlongtext; // large text structure
    struct mid2253_osd_bmp  osdbmp;  // BMP file structure
	struct mid2253_osd_styledtext osdstyledtext; // styled text structure
    struct mid2253_osd_rect  osdrect;  // rectangle structure
} MID2253_OSD_DATA;


// note: devid is a file descriptor to /dev/videoX device returned by open()
MID2253_API int S2253_StreamOverlay(MID2253_OVL_STRUCT *ovl, unsigned char *data, int devid, int strmidx);
MID2253_API int S2253_SetOsd(MID2253_OSD_TYPE osdtype, MID2253_OSD_DATA *osd, int devid, int strmidx);


#endif
