Horus Doc || Corba Reference || Corba   Client Server   Stubs C++   Stubs Java   Servant Generator  

mainDemoVideo.c File Reference

#include <vector>
#include "HxTimer.h"
#include "HxDXMedia.h"
#include "HxImageSeq.h"
#include "HxExportByteData.h"
#include "HxMakeFromByteData.h"

Functions

void showTimeInfo (bool theEnd)
int visitUsingSequence (HxString seqName)
int visitUsingDX (HxString seqName)
int testDisplayDX ()
void showUsage (char *progName)
int main (int argc, char *argv[])

Variables

int verbose = 0
bool doDisplay = false
bool doStep = false
int nFrames
int width
int height
HxTimer t
int nr
double total
double estTime
double fps

Function Documentation

void showTimeInfo bool    theEnd
 

00038 {
00039     total += t.lastTime();
00040     nr++;
00041     fps = nr / total;
00042     estTime = nFrames / fps;
00043     if (((verbose > 0) && (nr % verbose == 0)) || theEnd) {
00044         STD_COUT << "nr " << nr << " in "
00045                  << t.lastTime() << " s, " << fps << " fps, "
00046                  << "E " << total << " s, R " << estTime - total
00047                  << " s" << STD_ENDL;
00048     }
00049     if (theEnd)
00050         return;
00051     if (doStep) {
00052         char c;
00053         STD_COUT << "Hit return - ";
00054         c = STD_CIN.get();
00055     }
00056 }

int visitUsingSequence HxString    seqName
 

00060 {
00061     HxImageSeq seq(seqName, 0);
00062     nFrames = seq.nrFrames();
00063     STD_COUT << "Frames : " << nFrames << STD_ENDL;
00064     width = seq.frameWidth();
00065     height = seq.frameHeight();
00066     STD_COUT << "Width x height = " << width << " x " << height << STD_ENDL;
00067 
00068     void* dispH = 0;
00069     if (doDisplay)
00070         dispH = HxDXBeginDisplay(width, height);
00071 
00072     nr = 0;
00073     total = 0;
00074     int nPix = width * height;
00075     unsigned char* charBuf = new unsigned char[nPix * 3];
00076     int* intBuf = new int[nPix];
00077 
00078     for (HxImageSeqIter it = seq.begin() ; it != seq.end() ; it++) {
00079         t.start();
00080         HxImageRep im = *it;
00081 //        HxValue v = im.sum();
00082 //STD_COUT << "v: " << v << STD_ENDL;
00083 
00084 //        for (int i=0 ; i<nPix ; i++)
00085 //            buf[i] = 200;
00086 
00087         //im.exportOp(charBuf);
00088         HxExportByteData(im, charBuf);
00089 
00090         /*
00091         im.getRgbPixels2d(intBuf, HxString("Direct"));
00092         int* src = intBuf;
00093         unsigned char* dst = charBuf;
00094         int n = nPix;
00095         while(n--) {
00096             unsigned char r =  (unsigned char)((*src & 0x00ff0000) >> 16); //r
00097             unsigned char g =  (unsigned char)((*src & 0x0000ff00) >>  8); //g
00098             unsigned char b =  (unsigned char)((*src & 0x000000ff)      ); //b
00099             *dst++ = r;
00100             *dst++ = g;
00101             *dst++ = b;
00102             src++;
00103         }
00104 */
00105         if (dispH)
00106             HxDXPutFrame(dispH, charBuf);
00107         t.stop();
00108         showTimeInfo(false);
00109     }
00110     showTimeInfo(true);
00111     if (dispH != 0)
00112         HxDXEndDisplay(dispH);
00113     return 0;
00114 }

int visitUsingDX HxString    seqName
 

00118 {
00119     void* handle = HxDXLoadVideo(seqName.c_str());
00120     nFrames = HxDXGetLength(handle);
00121     STD_COUT << "Frames : " << nFrames << STD_ENDL;
00122     width = HxDXGetFrameWidth(handle);
00123     height = HxDXGetFrameHeight(handle);
00124     STD_COUT << "Width x height = " << width << " x " << height << STD_ENDL;
00125     HxSizes sizes = HxSizes(width, height, 1);
00126 
00127     void* dispH = 0;
00128     if (doDisplay)
00129         dispH = HxDXBeginDisplay(width, height);
00130 
00131     nr = 0;
00132     total = 0;
00133     int bufSize = width * height * 3;
00134     unsigned char* bufCopy = new unsigned char[bufSize];
00135 
00136     for (int it = 0 ; it < nFrames-1 ; it++) {
00137         t.start();
00138         unsigned char* data = HxDXGetFrame(handle, it);
00139 //STD_COUT << "Got frame" << STD_ENDL;
00140         if (data) {
00141 //            for (int i=0 ; i<bufSize ; i++)
00142 //                bufCopy[i] = data[i];
00143             HxImageRep im = HxMakeFromByteData(3, 2, sizes, data);
00144 //            HxValue v = im.max();
00145             HxExportByteData(im, bufCopy);
00146             if (dispH)
00147                 HxDXPutFrame(dispH, bufCopy);
00148 //                HxDXPutFrame(dispH, data);
00149         }
00150         t.stop();
00151         showTimeInfo(false);
00152     }
00153     showTimeInfo(true);
00154     HxDXCloseVideo(handle);
00155     if (dispH != 0)
00156         HxDXEndDisplay(dispH);
00157     return 0;
00158 }

