#include <v_lib.h>

/*
#include <process.h>

void thr(void *arg)
{
	printf("%d\n",imgDefaultAlpha(10));
	printf("%d\n",imgDefaultAlpha(20));
	_endthread();
}
*/

#define	A

int main()
{
#ifdef	A

	u32_t w,h;
	u8_p pixels;

	logUpperLevel(LOG_TRACE);
	logStartConsoleLog();
	
	pixels=jpgLoad("../media/mist.jpg",&w,&h);
	if(pixels)
	{
		bmpSave("bmp/freon_mist.bmp",w,h,pixels);
		tgaSave("tga/freon_mist.tga",w,h,pixels);
		free(pixels);
	}
	
	pixels=tgaLoad("tga/freon_mist.tga",&w,&h);
	if(pixels)
	{
		bmpSave("out/out.bmp",w,h,pixels);
		free(pixels);
	}
	
	pixels=bmpLoad("bmp/freon_mist.bmp",&w,&h);
	if(pixels)
	{
		tgaSave("out/out.tga",w,h,pixels);
		free(pixels);
	}
	
	return 0;
#elif	defined(B)

	int w,h;
	int i,rep,levels;
	u8_t *pixels;
	miphead_t *mip;
	char buf[_MAX_PATH];
	
	rep=100;
	levels=8;
	
	timeStart();
	pixels=jpgLoad("../media/water.jpg",&w,&h);
	timeStop();
	if(!pixels)
	{
		printf("Failed to read src image\n");
		return -1;
	}
	printf("jpgLoad: %d milliseconds\n",timeMilliseconds());
	
	timeStart();
	for(i=0;i<rep;i++)
	{
		mip=mipBuild(pixels,w,h,levels);
		if(!mip)
		{
			printf("Failed to build mip\n");
			free(pixels);
			return -1;
		}
		free(mip);
	}
	timeStop();
	
	printf("%d times mip(%d,%d - %d levels), %d milliseconds\n",
		rep,w,h,levels,timeMilliseconds());
	
	mip=mipBuild(pixels,w,h,levels);
	
	w=mip->width;
	h=mip->height;
	for(i=0;i<mip->num_levels;i++)
	{
		sprintf(buf,"mip_out/lev%000d.tga",i);
		tgaSave(buf,w,h,mip->level[i],false);
		w>>=1;
		h>>=1;
	}
	free(mip);

	free(pixels);

#endif
}
