Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
shm_image.h
1 
2 /***************************************************************************
3  * shm_image.h - shared memory image buffer
4  *
5  * Created: Thu Jan 12 13:12:24 2006
6  * Copyright 2005-2009 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __FIREVISION_FVUTILS_IPC_SHM_IMAGE_H_
25 #define __FIREVISION_FVUTILS_IPC_SHM_IMAGE_H_
26 
27 #include <utils/ipc/shm.h>
28 #include <utils/ipc/shm_lister.h>
29 #include <utils/time/time.h>
30 
31 #include <fvutils/ipc/defs.h>
32 #include <fvutils/color/colorspaces.h>
33 
34 
35 // Magic token to identify FireVision shared memory images
36 #define FIREVISION_SHM_IMAGE_MAGIC_TOKEN "FireVision Image"
37 
38 namespace firevision {
39 #if 0 /* just to make Emacs auto-indent happy */
40 }
41 #endif
42 
43 // Not that there is a relation to ITPimage_packet_header_t
44 /** Shared memory header struct for FireVision images. */
45 typedef struct {
46  char image_id[IMAGE_ID_MAX_LENGTH];/**< image ID */
47  char frame_id[FRAME_ID_MAX_LENGTH];/**< coordinate frame ID */
48  unsigned int colorspace; /**< color space */
49  unsigned int width; /**< width */
50  unsigned int height; /**< height */
51  unsigned int roi_x; /**< ROI start x */
52  unsigned int roi_y; /**< ROI start y */
53  unsigned int roi_width; /**< ROI width */
54  unsigned int roi_height; /**< ROI height */
55  // Circle relative to ROI
56  int circle_x; /**< ROI circle center x */
57  int circle_y; /**< ROI circle center y */
58  unsigned int circle_radius; /**< ROI circle radius */
59  long int capture_time_sec; /**< Time in seconds since the epoch when
60  * the image was captured. */
61  long int capture_time_usec; /**< Addendum to capture_time_sec in
62  * micro seconds. */
63  unsigned int flag_circle_found : 1; /**< 1 if circle found */
64  unsigned int flag_image_ready : 1; /**< 1 if image ready */
65  unsigned int flag_reserved : 30; /**< reserved for future use */
67 
70 {
71  public:
73  SharedMemoryImageBufferHeader(const char *image_id,
74  colorspace_t colorspace,
75  unsigned int width,
76  unsigned int height);
79 
80  virtual fawkes::SharedMemoryHeader * clone() const;
81  virtual bool matches(void *memptr);
82  virtual size_t size();
83  virtual void print_info();
84  virtual bool create();
85  virtual void initialize(void *memptr);
86  virtual void set(void *memptr);
87  virtual void reset();
88  virtual size_t data_size();
89  virtual bool operator==(const fawkes::SharedMemoryHeader &s) const;
90 
91  void set_image_id(const char *image_id);
92  void set_frame_id(const char *frame_id);
93  colorspace_t colorspace() const;
94  unsigned int width() const;
95  unsigned int height() const;
96  const char * image_id() const;
97  const char * frame_id() const;
98 
99  SharedMemoryImageBuffer_header_t * raw_header();
100 
101  private:
102  char *_image_id;
103  char *_frame_id;
104  colorspace_t _colorspace;
105  unsigned int _width;
106  unsigned int _height;
107 
108  char *_orig_image_id;
109  char *_orig_frame_id;
110  colorspace_t _orig_colorspace;
111  unsigned int _orig_width;
112  unsigned int _orig_height;
113 
115 };
116 
119 {
120  public:
123 
124  virtual void print_header();
125  virtual void print_footer();
126  virtual void print_no_segments();
127  virtual void print_no_orphaned_segments();
128  virtual void print_info(const fawkes::SharedMemoryHeader *header,
129  int shm_id, int semaphore,
130  unsigned int mem_size,
131  const void *memptr);
132 };
133 
134 
136 {
137 
138  public:
139  SharedMemoryImageBuffer(const char *image_id,
140  colorspace_t cspace,
141  unsigned int width, unsigned int height);
142  SharedMemoryImageBuffer(const char *image_id, bool is_read_only = true);
144 
145  const char * image_id() const;
146  const char * frame_id() const;
147  unsigned char * buffer() const;
148  colorspace_t colorspace() const;
149  unsigned int width() const;
150  unsigned int height() const;
151  unsigned int roi_x() const;
152  unsigned int roi_y() const;
153  unsigned int roi_width() const;
154  unsigned int roi_height() const;
155  int circle_x() const;
156  int circle_y() const;
157  unsigned int circle_radius() const;
158  bool circle_found() const;
159  void set_roi_x(unsigned int roi_x);
160  void set_roi_y(unsigned int roi_y);
161  void set_roi_width(unsigned int roi_w);
162  void set_roi_height(unsigned int roi_h);
163  void set_roi(unsigned int roi_x, unsigned int roi_y,
164  unsigned int roi_w, unsigned int roi_h);
165  void set_circle_x(int circle_x);
166  void set_circle_y(int circle_y);
167  void set_circle_radius(unsigned int circle_radius);
168  void set_circle(int x, int y, unsigned int r);
169  void set_circle_found(bool found);
170  bool set_image_id(const char *image_id);
171  void set_frame_id(const char *frame_id);
172 
173  fawkes::Time capture_time() const;
174  void capture_time(long int *sec, long int *usec) const;
175  void set_capture_time(fawkes::Time *time);
176  void set_capture_time(long int sec, long int usec);
177 
178  static void list();
179  static void cleanup(bool use_lister = true);
180  static bool exists(const char *image_id);
181  static void wipe(const char *image_id);
182 
183  private:
184  void constructor(const char *image_id, colorspace_t cspace,
185  unsigned int width, unsigned int height,
186  bool is_read_only);
187 
188  SharedMemoryImageBufferHeader *priv_header;
190 
191  char * _image_id;
192  colorspace_t _colorspace;
193  unsigned int _width;
194  unsigned int _height;
195 
196 
197 };
198 
199 
200 } // end namespace firevision
201 
202 #endif
long int capture_time_sec
Time in seconds since the epoch when the image was captured.
Definition: shm_image.h:59
Shared memory image buffer header.
Definition: shm_image.h:68
unsigned int circle_radius
ROI circle radius.
Definition: shm_image.h:58
long int capture_time_usec
Addendum to capture_time_sec in micro seconds.
Definition: shm_image.h:61
A class for handling time.
Definition: time.h:91
unsigned int roi_height
ROI height.
Definition: shm_image.h:54
Shared memory header struct for FireVision images.
Definition: shm_image.h:45
unsigned int colorspace
color space
Definition: shm_image.h:48
Shared memory image buffer.
Definition: shm_image.h:135
Format list output for shared memory segments.
Definition: shm_lister.h:38
Shared memory segment.
Definition: shm.h:49
Shared memory image buffer lister.
Definition: shm_image.h:117
Interface for shared memory header.
Definition: shm.h:33