Пример #1
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");
        }
Пример #2
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);
            }
        }
Пример #3
0
        public void Decompress()
        {
            var compressedImage   = CompressedImage.Load(compressedFileName);
            var uncompressedImage = Decompress(compressedImage);
            var resultBmp         = (Bitmap)uncompressedImage;

            resultBmp.Save(uncompressedFileName, ImageFormat.Bmp);
        }
Пример #4
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");
        }
Пример #5
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);
            }
        }
Пример #6
0
        private static void Main(string[] args)
        {
            ApplicationOptions options;

            if (!TryArgsParse(args, out options))
            {
                return;
            }

            //try
            //{
            SetMaxThread(options.MaxThreads);
            const int thinIndex          = 2;
            var       countSaveFrequence = PercentToCountFrequence(options.PercentCompress, options.Dct);

            var applicationModule = new ApplicationModule(options.Dct, countSaveFrequence, thinIndex);
            var applicationKernel = new StandardKernel(applicationModule);

            if (options.PathCompressFile != null)
            {
                var jpegCompressor  = applicationKernel.Get <ICompressor>();
                var bmp             = (Bitmap)Image.FromFile(options.PathSourceFile);
                var compressedImage = jpegCompressor.Compress(bmp);
                compressedImage.Save(options.PathCompressFile);
            }
            if (options.PathDecompressFile != null)
            {
                var jpegDecompressor  = applicationKernel.Get <IDecompressor>();
                var compressedImage   = CompressedImage.Load(options.PathSourceFile, options.Dct);
                var decompressedImage = jpegDecompressor.Decompress(compressedImage);
                decompressedImage.Save(options.PathDecompressFile, ImageFormat.Bmp);
            }
            //}
            //catch (Exception e)
            //{
            //    Console.WriteLine(e);
            //}
        }