// NewHelper constructs a helper for managing animated GIFs.
NewHelper constructs a helper for managing animated GIFs.
// NewHelper constructs a helper for managing animated GIFs .
func NewHelper(g *gif.GIF) (helper Helper, err error) {
	if !IsAnimated(g) {
		return helper, ErrNotAnimated
	}
	if len(g.Delay) < len(g.Image) {
		return helper, errors.New("Not enough delays")
	}
	if len(g.Disposal) < len(g.Image) {
		return helper, errors.New("Not enough disposals")
	}
	frames := make([]Frame, 1, len(g.Image))
	frames[0] = Frame{g.Image[0], g.Delay[0], g.Disposal[0]}
	for i, v := range g.Image[1:] {
		prevFrame := frames[len(frames)-1]
		nextFrame := image.NewRGBA(prevFrame.Bounds())
		combinePrevious := func() {
			draw.Src.Draw(
				nextFrame,
				nextFrame.Bounds(),
				prevFrame,
				image.Point{},
			)
		}
		switch pd := prevFrame.disposalMethod; pd {
		case gif.DisposalBackground:
		case gif.DisposalNone:
			fallthrough
		default:
			combinePrevious()
		}
		draw.Over.Draw(nextFrame, nextFrame.Bounds(), v, image.Point{})
		frames = append(frames, Frame{
			nextFrame,
			g.Delay[i+1],
			g.Disposal[i+1],
		})
	}
	var l looper
	switch g.LoopCount {
	case -1:
		l = noLoop{}
	case 0:
		l = infiniteLoop{}
	default:
		l = &countLoop{g.LoopCount}
	}
	helper = Helper{
		frames,
		l,
		0,
	}
	return
}
func NewHelper ( g * gif . GIF ) ( helper Helper , err error ) { if ! IsAnimated ( g ) { return helper , ErrNotAnimated } if len ( g . Delay ) < len ( g . Image ) { return helper , errors . New ( " " ) } if len ( g . Disposal ) < len ( g . Image ) { return helper , errors . New ( " " ) } frames := make ( [ ] Frame , 1 , len ( g . Image ) ) frames [ 0 ] = Frame { g . Image [ 0 ] , g . Delay [ 0 ] , g . Disposal [ 0 ] } for i , v := range g . Image [ 1 : ] { prevFrame := frames [ len ( frames ) - 1 ] nextFrame := image . NewRGBA ( prevFrame . Bounds ( ) ) combinePrevious := func ( ) { draw . Src . Draw ( nextFrame , nextFrame . Bounds ( ) , prevFrame , image . Point { } , ) } switch pd := prevFrame . disposalMethod ; pd { case gif . DisposalBackground : case gif . DisposalNone : fallthrough default : combinePrevious ( ) } draw . Over . Draw ( nextFrame , nextFrame . Bounds ( ) , v , image . Point { } ) frames = append ( frames , Frame { nextFrame , g . Delay [ i + 1 ] , g . Disposal [ i + 1 ] , } ) } var l looper switch g . LoopCount { case - 1 : l = noLoop { } case 0 : l = infiniteLoop { } default : l = & countLoop { g . LoopCount } } helper = Helper { frames , l , 0 , } return }
NewHelper constructs a helper for managing animated GIFs.
NewHelper constructs a helper for managing animated GIFs .
// NOTE Modern tools interpret this is "clear to transparent", so do nothing