X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=tools%2Fpngdump%2Ftiles.c;h=9421a06909f4d40eaf6240e09a94fa067526be26;hb=3ed6f84c7c0a45fc7813d1354a2ed38a750ff630;hp=bcf27e6e4b0db80b5b303c4d6650229e75b67438;hpb=c01146f8ecd395bfcdeb8af3b50f8a9ab2b87488;p=mdlife diff --git a/tools/pngdump/tiles.c b/tools/pngdump/tiles.c index bcf27e6..9421a06 100644 --- a/tools/pngdump/tiles.c +++ b/tools/pngdump/tiles.c @@ -1,12 +1,15 @@ #include #include #include +#include #include "tiles.h" #include "image.h" +static int matchtile(struct image *img, int toffs, int th); + int img2tiles(struct tilemap *tmap, struct image *img, int tw, int th, int dedup) { - int i, j, x, y, tx, ty, tileoffs, xtiles, ytiles, ntiles; + int i, j, x, y, tx, ty, tileoffs, xtiles, ytiles, ntiles, tileno, tid; struct image orig; unsigned int pix; @@ -34,6 +37,7 @@ int img2tiles(struct tilemap *tmap, struct image *img, int tw, int th, int dedup } } + tileno = 0; tileoffs = 0; y = 0; for(i=0; imap[tileno++] = tileoffs / th; + } + tileoffs += th; /* destination Y offset, inc by th for every tile */ + } else { + if(tmap) { + tmap->map[tileno++] = tid; + } + } + } else { + tileoffs += th; /* destination Y offset, inc by th for every tile */ + } x += tw; } y += th; } + if(dedup) { + putchar('\n'); + img->height = tileoffs; + } + free(orig.pixels); return 0; } -int dump_tilemap(struct tilemap *tmap, const char *fname) +static int matchtile(struct image *img, int toffs, int th) { + int i, tilesz; + int ntiles = toffs / th; + unsigned char *pa, *pb; + + tilesz = img->pitch * th; + pa = (unsigned char*)img->pixels; + pb = (unsigned char*)img->pixels + toffs * img->pitch; + + for(i=0; iwidth * tmap->height; + uint16_t id; + + if(sz <= 0) return -1; + + if(!(fp = fopen(fname, "wb"))) { + fprintf(stderr, "dump_tilemap: failed to open %s for writing\n", fname); + return -1; + } + + for(i=0; imap[i] << 8) | (tmap->map[i] >> 8); + fwrite(&id, sizeof id, 1, fp); + } + + fclose(fp); + return 0; +}