//------------------------------------------------------ // module : Tp2-IFT2425.c // author : // date : // version : 1.0 // language: C++ // note : //------------------------------------------------------ // //------------------------------------------------ // FICHIERS INCLUS ------------------------------- //------------------------------------------------ #include #include #include #include #include #include #include /*------------------------------------------------*/ /* DEFINITIONS -----------------------------------*/ /*------------------------------------------------*/ #define CARRE(X) ((X)*(X)) //------------------------- //--- Windows ------------- //------------------------- #include #include #include #include #include #include Display *display; int screen_num; int depth; Window root; Visual* visual; GC gc; /************************************************************************/ /* OPEN_DISPLAY() */ /************************************************************************/ int open_display() { if ((display=XOpenDisplay(NULL))==NULL) { printf("Connection impossible\n"); return(-1); } else { screen_num=DefaultScreen(display); visual=DefaultVisual(display,screen_num); depth=DefaultDepth(display,screen_num); root=RootWindow(display,screen_num); return 0; } } /************************************************************************/ /* FABRIQUE_WINDOW() */ /* Cette fonction crée une fenetre X et l'affiche à l'écran. */ /************************************************************************/ Window fabrique_window(char *nom_fen,int x,int y,int width,int height,int zoom) { Window win; XSizeHints size_hints; XWMHints wm_hints; XClassHint class_hints; XTextProperty windowName, iconName; char *name=nom_fen; if(zoom<0) { width/=-zoom; height/=-zoom; } if(zoom>0) { width*=zoom; height*=zoom; } win=XCreateSimpleWindow(display,root,x,y,width,height,1,0,255); size_hints.flags=PPosition|PSize|PMinSize; size_hints.min_width=width; size_hints.min_height=height; XStringListToTextProperty(&name,1,&windowName); XStringListToTextProperty(&name,1,&iconName); wm_hints.initial_state=NormalState; wm_hints.input=True; wm_hints.flags=StateHint|InputHint; class_hints.res_name=nom_fen; class_hints.res_class=nom_fen; XSetWMProperties(display,win,&windowName,&iconName, NULL,0,&size_hints,&wm_hints,&class_hints); gc=XCreateGC(display,win,0,NULL); XSelectInput(display,win,ExposureMask|KeyPressMask|ButtonPressMask| ButtonReleaseMask|ButtonMotionMask|PointerMotionHintMask| StructureNotifyMask); XMapWindow(display,win); return(win); } /****************************************************************************/ /* CREE_XIMAGE() */ /* Crée une XImage à partir d'un tableau de float */ /* L'image peut subir un zoom. */ /****************************************************************************/ XImage* cree_Ximage(float** mat,int z,int length,int width) { int lgth,wdth,lig,col,zoom_col,zoom_lig; float somme; unsigned char pix; unsigned char* dat; XImage* imageX; /*Zoom positiv*/ /*------------*/ if (z>0) { lgth=length*z; wdth=width*z; dat=(unsigned char*)malloc(lgth*(wdth*4)*sizeof(unsigned char)); if (dat==NULL) { printf("Impossible d'allouer de la memoire."); exit(-1); } for(lig=0;lig au format pgm //---------------------------------------------------------- void SaveImagePgm(char* bruit,char* name,float** mat,int lgth,int wdth) { int i,j; char buff[300]; FILE* fic; //--extension-- strcpy(buff,bruit); strcat(buff,name); strcat(buff,".pgm"); //--ouverture fichier-- fic=fopen(buff,"wb"); if (fic==NULL) { printf("Probleme dans la sauvegarde de %s",buff); exit(-1); } printf("\n Sauvegarde de %s au format pgm\n",buff); //--sauvegarde de l'entete-- fprintf(fic,"P5"); fprintf(fic,"\n# IMG Module"); fprintf(fic,"\n%d %d",wdth,lgth); fprintf(fic,"\n255\n"); //--enregistrement-- for(i=0;i0)&&(pix_x0)&&(pix_ywidth,x_ppicture1->height); XPutImage(display,win_ppicture2,gc,x_ppicture2,0,0,0,0,x_ppicture2->width,x_ppicture2->height); break; case KeyPress: if (XLookupKeysym(&ev.xkey,0)==XK_Return) { k++; k=k%NTEM; printf("[%d]",k); fflush(stdout); usleep(500000); x_ppicture1=cree_Ximage(Vct_ImgIn[k],zoom,length,width); x_ppicture2=cree_Ximage(Vct_ImgOut[k],zoom,length,width); XPutImage(display,win_ppicture1,gc,x_ppicture1,0,0,0,0,x_ppicture1->width,x_ppicture1->height); XPutImage(display,win_ppicture2,gc,x_ppicture2,0,0,0,0,x_ppicture2->width,x_ppicture2->height); } else { XDestroyImage(x_ppicture1); XDestroyImage(x_ppicture2); XFreeGC(display,gc); XCloseDisplay(display); flag_graph=0; break; } } if (!flag_graph) break; } } //retour sans probleme printf("\n Fini... \n\n\n"); return 0; }