egami
C++ Image Processing program
|
00001 #include <algorithm> 00002 #include <memory> 00003 #include <string> 00004 00005 #include <gtkmm/image.h> 00006 #include <gtkmm/dialog.h> 00007 #include <gtkmm/radiobutton.h> 00008 #include <gtkmm/stock.h> 00009 00010 #include "../display_unit.hpp" 00011 #include "../processing_page.hpp" 00012 #include "../processing_unit.hpp" 00013 #include "../utils.hpp" 00014 00015 namespace{ 00016 class Config: public Gtk::Dialog { 00017 public: 00018 enum Mode {UNKNOW, HORIZ, VERT}; 00019 Config(): h("Horizontal"), v("Vertical") { 00020 set_resizable(false); 00021 00022 Gtk::RadioButton::Group group = h.get_group(); 00023 v.set_group(group); 00024 00025 get_vbox()->pack_start(h); 00026 get_vbox()->pack_start(v); 00027 00028 h.set_active(); 00029 00030 add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); 00031 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 00032 00033 show_all_children(); 00034 } 00035 00036 Mode mode(){ 00037 if(h.get_active()) 00038 return HORIZ; 00039 else if(v.get_active()) 00040 return VERT; 00041 else 00042 return UNKNOW; 00043 } 00044 00045 private: 00046 Gtk::RadioButton h, v; 00047 }; 00048 00049 Display_unit* impl(const Image_unit *in){ 00050 Config c; 00051 if(c.run()!=Gtk::RESPONSE_OK || c.mode()==Config::UNKNOW) 00052 return nullptr; 00053 c.hide(); 00054 00055 Image_unit *out=new Image_unit(*in); 00056 00057 for(unsigned y=0; y<out->height(); ++y) 00058 for(unsigned x=0; x<out->width(); ++x){ 00059 unsigned char red, green, blue; 00060 switch(c.mode()){ 00061 case Config::HORIZ:{ 00062 red=in->red(in->height()-y-1, x); 00063 green=in->green(in->height()-y-1, x); 00064 blue=in->blue(in->height()-y-1, x); 00065 break; 00066 } case Config::VERT:{ 00067 red=in->red(y, in->width()-x-1); 00068 green=in->green(y, in->width()-x-1); 00069 blue=in->blue(y, in->width()-x-1); 00070 break; 00071 } 00072 } 00073 out->red(y, x, red); 00074 out->green(y, x, green); 00075 out->blue(y, x, blue); 00076 } 00077 00078 return out; 00079 } 00080 } 00081 00082 namespace Processes{ 00083 void mirror(){ 00084 Gtk::Image icon(cmake_install_prefix+std::string("/share/egami/icons/mirror.png")); 00085 std::shared_ptr<Processing_unit> pu(new Processing_unit(Processing(&impl), "Mirror", icon, false)); 00086 Processing_page::add_unit_to_page("Reshape", pu); 00087 } 00088 }