aseprite

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: ISC Imports: 11 Imported by: 2

README

Aseprite image loader

GoDoc Go Report Card Coverage Status

Overview

Package aseprite implements a decoder for Aseprite sprite files (.ase and .aseprite files).

Layers are flattened, blending modes are applied, and frames are arranged on a single texture atlas. Invisible and reference layers are ignored.

Limitations:

  • Tilemaps are not supported.
  • External files are not supported.
  • Old aseprite format is not supported.
  • Color profiles are ignored.

Install

go get -u github.com/askeladdk/aseprite

Quickstart

Use image.Decode to decode an aseprite sprite file to an image.Image:

import (
    _ "github.com/askeladdk/aseprite"
)

img, imgformat, err := image.Decode("test.aseprite")

This is enough to decode single frame images. Multiple frames are arranged as a texture atlas in a single image. Type cast the image to aseprite.Aseprite to access the frame data, as well as other meta data extracted from the sprite file:

if imgformat == "aseprite" {
    sprite := img.(*aseprite.Aseprite)
    for _, frame := range sprite.Frames {
        // etc ...
    }
}

Alternatively, use the Read function to directly decode an image to aseprite.Aseprite:

sprite, err := aseprite.Read(f)

Read the documentation for more information about what meta data is extracted.

License

Package aseprite is released under the terms of the ISC license.

The internal blend package is released by Guillermo Estrada under the terms of the MIT license: http://github.com/phrozen/blend.

Documentation

Overview

Package aseprite implements a decoder for Aseprite sprite files.

Layers are flattened, blending modes are applied, and frames are arranged on a single texture atlas. Invisible and reference layers are ignored. Tilesets and external files are not supported.

Aseprite file format spec: https://github.com/aseprite/aseprite/blob/main/docs/ase-file-specs.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(r io.Reader) (image.Image, error)

Decode decodes an Aseprite image from r and returns it as an image.Image.

func DecodeConfig

func DecodeConfig(r io.Reader) (image.Config, error)

DecodeConfig returns the color model and dimensions of an Aseprite image without decoding the entire image.

Types

type Aseprite

type Aseprite struct {
	// Image contains all frame images in a single image.
	// Frame bounds specify where the frame images are located.
	image.Image

	// Frames lists all frames that make up the sprite.
	Frames []Frame

	// Tags lists all animation tags.
	Tags []Tag

	// Slices lists all slices.
	Slices []Slice

	// LayerData lists the user data of all visible layers.
	LayerData [][]byte
}

Aseprite holds the results of a parsed Aseprite image file.

func Read added in v0.0.3

func Read(r io.Reader) (*Aseprite, error)

Read decodes an Aseprite image from r.

type Frame

type Frame struct {
	// Bounds is the image bounds of the frame in the sprite's atlas.
	Bounds image.Rectangle

	// Duration is the time in seconds that the frame should be displayed for
	// in a tag animation loop.
	Duration time.Duration

	// Data lists all optional user data set in the cels that make up the frame.
	// The data of invisible and reference layers is not included.
	Data [][]byte
}

Frame represents a single frame in the sprite.

type LoopDirection

type LoopDirection uint8

LoopDirection enumerates all loop animation directions.

const (
	Forward LoopDirection = iota
	Reverse
	PingPong
	PingPongReverse
)

type Slice

type Slice struct {
	// Bounds is the bounds of the image in the texture atlas.
	Bounds image.Rectangle

	// Center is the 9-slices center relative to Bounds.
	Center image.Rectangle

	// Pivot is the pivot point relative to Bounds.
	Pivot image.Point

	// Name is the name of the slice. Can be duplicate.
	Name string

	// Data is optional user data.
	Data []byte

	// Color is the slice color.
	Color color.Color
}

Slice represents a single slice.

type Tag

type Tag struct {
	// Name is the name of the tag. Can be duplicate.
	Name string

	// Lo is the first frame in the animation.
	Lo uint16

	// Hi is the last frame in the animation.
	Hi uint16

	// Repeat specifies how many times to repeat the animation.
	Repeat uint16

	// LoopDirection is the looping direction of the animation.
	LoopDirection LoopDirection
}

Tag is an animation tag.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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