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

📄 recimage.cpp

📁 CT工作站具有打印报告、病历管理、图像处理专家词库等功能
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	/*okSetCaptureParam(hpcih,4,FORM_GRAY10);
	okSetCaptureParam(hpcih,5,FORM_GRAY10);
	okLoadImageFile(hpcih,"c:\\ttt000.bmp",0,BUFFER,0,1);
	okConvertRect(hpcih,FRAME,0,BUFFER,0,1);
	okPlaybackFrom(hpcih,FRAME ,0,1);*/

	//void *buf=okGetBufferAddr(hpcih,0);
	okSetCaptureParam(hpcih,4,FORM_GRAY10);
	short w,h;
	long stride;
	unsigned char *src=(unsigned char*)lParm;
	unsigned char *buf=(unsigned char*)okGetTargetInfo(hpcih,BUFFER,0,&w,&h,&stride);
	/*FILE *fp;
	fp=fopen("c:\\xbbb.raw","rb");
	fread((char*)buf,GetFrameSize(hpcih),1,fp);
	fclose(fp);*/
	//memcpy(buf,(void*)lParm,GetFrameSize(hpcih));
	long fs=GetFrameSize(hpcih);
	memset(buf,0,fs);
	//int w=760;
	int sw,sh,tw,th;
	sw= HIWORD(wParm);
	sh= LOWORD(wParm);
	if(h<sh) th=h;else th=sh;
	if(w<sw) tw=w;else tw=sw;
	int offset=10,pix;
	for(int i=0;i<th;i++)
		for(int j=0;j<tw;j++)
		{
#ifdef COLORPIC
			//pix=src[j*3+i*sw*3]+offset;
			pix=src[j*3+i*sw*3];
			if(pix<4) pix=0;
			pix=pix*RephotoBri/255;
			//pix=j;
#else
			pix=src[j+i*sw];
			if(pix<4)pix=0;
			pix=pix*RephotoBri/255;
#endif
			if(pix>255)
			{
				buf[j*2+(h-i)*stride]=pix%256;
				buf[j*2+(h-i)*stride+1]=pix/256;
			}
			else
				buf[j*2+(h-i)*stride]=pix;

		}
	okPlaybackFrom(hpcih,BUFFER ,0,1);

	//okStopCapture(hpcih);
	//okCaptureTo(hpcih,FRAME,0,1);
	//okPlaybackFrom(hpcih,FRAME,0,1);
	//okPlaybackByBuffer(hpcih,(long)"c:\\xxt000.bmp",0,1);
}

void RecImage::mSetRecCon( WPARAM wParm, LPARAM lParm)
{
	//PCIHSetADParam(hpcih,AD_CONTRAST,wParm);
	okStopCapture(hpcih);
	okSetVideoParam(hpcih,3,wParm);
	okCaptureToScreen(hpcih);

}
void RecImage::mSetRecFrq( WPARAM wParm, LPARAM lParm)
{
	//PCIHSetADParam(hpcih,AD_FREQUENCY,wParm);
}
void RecImage::mSetRecClp( WPARAM wParm, LPARAM lParm)
{
	//PCIHSetADParam(hpcih,AD_CLAMPLEVEL,wParm);
}

void RecImage::mSetDispMode(WPARAM wParm, LPARAM lParm)
{
	SetDispMode();
}

void RecImage::CapturePIcOne(WPARAM wParm, LPARAM lParm)
{
	if(wParm==0)
	{
		char filename[500];
		sprintf(filename,"%s\\%d.jpg",((CBxtDlg *)AfxGetMainWnd())->m_workingpath,CapturedNum);
		//CaptureOne("c:\\xxx.bmp");
		CaptureOne(filename);

		//CPic jpic;
		//jpic.loadbmp("c:\\xxx.bmp");
		//jpic.savejpg(filename);
		//jpic.Close();
		CapturedNum++;
	}
	else
	{	
		char filename[500];
		sprintf(filename,"%s\\x1.seq",((CBxtDlg *)AfxGetMainWnd())->m_workingpath);
		bDispToScreen=1;
		okStopCapture(hpcih);
		okSetCaptureParam(hpcih,15,1);
		okCaptureByBuffer(hpcih,(long)filename,0,wParm);
		//okCaptureToScreen(hpcih);
	}
}

