コード例 #1
0
        public static Bitmap ToD2D1Bitmap(this SdBitmap bitmap, RenderTarget renderTarget, PixelFormat pixelFormat)
        {
            var sourceArea       = new SdRect(0, 0, bitmap.Width, bitmap.Height);
            var bitmapProperties = new BitmapProperties(pixelFormat);
            var size             = new SharpDX.Size2(bitmap.Width, bitmap.Height);

            // Transform pixels from BGRA to RGBA.
            var stride = bitmap.Width * sizeof(int);

            using (var tempStream = new SharpDX.DataStream(bitmap.Height * stride, true, true))
            {
                // Lock System.Drawing.Bitmap
                var bitmapData = bitmap.LockBits(sourceArea, ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

                // Convert all pixels.
                for (var y = 0; y < bitmap.Height; y++)
                {
                    var offset = bitmapData.Stride * y;
                    for (var x = 0; x < bitmap.Width; x++)
                    {
                        // Not optimized.
                        var B = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        var G = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        var R = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        var A = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        tempStream.Write(R | (G << 8) | (B << 16) | (A << 24));
                    }
                }
                bitmap.UnlockBits(bitmapData);
                tempStream.Position = 0;
                return(new Bitmap(renderTarget, size, tempStream, stride, bitmapProperties));
            }
        }
コード例 #2
0
        internal async Task <Texture2D> GetTextureAsync(string id, SharpDX.Size2 size)
        {
            Texture2D texture2D = null;

            using (var dataStream = await GetImageAsync(id))
            {
                if (dataStream != null)
                {
                    CheckMemoryUse();

                    if (Settings.UseJpeg)
                    {
                        texture2D = Texture2DFromJpeg(deviceResources, dataStream);
                    }
                    else if (Settings.DownloadRaw)
                    {
                        texture2D = Texture2DRaw(deviceResources, dataStream, size);
                    }
                    else
                    {
                        texture2D = Texture2D(deviceResources, dataStream);
                    }
                }
            }

            return(texture2D);
        }
コード例 #3
0
        private static SharpDX.Direct2D1.Bitmap SDXBitmapFromSysBitmap(SharpDX.Direct2D1.WindowRenderTarget device, System.Drawing.Bitmap bitmap)
        {
            var sourceArea       = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height);
            var bitmapProperties = new BitmapProperties(new PixelFormat(SharpDX.DXGI.Format.R8G8B8A8_UNorm, AlphaMode.Premultiplied));
            var size             = new SharpDX.Size2(bitmap.Width, bitmap.Height);

            // Transform pixels from BGRA to RGBA
            int stride = bitmap.Width * sizeof(int);

            using (var tempStream = new SharpDX.DataStream(bitmap.Height * stride, true, true))
            {
                // Lock System.Drawing.Bitmap
                var bitmapData = bitmap.LockBits(sourceArea, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

                // Convert all pixels
                for (int y = 0; y < bitmap.Height; y++)
                {
                    int offset = bitmapData.Stride * y;
                    for (int x = 0; x < bitmap.Width; x++)
                    {
                        // Not optimized
                        byte B    = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte G    = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte R    = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte A    = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        int  rgba = R | (G << 8) | (B << 16) | (A << 24);
                        tempStream.Write(rgba);
                    }
                }
                bitmap.UnlockBits(bitmapData);
                tempStream.Position = 0;

                return(new SharpDX.Direct2D1.Bitmap(device, size, tempStream, stride, bitmapProperties));
            }
        }
コード例 #4
0
        public int PresentSurface(short cx, short cy, short arx, short ary, ref IntPtr dwSurface)
        {
            lock (_lock)
                if (dwSurface != IntPtr.Zero && cx != 0 && cy != 0)
                {
                    if (cx != _originalVideoSize.Width || cy != _originalVideoSize.Height)
                    {
                        _originalVideoSize = new Size(cx, cy);
                    }

                    _aspectRatio.Width  = arx;
                    _aspectRatio.Height = ary;

                    // We need to Dispose the created instance because SharpDX tracks all created objects. When the surface is disposed, it will get released
                    // on unmanaged side as well, that's why we set the dwSurface to IntPtr.Zero to avoid duplicated release (which leads to hard crashes).
                    using (Surface surf = new Surface(dwSurface))
                    {
                        SurfaceDescription surfaceDesc = _surface == null ? new SurfaceDescription() : _surface.Description;
                        SurfaceDescription surfDesc    = surf.Description;
                        if (surfaceDesc.Width != surfDesc.Width || surfaceDesc.Height != surfDesc.Height)
                        {
                            if (_surface != null)
                            {
                                _surface.Dispose();
                            }
                            _surface = Surface.CreateRenderTarget(_device, surfDesc.Width, surfDesc.Height, Format.A8R8G8B8, MultisampleType.None, 0, false);
                        }
                        _device.StretchRectangle(surf, _surface, TextureFilter.None);
                    }
                    // Clear pointer, surface was already released.
                    dwSurface = IntPtr.Zero;
                }

            VideoSizePresentDlgt vsp = VideoSizePresent;

            if (vsp != null)
            {
                vsp(this);
                VideoSizePresent = null;
            }

            // Inform caller that we have changed the texture
            if (_onTextureInvalidated != null)
            {
                _onTextureInvalidated();
            }

            if (_renderDlgt != null)
            {
                _renderDlgt();
            }

            return(0);
        }
コード例 #5
0
 public void Free()
 {
     if (_surface == null)
     {
         return;
     }
     AllocationChanged(-AllocationSize);
     _surface.Dispose();
     _surface = null;
     _size    = new Size();
 }
コード例 #6
0
 public void Free()
 {
     if (_texture == null)
     {
         return;
     }
     lock (_texture)
     {
         AllocationChanged(-AllocationSize);
         _surface0.Dispose();
         _texture.Dispose();
         _texture  = null;
         _surface0 = null;
     }
     _size = new Size();
 }
コード例 #7
0
        internal SharpDX.DataStream CreateBitmap(MemoryStream stream, out SharpDX.Size2 size)
        {
            using (var decoder = new BitmapDecoder(factory, stream, DecodeOptions.CacheOnDemand))
            {
                using (var formatConverter = new FormatConverter(factory))
                {
                    formatConverter.Initialize(decoder.GetFrame(0), PixelFormat.Format32bppPRGBA);

                    var stride     = formatConverter.Size.Width * 4;
                    var dataStream = new SharpDX.DataStream(formatConverter.Size.Height * stride, true, true);
                    formatConverter.CopyPixels(stride, dataStream);

                    size = formatConverter.Size;

                    return(dataStream);
                }
            }
        }
コード例 #8
0
        private SharpDX.Direct2D1.Bitmap GDIBitmapToSharpDXBitmap(System.Drawing.Bitmap bitmap, SharpDX.Direct2D1.RenderTarget device)
        {
            System.Drawing.Rectangle           sourceArea       = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height);
            SharpDX.Direct2D1.BitmapProperties bitmapProperties = new SharpDX.Direct2D1.BitmapProperties(new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.R8G8B8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied));
            SharpDX.Size2 size = new SharpDX.Size2(bitmap.Width, bitmap.Height);

            // Transform pixels from GDI's wild ass BGRA to DXGI-compatible RGBA.
            int stride = bitmap.Width * sizeof(int);

            using (SharpDX.DataStream pixelStream = new SharpDX.DataStream(bitmap.Height * stride, true, true))
            {
                // Lock the source bitmap.
                System.Drawing.Imaging.BitmapData bitmapData = bitmap.LockBits(sourceArea, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

                // Convert each pixel.
                for (int y = 0; y < bitmap.Height; ++y)
                {
                    int offset = bitmapData.Stride * y;
                    for (int x = 0; x < bitmap.Width; ++x)
                    {
                        byte B = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte G = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte R = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte A = Marshal.ReadByte(bitmapData.Scan0, offset++);

                        int rgba = R | (G << 8) | (B << 16) | (A << 24);
                        pixelStream.Write(rgba);
                    }
                }

                // Unlock source bitmap now.
                bitmap.UnlockBits(bitmapData);

                // Reset stream position for reading.
                pixelStream.Position = 0;

                // Create the SharpDX bitmap from the DataStream.
                return(new SharpDX.Direct2D1.Bitmap(device, size, pixelStream, stride, bitmapProperties));
            }
        }
