VIDEO.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 /* VIDEO  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 "video.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 static void FadeTo(double mr, fullscreenbuffer *S, long Xmax, long Ymax,
00083                    long R, long G, long B, fullscreenbuffer *Bb){
00084  long i,j;
00085  if(Bb != NULL){
00086    for(i=0;i<Ymax;i++)for(j=0;j<Xmax;j++){
00087      S->R = (unsigned char)((double)(S->R)*(1.0-mr)+(double)Bb->R*mr);
00088      S->G = (unsigned char)((double)(S->G)*(1.0-mr)+(double)Bb->G*mr);
00089      S->B = (unsigned char)((double)(S->B)*(1.0-mr)+(double)Bb->B*mr);
00090      S++; Bb++;
00091    }
00092  }
00093  else {
00094    for(i=0;i<Ymax;i++)for(j=0;j<Xmax;j++){
00095      S->R = (unsigned char)((double)(S->R)*(1.0-mr)+(double)R*mr);
00096      S->G = (unsigned char)((double)(S->G)*(1.0-mr)+(double)G*mr);
00097      S->B = (unsigned char)((double)(S->B)*(1.0-mr)+(double)B*mr);
00098      S++;
00099    }
00100  }
00101 }
00102 
00103 static void WipeLR(double mr, fullscreenbuffer *S, long Xmax, long Ymax,
00104                    long R, long G, long B, fullscreenbuffer *Bb){
00105  long i,j;
00106  long w;
00107  fullscreenbuffer *bb;
00108  w=(long)((double)Xmax*mr)+1;
00109  for(i=0;i<Ymax;i++)for(j=0;j<Xmax;j++){
00110    if(j < w){
00111      if(Bb != NULL){
00112        bb=(Bb+i*Xmax+j);
00113        S->R=(unsigned char)bb->R;
00114        S->G=(unsigned char)bb->G;
00115        S->B=(unsigned char)bb->B;
00116      }
00117      else{
00118        S->R = (unsigned char)R;
00119        S->G = (unsigned char)G;
00120        S->B = (unsigned char)B;
00121      }
00122    }
00123    S++;
00124  }
00125 }
00126 
00127 static void WipeUD(double mr, fullscreenbuffer *S, long Xmax, long Ymax,
00128                    long R, long G, long B, fullscreenbuffer *Bb){
00129  long i,j;
00130  long w;
00131  fullscreenbuffer *bb;
00132  w=(long)((double)Ymax*mr)+1;
00133  for(i=0;i<Ymax;i++)for(j=0;j<Xmax;j++){
00134    if(i < w){
00135      if(Bb != NULL){
00136        bb=(Bb+i*Xmax+j);
00137        S->R=(unsigned char)bb->R;
00138        S->G=(unsigned char)bb->G;
00139        S->B=(unsigned char)bb->B;
00140      }
00141      else{
00142        S->R = (unsigned char)R;
00143        S->G = (unsigned char)G;
00144        S->B = (unsigned char)B;
00145      }
00146    }
00147    S++;
00148  }
00149 }
00150 
00151 static void WipeRL(double mr, fullscreenbuffer *S, long Xmax, long Ymax,
00152                    long R, long G, long B, fullscreenbuffer *Bb){
00153  long i,j;
00154  long w;
00155  fullscreenbuffer *bb;
00156  w=Xmax-(long)((double)Xmax*mr);
00157  for(i=0;i<Ymax;i++)for(j=0;j<Xmax;j++){
00158    if(j >= w){
00159      if(Bb != NULL){
00160        bb=(Bb+i*Xmax+j);
00161        S->R=(unsigned char)bb->R;
00162        S->G=(unsigned char)bb->G;
00163        S->B=(unsigned char)bb->B;
00164      }
00165      else{
00166        S->R = (unsigned char)R;
00167        S->G = (unsigned char)G;
00168        S->B = (unsigned char)B;
00169     }
00170    }
00171    S++;
00172  }
00173 }
00174 
00175 static void WipeDU(double mr, fullscreenbuffer *S, long Xmax, long Ymax,
00176                    long R, long G, long B, fullscreenbuffer *Bb){
00177  long i,j;
00178  long w;
00179  fullscreenbuffer *bb;
00180  w=Ymax-(long)((double)Ymax*mr);
00181  for(i=0;i<Ymax;i++)for(j=0;j<Xmax;j++){
00182    if(i >= w){
00183      if(Bb != NULL){
00184        bb=(Bb+i*Xmax+j);
00185        S->R=(unsigned char)bb->R;
00186        S->G=(unsigned char)bb->G;
00187        S->B=(unsigned char)bb->B;
00188      }
00189      else{
00190        S->R = (unsigned char)R;
00191        S->G = (unsigned char)G;
00192        S->B = (unsigned char)B;
00193      }
00194    }
00195    S++;
00196  }
00197 }
00198 
00199 static void Desaturate(double mr, fullscreenbuffer *S, long Xmax, long Ymax,
00200                    long R, long G, long B){
00201  long i,j;
00202  double f;
00203  f=(double)(R+G+B)*0.33333333/255.0;
00204  for(i=0;i<Ymax;i++)for(j=0;j<Xmax;j++){
00205    S->R = min(255,(unsigned char)((double)(S->R)*f));
00206    S->G = min(255,(unsigned char)((double)(S->G)*f));
00207    S->B = min(255,(unsigned char)((double)(S->B)*f));
00208    S++;
00209  }
00210 }
00211 
00212 static void Monochrome(double mr, fullscreenbuffer *S, long Xmax, long Ymax,
00213                    long R, long G, long B){
00214  long i,j;
00215  double mono;
00216  for(i=0;i<Ymax;i++)for(j=0;j<Xmax;j++){
00217    mono=0.3333333*((double)S->R+(double)S->G+(double)S->B);
00218    S->R = (unsigned char)min(255.0,(double)(S->R)*(1.0-mr)+mono*mr);
00219    S->G = (unsigned char)min(255.0,(double)(S->G)*(1.0-mr)+mono*mr);
00220    S->B = (unsigned char)min(255.0,(double)(S->B)*(1.0-mr)+mono*mr);
00221    S++;
00222  }
00223 }
00224 
00225 static void Negative(double mr, fullscreenbuffer *S, long Xmax, long Ymax,
00226                    long R, long G, long B){
00227  long i,j;
00228  for(i=0;i<Ymax;i++)for(j=0;j<Xmax;j++){
00229    S->R = (unsigned char)((double)S->R*(1.0-mr)+(double)(255 - S->R)*mr);
00230    S->G = (unsigned char)((double)S->G*(1.0-mr)+(double)(255 - S->G)*mr);
00231    S->B = (unsigned char)((double)S->B*(1.0-mr)+(double)(255 - S->B)*mr);
00232    S++;
00233  }
00234 }
00235 
00236 static void Colourise(double mr, fullscreenbuffer *S, long Xmax, long Ymax,
00237                        long levels){
00238  long i,j,nx;
00239  unsigned char R,G,B;
00240  double h,s,v;
00241  for(i=0;i<Ymax;i++)for(j=0;j<Xmax;j++){
00242    Rgb2Hsv(S->R,S->G,S->B,&h,&s,&v);
00243    if     (v > 0.8)v=1.0;
00244    else if(v > 0.6)v=0.8;
00245    else if(v > 0.4)v=0.6;
00246    else if(v > 0.2)v=0.4;
00247    else v=0.1;
00248    if     (s > 0.8)s=1.0;
00249    else if(s > 0.6)s=0.8;
00250    else if(s > 0.4)s=0.6;
00251    else if(s > 0.2)s=0.4;
00252    else s=0.1;
00253    Hsv2Rgb(h,s,v,&R,&G,&B);
00254    S->R = (unsigned char)((double)S->R*(1.0-mr)+(double)R*mr);
00255    S->G = (unsigned char)((double)S->G*(1.0-mr)+(double)G*mr);
00256    S->B = (unsigned char)((double)S->B*(1.0-mr)+(double)B*mr);
00257    S++;
00258  }
00259 }
00260 
00261 static void ChangeHue(double mr, fullscreenbuffer *S, long Xmax, long Ymax,
00262                        long angle){
00263  long i,j;
00264  unsigned char R,G,B;
00265  double h,s,v;
00266  for(i=0;i<Ymax;i++)for(j=0;j<Xmax;j++){
00267    Rgb2Hsv(S->R,S->G,S->B,&h,&s,&v);
00268    h += (double)angle*mr;
00269    while(h > 360.0)h -= 360.0;
00270    Hsv2Rgb(h,s,v,&R,&G,&B);
00271    S->R = (unsigned char)min(255,R);
00272    S->G = (unsigned char)min(255,G);
00273    S->B = (unsigned char)min(255,B);
00274    S++;
00275  }
00276 }
00277 
00278 static void Pixelate(double mr, fullscreenbuffer *S, long Xmax, long Ymax,
00279                      long nxx, long nyy){
00280  long i,j,k,l,nx,ny,n;
00281  double Rav,Gav,Bav;
00282  fullscreenbuffer *s;
00283  if(nxx < 1 || nyy < 1 || nxx > Xmax || nyy > Ymax)return;
00284  nx = Xmax/nxx; ny=Ymax/nyy;
00285  if(nx*nxx < Xmax)nx++;
00286  if(ny*nyy < Ymax)ny++;
00287  nx=1+mr*(nx-1);
00288  ny=1+mr*(ny-1);
00289  for(i=0;i<Ymax;i+=ny)for(j=0;j<Xmax;j+=nx){
00290    Rav=Gav=Bav=0.0; n=0;
00291    for(k=i;k<i+ny;k++)for(l=j;l<j+nx;l++){
00292      if(l < Xmax && k < Ymax){
00293        s=(S+k*Xmax+l);
00294        Rav += (double)s->R;
00295        Gav += (double)s->G;
00296        Bav += (double)s->B;
00297        n++;
00298      }
00299    }
00300    Rav /= (double)n; Gav /= (double)n; Bav /= (double)n;
00301    for(k=i;k<i+ny;k++)for(l=j;l<j+nx;l++){
00302      if(l < Xmax && k < Ymax){
00303        s=(S+k*Xmax+l);
00304        s->R = (unsigned char)(Rav);
00305        s->G = (unsigned char)(Gav);
00306        s->B = (unsigned char)(Bav);
00307      }
00308    }
00309  }
00310 }
00311 
00312 static void WipeBlocks(double mr, fullscreenbuffer *S, long Xmax, long Ymax,
00313                      long nnx, long nny, long R, long G, long B,
00314                      fullscreenbuffer *Bb){
00315  long i,j,k,l,nx,ny,n,ii,jj,id;
00316  fullscreenbuffer *s,*bb;
00317  if(nnx < 1 || nny < 1 || nnx > Xmax || nny > Ymax)return;
00318  nx = Xmax/nnx; ny=Ymax/nny;
00319  if(nx*nnx < Xmax)nx++;
00320  if(ny*nny < Ymax)ny++;
00321  n=(long)((double)nnx*(double)nny*mr);
00322  ii=0;
00323  for(i=0;i<Ymax;i+=ny){
00324    jj=0;
00325    for(j=0;j<Xmax;j+=nx){
00326      id=ii*nnx+jj;
00327      for(k=i;k<i+ny;k++)for(l=j;l<j+nx;l++){
00328        if(id < n && l < Xmax && k < Ymax){
00329          s=(S+k*Xmax+l);
00330          if(Bb != NULL){
00331            bb=(Bb+k*Xmax+l);
00332            s->R=(unsigned char)bb->R;
00333            s->G=(unsigned char)bb->G;
00334            s->B=(unsigned char)bb->B;
00335          }
00336          else{
00337            s->R = (unsigned char)R;
00338            s->G = (unsigned char)G;
00339            s->B = (unsigned char)B;
00340          }
00341        }
00342      }
00343      jj++;
00344    }
00345    ii++;
00346  }
00347 }
00348 
00349 static void InvertLR(double mr, fullscreenbuffer *S, long Xmax, long Ymax,
00350                    long R, long G, long B){
00351  long i,j;
00352  long w;
00353  fullscreenbuffer *T,*Row;
00354  if((T=(fullscreenbuffer *)X__Malloc(Xmax*sizeof(fullscreenbuffer))) == NULL){
00355    MessageBeep(MB_OK);
00356    return;
00357  }
00358  for(i=0;i<Ymax;i++){
00359    Row=(S+i*Xmax);
00360    memcpy(T,Row,Xmax*sizeof(fullscreenbuffer));
00361    for(j=0;j<Xmax;j++){
00362      (Row+j)->R = (T+Xmax-1-j)->R;
00363      (Row+j)->G = (T+Xmax-1-j)->G;
00364      (Row+j)->B = (T+Xmax-1-j)->B;
00365      (Row+j)->A = (T+Xmax-1-j)->A;
00366    }
00367  }
00368  X__Free(T);
00369 }
00370 
00371 static void InvertUD(double mr, fullscreenbuffer *S, long Xmax, long Ymax,
00372                    long R, long G, long B){
00373  long i,j;
00374  long w;
00375  fullscreenbuffer *T,*Row1,*Row2;
00376  if((T=(fullscreenbuffer *)X__Malloc(Xmax*sizeof(fullscreenbuffer))) == NULL){
00377    MessageBeep(MB_OK);
00378    return;
00379  }
00380  for(i=0;i<Ymax/2;i++){
00381    Row1=(S+i*Xmax);
00382    Row2=(S+(Ymax-1-i)*Xmax);
00383    memcpy(T,Row2,Xmax*sizeof(fullscreenbuffer));
00384    memcpy(Row2,Row1,Xmax*sizeof(fullscreenbuffer));
00385    memcpy(Row1,T,Xmax*sizeof(fullscreenbuffer));
00386  }
00387  X__Free(T);
00388 }
00389 
00390 static void WipeSquareIO(double mr, fullscreenbuffer *S, long Xmax, long Ymax,
00391                    long R, long G, long B, fullscreenbuffer *Bb){
00392  long i,j;
00393  long w,u;
00394  fullscreenbuffer *bb;
00395  w=(long)((double)Xmax/2*mr);
00396  u=(long)((double)Ymax/2*mr);
00397  for(i=0;i<Ymax;i++)for(j=0;j<Xmax;j++){
00398    if(j > Xmax/2-w && j < Xmax/2+w &&
00399       i > Ymax/2-u && i < Ymax/2+u){
00400      if(Bb != NULL){
00401        bb=(Bb+i*Xmax+j);
00402        S->R=(unsigned char)bb->R;
00403        S->G=(unsigned char)bb->G;
00404        S->B=(unsigned char)bb->B;
00405      }
00406      else{
00407        S->R = (unsigned char)R;
00408        S->G = (unsigned char)G;
00409        S->B = (unsigned char)B;
00410      }
00411    }
00412    S++;
00413  }
00414 }
00415 
00416 static void WipeSquareOI(double mr, fullscreenbuffer *S, long Xmax, long Ymax,
00417                    long R, long G, long B, fullscreenbuffer *Bb){
00418  long i,j;
00419  long w,u;
00420  fullscreenbuffer *bb;
00421  mr = 1.0-mr;
00422  w=(long)((double)Xmax/2*mr);
00423  u=(long)((double)Ymax/2*mr);
00424  for(i=0;i<Ymax;i++)for(j=0;j<Xmax;j++){
00425    if(j < Xmax/2-w || j > Xmax/2+w ||
00426       i < Ymax/2-u || i > Ymax/2+u){
00427      if(Bb != NULL){
00428        bb=(Bb+i*Xmax+j);
00429        S->R=(unsigned char)bb->R;
00430        S->G=(unsigned char)bb->G;
00431        S->B=(unsigned char)bb->B;
00432      }
00433      else{
00434        S->R = (unsigned char)R;
00435        S->G = (unsigned char)G;
00436        S->B = (unsigned char)B;
00437      }
00438    }
00439    S++;
00440  }
00441 }
00442 
00443 static void PiP(double mr, fullscreenbuffer *Screen, long Xmax, long Ymax,
00444                 long nx, long ny, long R, long G, long B, long type,
00445                 fullscreenbuffer *Bb){
00446  vector p,Mn={0.0,0.0,1.0},Mx,My,Mp;
00447  double r,g,b;
00448  long i,j,w;
00449  fullscreenbuffer *S,*T,*Tcreen, *bb;
00450  if((Tcreen=(fullscreenbuffer *)X__Malloc(Xmax*Ymax*sizeof(fullscreenbuffer))) == NULL){
00451    MessageBeep(MB_OK);
00452    return;
00453  }
00454  T=Tcreen; S=Screen;
00455  memset(T,0,Xmax*Ymax*sizeof(fullscreenbuffer));
00456  Mp[2]=Mx[2]=My[2]=p[2]=0.0;
00457  Mx[1]=0.0; My[0]=0.0;
00458 
00459  if(type == 2){ /* zoom */
00460    Mx[0]=max(1.0,(double)Xmax-mr*(double)(Xmax));
00461    My[1]=max(1.0,(double)Ymax-mr*(double)(Ymax));
00462    Mp[0]=mr*(double)Xmax/2;
00463    Mp[1]=mr*(double)Ymax/2;
00464  }
00465  else if(type == 3){ /* squeeze LR */
00466    Mx[0]=max(1.0,(double)Xmax-mr*(double)(Xmax));
00467    My[1]=(double)Ymax;
00468    Mp[0]=mr*(double)Xmax/2;
00469    Mp[1]=0.0;
00470  }
00471  else if(type == 4){ /* squeeze UD */
00472    Mx[0]=(double)Xmax;
00473    My[1]=max(1.0,(double)Ymax-mr*(double)(Ymax));
00474    Mp[0]=0.0;
00475    Mp[1]=mr*(double)Ymax/2;
00476  }
00477  else {
00478    Mx[0]=(double)Xmax+mr*(double)(Xmax/2-Xmax);
00479    My[1]=(double)Ymax+mr*(double)(Ymax/2-Ymax);
00480    Mp[0]=mr*(double)nx;
00481    Mp[1]=mr*(double)ny;
00482  }
00483 
00484  for(i=0;i<Ymax;i++)for(j=0;j<Xmax;j++){
00485    p[0]=(double)j;
00486    p[1]=(double)i;
00487    if((w=MapFrom(p,Mp,Mx,My,Mn,Screen,Xmax,Ymax,&r,&g,&b)) > 0){
00488      T->R=(unsigned char)r;
00489      T->G=(unsigned char)g;
00490      T->B=(unsigned char)b;
00491    }
00492    else if(Bb != NULL){
00493      bb=(Bb+i*Xmax+j);
00494      T->R=(unsigned char)bb->R;
00495      T->G=(unsigned char)bb->G;
00496      T->B=(unsigned char)bb->B;
00497    }
00498    else if(w < 0 && type == 0){
00499      T->R=S->R;
00500      T->G=S->G;
00501      T->B=S->B;
00502    }
00503    else{
00504      T->R=(unsigned char)R;
00505      T->G=(unsigned char)G;
00506      T->B=(unsigned char)B;
00507    }
00508    T->A=S->A;
00509    S++;
00510    T++;
00511  }
00512  memcpy(Screen,Tcreen,Xmax*Ymax*sizeof(fullscreenbuffer));
00513  X__Free(Tcreen);
00514 }
00515 
00516 static void GetP(vector pc, vector d, vector Mp, vector Mn, vector p){
00517  double mu;
00518  vector dp;
00519  VECSUB(Mp,pc,dp)
00520  mu=DOT(Mn,dp)/DOT(Mn,d);
00521  VECSCALE(mu,d,d)
00522  VECSUM(pc,d,p)
00523 }
00524 
00525 static void FoldPiP(double mr, fullscreenbuffer *Screen, long Xmax, long Ymax,
00526                 long nx, long ny, long R, long G, long B, long type,
00527                 fullscreenbuffer *Bb){
00528  vector p,pc,d,Mn={0.0,0.0,1.0},Mx,My,Mp,x,y;
00529  double r,g,b;
00530  long i,j,w;
00531  double Tx[4][4],Ta[4][4],Tb[4][4],angle;
00532  vector Mxx;
00533  fullscreenbuffer *T,*Tcreen,*bb;
00534  if((Tcreen=(fullscreenbuffer *)X__Malloc(Xmax*Ymax*sizeof(fullscreenbuffer))) == NULL){
00535    MessageBeep(MB_OK);
00536    return;
00537  }
00538  memset(Tcreen,0,Xmax*Ymax*sizeof(fullscreenbuffer));
00539  Mp[2]=Mx[2]=My[2]=p[2]=0.0;
00540  Mx[1]=0.0; My[0]=0.0;
00541  nx = max(nx,45);
00542  if(type != 2){
00543    nx = min(nx,89);
00544  }
00545  angle = nx*mr;
00546  angle *= PI/180.0;
00547  if(type == 0){
00548    roty(Tx,angle);
00549    Mx[0]=(double)Xmax+mr*(double)(Xmax*0.95-Xmax);
00550    My[1]=(double)Ymax+mr*(double)(Ymax*0.9-Ymax);
00551    Mp[0]=mr*(double)Xmax*0.025;
00552    Mp[1]=mr*(double)Ymax*0.05;
00553    VECCOPY(Mx,Mxx)
00554    m4by1(Tx,Mxx,Mx);
00555    VECCOPY(My,Mxx)
00556    m4by1(Tx,Mxx,My);
00557    VECCOPY(Mn,Mxx)
00558    m4by1(Tx,Mxx,Mn);
00559  }
00560  else if(type == 1){
00561    rotx(Tx,-angle);
00562    Mx[0]=(double)Xmax+mr*(double)(Xmax*0.95-Xmax);
00563    My[1]=(double)Ymax+mr*(double)(Ymax*0.9-Ymax);
00564    Mp[0]=mr*(double)Xmax*0.025;
00565    Mp[1]=Ymax-fabs((double)Ymax*cos(angle));
00566    Mp[2]=fabs((double)Ymax*sin(angle));
00567    VECCOPY(Mx,Mxx)
00568    m4by1(Tx,Mxx,Mx);
00569    VECCOPY(My,Mxx)
00570    m4by1(Tx,Mxx,My);
00571    VECCOPY(Mn,Mxx)
00572    m4by1(Tx,Mxx,Mn);
00573  }
00574  else if(type == 2){
00575    Mx[0]=(double)Xmax;
00576    My[1]=(double)Ymax;
00577    Mp[0]=0.0;
00578    Mp[1]=0.0;
00579    tram(Ta,-(double)Xmax*0.5,-(double)Ymax*0.5,0.0);
00580    rotz(Tx,angle);
00581    m4by4(Tx,Ta,Tb);
00582    tram(Tx,(double)Xmax*0.5,(double)Ymax*0.5,0.0);
00583    m4by4(Tx,Tb,Ta);
00584    m4by1(Ta,Mx,x);
00585    m4by1(Ta,My,y);
00586    VECCOPY(Mp,Mxx)
00587    m4by1(Ta,Mxx,Mp);
00588    VECSUB(x,Mp,Mx)
00589    VECSUB(y,Mp,My)
00590 //   VECCOPY(Mn,Mxx)
00591 //   m4by1(Tx,Mxx,Mn);
00592  }
00593  T=Tcreen;
00594  for(i=0;i<Ymax;i++)for(j=0;j<Xmax;j++){
00595    pc[0] = (double)(Xmax/2);
00596    pc[1] = (double)(Ymax/2);
00597    pc[2] = (double)(-Xmax*2);
00598    d[0]  = (double)(j-Xmax/2);
00599    d[1]  = (double)(i-Ymax/2);
00600    d[2]  = -pc[2];
00601    GetP(pc,d,Mp,Mn,p);
00602    if((w=MapFrom(p,Mp,Mx,My,Mn,Screen,Xmax,Ymax,&r,&g,&b)) > 0){
00603      T->R=(unsigned char)r;
00604      T->G=(unsigned char)g;
00605      T->B=(unsigned char)b;
00606    }
00607    else if(Bb != NULL){
00608      bb=(Bb+i*Xmax+j);
00609      T->R=(unsigned char)bb->R;
00610      T->G=(unsigned char)bb->G;
00611      T->B=(unsigned char)bb->B;
00612    }
00613    else{
00614      T->R=(unsigned char)R;
00615      T->G=(unsigned char)G;
00616      T->B=(unsigned char)B;
00617    }
00618    T++;
00619  }
00620  memcpy(Screen,Tcreen,Xmax*Ymax*sizeof(fullscreenbuffer));
00621  X__Free(Tcreen);
00622 }
00623 
00624 long _RenderImageProcess(char *PrmList, XIMAGE *lpXimage){
00625  double mr;
00626  char name_path[256],imagefile[256];
00627  fullscreenbuffer *Screen,*BackBuffer;
00628  BOOL bMorph=FALSE;
00629  long cR,cG,cB,mcR,mcG,mcB,dummy,type,hold,back,lframe,nx,ny,Xmax,Ymax;
00630 #include "pro_key.c"
00631  sscanf(PrmList,"%s %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %s",name_path,
00632         &version,&type,&hold,
00633         &nx,&ny,&cR,&cG,&cB,&back,&lframe,imagefile);
00634  if(lpXimage->Morph && lpXimage->mParameters != NULL){
00635    bMorph=TRUE; mr=lpXimage->MorphRatio;
00636    sscanf(lpXimage->mParameters,
00637           "%s %ld %ld %ld %ld %ld %ld %ld %ld",
00638           name_path,&version,&dummy,&dummy,&dummy,&dummy,&dummy,
00639           &mcR,&mcG,&mcB);
00640  }
00641  if(!bMorph){
00642    mr=(double)(lpXimage->last_frame - lpXimage->first_frame);
00643    if(mr < 1.0)return 1;
00644    mr=(double)(lpXimage->this_frame - lpXimage->first_frame)/mr;
00645  }
00646  if     (hold == 1)mr=(1.0-mr);
00647  else if(hold == 2)mr=1.0;
00648  else if(hold == 3)mr=0.0;
00649  BackBuffer=NULL;
00650  Xmax=lpXimage->Xmax; Ymax=lpXimage->Ymax;
00651  if(back > 0 && type != 1 && type != 2 && type != 3 && type != 8 &&
00652     type != 9 && type != 11 && type != 12 && type != 13){
00653    unsigned char *ImagePixels;
00654    int ImageXsize,ImageYsize;
00655    if(back == 2)GetAnimFileName(imagefile,name_path,
00656                      lpXimage->this_frame - lpXimage->first_frame + 1,
00657                      1,lframe,1);
00658    RestoreWhiteSpaces(imagefile);
00659    if((ImagePixels=LoadMAP(imagefile,&ImageXsize,&ImageYsize)) != NULL){
00660      BackBuffer=ScaleImageMap(ImagePixels,ImageXsize,ImageYsize,Xmax,Ymax);
00661      X__Free(ImagePixels);
00662    }
00663  }
00664  Screen=lpXimage->Screen;
00665  if(type ==  0)FadeTo(mr,Screen,Xmax,Ymax,cR,cG,cB,BackBuffer);
00666  if(type ==  1)Desaturate(mr,Screen,Xmax,Ymax,cR,cG,cB);
00667  if(type ==  2)Monochrome(mr,Screen,Xmax,Ymax,cR,cG,cB);
00668  if(type ==  3)Negative(mr,Screen,Xmax,Ymax,cR,cG,cB);
00669  if(type ==  4)WipeLR(mr,Screen,Xmax,Ymax,cR,cG,cB,BackBuffer);
00670  if(type ==  5)WipeRL(mr,Screen,Xmax,Ymax,cR,cG,cB,BackBuffer);
00671  if(type ==  6)WipeUD(mr,Screen,Xmax,Ymax,cR,cG,cB,BackBuffer);
00672  if(type ==  7)WipeDU(mr,Screen,Xmax,Ymax,cR,cG,cB,BackBuffer);
00673  if(type ==  8)Colourise(mr,Screen,Xmax,Ymax,nx);
00674  if(type ==  9)Pixelate(mr,Screen,Xmax,Ymax,nx,ny);
00675  if(type == 10)WipeBlocks(mr,Screen,Xmax,Ymax,nx,ny,cR,cG,cB,BackBuffer);
00676  if(type == 11)ChangeHue(mr,Screen,Xmax,Ymax,nx);
00677  if(type == 12)InvertLR(mr,Screen,Xmax,Ymax,cR,cG,cB);
00678  if(type == 13)InvertUD(mr,Screen,Xmax,Ymax,cR,cG,cB);
00679  if(type == 14)WipeSquareIO(mr,Screen,Xmax,Ymax,cR,cG,cB,BackBuffer);
00680  if(type == 15)WipeSquareOI(mr,Screen,Xmax,Ymax,cR,cG,cB,BackBuffer);
00681  if(type == 16)PiP(mr,Screen,Xmax,Ymax,nx,ny,cR,cG,cB,0,NULL);
00682  if(type == 17)PiP(mr,Screen,Xmax,Ymax,nx,ny,cR,cG,cB,1,BackBuffer);
00683  if(type == 18)PiP(mr,Screen,Xmax,Ymax,nx,ny,cR,cG,cB,2,BackBuffer);
00684  if(type == 19)PiP(mr,Screen,Xmax,Ymax,nx,ny,cR,cG,cB,3,BackBuffer);
00685  if(type == 20)PiP(mr,Screen,Xmax,Ymax,nx,ny,cR,cG,cB,4,BackBuffer);
00686  if(type == 21)FoldPiP(mr,Screen,Xmax,Ymax,nx,ny,cR,cG,cB,0,BackBuffer);
00687  if(type == 22)FoldPiP(mr,Screen,Xmax,Ymax,nx,ny,cR,cG,cB,1,BackBuffer);
00688  if(type == 23)FoldPiP(mr,Screen,Xmax,Ymax,nx,ny,cR,cG,cB,2,BackBuffer);
00689  if(BackBuffer != NULL)X__Free(BackBuffer);
00690  return 1;
00691 }
00692 
00693 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
00694 
00695 static long colour[3]={255,255,255};
00696 static long type=0,hold=0,back=0,lframe=9999,nx=10,ny=10;
00697 static char iname[256];
00698 static X__MEMORY_MANAGER *lpLocalEVI;
00699 
00700 char * _SetExternalParameters(
00701   char *Op,                 /* string for the parameters                  */
00702   HWND hWnd,                /* parent window                              */
00703   long ruler,               /* ruler scale value to facilitate scaling    */
00704   char *name,               /* name of DLL file with the effect           */
00705   X__MEMORY_MANAGER *lpEVI /* pointer to structure with memory functions */
00706                                     ){
00707  char buffer[1024];
00708  long id1,id2;   /* integer scaled radius value */
00709  strcpy(iname," ");
00710  if(Op != NULL){  /* parameters exist so read them off the list */
00711    sscanf(Op,"%s %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %s",buffer,&version,
00712           &type,&hold,&nx,&ny,&colour[0],&colour[1],&colour[2],
00713           &back,&lframe,iname);
00714  }
00715  lpLocalEVI=lpEVI;
00716  if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG_VIDEO),hWnd,
00717               (DLGPROC)DlgProc) == FALSE)return Op;
00718  if(Op != NULL)CALL_FREE(Op);  /* free the old string */
00719  sprintf(buffer,"%s %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %s",
00720            name,version,type,hold,
00721            nx,ny,colour[0],colour[1],colour[2],back,lframe,iname);
00722  if((Op=(char *)CALL_MALLOC(strlen(buffer)+1)) == NULL){
00723   MessageBox (GetFocus(),"External effect: Out of memory","Error",
00724                 MB_OK|MB_TASKMODAL|MB_ICONSTOP);
00725    return NULL;
00726  }
00727  strcpy(Op,buffer);
00728  return Op;
00729 }
00730 
00731 #define NVIDEO 24
00732 
00733 static void LoadAnimatedClip(HWND hDlg,long id){
00734  char *c,str[32],modname[256];
00735  GetModuleFileName(hDLLinstance,modname,255);
00736  if((c=strrchr(modname,'.')) != NULL){
00737    sprintf(str,"%ld",id+1);
00738    strcpy(c,str);
00739    strcat(modname,".avi");
00740    Animate_Open(GetDlgItem(hDlg,DLG_IMAGE),modname);
00741    Animate_Play(GetDlgItem(hDlg,DLG_IMAGE),0, -1, -1);
00742  }
00743 }
00744 
00745 
00746 /*************** Function that renders anyof the OpenGL Functionality ************/
00747 
00748 long _RenderGLexternal(char *PrmList, XIMAGE *lpXimage){
00749 MessageBox(NULL,"Fog OpenGL function called","OK",MB_OK);
00750  return 1;
00751 }
00752 
00753 
00754 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
00755  BOOL err;
00756  int i;
00757  char lname[256],text[512];
00758  static long type_list[NVIDEO]={
00759    DLG_VIDEO_1,
00760    DLG_VIDEO_2,
00761    DLG_VIDEO_3,
00762    DLG_VIDEO_4,
00763    DLG_VIDEO_5,
00764    DLG_VIDEO_6,
00765    DLG_VIDEO_7,
00766    DLG_VIDEO_8,
00767    DLG_VIDEO_9,
00768    DLG_VIDEO_10,
00769    DLG_VIDEO_11,
00770    DLG_VIDEO_12,
00771    DLG_VIDEO_13,
00772    DLG_VIDEO_14,
00773    DLG_VIDEO_15,
00774    DLG_VIDEO_16,
00775    DLG_VIDEO_17,
00776    DLG_VIDEO_18,
00777    DLG_VIDEO_19,
00778    DLG_VIDEO_20,
00779    DLG_VIDEO_21,
00780    DLG_VIDEO_22,
00781    DLG_VIDEO_23,
00782    DLG_VIDEO_24
00783  };
00784  static long text_list[NVIDEO]={
00785    IDX_VIDEO_1,
00786    IDX_VIDEO_2,
00787    IDX_VIDEO_3,
00788    IDX_VIDEO_4,
00789    IDX_VIDEO_5,
00790    IDX_VIDEO_6,
00791    IDX_VIDEO_7,
00792    IDX_VIDEO_8,
00793    IDX_VIDEO_9,
00794    IDX_VIDEO_10,
00795    IDX_VIDEO_11,
00796    IDX_VIDEO_12,
00797    IDX_VIDEO_13,
00798    IDX_VIDEO_14,
00799    IDX_VIDEO_15,
00800    IDX_VIDEO_16,
00801    IDX_VIDEO_17,
00802    IDX_VIDEO_18,
00803    IDX_VIDEO_19,
00804    IDX_VIDEO_20,
00805    IDX_VIDEO_21,
00806    IDX_VIDEO_22,
00807    IDX_VIDEO_23,
00808    IDX_VIDEO_24
00809  };
00810  switch( msg ) {
00811    case WM_INITDIALOG:
00812      if     (hold == 0)
00813        SendDlgItemMessage(hwnd,DLG_VIDEO_FADE_IN,BM_SETCHECK,TRUE,0);
00814      else if(hold == 1)
00815        SendDlgItemMessage(hwnd,DLG_VIDEO_FADE_OUT,BM_SETCHECK,TRUE,0);
00816      else if(hold == 2)
00817        SendDlgItemMessage(hwnd,DLG_VIDEO_HOLD_IN,BM_SETCHECK,TRUE,0);
00818      else if(hold == 3)
00819        SendDlgItemMessage(hwnd,DLG_VIDEO_HOLD_OUT,BM_SETCHECK,TRUE,0);
00820 //     for(i=0;i<NVIDEO-2;i++){
00821      for(i=0;i<NVIDEO;i++){
00822        LoadString(hDLLinstance,type_list[i],lname,256);
00823        SendDlgItemMessage(hwnd,DLG_VIDEO_LIST,LB_ADDSTRING,0,
00824                    (LPARAM)(LPCTSTR)lname);
00825      }
00826      SendDlgItemMessage(hwnd,DLG_VIDEO_LIST,LB_SETCURSEL,(WPARAM)type,0);
00827      if     (back == 0)
00828        SendDlgItemMessage(hwnd,DLG_VIDEO_PLAIN,BM_SETCHECK,TRUE,0);
00829      if     (back == 1)
00830        SendDlgItemMessage(hwnd,DLG_VIDEO_IMAGE,BM_SETCHECK,TRUE,0);
00831      if     (back == 2)
00832        SendDlgItemMessage(hwnd,DLG_VIDEO_ANIIMAGE,BM_SETCHECK,TRUE,0);
00833      strcpy(lname,iname);
00834      RestoreWhiteSpaces(lname);
00835      SetDlgItemText(hwnd,DLG_VIDEO_IMAGENAME,lname);
00836      SetDlgItemInt(hwnd,DLG_VIDEO_NX,nx,TRUE);
00837      SetDlgItemInt(hwnd,DLG_VIDEO_NY,ny,TRUE);
00838      SetDlgItemInt(hwnd,DLG_VIDEO_LASTFRAME,lframe,TRUE);
00839      LoadAnimatedClip(hwnd,type);
00840      LoadString(hDLLinstance,text_list[type],text,256);
00841      SendDlgItemMessage(hwnd,DLG_VIDEO_HELP,WM_SETTEXT,0,(LPARAM)text);
00842      CentreDialogOnScreen(hwnd);
00843      return TRUE;
00844    case WM_PAINT:
00845      PaintBackground(hwnd);
00846      break;
00847    case WM_DRAWITEM:{
00848        LPDRAWITEMSTRUCT lpdis;
00849        HBRUSH   hbr,hbrold;
00850        BYTE r,g,b;
00851        lpdis=(LPDRAWITEMSTRUCT)lparam;
00852        if(lpdis->CtlID == DLG_VIDEO_COLOUR){
00853          r=(BYTE)colour[0]; g=(BYTE)colour[1]; b=(BYTE)colour[2];
00854          if(lpdis->itemState & ODS_SELECTED)
00855             InvertRect(lpdis->hDC,&(lpdis->rcItem));
00856          else{
00857            hbr=CreateSolidBrush(RGB(r,g,b));
00858            hbrold=SelectObject(lpdis->hDC,hbr);
00859            Rectangle(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top,
00860                          lpdis->rcItem.right,lpdis->rcItem.bottom);
00861            SelectObject(lpdis->hDC,hbrold);
00862            DeleteObject(hbr);
00863          }
00864        }
00865      }
00866      break;
00867    case WM_COMMAND:
00868      switch(LOWORD(wparam)){
00869         case DLG_VIDEO_LIST:
00870           switch(HIWORD(wparam)){
00871             case LBN_SELCHANGE:{
00872                HWND hctl;
00873                hctl=GetDlgItem(hwnd,DLG_VIDEO_LIST);
00874                i=SendMessage(hctl,LB_GETCURSEL,0,0);
00875                LoadAnimatedClip(hwnd,i);
00876                LoadString(hDLLinstance,text_list[i],text,256);
00877                SendDlgItemMessage(hwnd,DLG_VIDEO_HELP,WM_SETTEXT,0,(LPARAM)text);
00878             }
00879             break;
00880             default: break;
00881           }
00882           break;
00883         case DLG_VIDEO_SETIMAGENAME:{
00884             strcpy(lname,iname);
00885             RestoreWhiteSpaces(lname);
00886             if(XimageFileName(lpLocalEVI->lpAni,lname,"gif",
00887                               "Choose First/Only Image File",
00888                               "All file formats|*.gif;*.tga|"
00889                               "Compuserve GIFs|*.gif|"
00890                               "Targa TGAs|*.tga|",
00891                               hwnd)){
00892 
00893               SetDlgItemText(hwnd,DLG_VIDEO_IMAGENAME,lname);
00894               HideWhiteSpaces(lname);
00895               strcpy(iname,lname);
00896             }
00897           }
00898           break;
00899         case DLG_VIDEO_COLOUR:
00900           SetColour(colour,hwnd);
00901           InvalidateRect(GetDlgItem(hwnd,DLG_VIDEO_COLOUR),NULL,FALSE);
00902           break;
00903         case IDCANCEL:
00904           EndDialog(hwnd,FALSE);
00905           return(TRUE);
00906         case IDOK:
00907           nx=GetDlgItemInt(hwnd,DLG_VIDEO_NX,&err,FALSE);
00908           ny=GetDlgItemInt(hwnd,DLG_VIDEO_NY,&err,FALSE);
00909           lframe=GetDlgItemInt(hwnd,DLG_VIDEO_LASTFRAME,&err,FALSE);
00910           if(SendDlgItemMessage(hwnd,DLG_VIDEO_FADE_IN,BM_GETCHECK,0,0))
00911             hold=0;
00912           if(SendDlgItemMessage(hwnd,DLG_VIDEO_FADE_OUT,BM_GETCHECK,0,0))
00913             hold=1;
00914           if(SendDlgItemMessage(hwnd,DLG_VIDEO_HOLD_IN,BM_GETCHECK,0,0))
00915             hold=2;
00916           if(SendDlgItemMessage(hwnd,DLG_VIDEO_HOLD_OUT,BM_GETCHECK,0,0))
00917             hold=3;
00918           if(SendDlgItemMessage(hwnd,DLG_VIDEO_ANIIMAGE,BM_GETCHECK,0,0))
00919             back=2;
00920           if(SendDlgItemMessage(hwnd,DLG_VIDEO_IMAGE,BM_GETCHECK,0,0))
00921             back=1;
00922           if(SendDlgItemMessage(hwnd,DLG_VIDEO_PLAIN,BM_GETCHECK,0,0))
00923             back=0;
00924           type=SendDlgItemMessage(hwnd,DLG_VIDEO_LIST,LB_GETCURSEL,0,0);
00925 //          for(i=0;i<NVIDEO;i++)
00926 //            if(SendDlgItemMessage(hwnd,type_list[i],BM_GETCHECK,0,0))type=i;
00927           EndDialog(hwnd,TRUE);
00928           return(TRUE);
00929         default:
00930           break;
00931       }
00932       break;
00933     default: break;
00934  }
00935  return FALSE;
00936 }
00937 
00938 #include "video2.c"

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