/*---------------------------------------------------*/ /* module : FonctionDemo.c */ /* auteur : Mignotte Max */ /* date : 10/09/99 */ /* langage : C */ /* labo : DIRO */ /*---------------------------------------------------*/ /*------------------------------------------------*/ /* FICHIERS INCLUS -------------------------------*/ /*------------------------------------------------*/ #include #include #include #include #include #include "FonctionDemo.h" /*------------------------------------------------*/ /* FONCTIONS -------------------------------------*/ /*------------------------------------------------*/ /*---------------------------------------------------------*/ /* Alloue de la memoire pour une matrice 1d de float */ /*---------------------------------------------------------*/ float* fmatrix_allocate_1d(int hsize) { float* matrix; matrix=(float*)malloc(sizeof(float)*hsize); if (matrix==NULL) printf("probleme d'allocation memoire"); return matrix; } /*----------------------------------------------------------*/ /* Alloue de la memoire pour une matrice 2d de float */ /*----------------------------------------------------------*/ float** fmatrix_allocate_2d(int vsize,int hsize) { int i; float** matrix; float *imptr; matrix=(float**)malloc(sizeof(float*)*vsize); if (matrix==NULL) printf("probleme d'allocation memoire"); imptr=(float*)malloc(sizeof(float)*hsize*vsize); if (imptr==NULL) printf("probleme d'allocation memoire"); for(i=0;i en pgm */ /*----------------------------------------------------------*/ void LoadImagePgm(char* name,float** mat,int length,int width) { int i,j,k; unsigned char var; char buff[NBCHAR]; char stringTmp1[NBCHAR],stringTmp2[NBCHAR],stringTmp3[NBCHAR]; int ta1,ta2,ta3; FILE *fic; /*-----nom du fichier pgm-----*/ strcpy(buff,name); strcat(buff,".pgm"); printf("---> Ouverture de %s",buff); /*----ouverture du fichier----*/ fic=fopen(buff,"r"); if (fic==NULL) { printf("\n- Grave erreur a l'ouverture de %s.pgm -\n",name); exit(-1); } /*--recuperation de l'entete--*/ fgets(stringTmp1,100,fic); fgets(stringTmp2,100,fic); fscanf(fic,"%d %d",&ta1,&ta2); fscanf(fic,"%d\n",&ta3); /*--affichage de l'entete--*/ printf("\n\n--Entete--"); printf("\n----------"); printf("\n%s%s%d %d \n%d\n",stringTmp1,stringTmp2,ta1,ta2,ta3); /*--chargement dans la matrice--*/ for(i=0;i au format pgm */ /*----------------------------------------------------------*/ void SaveImagePgm(char* name,float** mat,int length,int width) { int i,j,k; char buff[NBCHAR]; FILE* fic; time_t tm; /*--extension--*/ strcpy(buff,name); strcat(buff,".pgm"); /*--ouverture fichier--*/ fic=fopen(buff,"w"); if (fic==NULL) { printf(" Probleme dans la sauvegarde de %s",buff); exit(-1); } printf("\n Sauvegarde de %s au format pgm\n",name); /*--sauvegarde de l'entete--*/ fprintf(fic,"P5"); fprintf(fic,"\n# IMG Module, %s",ctime(&tm)); fprintf(fic,"%d %d",width,length); fprintf(fic,"\n255\n"); /*--enregistrement--*/ for(i=0;i