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

📄 aiedlg.cpp

📁 又VC++实现的基于TWAIN的扫描仪图像输入处理软件
💻 CPP
📖 第 1 页 / 共 4 页
字号:
        sprintf(str, "%d", blackPosB);
        WritePrivateProfileString("pSheX", "blackPosB", str, InitDir2); 
	
        whitePosM=GetPrivateProfileInt("pShe","whitePosM",0,InitDir2);  
        sprintf(str, "%d", whitePosM);
        WritePrivateProfileString("pSheX", "whitePosM", str, InitDir2); 
		
		whitePosR=GetPrivateProfileInt("pShe","whitePosR",0,InitDir2);  
        sprintf(str, "%d", whitePosR);
        WritePrivateProfileString("pSheX", "whitePosR", str, InitDir2); 
		
        whitePosG=GetPrivateProfileInt("pShe","whitePosG",0,InitDir2);  
        sprintf(str, "%d", whitePosG);
        WritePrivateProfileString("pSheX", "whitePosG", str, InitDir2);   
		
        whitePosB=GetPrivateProfileInt("pShe","whitePosB",0,InitDir2);  
        sprintf(str, "%d", whitePosB);
        WritePrivateProfileString("pSheX", "whitePosB", str, InitDir2); 
       

     //在校正窗口中显示校正结果
	 char IniFile0[120];
     GetWindowsDirectory(IniFile0,sizeof(IniFile0));
	 char* pFileName0=lstrcat(IniFile0,"\\twain_32\\MTIScanner\\preview0.bmp");
   
	BITMAPFILEHEADER Bmpfh0;
	BITMAPINFOHEADER Bifh0; 
	if(colornum==0)
	{
      Bifh0.biSize = sizeof(BITMAPINFOHEADER);
	  Bifh0.biWidth = (LONG) cxDIB;
	  Bifh0.biPlanes = 1;

	  Bifh0.biHeight = (LONG)(cyDIB);
	  Bifh0.biBitCount =24;
	  Bifh0.biSizeImage = cyDIB*cxDIB*3;

	  Bmpfh0.bfType= 0x4d42;   //mb
	  Bmpfh0.bfSize= 0x36+Bifh0.biSizeImage;   
	  Bmpfh0.bfReserved1	= 0; 
	  Bmpfh0.bfReserved2	= 0;
	  Bmpfh0.bfOffBits	= 0x36; 
	  Bifh0.biCompression = 0;
	  Bifh0.biXPelsPerMeter =(long)((100*100)/2.54);
	  Bifh0.biYPelsPerMeter =(long)((100*100)/2.54);
	  Bifh0.biClrUsed = 0;
	  Bifh0.biClrImportant = 0;	
	}