コード例 #9
0
        public int PresentSurface(short cx, short cy, short arx, short ary, ref IntPtr dwTexture)
        {
            lock (_lock)
                if (dwTexture != IntPtr.Zero && cx != 0 && cy != 0)
                {
                    if (cx != _originalVideoSize.Width || cy != _originalVideoSize.Height)
                    {
                        _originalVideoSize = new Size(cx, cy);
                    }

                    _aspectRatio.Width  = arx;
                    _aspectRatio.Height = ary;

                    FilterGraphTools.TryDispose(ref _texture);
                    _texture = new Texture(dwTexture);
                }

            VideoSizePresentDlgt vsp = VideoSizePresent;

            if (vsp != null)
            {
                vsp(this);
                VideoSizePresent = null;
            }

            // Inform caller that we have changed the texture
            if (_onTextureInvalidated != null)
            {
                _onTextureInvalidated();
            }

            if (_renderDlgt != null)
            {
                _renderDlgt();
            }

            return(0);
        }
コード例 #10
0
ファイル: D2DHelpers.cs プロジェクト: filipkunc/GLGraphics
        internal static SharpDX.Direct2D1.Bitmap ToD2DBitmap(this System.Drawing.Bitmap bitmap, SharpDX.Direct2D1.RenderTarget renderTarget)
        {
            var sourceArea = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height);
            var bitmapProperties = new SharpDX.Direct2D1.BitmapProperties(
                new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied));
            var size = new SharpDX.Size2(bitmap.Width, bitmap.Height);

            // Transform pixels from BGRA to RGBA
            int stride = bitmap.Width * sizeof(int);
            using (var tempStream = new SharpDX.DataStream(bitmap.Height * stride, true, true))
            {
                // Lock System.Drawing.Bitmap
                var bitmapData = bitmap.LockBits(sourceArea, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

                // Convert all pixels
                for (int y = 0; y < bitmap.Height; y++)
                {
                    int offset = bitmapData.Stride * y;
                    for (int x = 0; x < bitmap.Width; x++)
                    {
                        // Not optimized
                        byte B = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte G = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte R = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte A = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        int rgba = B | (G << 8) | (R << 16) | (A << 24);
                        tempStream.Write(rgba);
                    }

                }
                bitmap.UnlockBits(bitmapData);
                tempStream.Position = 0;

                return new SharpDX.Direct2D1.Bitmap(renderTarget, size, tempStream, stride, bitmapProperties);
            }
        }
