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

📄 video_channel.cpp

📁 实时监控
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	
	report_channel();

	CRightLogin* rl = CRightLogin::the_one();
	if( rl->m_hWnd )
		rl->PostMessage(WM_VIDEO_WND_INVOKED, (WPARAM)this, WM_LBUTTONDOWN);
	
	CRightVOD* rv = CRightVOD::the_one();
	if( chnl == VOD_GROUP && rv->m_hWnd )
		rv->PostMessage(WM_OPEN_VOD,(WPARAM)this->index());
	CRightMD* rmd = CRightMD::the_one();
	if( rmd->m_hWnd )
		rmd->PostMessage(WM_CHANNEL_OPEN);
}

//##ModelId=3F90BAA60344
void video_channel::video_closed(ULONG ip, USHORT port, int chnl)
{
	if( v_ip != ip_port(ip, port) ||
		v_chnl != chnl )
		return;
	clear_wnd();
	

	if( is_vod() )
	{
		CRightVOD* rv = CRightVOD::the_one();
		if( rv->m_hWnd )
			rv->PostMessage(WM_CLOSE_VOD,index(),0);
	}

	v_ip = 0;
	v_chnl = -2;
	m_Slow = 0;
	
	report_channel();

	CRightMD* rmd = CRightMD::the_one();
	if( rmd->m_hWnd )
		rmd->PostMessage(WM_CHANNEL_CLOSE);
}


/*
 *	video_mask 实现
 */
//##ModelId=3F90BAA603DA
const byte* video_channel::mask_data()
{
	
	return mask;
}

void video_channel::set_data(const byte* data)
{
	memcpy(mask, data, draw_byte_total);
}

//##ModelId=3F90BAA603E4
void video_channel::set_grid(int _w, int _h)
{
	if( _w == 0 )
	{
		drawing_grid = false;
		return;
	}
	drawing_grid = true;
	w = _w;
	h = _h;
	
	if( !mask )
		mask.alloc(draw_byte_total);	// 8 bits/byte
}

//##ModelId=3F90BAA70010
void video_channel::clear_grid()
{
	drawing_grid = false;
	mask.select_all();
}

//##ModelId=3F90BAA7001A
void video_channel::update()
{
//	RedrawWindow();
}

VIDEO_STANDARDS video_channel::On_videostandard_type()
{
	return vs;
}

