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)); } }
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); }
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)); } }
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); }
public void Free() { if (_surface == null) { return; } AllocationChanged(-AllocationSize); _surface.Dispose(); _surface = null; _size = new Size(); }
public void Free() { if (_texture == null) { return; } lock (_texture) { AllocationChanged(-AllocationSize); _surface0.Dispose(); _texture.Dispose(); _texture = null; _surface0 = null; } _size = new Size(); }
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); } } }
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)); } }
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); }
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); } }
public static extern void SetAdvancedOptions(int subPicsBufferAhead, Size textureSize, bool pow2tex, bool disableAnimation);
public static unsafe int Calliint25(void *thisObject, SharpDX.Size2 arg0, void *arg1, int arg2, void *arg3, void *arg4, void *methodPtr) { throw new NotImplementedException(); }
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); } }
public static unsafe void CalliStdCallvoid0(void *thisObject, void *param0, SharpDX.Mathematics.Interop.RawBool param1, SharpDX.Size2 param2, void *methodPtr) { throw null; }
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; }
public void Free() { if (_surface == null) return; AllocationChanged(-AllocationSize); _surface.Dispose(); _surface = null; _size = new Size(); }
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); }
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; }
public static unsafe void Callivoid42(void *thisObject, void *arg0, SharpDX.Mathematics.Interop.RawBool arg1, SharpDX.Size2 arg2, void *methodPtr) { throw new NotImplementedException(); }
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); }
public void Free() { if (_texture == null) return; lock (_texture) { AllocationChanged(-AllocationSize); _surface0.Dispose(); _texture.Dispose(); _texture = null; _surface0 = null; } _size = new Size(); }
public static extern bool LoadSubtitles(IntPtr d3DDev, Size size, string filename, IGraphBuilder graphBuilder, string paths, int lcidCI);
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; }