Skip to content

Commit 720cae7

Browse files
author
cqm
committed
Init Version
0 parents  commit 720cae7

File tree

153 files changed

+44211
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+44211
-0
lines changed

DrawVideo.cc

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#include <windows.h>
2+
#include <atltypes.h>
3+
#include "DrawVideo.h"
4+
5+
#define DBG_INFO
6+
#define GID_DRAWVDO "DrawVdo"
7+
#pragma comment(lib, "vfw32.lib")
8+
9+
CDrawVideo::CDrawVideo()
10+
{
11+
memset(&m_rect, 0, sizeof m_rect);
12+
m_bUseGDI = FALSE;
13+
m_bFit = TRUE;
14+
m_hDib = DrawDibOpen();
15+
if(!m_hDib)
16+
{
17+
DBG_INFO(GID_DRAWVDO, "***DrawDibOpen error");
18+
}
19+
Init(NULL);
20+
}
21+
22+
CDrawVideo::~CDrawVideo()
23+
{
24+
if (m_hDib){
25+
DrawDibClose(m_hDib);
26+
m_hDib = NULL;
27+
}
28+
}
29+
30+
void CDrawVideo::SetFitMode(BOOL bFit){
31+
m_bFit = bFit;
32+
}
33+
34+
void CDrawVideo::Draw(BYTE *pBuffer,int width, int height, LPCTSTR szText)
35+
{
36+
if(!IsWindow(m_hWnd))
37+
{
38+
DBG_INFO(GID_DRAWVDO, "no window %X, break draw", m_hWnd);
39+
return;
40+
}
41+
BOOL bVisible = (GetWindowLong(m_hWnd, GWL_STYLE) & WS_VISIBLE);
42+
if(!bVisible){ //IsWindowVisible(m_hWnd)
43+
DBG_INFO(GID_DRAWVDO, "m_hWnd %X not Visible skip draw", m_hWnd);
44+
return;
45+
}
46+
//DBG_TRACE("DrawVideo", "Draw");
47+
HDC hDC=::GetDC(m_hWnd);
48+
if(!hDC){
49+
DBG_INFO(GID_DRAWVDO, "unable to GetDC %X, break draw", m_hWnd);
50+
return ;
51+
}
52+
CRect destRect;
53+
if(!GetClientRect(m_hWnd, &destRect))
54+
{
55+
DBG_INFO(GID_DRAWVDO, "unable to GetClientRect %X,%d break draw", m_hWnd, GetLastError());
56+
ReleaseDC(m_hWnd,hDC);
57+
return;
58+
}
59+
if(destRect.IsRectEmpty())
60+
{
61+
DBG_INFO(GID_DRAWVDO, "***rect empty, GWL_STYLE: %X", GetWindowLong(m_hWnd, GWL_STYLE));
62+
ReleaseDC(m_hWnd,hDC);
63+
return;
64+
}
65+
if(destRect != m_rect)
66+
{
67+
DBG_INFO(GID_DRAWVDO, "MoveRect from %d,%d,%d,%d to %d,%d,%d,%d",
68+
m_rect.left, m_rect.top, m_rect.right, m_rect.bottom,
69+
destRect.left, destRect.top, destRect.right, destRect.bottom);
70+
m_rect = destRect;
71+
}
72+
destRect.DeflateRect(1,1);
73+
if (pBuffer)
74+
{
75+
bih.bmiHeader.biWidth = width;
76+
bih.bmiHeader.biHeight = height;
77+
bih.bmiHeader.biSizeImage = width * height * 3;
78+
if (!m_bFit){
79+
::SetBkColor(hDC, m_clrBK);
80+
::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, destRect, NULL, 0, NULL);
81+
float fRate = bih.bmiHeader.biWidth * 1.0f / bih.bmiHeader.biHeight;
82+
int newW = destRect.Height() * fRate;
83+
if (newW > destRect.Width()){
84+
int newH = destRect.Width() / fRate;
85+
int oldH = destRect.Height();
86+
destRect.top = (oldH - newH) / 2;
87+
destRect.bottom = destRect.top + newH;
88+
}
89+
else{
90+
int oldW = destRect.Width();
91+
destRect.left = (oldW - newW) / 2;
92+
destRect.right = destRect.left + newW;
93+
}
94+
}
95+
if(m_bUseGDI){
96+
int oldMode = SetStretchBltMode(hDC, COLORONCOLOR);
97+
StretchDIBits(hDC, destRect.left, destRect.top, destRect.Width(), destRect.Height(),
98+
0, 0, width, height, pBuffer, &bih, DIB_RGB_COLORS, SRCCOPY);
99+
SetStretchBltMode(hDC, oldMode);
100+
}
101+
else if(!::DrawDibDraw(m_hDib,
102+
hDC,
103+
destRect.left, // dest : left pos
104+
destRect.top, // dest : top pos
105+
destRect.Width(), // don't zoom x
106+
destRect.Height(), // don't zoom y
107+
&bih.bmiHeader, // bmp header info
108+
pBuffer, // bmp data
109+
0, // dest : left pos
110+
0, // dest : top pos
111+
width, // don't zoom x
112+
height, // don't zoom y
113+
DDF_NOTKEYFRAME )) // use prev params....//DDF_SAME_DRAW
114+
DBG_INFO(GID_DRAWVDO, "DrawDibDraw %X error", m_hWnd);
115+
116+
}
117+
// m_desRect.top = m_desRect.bottom - 20;
118+
if(szText && szText[0]){
119+
if(1){//GetIniInt("View", "TransText", 0)){
120+
SetBkMode(hDC, TRANSPARENT);
121+
SetTextColor(hDC, 0xffffff);
122+
}
123+
// TextOut(hDC, destRect.left+2, destRect.bottom - 20, szText, strlen(szText));
124+
DrawText(hDC, szText, -1, destRect, DT_BOTTOM|DT_SINGLELINE);
125+
}
126+
ReleaseDC(m_hWnd,hDC);
127+
128+
}
129+
130+
BOOL CDrawVideo::Init( HWND hWnd )
131+
{
132+
m_hWnd = hWnd;
133+
memset( &bih, 0, sizeof( bih ) );
134+
bih.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
135+
bih.bmiHeader.biPlanes = 1;
136+
bih.bmiHeader.biBitCount = 24;
137+
return TRUE;
138+
}

DrawVideo.h

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//绘制图像类
2+
//JC 2013-07-31
3+
#ifndef AVLIB_DRAWVIDEO_H_
4+
#define AVLIB_DRAWVIDEO_H_
5+
#include <Vfw.h>
6+
class CDrawVideo
7+
{
8+
//Attributes
9+
protected:
10+
HWND m_hWnd;
11+
HDRAWDIB m_hDib;
12+
BITMAPINFO bih;
13+
RECT m_rect;
14+
BOOL m_bUseGDI;
15+
BOOL m_bFit;
16+
// 背景色
17+
COLORREF m_clrBK;
18+
public:
19+
CDrawVideo();
20+
~CDrawVideo();
21+
22+
void SetFitMode(BOOL bFit);
23+
void SetBkColor(COLORREF color){ m_clrBK = color; }
24+
25+
BOOL Init(HWND hWnd);
26+
void Release(){}
27+
28+
//绘制RGB数据 数据长度为width*height*3
29+
void Draw(BYTE *pBuf,int width, int height, LPCTSTR szText=NULL);
30+
};
31+
32+
#endif //AVLIB_DRAWVIDEO_H_

0 commit comments

Comments
 (0)