//##ModelId=3F90BAA7002E
void video_channel::calc_mask(CPoint pt, int& x, int& y)
{
	CRect rc;
	GetClientRect(rc);
	//	ScreenToClient(&pt);
	// calculate the logical grid coord.
	x = (pt.x-rc.left)*10/(rc.Width()/h)/10;
	y = ((pt.y-rc.top)*10/(rc.Height()/w)/10);
}
void video_channel::check_playing_mode()
{
	if(!is_vod()) return;
	//if(m_boolcheckbuf) return;
	if(m_draw_id>40) m_draw_id=0;
	if(m_draw_id>20) return;

	if( !mem_draw ||
		!mem_draw->equal(cs, vs) )
	{
		safe_destroy(mem_draw);
		mem_draw = mem_draw_factory::create(cs, vs);
	}
	mem_draw->set_buf(m_checkbuf);
	int width = vs_width(vs);
	int height = vs_height(vs);
	int m=7*height/8;
	int k=15*height/16;
	int m_break=(m+k)/2;

	for( int i=7*width/8; i<width; i++ )
	{
	   for(int j=m; j<k; j++ )
		  mem_draw->lighten(i, j, 255);
       m++;
	   k--;
	   if(m>m_break||k<m_break)
		   break;
	}
}
//##ModelId=3F90BAA70024
void video_channel::check_grid(byte* yuvbuf)
{
	if( !drawing_grid )
		return;

	if( is_fulled() )
		return;

	if( !mem_draw ||
		!mem_draw->equal(cs, vs) )
	{
		safe_destroy(mem_draw);
		mem_draw = mem_draw_factory::create(cs, vs);
	}

	mem_draw->set_buf(yuvbuf);

	int width = vs_width(vs);
	int height = vs_height(vs);
	int pitch = width;
	

	int m_nub = 1;
	ULONG tip = v_ip.get_ip();
	USHORT tport = v_ip.look_port();
	if(check_16_version(tip, tport) || check_4008_version(tip, tport))
		m_nub = 4;
	if(check_4004_version(tip, tport) || check_2000_version(tip, tport) || check_2100_version(tip, tport))
		m_nub = 2;
	
	for( int i=1; i<w; i++ )
		for( int j=0; j<width; j++ )
			mem_draw->lighten(j, i*height/w, 255);
	
	for( i=1; i<h; i++ )	
		for( int j = 0; j<height; j++ )
			mem_draw->lighten(i*width/h, j, 255);
	

	//if(vs == PAL_D1 || vs == NTSC_D1) return;
	
	for( i=0; i<w; i++ )
		for( int j=0; j<h; j++ )
		{
			if( mask.is_set(j, m_nub*i) )
			{
				fill_black(j, i);
			}
		}
	/*
	//DWORD* p = (DWORD*)buf;
	byte* p = (byte*)yuvbuf;
	for( int i=0; i<height; i+=height/h )
	{
		if( i == 0 )
			continue;
		for( int j=0; j<width; j++ )
		{
			p[(i*width+j)] = 239;
			//	p[(j*height+i)/2] = yuv;
		}
	}
	for( i=0; i<width; i+=width/w )
	{
		if( i== 0 )
			continue;
		for( int j=0; j<height; j++ )
		{
			p[(j*width+i)] = 239;
		}
	}
	
	for( i=0; i<8; i++ )
	{
		for( int j=0; j<8; j++ )
		{
			if( mask.is_set(j, i) )
			{
				fill_black(yuvbuf, j, i);
			}
		}
	}
	*/
}

DWORD clip(DWORD x, int delta)
{
	byte* p = (byte*)&x;
	int t;

	for( int i=0; i<3; i++ )
	{
		t = p[i];
		t += delta;
		t = max(0, t);
		p[i] = t;
	}

	return x;
}

//##ModelId=3F90BAA70043
void video_channel::fill_black(int x, int y)
{
	int width = vs_width(vs);
	int height = vs_height(vs);

	int left = x*width/h;
	int right = (x+1)*width/h;
	int top = y*height/w;
	int bottom = (y+1)*height/w;

	for( int i=top; i<bottom; i++ )
	{
		for( int j=left; j<right; j++ )
		{
			mem_draw->lighten(j, i, -90);
		}
	}
	/*
	// YV12
	// YUV planar
	int width = WIDTH;
	int height = HEIGHT;
	int pitch = width;
	
	int left = x*width/w;
	int right = (x+1)*width/w;
	int top = y*height/h;
	int bottom = (y+1)*height/h;

	for( int i=top; i<bottom; i++ )
	{
		for( int j=left; j<right; j++ )
		{
			int tmp1, tmp2;
			int offset = (i*width+j);
			tmp1 = buf[offset];
			tmp2 = buf[offset+1];

			tmp1 -= 90;
			tmp2 -= 90;

			const int mn = 16;
			tmp1 = max(tmp1, mn);
			tmp2 = max(tmp2, mn);
			buf[offset] = tmp1;
			buf[offset+1] = tmp2;
		}
	}
/*
	// YUY2:

	int width = 352;
	int height = 288;
	int pitch = width*2;
	
	int left = x*width/w;
	int right = (x+1)*width/w;
	int top = y*height/h;
	int bottom = (y+1)*height/h;
	
	for( int i=top; i<bottom; i++ )
	{
		for( int j=left; j<right; j++ )
		{
			int tmp1, tmp2;
			int offset = (i*width+j)*2;
			
			tmp1 = buf[offset];
			tmp2 = buf[offset+2];
			
			tmp1 -= 90;
			tmp2 -= 90;
			
			const mn = 20;
			if( tmp1 < mn )
				tmp1 = mn;
			if( tmp2 < mn )
				tmp2 = mn;
			buf[offset] = tmp1;
			buf[offset+2] = tmp2;

			ASSERT(offset<202752);
		}
	}
*/
}

