warzone2100/tools/map/map2png.cpp

70 lines
1.1 KiB
C++
Raw Normal View History

// tool "framework"
#include "maplib.h"
#include "pngsave.h"
#include "mapload.h"
int main(int argc, char **argv)
{
2011-07-27 16:35:41 -07:00
char *filename, *p_filename;
char *base, tmpFile[PATH_MAX];
GAMEMAP *map;
2011-07-27 16:35:41 -07:00
if (argc != 2)
{
printf("Usage: %s <map>\n", argv[0]);
return -1;
}
2011-07-27 16:35:41 -07:00
physfs_init(argv[0]);
filename = physfs_addmappath(argv[1]);
p_filename = strrchr(filename, '/');
if (p_filename)
{
p_filename++;
base = strdup(p_filename);
}
else
{
base = strdup(filename);
}
if (!PHYSFS_exists(base))
{
PHYSFS_mkdir(base);
}
map = mapLoad(filename);
2011-07-27 16:35:41 -07:00
free(filename);
if (!map)
{
2011-07-27 16:35:41 -07:00
return EXIT_FAILURE;
}
uint x, y;
uint8_t *pixels = (uint8_t *)malloc(map->width * map->height);
2011-07-27 16:35:41 -07:00
for (x = 0; x < map->width; x++)
{
for (y = 0; y < map->height; y++)
{
MAPTILE *psTile = mapTile(map, x, y);
int pixpos = y * map->width + x;
2011-07-27 16:35:41 -07:00
pixels[pixpos++] = psTile->height;
}
}
2011-07-27 16:35:41 -07:00
strcpy(tmpFile, base);
strcat(tmpFile, "/height.png");
savePngI8(tmpFile, pixels, map->width, map->height);
free(pixels);
2011-07-27 16:35:41 -07:00
mapFree(map);
2011-07-27 16:35:41 -07:00
physfs_shutdown();
return 0;
}