aseprite

package module
v1.7.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 14 Imported by: 0

README

GoDoc Go Report Card Coverage Status

aseprite

Aseprite file parser/decoder in Go

Layers are not flattened, but this can be done with external Go image processing packages. The opacity and blending mode information of each layer and Cel is available. See quick example.

Chunk Types

Available chunks.

  • Layer Chunk (0x2004)
  • Cel Chunk (0x2005)
  • Tileset Chunk (0x2023)
  • Tags Chunk (0x2018)
  • User Data Chunk (0x2020)
  • Slice Chunk (0x2022)
  • Old palette chunk (0x0004)
  • Old palette chunk (0x0011)
  • Palette Chunk (0x2019)
  • Color Profile Chunk (0x2007)

The following chunks are not currently supported in this package.

  • Cel Extra Chunk (0x2006)
  • External Files Chunk (0x2008)
  • Mask Chunk (0x2016) DEPRECATED
  • Path Chunk (0x2017)

Documentation

Overview

Aseprite file parser/decoder

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ase added in v1.1.0

type Ase struct {
	ColorDepth ColorDepth

	// Canvas size (width and height)
	Size image.Point

	// Pixel aspect ratio (width:height)
	PixelRatio image.Point

	// Timeline frame durations
	Durations []time.Duration

	// Layers. Layer indices increase from bottom to top in Aseprite UI.
	Layers []*Layer

	// HasLayersUUID indicates whether each layer in the file contains a Universally Unique Identifier.
	HasLayersUUID bool

	// Aseprite slices. https://www.aseprite.org/api/slice#slice
	Slices []Slice

	// Timeline animation tags
	Tags []*Tag

	// Tilesets used in Tilemap layers
	Tilesets []*Tileset

	// Palette of file
	Palette color.Palette

	// Palette index for used as transparent color in each layer. (only for indexed images)
	TransparentIndex uint8

	ColorProfile ColorProfile
}

func Read

func Read(filepath string, onlyVisibleLayers bool) (a Ase, err error)

Read opens and parses an Aseprite file from the given filepath, optionally filtering to visible layers only

func ReadFs added in v1.1.0

func ReadFs(f fs.FS, filepath string, onlyVisibleLayers bool) (a Ase, err error)

ReadFs opens and parses an Aseprite file from a virtual filesystem, optionally filtering to visible layers only

func (*Ase) BuildTilemapImages added in v1.6.0

func (a *Ase) BuildTilemapImages()

BuildTilemapImages performs the final rasterization for all cels in tilemap layers. It iterates through the tile grid, resolves tile IDs via the associated tileset, and assembles the final image composite by applying bitmask flips (X/Y/D).

func (*Ase) GetLayerByName added in v1.5.0

func (a *Ase) GetLayerByName(name string) *Layer

GetLayerByName returns the first layer with the given name. Returns nil if no layer is found with that name.

func (*Ase) GetLayerByUUID added in v1.7.0

func (a *Ase) GetLayerByUUID(id uuid.UUID) *Layer

GetLayerByUUID returns the layer with the given UUID. Returns nil if no layer is found with that UUID.

func (*Ase) GetTagByName added in v1.7.8

func (a *Ase) GetTagByName(tagName string) *Tag

GetTagByName returns the first Tag with the given name. Returns nil if no layer is found with that name.

type BlendMode added in v1.1.0

type BlendMode uint16
const (
	Normal BlendMode = iota
	Multiply
	Screen
	Overlay
	Darken
	Lighten
	ColorDodge
	ColorBurn
	HardLight
	SoftLight
	Difference
	Exclusion
	Hue
	Saturation
	Color
	Luminosity
	Addition
	Subtract
	Divide
)

func (BlendMode) String added in v1.4.0

func (i BlendMode) String() string

type Cel added in v1.1.0

