00001
00002
00003
00004
00005 #include <stdlib.h>
00006 #include <stdio.h>
00007 #include <float.h>
00008 #include <math.h>
00009 #include <windows.h>
00010 #include <gl\gl.h>
00011 #include <gl\glu.h>
00012 #include "struct.h"
00013 #include "..\common\postprocess\ximage.h"
00014 #include "local.h"
00015
00016 #include "tv.h"
00017
00018 #if __X__MIPS__
00019 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00020 #endif
00021
00022 static HINSTANCE hDLLinstance=NULL;
00023
00024
00025
00026 #include "utils.h"
00027 #include "paint.c"
00028
00029
00030
00031 #if __WATCOMC__
00032 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00033 #elif __BC__
00034 BOOL WINAPI DllEntryPoint(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00035 #else
00036 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00037 #endif
00038 switch (dwReason) {
00039 case DLL_PROCESS_ATTACH:
00040 #if __X__MIPS__
00041 if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00042 #endif
00043 hDLLinstance = hDLL;
00044 break;
00045 case DLL_PROCESS_DETACH:
00046 #if __X__MIPS__
00047 if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00048 #endif
00049 break;
00050 }
00051 return (int)TRUE;
00052 }
00053
00054 #if __SC__
00055 #pragma startaddress(DllMain)
00056 #endif
00057
00058
00059
00060
00061
00062 static void Hsv2Rgb(double h, double s, double v,
00063 unsigned char *r, unsigned char *g, unsigned char *b){
00064 double rr,gg,bb,hh,ss,vv,maxcol,mincol;
00065 hh=(double)h; ss=(double)s; vv=(double)v;
00066 mincol=vv*(1.0-ss);
00067 if(hh <= 120.0){bb=mincol;
00068 if(hh <= 60){rr=vv; gg=mincol+hh*(vv-mincol)/(120.0-hh);}
00069 else {gg=vv; rr=mincol+(120.0-hh)*(vv-mincol)/hh;}
00070 }
00071 else if( hh <= 240){rr=mincol;
00072 if(hh <= 180){gg=vv; bb=mincol+(hh-120.0)*(vv-mincol)/(240.0-hh);}
00073 else {bb=vv; gg=mincol+(240.0-hh)*(vv-mincol)/(hh-120.0);}
00074 }
00075 else {gg=mincol;
00076 if(hh <= 300){bb=vv; rr=mincol+(hh-240.0)*(vv-mincol)/(360.0-hh);}
00077 else {rr=vv; bb=mincol+(360.0-hh)*(vv-mincol)/(hh-240.0);}
00078 }
00079 rr = rr*255.0; *r=(unsigned char)min(255,rr);
00080 gg = gg*255.0; *g=(unsigned char)min(255,gg);
00081 bb = bb*255.0; *b=(unsigned char)min(255,bb);
00082 }
00083
00084 static void Rgb2Hsv(unsigned char r, unsigned char g, unsigned char b,
00085 double *h, double *s, double *v){
00086 double rr,gg,bb,hh,ss,vv,maxcol,mincol;
00087 rr=(double)r; gg=(double)g; bb=(double)b;
00088 rr /= 255.0; gg /= 255.0; bb /= 255.0;
00089 maxcol=max(rr,max(gg,bb));
00090 mincol=min(rr,min(gg,bb));
00091 vv=maxcol;
00092 if(maxcol == mincol){ss=0; hh=0;}
00093 else{
00094 ss=(maxcol-mincol)/maxcol;
00095 if(mincol == bb)
00096 hh = 120.0*(gg-mincol)/(rr+gg-2.0*mincol);
00097 else if(mincol == rr)
00098 hh = 120.0*(1.0+(bb-mincol)/(bb+gg-2.0*mincol));
00099 else
00100 hh = 120.0*(2.0+(rr-mincol)/(rr+bb-2.0*mincol));
00101 }
00102 *h=hh;
00103 *s=ss;
00104 *v=vv;
00105 }
00106
00107 long _RenderImageProcess(char *PrmList, XIMAGE *lpXimage){
00108
00109
00110
00111
00112
00113
00114 int i,j,ftype,id1,id2;
00115 int mftype,mid1,mid2;
00116 double mr,range,d1,d2,h,s,v;
00117 char name_path[255];
00118 fullscreenbuffer *S;
00119 BOOL bMorph;
00120 sscanf(PrmList,"%s %d %d %d",name_path,&ftype,&id1,&id2);
00121 d1=(double)id1;
00122 d2=(double)id2;
00123 if(lpXimage->Morph && lpXimage->mParameters != NULL){
00124 bMorph=TRUE; mr=lpXimage->MorphRatio;
00125 sscanf(lpXimage->mParameters,"%s %d %d %d",
00126 name_path,&mftype,&mid1,&mid2);
00127 }
00128 d1/=255.0; d2/=255.0;
00129 range=(d1-d2);
00130 S=lpXimage->Screen;
00131 for(i=0;i<lpXimage->Ymax;i++){
00132 for(j=0;j<lpXimage->Xmax;j++){
00133 if(ftype == 0){
00134 if(j < lpXimage->Xmax - 2){
00135 S->R=(unsigned char)(((double)(S->R) + (double)((S+1)->R) + (double)((S+2)->R))/3);
00136 S->G=(unsigned char)(((double)(S->G) + (double)((S+1)->G) + (double)((S+2)->G))/3);
00137 S->B=(unsigned char)(((double)(S->B) + (double)((S+1)->B) + (double)((S+2)->B))/3);
00138 }
00139 else if(j < lpXimage->Xmax - 1){
00140 S->R=(unsigned char)(((double)(S->R) + (double)((S+1)->R))/2);
00141 S->G=(unsigned char)(((double)(S->G) + (double)((S+1)->G))/2);
00142 S->B=(unsigned char)(((double)(S->B) + (double)((S+1)->B))/2);
00143 }
00144 }
00145 Rgb2Hsv(S->R,S->G,S->B,&h,&s,&v);
00146 s=max(0.0,(s-d2))*range+d2;
00147 v=max(0.0,(v-d2))*range+d2;
00148 Hsv2Rgb(h,s,v,&(S->R),&(S->G),&(S->B));
00149
00150
00151
00152 S++;
00153 }
00154 }
00155 return 1;
00156 }
00157
00158
00159
00160 long _RenderGLexternal(char *PrmList, XIMAGE *lpXimage){
00161
00162 return 1;
00163 }
00164
00165
00166
00167
00168
00169 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
00170
00171 static double d1=200.0,d2=50.0;
00172 static int ftype=0;
00173
00174 char * _SetExternalParameters(
00175 char *Op,
00176 HWND hWnd,
00177 long ruler,
00178 char *name,
00179 X__MEMORY_MANAGER *lpEVI
00180 ){
00181
00182 char buffer[256];
00183 long id1,id2;
00184 if(Op != NULL){
00185 sscanf(Op,"%s %ld %ld %ld",buffer,&ftype,&id1,&id2);
00186 d1=(double)id1;
00187 d2=(double)id2;
00188 }
00189
00190
00191 if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG_FOG),hWnd,
00192 (DLGPROC)DlgProc) == FALSE)return Op;
00193
00194 if(Op != NULL)CALL_FREE(Op);
00195
00196 id1=(long)d1;
00197 id2=(long)d2;
00198 sprintf(buffer,"%s %ld %ld %ld",name,ftype,id1,id2);
00199
00200 if((Op=(char *)CALL_MALLOC(strlen(buffer)+1)) == NULL){
00201 MessageBox (GetFocus(),"External effect: Out of memory","Error",
00202 MB_OK|MB_TASKMODAL|MB_ICONSTOP);
00203 return NULL;
00204 }
00205
00206 strcpy(Op,buffer);
00207 return Op;
00208 }
00209
00210 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
00211 char str[32];
00212 switch( msg ) {
00213 case WM_INITDIALOG:
00214 if(ftype == 0)
00215 SendDlgItemMessage(hwnd,DLG_FOG_HAZE,BM_SETCHECK,TRUE,0);
00216 else
00217 SendDlgItemMessage(hwnd,DLG_FOG_FOG,BM_SETCHECK,TRUE,0);
00218 sprintf(str,"%.0f",d1);
00219 SetDlgItemText(hwnd,DLG_FOG_D1,str);
00220 sprintf(str,"%.0f",d2);
00221 SetDlgItemText(hwnd,DLG_FOG_D2,str);
00222 CentreDialogOnScreen(hwnd);
00223 return TRUE;
00224 case WM_PAINT:
00225 PaintBackground(hwnd);
00226 break;
00227 case WM_DRAWITEM:{
00228 LPDRAWITEMSTRUCT lpdis;
00229 HBRUSH hbr,hbrold;
00230 BYTE r,g,b;
00231 lpdis=(LPDRAWITEMSTRUCT)lparam;
00232 }
00233 break;
00234 case WM_COMMAND:
00235 switch(LOWORD(wparam)){
00236 case IDCANCEL:
00237 EndDialog(hwnd,FALSE);
00238 return(TRUE);
00239 case IDOK:
00240 if(SendDlgItemMessage(hwnd,DLG_FOG_FOG,BM_GETCHECK,0,0))
00241 ftype=1;
00242 else ftype=0;
00243 if(GetDlgItemText(hwnd,DLG_FOG_D1,str,12) != 0)d1=atof(str);
00244 if(GetDlgItemText(hwnd,DLG_FOG_D2,str,12) != 0)d2=atof(str);
00245 EndDialog(hwnd,TRUE);
00246 return(TRUE);
00247 default:
00248 break;
00249 }
00250 break;
00251 default: break;
00252 }
00253 return FALSE;
00254 }
00255