Character overlays implemented on the directx--yuv420p

Source: Internet
Author: User
Tags fread


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-&GT;DATA[1],720*576/4);
memcpy (Image->pixels[1],PFRAMEYUV-&GT;DATA[2],720*576/4);

。。。。。。。。。。。。。。。。。。。。。。。。。

Character overlays implemented on the directx--yuv420p

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.