animation

package
v0.0.0-...-8099344 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

Package animation provides animated image support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeGIF

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

DecodeGIF returns a GIF or gif.GIF decoded from the provided io.Reader. If the GIF data encodes a single frame, the image returned is a gif.GIF, otherwise a GIF is returned. When the result is a GIF, GIF delay, disposal and global background index values are checked for validity.

func IsGIF

func IsGIF(r ReadPeeker) bool

IsGIF returns whether the data held by r is a GIF image.

Types

type Animator

type Animator interface {
	// Animate renders the frames into dst and calls
	// fn on each rendered frame.
	Animate(ctx context.Context, dst draw.Image, fn func(image.Image) error) error
	image.Image
}

Animator is an image that can animate frames.

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache is an ardilla.RawFrame cache.

func NewCache

func NewCache(deck RawImager) *Cache

type GIF

type GIF struct {
	*gif.GIF

	// Cache caches GIF frames in the internal format
	// of the device. Cache must not be changed while
	// an animation is running.
	Cache *Cache
	// contains filtered or unexported fields
}

GIF is an animated GIF.

The GIF image.Image implementation is conditional on whether an animation The image is either from the first or last frame; if an terminates the last frame is used, if it does not terminate the first is used. GIF animations that terminate should ensure that the final frame is a complete renderable image.

GIF pointer values must not be shared between goroutines. It is safe to share the backing gif.GIF and Cache values, so if a GIF is to be used concurrently, each goroutine should have a pointer to a copy of a parent concrete GIF value.

func (*GIF) Animate

func (img *GIF) Animate(ctx context.Context, dst draw.Image, fn func(image.Image) error) error

Animate renders the receiver's frames into dst and calls fn on each rendered frame.

func (*GIF) At

func (img *GIF) At(x, y int) color.Color

At implements the image.Image interface. The frame image used

func (*GIF) Bounds

func (img *GIF) Bounds() image.Rectangle

Bounds implements the image.Image interface. The frame image used

func (*GIF) ColorModel

func (img *GIF) ColorModel() color.Model

ColorModel implements the image.Image interface. If the GIF has a global color table, its color model is returned, otherwise the first or last frame's model is used.

type GIFs

type GIFs []*GIF

GIFs is an animator that runs through a set of GIF animations in order. Each of the GIFs must have the same bounds and only the last GIF in the sequence may be non-terminating. As with the GIF type, if the final GIF in the sequence has completed, it's final frame is used as the complete image.Image, otherwise the first frame of the first GIF in the sequence is used.

func (GIFs) Animate

func (img GIFs) Animate(ctx context.Context, dst draw.Image, fn func(image.Image) error) error

Animate renders the receiver's GIFs' frames into dst and calls fn on each rendered frame.

func (GIFs) At

func (img GIFs) At(x, y int) color.Color

At implements the image.Image interface.

func (GIFs) Bounds

func (img GIFs) Bounds() image.Rectangle

Bounds implements the image.Image interface.

func (GIFs) ColorModel

func (img GIFs) ColorModel() color.Model

ColorModel implements the image.Image interface.

type Images

type Images struct {
	// The successive images.
	Image []image.Image

	// Delay is the delay between images.
	Delay time.Duration

	// LoopCount controls the number of times an animation will be
	// restarted during display.
	// A LoopCount of 0 means to loop forever.
	// A LoopCount of -1 means to show each frame only once.
	// Otherwise, the animation is looped LoopCount+1 times.
	LoopCount int

	// Cache caches frames in the internal format
	// of the device. Cache must not be changed while
	// an animation is running.
	Cache *Cache
	// contains filtered or unexported fields
}

Images is an animator that animates through a set of images in order similar to the GIFs type. If an image in the set is an Animator, it is animated. No checks are made for non-terminating animations with the set.

func (*Images) Animate

func (img *Images) Animate(ctx context.Context, dst draw.Image, fn func(image.Image) error) error

Animate renders the receiver's images into dst and calls fn on each rendered image.

func (*Images) At

func (img *Images) At(x, y int) color.Color

At implements the image.Image interface.

func (*Images) Bounds

func (img *Images) Bounds() image.Rectangle

Bounds implements the image.Image interface.

func (*Images) ColorModel

func (img *Images) ColorModel() color.Model

ColorModel implements the image.Image interface.

type RawImager

type RawImager interface {
	RawImage(img image.Image) (*ardilla.RawImage, error)
}

RawImager wraps the RawImage method.

type ReadPeeker

type ReadPeeker interface {
	io.Reader
	Peek(n int) ([]byte, error)
}

ReadPeeker is an io.Reader that can also peek n bytes ahead.

func AsReadPeeker

func AsReadPeeker(r io.Reader) ReadPeeker

AsReadPeeker converts an io.Reader to a ReadPeeker.

type Text

type Text string

Text is a scrolling text animator.

func (Text) GIF

func (t Text) GIF(bound image.Rectangle, pal color.Palette, fg, bg byte) (*GIF, error)

GIF returns a GIF containing animation frames required to present the full length of the receiver within the given bounds using basicfont.Face7x13. The provided palette must have at least two colors, which will be indexed by fg and bg to provide the foreground and background colors for the text animation.

Jump to

Keyboard shortcuts

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