Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

mxcpc_namespace.h

00001 //           ///          //                                        Mx clientSDK
00002 //          /////        ////                    Mx Crossplatform Client Library
00003 //         /// XXX     XXX ///
00004 //        ///    XXX XXX    ///     $RCSfile: mxcpc_namespace.h,v $
00005 //       ///       XXX       ///     $Revision: 1.8 $
00006 //      ///      XXX XXX      ///     $Date: 2006/01/13 13:53:08 $
00007 //     ////    XXX     XXX    ////     $Author: cvs-kai $
00008 //    ////                     ////
00009 //   ////  M  O  B  O  T  I  X  ////////////////////////////////////////////////
00010 //  //// Security Vision Systems //////////////////////////////////////////////
00011 //                                                                          //
00012 //  Copyright (C) 2005 - 2006, MOBOTIX AG, Germany                         //
00013 //  This software is made available under the BSD licence. Please refer   //
00014 //  to the file LICENCE.TXT contained in this distribution for details.  //
00015 //                                                                      //
00016 //  /////////////////////////////////////////////////////////////////////
00017 
00018 
00019 
00020 #ifndef __MXCPC_NAMESPACE_H__
00021 #define __MXCPC_NAMESPACE_H__
00022 
00023 
00024 
00025 class mxcpcStatusMessageHandler;
00026 
00027 
00028 
00029 //! Namespace holding type definition stuff and general basic methods for the
00030 //! <tt>mxcpc</tt> library.
00031 /*!
00032  *  \ingroup mxcpc_core
00033  */
00034 namespace mxcpc {
00035 
00036   typedef unsigned char  u8;
00037   typedef short         s16;
00038   typedef unsigned int  u32;
00039   
00040   extern mxcpcStatusMessageHandler *StatusMessageHandler;
00041   
00042   //! Base64 encode table, see RFC1113
00043   extern const char *Base64EncodeTable;
00044   
00045   //! Central definition of presets for camera framerate settings
00046   extern int FrameRatePresetNum;
00047   extern char *FrameRatePresetNames[];
00048   extern float FrameRatePresets[];
00049   
00050   //! Returns the mxcpc library's version string.
00051   const char *getVersionString(void); 
00052   
00053   //! Does the obvious thing.
00054   inline void clamp_s16(s16 *numba, s16 min, s16 max) {
00055     if(*numba < min) *numba = min;
00056     if(*numba > max) *numba = max;
00057   }
00058   //! Does the obvious thing.
00059   inline void clamp_int(int *numba, int min, int max) {
00060     if(*numba < min) *numba = min;
00061     if(*numba > max) *numba = max;
00062   }
00063 
00064   //! Endian conversion.
00065   inline void convert_endian_u32(mxcpc::u32 *numba_ptr) {
00066     mxcpc::u32 source_val;
00067     mxcpc::u8 *source_byte_ptr,
00068               *target_byte_ptr;
00069     
00070     source_val = *numba_ptr;
00071     source_byte_ptr = (mxcpc::u8 *)&source_val;
00072     target_byte_ptr = (mxcpc::u8 *)numba_ptr;
00073     
00074     target_byte_ptr[0] = source_byte_ptr[3];
00075     target_byte_ptr[1] = source_byte_ptr[2];
00076     target_byte_ptr[2] = source_byte_ptr[1];
00077     target_byte_ptr[3] = source_byte_ptr[0];
00078   }
00079 
00080   // Colorspace conversion from RGB to YUV.
00081   inline void convert_RGB_to_YUV(mxcpc::u8  r, mxcpc::u8  g, mxcpc::u8  b,
00082                                  mxcpc::u8 *y, mxcpc::u8 *u, mxcpc::u8 *v) {
00083 
00084     int int_r, int_g, int_b;
00085     int int_y, int_u, int_v;
00086                             
00087     int_r = (int)r;
00088     int_g = (int)g;
00089     int_b = (int)b;
00090     
00091     // coefficients computed from "Video Demystified" by K. JACK...
00092     int_y = (( 263*int_r + 516*int_g + 100*int_b) >> 10)   +    16;
00093     int_u = ((-152*int_r - 298*int_g + 450*int_b) >> 10)   +   128;
00094     int_v = (( 450*int_r - 377*int_g -  73*int_b) >> 10)   +   128;
00095     
00096     mxcpc::clamp_int(&int_y, 0, 255);
00097     mxcpc::clamp_int(&int_u, 0, 255);
00098     mxcpc::clamp_int(&int_v, 0, 255);
00099     
00100     *y = (mxcpc::u8)int_y;
00101     *u = (mxcpc::u8)int_u;
00102     *v = (mxcpc::u8)int_v;
00103   }
00104     
00105   // Colorspace conversion from RGB to YCbCr honoring ITU-R BT.601
00106   inline void convert_RGB_to_YCbCr(mxcpc::u8  r, mxcpc::u8   g, mxcpc::u8   b,
00107                                    mxcpc::u8 *y, mxcpc::u8 *Cb, mxcpc::u8 *Cr) {
00108 
00109     int int_r, int_g,  int_b;
00110     int int_y, int_Cb, int_Cr;
00111                             
00112     int_r = (int)r;
00113     int_g = (int)g;
00114     int_b = (int)b;
00115     
00116     // coefficients computed from ITU-R BT.601...
00117     int_y  = (( 306*int_r + 601*int_g + 117*int_b) >> 10);
00118     int_Cb = ((-173*int_r - 339*int_g + 512*int_b) >> 10)   +   128;
00119     int_Cr = (( 512*int_r - 429*int_g -  83*int_b) >> 10)   +   128;
00120     
00121     mxcpc::clamp_int(&int_y,  0, 255);
00122     mxcpc::clamp_int(&int_Cb, 0, 255);
00123     mxcpc::clamp_int(&int_Cr, 0, 255);
00124     
00125     *y  = (mxcpc::u8)int_y;
00126     *Cb = (mxcpc::u8)int_Cb;
00127     *Cr = (mxcpc::u8)int_Cr;
00128   }
00129   
00130   //! Encodes 3-byte block of binary input as 4-byte block of base64 characters.
00131   void encode_base64_block(unsigned char in[3], 
00132                            unsigned char out[4], 
00133                            int len);
00134   //! Encodes the given number of binary input bytes as a base64 character 
00135   //! string. 
00136   void encode_base64(unsigned char *data, int byte_num, 
00137                      unsigned char *target_buffer);   
00138   
00139   //! Used from within the <tt>mxcpc</tt> library to emit status messages.
00140   /*!
00141    *  That way, there is a central place that can be tweaked in order to change
00142    *  outputting of status messages.
00143    */ 
00144   void sendStatusMsg(const char *txt, void *class_ptr = 0);
00145   //! Registers the specified status message handler with <tt>mxcpc</tt>'s 
00146   //! central status messaging facility.
00147   /*!
00148    *  The <tt>mxcpc</tt> library assumes ownership over the specified handler
00149    *  object. Any potential previously installed message handler is discarded
00150    *  properly.
00151    *
00152    *  Passing <tt>0</tt> to the method will properly discard a previously 
00153    *  installed custom status message handler and revert to default status
00154    *  notification - which is sending all messages to <tt>stdout</tt>.
00155    *  Note that when shutting down, an <tt>mxcpc</tt> application should
00156    *  do exactly this to properly free the registered status message handler and
00157    *  the associated resources - if it had one installed in the first place.
00158    *
00159    *  Note that when using <tt>mxcpc</tt> functionality from different threads,
00160    *  any potentially installed custom status message handler must arrange for
00161    *  proper synchronization.
00162    */
00163   void setStatusMessageHandler(mxcpcStatusMessageHandler *handler);
00164 };
00165 
00166 
00167 
00168 #endif   // __MXCPC_NAMESPACE_H__
00169 

Generated on Mon Jan 30 15:52:41 2006 for mxcpc by  doxygen 1.4.4