private static unsafe void TestEmpty(ILZ4Compressor compressor, ILZ4Decompressor decompressor) { var bytes = new byte[50]; byte[] dst = compressor.Compress(bytes); var result = decompressor.Decompress(dst); }
private static void Test(string directory, ILZ4Compressor compressor, ILZ4Decompressor decompressor) { var w = new Stopwatch(); var dw = new Stopwatch(); long compressedTotal = 0; long uncompressedTotal = 0; for(int j=0;j<10;j++) foreach (var bytes in Read(directory)) { uncompressedTotal += bytes.Length; byte[] compressed = new byte[compressor.CalculateMaxCompressedLength(bytes.Length)]; w.Start(); int compressedLength = compressor.Compress(bytes, compressed); compressedTotal += compressedLength; w.Stop(); byte[] uncompressed = new byte[bytes.Length]; dw.Start(); decompressor.DecompressKnownSize(compressed, uncompressed, uncompressed.Length); dw.Stop(); for (int i = 0; i < uncompressed.Length; i++) { if (uncompressed[i] != bytes[i]) throw new Exception("Original bytes and decompressed bytes differ starting at byte " + i); } } Console.WriteLine("Ratio = " + compressedTotal * 1.0 / uncompressedTotal); Console.WriteLine("Compression Time (MB / sec) = " + uncompressedTotal / 1024.0 / 1024.0 / w.Elapsed.TotalSeconds); Console.WriteLine("Uncompression Time (MB / sec) = " + uncompressedTotal / 1024.0 / 1024.0 / dw.Elapsed.TotalSeconds); }
public ScapCapture(bool RecordMic, int NumberofThreads, int FramesPerSecond, ScapVideoFormats VideoFormat, ScapImageFormats ImageFormat, int Xcoord, int Ycoord, int CaptureWidth, int CaptureHeight, string CaptureDirectory, string ImageFilename, string VideoFilename, int Runtime) { IsSoundEnabled = RecordMic; IsMultiThreaded = true; Sw = new Stopwatch(); Compressor = LZ4CompressorFactory.CreateNew(); Decompressor = LZ4DecompressorFactory.CreateNew(); Imgext = ""; Vidext = ""; if (!Directory.Exists(CaptureDirectory)) { Directory.CreateDirectory(CaptureDirectory); Dir = CaptureDirectory + "\\"; } else { Dir = CaptureDirectory + "\\"; } Imgname = ImageFilename; Vidname = VideoFilename; Vidform = VideoFormat; Imgform = ImageFormat; NumThreads = 1; X = Xcoord; Y = Ycoord; W = CaptureWidth; H = CaptureHeight; Rtime = Runtime; Frames = 0; Capture = 0; FPS = FramesPerSecond; FBegin = 0; FEnd = -1; Length = 0; DecompProgress = 0; EncodeProgress = 0; CompressedDataList = new List <Databank>(); MainDataLists = new List <Databank> [NumThreads]; CompressorBools = new bool[NumThreads]; for (int c = 0; c < NumThreads; c++) { MainDataLists[c] = new List <Databank>(); MainDataLists[c].Capacity = 25; CompressorBools[c] = false; } IsInitialized = true; IsDecompressed = false; IsEncoded = false; IsMultiThreaded = false; HasCaptured = false; }
public Client(string address, int port = 4949) { ctx = new Context(4); sock = ctx.Socket(SocketType.REQ); // TODO: set me bmp = new Bitmap(640, 480, PixelFormat.Format16bppRgb555); sock.Connect("tcp://"+address+":"+port.ToString()); buf = new byte[640*480*3]; // w*h*BYTES PER PIXEL! dcmp = new LZ4Decompressor64(); // returns appropriate sized decompressor decompressed = new byte[640 * 480 * 3]; }
public override ExtendedDataInput Decompress(ExtendedDataInput input, int length, int unitLength, int elementCount, int extra, bool isLittleEndian) { int offset = 8; byte[] output = CreateColumnVector(elementCount, extra, unitLength, isLittleEndian, 0).array(); ILZ4Decompressor t = LZ4DecompressorFactory.CreateNew(); while (length > 0) { int blockSize = input.readInt(); if (blockSize < 0) { blockSize = blockSize & 2147483647; } length -= sizeof(int); blockSize = Math.Min(blockSize, length); if (blockSize == 0) { break; } byte[] src = new byte[blockSize]; int index = 0; while (index < blockSize) { index += ((BinaryReader)input).Read(src, index, blockSize - index); } byte[] ret = t.Decompress(src); if (offset + ret.Length > output.Length) { byte[] tmp = new byte[Math.Max(offset + ret.Length, output.Length) * 2]; Array.Copy(output, tmp, offset); output = tmp; } Buffer.BlockCopy(ret, 0, output, offset, ret.Length); offset += ret.Length; length -= blockSize; } if (isLittleEndian) { return(new LittleEndianDataInputStream(new MemoryStream(output))); } return(new BigEndianDataInputStream(new MemoryStream(output))); }
public ScapCapture(bool RecordMic, int NumberofThreads, int FramesPerSecond, ScapVideoFormats VideoFormat, ScapImageFormats ImageFormat, int Xcoord, int Ycoord, int CaptureWidth, int CaptureHeight) { IsSoundEnabled = RecordMic; IsMultiThreaded = true; Sw = new Stopwatch(); Compressor = LZ4CompressorFactory.CreateNew(); Decompressor = LZ4DecompressorFactory.CreateNew(); Imgext = ".bmp"; Vidext = ".avi"; Dir = Directory.GetCurrentDirectory() + "\\"; Imgname = ""; Vidname = "Vid"; Vidform = VideoFormat; Imgform = ImageFormat; NumThreads = NumberofThreads; X = Xcoord; Y = Ycoord; W = CaptureWidth; H = CaptureHeight; Rtime = -1; Frames = 0; Capture = 0; FPS = FramesPerSecond; FBegin = 0; FEnd = -1; Length = 0; DecompProgress = 0; EncodeProgress = 0; CompressedDataList = new List <Databank>(); MainDataLists = new List <Databank> [NumThreads]; CompressorBools = new bool[NumThreads]; for (int c = 0; c < NumThreads; c++) { MainDataLists[c] = new List <Databank>(); MainDataLists[c].Capacity = 25; CompressorBools[c] = false; } IsInitialized = true; IsDecompressed = false; IsEncoded = false; IsMultiThreaded = false; HasCaptured = false; }
public ScapCapture(bool RecordMic, int NumberofThreads) { IsSoundEnabled = RecordMic; IsMultiThreaded = true; Sw = new Stopwatch(); Compressor = LZ4CompressorFactory.CreateNew(); Decompressor = LZ4DecompressorFactory.CreateNew(); Imgext = ".bmp"; Vidext = ".avi"; Dir = Directory.GetCurrentDirectory() + "\\"; Imgname = ""; Vidname = "Vid"; Vidform = ScapVideoFormats.Default; Imgform = ScapImageFormats.Bmp; NumThreads = NumberofThreads; X = 0; Y = 0; W = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width; H = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height; Rtime = -1; Frames = 0; Capture = 0; FPS = 50; FBegin = 0; FEnd = -1; Length = 0; DecompProgress = 0; EncodeProgress = 0; CompressedDataList = new List <Databank>(); MainDataLists = new List <Databank> [NumThreads]; CompressorBools = new bool[NumThreads]; for (int c = 0; c < NumThreads; c++) { MainDataLists[c] = new List <Databank>(); MainDataLists[c].Capacity = 25; CompressorBools[c] = false; } IsInitialized = true; IsDecompressed = false; IsEncoded = false; IsMultiThreaded = false; HasCaptured = false; }
private static void Test(string directory, ILZ4Compressor compressor, ILZ4Decompressor decompressor) { var w = new Stopwatch(); var dw = new Stopwatch(); long compressedTotal = 0; long uncompressedTotal = 0; for (int j = 0; j < 10; j++) { foreach (var bytes in Read(directory)) { uncompressedTotal += bytes.Length; byte[] compressed = new byte[compressor.CalculateMaxCompressedLength(bytes.Length)]; w.Start(); int compressedLength = compressor.Compress(bytes, compressed); compressedTotal += compressedLength; w.Stop(); byte[] uncompressed = new byte[bytes.Length]; dw.Start(); decompressor.DecompressKnownSize(compressed, uncompressed, uncompressed.Length); dw.Stop(); for (int i = 0; i < uncompressed.Length; i++) { if (uncompressed[i] != bytes[i]) { throw new Exception("Original bytes and decompressed bytes differ starting at byte " + i); } } } } Console.WriteLine("Ratio = " + compressedTotal * 1.0 / uncompressedTotal); Console.WriteLine("Compression Time (MB / sec) = " + uncompressedTotal / 1024.0 / 1024.0 / w.Elapsed.TotalSeconds); Console.WriteLine("Uncompression Time (MB / sec) = " + uncompressedTotal / 1024.0 / 1024.0 / dw.Elapsed.TotalSeconds); }
public LZ4Compressor() { _compressor = LZ4CompressorFactory.CreateNew(); _decompressor = LZ4DecompressorFactory.CreateNew(); }
private static void TestUnknownSize(string directory, ILZ4Compressor compressor, ILZ4Decompressor decompressor) { foreach (var file in Directory.GetFiles(directory)) { var bytes = File.ReadAllBytes(file); var compressed = compressor.Compress(bytes); var decompressed = decompressor.Decompress(compressed); if (!bytes.SequenceEqual(decompressed)) throw new Exception("Compressing/Decompressing " + file + " failed."); } }
public void SetDecompressor(ILZ4Decompressor decompressor) { this.decompressor = decompressor; }
public LZ4Protection() : base() { this.Lz4Compressor = new LZ4Compressor32(); this.Lz4Decompressor = new LZ4Decompressor32(); }
private static void TestUnknownSize(string directory, ILZ4Compressor compressor, ILZ4Decompressor decompressor) { foreach (var file in Directory.GetFiles(directory)) { var bytes = File.ReadAllBytes(file); var compressed = compressor.Compress(bytes); var decompressed = decompressor.Decompress(compressed); if (!bytes.SequenceEqual(decompressed)) { throw new Exception("Compressing/Decompressing " + file + " failed."); } } }