egami
C++ Image Processing program
|
00001 #include <algorithm> 00002 #include <memory> 00003 #include <sstream> 00004 #include <vector> 00005 00006 #include "../catalogue.hpp" 00007 #include "../display_unit.hpp" 00008 #include "binary.hpp" 00009 00010 #include <gtkmm/dialog.h> 00011 #include <gtkmm/stock.h> 00012 #include <gtkmm/listviewtext.h> 00013 00014 namespace{ 00015 class Config: public Gtk::Dialog { 00016 public: 00017 Config(std::vector<std::shared_ptr<Display_unit>> &units): lvt(1) { 00018 set_resizable(false); 00019 lvt.set_column_title(0, "Name"); 00020 unsigned i=0; 00021 for(std::shared_ptr<Display_unit> unit: units){ 00022 i++; 00023 std::shared_ptr<Image_unit> iu(std::dynamic_pointer_cast<Image_unit>(unit)); 00024 if(iu){ 00025 list.push_back(iu); 00026 std::stringstream ss; 00027 ss << i; 00028 if(iu->get_path()!=""){ 00029 const std::string &filepath=iu->get_path(); 00030 std::string::const_reverse_iterator rlastslash=std::find(filepath.rbegin(), filepath.rend(), '/'); 00031 std::string::const_reverse_iterator rlastdot=std::find(filepath.rbegin(), filepath.rend(), '.'); 00032 if(rlastslash!=filepath.rend() && rlastdot!=filepath.rend()) 00033 ss << " " << std::string(rlastslash.base(), rlastdot.base()-1); 00034 } 00035 lvt.append(ss.str()); 00036 } 00037 } 00038 00039 get_vbox()->pack_start(lvt); 00040 00041 add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); 00042 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 00043 00044 show_all_children(); 00045 } 00046 00047 const Image_unit* choice() { 00048 Gtk::ListViewText::SelectionList sl=lvt.get_selected(); 00049 return list[sl[0]].get(); 00050 } 00051 00052 private: 00053 std::vector<std::shared_ptr<Image_unit>> list; 00054 Gtk::ListViewText lvt; 00055 }; 00056 } 00057 00058 Image_unit* bin_op(const Image_unit *lhs, std::function<unsigned char(unsigned char,unsigned char)> select){ 00059 std::vector<std::shared_ptr<Display_unit>> &&units=Display_catalogue::all_units(); 00060 Config c(units); 00061 if(c.run()!=Gtk::RESPONSE_OK) 00062 return nullptr; 00063 c.hide(); 00064 00065 const Image_unit *rhs=c.choice(); 00066 if(!rhs) 00067 return nullptr; 00068 00069 unsigned width=std::min(rhs->width(), lhs->width()); 00070 unsigned height=std::min(rhs->height(), lhs->height()); 00071 00072 Image_unit *out=new Image_unit(*lhs); 00073 00074 for(unsigned y=0; y<height; ++y) 00075 for(unsigned x=0; x<width; ++x){ 00076 out->red(y, x, select(lhs->red(y,x), rhs->red(y,x))); 00077 out->green(y, x, select(lhs->green(y,x), rhs->green(y,x))); 00078 out->blue(y, x, select(lhs->blue(y,x), rhs->blue(y,x))); 00079 } 00080 00081 return out; 00082 } 00083 00084 namespace Processes{ 00085 void binary(){ 00087 } 00088 }