/// <summary> /// One-liner to save Bitmaps to JPEG using LibJpeg. /// </summary> /// <param name="image">Bitmap</param> /// <param name="filename">Path to save to. Creates or overwrites if existing.</param> /// <param name="compression">Compression parameters.</param> public void Save(Bitmap image, string filename, CompressionParameters compression = null) { using(var jpeg = new JpegImage(image)) { jpeg.Save(filename, compression); } }
/// <summary> /// One-liner to save Bitmaps to JPEG using LibJpeg. /// </summary> /// <param name="image">Bitmap</param> /// <param name="filename">Path to save to. Creates or overwrites if existing.</param> /// <param name="compression">Compression parameters.</param> public void Save(Bitmap image, string filename, CompressionParameters compression = null) { using (var jpeg = new JpegImage(image)) { jpeg.Save(filename, compression); } }
private void Dispose(bool disposing) { if (!m_alreadyDisposed) { if (disposing) { // dispose managed resources if (m_compressedData != null) { m_compressedData.Dispose(); } if (m_decompressedData != null) { m_decompressedData.Dispose(); } } // free native resources m_compressionParameters = null; m_compressedData = null; m_decompressedData = null; m_rows = null; m_alreadyDisposed = true; } }
private void Dispose(bool disposing) { if (!m_alreadyDisposed) { if (disposing) { // dispose managed resources if (m_compressedData != null) { m_compressedData.Dispose(); } if (m_decompressedData != null) { m_decompressedData.Dispose(); } //#if !NETSTANDARD // if (m_bitmap != null) // m_bitmap.Dispose(); //#endif } // free native resources m_compressionParameters = null; m_compressedData = null; m_decompressedData = null; //#if !NETSTANDARD // m_bitmap = null; //#endif m_rows = null; m_alreadyDisposed = true; } }
/// <summary> /// Saves the jpeg to a file. /// </summary> /// <param name="filename">Path to save to. Will create or overwrite if existing.</param> /// <param name="parameters">Optional compression parameters.</param> public void Save(string filename, CompressionParameters parameters = null) { using (var stream = File.OpenWrite(filename)) { WriteJpeg(stream, parameters); } }
private void Compress(CompressionParameters parameters) { Debug.Assert(m_rows is object); Debug.Assert(m_rows.Count != 0); var source = new RawImage(m_rows, Colorspace); Compress(source, parameters); }
private void compress(CompressionParameters parameters) { Debug.Assert(m_rows != null); Debug.Assert(m_rows.Count != 0); RawImage source = new RawImage(m_rows, m_colorspace); compress(source, parameters); }
internal CompressionParameters(CompressionParameters parameters) { if (parameters == null) throw new ArgumentNullException("parameters"); m_quality = parameters.m_quality; m_smoothingFactor = parameters.m_smoothingFactor; m_simpleProgressive = parameters.m_simpleProgressive; }
public override void Save(Image i, Stream dest) { BitMiracle.LibJpeg.JpegImage j = BitMiracle.LibJpeg.JpegImage.FromBitmap((System.Drawing.Bitmap)i); CompressionParameters c = new CompressionParameters(); c.Quality = 100; c.SimpleProgressive = false; j.WriteJpeg(dest, c); j.Dispose(); System.GC.Collect(); }
private void applyParameters(CompressionParameters parameters) { Debug.Assert(parameters != null); m_compressor.Smoothing_factor = parameters.SmoothingFactor; m_compressor.jpeg_set_quality(parameters.Quality, true); if (parameters.SimpleProgressive) { m_compressor.jpeg_simple_progression(); } }
internal CompressionParameters(CompressionParameters parameters) { if (parameters is null) { throw new ArgumentNullException(nameof(parameters)); } Quality = parameters.Quality; SmoothingFactor = parameters.SmoothingFactor; SimpleProgressive = parameters.SimpleProgressive; }
internal CompressionParameters(CompressionParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } m_quality = parameters.m_quality; m_smoothingFactor = parameters.m_smoothingFactor; m_simpleProgressive = parameters.m_simpleProgressive; }
private void applyParameters(CompressionParameters parameters) { Debug.Assert(parameters is object); ClassicCompressor.SmoothingFactor = parameters.SmoothingFactor; ClassicCompressor.JpegSetQuality(parameters.Quality, true); if (parameters.SimpleProgressive) { ClassicCompressor.JpegSimpleProgression(); } }
#pragma warning disable IDE1006 // Naming Styles private void applyParameters(CompressionParameters parameters) #pragma warning restore IDE1006 // Naming Styles { Debug.Assert(parameters is object); ClassicCompressor.SmoothingFactor = parameters.SmoothingFactor; ClassicCompressor.JpegSetQuality(parameters.Quality, true); if (parameters.SimpleProgressive) { ClassicCompressor.JpegSimpleProgression(); } }
/// <summary> /// Determines whether the specified <see cref="System.Object"/> is equal to this instance. /// </summary> /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param> /// <returns> /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>. /// </returns> public override bool Equals(object obj) { CompressionParameters parameters = obj as CompressionParameters; if (parameters == null) { return(false); } return(m_quality == parameters.m_quality && m_smoothingFactor == parameters.m_smoothingFactor && m_simpleProgressive == parameters.m_simpleProgressive); }
public void TestCompressionResultsSameAsForCJpeg() { using (JpegImage jpeg = new JpegImage(Path.Combine(m_testcase, "test24.bmp"))) { testJpegOutput(jpeg, "test24.jpg", m_expectedResults); CompressionParameters parameters = new CompressionParameters(); parameters.Quality = 25; testJpegOutput(jpeg, parameters, "test24_25.jpg", m_expectedResults); parameters = new CompressionParameters(); parameters.SimpleProgressive = true; testJpegOutput(jpeg, parameters, "test24_prog.jpg", m_expectedResults); } }
private void compress(IRawImage source, CompressionParameters parameters) { Debug.Assert(source != null); if (!needCompressWith(parameters)) { return; } m_compressedData = new MemoryStream(); m_compressionParameters = new CompressionParameters(parameters); Jpeg jpeg = new Jpeg(); jpeg.CompressionParameters = m_compressionParameters; jpeg.Compress(source, m_compressedData); }
private void applyParameters(CompressionParameters parameters) { Debug.Assert(parameters != null); // TODO: Should really get In_color_space from this class, not values we've already set on m_compressor. m_compressor.jpeg_set_colorspace(m_compressor.map_colorspace(m_compressor.In_color_space), parameters.YHSamp, parameters.YVSamp, parameters.CbHSamp, parameters.CbVSamp, parameters.CrHSamp, parameters.CrVSamp); m_compressor.Smoothing_factor = parameters.SmoothingFactor; m_compressor.jpeg_set_quality(parameters.Quality, true); if (parameters.SimpleProgressive) { m_compressor.jpeg_simple_progression(); } }
private void Compress(IRawImage source, CompressionParameters parameters) { Debug.Assert(source is object); if (!NeedCompressWith(parameters)) { return; } m_compressedData = new MemoryStream(); m_compressionParameters = new CompressionParameters(parameters); var jpeg = new Jpeg { CompressionParameters = m_compressionParameters }; jpeg.Compress(source, m_compressedData); }
private void Dispose(bool disposing) { if (!m_alreadyDisposed) { if (disposing) { // dispose managed resources if (m_compressedData != null) { m_compressedData.Dispose(); } if (m_decompressedData != null) { m_decompressedData.Dispose(); } #if !SILVERLIGHT if (m_bitmap != null) { m_bitmap.Dispose(); } #endif } // free native resources m_compressionParameters = null; m_compressedData = null; m_decompressedData = null; #if !SILVERLIGHT m_bitmap = null; #endif m_rows = null; m_alreadyDisposed = true; } }
private void compress(IRawImage source, CompressionParameters parameters) { Debug.Assert(source != null); if (!needCompressWith(parameters)) return; m_compressedData = new MemoryStream(); m_compressionParameters = new CompressionParameters(parameters); Jpeg jpeg = new Jpeg(); jpeg.CompressionParameters = m_compressionParameters; jpeg.Compress(source, m_compressedData); }
/// <summary> /// Compresses image to JPEG with given parameters and writes it to stream. /// </summary> /// <param name="output">Output stream.</param> /// <param name="parameters">The parameters of compression.</param> public void WriteJpeg(Stream output, CompressionParameters parameters) { compress(parameters); compressedData.WriteTo(output); }
private void Dispose(bool disposing) { if (!m_alreadyDisposed) { if (disposing) { // dispose managed resources if (m_compressedData != null) m_compressedData.Dispose(); if (m_decompressedData != null) m_decompressedData.Dispose(); #if !NETSTANDARD if (m_bitmap != null) m_bitmap.Dispose(); #endif } // free native resources m_compressionParameters = null; m_compressedData = null; m_decompressedData = null; #if !NETSTANDARD m_bitmap = null; #endif m_rows = null; m_alreadyDisposed = true; } }
private void applyParameters(CompressionParameters parameters) { Debug.Assert(parameters != null); m_compressor.Smoothing_factor = parameters.SmoothingFactor; m_compressor.jpeg_set_quality(parameters.Quality, true); if (parameters.SimpleProgressive) m_compressor.jpeg_simple_progression(); }
private bool needCompressWith(CompressionParameters parameters) { return(m_compressedData == null || m_compressionParameters == null || !m_compressionParameters.Equals(parameters)); }
/// <summary> /// Saves the jpeg to a file. /// </summary> /// <param name="filename">Path to save to. Will create or overwrite if existing.</param> /// <param name="parameters">Optional compression parameters.</param> public void Save(string filename, CompressionParameters parameters = null) { using(var stream = File.OpenWrite(filename)) { WriteJpeg(stream, parameters); } }
public void TestCreateFromPixelsAndRecompress() { using (JpegImage jpegImage = createImageFromPixels()) { CompressionParameters compressionParameters = new CompressionParameters(); compressionParameters.Quality = 20; const string output = "JpegImageFromPixels_20.jpg"; testJpegOutput(jpegImage, compressionParameters, output, m_expectedResults); using (JpegImage recompressedImage = new JpegImage(output)) { Assert.AreEqual(recompressedImage.Colorspace, jpegImage.Colorspace); } } }
private static void testJpegOutput(JpegImage jpeg, CompressionParameters parameters, string jpegFileName, string folderWithExpectedResults) { using (FileStream output = new FileStream(jpegFileName, FileMode.Create)) jpeg.WriteJpeg(output, parameters); FileAssert.AreEqual(jpegFileName, Path.Combine(folderWithExpectedResults, jpegFileName)); }
private bool NeedCompressWith(CompressionParameters parameters) { return(m_compressedData is null || m_compressionParameters?.Equals(parameters) != true); }
private bool needCompressWith(CompressionParameters parameters) { return m_compressedData == null || m_compressionParameters == null || !m_compressionParameters.Equals(parameters); }
private static CompressionParameters ToCompressionParameters(DicomJpegParams parameters) { var compressionParams = new CompressionParameters(); if (parameters != null) { compressionParams.Quality = parameters.Quality; compressionParams.SmoothingFactor = parameters.SmoothingFactor; } return compressionParams; }
private void Dispose(bool disposing) { if (!m_alreadyDisposed) { if (disposing) { // dispose managed resources if (m_compressedData != null) m_compressedData.Dispose(); if (m_decompressedData != null) m_decompressedData.Dispose(); } // free native resources m_compressionParameters = null; m_compressedData = null; m_decompressedData = null; m_rows = null; m_alreadyDisposed = true; } }
private void applyParameters(CompressionParameters parameters) { Debug.Assert(parameters != null); // TODO: Should really get In_color_space from this class, not values we've already set on m_compressor. m_compressor.jpeg_set_colorspace(m_compressor.map_colorspace(m_compressor.In_color_space), parameters.YHSamp, parameters.YVSamp, parameters.CbHSamp, parameters.CbVSamp, parameters.CrHSamp, parameters.CrVSamp); m_compressor.Smoothing_factor = parameters.SmoothingFactor; m_compressor.jpeg_set_quality(parameters.Quality, true); if (parameters.SimpleProgressive) m_compressor.jpeg_simple_progression(); }