Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            try
            {
                Console.WriteLine(IntPtr.Size == 8 ? "64-bit version" : "32-bit version");
                var sw = Stopwatch.StartNew();
                //var fileName = @"sample.bmp";
                //var fileName = @"MARBLES.BMP";
                //var fileName = @"earth.bmp";
                var fileName             = @"kot.jpg";
                var compressedFileName   = fileName + ".compressed." + CompressionQuality;
                var uncompressedFileName = fileName + ".uncompressed." + CompressionQuality + ".bmp";

                var imageMatrix = Matrix.FromFile(fileName, out var length);
                sw.Stop();
                Console.WriteLine($"{imageMatrix.Width}x{imageMatrix.Height} - {length / (1024.0 * 1024):F2} MB");
                sw.Start();
                var compressionResult = Compress(imageMatrix);
                compressionResult.Save(compressedFileName);

                sw.Stop();
                Console.WriteLine("Compression: " + sw.Elapsed);
                sw.Restart();
                var compressedImage   = CompressedImage.Load(compressedFileName);
                var uncompressedImage = Uncompress(compressedImage);
                uncompressedImage.SaveToFile(uncompressedFileName);
                Console.WriteLine("Decompression: " + sw.Elapsed);
                Console.WriteLine($"Peak commit size: {MemoryMeter.PeakPrivateBytes() / (1024.0*1024):F2} MB");
                Console.WriteLine($"Peak working set: {MemoryMeter.PeakWorkingSet() / (1024.0*1024):F2} MB");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine(IntPtr.Size == 8 ? "64-bit version" : "32-bit version");
            var          sw       = Stopwatch.StartNew();
            const string fileName = @"earth.bmp";
//				var fileName = "Big_Black_River_Railroad_Bridge.bmp";
            var compressedFileName   = fileName + ".compressed." + CompressionQuality;
            var uncompressedFileName = fileName + ".uncompressed." + CompressionQuality + ".bmp";

            using (var fileStream = File.OpenRead(fileName))
                using (var bmp = (Bitmap)Image.FromStream(fileStream, false, false))
                {
                    var imageMatrix = (Matrix)bmp;

                    sw.Stop();
                    Console.WriteLine($"{bmp.Width}x{bmp.Height} - {fileStream.Length / (1024.0 * 1024):F2} MB");
                    sw.Start();

                    var compressionResult = Compress(imageMatrix, CompressionQuality);
                    compressionResult.Save(compressedFileName);
                }

            sw.Stop();
            GC.Collect();
            Console.WriteLine("Compression: " + sw.Elapsed);
            sw.Restart();
            var compressedImage   = CompressedImage.Load(compressedFileName);
            var uncompressedImage = Uncompress(compressedImage);
            var resultBmp         = (Bitmap)uncompressedImage;

            resultBmp.Save(uncompressedFileName, ImageFormat.Bmp);
            Console.WriteLine("Decompression: " + sw.Elapsed);
            Console.WriteLine($"Peak commit size: {MemoryMeter.PeakPrivateBytes() / (1024.0*1024):F2} MB");
            Console.WriteLine($"Peak working set: {MemoryMeter.PeakWorkingSet() / (1024.0*1024):F2} MB");
        }
