#include "stdafx.h"
#include "Img_lib.h"
using namespace cv;
using namespace System::Drawing;

#define USESCREEN_WIDTH 1800
#define USESCREEN_HEIGHT 900
#define BORDERS 10

/*New small image is created and it location is stolen as a poiner 
in variable of respective camera*/
int prepare_smallimage(Camera* cam, Cameras *hand){
	CvSize pole,resized;
	static int rows, columns;
	static int limitx, limity;
	static int newsizex, newsizey;
	static float scale, aspectrpic, aspectrframe;
	pole.height = cam->get_roi()->roi_height;
	pole.width = cam->get_roi()->roi_width;
	cam->output_Img = Mat(pole, CV_8UC1);
	
	switch(hand->celkem)
	{
	case 1:
		rows= 1;
		columns = 1;
		limitx=(USESCREEN_WIDTH-BORDERS*2);
		limity=(USESCREEN_HEIGHT-BORDERS*2);
		break;
	case 2:
		rows= 1;
		columns = 2;
		limitx=(USESCREEN_WIDTH-BORDERS*3)/2;
		limity=(USESCREEN_HEIGHT-BORDERS*2);
		break;
	case 3:
		rows= 2;
		columns = 2;
		limitx=(USESCREEN_WIDTH-BORDERS*3)/2;
		limity=(USESCREEN_HEIGHT-BORDERS*3)/2;
		break;
	case 4:
		rows= 2;
		columns = 2;
		limitx=(USESCREEN_WIDTH-BORDERS*3)/2;
		limity=(USESCREEN_HEIGHT-BORDERS*3)/2;
		break;
	case 5:
		rows= 2;
		columns = 3;
		limitx=(int)(USESCREEN_WIDTH-BORDERS*4)/3;
		limity=(USESCREEN_HEIGHT-BORDERS*3)/2;
		break;
	case 6:
		rows= 2;
		columns = 3;
		limitx=(int)(USESCREEN_WIDTH-BORDERS*4)/3;
		limity=(USESCREEN_HEIGHT-BORDERS*3)/2;
		break;
	default:
		break;
	}	
	aspectrpic = (float)cam->output_Img.size().width/cam->output_Img.size().height;
	aspectrframe = (float)limitx/limity;
	scale = (aspectrpic>=aspectrframe)?((float)limitx/(cam->output_Img.size().width)):((float)limity/(cam->output_Img.size().height));
	newsizex = (int)scale*(cam->output_Img.size().width);
	newsizey = (int)scale*(cam->output_Img.size().height);
	resized.height = newsizey;
	resized.width = newsizex;
	hand->pole.height = newsizey;
	hand->pole.width = newsizex;


	return 1;

}


/*int prepare_largeimage(Cameras* hand){
	CvSize pole;
	UINT32 x,y;
	y= USESCREEN_HEIGHT;
	x= USESCREEN_WIDTH;
	pole.height = y;
	pole.width = x;
				//hand->output_CVimg = cvCreateImage(pole,IPL_DEPTH_8U,1);
	hand->output_Img = Mat(pole, CV_8UC1);
	return 1;

}*/

/*int update_largeimage(Camera*cam, Cameras*hand){
	if(hand->locked1!=TRUE){
	hand->locked1=TRUE;
	static unsigned int currentcams = 0;
	static int rows, columns;
	static int limitx, limity;
	static int newsizex, newsizey;
	static float scale, aspectrpic, aspectrframe;

	currentcams=hand->celkem;
	for(unsigned int i = 0;i<hand->celkem;i++){
	switch(cam->cam_index){
	case 0:
		cvSetImageROI(hand->output_CVimg, cvRect(BORDERS, BORDERS, hand->pole.width,hand->pole.height));
        cvResize(cam->output_CVimg, hand->output_CVimg);
        cvResetImageROI(hand->output_CVimg);
		break;
	case 1:
		cvSetImageROI(hand->output_CVimg, cvRect(BORDERS*2+hand->pole.width, BORDERS,  hand->pole.width,hand->pole.height));
        cvResize(cam->output_CVimg, hand->output_CVimg);
        cvResetImageROI(hand->output_CVimg);
		break;
	case 2:
		cvSetImageROI(hand->output_CVimg, cvRect(BORDERS, BORDERS*2+hand->pole.height, hand->pole.height,hand->pole.height));
        cvResize(cam->output_CVimg, hand->output_CVimg);
        cvResetImageROI(hand->output_CVimg);
		break;
	case 3:
		cvSetImageROI(hand->output_CVimg, cvRect(BORDERS*2+hand->pole.width, BORDERS*2+hand->pole.height, hand->pole.width,hand->pole.height));
        cvResize(cam->output_CVimg, hand->output_CVimg);
        cvResetImageROI(hand->output_CVimg);
		break;
	case 4:
		cvSetImageROI(hand->output_CVimg, cvRect(BORDERS*3+(hand->pole.width)*2, BORDERS, hand->pole.width,hand->pole.height));
        cvResize(cam->output_CVimg, hand->output_CVimg);
        cvResetImageROI(hand->output_CVimg);
		break;
	case 5:
		cvSetImageROI(hand->output_CVimg, cvRect(BORDERS*3+(hand->pole.width)*2, BORDERS*2+(hand->pole.height), hand->pole.width,hand->pole.height));
        cvResize(cam->output_CVimg, hand->output_CVimg);
        cvResetImageROI(hand->output_CVimg);
		break;
	default:
		break;
	}
}
	}
	return 1;
}*/