void RecImage::SetDispMode()
{

}


void RecImage::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
}





BOOL GetBitmapHeader(HANDLE hBoard, TARGET src, LPBITMAPINFOHEADER lpbi)
{
	short		width,height;
	long		form;

	form=GetTargetSize(hBoard, src, &width, &height);

	//here take form as screen forever 
	//form=okSetCaptureParam(hBoard,CAPTURE_SCRRGBFORMAT,GETCURRPARAM); //-1
	form=okSetCaptureParam(hBoard,4,GETCURRPARAM); //-1

	SetBitmapHeader(lpbi, width, height, HIWORD(form), LOWORD(form) );

	return LOWORD(form);
}

//set data to dib 
long SetDataToDIB(TARGET src, short start, LPBITMAPINFOHEADER lpbi, LPBYTE lpdib)
{
	BLOCKINFO	blk;
	int	aa=	sizeof(blk);

	//get image to app buffer from tgt
	blk.lpBits=lpdib;			
	blk.iWidth=(short)lpbi->biWidth;
	blk.iHeight=-(short)lpbi->biHeight; //to invert y
	blk.iBitCount=lpbi->biBitCount;
	if(lpbi->biCompression==BI_BITFIELDS) {//
		DWORD	*lpMask;
		lpMask=(DWORD *)((LPSTR)lpbi+lpbi->biSize);
		if(lpMask[1]==0x03e0) //555
			blk.iFormType=FORM_RGB555;
	}

	return okConvertRect(hBoard,(TARGET)&blk,0,src,start,1);
	
}
//--demo to set current capture rect on screen. mode=0: left-top, 1:centerize
long SetToWndRectEx(HANDLE hBoard, HWND hWnd, long lMode)
{
	long	lSize;
	RECT	rect;
	

	if(	!IsWindow(hWnd) )
		return FALSE;
	if(IsIconic(hWnd) )
		return FALSE;

	//get client rect
	GetClientRect(hWnd,&rect);

	if(lMode==1) { //set to center
		short		width,height;
		//get available rect size
		//lSize=okSetVideoParam(hBoard,VIDEO_AVAILRECTSIZE,-1);
		//or set to expected size
		//sampwidth=LOWORD(lSize);
		//sampheight=HIWORD(lSize);
		if( okGetCaptureStatus(hBoard,0) ) { //capturing
			width=sampwidth;
			height=sampheight;
		}
		else { //frozen status
			width=(short)lpbi->biWidth;
			height=(short)lpbi->biHeight;
		}
		if( (rect.right) > width )
			rect.left=( (rect.right - width )/2 ) ;//& (~0x3);
		if( (rect.bottom) > height )
			rect.top=( (rect.bottom - height )/2);
	}

	//make offset x,y
	lSize=MAKELONG(rect.left,rect.top);
	rect.right=rect.left+min(sampwidth,rect.right);
	rect.bottom=rect.top+min(sampheight,rect.bottom);

	//map to absolute screen rect
	MapWindowPoints(hWnd,HWND_DESKTOP,(LPPOINT)&rect,2);

	okSetTargetRect(hBoard, SCREEN, &rect);

	return lSize;

}

