Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages | Examples

vetUtility.cpp

Go to the documentation of this file.
00001 
00019 #include "vetUtility.h"
00020 
00021 #include <stdio.h>
00022 #include "../support/ccvt/ccvt.h"
00023 
00024 
00025 
00030 #include <string.h>
00031 char* vetUtility::getTypeNameFromClassTypeID(int classType_id)
00032  {
00033         char* ret = new char[32];
00034 
00035         switch( classType_id )
00036          {
00037                 case VETCLASS_TYPE_FRAME        : strcpy(ret, "vetFrame");
00038                 case VETCLASS_TYPE_BUFFER       : strcpy(ret, "vetBuffer");
00039                 case VETCLASS_TYPE_INPUT        : strcpy(ret, "vetInput");
00040                 case VETCLASS_TYPE_OUTPUT       : strcpy(ret, "vetOutput");
00041                 case VETCLASS_TYPE_FILTER       : strcpy(ret, "vetFilter");
00042                 case VETCLASS_TYPE_CODEC        : strcpy(ret, "vetCodec");
00043                 case VETCLASS_TYPE_VISION       : strcpy(ret, "vetVision");
00044                 default                                         : strcpy(ret, "UNKNOWN");
00045          }
00046         return ret;
00047  }
00048 
00049 
00054 
00055 /*
00056 void rgb555_rgb(void* src, void* dst, int width,int height)
00057  {
00058 
00059         unsigned int* srcPtr = (unsigned int*)src;
00060 
00061         for (unsigned int i = 0; i < width*height; i++)
00062          {
00063                 *(dst++) = bitcopy_n(srcPtr >> (10 - 3), 3);
00064                 *(dst++) = bitcopy_n(srcPtr >> (5 - 3), 3);
00065                 *(dst++) = bitcopy_n(srcPtr << 3, 3);
00066          }
00067 
00068 
00069  }
00070 
00071 
00072 void vetUtility::conv_420p_rgb96(int width,int height,void* src,void* dst)
00073 {
00074         static unsigned int oldSize = 0;
00075         static unsigned char* rgb;
00076 //static ?
00077 
00078         unsigned int size = width * height;
00079 
00080         // reallocate memory if the sizes have changed
00081         if (oldSize < size) {
00082                 delete [] rgb;
00083                 rgb = new  unsigned char [size * 4];
00084         }
00085 
00086         // set up all the pointers
00087         unsigned char   *s = (unsigned char *)src;
00088         int             *d = (int *)dst;
00089 
00090         static unsigned int offset_U = size;
00091         static unsigned int offset_V = size + size / 4;
00092 
00093         unsigned char*  Y = s;
00094         unsigned char*  U = s + offset_U;
00095         unsigned char*  V = s + offset_V;
00096 
00097         // convert away
00098         ccvt_420p_rgb32(width, height, Y, U, V, rgb);
00099         conv_rgb32_rgb96(width, height, rgb, d);
00100 }
00101 */
00102 
00103 void vetUtility::conv_420p_grey(int width,int height,void *src,void *dst)
00104 {
00105         unsigned char   *s = (unsigned char *)src;
00106         int             *d = (int *)dst;
00107 
00108         unsigned int size = width * height;
00109 
00110         for (unsigned int i = 0; i < size; i++)
00111          *(d++) = *(s++);
00112 }
00113 
00114 
00115 void vetUtility::conv_bgr24_rgb96(void *src, unsigned char *dst, unsigned int width, unsigned int height)
00116 {
00117 //BUG
00118         unsigned char*  s = (unsigned char*)src ;
00119         unsigned char* d = dst + 2 ;
00120 
00121         for (unsigned int i = 0; i < width*height; i++, d+=5)
00122          {
00123                 *(d--) = *(s++);
00124                 *(d--) = *(s++);
00125                 *(d) = *(s++);
00126          }
00127 
00128 }
00129 
00130 /*
00131 void conv_rgb24_rgb96(int width, int height, void *src, unsigned char *d)
00132 {
00133         unsigned char** rows = (unsigned char**) src;
00134         unsigned char*  s;
00135 
00136         for (int j = 0; j < height; j++) {
00137                 s = rows[j];
00138 
00139                 for (int i = 0; i < width; i++) {
00140                         *(d++) = *(s++);
00141                         *(d++) = *(s++);
00142                         *(d++) = *(s++);
00143                 }
00144         }
00145 }
00146 
00147         unsigned char* s = (unsigned char*)src;
00148         unsigned char* d = dst;
00149 
00150         for (unsigned int i = 0; i < width * height; i++) {
00151                 *(d++) = *(s++);
00152                 *(d++) = *(s++);
00153                 *(d++) = *(s++);
00154         }
00155 */
00156 void vetUtility::conv_rgb24_rgb96(void *src, unsigned char *dst, unsigned int width, unsigned int height)
00157 {
00158         unsigned char** rows = (unsigned char**) src;
00159         unsigned char*  s;
00160         unsigned char* d = dst;
00161 
00162         for (unsigned int j = 0; j < height; j++) {
00163                 s = rows[j];
00164 
00165                 for (unsigned int i = 0; i < width; i++) {
00166                         *(d++) = *(s++);
00167                         *(d++) = *(s++);
00168                         *(d++) = *(s++);
00169                 }
00170         }
00171 }
00172 
00173 void vetUtility::conv_rgb24_rgb96_(void *src, int *dst, unsigned int width, unsigned int height)
00174 {
00175         unsigned char** rows = (unsigned char**) src;
00176         unsigned char*  s;
00177         int* d = dst;
00178 
00179         for (unsigned int j = 0; j < height; j++) {
00180                 s = rows[j];
00181 
00182                 for (unsigned int i = 0; i < width; i++) {
00183                         *(d++) = *(s++);
00184                         *(d++) = *(s++);
00185                         *(d++) = *(s++);
00186                 }
00187         }
00188 }
00189 
00190 void vetUtility::conv_rgb32_rgb96(int width,int height,void *src,void *dst)
00191 {
00192         unsigned char   *s = (unsigned char *)src;
00193         int             *d = (int *)dst;
00194 
00195         unsigned int size = width * height;
00196 
00197         for (unsigned int i = 0; i < size; i++, s++) {
00198                 *(d++) = *(s++);
00199                 *(d++) = *(s++);
00200                 *(d++) = *(s++);
00201         }
00202 }
00203 
00204 
00205 
00206 
00207 
00208 
00209 
00210 /* Functions in ccvt_i386.S/ccvt_c.c */
00211 /* 4:2:0 YUV interlaced to RGB 24bit */
00212 /*
00213 VETRESULT vetUtility::conv_420i_rgb24( void* dataIn, vetFrameRGB24& img)
00214  {
00215         if ( &img == NULL || dataIn == NULL || img.width == 0 || img.height == 0 )
00216                 return VETRET_PARAM_ERR;
00217 
00218         ccvt_420i_rgb24(img.width, img.height, dataIn, (unsigned char*)img.data[0] );
00219 
00220         return VETRET_OK;
00221  }
00222 */
00223 /* Functions in ccvt_i386.S/ccvt_c.c */
00224 /* RGB to 4:2:0 YUV planar     */
00225 /*
00226 VETRESULT vetUtility::conv_rgb24_420p(vetFrameRGB24& img, void *dsty, void *dstu, void *dstv)
00227  {
00228         if ( &img == NULL || dsty == NULL || dstu == NULL ||  dstv == NULL || img.width == 0 || img.height == 0 )
00229                 return VETRET_PARAM_ERR;
00230 
00231         ccvt_rgb24_420p(img.width, img.height, (unsigned char*)img.data[0], dsty, dstu, dstv);
00232 
00233         return VETRET_OK;
00234  }
00235 */
00236 
00237 
00244 
00251 /*
00252 European TV (PAL and SECAM coded) uses Y'U'V' components. Y' is similar to
00253 perceived luminance, U' and V' carry the colour information and some
00254 luminance information and are bipolar (they go negative as well as positive).
00255 The symbols U and V here are not related to the U and V of CIE YUV (1960).
00256 
00257 This coding is also used in some 525 line systems with PAL subcarriers,
00258 particularly in parts of the Americas. The specification here is that of the
00259 European Broadcasting Union (EBU). Y' has a bandwidth of 5 MHz in Europe,
00260 5.5 MHz in UK. The U' and V' signals usually have up to 2.5 MHz bandwidth
00261 in a component studio system, but can be as little as 600 kHz or less in a
00262 VHS recorder. U' and V' always have the same bandwidth as each other. The
00263 CRT gamma law is assumed to be 2.8, but camera correction laws are the same
00264 as in all other systems (approximately 0.45). The system white point is D65,
00265 the chromaticity coordinates are:
00266 
00267     R:      xr=0.64      yr=0.33
00268     G:      xg=0.29      yg=0.60
00269     B:      xb=0.15      yb=0.06
00270     White:  xn=0.312713  yn=0.329016
00271 
00272 The conversion equations for linear signals are:-
00273 */
00274 double cvm_rgb_yuv[] =  {
00275                                                         0.431, 0.342, 0.178,
00276                                                         0.222, 0.707, 0.071,
00277                                                         0.020, 0.130, 0.939
00278                                                 };
00279 double cvm_yuv_rgb[] =  {
00280                                                          3.063, -1.393, -0.476,
00281                                                         -0.969,  1.876,  0.042,
00282                                                          0.068, -0.229,  1.069
00283                                                 };
00284 
00285 
00286 
00287 template<class T, class S>
00288 VETRESULT vetUtility::conv_rgb_yuv(T* out, S* in, unsigned int width, unsigned int height)
00289  {
00290         return conv_linear(out, in, cvm_yuv_rgb, width, height);
00291  }
00292 
00293 
00294 template<class T, class S>
00295 VETRESULT vetUtility::conv_yuv_rgb(T* out, S* in, unsigned int width, unsigned int height)
00296  {
00297         return conv_linear(out, in, cvm_rgb_yuv, width, height);
00298  }
00299 
00300 
00302 /*
00303 The YIQ system is the color primary system adopted by National Television System Committee (NTSC) for color TV broadcasting. The YIQ color solid is made by a linear transformation of the RGB cube. Its purpose is to exploit certain characteristics of the human eye to maximize the utilization of a fixed bandwidth. The human visual system is more sensitive to changes in luminance than to changes in hue or saturation, and thus a wider bandwidth should be dedicated to luminance than to color information. Y is similar to perceived luminance, I and Q carry color information and some luminance information. The Y signal usually has 4.2 MHz bandwidth in a 525 line system. Originally, the I and Q had different bandwidths (1.5 and 0.6 MHz), but now they commonly have the same bandwidth of 1 MHz.
00304 
00305 */
00306 double cvm_rgb_yiq[] =  {
00307                                                         0.299,  0.587,  0.114,
00308                                                         0.596, -0.275, -0.321,
00309                                                         0.212, -0.523,  0.311
00310                                                 };
00311 double cvm_yiq_rgb[] =  {
00312                                                         1,  0.956,  0.621,
00313                                                         1, -0.272, -0.647,
00314                                                         1, -1.105,  1.702
00315                                                 };
00316 
00317 
00318 template<class T, class S>
00319 VETRESULT vetUtility::conv_rgb_yiq(T* out, S* in, unsigned int width, unsigned int height)
00320  {
00321         return conv_linear(out, in, cvm_rgb_yiq, width, height);
00322  }
00323 
00324 
00325 template<class T, class S>
00326 VETRESULT vetUtility::conv_yiq_rgb(T* out, S* in, unsigned int width, unsigned int height)
00327  {
00328         return conv_linear(out, in, cvm_yiq_rgb, width, height);
00329  }
00332 /*
00333 SMPTE-C is the current colour standard for broadcasting in America, the old
00334 NTSC standard for primaries is no longer in wide use because the primaries
00335 of the system have gradually shifted towards those of the EBU
00336 (see section 6.2). In all other respects, SMPTE-C is the same as NTSC.
00337 The CRT gamma law is assumed to be 2.2. The white point is now D65, and
00338 the chromaticities are:
00339 
00340     R:     xr=0.630     yr=0.340
00341     G:     xg=0.310     yg=0.595
00342     B:     xb=0.155     yb=0.070
00343     White: xn=0.312713  yn=0.329016
00344 
00345 The conversion equations for linear signals are:
00346 */
00347 double cvm_rgb_smpte_c[] =      {
00348                                                                 0.3935, 0.3653, 0.1916,
00349                                                                 0.2124, 0.7011, 0.0866,
00350                                                                 0.0187, 0.1119, 0.9582
00351                                                 };
00352 double cvm_smpte_c_rgb[] =      {
00353                                                                  3.5058, -1.7397, -0.5440,
00354                                                                 -1.0690,  1.9778,  0.0352,
00355                                                                  0.0563, -0.1970,  1.0501
00356                                                 };
00357 
00358 
00359 template<class T, class S>
00360 VETRESULT vetUtility::conv_rgb_smpte_c(T* out, S* in, unsigned int width, unsigned int height)
00361  {
00362         return conv_linear(out, in, cvm_rgb_smpte_c, width, height);
00363  }
00364 
00365 
00366 template<class T, class S>
00367 VETRESULT vetUtility::conv_smpte_c_rgb(T* out, S* in, unsigned int width, unsigned int height)
00368  {
00369         return conv_linear(out, in, cvm_smpte_c_rgb, width, height);
00370  }
00371 
00372 
00374 
00375 
00376 /*
00377 RGB values in a particular set of primaries can be transformed to and from CIE XYZ via a 3x3 matrix transform. These transforms involve tristimulus values, that is a set of three linear-light components that conform to the CIE color-matching functions. CIE XYZ is a special set of tristimulus values. In XYZ, any color is represented as a set of positive values.
00378 
00379 To transform from XYZ to RGB (with D65 white point), the matrix transform used is [3]:
00380 
00381    [ R ]   [  3.240479 -1.537150 -0.498535 ]   [ X ]
00382    [ G ] = [ -0.969256  1.875992  0.041556 ] * [ Y ]
00383    [ B ]   [  0.055648 -0.204043  1.057311 ]   [ Z ].
00384 
00385 The range for valid R, G, B values is [0,1]. Note, this matrix has negative coefficients. Some XYZ color may be transformed to RGB values that are negative or greater than one. This means that not all visible colors can be produced using the RGB system.
00386 
00387 The inverse transformation matrix is as follows:
00388 
00389    [ X ]   [  0.412453  0.357580  0.180423 ]   [ R ] **
00390    [ Y ] = [  0.212671  0.715160  0.072169 ] * [ G ]
00391    [ Z ]   [  0.019334  0.119193  0.950227 ]   [ B ].
00392 
00393 */
00394 double cvm_rgb_xyz[] =  {
00395                                                         0.412453, 0.357580, 0.180423,
00396                                                         0.212671, 0.715160, 0.072169,
00397                                                         0.019334, 0.119193, 0.950227
00398                                                 };
00399 double cvm_xyz_rgb[] =  {
00400                                                          3.240479, -1.537150, -0.498535,
00401                                                         -0.969256,  1.875992,  0.041556,
00402                                                          0.055648, -0.204043,  1.057311
00403                                                 };
00404 
00405 //BUG
00406 template<class T, class S>
00407 VETRESULT vetUtility::conv_rgb_xyz(T* out, S* in, unsigned int width, unsigned int height)
00408  {
00409         return conv_linear(out, in, cvm_rgb_xyz, width, height);
00410  }
00411 
00412 
00413 template<class T, class S>
00414 VETRESULT vetUtility::conv_xyz_rgb(T* out, S* in, unsigned int width, unsigned int height)
00415  {
00416         return conv_linear(out, in, cvm_xyz_rgb, width, height);
00417  }
00418 
00419 
00420 
00421 
00423 /*
00424 [6.5] ITU.BT-709 HDTV studio production in Y'CbCr
00425 
00426 This is a recent standard, defined only as an interim standard for HDTV
00427 studio production. It was defined by the CCIR (now the ITU) in 1988, but is
00428 not yet recommended for use in broadcasting. The primaries are the R and B
00429 from the EBU, and a G which is midway between SMPTE-C and EBU. The CRT gamma
00430 law is assumed to be 2.2. White is D65. The chromaticities are:
00431     R:      xr=0.64       yr=0.33
00432     G:      xg=0.30       yg=0.60
00433     B:      xb=0.15       yb=0.06
00434     White:  xn=0.312713   yn=0.329016
00435 
00436 The conversion equations for linear signals are:
00437 */
00438 double cvm_rgb_bt709[] =        {
00439                                                         0.412, 0.358, 0.180,
00440                                                         0.213, 0.715, 0.072,
00441                                                         0.019, 0.119, 0.950
00442                                                 };
00443 double cvm_bt709_rgb[] =        {
00444                                                          3.241, -1.537, -0.499,
00445                                                         -0.969,  1.876,  0.042,
00446                                                          0.056, -0.204,  1.057
00447                                                 };
00448 
00449 
00450 template<class T, class S>
00451 VETRESULT vetUtility::conv_rgb_bt709(T* out, S* in, unsigned int width, unsigned int height)
00452  {
00453         return conv_linear(out, in, cvm_rgb_bt709, width, height);
00454  }
00455 
00456 
00457 template<class T, class S>
00458 VETRESULT vetUtility::conv_bt709_rgb(T* out, S* in, unsigned int width, unsigned int height)
00459  {
00460         return conv_linear(out, in, cvm_bt709_rgb, width, height);
00461  }
00462 
00463 
00465 /*
00466 [6.6] SMPTE-240M Y'PbPr
00467 
00468 This one of the developments of NTSC component coding, in which the B primary
00469 and white point were changed. The CRT gamma law is assumed to be 2.2. The
00470 white point is D65, chromaticity coordinates are:
00471     R:      xr=0.67     yr=0.33
00472     G:      xg=0.21     yg=0.71
00473     B:      xb=0.15     yb=0.06
00474     White:  xn=0.312713 yn=0.329016
00475 
00476 The conversion equations for linear signals are:
00477 */
00478 double cvm_rgb_smpte240m[] =    {
00479                                                         0.567, 0.190, 0.193,
00480                                                         0.279, 0.643, 0.077,
00481                                                         0.000, 0.073, 1.016
00482                                                 };
00483 double cvm_smpte240m_rgb[] =    {
00484                                                          2.042, -0.565, -0.345,
00485                                                         -0.894,  1.815,  0.032,
00486                                                          0.064, -0.129,  0.912
00487                                                 };
00488 
00489 
00490 template<class T, class S>
00491 VETRESULT vetUtility::conv_rgb_smpte240m(T* out, S* in, unsigned int width, unsigned int height)
00492  {
00493         return conv_linear(out, in, cvm_rgb_smpte240m, width, height);
00494  }
00495 
00496 
00497 template<class T, class S>
00498 VETRESULT vetUtility::conv_smpte240m_rgb(T* out, S* in, unsigned int width, unsigned int height)
00499  {
00500         return conv_linear(out, in, cvm_smpte240m_rgb, width, height);
00501  }
00502 
00503 
00504 
00505 
00509 
00510 
00511 void yuv422to420p(unsigned char *map, unsigned char *cap_map, int width, int height)
00512 {
00513         unsigned char *src, *dest, *src2, *dest2;
00514         int i, j;
00515 
00516         /* Create the Y plane */
00517         src=cap_map;
00518         dest=map;
00519         for (i=width*height; i; i--) {
00520                 *dest++=*src;
00521                 src+=2;
00522         }
00523         /* Create U and V planes */
00524         src=cap_map+1;
00525         src2=cap_map+width*2+1;
00526         dest=map+width*height;
00527         dest2=dest+(width*height)/4;
00528         for (i=height/2; i; i--) {
00529                 for (j=width/2; j; j--) {
00530                         *dest=((int)*src+(int)*src2)/2;
00531                         src+=2;
00532                         src2+=2;
00533                         dest++;
00534                         *dest2=((int)*src+(int)*src2)/2;
00535                         src+=2;
00536                         src2+=2;
00537                         dest2++;
00538                 }
00539                 src+=width*2;
00540                 src2+=width*2;
00541         }
00542 }
00543 
00544 // this is bgr !
00545 void rgb24toyuv420p(unsigned char *map, unsigned char *cap_map, int width, int height)
00546 {
00547         unsigned char *y, *u, *v;
00548         unsigned char *r, *g, *b;
00549         int i, loop;
00550 
00551         b=cap_map;
00552         g=b+1;
00553         r=g+1;
00554         y=map;
00555         u=y+width*height;
00556         v=u+(width*height)/4;
00557         memset(u, 0, width*height/4);
00558         memset(v, 0, width*height/4);
00559 
00560         for(loop=0; loop<height; loop++) {
00561                 for(i=0; i<width; i+=2) {
00562                         *y++=(9796**r+19235**g+3736**b)>>15;
00563                         *u+=((-4784**r-9437**g+14221**b)>>17)+32;
00564                         *v+=((20218**r-16941**g-3277**b)>>17)+32;
00565                         r+=3;
00566                         g+=3;
00567                         b+=3;
00568                         *y++=(9796**r+19235**g+3736**b)>>15;
00569                         *u+=((-4784**r-9437**g+14221**b)>>17)+32;
00570                         *v+=((20218**r-16941**g-3277**b)>>17)+32;
00571                         r+=3;
00572                         g+=3;
00573                         b+=3;
00574                         u++;
00575                         v++;
00576                 }
00577 
00578                 if ((loop & 1) == 0)
00579                 {
00580                         u-=width/2;
00581                         v-=width/2;
00582                 }
00583         }
00584 }
00585 
00586 
00592 
00593 
00594 
00595 
00596 /* Colour ConVerT: going from one colour space to another
00597 
00598    Format descriptions:
00599    420i = "4:2:0 interlaced"
00600            YYYY UU YYYY UU   even lines
00601            YYYY VV YYYY VV   odd lines
00602            U/V data is subsampled by 2 both in horizontal
00603            and vertical directions, and intermixed with the Y values.
00604 
00605    420p = "4:2:0 planar"
00606            YYYYYYYY      N lines
00607            UUUU          N/2 lines
00608            VVVV          N/2 lines
00609            U/V is again subsampled, but all the Ys, Us and Vs are placed
00610            together in separate buffers. The buffers may be placed in
00611            one piece of contiguous memory though, with Y buffer first,
00612            followed by U, followed by V.
00613 
00614    yuyv = "4:2:2 interlaced"
00615            YUYV YUYV YUYV ...   N lines
00616            The U/V data is subsampled by 2 in horizontal direction only.
00617 
00618    bgr24 = 3 bytes per pixel, in the order Blue Green Red (whoever came up
00619            with that idea...)
00620    rgb24 = 3 bytes per pixel, in the order Red Green Blue (which is sensible)
00621    rgb32 = 4 bytes per pixel, in the order Red Green Blue Alpha, with
00622            Alpha really being a filler byte (0)
00623    bgr32 = last but not least, 4 bytes per pixel, in the order Blue Green Red
00624            Alpha, Alpha again a filler byte (0)
00625  */
00626 
00627 /* Functions in ccvt_i386.S/ccvt_c.c */
00628 
00629 /* 4:2:0 YUV planar to RGB/BGR     */
00630 //void ccvt_420p_rgb32(int width, int height, void *srcy, void *srcu, void *srcv, void *dst);
00631 //void ccvt_420p_bgr32(int width, int height, void *srcy, void *srcu, void *srcv, void *dst);
00632 
00633 /* RGB/BGR to 4:2:0 YUV interlaced */
00634 
00635 /* RGB/BGR to 4:2:0 YUV planar     */
00636 //void ccvt_rgb24_420p(int width, int height, void *src, void *dsty, void *dstu, void *dstv);
00637 //void ccvt_bgr24_420p(int width, int height, void *src, void *dsty, void *dstu, void *dstv);
00638 
00639 /* Go from 420i to other yuv formats */
00640 //void ccvt_420i_420p(int width, int height, void *src, void *dsty, void *dstu, void *dstv);
00641 //void ccvt_420i_yuyv(int width, int height, void *src, void *dst);
00642 
00643 
00644 
00645 //void ccvt_420i_bgr24(int width, int height, void *src, void *dst);
00646 //void ccvt_420i_bgr32(int width, int height, void *src, void *dst);
00647 
00648 
00649 
00650 
00651 
00652 
00653 
00654 
00655 
00656 
00657 
00658 
00659 
00660 
00661 
00662 
00663 
00664 
00665 
00666 
00667 
00668 
00669 
00670 // SLEEPING ROUTINES, OS DEPENDENT
00671 
00672 
00673 #if defined(sun)        || defined(__sun)       || defined(linux)       || defined(__linux)    \
00674  || defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__OPENBSD__) || defined(__MACOSX__) \
00675  || defined(__APPLE__)  || defined(sgi)         || defined(__sgi)
00676 // Unix (Linux,Solaris,BSD,Irix,...)
00677 
00678         #include <unistd.h>
00679         #include <time.h>
00680 
00681 
00682         // got problems using usleep(millisec), and this is great :P
00683         void vetUtility::vetSleep(long millisec)
00684          {
00685                 if (millisec == 0)
00686                         return;
00687 
00688                 double offset = clock() * 1000000 / CLOCKS_PER_SEC;
00689 
00690                 while (offset + millisec*1000  >= clock() * 1000000 / CLOCKS_PER_SEC) ;
00691          }
00692 
00693 
00694         /* returns time in micro-s*/
00695         double vetUtility::getTime_usec()
00696          {
00697                 clock_t clk;
00698                 clk = clock();
00699                 return clk * 1000000 / CLOCKS_PER_SEC;
00700          }
00701 
00702 #elif defined(_WIN32) || defined(__WIN32__)
00703 // Windows
00704 
00705         #include <windows.h>
00706         #include <time.h>       /* for gettimeofday */
00707 
00708         void vetUtility::vetSleep(long millisec)
00709          {
00710                 Sleep(millisec);
00711          }
00712 
00713 
00714         /* returns time in micro-s*/
00715 
00716 //BUG
00717         double vetUtility::getTime_usec()
00718          {
00719 //              struct timeval  tv;
00720 //              gettimeofday(&tv, 0);
00721                 return -1;
00722          }
00723 /*
00724 #else
00725 // Unknown configuration : compile with minimal dependencies.
00726 
00727 
00728         void vetUtility::vetSleep(long millisec)
00729          {
00730                 ;
00731          }
00732 
00733 
00734 //BUG
00735         double vetUtility::getTime_usec()
00736          {
00737 //              struct timeval  tv;
00738 //              gettimeofday(&tv, 0);
00739                 return -1;
00740          }
00741 */
00742 #endif
00743 
00744 
00745 
00746 

Generated on Tue Jan 24 11:59:05 2006 for VETLib by  doxygen 1.4.4