public void Dispose() { if (_decompress) { _decompressor.Dispose(); } else { _compressor.Dispose(); } }
/// <summary> /// Call this when finished with the instance. If using a C# using block, you won't need to call this. /// </summary> public void Dispose() { try { lock (this) { if (isDisposed) { return; } isDisposed = true; decoder.Dispose(); decomp.Dispose(); comp.Dispose(); } } catch (Exception) { Console.WriteLine("Exception disposing TurboJpeg stuff in JpegDiffVideoEncoder"); } }
private static void JpegTurboCompression() { var sw = new Stopwatch(); var sourceImage = (Bitmap)Image.FromFile(@"D:\Downloads\1.jpg"); var width = sourceImage.Width; var height = sourceImage.Height; long average = 0; var iterations = 0; var compressor = new TJCompressor(); try { Console.WriteLine("Using libjpeg turbo"); while (!_stop) { sw.Restart(); compressor.Compress(sourceImage, TJSubsamplingOptions.TJSAMP_GRAY, Quality, TJFlags.BOTTOMUP); sw.Stop(); var sleepValue = 1000 / 25.0 - sw.ElapsedMilliseconds; if (sleepValue < 0) { sleepValue = 0; } average += sw.ElapsedMilliseconds; iterations++; Thread.Sleep((int)sleepValue); } Console.WriteLine("Average compression time for image {0}x{1} is {2:f3} ms. Iterations count {3}", width, height, (double)average / iterations, iterations); } finally { compressor.Dispose(); sourceImage.Dispose(); Wait.Set(); } }
private static void JpegTurboCompression() { var sw = new Stopwatch(); var sourceImage = (Bitmap)Image.FromFile(@"D:\Downloads\1.jpg"); var width = sourceImage.Width; var height = sourceImage.Height; long average = 0; var iterations = 0; var compressor = new TJCompressor(); try { Console.WriteLine("Using libjpeg turbo"); while (!_stop) { sw.Restart(); compressor.Compress(sourceImage, TJSubsamplingOptions.TJSAMP_GRAY, Quality, TJFlags.BOTTOMUP); sw.Stop(); var sleepValue = 1000 / 25.0 - sw.ElapsedMilliseconds; if (sleepValue < 0) sleepValue = 0; average += sw.ElapsedMilliseconds; iterations++; Thread.Sleep((int)sleepValue); } Console.WriteLine("Average compression time for image {0}x{1} is {2:f3} ms. Iterations count {3}", width, height, (double)average / iterations, iterations); } finally { compressor.Dispose(); sourceImage.Dispose(); Wait.Set(); } }
public void Clean() { _compressor.Dispose(); }
private static void JpegTurboCompression() { var sw = new Stopwatch(); var sourceImage = (Bitmap)Image.FromFile(@"d:\1.jpg"); var pixelFormat = sourceImage.PixelFormat; var width = sourceImage.Width; var height = sourceImage.Height; long average = 0; var iterations = 0; var compressor = new TJCompressor(); // ReSharper disable once ExceptionNotDocumented var srcData = sourceImage.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, pixelFormat); var stride = srcData.Stride; var srcPtr = srcData.Scan0; TJPixelFormats tjPixelFormat; switch (pixelFormat) { case PixelFormat.Format8bppIndexed: tjPixelFormat = TJPixelFormats.TJPF_GRAY; break; case PixelFormat.Format24bppRgb: tjPixelFormat = TJPixelFormats.TJPF_RGB; break; case PixelFormat.Format32bppArgb: tjPixelFormat = TJPixelFormats.TJPF_ARGB; break; default: throw new ArgumentOutOfRangeException(); } try { Console.WriteLine("Using libjpeg turbo"); while (!_stop) { sw.Restart(); compressor.Compress(srcPtr, stride, width, height, tjPixelFormat, TJSubsamplingOptions.TJSAMP_GRAY, Quality, TJFlags.BOTTOMUP); sw.Stop(); var sleepValue = 1000 / 25.0 - sw.ElapsedMilliseconds; if (sleepValue < 0) { sleepValue = 0; } average += sw.ElapsedMilliseconds; iterations++; Thread.Sleep((int)sleepValue); } Console.WriteLine("Average compression time for image {0}x{1} is {2:f3} ms. Iterations count {3}", width, height, (double)average / iterations, iterations); } finally { sourceImage.UnlockBits(srcData); compressor.Dispose(); sourceImage.Dispose(); Wait.Set(); } }