Documentation
¶
Overview ¶
Package imager provides functionality for rendering assets to images.
Index ¶
- func DrawFrame(anim Animation, canvas draw.Image, offset image.Point, drawer draw.Drawer, ...)
- func NewFurniImager(mgr res.LibraryManager) *furniImager
- func RenderFrame(anim Animation, seqIndex int, frameIndex int) image.Image
- func RenderFrames(anim Animation, seqIndex, frameCount int) []image.Image
- func RenderFramesBounds(bounds image.Rectangle, anim Animation, seqIndex, frameCount int) []image.Image
- func RenderQuantizedFrames(anim Animation, seqIndex int, palette color.Palette, count int) []*image.Paletted
- type AnimatedEncoder
- type AnimatedImageEncoder
- type Animation
- type AnimationEncoder
- type AnimationLayer
- type AnimationSequenceEncoder
- type Avatar
- type AvatarImager
- type AvatarPart
- type Blend
- type Encoder
- type EncoderOption
- type FigureAssetSpec
- type Frame
- type FrameEncoder
- type Furni
- type FurniImager
- type GifEncoderOptions
- type ImageEncoder
- type Sprite
- type StaticEncoder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DrawFrame ¶
func DrawFrame(anim Animation, canvas draw.Image, offset image.Point, drawer draw.Drawer, seqIndex int, frameIndex int)
DrawFrame draws a single from from an animation onto the canvas at the specified offset 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 ¶
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 ¶
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.
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 ¶
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 ¶
Bounds gets the union of the bounds of all frames in this animation for the specified sequence.
func (*Animation) LongestSequence ¶
LongestSequence gets the longest frame sequence of all layers in this animation for the specified sequence.
func (Animation) RequiredAssets ¶
RequiredAssets gets all assets used in the specified frame sequence in this animation.
func (*Animation) TotalFrames ¶
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 is the name of the library that contains this part. // It may be an empty string if the library failed to resolve. LibraryName string AssetSpec FigureAssetSpec Asset *res.Asset SetType nx.FigurePartType SetId int Type nx.FigurePartType Id int // Color is the color for this avatar part. It may be nil if the color failed to resolve. Color color.Color Hidden bool }
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
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 ¶
FurniImager represents an imager that can compose furni into animations.
type GifEncoderOptions ¶
type ImageEncoder ¶
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 ¶
Bounds returns the bounds of the sprite's image translated by the sprite's offset.
func (*Sprite) Draw ¶
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.
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