unsigned char *ptemp;
BYTE osdy = 0;
BYTE OSDU = 0;
BYTE OSDV = 0;
void Osdsettextcolor (Byte osdr, byte OSDG, byte osdb)
{
Osdy = 0.25*osdr+0.504*osdg+0.098*osdb+16;
OSDU = -0.148*osdr-0.291*osdg+0.439*osdb+128;
OSDV = 0.439*osdr-0.368*osdg-0.071*osdb+128;
}
void Ctest0dlg::setosd ()
{
FILE *fp=fopen ("D:\\temp\\osd.bmp", "RB");
if (fp = = 0)
return;
HDC HDC =:: GetDC (GetSafeHwnd ());
HDC HMEMDC = CreateCompatibleDC (HDC);
Fseek (FP, sizeof (Bitmapfileheader), 0);
Bitmapinfoheader Head;
Fread (&head, sizeof (Bitmapinfoheader), 1, FP);
int bmpheight = Head.biheight;
int bmpwidth = Head.biwidth;
int bibitcount = Head.bibitcount;
int linebyte = (bmpwidth*bibitcount/8+3)/4*4;
Rgbquad *pcolortable;
unsigned char *pbmpbuf = new unsigned char[linebyte*bmpheight];
Fread (Pbmpbuf, 1, Linebyte*bmpheight, FP);
memset (pbmpbuf,0, linebyte*bmpheight);
CDC *M_PMEMDC;
M_PMEMDC = new CDC ();
CDC *PDC;
PDC = GetDC ();
M_pmemdc->createcompatibledc (PDC);
CBitmap *m_poldbmp = NULL;
CBitmap *m_pmembmp = new CBitmap (); Create a compatible bitmap based on the size of the picture
M_pmembmp->createcompatiblebitmap (PDC, Bmpwidth, bmpheight);
M_poldbmp = M_pmemdc->selectobject (m_pmembmp);
Drawing data from an image to a compatible bitmap
SetDIBits (M_pmemdc->getsafehdc (), (HBITMAP) M_pmembmp->m_hobject,
0, Bmpheight, (LPVOID) Pbmpbuf, (bitmapinfo*) &head, dib_rgb_colors);
M_pmemdc->setbkmode (TRANSPARENT);
M_pmemdc->settextcolor (RGB (255, 0, 0));//rgb marker Color
Osdsettextcolor (0, 0, 0);//osd Display Color
//Set Font
CFont font;
Font. CreateFont (20,15,0,0,10,false,false,false,ansi_charset,out_default_precis,out_default_precis,default_quality, Ff_swiss, "song Body");
SelectObject (HMEMDC, font);
///////////////////////////
SYSTEMTIME St;
CString Strdate,strtime;
Getlocaltime (&ST);
Strdate.format ("Time%04d-%02d-%02d", st.wyear,st.wmonth,st.wday);
Strtime.format ("%02d:%02d:%02d", St.whour,st.wminute,st.wsecond);
//Add text to a specified location
M_pmemdc->textout (+, strdate+strtime);
ptemp = new unsigned char[linebyte*bmpheight];
GetDIBits (M_pmemdc->getsafehdc (), (HBITMAP) m_pmembmp->m_hobject, 0, Bmpheight,
(LPVOID) Ptemp, (bitmapinfo*) &head, dib_rgb_colors);
Fclose (FP);
Delete m_pmembmp;
Delete M_PMEMDC;
Delete[] Pbmpbuf;
MessageBox ("voer!");
}
Invoke part
//////////////////////////////////////////////////////////////////////////////////////
Setosd ();
for (int i=0;i<80;i++)
{
for (int k=0;k<640;k++)
{
dc. SetPixel (K,79-i,rgb (ptemp[(i*640+k) *3+2],ptemp[(i*640+k) *3+1],ptemp[(i*640+k) *3+0]));
if (ptemp[(i*640+k) *3+2]!=0)//need overlay via marker color filter
{
pframeyuv->data[0][(79-i) *720+k]=osdy;
if ((79-i)%2==0)
{
pframeyuv->data[1][(79-i) *720/4+k/2]=osdu;
pframeyuv->data[2][(79-i) *720/4+K/2]=OSDV;
}
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////
memcpy (Image->pixels[0],pframeyuv->data[0],720*576)///Copy data yuv420, can also pre-change the pointer
memcpy (Image->pixels[2],PFRAMEYUV->DATA[1],720*576/4);
memcpy (Image->pixels[1],PFRAMEYUV->DATA[2],720*576/4);
。。。。。。。。。。。。。。。。。。。。。。。。。
Character overlays implemented on the directx--yuv420p