Exemple #1
0
        /// <summary>
        /// parses image and write arrays to output file
        /// </summary>
        /// <param name="options">parsed command line args</param>
        /// <returns>error code</returns>
        static ErrorCode ParseFontImage(ParseOptions options)
        {
            try
            {
                if (options.ExcessValue != null)
                {
                    return(ErrorCode.ArgumentsMismatch);
                }

                Settings        = PixelSettings.FromFile(options.PixelSettingsPath);
                _outputFileName = options.OutputFileName;

                var bitmap = new Bitmap(Image.FromFile(options.InputFileName));
                var mapper = new PixelMapper(bitmap, Settings);
                var map    = mapper.MapPixels(options.SkipHeaders);
                OutputFileFormatter.WriteOutput(map, options.OutputFileName, options.SingleArray, options.ArrayContentOnly);
            }
            catch (Exception e)
            {
                switch (e)
                {
                case FileNotFoundException _:
                    return(ErrorCode.FileNotFound);

                case ArgumentException _:
                    return(ErrorCode.FileParsingError);

                default:
                    return(ErrorCode.UknownError);
                }
            }
            return(ErrorCode.NoError);
        }
Exemple #2
0
        /// <summary>
        /// parses image and write arrays to output file
        /// </summary>
        /// <param name="options">parsed command line args</param>
        /// <returns>error code</returns>
        static int ParseFontImage(ParseOptions options)
        {
            try
            {
                var bitmap   = new Bitmap(Image.FromFile(options.InputFileName));
                var settings = PixelSettings.FromFile(options.PixelSettingsPath);
                var mapper   = new PixelMapper(bitmap, settings);
                var map      = mapper.MapPixels();
                OutputFileFormatter.WriteOutput(map, options.OutputFileName, options.SingleArray);
            }
            catch (Exception e)
            {
                if (e is FileNotFoundException)
                {
                    ConsoleLogger.WriteMessage($"File not found or invalid file name \"{e.Message}\"", MessageType.Error);
                    return((int)ErrorCode.FileNotFound);
                }

                ConsoleLogger.WriteMessage(e.Message + "\n" + e.InnerException?.Message, MessageType.Error);

                if (e is ArgumentException)
                {
                    return((int)ErrorCode.FileParsingError);
                }

                return((int)ErrorCode.UknownError);
            }
            return((int)ErrorCode.NoError);
        }
 public PatternGenerator(PixelSettings settings)
 {
     _settings        = settings;
     _delimeterColor  = ColorTranslator.FromHtml(_settings.DelimeterColor);
     _backGroundColor = ColorTranslator.FromHtml(_settings.BackgroundColor);
     foreach (var i in settings.ColorMapping)
     {
         Colors.Add(i.Value, ColorTranslator.FromHtml(i.Key));
     }
 }
Exemple #4
0
        public PixelMapper(Bitmap bitmap, PixelSettings settings)
        {
            _bitmap   = bitmap;
            _settings = settings;

            ColorMappings = new Dictionary <Color, int>();
            foreach (var i in settings.ColorMapping)
            {
                ColorMappings.Add(ColorTranslator.FromHtml(i.Key), i.Value);
            }
        }
Exemple #5
0
        public PatternGenerator(PixelSettings settings)
        {
            _settings        = settings;
            _delimeterColor  = ColorTranslator.FromHtml(_settings.DelimeterColor);
            _backGroundColor = ColorTranslator.FromHtml(_settings.BackgroundColor);
            foreach (var i in settings.ColorMapping)
            {
                if (Colors.ContainsKey(i.Value))
                {
                    throw new ConfigurationErrorsException($"Config file ColorMapping has several keys {i.Value}");
                }

                Colors.Add(i.Value, ColorTranslator.FromHtml(i.Key));
            }
        }
Exemple #6
0
        /// <summary>
        /// parses image and write arrays to output file
        /// </summary>
        /// <param name="options">parsed command line args</param>
        /// <returns>always returns null</returns>
        static object ParseFontImage(ParseOptions options)
        {
            if (options.ExcessValue != null)
            {
                throw new ArgumentException("Argument mismatch!");
            }

            Settings        = PixelSettings.FromFile(options.PixelSettingsPath);
            _outputFileName = options.OutputFileName;

            var bitmap = new Bitmap(Image.FromFile(options.InputFileName));
            var mapper = new PixelMapper(bitmap, Settings);
            var map    = mapper.MapPixels(options.SkipHeaders);

            OutputFileFormatter.WriteOutput(map, options.OutputFileName, options.SingleArray, options.ArrayContentOnly);

            return(null);
        }
Exemple #7
0
 /// <summary>
 /// Grid pattern generation and writing to file
 /// </summary>
 /// <param name="options">parsed command line args</param>
 /// <returns>error code</returns>
 static int GeneratePattern(GenerateOptions options)
 {
     try
     {
         var settings  = PixelSettings.FromFile(options.PixelSettingsPath);
         var generator = new PatternGenerator(settings);
         var pattern   = generator.GeneratePattern(options.PatternWidth, options.PatternHeight);
         pattern.Save(options.OutputFileName);
     }
     catch (Exception e)
     {
         ConsoleLogger.WriteMessage(e.Message + "\n" + e.InnerException?.Message, MessageType.Error);
         if (e is FileNotFoundException)
         {
             return((int)ErrorCode.FileNotFound);
         }
         return((int)ErrorCode.UknownError);
     }
     return((int)ErrorCode.NoError);
 }
Exemple #8
0
        /// <summary>
        /// Grid pattern generation and writing to file
        /// </summary>
        /// <param name="options">parsed command line args</param>
        /// <returns>error code</returns>
        static ErrorCode GeneratePattern(GenerateOptions options)
        {
            try
            {
                if (options.ExcessValue != null)
                {
                    return(ErrorCode.ArgumentsMismatch);
                }

                Settings        = PixelSettings.FromFile(options.PixelSettingsPath);
                _outputFileName = options.OutputFileName;

                var    generator  = new PatternGenerator(Settings);
                byte[] sampleData = null;
                if (options.InputFileName != null)
                {
                    sampleData = ParseDataFile(options.InputFileName);
                }
                var pattern = generator.GeneratePattern(options.PatternWidth,
                                                        options.PatternHeight, options.EnumerationStyle, sampleData);
                pattern.Save(options.OutputFileName);
            }
            catch (Exception e)
            {
                switch (e)
                {
                case PixelProcessingException _:
                    ConsoleLogger.WriteMessage(e.Message, MessageType.Error);
                    return(ErrorCode.FileParsingError);

                case FileNotFoundException _:
                    return(ErrorCode.FileNotFound);

                default:
                    return(ErrorCode.UknownError);
                }
            }
            return(ErrorCode.NoError);
        }
Exemple #9
0
        /// <summary>
        /// Grid pattern generation and writing to file
        /// </summary>
        /// <param name="options">parsed command line args</param>
        /// <returns>always returns null</returns>
        static object GeneratePattern(GenerateOptions options)
        {
            if (options.ExcessValue != null)
            {
                throw new ArgumentException("Argument mismatch!");
            }

            Settings        = PixelSettings.FromFile(options.PixelSettingsPath);
            _outputFileName = options.OutputFileName;

            var generator = new PatternGenerator(Settings);

            byte[] sampleData = null;
            if (options.InputFileName != null)
            {
                sampleData = ParseDataFile(options.InputFileName);
            }
            var pattern = generator.GeneratePattern(options.PatternWidth,
                                                    options.PatternHeight, options.EnumerationStyle, sampleData);

            pattern.Save(options.OutputFileName);

            return(null);
        }
Exemple #10
0
 public PatternGenerator(PixelSettings settings)
 {
     _settings        = settings;
     _delimeterColor  = ColorTranslator.FromHtml(_settings.DelimeterColor);
     _backGroundColor = ColorTranslator.FromHtml(_settings.BackgroundColor);
 }