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
Structs§
- Aseprite
File - An Aseprite
.ase/.asepritefile. - 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).
- External
File - A reference to an external file.
- Frame
- A single animation frame.
- Grid
Info - Grid overlay settings.
- Group
Ref - Handle to a group layer. Obtained from
AsepriteFile::add_grouporAsepriteFile::group_ref. - Layer
- A layer in the file (normal, group, or tilemap).
- Layer
Options - Options for creating a new layer.
- Layer
Ref - Handle to a non-group layer. Obtained from
AsepriteFile::add_layerorAsepriteFile::layer_ref. - Legacy
Mask - A legacy mask chunk (deprecated in modern Aseprite, preserved for round-trip fidelity).
- Nine
Patch - 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. - Properties
Map - A named map of typed properties within user data.
- Slice
- A named rectangular region, optionally with nine-patch and pivot data.
- Slice
Key - A slice’s bounds at a specific frame.
- Tag
- An animation tag spanning a range of frames.
- Tileset
- A tileset definition.
- Tileset
Flags - Bitflags for tileset properties.
- User
Data - User-defined metadata attached to layers, cels, tags, slices, or the sprite itself.
Enums§
- Aseprite
Error - Errors that can occur when reading or writing Aseprite files.
- Blend
Mode - Layer blend mode, matching Aseprite’s blend mode list.
- CelKind
- The type and data of a cel.
- Color
Mode - The color depth mode of an Aseprite file.
- Color
Profile - Color profile embedded in the file.
- External
File Type - The type of an external file reference.
- Layer
Kind - The type of a layer.
- Loop
Direction - Animation loop direction for tags.
- Property
Value - A typed value within a properties map.
- Tileset
Data - The pixel data source for a tileset.