47int 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,
"%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");
87 if (map->cells == NULL)
92 map->cells = calloc((
size_t)width * height,
sizeof(map->cells[0]));
96 if (width != map->size_x || height != map->size_y)
105 for (j = height - 1; j >= 0; j--)
107 for (i = 0; i < width; i++)
116 else if (ch > 3 * depth / 4)
127 else if (ch > 3 * depth / 4)
133 if (!MAP_VALID(map, i, j))
135 cell = map->cells + MAP_INDEX(map, i, j);
136 cell->occ_state = occ;