53 int width, height, depth;
57 file = fopen(filename,
"r");
60 fprintf(stderr,
"%s: %s\n", strerror(errno), filename);
66 if ((fscanf(file,
"%2s \n", magic) != 1) || (strcmp(magic,
"P5") != 0))
68 fprintf(stderr,
"incorrect image format; must be PGM/binary");
74 while ((ch = fgetc(file)) ==
'#')
75 while (fgetc(file) !=
'\n');
79 if(fscanf(file,
" %d %d \n %d \n", &width, &height, &depth) != 3)
81 fprintf(stderr,
"Failed ot read image dimensions");
86 if (map->
cells == NULL)
91 map->
cells = calloc(width * height,
sizeof(map->
cells[0]));
103 for (j = height - 1; j >= 0; j--)
105 for (i = 0; i < width; i++)
114 else if (ch > 3 * depth / 4)
125 else if (ch > 3 * depth / 4)