Ejemplo n.º 1
0
        public void TestSetAlphaBitmap()
        {
            int hr = 0;

            // GDI Stuff
            IntPtr hdc     = g.GetHdc();
            IntPtr memDC   = CreateCompatibleDC(hdc);
            IntPtr hBirmap = bmp.GetHbitmap();

            SelectObject(memDC, hBirmap);

            alphaBitmap              = new VMR9AlphaBitmap();
            alphaBitmap.dwFlags      = VMR9AlphaBitmapFlags.hDC | VMR9AlphaBitmapFlags.SrcColorKey | VMR9AlphaBitmapFlags.FilterMode;
            alphaBitmap.hdc          = memDC;
            alphaBitmap.pDDS         = IntPtr.Zero;
            alphaBitmap.fAlpha       = 0.5f;
            alphaBitmap.rSrc         = new DsRect(0, 0, 255, 255); // SetAlphaBitmap only accept the full size
            alphaBitmap.rDest        = new NormalizedRect(0.0f, 0.0f, 1.0f, 1.0f);
            alphaBitmap.clrSrcKey    = ColorTranslator.ToWin32(colorKey);
            alphaBitmap.dwFilterMode = VMRMixerPrefs.BiLinearFiltering;

            hr = mixerBitmap.SetAlphaBitmap(ref alphaBitmap);
            DsError.ThrowExceptionForHR(hr);

            DeleteObject(hBirmap);
            DeleteDC(memDC);
            g.ReleaseHdc(hdc);

            Debug.Assert(hr == 0, "IVMRMixerBitmap9.SetAlphaBitmap");
        }
Ejemplo n.º 2
0
        public void TestUpdateAlphaBitmapParameters()
        {
            int hr = 0;

            // show the bitmap half smaller in the middle of the window
            // We don't change the image so no need to play again with GDI
            alphaBitmap              = new VMR9AlphaBitmap();
            alphaBitmap.dwFlags      = VMR9AlphaBitmapFlags.SrcColorKey | VMR9AlphaBitmapFlags.FilterMode;
            alphaBitmap.hdc          = IntPtr.Zero;
            alphaBitmap.pDDS         = IntPtr.Zero;
            alphaBitmap.fAlpha       = 0.5f;
            alphaBitmap.rSrc         = new DsRect(0, 0, 255, 255);
            alphaBitmap.rDest        = new NormalizedRect(0.25f, 0.25f, 0.75f, 0.75f);
            alphaBitmap.clrSrcKey    = ColorTranslator.ToWin32(colorKey);
            alphaBitmap.dwFilterMode = VMRMixerPrefs.BiLinearFiltering;

            hr = mixerBitmap.UpdateAlphaBitmapParameters(ref alphaBitmap);
            DsError.ThrowExceptionForHR(hr);

            Debug.Assert(hr == 0, "IVMRMixerBitmap9.UpdateAlphaBitmapParameters");
        }
Ejemplo n.º 3
0
        private void SetMixerSettings()
        {
            VMR9AlphaBitmap bitmap;

            if (!this._bMixerEnabled)
            {
                if (this._bMixerImageWasUsed)
                {
                    DsError.ThrowExceptionForHR(this.DX.MixerBitmap.GetAlphaBitmapParameters(out bitmap));
                    bitmap.dwFlags = VMR9AlphaBitmapFlags.Disable;
                    DsError.ThrowExceptionForHR(this.DX.MixerBitmap.UpdateAlphaBitmapParameters(ref bitmap));
                }
            }
            else if (this._OverlayBitmap != null)
            {
                Graphics graphics = Graphics.FromImage(this._OverlayBitmap);
                IntPtr   hdc      = graphics.GetHdc();
                IntPtr   ptr2     = NativeMethodes.CreateCompatibleDC(hdc);
                IntPtr   hbitmap  = this._OverlayBitmap.GetHbitmap();
                NativeMethodes.SelectObject(ptr2, hbitmap);
                bitmap = new VMR9AlphaBitmap {
                    dwFlags      = VMR9AlphaBitmapFlags.FilterMode | VMR9AlphaBitmapFlags.SrcColorKey | VMR9AlphaBitmapFlags.hDC,
                    hdc          = ptr2,
                    rSrc         = new DsRect(0, 0, this._OverlayBitmap.Size.Width, this._OverlayBitmap.Size.Height),
                    rDest        = new NormalizedRect(0f, 0f, 1f, 1f),
                    clrSrcKey    = ColorTranslator.ToWin32(this._GDIColorKey),
                    dwFilterMode = VMRMixerPrefs.PointFiltering,
                    fAlpha       = this._GDIAlphaValue
                };
                DsError.ThrowExceptionForHR(this.DX.MixerBitmap.SetAlphaBitmap(ref bitmap));
                NativeMethodes.DeleteObject(hbitmap);
                NativeMethodes.DeleteDC(ptr2);
                graphics.ReleaseHdc(hdc);
                graphics.Dispose();
                this._bMixerImageWasUsed = true;
            }
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
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);
        }