Пример #1
0
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;
	//prepare cos value table
	cosVal[0] = 1; cosVal[1] = cos(PI/16); cosVal[2] = cos(PI/8); cosVal[3] = cos((3*PI)/16);
	cosVal[4] = c; cosVal[5] = cos((5*PI)/16); cosVal[6] = cos((3*PI)/8); cosVal[7] = cos((7*PI)/16);
	cosVal[8] = 0; cosVal[9] = -sin(PI/16); cosVal[10] = -sin(PI/8); cosVal[11] = -sin((3*PI)/16);
	cosVal[12] = -c; cosVal[13] = -sin((5*PI)/16); cosVal[14] = -sin((3*PI)/8); cosVal[15] = -sin((7*PI)/16);

	for(int i = 0; i < 16; ++i){
		cosVal[i+16] = - cosVal[i];
	}

	int wd, ht;
	char ImagePath[_MAX_PATH];
	sscanf(lpCmdLine, "%s %d %d %d", &ImagePath, &quantizationLevel, &deliveryMode, &latency);
	
	if(quantizationLevel > 7 || quantizationLevel < 0){
		MessageBox(NULL, "Quantization Level can be 0 to 7 only.", NULL, NULL);
		return FALSE;
	}
	if(deliveryMode > 3 || deliveryMode < 1){
		MessageBox(NULL, "Delivery Mode can be either 1 2 or 3 only.", NULL, NULL);
		return FALSE;
	}
	if(latency < 0){
		MessageBox(NULL, "Latency can be greater than 0 only.", NULL, NULL);
		return FALSE;
	}

	wd=352; ht=288;	
	originalImage.setWidth(wd);
	originalImage.setHeight(ht);
	originalImage.setImagePath(ImagePath);
	originalImage.ReadImage();
	
	nextStart = wd + 50;
				
	workingImage.setHeight(ht);
	workingImage.setWidth(wd);
	
	Byte* imgd = new Byte[ht*wd*3];
	memset(imgd, 0xFF, sizeof(Byte)*ht*wd*3);
	
	workingImage.setImageData(imgd);
	imgd = NULL;
		
	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_IMAGE, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow)) 
	{
		return FALSE;
	}	
	
	TwoByte *s = new TwoByte[ht*wd*3];
	MyStorage strg;
	strg.setStorage(s);
	encode(s);	

	if(deliveryMode == 1){
		_beginthread (sendDecodeSequentialMode, 0, s);	
	}
	else if(deliveryMode == 2){
		_beginthread (sendSpectralSelection, 0, s);
	}
	else if(deliveryMode == 3){
		_beginthread (sendSuccessiveBits, 0, s);
	}
	

	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_IMAGE);
	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
		
	return msg.wParam;
}