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

📄 rsip.cpp

📁 基于小波的SAR斑点处理
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	
	pDocTemplate->InitialUpdateFrame(pFrame, pDocument);
}

void CRSIPApp::OnFileImport() 
{
	CString filter="Bitmap Files(*.bmp)|*.bmp|Tape Files(*.bil;*.bsq;*.bip)|*.bil;*.bsq;*.bip||";
	CFileDialog dlg(TRUE,NULL,NULL,
		OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
		filter,NULL);
	if(dlg.DoModal() == IDOK)
	{
		CString szFilePathName = dlg.GetPathName();
		CString szExtent = szFilePathName.Right(3);
		szExtent.MakeUpper();

		if(szExtent=="BMP")
		{
			ImportBMPFile(szFilePathName);
		}
		else
		{
			ImportTapeFile(szFilePathName);
		}
		m_nDocCount++;
	}
}

void CRSIPApp::ImportBMPFile(LPCTSTR szFileFullName)
{
	CFile file;
	if(0==file.Open(szFileFullName,CFile::modeRead))
	{
		AfxMessageBox("不能打开BMP文件!");
		return;
	}
	
	BITMAPFILEHEADER bmpfh;
	BITMAPINFOHEADER bmpheader;
	file.Read(&bmpfh,sizeof(BITMAPFILEHEADER));
	file.Read(&bmpheader,sizeof(BITMAPINFOHEADER));
	if(bmpfh.bfType!=19778)
	{
		AfxMessageBox("该BMP文件格式不对!");
		file.Close();
		return;
	}
	int nWidth = (int)bmpheader.biWidth;
	int nHeight = (int)bmpheader.biHeight;

	int BitNum;
	int BmpCol;
	if(bmpheader.biBitCount==24)
	{
		BitNum = 3;
		BmpCol = (nWidth*3+3)/4*4;
	}
	else
	{
		BitNum = 1;
		BmpCol = (nWidth+3)/4*4;
	}
	DWORD dwSize=(DWORD)BmpCol*nHeight;
	///////////////////////////////////////////////
	//For Block Open
	BYTE *pNewData = (BYTE *)malloc(dwSize);
	if(pNewData==NULL)
	{
		AfxMessageBox("没有足够内存来装载该BMP文件!");
		file.Close();
		return;
	}

	RGBQUAD Rgb;
	BYTE *Line;
	int FileBmpCol;
	COLORREF *Pal = new COLORREF[256];
	int RealColorNum;
	if(bmpheader.biBitCount == 1)
	{
		if(bmpheader.biClrUsed==0)
			RealColorNum = 2;
		else
			RealColorNum = (int)bmpheader.biClrUsed;
		for(int i=0;i<RealColorNum;i++)
		{
			file.Read(&Rgb,sizeof(RGBQUAD));
			Pal[i] = RGB(Rgb.rgbRed,Rgb.rgbGreen,Rgb.rgbBlue);
		}
		FileBmpCol =(int)((bmpheader.biWidth+31)/32*4);
	}
	else if(bmpheader.biBitCount == 4)
	{
		if(bmpheader.biClrUsed==0)
			RealColorNum = 16;
		else
			RealColorNum = (int)bmpheader.biClrUsed;
		for(int i=0;i<RealColorNum;i++)
		{
			file.Read(&Rgb,sizeof(RGBQUAD));
			Pal[i] = RGB(Rgb.rgbRed,Rgb.rgbGreen,Rgb.rgbBlue);
		}
		FileBmpCol = (int)((bmpheader.biWidth+7)/8*4);
	}
	else if(bmpheader.biBitCount == 8)
	{
		if(bmpheader.biClrUsed==0)
			RealColorNum = 256;
		else
			RealColorNum = (int)bmpheader.biClrUsed;
		for(int i=0;i<RealColorNum;i++)
		{
			file.Read(&Rgb,sizeof(RGBQUAD));
			Pal[i] = RGB(Rgb.rgbRed,Rgb.rgbGreen,Rgb.rgbBlue);
		}
		FileBmpCol = (int)((bmpheader.biWidth+3)/4)*4;
	}
	else
		FileBmpCol = (int)((bmpheader.biWidth*3+3)/4)*4;
	
	//Begin Read Data
	Line = new BYTE[FileBmpCol];
	int Count;

	int Process=0;
	int RPro;
					
	for(int i=0;i<nHeight;i++)
	{
		RPro=(int)(100L*i/(nHeight-1));
		if(RPro>Process)
		{
			for(int j=0;j<RPro-Process;j++)
				UpdateStatusBar();
			Process=RPro;
		}
		file.Read(Line,FileBmpCol);
		//DeCode
		if(bmpheader.biBitCount == 1)
		{
			for(Count=0;Count<nWidth/8;Count++)
				for(int j=0;j<8;j++)
					pNewData[(DWORD)i*BmpCol+Count*8+j] =
						(Line[Count]>>(8-j-1))&1;
			for(int j=Count*8;j<nWidth;j++)
				pNewData[(DWORD)i*BmpCol+j] =
					(Line[Count]>>(7-(j-Count*8)))&1;
		}
		else if(bmpheader.biBitCount == 4)
		{
			for(Count=0;Count<nWidth/2;Count++)
				for(int j=0;j<2;j++)
					pNewData[(DWORD)i*BmpCol+Count*2+j] =
						(Line[Count]>>(4*(2-j-1)))&0xf;
			for(int j=Count*2;j<nWidth;j++)
				pNewData[(DWORD)i*BmpCol+j] =
					(Line[Count]>>(4*(2-(j-Count*2)-1)))&0xf;
		}
		else if(bmpheader.biBitCount == 8)
		{
			for(Count=0;Count<nWidth;Count++)
				pNewData[(DWORD)i*BmpCol+Count] = Line[Count];
		}
		else
		{
			for(Count=0;Count<BmpCol;Count++)
				pNewData[(DWORD)i*BmpCol+Count] = Line[Count];
		}
	}
	delete []Line;	
	file.Close();
  
	CRSIPApp *theApp = (CRSIPApp *)AfxGetApp();
	if(BitNum==1)
	{
		CRSImage *pRSImage = new CRSImage();
		pRSImage->m_nImgType = IMAGE_SINGLEBAND;
		pRSImage->m_pImgData = pNewData;
		pRSImage->m_nImgHeight = nHeight;
		pRSImage->m_nImgWidth = nWidth;
		if(pRSImage->m_pPal!=NULL)
			delete []pRSImage->m_pPal;
		pRSImage->m_pPal = Pal;

		theApp->CreateNewImageDoc(pRSImage,szFileFullName);			
	}
	else if(BitNum==3)
	{
		CRSImage *pRSImage = new CRSImage();
		pRSImage->m_nImgType = IMAGE_COMBINE;
		pRSImage->m_pImgData = pNewData;
		pRSImage->m_nImgHeight = nHeight;
		pRSImage->m_nImgWidth = nWidth;

		theApp->CreateNewImageDoc(pRSImage,szFileFullName);
	}
}

