Documentation

Overview

Package spr implements a reader for individual sprites in a Tibia.spr files.

A higher level implementation needs to be used together with the dataset information on a thing's graphics layout and sprites in order to actually construct a full recognizable image.

Since .pic format also uses the same encoder, it can be used as a basis for a .pic decoder.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

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

func DecodeConfig

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

func DecodeOne

func DecodeOne(r io.ReadSeeker, which int) (image.Image, error)

DecodeOne accepts an io.ReadSeeker positioned at the beginning of a spr-formatted file (a sprite set file), finds the image with passed index, and returns the requested image as an image.Image.

Example

ExampleDecodeOne decodes a single spr, encodes it into a png, and prints out the image size.

Code:

var err error
f, _ := os.Open(os.Getenv("TEST_SRCDIR") + "/tibia854/Tibia.spr")
if f == nil {
	f, _ = os.Open("../datafiles/Tibia.spr")
}
if f == nil {
	f, _ = os.Open(os.Args[0] + ".runfiles/go_tibia/external/tibia854/Tibia.spr")
}
defer f.Close()

img, err := DecodeOne(f, 423)
if err != nil {
	fmt.Printf("failed to decode spr: %s", err)
	return
}
f, _ = os.Create(os.TempDir() + "/423.png")
png.Encode(f, img)
f.Close()

fmt.Printf("image: %dx%d\n", img.Bounds().Size().X, img.Bounds().Size().Y)
image: 32x32

func DecodeOnePic

func DecodeOnePic(r io.ReadSeeker, which int) (image.Image, error)

DecodeOnePic behaves like DecodeOne, except it accepts .pic formatted files.

func DecodeUpcoming

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

DecodeUpcoming decodes a single block of spr-format data. This is used in both pic and spr files.

func Encode

func Encode(w io.Writer, m image.Image, o *Options) error

Types

type ColorKey

type ColorKey struct{ ColorKeyR, ColorKeyG, ColorKeyB uint8 }
type Header struct {
	Signature   uint32
	SpriteCount uint16
}

type Options

type Options struct{}

type SpriteSet

type SpriteSet struct {
	Header
	// contains filtered or unexported fields
}

func DecodeAll

func DecodeAll(r io.Reader) (*SpriteSet, error)

DecodeAll decodes all images in the passed reader, and returns a sprite set.

It is currently implemented as an in-memory buffer which can be queried to return a particular sprite.

func (*SpriteSet) EncodeAll

func (s *SpriteSet) EncodeAll(w io.Writer) error

EncodeAll encodes all images in the sprite set and writes them to the passed writer.

It is currently not implemented.

func (*SpriteSet) Image

func (s *SpriteSet) Image(idx int) image.Image