1 (edited by catpaw 2008-07-04 10:16:14)

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.

2

Re: extract pngs from existing maps.

give me src i try to compile it wink

Remember me? Questions? Just leave a message, I will respond within 72 hrs!

3

Re: extract pngs from existing maps.

Dani wrote:

give me src i try to compile it wink

Src is in first post smile

4

Re: extract pngs from existing maps.

catpaw wrote:
Dani wrote:

give me src i try to compile it wink

Src is in first post smile

nonono .. i hate patch files.. or something ... i mean the full src code..

Remember me? Questions? Just leave a message, I will respond within 72 hrs!

5

Re: extract pngs from existing maps.

This isn't a patch file, simply use e.g. notepad to create this one file in src/tools, and edit default.bam by hand.

6

Re: extract pngs from existing maps.

i know.. but its work for me xDD i try w8 a moment

Remember me? Questions? Just leave a message, I will respond within 72 hrs!

7

Re: extract pngs from existing maps.

XD if you want, i can send you the football.png

Antoine de Saint Exupéry: It seems that perfection is reached not when there is nothing left to add, but when there is nothing left to take away.
Besides -  I am the gfx guy!

8

Re: extract pngs from existing maps.

hmm i love bam xDDD look at this http://img124.imageshack.us/img124/9074/jehaaayx1.jpg

Remember me? Questions? Just leave a message, I will respond within 72 hrs!

9

Re: extract pngs from existing maps.

Landil wrote:

XD if you want, i can send you the football.png

smile I have it now already big_smile

10

Re: extract pngs from existing maps.

Dani wrote:

hmm i love bam xDDD look at this http://img124.imageshack.us/img124/9074/jehaaayx1.jpg

This doesn't look like my fault...

Could be that a C++ file is tried to be compiler by the classical C compiler.

11

Re: extract pngs from existing maps.

hmm.. very bad... but client compiling doesnt work... only server and so one.. -.-...

Remember me? Questions? Just leave a message, I will respond within 72 hrs!

12

Re: extract pngs from existing maps.

Dani wrote:

hmm.. very bad... but client compiling doesnt work... only server and so one.. -.-...

your missing some development library, i don't know.

13

Re: extract pngs from existing maps.

ive downloaded everything new.. bam tw source and and.. it wont work sad:(:(

Remember me? Questions? Just leave a message, I will respond within 72 hrs!

14

Re: extract pngs from existing maps.

Dani wrote:

ive downloaded everything new.. bam tw source and and.. it wont work sad:(:(

Try now, I changed default.bam the "client_settings" were actually not necessary, I believe.

15

Re: extract pngs from existing maps.

And what is wrong with patch files?

if($poster["intelligence"] == $intelligence["idiot"])
        deny_post($poster);

16

Re: extract pngs from existing maps.

Ugh... I think this function wasn't implemented because either of copyright issues or to prevent unfinished tilesets getting public available.. hmm

-1 hmm

bam: WARNING:'src/game/server/gamemodes/mod.cpp' comes from the future

17

Re: extract pngs from existing maps.

Yeah, things like this is not good, the art in a map belong to the map creator, and if he/she doesn't want to release it, it is illegal to extract it afaik. I recommend people not to use this, but instead to politely ask the map creator about the tileset.

Official Teeworlds map developer and community moderator
Administrator for the Teeworlds community Teesites

18 (edited by catpaw 2008-07-05 15:08:34)

Re: extract pngs from existing maps.

Chi11y wrote:

Yeah, things like this is not good, the art in a map belong to the map creator, and if he/she doesn't want to release it, it is illegal to extract it afaik. I recommend people not to use this, but instead to politely ask the map creator about the tileset.

Extracting is not illegal, if it would be, running the teeworlds client would be illegal. Redistributing without consent would be.

But honestly, what do you think gives a better teeworlds repository. A group of editors who inspire each other, build on other maps to improve or a group of editors where each one screams mine! mine! mine! like greedy little squirrels.

Most often some map creator just forgets to upload the tileset itself. If anyone has a problem seeing his graphics used anywhere he should complain then. Not beforehand.

19 (edited by catpaw 2008-07-05 15:12:52)

Re: extract pngs from existing maps.

shmafoozius wrote:

Ugh... I think this function wasn't implemented because either of copyright issues or to prevent unfinished tilesets getting public available.. hmm

-1 hmm

Software wanting to control people is bad. Software should enable you, not the software creator executing control on users.

People should at most control people. So when somebody decided an "unfinshed" tileset is enough finshed for them it is.

If you consider this tool not to be good, just don't use it.

20

Re: extract pngs from existing maps.

Roanoke wrote:

And what is wrong with patch files?

I was just too lazy, because my sourcebase contained more modifications than just this tool.
+ the todays windows generations are not capable of using simple commandline tools anyway hmm

21

Re: extract pngs from existing maps.

I have to agree with chi11y on this matter...

No matter how much the information (tilesets in this case) wants to be free, they aren't as the law looks today.
Asking the creator would be the only solution...

Used to be very active waay back

22

Re: extract pngs from existing maps.

FireArrow wrote:

I have to agree with chi11y on this matter...

No matter how much the information (tilesets in this case) wants to be free, they aren't as the law looks today.
Asking the creator would be the only solution...

sue me! or other map creators

People were reusing already tilesets eitherway, by loading the old map into the editor removing all the contents and reusing the tilesets.

I find this sudden "worries" to be redicolous, especially for people wanting to play a free game. Next week pay for teeworlds because we are all copyright evangelists hmm

23

Re: extract pngs from existing maps.

One use I wrote this tool for, was to extract a tilesite, load it as background into inkscape and design my own tileset inspired of the original one.

This is a legal use, no matter how u turn it.

Its not the knife thats evil, its what some people do with it while others use it to cut just bread.

24

Re: extract pngs from existing maps.

hehe ... you should rename your nick to copycat ^^

Antoine de Saint Exupéry: It seems that perfection is reached not when there is nothing left to add, but when there is nothing left to take away.
Besides -  I am the gfx guy!

25

Re: extract pngs from existing maps.

Landil wrote:

hehe ... you should rename your nick to copycat ^^

Except my contribution 'til now were highly original smile