public CompressScreen(bool _dxMode) { this.screenBounds = Screen.PrimaryScreen.Bounds; prev = new Bitmap(screenBounds.Width, screenBounds.Height, PixelFormat.Format32bppArgb); cur = new Bitmap(screenBounds.Width, screenBounds.Height, PixelFormat.Format32bppArgb); using (Graphics g = Graphics.FromImage(prev)) { g.Clear(Color.Black); } compressionBuffer = new byte[screenBounds.Width * screenBounds.Height * 4]; int backBufSize = LZ4.LZ4Codec.MaximumOutputLength(compressionBuffer.Length) + 4; compressedScreen = new CompressedScreen(backBufSize); //directX Constructor if (_dxMode == true) { factory = new Factory1(); adapter = factory.GetAdapter1(0); device = new SharpDX.Direct3D11.Device(adapter); output = adapter.GetOutput(0); output1 = output.QueryInterface <Output1>(); textureDesc = new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = screenBounds.Width, Height = screenBounds.Height, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging }; screenTexture = new Texture2D(device, textureDesc); duplicatedOutput = output1.DuplicateOutput(device); } }
public DecompressScreen(CompressedScreen compressed) { decompressed = new byte[LZ4.LZ4Codec.MaximumOutputLength(compressed.Data.Length)]; LZ4.LZ4Codec.Decode(compressed.Data, 0, compressed.Size, decompressed, 0, decompressed.Length); }