//set bitmap header and bitmap info if need
long SetBitmapHeader(LPBITMAPINFOHEADER lpbi,short width,short height, short bits, short form)
{
	long	wbytes;

	if(!lpbi)
		return FALSE;

	lpbi->biWidth=width;
	lpbi->biHeight=height;

	lpbi->biSize=sizeof(BITMAPINFOHEADER);
	lpbi->biPlanes=1;

	lpbi->biBitCount=bits;
	wbytes=((((lpbi->biWidth*bits)+31)&~31)>>3);//bmp need 4 byte align
	lpbi->biSizeImage=wbytes*lpbi->biHeight;

	lpbi->biClrUsed=0;
	//special format for 555,565 & 32 
	if(form==FORM_RGB555 || form==FORM_RGB565 || form==FORM_RGB8888 ) 
		lpbi->biCompression=BI_BITFIELDS;
	else
		lpbi->biCompression=0;
	if(lpbi->biCompression==BI_BITFIELDS) {//
		DWORD	*lpmask;
		lpmask=(DWORD *)((LPSTR)lpbi+lpbi->biSize);

		if(form==FORM_RGB555) {
			lpmask[2]=0x001f; //blue
			lpmask[1]=0x03e0;
			lpmask[0]=0x7c00;
		}
		else if(form==FORM_RGB565) {
			lpmask[2]=0x001f; //blue
			lpmask[1]=0x07e0;
			lpmask[0]=0xf800;
		}
		else if(bits==32) {
			lpmask[2]=0x0000ff;
			lpmask[1]=0x00ff00;
			lpmask[0]=0xff0000;
		}
	}
	else if(bits<=12) { // 8,10,12
		int		i;
		RGBQUAD	*lpRGB=(RGBQUAD *)((LPSTR)lpbi+lpbi->biSize);

		lpbi->biClrUsed=(1<<bits);
		for(i=0; i<(short)lpbi->biClrUsed;i++) {
			lpRGB[i].rgbBlue=i;
			lpRGB[i].rgbGreen=i;
			lpRGB[i].rgbRed=i;
			lpRGB[i].rgbReserved=0;
		}
	} 
	lpbi->biClrImportant=lpbi->biClrUsed;

	return lpbi->biClrUsed;
}

//get size 
long GetTargetSize(HANDLE hBoard, TARGET tgt, short *width, short *height)
{
	RECT	rect;
	long	form;


	if( (tgt==SCREEN ) ||(tgt==BUFFER) ) {
		rect.right=-1;
		okSetTargetRect(hBoard,tgt,&rect); //get current rect
		*width=(short)(rect.right-rect.left);
		*height=(short)(rect.bottom-rect.top);

		if(tgt==SCREEN ) {
			form=okSetCaptureParam(hBoard,CAPTURE_SCRRGBFORMAT,GETCURRPARAM); //-1
			//limit to video rect
			rect.right=-1; //max. captured rect
			okSetTargetRect(hBoard,VIDEO,&rect); //get video rect
			*width=(short)min(*width,rect.right-rect.left);
			*height=(short)min(*height,rect.bottom-rect.top);
		}
		else if(tgt==BUFFER) 
			form=okSetCaptureParam(hBoard,CAPTURE_BUFRGBFORMAT,GETCURRPARAM); //-1

	} else if(tgt>BUFFER) { //from blkinfo
		LPBLOCKINFO	lpblk;
		lpblk=(LPBLOCKINFO)tgt;

		*width=lpblk->iWidth;
		*height=abs(lpblk->iHeight);
		form=MAKELONG(lpblk->iFormType,lpblk->iBitCount);
	}


	return form;
}

BOOL ConvertBitmap(LPBITMAPINFOHEADER lpbi,LPSTR lpdib)
{
	long	i,wbytes;
	LPSTR	lpbuf;
	LPSTR	lptop,lpbottom;

	if(!lpbi)
		return FALSE;
	if(!lpbi->biHeight)
		return FALSE;

	//inverse dib (top to bottom)
	wbytes=lpbi->biSizeImage/lpbi->biHeight;
	lpbuf=(LPSTR)GlobalAlloc(GPTR,wbytes);

	lptop=lpdib;
	lpbottom=lpdib+(lpbi->biHeight-1)*wbytes;
	for(i=0;i<lpbi->biHeight/2;i++) {
		CopyMemory(lpbuf,lptop,wbytes);
		CopyMemory(lptop,lpbottom,wbytes);
		CopyMemory(lpbottom,lpbuf,wbytes);
		lptop+=wbytes;
		lpbottom-=wbytes;
	}
	return TRUE;
}

