private void LoadTexture(String imageFile) { lock (textureLock) { if (mCardTexture != null) { mCardTexture.Dispose(); mCardTexture = null; } if (File.Exists(imageFile)) { BitmapImage src = new BitmapImage(); src.BeginInit(); src.UriSource = new Uri(imageFile); src.EndInit(); WriteableBitmap wb = new WriteableBitmap(src); mCardTexture = GS.CreateTexture((UInt32)wb.PixelWidth, (UInt32)wb.PixelHeight, GSColorFormat.GS_BGRA, null, false, false); mCardTexture.SetImage(wb.BackBuffer, GSImageFormat.GS_IMAGEFORMAT_BGRA, (UInt32)(wb.PixelWidth * 4)); } else { mCardTexture = null; } } }
override public void UpdateSettings() { UInt32 width = (UInt32)config.GetInt("width", 640); UInt32 height = (UInt32)config.GetInt("height", 480); Size.X = width; Size.Y = height; config.Parent.SetInt("cx", (Int32)width); config.Parent.SetInt("cy", (Int32)height); lock (textureLock) { if (texture != null) { texture.Dispose(); texture = null; } texture = GS.CreateTexture(width, height, GSColorFormat.GS_BGRA, null, false, false); } if (overlayHook == null) { overlayHook = new OverlayHook(); overlayHook.Start(width, height); } else { overlayHook.UpdateSize(width, height); } }
public override void Preprocess() { // only does something if browser is single threaded event loop BrowserManager.Instance.Update(); lock (pendingTextureLock) { if (pendingTexture != null && pendingTexture.Texture == null) { pendingTexture.Texture = GS.CreateTexture(pendingTexture.Width, pendingTexture.Height, GSColorFormat.GS_BGRA, null, false, false); } } }
public override void Render(float x, float y, float width, float height) { lock (textureLock) { try { if (texture != null) { texture.Dispose(); texture = null; } //if (File.Exists(imageFile)) //{ var c = new WebClient(); var bytes = c.DownloadData(_serverUrl + "liveview.jpg"); var ms = new MemoryStream(bytes); BitmapImage src = new BitmapImage(); src.BeginInit(); src.CacheOption = BitmapCacheOption.OnLoad; src.StreamSource = ms; src.EndInit(); WriteableBitmap wb = new WriteableBitmap(new FormatConvertedBitmap(src, PixelFormats.Bgra32, null, 0)); texture = GS.CreateTexture((UInt32)wb.PixelWidth, (UInt32)wb.PixelHeight, GSColorFormat.GS_BGRA, null, false, false); texture.SetImage(wb.BackBuffer, GSImageFormat.GS_IMAGEFORMAT_BGRA, (UInt32)(wb.PixelWidth * 4)); config.Parent.SetInt("cx", wb.PixelWidth); config.Parent.SetInt("cy", wb.PixelHeight); Size.X = (float)wb.PixelWidth; Size.Y = (float)wb.PixelHeight; GS.DrawSprite(texture, 0xFFFFFFFF, x, y, x + width, y + height); } catch (Exception exception) { this.Api.Log(exception.Message); } //} //else //{ // texture = null; //} } }
private void UpdateTexture() { if (imageData == null) { return; } currentSize.Height = imageData.Size.Height; currentSize.Width = imageData.Size.Width; lock (imageLock) { texture = GS.CreateTexture((uint)imageData.Size.Width, (uint)imageData.Size.Height, GSColorFormat.GS_BGRA, null, false, false); texture.SetImage(imageData.Pixels, GSImageFormat.GS_IMAGEFORMAT_BGRA, (UInt32)(imageData.Size.Width * 4)); } }
public override void Render(float x, float y, float width, float height) { if (_texture == null) { InitBmp(); Init(); _texture = GS.CreateTexture((UInt32)Size.X, (UInt32)Size.Y, GSColorFormat.GS_BGRA, null, false, false); } else { lock (ImageLock) { Pad.RefreshState(); _texture.SetImage(XBDrawer.Draw(Pad.GetJoyState()), GSImageFormat.GS_IMAGEFORMAT_BGRA, (UInt32)(Size.X * 4)); GS.DrawSprite(_texture, 0xFFFFFFFF, x, y, x + width, y + height); } } }
public override void Preprocess() { if (form == null || !form.Visible) { return; } lock (form.BackBufferLock) { var buffer = form.BackBuffer; if (texture == null || texture.Width != buffer.Width || texture.Height != buffer.Height) { if (texture != null) { texture.Dispose(); } texture = GS.CreateTexture((uint)buffer.Width, (uint)buffer.Height, GSColorFormat.GS_BGRA, null, false, false); Size = new Vector2(buffer.Width, buffer.Height); } Rectangle rect = new Rectangle(0, 0, buffer.Width, buffer.Height); System.Drawing.Imaging.BitmapData bmpData = buffer.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, buffer.PixelFormat); IntPtr ptr = bmpData.Scan0; int bytes = Math.Abs(bmpData.Stride) * buffer.Height; byte[] rgbValues = new byte[bytes]; System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes); buffer.UnlockBits(bmpData); texture.SetImage(rgbValues, GSImageFormat.GS_IMAGEFORMAT_BGRA, (uint)(buffer.Width * 4)); } }
private void GetImage(float x, float y, float width, float height) { try { var image = pipeProxy.GetImage(); if (image != null) { lock (imageLock) imageData = image; } } catch { isConnecting = true; lock (imageLock) { texture = GS.CreateTexture((uint)Size.X, (uint)Size.Y, GSColorFormat.GS_BGRA, null, false, false); GS.DrawSprite(texture, 0xFFFFFFFF, x, y, x + width, y + height); } Task.Run(() => ConnectWCF()); } }
public void ConnectWCF() { isConnecting = true; lock (imageLock) imageData = null; string lastConnectError = String.Empty; while (imageData == null && isRendering) { Debug.Print("OBS plugin is trying to reconnect..."); try { if (pipeFactory == null) { pipeFactory = new DuplexChannelFactory <IOBSPluginService>(this, new NetNamedPipeBinding() { MaxReceivedMessageSize = 8294400 * 2, MaxBufferSize = 8294400 * 2 }, new EndpointAddress( "net.pipe://localhost/ImageSource")); } if (pipeProxy == null) { pipeProxy = pipeFactory.CreateChannel(); } if (pipeProxy != null) { config.HideControls = Properties.Settings.Default.HideControls; uint timeout = 0; if (uint.TryParse(Properties.Settings.Default.FadeOutTimeout, out timeout)) { config.FadeOutTimeout = timeout; } else { Properties.Settings.Default.FadeOutTimeout = "15"; config.FadeOutTimeout = 15; } config.IsFadeOutEnabled = Properties.Settings.Default.IsFadeOutEnabled; Log.WriteInfo("Set config"); pipeProxy.SetConfig(config); Debug.Print("OBSPlugin: trying to get first image"); pipeProxy.Subscribe(); lock (imageLock) imageData = pipeProxy.GetFirstImage(); if (imageData == null) { Debug.Print("OBSPlugin: got null image data"); lock (imageLock) texture = GS.CreateTexture(100, 100, GSColorFormat.GS_BGRA, null, false, false); Size.X = 100; Size.Y = 100; } else { Log.WriteInfo("Got first image {0}x{1}", imageData.Size.Width, imageData.Size.Height); Log.WriteInfo("Update settings"); UpdateSettings(); Log.WriteInfo("Update texture"); UpdateTexture(); break; } } else { Debug.Print("OBSPlugin: pipe proxy is null"); } } catch (Exception e) { if (lastConnectError != e.Message) { Log.WriteError("OBS plugin connect error\n{0}\n{1}", e.Message, e.StackTrace); lastConnectError = e.Message; } pipeProxy = null; } Thread.Sleep(1000); } isConnecting = false; }
public bool UpdateTexture() { string text = Gw2Plugin.Instance.ScriptsManager.FormatString(this.config.GetString("textFormat")); if (text != this.oldText) { this.oldText = text; this.textImage.Text = text; } if (!this.textImage.AnimationActive) { this.textImage.StartAnimation(); } // Fade in and out when the fade animator is currently null (aka when the Mumble Link state changes) if (this.hideWhenGw2IsInactive && this.fadeAnimator == null) { if (!this.isVisible && Gw2Plugin.Instance.MumbleLinkManager.IsActive) { this.fadeAnimator = new FadeAnimator(FadeMode.FadeIn); } else if (this.isVisible && !Gw2Plugin.Instance.MumbleLinkManager.IsActive) { this.fadeAnimator = new FadeAnimator(FadeMode.FadeOut); } if (this.fadeAnimator != null) { this.fadeAnimator.AnimationFinished += (s_, e_) => { this.textImage.Animators.Remove(this.fadeAnimator); if (this.fadeAnimator.FadeMode == FadeMode.FadeOut) { this.isVisible = false; } }; // Workaround if another animator uses a custom viewport: // This viewport will be ignored in PixelWidth and PixelHeight if the image is actually smaller // Therefore, insert the fade animator before every other animator this.textImage.Animators.Insert(0, this.fadeAnimator); this.isVisible = true; } } else if (!this.hideWhenGw2IsInactive) { this.isVisible = true; } if (this.textImage.AnimateFrame() || this.texture == null) { int pixelWidth = this.textImage.Bitmap.PixelWidth; int pixelHeight = this.textImage.Bitmap.PixelHeight; byte[] pixels = this.textImage.GetPixels(); Texture newTexture = GS.CreateTexture((uint)pixelWidth, (uint)pixelHeight, GSColorFormat.GS_BGRA, null, false, false); newTexture.SetImage(pixels, GSImageFormat.GS_IMAGEFORMAT_BGRA, (uint)this.textImage.GetStride()); this.config.Parent.SetInt("cx", pixelWidth); this.config.Parent.SetInt("cy", pixelHeight); this.Size.X = pixelWidth; this.Size.Y = pixelHeight; lock (textureLock) this.texture = newTexture; return(true); } return(false); }