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

XFuVideoRecorder.cpp

Go to the documentation of this file.
00001 /*! \file 
00002  * X-Forge Util <br>
00003  * Copyright 2000-2003 Fathammer Ltd
00004  * 
00005  * \brief Video recorder class (for desktop use)
00006  * 
00007  * $Id: XFuVideoRecorder.cpp,v 1.7 2003/08/12 13:34:08 lars Exp $
00008  * $Date: 2003/08/12 13:34:08 $
00009  * $Revision: 1.7 $
00010  */
00011 #include <xfcore/XFcCore.h>
00012 #include <xfutil/XFuVideoRecorder.h>
00013 
00014 XFuVideoRecorder::XFuVideoRecorder()
00015 {
00016     mLastTick = (FLOAT32)XFcCore::getTick();
00017     mTicksPerFrame = 1;
00018     mFrame = 0;
00019     mPrefix = NULL;
00020 }
00021 
00022 
00023 static const UINT8 xfuBmpHdr[] = 
00024 {
00025         0x42,0x4d,0x38,0x84,
00026         0x03,0x00,0x00,0x00,
00027         0x00,0x00,0x36,0x00,
00028         0x00,0x00,0x28,0x00,
00029         0x00,0x00,0xF0,0x00,
00030         0x00,0x00,0x40,0x01,
00031         0x00,0x00,0x01,0x00,
00032         0x18,0x00,0x00,0x00,
00033         0x00,0x00,0x00,0x00,
00034         0x00,0x00,0x12,0x0B,
00035         0x00,0x00,0x12,0x0B,
00036         0x00,0x00,0x00,0x00,
00037         0x00,0x00,0x00,0x00,
00038         0x00,0x00
00039 };
00040 
00041 
00042 void XFuVideoRecorder::storeFrame(XFcGLSurface *aSurface)
00043 {
00044     CHAR name[32];
00045     XFcStringToolkit::format(name, "%s%04d.bmp", mPrefix, mFrame);
00046     XFcFile *f = XFcFile::open(name, XFCSTR("wb"));
00047 
00048     UINT8 bmphdr[54];
00049     memcpy(bmphdr, xfuBmpHdr, 54);
00050 
00051     UINT16 *buf;
00052     aSurface->lock((void **)&buf, XFCGF_R5G5X1B5, XFCGFX_DISCARDCHANGES);    
00053     if (buf == NULL)
00054     {
00055         f->close();
00056         return;
00057     }
00058     
00059     INT32 width = aSurface->getWidth();
00060     INT32 height = aSurface->getHeight();
00061 
00062     *((INT32 *)(bmphdr + 18)) = width;
00063     *((INT32 *)(bmphdr + 22)) = height;   
00064     
00065     f->write(bmphdr, 1, 54);
00066     
00067     INT32 j,i;
00068     for (j = 0; j < height; j++)
00069     {
00070         for (i = 0; i < width; i++) 
00071         {
00072             int srccolor = buf[((height - 1) - j) * width + i];
00073             int c = ((srccolor & 0x001f) << 3) + 
00074                     ((srccolor & 0x07c0) << 5) + 
00075                     ((srccolor & 0xf800) << 8); 
00076             f->write(&c, 3, 1);
00077         }                
00078     }
00079     f->close();
00080     aSurface->unlock();
00081 
00082     mFrame++;
00083 }
00084 
00085 
00086 XFuVideoRecorder * XFuVideoRecorder::create(const CHAR *aPrefix, INT32 aDesiredFPS)
00087 {
00088     if (aDesiredFPS <= 0)
00089         return NULL;
00090 
00091     XFuVideoRecorder * v = new XFuVideoRecorder();
00092     
00093     if (v == NULL)
00094         return NULL;
00095     
00096     if (aPrefix != NULL)
00097     {
00098         v->mPrefix = XFcStringToolkit::copy(aPrefix);
00099         if (v->mPrefix == NULL)
00100         {
00101             delete v;
00102             return NULL;
00103         }
00104         
00105     }
00106     
00107     v->mTicksPerFrame = 1000.0f / (FLOAT32)aDesiredFPS;
00108     
00109     return v;
00110 }
00111  
00112 
00113 void XFuVideoRecorder::tick(XFcGLSurface *aSurface)
00114 {
00115     FLOAT32 tick = (FLOAT32)XFcCore::getTick();
00116 
00117     if (tick - mLastTick < mTicksPerFrame)
00118         return;
00119 
00120     while (mLastTick < tick - mTicksPerFrame)
00121     {
00122         storeFrame(aSurface);
00123         mLastTick += mTicksPerFrame;
00124     }
00125 }
00126 
00127 
00128 XFuVideoRecorder::~XFuVideoRecorder()
00129 {
00130     delete[] mPrefix;
00131 }
00132 

   
X-Forge Documentation
Confidential
Copyright © 2002-2003 Fathammer
   
Documentation generated
with doxygen
by Dimitri van Heesch