BLUR.C

Go to the documentation of this file.
00001 /* --
00002 OpenFX version 2.x - Modelling, Animation and Rendering Package
00003 -- */
00004 
00005 /* BLUR.C  */
00006 
00007 #include <stdlib.h>
00008 #include <stdio.h>
00009 #include <float.h>
00010 #include <math.h>
00011 #include <windows.h>
00012 #include "struct.h"           /* general structures    */
00013 #include "..\common\postprocess\ximage.h"
00014 #include "local.h"
00015 
00016 #include "blur.h"
00017 
00018 #if __X__MIPS__
00019 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00020 #endif
00021 
00022 static HINSTANCE hDLLinstance=NULL; /* use to pick up resources from DLL  */
00023 
00024 #include "utils.h"
00025 #include "paint.c"
00026 
00027 #if __WATCOMC__
00028 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00029 #elif __BC__
00030 BOOL WINAPI DllEntryPoint(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00031 #else
00032 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00033 #endif
00034   switch (dwReason) {
00035     case DLL_PROCESS_ATTACH:
00036 #if __X__MIPS__
00037       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00038 #endif
00039       hDLLinstance = hDLL;  /* handle to DLL file */
00040       break;
00041     case DLL_PROCESS_DETACH:
00042 #if __X__MIPS__
00043       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00044 #endif
00045       break;
00046   }
00047 return (int)TRUE;
00048 }
00049 
00050 #if __SC__
00051 #pragma startaddress(DllMain)
00052 #endif
00053 
00054 long _RenderImageProcess(char *PrmList, XIMAGE *lpXimage){
00055  long v,i,j,k,l,ai,aj,atype,back,nmax,n1,n2,Xres,Yres,id1,kmax,lmax,disp;
00056  long matype,mback,mid1,mnmax;
00057  double ar,ag,ab,an,z,mr,dscale;
00058  char name_path[255];
00059  fullscreenbuffer *S,*So,*Si;
00060 #include "pro_key.c"
00061  Xres=lpXimage->Xmax; Yres=lpXimage->Ymax;
00062  So=(fullscreenbuffer *)X__Malloc(Xres*Yres*(long)sizeof(fullscreenbuffer));
00063  if(So == NULL){
00064    MessageBox(GetFocus(),"Memory Out",NULL,MB_OK);
00065    return 0;
00066  }
00067  memcpy(So,lpXimage->Screen,sizeof(fullscreenbuffer)*Xres*Yres);
00068  sscanf(PrmList,"%s %ld %ld %ld %ld %ld",name_path,&nmax,&atype,&back,&id1,&v);
00069  if(lpXimage->Morph && lpXimage->mParameters != NULL){
00070    mr=lpXimage->MorphRatio;
00071    sscanf(lpXimage->mParameters,"%s %ld %ld %ld %ld %ld",
00072           name_path,&mnmax,&matype,&mback,&mid1,&v);
00073    id1=(long)((double)mid1 + mr*((double)id1-(double)mid1));
00074    nmax=(long)((double)mnmax + mr*((double)nmax-(double)mnmax));
00075  }
00076  nmax=nmax*(Xres/320);
00077  if(atype == 2){kmax=1; n1=0;} else {kmax=nmax; n1=nmax/2;}
00078  if(atype == 3){lmax=1; n2=0;} else {lmax=nmax; n2=nmax/2;}
00079  dscale = (double)id1*((double)Xres/320.0)/16384.0;
00080 
00081  if(atype == 1)for(i=0;i<Yres;i++){
00082    for(j=0;j<Xres;j++){
00083      if(back && (lpXimage->Screen+(Xres*i+j))->A > 0)continue;
00084      ar=ag=ab=an=0.0;
00085      for(k=0;k<kmax;k++)for(l=0;l<lmax;l++){
00086        aj=l-n2;
00087        ai=k-n1;
00088        if((i+ai) >= 0 && (j+aj) >= 0 &&
00089           (j+aj) < Xres && (i+ai) < Yres){
00090          Si=(lpXimage->Screen+(Xres*(i+ai))+(j+aj));
00091          if(back && Si->A > 0)continue;
00092          ar+=(double)Si->R;
00093          ag+=(double)Si->G;
00094          ab+=(double)Si->B;
00095          an += 1.0;
00096        }
00097      }
00098      if(an > 0.0){
00099        S=(So+(Xres*i)+j);
00100        S->R = (unsigned char)(min(255.0,ar/an));
00101        S->G = (unsigned char)(min(255.0,ag/an));
00102        S->B = (unsigned char)(min(255.0,ab/an));
00103      }
00104    }
00105  }
00106 
00107  if(atype == 2)for(i=0;i<Yres;i++){
00108    disp=(long)((double)(rand()-16384)*dscale);
00109    for(j=0;j<Xres;j++){
00110      if(back && (lpXimage->Screen+(Xres*i+j))->A > 0)continue;
00111      ar=ag=ab=an=0.0;
00112      for(k=0;k<kmax;k++)for(l=0;l<lmax;l++){
00113        aj=l-n2+disp;
00114        ai=k-n1;
00115        if((i+ai) >= 0 && (j+aj) >= 0 &&
00116           (j+aj) < Xres && (i+ai) < Yres){
00117          Si=(lpXimage->Screen+(Xres*(i+ai))+(j+aj));
00118          if(back && Si->A > 0)continue;
00119          ar+=(double)Si->R;
00120          ag+=(double)Si->G;
00121          ab+=(double)Si->B;
00122          an += 1.0;
00123        }
00124      }
00125      if(an > 0.0){
00126        S=(So+(Xres*i)+j);
00127        S->R = (unsigned char)(min(255.0,ar/an));
00128        S->G = (unsigned char)(min(255.0,ag/an));
00129        S->B = (unsigned char)(min(255.0,ab/an));
00130      }
00131    }
00132  }
00133 
00134  if(atype == 3)for(j=0;j<Xres;j++){
00135    disp=(long)((double)(rand()-16384)*dscale);
00136    for(i=0;i<Yres;i++){
00137      if(back && (lpXimage->Screen+(Xres*i+j))->A > 0)continue;
00138      ar=ag=ab=an=0.0;
00139      for(l=0;l<lmax;l++)for(k=0;k<kmax;k++){
00140        aj=l-n2;
00141        ai=k-n1+disp;
00142        if((i+ai) >= 0 && (j+aj) >= 0 &&
00143           (j+aj) < Xres && (i+ai) < Yres){
00144          Si=(lpXimage->Screen+(Xres*(i+ai))+(j+aj));
00145          if(back && Si->A > 0)continue;
00146          ar+=(double)Si->R;
00147          ag+=(double)Si->G;
00148          ab+=(double)Si->B;
00149          an += 1.0;
00150        }
00151      }
00152      if(an > 0.0){
00153        S=(So+(Xres*i)+j);
00154        S->R = (unsigned char)(min(255.0,ar/an));
00155        S->G = (unsigned char)(min(255.0,ag/an));
00156        S->B = (unsigned char)(min(255.0,ab/an));
00157      }
00158    }
00159  }
00160 
00161  memcpy(lpXimage->Screen,So,sizeof(fullscreenbuffer)*Xres*Yres);
00162  X__Free(So);
00163  return 1;
00164 }
00165 
00166 /*************** Function that renders any of the OpenGL Functionality ************/
00167 
00168 long _RenderGLexternal(char *PrmList, XIMAGE *lpXimage){
00169 MessageBox(NULL,"OpenGL function called","OK",MB_OK);
00170  return 1;
00171 }
00172 
00173 
00174 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
00175 
00176 static int  id1=3,version=1,samples=7,atype=1,back=1;
00177 
00178 char * _SetExternalParameters(
00179   char *Op,                 /* string for the parameters                  */
00180   HWND hWnd,                /* parent window                              */
00181   long ruler,               /* ruler scale value to facilitate scaling    */
00182   char *name,               /* name of DLL file with the effect           */
00183   X__MEMORY_MANAGER *lpEVI /* pointer to structure with memory functions */
00184                                     ){
00185  /* output name and buffer should be as long as necessary to hold full string */
00186  char buffer[256];
00187  if(Op != NULL){  /* parameters exist so read them off the list */
00188    sscanf(Op,"%s %ld %ld %ld %ld %ld",buffer,&samples,&atype,&back,&id1,&version);
00189  }
00190  /*   Do the user interface as required to set up the effect, may use a     */
00191  /*   dialog box etc. Return old string if effect is cancelled (no change)  */
00192  if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG_BLUR),hWnd,
00193               (DLGPROC)DlgProc) == FALSE)return Op;
00194  /* Free space occupied by old parameter string */
00195  if(Op != NULL)CALL_FREE(Op);  /* free the old string */
00196  /* print the parameters into the buffer */
00197  sprintf(buffer,"%s %ld %ld %ld %ld %ld",name,samples,atype,back,id1,version);
00198  /* Prepare the output buffer to take copy of parameter list */
00199  if((Op=(char *)CALL_MALLOC(strlen(buffer)+1)) == NULL){
00200   MessageBox (GetFocus(),"External effect: Out of memory","Error",
00201                 MB_OK|MB_TASKMODAL|MB_ICONSTOP);
00202    return NULL;
00203  }
00204  /* Copy the parameter string to the output buffer */
00205  strcpy(Op,buffer);
00206  return Op;
00207 }
00208 
00209 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
00210  char str[32];
00211  BOOL err;
00212  switch( msg ) {
00213    case WM_INITDIALOG:
00214      SetDlgItemInt(hwnd,DLG_BLUR_SAMPLES,samples,FALSE);
00215      SetDlgItemInt(hwnd,DLG_BLUR_D1,id1,FALSE);
00216      if(back == 1)SendDlgItemMessage(hwnd,DLG_BLUR_BACK,BM_SETCHECK,TRUE,0);
00217      if     (atype == 1)
00218        SendDlgItemMessage(hwnd,DLG_BLUR_ACC1,BM_SETCHECK,TRUE,0);
00219      else if(atype == 2)
00220        SendDlgItemMessage(hwnd,DLG_BLUR_ACC2,BM_SETCHECK,TRUE,0);
00221      else
00222        SendDlgItemMessage(hwnd,DLG_BLUR_ACC3,BM_SETCHECK,TRUE,0);
00223      CentreDialogOnScreen(hwnd);
00224      return TRUE;
00225    case WM_PAINT:
00226      PaintBackground(hwnd);
00227      break;
00228    case WM_COMMAND:
00229      switch(LOWORD(wparam)){
00230         case IDCANCEL:
00231           EndDialog(hwnd,FALSE);
00232           return(TRUE);
00233         case IDOK:
00234           samples=GetDlgItemInt(hwnd,DLG_BLUR_SAMPLES,&err,FALSE);
00235           id1=GetDlgItemInt(hwnd,DLG_BLUR_D1,&err,FALSE);
00236           if(samples < 0)samples=1;
00237           if(SendDlgItemMessage(hwnd,DLG_BLUR_BACK,BM_GETCHECK,0,0))
00238                back=1;
00239           else back=0;
00240           if   (SendDlgItemMessage(hwnd,DLG_BLUR_ACC3,BM_GETCHECK,0,0))
00241                atype=3;
00242           else if(SendDlgItemMessage(hwnd,DLG_BLUR_ACC2,BM_GETCHECK,0,0))
00243                atype=2;
00244           else atype=1;
00245           EndDialog(hwnd,TRUE);
00246           return(TRUE);
00247         default:
00248           break;
00249       }
00250       break;
00251     default: break;
00252  }
00253  return FALSE;
00254 }
00255 

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