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 "struct.h"
00032 #include "..\common\postprocess\ximage.h"
00033 #include "local.h"
00034
00035 #include "pixelate.h"
00036
00037 #if __X__MIPS__
00038 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00039 #endif
00040
00041 static HINSTANCE hDLLinstance=NULL;
00042
00043 #include "utils.h"
00044 #include "paint.c"
00045
00046 #if __WATCOMC__
00047 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00048 #elif __BC__
00049 BOOL WINAPI DllEntryPoint(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00050 #else
00051 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00052 #endif
00053 switch (dwReason) {
00054 case DLL_PROCESS_ATTACH:
00055 hDLLinstance = hDLL;
00056 break;
00057 case DLL_PROCESS_DETACH:
00058 break;
00059 }
00060 return (int)TRUE;
00061 }
00062
00063 static void GetConeR(long x, long y, long r,
00064 long Xmax, long Ymax,
00065 unsigned char *R,
00066 unsigned char *G,
00067 unsigned char *B,
00068 fullscreenbuffer *S){
00069 float d,dc=75.0;
00070 d=dc*((float)rand()/32767.0 - 0.5);
00071 d += (float)((S+y*Xmax+x)->R);
00072 d=min(255.0,d);
00073 d=max(0,d);
00074 *R=(unsigned char)d;
00075 d=dc*((float)rand()/32767.0 - 0.5);
00076 d += (float)((S+y*Xmax+x)->G);
00077 d=min(255.0,d);
00078 d=max(0,d);
00079 *G=(unsigned char)d;
00080 d=dc*((float)rand()/32767.0 - 0.5);
00081 d += (float)((S+y*Xmax+x)->B);
00082 d=min(255.0,d);
00083 d=max(0,d);
00084 *B=(unsigned char)d;
00085 return;
00086 }
00087
00088 static void GetConeC(long x, long y, long r,
00089 long Xmax, long Ymax,
00090 unsigned char *R,
00091 unsigned char *G,
00092 unsigned char *B,
00093 fullscreenbuffer *S){
00094 *R=(S+y*Xmax+x)->R;
00095 *G=(S+y*Xmax+x)->G;
00096 *B=(S+y*Xmax+x)->B;
00097 return;
00098 }
00099
00100 static void GetConeA(long x, long y, long r,
00101 long Xmax, long Ymax,
00102 unsigned char *R,
00103 unsigned char *G,
00104 unsigned char *B,
00105 fullscreenbuffer *S){
00106 float d,c=0.0,dr=0.0,dg=0.0,db=0.0;
00107 long i,j;
00108 fullscreenbuffer *s;
00109 for(i=max(x-r,0);i<min(x+r,Xmax-1);i++)
00110 for(j=max(y-r,0);j<min(y+r,Ymax-1);j++){
00111 d=sqrt((x-i)*(x-i)+(y-j)*(y-j));
00112 if(d < (float)r){
00113 s=(S+j*Xmax+i);
00114 c += 1.0;
00115 dr += (float)s->R;
00116 dg += (float)s->G;
00117 db += (float)s->B;
00118 }
00119 }
00120 *R = (unsigned char)(dr/c);
00121 *G = (unsigned char)(dg/c);
00122 *B = (unsigned char)(db/c);
00123 return;
00124 }
00125
00126 static void DrawCone(long x, long y, long r,
00127 long Xmax, long Ymax,
00128 unsigned char R,
00129 unsigned char G,
00130 unsigned char B,
00131 fullscreenbuffer *S,
00132 float *Z,
00133 int type){
00134 long i,j;
00135 float d,z;
00136 fullscreenbuffer *s;
00137 for(i=max(x-r,0);i<min(x+r,Xmax-1);i++)
00138 for(j=max(y-r,0);j<min(y+r,Ymax-1);j++){
00139 d=sqrt((float)(x-i)*(float)(x-i)+
00140 (float)(y-j)*(float)(y-j));
00141 if(d < (float)r){
00142 z=(r-d);
00143 if(z > *(Z+j*Xmax+i)){
00144 s=(S+j*Xmax+i);
00145
00146 if(type == 1 && r < 4) {
00147 if((d=fabs(z - *(Z+j*Xmax+i))) < 2.0){
00148 s->R=(2.0-d)/2.0*255+d/2.0*R;
00149 s->G=(2.0-d)/2.0*255+d/2.0*G;
00150 s->B=(2.0-d)/2.0*255+d/2.0*B;
00151 }
00152 else{
00153 s->R=R;
00154 s->G=G;
00155 s->B=B;
00156 }
00157 }
00158 else{
00159
00160 s->R=R;
00161 s->G=G;
00162 s->B=B;
00163 }
00164 *(Z+j*Xmax+i) = z;
00165 }
00166 }
00167 }
00168 return;
00169 }
00170
00171 long _RenderImageProcess(char *PrmList, XIMAGE *lpXimage){
00172 unsigned char R,G,B;
00173 long v,x,y,i,j,iRad,Xres,Yres,nXcones,nYcones,type;
00174 char name_path[255];
00175 float rad=0.125,*Zb;
00176 fullscreenbuffer *S,*So;
00177 sscanf(PrmList,"%s %ld %ld %f",name_path,&v,&type,&rad);
00178 Xres=lpXimage->Xmax; Yres=lpXimage->Ymax;
00179 iRad=(long)(rad*(float)Xres);
00180
00181
00182 nXcones=Xres/iRad+1;
00183 nYcones=Yres/iRad+1;
00184
00185 if(type == 0){
00186 iRad *= 2.0;
00187 nXcones *= 1.5; nYcones *= 1.5;
00188 }
00189 else{
00190 iRad *= 0.5;
00191 nXcones *= 1.5; nYcones *= 1.5;
00192 }
00193
00194
00195
00196
00197 So=(fullscreenbuffer *)X__Malloc(Xres*Yres*(long)sizeof(fullscreenbuffer));
00198 if(So == NULL){
00199 MessageBox(GetFocus(),"Memory Out",NULL,MB_OK);
00200 return 0;
00201 }
00202 Zb=(float *)X__Malloc(Xres*Yres*(long)sizeof(float));
00203 if(So == NULL){
00204 X__Free(So);
00205 MessageBox(GetFocus(),"Memory Out",NULL,MB_OK);
00206 return 0;
00207 }
00208 S=lpXimage->Screen;
00209 memset(So,0xFF,sizeof(fullscreenbuffer)*Xres*Yres);
00210 for(i=0;i<Xres;i++)for(j=0;j<Yres;j++)*(Zb+j*Xres+i)=0.0;
00211 for(i=0;i<nXcones;i++)for(j=0;j<nYcones;j++){
00212 x=(long)(Xres*(float)rand()/32767.0);
00213 y=(long)(Yres*(float)rand()/32767.0);
00214 GetConeC(x,y,iRad,Xres,Yres,&R,&G,&B,S);
00215
00217 DrawCone(x,y,iRad,Xres,Yres,R,G,B,So,Zb,type);
00218 }
00219
00220 memcpy(S,So,sizeof(fullscreenbuffer)*Xres*Yres);
00221 X__Free(So);
00222 X__Free(Zb);
00223 return 1;
00224 }
00225
00226
00227
00228 long _RenderGLexternal(char *PrmList, XIMAGE *lpXimage){
00229 MessageBox(NULL,"OpenGL function called","OK",MB_OK);
00230 return 1;
00231 }
00232
00233
00234
00235 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
00236
00237 static int version=1;
00238 static long type=0;
00239 static double radius=0.125;
00240
00241 char * _SetExternalParameters(
00242 char *Op,
00243 HWND hWnd,
00244 long ruler,
00245 char *name,
00246 X__MEMORY_MANAGER *lpEVI
00247 ){
00248 char buffer[256];
00249 if(Op != NULL){
00250 sscanf(Op,"%s %ld %ld %f",buffer,&version,&type,&radius);
00251 }
00252 if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG_PIXELATE),hWnd,
00253 (DLGPROC)DlgProc) == FALSE)return Op;
00254 if(Op != NULL)CALL_FREE(Op);
00255 sprintf(buffer,"%s %ld %ld %f",name,version,type,radius);
00256 if((Op=(char *)CALL_MALLOC(strlen(buffer)+1)) == NULL){
00257 MessageBox (GetFocus(),"External effect: Out of memory","Error",
00258 MB_OK|MB_TASKMODAL|MB_ICONSTOP);
00259 return NULL;
00260 }
00261 strcpy(Op,buffer);
00262 return Op;
00263 }
00264
00265 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
00266 char str[32];
00267 BOOL err;
00268 switch( msg ) {
00269 case WM_INITDIALOG:
00270 radius *= 100.0;
00271 sprintf(str,"%.1f",radius);
00272 SetDlgItemText(hwnd,DLG_PIXELATE_RADIUS,str);
00273 if (type == 0)
00274 SendDlgItemMessage(hwnd,DLG_PIXELATE_CRYSTAL,BM_SETCHECK,TRUE,0);
00275 if (type == 1)
00276 SendDlgItemMessage(hwnd,DLG_PIXELATE_POINTS,BM_SETCHECK,TRUE,0);
00277 CentreDialogOnScreen(hwnd);
00278 return TRUE;
00279 case WM_PAINT:
00280 PaintBackground(hwnd);
00281 break;
00282 case WM_COMMAND:
00283 switch(LOWORD(wparam)){
00284 case IDCANCEL:
00285 EndDialog(hwnd,FALSE);
00286 return(TRUE);
00287 case IDOK:
00288 if(GetDlgItemText(hwnd,DLG_PIXELATE_RADIUS,str,12) != 0)
00289 radius=atof(str);
00290 radius *= 0.01;
00291 if(SendDlgItemMessage(hwnd,DLG_PIXELATE_CRYSTAL,BM_GETCHECK,0,0))
00292 type=0;
00293 else type=1;
00294
00295 EndDialog(hwnd,TRUE);
00296 return(TRUE);
00297 default:
00298 break;
00299 }
00300 break;
00301 default: break;
00302 }
00303 return FALSE;
00304 }
00305