avi_map.c

Go to the documentation of this file.
00001 /* --
00002 OpenFX version 2.0 - Modelling, Animation and Rendering Package
00003 Copyright (C) 2000 - 2007 OpenFX Development Team
00004 -- */
00005 
00006 /*  AVI_MAP.C  */
00007 
00008 // This does not work for  DV encoded video but does for  Uncompressed and  Cinepak codecs.
00009 
00010 #include <stdlib.h>
00011 #include <stdio.h>
00012 #include <windows.h>
00013 #include <vfw.h>
00014 
00015 #include "../common/mem.h"
00016 
00017 typedef struct SCREENBUFFER {
00018  unsigned char A,R,G,B;
00019 } fullscreenbuffer;
00020 
00021 static long LoadBmpImageMap(char *fn, long *xxx, long *yyy, BOOL size_only,
00022    unsigned char *pR, unsigned char *pG, unsigned char *pB, unsigned char *source_buffer);
00023 static HINSTANCE hThisInstance;
00024 
00025 #if __WATCOMC__
00026 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00027 #else
00028 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00029 #endif
00030   switch (dwReason) {
00031     case DLL_PROCESS_ATTACH: {
00032       hThisInstance=hDLL;
00033       break;
00034     }
00035     case DLL_PROCESS_DETACH:
00036       break;
00037   }
00038   return TRUE;
00039 }
00040 
00041 BOOL _PutExternalImage
00042  (char *szOutFileName,
00043   long nx, long ny,
00044   long quality,
00045   fullscreenbuffer *image){
00046  return FALSE;
00047 }
00048 
00049 BOOL _GetExternalImageSize
00050  (char *filename,
00051   long *x,
00052   long *y,
00053   long frame){
00054  LONG hr; 
00055  AVIFILEINFO fi,*pfi;
00056  PAVIFILE pfile; 
00057  pfi=&fi;
00058  hr = AVIFileOpen(&pfile, filename,OF_SHARE_DENY_WRITE,0L); 
00059  if (hr != 0)return FALSE;
00060  if(AVIFileInfo(pfile,pfi,sizeof(AVIFILEINFO)) != 0){AVIFileRelease(pfile); return FALSE;}
00061  *y = pfi->dwHeight;
00062  *x = pfi->dwWidth;
00063  AVIFileRelease(pfile);  // closes the file 
00064  return TRUE;
00065 }
00066 
00067 BOOL _GetExternalImage
00068  (char *filename,
00069   long x, long y,
00070   unsigned char *Red,
00071   unsigned char *Green,
00072   unsigned char *Blue,
00073   long frame){
00074  BOOL bWorked=FALSE;
00075  LONG hr; 
00076  LPSTR pformat;
00077  AVIFILEINFO fi,*pfi;
00078  PAVIFILE pfile; 
00079  PAVISTREAM psin[5];
00080  AVISTREAMINFO avis; 
00081  LPBITMAPINFOHEADER lpBmi;
00082  BITMAPINFOHEADER Bmi;
00083  long i,j,ff,size,vstream = -1;
00084  long nsamples;
00085  char buffer[256];
00086  unsigned char *r,*g,*b,*pp,*prow;
00087  pfi=&fi;
00088  hr = AVIFileOpen(&pfile, filename,OF_SHARE_DENY_WRITE,0L); 
00089  if (hr != 0)return FALSE;
00090  if(AVIFileInfo(pfile,pfi,sizeof(AVIFILEINFO)) != 0){AVIFileRelease(pfile); return FALSE;}
00091  if(y != pfi->dwHeight){AVIFileRelease(pfile); return FALSE;}
00092  if(x != pfi->dwWidth){AVIFileRelease(pfile); return FALSE;}
00093  for(i=0;i<5;i++){
00094    psin[i]=NULL;
00095    if(AVIFileGetStream(pfile,&psin[i],0,i) == AVIERR_OK){
00096      AVIStreamInfo(psin[i],&avis,sizeof(avis));
00097      if(avis.fccType == streamtypeVIDEO){
00098        vstream=i;
00099        AVIStreamFormatSize(psin[i],0,&size);
00100        if((pformat = (LPSTR)X__Malloc(size)) != NULL){
00101          if(AVIStreamReadFormat(psin[i],0,pformat,&size) == AVIERR_OK){
00102            lpBmi=(LPBITMAPINFOHEADER)pformat;
00103            sprintf(buffer,"Size (%ld %ld) Bits %ld",lpBmi->biWidth,lpBmi->biHeight,
00104                    (long)(lpBmi->biBitCount));
00105            memcpy(&Bmi,pformat,sizeof(BITMAPINFOHEADER)); 
00106            //MessageBox(NULL,buffer,"AVI_FILE",MB_OK);
00107            nsamples=AVIStreamEnd(psin[i]);
00108            sprintf(buffer,"%ld Frames (%0.3lfs)",nsamples,
00109            (double)AVIStreamSampleToTime(psin[i],nsamples)*0.001);
00110            //MessageBox(NULL,buffer,"AVI_FILE",MB_OK);
00111          }
00112          X__Free(pformat);
00113        }
00114        break;
00115      }
00116    }
00117  } 
00118  ff=frame%nsamples - 1; ff=max(0,ff); ff=min(ff,nsamples);
00119  if(vstream >= 0){
00120    LPBITMAPINFOHEADER lpbi; 
00121    PGETFRAME pgf;
00122    //MessageBox(NULL,"About to open stream","AVI_FILE",MB_OK);
00123    lpbi=&Bmi;
00124    memset(lpbi,0,sizeof(BITMAPINFOHEADER));
00125    lpbi->biSize=sizeof(BITMAPINFOHEADER);
00126    lpbi->biWidth=(DWORD)x;
00127    lpbi->biHeight=(DWORD)y;
00128    lpbi->biPlanes=1;
00129    lpbi->biBitCount=24;
00130    lpbi->biCompression=BI_RGB;
00131    lpbi->biSizeImage = 0;
00132    lpbi->biXPelsPerMeter=0;
00133    lpbi->biYPelsPerMeter=0;
00134    lpbi->biClrUsed=0;
00135    lpbi->biClrImportant=0;
00136    pgf=AVIStreamGetFrameOpen(psin[vstream],lpbi);
00137    if(pgf != NULL){
00138      //MessageBox(NULL,"StreamOpen","AVI_FILE",MB_OK);
00139      pp=AVIStreamGetFrame(pgf,ff); 
00140      if(pp != NULL){
00141        lpBmi=(LPBITMAPINFOHEADER)pp;
00142        sprintf(buffer,"Frame %ld Size (%ld %ld) Bits %ld colours %ld  size %ld",ff,lpBmi->biWidth,lpBmi->biHeight,
00143                    (long)(lpBmi->biBitCount),(long)lpBmi->biClrUsed,(long)lpBmi->biSizeImage);
00144 //       MessageBox(NULL,buffer,"Writing Output",MB_OK);
00145        r=Red; g=Green; b=Blue; pp += sizeof(BITMAPINFOHEADER);
00146        for(i=0;i<y;i++){
00147          prow=(pp+x*(y-i-1)*3);
00148          for(j=0;j<x;j++){
00149           *b++ = *prow++;
00150           *g++ = *prow++;
00151           *r++ = *prow++;
00152          }
00153        }
00154        bWorked=TRUE;
00155      }
00156      AVIStreamGetFrameClose(pgf);
00157    }
00158    AVIStreamRelease(psin[vstream]);
00159  }
00160  AVIFileRelease(pfile);  
00161  return bWorked;
00162 }
00163 

Generated on Sun Apr 27 14:20:13 2014 for OpenFX by  doxygen 1.5.6