00001
00002
00003
00004 #include "funcoesHAIRCAPTURE.h"
00005 #include "jpeg.c"
00006
00007
00008
00009
00010
00011
00012
00013
00014 std::string ToString(int Cnumero)
00015 {
00016 char sz[101];
00017 sprintf(sz, "%d", Cnumero);
00018 std::string lreturn(sz);
00019 return lreturn;
00020 }
00021
00022 std::string ToString(float Cnumero)
00023 {
00024 char sz[101];
00025 sprintf(sz, "%G", Cnumero);
00026 std::string lreturn(sz);
00027
00028 return lreturn;
00029 }
00030
00031
00032
00033
00034
00035
00036
00037 bool FileExist(char *lcharFILE)
00038 {
00039 bool lboolRETORNO = true;
00040
00041 struct stat lstatFILE;
00042
00043 if ( stat(lcharFILE,&lstatFILE))
00044 {
00045 lboolRETORNO = false;
00046 printf(" > File not exist! \n");
00047 }
00048
00049 if(lstatFILE.st_size<=0)
00050 {
00051 lboolRETORNO = false;
00052 printf(" > File error!");
00053 }
00054
00055 return lboolRETORNO;
00056 }
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 void *ThreadAoVivo(HAIR::CAPTURE *VIDEO)
00068 {
00069 VIDEO->Live();
00070 }
00071
00072
00073
00074
00075
00076
00077
00078
00079 uchar SAT(int val)
00080 {
00081
00082 if (val < 0) return 0;
00083 else if (val > 255) return 255;
00084 return (uchar) val;
00085 }
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 void update(SDL_Surface * screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h)
00099 {
00100 SDL_UpdateRect(screen, x, y, w, h);
00101 }
00102
00103 namespace HAIR
00104 {
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 void CAPTURE::PlayMPEG(char *name)
00115 {
00116 this->mpeg = SMPEG_new(name, &this->info, 1);
00117 SMPEG_setdisplay(this->mpeg, this->video_surface, NULL, update);
00118 SMPEG_play(this->mpeg);
00119 this->UseVideo = true;
00120 }
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 void CAPTURE::Live(void)
00132 {
00133 this->map_buffer.frame = 1;
00134 do
00135 {
00136 if (-1 == ioctl(this->fd, VIDIOCMCAPTURE, &this->map_buffer))
00137 {
00138 printf(" > Error: Grabber chip can't sync (no station tuned in?)\n");
00139 exit(-1);
00140 }
00141 this->map_buffer.frame = !this->map_buffer.frame;
00142
00143 if (-1 == ioctl(this->fd, VIDIOCSYNC, &this->map_buffer.frame))
00144 {
00145 printf(" > Error: on sync!\n");
00146 exit(-1);
00147 }
00148 this->WriteScreen(this->map+ this->buffers.offsets[this->map_buffer.frame]);
00149 SDL_PollEvent(&this->event);
00150 this->key = this->event.key.keysym.sym;
00151 } while ((this->event.type != SDL_KEYDOWN) || (this->key!=SDLK_q));
00152
00153 SMPEG_delete(this->mpeg);
00154 SDL_Quit();
00155
00156
00157 }
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 void CAPTURE::SetFont(char *lfontName)
00169 {
00170 this->fontName = lfontName;
00171 }
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 void CAPTURE::SetFontSize(int lintSize)
00183 {
00184 this->size_font = lintSize;
00185
00186 }
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 void CAPTURE::SetDevice(char *lDevice)
00198 {
00199 this->device = lDevice;
00200 }
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 void CAPTURE::ColorBit(int depth)
00212 {
00213 this->depth = depth;
00214 }
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225 void CAPTURE::Resolution(int width, int height)
00226 {
00227 this->width = width;
00228 this->height= height;
00229 }
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 void CAPTURE::ResolutionWin(int width, int height)
00242 {
00243 this->widthWin = width;
00244 this->heightWin = height;
00245 }
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 void CAPTURE::SetAngleText(int lintAngle)
00257 {
00258 this->RotateText = lintAngle;
00259 }
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271 void CAPTURE::SetAngleVideo(int lintAngle)
00272 {
00273 this->RotateVideo = lintAngle;
00274 }
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288 void CAPTURE::SetVideoPos(int x, int y)
00289 {
00290 this->top = y;
00291 this->left = x;
00292 }
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 void CAPTURE::convertYUV420PtoGray(void)
00305 {
00306 unsigned int gray;
00307 unsigned long len = (this->width*this->height*3)>> 2;
00308 unsigned char *src = this->v4l_convert_buf;
00309 unsigned char *dst = this->last_map;
00310 while(len--)
00311 {
00312 gray = src[0]+src[1]+src[2];
00313 dst[0]=dst[1]=dst[2]=gray/4;
00314
00315 src += 4;
00316 dst += 4;
00317
00318 }
00319
00320 if (this->debug)
00321 printf(" > Convert to GrayScale.\n");
00322 }
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333 void CAPTURE::convertYUV420PtoRGB(bool forDISK)
00334 {
00335 unsigned char *y, *u, *v, *r, *g, *b;
00336 int tmp,i;
00337
00338 if (this->map_buffer.format==VIDEO_PALETTE_YUV420P)
00339 {
00340 r=this->v4l_convert_buf;
00341 g=this->v4l_convert_buf+1;
00342 b=this->v4l_convert_buf+2;
00343 if (this->debug)
00344 printf(" > Convert YUV to RGB for video live.\n");
00345 y=this->map;
00346
00347 u=y+this->width*this->height;
00348 v=y+this->width*this->height+(this->width*this->height)/4;
00349 for (i=0; i<this->width*this->height; i++)
00350 {
00351 tmp=(((int)*y-16)*76284 + 104595*((int)*u-128)) >>16;
00352 if (tmp<0) tmp=0; if (tmp>255) tmp=255;
00353 *b=tmp;
00354 tmp=(((int)*y-16)*76284 - 53281*((int)*u-128) - 25625*((int)*v-128)) >>16;
00355 if (tmp<0) tmp=0; if (tmp>255) tmp=255;
00356 *g=tmp;
00357 tmp=(((int)*y-16)*76284 + 132252*((int)*v-128)) >>16;
00358 if (tmp<0) tmp=0; if (tmp>255) tmp=255;
00359 *r=tmp;
00360 if (i & 1)
00361 {
00362 u++;
00363 v++;
00364 }
00365 if (i%(this->width*2)==this->width-1)
00366 {
00367 u-=this->width/2;
00368 v-=this->width/2;
00369 }
00370 r+=3;
00371 g+=3;
00372 b+=3;
00373 y++;
00374 }
00375 }
00376
00377 }
00378
00379
00380
00381
00382
00383
00384
00385
00386 void CAPTURE::swap_rgb24(void)
00387 {
00388 this->v4l_convert_buf = this->map;
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403 }
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416 bool CAPTURE::SaveJPG(char *name,bool lboolFRAMEGRAY)
00417 {
00418 bool lboolreturn = false;
00419
00420 unlink(name);
00421
00422 if (this->map_buffer.format==VIDEO_PALETTE_YUV420P)
00423 {
00424 this->convertYUV420PtoRGB(true);
00425 }
00426 else
00427 swap_rgb24();
00428
00429 int quality = 75;
00430 imageRGB img;
00431 img.data = this->v4l_convert_buf;
00432
00433 img.width = this->width;
00434 img.height = this->height;
00435
00436
00437 int w, h;
00438 for (w = 0; w < img.width; w++)
00439 {
00440 for (h = 0; h < img.height; h++)
00441 {
00442 uchar* pixel = &img.data[3*(w + img.width*h)];
00443 pixel[0] = SAT(pixel[0]+10);
00444 pixel[1] = pixel[1];
00445 pixel[2] = SAT(pixel[2]-10);
00446 }
00447 }
00448
00449 lboolreturn = write_JPEG_file (name, quality, img);
00450
00451 if (this->debug)
00452 printf(" > SaveJPG(%s,%d)\n", name,lboolFRAMEGRAY);
00453
00454 lboolreturn = FileExist(name);
00455
00456 return lboolreturn;
00457
00458
00459 }
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471 void CAPTURE::LoadJPG(char *name,int lintX, int lintY, float lfloatSCALE, TypeSurface lsurfaceScreen, int lintAngleRotate )
00472 {
00473
00474 SDL_Surface *LimageLarge;
00475 SDL_Surface *LimageSmall;
00476
00477 SDL_RWops *rwop;
00478 rwop=SDL_RWFromFile(name, "rb");
00479
00480 if (this->debug)
00481 printf(" > LoadJPG ...");
00482 LimageLarge=IMG_LoadJPG_RW(rwop);
00483 if(!LimageLarge)
00484 {
00485 printf(" > IMG_LoadJPG_RW: %s\n", IMG_GetError());
00486 }
00487
00488 if (this->debug)
00489 printf(" OK!\n");
00490
00491 LimageSmall = zoomSurface(LimageLarge, lfloatSCALE,lfloatSCALE, 1);
00492
00493 this->TempRect.x = lintX;
00494 this->TempRect.y = lintY;
00495 this->TempRect.w = LimageSmall->w;
00496 this->TempRect.h = LimageSmall->h;
00497
00498 if(lintAngleRotate!=0)
00499 {
00500 LimageSmall = rotozoomSurface(LimageSmall, lintAngleRotate, 1,SMOOTHING_ON);
00501 this->TempRect.w = LimageSmall->h;
00502 this->TempRect.h = LimageSmall->w;
00503 }
00504
00505
00506 switch(lsurfaceScreen)
00507 {
00508
00509 case TEXTS:
00510 {
00511 SDL_BlitSurface(LimageSmall, NULL, this->text_surface, &TempRect);
00512 SDL_UpdateRect(this->text_surface, 0, 0, 0, 0);
00513 this->UseText = true;
00514 break;
00515 }
00516 case DRAW:
00517 {
00518 SDL_BlitSurface(LimageSmall, NULL, this->draw_surface, &TempRect);
00519 SDL_UpdateRect(this->draw_surface, 0, 0, 0, 0);
00520 this->UseDraw = true;
00521 break;
00522 }
00523
00524 case ZOOM:
00525 {
00526 SDL_BlitSurface(LimageSmall, NULL, this->zoomout_surface, &TempRect);
00527 SDL_UpdateRect(this->zoomout_surface, 0, 0, 0, 0);
00528 this->UseZoomOut = true;
00529 break;
00530 }
00531 case VIDEO:
00532 {
00533 SDL_BlitSurface(LimageSmall, NULL, this->video_surface, &TempRect);
00534 SDL_UpdateRect(this->video_surface, 0, 0, 0, 0);
00535 this->UseVideo = true;
00536 break;
00537 }
00538
00539 }
00540
00541 SDL_FreeSurface(LimageSmall);
00542 SDL_FreeSurface(LimageLarge);
00543
00544 if (this->debug)
00545 printf(" > LoadJPG(%s,%d,%d,%f,%d)\n", name,lintX, lintY, lfloatSCALE,lsurfaceScreen);
00546 }
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559 void CAPTURE::Background(char *name)
00560 {
00561
00562 SDL_Surface *LimageLarge;
00563
00564 SDL_RWops *rwop;
00565 rwop=SDL_RWFromFile(name, "rb");
00566
00567 LimageLarge = IMG_LoadJPG_RW(rwop);
00568
00569 if(!LimageLarge)
00570 {
00571 printf(" > IMG_LoadJPG_RW: %s\n", IMG_GetError());
00572 }
00573 SDL_BlitSurface(LimageLarge, NULL, this->screen, NULL);
00574 SDL_UpdateRect(this->screen, 0, 0, 0, 0);
00575
00576 }
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587 void CAPTURE::ViewLastMap(int lintX, int lintY, float lfloatSCALE, TypeSurface lsurfaceScreen)
00588 {
00589 SDL_Surface *LimageSmall;
00590 SDL_Surface *LimageLarge;
00591
00592 if(this->debug)
00593 printf(" > Starting ViewLastMap.\n");
00594
00595
00596 LimageLarge = SDL_CreateRGBSurfaceFrom((void *) this->last_map, this->width, this->height, this->depth, this->width*3, 0xFF0000, 0x00FF00, 0x0000FF, 0x000000);
00597
00598
00599 LimageSmall = zoomSurface(LimageLarge, lfloatSCALE,lfloatSCALE, 1);
00600
00601 this->TempRectImage.x = lintX;
00602 this->TempRectImage.y = lintY;
00603 this->TempRectImage.w = LimageSmall->w;
00604 this->TempRectImage.h = LimageSmall->h;
00605
00606 switch(lsurfaceScreen)
00607 {
00608
00609 case TEXTS:
00610 {
00611 this->UseText = false;
00612 SDL_BlitSurface(LimageSmall, NULL, this->text_surface, &TempRectImage);
00613 SDL_UpdateRect(this->text_surface, 0, 0, 0, 0);
00614 this->UseText = true;
00615 break;
00616 }
00617 case DRAW:
00618 {
00619 this->UseDraw = false;
00620 SDL_BlitSurface(LimageSmall, NULL, this->draw_surface, &TempRectImage);
00621 SDL_UpdateRect(this->draw_surface, 0, 0, 0, 0);
00622 this->UseDraw = true;
00623 break;
00624 }
00625
00626 case ZOOM:
00627 {
00628 this->UseZoomOut = false;
00629 SDL_BlitSurface(LimageSmall, NULL, this->zoomout_surface, &TempRectImage);
00630 SDL_UpdateRect(this->zoomout_surface, 0, 0, 0, 0);
00631 this->UseZoomOut = true;
00632 break;
00633 }
00634 case VIDEO:
00635 {
00636 this->UseVideo = false;
00637 SDL_BlitSurface(LimageSmall, NULL, this->video_surface, &TempRectImage);
00638 SDL_UpdateRect(this->video_surface, 0, 0, 0, 0);
00639 this->UseVideo = true;
00640 break;
00641 }
00642
00643 }
00644
00645 SDL_FreeSurface(LimageSmall);
00646 SDL_FreeSurface(LimageLarge);
00647
00648 if(this->debug)
00649 printf(" > Finishing ViewLastMap.\n");
00650
00651
00652
00653 }
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665 void CAPTURE::SavePPM(char *name)
00666 {
00667 int i=0;
00668 FILE *fp;
00669
00670 this->convertYUV420PtoRGB(true);
00671 sprintf (this->arqPPM, "P6 %d %d 255 ", this->width, this->height);
00672
00673 for (i=0; i<(this->width*this->height*3); i++)
00674 this->arqPPM[i+15] = this->v4l_convert_buf[i];
00675
00676 if ((fp=fopen(name, "w+")) == NULL)
00677 {
00678 printf(" > Error: write image PPM!");
00679 exit(-1);
00680 }
00681 fwrite ((char*)this->arqPPM, (this->width*this->height * 3)+15, 1, fp);
00682 fclose (fp);
00683 }
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694 void CAPTURE::WriteScreen(unsigned char* tmap)
00695 {
00696 int lintLoop = 0;
00697
00698
00699 if (this->map_buffer.format==VIDEO_PALETTE_YUV420P)
00700 {
00701 unsigned int sizeY = this->width * this->height;
00702 unsigned int sizeUV = (this->width /2)* ( this->height / 2 );
00703
00704 this->offscreen = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_DOUBLEBUF, this->width, this->height, this->depth, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
00705
00706 this->offscreenOVL = SDL_CreateYUVOverlay (this->width , this->height ,SDL_IYUV_OVERLAY,this->offscreen );
00707
00708 SDL_LockYUVOverlay (this->offscreenOVL) ;
00709
00710 memcpy( this-> offscreenOVL->pixels[ 0 ] , tmap , sizeY ) ;
00711 memcpy( this-> offscreenOVL->pixels[ 1 ] , tmap+sizeY , sizeUV ) ;
00712 memcpy( this->offscreenOVL->pixels[ 2 ] , tmap+sizeY+sizeUV , sizeUV ) ;
00713
00714 SDL_UnlockYUVOverlay ( this->offscreenOVL ) ;
00715 this->TempRect.x = 0;
00716 this->TempRect.y = 0;
00717 this->TempRect.w = this->width ;
00718 this->TempRect.h = this->height ;
00719 SDL_DisplayYUVOverlay( this->offscreenOVL,&this->TempRect) ;
00720 }
00721 else
00722 {
00723 this->offscreen = SDL_CreateRGBSurfaceFrom((void *) tmap, this->width, this->height, this->depth, this->width*3, 0xFF0000, 0x00FF00, 0x0000FF, 0x000000);
00724 }
00725 this->TempRect.y = this->top;
00726 this->TempRect.x = this->left;
00727
00728 if(this->RotateVideo!=0)
00729 {
00730 this->offscreen = rotozoomSurface(this->offscreen, this->RotateVideo, 1,SMOOTHING_ON);
00731 this->TempRect.w = this->height;
00732 this->TempRect.h = this->width;
00733 }
00734
00735
00736
00737 SDL_BlitSurface(this->offscreen, NULL, this->screen, &this->TempRect);
00738
00739 this->TempRect.x = this->left;
00740 this->TempRect.y = this->top;
00741
00742 if(this->UseZoomOut)
00743 {
00744
00745 SDL_BlitSurface( this->zoomout_surface, NULL, this->screen, &this->TempRect);
00746
00747 }
00748
00749 if(this->UseVideo)
00750 {
00751
00752 this->TempRect.y = this->top;
00753 this->TempRect.x = this->left+(this->width/2)+1;
00754 SDL_BlitSurface(this->video_surface, NULL, this->screen, &this->TempRect);
00755 if(SMPEG_status(this->mpeg) != SMPEG_PLAYING)
00756 {
00757 SMPEG_stop(this->mpeg);
00758 SMPEG_delete(this->mpeg);
00759 ClearSurface(VIDEO);
00760 }
00761
00762 }
00763
00764 this->TempRect.x = 0;
00765 if(this->GrabZoom)
00766 {
00767 this->GrabZoom = false;
00768 this->ZoomOut(true);
00769 }
00770
00771
00772 if(this->UseDraw)
00773 {
00774
00775 SDL_BlitSurface( this->draw_surface, NULL, this->screen, NULL);
00776
00777 }
00778
00779 if(this->UseText)
00780 {
00781
00782 SDL_BlitSurface( this->text_surface,NULL,this->screen,NULL);
00783
00784 }
00785
00786 SDL_UpdateRect(this->screen, 0, 0, 0, 0);
00787
00788 do
00789 {
00790 SDL_PollEvent(&this->event);
00791 if ((this->event.type == SDL_MOUSEBUTTONDOWN))
00792 {
00793 if((lintTouchX != this->event.motion.x) || (lintTouchY != this->event.motion.y))
00794 {
00795 if(this->debug)
00796 printf(" > Mouse pointer X:%d , Y:%d \n", this->event.motion.x, this->event.motion.y);
00797
00798 lintTouchX = this->event.motion.x;
00799 lintTouchY = this->event.motion.y;
00800 if(this->ScanButtons)
00801 {
00802 SDL_LockMutex(this->mutex);
00803 this->LastButton = FindButton(this->event.motion.x, this->event.motion.y);
00804
00805 SDL_CondSignal(this->cond);
00806 SDL_UnlockMutex(this->mutex);
00807 }
00808 }
00809 }
00810
00811
00812 if (this->event.type == SDL_KEYDOWN)
00813 {
00814
00815 this->key = this->event.key.keysym.sym;
00816
00817 if(this->key==this->KeyZoomOutOn)
00818 this->ZoomOut(true);
00819
00820 if(this->key==this->KeyVideoOn)
00821 this->PlayMPEG(this->mpegName);
00822
00823
00824 if(this->key==KeyZoomOutOff)
00825 {
00826 ClearSurface(TEXTS);
00827 ClearSurface(ZOOM);
00828
00829 }
00830
00831 if(this->key==KeyFullScreeen)
00832 SDL_WM_ToggleFullScreen(this->screen);
00833
00834
00835 if(this->key==KeySaveFrame)
00836 this->SavePPM("screenshot.ppm");
00837
00838 if(this->key == SDLK_RIGHT)
00839 {
00840 AdjustVideo(+1);
00841 }
00842
00843 if(this->key == SDLK_LEFT)
00844 {
00845 AdjustVideo(-1);
00846 }
00847
00848 if(this->key == SDLK_UP)
00849 {
00850 SelectAdjust(+1);
00851 }
00852
00853 if(this->key == SDLK_DOWN)
00854 {
00855 SelectAdjust(-1);
00856 }
00857
00858 if((this->key>= SDLK_0) && (this->key<= SDLK_9) && (this->Lastkey!=this->key))
00859 {
00860 this->Lastkey=this->key;
00861 this->SetInputCamera(this->key-SDLK_0,VIDEO_MODE_NTSC);
00862 ioctl(this->fd, VIDIOCSCHAN,&this->vch);
00863 if(this->debug)
00864 printf(" > Source %d selected\n",(this->key-SDLK_0));
00865 }
00866
00867
00868
00869
00870 if(this->key==KeyQuit)
00871 {
00872 this->VideoTerminate();
00873 }
00874 }
00875
00876
00877 } while(lintLoop++<10);
00878
00879 if (this->map_buffer.format==VIDEO_PALETTE_YUV420P)
00880 SDL_FreeYUVOverlay(this->offscreenOVL);
00881
00882 SDL_FreeSurface(this->offscreen);
00883
00884 }
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895 void CAPTURE::Open(void)
00896 {
00897 if (-1 == (this->fd = open(this->device, O_RDWR)))
00898 {
00899 printf(" > Error: opening device: %s\n", this->device);
00900 exit(-1);
00901 }
00902
00903 if (-1 == ioctl(this->fd,VIDIOCGCAP,&this->capability))
00904 {
00905 printf(" > Error: ioctl(fd,VIDIOCGCAP,&capability)\n");
00906 exit(-1);
00907 }
00908
00909 if (this->debug)
00910 {
00911
00912 printf(" _ _ _ ___ ____ ____ _ ____ _____ _ _ ____ _____ \n");
00913 printf("| | | | / \\ |_ _| _ \\ / ___| / \\ | _ \\_ _| | | | _ \\| ____|\n");
00914 printf("| |_| | / _ \\ | || |_) | | / _ \\ | |_) || | | | | | |_) | _| \n");
00915 printf("| _ |/ ___ \\ | || _ <| |___ / ___ \\| __/ | | | |_| | _ <| |___ \n");
00916 printf("|_| |_/_/ \\_\\___|_| \\_\\\\____/_/ \\_\\_| |_| \\___/|_| \\_\\_____|\n");
00917
00918 printf(" > \n");
00919 printf(" > V4L function VIDIOCGCAP.\n");
00920 printf(" > Name : %s\n", &this->capability.name);
00921 printf(" > Channels : %i\n", this->capability.channels);
00922 printf(" > Audios : %i\n", this->capability.audios);
00923 printf(" > Maxwidth : %i\n", this->capability.maxwidth);
00924 printf(" > Maxheight : %i\n", this->capability.maxheight);
00925 printf(" > Minwidth : %i\n", this->capability.minwidth);
00926 printf(" > Minheight : %i\n", this->capability.minheight);
00927 }
00928
00929 if (-1==ioctl(this->fd,VIDIOCGFBUF,&this->fbuffers))
00930 {
00931 printf(" > ERRO: V4L function VIDIOCGFBUF.\n");
00932 }
00933 else
00934 {
00935 if (-1==ioctl(this->fd,VIDIOCSFBUF,&this->fbuffers))
00936 {
00937 printf(" > ERRO: V4L function VIDIOCSFBUF.\n");
00938 }
00939 else
00940 {
00941 if (this->debug)
00942 {
00943 printf (" > V4L function VIDIOCSFBUF.\n");
00944 printf (" > Add : %d\n", this->fbuffers.base);
00945 printf (" > Height : %d\n", this->fbuffers.height);
00946 printf (" > Width : %d\n", this->fbuffers.width);
00947 printf (" > Depth : %d\n", this->fbuffers.depth);
00948 printf (" > BPL : %d\n", this->fbuffers.bytesperline);
00949 }
00950 }
00951 }
00952
00953 if (-1==ioctl(this->fd,VIDIOCGWIN,&this->videowin))
00954 {
00955 printf(" > ERRO: V4L function VIDIOCGWIN.\n");
00956 }
00957 else
00958 {
00959 videowin.x = 0;
00960 videowin.y = 0;
00961 videowin.width = this->width;
00962 videowin.height = this->height;
00963 videowin.clipcount = 0;
00964 videowin.chromakey = 1;
00965 videowin.flags = VIDEO_CLIPMAP_SIZE;
00966
00967 if (-1==ioctl(this->fd,VIDIOCSWIN,&this->videowin))
00968 {
00969 printf(" > ERRO: V4L function VIDIOCSWIN.\n");
00970 }
00971 }
00972
00973 if(-1 == ioctl(this->fd, VIDIOCGCHAN,&this->vch))
00974 {
00975 printf(" > ERRO: V4L function VIDIOCGCHAN.\n");
00976 exit(-1);
00977 }
00978 else
00979 {
00980 this->vch.norm = this->lintVideoMode;
00981 this->vch.tuners = this->llongTuners;
00982
00983 if(-1 == ioctl(this->fd, VIDIOCSCHAN,&this->vch))
00984 {
00985 printf(" > ERRO: V4L function VIDIOCSCHAN.\n");
00986 exit(-1);
00987 }
00988 else
00989 {
00990
00991 if(this->debug)
00992 {
00993 printf(" > V4L function VIDIOCSCHAN.\n");
00994 printf(" > Name : %s\n", this->vch.name);
00995 printf(" > Channel : %i\n", this->vch.channel);
00996 printf(" > Tuners : %i\n", this->vch.tuners);
00997 printf(" > Flags : %i\n", this->vch.flags);
00998 printf(" > Type : %i\n", this->vch.type);
00999 printf(" > Norm : %i\n", this->vch.norm);
01000 }
01001 }
01002
01003 }
01004
01005 if(this->map_buffer.format == 0)
01006 {
01007 if(!strcmp(this->vch.name,"Webcam"))
01008 {
01009 this->SetHardwareWebCam();
01010 }
01011 else
01012 {
01013 this->SetHardwareCaptureCard();
01014
01015 }
01016
01017 }
01018
01019
01020
01021
01022 if(-1 == ioctl(this->fd, VIDIOCGTUNER,&this->vtuner))
01023 {
01024 printf(" > ERRO: V4L function VIDIOCGTUNER.\n");
01025 }
01026 else
01027 {
01028 if(-1 == ioctl(this->fd, VIDIOCSTUNER,&this->vtuner))
01029 {
01030 printf(" > ERRO: V4L function VIDIOCSTUNER.\n");
01031 }
01032 else
01033 {
01034
01035 if(this->debug)
01036 {
01037 printf(" > V4L function VIDIOCSTUNER.\n");
01038 printf(" > Tuner : %i\n", this->vtuner.tuner);
01039 printf(" > Name : %s\n", this->vtuner.name);
01040 printf(" > Low frequency : %i\n", this->vtuner.rangelow);
01041 printf(" > High frequency : %i\n", this->vtuner.rangehigh);
01042 printf(" > Flags : %i\n", this->vtuner.flags);
01043 printf(" > Mode : %i\n", this->vtuner.mode);
01044 printf(" > Signal : %i\n", this->vtuner.signal);
01045 }
01046 }
01047
01048 }
01049
01050
01051
01052 if (-1==ioctl( this->fd, VIDIOCGPICT, &this->pic ))
01053 {
01054 printf(" > ERRO: V4L function VIDIOCGPICT.\n");
01055 }
01056 else
01057 {
01058 this->pic.palette = this->lintVideoFormat;
01059 this->pic.depth = this->depth;
01060
01061 if (-1==ioctl( this->fd, VIDIOCSPICT, &this->pic ))
01062 {
01063 printf(" > ERRO: V4L function VIDIOCSPICT.\n");
01064 }
01065 else
01066 {
01067 if (this->debug)
01068 {
01069 printf(" > V4L function VIDIOCSPICT.\n");
01070 printf(" > Brightness : %d \n", this->pic.brightness/256 );
01071 printf(" > Hue : %d\n", this->pic.hue/256);
01072 printf(" > Colour : %d\n", this->pic.colour/256 );
01073 printf(" > Contrast : %d \n", this->pic.contrast/256 );
01074 printf(" > Whiteness : %d\n", this->pic.whiteness/256 );
01075 printf(" > Depth : %d\n", this->pic.depth );
01076 printf(" > Palette : %d \n", this->pic.palette );
01077
01078 }
01079 }
01080 }
01081 if(this->AudioEnabled)
01082 {
01083 if (-1 == ioctl(this->fd,VIDIOCGAUDIO, &this->audio))
01084 {
01085 printf(" > ERRO: V4L function VIDIOCGAUDIO.\n");
01086 }
01087 else
01088 {
01089 this->audio.flags = VIDEO_AUDIO_VOLUME;
01090 this->audio.volume = 30000;
01091 if (-1 == ioctl(this->fd,VIDIOCSAUDIO, &this->audio))
01092 {
01093 printf(" > ERRO: V4L function VIDIOCSAUDIO.\n");
01094 }
01095 }
01096 }
01097
01098
01099 if (-1 == ioctl(this->fd,VIDIOCGMBUF,&this->buffers))
01100 {
01101 printf(" > ERRO: V4L function VIDIOCGMBUF.\n");
01102 exit(-1);
01103 }
01104
01105
01106 if (this->debug)
01107 {
01108 printf(" > V4L function VIDIOCGMBUF.\n");
01109 printf(" > Size : %d\n",this->buffers.size);
01110 printf(" > Frames : %d\n",this->buffers.frames);
01111 }
01112
01113 this->map = (unsigned char *)mmap(0,buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,this->fd,0);
01114 if (this->map == NULL)
01115 {
01116 printf(" > ERRO: Mmap is NULL.\n");
01117 exit(-1);
01118 }
01119 this->last_map = (unsigned char *)malloc(this->buffers.size);
01120 this->v4l_convert_buf = (unsigned char *)malloc(this->buffers.size);
01121 this->arqPPM = (char *)malloc((this->width*this->height*3)+15);
01122
01123 this->map_buffer.width = this->width;
01124 this->map_buffer.height = this->height;
01125 this->map_buffer.format = this->pic.palette;
01126 this->map_buffer.frame = 0;
01127 if (-1 == ioctl(this->fd, VIDIOCMCAPTURE, &map_buffer))
01128 {
01129 printf(" > ERRO: Grabber chip error sync.\n");
01130 exit(-1);
01131 }
01132
01133 if (this->debug)
01134 {
01135 printf(" > V4L function VIDIOCMCAPTURE.\n");
01136 printf(" > Width : %d\n",this->map_buffer.width);
01137 printf(" > Height : %d\n",this->map_buffer.height);
01138 printf(" > Format : %d\n",this->map_buffer.format);
01139 printf(" > Frame : %d\n",this->map_buffer.frame);
01140 }
01141
01142 }
01143
01144
01145
01146
01147
01148
01149
01150
01151
01152
01153 void CAPTURE::VideoCreate(void)
01154 {
01155 this->Open();
01156
01157 }
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169 void CAPTURE::VideoTerminate(void)
01170 {
01171 if(this->AudioEnabled)
01172 {
01173 this->audio.flags = VIDEO_AUDIO_MUTE;
01174 this->audio.volume = 0;
01175 ioctl(this->fd,VIDIOCSAUDIO, &this->audio);
01176 }
01177 close(this->fd);
01178 SDL_Quit();
01179 exit(0);
01180
01181 }
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193 void CAPTURE::InicializeWin(void)
01194 {
01195 SDL_Init(SDL_INIT_VIDEO );
01196
01197
01198
01199 this->screen = SDL_SetVideoMode(this->widthWin, this->heightWin, this->depth,
01200 SDL_HWSURFACE);
01201
01202 if ( this->screen == NULL )
01203 {
01204 fprintf(stderr, " > SDL Error: Couldn't set %dx%d video mode: %s\n",
01205 this->width,this->height, SDL_GetError());
01206 exit(-1);
01207 }
01208 SDL_WM_SetCaption("NETi TECNOLOGIA", NULL);
01209 this->TempRect.x = 0;
01210 this->TempRect.y = 0;
01211 this->TempRect.w = this->widthWin;
01212 this->TempRect.h = this->heightWin;
01213
01214 printf( " > SDL Created %dx%d with %d color Surface Draw.\n",this->width, this->height,this->depth);
01215
01216 this->draw_surface = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_DOUBLEBUF,
01217 this->widthWin, this->heightWin, this->depth,
01218 screen->format->Rmask, screen->format->Gmask,
01219 screen->format->Bmask, screen->format->Amask);
01220 this->colorTransparent = SDL_MapRGB(this->draw_surface->format,SRCcolorTransparent.r,
01221 SRCcolorTransparent.g,SRCcolorTransparent.b);
01222
01223 SDL_SetColorKey(this->draw_surface,SDL_SRCCOLORKEY,this->colorTransparent);
01224 SDL_FillRect(this->draw_surface,&this->TempRect, this->colorTransparent);
01225
01226 this->text_surface = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_DOUBLEBUF,
01227 this->widthWin, this->heightWin, this->depth,
01228 screen->format->Rmask, screen->format->Gmask,
01229 screen->format->Bmask, screen->format->Amask);
01230 SDL_SetColorKey(this->text_surface,SDL_SRCCOLORKEY,this->colorTransparent);
01231 SDL_FillRect(this->text_surface,&this->TempRect, this->colorTransparent);
01232
01233 this->TempRect.w = this->width/2;
01234 this->TempRect.h = this->height/2;
01235
01236
01237 this->video_surface = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_DOUBLEBUF,
01238 this->TempRect.w, this->TempRect.h, this->depth,
01239 screen->format->Rmask, screen->format->Gmask,
01240 screen->format->Bmask, screen->format->Amask);
01241 SDL_SetColorKey( this->video_surface,SDL_SRCCOLORKEY,this->colorTransparent);
01242 SDL_FillRect(this->video_surface,&this->TempRect, this->colorTransparent);
01243
01244
01245 this->TempRect.w = this->width;
01246 this->TempRect.h = this->height;
01247
01248
01249
01250 this->zoomout_surface = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_DOUBLEBUF,
01251 this->TempRect.w, this->TempRect.h, this->depth,
01252 screen->format->Rmask, screen->format->Gmask,
01253 screen->format->Bmask, screen->format->Amask);
01254 SDL_SetColorKey( this->zoomout_surface,SDL_SRCCOLORKEY,this->colorTransparent);
01255 SDL_FillRect(this->zoomout_surface,&this->TempRect, this->colorTransparent);
01256 }
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268 void CAPTURE::ClearSurface(TypeSurface lsurfaceScreen ,bool lboolSurface)
01269 {
01270 this->TempRect.x = 1;
01271 this->TempRect.y = 1;
01272
01273 switch(lsurfaceScreen)
01274 {
01275 case DRAW:
01276 { this->UseDraw = lboolSurface;
01277 this->TempRect.w = this->draw_surface->w;
01278 this->TempRect.h = this->draw_surface->h;
01279 SDL_FillRect(this->draw_surface,&this->TempRect, this->colorTransparent);
01280 break;
01281 }
01282 case TEXTS:
01283 { this->UseText = lboolSurface;
01284 this->TempRect.w = this->text_surface->w;
01285 this->TempRect.h = this->text_surface->h;
01286 SDL_FillRect(this->text_surface,&this->TempRect, this->colorTransparent);
01287 break;
01288 }
01289 case ZOOM:
01290 { this->UseZoomOut = lboolSurface;
01291 this->TempRect.w = this->zoomout_surface->w;
01292 this->TempRect.h = this->zoomout_surface->h;
01293 SDL_FillRect(this->zoomout_surface,&this->TempRect, this->colorTransparent);
01294 break;
01295 }
01296 case VIDEO:
01297 { this->UseVideo = lboolSurface;
01298 this->TempRect.w = this->video_surface->w;
01299 this->TempRect.h = this->video_surface->h;
01300 SDL_FillRect(this->video_surface,&this->TempRect, this->colorTransparent);
01301 break;
01302 }
01303
01304
01305 }
01306 }
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317 void CAPTURE::ClearSurface(TypeSurface lsurfaceScreen ,int lintX, int lintY, int lintW, int lintH)
01318 {
01319 this->TempRect.x = lintX;
01320 this->TempRect.y = lintY;
01321
01322 switch(lsurfaceScreen)
01323 {
01324 case VIDEO:
01325 {
01326 this->TempRect.w = lintW;
01327 this->TempRect.h = lintH;
01328 SDL_FillRect(this->video_surface,&this->TempRect, this->colorTransparent);
01329 break;
01330 }
01331 case TEXTS:
01332 {
01333 this->TempRect.w = lintW;
01334 this->TempRect.h = lintH;
01335 SDL_FillRect(this->text_surface,&this->TempRect, this->colorTransparent);
01336 break;
01337 }
01338 case DRAW:
01339 {
01340 this->TempRect.w = lintW;
01341 this->TempRect.h = lintH;
01342 SDL_FillRect(this->draw_surface,&this->TempRect, this->colorTransparent);
01343 break;
01344 }
01345 case ZOOM:
01346 {
01347 this->TempRect.w = lintW;
01348 this->TempRect.h = lintH;
01349 SDL_FillRect(this->zoomout_surface,&this->TempRect, this->colorTransparent);
01350 break;
01351 }
01352
01353
01354 }
01355 }
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367 void CAPTURE::Show(void)
01368 {
01369 this->thread = new pthread_t();
01370 if (pthread_create(this->thread, NULL, (void *(*)(void *))ThreadAoVivo, this))
01371 {
01372 printf(" > Error: creating the first thread\n");
01373 exit(-1);
01374 }
01375
01376 if (this->debug)
01377 {
01378 printf(" > Result of MultThread.\n");
01379 printf(" > Thread ok!\n");
01380 }
01381 }
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392 void CAPTURE::VideoInicialize(void)
01393 {
01394 this->Show();
01395 }
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406 void CAPTURE::WaitForVideo(void)
01407 {
01408 pthread_join(*this->thread, 0);
01409 }
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420 void CAPTURE::WriteText(int lintx, int linty, char *lcharText,int lintSIZE, bool lboolSHADOW)
01421 {
01422 this->UseText = false;
01423
01424 if (this->debug)
01425 {
01426 printf(" > WriteText(%d,%d,%s,%d,%d)\n",lintx, linty, lcharText,lintSIZE,lboolSHADOW);
01427 }
01428
01429 TTF_Init();
01430 SDL_Surface *Limage;
01431 SDL_Surface *LimageShadow;
01432 SDL_Surface *LimageR;
01433
01434 int intTMPR, intTMPG, intTMPB;
01435
01436
01437 this->NameFont= TTF_OpenFont( this->fontName,lintSIZE);
01438 TTF_SetFontStyle(this->NameFont, TTF_STYLE_NORMAL);
01439
01440 if(lboolSHADOW)
01441 {
01442
01443
01444
01445
01446
01447 LimageShadow = TTF_RenderText_Solid(this->NameFont,lcharText,(SDL_Color){1,1,1});
01448
01449
01450 this->TempRect.x = lintx+2;
01451 this->TempRect.y = linty+2;
01452 this->TempRect.w = LimageShadow->w;
01453 this->TempRect.h = LimageShadow->h;
01454
01455 if(this->RotateText!=0)
01456 {
01457 LimageR = rotozoomSurface(LimageShadow, this->RotateText, 1,SMOOTHING_ON);
01458 this->TempRect.w = LimageR->h;
01459 this->TempRect.h = LimageR->w;
01460
01461 SDL_BlitSurface(LimageR,NULL,this->text_surface,&TempRect);
01462 }
01463 else
01464 {
01465 SDL_BlitSurface(LimageShadow,NULL,this->text_surface,&TempRect);
01466 }
01467
01468 SDL_FreeSurface(LimageShadow);
01469 }
01470
01471
01472 Limage = TTF_RenderText_Solid(this->NameFont,lcharText, this->colorFont);
01473 TTF_CloseFont( this->NameFont );
01474 TTF_Quit();
01475
01476 this->xText = lintx;
01477 this->yText = linty;
01478
01479 this->TempRect.x =this->xText;
01480 this->TempRect.y =this->yText;
01481 this->TempRect.w = Limage->w;
01482 this->TempRect.h = Limage->h;
01483
01484 if(this->RotateText!=0)
01485 {
01486 LimageR = rotozoomSurface(Limage, this->RotateText, 1,SMOOTHING_ON);
01487 this->TempRect.w = LimageR->h;
01488 this->TempRect.h = LimageR->w;
01489
01490 SDL_BlitSurface(LimageR,NULL,this->text_surface,&TempRect);
01491 SDL_FreeSurface(LimageR);
01492 }
01493 else
01494 {
01495 SDL_BlitSurface(Limage,NULL,this->text_surface,&TempRect);
01496 }
01497
01498 SDL_UpdateRect(this->text_surface, 0, 0, 0, 0);
01499 SDL_FreeSurface(Limage);
01500 this->UseText = true;
01501 }
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511 void CAPTURE::WriteText(int lintx, int linty, char *lcharText)
01512 {
01513 this->UseText = false;
01514
01515 if (this->debug)
01516 {
01517 printf(" > WriteText(%d,%d,%s)\n",lintx, linty, lcharText);
01518 }
01519 TTF_Init();
01520
01521 SDL_Surface *Limage;
01522 SDL_Surface *LimageR;
01523
01524 this->NameFont= TTF_OpenFont( this->fontName, this->size_font );
01525 TTF_SetFontStyle(this->NameFont, TTF_STYLE_NORMAL);
01526 Limage = TTF_RenderText_Solid(this->NameFont,lcharText, this->colorFont);
01527 TTF_CloseFont( this->NameFont );
01528 TTF_Quit();
01529
01530 this->xText = lintx;
01531 this->yText = linty;
01532
01533 this->TempRect.x =this->xText;
01534 this->TempRect.y =this->yText;
01535 this->TempRect.w = Limage->w;
01536 this->TempRect.h = Limage->h;
01537
01538 if(this->RotateText!=0)
01539 {
01540 LimageR = rotozoomSurface(Limage, this->RotateText, 1,SMOOTHING_ON);
01541
01542 this->TempRect.w = LimageR->h;
01543 this->TempRect.h = LimageR->w;
01544
01545 SDL_BlitSurface(LimageR,NULL,this->text_surface,&TempRect);
01546 SDL_FreeSurface(LimageR);
01547
01548 }
01549 else
01550 {
01551 SDL_BlitSurface(Limage,NULL,this->text_surface,&TempRect);
01552 }
01553
01554 SDL_UpdateRect(this->text_surface, 0, 0, 0, 0);
01555 SDL_FreeSurface(Limage);
01556
01557 this->UseText = true;
01558 }
01559
01560
01561
01562
01563
01564
01565
01566
01567
01568
01569 void CAPTURE::Circle(int lintx, int linty,int lintrad, int lintR, int lintG,int lintB, TypeSurface lsurfaceScreen )
01570 {
01571 switch(lsurfaceScreen)
01572 {
01573 case TEXTS:
01574 {
01575 this->UseText = false;
01576 circleRGBA(this->text_surface,lintx, linty, lintrad, lintR, lintG, lintB, 255);
01577 this->UseText = true;
01578 break;
01579 }
01580 case DRAW:
01581 {
01582 this->UseDraw = false;
01583 circleRGBA(this->draw_surface,lintx, linty, lintrad, lintR, lintG, lintB, 255);
01584 this->UseDraw = true;
01585 break;
01586 }
01587 case ZOOM:
01588 {
01589 this->UseZoomOut = false;
01590 circleRGBA(this->zoomout_surface,lintx, linty, lintrad, lintR, lintG, lintB, 255);
01591 this->UseZoomOut = true;
01592 break;
01593 }
01594 case VIDEO:
01595 {
01596 this->UseVideo = false;
01597 circleRGBA(this->video_surface,lintx, linty, lintrad, lintR, lintG, lintB, 255);
01598 this->UseVideo = true;
01599 break;
01600 }
01601
01602 }
01603 }
01604
01605
01606
01607
01608
01609
01610
01611
01612
01613
01614
01615 void CAPTURE::Line(int lintx1, int linty1,int lintx2, int linty2, int lintR, int lintG,int lintB, TypeSurface lsurfaceScreen)
01616 {
01617 switch(lsurfaceScreen)
01618 {
01619 case TEXTS:
01620 {
01621 this->UseText = false;
01622 lineRGBA(this->text_surface,lintx1, linty1,lintx2, linty2, lintR, lintG, lintB, 255);
01623 this->UseText = true;
01624 break;
01625 }
01626 case DRAW:
01627 {
01628 this->UseDraw = false;
01629 lineRGBA(this->draw_surface,lintx1, linty1,lintx2, linty2, lintR, lintG, lintB, 255);
01630 this->UseDraw = true;
01631 break;
01632 }
01633 case ZOOM:
01634 {
01635 this->UseZoomOut = false;
01636 lineRGBA(this->zoomout_surface,lintx1, linty1,lintx2, linty2, lintR, lintG, lintB, 255);
01637 this->UseZoomOut = true;
01638 break;
01639 }
01640 case VIDEO:
01641 {
01642 this->UseVideo = false;
01643 lineRGBA(this->video_surface,lintx1, linty1,lintx2, linty2, lintR, lintG, lintB, 255);
01644 this->UseVideo = true;
01645 break;
01646 }
01647
01648 }
01649 }
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659 void CAPTURE::RectangleZoom(int lintx1, int linty1,int lintx2, int linty2, int lintR, int lintG,int lintB )
01660 {
01661
01662 rectangleRGBA(this->zoomout_surface,lintx1, linty1,lintx2, linty2, lintR, lintG, lintB, 255);
01663
01664
01665 }
01666
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676 void CAPTURE::Rectangle(int lintx1, int linty1,int lintx2, int linty2, int lintR, int lintG,int lintB, TypeSurface lsurfaceScreen)
01677 {
01678 switch(lsurfaceScreen)
01679 {
01680 case TEXTS:
01681 {
01682 this->UseText = false;
01683 rectangleRGBA(this->text_surface,lintx1, linty1,lintx2, linty2, lintR, lintG, lintB, 255);
01684 this->UseText = true;
01685 break;
01686 }
01687 case DRAW:
01688 {
01689 this->UseDraw = false;
01690 rectangleRGBA(this->draw_surface,lintx1, linty1,lintx2, linty2, lintR, lintG, lintB, 255);
01691 this->UseDraw = true;
01692 break;
01693 }
01694 case ZOOM:
01695 {
01696 this->UseZoomOut = false;
01697 rectangleRGBA(this->zoomout_surface,lintx1, linty1,lintx2, linty2, lintR, lintG, lintB, 255);
01698 this->UseZoomOut = true;
01699 break;
01700 }
01701 case VIDEO:
01702 {
01703 this->UseVideo = false;
01704 rectangleRGBA(this->video_surface,lintx1, linty1,lintx2, linty2, lintR, lintG, lintB, 255);
01705 this->UseVideo = true;
01706 break;
01707 }
01708
01709 }
01710
01711 }
01712
01713
01714
01715
01716
01717
01718
01719
01720
01721 void CAPTURE::RectangleFill(int lintx1, int linty1,int lintx2, int linty2, int lintR, int lintG,int lintB, TypeSurface lsurfaceScreen)
01722 {
01723 switch(lsurfaceScreen)
01724 {
01725 case TEXTS:
01726 {
01727 this->UseText = false;
01728 boxRGBA(this->text_surface,lintx1, linty1,lintx2, linty2, lintR, lintG, lintB, 255);
01729 this->UseText = true;
01730 break;
01731 }
01732 case DRAW:
01733 {
01734 this->UseDraw = false;
01735 boxRGBA(this->draw_surface,lintx1, linty1,lintx2, linty2, lintR, lintG, lintB, 255);
01736 this->UseDraw = true;
01737 break;
01738 }
01739 case ZOOM:
01740 {
01741 this->UseZoomOut = false;
01742 boxRGBA(this->zoomout_surface,lintx1, linty1,lintx2, linty2, lintR, lintG, lintB, 255);
01743 this->UseZoomOut = true;
01744 break;
01745 }
01746 case VIDEO:
01747 {
01748 this->UseVideo = false;
01749 boxRGBA(this->video_surface,lintx1, linty1,lintx2, linty2, lintR, lintG, lintB, 255);
01750 this->UseVideo = true;
01751 break;
01752 }
01753 }
01754 }
01755
01756
01757
01758
01759
01760
01761
01762
01763 void CAPTURE::Progress(char *lcharText,int lintPROGRESS, int lintTOTAL)
01764 {
01765 int intTMPR, intTMPG, intTMPB;
01766
01767 intTMPR = this->colorFont.r;
01768 intTMPG = this->colorFont.g;
01769 intTMPB = this->colorFont.b;
01770 this->SetColorFont(this->colorFontVideo.r,this->colorFontVideo.g,this->colorFontVideo.b);
01771
01772 ClearSurface(TEXTS,this->left,this->top,this->width,this->height);
01773
01774
01775 if(this->RotateText!=0)
01776 {
01777 int lintY1 = this->top+10;
01778 int lintY2 = this->top+((lintPROGRESS*int(this->height -10))/lintTOTAL);
01779 WriteText(this->left+10,lintY1, lcharText, 30, true);
01780 this->UseText = false;
01781 boxRGBA(this->text_surface,this->left+43,lintY1-2,this->left+77,lintY2+2,0,0,0,255);
01782 boxRGBA(this->text_surface,this->left+45,lintY1,this->left+75,lintY2,255,255,255,255);
01783 this->UseText = true;
01784 }
01785 else
01786 {
01787 int lintX1 = this->left+10;
01788 int lintX2 = this->left+((lintPROGRESS*int(this->width -10))/lintTOTAL);
01789 WriteText(lintX1,this->top+10, lcharText, 30, true);
01790
01791 this->UseText = false;
01792 boxRGBA(this->text_surface,lintX1-2,this->top+43,lintX2+2,this->top+77,0,0,0,255);
01793 boxRGBA(this->text_surface,lintX1,this->top+45,lintX2,this->top+75,255,255,255,255);
01794 this->UseText = true;
01795 }
01796
01797 this->SetColorFont(intTMPR,intTMPG,intTMPB);
01798
01799 }
01800
01801
01802
01803
01804
01805
01806
01807
01808
01809
01810 void CAPTURE::LoadBMP(char * lcharBMP)
01811 {
01812 this->UseDraw = false;
01813 SDL_Surface *Limage;
01814 Limage = SDL_LoadBMP(lcharBMP);
01815 SDL_SetColorKey(Limage,SDL_RLEACCEL,this->colorTransparent);
01816 SDL_BlitSurface(Limage, NULL, this->draw_surface, NULL);
01817 SDL_UpdateRect(this->draw_surface, 0, 0, 0, 0);
01818 SDL_FreeSurface(Limage);
01819 this->UseDraw = true;
01820 }
01821
01822
01823
01824
01825
01826
01827
01828
01829
01830
01831 void CAPTURE::ZoomOut(bool lboolStatus)
01832 {
01833
01834 this->TempRect.x=1;
01835 this->TempRect.y=1;
01836 this->TempRect.w=this->width/2;
01837 this->TempRect.h =this->height/2;
01838
01839 this->UseZoomOut = false;
01840 if(lboolStatus)
01841 {
01842 SDL_Surface *Limage;
01843 Limage = zoomSurface(this->offscreen, 0.5,0.5, 1);
01844
01845 SDL_BlitSurface(Limage, NULL, this->zoomout_surface, NULL);
01846 SDL_UpdateRect(this->zoomout_surface, 0, 0, 0, 0);
01847 this->UseZoomOut = true;
01848 SDL_FreeSurface(Limage);
01849 }
01850 }
01851
01852
01853
01854
01855
01856
01857
01858
01859
01860
01861 void CAPTURE::SetFormatPalette(int lFormat)
01862 {
01863 this->lintVideoFormat = lFormat;
01864 this->map_buffer.format = lFormat;
01865 this->pic.palette = lFormat;
01866 }
01867
01868
01869
01870
01871
01872
01873
01874
01875
01876
01877 void CAPTURE::SetInputTelevision(int lVideoMode)
01878 {
01879 this->lintVideoMode = lVideoMode;
01880 vch.channel = 0;
01881 vch.norm = lVideoMode;
01882 vch.type = VIDEO_TYPE_TV;
01883 vch.flags = VIDEO_VC_TUNER |VIDEO_VC_AUDIO;
01884
01885
01886 }
01887
01888
01889
01890
01891
01892
01893
01894
01895
01896
01897 void CAPTURE::SetInputCamera(int lInput, int lVideoMode)
01898 {
01899 this->lintVideoMode = lVideoMode;
01900 vch.channel = lInput;
01901 vch.norm = lVideoMode;
01902 vch.type = VIDEO_TYPE_CAMERA;
01903 }
01904
01905
01906
01907
01908
01909
01910
01911
01912
01913
01914
01915 void CAPTURE::SetTransparent(int lintR, int lintG,int lintB )
01916 {
01917 this->SRCcolorTransparent.r =lintR;
01918 this->SRCcolorTransparent.g =lintG;
01919 this->SRCcolorTransparent.b =lintB;
01920 }
01921
01922
01923
01924
01925
01926
01927
01928
01929
01930
01931 void CAPTURE::SetKeyZoomOutOn(SDLKey Lkey)
01932 {
01933 this->KeyZoomOutOn=Lkey;
01934 }
01935
01936
01937
01938
01939
01940
01941
01942
01943
01944
01945 void CAPTURE::SetKeyZoomOutOff(SDLKey Lkey)
01946 {
01947 this->KeyZoomOutOff=Lkey;
01948 }
01949
01950
01951
01952
01953
01954
01955
01956
01957
01958
01959 void CAPTURE::SetKeyFullScreeen(SDLKey Lkey)
01960 {
01961 this->KeyFullScreeen=Lkey;
01962 }
01963
01964
01965
01966
01967
01968
01969
01970
01971
01972
01973 void CAPTURE::SetKeySaveFrame(SDLKey Lkey)
01974 {
01975 this->KeySaveFrame=Lkey;
01976 }
01977
01978
01979
01980
01981
01982
01983
01984
01985
01986
01987 void CAPTURE::SetKeyQuit(SDLKey Lkey)
01988 {
01989 this->KeyQuit=Lkey;
01990 }
01991
01992
01993
01994
01995
01996
01997
01998
01999
02000
02001 void CAPTURE::SetKeyVideoOn(SDLKey Lkey)
02002 {
02003 this->KeyVideoOn=Lkey;
02004 }
02005
02006
02007
02008
02009
02010
02011
02012
02013 void CAPTURE::ShowMouse(void)
02014 {
02015 SDL_ShowCursor(SDL_ENABLE);
02016 }
02017
02018
02019
02020
02021
02022
02023
02024
02025
02026 void CAPTURE::HideMouse(void)
02027 {
02028 SDL_ShowCursor(SDL_DISABLE);
02029 }
02030
02031
02032
02033
02034
02035
02036
02037
02038
02039 void CAPTURE::DefinePositionButton(int lintBUTTON,int lintX, int lintY, int lintW, int lintH)
02040 {
02041 this->gButtons[lintBUTTON].x = lintX;
02042 this->gButtons[lintBUTTON].y = lintY;
02043 this->gButtons[lintBUTTON].w = lintW;
02044 this->gButtons[lintBUTTON].h = lintH;
02045 }
02046
02047
02048
02049
02050
02051
02052
02053
02054
02055 int CAPTURE::FindButton(int lintX, int lintY)
02056 {
02057 int lreturn = -1;
02058 for (int i=MAX_BUTTON; i>=0; i--)
02059 {
02060 if(((lintX>this->gButtons[i].x) &&
02061 (lintX<(this->gButtons[i].x+this->gButtons[i].w))) &&
02062 ((lintY>this->gButtons[i].y) &&
02063 (lintY<(this->gButtons[i].y+this->gButtons[i].h))))
02064 lreturn = i;
02065
02066 }
02067 return lreturn;
02068 }
02069
02070
02071
02072
02073
02074
02075
02076
02077
02078 int CAPTURE::GetLastButton(void)
02079 {
02080 this->mutex = SDL_CreateMutex();
02081 this->cond = SDL_CreateCond();
02082
02083 SDL_LockMutex(this->mutex);
02084 SDL_CondWait(this->cond, this->mutex);
02085 SDL_UnlockMutex(this->mutex);
02086
02087 return this->LastButton;
02088 }
02089
02090
02091
02092
02093
02094
02095
02096
02097
02098 int CAPTURE::TouchScreen(bool lboolSTATUS)
02099 {
02100 if(!lboolSTATUS)
02101 this->ScanButtons = false;
02102 else
02103 {
02104 this->LastButton = -1;
02105 this->ScanButtons = true;
02106 }
02107
02108 }
02109
02110
02111
02112
02113
02114
02115
02116
02117
02118 void CAPTURE::SelectContrast(int lintVALUE)
02119 {
02120 this->pic.contrast = lintVALUE;
02121 if(this->pic.contrast>64500)
02122 this->pic.contrast=64500;
02123
02124 Progress("Contrast",this->pic.contrast,64500);
02125
02126 if (-1==ioctl( this->fd, VIDIOCSPICT, &this->pic ))
02127 printf(" > ERRO: V4L function ioctl VIDIOCSPICT.\n");
02128
02129
02130 }
02131
02132
02133
02134
02135
02136
02137
02138
02139
02140 void CAPTURE::SelectBrightness(int lintVALUE)
02141 {
02142 this->pic.brightness = lintVALUE;
02143 if(this->pic.brightness>64500)
02144 this->pic.brightness=64500;
02145
02146 Progress("Brightness",this->pic.brightness,64500);
02147
02148 if (-1==ioctl( this->fd, VIDIOCSPICT, &this->pic ))
02149 printf(" > ERRO: V4L function ioctl VIDIOCSPICT.\n");
02150
02151 }
02152
02153
02154
02155
02156
02157
02158
02159
02160
02161 void CAPTURE::SelectColor(int lintVALUE)
02162 {
02163
02164
02165 this->pic.colour = lintVALUE;
02166 if(this->pic.colour>64500)
02167 this->pic.colour=64500;
02168
02169 Progress("Color",this->pic.colour,64500);
02170
02171 if (-1==ioctl( this->fd, VIDIOCSPICT, &this->pic ))
02172 printf(" > ERRO: V4L function ioctl VIDIOCSPICT.\n");
02173 }
02174
02175
02176
02177
02178
02179
02180
02181
02182
02183 void CAPTURE::SelectHue(void)
02184 {
02185 this->adjustVIDEO = 1;
02186 Progress("Hue",this->pic.brightness,65535);
02187 }
02188
02189
02190
02191
02192
02193
02194
02195
02196
02197
02198 void CAPTURE::SelectAdjust(int lintMOVEMENT)
02199 {
02200 this->adjustVIDEO += lintMOVEMENT;
02201
02202 if(this->adjustVIDEO>3)
02203 this->adjustVIDEO = 0;
02204
02205 if(this->adjustVIDEO<0)
02206 this->adjustVIDEO = 3;
02207
02208 switch(this->adjustVIDEO)
02209 {
02210 case 0:
02211 {
02212 Progress("Brightness",this->pic.brightness,65535);
02213 break;
02214 }
02215 case 1:
02216 {
02217 Progress("Hue",this->pic.hue,65500);
02218 break;
02219 }
02220 case 2:
02221 {
02222 Progress("Color",this->pic.colour,65535);
02223 break;
02224 }
02225 case 3:
02226 {
02227 Progress("Contrast",this->pic.contrast,65535);
02228 break;
02229 }
02230
02231 }
02232 }
02233
02234
02235
02236
02237
02238
02239
02240
02241
02242
02243 void CAPTURE::AdjustVideo(int lintMOVEMENT)
02244 {
02245 if(!this->imageAdjust)
02246 {
02247 this->imageAdjust = true;
02248 lintMOVEMENT *= 1000;
02249
02250 switch(this->adjustVIDEO)
02251 {
02252 case 0:
02253 {
02254 this->pic.brightness += lintMOVEMENT;
02255 if(this->pic.brightness>64500)
02256 this->pic.brightness=64500;
02257
02258 if(this->pic.brightness<1500)
02259 this->pic.brightness=1500;
02260 Progress("Brightness",this->pic.brightness,65535);
02261 printf("%d\n",this->pic.brightness);
02262 break;
02263 }
02264 case 1:
02265 {
02266 this->pic.hue += lintMOVEMENT;
02267 if(this->pic.hue>64500)
02268 this->pic.hue=64500;
02269
02270 if(this->pic.hue<1500)
02271 this->pic.hue=1500;
02272 Progress("Hue",this->pic.hue,65500);
02273 break;
02274 }
02275 case 2:
02276 {
02277 this->pic.colour += lintMOVEMENT;
02278 if(this->pic.colour>64500)
02279 this->pic.colour=64500;
02280
02281 if(this->pic.colour<1500)
02282 this->pic.colour=1500;
02283 Progress("Color",this->pic.colour,65535);
02284 break;
02285 }
02286 case 3:
02287 {
02288 this->pic.contrast += lintMOVEMENT;
02289 if(this->pic.contrast>64500)
02290 this->pic.contrast=64500;
02291
02292 if(this->pic.contrast<1500)
02293 this->pic.contrast=1500;
02294 Progress("Contrast",this->pic.contrast,65535);
02295 break;
02296 }
02297
02298 }
02299 if (-1==ioctl( this->fd, VIDIOCSPICT, &this->pic ))
02300 {
02301 printf(" > ERRO: V4L function ioctl VIDIOCSPICT.\n");
02302
02303 }
02304 this->imageAdjust = false;
02305 }
02306 }
02307
02308
02309
02310
02311
02312
02313
02314
02315 void CAPTURE::SetColorFont( int lintR, int lintG,int lintB )
02316 {
02317 this->colorFont.r = lintR;
02318 this->colorFont.g = lintG;
02319 this->colorFont.b = lintB;
02320
02321 }
02322
02323
02324
02325
02326
02327
02328
02329
02330
02331
02332 std::string CAPTURE::GetTouch(int lintX, int lintY,int linSize_font, bool lboolShadow)
02333 {
02334 std::string gstringTXT ="";
02335 std::string lstringBUFFER ="";
02336
02337 while(this->LastButton != 11)
02338 { ToString(this->GetLastButton());
02339 if(this->LastButton == 10)
02340 {
02341 lstringBUFFER = "";
02342 this->ClearSurface(TEXTS);
02343 }
02344 else
02345 {
02346 if((this->LastButton != 11) && (this->LastButton != -1))
02347 {
02348 lstringBUFFER += ToString(this->LastButton);
02349
02350 if((lstringBUFFER.size()==1) && (gstringTXT.empty()))
02351 this->ClearSurface(TEXTS);
02352
02353
02354 gstringTXT = lstringBUFFER;
02355 this->WriteText(lintX,lintY,(char *)gstringTXT.c_str(),linSize_font,lboolShadow);
02356 }
02357 usleep(1);
02358 }
02359
02360 if(gstringTXT.size() > (this->MaxTextTouch))
02361 {
02362 lstringBUFFER = "";
02363 this->ClearSurface(TEXTS);
02364 }
02365
02366 }
02367 this->LastButton = -1;
02368
02369 printf(" > Result of GetTouch: %s\n", lstringBUFFER.c_str());
02370
02371 return lstringBUFFER;
02372
02373 }
02374
02375
02376
02377
02378
02379
02380
02381
02382 void CAPTURE::SetImageFile(char *lcharImageFile, TypeImage ltypeimageType)
02383 {
02384 this->imageFile = lcharImageFile;
02385 this->typeImageFile = ltypeimageType;
02386 }
02387
02388
02389
02390
02391
02392
02393
02394
02395 void CAPTURE::VideoCapture(void)
02396 {
02397 switch(this->typeImageFile)
02398 {
02399 case PPM:
02400 {
02401 this->SavePPM((char*)this->imageFile.c_str());
02402 }
02403 case JPG:
02404 {
02405 this->SaveJPG((char*)this->imageFile.c_str());
02406 }
02407 }
02408 }
02409
02410
02411
02412
02413
02414
02415
02416
02417
02418 void CAPTURE::SetHardwareWebCam(void)
02419 {
02420
02421 this->map_buffer.format = VIDEO_PALETTE_YUV420P;
02422 this->lintVideoFormat = VIDEO_PALETTE_YUV420P;
02423 this->pic.palette = VIDEO_PALETTE_YUV420P;
02424
02425 }
02426
02427
02428
02429
02430
02431
02432
02433
02434
02435 void CAPTURE::SetHardwareCaptureCard(void)
02436 {
02437
02438 this->map_buffer.format = VIDEO_PALETTE_RGB24;
02439 this->lintVideoFormat = VIDEO_PALETTE_RGB24;
02440 this->pic.palette = VIDEO_PALETTE_RGB24;
02441
02442 }
02443
02444
02445
02446
02447
02448
02449
02450
02451
02452 void CAPTURE::SetInputChannel(int lintVALUE)
02453 {
02454
02455 this->vch.channel = lintVALUE;
02456
02457 if (-1==ioctl( this->fd, VIDIOCGCHAN, &this->vch ))
02458 printf(" > ERRO: V4L function ioctl VDIOCGCHAN.\n");
02459
02460 if (-1==ioctl( this->fd, VIDIOCSCHAN, &this->vch ))
02461 printf(" > ERRO: V4L function ioctl VIDIOCSCHAN.\n");
02462
02463 }
02464
02465
02466
02467
02468
02469
02470
02471
02472
02473 int CAPTURE::MaxWidth(void)
02474 {
02475 return this->widthWin;
02476 }
02477
02478
02479
02480
02481
02482
02483
02484
02485
02486 int CAPTURE::MaxHeight(void)
02487 {
02488 return this->heightWin;
02489 }
02490
02491
02492
02493
02494
02495
02496
02497
02498
02499 void CAPTURE::SetMaxTextTouch(int lintVALUE)
02500 {
02501 this->MaxTextTouch = lintVALUE;
02502 }
02503
02504
02505
02506
02507
02508
02509
02510
02511
02512 void CAPTURE::FullScreen(void)
02513 {
02514 SDL_WM_ToggleFullScreen(this->screen);
02515 }
02516
02517 }