asefile

package module
v0.0.0-...-57bf0b8 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2024 License: BSD-3-Clause Imports: 7 Imported by: 3

README

Welcome to asefile

Asefile is a library for loading the aseprite file format. Included is an example of how to use the library, and then render a frame from aseprite using ebiten.

  • Not all features have been tested yet - eg encoding back into a file
  • Files where the image is encoded in different ways eg, raw pixel data as opposed to zlib compressed
  • Etc

Loading and rendering a frame

The below code is a brief example of how you can load and render a frame to an ebiten image

var aseFile asefile.AsepriteFile
if err := aseFile.DecodeFile("example/Chica.aseprite"); err != nil {
    log.Fatal(err)
}
g.aseImg = ebi.NewImage(int(aseFile.Header.WidthInPixels), int(aseFile.Header.HeightInPixels))
for _, cel := range aseFile.Frames[0].Cels {
    dat := cel.RawCelData
    w, h := cel.WidthInPix, cel.HeightInPix
    offset := 0
    for y := 0; y < int(h); y += 1 {
        for x := 0; x < int(w); x, offset = x+1, offset+4 {
            col := color.RGBA{dat[offset], dat[offset+1], dat[offset+2], dat[offset+3]}
            g.aseImg.Set(int(cel.X)+x, int(cel.Y)+y, col)
        }
    }
}

Run the example

If you clone the repository then go run example/main.go

result

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeAseString

func DecodeAseString(r io.Reader) string

func EncodeAseString

func EncodeAseString(w io.Writer, str string)

Types

type AsepriteCelChunk2005

type AsepriteCelChunk2005 struct {
	LayerIndex   uint16
	X, Y         int16
	OpacityLevel byte
	CelType      uint16

	// + For cel type = 0 (Raw Image Data)
	WidthInPix, HeightInPix uint16
	RawPixData              []byte
	// + For cel type = 1 (Linked Cel)
	FramePosToLinkWith uint16
	// + For cel type = 2 (Compressed Image)
	// WORD      Width in pixels
	// WORD      Height in pixels
	RawCelData []byte // "Raw Cel" data decompressed from ZLIB (see NOTE.3)
	// + For cel type = 3 (Compressed Tilemap)
	WidthInTiles, HeightInTiles uint16
	BitsPerTile                 uint16 // (at the moment it's always 32-bit per tile)
	BitMaskForTileID            uint32 // (e.g. 0x1fffffff for 32-bit tiles)
	BitMaskForXFlip             uint32
	BitMaskForYFlip             uint32
	BitMaskFor90CWRot           uint32

	Tiles []byte // zlib data (see NOTE.3)
	Extra *AsepriteCelExtraChunk2006
	// contains filtered or unexported fields
}

func (*AsepriteCelChunk2005) Decode

func (aseCelChunk *AsepriteCelChunk2005) Decode(r io.Reader)

func (*AsepriteCelChunk2005) Encode

func (aseCelChunk *AsepriteCelChunk2005) Encode(w io.Writer)

type AsepriteCelExtraChunk2006

type AsepriteCelExtraChunk2006 struct {
	Flags              uint32
	PreciseX, PreciseY uint32
	WidthCelInSprite   uint32
	HeightCelInSprite  uint32
	// contains filtered or unexported fields
}

*

  • Cel Extra Chunk (0x2006)
  • Adds extra information to the latest read cel. *
  • DWORD Flags (set to zero)
  • 1 = Precise bounds are set
  • FIXED Precise X position
  • FIXED Precise Y position
  • FIXED Width of the cel in the sprite (scaled in real-time)
  • FIXED Height of the cel in the sprite
  • BYTE[16] For future use (set to zero)

func (*AsepriteCelExtraChunk2006) Decode

func (aseCelExtra *AsepriteCelExtraChunk2006) Decode(r io.Reader)

func (*AsepriteCelExtraChunk2006) Encode

func (aseCelExtra *AsepriteCelExtraChunk2006) Encode(w io.Writer)

type AsepriteCodec

type AsepriteCodec interface {
	Decode(r io.Reader) error
	Encode(w io.Writer)
}

type AsepriteColorProfileChunk2007

type AsepriteColorProfileChunk2007 struct {
	Type       uint16
	Flags      uint16
	FixedGamma uint32

	// + If type = ICC:
	ICCProfileDatLen uint32
	ICCProfileDat    []byte
	// contains filtered or unexported fields
}

func (*AsepriteColorProfileChunk2007) Decode