//##ModelId=3F90BAA701B5
void video_channel::OnLButtonDown(UINT nFlags, CPoint point) 
{

	if (drawing_grid) 
	{
		point_ldown = point;
		/*int x, y ;
		calc_mask(point, x, y) ;
		mask.toggle(x, y) ;*/
	}
	else  
	{
		CRightCamera::the_one()->ipp = v_ip ;
		baseclass::OnLButtonDown(nFlags, point) ;
	}
}

void video_channel::OnLButtonUp(UINT nFlags, CPoint point) 
{
	if (!drawing_grid)  return ;
	
	int x1, y1,x2,y2 ;

	calc_mask(point_ldown, x1, y1);
	calc_mask(point, x2, y2);

	int x_begin = min(x1, x2);
	int x_end = max(x1, x2);
	int y_begin = min(y1, y2);
	int y_end = max(y1, y2);

	int m_nub = 1;
	ULONG tip = v_ip.get_ip();
	USHORT tport = v_ip.look_port();

	if(check_16_version(tip, tport) || check_4008_version(tip, tport))
		m_nub = 4;
	if(check_4004_version(tip, tport) || check_2000_version(tip, tport) || check_2100_version(tip, tport))
		m_nub = 2;

	for(int i = x_begin; i<= x_end; i++ )
		for(int j = y_begin; j<= y_end; j++)
		{
			mask.toggle(i, m_nub*j) ;	
		}
}

//##ModelId=3F90BAA701DE
void video_channel::OnRButtonDown() 
{
	if( GetAsyncKeyState(VK_CONTROL) )
		mask.select_all();
	else
		mask.remove_all();

}
//##ModelId=3F90BAA701D3
void video_channel::OnRButtonDown(UINT nFlags, CPoint point) 
{
	if (drawing_grid)  {
		if ((nFlags & MK_CONTROL) == MK_CONTROL)
			mask.select_all() ;
		else
			mask.remove_all() ;
		return ;
	}
	baseclass::OnRButtonDown(nFlags, point) ;
}

//##ModelId=3F90BAA70150
LRESULT video_channel::on_vod_set_speed(WPARAM w, LPARAM)
{
	if( !IsWindow(CRightVOD::the_one()->m_hWnd))
		return 0;
	CRightVOD::the_one()->PostMessage(WM_SET_VOD_SPEED, w);
	return 0;
}

extern void DrawBitmap( CDC *pDC, HBITMAP hBitmap, HPALETTE hPal, int xDest, int yDest,
				int wDest, int hDest);

//##ModelId=3F90BAA701C9
void video_channel::OnPaint() 
{
	if( !VIDEO_LOGO.IsLoaded() )
		baseclass::OnPaint();
	else
	{
		CPaintDC dc(this);
		if( is_video_opened() )
		{
			CRect rc;
			GetWindowRect(rc);
			CWnd* p = GetParent();
			if( !p )
				return;
			COLORREF bk = RGB(255,255,255);
			if( is_sel() )
			{
				bk = RGB(255,0,0);
			}
			CClientDC dc(p);
			p->ScreenToClient(rc);
			rc.InflateRect(1,1,1,1);
			dc.FrameRect(rc, &CBrush(bk));
			return;
		}

		CRect rc;
		GetClientRect(rc);
		CMemDC mdc(&dc, rc);
		VIDEO_LOGO.Draw(&mdc, CPoint(0,0), rc.Size());

		if( is_fulled() )
			return;

		COLORREF cl = RGB(255,255,255);
		if( is_sel() )
		{
			cl = RGB(255,0,0);
		}
		mdc.FrameRect(rc, &CBrush(cl));
	}
}

⌨️ 快捷键说明

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