EMBOSS.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 /* emboss  Image post-processor using Z buffer                            */
00025 
00026 #include <stdlib.h>
00027 #include <stdio.h>
00028 #include <float.h>
00029 #include <math.h>
00030 #include <windows.h>
00031 #include <commctrl.h>
00032 #include "struct.h"           /* general structures    */
00033 #include "..\common\postprocess\ximage.h"
00034 #include "local.h"
00035 
00036 #include "emboss.h"
00037 
00038 static long version=0;
00039 
00040 #if __X__MIPS__
00041 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00042 #endif
00043 
00044 static HINSTANCE hDLLinstance=NULL; /* use to pick up resources from DLL  */
00045 
00046 #include "utils.h"
00047 #include "paint.c"
00048 
00049 #include "..\animate\wspaces.c"
00050 
00051 #include "video1.c"
00052 
00053 unsigned char *LoadMAP(char *name, int *x, int *y);
00054 
00055 #if __WATCOMC__
00056 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00057 #elif __BC__
00058 BOOL WINAPI DllEntryPoint(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00059 #else
00060 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00061 #endif
00062   switch (dwReason) {
00063     case DLL_PROCESS_ATTACH:
00064 #if __X__MIPS__
00065       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00066 #endif
00067       hDLLinstance = hDLL;  /* handle to DLL file */
00068       break;
00069     case DLL_PROCESS_DETACH:
00070 #if __X__MIPS__
00071       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00072 #endif
00073       break;
00074   }
00075 return (int)TRUE;
00076 }
00077 
00078 #if __SC__
00079 #pragma startaddress(DllMain)
00080 #endif
00081 
00082 
00083 long _RenderImageProcess(char *PrmList, XIMAGE *lpXimage){
00084  double mr;
00085  char name_path[256],imagefile[256];
00086  fullscreenbuffer *Screen,*BackBuffer;
00087  BOOL bMorph=FALSE;
00088  long cR,cG,cB,mcR,mcG,mcB,dummy,type,hold,back,lframe,nx,ny,Xmax,Ymax,frame;
00089  sscanf(PrmList,"%s %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %s",name_path,
00090         &version,&type,&hold,
00091         &nx,&ny,&cR,&cG,&cB,&back,&lframe,imagefile);
00092  if(lpXimage->Morph && lpXimage->mParameters != NULL){
00093    bMorph=TRUE; mr=lpXimage->MorphRatio;
00094    sscanf(lpXimage->mParameters,
00095           "%s %ld %ld %ld %ld %ld %ld %ld %ld",
00096           name_path,&version,&dummy,&dummy,&dummy,&dummy,&dummy,
00097           &mcR,&mcG,&mcB);
00098  }
00099  if(!bMorph){
00100    mr=(double)(lpXimage->last_frame - lpXimage->first_frame);
00101    if(mr < 1.0)mr=0.0; //return 1;
00102    else mr=(double)(lpXimage->this_frame - lpXimage->first_frame)/mr;
00103  }
00104  frame=lpXimage->this_frame - lpXimage->first_frame + 1;
00105  if     (hold == 1)mr=(1.0-mr);
00106  else if(hold == 2)mr=1.0;
00107  else if(hold == 3)mr=0.0;
00108  BackBuffer=NULL;
00109  Xmax=lpXimage->Xmax; Ymax=lpXimage->Ymax;
00110  Screen=lpXimage->Screen;
00111  if(back > 0){
00112    unsigned char *ImagePixels;
00113    int ImageXsize,ImageYsize;
00114    if(back == 2)GetAnimFileName(imagefile,name_path,
00115                      lpXimage->this_frame - lpXimage->first_frame + 1,
00116                      1,lframe,1);
00117    RestoreWhiteSpaces(imagefile);
00118    if((ImagePixels=LoadMAP(imagefile,&ImageXsize,&ImageYsize)) != NULL){
00119      BackBuffer=ScaleImageMap(ImagePixels,ImageXsize,ImageYsize,Xmax,Ymax);
00120      X__Free(ImagePixels);
00121    }
00122  }
00123  else{
00124    if((BackBuffer=(fullscreenbuffer *)X__Malloc(Xmax*Ymax*
00125       sizeof(fullscreenbuffer))) == NULL)return 0;
00126    memcpy(BackBuffer,Screen,Xmax*Ymax*sizeof(fullscreenbuffer));
00127  }
00128  if(BackBuffer != NULL){
00129    long i,j;
00130    fullscreenbuffer *S,*B;
00131    double shade,background,NdotL,spec;
00132    double a,spower,
00133           azimuth=0.7777,
00134           elevation=0.7777,
00135           Nx,Ny,Nz,Lx,Ly,Lz,Nz2,NzLz,Vx=0.0,Vy=0.0,Vz=255.9,VzNz,len;
00136    spower=(double)10;
00137    B=BackBuffer;
00138    azimuth = (double)ny*3.1415926/180.0;
00139    Lx=cos(azimuth)*cos(elevation)*255.9;
00140    Ly=sin(azimuth)*cos(elevation)*255.9;
00141    Lz=sin(elevation)*255.9;
00142    Vx += Lx; Vy += Ly; Vz += Lz;
00143    NdotL=1.0/sqrt(Vx*Vx+Vy*Vy+Vz*Vz);
00144    Vx *= NdotL; Vy *= NdotL; Vz *= NdotL;
00145    for(i=1;i<Ymax-1;i++)for(j=1;j<Xmax-1;j++){
00146      a=((double)(B->R)+(double)(B->G)+(double)(B->B))/3.0;
00147      B->R=(unsigned char)a;
00148      B->G=(unsigned char)a;
00149      B->B=(unsigned char)a;
00150      B++;
00151    }
00152    B=BackBuffer;
00153    for(i=1;i<Ymax-1;i++){
00154      for(j=1;j<Xmax-1;j++){
00155        a=(double)(B+(i-1)*Xmax+(j-1))->R+
00156          (double)(B+(i-1)*Xmax+(j  ))->R+
00157          (double)(B+(i-1)*Xmax+(j+1))->R+
00158          (double)(B+(i  )*Xmax+(j-1))->R+
00159          (double)(B+(i  )*Xmax+(j  ))->R+
00160          (double)(B+(i  )*Xmax+(j+1))->R+
00161          (double)(B+(i+1)*Xmax+(j-1))->R+
00162          (double)(B+(i+1)*Xmax+(j  ))->R+
00163          (double)(B+(i+1)*Xmax+(j+1))->R;
00164        (B+i*Xmax+j)->R=(unsigned char)(a/9.0);
00165        a=(double)(B+(i-1)*Xmax+(j-1))->G+
00166          (double)(B+(i-1)*Xmax+(j  ))->G+
00167          (double)(B+(i-1)*Xmax+(j+1))->G+
00168          (double)(B+(i  )*Xmax+(j-1))->G+
00169          (double)(B+(i  )*Xmax+(j  ))->G+
00170          (double)(B+(i  )*Xmax+(j+1))->G+
00171          (double)(B+(i+1)*Xmax+(j-1))->G+
00172          (double)(B+(i+1)*Xmax+(j  ))->G+
00173          (double)(B+(i+1)*Xmax+(j+1))->G;
00174        (B+i*Xmax+j)->G=(unsigned char)(a/9.0);
00175        a=(double)(B+(i-1)*Xmax+(j-1))->B+
00176          (double)(B+(i-1)*Xmax+(j  ))->B+
00177          (double)(B+(i-1)*Xmax+(j+1))->B+
00178          (double)(B+(i  )*Xmax+(j-1))->B+
00179          (double)(B+(i  )*Xmax+(j  ))->B+
00180          (double)(B+(i  )*Xmax+(j+1))->B+
00181          (double)(B+(i+1)*Xmax+(j-1))->B+
00182          (double)(B+(i+1)*Xmax+(j  ))->B+
00183          (double)(B+(i+1)*Xmax+(j+1))->B;
00184        (B+i*Xmax+j)->B=(unsigned char)(a/9.0);
00185      }
00186    }
00187    B=BackBuffer;
00188    nx = max(1,nx);
00189    Nz=(6.0*255.0)/((double)nx/10.0);
00190    Nz2=Nz*Nz;
00191    NzLz=Nz*Lz;
00192    VzNz=Vz*Nz;
00193    background=Lz/255.0;
00194    for(i=0;i<Ymax;i++){
00195      for(j=0;j<Xmax;j++){
00196        S=(Screen+i*Xmax+j);
00197        spec=0.0;
00198        if(i > 0 && i < Ymax-1 && j > 0 && j < Xmax-1){
00199          Ny= -(double)(B+(i-1)*Xmax+(j-1))->R
00200              -(double)(B+(i-1)*Xmax+(j  ))->R
00201              -(double)(B+(i-1)*Xmax+(j+1))->R+
00202               (double)(B+(i+1)*Xmax+(j-1))->R+
00203               (double)(B+(i+1)*Xmax+(j  ))->R+
00204               (double)(B+(i+1)*Xmax+(j+1))->R;
00205 
00206          Nx= -(double)(B+(i-1)*Xmax+(j-1))->R
00207              -(double)(B+(i  )*Xmax+(j-1))->R
00208              -(double)(B+(i+1)*Xmax+(j-1))->R+
00209               (double)(B+(i-1)*Xmax+(j+1))->R+
00210               (double)(B+(i  )*Xmax+(j+1))->R+
00211               (double)(B+(i+1)*Xmax+(j+1))->R;
00212 
00213          if(fabs(Nx) < 1.0 && fabs(Ny) < 1.0){
00214            shade=background;
00215          }
00216          else if((NdotL=Nx*Lx+Ny*Ly+NzLz) < 0.0){
00217            shade=0;
00218          }
00219          else{
00220            len=1.0/sqrt(Nx*Nx+Ny*Ny+Nz2);
00221            shade=NdotL*len/255.0;
00222            NdotL=(Vx*Nx+Vy*Ny+VzNz)*len;
00223            if(NdotL > 0)spec=pow((2*NdotL*NdotL-1.0),spower);
00224          }
00225        }
00226        else shade=background;
00227        S->R = (unsigned char)(min(255,(double)S->R*shade+spec*255.0));
00228        S->G = (unsigned char)(min(255,(double)S->G*shade+spec*255.0));
00229        S->B = (unsigned char)(min(255,(double)S->B*shade+spec*255.0));
00230      }
00231    }
00232  }
00233  if(BackBuffer != NULL)X__Free(BackBuffer);
00234  return 1;
00235 }
00236 
00237 /*************** Function that renders any of the OpenGL Functionality ************/
00238 
00239 long _RenderGLexternal(char *PrmList, XIMAGE *lpXimage){
00240 MessageBox(NULL,"OpenGL function called","OK",MB_OK);
00241  return 1;
00242 }
00243 
00244 /*************** +++++++++++++++++++++++++++++++++++++++++++++++++++++ ************/
00245 
00246 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
00247 
00248 // ny is angle
00249 // nx is % of slope  100 is highest 0 is lowest
00250 
00251 
00252 static long colour[3]={255,255,255};
00253 static long type=0,hold=0,back=0,lframe=9999,nx=50,ny=45;
00254 static char iname[256];
00255 static X__MEMORY_MANAGER *lpLocalEVI;
00256 
00257 char * _SetExternalParameters(
00258   char *Op,                 /* string for the parameters                  */
00259   HWND hWnd,                /* parent window                              */
00260   long ruler,               /* ruler scale value to facilitate scaling    */
00261   char *name,               /* name of DLL file with the effect           */
00262   X__MEMORY_MANAGER *lpEVI /* pointer to structure with memory functions */
00263                                     ){
00264  char buffer[1024];
00265  long id1,id2;   /* integer scaled radius value */
00266  strcpy(iname," ");
00267  if(Op != NULL){  /* parameters exist so read them off the list */
00268    sscanf(Op,"%s %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %s",buffer,&version,
00269           &type,&hold,&nx,&ny,&colour[0],&colour[1],&colour[2],
00270           &back,&lframe,iname);
00271  }
00272  lpLocalEVI=lpEVI;
00273  if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG_VIDEO),hWnd,
00274               (DLGPROC)DlgProc) == FALSE)return Op;
00275  if(Op != NULL)CALL_FREE(Op);  /* free the old string */
00276  sprintf(buffer,"%s %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %s",
00277            name,version,type,hold,
00278            nx,ny,colour[0],colour[1],colour[2],back,lframe,iname);
00279  if((Op=(char *)CALL_MALLOC(strlen(buffer)+1)) == NULL){
00280   MessageBox (GetFocus(),"External effect: Out of memory","Error",
00281                 MB_OK|MB_TASKMODAL|MB_ICONSTOP);
00282    return NULL;
00283  }
00284  strcpy(Op,buffer);
00285  return Op;
00286 }
00287 
00288 
00289 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
00290  BOOL err;
00291  int i;
00292  char lname[256],text[512];
00293  switch( msg ) {
00294    case WM_INITDIALOG:
00295      if     (hold == 0)
00296        SendDlgItemMessage(hwnd,DLG_VIDEO_FADE_IN,BM_SETCHECK,TRUE,0);
00297      else if(hold == 1)
00298        SendDlgItemMessage(hwnd,DLG_VIDEO_FADE_OUT,BM_SETCHECK,TRUE,0);
00299      else if(hold == 2)
00300        SendDlgItemMessage(hwnd,DLG_VIDEO_HOLD_IN,BM_SETCHECK,TRUE,0);
00301      else if(hold == 3)
00302        SendDlgItemMessage(hwnd,DLG_VIDEO_HOLD_OUT,BM_SETCHECK,TRUE,0);
00303      if     (back == 0)
00304        SendDlgItemMessage(hwnd,DLG_VIDEO_PLAIN,BM_SETCHECK,TRUE,0);
00305      if     (back == 1)
00306        SendDlgItemMessage(hwnd,DLG_VIDEO_IMAGE,BM_SETCHECK,TRUE,0);
00307      if     (back == 2)
00308        SendDlgItemMessage(hwnd,DLG_VIDEO_ANIIMAGE,BM_SETCHECK,TRUE,0);
00309      strcpy(lname,iname);
00310      RestoreWhiteSpaces(lname);
00311      SetDlgItemText(hwnd,DLG_VIDEO_IMAGENAME,lname);
00312      SetDlgItemInt(hwnd,DLG_VIDEO_NX,nx,TRUE);
00313      SetDlgItemInt(hwnd,DLG_VIDEO_NY,ny,TRUE);
00314      SetDlgItemInt(hwnd,DLG_VIDEO_LASTFRAME,lframe,TRUE);
00315      CentreDialogOnScreen(hwnd);
00316    case WM_PAINT:
00317      PaintBackground(hwnd);
00318      break;
00319      return TRUE;
00320    case WM_COMMAND:
00321      switch(LOWORD(wparam)){
00322         case DLG_VIDEO_SETIMAGENAME:{
00323             strcpy(lname,iname);
00324             RestoreWhiteSpaces(lname);
00325             if(XimageFileName(lpLocalEVI->lpAni,lname,"gif",
00326                               "Choose First/Only Image File",
00327                               "All file formats|*.gif;*.tga|"
00328                               "Compuserve GIFs|*.gif|"
00329                               "Targa TGAs|*.tga|",
00330                               hwnd)){
00331 
00332               SetDlgItemText(hwnd,DLG_VIDEO_IMAGENAME,lname);
00333               HideWhiteSpaces(lname);
00334               strcpy(iname,lname);
00335             }
00336           }
00337           break;
00338         case IDCANCEL:
00339           EndDialog(hwnd,FALSE);
00340           return(TRUE);
00341         case IDOK:
00342           nx=GetDlgItemInt(hwnd,DLG_VIDEO_NX,&err,FALSE);
00343           ny=GetDlgItemInt(hwnd,DLG_VIDEO_NY,&err,FALSE);
00344           lframe=GetDlgItemInt(hwnd,DLG_VIDEO_LASTFRAME,&err,FALSE);
00345           if(SendDlgItemMessage(hwnd,DLG_VIDEO_FADE_IN,BM_GETCHECK,0,0))
00346             hold=0;
00347           if(SendDlgItemMessage(hwnd,DLG_VIDEO_FADE_OUT,BM_GETCHECK,0,0))
00348             hold=1;
00349           if(SendDlgItemMessage(hwnd,DLG_VIDEO_HOLD_IN,BM_GETCHECK,0,0))
00350             hold=2;
00351           if(SendDlgItemMessage(hwnd,DLG_VIDEO_HOLD_OUT,BM_GETCHECK,0,0))
00352             hold=3;
00353           if(SendDlgItemMessage(hwnd,DLG_VIDEO_ANIIMAGE,BM_GETCHECK,0,0))
00354             back=2;
00355           if(SendDlgItemMessage(hwnd,DLG_VIDEO_IMAGE,BM_GETCHECK,0,0))
00356             back=1;
00357           if(SendDlgItemMessage(hwnd,DLG_VIDEO_PLAIN,BM_GETCHECK,0,0))
00358             back=0;
00359           EndDialog(hwnd,TRUE);
00360           return(TRUE);
00361         default:
00362           break;
00363       }
00364       break;
00365     default: break;
00366  }
00367  return FALSE;
00368 }
00369 
00370 #include "video2.c"
00371 

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