type Cel struct {

	// LayerIndex is the raw index of the layer this cel belongs to.
	LayerIndex int

	// ZIndex defines the display order override.
	// 0 = default, +N = show N layers forward, -N = show N layers back.
	ZIndex int

	// Cel position
	Pos image.Point

	// Cel Width and Cel Height. Pixel unit for Image layers.
	//
	// Number of tiles for Tilemap layers.
	Size image.Point

	// Cel image
	Image image.Image

	// Cel opacity. (0-255)
	Opacity uint8

	// Tiles contains the ID and flip flags for each tile in a tilemap layer.
	// This is nil for regular image layers.
	Tiles []Tile

	// Type specifies if this cel is a Raw Image, Linked Cel, Compressed Image, or Tilemap.
	Type CelType

	// UserData contains extra information like text and color associated with the cel.
	UserData
	// contains filtered or unexported fields
}

A cel is an image in a specific xy-coordinate, and a specific layer/frame combination.

func (*Cel) BuildTilemapImage added in v1.5.0

func (c *Cel) BuildTilemapImage()

BuildTilemapImage rasterizes the tilemap cel into an image. It resolves each tile index against the associated tileset, applies bitmask transformations for flips (X/Y/D), and performs a draw-call to assemble the final pixel buffer into the Cel's Image field.

func (*Cel) GetLayer added in v1.6.0

func (c *Cel) GetLayer() *Layer

GetLayer returns layer this cel belongs to

type CelType added in v1.5.0

type CelType uint16
const (
	RawUncompressed CelType = iota
	LinkedCel
	CompressedImage
	CompressedTilemap
)

func (CelType) String added in v1.5.0

func (i CelType) String() string

type ColorDepth added in v1.4.0

type ColorDepth uint16
const (
	NRGBA ColorDepth = 32
	// Grayscale mode is parsed as image.NRGBA images.
	Grayscale ColorDepth = 16
	Indexed   ColorDepth = 8
)

func (ColorDepth) String added in v1.4.0

func (i ColorDepth) String() string

type ColorProfile added in v1.7.0

type ColorProfile struct {
	Type  uint16  // 0: No color profile, 1: Use sRGB, 2: Use embedded ICC profile
	Flags uint16  // Bit 1: Use special fixed gamma
	Gamma float64 // Fixed gamma value converted from 16.16 fixed-point
	ICC   []byte  // Embedded ICC profile data (only populated if Type == 2)
}

type FlipBitMask added in v1.5.0

type FlipBitMask uint8
const (
	//Bitmask for X flip
	FlipX FlipBitMask = 1 << iota
	// Bitmask for Y flip
	FlipY
	// Bitmask for diagonal flip (swap X/Y axis)
	FlipD
)

func (FlipBitMask) IsFlipD added in v1.5.0

func (f FlipBitMask) IsFlipD() bool

is diagonal flip (swap X/Y axis)

func (FlipBitMask) IsFlipX added in v1.5.0

func (f FlipBitMask) IsFlipX() bool

is Y flip

func (FlipBitMask) IsFlipY added in v1.5.0

func (f FlipBitMask) IsFlipY() bool

is X flip

func (FlipBitMask) String added in v1.5.0

func (i FlipBitMask) String() string

type Layer added in v1.1.0

type Layer struct {

	// Layer name.
	Name string

	// Layer's universally unique identifier.
	//
	// This field is uuid.Nil (all zeros) if Ase.HasLayersUUID is false.
	UUID uuid.UUID

	// Layer type
	Type LayerType

	// Layer flags
	Flags uint16

	// Blending mode of this layer.
	BlendMode BlendMode

	// Layer opacity. (0-255)
	Opacity uint8

	// Index matches the frame number
	Cels []*Cel

	// The child level is used to show the relationship of this layer with the last one read.
	//
	// https://github.com/aseprite/aseprite/blob/main/docs/ase-file-specs.md#note1
	ChildLevel uint16

	// Index for Ase.Tilesets[]
	TilesetIndex uint32

	UserData
	// contains filtered or unexported fields
}

func (*Layer) Cel added in v1.5.0

func (l *Layer) Cel(frame int) *Cel

Cel returns the cel at the specified frame.

