Convert png sprite sheet to fpg

Started by pob, January 02, 2011, 05:45:20 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

pob

This will convert a png file of equal sized tiles (x times y) into an fpg.

Program pngtofpg

import "mod_say"
import "mod_map"
import "mod_string"

Process Main()
private
int png_file;
int file_id;
int map_id;
int xloop;
int yloop;
int png_width;
int png_height;
int num_tiles_x;
int num_tiles_y;
int tile_width;
int tile_height;
int gfx_depth;
string filename;
Begin

if (argc<4)
say("Usage:");
say("pngtofpg filename.png numtiles_x numtiles_y");
else
filename=argv[1];
num_tiles_x=atoi(argv[2]);
num_tiles_y=atoi(argv[3]);

png_file=png_load(filename);
png_width=graphic_info(0,png_file,G_WIDTH);
png_height=graphic_info(0,png_file,G_HEIGHT);
gfx_depth=graphic_info(0,png_file,G_DEPTH);
tile_width=png_width/num_tiles_x;
tile_height=png_height/num_tiles_y;

say("Extracting "+itoa(num_tiles_x)+" x "+itoa(num_tiles_y)+" tiles.");
say("Tiles are "+itoa(tile_width)+" x "+itoa(tile_height)+" pixels.");
say("Graphics depth is "+itoa(gfx_depth)+" bit.");

map_id=map_new(tile_width,tile_height,gfx_depth);
file_id=fpg_new();
for(yloop=0;yloop<num_tiles_y;yloop++)
for(xloop=0;xloop<num_tiles_x;xloop++)
map_block_copy(0,map_id,0,0,png_file,xloop*tile_width,yloop*tile_height,tile_width,tile_height,0);
fpg_add(file_id,yloop*num_tiles_x+xloop+1,0,map_id);
end //for xloop
end //for yloop
fpg_save(file_id,filename+".fpg");
end //if
End

SplinterGU

thanks... maybe the new fonts functions can be used for this... maybe with a minimal modification...
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

Sslaxx

#2
Pardon me for dredging up this old topic, but the code here is broken (due to the forums mangling it maybe?).

http://sslaxx.twu.net/Png2Fpg.prg is what it should be - I think. It compiles and runs, at least. Not tested what it produces, yet.

OK, tested it and it does not work as expected. Sprite 1 seems to be OK, but other sprites appear to be corrupted.
Stuart "Sslaxx" Moore.