func (aseColProfile *AsepriteColorProfileChunk2007) Decode(r io.Reader)

func (AsepriteColorProfileChunk2007) Encode

func (aseColProfile AsepriteColorProfileChunk2007) Encode(w io.Writer)

type AsepriteExternalFilesChunk2008

type AsepriteExternalFilesChunk2008 struct {
	NumEntries uint32

	// + for each entry
	ExternalFile []AsepriteExternalFilesChunk2008Entry
	// contains filtered or unexported fields
}

func (*AsepriteExternalFilesChunk2008) Decode

func (aseExtFile *AsepriteExternalFilesChunk2008) Decode(r io.Reader)

func (*AsepriteExternalFilesChunk2008) Encode

func (aseExtFile *AsepriteExternalFilesChunk2008) Encode(w io.Writer)

type AsepriteExternalFilesChunk2008Entry

type AsepriteExternalFilesChunk2008Entry struct {
	EntryID uint32

	ExternalFilename string
	// contains filtered or unexported fields
}

type AsepriteFile

type AsepriteFile struct {
	Header AsepriteHeader
	Frames []AsepriteFrame
}

func (*AsepriteFile) Decode

func (aseFile *AsepriteFile) Decode(r io.Reader) error

func (*AsepriteFile) DecodeFile

func (aseFile *AsepriteFile) DecodeFile(fName string) error

func (*AsepriteFile) Encode

func (aseFile *AsepriteFile) Encode(w io.Writer)

type AsepriteFrame

type AsepriteFrame struct {
	BytesThisFrame            uint32
	MagicNumber               uint16 // F1FA
	ChunksThisFrame           uint16 // If this value is FFFF there "may" be more chunks to read
	FrameDurationMilliseconds uint16

	ChunksThisFrameExt uint32 // New field which specifies num chunks. If 0, use old field
	OldPalettes0004    []AsepriteOldPaletteChunk0004
	OldPalettes0011    []AsepritePaletteChunk0011
	Layers             []AsepriteLayerChunk2004
	Cels               []AsepriteCelChunk2005
	ColorProfiles      []AsepriteColorProfileChunk2007
	Tags               AsepriteTagsChunk2018
	Palettes           []AsepritePaletteChunk2019
	Slices             []AsepriteSliceChunk2022
	// contains filtered or unexported fields
}

func (*AsepriteFrame) Decode

func (aseFrame *AsepriteFrame) Decode(r io.Reader) error

func (AsepriteFrame) Encode

func (aseFrame AsepriteFrame) Encode(w io.Writer)

type AsepriteHeader

type AsepriteHeader struct {
	FileSize       uint32
	MagicNumber    uint16 // A5E0
	Frames         uint16
	WidthInPixels  uint16
	HeightInPixels uint16
	ColorDepth     uint16
	Flags          uint32
	Speed          uint16 // deprecated, use frame duration from frame header

	PaletteEntry byte // represents transparent color in all non-background layers (only for indexed sprites)

	NumberOfColors uint16
	// (pixel ratio is "pxel width/pixel height")
	PixelWidth, PixelHeight byte
	XPositionOfGrid         int16
	YPositionOfGrid         int16
	GridWidth, GridHeight   uint16
	// contains filtered or unexported fields
}

func (*AsepriteHeader) Decode

func (aseHeader *AsepriteHeader) Decode(r io.Reader) error

func (*AsepriteHeader) Encode

func (aseHeader *AsepriteHeader) Encode(w io.Writer)

type AsepriteLayerChunk2004

type AsepriteLayerChunk2004 struct {
	Flags                uint16
	LayerType            uint16
	LayerChildLevel      uint16
	DefLayerWidthPixels  uint16 // (ignored)
	DefLayerHeightPixels uint16 // (ignored)
	BlendMode            uint16
	Opacity              byte // only valid if file headre flag field has bit 1 set

	LayerName string
	// + if layer type = 2
	TilesetIndex uint32
	UserData     AsepriteUserDataChunk2020
	// contains filtered or unexported fields
}

func (*AsepriteLayerChunk2004) AddUserData

func (layer *AsepriteLayerChunk2004) AddUserData(userData AsepriteUserDataChunk2020)

func (*AsepriteLayerChunk2004) Decode

func (aseLayerChunk *AsepriteLayerChunk2004) Decode(r io.Reader) error

func (AsepriteLayerChunk2004) Encode

func (aseLayerChunk AsepriteLayerChunk2004) Encode(w io.Writer)

type AsepriteMaskChunk2016

