File: map2png.cpp

package info (click to toggle)
warzone2100 4.6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 660,320 kB
  • sloc: cpp: 676,209; ansic: 391,201; javascript: 78,238; python: 16,632; php: 4,294; sh: 4,094; makefile: 2,629; lisp: 1,492; cs: 489; xml: 404; perl: 224; ruby: 156; java: 89
file content (69 lines) | stat: -rw-r--r-- 1,081 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// tool "framework"
#include "maplib.h"
#include "pngsave.h"
#include "mapload.h"

int main(int argc, char **argv)
{
	char *filename, *p_filename;
	char *base, tmpFile[PATH_MAX];

	GAMEMAP *map;
	
	if (argc != 2)
	{
		printf("Usage: %s <map>\n", argv[0]);
		return -1;
	}

	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);
	free(filename);
	
	if (!map)
	{
		return EXIT_FAILURE;
	}
	
	uint x, y;
	uint8_t *pixels = (uint8_t *)malloc(map->width * map->height);

	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;

			pixels[pixpos++] = psTile->height;
		}
	}

	strcpy(tmpFile, base);
	strcat(tmpFile, "/height.png");
	
	savePngI8(tmpFile, pixels, map->width, map->height);
	free(pixels);

	mapFree(map);

	physfs_shutdown();

	return 0;
}