⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imageproc.cpp

📁 GPS programme for changchun at 8X
💻 CPP
📖 第 1 页 / 共 3 页
字号:
			} 

			fclose(fInfo);

			if (!bFrameErrFlag)
			{
				nFrameNum++;
			}
	
			nBlockCont++;//走步
		
		}//帧(块)循环结束
	
		fclose(fErrorReport);
		fErrorReport = NULL;



	}
//add error report


	
	FindClose(hFind);
	pThis->m_vdw.pTitle = (PCHAR)"Over";
	::SendMessage(pThis->m_hWnd, MSG_SHOWIMG, 0, (LPARAM)&pThis->m_vdw);//Display .bmp;
	
// 这是在堆中开辟的空间,只能在解构函数中摧毁
// 下面的代码只能释放栈中的空间

//	free(pCurStream);//释放空间
//	pCurStream=NULL;//杜绝野指针
//
//	free(pStrAfterRSDec);
//	pStrAfterRSDec=NULL;
//
//	free(pRecImg);
//	pRecImg=NULL;
//
//	free(pSubFrameAToSpDec);
//	pSubFrameAToSpDec=NULL;
//
//	free(pSubFrameBToSpDec);
//	pSubFrameBToSpDec=NULL;
//
//	free(pSubFrameAStart);
//	pSubFrameAStart=NULL;
//
//	free(pSubFrameBStart);
//	pSubFrameBStart=NULL;
//
//	free(pRecSubImgA);
//	pRecSubImgA=NULL;
//	
//	free(pRecSubImgB);
//	pRecSubImgB=NULL;
//
	return 0;
}

int ImageProc::TreatPackNumErrA(int arrPackNumA[PACKET_OF_SUBFRAME_A])
{
	int i;
	for (i=0;i<PACKET_OF_SUBFRAME_A;i++)
	{
		if (i!=arrPackNumA[i])
		{
			break;
		}
	}
	return(i-1);
}

int ImageProc::TreatPackNumErrB(int arrPackNumB[PACKET_OF_SUBFRAME_B])
{
	int i;
	for (i=0;i<PACKET_OF_SUBFRAME_B;i++)
	{
		if (i!=arrPackNumB[i])
		{
			break;
		}
	}
	return(i-1);
}


int ImageProc::FormSpDecStreamA(int nLastPackOfNoErrStream,unsigned char *pSubFrameAStart,unsigned char *pSubFrameAToSpDec)
{
	int nPackCont;
	int nSpihtStrlen=0;
	memset(pSubFrameAToSpDec,0,SUBFRAME_A_TO_SPDEC_LENGTH);
	for (nPackCont=0;nPackCont<=nLastPackOfNoErrStream;nPackCont++)
	{
		if (nPackCont==0)
		{
			pSubFrameAStart=pSubFrameAStart+FIRST_PACKET_FOR_SPDEC_OFFSET+1;
			memcpy(pSubFrameAToSpDec,pSubFrameAStart,FIRST_PACKET_FOR_SPDEC_LENFTH);
			pSubFrameAToSpDec=pSubFrameAToSpDec+FIRST_PACKET_FOR_SPDEC_LENFTH;			
			nSpihtStrlen=nSpihtStrlen + FIRST_PACKET_FOR_SPDEC_LENFTH;
			pSubFrameAStart = pSubFrameAStart + FIRST_PACKET_FOR_SPDEC_LENFTH;
			continue;
		}
		pSubFrameAStart=pSubFrameAStart+OTHER_PACKET_FOR_SPDEC_OFFSET+1;
		memcpy(pSubFrameAToSpDec,pSubFrameAStart,OTHER_PACKET_FOR_SPDEC_LENGTH);	
		pSubFrameAToSpDec=pSubFrameAToSpDec+OTHER_PACKET_FOR_SPDEC_LENGTH;
		nSpihtStrlen=nSpihtStrlen + OTHER_PACKET_FOR_SPDEC_LENGTH;
		pSubFrameAStart = pSubFrameAStart + OTHER_PACKET_FOR_SPDEC_LENGTH;
	}	
	return(nSpihtStrlen);	
}

