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

📄 prot.cpp

📁 又VC++实现的基于TWAIN的扫描仪图像输入处理软件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	static LPSTR lpStart0,lp0;
	static LPSTR lphmem1,lphmem2;

	int x0,y0;//行拼的时候用到的数据
	int y1,y2;//奇偶拼的时候用到的数据
	
	static CScanningProgress* pScanningProgress;
	static CProgressCtrl *pProgressCtrl;

    static int nReadInBytes;
    int nReadInBytes1,nReadInBytes2;
    int downRow;    //实际扫描块的行数
    static int nReadInBytes0;
    TW_UINT16 twRc = TWRC_SUCCESS;
    pTW_IMAGEMEMXFER pMem;
 
	static    LPBITMAPINFO pdib;
    static    BOOL done=FALSE;		
    static    BITMAPINFOHEADER        bi;

    static DWORD bytesout = 0;
    TW_UINT32 maxrows;
    TW_UINT32 RowsWritten;
     
    static int count = 0;
    static int number2=0;
	static int n6=1;
	static double number1;

    static int biWidth,biSizeImage,biBitCount;

	int nCount=0;
	int i;
	int n1,n2,n3;
 
    int huigui;
	char str[36];
   
	CString	m_sHuiGuiType;
	GetPrivateProfileString("huigui type","type","零点位置",str,36,InitDir2);
    m_sHuiGuiType=_T(str); 
 
    if(m_sHuiGuiType=="零点位置")
	{
      huigui=0;
	}
    if(m_sHuiGuiType=="中间位置")
	{
      huigui=2;
	}
    if(m_sHuiGuiType=="静止不动")
	{
      huigui=1;
	}

    int shuzu;
    shuzu=GetPrivateProfileInt("Shuzu","shuzu",1200,InitDir2);

    LogMessage("MemXfer Start\r\n");
	pScanner->m_nColor = GetPrivateProfileInt("color num","color",16777216,InitDir2);

	//测试,用于扫描起始显示时间   
     time_t date1_t;
	 time(&date1_t);		
	 int Hour,Minute,Second;
	 CTime time1(date1_t);
 
    CWaitCursor wait;
   //根据不同颜色的图象,对从SCSI接口中读取的数据,进行不同的处理
   if(pScanner->m_nColor==16777216)   //彩色图像处理
   {
     if (done)
     {
        pMem = (pTW_IMAGEMEMXFER)(pTWMsg->pData);
        pMem->BytesWritten = 0L;

        done = FALSE;
        count    = 0;
		number2  = 0;
		number1  = 0;
		n6=1;
	    bytesout = 0;

		GlobalUnlock(hmem1);
		GlobalFree(hmem1);

		GlobalUnlock(bmp);
		GlobalFree(bmp);

		GlobalUnlock(hbuffer1);
		GlobalFree(hbuffer1);

		GlobalUnlock(hmem);
		GlobalFree(hmem);

		GlobalUnlock(hbuffer2);
		GlobalFree(hbuffer2);


    	_lclose(fh);

		DestroyWindow(pScanningProgress->m_hWnd);
		delete pScanningProgress;

		pMainDialog->m_bModal = FALSE;

        LogMessage("XferDone returned\n");
        return(TWRC_XFERDONE);
     }
     
     //分辨率为连续可调时候的拼色参数
	 //x0表示R和G之间的差距,y0表示R和B之间的差距
	 int reso1;
	 x0=0;
	 y0=0;
	 reso1=25;
     
	 while(pScanner->m_nDPI>reso1)
	 {
		 reso1=reso1+50;
		 x0++;
		 y0=2*x0;
	 }
   
     int pjrow;
//	 pjrow=(int)(pScanner->m_nDPI/100.0+0.5);
	 pjrow=(int)(pScanner->m_nDPI/100.0);
	 y2=pjrow;//表示奇偶差距
	 y1=y2+y0; //表示需要总的读进来的数据

//****************************************************************************************
//  以下代码是处理数据过程,包括对数据的接收,拼齐等处理                                //
//****************************************************************************************
     // 计算传输数据时数据量的大小
		bi.biSize = 40;
	    bi.biWidth = (long)(((pScanner->m_rtScanZoom).right-(pScanner->m_rtScanZoom).left)/FuMian*(pScanner->m_nDPI));
	    bi.biHeight = (long)(((pScanner->m_rtScanZoom).bottom-(pScanner->m_rtScanZoom).top)/FuMian*(pScanner->m_nDPI));
		bi.biPlanes = 1;
	    bi.biCompression = 0;
	    bi.biClrUsed = 0;
	    bi.biClrImportant = 0;
		
		//计算奇偶数组
        shuzu1((long)((pScanner->m_rtScanZoom).left/FuMian*shuzu),pScanner->m_nDPI);
	    switch(pScanner->m_nColor)
		{
		  case  16777216:
		    bi.biBitCount = 24;
		    bi.biSizeImage = bi.biWidth*bi.biHeight*3;
			break;
		  case 256:
			bi.biBitCount = 8;
		    bi.biSizeImage = bi.biWidth*bi.biHeight;
			break;
		  case 2:
            bi.biWidth=(bi.biWidth/8)*8;
			bi.biBitCount = 1;
			bi.biSizeImage = bi.biWidth*bi.biHeight/8;
			//bi.biSizeImage = bi.biWidth*bi.biHeight;
		    break;
		}

		bi.biXPelsPerMeter = pScanner->m_nDPI;
		bi.biYPelsPerMeter = pScanner->m_nDPI;

	    dwBits = bi.biSizeImage;
		dwFileLen = bi.biSize + (DWORD)PaletteSize (&bi) + dwBits;
		number1=dwBits/50;
		pdib = ( LPBITMAPINFO )GlobalLock(bmp);	  
				
		nReadInBytes=(1044480)/(bi.biBitCount*bi.biWidth/8);
		nReadInBytes=nReadInBytes*(bi.biBitCount*bi.biWidth/8);
        nPrePos=0;	

    //数据传输太大 ,退出 
    if (count > 100000)
    {   
        if (TimerOut == 99999) 
            MessageBox(NULL,"The source aborts a memory transfer","Sample Source",MB_OK);
        else
           	MessageBox(hAppWnd, details, "Sample Source Error:Timer is OUT", MB_OK);
        
        pMem = (pTW_IMAGEMEMXFER)(pTWMsg->pData);
        pMem->BytesWritten = 0L;

        bytesout = 0;
        done = FALSE;

        count = 0;
        number2=0;
		number1=0;
		n6=1;
		
		GlobalUnlock(hmem1);
		GlobalFree(hmem1);
		GlobalUnlock(hbuffer1);
		GlobalFree(hbuffer1);
	
		GlobalUnlock(hbuffer2);
		GlobalFree(hbuffer2);

        GlobalUnlock(hbuffer3);
		GlobalFree(hbuffer3); 
		
        return(TWRC_XFERDONE);
    }
     
    //扫描数据的第一块
	 if(count==0)
	  { 
       //建立进程条窗口
       pScanningProgress = new CScanningProgress;
       pScanningProgress->Create(IDD_DIALOG_SCANNING_PROGRESS,NULL);
    
	 }
     	  
	 //判断是否终止扫描过程
	 /*MSG Cancelmsg;
	 PeekMessage(&Cancelmsg,pScanningProgress->m_hWnd,WM_KEYFIRST,WM_KEYLAST,PM_REMOVE);
	 if(Cancelmsg.message ==WM_KEYDOWN)
	 {
	   if(Cancelmsg.wParam == 'q' | Cancelmsg.wParam =='Q')
	   {
	    LogMessage("XferCancel returned\n");

		pMem = (pTW_IMAGEMEMXFER)(pTWMsg->pData);
		pMem->BytesWritten = 0L;

		bytesout = 0;
		done = FALSE;

		count = 0;
        number2=0;
		number1=0;
		n6=1; 

		GlobalUnlock(hmem1);
		GlobalFree(hmem1);
		GlobalUnlock(bmp);
		GlobalFree(bmp);
		GlobalUnlock(hbuffer1);
		GlobalFree(hbuffer1);

		GlobalUnlock(hbuffer2);
		GlobalFree(hbuffer2);

        //GlobalUnlock(hbuffer3);
		//GlobalFree(hbuffer3);

		_lclose(fh);

		DestroyWindow(pScanningProgress->m_hWnd );
		delete pScanningProgress;
		pScanningProgress = NULL;
		pMainDialog->m_bModal = FALSE;
	  }
	}*/

     //传输消息设置以及对PHOTOSHOP空间的需要
     switch (pTWMsg->MSG)
	 {
       case MSG_GET:
          LogMessage("MSG_GET\r\n");
          pMem = (pTW_IMAGEMEMXFER)(pTWMsg->pData);
          if (pMem->Memory.Length < 
              GetPrivateProfileInt("Setup Memory Transfer","Min",512,SourceControl)
              || pMem->Memory.Length > 
              GetPrivateProfileInt("Setup Memory Transfer","Max",2048,SourceControl))
		  {
		      return(TWRC_FAILURE);
		  }
	      LogMessage("Incremented pointer\r\n");
          pMem->Compression = TWCP_NONE;
          pMem->BytesPerRow = (bi.biBitCount * bi.biWidth)/8;//3*bi.biWidth;//
         
		  int m;
		  m=bi.biWidth/2;

          //判断PHOTOSHOP一次能接受的行数,不足一行读入一行,分两次送给PHOTOSHOP
          maxrows = pMem->Memory.Length/pMem->BytesPerRow;
		  if(maxrows==0)
		  {
	         pMem->YOffset =bytesout/pMem->BytesPerRow;
             LogMessage("Set structure\r\n");   
             RowsWritten = bytesout/pMem->BytesPerRow;
		     if(count%2==0)
			 {
		       pMem->Columns = m;
			   pMem->XOffset =0;	
		       pMem->BytesWritten =(bi.biBitCount *m)/8;
			 }
		     else
			 {
			   pMem->Columns = bi.biWidth-m;	
			   pMem->BytesWritten =(bi.biBitCount * (bi.biWidth-m))/8;
			   pMem->XOffset =m;
			 }
             pMem->Rows =1;
	    
		    if(count==0)
			{
			  pProgressCtrl = (CProgressCtrl *)pScanningProgress->GetDlgItem(IDC_PROGRESS1);
		      pProgressCtrl->SetRange(0,50);

			  hbuffer2 = GlobalAlloc(GHND, (pMem->Rows+y1)*pMem->BytesPerRow);
			  lpStart2=(LPSTR)GlobalLock(hbuffer2);
			  lpBits2=lpStart2;

              hbuffer1 = GlobalAlloc(GHND, nReadInBytes);
		      lpBits=(LPSTR)GlobalLock(hbuffer1);
			  lpBits1=lpBits;
			  lpStart1=lpBits; 
		
			  if((int)((pMem->Rows+y1)*pMem->BytesPerRow)>nReadInBytes)
			  {
			    n1=((pMem->Rows+y1)*pMem->BytesPerRow)/nReadInBytes;
			    nReadInBytes0=((pMem->Rows+y1)*pMem->BytesPerRow)-n1*nReadInBytes;
			  }
			  else
			  {
		        n1=0;
			    nReadInBytes0=(pMem->Rows+y1)*pMem->BytesPerRow;
			  }
			}
		    else if(count%2==0&&count>0)
			{
			   hbuffer1 = GlobalAlloc(GHND, nReadInBytes);
		       lpBits=(LPSTR)GlobalLock(hbuffer1);
			   lpBits1=lpBits;
			   lpStart1=lpBits;	

			   if((int)((pMem->Rows)*pMem->BytesPerRow)>nReadInBytes)
			   {
				 n1=((pMem->Rows)*pMem->BytesPerRow)/nReadInBytes;
				 nReadInBytes0=((pMem->Rows)*pMem->BytesPerRow)-n1*nReadInBytes;
			   }
			   else
			   {
			      n1=0;
				  nReadInBytes0=(pMem->Rows)*pMem->BytesPerRow;
				}
			  }
            //从下层读取数据块大小为象素数,而不是字节数
		     nReadInBytes1=nReadInBytes/3;
	         nReadInBytes2=nReadInBytes0/3; 
		
	        if(count%2==0)
			{
		       while(n1>0)
			   {
			     //从SCSI接口读取数据
                 downRow=nReadInBytes/pMem->BytesPerRow;
				 SCSI_Read1(lpBits,nReadInBytes,nReadInBytes1,downRow,0);

			     lpBits1=lpStart1;
			     memcpy(lpBits2,lpBits1,nReadInBytes);
			     lpBits2=lpBits2+nReadInBytes;

	             number2=number2+nReadInBytes;
                 if(number2>=(number1*n6))
				 {
			       pProgressCtrl->OffsetPos((int)(number2/(number1*n6)+0.5));
                   nPrePos=nPrePos+1;
                   n6++;
				 }
                 n1--;
			   }
               //从SCSI接口读取数据
               downRow=nReadInBytes0/pMem->BytesPerRow;
			   SCSI_Read1(lpBits,nReadInBytes0,nReadInBytes2,downRow,0);

	           n2=0;
		       lpBits1=lpStart1;
		
		       if(nReadInBytes0!=0)
			   {
		        memcpy(lpBits2,lpBits1,nReadInBytes0);
		        lpBits2=lpBits2+nReadInBytes0;	

                number2=number2+nReadInBytes0;
                if(number2>=(number1*n6))
				{
			      pProgressCtrl->OffsetPos((int)(number2/(number1*n6)+0.5));
                  nPrePos=nPrePos+1;
                  n6++;
				}
			   }

			  //行拼之前,首先要进行奇偶拼,使得在一行
			  pinj();
			  //拼色并将数据写入到PHOTOSHOP缓冲区中,这是行拼
			  hmem1 = GlobalAlloc(GHND, pMem->BytesPerRow);
		      lphmem1 = (LPSTR)GlobalLock(hmem1);
		      lphmem2=lphmem1;

		      lp1=lpStart2;
	          lp2=lp1+x0*pMem->BytesPerRow;
		      lp3=lp1+y0*pMem->BytesPerRow;
			  lp4=lp1+y2*pMem->BytesPerRow;
			  lp5=lp2+y2*pMem->BytesPerRow;
	          lp6=lp3+y2*pMem->BytesPerRow;
            
		 	  int n4;

		      for(n2=0;n2<(int)(pMem->BytesPerRow/3);n2++)

⌨️ 快捷键说明

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