#include <v_lib.h>

u32_t width;
u32_t height;
u8_t *pixbuf;

void setpixel(u32_t x,u32_t y,u32_t pixel)
{
	u32_t *ptr=(u32_t*)pixbuf;
	ptr[y*width+x]=pixel;
}
	
u8_t *create_pixbuf(u32_t w,u32_t h)
{
	u32_t x,y;
	width=w;
	height=h;
	pixbuf=(u8_t*)malloc(w*h*4);
	v_zero(pixbuf,w*h*4);
	for(x=0;x<w;x++)
	{
		setpixel(x,0,0xFF);
		setpixel(x,h-1,0xFF0000);
	}
	for(y=0;y<h;y++)
	{
		setpixel(0,y,0xFFFFFF);
		setpixel(w-1,y,0xFF00);
	}
	return pixbuf;
}

int main()
{
	logStartConsoleLog();
	logUpperLevel(LOG_TRACE);
	create_pixbuf(3,10);
	tgaSave("out.tga",width,height,pixbuf);
	bmpSave("out.bmp",width,height,pixbuf);
	free(pixbuf);
	
	pixbuf=tgaLoad("out.tga",&width,&height);
	bmpSave("out_tga.bmp",width,height,pixbuf);
	free(pixbuf);
	
	pixbuf=bmpLoad("out.bmp",&width,&height);
	tgaSave("out_bmp.tga",width,height,pixbuf);
	bmpSaveEx("//./clipboard",width,height,pixbuf,30,100);
	free(pixbuf);
	
	return 0;
}