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

SDLDisplayFormatTest.cpp

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002     Phission : 
00003         Realtime Vision Processing System
00004     
00005     Copyright (C) 2003 Philip D.S. Thoren (pthoren@cs.uml.edu)
00006     University of Massachusetts at Lowell,
00007     Laboratory for Artificial Intelligence and Robotics
00008     
00009     This file is part of Phission.
00010 
00011  ---------------------------------------------------------------------------*/
00012 #include <SDLDisplayFormatTest.h>
00013 #include <phission.h>
00014 
00015 /* ------------------------------------------------------------------------ */
00016 int usage ()
00017 {
00018     printf("\n\nUsage:\n");
00019     printf("\t--help  Display usage\n");
00020     printf("\t--test  Loop through all formats and then close test\n");
00021     printf("\n\n");
00022     exit(1);
00023 }
00024         
00025 /* ------------------------------------------------------------------------ */
00026 int main(int argc, char *argv[] )
00027 {
00028     phFUNCTION("main")
00029 
00030     char        *capture_path   = NULL;
00031     int         channel         = 0;
00032         
00033     uint32_t    width = 320;
00034     uint32_t    height = 240;
00035     
00036     int         do_sleep = 1;
00037 
00038     /* This tests the supported formats for the SDL display */
00039     uint32_t    format_count        = 0;
00040     uint32_t    format_switch_count = 10;
00041     uint32_t    format_print        = 1;
00042     uint32_t    format_index        = 0;
00043     const uint32_t format_max       = 6;
00044     uint32_t    formats[format_max] = 
00045                              {  phImageBGRA32,
00046                                 phImageABGR32,
00047                                 phImageRGBA32,
00048                                 phImageGREY8,
00049                                 phImageBGR24,
00050                                 phImageRGB24   };
00051     
00052     int         displaysOpen= 1;
00053     SDLDisplay  *display    = NULL;
00054 #ifdef WIN32
00055     VFWSource   *capture = new VFWSource();
00056 #else
00057     V4LCapture  *capture = new V4LCapture();
00058 #endif
00059         
00060     /* Utility class to ease the starting and stopping of displays, captures and
00061      * pipelines */
00062     phSystem    system;
00063    
00064     /* Remove the code below when using this code as an example.
00065      * 
00066      * This just checks whether "--test" has been specified with
00067      * a time value argument. It's for testing all the examples
00068      * without the need for human intervention. */
00069     int             test = 0;
00070 
00071     phArgTable      *arg_parser = new phArgTable();
00072 
00073     rc = arg_parser->add("--test",&test,phARG_BOOL);
00074     phCHECK_RC(rc,NULL,"arg_parser->add");
00075     rc = arg_parser->add("--help",(void *)&usage,phARG_FUNC);
00076     phCHECK_RC(rc,NULL,"arg_parser->add");
00077     
00078     rc = arg_parser->add("--path",&capture_path,phARG_CHAR);
00079     phCHECK_RC(rc,NULL,"arg_parser->add");
00080 
00081     rc = arg_parser->add("--channel",&channel,phARG_INT);
00082     phCHECK_RC(rc,NULL,"arg_parser->add");
00083     
00084     rc = arg_parser->parse(argc,argv);
00085     phCHECK_RC(rc,NULL,"arg_parser->parse");
00086    
00087     /* Set up the capture device */
00088     capture->set(width,height,capture_path);
00089     capture->setChannel(channel);
00090     capture->setColour(65000);
00091     capture->setHue(65500);
00092     capture->setContrast(31000);
00093     capture->setBrightness(29000);
00094     capture->setFormat(formats[format_index]);
00095 
00096     rc = system.addCapture(capture);
00097     phPRINT_RC(rc,NULL,"system.addCapture(capture)");
00098     
00099     display    = new SDLDisplay(width,height,"SDLLiveSourceTest");
00100  
00101     display->setLiveSourceInput(capture->getLiveSourceOutput());
00102 
00103     rc = system.addDisplay(display);
00104     phPRINT_RC(rc,NULL,"system.addDisplay(display)");
00105             
00106 
00107     /* startup */
00108     rc = system.startup();
00109     phPRINT_RC(rc,NULL,"system.startup()");
00110    
00111     while (displaysOpen)
00112     {
00113         /* Sleep a while, don't loop tightly */
00114         if (do_sleep)
00115         {
00116             phMSleep(100);
00117         }
00118         else
00119         {        
00120             /* Yielding is optional. This gives up the thread's timeslice
00121              * to prevent slow response in other threads. It consumes more
00122              * CPU cycles than sleeping. Use it instead of sleeping if
00123              * this loop is processing anything */
00124         
00125             phYield();
00126         }
00127 
00128         format_count++;
00129 
00130         if (format_count > format_switch_count)
00131         {
00132             format_count = 0;
00133             format_index++;
00134 
00135             if (format_index >= format_max)
00136             {
00137                 if (test) displaysOpen = 0;
00138                 format_index = 0;
00139             }
00140 
00141             if (format_print)
00142             {
00143                 phPROGRESS("Switching to capture format: %s\n",
00144                         phImageFormatToString(formats[format_index]));
00145             }
00146 
00147             if (capture->isCapturing())
00148             {
00149                 rc = capture->stop();
00150                 phCHECK_RC(rc,NULL,"Error stopping capture thread" );
00151             }
00152             
00153             rc = capture->setFormat(formats[format_index]);
00154             phPRINT_RC(rc,NULL,"capture->setFormat");
00155             
00156             if (capture->isCapturing() == 0)
00157             {
00158                 rc = capture->start();
00159                 phCHECK_RC(rc,NULL,"Error starting capture thread" );
00160             }
00161             phMSleep(1000);
00162         }
00163         
00164         if (!test)
00165         {
00166             displaysOpen = 0;
00167             if (display->isOpen())
00168             {
00169                 displaysOpen = 1;
00170             }
00171         }
00172     }
00173 
00174     rc = system.shutdown();
00175     phPRINT_RC(rc,NULL,"system.shutdown()");
00176 
00177 
00178 error:
00179     phDelete(display);
00180     phDelete(capture);
00181     
00182     phFree(capture_path);
00183     phDelete(arg_parser);
00184 
00185     return phSUCCESS;
00186 }




Copyright (C) 2002 - 2007 Philip D.S. Thoren ( pthoren@users.sourceforge.net )
University Of Massachusetts at Lowell
Robotics Lab
SourceForge.net Logo

Generated on Sat Jun 16 02:44:07 2007 for phission by  doxygen 1.4.4