void CRSIPApp::ImportTapeFile(LPCTSTR szFileFullName)
{
	int BFlag;
		//1:BIL
		//2:BSQ
		//3:BIP;
	char szTapeFileName[256];
	strcpy(szTapeFileName,szFileFullName);
	int Strlen = strlen(szFileFullName);
	if(stricmp(szTapeFileName+Strlen-3,"BIL")==0)
		BFlag = 1;
	else if(stricmp(szTapeFileName+Strlen-3,"BSQ")==0)
		BFlag = 2;
	else  if(stricmp(szTapeFileName+Strlen-3,"BIP")==0)
		BFlag = 3;
	
	CFile file;
		
	if(0==file.Open(szFileFullName,CFile::modeRead))
	{
		AfxMessageBox("不能打开磁带文件!");
		return;
	}
	
	CTapeImageInfo infoDlg;
	if(infoDlg.DoModal()==IDOK)
	{		
		int Height = infoDlg.m_nImageHeight;
		int Width = infoDlg.m_nImageWidth;
		int BandNum = infoDlg.m_nBandNum;
		int TotalBytes = 0;
		int BandGapBytes = 0;
		
		int BmpCol = (Width+3)/4*4;
		BYTE *Line;
		LPBYTE * ppImageData = new LPBYTE[BandNum];
		
		DWORD size = (DWORD)BmpCol*Height;
	
		BeginWaitCursor();

		for(int i=0; i<BandNum; i++)						//band
		{
			ppImageData[i] = (BYTE *)malloc(size);
			if(ppImageData[i]==NULL)
			{
				AfxMessageBox("没有足够内存装载该磁带文件!");
				file.Close();
				return;
			}
		}

		if(BFlag==1 || BFlag==3)//BIL Or Bip
		{
			TotalBytes = BandNum*Width;
			Line = new BYTE[TotalBytes];
			
			int Process=0;
			int RPro;
			int LineOrder=0;

			for(int i=0; i<Height; i++)						//row
			{
				RPro=(int)(100.0 * (LineOrder+1) / Height);
				if(RPro > Process)
				{
					for(int j=0; j<RPro-Process; j++)
						UpdateStatusBar();
					Process=RPro;
				}
				
				file.Read(Line,TotalBytes);
				if(BFlag==1)
					for(int j=0; j<BandNum; j++)
					{
						for(int n=0; n<Width; n++)			//col
							ppImageData[j][(Height-i-1)*BmpCol+n] =
								Line[j*(Width+BandGapBytes)+n];
					}
				else	
					for(int j=0; j<BandNum; j++)
					{
						for(int n=0; n<Width; n++)			//col
							ppImageData[j][(Height-i-1)*BmpCol+n] =
								Line[BandNum*n+j];
					}
			}
		}
		else if(BFlag==2)
		{
			Line = new BYTE[Width];

			for(int n=0; n<BandNum; n++)
			{
				int Process=0;
				int RPro;
				int LineOrder=0;
				for(i=0; i<Height; i++)						//row
				{
					RPro=(int)(100.0 * (LineOrder+1) / Height);
					if(RPro>Process)
					{
						for(int j=0; j<RPro-Process; j++)
							UpdateStatusBar();
						Process=RPro;
					}

					file.Read((ppImageData[n]+(DWORD)BmpCol*(Height-i-1)),	//col
					  (long)Width);
				}//End of Read a block
			}//End of Read a band
		}

		delete []Line;
		file.Close();

		CRSIPApp *theApp = (CRSIPApp *)AfxGetApp();

		for(i=0;i<BandNum;i++)
		{
			CRSImage *pNewRsImage = new CRSImage();
						
			pNewRsImage->m_pImgData = ppImageData[i];
			pNewRsImage->m_nImgHeight = Height;
			pNewRsImage->m_nImgWidth = Width;
			pNewRsImage->m_nImgType = IMAGE_SINGLEBAND;

			theApp->CreateNewImageDoc(pNewRsImage,szFileFullName);
		}
		delete []ppImageData;

		EndWaitCursor();
	}
}

⌨️ 快捷键说明

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