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 
40 class Camera;
41 
42 class ImageWidget : public Gtk::Image
43 {
44 private:
45  class RefThread : public fawkes::Thread
46  {
47  public:
48  RefThread(ImageWidget *widget, unsigned int refresh_delay);
49  void set_delay(unsigned int refresh_delay);
50  void save_on_refresh(bool enabled,
51  std::string path = "",
52  Glib::ustring type = "",
53  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,
78  unsigned int refresh_delay = 0,
79  unsigned int width = 0,
80  unsigned int height = 0);
81  ImageWidget(BaseObjectType *cobject, Glib::RefPtr<Gtk::Builder> builder);
82 #ifdef HAVE_GLADEMM
83  ImageWidget(BaseObjectType *cobject, Glib::RefPtr<Gnome::Glade::Xml> refxml);
84 #endif
85  virtual ~ImageWidget();
86 
87  void set_camera(Camera *cam, unsigned int refresh_delay = 0);
88  void enable_camera(bool enable);
89  void set_size(unsigned int width, unsigned int height);
90  virtual bool show(colorspace_t colorspace,
91  unsigned char *buffer,
92  unsigned int width = 0,
93  unsigned int height = 0);
94  void set_refresh_delay(unsigned int refresh_delay);
95  void refresh_cam();
96  unsigned int get_width() const;
97  unsigned int get_height() const;
98  Glib::RefPtr<Gdk::Pixbuf> get_buffer() const;
99  void set_rgb(unsigned int x, unsigned int y, unsigned char r, unsigned char g, unsigned char b);
100  void set_rgb(unsigned int x, unsigned int y, RGB_t rgb);
101  bool save_image(std::string filename, Glib::ustring type) const throw();
102  void save_on_refresh_cam(bool enabled,
103  std::string path = "",
104  Glib::ustring type = "",
105  unsigned int img_num = 0);
106  unsigned int get_image_num();
107  sigc::signal<void, colorspace_t, unsigned char *, unsigned int, unsigned int> &signal_show();
108 
109 private:
110  void set_cam();
111 
112  unsigned int width_;
113  unsigned int height_;
114 
115  Glib::RefPtr<Gdk::Pixbuf> pixbuf_;
116 
117  RefThread * refresh_thread_;
118  Camera * cam_;
119  fawkes::Mutex *cam_mutex_;
120  bool cam_has_buffer_;
121  bool cam_has_timestamp_;
122  bool cam_enabled_;
123 
124  sigc::signal<void, colorspace_t, unsigned char *, unsigned int, unsigned int> signal_show_;
125 };
126 
127 } // end namespace firevision
128 
129 #endif /* FIREVISION_FVWIDGETS_IMAGE_WIDGET_H__ */
firevision::ImageWidget::ImageWidget
ImageWidget(unsigned int width, unsigned int height)
Creates a new ImageWidget with predefined width and height.
Definition: image_widget.cpp:47
firevision::ImageWidget::save_on_refresh_cam
void save_on_refresh_cam(bool enabled, std::string path="", Glib::ustring type="", unsigned int img_num=0)
Saves the content of the image on every refresh.
Definition: image_widget.cpp:460
firevision::ImageWidget::set_camera
void set_camera(Camera *cam, unsigned int refresh_delay=0)
Set the camera from which the ImageWidget obtains the images.
Definition: image_widget.cpp:160
fawkes::Mutex
Mutex mutual exclusion lock.
Definition: mutex.h:33
firevision::ImageWidget::refresh_cam
void refresh_cam()
Performs a refresh during the next loop of the refresh thread.
Definition: image_widget.cpp:395
firevision::ImageWidget::get_image_num
unsigned int get_image_num()
Returns the latest image number.
Definition: image_widget.cpp:473
firevision::ImageWidget::~ImageWidget
virtual ~ImageWidget()
Destructor.
Definition: image_widget.cpp:143
firevision::RGB_t
Structure defining an RGB pixel (in R-G-B byte ordering).
Definition: rgb.h:62
firevision::ImageWidget::get_width
unsigned int get_width() const
Returns the image buffer width.
Definition: image_widget.cpp:247
firevision::ImageWidget::enable_camera
void enable_camera(bool enable)
En-/disable the camera.
Definition: image_widget.cpp:193
firevision::ImageWidget
This class is an image container to display fawkes cameras (or image buffers) inside a Gtk::Container...
Definition: image_widget.h:43
firevision::ImageWidget::save_image
bool save_image(std::string filename, Glib::ustring type) const
Saves the current content of the Image.
Definition: image_widget.cpp:435
firevision::ImageWidget::set_size
void set_size(unsigned int width, unsigned int height)
Sets the size of the ImageWidget.
Definition: image_widget.cpp:215
firevision::ImageWidget::show
virtual bool show(colorspace_t colorspace, unsigned char *buffer, unsigned int width=0, unsigned int height=0)
Show image from given colorspace.
Definition: image_widget.cpp:324
fawkes
Fawkes library namespace.
firevision::ImageWidget::set_refresh_delay
void set_refresh_delay(unsigned int refresh_delay)
Sets the refresh delay for automatic camera refreshes.
Definition: image_widget.cpp:386
firevision::ImageWidget::get_height
unsigned int get_height() const
Returns the image buffer height.
Definition: image_widget.cpp:257
firevision::ImageWidget::set_rgb
void set_rgb(unsigned int x, unsigned int y, unsigned char r, unsigned char g, unsigned char b)
Sets a pixel to the given RGB colors.
Definition: image_widget.cpp:282
firevision::ImageWidget::signal_show
sigc::signal< void, colorspace_t, unsigned char *, unsigned int, unsigned int > & signal_show()
Signal emits after a new buffer gets successfully shown (see.
Definition: image_widget.cpp:375
firevision::ImageWidget::get_buffer
Glib::RefPtr< Gdk::Pixbuf > get_buffer() const
Returns the widgets pixel buffer (RGB!)
Definition: image_widget.cpp:267
fawkes::Thread
Thread class encapsulation of pthreads.
Definition: thread.h:46
firevision::Camera
Camera interface for image aquiring devices in FireVision.
Definition: camera.h:33