DOF.C

Go to the documentation of this file.
00001 /* --
00002 OpenFX version 2.0 - Modelling, Animation and Rendering Package
00003 Copyright (C) 2000 -  OpenFX Development Team
00004 
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019 You may contact the OpenFX development team via elecronic mail
00020 at core@openfx.org, or visit our website at http://openfx.org for
00021 further information and support details.
00022 -- */
00023 
00024 /* DOF.C  Image post-processor using Z buffer                            */
00025 /*                                                                       */
00026 
00027 #include <stdlib.h>
00028 #include <stdio.h>
00029 #include <float.h>
00030 #include <math.h>
00031 #include <windows.h>
00032 #include "struct.h"           /* general structures    */
00033 #include "..\common\postprocess\ximage.h"
00034 #include "local.h"
00035 
00036 #include "dof.h"
00037 
00038 #if __X__MIPS__
00039 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00040 #endif
00041 
00042 static HINSTANCE hDLLinstance=NULL; /* use to pick up resources from DLL  */
00043 
00044 #include "utils.h"
00045 
00046 #include "paint.c"
00047 
00048 #if __WATCOMC__
00049 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00050 #elif __BC__
00051 BOOL WINAPI DllEntryPoint(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00052 #else
00053 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00054 #endif
00055   switch (dwReason) {
00056     case DLL_PROCESS_ATTACH:
00057 #if __X__MIPS__
00058       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00059 #endif
00060       hDLLinstance = hDLL;  /* handle to DLL file */
00061       break;
00062     case DLL_PROCESS_DETACH:
00063 #if __X__MIPS__
00064       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00065 #endif
00066       break;
00067   }
00068 return (int)TRUE;
00069 }
00070 
00071 #if __SC__
00072 #pragma startaddress(DllMain)
00073 #endif
00074 
00075 long _RenderImageProcess(char *PrmList, XIMAGE *lpXimage){
00076  long v,i,j,k,l,ai,aj,n,atype,back,nmax,n2,Xres,Yres,id1;
00077  long matype,mback,mid1,mnmax;
00078  double d1,d2,ar,ag,ab,an,z,mr;
00079  char name_path[255];
00080  fullscreenbuffer *S,*So,*Si;
00081  float *Z;
00082 #include "pro_key.c"
00083  if((Z=lpXimage->Zbuffer) == NULL){
00084    MessageBox(GetFocus(),"Z buffer must be available for this effect",
00085               NULL,MB_OK);
00086    return 0;
00087  }
00088  Xres=lpXimage->Xmax; Yres=lpXimage->Ymax;
00089  So=(fullscreenbuffer *)X__Malloc(Xres*Yres*(long)sizeof(fullscreenbuffer));
00090  if(So == NULL){
00091    MessageBox(GetFocus(),"Memory Out",NULL,MB_OK);
00092    return 0;
00093  }
00094  memcpy(So,lpXimage->Screen,sizeof(fullscreenbuffer)*Xres*Yres);
00095  sscanf(PrmList,"%s %ld %ld %ld %ld %ld",name_path,&nmax,&atype,&back,&id1,&v);
00096  if(lpXimage->Morph && lpXimage->mParameters != NULL){
00097    mr=lpXimage->MorphRatio;
00098    sscanf(lpXimage->mParameters,"%s %ld %ld %ld %ld %ld",
00099           name_path,&mnmax,&matype,&mback,&mid1,&v);
00100    id1=(long)((double)mid1 + mr*((double)id1-(double)mid1));
00101    nmax=(long)((double)mnmax + mr*((double)nmax-(double)mnmax));
00102  }
00103  d1=(double)id1;
00104  nmax=nmax*(Xres/320);
00105 //sprintf(name_path,"nmax=%ld acc=%ld back=%ld",nmax,atype,back);
00106 //MessageBox(NULL,name_path,"Debug",MB_OK);
00107  for(i=0;i<Yres;i++){
00108    for(j=0;j<Xres;j++){
00109      Z=(lpXimage->Zbuffer+(Xres*i)+j);
00110      if(!back && *Z > FARAWAY-10.0)continue;
00111      z=min(1.0,fabs(1.0-d1/(*Z)));
00112      n=1+(int)((double)nmax*z);
00113      n2=n/2;
00114      ar=ag=ab=an=0.0;
00115      for(k=0;k<n;k+=atype)for(l=0;l<n;l+=atype){
00116        ai=k-n2; aj=l-n2;
00117        if((i+ai) >= 0 && (j+aj) >= 0 &&
00118           (j+aj) < Xres && (i+ai) < Yres){
00119          Si=(lpXimage->Screen+(Xres*(i+ai))+(j+aj));
00120          ar+=(double)Si->R;
00121          ag+=(double)Si->G;
00122          ab+=(double)Si->B;
00123          an += 1.0;
00124        }
00125      }
00126 
00127      if(an > 0.0){
00128        S=(So+(Xres*i)+j);
00129        S->R = (unsigned char)(min(255.0,ar/an));
00130        S->G = (unsigned char)(min(255.0,ag/an));
00131        S->B = (unsigned char)(min(255.0,ab/an));
00132      }
00133    }
00134  }
00135  memcpy(lpXimage->Screen,So,sizeof(fullscreenbuffer)*Xres*Yres);
00136  X__Free(So);
00137  return 1;
00138 }
00139 
00140 /*************** Function that renders anyof the OpenGL Functionality ************/
00141 
00142 long _RenderGLexternal(char *PrmList, XIMAGE *lpXimage){
00143 MessageBox(NULL,"Fog OpenGL function called","OK",MB_OK);
00144  return 1;
00145 }
00146 
00147 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
00148 
00149 static double   d1=2.0;
00150 static int      version=1,samples=7,atype=1,back=1;
00151 
00152 char * _SetExternalParameters(
00153   char *Op,                 /* string for the parameters                  */
00154   HWND hWnd,                /* parent window                              */
00155   long ruler,               /* ruler scale value to facilitate scaling    */
00156   char *name,               /* name of DLL file with the effect           */
00157   X__MEMORY_MANAGER *lpEVI /* pointer to structure with memory functions */
00158                                     ){
00159  /* output name and buffer should be as long as necessary to hold full string */
00160  char buffer[256];
00161  long id1,id2;   /* integer scaled radius value */
00162  if(Op != NULL){  /* parameters exist so read them off the list */
00163    sscanf(Op,"%s %ld %ld %ld %ld %ld",buffer,&samples,&atype,&back,&id1,&version);
00164    d1=(double)id1/(double)ruler;
00165  }
00166  /*   Do the user interface as required to set up the effect, may use a     */
00167  /*   dialog box etc. Return old string if effect is cancelled (no change)  */
00168  if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG_DOF),hWnd,
00169               (DLGPROC)DlgProc) == FALSE)return Op;
00170  /* Free space occupied by old parameter string */
00171  if(Op != NULL)CALL_FREE(Op);  /* free the old string */
00172  /* print the parameters into the buffer */
00173  id1=(long)(d1*(double)ruler);
00174  sprintf(buffer,"%s %ld %ld %ld %ld %ld",name,samples,atype,back,id1,version);
00175  /* Prepare the output buffer to take copy of parameter list */
00176  if((Op=(char *)CALL_MALLOC(strlen(buffer)+1)) == NULL){
00177   MessageBox (GetFocus(),"External effect: Out of memory","Error",
00178                 MB_OK|MB_TASKMODAL|MB_ICONSTOP);
00179    return NULL;
00180  }
00181  /* Copy the parameter string to the output buffer */
00182  strcpy(Op,buffer);
00183  return Op;
00184 }
00185 
00186 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
00187  char str[32];
00188  BOOL err;
00189  switch( msg ) {
00190    case WM_INITDIALOG:
00191      sprintf(str,"%.2f",d1);
00192      SetDlgItemText(hwnd,DLG_DOF_D1,str);
00193      SetDlgItemInt(hwnd,DLG_DOF_SAMPLES,samples,FALSE);
00194      if(back == 1)SendDlgItemMessage(hwnd,DLG_DOF_BACK,BM_SETCHECK,TRUE,0);
00195      if     (atype == 1)
00196        SendDlgItemMessage(hwnd,DLG_DOF_ACC1,BM_SETCHECK,TRUE,0);
00197      else if(atype == 2)
00198        SendDlgItemMessage(hwnd,DLG_DOF_ACC2,BM_SETCHECK,TRUE,0);
00199      else
00200        SendDlgItemMessage(hwnd,DLG_DOF_ACC3,BM_SETCHECK,TRUE,0);
00201      CentreDialogOnScreen(hwnd);
00202      return TRUE;
00203    case WM_PAINT:
00204      PaintBackground(hwnd);
00205      break;
00206    case WM_COMMAND:
00207      switch(LOWORD(wparam)){
00208         case IDCANCEL:
00209           EndDialog(hwnd,FALSE);
00210           return(TRUE);
00211         case IDOK:
00212           if(GetDlgItemText(hwnd,DLG_DOF_D1,str,12) != 0)d1=atof(str);
00213           samples=GetDlgItemInt(hwnd,DLG_DOF_SAMPLES,&err,FALSE);
00214           if(samples < 0)samples=1;
00215           if(SendDlgItemMessage(hwnd,DLG_DOF_BACK,BM_GETCHECK,0,0))
00216                back=1;
00217           else back=0;
00218           if   (SendDlgItemMessage(hwnd,DLG_DOF_ACC3,BM_GETCHECK,0,0))
00219                atype=3;
00220           else if(SendDlgItemMessage(hwnd,DLG_DOF_ACC2,BM_GETCHECK,0,0))
00221                atype=2;
00222           else atype=1;
00223           EndDialog(hwnd,TRUE);
00224           return(TRUE);
00225         default:
00226           break;
00227       }
00228       break;
00229     default: break;
00230  }
00231  return FALSE;
00232 }
00233 

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