コード例 #11
0
 public static extern void SetAdvancedOptions(int subPicsBufferAhead, Size textureSize, bool pow2tex,
                                              bool disableAnimation);
コード例 #12
0
 public static unsafe int Calliint25(void *thisObject, SharpDX.Size2 arg0, void *arg1, int arg2, void *arg3, void *arg4, void *methodPtr)
 {
     throw new NotImplementedException();
 }
コード例 #13
0
 internal Texture2D Texture2DRaw(DeviceResources deviceResources, MemoryStream rawData, SharpDX.Size2 size)
 {
     using (var dataStream = new SharpDX.DataStream((int)rawData.Length, true, true))
     {
         dataStream.Write(rawData.ToArray(), 0, (int)rawData.Length);
         var texture2D = Texture2D(deviceResources, dataStream, size);
         return(texture2D);
     }
 }
コード例 #14
0
 public static unsafe void CalliStdCallvoid0(void *thisObject, void *param0, SharpDX.Mathematics.Interop.RawBool param1, SharpDX.Size2 param2, void *methodPtr)
 {
     throw null;
 }
コード例 #15
0
ファイル: EVRCallback.cs プロジェクト: BigGranu/MediaPortal-2
    public int PresentSurface(short cx, short cy, short arx, short ary, ref IntPtr dwSurface)
    {
      lock (_lock)
        if (dwSurface != IntPtr.Zero && cx != 0 && cy != 0)
        {
          if (cx != _originalVideoSize.Width || cy != _originalVideoSize.Height)
            _originalVideoSize = new Size(cx, cy);

          _aspectRatio.Width = arx;
          _aspectRatio.Height = ary;

          // We need to Dispose the created instance because SharpDX tracks all created objects. When the surface is disposed, it will get released
          // on unmanaged side as well, that's why we set the dwSurface to IntPtr.Zero to avoid duplicated release (which leads to hard crashes).
          using (Surface surf = new Surface(dwSurface))
          {
            SurfaceDescription surfaceDesc = _surface == null ? new SurfaceDescription() : _surface.Description;
            SurfaceDescription surfDesc = surf.Description;
            if (surfaceDesc.Width != surfDesc.Width || surfaceDesc.Height != surfDesc.Height)
            {
              if (_surface != null)
                _surface.Dispose();
              _surface = Surface.CreateRenderTarget(_device, surfDesc.Width, surfDesc.Height, Format.A8R8G8B8, MultisampleType.None, 0, false);
            }
            _device.StretchRectangle(surf, _surface, TextureFilter.None);
          }
          // Clear pointer, surface was already released.
          dwSurface = IntPtr.Zero;
        }

      VideoSizePresentDlgt vsp = VideoSizePresent;
      if (vsp != null)
      {
        vsp(this);
        VideoSizePresent = null;
      }

      // Inform caller that we have changed the texture
      if (_onTextureInvalidated != null)
        _onTextureInvalidated();

      if (_renderDlgt != null)
        _renderDlgt();

      return 0;
    }
コード例 #16
0
 public void Free()
 {
   if (_surface == null)
     return;
   AllocationChanged(-AllocationSize);
   _surface.Dispose();
   _surface = null;
   _size = new Size();
 }
