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

📄 settings.cpp

📁 又VC++实现的基于TWAIN的扫描仪图像输入处理软件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
   	//设置位置信息窗口中的信息,主要是改变了图像类型
    m_pPositionInfo->SetPosition(tempRect,0);
	pScanner->SetClororNum(n);

    ::GlobalUnlock((HGLOBAL) hDIB0);
	::GlobalUnlock((HGLOBAL) hDIB1);
	pViewWnd->InvalidateRect( NULL);
}

///////////////////////////////////////////////////////////
//设置扫描分辨率,被主菜单和设置窗口调用                  //
///////////////////////////////////////////////////////////
void CSettings::SetRd(int nRd)
{
  	int nR;
    char str[36];  
	RECT tempRect;
    
	nR=nRd;

    tempRect.top	= (pViewWnd->m_SelectZoom.top)*10;
	tempRect.left	= (pViewWnd->m_SelectZoom.left)*10;
	tempRect.right	= (pViewWnd->m_SelectZoom.right)*10;
	tempRect.bottom = (pViewWnd->m_SelectZoom.bottom)*10;

    pScanner->SetDPI(nR);
    sprintf(str, "%d", nR);
    WritePrivateProfileString("resoultion", "reso", str, InitDir2);
    
    m_pPositionInfo->SetPosition(tempRect,0);
}

///////////////////////////////////////////////////////////
//设置扫描方式,被主菜单和设置窗口调用                   //
///////////////////////////////////////////////////////////
void CSettings::SetScanWay(int n)
{
   CString ScanType;
   RECT tempRect;

   tempRect.top	= (pViewWnd->m_SelectZoom.top)*10;
   tempRect.left	= (pViewWnd->m_SelectZoom.left)*10;
   tempRect.right	= (pViewWnd->m_SelectZoom.right)*10;
   tempRect.bottom = (pViewWnd->m_SelectZoom.bottom)*10;
   if(n==0)
   {
     ScanType="Twain";
   }
   if(n==1)
   {
     ScanType="文件";
   }
   WritePrivateProfileString("scan type", "type", ScanType, InitDir2);
    //设置位置信息窗口中的信息,主要是改变了图像类型
   m_pPositionInfo->SetPosition(tempRect,0);
}

/////////////////////////////////////////////////////////////////////
//回归方式
/////////////////////////////////////////////////////////////////////
void CSettings::SetHuiGuiWay(int n)
{
    CString HuiGuiType;
    RECT tempRect;

    tempRect.top	= (pViewWnd->m_SelectZoom.top)*10;
    tempRect.left	= (pViewWnd->m_SelectZoom.left)*10;
    tempRect.right	= (pViewWnd->m_SelectZoom.right)*10;
    tempRect.bottom = (pViewWnd->m_SelectZoom.bottom)*10;
    if(n==0)
    {
      HuiGuiType="零点位置";
    }
    if(n==2)
    {
      HuiGuiType="中间位置";
    }
    if(n==1)
    {
      HuiGuiType="静止不动";
    }
    WritePrivateProfileString("huigui type", "type", HuiGuiType, InitDir2);
    //设置位置信息窗口中的信息,主要是改变了图像类型
    m_pPositionInfo->SetPosition(tempRect,0);
}

///////////////////////////////////////////////////////////////
//设置颜色通道                                               //
///////////////////////////////////////////////////////////////
void CSettings::SetChannel(int n)
{
   char str[36];
   int channel;
   RECT tempRect;
   
   channel=n;

   tempRect.top	= (pViewWnd->m_SelectZoom.top)*10;
   tempRect.left	= (pViewWnd->m_SelectZoom.left)*10;
   tempRect.right	= (pViewWnd->m_SelectZoom.right)*10;
   tempRect.bottom = (pViewWnd->m_SelectZoom.bottom)*10;

   sprintf(str, "%d", channel);
   WritePrivateProfileString("xianzhen", "channel", str, InitDir2);
   m_pPositionInfo->SetPosition(tempRect,0);
}

///////////////////////////////////////////////////////////
//						 置扫描校正方式                  //
///////////////////////////////////////////////////////////
void CSettings::SetJZmode(int nMode)
{
    char str[36];  
	RECT tempRect;
    
    tempRect.top	= (pViewWnd->m_SelectZoom.top)*10;
	tempRect.left	= (pViewWnd->m_SelectZoom.left)*10;
	tempRect.right	= (pViewWnd->m_SelectZoom.right)*10;
	tempRect.bottom = (pViewWnd->m_SelectZoom.bottom)*10;

	//保存扫描校正方式参数到参数文件
	sprintf(str, "%d", nMode);
  	WritePrivateProfileString("ScanCai_Mod","ScnCaiMod", str, InitDir2); 
  
    m_pPositionInfo->SetPosition(tempRect,0);
}
/*

///////////////////////////////////////////////////////////
//						 设置图像增强方式                //
///////////////////////////////////////////////////////////
void CSettings::SetENAHmode(bool nENAMode)
{
    char str[36];  
	RECT tempRect;
    
    tempRect.top	= (pViewWnd->m_SelectZoom.top)*10;
	tempRect.left	= (pViewWnd->m_SelectZoom.left)*10;
	tempRect.right	= (pViewWnd->m_SelectZoom.right)*10;
	tempRect.bottom = (pViewWnd->m_SelectZoom.bottom)*10;

	//保存扫描校正方式参数到参数文件
	sprintf(str, "%d", nMode);
	WritePrivateProfileString("JiaoZen Mode","JZMode", str, InitDir2); 
    
    m_pPositionInfo->SetPosition(tempRect,0);
}
*/

