RAIN.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 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 #include <stdlib.h>
00025 #include <stdio.h>
00026 #include <float.h>
00027 #include <math.h>
00028 #include <windows.h>
00029 #include "struct.h"           /* general structures    */
00030 #include "..\common\postprocess\ximage.h"
00031 #include "local.h"
00032 
00033 #include "rain.h"
00034 
00035 #define RCOL 100
00036 #define FACTOR 0.9
00037 #if __X__MIPS__
00038 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00039 #endif
00040 
00041 static HINSTANCE hDLLinstance=NULL; /* use to pick up resources from DLL   */
00042 
00043 /************************** Local Utility Functions ***********************/
00044 
00045 #include "utils.h"
00046 #include "paint.c"
00047 
00048 /************************** DLL entry point ********************************/
00049 
00050 #if __WATCOMC__
00051 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00052 #elif __BC__
00053 BOOL WINAPI DllEntryPoint(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00054 #else
00055 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00056 #endif
00057   switch (dwReason) {
00058     case DLL_PROCESS_ATTACH:
00059 #if __X__MIPS__
00060       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00061 #endif
00062 //MessageBox(NULL,"Attaching",NULL,MB_OK);
00063       hDLLinstance = hDLL;  /* handle to DLL file */
00064       break;
00065     case DLL_PROCESS_DETACH:
00066 #if __X__MIPS__
00067       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00068 #endif
00069 //MessageBox(NULL,"Detaching",NULL,MB_OK);
00070       break;
00071   }
00072 return (int)TRUE;
00073 }
00074 
00075 #if __SC__
00076 #pragma startaddress(DllMain)
00077 #endif
00078 
00079 /*******************************************************************\
00080 |                Code that executes the process                     |
00081 \*******************************************************************/
00082 
00083 long _RenderImageProcess(char *PrmList, XIMAGE *lpXimage){
00084 
00085  long i,j, np, inp; 
00086  long direct;
00087  int prob, speed;
00088  char dummy[255];
00089  fullscreenbuffer *S;
00090  /* read the parameters from the parameter list */
00091  sscanf(PrmList,"%s %d %d %d",dummy, &prob, &direct, &speed);
00092  /* set local pointer to start of screen buffer */
00093  S=lpXimage->Screen;
00094  srand(1109);
00095  np=(long)(((double)prob/2000.0)*((double)(lpXimage->Xmax)*(double)(lpXimage->Ymax)));
00096  if (direct>0){
00097    for (inp=0;inp<np/3;inp++){
00098       i=((lpXimage->Xmax-1)*(rand()))/RAND_MAX+1;
00099       j=((lpXimage->Ymax-1)*(rand()))/RAND_MAX+1;
00100       j=j+((lpXimage->this_frame)*speed);
00101       i=i+((lpXimage->this_frame)*direct);
00102       while (j>=lpXimage->Ymax){
00103          j=j-lpXimage->Ymax;
00104       }
00105       while (i>=lpXimage->Xmax){
00106          i=i-lpXimage->Xmax;
00107       }
00108       while (i<0){
00109          i=i+lpXimage->Xmax;
00110       }
00111       (S+(j*(lpXimage->Xmax))+i)->R=min(((S+(j*(lpXimage->Xmax))+i)->R*FACTOR)+RCOL,255);
00112       (S+(j*(lpXimage->Xmax))+i)->G=min(((S+(j*(lpXimage->Xmax))+i)->G*FACTOR)+RCOL,255);
00113       (S+(j*(lpXimage->Xmax))+i)->B=min(((S+(j*(lpXimage->Xmax))+i)->B*FACTOR)+RCOL,255);
00114 
00115       if (i>2 && i<lpXimage->Xmax-2 && j>2 && j<lpXimage->Ymax-2){
00116          (S+((j+1)*(lpXimage->Xmax))+i+1)->R=min(((S+((j+1)*(lpXimage->Xmax))+i+1)->R*FACTOR)+RCOL,255);
00117          (S+((j+1)*(lpXimage->Xmax))+i+1)->G=min(((S+((j+1)*(lpXimage->Xmax))+i+1)->G*FACTOR)+RCOL,255);
00118          (S+((j+1)*(lpXimage->Xmax))+i+1)->B=min(((S+((j+1)*(lpXimage->Xmax))+i+1)->B*FACTOR)+RCOL,255);
00119          
00120          (S+((j+2)*(lpXimage->Xmax))+i+2)->R=min(((S+((j+2)*(lpXimage->Xmax))+i+2)->R*FACTOR)+RCOL,255);
00121          (S+((j+2)*(lpXimage->Xmax))+i+2)->G=min(((S+((j+2)*(lpXimage->Xmax))+i+2)->G*FACTOR)+RCOL,255);
00122          (S+((j+2)*(lpXimage->Xmax))+i+2)->B=min(((S+((j+2)*(lpXimage->Xmax))+i+2)->B*FACTOR)+RCOL,255);
00123 
00124          (S+((j-1)*(lpXimage->Xmax))+i-1)->R=min(((S+((j-1)*(lpXimage->Xmax))+i-1)->R*FACTOR)+RCOL,255);
00125          (S+((j-1)*(lpXimage->Xmax))+i-1)->G=min(((S+((j-1)*(lpXimage->Xmax))+i-1)->G*FACTOR)+RCOL,255);
00126          (S+((j-1)*(lpXimage->Xmax))+i-1)->B=min(((S+((j-1)*(lpXimage->Xmax))+i-1)->B*FACTOR)+RCOL,255);
00127 
00128       }
00129    }
00130 
00131    for (inp=0;inp<np/3;inp++){
00132       i=((lpXimage->Xmax-1)*(rand()))/RAND_MAX+1;
00133       j=((lpXimage->Ymax-1)*(rand()))/RAND_MAX+1;
00134       j=j+((lpXimage->this_frame)*(speed-1));
00135       i=i+((lpXimage->this_frame)*(direct-1));
00136       while (j>=lpXimage->Ymax){
00137          j=j-lpXimage->Ymax;
00138       }
00139       while (i>=lpXimage->Xmax){
00140          i=i-lpXimage->Xmax;
00141       }
00142       while (i<0){
00143          i=i+lpXimage->Xmax;
00144       }
00145       (S+(j*(lpXimage->Xmax))+i)->R=min(((S+(j*(lpXimage->Xmax))+i)->R*FACTOR)+RCOL,255);
00146       (S+(j*(lpXimage->Xmax))+i)->G=min(((S+(j*(lpXimage->Xmax))+i)->G*FACTOR)+RCOL,255);
00147       (S+(j*(lpXimage->Xmax))+i)->B=min(((S+(j*(lpXimage->Xmax))+i)->B*FACTOR)+RCOL,255);
00148 
00149       if (i>2 && i<lpXimage->Xmax-2 && j>2 && j<lpXimage->Ymax-2){
00150          (S+((j+1)*(lpXimage->Xmax))+i+1)->R=min(((S+((j+1)*(lpXimage->Xmax))+i+1)->R*FACTOR)+RCOL,255);
00151          (S+((j+1)*(lpXimage->Xmax))+i+1)->G=min(((S+((j+1)*(lpXimage->Xmax))+i+1)->G*FACTOR)+RCOL,255);
00152          (S+((j+1)*(lpXimage->Xmax))+i+1)->B=min(((S+((j+1)*(lpXimage->Xmax))+i+1)->B*FACTOR)+RCOL,255);
00153          
00154          (S+((j-1)*(lpXimage->Xmax))+i-1)->R=min(((S+((j-1)*(lpXimage->Xmax))+i-1)->R*FACTOR)+RCOL,255);
00155          (S+((j-1)*(lpXimage->Xmax))+i-1)->G=min(((S+((j-1)*(lpXimage->Xmax))+i-1)->G*FACTOR)+RCOL,255);
00156          (S+((j-1)*(lpXimage->Xmax))+i-1)->B=min(((S+((j-1)*(lpXimage->Xmax))+i-1)->B*FACTOR)+RCOL,255);
00157 
00158       }
00159    }
00160  }
00161 if (direct<0){
00162    for (inp=0;inp<np/3;inp++){
00163       i=((lpXimage->Xmax-1)*(rand()))/RAND_MAX+1;
00164       j=((lpXimage->Ymax-1)*(rand()))/RAND_MAX+1;
00165       j=j+((lpXimage->this_frame)*speed);
00166       i=i+((lpXimage->this_frame)*direct);
00167       while (j>=lpXimage->Ymax){
00168          j=j-lpXimage->Ymax;
00169       }
00170       while (i>=lpXimage->Xmax){
00171          i=i-lpXimage->Xmax;
00172       }
00173       while (i<0){
00174          i=i+lpXimage->Xmax;
00175       }
00176       (S+(j*(lpXimage->Xmax))+i)->R=min(((S+(j*(lpXimage->Xmax))+i)->R*FACTOR)+RCOL,255);
00177       (S+(j*(lpXimage->Xmax))+i)->G=min(((S+(j*(lpXimage->Xmax))+i)->G*FACTOR)+RCOL,255);
00178       (S+(j*(lpXimage->Xmax))+i)->B=min(((S+(j*(lpXimage->Xmax))+i)->B*FACTOR)+RCOL,255);
00179 
00180       if (i>2 && i<lpXimage->Xmax-2 && j>2 && j<lpXimage->Ymax-2){
00181          (S+((j+1)*(lpXimage->Xmax))+i-1)->R=min(((S+((j+1)*(lpXimage->Xmax))+i-1)->R*FACTOR)+RCOL,255);
00182          (S+((j+1)*(lpXimage->Xmax))+i-1)->G=min(((S+((j+1)*(lpXimage->Xmax))+i-1)->G*FACTOR)+RCOL,255);
00183          (S+((j+1)*(lpXimage->Xmax))+i-1)->B=min(((S+((j+1)*(lpXimage->Xmax))+i-1)->B*FACTOR)+RCOL,255);
00184          
00185          (S+((j+2)*(lpXimage->Xmax))+i-2)->R=min(((S+((j+2)*(lpXimage->Xmax))+i-2)->R*FACTOR)+RCOL,255);
00186          (S+((j+2)*(lpXimage->Xmax))+i-2)->G=min(((S+((j+2)*(lpXimage->Xmax))+i-2)->G*FACTOR)+RCOL,255);
00187          (S+((j+2)*(lpXimage->Xmax))+i-2)->B=min(((S+((j+2)*(lpXimage->Xmax))+i-2)->B*FACTOR)+RCOL,255);
00188 
00189          (S+((j-1)*(lpXimage->Xmax))+i+1)->R=min(((S+((j-1)*(lpXimage->Xmax))+i+1)->R*FACTOR)+RCOL,255);
00190          (S+((j-1)*(lpXimage->Xmax))+i+1)->G=min(((S+((j-1)*(lpXimage->Xmax))+i+1)->G*FACTOR)+RCOL,255);
00191          (S+((j-1)*(lpXimage->Xmax))+i+1)->B=min(((S+((j-1)*(lpXimage->Xmax))+i+1)->B*FACTOR)+RCOL,255);
00192 
00193       }
00194    }
00195 
00196    for (inp=0;inp<np/3;inp++){
00197       i=((lpXimage->Xmax-1)*(rand()))/RAND_MAX+1;
00198       j=((lpXimage->Ymax-1)*(rand()))/RAND_MAX+1;
00199       j=j+((lpXimage->this_frame)*(speed-1));
00200       i=i+((lpXimage->this_frame)*(direct+1));
00201       while (j>=lpXimage->Ymax){
00202          j=j-lpXimage->Ymax;
00203       }
00204       while (i>=lpXimage->Xmax){
00205          i=i-lpXimage->Xmax;
00206       }
00207       while (i<0){
00208          i=i+lpXimage->Xmax;
00209       }
00210       (S+(j*(lpXimage->Xmax))+i)->R=min(((S+(j*(lpXimage->Xmax))+i)->R*FACTOR)+RCOL,255);
00211       (S+(j*(lpXimage->Xmax))+i)->G=min(((S+(j*(lpXimage->Xmax))+i)->G*FACTOR)+RCOL,255);
00212       (S+(j*(lpXimage->Xmax))+i)->B=min(((S+(j*(lpXimage->Xmax))+i)->B*FACTOR)+RCOL,255);
00213 
00214       if (i>2 && i<lpXimage->Xmax-2 && j>2 && j<lpXimage->Ymax-2){
00215          (S+((j+1)*(lpXimage->Xmax))+i-1)->R=min(((S+((j+1)*(lpXimage->Xmax))+i-1)->R*FACTOR)+RCOL,255);
00216          (S+((j+1)*(lpXimage->Xmax))+i-1)->G=min(((S+((j+1)*(lpXimage->Xmax))+i-1)->G*FACTOR)+RCOL,255);
00217          (S+((j+1)*(lpXimage->Xmax))+i-1)->B=min(((S+((j+1)*(lpXimage->Xmax))+i-1)->B*FACTOR)+RCOL,255);
00218          
00219          (S+((j-1)*(lpXimage->Xmax))+i+1)->R=min(((S+((j-1)*(lpXimage->Xmax))+i+1)->R*FACTOR)+RCOL,255);
00220          (S+((j-1)*(lpXimage->Xmax))+i+1)->G=min(((S+((j-1)*(lpXimage->Xmax))+i+1)->G*FACTOR)+RCOL,255);
00221          (S+((j-1)*(lpXimage->Xmax))+i+1)->B=min(((S+((j-1)*(lpXimage->Xmax))+i+1)->B*FACTOR)+RCOL,255);
00222 
00223       }
00224    }
00225  }
00226 if (direct==0){
00227    for (inp=0;inp<np/3;inp++){
00228       i=((lpXimage->Xmax-1)*(rand()))/RAND_MAX+1;
00229       j=((lpXimage->Ymax-1)*(rand()))/RAND_MAX+1;
00230       j=j+((lpXimage->this_frame)*speed);
00231       i=i+((lpXimage->this_frame)*direct);
00232       while (j>=lpXimage->Ymax){
00233          j=j-lpXimage->Ymax;
00234       }
00235       while (i>=lpXimage->Xmax){
00236          i=i-lpXimage->Xmax;
00237       }
00238       while (i<0){
00239          i=i+lpXimage->Xmax;
00240       }
00241       (S+(j*(lpXimage->Xmax))+i)->R=min(((S+(j*(lpXimage->Xmax))+i)->R*FACTOR)+RCOL,255);
00242       (S+(j*(lpXimage->Xmax))+i)->G=min(((S+(j*(lpXimage->Xmax))+i)->G*FACTOR)+RCOL,255);
00243       (S+(j*(lpXimage->Xmax))+i)->B=min(((S+(j*(lpXimage->Xmax))+i)->B*FACTOR)+RCOL,255);
00244 
00245       if (i>2 && i<lpXimage->Xmax-2 && j>2 && j<lpXimage->Ymax-2){
00246          (S+((j+1)*(lpXimage->Xmax))+i)->R=min(((S+((j+1)*(lpXimage->Xmax))+i)->R*FACTOR)+RCOL,255);
00247          (S+((j+1)*(lpXimage->Xmax))+i)->G=min(((S+((j+1)*(lpXimage->Xmax))+i)->G*FACTOR)+RCOL,255);
00248          (S+((j+1)*(lpXimage->Xmax))+i)->B=min(((S+((j+1)*(lpXimage->Xmax))+i)->B*FACTOR)+RCOL,255);
00249          
00250          (S+((j+2)*(lpXimage->Xmax))+i)->R=min(((S+((j+2)*(lpXimage->Xmax))+i)->R*FACTOR)+RCOL,255);
00251          (S+((j+2)*(lpXimage->Xmax))+i)->G=min(((S+((j+2)*(lpXimage->Xmax))+i)->G*FACTOR)+RCOL,255);
00252          (S+((j+2)*(lpXimage->Xmax))+i)->B=min(((S+((j+2)*(lpXimage->Xmax))+i)->B*FACTOR)+RCOL,255);
00253 
00254          (S+((j-1)*(lpXimage->Xmax))+i)->R=min(((S+((j-1)*(lpXimage->Xmax))+i)->R*FACTOR)+RCOL,255);
00255          (S+((j-1)*(lpXimage->Xmax))+i)->G=min(((S+((j-1)*(lpXimage->Xmax))+i)->G*FACTOR)+RCOL,255);
00256          (S+((j-1)*(lpXimage->Xmax))+i)->B=min(((S+((j-1)*(lpXimage->Xmax))+i)->B*FACTOR)+RCOL,255);
00257 
00258       }
00259    }
00260 
00261    for (inp=0;inp<np/3;inp++){
00262       i=((lpXimage->Xmax-1)*(rand()))/RAND_MAX+1;
00263       j=((lpXimage->Ymax-1)*(rand()))/RAND_MAX+1;
00264       j=j+((lpXimage->this_frame)*(speed-1));
00265       i=i+((lpXimage->this_frame)*(direct));
00266       while (j>=lpXimage->Ymax){
00267          j=j-lpXimage->Ymax;
00268       }
00269       while (i>=lpXimage->Xmax){
00270          i=i-lpXimage->Xmax;
00271       }
00272       while (i<0){
00273          i=i+lpXimage->Xmax;
00274       }
00275       (S+(j*(lpXimage->Xmax))+i)->R=min(((S+(j*(lpXimage->Xmax))+i)->R*FACTOR)+RCOL,255);
00276       (S+(j*(lpXimage->Xmax))+i)->G=min(((S+(j*(lpXimage->Xmax))+i)->G*FACTOR)+RCOL,255);
00277       (S+(j*(lpXimage->Xmax))+i)->B=min(((S+(j*(lpXimage->Xmax))+i)->B*FACTOR)+RCOL,255);
00278 
00279       if (i>2 && i<lpXimage->Xmax-2 && j>2 && j<lpXimage->Ymax-2){
00280          (S+((j+1)*(lpXimage->Xmax))+i)->R=min(((S+((j+1)*(lpXimage->Xmax))+i)->R*FACTOR)+RCOL,255);
00281          (S+((j+1)*(lpXimage->Xmax))+i)->G=min(((S+((j+1)*(lpXimage->Xmax))+i)->G*FACTOR)+RCOL,255);
00282          (S+((j+1)*(lpXimage->Xmax))+i)->B=min(((S+((j+1)*(lpXimage->Xmax))+i)->B*FACTOR)+RCOL,255);
00283          
00284          (S+((j-1)*(lpXimage->Xmax))+i)->R=min(((S+((j-1)*(lpXimage->Xmax))+i)->R*FACTOR)+RCOL,255);
00285          (S+((j-1)*(lpXimage->Xmax))+i)->G=min(((S+((j-1)*(lpXimage->Xmax))+i)->G*FACTOR)+RCOL,255);
00286          (S+((j-1)*(lpXimage->Xmax))+i)->B=min(((S+((j-1)*(lpXimage->Xmax))+i)->B*FACTOR)+RCOL,255);
00287 
00288       }
00289    }
00290  }
00291  return 1;          /* all done OK                           */
00292 }
00293 
00294 /*************** Function that renders any of the OpenGL Functionality ************/
00295 
00296 long _RenderGLexternal(char *PrmList, XIMAGE *lpXimage){
00297 MessageBox(NULL,"OpenGL function called","OK",MB_OK);
00298  return 1;
00299 }
00300 
00301 
00302 /*************** Functions used for set up  ***************/
00303 
00304 /* local variable for communication between dialog box and Setup function */
00305 int prob=20;
00306 long angle=0;
00307 int speed=5;
00308 
00309 
00310 /* Dialog box callback prototype */
00311 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
00312 
00313 char * _SetExternalParameters(
00314   char *Op,                 /* string for the parameters                  */
00315   HWND hWnd,                /* parent window                              */
00316   long ruler,               /* ruler scale value to facilitate scaling    */
00317   char *name,               /* name of DLL file with the effect           */
00318   X__MEMORY_MANAGER *lpEVI /* pointer to structure with memory functions */
00319                                     ){
00320  /* output buffer should be as long as necessary to hold full string        */
00321  char buffer[256];
00322  if(Op != NULL){  /* parameters exist so read them off the list */
00323    sscanf(Op,"%s %d %d %d",buffer, &prob, &angle, &speed);
00324  }
00325  /*   Do the user interface as required to set up the effect, may use a     */
00326  /*   dialog box etc. Return old string if effect is cancelled (no change)  */
00327  if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG_RAIN),hWnd,
00328               (DLGPROC)DlgProc) == FALSE)return Op;
00329  /* Free space occupied by old parameter string */
00330  if(Op != NULL)CALL_FREE(Op);  /* free the old string */
00331  /* print the parameters into the buffer */
00332  sprintf(buffer,"%s %d %d %d",name, prob, angle, speed);
00333  /* Prepare the output buffer to take copy of parameter list */
00334  if((Op=(char *)CALL_MALLOC(strlen(buffer)+1)) == NULL){
00335   MessageBox (GetFocus(),"External effect: Out of memory","Error",
00336                 MB_OK|MB_TASKMODAL|MB_ICONSTOP);
00337    return NULL;
00338  }
00339  /* Copy the parameter string to the output buffer */
00340  strcpy(Op,buffer);
00341  return Op;
00342 }
00343 
00344 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
00345  char str[32];
00346  switch( msg ) {
00347    case WM_INITDIALOG:
00348      /* prime dialog box controls          */
00349      sprintf(str,"%d",prob);
00350      SetDlgItemText(hwnd,DLG_PROB,str);
00351      sprintf(str,"%d",angle);
00352      SetDlgItemText(hwnd,DLG_ANGLE,str);
00353      sprintf(str,"%d",speed);
00354      SetDlgItemText(hwnd,DLG_SPEED,str);
00355      CentreDialogOnScreen(hwnd);
00356      return TRUE;
00357    case WM_PAINT:
00358      PaintBackground(hwnd);
00359      break;
00360      return TRUE;
00361    case WM_COMMAND:
00362      switch(LOWORD(wparam)){
00363         case IDCANCEL:    /* user clicked cancel                            */
00364           EndDialog(hwnd,FALSE);
00365           return(TRUE);
00366         case IDOK:        /* OK so get numbers from the Dailog Box controls */
00367           if(GetDlgItemText(hwnd,DLG_PROB,str,12) != 0)
00368             sscanf(str,"%d",&prob);
00369         if(GetDlgItemText(hwnd,DLG_ANGLE,str,12) != 0)
00370             sscanf(str,"%d",&angle);
00371         if(GetDlgItemText(hwnd,DLG_SPEED,str,12) != 0)
00372             sscanf(str,"%d",&speed);
00373         if (speed<2){
00374             MessageBox(NULL,"The speed value must be greater than 1.",NULL,MB_OK);
00375         }
00376         else EndDialog(hwnd,TRUE);
00377         return(TRUE);
00378         default:
00379           break;
00380       }
00381       break;
00382     default: break;
00383  }
00384  return FALSE;
00385 }
00386 

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