public void Update(DX11RenderContext context) { if ((isImageReady && invalidate) || !this.FTextureOutput[0].Contains(context)) { if (this.FTextureOutput[0].Contains(context)) { this.FTextureOutput[0].Dispose(context); } texture = new DX11DynamicTexture2D(context, width, height, SlimDX.DXGI.Format.B8G8R8A8_UNorm); this.FTextureOutput[0][context] = texture; invalidate = false; } if (browser != null && image != null && isImageReady && FEnabledIn[0]) { lock (bLock) { unsafe { fixed(byte *p = image) { texture.WriteDataPitch((IntPtr)p, width * height * 4); } } } } }
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; } } }
unsafe void ThreadedFunction() { Random random = new Random(); Thread.Sleep((int)(random.NextDouble() * 1000.0)); while(FRunningThread) { try { if (FNeedsRelist) { try { var filenames = Directory.GetFiles(FPath, FMask); lock (FMemoryPoolLock) { FMemoryPool.Clear(); foreach (var filename in filenames) { var image = new Image(); image.Filename = filename; FMemoryPool.Add(image); } } } catch (Exception e) { FLogger.Log(e); } FNeedsRelist = false; } lock (FMemoryPoolLock) { int imageIndex = 0; foreach (var image in FMemoryPool) { try { if (!image.LoadedCPU) { var bitmap = new Bitmap(image.Filename); image.Data = new byte[FWidth * FHeight]; var bitmapData = bitmap.LockBits(new Rectangle(0, 0, FWidth, FHeight), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); Exception e3 = null; try { byte* input = (byte*)bitmapData.Scan0; fixed (byte* outputFixed = &image.Data[0]) { byte* output = outputFixed; for (int i = 0; i < FWidth * FHeight; i++) { input++; //a int pixelData = 0; pixelData += *input++; pixelData += *input++; pixelData += *input++; *output++ = (byte)(pixelData / 3); } } image.LoadedCPU = true; } catch (Exception e2) { e3 = e2; } finally { bitmap.UnlockBits(bitmapData); } if (e3 != null) { throw (e3); } //we've done enough work for this cycle break; } lock (FTexturePoolLock) { foreach (var resourcePool in FTexturePool) { lock(FLockCreation)// make sure all threads don't go crazy at the same time { var context = resourcePool.Key; var texturePool = resourcePool.Value.FTextures; if (texturePool.Count <= imageIndex) { var texture = new DX11DynamicTexture2D(context, FWidth, FHeight, SlimDX.DXGI.Format.R8_UNorm); GCHandle pinnedArray = GCHandle.Alloc(image.Data, GCHandleType.Pinned); IntPtr pointer = pinnedArray.AddrOfPinnedObject(); texture.WriteDataPitch(pointer, image.Data.Length, FWidth); pinnedArray.Free(); texturePool.Add(texture); } } //we've done enough work for this cycle break; } } } catch (Exception e) { FLogger.Log(e); } imageIndex++; } } } catch(Exception e) { } Thread.Sleep(10); } }