//写PREVIEW0.BMP 
	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*)(lpDIB0Bits) = IndexCanR00[*(unsigned char*)(lpDIB0Bits)];
		  }
		  if(channel==42)
		  {
		   *(unsigned char*)(lpDIB0Bits) =  IndexCanG00[*(unsigned char*)(lpDIB0Bits)];
		  }
          if(channel==41)
		 {
		  *(unsigned char*)(lpDIB0Bits) =  IndexCanB00[*(unsigned char*)(lpDIB0Bits)];
		  }
	    (unsigned char*)lpDIB1Bits++;
		(unsigned char*)lpDIB0Bits++;		 
	   }
	 }
	 else if(colornum==256)
	 {
       nBitCount=cxDIB*cyDIB;
       for(i=0;i<nBitCount;i++)
	   {		
		 if(channel==44)
		 {
		  *(unsigned char*)(lpDIB0Bits) =  IndexCanR00[*(unsigned char*)(lpDIB0Bits)];
		 }
		 if(channel==42) 
		 {
		  *(unsigned char*)(lpDIB0Bits) =  IndexCanG00[*(unsigned char*)(lpDIB0Bits)];
		 }
         if(channel==41)
		 {
		  *(unsigned char*)(lpDIB0Bits) =  IndexCanB00[*(unsigned char*)(lpDIB0Bits)];
		 }
	    (unsigned char*)lpDIB1Bits++;
		(unsigned char*)lpDIB0Bits++;		 
	   }
	 }
     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*)(lpDIB0Bits) =  IndexCanR00[nTemp];
                (unsigned char*)lpDIB0Bits++;
                *(unsigned char*)(lpDIB0Bits) =  IndexCanR00[nTemp];
                (unsigned char*)lpDIB0Bits++;
                *(unsigned char*)(lpDIB0Bits) =  IndexCanR00[nTemp];
                (unsigned char*)lpDIB0Bits++;
			  }
		     if(channel==42)
			 {
		         *(unsigned char*)(lpDIB0Bits) =  IndexCanG00[nTemp];
                (unsigned char*)lpDIB0Bits++;
                *(unsigned char*)(lpDIB0Bits) =  IndexCanG00[nTemp];
                (unsigned char*)lpDIB0Bits++;
                *(unsigned char*)(lpDIB0Bits) =  IndexCanG00[nTemp];
                (unsigned char*)lpDIB0Bits++;
               			  }
             if(channel==41)
			 {
		       *(unsigned char*)(lpDIB0Bits) =  IndexCanB00[nTemp];
                (unsigned char*)lpDIB0Bits++;
               *(unsigned char*)(lpDIB0Bits) =  IndexCanB00[nTemp];
                (unsigned char*)lpDIB0Bits++;
               *(unsigned char*)(lpDIB0Bits) =  IndexCanB00[nTemp];
                (unsigned char*)lpDIB0Bits++;
             }  
		   }
		   else
		   {
		     *(unsigned char*)(lpDIB0Bits) =  IndexCanB00[*(unsigned char*)(lpDIB0Bits)];
	         (unsigned char*)lpDIB0Bits++;
             *(unsigned char*)(lpDIB0Bits) =  IndexCanG00[*(unsigned char*)(lpDIB0Bits)];
	         (unsigned char*)lpDIB0Bits++;
		     *(unsigned char*)(lpDIB0Bits) =  IndexCanR00[*(unsigned char*)(lpDIB0Bits)];
		     (unsigned char*)lpDIB0Bits++;
		   }
		   i++;
		   i++;
		} 
	}

    if( !PreviewBitmap.Open( pFileName0, CFile::modeCreate | CFile::modeWrite, &e ) )
	 {
		#ifdef _DEBUG    
		afxDump << "File could not be opened " << e.m_cause << "\n";
		#endif
	}
    if(nColor==2)
	 {
         PreviewBitmap.Seek(62,CFile::begin);  
	 }
	if(nColor==256)
	{
        PreviewBitmap.Seek(1078,CFile::begin); 
	}
	
	if(colornum==0)
	{
	    PreviewBitmap.Write(&Bmpfh0,sizeof(BITMAPFILEHEADER));
	    PreviewBitmap.Write(&Bifh0,sizeof(BITMAPINFOHEADER));
	}
    PreviewBitmap.Write(lpStart,nBitCount);
    PreviewBitmap.Close(); 
      
    hbmp1=::ReadDIBFile( pFileName0 );
    pScanner->SetHandleofPreviewBMP(hbmp1);
    hbmp1=::ReadDIBFile( pFileName0 );
	pScanner->SetHandleofAdjustedPreviewBMP(hbmp1);

    ::GlobalUnlock((HGLOBAL) hDIB0);
	::GlobalUnlock((HGLOBAL) hDIB1);
     
    GetDlgItem(IDC_STATIC_ORIGINAL)->GetClientRect(rect);
	GetDlgItem(IDC_STATIC_ORIGINAL)->ClientToScreen(rect);
	ScreenToClient(rect);
    InvalidateRect( &rect, TRUE );
   }
    
}

