I implemented the EVR renderer into a player of mine to deal with bad resizing quality on Windows Vista+ and came to problems...
I have subtitle overlay problems with the EVR:
try to see what i m talking about - you must set the EVR in options.
I used this to apply a 32bit alpha bitmap onto VMR9, using a DirectX surface:
private void SetVRM9MixerSettings(int width, int height, int lines)
{
int hr = 0;
VMR9AlphaBitmap alphaBmp;
// Set Alpha Bitmap Parameters for using a Direct3D surface
alphaBmp = new VMR9AlphaBitmap();
alphaBmp.dwFlags = VMR9AlphaBitmapFlags.EntireDDS | VMR9AlphaBitmapFlags.FilterMode;
// on unmanagedSurface the bitmap was drawn with transparency
alphaBmp.pDDS = unmanagedSurface;
alphaBmp.rDest = GetDestRectangle(width, height, lines);
alphaBmp.fAlpha = 1.0f;
alphaBmp.dwFilterMode = VMRMixerPrefs.BiLinearFiltering;
// for anaglyph half SBS
if (FrameMode == Mars.FrameMode.HalfSideBySide)
{
alphaBmp.rDest.left /= 2;
alphaBmp.rDest.right /= 2;
}
// Set Alpha Bitmap Parameters
hr = mixerBitmap.SetAlphaBitmap(ref alphaBmp);
DsError.ThrowExceptionForHR(hr);
}
Now however the project MediaFoundation.NET doesnt have the alphaBmp.pDDS pointer to set, so I cannot use a directdraw surface and need to use GDI (IF SOMEONE HAS A METHOD TO DO THIS IT WOULD BE COOL). But with GDI I cannot use 32bit alpha Bitmaps for true transparency - I only get 1 bit transparency with this approach:
private void SetEVRMixerSettings(int width, int height, int subtitleLines)
{
MFVideoAlphaBitmap alphaBmp = new MFVideoAlphaBitmap();
//alphaBitmap is a 32bit semitransparent Bitmap
Graphics g = Graphics.FromImage(alphaBitmap);
// get pointer to needed objects
IntPtr hdc = g.GetHdc();
IntPtr memDC = CreateCompatibleDC(hdc);
IntPtr hBitmap = alphaBitmap.GetHbitmap();
IntPtr hOld = SelectObject(memDC, hBitmap);
alphaBmp.GetBitmapFromDC = true;
alphaBmp.stru = memDC;
alphaBmp.paras = new MFVideoAlphaBitmapParams();
alphaBmp.paras.dwFlags = MFVideoAlphaBitmapFlags.Alpha | MFVideoAlphaBitmapFlags.SrcColorKey | MFVideoAlphaBitmapFlags.DestRect;
// calculate destination rectangle
MFVideoNormalizedRect mfNRect = new MFVideoNormalizedRect();
NormalizedRect nRect = GetDestRectangle(width, height, subtitleLines);
mfNRect.top = nRect.top;
mfNRect.left = nRect.left;
mfNRect.right = nRect.right;
mfNRect.bottom = nRect.bottom;
// used when viewing half side by side anaglyph video that is stretched to full width
if (FrameMode == Mars.FrameMode.HalfSideBySide)
{
mfNRect.left /= 2;
mfNRect.right /= 2;
}
alphaBmp.paras.nrcDest = mfNRect;
// calculate source rectangle (full subtitle bitmap)
MFRect rcSrc = new MFRect();
rcSrc.bottom = alphaBitmap.Height;
rcSrc.right = alphaBitmap.Width;
rcSrc.top = 0;
rcSrc.left = 0;
alphaBmp.paras.rcSrc = rcSrc;
// apply 1-bit transparency
System.Drawing.Color colorKey = System.Drawing.Color.Black;
alphaBmp.paras.clrSrcKey = ColorTranslator.ToWin32(colorKey);
// 90% visible
alphaBmp.paras.fAlpha = 0.9F;
// set the bitmap to the evr mixer
evrMixerBitmap.SetAlphaBitmap(alphaBmp);
// cleanup
SelectObject(memDC, hOld);
DeleteDC(memDC);
g.ReleaseHdc();
}
So the questions are:
- How to use a DirectDraw surface to mix bitmaps on the EVR video or
- How to mix a semi transparent bitmap without DirectDraw?
Thank you very much!