go-tibia: badc0de.net/pkg/go-tibia/spr Index | Examples | Files

package spr

import "badc0de.net/pkg/go-tibia/spr"

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

Package Files

doc.go image.go spr.go

func Decode Uses

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

func DecodeConfig Uses

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

func DecodeOne Uses

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.

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)

Output:

image: 32x32

func DecodeOnePic Uses

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

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

func DecodeUpcoming Uses

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 Uses

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

type ColorKey Uses

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

type Options Uses

type Options struct{}

type SpriteSet Uses

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

func DecodeAll Uses

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 Uses

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 Uses

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

Package spr imports 8 packages (graph) and is imported by 5 packages. Updated 2020-10-13. Refresh now. Tools for package owners.