Пример #1
0
        // Testing mainframe
        public static void Main(String[] args)
        {
            if (args.Length != 1)
            {
                StringBuilder error_message = new StringBuilder("Invalid use:");
                error_message.Append(String.Format("\targ #{0}: {1}", 1, "file_name"));

                throw new Exception(error_message.ToString());
            }

            BinaryFileReader reader = new BinaryFileReader(args[0], System.Environment.CurrentDirectory);
            //reader.display();

            PNG_Decoder decoder = new PNG_Decoder(reader.file_data);

            byte[] greyscale_bytes = decoder.to_greyscale();

            /*
             * Console.WriteLine("The converted bytes to greyscale are:");
             * Console.Write("[{0}", greyscale_bytes[0]);
             * for (int i = 1; i < greyscale_bytes.Length; i++)
             * {
             * Console.Write(", ");
             * if (i % 5 == 0)
             * {
             *    Console.WriteLine();
             * }
             * Console.Write(greyscale_bytes[i]);
             * }
             * Console.WriteLine("]");
             * */

            Console.WriteLine();
            Console.WriteLine();

            string[] ASCII_lines = ASCII_Converter.convert_to_ASCII_art(greyscale_bytes, decoder.height, decoder.width);

            // make a text file
            StringBuilder txt_path_builder = new StringBuilder(reader.filepath.Remove(reader.filepath.LastIndexOf(".")));

            txt_path_builder.Append(".txt");

            ASCII_Converter.to_txt(ASCII_lines, txt_path_builder.ToString());
        }
        // Testing mainframe
        public static void Main(String[] args)
        {
            if (args.Length != 1)
             {
            StringBuilder error_message = new StringBuilder("Invalid use:");
            error_message.Append(String.Format("\targ #{0}: {1}", 1, "file_name"));

            throw new Exception(error_message.ToString());
             }

             BinaryFileReader reader = new BinaryFileReader(args[0], System.Environment.CurrentDirectory);
             //reader.display();

             PNG_Decoder decoder = new PNG_Decoder(reader.file_data);
             byte[] greyscale_bytes = decoder.to_greyscale();

             /*
             Console.WriteLine("The converted bytes to greyscale are:");
             Console.Write("[{0}", greyscale_bytes[0]);
             for (int i = 1; i < greyscale_bytes.Length; i++)
             {
            Console.Write(", ");
            if (i % 5 == 0)
            {
               Console.WriteLine();
            }
            Console.Write(greyscale_bytes[i]);
             }
             Console.WriteLine("]");
              * */

             Console.WriteLine();
             Console.WriteLine();

             string[] ASCII_lines = ASCII_Converter.convert_to_ASCII_art(greyscale_bytes, decoder.height, decoder.width);

             // make a text file
             StringBuilder txt_path_builder = new StringBuilder(reader.filepath.Remove(reader.filepath.LastIndexOf(".")));
             txt_path_builder.Append(".txt");

             ASCII_Converter.to_txt(ASCII_lines, txt_path_builder.ToString());
        }
        public static void initialize_ASCII_hashes(Image_Sizes image_size)
        {
            // get the folder
               StringBuilder path_builder = new StringBuilder(System.Environment.CurrentDirectory);

               if (image_size == Image_Sizes.SMALL)
               {
                  path_builder.Append("\\ASCII_Characters_Small\\");
               }
               else if (image_size == Image_Sizes.MEDIUM)
               {
                  path_builder.Append("\\ASCII_Characters_Medium\\");
               }
               else if (image_size == Image_Sizes.LARGE)
               {
                  path_builder.Append("\\ASCII_Characters_Large\\");
               }
               else if (image_size == Image_Sizes.X_LARGE)
               {
                  path_builder.Append("\\ASCII_Characters_X_Large\\");
               }
               else
               {
                  throw new ArgumentException("ASCII_Converter: Invalid image size for ASCII hash initialization.");
               }

               // record the image tier
               image_tier = image_size;

               ASCII_Characters = new char[] {'!', '"', '#', '$', '%', '&', '\'', '(', ')', '*',
                  '+', ',', '-', '.', '/', '0', '1', '2', '3', '4',
                  '5', '6', '7', '8', '9', ':', ';', '<', '=', '>',
                  '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
                  'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
                  'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\',
                  ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f',
                  'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
                  'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
                  ' ', '{', '|', '}'
               };
               string[] files = {"exclamation_mark", "quotation_mark", "hashtag", "dollar_sign", "percent", "ampersans", "apostrophe", "left_parenthesis", "right_parenthesis", "asterisk",
                                "plus_sign", "comma", "minus_sign", "period", "forward_slash", "zero", "one", "two", "three", "four",
                                "five", "six", "seven", "eight", "nine", "colon", "semicolon", "less_than_symbol", "equals_sign", "greater_than_symbol",
                                "question_mark", "at_symbol", "A", "B", "C", "D", "E", "F", "G", "H",
                                "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
                                "S", "T", "U", "V", "W", "X", "Y", "Z", "left_square_bracket", "backslash",
                                "right_square_bracket", "carrot", "underscore", "single_quote_mark", "lowercase_a", "lowercase_b", "lowercase_c", "lowercase_d", "lowercase_e", "lowercase_f",
                                "lowercase_g", "lowercase_h", "lowercase_i", "lowercase_j", "lowercase_k", "lowercase_l", "lowercase_m", "lowercase_n", "lowercase_o", "lowercase_p",
                                "lowercase_q", "lowercase_r", "lowercase_s", "lowercase_t", "lowercase_u", "lowercase_v", "lowercase_w", "lowercase_x", "lowercase_y", "lowercase_z",
                                "space", "left_bracket", "vertical_line", "right_bracket"
                                };
               ASCII_hashes = new uint[ASCII_Characters.Length];

               for(int i = 0; i < ASCII_Characters.Length; i++){
                  BinaryFileReader file_reader = new BinaryFileReader(files[i] + ".png", path_builder.ToString());
                  PNG_Decoder png_decoder = new PNG_Decoder(file_reader.file_data);
                  byte[] file_bytes = png_decoder.to_greyscale();

                  for(int byte_index = 0; byte_index < file_bytes.Length; byte_index++){
                     ASCII_hashes[i] = ASCII_hashes[i] << 1;
                     if (file_bytes[byte_index] < 100)
                     {
                        ASCII_hashes[i] += 1;
                     }
                     //ASCII_hashes[i] += file_bytes[byte_index];
                  }
               }

               initialized = true;
        }
