Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * shm_image.h - shared memory image buffer 00004 * 00005 * Created: Thu Jan 12 13:12:24 2006 00006 * Copyright 2005-2009 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #ifndef __FIREVISION_FVUTILS_IPC_SHM_IMAGE_H_ 00025 #define __FIREVISION_FVUTILS_IPC_SHM_IMAGE_H_ 00026 00027 #include <utils/ipc/shm.h> 00028 #include <utils/ipc/shm_lister.h> 00029 #include <utils/time/time.h> 00030 00031 #include <fvutils/ipc/defs.h> 00032 #include <fvutils/color/colorspaces.h> 00033 00034 00035 // Magic token to identify FireVision shared memory images 00036 #define FIREVISION_SHM_IMAGE_MAGIC_TOKEN "FireVision Image" 00037 00038 namespace firevision { 00039 #if 0 /* just to make Emacs auto-indent happy */ 00040 } 00041 #endif 00042 00043 // Not that there is a relation to ITPimage_packet_header_t 00044 /** Shared memory header struct for FireVision images. */ 00045 typedef struct { 00046 char image_id[IMAGE_ID_MAX_LENGTH];/**< image ID */ 00047 char frame_id[FRAME_ID_MAX_LENGTH];/**< coordinate frame ID */ 00048 unsigned int colorspace; /**< color space */ 00049 unsigned int width; /**< width */ 00050 unsigned int height; /**< height */ 00051 unsigned int roi_x; /**< ROI start x */ 00052 unsigned int roi_y; /**< ROI start y */ 00053 unsigned int roi_width; /**< ROI width */ 00054 unsigned int roi_height; /**< ROI height */ 00055 // Circle relative to ROI 00056 int circle_x; /**< ROI circle center x */ 00057 int circle_y; /**< ROI circle center y */ 00058 unsigned int circle_radius; /**< ROI circle radius */ 00059 long int capture_time_sec; /**< Time in seconds since the epoch when 00060 * the image was captured. */ 00061 long int capture_time_usec; /**< Addendum to capture_time_sec in 00062 * micro seconds. */ 00063 unsigned int flag_circle_found : 1; /**< 1 if circle found */ 00064 unsigned int flag_image_ready : 1; /**< 1 if image ready */ 00065 unsigned int flag_reserved : 30; /**< reserved for future use */ 00066 } SharedMemoryImageBuffer_header_t; 00067 00068 class SharedMemoryImageBufferHeader 00069 : public fawkes::SharedMemoryHeader 00070 { 00071 public: 00072 SharedMemoryImageBufferHeader(); 00073 SharedMemoryImageBufferHeader(const char *image_id, 00074 colorspace_t colorspace, 00075 unsigned int width, 00076 unsigned int height); 00077 SharedMemoryImageBufferHeader(const SharedMemoryImageBufferHeader *h); 00078 virtual ~SharedMemoryImageBufferHeader(); 00079 00080 virtual fawkes::SharedMemoryHeader * clone() const; 00081 virtual bool matches(void *memptr); 00082 virtual size_t size(); 00083 virtual void print_info(); 00084 virtual bool create(); 00085 virtual void initialize(void *memptr); 00086 virtual void set(void *memptr); 00087 virtual void reset(); 00088 virtual size_t data_size(); 00089 virtual bool operator==(const fawkes::SharedMemoryHeader &s) const; 00090 00091 void set_image_id(const char *image_id); 00092 void set_frame_id(const char *frame_id); 00093 colorspace_t colorspace() const; 00094 unsigned int width() const; 00095 unsigned int height() const; 00096 const char * image_id() const; 00097 const char * frame_id() const; 00098 00099 SharedMemoryImageBuffer_header_t * raw_header(); 00100 00101 private: 00102 char *_image_id; 00103 char *_frame_id; 00104 colorspace_t _colorspace; 00105 unsigned int _width; 00106 unsigned int _height; 00107 00108 char *_orig_image_id; 00109 char *_orig_frame_id; 00110 colorspace_t _orig_colorspace; 00111 unsigned int _orig_width; 00112 unsigned int _orig_height; 00113 00114 SharedMemoryImageBuffer_header_t *_header; 00115 }; 00116 00117 class SharedMemoryImageBufferLister 00118 : public fawkes::SharedMemoryLister 00119 { 00120 public: 00121 SharedMemoryImageBufferLister(); 00122 virtual ~SharedMemoryImageBufferLister(); 00123 00124 virtual void print_header(); 00125 virtual void print_footer(); 00126 virtual void print_no_segments(); 00127 virtual void print_no_orphaned_segments(); 00128 virtual void print_info(const fawkes::SharedMemoryHeader *header, 00129 int shm_id, int semaphore, 00130 unsigned int mem_size, 00131 const void *memptr); 00132 }; 00133 00134 00135 class SharedMemoryImageBuffer : public fawkes::SharedMemory 00136 { 00137 00138 public: 00139 SharedMemoryImageBuffer(const char *image_id, 00140 colorspace_t cspace, 00141 unsigned int width, unsigned int height); 00142 SharedMemoryImageBuffer(const char *image_id, bool is_read_only = true); 00143 ~SharedMemoryImageBuffer(); 00144 00145 const char * image_id() const; 00146 const char * frame_id() const; 00147 unsigned char * buffer() const; 00148 colorspace_t colorspace() const; 00149 unsigned int width() const; 00150 unsigned int height() const; 00151 unsigned int roi_x() const; 00152 unsigned int roi_y() const; 00153 unsigned int roi_width() const; 00154 unsigned int roi_height() const; 00155 int circle_x() const; 00156 int circle_y() const; 00157 unsigned int circle_radius() const; 00158 bool circle_found() const; 00159 void set_roi_x(unsigned int roi_x); 00160 void set_roi_y(unsigned int roi_y); 00161 void set_roi_width(unsigned int roi_w); 00162 void set_roi_height(unsigned int roi_h); 00163 void set_roi(unsigned int roi_x, unsigned int roi_y, 00164 unsigned int roi_w, unsigned int roi_h); 00165 void set_circle_x(int circle_x); 00166 void set_circle_y(int circle_y); 00167 void set_circle_radius(unsigned int circle_radius); 00168 void set_circle(int x, int y, unsigned int r); 00169 void set_circle_found(bool found); 00170 bool set_image_id(const char *image_id); 00171 void set_frame_id(const char *frame_id); 00172 00173 fawkes::Time capture_time() const; 00174 void capture_time(long int *sec, long int *usec) const; 00175 void set_capture_time(fawkes::Time *time); 00176 void set_capture_time(long int sec, long int usec); 00177 00178 static void list(); 00179 static void cleanup(bool use_lister = true); 00180 static bool exists(const char *image_id); 00181 static void wipe(const char *image_id); 00182 00183 private: 00184 void constructor(const char *image_id, colorspace_t cspace, 00185 unsigned int width, unsigned int height, 00186 bool is_read_only); 00187 00188 SharedMemoryImageBufferHeader *priv_header; 00189 SharedMemoryImageBuffer_header_t *raw_header; 00190 00191 char * _image_id; 00192 colorspace_t _colorspace; 00193 unsigned int _width; 00194 unsigned int _height; 00195 00196 00197 }; 00198 00199 00200 } // end namespace firevision 00201 00202 #endif