1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| image_t *charger_image_pgm(char *nom_fichier){
FILE *fic;
image_t *img;
unsigned long nx,ny,nb_ng;
fic=fopen(nom_fichier,"r");
if(fic == NULL){
fprintf(stderr, "impossible d'ouvrir le fichier" );
return 0;
}
fscanf(fic,"P5\n");
fscanf(fic, "%d %d\n", &nx, &ny);
fscanf(fic, "%d\n", &nb_ng);
printf("largeur :%d\n", nx);
printf("longueur :%d\n", ny);
printf("hauteur :%d\n", nb_ng);
img = creer_image();
img->nx = nx;
img->ny = ny;
img->nb_ng = nb_ng;
img->buff = malloc(img->nx *i mg->ny * sizeof(unsigned char));
fread(img->buff, img->nx, img->ny * sizeof(unsigned char),fic);
fclose(fic);
return img;
} |