예제 #1
0
		/// <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);
			}
		}
예제 #2
0
 /// <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);
     }
 }
예제 #3
0
        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;
            }
        }
예제 #4
0
        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;
            }
        }
예제 #5
0
 /// <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);
     }
 }
예제 #6
0
        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);
        }
예제 #7
0
        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;
        }
예제 #9
0
 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();
 }
예제 #10
0
        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();
            }
        }
예제 #11
0
        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;
        }
예제 #13
0
        private void applyParameters(CompressionParameters parameters)
        {
            Debug.Assert(parameters is object);

            ClassicCompressor.SmoothingFactor = parameters.SmoothingFactor;
            ClassicCompressor.JpegSetQuality(parameters.Quality, true);
            if (parameters.SimpleProgressive)
            {
                ClassicCompressor.JpegSimpleProgression();
            }
        }
예제 #14
0
#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);
        }
예제 #16
0
        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);
            }
        }
예제 #17
0
        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);
        }
예제 #18
0
        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();
            }
        }
예제 #19
0
        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);
        }
예제 #20
0
        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;
            }
        }
예제 #21
0
        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);
        }
예제 #22
0
        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);
        }
예제 #23
0
 /// <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);
 }
예제 #24
0
        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;
            }
        }
예제 #25
0
파일: Jpeg.cs 프로젝트: lygroup/libjpeg.net
        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();
        }
예제 #26
0
 private bool needCompressWith(CompressionParameters parameters)
 {
     return(m_compressedData == null ||
            m_compressionParameters == null ||
            !m_compressionParameters.Equals(parameters));
 }
예제 #27
0
		/// <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);
			}
		}
예제 #28
0
        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);
                }
            }
        }
예제 #29
0
 /// <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);
 }
예제 #30
0
        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));
        }
예제 #31
0
 private bool NeedCompressWith(CompressionParameters parameters)
 {
     return(m_compressedData is null ||
            m_compressionParameters?.Equals(parameters) != true);
 }
예제 #32
0
 private bool needCompressWith(CompressionParameters parameters)
 {
     return m_compressedData == null || 
            m_compressionParameters == null || 
            !m_compressionParameters.Equals(parameters);
 }
예제 #33
0
        private static CompressionParameters ToCompressionParameters(DicomJpegParams parameters)
        {
            var compressionParams = new CompressionParameters();

            if (parameters != null)
            {
                compressionParams.Quality = parameters.Quality;
                compressionParams.SmoothingFactor = parameters.SmoothingFactor;
            }

            return compressionParams;
        }
예제 #34
0
        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;
            }
        }
예제 #35
0
		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();
		}