#ifndef V_IMAGE_H
#define V_IMAGE_H

#define	DEFAULT_COLORCHANNEL_VALUE	0x80

#define	LIBV_CLIPBOARD_NAME	"//./clipboard"
EXTERN_STRING(libv_clipboard_name)

#ifdef 	__cplusplus
extern	"C" {
#endif	/* __cplusplus */
	/*	Use this to set default alpha value for images without alpha
	 *	channel (alpha channel may present only in TGA images).
	 *	Returns old default alpha value.
	 *	Initial alpha is equal to DEFAULT_COLORCHANNEL_VALUE
	 */
	u8_t	V_GLOBAL		imgDefaultAlpha(u8_t new_alpha);
	/*	tgaLoad - load Targa image.
	 *	Input:
	 *		- name: name of input file;
	 *		- width, height: points to the width and height of image.
	 *	Output:
	 *		Returns malloc()'ed block of width*height*4 bytes, image
	 *		dimensions stored in 'width' and 'height'; in case of
	 *		error returns NULL ('width' and 'height' unchanged).
	 *	Notes.
	 *		1. 'width' and/or 'height' can be NULL.
	 *		2. Supported formats: TGA #2, #10.
	 */
	u8_p 	V_GLOBAL	tgaLoad(char *name,u32_t *width,u32_t *height);
	/*	tgaSave: saves RGBA (32-bit) targa image.
	 *	Input:
	 *		- name: image file name;
	 *		- width, height: dimensions of image;
	 *		- pixels: block of width*height*4 bytes.
	 *	Output: true if no error, false otherwise.
	 */
	vboolean	V_GLOBAL	tgaSave(char *name,u32_t width,u32_t height,
		u8_t *pixels);
	/*	tgaSaveEx: saves either RGB or RGBA (32-bit) targa image.
	 *	Input:
	 *		- save_alpha: if true, saves RGBA image; if false,
	 *			behaves like tgaSave().
	 *	Output: true if no error, false otherwise.
	 */
	vboolean	V_GLOBAL	tgaSaveEx(char *name,
		u32_t width,u32_t height,u8_t *pixels,vboolean save_alpha);
	/*	jpgLoad - load JPEG image.
	 *	Input, Output: see above.
	 *	NOTE. Currently no saving routine for JPEG (libv utilizes only
	 *	decompression size of libjpeg - about 100k of binaries).
	 */
	u8_p 	V_GLOBAL	jpgLoad(char *name,u32_t *width,u32_t *height);
	/*	bmpLoad - load Windows bitmap.
	 *	Input:
	 *		- name: name of input file;
	 *		- width, height: points to the width and height of image.
	 *	Output:
	 *		Returns malloc()'ed block of width*height*4 bytes, image
	 *		dimensions stored in 'width' and 'height'; in case of
	 *		error returns NULL ('width' and 'height' unchanged).
	 *	Notes.
	 *		1. 'width' and 'height' can be NULL.
	 *		Supported formats: RGB bitmap, paletted (256-color) bitmap.
	 */
	u8_p	V_GLOBAL	bmpLoad(char *name,u32_t *width,u32_t *height);
	/*	bmpSave: saves RGB (24-bit) Windows bitmap image.
	 *	Input:
	 *		- name: image file name or "//./clipboard";
	 *		- width, height: dimensions of image;
	 *		- pixels: block of width*height*4 bytes.
	 *	Output: true if no error, false otherwise.
	 */
	vboolean	V_GLOBAL	bmpSave(char *name,u32_t width,u32_t height,
		u8_t *pixels);
	/*	bmpSaveEx(): saves RGB image of resolution (1000*width)/mmWidth
	 *	by (1000*height) / mmHeight pels per meter.
	 *	Input:
	 *		- name: image file name or "//./clipboard";
	 *		- mmWidth: width of image in millimeters;
	 *		- mmHeight: height of image in millimeters.
	 *	Output: true if no error, false otherwise.
	 */
	vboolean	V_GLOBAL	bmpSaveEx(char *name,u32_t width,u32_t height,
		u8_t *pixels,u32_t mmWidth,u32_t mmHeight);
	/*	Utility function for bmpSaveEx(): calculates size in millimeters
	 *	by given picture size and device resolution in DPI */
	u32_t		V_GLOBAL	bmpMMFromPixels(u32_t num_pixels,
		u32_t device_dpi);
	/*
	 * The following routines determine image format by the file extension
	 */
	u8_p V_GLOBAL	rgbaLoad(char *file_name,u32_t *width_ret, u32_t *height_ret);
	vboolean V_GLOBAL	rgbaSave(char *file_name,u32_t width, u32_t height,
		u8_p pixels);
	vboolean V_GLOBAL	rgbaSaveEx(char *file_name,u32_t width, u32_t height,
		u8_p pixels,u32_t mmWidth,u32_t mmHeight);
#ifdef	CONFIG_WIN32_DIBOBJECT
	/*
 	 * Creates packed Win32 DIB structure in memory (implementation is
 	 * portable, but the function itself not very useful under UNIX).
 	 */
	void_p	V_GLOBAL	bmpCreateDIBObject(u8_t *rgba,u32_t width,u32_t height,
		u32_t mmWidth,u32_t mmHeight);
#endif	/* CONFIG_WIN32_DIBOBJECT */
	/*
	 * Scales image to arbitrary size. Returns memAlloc()'ed block; if
	 *	'keepon' == true, than original block _not_ memFree()d.
	 * Uses fast routines for halving; for other size, uses slow
	 * floating-point matrix resampling functions.
	 */
	u8_p	V_GLOBAL	rgbaScale(u8_t *src,u32_t width,u32_t height,
		u32_t new_width,u32_t new_height,vboolean keepon);
	/*
	 * Extracts channels from RGBA8 image, converting range [0..255] to [0..1].
	 * Any of 'r' ... 'a' matices can be NULL.
	 */
	vboolean V_GLOBAL	rgbaSplitChannels(matrix_p r,matrix_p g,matrix_p b,matrix_p a,
		u8_p src,u32_t width,u32_t height);
	/*
	 * Reverse of rgbaSplitChannels().
	 */
	vboolean V_GLOBAL	rgbaCombineChannels(matrix_p r,matrix_p g,matrix_p b,matrix_p a,
		u8_p dst,u32_t width,u32_t height);
	/*
	 * Loads color channels of image stored in file 'file_name' into matrices
	 * and stores the matrices in 'X_ret' arguments. If 'X_ret' is NULL,
	 * corresponding channel will not be loaded.
	 */
	vboolean V_GLOBAL	rgbaLoadChannels(char *file_name,
		matrix_p *r_ret,matrix_p *g_ret,matrix_p *b_ret,matrix_p *a_ret);
	/*
	 * Saves color channels to file 'file_name'. Al least one of
	 * channels must not be NULL.
	 */
	vboolean V_GLOBAL	rgbaSaveChannels(char *file_name,
		matrix_p r,matrix_p g,matrix_p b,matrix_p a);
#ifdef __cplusplus
}
#endif	/* __cplusplus */

#endif	/* V_IMAGE_H */
