funcoesHAIRCAPTURE.cpp

Go to the documentation of this file.
00001 // Autor: Alessandro de Oliveira Faria <alessandrofaria@netitec.com.br>
00002 // http://www.netitec.com.br/alessandro
00003 
00004 #include "funcoesHAIRCAPTURE.h"
00005 #include "jpeg.c"
00006 
00007 //****************************************************************************
00008 // TYPE........: Function
00009 // NAME........: TOSTRINGTCP
00010 // SUMMARY.....: Convert the number type int/float to string.
00011 // CREATED.....: 03/12/2004
00012 // MODIFIED....: 06/02/2005
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 // TYPE........: Function
00032 // NAME........: FileExist
00033 // SUMMARY.....: Verify if file exist in disk.
00034 // CREATED.....: 03/12/2004
00035 // MODIFIED....: 06/02/2005
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 //!SUMMARY.....: Execute the Method Live
00061 /* TYPE........: Function for thread
00062  * NAME........: ThreadAoVivo
00063  * CREATED.....: Jun-20-2005
00064  * MODIFIED....: Jul-01-2005
00065  *\param VIDEO pointer for CAPTURE class
00066  *****************************************************************************/
00067 void *ThreadAoVivo(HAIR::CAPTURE *VIDEO)
00068 {
00069   VIDEO->Live();
00070 }
00071 //****************************************************************************
00072 //!SUMMARY.....: Limite saturation color
00073 /*!TYPE........: Function for save frame jpeg
00074  * NAME........: Sat
00075  * CREATED.....: Nov-05-2005
00076  * MODIFIED....: Nov-11-2005
00077  *\param val Value color
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 //!SUMMARY.....: Feedback function for play mpeg
00088 /*!TYPE........: Function 
00089  * NAME........: UPDATE
00090  * CREATED.....: Nov-05-2005
00091  * MODIFIED....: Nov-11-2005
00092  *\param screen Surface for display mpeg
00093  *\param x First position
00094  *\param y First positon
00095  *\param w Width of video
00096  *\param h height of video
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 // TYPE........: Method
00107 // NAME........: PLAYMPEG
00108 // SUMMARY.....: Show and play MPEG videoe
00109 // CREATED.....: 07-Nov-2005
00110 // MODIFIED....: 11-Nov-2005
00111 // PARAMETERS..: 
00112 //     char *name MPEG file name
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 // TYPE........: Method 
00124 // NAME........: Live
00125 // SUMMARY.....: Show Image
00126 // CREATED.....: 01-Jul-2005
00127 // MODIFIED....: 02-Jul-2005
00128 // PARAMETERS..: none
00129 // COMMENT.....: none
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 // TYPE........: Method 
00161 // NAME........: SetFont
00162 // SUMMARY.....: Change Fonte TrueType
00163 // CREATED.....: 20-June2005
00164 // MODIFIED....: 01-July-2005
00165 // PARAMETERS..: char Font Name
00166 // COMMENT.....: none
00167 //****************************************************************************
00168 void CAPTURE::SetFont(char *lfontName)
00169 {
00170    this->fontName = lfontName;  
00171 }
00172 
00173 //****************************************************************************
00174 // TYPE........: Method
00175 // NAME........: SetSizeFont
00176 // SUMMARY.....: Change Fonte Size
00177 // CREATED.....: 24-Jan-2006
00178 // MODIFIED....: 24-Jan-2006
00179 // PARAMETERS..: int Size Font
00180 // COMMENT.....: none
00181 //****************************************************************************
00182 void CAPTURE::SetFontSize(int lintSize)
00183 {
00184    this->size_font = lintSize;
00185 
00186 }
00187 
00188 //****************************************************************************
00189 // TYPE........: Method 
00190 // NAME........: SetDevice
00191 // SUMMARY.....: Change Video Device
00192 // CREATED.....: 20-July-2005
00193 // MODIFIED....: 01-July-2005
00194 // PARAMETERS..: char Name Device
00195 //      COMMENT.....: none
00196 //****************************************************************************
00197 void CAPTURE::SetDevice(char *lDevice)
00198 {
00199    this->device = lDevice;      
00200 }
00201 
00202 //****************************************************************************
00203 // TYPE........: Method 
00204 // NAME........: ColorBit
00205 // SUMMARY.....: Change Bit Color Image
00206 // CREATED.....: 20-June2005
00207 // MODIFIED....: 01-July-2005
00208 // PARAMETERS..: Int Depth
00209 // COMMENT.....: none
00210 //****************************************************************************
00211 void CAPTURE::ColorBit(int depth)
00212 {
00213    this->depth = depth; 
00214 }
00215 
00216 //****************************************************************************
00217 // TYPE........: Method 
00218 // NAME........: Resolution
00219 // SUMMARY.....: Change resolution 
00220 // CREATED.....: 19-June2005
00221 // MODIFIED....: 01-July-2005
00222 // PARAMETERS..: Int Width, Height
00223 // COMMENT.....: none
00224 //****************************************************************************
00225 void CAPTURE::Resolution(int width, int height)
00226 {
00227    this->width = width;
00228    this->height= height;
00229 }
00230 
00231 
00232 //****************************************************************************
00233 // TYPE........: Method
00234 // NAME........: Resolution
00235 // SUMMARY.....: Change resolution window
00236 // CREATED.....: 24-Jan-2006
00237 // MODIFIED....: 01-Jan-2006
00238 // PARAMETERS..: Int Width, Height
00239 // COMMENT.....: none
00240 //****************************************************************************
00241 void CAPTURE::ResolutionWin(int width, int height)
00242 {
00243    this->widthWin  = width;
00244    this->heightWin = height;
00245 }
00246 
00247 //****************************************************************************
00248 // TYPE........: Method
00249 // NAME........: SetAngleText
00250 // SUMMARY.....: Change the angle for rotation text surface
00251 // CREATED.....: 24-Jan-2006
00252 // MODIFIED....: 24-Jan-2006
00253 // PARAMETERS..: Int Angle
00254 // COMMENT.....: none
00255 //****************************************************************************
00256 void CAPTURE::SetAngleText(int lintAngle)
00257 {
00258    this->RotateText  = lintAngle;
00259 }
00260 
00261 
00262 //****************************************************************************
00263 // TYPE........: Method
00264 // NAME........: SetAngleVideo
00265 // SUMMARY.....: Change the angle for rotation video surface
00266 // CREATED.....: 24-Aug-2006
00267 // MODIFIED....: 24-Aug-2006
00268 // PARAMETERS..: Int Angle
00269 // COMMENT.....: none
00270 //****************************************************************************
00271 void CAPTURE::SetAngleVideo(int lintAngle)
00272 {
00273    this->RotateVideo  = lintAngle;
00274 }
00275 
00276 
00277 
00278 
00279 //****************************************************************************
00280 // TYPE........: Method
00281 // NAME........: SetVideoPos
00282 // SUMMARY.....: Change the position of window video live
00283 // CREATED.....: 24-Jan-2006
00284 // MODIFIED....: 24-Jan-2006
00285 // PARAMETERS..: Int Width, Height
00286 // COMMENT.....: none
00287 //****************************************************************************
00288 void CAPTURE::SetVideoPos(int x, int y)
00289 {
00290    this->top  = y;
00291    this->left = x;
00292 }
00293 
00294 
00295 //****************************************************************************
00296 // TYPE........: Method 
00297 // NAME........: convertYUV420PtoGray
00298 // SUMMARY.....: Convert map image YUV to Gray
00299 // CREATED.....: 27-Mar-2006
00300 // MODIFIED....: 27-Mar-2006
00301 // PARAMETERS..: none
00302 // COMMENT.....: none
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 // TYPE........: Method 
00326 // NAME........: convertYUV420PtoRGB
00327 // SUMMARY.....: Convert map image YUV to RGB
00328 // CREATED.....: 06-June2005
00329 // MODIFIED....: 02-July-2005
00330 // PARAMETERS..: none
00331 // COMMENT.....: none
00332 //****************************************************************************
00333 void CAPTURE::convertYUV420PtoRGB(bool forDISK) 
00334 {
00335    unsigned char *y, *u, *v, *r, *g, *b;
00336    int tmp,i;
00337    // Convert if format same YUV
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 // TYPE........: Method
00381 // NAME........: converttoRGB
00382 // SUMMARY.....: Convert map image to RGB
00383 // CREATED.....: Nov-21-2005
00384 // MODIFIED....: Nov-21-2005
00385 //****************************************************************************
00386 void CAPTURE::swap_rgb24(void) 
00387 {
00388    this->v4l_convert_buf = this->map;
00389 
00390    //this->last_map = this->v4l_convert_buf;
00391    /*unsigned char  c;
00392    unsigned char *p = this->v4l_convert_buf;
00393    int   i = (this->width*this->height) ;
00394    while (--i) 
00395    {
00396       c = p[0];
00397       p[0] = p[2];
00398       p[2] = c;
00399       p += 3;
00400    }*/
00401    //this->last_map = this->map;
00402 
00403 }
00404 
00405 
00406 
00407 //****************************************************************************
00408 // TYPE........: Method 
00409 // NAME........: SavePPM
00410 // SUMMARY.....: Save frame in format PPM Portable Pixel Map
00411 // CREATED.....: 20-June2005
00412 // MODIFIED....: 01-July-2005
00413 // PARAMETERS..: char File Name 
00414 // COMMENT.....: none
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; //(unsigned char*)this->offscreen->pixels; // 
00432 
00433    img.width  = this->width;
00434    img.height = this->height;
00435 
00436    // adjust colors
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);  // more RED
00444          pixel[1] = pixel[1];          // no change in GREEN
00445          pixel[2] = SAT(pixel[2]-10);  // less BLUE
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 // TYPE........: Method
00464 // NAME........: LoadJPEG
00465 // SUMMARY.....: Load frame in format JPEG
00466 // CREATED.....: 15-Nov-2005
00467 // MODIFIED....: 15-Nov-2005
00468 // PARAMETERS..: char File Name
00469 // COMMENT.....: none
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 // TYPE........: Method
00552 // NAME........: Background
00553 // SUMMARY.....: Load and define JPEG background
00554 // CREATED.....: 24-Jan-2006
00555 // MODIFIED....: 24-Jan-2006
00556 // PARAMETERS..: char File Name
00557 // COMMENT.....: none
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 // TYPE........: Method
00580 // NAME........: VIEWLASTMAP
00581 // SUMMARY.....: Display last frame saved
00582 // CREATED.....: 15-Nov-2005
00583 // MODIFIED....: 15-Nov-2005
00584 // PARAMETERS..: none
00585 // COMMENT.....: none
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 // TYPE........: Method 
00658 // NAME........: SavePPM
00659 // SUMMARY.....: Save frame in format PPM Portable Pixel Map
00660 // CREATED.....: 20-June2005
00661 // MODIFIED....: 01-July-2005
00662 // PARAMETERS..: char File Name 
00663 // COMMENT.....: none
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 // TYPE........: Method 
00687 // NAME........: WriteScreen
00688 // SUMMARY.....: Wrtie image in Video
00689 // CREATED.....: 30-June2005
00690 // MODIFIED....: 01-July-2005
00691 // PARAMETERS..: unsigned char Map Image
00692 // COMMENT.....: none
00693 //****************************************************************************
00694 void CAPTURE::WriteScreen(unsigned char* tmap) 
00695 {
00696     int lintLoop = 0;
00697         
00698    // Convert palette for RGB
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    //SDL_BlitSurface(this->offscreen, NULL, this->screen, NULL);
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       //SDL_LockSurface( this->zoomout_surface);
00745       SDL_BlitSurface( this->zoomout_surface, NULL, this->screen, &this->TempRect);
00746       //SDL_UnlockSurface( this->zoomout_surface);
00747    }
00748 
00749    if(this->UseVideo)
00750    {  
00751       //SDL_LockSurface( this->video_surface);
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       //SDL_UnlockSurface( this->video_surface);
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       //SDL_LockSurface( this->draw_surface);
00775       SDL_BlitSurface( this->draw_surface, NULL, this->screen, NULL);
00776       //SDL_UnlockSurface( this->draw_surface);
00777    }
00778 
00779    if(this->UseText)
00780    {
00781       //SDL_LockSurface( this->text_surface);
00782       SDL_BlitSurface( this->text_surface,NULL,this->screen,NULL);
00783       //SDL_UnlockSurface( this->text_surface);
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          // Key SPACE: ZoomOut On
00817          if(this->key==this->KeyZoomOutOn)
00818          this->ZoomOut(true);
00819 
00820          if(this->key==this->KeyVideoOn)
00821          this->PlayMPEG(this->mpegName);
00822 
00823          // Key C: ZoomOut Off
00824          if(this->key==KeyZoomOutOff) 
00825          {  
00826             ClearSurface(TEXTS);
00827             ClearSurface(ZOOM);
00828             //this->ZoomOut(false);
00829          }
00830          // Key F: Fullscreen On/Off
00831          if(this->key==KeyFullScreeen)
00832          SDL_WM_ToggleFullScreen(this->screen);
00833 
00834          // Key S: Save screenshot : screenshot.ppm
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          // Key Q: Quit 
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 // TYPE........: Method
00888 // NAME........: Open
00889 // SUMMARY.....: Inicialize VideoCapture
00890 // CREATED.....: 03-June2005
00891 // MODIFIED....: 01-July-2005
00892 // PARAMETERS..: none
00893 // COMMENT.....: none
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    //fcntl(fd,F_SETFD,FD_CLOEXEC);
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 // TYPE........: Method
01146 // NAME........: VideoCreate
01147 // SUMMARY.....: Inicialize VideoCapture
01148 // CREATED.....: 09-June2005
01149 // MODIFIED....: 01-July-2005
01150 // PARAMETERS..: none
01151 // COMMENT.....: none
01152 //****************************************************************************
01153 void CAPTURE::VideoCreate(void)
01154 {
01155    this->Open();
01156 
01157 }
01158 
01159 
01160 //****************************************************************************
01161 // TYPE........: Method
01162 // NAME........: InitVideo
01163 // SUMMARY.....: Inicialize Video
01164 // CREATED.....: 09-June2005
01165 // MODIFIED....: 01-July-2005
01166 // PARAMETERS..: none
01167 // COMMENT.....: none
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 // TYPE........: Method
01186 // NAME........: InicializeWin
01187 // SUMMARY.....: Inicialize Video
01188 // CREATED.....: 09-June2005
01189 // MODIFIED....: 01-July-2005
01190 // PARAMETERS..: none
01191 // COMMENT.....: none
01192 //****************************************************************************
01193 void CAPTURE::InicializeWin(void) 
01194 {
01195    SDL_Init(SDL_INIT_VIDEO );
01196         
01197 //   this->screen = SDL_SetVideoMode(this->width, this->height, this->depth, 
01198 //                                   SDL_HWSURFACE | SDL_DOUBLEBUF);
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    // Create surface MPEG video
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    // Create surface ZoomOut
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 // TYPE........: Method
01262 // NAME........: ClearSurface
01263 // SUMMARY.....: Clear surface 
01264 // CREATED.....: 11-Nov-2005
01265 // MODIFIED....: 18-Mar-2006
01266 // COMMENT.....: none
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 // TYPE........: Method
01310 // NAME........: ClearSurface
01311 // SUMMARY.....: Clear surface 
01312 // CREATED.....: 11-Fev-2006
01313 // MODIFIED....: 11-Fev-2006
01314 // PARAMETERS..: SDL_Surface *lsurfaceScreen
01315 // COMMENT.....: none
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 // TYPE........: Method
01360 // NAME........: Show
01361 // SUMMARY.....: Show Live Video (thread)
01362 // CREATED.....: 09-June2005
01363 // MODIFIED....: 01-July-2005
01364 // PARAMETERS..: none
01365 // COMMENT.....: none
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 // TYPE........: Method
01385 // NAME........: VideoInicialize
01386 // SUMMARY.....: Show Live Video (thread)
01387 // CREATED.....: 09-June2005
01388 // MODIFIED....: 01-July-2005
01389 // PARAMETERS..: none
01390 // COMMENT.....: none
01391 //****************************************************************************
01392 void CAPTURE::VideoInicialize(void)
01393 {
01394     this->Show();
01395 }
01396 
01397 //****************************************************************************
01398 // TYPE........: Method
01399 // NAME........: WaitForVideo
01400 // SUMMARY.....: Wait for thresd Live
01401 // CREATED.....: 29-June2005
01402 // MODIFIED....: 01-July-2005
01403 // PARAMETERS..: none
01404 // COMMENT.....: none
01405 //****************************************************************************
01406 void CAPTURE::WaitForVideo(void) 
01407 {
01408    pthread_join(*this->thread, 0);
01409 }
01410 
01411 //****************************************************************************
01412 // TYPE........: Method
01413 // NAME........: WaitText
01414 // SUMMARY.....: Write text over video
01415 // CREATED.....: 15-June2005
01416 // MODIFIED....: 01-July-2005
01417 // PARAMETERS..: none
01418 // COMMENT.....: none
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       //intTMPR = this->colorFont.r;
01443       //intTMPG = this->colorFont.g;
01444       //intTMPB = this->colorFont.b;
01445 
01446       //this->SetColorFont(1,1,1);
01447       LimageShadow = TTF_RenderText_Solid(this->NameFont,lcharText,(SDL_Color){1,1,1});
01448       //this->SetColorFont(intTMPR,intTMPG,intTMPB);
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 // TYPE........: Method
01504 // NAME........: WriteText
01505 // SUMMARY.....: Write text over video
01506 // CREATED.....: 15-June2005
01507 // MODIFIED....: 01-July-2005
01508 // PARAMETERS..: none
01509 // COMMENT.....: none
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 // TYPE........: Method
01562 // NAME........: Circle
01563 // SUMMARY.....: Draw primitive circle over video
01564 // CREATED.....: 30-Oct-2006
01565 // MODIFIED....: 30-Oct-2006
01566 // PARAMETERS..: Int x,y for coodinate, rad for radius and r,g,b for color
01567 // COMMENT.....: none
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 // TYPE........: Method
01608 // NAME........: Line
01609 // SUMMARY.....: Draw primitive line over video
01610 // CREATED.....: 19-June2005
01611 // MODIFIED....: 01-July-2005
01612 // PARAMETERS..: Int x1,x2 to x2,y2 and r,g,G
01613 // COMMENT.....: none
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 // TYPE........: Method
01652 // NAME........: Rectangle
01653 // SUMMARY.....: Draw rectangle over surface zoomout
01654 // CREATED.....: 15-Nov-2005
01655 // MODIFIED....: 01-Nov-2005
01656 // PARAMETERS..: Int x1,x2 to x2,y2 and r,g,G
01657 // COMMENT.....: none
01658 //****************************************************************************
01659 void CAPTURE::RectangleZoom(int lintx1, int linty1,int lintx2, int linty2,  int lintR, int lintG,int lintB )
01660 {
01661    //this->UseZoomOut  = false;
01662    rectangleRGBA(this->zoomout_surface,lintx1, linty1,lintx2,  linty2,  lintR, lintG, lintB, 255);
01663    //this->UseZoomOut  = true;
01664 
01665 }
01666 
01667 //****************************************************************************
01668 // TYPE........: Method
01669 // NAME........: Rectangle
01670 // SUMMARY.....: Draw rectangle over video
01671 // CREATED.....: 15-Nov-2005
01672 // MODIFIED....: 01-Nov-2005
01673 // PARAMETERS..: Int x1,x2 to x2,y2 and r,g,G
01674 // COMMENT.....: none
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 // TYPE........: Method
01715 // NAME........: Rectangle
01716 // SUMMARY.....: Draw rectangle fill over video
01717 // CREATED.....: 15-Oct-2005
01718 // MODIFIED....: 20-Mar-2006
01719 // COMMENT.....: none
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 // TYPE........: Method
01758 // NAME........: Rectangle
01759 // SUMMARY.....: Draw a bar progress                 
01760 // CREATED.....: 15-Nov-2005
01761 // MODIFIED....: 17-Nov-2005
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 // TYPE........: Method
01803 // NAME........: LoadBMP
01804 // SUMMARY.....: Draw Bitmap image over video
01805 // CREATED.....: 19-June2005
01806 // MODIFIED....: 26-July-2005
01807 // PARAMETERS..: char * lcharBMP
01808 // COMMENT.....: none
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 // TYPE........: Method
01824 // NAME........: ZoomOut
01825 // SUMMARY.....: Show static image 
01826 // CREATED.....: 19-June2005
01827 // MODIFIED....: 12-Setp-2005
01828 // PARAMETERS..: bool lboolStatus
01829 // COMMENT.....: none
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 // TYPE........: Method
01854 // NAME........: SetFormatPalette
01855 // SUMMARY.....: Set video palette 
01856 // CREATED.....: 07-Agu-005
01857 // MODIFIED....: 07-Agu-0050
01858 // PARAMETERS..: int lFormat
01859 // COMMENT.....: none
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 // TYPE........: Method
01870 // NAME........: SetInputTelevision
01871 // SUMMARY.....: Set mode input television
01872 // CREATED.....: 07-Agu-005
01873 // MODIFIED....: 07-Agu-0050
01874 // PARAMETERS..: int lVideoMode
01875 // COMMENT.....: none
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    //vtuner.tuner = 77,25;
01885  
01886 }
01887 
01888 //***************************************************************************
01889 // TYPE........: Method
01890 // NAME........: SetInputCamera
01891 // SUMMARY.....: Set mode input Camera
01892 // CREATED.....: 07-Agu-005
01893 // MODIFIED....: 07-Agu-0050
01894 // PARAMETERS..: int lVideoMode
01895 // COMMENT.....: none
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 // TYPE........: Method
01908 // NAME........: SetTransparent
01909 // SUMMARY.....: Set Transparent color
01910 // CREATED.....: 12-Setp-2005
01911 // MODIFIED....: 12-Setp-2005
01912 // PARAMETERS..: int lintR , int lintG,int lintB
01913 // COMMENT.....: none
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 // TYPE........: Method
01924 // NAME........: SetKeyZoomOutOn
01925 // SUMMARY.....: Set key in ZoomOutOn
01926 // CREATED.....: 12-Setp-2005
01927 // MODIFIED....: 12-Setp-2005
01928 // PARAMETERS..: SDLKey Lkey
01929 // COMMENT.....: none
01930 //****************************************************************************
01931 void CAPTURE::SetKeyZoomOutOn(SDLKey Lkey)
01932 {
01933    this->KeyZoomOutOn=Lkey;
01934 }
01935 
01936 //***************************************************************************
01937 // TYPE........: Method
01938 // NAME........: SetKeyZoomOutOff
01939 // SUMMARY.....: Set key in ZoomOutOff
01940 // CREATED.....: 12-Setp-2005
01941 // MODIFIED....: 12-Setp-2005
01942 // PARAMETERS..: SDLKey Lkey
01943 // COMMENT.....: none
01944 //****************************************************************************
01945 void CAPTURE::SetKeyZoomOutOff(SDLKey Lkey)
01946 {
01947    this->KeyZoomOutOff=Lkey;
01948 }
01949 
01950 //***************************************************************************
01951 // TYPE........: Method
01952 // NAME........: SetKeyFullScreeen
01953 // SUMMARY.....: Set key in FullScreeen
01954 // CREATED.....: 12-Setp-2005
01955 // MODIFIED....: 12-Setp-2005
01956 // PARAMETERS..: SDLKey Lkey
01957 // COMMENT.....: none
01958 //****************************************************************************
01959 void CAPTURE::SetKeyFullScreeen(SDLKey Lkey)
01960 {
01961    this->KeyFullScreeen=Lkey;
01962 }
01963 
01964 //***************************************************************************
01965 // TYPE........: Method
01966 // NAME........: SetKeySaveFrame
01967 // SUMMARY.....: Set key in SaveFrame
01968 // CREATED.....: 12-Setp-2005
01969 // MODIFIED....: 12-Setp-2005
01970 // PARAMETERS..: SDLKey Lkey
01971 // COMMENT.....: none
01972 //****************************************************************************
01973 void CAPTURE::SetKeySaveFrame(SDLKey Lkey)
01974 {
01975    this->KeySaveFrame=Lkey;
01976 }
01977 
01978 //***************************************************************************
01979 // TYPE........: Method
01980 // NAME........: SetKeySaveFrame
01981 // SUMMARY.....: Set key in SaveFrame
01982 // CREATED.....: 12-Setp-2005
01983 // MODIFIED....: 12-Setp-2005
01984 // PARAMETERS..: SDLKey Lkey
01985 // COMMENT.....: none
01986 //****************************************************************************
01987 void CAPTURE::SetKeyQuit(SDLKey Lkey)
01988 {
01989    this->KeyQuit=Lkey;
01990 }
01991 
01992 //***************************************************************************
01993 // TYPE........: Method
01994 // NAME........: SetKeyVideoOn
01995 // SUMMARY.....: Set key for play mpeg video
01996 // CREATED.....: 11-Oct-2005
01997 // MODIFIED....: 11-Oct2005
01998 // PARAMETERS..: SDLKey Lkey
01999 // COMMENT.....: none
02000 //****************************************************************************
02001 void CAPTURE::SetKeyVideoOn(SDLKey Lkey)
02002 {
02003    this->KeyVideoOn=Lkey;
02004 }
02005 //***************************************************************************
02006 // TYPE........: Method
02007 // NAME........: ShowMouse
02008 // SUMMARY.....: Enable mouse cursor
02009 // CREATED.....: 11-Nov-2005
02010 // MODIFIED....: 11-Nov-2005
02011 // COMMENT.....: none
02012 //****************************************************************************
02013 void CAPTURE::ShowMouse(void)
02014 {
02015    SDL_ShowCursor(SDL_ENABLE);
02016 }
02017 
02018 //***************************************************************************
02019 // TYPE........: Method
02020 // NAME........: HideMouse
02021 // SUMMARY.....: Disable mouse cursor
02022 // CREATED.....: 11-Nov-2005
02023 // MODIFIED....: 11-Nov-2005
02024 // COMMENT.....: none
02025 //****************************************************************************
02026 void CAPTURE::HideMouse(void)
02027 {
02028    SDL_ShowCursor(SDL_DISABLE);
02029 }
02030 
02031 //***************************************************************************
02032 // TYPE........: Method
02033 // NAME........: DefinePositionButton 
02034 // SUMMARY.....: Define the position button
02035 // CREATED.....: 11-Nov-2005
02036 // MODIFIED....: 11-Nov-2005
02037 // COMMENT.....: none
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 // TYPE........: Method
02049 // NAME........: FindButton
02050 // SUMMARY.....: Scan a button
02051 // CREATED.....: 11-Nov-2005
02052 // MODIFIED....: 11-Nov-2005
02053 // COMMENT.....: none
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 // TYPE........: Method
02072 // NAME........: GetLastKey
02073 // SUMMARY.....: Get Last Button
02074 // CREATED.....: 17-Nov-2005
02075 // MODIFIED....: 17-Nov-2005
02076 // COMMENT.....: none
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 // TYPE........: Method
02092 // NAME........: TouchScreen 
02093 // SUMMARY.....: On/Off Touch Screen Display
02094 // CREATED.....: 17-Nov-2005
02095 // MODIFIED....: 17-Nov-2005
02096 // COMMENT.....: none
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 // TYPE........: Method
02112 // NAME........: SelectContrast
02113 // SUMMARY.....: Select the function contrast
02114 // CREATED.....: 17-Mar-2006
02115 // MODIFIED....: 17-Mar-2006
02116 // COMMENT.....: none
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 // TYPE........: Method
02134 // NAME........: SelectBrightness
02135 // SUMMARY.....: Select the function brightness
02136 // CREATED.....: 17-Mar-2006
02137 // MODIFIED....: 17-Mar-2006
02138 // COMMENT.....: none
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 // TYPE........: Method
02155 // NAME........: SelectColor
02156 // SUMMARY.....: Select the function color
02157 // CREATED.....: 17-Mar-2006
02158 // MODIFIED....: 17-Mar-2006
02159 // COMMENT.....: none
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 // TYPE........: Method
02177 // NAME........: SelectHue
02178 // SUMMARY.....: Select the function hue
02179 // CREATED.....: 17-Mar-2006
02180 // MODIFIED....: 17-Mar-2006
02181 // COMMENT.....: none
02182 //****************************************************************************
02183 void CAPTURE::SelectHue(void)
02184 {
02185    this->adjustVIDEO = 1;
02186    Progress("Hue",this->pic.brightness,65535);
02187 }
02188 
02189 
02190 //***************************************************************************
02191 // TYPE........: Method
02192 // NAME........: Select Adjust Video
02193 // SUMMARY.....: Adjust Video Live
02194 // CREATED.....: 17-Nov-2005
02195 // MODIFIED....: 17-Nov-2005
02196 // COMMENT.....: none
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 // TYPE........: Method
02237 // NAME........: AdjustVideo 
02238 // SUMMARY.....: Adjust Video Live
02239 // CREATED.....: 17-Nov-2005
02240 // MODIFIED....: 17-Nov-2005
02241 // COMMENT.....: none
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          //exit(-1);
02303    }
02304    this->imageAdjust = false;
02305 }   
02306 }
02307 //***************************************************************************
02308 // TYPE........: Method
02309 // NAME........: SetColorFont
02310 // SUMMARY.....: Define the color font
02311 // CREATED.....: 18-Nov-2005
02312 // MODIFIED....: 18-Nov-2005
02313 // COMMENT.....: none
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 // TYPE........: Method
02326 // NAME........: GetTouch
02327 // SUMMARY.....: Input Touch Screen
02328 // CREATED.....: 24-Jan-2006
02329 // MODIFIED....: 24-Jan-2006
02330 // COMMENT.....: none
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 //            gstringTXT = ": "+lstringBUFFER;
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 // TYPE........: Method
02376 // NAME........: SetImageFile
02377 // SUMMARY.....: Define type and image file.
02378 // CREATED.....: 09-Jan-2006
02379 // MODIFIED....: 09-Jan-2006
02380 // COMMENT.....: none
02381 //****************************************************************************
02382 void CAPTURE::SetImageFile(char *lcharImageFile, TypeImage ltypeimageType)
02383 {
02384    this->imageFile = lcharImageFile;
02385    this->typeImageFile = ltypeimageType;
02386 }
02387 //***************************************************************************
02388 // TYPE........: Method
02389 // NAME........: VideoCapture
02390 // SUMMARY.....: Save frame in the disk.
02391 // CREATED.....: 09-Jan-2006
02392 // MODIFIED....: 09-Jan-2006
02393 // COMMENT.....: none
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 // TYPE........: Method
02412 // NAME........: SetHardwareWebCam 
02413 // SUMMARY.....: Set the property for operation in webcam.
02414 // CREATED.....: 24-Ago-2006
02415 // MODIFIED....: 24-Ago-2006
02416 // COMMENT.....: none
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 // TYPE........: Method
02429 // NAME........: SetHardwareCaptureCard
02430 // SUMMARY.....: Set the property for operation in capture card.
02431 // CREATED.....: 24-Ago-2006
02432 // MODIFIED....: 24-Ago-2006
02433 // COMMENT.....: none
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 // TYPE........: Method
02446 // NAME........: SetInputChannel
02447 // SUMMARY.....: Set input channel in Television
02448 // CREATED.....: 26-Ago-2006
02449 // MODIFIED....: 26-Ago-2006
02450 // COMMENT.....: none
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 // TYPE........: Method
02467 // NAME........: MaxWidth
02468 // SUMMARY.....: Return the Max witdth of the main window
02469 // CREATED.....: 05-Sep-2006
02470 // MODIFIED....: 05-Sep-2006
02471 // COMMENT.....: none
02472 //****************************************************************************
02473 int CAPTURE::MaxWidth(void)
02474 {
02475    return this->widthWin;
02476 }
02477 
02478 //***************************************************************************
02479 // TYPE........: Method
02480 // NAME........: MaxHeight
02481 // SUMMARY.....: Return the Max height of the main window
02482 // CREATED.....: 05-Sep-2006
02483 // MODIFIED....: 05-Sep-2006
02484 // COMMENT.....: none
02485 //****************************************************************************
02486 int CAPTURE::MaxHeight(void)
02487 {
02488    return this->heightWin;
02489 }
02490 
02491 //***************************************************************************
02492 // TYPE........: Method
02493 // NAME........: SetMaxTextTouch
02494 // SUMMARY.....: Set the max lenght for input touchscreen
02495 // CREATED.....: 05-Sep-2006
02496 // MODIFIED....: 05-Sep-2006
02497 // COMMENT.....: none
02498 //****************************************************************************
02499 void CAPTURE::SetMaxTextTouch(int lintVALUE)
02500 {
02501    this->MaxTextTouch = lintVALUE;
02502 }
02503 
02504 //***************************************************************************
02505 // TYPE........: Method
02506 // NAME........: FullScreen
02507 // SUMMARY.....: Enable/Disable full Screen mode.
02508 // CREATED.....: 21-Oct-2006
02509 // MODIFIED....: 21-Oct-2006
02510 // COMMENT.....: none
02511 //****************************************************************************
02512 void CAPTURE::FullScreen(void)
02513 {
02514    SDL_WM_ToggleFullScreen(this->screen);
02515 }
02516 
02517 }

Generated on Tue Apr 3 11:59:07 2007 for NETi TECNOLOGIA - libHAIRCAPTURE by  doxygen 1.5.0-1