A texture atlas packer library/CLI tool.
I know there are a lot of these out there, but I didn't find one that did
everything I wanted it to:
I also wanted a project to learn Rust with, and making a command-line tool a perfect candidate.
Example usages: ```
out.bin
, out.txt
, and out4.png
tatlap sprite1.png sprite2.png sprite3.png
tatlap --out sprites data/*.png
tatlap --file listofsprites.txt
cat listofsprites.txt | tatlap --stdin
tatlap --atlas out newsprite.png
The `.txt` output file contains locations of the packed sprites.
For example:
4 459 638 45 37 69 53 192 192
```
4
- This represent the number of color channels this image has.459 638
- These are the x and y pixel coordinates where the sprite was packed into the resulting texture atlas45 37
- This is the dimensions of the sprite after the transparent borders were trimmed off67 53
- This is how many pixels from the left and top were trimmed off192 192
- The dimensions of the image before it was trimmedThe .bin
output file contains the same data as the .txt
output, but contains
the values in serialized in a binary file. The first value (bytes per pixel) is
a single byte, but the others are 16-bit unsigned integers (in little endian),
so each image takes 17 bytes.
How you use the .txt
and .bin
is up to you; I find the .bin
more useful
for loading the sprites. Here is an example of how to would load it in C:
``` C
FILE* fp = fopen("out.bin");
uint8t bpp;
fread(&bpp 1, 1, fp);
uint16t d[8];
fread(&xywh, 2, 8, fp); // Note that this won't work on bit-endian systems
// Extract the sprite based on d[0-4]
// Calculate where to draw the sprite centered on x
and y
// x - half uncropped width + cropped offset
int drawx = x - d[6]/2 + d[4];
int drawy = y - d[7]/2 + d[5];
```