imager

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package imager provides functionality for rendering assets to images.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DrawFrame

func DrawFrame(anim Animation, canvas draw.Image, drawer draw.Drawer, seqIndex int, frameIndex int)

DrawFrame draws a single from from an animation onto the canvas using the specified drawer. seqIndex selects the animation sequence to render, while frameIndex selects the index of the frame within the sequence to render.

func NewFurniImager

func NewFurniImager(mgr res.LibraryManager) *furniImager

NewFurniImager creates a new furni imager using the specified library manager.

func RenderFrame

func RenderFrame(anim Animation, seqIndex int, frameIndex int) image.Image

RenderFrame renders a single from from an animation to an image. seqIndex selects the animation sequence to render, while frameIndex selects the index of the frame within the sequence to render.

func RenderFrames

func RenderFrames(anim Animation, seqIndex, frameCount int) []image.Image

RenderFramesBounds renders each frame of an animation to images. seqIndex selects the animation sequence to render, while frameCount specifies the number of frames to render.

func RenderFramesBounds

func RenderFramesBounds(bounds image.Rectangle, anim Animation, seqIndex, frameCount int) []image.Image

RenderFramesBounds renders each frame of an animation to images of the size specified by bounds. seqIndex selects the animation sequence to render, while frameCount specifies the number of frames to render.

func RenderQuantizedFrames

func RenderQuantizedFrames(anim Animation, seqIndex int, palette color.Palette, count int) []*image.Paletted

Types

type AnimatedEncoder

type AnimatedEncoder interface {
	AnimationEncoder
	AnimatedImageEncoder
}

AnimatedEncoder represents an encoder that can encode animations and image sequences.

func NewEncoderAPNG

func NewEncoderAPNG() AnimatedEncoder

type AnimatedImageEncoder

type AnimatedImageEncoder interface {
	EncodeImages(w io.Writer, frames []image.Image) error
}

AnimatedImageEncoder represents an encoder that can encode a sequence of images.

type Animation

type Animation struct {
	Background color.Color            // Background defines the color to fill the canvas with when rendering.
	Layers     map[int]AnimationLayer // Layers is a map of animation layers by index.
}

Animation represents an animated asset.

func (Animation) Bounds

func (animation Animation) Bounds(seqIndex int) (bounds image.Rectangle)

Bounds gets the union of the bounds of all frames in this animation for the specified sequence.

func (*Animation) LongestSequence

func (animation *Animation) LongestSequence(seqIndex int) int

LongestSequence gets the longest frame sequence of all layers in this animation for the specified sequence.

func (Animation) RequiredAssets

func (anim Animation) RequiredAssets(seqIndex int) []*res.Asset

RequiredAssets gets all assets used in the specified frame sequence in this animation.

func (*Animation) TotalFrames

func (animation *Animation) TotalFrames(seqIndex int) int

TotalFrames gets the total number of frames in this animation for the specified sequence.

type AnimationEncoder

type AnimationEncoder interface {
	EncodeAnimation(w io.Writer, anim Animation, seqIndex, frameCount int) error
}

AnimationEncoder represents an encoder that can encode an animation.

type AnimationLayer

type AnimationLayer struct {
	Frames      map[int]Frame       // Frames is a map of frames by index.
	FrameRepeat int                 // FrameRepeat defines the duration of each frame for this layer.
	Sequences   []res.FrameSequence // Sequences contains a list of frame sequences.
	Z           int                 // Z defines the Z-order of this layer.
}

AnimationLayer defines a set of frames and frame sequences.

func (AnimationLayer) SequenceOrDefault

func (animationLayer AnimationLayer) SequenceOrDefault(seqIndex int) res.FrameSequence

SequenceOrDefault gets the specified frame sequence if it exists, the first sequence if `i` is out of range, or a sequence with a single zero frame if the animation has no frame sequences.

type AnimationSequenceEncoder

type AnimationSequenceEncoder interface {
	EncodeAnimations(w io.Writer, anims []Animation, seqIndex, frameCount int) error
}

AnimationSequenceEncoder represents an encoder that can encode a sequence of animations.

type Avatar

type Avatar struct {
	nx.Figure
	Direction     int
	HeadDirection int
	Actions       []nx.AvatarState
	Expression    nx.AvatarState
	HandItem      int
	Effect        int
	Sign          int
	HeadOnly      bool
}

An Avatar defines the state of a Figure in a room.

type AvatarImager

type AvatarImager interface {
	Compose(avatar Avatar) (Animation, error)
	Parts(figure nx.Figure) ([]AvatarPart, error)
	RequiredLibs(figure nx.Figure) ([]string, error)
}

