Skip to main content

Crate aseprite

Crate aseprite 

Source
Expand description

Read and write Aseprite .ase/.aseprite files.

This crate provides full support for the Aseprite binary file format, including reading, writing, and byte-perfect round-trip preservation. All color modes (RGBA, Grayscale, Indexed), layer types (normal, group, tilemap), animation tags, slices, user data with typed properties, and tilesets are supported.

§Reading a file

use aseprite::AsepriteFile;

let data = std::fs::read("sprite.aseprite").unwrap();
let file = AsepriteFile::from_reader(&data[..]).unwrap();

println!("{}x{}, {} frames", file.width(), file.height(), file.frames().len());
for layer in file.layers() {
    println!("  layer: {}", layer.name);
}

§Creating a file from scratch

use aseprite::*;

let mut file = AsepriteFile::new(16, 16, ColorMode::Rgba);
let layer = file.add_layer("Background");
let frame = file.add_frame(100);
let pixels = Pixels::new(vec![0u8; 16 * 16 * 4], 16, 16, ColorMode::Rgba).unwrap();
file.set_cel(layer, frame, pixels, 0, 0).unwrap();

let mut output = Vec::new();
file.write_to(&mut output).unwrap();

§Feature flags

FeatureDescription
imageEnables conversions between Pixels and image::RgbaImage
tiny-skiaEnables conversions between Pixels and tiny_skia::Pixmap (handles premultiplied alpha)

Structs§

AsepriteFile
An Aseprite .ase/.aseprite file.
Cel
A cel (the content of one layer in one frame).
CelExtra
Extra precision bounds for a cel.
CelOptions
Options for creating a cel with non-default opacity, position, or z-index.
Color
An RGBA color with an optional name (used in palettes).
ExternalFile
A reference to an external file.
Frame
A single animation frame.
GridInfo
Grid overlay settings.
GroupRef
Handle to a group layer. Obtained from AsepriteFile::add_group or AsepriteFile::group_ref.
Layer
A layer in the file (normal, group, or tilemap).
LayerOptions
Options for creating a new layer.
LayerRef
Handle to a non-group layer. Obtained from AsepriteFile::add_layer or AsepriteFile::layer_ref.
LegacyMask
A legacy mask chunk (deprecated in modern Aseprite, preserved for round-trip fidelity).
NinePatch
Nine-patch (9-slice) center region within a slice.
Pixels
Raw pixel data buffer. Format depends on the file’s ColorMode: RGBA = 4 bytes/pixel, Grayscale = 2 bytes/pixel, Indexed = 1 byte/pixel.
PropertiesMap
A named map of typed properties within user data.
Slice
A named rectangular region, optionally with nine-patch and pivot data.
SliceKey
A slice’s bounds at a specific frame.
Tag
An animation tag spanning a range of frames.
Tileset
A tileset definition.
TilesetFlags
Bitflags for tileset properties.
UserData
User-defined metadata attached to layers, cels, tags, slices, or the sprite itself.

Enums§

AsepriteError
Errors that can occur when reading or writing Aseprite files.
BlendMode
Layer blend mode, matching Aseprite’s blend mode list.
CelKind
The type and data of a cel.
ColorMode
The color depth mode of an Aseprite file.
ColorProfile
Color profile embedded in the file.
ExternalFileType
The type of an external file reference.
LayerKind
The type of a layer.
LoopDirection
Animation loop direction for tags.
PropertyValue
A typed value within a properties map.
TilesetData
The pixel data source for a tileset.