00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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"
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;
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;
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
00106
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
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,
00154 HWND hWnd,
00155 long ruler,
00156 char *name,
00157 X__MEMORY_MANAGER *lpEVI
00158 ){
00159
00160 char buffer[256];
00161 long id1,id2;
00162 if(Op != NULL){
00163 sscanf(Op,"%s %ld %ld %ld %ld %ld",buffer,&samples,&atype,&back,&id1,&version);
00164 d1=(double)id1/(double)ruler;
00165 }
00166
00167
00168 if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG_DOF),hWnd,
00169 (DLGPROC)DlgProc) == FALSE)return Op;
00170
00171 if(Op != NULL)CALL_FREE(Op);
00172
00173 id1=(long)(d1*(double)ruler);
00174 sprintf(buffer,"%s %ld %ld %ld %ld %ld",name,samples,atype,back,id1,version);
00175
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
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