Пример #4
0
        static public void initialize_ASCII_hashes(Image_Sizes image_size)
        {
            // get the folder
            StringBuilder path_builder = new StringBuilder(System.Environment.CurrentDirectory);

            if (image_size == Image_Sizes.SMALL)
            {
                path_builder.Append("\\ASCII_Characters_Small\\");
            }
            else if (image_size == Image_Sizes.MEDIUM)
            {
                path_builder.Append("\\ASCII_Characters_Medium\\");
            }
            else if (image_size == Image_Sizes.LARGE)
            {
                path_builder.Append("\\ASCII_Characters_Large\\");
            }
            else if (image_size == Image_Sizes.X_LARGE)
            {
                path_builder.Append("\\ASCII_Characters_X_Large\\");
            }
            else
            {
                throw new ArgumentException("ASCII_Converter: Invalid image size for ASCII hash initialization.");
            }

            // record the image tier
            image_tier = image_size;

            ASCII_Characters = new char[] { '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*',
                                            '+', ',', '-', '.', '/', '0', '1', '2', '3', '4',
                                            '5', '6', '7', '8', '9', ':', ';', '<', '=', '>',
                                            '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
                                            'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
                                            'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\',
                                            ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f',
                                            'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
                                            'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
                                            ' ', '{', '|', '}' };
            string[] files = { "exclamation_mark",     "quotation_mark", "hashtag",       "dollar_sign",       "percent",       "ampersans",   "apostrophe",  "left_parenthesis", "right_parenthesis",   "asterisk",
                               "plus_sign",            "comma",          "minus_sign",    "period",            "forward_slash", "zero",        "one",         "two",              "three",               "four",
                               "five",                 "six",            "seven",         "eight",             "nine",          "colon",       "semicolon",   "less_than_symbol", "equals_sign",         "greater_than_symbol",
                               "question_mark",        "at_symbol",      "A",             "B",                 "C",             "D",           "E",           "F",                "G",                   "H",
                               "I",                    "J",              "K",             "L",                 "M",             "N",           "O",           "P",                "Q",                   "R",
                               "S",                    "T",              "U",             "V",                 "W",             "X",           "Y",           "Z",                "left_square_bracket", "backslash",
                               "right_square_bracket", "carrot",         "underscore",    "single_quote_mark", "lowercase_a",   "lowercase_b", "lowercase_c", "lowercase_d",      "lowercase_e",         "lowercase_f",
                               "lowercase_g",          "lowercase_h",    "lowercase_i",   "lowercase_j",       "lowercase_k",   "lowercase_l", "lowercase_m", "lowercase_n",      "lowercase_o",         "lowercase_p",
                               "lowercase_q",          "lowercase_r",    "lowercase_s",   "lowercase_t",       "lowercase_u",   "lowercase_v", "lowercase_w", "lowercase_x",      "lowercase_y",         "lowercase_z",
                               "space",                "left_bracket",   "vertical_line", "right_bracket" };
            ASCII_hashes = new uint[ASCII_Characters.Length];

            for (int i = 0; i < ASCII_Characters.Length; i++)
            {
                BinaryFileReader file_reader = new BinaryFileReader(files[i] + ".png", path_builder.ToString());
                PNG_Decoder      png_decoder = new PNG_Decoder(file_reader.file_data);
                byte[]           file_bytes  = png_decoder.to_greyscale();

                for (int byte_index = 0; byte_index < file_bytes.Length; byte_index++)
                {
                    ASCII_hashes[i] = ASCII_hashes[i] << 1;
                    if (file_bytes[byte_index] < 100)
                    {
                        ASCII_hashes[i] += 1;
                    }
                    //ASCII_hashes[i] += file_bytes[byte_index];
                }
            }

            initialized = true;
        }