Exemplo n.º 3
0
        private static void Main()
        {
            Process.GetCurrentProcess().ProcessorAffinity = (IntPtr)3;
            Console.WriteLine(IntPtr.Size == 8 ? "64-bit version" : "32-bit version");

            var fileName = "sample.bmp";

            //var fileName = "earth.bmp";
            //var fileName = "marbles.bmp";
            //var fileName = "marbles2.bmp";
            fileName = fileName.Insert(0, @"Images\");
            var compressedFileName   = fileName + ".compressed." + CompressionQuality;
            var uncompressedFileName = fileName + ".uncompressed." + CompressionQuality + ".bmp";

            var sw = Stopwatch.StartNew();

            using (var fileStream = File.OpenRead(fileName))
                using (var bmp = (Bitmap)Image.FromStream(fileStream, false, false))
                {
                    var imageMatrix = (Matrix)bmp;
                    sw.Stop();
                    Console.WriteLine("getPixel: {0}", sw.ElapsedMilliseconds);
                    Console.WriteLine($"{bmp.Width}x{bmp.Height} - {fileStream.Length / (1024.0 * 1024):F2} MB");

                    sw.Start();
                    var compressionResult = Compress(imageMatrix);
                    sw.Stop();
                    Console.WriteLine("Compression: " + sw.Elapsed);

                    compressionResult.Save(compressedFileName);
                }

            var compressedImage = CompressedImage.Load(compressedFileName);

            sw.Restart();
            var uncompressedImage = Uncompress(compressedImage);

            Console.WriteLine("Decompression: " + sw.Elapsed);

            sw.Restart();
            var resultBmp = (Bitmap)uncompressedImage;

            Console.WriteLine("setPixel: {0}", sw.ElapsedMilliseconds);
            resultBmp.Save(uncompressedFileName, ImageFormat.Bmp);

            Console.WriteLine($"Peak commit size: {MemoryMeter.PeakPrivateBytes() / (1024.0 * 1024):F2} MB");
            Console.WriteLine($"Peak working set: {MemoryMeter.PeakWorkingSet() / (1024.0 * 1024):F2} MB");
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            try
            {
                var sw                   = Stopwatch.StartNew();
                var fileName             = @"..\..\sample.bmp";
                var compressedFileName   = fileName + ".compressed." + CompressionQuality;
                var uncompressedFileName = fileName + ".uncompressed." + CompressionQuality + ".bmp";

                using (var fileStream = File.OpenRead(fileName))
                    using (var bmp = (Bitmap)Image.FromStream(fileStream, false, false))
                    {
                        var imageMatrix = (Matrix)bmp;

                        sw.Stop();
                        Console.WriteLine($"{bmp.Width}x{bmp.Height} - {fileStream.Length / (1024.0 * 1024):F2} MB");
                        sw.Start();

                        var compressionResult = Compress(imageMatrix, CompressionQuality);
                        compressionResult.Save(compressedFileName);
                    }

                sw.Stop();
                Console.WriteLine("Compression: " + sw.Elapsed);
                sw.Restart();
                var compressedImage   = CompressedImage.Load(compressedFileName);
                var uncompressedImage = Uncompress(compressedImage);
                var resultBmp         = (Bitmap)uncompressedImage;
                resultBmp.Save(uncompressedFileName, ImageFormat.Bmp);
                Console.WriteLine("Decompression: " + sw.Elapsed);
                Console.WriteLine($"Peak commit size: {MemoryMeter.PeakPrivateBytes() / (1024.0 * 1024):F2} MB");
                Console.WriteLine($"Peak working set: {MemoryMeter.PeakWorkingSet() / (1024.0 * 1024):F2} MB");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            //BenchmarkRunner.Run<CompressDecompressBenchmark>();

            //FFT.Test();
            //var fileName = @"..\..\Big_Black_River_Railroad_Bridge.bmp";
            var fileName   = @"..\..\sample.bmp";
            var compressor = new JpegCompressor(fileName);

            var sw = Stopwatch.StartNew();

            compressor.Compress();

            sw.Stop();
            Console.WriteLine("Compression: " + sw.Elapsed);
            sw.Restart();

            compressor.Decompress();

            Console.WriteLine("Decompression: " + sw.Elapsed);
            Console.WriteLine($"Peak commit size: {MemoryMeter.PeakPrivateBytes() / (1024.0 * 1024):F2} MB");
            Console.WriteLine($"Peak working set: {MemoryMeter.PeakWorkingSet() / (1024.0 * 1024):F2} MB");
            //Console.ReadLine();
        }