DirectX--yuv420p上實現的字元疊加,yuv420p

來源:互聯網
上載者:User

DirectX--yuv420p上實現的字元疊加,yuv420p


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();       //根據圖片的大小建立一個相容位元影像
m_pMemBmp->CreateCompatibleBitmap(pDC, bmpWidth, bmpHeight);
m_pOldBmp = m_pMemDC->SelectObject(m_pMemBmp);

// 把映像的資料繪製到相容位元影像上
 
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標記色
OSDSetTextColor(0, 0, 0);//OSD顯示色

//設定字型
CFont font;
font.CreateFont(20,15,0,0,10,FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_DEFAULT_PRECIS,OUT_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_SWISS,"宋體");
SelectObject(hMemDC, font); 
///////////////////////////
SYSTEMTIME st;
CString strDate,strTime;
GetLocalTime(&st);
strDate.Format("時間 %04d-%02d-%02d ",st.wYear,st.wMonth,st.wDay);
strTime.Format("%02d:%02d:%02d",st.wHour,st.wMinute,st.wSecond);
// 添加文字到指定位置
m_pMemDC->TextOut(20, 40, 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!");
}

調用部分

//////////////////////////////////////////////////////////////////////////////////////
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)//需要疊加  通過標記色過濾
{
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);//拷貝資料yuv420,也可預先改變指標
  memcpy(image->pixels[2],pFrameYUV->data[1],720*576/4);
  memcpy(image->pixels[1],pFrameYUV->data[2],720*576/4);

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.