/////////////////////////////////////////////////////////
//取消窗口,恢复确认之前的一次结果
////////////////////////////////////////////////////////
void CAIEDlg::OnButton1() 
{
	
	HANDLE hDIB0 = pScanner->GetHandleofPreviewBMP();
	HANDLE hDIB1 = pScanner->GetHandleofAdjustedPreviewBMP();
	int i;

	LPSTR    lpDIBHdr;           
	LPSTR    lpDIBHdr1;
	LPSTR    lpDIB0Bits;          
	LPSTR    lpDIB1Bits;           
  
	CRect rect;
	pScanner->m_nh1=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;

    single=FALSE;

	if(colornum==2)
	{
	  nBitCount=cxDIB*cyDIB/8;
	}
	else if(colornum==256)
	{
      nBitCount=cxDIB*cyDIB;
	}
    else
	{
	  nBitCount=cxDIB*cyDIB*3;
	}

	for(i=0;i<nBitCount;i++)
	{		
	  *(unsigned char*)(lpDIB1Bits) = *(unsigned char*)(lpDIB0Bits);
	  (unsigned char*)lpDIB0Bits++;
	  (unsigned char*)lpDIB1Bits++;
	}

    //恢复到确认之前的值
	 if(m_bShowBCE)
	 {
	  m_pBCEDlg->quexiao();
	 }
	 if(m_bShowSHE)
	 {
      m_pSHEDlg->quexiao1();
	 }

	be=FALSE;
    ::GlobalUnlock((HGLOBAL) hDIB0);
	::GlobalUnlock((HGLOBAL) hDIB1);
	GetDlgItem(IDC_STATIC_ENHANCED)->GetClientRect(rect);
	GetDlgItem(IDC_STATIC_ENHANCED)->ClientToScreen(rect);
	ScreenToClient(rect);
    InvalidateRect( &rect, TRUE );
	 
	if(m_bShowCE)
	{
       COORDINATE p;
       COORDINATE p1;
       CRect rect;

	   if(method==TRUE)
	   {
		 m_pCEDlg->m_PointList.RemoveAll();
		 p.x=0;
		 p.y=0;
		 m_pCEDlg->m_PointList.AddTail(p);
		 p.x=255;
		 p.y=255;
		 m_pCEDlg->m_PointList.AddTail(p);
         m_pCEDlg->Updatem_IndexfromLines( );
         m_pCEDlg->InvalidateRect( NULL ); 
	   }
	   if(method==FALSE)
	   {
         m_pCEDlg->m_PointList.RemoveAll();
         p1.x=0;
		 p1.y=0;
         m_pCEDlg->m_PointList.AddTail(p1);

		 for(i=1;i<26;i++)
		 {
		   p1.x=10*i;
		   p1.y=(int)(255*pow(p1.x/255.0,0.5));
		   m_pCEDlg->m_PointList.AddTail(p1);
		 }
		 p1.x=255;
		 p1.y=255;
		 m_pCEDlg->m_PointList.AddTail(p1);
         m_pCEDlg->Updatem_IndexfromGamma( 0.5 );
	     m_pCEDlg->InvalidateRect( NULL ); 
	   }
	}
  }

