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 #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"
00033 #include "..\common\postprocess\ximage.h"
00034 #include "local.h"
00035
00036 #include "image.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;
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;
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 CycleBrightness(double mr, fullscreenbuffer *S, long Xmax, long Ymax,
00083 long R, long G, long B, fullscreenbuffer *Bb){
00084 long i,j;
00085 double mono;
00086 for(i=0;i<Ymax;i++)for(j=0;j<Xmax;j++){
00087 mono=((double)(S->R) + (double)(S->G) + (double)(S->B))*0.33333;
00088 mono -= 256.0*mr;
00089 if(mono < 0.0)mono += 256;
00090 S->R = (unsigned char)mono;
00091 S->G = (unsigned char)mono;
00092 S->B = (unsigned char)mono;
00093 S++;
00094 }
00095 }
00096
00097
00098 static void CycleColours(double mr, fullscreenbuffer *S, long Xmax, long Ymax,
00099 long R, long G, long B, fullscreenbuffer *Bb){
00100 long i,j;
00101 double r,g,b;
00102 for(i=0;i<Ymax;i++)for(j=0;j<Xmax;j++){
00103 r=(double)(S->R);
00104 g=(double)(S->G);
00105 b=(double)(S->B);
00106 r -= 256.0*mr; if(r < 0.0)r += 256;
00107 g -= 256.0*mr; if(g < 0.0)g += 256;
00108 b -= 256.0*mr; if(b < 0.0)b += 256;
00109 S->R = (unsigned char)r;
00110 S->G = (unsigned char)g;
00111 S->B = (unsigned char)b;
00112 S++;
00113 }
00114 }
00115
00116 static void OscillateBrightness(double mr, fullscreenbuffer *S, long Xmax, long Ymax,
00117 long R, long G, long B, fullscreenbuffer *Bb){
00118 long i,j;
00119 double mono,phase;
00120 for(i=0;i<Ymax;i++)for(j=0;j<Xmax;j++){
00121 phase=((double)(S->R) + (double)(S->G) + (double)(S->B))*0.33333/256.0;
00122 mono = sin(2*3.1415926*(mr+phase));
00123 mono = min(255.0,(1.0+mono)*128.0);
00124 S->R = (unsigned char)mono;
00125 S->G = (unsigned char)mono;
00126 S->B = (unsigned char)mono;
00127 S++;
00128 }
00129 }
00130
00131 static void OscillateColours(double mr, fullscreenbuffer *S, long Xmax, long Ymax,
00132 long R, long G, long B, fullscreenbuffer *Bb){
00133 long i,j;
00134 double r,g,b,phaser,phaseg,phaseb;
00135 for(i=0;i<Ymax;i++)for(j=0;j<Xmax;j++){
00136 phaser=((double)(S->R))/256.0;
00137 phaseg=((double)(S->G))/256.0;
00138 phaseb=((double)(S->B))/256.0;
00139 r = sin(2*3.1415926*(mr+phaser));
00140 r = min(255.0,(1.0+r)*128.0);
00141 g = sin(2*3.1415926*(mr+phaseg));
00142 g = min(255.0,(1.0+g)*128.0);
00143 b = sin(2*3.1415926*(mr+phaseb));
00144 b = min(255.0,(1.0+b)*128.0);
00145 S->R = (unsigned char)r;
00146 S->G = (unsigned char)g;
00147 S->B = (unsigned char)b;
00148 S++;
00149 }
00150 }
00151
00152 static void TintImage(double mr, fullscreenbuffer *S, long Xmax, long Ymax,
00153 long R, long G, long B, fullscreenbuffer *Bb){
00154 long i,j;
00155 double r,g,b;
00156 for(i=0;i<Ymax;i++)for(j=0;j<Xmax;j++){
00157 r=(double)(S->R) * (1.0-(1.0-((double)R)/255.0)*mr);
00158 g=(double)(S->G) * (1.0-(1.0-((double)G)/255.0)*mr);
00159 b=(double)(S->B) * (1.0-(1.0-((double)B)/255.0)*mr);
00160 S->R = (unsigned char)r;
00161 S->G = (unsigned char)g;
00162 S->B = (unsigned char)b;
00163 S++;
00164 }
00165 }
00166
00167
00168
00169 long _RenderImageProcess(char *PrmList, XIMAGE *lpXimage){
00170 double mr;
00171 char name_path[256],imagefile[256];
00172 fullscreenbuffer *Screen,*BackBuffer;
00173 BOOL bMorph=FALSE;
00174 long cR,cG,cB,mcR,mcG,mcB,dummy,type,hold,back,lframe,nx,ny,Xmax,Ymax;
00175 #include "pro_key.c"
00176 sscanf(PrmList,"%s %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %s",name_path,
00177 &version,&type,&hold,
00178 &nx,&ny,&cR,&cG,&cB,&back,&lframe,imagefile);
00179 if(lpXimage->Morph && lpXimage->mParameters != NULL){
00180 bMorph=TRUE; mr=lpXimage->MorphRatio;
00181 sscanf(lpXimage->mParameters,
00182 "%s %ld %ld %ld %ld %ld %ld %ld %ld",
00183 name_path,&version,&dummy,&dummy,&dummy,&dummy,&dummy,
00184 &mcR,&mcG,&mcB);
00185 }
00186 if(!bMorph){
00187 mr=(double)(lpXimage->last_frame - lpXimage->first_frame);
00188 if(mr < 1.0)return 1;
00189 mr=(double)(lpXimage->this_frame - lpXimage->first_frame)/mr;
00190 }
00191 if (hold == 1)mr=(1.0-mr);
00192 else if(hold == 2)mr=1.0;
00193 else if(hold == 3)mr=0.0;
00194 BackBuffer=NULL;
00195 Xmax=lpXimage->Xmax; Ymax=lpXimage->Ymax;
00196 #if 0
00197 if(back > 0 && type != 1 && type != 2 && type != 3 && type != 8 &&
00198 type != 9 && type != 11 && type != 12 && type != 13){
00199 unsigned char *ImagePixels;
00200 int ImageXsize,ImageYsize;
00201 if(back == 2)GetAnimFileName(imagefile,name_path,
00202 lpXimage->this_frame - lpXimage->first_frame + 1,
00203 1,lframe,1);
00204 RestoreWhiteSpaces(imagefile);
00205 if((ImagePixels=LoadMAP(imagefile,&ImageXsize,&ImageYsize)) != NULL){
00206 BackBuffer=ScaleImageMap(ImagePixels,ImageXsize,ImageYsize,Xmax,Ymax);
00207 X__Free(ImagePixels);
00208 }
00209 }
00210 #endif
00211 Screen=lpXimage->Screen;
00212 if(type == 0)CycleBrightness(mr,Screen,Xmax,Ymax,cR,cG,cB,BackBuffer);
00213 if(type == 1)OscillateBrightness(mr,Screen,Xmax,Ymax,cR,cG,cB,BackBuffer);
00214 if(type == 2)CycleColours(mr,Screen,Xmax,Ymax,cR,cG,cB,BackBuffer);
00215 if(type == 3)OscillateColours(mr,Screen,Xmax,Ymax,cR,cG,cB,BackBuffer);
00216 if(type == 4)TintImage(mr,Screen,Xmax,Ymax,cR,cG,cB,BackBuffer);
00217 if(BackBuffer != NULL)X__Free(BackBuffer);
00218 return 1;
00219 }
00220
00221
00222
00223 long _RenderGLexternal(char *PrmList, XIMAGE *lpXimage){
00224 MessageBox(NULL,"OpenGL function called","OK",MB_OK);
00225 return 1;
00226 }
00227
00228
00229 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
00230
00231 static long colour[3]={255,255,255};
00232 static long type=0,hold=0,back=0,lframe=9999,nx=10,ny=10;
00233 static char iname[256];
00234 static X__MEMORY_MANAGER *lpLocalEVI;
00235
00236 char * _SetExternalParameters(
00237 char *Op,
00238 HWND hWnd,
00239 long ruler,
00240 char *name,
00241 X__MEMORY_MANAGER *lpEVI
00242 ){
00243 char buffer[1024];
00244 long id1,id2;
00245 strcpy(iname," ");
00246 if(Op != NULL){
00247 sscanf(Op,"%s %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %s",buffer,&version,
00248 &type,&hold,&nx,&ny,&colour[0],&colour[1],&colour[2],
00249 &back,&lframe,iname);
00250 }
00251 lpLocalEVI=lpEVI;
00252 if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG_VIDEO),hWnd,
00253 (DLGPROC)DlgProc) == FALSE)return Op;
00254 if(Op != NULL)CALL_FREE(Op);
00255 sprintf(buffer,"%s %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %s",
00256 name,version,type,hold,
00257 nx,ny,colour[0],colour[1],colour[2],back,lframe,iname);
00258 if((Op=(char *)CALL_MALLOC(strlen(buffer)+1)) == NULL){
00259 MessageBox (GetFocus(),"External effect: Out of memory","Error",
00260 MB_OK|MB_TASKMODAL|MB_ICONSTOP);
00261 return NULL;
00262 }
00263 strcpy(Op,buffer);
00264 return Op;
00265 }
00266
00267 #define NVIDEO 5
00268
00269 static void LoadAnimatedClip(HWND hDlg,long id){
00270 char *c,str[32],modname[256];
00271 GetModuleFileName(hDLLinstance,modname,255);
00272 if((c=strrchr(modname,'.')) != NULL){
00273 sprintf(str,"%ld",id+1);
00274 strcpy(c,str);
00275 strcat(modname,".avi");
00276 Animate_Open(GetDlgItem(hDlg,DLG_IMAGE),modname);
00277 Animate_Play(GetDlgItem(hDlg,DLG_IMAGE),0, -1, -1);
00278 }
00279 }
00280
00281 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
00282 BOOL err;
00283 int i;
00284 char lname[256],text[512];
00285 static long type_list[NVIDEO]={
00286 DLG_VIDEO_1,
00287 DLG_VIDEO_2,
00288 DLG_VIDEO_3,
00289 DLG_VIDEO_4,
00290 DLG_VIDEO_5
00291 };
00292 static long text_list[NVIDEO]={
00293 IDX_VIDEO_1,
00294 IDX_VIDEO_2,
00295 IDX_VIDEO_3,
00296 IDX_VIDEO_4,
00297 IDX_VIDEO_5
00298 };
00299 switch( msg ) {
00300 case WM_INITDIALOG:
00301 if (hold == 0)
00302 SendDlgItemMessage(hwnd,DLG_VIDEO_FADE_IN,BM_SETCHECK,TRUE,0);
00303 else if(hold == 1)
00304 SendDlgItemMessage(hwnd,DLG_VIDEO_FADE_OUT,BM_SETCHECK,TRUE,0);
00305 else if(hold == 2)
00306 SendDlgItemMessage(hwnd,DLG_VIDEO_HOLD_IN,BM_SETCHECK,TRUE,0);
00307 else if(hold == 3)
00308 SendDlgItemMessage(hwnd,DLG_VIDEO_HOLD_OUT,BM_SETCHECK,TRUE,0);
00309 for(i=0;i<NVIDEO;i++){
00310 LoadString(hDLLinstance,type_list[i],lname,256);
00311 SendDlgItemMessage(hwnd,DLG_VIDEO_LIST,LB_ADDSTRING,0,
00312 (LPARAM)(LPCTSTR)lname);
00313 }
00314 SendDlgItemMessage(hwnd,DLG_VIDEO_LIST,LB_SETCURSEL,(WPARAM)type,0);
00315 if (back == 0)
00316 SendDlgItemMessage(hwnd,DLG_VIDEO_PLAIN,BM_SETCHECK,TRUE,0);
00317 if (back == 1)
00318 SendDlgItemMessage(hwnd,DLG_VIDEO_IMAGE,BM_SETCHECK,TRUE,0);
00319 if (back == 2)
00320 SendDlgItemMessage(hwnd,DLG_VIDEO_ANIIMAGE,BM_SETCHECK,TRUE,0);
00321 strcpy(lname,iname);
00322 RestoreWhiteSpaces(lname);
00323 SetDlgItemText(hwnd,DLG_VIDEO_IMAGENAME,lname);
00324 SetDlgItemInt(hwnd,DLG_VIDEO_NX,nx,TRUE);
00325 SetDlgItemInt(hwnd,DLG_VIDEO_NY,ny,TRUE);
00326 SetDlgItemInt(hwnd,DLG_VIDEO_LASTFRAME,lframe,TRUE);
00327 LoadAnimatedClip(hwnd,type);
00328 LoadString(hDLLinstance,text_list[type],text,256);
00329 SendDlgItemMessage(hwnd,DLG_VIDEO_HELP,WM_SETTEXT,0,(LPARAM)text);
00330 CentreDialogOnScreen(hwnd);
00331 return TRUE;
00332 case WM_PAINT:
00333 PaintBackground(hwnd);
00334 break;
00335 case WM_DRAWITEM:{
00336 LPDRAWITEMSTRUCT lpdis;
00337 HBRUSH hbr,hbrold;
00338 BYTE r,g,b;
00339 lpdis=(LPDRAWITEMSTRUCT)lparam;
00340 if(lpdis->CtlID == DLG_VIDEO_COLOUR){
00341 r=(BYTE)colour[0]; g=(BYTE)colour[1]; b=(BYTE)colour[2];
00342 if(lpdis->itemState & ODS_SELECTED)
00343 InvertRect(lpdis->hDC,&(lpdis->rcItem));
00344 else{
00345 hbr=CreateSolidBrush(RGB(r,g,b));
00346 hbrold=SelectObject(lpdis->hDC,hbr);
00347 Rectangle(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top,
00348 lpdis->rcItem.right,lpdis->rcItem.bottom);
00349 SelectObject(lpdis->hDC,hbrold);
00350 DeleteObject(hbr);
00351 }
00352 }
00353 }
00354 break;
00355 case WM_COMMAND:
00356 switch(LOWORD(wparam)){
00357 case DLG_VIDEO_LIST:
00358 switch(HIWORD(wparam)){
00359 case LBN_SELCHANGE:{
00360 HWND hctl;
00361 hctl=GetDlgItem(hwnd,DLG_VIDEO_LIST);
00362 i=SendMessage(hctl,LB_GETCURSEL,0,0);
00363 LoadAnimatedClip(hwnd,i);
00364 LoadString(hDLLinstance,text_list[i],text,256);
00365 SendDlgItemMessage(hwnd,DLG_VIDEO_HELP,WM_SETTEXT,0,(LPARAM)text);
00366 }
00367 break;
00368 default: break;
00369 }
00370 break;
00371 case DLG_VIDEO_SETIMAGENAME:{
00372 strcpy(lname,iname);
00373 RestoreWhiteSpaces(lname);
00374 if(XimageFileName(lpLocalEVI->lpAni,lname,"gif",
00375 "Choose First/Only Image File",
00376 "All file formats|*.gif;*.tga|"
00377 "Compuserve GIFs|*.gif|"
00378 "Targa TGAs|*.tga|",
00379 hwnd)){
00380
00381 SetDlgItemText(hwnd,DLG_VIDEO_IMAGENAME,lname);
00382 HideWhiteSpaces(lname);
00383 strcpy(iname,lname);
00384 }
00385 }
00386 break;
00387 case DLG_VIDEO_COLOUR:
00388 SetColour(colour,hwnd);
00389 InvalidateRect(GetDlgItem(hwnd,DLG_VIDEO_COLOUR),NULL,FALSE);
00390 break;
00391 case IDCANCEL:
00392 EndDialog(hwnd,FALSE);
00393 return(TRUE);
00394 case IDOK:
00395 nx=GetDlgItemInt(hwnd,DLG_VIDEO_NX,&err,FALSE);
00396 ny=GetDlgItemInt(hwnd,DLG_VIDEO_NY,&err,FALSE);
00397 lframe=GetDlgItemInt(hwnd,DLG_VIDEO_LASTFRAME,&err,FALSE);
00398 if(SendDlgItemMessage(hwnd,DLG_VIDEO_FADE_IN,BM_GETCHECK,0,0))
00399 hold=0;
00400 if(SendDlgItemMessage(hwnd,DLG_VIDEO_FADE_OUT,BM_GETCHECK,0,0))
00401 hold=1;
00402 if(SendDlgItemMessage(hwnd,DLG_VIDEO_HOLD_IN,BM_GETCHECK,0,0))
00403 hold=2;
00404 if(SendDlgItemMessage(hwnd,DLG_VIDEO_HOLD_OUT,BM_GETCHECK,0,0))
00405 hold=3;
00406 if(SendDlgItemMessage(hwnd,DLG_VIDEO_ANIIMAGE,BM_GETCHECK,0,0))
00407 back=2;
00408 if(SendDlgItemMessage(hwnd,DLG_VIDEO_IMAGE,BM_GETCHECK,0,0))
00409 back=1;
00410 if(SendDlgItemMessage(hwnd,DLG_VIDEO_PLAIN,BM_GETCHECK,0,0))
00411 back=0;
00412 type=SendDlgItemMessage(hwnd,DLG_VIDEO_LIST,LB_GETCURSEL,0,0);
00413
00414
00415 EndDialog(hwnd,TRUE);
00416 return(TRUE);
00417 default:
00418 break;
00419 }
00420 break;
00421 default: break;
00422 }
00423 return FALSE;
00424 }
00425
00426 #include "video2.c"