Fawkes API
Fawkes Development Version
|
00001 /*************************************************************************** 00002 * image_widget.h - Gtkmm widget to draw an image inside a Gtk::Window 00003 * 00004 * Created: Wed Nov 26 00:00:00 2008 00005 * Copyright 2008 Christof Rath <christof.rath@gmail.com> 00006 * 00007 ****************************************************************************/ 00008 00009 /* This program is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU Library General Public License for more details. 00018 * 00019 * Read the full text in the LICENSE.GPL file in the doc directory. 00020 */ 00021 00022 #ifndef __FIREVISION_FVWIDGETS_IMAGE_WIDGET_H_ 00023 #define __FIREVISION_FVWIDGETS_IMAGE_WIDGET_H_ 00024 00025 #include <core/threading/thread.h> 00026 #include <fvutils/color/colorspaces.h> 00027 #include <fvutils/color/rgb.h> 00028 00029 #include <gtkmm.h> 00030 #ifdef HAVE_GLADEMM 00031 # include <libglademm/xml.h> 00032 #endif 00033 00034 namespace fawkes { 00035 class Mutex; 00036 } 00037 00038 namespace firevision { 00039 #if 0 /* just to make Emacs auto-indent happy */ 00040 } 00041 #endif 00042 00043 class Camera; 00044 00045 class ImageWidget : public Gtk::Image 00046 { 00047 private: 00048 class RefThread : public fawkes::Thread 00049 { 00050 public: 00051 RefThread(ImageWidget *widget, unsigned int refresh_delay); 00052 void set_delay(unsigned int refresh_delay); 00053 void save_on_refresh(bool enabled, std::string path = "", Glib::ustring type = "", unsigned int img_num = 0); 00054 void refresh_cam(); 00055 void stop(); 00056 unsigned int get_img_num(); 00057 00058 private: 00059 void loop(); 00060 void perform_refresh(); 00061 00062 ImageWidget *__widget; 00063 bool __stop; 00064 bool __do_refresh; 00065 unsigned int __refresh_delay; 00066 unsigned int __loop_cnt; 00067 Glib::Dispatcher __dispatcher; 00068 00069 bool __save_imgs; 00070 std::string __save_path; 00071 Glib::ustring __save_type; 00072 unsigned int __save_num; 00073 }; 00074 00075 public: 00076 ImageWidget(unsigned int width, unsigned int height); 00077 ImageWidget(Camera *cam, unsigned int refresh_delay = 0, unsigned int width = 0, unsigned int height = 0); 00078 #ifdef HAVE_GLADEMM 00079 ImageWidget(BaseObjectType* cobject, Glib::RefPtr<Gnome::Glade::Xml> refxml); 00080 #endif 00081 virtual ~ImageWidget(); 00082 00083 void set_camera(Camera *cam, unsigned int refresh_delay = 0); 00084 void enable_camera(bool enable); 00085 void set_size(unsigned int width, unsigned int height); 00086 virtual bool show(colorspace_t colorspace, unsigned char *buffer, unsigned int width = 0, unsigned int height = 0); 00087 void set_refresh_delay(unsigned int refresh_delay); 00088 void refresh_cam(); 00089 unsigned int get_width() const; 00090 unsigned int get_height() const; 00091 Glib::RefPtr<Gdk::Pixbuf> get_buffer() const; 00092 void set_rgb(unsigned int x, unsigned int y, unsigned char r, unsigned char g, unsigned char b); 00093 void set_rgb(unsigned int x, unsigned int y, RGB_t rgb); 00094 bool save_image(std::string filename, Glib::ustring type) const throw(); 00095 void save_on_refresh_cam(bool enabled, std::string path = "", Glib::ustring type = "", unsigned int img_num = 0); 00096 unsigned int get_image_num(); 00097 sigc::signal<void, colorspace_t, unsigned char *, unsigned int, unsigned int> & signal_show(); 00098 00099 private: 00100 void set_cam(); 00101 00102 unsigned int __width; 00103 unsigned int __height; 00104 00105 Glib::RefPtr<Gdk::Pixbuf> __pixbuf; 00106 00107 RefThread *__refresh_thread; 00108 Camera *__cam; 00109 fawkes::Mutex *__cam_mutex; 00110 bool __cam_has_buffer; 00111 bool __cam_has_timestamp; 00112 bool __cam_enabled; 00113 00114 sigc::signal<void, colorspace_t, unsigned char *, unsigned int, unsigned int> __signal_show; 00115 }; 00116 00117 } // end namespace firevision 00118 00119 #endif /* __FIREVISION_FVWIDGETS_IMAGE_WIDGET_H_ */