コード例 #17
0
        internal static Texture2D Texture2D(DeviceResources deviceResources, SharpDX.DataStream stream, SharpDX.Size2 size)
        {
            var textDesc = TextureDescription(1, size.Width, size.Height, ResourceOptionFlags.None);

            SharpDX.DataBox[] dataRects = { new SharpDX.DataBox(stream.DataPointer, size.Width * 4, 0) };

            var texture2D = new Texture2D(deviceResources.D3DDevice, textDesc, dataRects);

            return(texture2D);
        }
コード例 #18
0
ファイル: EVRCallback.cs プロジェクト: davinx/MediaPortal-2
    public int PresentSurface(short cx, short cy, short arx, short ary, ref IntPtr dwTexture)
    {
      lock (_lock)
        if (dwTexture != IntPtr.Zero && cx != 0 && cy != 0)
        {
          if (cx != _originalVideoSize.Width || cy != _originalVideoSize.Height)
            _originalVideoSize = new Size(cx, cy);

          _aspectRatio.Width = arx;
          _aspectRatio.Height = ary;

          FilterGraphTools.TryDispose(ref _texture);
          _texture = new Texture(dwTexture);
        }

      VideoSizePresentDlgt vsp = VideoSizePresent;
      if (vsp != null)
      {
        vsp(this);
        VideoSizePresent = null;
      }

      // Inform caller that we have changed the texture
      if (_onTextureInvalidated != null)
        _onTextureInvalidated();

      if (_renderDlgt != null)
        _renderDlgt();

      return 0;
    }
コード例 #19
0
 public static unsafe void Callivoid42(void *thisObject, void *arg0, SharpDX.Mathematics.Interop.RawBool arg1, SharpDX.Size2 arg2, void *methodPtr)
 {
     throw new NotImplementedException();
 }
コード例 #20
0
        internal static Texture2D TextureCube(DeviceResources deviceResources, SharpDX.DataStream stream, SharpDX.Size2 size)
        {
            var arraySize = 6;
            var textDesc  = TextureDescription(arraySize, size.Width, size.Height, ResourceOptionFlags.TextureCube);

            var stride    = size.Width * 4;
            var dataRects = new SharpDX.DataBox[arraySize];

            for (var i = 0; i < arraySize; i++)
            {
                dataRects[i] = new SharpDX.DataBox(stream.DataPointer, stride, 0);
            }

            var texture2D = new Texture2D(deviceResources.D3DDevice, textDesc, dataRects);

            return(texture2D);
        }
コード例 #21
0
 public void Free()
 {
   if (_texture == null)
     return;
   lock (_texture)
   {
     AllocationChanged(-AllocationSize);
     _surface0.Dispose();
     _texture.Dispose();
     _texture = null;
     _surface0 = null;
   }
   _size = new Size();
 }
コード例 #22
0
 public static extern bool LoadSubtitles(IntPtr d3DDev, Size size, string filename, IGraphBuilder graphBuilder,
                                         string paths, int lcidCI);
コード例 #23
0
ファイル: EVRCallback.cs プロジェクト: CAARNICL/MediaPortal-2
    public int PresentSurface(short cx, short cy, short arx, short ary, IntPtr dwSurface)
    {
      lock (_lock)
        if (dwSurface != IntPtr.Zero && cx != 0 && cy != 0)
        {
          if (cx != _originalVideoSize.Width || cy != _originalVideoSize.Height)
            _originalVideoSize = new Size(cx, cy);

          _aspectRatio.Width = arx;
          _aspectRatio.Height = ary;

          Surface surf = new Surface(dwSurface); // No using / Dispose here as we did not create this surface (done by EVR!)
          SurfaceDescription surfaceDesc = _surface == null ? new SurfaceDescription() : _surface.Description;
          SurfaceDescription surfDesc = surf.Description;
          if (surfaceDesc.Width != surfDesc.Width || surfaceDesc.Height != surfDesc.Height)
          {
            if (_surface != null)
              _surface.Dispose();
            _surface = Surface.CreateRenderTarget(_device, surfDesc.Width, surfDesc.Height, Format.A8R8G8B8, MultisampleType.None, 0, false);
          }

          _device.StretchRectangle(surf, _surface, TextureFilter.None);
        }

      VideoSizePresentDlgt vsp = VideoSizePresent;
      if (vsp != null)
      {
        vsp(this);
        VideoSizePresent = null;
      }

      // Inform caller that we have changed the texture
      if (_onTextureInvalidated != null)
        _onTextureInvalidated();

      if (_renderDlgt != null)
        _renderDlgt();

      return 0;
    }