/////////////////////////////////////////////////////////////////
//重新置初值,未做任何修正之前的状态
////////////////////////////////////////////////////////////////
void CAIEDlg::OnReset() 
{
    HDIB hbmp;

    char IniFile[120];
    GetWindowsDirectory(IniFile,sizeof(IniFile));
    char* pFileName=lstrcat(IniFile,"\\twain_32\\MTIScanner\\preview.bmp");  
	
 	hbmp=::ReadDIBFile( pFileName );
	pScanner->SetHandleofPreviewBMP(hbmp);
	hbmp=::ReadDIBFile( pFileName );
	pScanner->SetHandleofAdjustedPreviewBMP(hbmp);
	HANDLE hDIB0 = pScanner->GetHandleofPreviewBMP();
	HANDLE hDIB1 = pScanner->GetHandleofAdjustedPreviewBMP();
	
	int i;
    char str[36];
    int bM,bR,bG,bB;
	int cM,cR,cG,cB;
	int hM,hR,hG,hB;
	int sM,sR,sG,sB;
    int lM,lR,lG,lB;
    int blackPosM,blackPosR,blackPosB,blackPosG;
    int whitePosM,whitePosR,whitePosB,whitePosG;

   pScanner->m_nDPI= GetPrivateProfileInt("resoultion","reso",300,InitDir2);	//WZL 2004-6-18


	bM=128; 
    sprintf(str, "%d", bM);
    WritePrivateProfileString("pbrightnessX", "brightM", str, InitDir2);
	
	bR=128; 
    sprintf(str, "%d", bR);
    WritePrivateProfileString("pbrightnessX", "brightR", str, InitDir2);

	bG=128;
    sprintf(str, "%d", bG);
    WritePrivateProfileString("pbrightnessX", "brightG", str, InitDir2);

    bB=128;
    sprintf(str, "%d", bB);
    WritePrivateProfileString("pbrightnessX", "brightB", str, InitDir2); 

    cM=128;
    sprintf(str, "%d", cM);
    WritePrivateProfileString("pcontrastX", "contrastM", str, InitDir2);  
	
	cR=128;
    sprintf(str, "%d", cR);
    WritePrivateProfileString("pcontrastX", "contrastR", str, InitDir2);  

    cG=128;
    sprintf(str, "%d", cG);
    WritePrivateProfileString("pcontrastX", "contrastG", str, InitDir2);

    cB=128;
    sprintf(str, "%d", cB);
    WritePrivateProfileString("pcontrastX", "contrastB", str, InitDir2);

    lM=128; 
    sprintf(str, "%d", lM);
    WritePrivateProfileString("plimitX", "limitM", str, InitDir2);
	
	lR=128; 
    sprintf(str, "%d", lR);
    WritePrivateProfileString("plimitX", "limitR", str, InitDir2);

    lG=128;
    sprintf(str, "%d", lG);
    WritePrivateProfileString("plimitX", "limitG", str, InitDir2);

    lB=128; 
    sprintf(str, "%d", lB);
    WritePrivateProfileString("plimitX", "limitB", str, InitDir2);
             
    sM=0;
    sprintf(str, "%d", sM);
    WritePrivateProfileString("pSheX", "shadeM", str, InitDir2);

	sR=0;
    sprintf(str, "%d", sR);
    WritePrivateProfileString("pSheX", "shadeR", str, InitDir2);

    sG=0;
    sprintf(str, "%d", sG);
    WritePrivateProfileString("pSheX", "shadeG", str, InitDir2);

    sB=0;
    sprintf(str, "%d", sB);
    WritePrivateProfileString("pSheX", "shadeB", str, InitDir2);

	hM=255;
	sprintf(str, "%d", hM);
    WritePrivateProfileString("pSheX", "highM", str, InitDir2); 
	
	hR=255;
	sprintf(str, "%d", hR);
    WritePrivateProfileString("pSheX", "highR", str, InitDir2); 

    hG=255; 
	sprintf(str, "%d", hG);
    WritePrivateProfileString("pSheX", "highG", str, InitDir2);

    hB=255;  
    sprintf(str, "%d", hB);
    WritePrivateProfileString("pSheX", "highB", str, InitDir2);
   
    blackPosM=0; 
    sprintf(str, "%d", blackPosM);
    WritePrivateProfileString("pSheX", "blackPosM", str, InitDir2); 
	
	blackPosR=0; 
    sprintf(str, "%d", blackPosR);
    WritePrivateProfileString("pSheX", "blackPosR", str, InitDir2); 
		
    blackPosG=0; 
    sprintf(str, "%d", blackPosG);
    WritePrivateProfileString("pSheX", "blackPosG", str, InitDir2);   
		
    blackPosB=0; 
    sprintf(str, "%d", blackPosB);
    WritePrivateProfileString("pSheX", "blackPosB", str, InitDir2); 
   
    whitePosM=145;  
    sprintf(str, "%d", whitePosM);
    WritePrivateProfileString("pSheX", "whitePosM", str, InitDir2); 
	
	whitePosR=145;  
    sprintf(str, "%d", whitePosR);
    WritePrivateProfileString("pSheX", "whitePosR", str, InitDir2); 
		
    whitePosG=145;  
    sprintf(str, "%d", whitePosG);
    WritePrivateProfileString("pSheX", "whitePosG", str, InitDir2);   
		
    whitePosB=145;  
    sprintf(str, "%d", whitePosB);
    WritePrivateProfileString("pSheX", "whitePosB", str, InitDir2); 

   //恢复GAMMA校正文件
    char buffer4[768];
	CFile * fp1 = new CFile;

	GetWindowsDirectory(IniFile,sizeof(IniFile));
    char* pFileName1=lstrcat(IniFile,"\\twain_32\\MTIScanner\\Gamma.txt");
   
	try
	{
	   fp1->Open( pFileName1, CFile::modeWrite|CFile::modeCreate);
	}
	catch( CFileException e )
	{
	    afxDump << "File could not be opened " << e.m_cause << "\n";
		return ;
	}
    for(i=0;i<256;i++)
	{
      buffer4[i]=i;
	}
	for(i=0;i<256;i++)
	{
      buffer4[i+256]=i;
	}
    for(i=0;i<256;i++)
	{
      buffer4[i+512]=i;
	} 

	fp1->Write(&buffer4[0],768);
  	fp1->Close(); 

	single=FALSE;

⌨️ 快捷键说明

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