/*
 * vg_driver.h
 *
 *  Created on: 20/giu/2018
 *      Author: chessaa
 */

#ifndef VG_DRIVER_H_
#define VG_DRIVER_H_

#include <stdint.h>

enum vg_drv_standard_t
{
	vg_std_stanag3350_b,	//574x574 (625 lines lines)
	vg_std_stanag3350_c,	//484x484 (525 lines)

	vg_std_svga,	//800x600
	vg_std_xga,		//1924x768

	vg_std_stanag3350_b_11,	//aspect ratio 1:1
	vg_std_stanag3350_c_11,	//aspect ratio 1:1

	vg_std_digital_50hz,
	vg_std_digital_60hz,

	vg_std_default,

	//Some usefull alias
	vg_std_grifo_f=vg_std_stanag3350_c,
	vg_std_grifo_m=vg_std_stanag3350_b,
	vg_std_grifo_s=vg_std_stanag3350_b
};

enum vg_drv_builtin_test_pattern_t
{
	vg_drv_tp_unioform_gray_50=0,
	vg_drv_tp_uniform_white,
	vg_drv_white_bounding_b0x,
	vg_drv_tp_white_square_reticle,
	vg_drv_tp_color_bars,
	vg_drv_tp_alorithminc
};


typedef uint32_t vg_drv_raw_color_t;

struct vg_drv_palette_t
{
	enum { num_colors=256};
	vg_drv_raw_color_t color[num_colors];
};


struct vg_drv_vstd_param_t
{
	unsigned int id;
	unsigned int dx;
	unsigned int dy;
	const char* name;
	unsigned int interlaced;
	bool digital;

	const char* nickname;
};

extern void vg_drv_set_graphic_geometry(unsigned int dx, unsigned int dy);

extern void vg_drv_set_default_standard(vg_drv_standard_t std);

extern void* vg_drv_configure(void* driver_memory_address, void* gfx_palet_address, void* sc_palet_address);

extern void* vg_drv_reconfigure(unsigned int flags, void* driver_memory_address, void* gfx_palet_address, void* sc_palet_address, void* fw_internal_fb);

extern const vg_drv_vstd_param_t* vg_drv_change_standard(vg_drv_standard_t std, bool left_aligned=false);

extern int vg_drv_setup(enum vg_drv_standard_t phy_vid, void* fb, unsigned int dx, unsigned int dy, unsigned int stride);

extern void vg_drv_set_framebuffer(const void* fb, unsigned int size);

extern int vg_drv_video_enable(int enable);

extern int vg_drv_builtin_test_pattern_enable(int enable, enum vg_drv_builtin_test_pattern_t pattern_id);

extern struct vg_drv_palette_t* vg_drv_get_gfx_palette(void);
extern struct vg_drv_palette_t* vg_drv_get_sc_palette(void);
extern void* vg_drv_get_fr_interal_fb();

extern void vg_drv_gfx_palette_set_gray_scale(bool with_occlusion=true);

extern void vg_drv_set_gfx_color(unsigned int index, unsigned int color);
extern void vg_drv_set_sc_color(unsigned int index, unsigned int color);

extern vg_drv_raw_color_t vg_drv_color_encode(unsigned int red, unsigned int green, unsigned int blue);

extern vg_drv_raw_color_t vg_drv_color_encode_luminance(unsigned int luminance, unsigned int red, unsigned int green, unsigned int blue);

extern vg_drv_raw_color_t vg_drv_color_encode_gray(unsigned int luminance);


//Test Support
extern int vg_drv_enable_test_pattern(int pattern, unsigned int white_level=0);

extern int vg_drv_gen_test_pattern(int /*patterid*/, unsigned int white, void* gc_buffer, int dx, int dy, int stride=0);

extern const vg_drv_vstd_param_t* vg_drv_vstd_info(int code);

extern void vg_drv_resize(int phy_dx, int phy_dy, int stride);

#endif /* VG_DRIVER_H_ */
