X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=tools%2Fpngdump%2Ftiles.c;h=9421a06909f4d40eaf6240e09a94fa067526be26;hb=3ed6f84c7c0a45fc7813d1354a2ed38a750ff630;hp=92f404fe54dfebe4301006f2a099f06fe4ed830c;hpb=c16cb68351e8a31e2b1f91f7b46bf29e41df6a97;p=mdlife diff --git a/tools/pngdump/tiles.c b/tools/pngdump/tiles.c index 92f404f..9421a06 100644 --- a/tools/pngdump/tiles.c +++ b/tools/pngdump/tiles.c @@ -50,18 +50,30 @@ int img2tiles(struct tilemap *tmap, struct image *img, int tw, int th, int dedup } } - if(!dedup || (tid = matchtile(img, tileoffs, th)) == -1) { - tmap->map[tileno] = tileno; - tileoffs += th; /* destination Y offset, inc by th for every tile */ + if(dedup) { + if((tid = matchtile(img, tileoffs, th)) == -1) { + if(tmap) { + tmap->map[tileno++] = tileoffs / th; + } + tileoffs += th; /* destination Y offset, inc by th for every tile */ + } else { + if(tmap) { + tmap->map[tileno++] = tid; + } + } } else { - tmap->map[tileno] = tid; + tileoffs += th; /* destination Y offset, inc by th for every tile */ } - tileno++; x += tw; } y += th; } + if(dedup) { + putchar('\n'); + img->height = tileoffs; + } + free(orig.pixels); return 0; } @@ -74,7 +86,7 @@ static int matchtile(struct image *img, int toffs, int th) tilesz = img->pitch * th; pa = (unsigned char*)img->pixels; - pb = (unsigned char*)img->pixels + toffs * tilesz; + pb = (unsigned char*)img->pixels + toffs * img->pitch; for(i=0; i