func (*Layer) GetTileset added in v1.6.0

func (l *Layer) GetTileset() *Tileset

GetTileset returns the Tileset used by Tilemap layers. It returns nil if layer is not a tilemap.

func (*Layer) IsBackgroundLayer added in v1.7.5

func (l *Layer) IsBackgroundLayer() bool

func (*Layer) IsCelEmpty added in v1.5.0

func (l *Layer) IsCelEmpty(frame int) bool

IsCelEmpty checks if the frame has no content.

func (*Layer) IsGroupCollapsed added in v1.7.5

func (l *Layer) IsGroupCollapsed() bool

func (*Layer) IsGroupLayer added in v1.7.8

func (l *Layer) IsGroupLayer() bool

func (*Layer) IsLocked added in v1.7.5

func (l *Layer) IsLocked() bool

func (*Layer) IsReferenceLayer added in v1.7.5

func (l *Layer) IsReferenceLayer() bool

func (*Layer) IsTilemapLayer added in v1.7.8

func (l *Layer) IsTilemapLayer() bool

func (*Layer) IsVisible added in v1.7.5

func (l *Layer) IsVisible() bool

func (*Layer) PreferLinkedCels added in v1.7.5

func (l *Layer) PreferLinkedCels() bool

type LayerType added in v1.4.0

type LayerType uint16
const (
	Image LayerType = iota
	Group
	Tilemap
)

func (LayerType) String added in v1.4.0

func (i LayerType) String() string

type LoopDirection

type LoopDirection uint8
const (
	Forward LoopDirection = iota
	Reverse
	PingPong
	PingPongReverse
)

func (LoopDirection) String added in v1.4.0

func (i LoopDirection) String() string

type Slice

type Slice struct {
	UserData
	Name   string
	Frames []SliceFrame
}

type SliceFrame added in v1.1.0

type SliceFrame struct {

	// The bounds of the slice in the canvas
	Bounds image.Rectangle

	// 9-slices internal rectangle (relative to slice bounds)
	Rect9Slices image.Rectangle

	// A pivot to specify the central/base location. (relative to slice bounds)
	Pivot image.Point
}

type Tag

type Tag struct {
	Name string

	// Frame index where this tag starts.
	Start int

	// Frame index where this tag ends.
	End int

	// Play this animation section N times, 0 means infinite.
	Repeat uint16

	LoopDirection LoopDirection

	UserData
}

Tag Represents a tag in the timeline.

type Tile added in v1.5.0

type Tile struct {
	ID  uint32      // Tile index
	XYD FlipBitMask // XYD bitmask flags
}

type Tileset added in v1.5.0

type Tileset struct {

	// Tileset name
	Name string

	// Tileset ID
	ID uint32

	// Tile width/height
	TileSize image.Point

	NumTiles int

	// Tileset image containing all tiles vertically (Present if Flags & 2 is set)
	Image image.Image

	// Tileset flags
	//
	// 1 - Include link to external file
	//
	// 2 - Include tiles inside this file
	//
	// 4 - Tilemaps using this tileset use tile ID=0 as empty tile
	//     (this is the new format). In rare cases this bit is off,
	//     and the empty tile will be equal to 0xffffffff (used in
	//     internal versions of Aseprite)
	//
	// 8 - Aseprite will try to match modified tiles with their X
	//     flipped version automatically in Auto mode when using
	//     this tileset.
	//
	// 16 - Same for Y flips
	//
	// 32 - Same for D(iagonal) flips
	Flags uint32

	// External file data (Present if Flags & 1 is set)
	ExternalFileID    uint32
	ExternalTilesetID uint32

	// Index to show in the UI (usually 1)
	BaseIndex int
}

Tileset represents a set of tiles defined in the .ase file (Chunk 0x2023)

func (*Tileset) TileImage added in v1.5.0

func (ts *Tileset) TileImage(tileID uint32) image.Image

TileImage returns single tile sub-image

type UserData added in v1.1.0

type UserData struct {
	Color color.NRGBA
	Text  string
}

User-defined data

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL