Example #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 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);
        }
Example #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 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);
        }
Example #3
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);
        }