int ImageProc::FormSpDecStreamB(int nLastPackOfNoErrStream,unsigned char *pSubFrameBStart,unsigned char *pSubFrameBToSpDec)
{
	int nPackCont;
	int nSpihtStrlen=0;
	memset(pSubFrameBToSpDec,0,SUBFRAME_B_TO_SPDEC_LENGTH);

	for (nPackCont=0;nPackCont<=nLastPackOfNoErrStream;nPackCont++)
	{
		if (nPackCont==0)
		{
			pSubFrameBStart=pSubFrameBStart+FIRST_PACKET_FOR_SPDEC_OFFSET+1;
			memcpy(pSubFrameBToSpDec,pSubFrameBStart,FIRST_PACKET_FOR_SPDEC_LENFTH);
			pSubFrameBToSpDec=pSubFrameBToSpDec+FIRST_PACKET_FOR_SPDEC_LENFTH;
			nSpihtStrlen=nSpihtStrlen + FIRST_PACKET_FOR_SPDEC_LENFTH;
			pSubFrameBStart = pSubFrameBStart + FIRST_PACKET_FOR_SPDEC_LENFTH;			
			continue;
		}
		pSubFrameBStart=pSubFrameBStart+OTHER_PACKET_FOR_SPDEC_OFFSET+1;
		memcpy(pSubFrameBToSpDec,pSubFrameBStart,OTHER_PACKET_FOR_SPDEC_LENGTH);		
		pSubFrameBToSpDec=pSubFrameBToSpDec+OTHER_PACKET_FOR_SPDEC_LENGTH;
		nSpihtStrlen=nSpihtStrlen + OTHER_PACKET_FOR_SPDEC_LENGTH;
		pSubFrameBStart = pSubFrameBStart + OTHER_PACKET_FOR_SPDEC_LENGTH;
	}	
	return(nSpihtStrlen);	
}





//----------------------------------------------------------------------------
//功能:存bmp文件,写入文件头及相应内容
//参数:
//      szImageName -- 文件名
//      pbi         -- BMP位图信息
//      byImgData   -- 数据内存
//
void
ImageProc::SaveImage(CString szImageName, 
							 PBITMAPINFO pbi, 
							 unsigned char* pbyImgData
							 )
{
    HANDLE hf;                  // file handle 
    BITMAPFILEHEADER hdr;       // bitmap file-header 
    PBITMAPINFOHEADER pbih;     // bitmap info-header 
    DWORD dwTotal;              // total count of bytes 
	LPBYTE lpBits;              // memory pointer 
    DWORD cb;                   // incremental count of bytes 
    BYTE *hp;                   // byte pointer 
    DWORD dwTmp; 

	pbih = (PBITMAPINFOHEADER) pbi; 
	pbih->biSizeImage = IMG_SIZE;

	if(!(lpBits=(LPBYTE)GlobalAlloc(GMEM_FIXED,pbih->biSizeImage)))
	{
		TRACE(_T("GlobalAlloc Failed!\n"));
		return;
	}

	//按windows系统坐标调整图像数据
	for(int i=0;i<IMG_HEIGHT;i++)
	{
		memcpy(lpBits+i*IMG_WIDTH,pbyImgData+(IMG_HEIGHT-1-i)*IMG_WIDTH,IMG_WIDTH);
	}
	pbih->biHeight = IMG_HEIGHT;

	
	// Create the .BMP file. 
    hf = CreateFile(szImageName, 
                   GENERIC_READ | GENERIC_WRITE, 
                   (DWORD) 0, 
                   NULL, 
                   CREATE_ALWAYS, 
                   FILE_ATTRIBUTE_NORMAL, 
                   (HANDLE) NULL); 
    if (hf == INVALID_HANDLE_VALUE) 
	{
		TRACE("Open bmp file err!\n");
		return;
	}
  
	// 0x42 = "B" 0x4d = "M" 
	hdr.bfType = 0x4d42;        
 	// Compute the size of the entire file. 
    hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) + 
                 pbih->biSize + pbih->biClrUsed * sizeof(RGBQUAD) +
				 pbih->biSizeImage + 2); 
    hdr.bfReserved1 = 0; 
    hdr.bfReserved2 = 0; 

    // Compute the offset to the array of color indices. 
    hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + 
                    pbih->biSize + pbih->biClrUsed * sizeof (RGBQUAD); 

    // Copy the BITMAPFILEHEADER into the .BMP file. 
    WriteFile(hf, (LPVOID) &hdr, sizeof(BITMAPFILEHEADER), 
        (LPDWORD) &dwTmp,  NULL);


    // Copy the BITMAPINFOHEADER and RGBQUAD array into the file. 
    WriteFile(hf, (LPVOID) pbih, sizeof(BITMAPINFOHEADER) 
                  + pbih->biClrUsed * sizeof (RGBQUAD), 
                  (LPDWORD) &dwTmp, ( NULL));


    // Copy the array of color indices into the .BMP file. 
    dwTotal = cb = pbih->biSizeImage; 
    hp = lpBits; 
    WriteFile(hf, (LPSTR) hp, (int) cb, (LPDWORD) &dwTmp, NULL);


    // Close the .BMP file. 
    if (!CloseHandle(hf)) 
	{
		TRACE("Fail to close img file!\n");
		return;
    }
	
    // Free memory. 
    GlobalFree((HGLOBAL)lpBits);
	pbih->biHeight = -1*IMG_HEIGHT;

	return;
}




