Fawkes API  Fawkes Development Version
image_widget.h
1 /***************************************************************************
2  * image_widget.h - Gtkmm widget to draw an image inside a Gtk::Window
3  *
4  * Created: Wed Nov 26 00:00:00 2008
5  * Copyright 2008 Christof Rath <christof.rath@gmail.com>
6  *
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Library General Public License for more details.
18  *
19  * Read the full text in the LICENSE.GPL file in the doc directory.
20  */
21 
22 #ifndef __FIREVISION_FVWIDGETS_IMAGE_WIDGET_H_
23 #define __FIREVISION_FVWIDGETS_IMAGE_WIDGET_H_
24 
25 #include <core/threading/thread.h>
26 #include <fvutils/color/colorspaces.h>
27 #include <fvutils/color/rgb.h>
28 
29 #include <gtkmm.h>
30 #ifdef HAVE_GLADEMM
31 # include <libglademm/xml.h>
32 #endif
33 
34 namespace fawkes {
35  class Mutex;
36 }
37 
38 namespace firevision {
39 #if 0 /* just to make Emacs auto-indent happy */
40 }
41 #endif
42 
43 class Camera;
44 
45 class ImageWidget : public Gtk::Image
46 {
47  private:
48  class RefThread : public fawkes::Thread
49  {
50  public:
51  RefThread(ImageWidget *widget, unsigned int refresh_delay);
52  void set_delay(unsigned int refresh_delay);
53  void save_on_refresh(bool enabled, std::string path = "", Glib::ustring type = "", unsigned int img_num = 0);
54  void refresh_cam();
55  void stop();
56  unsigned int get_img_num();
57 
58  private:
59  void loop();
60  void perform_refresh();
61 
62  ImageWidget *__widget;
63  bool __stop;
64  bool __do_refresh;
65  unsigned int __refresh_delay;
66  unsigned int __loop_cnt;
67  Glib::Dispatcher __dispatcher;
68 
69  bool __save_imgs;
70  std::string __save_path;
71  Glib::ustring __save_type;
72  unsigned int __save_num;
73  };
74 
75  public:
76  ImageWidget(unsigned int width, unsigned int height);
77  ImageWidget(Camera *cam, unsigned int refresh_delay = 0, unsigned int width = 0, unsigned int height = 0);
78  ImageWidget(BaseObjectType* cobject, Glib::RefPtr<Gtk::Builder> builder);
79 #ifdef HAVE_GLADEMM
80  ImageWidget(BaseObjectType* cobject, Glib::RefPtr<Gnome::Glade::Xml> refxml);
81 #endif
82  virtual ~ImageWidget();
83 
84  void set_camera(Camera *cam, unsigned int refresh_delay = 0);
85  void enable_camera(bool enable);
86  void set_size(unsigned int width, unsigned int height);
87  virtual bool show(colorspace_t colorspace, unsigned char *buffer, unsigned int width = 0, unsigned int height = 0);
88  void set_refresh_delay(unsigned int refresh_delay);
89  void refresh_cam();
90  unsigned int get_width() const;
91  unsigned int get_height() const;
92  Glib::RefPtr<Gdk::Pixbuf> get_buffer() const;
93  void set_rgb(unsigned int x, unsigned int y, unsigned char r, unsigned char g, unsigned char b);
94  void set_rgb(unsigned int x, unsigned int y, RGB_t rgb);
95  bool save_image(std::string filename, Glib::ustring type) const throw();
96  void save_on_refresh_cam(bool enabled, std::string path = "", Glib::ustring type = "", unsigned int img_num = 0);
97  unsigned int get_image_num();
98  sigc::signal<void, colorspace_t, unsigned char *, unsigned int, unsigned int> & signal_show();
99 
100  private:
101  void set_cam();
102 
103  unsigned int __width;
104  unsigned int __height;
105 
106  Glib::RefPtr<Gdk::Pixbuf> __pixbuf;
107 
108  RefThread *__refresh_thread;
109  Camera *__cam;
110  fawkes::Mutex *__cam_mutex;
111  bool __cam_has_buffer;
112  bool __cam_has_timestamp;
113  bool __cam_enabled;
114 
115  sigc::signal<void, colorspace_t, unsigned char *, unsigned int, unsigned int> __signal_show;
116 };
117 
118 } // end namespace firevision
119 
120 #endif /* __FIREVISION_FVWIDGETS_IMAGE_WIDGET_H_ */
This class is an image container to display fawkes cameras (or image buffers) inside a Gtk::Container...
Definition: image_widget.h:45
Structure defining an RGB pixel (in R-G-B byte ordering).
Definition: rgb.h:44
Camera interface for image aquiring devices in FireVision.
Definition: camera.h:35
Fawkes library namespace.
Thread class encapsulation of pthreads.
Definition: thread.h:42
Mutex mutual exclusion lock.
Definition: mutex.h:32