Example #1
0
        private void SetMixerSettings()
        {
            int hr = 0;
            VMR9AlphaBitmap alphaBmp;

            if (!mixerEnabled) // Did the user disable the bitmap ?
            {
                // Get current Alpha Bitmap Parameters
                hr = mixerBitmap.GetAlphaBitmapParameters(out alphaBmp);
                DsError.ThrowExceptionForHR(hr);

                // Disable them
                alphaBmp.dwFlags = VMR9AlphaBitmapFlags.Disable;

                // Update the Alpha Bitmap Parameters
                hr = mixerBitmap.UpdateAlphaBitmapParameters(ref alphaBmp);
                DsError.ThrowExceptionForHR(hr);

                return;
            }

            if (usingGDI)
            {
                // Old school GDI stuff...
                Graphics g = Graphics.FromImage(colorKeyBitmap);
                IntPtr hdc = g.GetHdc();
                IntPtr memDC = NativeMethodes.CreateCompatibleDC(hdc);
                IntPtr hBitmap = colorKeyBitmap.GetHbitmap();
                NativeMethodes.SelectObject(memDC, hBitmap);

                // Set Alpha Bitmap Parameters for using a GDI DC
                alphaBmp = new VMR9AlphaBitmap();
                alphaBmp.dwFlags = VMR9AlphaBitmapFlags.hDC | VMR9AlphaBitmapFlags.SrcColorKey | VMR9AlphaBitmapFlags.FilterMode;
                alphaBmp.hdc = memDC;
                alphaBmp.rSrc = new DsRect(0, 0, colorKeyBitmap.Size.Width, colorKeyBitmap.Size.Height);
                alphaBmp.rDest = GetDestRectangle();
                alphaBmp.clrSrcKey = ColorTranslator.ToWin32(colorKey);
                alphaBmp.dwFilterMode = VMRMixerPrefs.PointFiltering;
                alphaBmp.fAlpha = 0.75f;

                // Set Alpha Bitmap Parameters
                hr = mixerBitmap.SetAlphaBitmap(ref alphaBmp);
                DsError.ThrowExceptionForHR(hr);

                // Release GDI handles
                NativeMethodes.DeleteObject(hBitmap);
                NativeMethodes.DeleteDC(memDC);
                g.ReleaseHdc(hdc);
                g.Dispose();
            }
            else // Using a Direct3D surface
            {
                // Set Alpha Bitmap Parameters for using a Direct3D surface
                alphaBmp = new VMR9AlphaBitmap();
                alphaBmp.dwFlags = VMR9AlphaBitmapFlags.EntireDDS;
                alphaBmp.pDDS = unmanagedSurface;
                alphaBmp.rDest = GetDestRectangle();
                alphaBmp.fAlpha = 1.0f;
                // Note : Alpha values from the bitmap are cumulative with the fAlpha parameter.
                // Example : texel alpha = 128 (50%) & fAlpha = 0.5f (50%) = effective alpha : 64 (25%)

                // Set Alpha Bitmap Parameters
                hr = mixerBitmap.SetAlphaBitmap(ref alphaBmp);
                DsError.ThrowExceptionForHR(hr);
            }
        }