//------------------------------------------------------------------------
// 初始化显示窗口线程 [05.12.11]
//modified by ken [06.03.14]
//The same in the "Using Window Classes" in MSDN
DWORD WINAPI ImageProc::InitShowWnd(LPVOID lpvoid)
{
	ImageProc *pThis = (ImageProc*)lpvoid;
	pThis->m_hinst = AfxGetInstanceHandle();

	if (pThis->m_hWnd == NULL)
	{
		pThis->m_wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
		pThis->m_wndclass.lpfnWndProc   = DispProc ;
  		pThis->m_wndclass.cbClsExtra    = 0 ;
  		pThis->m_wndclass.cbWndExtra    = 0 ;
   		pThis->m_wndclass.hInstance     = pThis->m_hinst ;
		pThis->m_wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
		pThis->m_wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
		pThis->m_wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
		pThis->m_wndclass.lpszMenuName  = NULL ;
 		pThis->m_wndclass.lpszClassName = _T("XDRecImg")  ;
  		
		RegisterClass(&pThis->m_wndclass);

   	}
	
	//modified by Mabel [06.03.18]
	pThis->m_hWnd = CreateWindow(_T("XDRecImg"), _T("XDRecImg"),
								WS_OVERLAPPED | WS_THICKFRAME, 
								pThis->m_WinPar.StarX, 
								pThis->m_WinPar.StarY,
								pThis->m_WinPar.EndX - pThis->m_WinPar.StarX, 
								pThis->m_WinPar.EndY - pThis->m_WinPar.StarY,
								NULL, NULL, pThis->m_hinst, NULL);
	
	//modified by ken [06.03.14]
	MSG msg;
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	TRACE("XLei:InitShowWnd thread quit.\n");
	return 0;
}



//----------------------------------------------------------------------------
// [05.12.11]
// 功能:显示窗口回调函数,用于处理窗口消息
//
LRESULT CALLBACK ImageProc::DispProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HDC         hdc;
//     PAINTSTRUCT ps;
	//
	VDWINDOW *pvdw;
	HANDLE	hBitmap;
	HDC		hMemDC;
	static BOOL bfirstLove = FALSE;

