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

📄 aiedlg.cpp

📁 又VC++实现的基于TWAIN的扫描仪图像输入处理软件
💻 CPP
📖 第 1 页 / 共 4 页
字号:

	if(m_bShowSHE)
	{
	  m_pSHEDlg->DestroyWindow();
	  delete m_pSHEDlg;
	  m_pSHEDlg = new CSHE(this);
	  m_pSHEDlg->Create();
	}
	if(m_bShowCE)
	{
	  m_pCEDlg->DestroyWindow();
	  delete m_pCEDlg;
      m_pCEDlg = new CCEDlg(this);
	  m_pCEDlg->Create();
	}
	if(m_pBCEDlg)
	{
	  m_pBCEDlg->DestroyWindow();
	  delete m_pBCEDlg;
      m_pBCEDlg = new CBCEDlg(this);
	  m_pBCEDlg->Create();
	}
    pViewWnd->InvalidateRect(NULL);
    CDialog::OnCancel(); 
}

//////////////////////////////////////////////////////////////////
//黑白图像的阈值
/////////////////////////////////////////////////////////////////
LONG CAIEDlg::AdjustPreLimit(int factor,int nChannel )
{
  
  int limit;
  limit=factor;

  HANDLE hDIB0 =pScanner-> GetHandleofPreviewBMP();
  HANDLE hDIB1 = pScanner->GetHandleofAdjustedPreviewBMP();	
  int i;
  LPSTR    lpDIBHdr;           
  LPSTR    lpDIBHdr1;
  LPSTR    lpDIB0Bits;           
  LPSTR    lpDIB1Bits;           
  CRect rect;

  if (hDIB0 == NULL||hDIB1 == NULL)
	  return FALSE;
  lpDIBHdr  = (LPSTR) ::GlobalLock((HGLOBAL) hDIB0);
  lpDIB0Bits = ::FindDIBBits(lpDIBHdr);
  lpDIBHdr1  = (LPSTR) ::GlobalLock((HGLOBAL) hDIB1);
  lpDIB1Bits = ::FindDIBBits(lpDIBHdr1);

  int cxDIB = (int) ::DIBWidth(lpDIBHdr);        
  int cyDIB = (int) ::DIBHeight(lpDIBHdr);      
  int colornum=(int)::DIBNumColors(lpDIBHdr);
  int nBitCount;
  int nTemp; 

  heibai=TRUE;
  if(be==TRUE)
  {
	if(colornum==2)
	{
	  nBitCount=cxDIB*cyDIB/8;
	}
	if(colornum==256)
	{
      nBitCount=cxDIB*cyDIB;
	}
    else
	{
	  nBitCount=cxDIB*cyDIB*3;
	}
  }
   
  if(colornum==256)
  {
    for(i=0;i<nBitCount;i++)
	{
		nTemp=*(unsigned char*)(lpDIB0Bits);
		if(nTemp<=limit)
		{
          *(unsigned char*)(lpDIB1Bits)=0;
		}
		else
		{
          *(unsigned char*)(lpDIB1Bits)=255;
		}
        (unsigned char*)lpDIB0Bits++;  
        (unsigned char*)lpDIB1Bits++;
	  }
	}
	if(colornum==0)
	{
	  for(i=0;i<nBitCount;i++)
	  {		
		nTemp=(int)(*(unsigned char*)(lpDIB0Bits)*0.2+*(unsigned char*)(lpDIB0Bits+1)*0.21+*(unsigned char*)(lpDIB0Bits+2)*0.59);
		if( nTemp<=limit )
		{
		  *(unsigned char*)(lpDIB1Bits)=0;
          *(unsigned char*)(lpDIB1Bits+1)=0;
          *(unsigned char*)(lpDIB1Bits+2)=0;
		}
		if( nTemp>limit )
		{
		  *(unsigned char*)(lpDIB1Bits)=255;
          *(unsigned char*)(lpDIB1Bits+1)=255;
          *(unsigned char*)(lpDIB1Bits+2)=255;
		}
		(unsigned char*)lpDIB0Bits++;
		(unsigned char*)lpDIB0Bits++;
        (unsigned char*)lpDIB0Bits++;
        (unsigned char*)lpDIB1Bits++;
		(unsigned char*)lpDIB1Bits++;
        (unsigned char*)lpDIB1Bits++;
		i++;
		i++;
	  }
	}
   ::GlobalUnlock((HGLOBAL) hDIB0);
   ::GlobalUnlock((HGLOBAL) hDIB1);
   
    GetDlgItem(IDC_STATIC_ENHANCED)->GetClientRect(rect);
	GetDlgItem(IDC_STATIC_ENHANCED)->ClientToScreen(rect);
	ScreenToClient(rect);
	InvalidateRect( &rect, TRUE );

   return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
//图像增强过程,被Adjust**等调用,具体实现校正过程
//校正次序:明度对比度高光阴影
////////////////////////////////////////////////////////////////////////////
void CAIEDlg::jiaose() 
{
    int Factor;
	int i;
    //明亮度的校正过程
	Factor=GetPrivateProfileInt("pbrightness2","brightR",128,InitDir2);
	factorBR=Factor-128;
    Factor=GetPrivateProfileInt("pbrightness2","brightG",128,InitDir2);
	factorBG=Factor-128;
    Factor=GetPrivateProfileInt("pbrightness2","brightB",128,InitDir2);
	factorBB=Factor-128;

	for(i=0;i<256;i++)
	{
      IndexCanR00[i]=IndexCanR[i]+factorBR;
	  IndexCanG00[i]= IndexCanG[i]+factorBG;
	  IndexCanB00[i]= IndexCanB[i]+factorBB;
	}

	//对比度校正过程
    Factor=GetPrivateProfileInt("pcontrast2","contrastR",128,InitDir2);
	factorCR=Factor/128.0;
    Factor=GetPrivateProfileInt("pcontrast2","contrastG",128,InitDir2);
	factorCG=Factor/128.0;
    Factor=GetPrivateProfileInt("pcontrast2","contrastB",128,InitDir2);
	factorCB=Factor/128.0;

    for(i=0;i<256;i++)
	{
        IndexCanR00[i]=(int)(128+(double)(IndexCanR00[i]-128)*factorCR);
	    IndexCanG00[i]=(int)(128+(double)(IndexCanG00[i]-128)*factorCG);
	    IndexCanB00[i]=(int)(128+(double)( IndexCanB00[i]-128)*factorCB);
	}
    
	//阴影和高光的校正
    factorHR=GetPrivateProfileInt("pShe","highR",255,InitDir2);
    factorHG=GetPrivateProfileInt("pShe","highG",255,InitDir2);
	factorHB=GetPrivateProfileInt("pShe","highB",255,InitDir2);
   
	factorSR=GetPrivateProfileInt("pShe","shadeR",0,InitDir2);
    factorSG=GetPrivateProfileInt("pShe","shadeG",0,InitDir2);
    factorSB=GetPrivateProfileInt("pShe","shadeB",0,InitDir2);

    for(i=0;i<256;i++)
	{
	   if(IndexCanR00[i]>=factorHR)
	    IndexCanR00[i]=255;
	   if(IndexCanR00[i]<=factorSR)
		IndexCanR00[i]=0;

       if(IndexCanG00[i]>=factorHG)
	    IndexCanG00[i]=255;
	   if(IndexCanG00[i]<=factorSG)
		IndexCanG00[i]=0;

       if(IndexCanB00[i]>=factorHB)
	    IndexCanB00[i]=255;
	   if(IndexCanB00[i]<=factorSB)
		IndexCanB00[i]=0;
	}

	//GAMMA校正,就是将校正结果映射到索引表中
	for(i=0;i<256;i++)
	{
       IndexCanR00[i]=IndexCanR1[IndexCanR00[i]];
       IndexCanG00[i]=IndexCanG1[IndexCanG00[i]];
       IndexCanB00[i]=IndexCanB1[IndexCanB00[i]];
	}

}

//////////////////////////////////////////////////////////////
//关闭窗口
//////////////////////////////////////////////////////////////
void CAIEDlg::OnGuanbi() 
{
   char IniFile[120];
   GetWindowsDirectory(IniFile,sizeof(IniFile));
   char* pFileName=lstrcat(IniFile,"\\twain_32\\MTIScanner\\preview.bmp");  
   HDIB hbmp;
   	 
   hbmp=::ReadDIBFile( pFileName );
   pScanner->SetHandleofPreviewBMP(hbmp);
   hbmp=::ReadDIBFile( pFileName );
   pScanner->SetHandleofAdjustedPreviewBMP(hbmp);
   HANDLE hDIB0 = pScanner->GetHandleofPreviewBMP();
   HANDLE hDIB1 = pScanner->GetHandleofPreviewBMP();

   LPSTR    lpDIBHdr;
   LPSTR    lpDIBHdr1;
   LPSTR    lpDIB0Bits;         
   LPSTR    lpDIB1Bits; 
   int i;
   int nTemp;
    
   if (hDIB0 == NULL||hDIB1 == NULL)
	return ;
		
   lpDIBHdr  = (LPSTR) ::GlobalLock((HGLOBAL) hDIB0);
   lpDIB0Bits = ::FindDIBBits(lpDIBHdr);

   lpDIBHdr1  = (LPSTR) ::GlobalLock((HGLOBAL) hDIB1);
   lpDIB1Bits = ::FindDIBBits(lpDIBHdr1);

   int cxDIB = (int) ::DIBWidth(lpDIBHdr);         
   int cyDIB = (int) ::DIBHeight(lpDIBHdr);      
   int colornum=(int)::DIBNumColors(lpDIBHdr);
   int nBitCount;
   
   //显示适当图像
   pScanner->m_nColor=GetPrivateProfileInt("color num","color",16777216,InitDir2); 
  
   pScanner->m_nDPI= GetPrivateProfileInt("resoultion","reso",300,InitDir2);	//WZL 2004-6-18
   
   int channel;
   channel=GetPrivateProfileInt("xianzhen","channel",42,InitDir2);
/* 按照原来在进行整体调整*/
 	if(colornum==2)
	{
	  nBitCount=cxDIB*cyDIB/8;
      for(i=0;i<nBitCount;i++)
	  {	
		if(channel==44)
		{
		 *(unsigned char*)(lpDIB1Bits) =  IndexCanR00[*(unsigned char*)(lpDIB0Bits)];
		}
		if(channel==42)
		{
		 *(unsigned char*)(lpDIB1Bits) =  IndexCanG00[*(unsigned char*)(lpDIB0Bits)];
		}
        if(channel==41)
		{
		 *(unsigned char*)(lpDIB1Bits) =  IndexCanB00[*(unsigned char*)(lpDIB0Bits)];
		}
	    (unsigned char*)lpDIB0Bits++;
        (unsigned char*)lpDIB1Bits++;
	  } 
	}
	else if(colornum==256)
	{
       nBitCount=cxDIB*cyDIB;
       for(i=0;i<nBitCount;i++)
	   {		
		  if(channel==44)
		  {
		    *(unsigned char*)(lpDIB1Bits) =  IndexCanR00[*(unsigned char*)(lpDIB0Bits)];
		  }
		  if(channel==42)
		  {
		    *(unsigned char*)(lpDIB1Bits) =  IndexCanG00[*(unsigned char*)(lpDIB0Bits)];
		  }
          if(channel==41)
		  {
		    *(unsigned char*)(lpDIB1Bits) =  IndexCanB00[*(unsigned char*)(lpDIB0Bits)];
		  }
	     (unsigned char*)lpDIB0Bits++;
         (unsigned char*)lpDIB1Bits++;
	   } 
	}
    else
	{
	   nBitCount=cxDIB*cyDIB*3;
	   for(i=0;i<nBitCount;i++)
	   {		
		   nTemp=(int)(*(unsigned char*)(lpDIB0Bits)*0.2+*(unsigned char*)(lpDIB0Bits+1)*0.21+*(unsigned char*)(lpDIB0Bits+2)*0.59);
		   if(pScanner->m_nColor==256)
		   {
              if(channel==44)
			  {
		        *(unsigned char*)(lpDIB1Bits) =  IndexCanR00[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
                *(unsigned char*)(lpDIB1Bits) =  IndexCanR00[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
                *(unsigned char*)(lpDIB1Bits) =  IndexCanR00[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 

			  }
		      if(channel==42)
			  {
		         *(unsigned char*)(lpDIB1Bits) =  IndexCanG00[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
                *(unsigned char*)(lpDIB1Bits) =  IndexCanG00[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
                *(unsigned char*)(lpDIB1Bits) =  IndexCanG00[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
			  }
             if(channel==41)
			 {
		       *(unsigned char*)(lpDIB1Bits) =  IndexCanB00[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
                *(unsigned char*)(lpDIB1Bits) =  IndexCanB00[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
                *(unsigned char*)(lpDIB1Bits) =  IndexCanB00[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
			 }  
		   }
		   else
		   {
		     *(unsigned char*)(lpDIB1Bits) =  IndexCanB00[*(unsigned char*)(lpDIB0Bits)];
	         (unsigned char*)lpDIB0Bits++;
             (unsigned char*)lpDIB1Bits++;
		     *(unsigned char*)(lpDIB1Bits) =  IndexCanG00[*(unsigned char*)(lpDIB0Bits)];
	         (unsigned char*)lpDIB1Bits++;
		     (unsigned char*)lpDIB0Bits++;
		     *(unsigned char*)(lpDIB1Bits) =  IndexCanR00[*(unsigned char*)(lpDIB0Bits)];
		   	 (unsigned char*)lpDIB1Bits++;
             (unsigned char*)lpDIB0Bits++;
		   }
		   i++;
		   i++;
		} 
	}
    ::GlobalUnlock((HGLOBAL) hDIB0);
    ::GlobalUnlock((HGLOBAL) hDIB1);
	pViewWnd->InvalidateRect(NULL);
    CDialog::OnCancel();
	
}


///////////////////////////////////////////////////////////////////
//显示图像校正结构
////////////////////////////////////////////////////////////////
void CAIEDlg::display() 
{
	HANDLE hDIB0 = pScanner->GetHandleofPreviewBMP();
	HANDLE hDIB1 = pScanner->GetHandleofAdjustedPreviewBMP();

	int i;
		__int16 nTemp;

	LPSTR    lpDIBHdr;
	LPSTR    lpDIBHdr1;
	LPSTR    lpDIB0Bits;         
	LPSTR    lpDIB1Bits;          
  
	CRect rect;
	if (hDIB0 == NULL||hDIB1 == NULL)
	return ;
		
	lpDIBHdr  = (LPSTR) ::GlobalLock((HGLOBAL) hDIB0);
	lpDIB0Bits = ::FindDIBBits(lpDIBHdr);

	lpDIBHdr1  = (LPSTR) ::GlobalLock((HGLOBAL) hDIB1);
	lpDIB1Bits = ::FindDIBBits(lpDIBHdr1);

	int cxDIB = (int) ::DIBWidth(lpDIBHdr);         
	int cyDIB = (int) ::DIBHeight(lpDIBHdr);      
	int colornum=(int)::DIBNumColors(lpDIBHdr);
	int nBitCount;

    pScanner->m_nColor=GetPrivateProfileInt("color num","color",16777216,InitDir2); 
	
    int channel;
    channel=GetPrivateProfileInt("xianzhen","channel",42,InitDir2);
 /* 按照原来在进行整体调整*/
 	
	   nBitCount=cxDIB*cyDIB*3;
	   for(i=0;i<nBitCount;i++)
	   {		
		   nTemp=(int)(*(unsigned char*)(lpDIB0Bits)*0.2+*(unsigned char*)(lpDIB0Bits+1)*0.21+*(unsigned char*)(lpDIB0Bits+2)*0.59);
		   if(pScanner->m_nColor==256)
		   {
              if(channel==44)
			  {
		        *(unsigned char*)(lpDIB1Bits) =  IndexCanR00[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
                *(unsigned char*)(lpDIB1Bits) =  IndexCanR00[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
                *(unsigned char*)(lpDIB1Bits) =  IndexCanR00[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 

			  }
		      if(channel==42)
			  {
		         *(unsigned char*)(lpDIB1Bits) =  IndexCanG00[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
                *(unsigned char*)(lpDIB1Bits) =  IndexCanG00[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
                *(unsigned char*)(lpDIB1Bits) =  IndexCanG00[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
			  }
             if(channel==41)
			 {
		       *(unsigned char*)(lpDIB1Bits) =  IndexCanB00[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
                *(unsigned char*)(lpDIB1Bits) =  IndexCanB00[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
                *(unsigned char*)(lpDIB1Bits) =  IndexCanB00[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
			 }  
		   }
		   else
		   {
		     *(unsigned char*)(lpDIB1Bits) =  IndexCanB00[*(unsigned char*)(lpDIB0Bits)];
	         (unsigned char*)lpDIB0Bits++;
             (unsigned char*)lpDIB1Bits++;
		     *(unsigned char*)(lpDIB1Bits) =  IndexCanG00[*(unsigned char*)(lpDIB0Bits)];
	         (unsigned char*)lpDIB1Bits++;
		     (unsigned char*)lpDIB0Bits++;
		     *(unsigned char*)(lpDIB1Bits) =  IndexCanR00[*(unsigned char*)(lpDIB0Bits)];
		   	 (unsigned char*)lpDIB1Bits++;
             (unsigned char*)lpDIB0Bits++;
		   }
		   i++;
		   i++;
		} 
	
  ::GlobalUnlock((HGLOBAL) hDIB0);
  ::GlobalUnlock((HGLOBAL) hDIB1);
	
}

⌨️ 快捷键说明

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