#include "Common.h"
#include <string>
#include <iostream>

using namespace CALIB; 

int CALIB::Common::doubleNum(int num,bool up)
{
	if(up)
		num = num * 2;
	else
		num = num / 2;
	return num;
}

void CALIB::Common::countCoordinates(int index,int srcX,int srcY,int * dstX,int *dstY,bool inverseY)
{
	if(inverseY)
	{
		switch(index)
		{
			case UPPER_LEFT:
				*dstY = srcY;
				break;
			case UPPER_RIGHT:
				*dstX = srcX;
				*dstY = srcY;
				break;				
			case BOTTOM_RIGHT:
				*dstX = srcX;
				break;
			default:			
				break;
		}
		return;
	}
	switch(index)
	{
		case UPPER_RIGHT:
			*dstX = srcX;
			break;
		case BOTTOM_LEFT:
			*dstY = srcY;
			break;
		case BOTTOM_RIGHT:
			*dstX = srcX;
			*dstY = srcY;
			break;
		default:			
			break;
	}
}

float CALIB::Common::convertUnsignedCharToFloat(unsigned char value)
{
	float result = value;
	if(result < 0)
		result += CHAR_LENGHT;
	return result;
}