// 	long temp;

	static INT  nX;
	static INT	nY;
	static INT	nWidth;
	static INT	nHeigh;
	static PCHAR pBuf;
	static CHAR szTitle[256];

	//Mabel [06.03.07]
	static CHAR szTxtShow[256] = "Hello";
	static INT  nTxtShowLen;
	//Mabel [06.03.07]

	//Mabel [06.03.08]
	RECT rt;
	rt.top = 0;
	rt.bottom = 300;
	rt.left = 0;
	rt.right = 300;
	

    switch (message)
    {
		case WM_CREATE:
// 			TRACE("case WM_CREATE.\n");
			return 0 ;
			
		case MSG_SHOWIMG:
							
			hdc = GetDC(hwnd);
			pvdw = (VDWINDOW *)lParam;//VDWINDOW 自定义;

			hBitmap = CreateDIBitmap(hdc, (BITMAPINFOHEADER FAR *)pvdw->pBmp, \
												   CBM_INIT, pvdw->pBuf, \
												   (LPBITMAPINFO)pvdw->pBmp,DIB_RGB_COLORS);
			if(NULL == hBitmap)
			{
				TRACE(_T("image create wrong! "));
				return 0;
			}


			
//Display 1 ;
//			temp = long(hBitmap);
//			
//			if(!DrawState(hMemDC,NULL, NULL, hBitmap,NULL, 0, 0,500, 500, DST_BITMAP))
//			{
//				TRACE(_T("image Display wrong!"));
//				return 0;
//			}
			
// Display 2 ;				
		
					hMemDC = CreateCompatibleDC(hdc);
					SelectObject(hMemDC, hBitmap);

					//modified by Mabel [06.03.15] [06.03.18]
					SetWindowPos(hwnd, HWND_TOP,  \
												 pvdw->pWinPar->StarX, \
												 pvdw->pWinPar->StarY, \
												 pvdw->pWinPar->EndX - pvdw->pWinPar->StarX, \
												 pvdw->pWinPar->EndY - pvdw->pWinPar->StarY, \
												 SWP_FRAMECHANGED);
					//modified by Mabel [06.03.15] [06.03.18]
					::SetStretchBltMode(hdc, HALFTONE);
							if( !StretchBlt(hdc, \
											0, \
											0, \
											pvdw->pWinPar->EndX - pvdw->pWinPar->StarX, \
											pvdw->pWinPar->EndY - pvdw->pWinPar->StarY, \
											hMemDC, 0, 0, IMG_WIDTH, IMG_HEIGHT, SRCCOPY))
							{
								TRACE(("display wrong! "));
							}
								
								

//			nX = pvdw->pWinPar->StarX;
//			nY = pvdw->pWinPar->StarY;
//			nWidth = pvdw->pWinPar->EndX - pvdw->pWinPar->StarX; //modified by Mabel [06.03.15]
//			nHeigh = pvdw->pWinPar->EndY - pvdw->pWinPar->StarY; //modified by Mabel [06.03.15]
//			pBuf = pvdw->pBuf;

//				//Mabel [06.03.07]
//					::SetBkMode(hdc, TRANSPARENT);
//					::SetTextColor(hdc, RGB(0,255,0));
//					rt.right = nWidth;//Mabel [06.03.17]
//					::DrawText(hdc, szTxtShow, -1, &rt, \
//								DT_WORDBREAK|DT_LEFT|DT_END_ELLIPSIS);			
//					//Mabel [06.03.07]
//	
					
							
			strcpy(szTitle, pvdw->pTitle);

			SetWindowText(hwnd, szTitle);

			DeleteDC(hMemDC);
			DeleteObject(hBitmap);		
			ReleaseDC(hwnd, hdc);
			break;

			

            

//		case   WM_PAINT:
//// 			if (bfirstLove)
//// 			{
//				hdc = BeginPaint (hwnd, &ps);		
//				
//				hBitmap = CreateDIBitmap(hdc, \
//										 (BITMAPINFOHEADER FAR *)ImageProc::m_pBmp, \
//										 CBM_INIT, pBuf, \
//										 (LPBITMAPINFO)ImageProc::m_pBmp, \
//										 DIB_RGB_COLORS);
//				if(NULL == hBitmap)
//				{
//					TRACE(_T("image create wrong! %d %s %d"), GetLastError(), __FILE__, __LINE__);
//					return 0;
//				}
//				
//				hMemDC = CreateCompatibleDC(hdc);
//				SelectObject(hMemDC, hBitmap);
//				SetWindowText(hwnd, szTitle);//
//				//modified by Mabel [06.03.15] [06.03.18]
//				SetWindowPos(hwnd, HWND_TOP,  nX, nY, \
//							 nWidth, nHeigh, SWP_FRAMECHANGED);
//				//modified by Mabel [06.03.15] [06.03.18]
//				::SetStretchBltMode(hdc, HALFTONE);
//				if( !StretchBlt(hdc, 0, 0, nWidth, nHeigh,\
//								hMemDC, 0, 0, IMG_WIDTH, IMG_HEIGHT, SRCCOPY))
//				{
//					TRACE(_T("display wrong! %s %d"), __FILE__, __LINE__);
//				}
//
//				//Mabel [06.03.07]
//				::SetBkMode(hdc, TRANSPARENT);
//				::SetTextColor(hdc, RGB(0,255,0));
//				rt.right = nWidth;//Mabel [06.03.17]
//				::DrawText(hdc, szTxtShow, -1, &rt, \
//							DT_WORDBREAK|DT_LEFT|DT_END_ELLIPSIS);			
//				//Mabel [06.03.07]
//
//				DeleteDC(hMemDC);
//				DeleteObject(hBitmap);		
//				EndPaint (hwnd, &ps) ;			
//// 			}
//			break;
			
//		case  WM_CLOSE:
//			DestroyWindow(hwnd);


		case   WM_DESTROY:
			PostQuitMessage(0);
			return 0 ;
    }
	
	return DefWindowProc(hwnd, message, wParam, lParam) ;
}






















⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -