image_widget.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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 #include <libglademm/xml.h>
00031
00032 class Camera;
00033
00034 namespace fawkes {
00035 class Mutex;
00036 }
00037
00038 class ImageWidget : public Gtk::Image
00039 {
00040 private:
00041 class RefThread : public fawkes::Thread
00042 {
00043 public:
00044 RefThread(ImageWidget *widget, unsigned int refresh_delay);
00045 void set_delay(unsigned int refresh_delay);
00046 void save_on_refresh(bool enabled, std::string path = "", Glib::ustring type = "", unsigned int img_num = 0);
00047 void refresh_cam();
00048 void stop();
00049 unsigned int get_img_num();
00050
00051 private:
00052 void loop();
00053 void perform_refresh();
00054
00055 ImageWidget *__widget;
00056 bool __stop;
00057 bool __do_refresh;
00058 unsigned int __refresh_delay;
00059 unsigned int __loop_cnt;
00060 Glib::Dispatcher __dispatcher;
00061
00062 bool __save_imgs;
00063 std::string __save_path;
00064 Glib::ustring __save_type;
00065 unsigned int __save_num;
00066 };
00067
00068 public:
00069 ImageWidget(unsigned int width, unsigned int height);
00070 ImageWidget(Camera *cam, unsigned int refresh_delay = 0, unsigned int width = 0, unsigned int height = 0);
00071 ImageWidget(BaseObjectType* cobject, Glib::RefPtr<Gnome::Glade::Xml> refxml);
00072 virtual ~ImageWidget();
00073
00074 void set_camera(Camera *cam, unsigned int refresh_delay = 0);
00075 void enable_camera(bool enable);
00076 void set_size(unsigned int width, unsigned int height);
00077 virtual bool show(colorspace_t colorspace, unsigned char *buffer, unsigned int width = 0, unsigned int height = 0);
00078 void set_refresh_delay(unsigned int refresh_delay);
00079 void refresh_cam();
00080 unsigned int get_width() const;
00081 unsigned int get_height() const;
00082 Glib::RefPtr<Gdk::Pixbuf> get_buffer() const;
00083 void set_rgb(unsigned int x, unsigned int y, unsigned char r, unsigned char g, unsigned char b);
00084 void set_rgb(unsigned int x, unsigned int y, RGB_t rgb);
00085 bool save_image(std::string filename, Glib::ustring type) const throw();
00086 void save_on_refresh_cam(bool enabled, std::string path = "", Glib::ustring type = "", unsigned int img_num = 0);
00087 unsigned int get_image_num();
00088 sigc::signal<void, colorspace_t, unsigned char *, unsigned int, unsigned int> & signal_show();
00089
00090 private:
00091 void set_cam();
00092
00093 unsigned int __width;
00094 unsigned int __height;
00095
00096 Glib::RefPtr<Gdk::Pixbuf> __pixbuf;
00097
00098 RefThread *__refresh_thread;
00099 Camera *__cam;
00100 fawkes::Mutex *__cam_mutex;
00101 bool __cam_has_buffer;
00102 bool __cam_has_timestamp;
00103 bool __cam_enabled;
00104
00105 sigc::signal<void, colorspace_t, unsigned char *, unsigned int, unsigned int> __signal_show;
00106 };
00107
00108 #endif