Example #2
0
        private void PutOnOverlay(Bitmap bmp)
        {
            if (myTunner.VideoRendererFilter is IVMRMixerBitmap9)
            {

                var mixerBitmap = myTunner.VideoRendererFilter as IVMRMixerBitmap9;
                var param = new VMR9AlphaBitmap();
                var hr = mixerBitmap.GetAlphaBitmapParameters(out param);
                DsError.ThrowExceptionForHR(hr);

                var hdc = Graphics.FromHwnd(myTunner.Render.Handle).GetHdc();
                var memDC = Win32.CreateCompatibleDC(hdc);
                var hBitmap = bmp.GetHbitmap();
                try
                {
                    Win32.SelectObject(memDC, hBitmap);

                    var bw = bmp.Width;
                    var bh = bmp.Height;

                    var rw = myTunner.Render.Width;
                    var rh = myTunner.Render.Height;
                    var size = myTunner.GetCaptureScreenSize();
                    bw = rw;
                    bh = rh;

                    rw = size.Width;
                    rh = size.Height;

                    param.dwFlags = VMR9AlphaBitmapFlags.hDC | VMR9AlphaBitmapFlags.SrcColorKey | VMR9AlphaBitmapFlags.FilterMode;
                    param.hdc = memDC;
                    param.rSrc = new DsRect(0, 0, bw, bh);
                    param.rDest = new NormalizedRect(0f, 0f, (float)bw / rw, (float)bh / rh);
                    param.fAlpha = 1.0f;
                    //param.dwFilterMode = VMRMixerPrefs.BiLinearFiltering;
                    //param.clrSrcKey = ColorTranslator.ToWin32(Color.FromArgb(255, 0, 0, 0));//Color.White.ToArgb();
                    param.clrSrcKey = ColorTranslator.ToWin32(bmp.GetPixel(0, 0));
                    hr = mixerBitmap.SetAlphaBitmap(ref param);
                    DsError.ThrowExceptionForHR(hr);
                }
                finally
                {
                    Win32.DeleteDC(memDC);
                    Win32.ReleaseDC(myTunner.Render.Handle, hdc);
                    Win32.DeleteObject(hBitmap);
                }

            }
        }
Example #3
0
        private void SetMixerSettings()
        {
            int hr = 0;
            VMR9AlphaBitmap alphaBmp;

            if (!_bMixerEnabled) // Did the user disable the bitmap ?
            {
                if (!_bMixerImageWasUsed)
                    return; // Mixer was not used, can't disable it

                // Get current Alpha Bitmap Parameters
                hr = DX.MixerBitmap.GetAlphaBitmapParameters(out alphaBmp);
                DsError.ThrowExceptionForHR(hr);

                // Disable them
                //alphaBmp.dwFlags = VMRBitmap.Disable;
                alphaBmp.dwFlags = VMR9AlphaBitmapFlags.Disable;

                // Update the Alpha Bitmap Parameters
                hr = DX.MixerBitmap.UpdateAlphaBitmapParameters(ref alphaBmp);
                DsError.ThrowExceptionForHR(hr);

                return;
            }

            if (_OverlayBitmap == null)
            {
                // ignore it. Bitmap can be null
                //throw new Exception(@"Overlay bitmap should be already initialized.");
                return;
            }

#if USE_D3D
            if (_UseGDI)
            {
#endif
            // Old school GDI stuff...
            Graphics g = Graphics.FromImage(_OverlayBitmap);

            IntPtr hdc = g.GetHdc();
            IntPtr memDC = NativeMethodes.CreateCompatibleDC(hdc);
            IntPtr hBitmap = _OverlayBitmap.GetHbitmap();
            NativeMethodes.SelectObject(memDC, hBitmap);

            // Set Alpha Bitmap Parameters for using a GDI DC
            alphaBmp = new VMR9AlphaBitmap();
            alphaBmp.dwFlags = VMR9AlphaBitmapFlags.hDC | VMR9AlphaBitmapFlags.SrcColorKey | VMR9AlphaBitmapFlags.FilterMode;
            alphaBmp.hdc = memDC;
            alphaBmp.rSrc = new DsRect(0, 0, _OverlayBitmap.Size.Width, _OverlayBitmap.Size.Height);
            alphaBmp.rDest = new NormalizedRect(0.0f, 0.0f, 1.0f, 1.0f);
            alphaBmp.clrSrcKey = ColorTranslator.ToWin32(_GDIColorKey);
            alphaBmp.dwFilterMode = VMRMixerPrefs.PointFiltering;
            alphaBmp.fAlpha = _GDIAlphaValue;

            // Set Alpha Bitmap Parameters
            hr = DX.MixerBitmap.SetAlphaBitmap(ref alphaBmp);
            DsError.ThrowExceptionForHR(hr);

            // Release GDI handles
            NativeMethodes.DeleteObject(hBitmap);
            NativeMethodes.DeleteDC(memDC);
            g.ReleaseHdc(hdc);
            g.Dispose();
#if USE_D3D
            }
            else // Using a Direct3D surface
            {
                _pDirect3DMixing.StoreBitmapToSurface(_OverlayBitmap);

                // Set Alpha Bitmap Parameters for using a Direct3D surface
                alphaBmp = new VMR9AlphaBitmap();
                alphaBmp.dwFlags = VMR9AlphaBitmapFlags.EntireDDS;
                alphaBmp.pDDS = _pDirect3DMixing.unmanagedSurface;
                //alphaBmp.rDest = CalculateNormalizedVideoFrameSize();
                alphaBmp.rDest = new NormalizedRect(0.0f, 0.0f, 1.0f, 1.0f);
                alphaBmp.fAlpha = 1.0f;
                // Note : Alpha values from the bitmap are cumulative with the fAlpha parameter.
                // Example : texel alpha = 128 (50%) & fAlpha = 0.5f (50%) = effective alpha : 64 (25%)

                // Set Alpha Bitmap Parameters
                hr = DX.MixerBitmap.SetAlphaBitmap(ref alphaBmp);
                DsError.ThrowExceptionForHR(hr);
            }
#endif
            _bMixerImageWasUsed = true;

        }
