text over the video

text over the video

Postby fafi » Fri Oct 31, 2008 1:16 am

Hi All !

Can someone translate to FWH ?

Thanks for help

Best Regards
Fafi

Code: Select all  Expand view
The Actual Work

Displaying text over video means, that first we need to create a bitmap then we will write our text over that bitmap, and that bitmap will be blended with the running video with the help of VMR9.

Need Some Control Over Mixing

The thing that is vital, Is some preferences which we need to set. Actually if you display an image over video, You don’t need much control over actual blending, Because if an image is a bit is scaled or changed it is difficult to catch it, But in the case of text you can’t accept such situation. Because if text is a bit scaled or changed it would be much harder to read it. So first of all we need to tell the mixer to not scale our text. The interface which will come to save us is IVMRMixerControl9. Here we request point filtering instead of bilinear filtering (which is default) to improve the text quality. If you are not scaling the app Image, you should use point filtering.

pVmr->QueryInterface( IID_IVMRMixerControl9, (void**) &pMix);
DWORD dwPrefs=0;
pMix->GetMixingPrefs( &dwPrefs);
dwPrefs |= MixerPref_PointFiltering;
dwPrefs &= ~( MixerPref_BiLinearFiltering );
pMix->SetMixingPrefs( dwPrefs );

Text To Image

Now we will create the bitmap having our text.

CDC * pdc = GetDC();
CDC mCompatibleDC;
mCompatibleDC.CreateCompatibleDC( pdc );
mCompatibleDC.SelectObject( mFont );
CSize strSize = mCompatibleDC.GetTextExtent( strFinish );
CBitmap bm;
bm.CreateCompatibleBitmap( pdc, strSize.cx, strSize.cy);
mCompatibleDC.SelectObject( &bm );
mCompatibleDC.SetBkColor(mBK_Color);
mCompatibleDC.SetTextColor(mTXT_Color);
mCompatibleDC.TextOut(0,0,strFinish);
This is easy to understand the above code.

    * Create CDC which should be compatible with the display (or as required)
    *  Then we select the font in that CDC.
    * We get the size of the actual text in logical units.
    * Then we create the bitmap of the size of the text.
    * We select that bitmap in our CDC.
    * We set text and background color of the text .
    * We write the actual text in our CDC

This all mean, that now in our CDC we have an image with the required text.

Displaying Text Over Video

Now we will prepare for showing the image with text over video. This snippet of code is  approximately similar to a my previous article..
VMR9AlphaBitmap bmpInfo;
ZeroMemory(&bmpInfo, sizeof(bmpInfo) );
bmpInfo.dwFlags |= VMRBITMAP_HDC;
bmpInfo.hdc = pDC->m_hDC;
LONG cx, cy;
pWC->GetNativeVideoSize( &cx, &cy, NULL, NULL);
bmpInfo.rSrc = Rect;
// rDest specifies the destination rectangle
//in composition space (0.0f to 1.0f)
bmpInfo.rDest.right = 1.0f;
bmpInfo.rDest.left = 0.0f;
bmpInfo.rDest.top = (float)(cy - Rect.Height()) / (float)cy - EDGE_BUFFER;
bmpInfo.rDest.bottom = 1.0f - EDGE_BUFFER;
// Set the transparency
// value (1.0 is opaque, 0.0 is transparent)
bmpInfo.fAlpha = 1.0;
pBmp->SetAlphaBitmap( &bmpInfo);
All is done now you can blend any text over video.

User avatar
fafi
 
Posts: 169
Joined: Mon Feb 25, 2008 2:42 am

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 44 guests