type AsepriteMaskChunk2016 struct {
	X, Y          int16
	Width, Height uint16

	MaskName   string
	BitMapData []byte
	// contains filtered or unexported fields
}

func (*AsepriteMaskChunk2016) Decode

func (aseMask *AsepriteMaskChunk2016) Decode(r io.Reader)

func (*AsepriteMaskChunk2016) Encode

func (aseMask *AsepriteMaskChunk2016) Encode(w io.Writer)

type AsepriteOldPaletteChunk0004

type AsepriteOldPaletteChunk0004 struct {
	NumberOfPackets uint16
	// + for each packet
	Packets []AsepriteOldPaletteChunk0004Packet
}

*

  • Then each chunk format is:
  • DWORD Chunk size
  • WORD Chunk type
  • BYTE[] Chunk data *
  • ----------------- *
  • Ignore this chunk if you find the new palette chunk (0x2019) Aseprite v1.1 saves both chunks 0x0004 and 0x2019 just for backward compatibility.
  • WORD Number of packets
  • + For each packet
  • BYTE Number of palette entries to skip from the last packet (start from 0)
  • BYTE Number of colors in the packet (0 means 256)
  • + For each color in the packet
  • BYTE Red (0-255)
  • BYTE Green (0-255)
  • BYTE Blue (0-255)

func (*AsepriteOldPaletteChunk0004) Decode

func (asePaletteChunk *AsepriteOldPaletteChunk0004) Decode(r io.Reader)

func (AsepriteOldPaletteChunk0004) Encode

func (asePaletteChunk AsepriteOldPaletteChunk0004) Encode(w io.Writer)

type AsepriteOldPaletteChunk0004Packet

type AsepriteOldPaletteChunk0004Packet struct {
	NumPalletteEntriesToSkip byte // from thee last packet (start from 0)
	NumColorsInThePacket     byte // 0 means 256
	//   + for each color in the packet
	Colors []AsepriteRGB24
}

type AsepritePaletteChunk0011

type AsepritePaletteChunk0011 struct {
	NumberOfPackets uint16
	// + for each packet
	Packets []AsepritePaletteChunk0011Packet
}

func (*AsepritePaletteChunk0011) Decode

func (asePaletteChunk *AsepritePaletteChunk0011) Decode(r io.Reader)

func (AsepritePaletteChunk0011) Encode

func (asePaletteChunk AsepritePaletteChunk0011) Encode(w io.Writer)

type AsepritePaletteChunk0011Packet

type AsepritePaletteChunk0011Packet struct {
	NumPalletteEntriesToSkip byte // start from 0
	NumColorsInThePacket     byte // 0 means 256
	// + for each color in the packet
	Colors []AsepriteRGB24 // but using colors in the range 0-63
}

type AsepritePaletteChunk2019

type AsepritePaletteChunk2019 struct {
	PaletteSize           uint32
	FirstColIndexToChange uint32
	LastColIndexToChange  uint32

	// + For each palette entry in [from,to] range (to-from+1 entries)
	PaletteEntries []AsepritePaletteChunk2019Entry
	// contains filtered or unexported fields
}

func (*AsepritePaletteChunk2019) Decode

func (asePaletteChunk *AsepritePaletteChunk2019) Decode(r io.Reader)

func (AsepritePaletteChunk2019) Encode

func (asePaletteChunk AsepritePaletteChunk2019) Encode(w io.Writer)

type AsepritePaletteChunk2019Entry

type AsepritePaletteChunk2019Entry struct {
	EntryFlags uint16
	R, G, B, A byte
	// + If has name bit in entry flags
	ColorName string
}

func (*AsepritePaletteChunk2019Entry) Decode

func (asePaletteEntry *AsepritePaletteChunk2019Entry) Decode(r io.Reader)

func (AsepritePaletteChunk2019Entry) Encode

func (asePaletteEntry AsepritePaletteChunk2019Entry) Encode(w io.Writer)

type AsepritePathChunk2017

type AsepritePathChunk2017 struct{}

type AsepriteRGB24

type AsepriteRGB24 struct {
	R, G, B byte
}

Just used here by certain packets

type AsepriteSliceChunk2022

type AsepriteSliceChunk2022 struct {
	NumSliceKeys uint32
	Flags        uint32

	Name string
	// + For each slice key
	SliceKeysData []AsepriteSliceChunk2022Data
	UserData      AsepriteUserDataChunk2020
	// contains filtered or unexported fields
}

func (*AsepriteSliceChunk2022) AddUserData