AvatarImager represents an imager that can compose avatars into animations.

func NewAvatarImager

func NewAvatarImager(mgr gd.Manager) AvatarImager

type AvatarPart

type AvatarPart struct {
	LibraryName string
	AssetSpec   FigureAssetSpec
	Asset       *res.Asset
	SetType     nx.FigurePartType
	SetId       int
	Type        nx.FigurePartType
	Id          int
	Color       color.Color
	Hidden      bool
}

type Blend

type Blend int

Blend represents a color blending mode.

const (
	BlendNone Blend = iota // No blend mode.
	BlendAdd               // Additive blending.
	BlendCopy
)

type Encoder

type Encoder interface {
	StaticEncoder
	AnimatedEncoder
}

Encoder represents an encoder that can encode animations and frames.

func NewEncoderGIF

func NewEncoderGIF(options ...EncoderOption) Encoder

type EncoderOption

type EncoderOption func(any)

func WithAlphaThreshold

func WithAlphaThreshold(threshold uint16) EncoderOption

func WithColors

func WithColors(n int) EncoderOption

type FigureAssetSpec

type FigureAssetSpec struct {
	State nx.AvatarState
	Type  nx.FigurePartType
	Id    int
	Dir   int
	Frame int
}

func (FigureAssetSpec) String

func (spec FigureAssetSpec) String() string

type Frame

type Frame []Sprite

func (Frame) Bounds

func (f Frame) Bounds() (bounds image.Rectangle)

Bounds returns the union of the bounds of all sprites in this frame.

func (Frame) Draw

func (frame Frame) Draw(canvas draw.Image, drawer draw.Drawer)

Draw draws the frame onto the canvas using the provided drawer. If the drawer is nil, one will be selected automatically based on each sprite's blending mode.

func (Frame) ToImage

func (frame Frame) ToImage() image.Image

type FrameEncoder

type FrameEncoder interface {
	EncodeFrame(w io.Writer, anim Animation, seqIndex, frameIndex int) error
}

FrameEncoder represents an encoder that can encode a single frame within an animation.

func NewEncoderSVG

func NewEncoderSVG() FrameEncoder

type Furni

type Furni struct {
	Identifier string // Identifier is the class name of the furni library.
	Size       int    // Size selects the visualization size to render.
	Direction  int    // Direction selects the direction of the furni to render.
	State      int    // State selects the animation state to render.
	Sequence   int    // Sequence selects the index of the animation sequence to render.
	Color      int    // Color selects the index of the color within the visualization to render.
	Shadow     bool   // Shadow configures whether to render the shadow layer.
}

Furni represents a furniture to render.

type FurniImager

type FurniImager interface {
	Compose(furni Furni) Animation
}

FurniImager represents an imager that can compose furni into animations.

type GifEncoderOptions

type GifEncoderOptions struct {
	AlphaThreshold uint16
	Colors         int
}

type ImageEncoder

type ImageEncoder interface {
	EncodeImage(w io.Writer, frame image.Image) error
}

ImageEncoder represents an encoder that can encode an image.

type Sprite

type Sprite struct {
	Asset  *res.Asset  // A reference to the asset used by this sprite.
	FlipH  bool        // FlipH defines whether to flip the asset horizontally.
	FlipV  bool        // FlipV defines whether to flip the asset vertically.
	Offset image.Point // Offset defines the offset point from the origin to draw the asset.
	Color  color.Color // Color defines the color to blend with the asset.
	Blend  Blend       // Blend defines the blending mode used to draw the asset.
	Alpha  uint8       // Alpha defines the alpha transparency of the asset.
}

Sprite defines parameters for an asset to be drawn on a canvas.

func (*Sprite) Bounds

func (s *Sprite) Bounds() image.Rectangle

Bounds returns the bounds of the sprite's image translated by the sprite's offset.

func (*Sprite) Draw

func (s *Sprite) Draw(canvas draw.Image, drawer draw.Drawer)

Draw draws the sprite onto the canvas using the provided drawer. If the drawer is nil, one will be selected automatically based on the sprite's blending mode.

func (*Sprite) Image

func (s *Sprite) Image() image.Image

Image gets the source image for this sprite.

func (*Sprite) Size

func (s *Sprite) Size() image.Point

Size returns the size of the sprite.

type StaticEncoder

type StaticEncoder interface {
	FrameEncoder
	ImageEncoder
}

StaticEncoder represents an encoder that can encode an image or a single frame from an animation.

func NewEncoderPNG

func NewEncoderPNG() StaticEncoder

Jump to

Keyboard shortcuts

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