Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

AVI.cpp

Go to the documentation of this file.
00001 #include "AVI.h"
00002 
00003 AVI::AVI() {
00004 
00005         curFrame = 0;
00006         hdc = CreateCompatibleDC(0);
00007 
00008         hdd = DrawDibOpen();
00009         data = 0;
00010         elapsedTime = 0;
00011         glGenTextures(1, &texture);
00012 
00013         scale = 1;
00014         play = true;
00015         looping = false;
00016         direction = true;
00017 
00018 }
00019 
00020 AVI::~AVI() {
00021 
00022 }
00023 
00024 void AVI::unload() {
00025         DeleteObject(hBitmap);
00026         DrawDibClose(hdd);
00027         AVIStreamGetFrameClose(pgf);
00028         AVIStreamRelease(pavi);
00029         AVIFileExit();
00030 }
00031 
00032 bool AVI::load(LPCSTR filename) {
00047         AVIFileInit();
00048 
00049         done = false;
00050 
00051         if(AVIStreamOpenFromFile(&pavi,filename,streamtypeVIDEO,0,OF_READ,NULL) != 0) {
00052                 LOG_ERROR(("Failed to Open the AVI Stream"));
00053                 return false;
00054         }
00055 
00056         AVIStreamInfo(pavi,&psi,sizeof(psi));
00057 
00058         width = psi.rcFrame.right - psi.rcFrame.left;
00059         height = psi.rcFrame.bottom - psi.rcFrame.top;
00060 
00061         //grab the last frame
00062 
00063         lastframe = AVIStreamLength(pavi);
00064 
00065         //grab the length of time of a frame
00066 
00067         millisPerFrame = AVIStreamSampleToTime(pavi,1);
00068 
00069         //Set up our bitmap stuff to resize our texture
00070 
00071         bmih.biSize = sizeof(BITMAPINFOHEADER);
00072         bmih.biPlanes = 1;
00073         bmih.biBitCount = 24;
00074         bmih.biWidth = 256;
00075         bmih.biHeight = 256;
00076         //requested compression mode
00077 
00078         bmih.biCompression = BI_RGB;
00079 
00080         //Create the dib
00081 
00082         hBitmap = CreateDIBSection(hdc,(BITMAPINFO*)(&bmih),DIB_RGB_COLORS,(void**)(&data),NULL,NULL);
00083         //select our hbitmap into our dc
00084 
00085         SelectObject(hdc,hBitmap);
00086 
00087         //create a getframe object
00088 
00089         pgf = AVIStreamGetFrameOpen(pavi,NULL);
00090         //check to see if we screwed up
00091 
00092         if(pgf == NULL)
00093         {
00094                 LOG_ERROR(("Failed to create a GetFrame object"));
00095                 return false;
00096         }
00097 
00098         //now we have to create the gl texture
00107         return true;
00108 }
00109 
00110 void AVI::setFrame(int frame) {
00111         if ((frame <= lastframe) && (frame >= 0)) {
00112                 elapsedTime = frame*millisPerFrame;
00113                 curFrame = frame;
00114         }
00115 }
00116 
00117 void AVI::update(DWORD milliseconds)
00118 {
00119 
00120         if(play)
00121         {
00122                 if(direction)
00123                 {
00124                         elapsedTime += (DWORD)(milliseconds*scale);
00125                         curFrame = int((float)elapsedTime/(float)millisPerFrame);
00126 
00127                         if(curFrame >= lastframe)
00128                         {
00129                                 if(looping)
00130                                 {
00131                                         elapsedTime = 0;
00132                                         curFrame = 0;
00133                                 }
00134                                 else
00135                                 {
00136                                         curFrame = lastframe -1;
00137                                         done = true;
00138                                 }
00139                         }               
00140                 }
00141                 else
00142                 {
00143                         elapsedTime -= (int)(milliseconds*scale);
00144                         curFrame = int((float)elapsedTime/(float)millisPerFrame);                       
00145 
00146                         if(curFrame < 0)
00147                         {
00148                                 if(looping)
00149                                 {
00150                                         elapsedTime = (lastframe-1)*millisPerFrame;
00151                                         curFrame = lastframe-1;
00152                                 }
00153                                 else
00154                                 {
00155                                         curFrame = 0;
00156                                         done = true;
00157                                 }
00158                         }               
00159                 }       
00160         }
00161 }
00162 
00163 GLuint AVI::genTex(int w, int h) {
00164         LPBITMAPINFOHEADER lpbi;
00165         //grab the tex data
00166 
00167         //clamp the current frame
00168 
00169         if(curFrame < 0)
00170                 curFrame = 0;
00171         if(curFrame >= lastframe)
00172                 curFrame = lastframe - 1;
00173         lpbi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(pgf, curFrame);
00174         pdata = (char*)lpbi + lpbi->biSize + lpbi->biClrUsed*sizeof(RGBQUAD);
00175         DrawDibDraw(hdd,hdc,0,0,w,h,lpbi,pdata,0,0,width,height,0);
00176 
00177         //flip the colors
00178 
00179         void * b = data;
00180         __asm
00181         {
00182                 mov ecx,256*256
00183                 mov ebx, b
00184                 label:
00185                         mov al,[ebx+0]
00186                         mov ah,[ebx+2]
00187                         mov [ebx+2],al
00188                         mov [ebx+0],ah
00189 
00190                         add ebx,3
00191                         dec ecx
00192                         jnz label
00193         }
00194 /*
00195         glBindTexture(GL_TEXTURE_2D, texture);
00196         //update our texture
00197 
00198         glTexSubImage2D(GL_TEXTURE_2D,0,0,0,256,256,GL_RGB,GL_UNSIGNED_BYTE,data);
00199 */
00200         return texture;
00201 }
00202 
00203 void AVI::setState(int state) {
00220 }

Generated on Sun Jun 5 15:47:03 2005 for Defacto by  doxygen 1.4.3