コード例 #1
0
ファイル: MainForm.cs プロジェクト: rstarkov/i4c
        private void Compressor_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem mi      = (ToolStripMenuItem)sender;
            var        compressorName = mi.Text.Replace("&", "");
            Compressor compr          = Program.GetCompressor(compressorName);
            var        input          = InputBox.GetLine("Please enter the arguments for this compressor:", Program.Settings.LastArgs.Get(compressorName, ""));

            if (input == null)
            {
                return;
            }
            Program.Settings.LastArgs[compressorName] = input;
            Program.Settings.Save();
            var args = input.Split(' ');

            compr.Configure(args.Skip(1).Select(val => (RVariant)val).ToArray());
            ThreadPool.QueueUserWorkItem(dummy => Program.CompressDecompressSingle(compr, args[0]));
        }
コード例 #2
0
        public static IntField FieldcodeRunlengthsDe2(int[] runs, int width, int height, SymbolCodec runlengthCodec, Compressor compr)
        {
            IntField image = new IntField(width, height);
            var      data  = runlengthCodec.Decode(runs);

            for (int i = 1; i <= 3; i++)
            {
                int offs = width * height * (i - 1);
                for (int p = 0; p < width * height; p++)
                {
                    if (data[offs + p] == 1)
                    {
                        image.Data[p] = i;
                    }
                }

                // Visualise
                IntField img = new IntField(width, height);
                Array.Copy(data, offs, img.Data, 0, width * height);
                compr.AddImageGrayscale(img, 0, 1, "field" + i);
            }
            compr.AddImageGrayscale(image, 0, 3, "xformed");
            return(image);
        }
コード例 #3
0
        public static int[] FieldcodeRunlengthsEn2(IntField image, SymbolCodec runlengthCodec, Compressor compr)
        {
            compr.AddImageGrayscale(image, 0, 3, "xformed");
            List <int> data = new List <int>();

            for (int i = 1; i <= 3; i++)
            {
                IntField temp = image.Clone();
                temp.Map(x => x == i ? 1 : 0);
                data.AddRange(temp.Data);
                compr.AddImageGrayscale(temp, 0, 1, "field" + i);
            }
            var runs = runlengthCodec.Encode(data.ToArray());

            compr.SetCounter("runs", runs.Length);
            return(runs);
        }
コード例 #4
0
        public static IntField FieldcodeRunlengthsDe(List <int[]> fields, int width, int height, SymbolCodec runlengthCodec, Compressor compr)
        {
            IntField image = new IntField(width, height);

            for (int i = 1; i <= 3; i++)
            {
                CodecUtil.Shift(fields[i - 1], -1);
                var f = runlengthCodec.Decode(fields[i - 1]);

                for (int p = 0; p < width * height; p++)
                {
                    if (f[p] == 1)
                    {
                        image.Data[p] = i;
                    }
                }

                // Visualise
                IntField img = new IntField(width, height);
                img.Data = f;
                compr.AddImageGrayscale(img, 0, 1, "field" + i);
            }
            compr.AddImageGrayscale(image, 0, 3, "xformed");
            return(image);
        }
コード例 #5
0
        public static List <int[]> FieldcodeRunlengthsEn(IntField image, SymbolCodec runlengthCodec, Compressor compr)
        {
            compr.AddImageGrayscale(image, 0, 3, "xformed");
            var fields = new List <int[]>();

            for (int i = 1; i <= 3; i++)
            {
                IntField temp = image.Clone();
                temp.Map(x => x == i ? 1 : 0);
                var field = runlengthCodec.Encode(temp.Data);
                CodecUtil.Shift(field, 1);
                compr.SetCounter("symbols|field-" + i, field.Length);
                fields.Add(field);
                compr.AddImageGrayscale(temp, 0, 1, "field" + i);
            }
            return(fields);
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: rstarkov/i4c
        /// <summary>
        /// Processes the "benchmark algorithm on all files" command-line command.
        /// </summary>
        private static void command_Benchmark(string algName, RVariant[] algArgs)
        {
            WaitFormShow("benchmarking...");

            Dictionary <string, Compressor> compressors = new Dictionary <string, Compressor>();

            foreach (var file in Directory.GetFiles(".", "*.png"))
            {
                compressors.Add(file, GetCompressor(algName));
            }

            // Queue all jobs...
            foreach (var file in compressors.Keys)
            {
                Compressor compr = compressors[file];
                compr.Configure(algArgs);
                compr.CanonicalFileName = Path.GetFileNameWithoutExtension(file);
                string sourcePath = file;
                string destDir    = PathUtil.AppPathCombine("i4c-output", "benchmark.{0},{1}".Fmt(algName, compr.ConfigString), compr.CanonicalFileName);
                string destFile   = "{0}.{1},{2}.i4c".Fmt(compr.CanonicalFileName, algName, compr.ConfigString);

                Func <Compressor, string, string, string, WaitCallback> makeCallback =
                    (v1, v2, v3, v4) => (dummy2 => CompressFile(v1, v2, v3, v4));
                ThreadPool.QueueUserWorkItem(makeCallback(compr, sourcePath, destDir, destFile));
            }
            // ...and wait until they're finished.
            int worker = 0, dummy;

            while (worker < Environment.ProcessorCount)
            {
                Thread.Sleep(200);
                ThreadPool.GetAvailableThreads(out worker, out dummy);
            }

            // Compute stats totals
            Dictionary <string, double> totals = new Dictionary <string, double>();

            foreach (var file in compressors.Keys)
            {
                var counters = compressors[file].Counters;
                foreach (var key in counters.Keys)
                {
                    if (totals.ContainsKey(key))
                    {
                        totals[key] += counters[key];
                    }
                    else
                    {
                        totals.Add(key, counters[key]);
                    }
                }
            }

            // Write stats totals to a text file
            TextTable table = new TextTable {
                ColumnSpacing = 3, MaxWidth = int.MaxValue, DefaultAlignment = HorizontalTextAlignment.Right
            };

            table.SetCell(1, 0, "TOTAL");
            int colnum = 2;
            int rownum = 2;

            foreach (var str in compressors.Values.Select(val => val.CanonicalFileName).Order())
            {
                table.SetCell(colnum++, 0, str);
            }
            int indent_prev = 0;

            foreach (var key in totals.Keys.Order())
            {
                int indent = 4 * key.ToCharArray().Count(c => c == '|');
                if (indent < indent_prev)
                {
                    rownum++;
                }
                indent_prev = indent;
                table.SetCell(0, rownum, new string(' ', indent) + key.Split('|').Last(), alignment: HorizontalTextAlignment.Left);
                table.SetCell(1, rownum, Math.Round(totals[key], 3).ToString("#,0"));
                colnum = 2;
                foreach (var compr in compressors.Values.OrderBy(c => c.CanonicalFileName))
                {
                    if (compr.Counters.ContainsKey(key))
                    {
                        table.SetCell(colnum++, rownum, Math.Round(compr.Counters[key], 3).ToString("#,0"));
                    }
                    else
                    {
                        table.SetCell(colnum++, rownum, "N/A");
                    }
                }
                rownum++;
            }
            File.WriteAllText(PathUtil.AppPathCombine("i4c-output", "benchmark.{0},{1}.txt".Fmt(algName, compressors.Values.First().ConfigString)), table.ToString());

            WaitFormHide();
        }