int ppm_read(int *p_w, int *p_h, unsigned char
**p_rgb, char *file_name) {
FILE
*fp; char line[80]; int rgb_size; int max;
fp =
fopen(file_name, "rb");
if (fp == NULL) {
printf(”Error reading %s",file_name); return 0;}
fgets(line,80,fp);
if(strcmp(line,"P6\n")) { printf(”Wrong signature\n");
return 0; }
while (fscanf( fp,
" %d ", p_w ) != 1) fgets(line, 80, fp);
while
(fscanf( fp, " %d ", p_h ) != 1) fgets(line, 80, fp);
while
(fscanf( fp, " %d", &max ) != 1) fgets(line, 80, fp);
fgetc(fp);
rgb_size=3*(*p_w)*(*p_h);
(*p_rgb) = (unsigned char *) calloc(rgb_size, 1);
if
((*p_rgb) != NULL)
fread( (*p_rgb), rgb_size, 1, fp );
fclose(fp);
return
1;
}