Skip to content

aforren1/patlas

Repository files navigation

image Build

A simple, runtime-dependency-free texture atlas packer.

Basic usage:

from patlas import AtlasPacker, load
from glob import glob

ap = AtlasPacker(side=2048, pad=2)
ap.pack(glob('images/*.png')) # list of images
ap.pack(['images/image.jpg']) # can call multiple times (packing quality may suffer)

ap.atlas # memoryview of RGBA texture
ap.metadata # dictionary of image locations and image format

ap.save('atlas') # serialize as custom .patlas file

atlas, metadata = load('atlas.patlas')

See demo.py for example usage with ModernGL.

Features/limitations:

  • Uses stb_image, stb_rect_pack, and stb_dxt from stb
    • Can import any image format stb_image can (see here)
  • Only square RGBA textures (currently)
  • Optional DXT5/BC3(?) compression
    • Pass texture_format=TextureFormat.DXT5 to AtlasPacker initialization.
  • Optional OpenMP support (disabled by default to reduce wheel size) can substantially reduce runtime. To enable, build from source with OMP=1 set in the environment, e.g. OMP=1 pip install patlas --no-binary patlas
    • On Windows, should "just work"?
    • MacOS may need extra packages, e.g. libomp from brew
    • Linux may need extra packages, e.g. libomp-dev on Ubuntu
  • Save to a custom .patlas file
    • Uses qoi image format + zlib for fast and small encoding/decoding
    • See the save method of AtlasPacker for gory details
  • Includes a command-line utility (see patlas --help for details)
  • Requires Cython at build time (but source distribution should have pre-generated .c files)