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
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
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
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
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
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
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00244
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
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
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
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
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
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
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
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
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
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
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
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
00517 src=cap_map;
00518 dest=map;
00519 for (i=width*height; i; i--) {
00520 *dest++=*src;
00521 src+=2;
00522 }
00523
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
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
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
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
00677
00678 #include <unistd.h>
00679 #include <time.h>
00680
00681
00682
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
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
00704
00705 #include <windows.h>
00706 #include <time.h>
00707
00708 void vetUtility::vetSleep(long millisec)
00709 {
00710 Sleep(millisec);
00711 }
00712
00713
00714
00715
00716
00717 double vetUtility::getTime_usec()
00718 {
00719
00720
00721 return -1;
00722 }
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742 #endif
00743
00744
00745
00746