47 int map_load_occ(map_t *map,
const char *filename,
double scale,
int negate)
53 int width, height, depth;
57 file = fopen(filename,
"r");
60 fprintf(stderr,
"%s: %s\n", strerror(errno), filename);
66 if ((fscanf(file,
"%10s \n", magic) != 1) || (strcmp(magic,
"P5") != 0))
68 fprintf(stderr,
"incorrect image format; must be PGM/binary");
73 while ((ch = fgetc(file)) ==
'#')
74 while (fgetc(file) !=
'\n');
78 if(fscanf(file,
" %d %d \n %d \n", &width, &height, &depth) != 3)
80 fprintf(stderr,
"Failed ot read image dimensions");
85 if (map->cells == NULL)
90 map->cells = calloc(width * height,
sizeof(map->cells[0]));
94 if (width != map->size_x || height != map->size_y)
102 for (j = height - 1; j >= 0; j--)
104 for (i = 0; i < width; i++)
113 else if (ch > 3 * depth / 4)
124 else if (ch > 3 * depth / 4)
130 if (!MAP_VALID(map, i, j))
132 cell = map->cells + MAP_INDEX(map, i, j);
133 cell->occ_state = occ;