/////////////////////////////////////////////////////////////
//校正函数执行过程,被CHECK()调用
/////////////////////////////////////////////////////////////
void CSettings::jiaose1()
{
   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;
   int Factor;
   int factorBR,factorBG,factorBB;
   double factorCR,factorCG,factorCB;
   int factorHR,factorHG,factorHB;
   int factorSR,factorSG,factorSB;
   //按照上次校正值修正
   for(i=0;i<256;i++)
	{
	  IndexCanR0[i]=i;
	  IndexCanG0[i]=i;
	  IndexCanB0[i]=i;
   }  
  
    //明亮度的校正过程
	Factor=GetPrivateProfileInt("pbrightnessX","brightR",128,InitDir2);
	factorBR=Factor-128;
    Factor=GetPrivateProfileInt("pbrightnessX","brightG",128,InitDir2);
	factorBG=Factor-128;
    Factor=GetPrivateProfileInt("pbrightnessX","brightB",128,InitDir2);
	factorBB=Factor-128;

	for(i=0;i<256;i++)
	{
      IndexCanR0[i]=IndexCanR0[i]+factorBR;
	  IndexCanG0[i]= IndexCanG0[i]+factorBG;
	  IndexCanB0[i]= IndexCanB0[i]+factorBB;
	}

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

    for(i=0;i<256;i++)
	{
        IndexCanR0[i]=(int)(128+(double)(IndexCanR0[i]-128)*factorCR);
	    IndexCanG0[i]=(int)(128+(double)(IndexCanG0[i]-128)*factorCG);
	    IndexCanB0[i]=(int)(128+(double)( IndexCanB0[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(IndexCanR0[i]>=factorHR)
	    IndexCanR0[i]=255;
	   if(IndexCanR0[i]<=factorSR)
		IndexCanR0[i]=0;

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

       if(IndexCanB0[i]>=factorHB)
	    IndexCanB0[i]=255;
	   if(IndexCanB0[i]<=factorSB)
		IndexCanB0[i]=0;
	}
    
     //读取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::modeRead );
	 }
	 catch( CFileException e )
	 {
	    afxDump << "File could not be opened " << e.m_cause << "\n";
	    return;
	 }
	 fp1->Read(&buffer4[0],768);
  	 fp1->Close(); 

	 for(i=0;i<256;i++)
	 {
       IndexCanR1[i]=buffer4[i];
	 }
     for(i=0;i<256;i++)
	 {
       IndexCanG1[i]=buffer4[i+256];
	 }
     for(i=0;i<256;i++)
	 {
       IndexCanB1[i]=buffer4[i+512];
	 }
	//GAMMA校正,就是将校正结果映射到索引表中
	for(i=0;i<256;i++)
	{
       IndexCanR0[i]=IndexCanR1[IndexCanR0[i]];
       IndexCanG0[i]=IndexCanG1[IndexCanG0[i]];
       IndexCanB0[i]=IndexCanB1[IndexCanB0[i]];
	}
    
   //显示适当图像
   pScanner->m_nColor=GetPrivateProfileInt("color num","color",16777216,InitDir2); 
   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) =  IndexCanR0[*(unsigned char*)(lpDIB0Bits)];
		}
		if(channel==42)
		{
		 *(unsigned char*)(lpDIB1Bits) =  IndexCanG0[*(unsigned char*)(lpDIB0Bits)];
		}
        if(channel==41)
		{
		 *(unsigned char*)(lpDIB1Bits) =  IndexCanB0[*(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) =  IndexCanR0[*(unsigned char*)(lpDIB0Bits)];
		  }
		  if(channel==42)
		  {
		    *(unsigned char*)(lpDIB1Bits) =  IndexCanG0[*(unsigned char*)(lpDIB0Bits)];
		  }
          if(channel==41)
		  {
		    *(unsigned char*)(lpDIB1Bits) =  IndexCanB0[*(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) =  IndexCanR0[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
                *(unsigned char*)(lpDIB1Bits) =  IndexCanR0[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
                *(unsigned char*)(lpDIB1Bits) =  IndexCanR0[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 

			  }
		      if(channel==42)
			  {
		         *(unsigned char*)(lpDIB1Bits) =  IndexCanG0[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
                *(unsigned char*)(lpDIB1Bits) =  IndexCanG0[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
                *(unsigned char*)(lpDIB1Bits) =  IndexCanG0[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
			  }
             if(channel==41)
			 {
		       *(unsigned char*)(lpDIB1Bits) =  IndexCanB0[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
                *(unsigned char*)(lpDIB1Bits) =  IndexCanB0[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
                *(unsigned char*)(lpDIB1Bits) =  IndexCanB0[nTemp];
                (unsigned char*)lpDIB0Bits++;
                (unsigned char*)lpDIB1Bits++; 
			 }  
		   }
		   else
		   {
		     *(unsigned char*)(lpDIB1Bits) =  IndexCanB0[*(unsigned char*)(lpDIB0Bits)];
	         (unsigned char*)lpDIB0Bits++;
             (unsigned char*)lpDIB1Bits++;
		     *(unsigned char*)(lpDIB1Bits) =  IndexCanG0[*(unsigned char*)(lpDIB0Bits)];
	         (unsigned char*)lpDIB1Bits++;
		     (unsigned char*)lpDIB0Bits++;
		     *(unsigned char*)(lpDIB1Bits) =  IndexCanR0[*(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 + -