int testDisplayDX  
 

00162 {
00163     int width = 320;
00164     int height = 200;
00165     HxSizes sizes(width, height, 1);
00166     void* dispH = HxDXBeginDisplay(width, height);
00167     HxTimer t;
00168     int nFrames = 1000;
00169     int nr = 0;
00170     double total = 0;
00171     double estTime;
00172     double fps;
00173     int bufSize = width * height * 4;
00174     unsigned char* buf = new unsigned char[bufSize];
00175     for (int it = 0 ; it < nFrames ; it++) {
00176         t.start();
00177         for (int i=0 ; i<bufSize ; i++)
00178             buf[i] = it % 250;
00179         HxDXPutFrame(dispH, buf);
00180         t.stop();
00181         total += t.lastTime();
00182         nr++;
00183         fps = nr / total;
00184         estTime = nFrames / fps;
00185         if (nr % 20 == 0) {
00186             STD_COUT << "fr " << nr << " (" << nFrames << ") in "
00187                    << t.lastTime() << " s\t " << fps << " fps, "
00188                    << "E " << total << " R " << estTime - total
00189                    << STD_ENDL;
00190         }
00191     }
00192     HxDXEndDisplay(dispH);
00193     return 0;
00194 }

void showUsage char *    progName
 

00198 {
00199     STD_COUT
00200     << "Usage : " << progName << " [-source videoFile] " << STD_ENDL
00201     << "    [--generator] [-verb perNrFrames] " << STD_ENDL
00202     << "    [--useHxImageSeq] [--display] [--step] [--help]" << STD_ENDL;
00203 }

int main int    argc,
char *    argv[]
 

00207 {
00208     HxString videoFile;
00209     bool useGenerator = false;
00210     bool useHxImageSeq = false;
00211 
00212     int i = 1;
00213     while (i < argc) {
00214         if (HxString(argv[i]) == "-source") {
00215             videoFile = HxString(argv[i+1]);
00216             i++;
00217         }
00218         if (HxString(argv[i]) == "--generator")
00219             useGenerator = true;
00220         if (HxString(argv[i]) == "-verb") {
00221             verbose = atol(argv[i+1]);
00222             i++;
00223         }
00224         if (HxString(argv[i]) == "--useHxImageSeq")
00225             useHxImageSeq = true;
00226         if (HxString(argv[i]) == "--display")
00227             doDisplay = true;
00228         if (HxString(argv[i]) == "--step")
00229             doStep = true;
00230         if (HxString(argv[i]) == "--help") {
00231             showUsage(argv[0]);
00232             return 1;
00233         }
00234         i++;
00235     }
00236 
00237     // need videoFile or generator
00238     if ((videoFile == "") && !useGenerator) {
00239         showUsage(argv[0]);
00240         return 1;
00241     }
00242 
00243     if (useGenerator)
00244         STD_COUT << "Using generator" << STD_ENDL;
00245     else
00246         STD_COUT << "videoFile : " << videoFile << STD_ENDL;
00247     STD_COUT << "useHxImageSeq : " << useHxImageSeq << STD_ENDL;
00248     STD_COUT << "doDisplay : " << doDisplay << STD_ENDL;
00249 
00250     if (useGenerator)
00251         return testDisplayDX();
00252     if (useHxImageSeq)
00253         return visitUsingSequence(videoFile);
00254     return visitUsingDX(videoFile);
00255 }


Variable Documentation

int verbose = 0 [static]
 

bool doDisplay = false [static]
 

bool doStep = false [static]
 

int nFrames
 

int width
 

int height
 

HxTimer t [static]
 

int nr [static]
 

double total [static]
 

double estTime [static]
 

double fps [static]
 


Generated on Tue Feb 3 14:20:13 2004 for CorbaReference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001