Example #4
0
    public bool SaveBitmap(Bitmap bitmap, bool show, bool transparent, float alphaValue)
    {
      if (!_isVmr9Initialized)
      {
        return false;
      }
      if (_vmr9Filter == null)
      {
        return false;
      }

      if (MixerBitmapInterface == null)
      {
        return false;
      }

      if (GUIGraphicsContext.Vmr9Active == false)
      {
        Log.Info("SaveVMR9Bitmap() failed - no VMR9");
        return false;
      }
      int hr = 0;
      // transparent image?
      using (MemoryStream mStr = new MemoryStream())
      {
        if (bitmap != null)
        {
          if (transparent == true)
          {
            bitmap.MakeTransparent(Color.Black);
          }
          bitmap.Save(mStr, ImageFormat.Bmp);
          mStr.Position = 0;
        }

        VMR9AlphaBitmap bmp = new VMR9AlphaBitmap();

        if (show == true)
        {
          // get AR for the bitmap
          Rectangle src, dest;
          g_vmr9.GetVideoWindows(out src, out dest);

          int width = g_vmr9.VideoWidth;
          int height = g_vmr9.VideoHeight;

          float xx = (float)src.X / width;
          float yy = (float)src.Y / height;
          float fx = (float)(src.X + src.Width) / width;
          float fy = (float)(src.Y + src.Height) / height;
          //

          using (
            Surface surface = GUIGraphicsContext.DX9Device.CreateOffscreenPlainSurface(GUIGraphicsContext.Width,
                                                                                       GUIGraphicsContext.Height,
                                                                                       Format.X8R8G8B8,
                                                                                       Pool.SystemMemory))
          {
            SurfaceLoader.FromStream(surface, mStr, Filter.None, 0);
            bmp.dwFlags = (VMR9AlphaBitmapFlags)(4 | 8);
            bmp.clrSrcKey = 0;
            unsafe
            {
              bmp.pDDS = (IntPtr)surface.UnmanagedComPointer;
            }
            bmp.rDest = new NormalizedRect();
            bmp.rDest.top = yy;
            bmp.rDest.left = xx;
            bmp.rDest.bottom = fy;
            bmp.rDest.right = fx;
            bmp.fAlpha = alphaValue;
            //Log.Info("SaveVMR9Bitmap() called");
            hr = g_vmr9.MixerBitmapInterface.SetAlphaBitmap(ref bmp);
            if (hr != 0)
            {
              //Log.Info("SaveVMR9Bitmap() failed: error {0:X} on SetAlphaBitmap()",hr);
              return false;
            }
          }
        }
        else
        {
          bmp.dwFlags = (VMR9AlphaBitmapFlags)1;
          bmp.clrSrcKey = 0;
          bmp.rDest = new NormalizedRect();
          bmp.rDest.top = 0.0f;
          bmp.rDest.left = 0.0f;
          bmp.rDest.bottom = 1.0f;
          bmp.rDest.right = 1.0f;
          bmp.fAlpha = alphaValue;
          hr = g_vmr9.MixerBitmapInterface.UpdateAlphaBitmapParameters(ref bmp);
          if (hr != 0)
          {
            return false;
          }
        }
      }
      // dispose
      return true;
    }