Пример #1
0
        static void Main(string[] args)
        {
            CmdOptions.Touch();
            string tooltip;

            Dither.InitParams(out CmdOptions.options.param, out tooltip, out CmdOptions.options.name);
            Draw.SetPens(100);

            if (args.Length < 1)
            {
                Console.WriteLine("Warning: no command-line options, using default values!");
            }
            else
            {
                for (int i = 0; i < args.Length; i++)
                {
                    if (!string.IsNullOrEmpty(args[i]))
                    {
                        string opt = args[i];
                        if (!CmdOptions.options.ParseOption(args, ref i))
                        {
                            Console.WriteLine($"Warning: invalid option '{opt}'!");
                        }
                    }
                }
            }

            //--- do the job ---
            if (!wasComputed)
            {
                Compute();
            }
        }
Пример #2
0
        static public void Compute()
        {
            wasComputed = true;
            foreach (var imageFn in CmdOptions.options.inputFiles)
            {
                Bitmap inp = null;
                try
                {
                    inp = (Bitmap)Image.FromFile(imageFn);
                }
                catch (Exception)
                {
                }

                if (inp == null)
                {
                    inp = Draw.TestImageGray(1200, 900, 12);
                }

                Bitmap bmp;
                sw.Restart();

                long dots = Dither.TransformImage(inp, out bmp, inp.Width, inp.Height, CmdOptions.options.param);

                sw.Stop();
                float elapsed = 1.0e-3f * sw.ElapsedMilliseconds;

                bmp.SetResolution(1200, 1200);

                Util.Log(CmdOptions.options.param);
                Util.LogFormat("Name: '{0}', input: '{1}', elapsed: {2:f3}s, dots: {3}, dps: {4}, hash: {5:X16}",
                               CmdOptions.options.name, imageFn, elapsed, Util.kmg(dots), Util.kmg((long)(dots / elapsed)),
                               Draw.Hash(bmp));

                string fileName = CmdOptions.options.outputFileName;
                if (string.IsNullOrEmpty(fileName))
                {
                    fileName = Path.GetFileName(imageFn);
                }
                string outFn = Path.Combine(CmdOptions.options.outDir, fileName);
                string ext   = Path.GetExtension(outFn);
                if (ext.ToLower() != ".png")
                {
                    outFn = outFn.Substring(0, outFn.Length - ext.Length) + ".png";
                }
                bmp.Save(outFn, System.Drawing.Imaging.ImageFormat.Png);

                Util.LogFormat("Output: '{0} ({1}x{2}px, {3:f1}x{4:f1}cm)' .. saved",
                               outFn, bmp.Width, bmp.Height,
                               bmp.Width * 2.54 / 1200.0, bmp.Height * 2.54 / 1200.0);
                inp.Dispose();
                bmp.Dispose();
            }
        }
Пример #3
0
        public Form1()
        {
            InitializeComponent();

            Draw.SetPens(100);
            string param;
            string name;

            Dither.InitParams(out param, out tooltip, out name);
            textParam.Text = param ?? "";
            Text          += " (" + rev + ") '" + name + '\'';

            newImage((Image)null);
        }
Пример #4
0
        private void transform()
        {
            if (inputImage != null)
            {
                Bitmap    ibmp = (Bitmap)inputImage;
                Bitmap    bmp;
                Stopwatch sw = new Stopwatch();
                sw.Start();

                long dots = Dither.TransformImage(ibmp, out bmp, ibmp.Width, ibmp.Height, textParam.Text);

                sw.Stop();
                float elapsed = 1.0e-3f * sw.ElapsedMilliseconds;

                bmp.SetResolution(1200, 1200);
                SetImage(bmp);

                SetText(string.Format(CultureInfo.InvariantCulture, "Elapsed: {0:f3}s, dots: {1}",
                                      elapsed, Util.kmg(dots)));
            }

            StopComputation();
        }