spr

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2024 License: GPL-2.0 Imports: 8 Imported by: 0

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)

Decode returns the first image from either spriteset or picture file.

func DecodeConfig

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

DecodeConfig returns the image.Config (width, height, colormodel) for the first image in either spriteset or picture file.

func DecodeConfigAll added in v0.0.6

func DecodeConfigAll(r io.Reader) ([]image.Config, error)

DecodeConfigAll is not implemented, but would be useful for PICs.

It would return the dimensions of each of the images in the PIC file, or 32x32 for all images in the SPR file.

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.

var err error
f, err := paths.Open("Tibia.spr")
if err != nil {
	panic(err.Error())
}
defer f.Close()

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

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

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

Jump to

Keyboard shortcuts

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