apng

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: BSD-3-Clause Imports: 8 Imported by: 1

README

APNG golang library

APNG decoder with frame-hook for golang
Instead of storing every frame of the apng in memory, you can run any function you like on every frame. Forked from github.com/kettek/apng

Example

package main

import (
	"fmt"
	"os"
	"github.com/nexryai/apng"
)

func main() {
	// Open our animated PNG file
	f, err := os.Open("input.png")
	if err != nil {
		panic(err)
	}
	defer f.Close()

	_, err = apng.DecodeAll(f, func(f *apng.FrameHookArgs) error {
		fmt.Printf("Frame %d | Delay:%v\n", f.Num, f.Delay)
		return nil
	})

	if err != nil {
		panic(err)
	}
}

Documentation

Overview

Package apng implements an APNG image decoder.

The PNG specification is at https://www.w3.org/TR/PNG/. The APNG specification is at https://wiki.mozilla.org/APNG_Specification

Index

Constants

View Source
const (
	DISPOSE_OP_NONE       = 0
	DISPOSE_OP_BACKGROUND = 1
	DISPOSE_OP_PREVIOUS   = 2
)

dispose_op values, as per the APNG spec.

View Source
const (
	BLEND_OP_SOURCE = 0
	BLEND_OP_OVER   = 1
)

blend_op values, as per the APNG spec.

Variables

This section is empty.

Functions

func DecodeConfig

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

DecodeConfig returns the color model and dimensions of a PNG image without decoding the entire image.

Types

type APNG

type APNG struct {
	Frames []Frame
	// LoopCount defines the number of times an animation will be
	// restarted during display.
	// A LoopCount of 0 means to loop forever
	LoopCount uint
}

func DecodeAll

func DecodeAll(r io.Reader, hook func(*FrameHookArgs) error) (APNG, error)

DecodeAll reads an APNG file from r and returns it as an APNG Type. If the first frame returns true for IsDefault(), that frame should not be part of the result. The type of Image returned depends on the PNG contents.

type FormatError

type FormatError string

A FormatError reports that the input is not a valid PNG.

func (FormatError) Error

func (e FormatError) Error() string

type Frame

type Frame struct {
	XOffset, YOffset int
	DelayNumerator   uint16
	DelayDenominator uint16
	DelayTime        float32
	DisposeOp        byte
	BlendOp          byte
	// IsDefault indicates if the Frame is a default image that
	// should not be used in the animation. IsDefault can only
	// be true on the first frame.
	IsDefault bool
	// contains filtered or unexported fields
}

func (*Frame) GetDelay

func (f *Frame) GetDelay() float64

GetDelay returns the number of seconds in the frame.

type FrameHookArgs added in v0.0.2

type FrameHookArgs struct {
	Buffer  *image.Image
	Num     int
	Delay   float32
	Width   int
	OffsetX int
	Height  int
	OffsetY int
}

type UnsupportedError

type UnsupportedError string

An UnsupportedError reports that the input uses a valid but unimplemented PNG feature.

func (UnsupportedError) Error

func (e UnsupportedError) Error() string

Jump to

Keyboard shortcuts

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