Topic: extract pngs from existing maps.
Ever wanted to edit an image from an existing map? To enhance it? To import it in another map?
Now because I needed this, I wanted to improve for example the foot2.map but didn't had the image, its kinda nasty:
I've written a tool you can extract pngs from existing maps.
Create this file in src/tools/map_extract.cpp:
/* dcopyright (c) 2007 magnus auvinen, see licence.txt for more info */
/* +stuff added by axel, open domain*/
/**
* This application will extract embedded pngs from new map files.
*/
extern "C" {
#include <engine/e_datafile.h>
#include <stdio.h>
#include <stdlib.h>
#include "game/g_mapitems.h"
#include "engine/external/pnglite/pnglite.h"
}
int main(int argc, char **argv)
{
if(argc != 2) {
printf("wrong arguments, there has to be one and only one and this is the mapfile to extract the images from.\n");
return -1;
}
DATAFILE *df = datafile_load(argv[1]);
if(!df) {
printf("cannot read %s\n", argv[1]);
return -1;
}
printf("loading %s\n", argv[1]);
// check version
MAPITEM_VERSION *item = (MAPITEM_VERSION *)datafile_find_item(df, MAPITEMTYPE_VERSION, 0);
if(!item) {
printf("cannot extract from old maps\n");
return -1;
}
png_init(0, 0);
// load images
int start, num;
datafile_get_type(df, MAPITEMTYPE_IMAGE, &start, &num);
for(int i = 0; i < num; i++)
{
MAPITEM_IMAGE *item = (MAPITEM_IMAGE *)datafile_get_item(df, start+i, 0, 0);
char *name = (char *)datafile_get_data(df, item->image_name);
if(item->external) {
printf("skipping external %s\n", name);
} else {
printf("writing %s.png\n", name);
void *data = datafile_get_data(df, item->image_data);
char buf[255];
snprintf(buf, sizeof(buf), "%s.png", name);
png_t png;
png_open_file_write(&png, buf);
png_set_data(&png, item->width, item->height, 8, PNG_TRUECOLOR_ALPHA, (unsigned char*) data);
png_close_file(&png);
}
}
datafile_unload(df);
return 0;
}
edit in default.bam where it reads:
...
for i,v in objs do
toolname = PathFilename(PathBase(v))
tools[i] = Link(settings, toolname, v, engine)
end
...
to
...
for i,v in objs do
toolname = PathFilename(PathBase(v))
tools[i] = Link(settings, toolname, v, engine, zlib, pnglite)
end
...
Compile like usual. Usage is straight forward, 1 argument that is the map, it will place the embedded pngs in the current directory you called it from.
I'm Linux only, so I cannot give you a windows executable.