func (sliceChunk *AsepriteSliceChunk2022) AddUserData(userDat AsepriteUserDataChunk2020)

func (*AsepriteSliceChunk2022) Decode

func (aseSlice *AsepriteSliceChunk2022) Decode(r io.Reader)

func (AsepriteSliceChunk2022) Encode

func (aseSlice AsepriteSliceChunk2022) Encode(w io.Writer)

type AsepriteSliceChunk2022Data

type AsepriteSliceChunk2022Data struct {
	FrameNumber             uint32
	SliceXOriginCoords      int32
	SliceYOriginCoords      int32
	SliceWidth, SliceHeight uint32
	// + If flags have bit 1
	CenterX, CenterY          int32
	CenterWidth, CenterHeight uint32
	// + If flags have bit 2
	PivotX, PivotY int32
	// contains filtered or unexported fields
}

func (*AsepriteSliceChunk2022Data) Decode

func (aseSliceDat *AsepriteSliceChunk2022Data) Decode(r io.Reader)

func (AsepriteSliceChunk2022Data) Encode

func (aseSliceDat AsepriteSliceChunk2022Data) Encode(w io.Writer)

type AsepriteTagsChunk2018

type AsepriteTagsChunk2018 struct {
	NumTags uint16

	Tags     []AsepriteTagsChunk2018Tag
	UserData []AsepriteUserDataChunk2020
	// contains filtered or unexported fields
}

*

  • Tags Chunk (0x2018)
  • After the tags chunk, you can write one user data chunk for each tag. E.g. if there are 10 tags, you can then write 10 user data chunks one for each tag. *
  • WORD Number of tags
  • BYTE[8] For future (set to zero)
  • + For each tag
  • WORD From frame
  • WORD To frame
  • BYTE Loop animation direction
  • 0 = Forward
  • 1 = Reverse
  • 2 = Ping-pong
  • BYTE[8] For future (set to zero)
  • BYTE[3] RGB values of the tag color
  • Deprecated, used only for backward compatibility with Aseprite v1.2.x
  • The color of the tag is the one in the user data field following
  • the tags chunk
  • BYTE Extra byte (zero)
  • STRING Tag name

func (*AsepriteTagsChunk2018) AddUserData

func (tagsChunk *AsepriteTagsChunk2018) AddUserData(userDat AsepriteUserDataChunk2020)

func (*AsepriteTagsChunk2018) Decode

func (aseTags *AsepriteTagsChunk2018) Decode(r io.Reader)

func (AsepriteTagsChunk2018) Encode

func (aseTags AsepriteTagsChunk2018) Encode(w io.Writer)

type AsepriteTagsChunk2018Tag

type AsepriteTagsChunk2018Tag struct {
	FromFrame, ToFrame uint16
	LoopAnimDirection  byte

	TagColor  [3]byte // deprecated
	ExtraByte byte    // (zero)
	TagName   string
	// contains filtered or unexported fields
}

func (*AsepriteTagsChunk2018Tag) Decode

func (aseTag *AsepriteTagsChunk2018Tag) Decode(r io.Reader)

func (AsepriteTagsChunk2018Tag) Encode

func (aseTag AsepriteTagsChunk2018Tag) Encode(w io.Writer)

type AsepriteTilesetChunk2023

type AsepriteTilesetChunk2023 struct {
	TilesetID             uint32
	Flags                 uint32
	NumTiles              uint32
	TileWidth, TileHeight uint16
	BaseIndex             int16

	Name string
	// + If flag 1 is set
	ExternalFileID          uint32
	TilesetIDInExternalFile uint32
	// + If flag 2 is set
	CompressedDatLen     uint32
	CompressedTilesetImg []byte
	// contains filtered or unexported fields
}

func (*AsepriteTilesetChunk2023) Decode

func (aseTileset *AsepriteTilesetChunk2023) Decode(r io.Reader)

type AsepriteUserDatHolder

type AsepriteUserDatHolder interface {
	AddUserData(AsepriteUserDataChunk2020)
}

type AsepriteUserDataChunk2020

type AsepriteUserDataChunk2020 struct {
	Flags uint32
	// + If flags have bit 1
	Text string
	// + If flags have bit 2
	R, G, B, A byte
}

func (*AsepriteUserDataChunk2020) Decode

func (aseUserDat *AsepriteUserDataChunk2020) Decode(r io.Reader)

func (AsepriteUserDataChunk2020) Encode

func (aseUserDat AsepriteUserDataChunk2020) Encode(w io.Writer)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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