shm_image.h

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   unsigned int  colorspace;             /**< color space */
00048   unsigned int  width;                  /**< width */
00049   unsigned int  height;                 /**< height */
00050   unsigned int  roi_x;                  /**< ROI start x */
00051   unsigned int  roi_y;                  /**< ROI start y */
00052   unsigned int  roi_width;              /**< ROI width */
00053   unsigned int  roi_height;             /**< ROI height */
00054   // Circle relative to ROI
00055   int           circle_x;               /**< ROI circle center x */
00056   int           circle_y;               /**< ROI circle center y */
00057   unsigned int  circle_radius;          /**< ROI circle radius */
00058   long int      capture_time_sec;       /**< Time in seconds since the epoch when
00059                                          * the image was captured. */
00060   long int      capture_time_usec;      /**< Addendum to capture_time_sec in
00061                                          * micro seconds. */
00062   unsigned int  flag_circle_found :  1; /**< 1 if circle found */
00063   unsigned int  flag_image_ready  :  1; /**< 1 if image ready */
00064   unsigned int  flag_reserved     : 30; /**< reserved for future use */
00065 } SharedMemoryImageBuffer_header_t;
00066 
00067 class SharedMemoryImageBufferHeader
00068 : public fawkes::SharedMemoryHeader
00069 {
00070  public:
00071   SharedMemoryImageBufferHeader();
00072   SharedMemoryImageBufferHeader(const char *image_id,
00073                                 colorspace_t colorspace,
00074                                 unsigned int width,
00075                                 unsigned int height);
00076   SharedMemoryImageBufferHeader(const SharedMemoryImageBufferHeader *h);
00077   virtual ~SharedMemoryImageBufferHeader();
00078 
00079   virtual fawkes::SharedMemoryHeader *  clone() const;
00080   virtual bool         matches(void *memptr);
00081   virtual size_t       size();
00082   virtual void         print_info();
00083   virtual bool         create();
00084   virtual void         initialize(void *memptr);
00085   virtual void         set(void *memptr);
00086   virtual void         reset();
00087   virtual size_t       data_size();
00088   virtual bool         operator==(const fawkes::SharedMemoryHeader &s) const;
00089 
00090   void                 set_image_id(const char *image_id);
00091   colorspace_t         colorspace() const;
00092   unsigned int         width() const;
00093   unsigned int         height() const;
00094   const char *         image_id() const;
00095 
00096   SharedMemoryImageBuffer_header_t * raw_header();
00097 
00098  private:
00099   char          *_image_id;
00100   colorspace_t   _colorspace;
00101   unsigned int   _width;
00102   unsigned int   _height;
00103 
00104   char          *_orig_image_id;
00105   colorspace_t   _orig_colorspace;
00106   unsigned int   _orig_width;
00107   unsigned int   _orig_height;
00108 
00109   SharedMemoryImageBuffer_header_t *_header;
00110 };
00111 
00112 class SharedMemoryImageBufferLister
00113 : public fawkes::SharedMemoryLister
00114 {
00115  public:
00116   SharedMemoryImageBufferLister();
00117   virtual ~SharedMemoryImageBufferLister();
00118 
00119   virtual void print_header();
00120   virtual void print_footer();
00121   virtual void print_no_segments();
00122   virtual void print_no_orphaned_segments();
00123   virtual void print_info(const fawkes::SharedMemoryHeader *header,
00124                           int shm_id, int semaphore,
00125                           unsigned int mem_size,
00126                           const void *memptr);
00127 };
00128 
00129 
00130 class SharedMemoryImageBuffer : public fawkes::SharedMemory
00131 {
00132 
00133  public:
00134   SharedMemoryImageBuffer(const char *image_id,
00135                           colorspace_t cspace,
00136                           unsigned int width, unsigned int height);
00137   SharedMemoryImageBuffer(const char *image_id, bool is_read_only = true);
00138   ~SharedMemoryImageBuffer();
00139 
00140   const char *     image_id() const;
00141   unsigned char *  buffer() const;
00142   colorspace_t     colorspace() const;
00143   unsigned int     width() const;
00144   unsigned int     height() const;
00145   unsigned int     roi_x() const;
00146   unsigned int     roi_y() const;
00147   unsigned int     roi_width() const;
00148   unsigned int     roi_height() const;
00149   int              circle_x() const;
00150   int              circle_y() const;
00151   unsigned int     circle_radius() const;
00152   bool             circle_found() const;
00153   void             set_roi_x(unsigned int roi_x);
00154   void             set_roi_y(unsigned int roi_y);
00155   void             set_roi_width(unsigned int roi_w);
00156   void             set_roi_height(unsigned int roi_h);
00157   void             set_roi(unsigned int roi_x, unsigned int roi_y,
00158                            unsigned int roi_w, unsigned int roi_h);
00159   void             set_circle_x(int circle_x);
00160   void             set_circle_y(int circle_y);
00161   void             set_circle_radius(unsigned int circle_radius);
00162   void             set_circle(int x, int y, unsigned int r);
00163   void             set_circle_found(bool found);
00164   bool             set_image_id(const char *image_id);
00165 
00166   fawkes::Time     capture_time() const;
00167   void             capture_time(long int *sec, long int *usec) const;
00168   void             set_capture_time(fawkes::Time *time);
00169   void             set_capture_time(long int sec, long int usec);
00170 
00171   static void      list();
00172   static void      cleanup(bool use_lister = true);
00173   static bool      exists(const char *image_id);
00174   static void      wipe(const char *image_id);
00175 
00176  private:
00177   void constructor(const char *image_id, colorspace_t cspace,
00178                    unsigned int width, unsigned int height,
00179                    bool is_read_only);
00180 
00181   SharedMemoryImageBufferHeader    *priv_header;
00182   SharedMemoryImageBuffer_header_t *raw_header;
00183 
00184   char *         _image_id;
00185   colorspace_t   _colorspace;
00186   unsigned int   _width;
00187   unsigned int   _height;
00188 
00189 
00190 };
00191 
00192 
00193 } // end namespace firevision
00194 
00195 #endif

Generated on 1 Mar 2011 for Fawkes API by  doxygen 1.6.1