OpenVideo Documentation

   Main Page       Modules       Class Hierarchy       Alphabetical List       Compound List       File List       Compound Members       Related Pages   

TestWinCE.cpp

Go to the documentation of this file.
00001 
00002 #include "TestWinCE.h"
00003 #include "PocketHAL/utility.h"
00004 
00005 #include <openVideo/nodes/VideoSink.h>
00006 #include <ace/ACE.h>
00007 
00008 
00009 PHAL_DECLARE_ENTRY_POINT( TestWinCE );
00010 
00011 
00012 DWORD WINAPI
00013 ManagerThreadFunc(LPVOID lpParam)
00014 {
00015     openvideo::Manager* manager = (openvideo::Manager*)lpParam;
00016 
00017     manager->run();
00018     return 0;
00019 }
00020 
00021 
00022 TestWinCE::TestWinCE()
00023 {
00024     ACE::init();
00025 
00026     m_config.m_appName     = TEXT("OpenVideo Sample");
00027     m_config.m_orientation = PHAL::ORIENTATION_ROTATE90CCW;
00028 
00029     videoPixels = new unsigned short[VIDEO_WIDTH*VIDEO_HEIGHT];
00030 
00031     rotateSamples = true;
00032     showZoomed = false;
00033 
00034     hThread = NULL;
00035     dwThreadId = 0;
00036 }
00037 
00038 
00039 bool
00040 TestWinCE::OnInitialize()
00041 {
00042     if (!Game::OnInitialize())
00043         return false;
00044 
00045     manager = openvideo::Manager::getInstance();
00046     manager->parseConfiguration("openvideo.xml");
00047 
00048     if(openvideo::Node* node = manager->getNode("Simple video out"))
00049     {
00050         //node->getName();
00051         openvideo::VideoSink* sink = (openvideo::VideoSink*)node;
00052         sink->subscribe(this);
00053     }
00054 
00055     //hThread = ::CreateThread(NULL, 0, ManagerThreadFunc, this, 0, &dwThreadId);
00056     manager->run();
00057 
00058     return true;
00059 }
00060 
00061 
00062 void
00063 TestWinCE::OnShutdown()
00064 {
00065 
00066 
00067     Game::OnShutdown();
00068 }
00069 
00070 
00071 bool
00072 TestWinCE::OnGameLoop()
00073 {
00074     PHAL::Display* display = GetDisplay();
00075 
00076     if (display->BeginScene())
00077     {
00078         // Render one frame
00079         Clear( display->GetBackBuffer(), PHAL::COLOR_BLACK );
00080         //drawVideo(display, showZoomed);
00081         DrawText( display->GetBackBuffer(), 0, 0, GetFPSString() );
00082         display->Swap();
00083     }
00084 
00085     return Game::OnGameLoop();
00086 }
00087 
00088 
00089 void
00090 TestWinCE::OnStylusDown( PHAL::Point p )
00091 {
00092     if(p.x<320)
00093         rotateSamples = !rotateSamples;
00094     else
00095         showZoomed = !showZoomed;
00096 
00097     //syncedSink.setRotateSamples(rotateSamples);
00098 }
00099 
00100 
00101 void dump(const char* nFileName, void* nData, unsigned int nNumBytes)
00102 {
00103     if(FILE* fp = fopen(nFileName, "wb"))
00104     {
00105         fwrite(nData, 1, nNumBytes, fp);
00106         fclose(fp);
00107     }
00108 }
00109 
00110 void
00111 TestWinCE::drawVideo(PHAL::Display* nDisplay, bool nZoom)
00112 {
00113     //dump("small.raw", (void*)currentImage->getPixels(), 320*240*2);
00114 
00115     if(nZoom)
00116     {
00117         unsigned int *dst = (unsigned int *)nDisplay->GetBackBuffer()->GetPixels();
00118         const unsigned short *src = videoPixels;
00119         unsigned int pix0,pix1,pix2,pix3;
00120 
00121         for(int y=0; y<240; y++)
00122         {
00123             // optimized method with 4x loop unrolling and 4 pixels at once
00124             //
00125 #if 1
00126             int w=320/4 + 1;
00127             while(--w)
00128             {
00129                 // read 4 pixels
00130                 //
00131                 pix0 = *src++;
00132                 pix1 = *src++;
00133                 pix2 = *src++;
00134                 pix3 = *src++;
00135 
00136                 // duplicate each pixel into a full 32-bit word
00137                 //
00138                 pix0 |= (pix0<<16);
00139                 pix1 |= (pix1<<16);
00140                 pix2 |= (pix2<<16);
00141                 pix3 |= (pix3<<16);
00142 
00143                 // write all 16 pixels
00144                 //
00145                 dst[0] = dst[320] = pix0;
00146                 dst[1] = dst[321] = pix1;
00147                 dst[2] = dst[322] = pix2;
00148                 dst[3] = dst[323] = pix3;
00149 
00150                 dst+=4;
00151             }
00152 #else       
00153             // slower, simpler method: no unrolling, no optimied loop variable
00154             //
00155             for(int x=0; x<320; x++)
00156             {
00157                 unsigned int pix = *src++;
00158                 pix |= (pix<<16);
00159 
00160                 dst[0] = pix;
00161                 dst[320] = pix;
00162 
00163                 dst++;
00164             }
00165 #endif
00166             dst += 320;
00167         }
00168     }
00169     else
00170     {
00171         unsigned char *dst = (unsigned char *)nDisplay->GetBackBuffer()->GetPixels(160,120);
00172         const unsigned short *src = videoPixels;
00173 
00174         for(int y=0; y<VIDEO_HEIGHT; y++)
00175         {
00176             memcpy(dst, src, VIDEO_WIDTH*2);
00177             dst += nDisplay->GetBackBuffer()->GetPitch();
00178             src += VIDEO_WIDTH;
00179         }
00180     }
00181 }
00182 
00183 
00184 void
00185 TestWinCE::initPixelFormats()
00186 {
00187     pixelFormats.push_back(FORMAT_R5G6B5);
00188     pixelFormats.push_back(FORMAT_R8G8B8);
00189     pixelFormats.push_back(FORMAT_B8G8R8);
00190 }
00191 
00192 
00193 void
00194 TestWinCE::update(openvideo::State* curState)
00195 {
00196     if(curState && curState->frame)
00197         memcpy(videoPixels, (void*)state->frame, VIDEO_WIDTH*VIDEO_HEIGHT*2);
00198 }
00199 
 This page was generated at Wed May 31 13:04:16 2006 for OpenVideo by Doxygen.
 If you have any comments, please send a message to schmalstieg@icg.tu-graz.ac.at.
www.studierstube.org