diff --git a/ascii_converter.sln b/ascii_converter.sln new file mode 100644 index 0000000..13a261a --- /dev/null +++ b/ascii_converter.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ascii_converter", "ascii_converter\ascii_converter.vcxproj", "{0B760371-82E5-4FA2-9801-B4EC53B0916D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0B760371-82E5-4FA2-9801-B4EC53B0916D}.Debug|Win32.ActiveCfg = Debug|Win32 + {0B760371-82E5-4FA2-9801-B4EC53B0916D}.Debug|Win32.Build.0 = Debug|Win32 + {0B760371-82E5-4FA2-9801-B4EC53B0916D}.Release|Win32.ActiveCfg = Release|Win32 + {0B760371-82E5-4FA2-9801-B4EC53B0916D}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/ascii_converter/ascii_converter.aps b/ascii_converter/ascii_converter.aps new file mode 100644 index 0000000..df699b6 Binary files /dev/null and b/ascii_converter/ascii_converter.aps differ diff --git a/ascii_converter/ascii_converter.rc b/ascii_converter/ascii_converter.rc new file mode 100644 index 0000000..1868ef3 Binary files /dev/null and b/ascii_converter/ascii_converter.rc differ diff --git a/ascii_converter/ascii_converter.vcxproj b/ascii_converter/ascii_converter.vcxproj new file mode 100644 index 0000000..9623da3 --- /dev/null +++ b/ascii_converter/ascii_converter.vcxproj @@ -0,0 +1,103 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {0B760371-82E5-4FA2-9801-B4EC53B0916D} + v2.0 + ManagedCProj + ascii_converter + + + + Application + true + v110 + true + Unicode + + + Application + false + v110 + true + Unicode + false + + + + + + + + + + + + + true + + + false + + + + Level3 + Disabled + WIN32;_DEBUG;%(PreprocessorDefinitions) + + + true + + + + + + Level3 + WIN32;NDEBUG;%(PreprocessorDefinitions) + Full + + + true + + + + + + + + + + + + + + + + CppForm + + + + + + main.h + + + + + + + + + + + + \ No newline at end of file diff --git a/ascii_converter/ascii_converter.vcxproj.filters b/ascii_converter/ascii_converter.vcxproj.filters new file mode 100644 index 0000000..d79de20 --- /dev/null +++ b/ascii_converter/ascii_converter.vcxproj.filters @@ -0,0 +1,45 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + + + Source Files + + + + + Resource Files + + + + + Resource Files + + + + + Resource Files + + + \ No newline at end of file diff --git a/ascii_converter/ascii_converter.vcxproj.user b/ascii_converter/ascii_converter.vcxproj.user new file mode 100644 index 0000000..7cbb321 --- /dev/null +++ b/ascii_converter/ascii_converter.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ascii_converter/icon.ico b/ascii_converter/icon.ico new file mode 100644 index 0000000..bba6792 Binary files /dev/null and b/ascii_converter/icon.ico differ diff --git a/ascii_converter/main.cpp b/ascii_converter/main.cpp new file mode 100644 index 0000000..c4c0175 --- /dev/null +++ b/ascii_converter/main.cpp @@ -0,0 +1,11 @@ +#include +#include "main.h" +#pragma comment( lib, "user32.lib" ) + +using namespace System; +using namespace System::Windows::Forms; +[STAThread] +BOOL WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, INT ) { + Application::Run( gcnew ascii_converter::main ); + return TRUE; +} \ No newline at end of file diff --git a/ascii_converter/main.h b/ascii_converter/main.h new file mode 100644 index 0000000..b9acc5f --- /dev/null +++ b/ascii_converter/main.h @@ -0,0 +1,297 @@ +#pragma once + +namespace ascii_converter { + + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + /// + /// Summary for main + /// + public ref class main : public System::Windows::Forms::Form + { + public: + main(void) + { + InitializeComponent(); + // + //TODO: Add the constructor code here + // + } + + protected: + /// + /// Clean up any resources being used. + /// + ~main() + { + if (components) + { + delete components; + } + } + private: System::Windows::Forms::Label^ label1; + protected: + private: System::Windows::Forms::TextBox^ textBox1; + private: System::Windows::Forms::Button^ button1; + private: System::Windows::Forms::PictureBox^ pictureBox1; + private: System::Windows::Forms::RichTextBox^ richTextBox1; + private: System::Windows::Forms::Button^ button2; + private: System::Windows::Forms::TextBox^ textBox2; + private: System::Windows::Forms::Label^ label2; + private: System::Windows::Forms::TextBox^ textBox3; + private: System::Windows::Forms::Label^ label3; + + private: System::Windows::Forms::TextBox^ textBox4; + private: System::Windows::Forms::Label^ label4; + private: System::Windows::Forms::CheckBox^ checkBox1; + + private: + /// + /// Required designer variable. + /// + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + void InitializeComponent(void) + { + this->label1 = (gcnew System::Windows::Forms::Label()); + this->textBox1 = (gcnew System::Windows::Forms::TextBox()); + this->button1 = (gcnew System::Windows::Forms::Button()); + this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox()); + this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox()); + this->button2 = (gcnew System::Windows::Forms::Button()); + this->textBox2 = (gcnew System::Windows::Forms::TextBox()); + this->label2 = (gcnew System::Windows::Forms::Label()); + this->textBox3 = (gcnew System::Windows::Forms::TextBox()); + this->label3 = (gcnew System::Windows::Forms::Label()); + this->textBox4 = (gcnew System::Windows::Forms::TextBox()); + this->label4 = (gcnew System::Windows::Forms::Label()); + this->checkBox1 = (gcnew System::Windows::Forms::CheckBox()); + (cli::safe_cast(this->pictureBox1))->BeginInit(); + this->SuspendLayout(); + // + // label1 + // + this->label1->AutoSize = true; + this->label1->Location = System::Drawing::Point(12, 9); + this->label1->Name = L"label1"; + this->label1->Size = System::Drawing::Size(55, 13); + this->label1->TabIndex = 0; + this->label1->Text = L"Image file:"; + // + // textBox1 + // + this->textBox1->Location = System::Drawing::Point(73, 6); + this->textBox1->Name = L"textBox1"; + this->textBox1->Size = System::Drawing::Size(474, 20); + this->textBox1->TabIndex = 1; + this->textBox1->Text = L"image.bmp"; + // + // button1 + // + this->button1->Location = System::Drawing::Point(553, 4); + this->button1->Name = L"button1"; + this->button1->Size = System::Drawing::Size(75, 23); + this->button1->TabIndex = 2; + this->button1->Text = L"Load..."; + this->button1->UseVisualStyleBackColor = true; + this->button1->Click += gcnew System::EventHandler(this, &main::button1_Click); + // + // pictureBox1 + // + this->pictureBox1->Location = System::Drawing::Point(15, 32); + this->pictureBox1->Name = L"pictureBox1"; + this->pictureBox1->Size = System::Drawing::Size(303, 218); + this->pictureBox1->TabIndex = 3; + this->pictureBox1->TabStop = false; + // + // richTextBox1 + // + this->richTextBox1->Font = (gcnew System::Drawing::Font(L"Lucida Console", 10)); + this->richTextBox1->Location = System::Drawing::Point(325, 32); + this->richTextBox1->Name = L"richTextBox1"; + this->richTextBox1->ReadOnly = true; + this->richTextBox1->ScrollBars = System::Windows::Forms::RichTextBoxScrollBars::ForcedBoth; + this->richTextBox1->Size = System::Drawing::Size(303, 218); + this->richTextBox1->TabIndex = 4; + this->richTextBox1->Text = L""; + this->richTextBox1->WordWrap = false; + // + // button2 + // + this->button2->Location = System::Drawing::Point(15, 282); + this->button2->Name = L"button2"; + this->button2->Size = System::Drawing::Size(613, 23); + this->button2->TabIndex = 5; + this->button2->Text = L"Make ASCII..."; + this->button2->UseVisualStyleBackColor = true; + this->button2->Click += gcnew System::EventHandler(this, &main::button2_Click); + // + // textBox2 + // + this->textBox2->Location = System::Drawing::Point(73, 256); + this->textBox2->Name = L"textBox2"; + this->textBox2->Size = System::Drawing::Size(90, 20); + this->textBox2->TabIndex = 7; + this->textBox2->Text = L".;O;|"; + // + // label2 + // + this->label2->AutoSize = true; + this->label2->Location = System::Drawing::Point(12, 259); + this->label2->Name = L"label2"; + this->label2->Size = System::Drawing::Size(37, 13); + this->label2->TabIndex = 6; + this->label2->Text = L"Chars:"; + // + // textBox3 + // + this->textBox3->Location = System::Drawing::Point(386, 256); + this->textBox3->Name = L"textBox3"; + this->textBox3->Size = System::Drawing::Size(90, 20); + this->textBox3->TabIndex = 9; + this->textBox3->Text = L"2"; + // + // label3 + // + this->label3->AutoSize = true; + this->label3->Location = System::Drawing::Point(325, 259); + this->label3->Name = L"label3"; + this->label3->Size = System::Drawing::Size(49, 13); + this->label3->TabIndex = 8; + this->label3->Text = L"W scale:"; + // + // textBox4 + // + this->textBox4->Location = System::Drawing::Point(229, 256); + this->textBox4->Name = L"textBox4"; + this->textBox4->Size = System::Drawing::Size(90, 20); + this->textBox4->TabIndex = 12; + this->textBox4->Text = L"10"; + // + // label4 + // + this->label4->AutoSize = true; + this->label4->Location = System::Drawing::Point(168, 259); + this->label4->Name = L"label4"; + this->label4->Size = System::Drawing::Size(58, 13); + this->label4->TabIndex = 11; + this->label4->Text = L"Tolerance:"; + // + // checkBox1 + // + this->checkBox1->AutoSize = true; + this->checkBox1->Checked = true; + this->checkBox1->CheckState = System::Windows::Forms::CheckState::Checked; + this->checkBox1->Location = System::Drawing::Point(482, 258); + this->checkBox1->Name = L"checkBox1"; + this->checkBox1->Size = System::Drawing::Size(85, 17); + this->checkBox1->TabIndex = 13; + this->checkBox1->Text = L"Add shadow"; + this->checkBox1->UseVisualStyleBackColor = true; + // + // main + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(643, 313); + this->Controls->Add(this->checkBox1); + this->Controls->Add(this->textBox4); + this->Controls->Add(this->label4); + this->Controls->Add(this->textBox3); + this->Controls->Add(this->label3); + this->Controls->Add(this->textBox2); + this->Controls->Add(this->label2); + this->Controls->Add(this->button2); + this->Controls->Add(this->richTextBox1); + this->Controls->Add(this->pictureBox1); + this->Controls->Add(this->button1); + this->Controls->Add(this->textBox1); + this->Controls->Add(this->label1); + this->DoubleBuffered = true; + this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle; + this->MaximizeBox = false; + this->Name = L"main"; + this->Text = L"ASCII Converter"; + (cli::safe_cast(this->pictureBox1))->EndInit(); + this->ResumeLayout(false); + this->PerformLayout(); + + } +#pragma endregion + + array< unsigned int, 2 >^ pixels; + Color pixel; + INT w, h, wscale, tolerance, bAddShadow; + + void button1_Click( Object^ sender, EventArgs^ e ) { + Bitmap^ image = nullptr; + try { //catching exceptions + image = (Bitmap^)Image::FromFile(textBox1->Text); + } + catch( BadImageFormatException^ ) { + MessageBoxA( NULL, "Error\n\tCan't load specified image\n\tBadImageFormat", NULL, MB_ICONERROR ); + return; + } + catch( OutOfMemoryException^ ) { + MessageBoxA( NULL, "Error\n\tCan't load specified image\n\tOutOfMemory", NULL, MB_ICONERROR ); + return; + } + catch( IO::FileNotFoundException^ ) { + MessageBoxA( NULL, "Error\n\tCan't load specified image\n\tFileNotFound", NULL, MB_ICONERROR ); + return; + } + w = image->Width, h = image->Height; + tolerance = Convert::ToInt16( textBox4->Text ); + pixels = gcnew array< unsigned int, 2 >(w, h); //make a 2-dimensional array to store pixel data in + for( INT y = 0; y < h; y++ ) { + for( INT x = 0; x < w; x++ ) { //thumb thru the pixels + pixel = image->GetPixel(x, y); //get pixel color + pixels[x, y] = (pixel.R > tolerance && pixel.G > tolerance && pixel.B > tolerance); + } //check if the pixel is bright enough to tolerate it as something we should draw + } + pictureBox1->Image = image; //load the image into picture-box + } + + void button2_Click( Object^ sender, EventArgs^ e ) { + richTextBox1->Clear(); //clear the previous art + wscale = Convert::ToInt16( textBox3->Text ); //set w-scale + bAddShadow = checkBox1->Checked; + wchar_t chars[3] = { Convert::ToChar(textBox2->Text->Substring(0, 1)), + Convert::ToChar(textBox2->Text->Substring(2, 1)), + Convert::ToChar(textBox2->Text->Substring(4, 1)) }; //set our characters + for( INT y = 0; y < h; y++ ) { + for( INT x = 0; x < w; x++ ) { //thumb thru the pixels array & process it + for( INT s = 0; s < wscale; s++ ) { //if we need to scale by width, do so + if( pixels[x, y] ) { + if( x && x < w-1 ) { //still within the bounds + if( bAddShadow && ((pixels[x-1, y] && !pixels[x, y]) || (!pixels[x+1, y] && pixels[x, y])) ) + richTextBox1->Text += chars[2].ToString(); + else richTextBox1->Text += chars[0].ToString(); + } + else richTextBox1->Text += chars[0].ToString(); + } + else richTextBox1->Text += chars[1].ToString(); + } + } + richTextBox1->Text += "\n"; //new-line determinator after each vertical line + } + } + + void button3_Click( Object^ sender, EventArgs^ e ) { + if( richTextBox1->Text != String::Empty ) { //if the art has been drawn + Clipboard::Clear(); //clear the previously stored data + Clipboard::SetText( richTextBox1->Text ); //paste it into clipboard + } + } +}; +} diff --git a/ascii_converter/main.resx b/ascii_converter/main.resx new file mode 100644 index 0000000..29dcb1b --- /dev/null +++ b/ascii_converter/main.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ascii_converter/resource.h b/ascii_converter/resource.h new file mode 100644 index 0000000..fdd97cb Binary files /dev/null and b/ascii_converter/resource.h differ