long		elapsed;
long		numframe;
char		string[256];
long		bufform;
BLOCKINFO	blk;
BOOL CALLBACK BeginCapture(HANDLE hBoard)
{
	short		width,height;
	long		blkform;

	blkform=sizeof(blk);
	//AfxMessageBox("dd");
	if(bDispToScreen) {
		bufform=GetTargetSize(hBoard, BUFFER, &width, &height);
		if( (LOWORD(bufform)==FORM_GRAY10) || (LOWORD(bufform)==FORM_GRAY12) ) { //special  
			//blkform=okSetCaptureParam(hBoard,CAPTURE_SCRRGBFORMAT,GETCURRPARAM); //-1
			blkform=MAKELONG(FORM_GRAY8,8);
		}
		else //take same bits as buffer
			blkform=bufform;
		SetBitmapHeader(lpbi, width, height, HIWORD(blkform), LOWORD(blkform) );
	}

	blk.lpBits=(unsigned char*)lpdib;
	blk.iBitCount=lpbi->biBitCount;
	blk.iWidth=(short)lpbi->biWidth;

	if( okSetCaptureParam(hBoard,CAPTURE_SAMPLEFIELD,1)==0 ) //sample in field by field
		if( LOWORD(okSetVideoParam(hBoard,VIDEO_SIGNALTYPE,-1))==1 ) //interlace video
			if(okSetConvertParam(hBoard,CONVERT_FIELDEXTEND,-1)!=0 )
				lpbi->biHeight*=2; //double size for ht

	blk.iHeight=-(short)lpbi->biHeight; //note: minus is for invert dib in y by ConvertRect	

	elapsed=GetTickCount();
	numframe=0;

	return 1;
}

BOOL CALLBACK BackDisplay(HANDLE hBoard,long no)
{		
	//return 1;

	numframe++;
	Sleep(PlayBackDelay);
	//sprintf(string,"captured frames = %d ",no);
	//sprintf(string,"Total frames = %d; Current = %d ",numframe, no);
	//SetWindowText(hwnd,string);
	//AfxMessageBox("dd");
	if(bDispToScreen) {
		if( (LOWORD(bufform)==FORM_GRAY10) ||(LOWORD(bufform)==FORM_GRAY12) ) { //special  
			//way 1
			//okConvertRect(hBoard,(TARGET)&blk,0,BUFFER,(short)no,1);
			okConvertRect(hBoard,SCREEN,0,BUFFER,(short)no,1);
			//way 2
			//okReadRectEx(hBoard,BUFFER,(short)no,lpdib, MAKELONG(FORM_GRAY8,1)); 
														 //read only red data
		}
		else {
			//Sleep(5);
			//way 1
			//okTransferRect(hBoard,(TARGET)&blk,0,BUFFER,(short)no,1);
			//okTransferRect(hBoard,SCREEN,0,BUFFER,(short)no,1);
			okConvertRect(hBoard,SCREEN,0,BUFFER,(short)no,1);
			//way 2
			//okReadRect(hBoard,BUFFER,(short)no,lpdib);
		}
		//InvalidateRect(hwnd,NULL,FALSE);
	}

	return 1;
}

BOOL CALLBACK EndCapture(HANDLE hBoard)
{
	
	elapsed=GetTickCount()-elapsed;								

	//sprintf(string,"Total frames = %d;  elapsed time= %d ms",numframe,elapsed);
	//SetWindowText(hwnd,string);

	//clear callback
	okSetSeqCallback(hBoard,NULL,NULL,NULL);

	return 1;
}

long GetFrameSize(HANDLE hBoard)
{
	long	bits,size;

	size=okSetCaptureParam(hBoard,CAPTURE_BUFBLOCKSIZE,-1);
	bits=okSetCaptureParam(hBoard,CAPTURE_BUFRGBFORMAT,-1);
	size=(HIWORD(bits))/8*LOWORD(size)*HIWORD(size);

	return size;
}

⌨️ 快捷键说明

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