SNOW.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 <time.h>
00030 #include "struct.h"           /* general structures    */
00031 #include "..\common\postprocess\ximage.h"
00032 #include "local.h"
00033 
00034 #include "snow.h"
00035 
00036 
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  
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=200;
00112     (S+(j*(lpXimage->Xmax))+i)->G=200;
00113     (S+(j*(lpXimage->Xmax))+i)->B=200;
00114 
00115     if (i>0 && i<lpXimage->Xmax && j>0 && j<lpXimage->Ymax-1){
00116       (S+(j*(lpXimage->Xmax))+i+1)->R=255;
00117       (S+(j*(lpXimage->Xmax))+i+1)->G=255;
00118       (S+(j*(lpXimage->Xmax))+i+1)->B=255;
00119       (S+(j*(lpXimage->Xmax))+i-1)->R=255;
00120       (S+(j*(lpXimage->Xmax))+i-1)->G=255;
00121       (S+(j*(lpXimage->Xmax))+i-1)->B=255;
00122       (S+((j+1)*(lpXimage->Xmax))+i)->R=255;
00123       (S+((j+1)*(lpXimage->Xmax))+i)->G=255;
00124       (S+((j+1)*(lpXimage->Xmax))+i)->B=255;
00125       (S+((j-1)*(lpXimage->Xmax))+i)->R=255;
00126       (S+((j-1)*(lpXimage->Xmax))+i)->G=255;
00127       (S+((j-1)*(lpXimage->Xmax))+i)->B=255;
00128     }
00129 
00130    
00131 
00132   }
00133   for (inp=0;inp<np/3;inp++){
00134     i=((lpXimage->Xmax-1)*(rand()))/RAND_MAX+1;
00135     j=((lpXimage->Ymax-1)*(rand()))/RAND_MAX+1;
00136     j=j+((lpXimage->this_frame)*(speed+1));
00137     i=i+((lpXimage->this_frame)*direct);
00138     while (j>=lpXimage->Ymax){
00139       j=j-lpXimage->Ymax;
00140     }
00141     while (i>=lpXimage->Xmax){
00142       i=i-lpXimage->Xmax;
00143     }
00144     while (i<0){
00145       i=i+lpXimage->Xmax;
00146     }
00147     (S+(j*(lpXimage->Xmax))+i)->R=255;
00148     (S+(j*(lpXimage->Xmax))+i)->G=255;
00149     (S+(j*(lpXimage->Xmax))+i)->B=255;
00150    }
00151 
00152 
00153   for (inp=0;inp<np/3;inp++){
00154     i=((lpXimage->Xmax-1)*(rand()))/RAND_MAX+1;
00155     j=((lpXimage->Ymax-1)*(rand()))/RAND_MAX+1;
00156     j=j+((lpXimage->this_frame)*(speed-1));
00157     i=i+((lpXimage->this_frame)*direct);
00158     while (j>=lpXimage->Ymax){
00159       j=j-lpXimage->Ymax;
00160     }
00161     while (i>=lpXimage->Xmax){
00162       i=i-lpXimage->Xmax;
00163     }
00164     while (i<0){
00165       i=i+lpXimage->Xmax;
00166     }
00167     (S+(j*(lpXimage->Xmax))+i)->R=255;
00168     (S+(j*(lpXimage->Xmax))+i)->G=255;
00169     (S+(j*(lpXimage->Xmax))+i)->B=255;
00170    }
00171 
00172  return 1;          /* all done OK                           */
00173 }
00174 
00175 /*************** Function that renders any of the OpenGL Functionality ************/
00176 
00177 long _RenderGLexternal(char *PrmList, XIMAGE *lpXimage){
00178 MessageBox(NULL,"OpenGL function called","OK",MB_OK);
00179  return 1;
00180 }
00181 
00182 /*************** Functions used for set up  ***************/
00183 
00184 
00185 /* local variable for communication between dialog box and Setup function */
00186 int prob=30;
00187 long angle=0;
00188 int speed=2;
00189 
00190 
00191 /* Dialog box callback prototype */
00192 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
00193 
00194 char * _SetExternalParameters(
00195   char *Op,                 /* string for the parameters                  */
00196   HWND hWnd,                /* parent window                              */
00197   long ruler,               /* ruler scale value to facilitate scaling    */
00198   char *name,               /* name of DLL file with the effect           */
00199   X__MEMORY_MANAGER *lpEVI /* pointer to structure with memory functions */
00200                                     ){
00201  /* output buffer should be as long as necessary to hold full string        */
00202  char buffer[256];
00203  if(Op != NULL){  /* parameters exist so read them off the list */
00204    sscanf(Op,"%s %d %d %d",buffer, &prob, &angle, &speed);
00205  }
00206  /*   Do the user interface as required to set up the effect, may use a     */
00207  /*   dialog box etc. Return old string if effect is cancelled (no change)  */
00208  if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG_SNOW1),hWnd,
00209               (DLGPROC)DlgProc) == FALSE)return Op;
00210  /* Free space occupied by old parameter string */
00211  if(Op != NULL)CALL_FREE(Op);  /* free the old string */
00212  /* print the parameters into the buffer */
00213  sprintf(buffer,"%s %d %d %d",name, prob, angle, speed);
00214  /* Prepare the output buffer to take copy of parameter list */
00215  if((Op=(char *)CALL_MALLOC(strlen(buffer)+1)) == NULL){
00216   MessageBox (GetFocus(),"External effect: Out of memory","Error",
00217                 MB_OK|MB_TASKMODAL|MB_ICONSTOP);
00218    return NULL;
00219  }
00220  /* Copy the parameter string to the output buffer */
00221  strcpy(Op,buffer);
00222  return Op;
00223 }
00224 
00225 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
00226  char str[32];
00227  switch( msg ) {
00228    case WM_INITDIALOG:
00229      /* prime dialog box controls          */
00230      sprintf(str,"%d",prob);
00231      SetDlgItemText(hwnd,DLG_PROB,str);
00232      sprintf(str,"%d",angle);
00233      SetDlgItemText(hwnd,DLG_ANGLE,str);
00234      sprintf(str,"%d",speed);
00235      SetDlgItemText(hwnd,DLG_SPEED,str);
00236      CentreDialogOnScreen(hwnd);
00237      return TRUE;
00238    case WM_PAINT:
00239      PaintBackground(hwnd);
00240      break;
00241      return TRUE;
00242    case WM_COMMAND:
00243      switch(LOWORD(wparam)){
00244         case IDCANCEL:    /* user clicked cancel                            */
00245           EndDialog(hwnd,FALSE);
00246           return(TRUE);
00247         case IDOK:        /* OK so get numbers from the Dailog Box controls */
00248           if(GetDlgItemText(hwnd,DLG_PROB,str,12) != 0)
00249             sscanf(str,"%d",&prob);
00250       if(GetDlgItemText(hwnd,DLG_ANGLE,str,12) != 0)
00251             sscanf(str,"%d",&angle);
00252       if(GetDlgItemText(hwnd,DLG_SPEED,str,12) != 0)
00253             sscanf(str,"%d",&speed);
00254       if (speed<2){
00255         MessageBox(NULL,"The speed value must be greater than 1.",NULL,MB_OK);
00256       }
00257       else EndDialog(hwnd,TRUE);
00258       return(TRUE);
00259         default:
00260           break;
00261       }
00262       break;
00263     default: break;
00264  }
00265  return FALSE;
00266 }
00267 

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