public void Update(FeralTic.DX11.DX11RenderContext context) { for (int i = 0; i < FTextureOut.SliceCount; i++) { if (!FTextureOut[i].Contains(context)) { renderer = new BitmapRenderer(); renderer.TextFont = new System.Drawing.Font(FFontIn[i].Name, FFontSizeIn[i]); Bitmap bmp = new Bitmap(GenerateBarcodeImage(i)); DX11DynamicTexture2D tex = new DX11DynamicTexture2D(context, bmp.Width, bmp.Height, SlimDX.DXGI.Format.R8G8B8A8_UNorm); int pitch = tex.GetRowPitch(); var data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, bmp.PixelFormat); if (pitch != bmp.Width * 4) { tex.WriteDataPitch(data.Scan0, bmp.Width * bmp.Height * 4); } else { tex.WriteData(data.Scan0, bmp.Width * bmp.Height * 4); } FTextureOut[i][context] = tex; } } }
public void Update(IPluginIO pin, FeralTic.DX11.DX11RenderContext context) { for (int i = 0; i < this.FTextureOut.SliceCount; i++) { if (!this.FTextureOut[i].Contains(context)) { Bitmap bmp = ComputeQRCode(i); DX11DynamicTexture2D tex = new DX11DynamicTexture2D(context, bmp.Width, bmp.Height, SlimDX.DXGI.Format.R8G8B8A8_UNorm); int pitch = tex.GetRowPitch(); var data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, bmp.PixelFormat); if (pitch != bmp.Width * 4) { tex.WriteDataPitch(data.Scan0, bmp.Width * bmp.Height * 4); } else { tex.WriteData(data.Scan0, bmp.Width * bmp.Height * 4); } this.FTextureOut[i][context] = tex; } } }
public void Destroy(IPluginIO pin, FeralTic.DX11.DX11RenderContext context, bool force) { for (int i = 0; i < this.FTextureOut.SliceCount; i++) { if (this.FTextureOut[i] != null) { this.FTextureOut[i].Dispose(context); } } }
public DX11ResourceTexture2D SetTexture(Frame frame, DX11ResourceTexture2D texture, FeralTic.DX11.DX11RenderContext context) { device = context.Device; if (texture == null) { texture = new DX11ResourceTexture2D(context); } if (description.Width != 0) { if (!texture.MatchesSizeByDescription(description)) { var tex = new Texture2D(device, description); texture.SetResource(tex); texture.Meta = ""; } if (frame.Loaded && (texture.Meta != frame.Filename)) { frame.CopyResource(texture); texture.Meta = frame.Filename; } } return(texture); }
public void Process(DX11Resource <DX11Texture2D> input, FeralTic.DX11.DX11RenderContext context) { DX11Texture2D t = input[context]; var height = t.Height; var width = t.Width; var imageLink = Output; var imageAttributes = imageLink.ImageAttributes; var desiredImageFormat = ToOpenCVFormat(t.Format); if (desiredImageFormat == TColorFormat.UnInitialised) { throw (new Exception("No suitible image type available for this texture type " + t.Format.ToString())); } //-- //check attributes and reinitialise the image and offscreen buffer if we haven't got the right description ready // if (imageAttributes == null || FOffscreenBuffer == null || !imageAttributes.Initialised || FOffscreenBuffer.Description.Format != t.Description.Format || imageAttributes.Width != t.Width || imageAttributes.Height != t.Height || imageAttributes.ColorFormat != desiredImageFormat) { if (FOffscreenBuffer != null) { FOffscreenBuffer.Dispose(); } var description = new Texture2DDescription() { Width = width, Height = height, Format = t.Format, MipLevels = 1, Usage = ResourceUsage.Staging, BindFlags = BindFlags.None, CpuAccessFlags = CpuAccessFlags.Read, SampleDescription = new SampleDescription(1, 0), ArraySize = 1 }; FOffscreenBuffer = new Texture2D(context.Device, description); imageLink.Initialise(new CVImageAttributes(desiredImageFormat, t.Width, t.Height)); } // //-- //-- //copy the texture to offscreen buffer // context.CurrentDeviceContext.CopyResource(t.Resource, FOffscreenBuffer); // //-- //-- //copy the data out of the offscreen buffer // var surface = FOffscreenBuffer.AsSurface(); var bytesPerRow = imageAttributes.Stride; var data = MapForRead(context.CurrentDeviceContext); lock (imageLink.BackLock) { var image = imageLink.BackImage; try { var source = data.Data.DataPointer; image.SetPixels(source); var destination = image.Data; for (int row = 0; row < t.Height; row++) { CopyMemory(destination, source, bytesPerRow); source += data.RowPitch; destination += bytesPerRow; } } finally { UnMap(context.CurrentDeviceContext); } } // //-- imageLink.Swap(); }
public FeralTic.DX11.Resources.DX11ResourceTexture2D SetSRV(FeralTic.DX11.Resources.DX11ResourceTexture2D texture, FeralTic.DX11.DX11RenderContext context) { if (texture == null) { texture = new FeralTic.DX11.Resources.DX11ResourceTexture2D(context); } if (texture.Meta != this.filename && (WaitForFrame || this.Loaded)) { sw.Restart(); var handle = RefCounter.Use(); if (!this.Loaded) { try { LoadTask.Wait(); } catch (AggregateException) // .Wait can surface the exception { handle.Dispose(); LogExceptions(LoadTask, "while waiting"); } } if (this.Loaded) { texture.SetBySRV(decoder.SRV, handle); SwapTime = sw.Elapsed.TotalMilliseconds; } } return(texture); }
public void Destroy(FeralTic.DX11.DX11RenderContext context, bool force) { FTextureOut.SafeDisposeAll(context); }