gogif

package module
v0.0.0-...-9ca53c9 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: BSD-2-Clause Imports: 11 Imported by: 0

README

Hi! Please read the note below.

Aside from the median cut quantizer, this code has been merged into the Go standard library. I would strongly encourage you to use that instead :).

Contributors

example in cmd directory

To run the the example

go run -v -race cmd/main.go > out.gif

Documentation

Overview

Package gif implements a GIF image decoder and encoder.

The GIF specification is at http://www.w3.org/Graphics/GIF/spec-gif89a.txt.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

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

Decode reads a GIF image from r and returns the first embedded image as an image.Image.

func DecodeAll

func DecodeAll(r io.Reader) (*gif.GIF, error)

DecodeAll reads a GIF image from r and returns the sequential frames and timing information.

func DecodeConfig

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

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

func Encode

func Encode(w io.Writer, m image.Image, o *Options) error

Encode writes the Image m to w in GIF format.

func EncodeAll

func EncodeAll(w io.Writer, g *gif.GIF) error

EncodeAll writes the images in g to w in GIF format with the given loop count and delay between frames.

func EncodeStream

func EncodeStream(w io.Writer, g *StreamedGIF) error

EncodeAll writes the images in g to w in GIF format with the given loop count and delay between frames.

func ToPaletted

func ToPaletted(m image.Image, o *Options) (*image.Paletted, error)

Types

type GifFrame

type GifFrame struct {
	Image *image.Paletted // The successive images.
	Delay int             // The successive delay times, one per frame, in 100ths of a second.
}

type MedianCutQuantizer

type MedianCutQuantizer struct {
	NumColor int
}

MedianCutQuantizer constructs a palette with a maximum of NumColor colors by iteratively splitting clusters of color points mapped on a three-dimensional (RGB) Euclidian space. Once the number of clusters is within the specified bounds, the resulting color is computed by averaging those within each grouping.

func (*MedianCutQuantizer) Quantize

func (q *MedianCutQuantizer) Quantize(dst *image.Paletted, r image.Rectangle, src image.Image, sp image.Point)

type Options

type Options struct {
	Quantizer Quantizer
}

Options are the encoding parameters.

type Quantizer

type Quantizer interface {
	// Quantize sets dst.Palette as well as dst's pixels.
	Quantize(dst *image.Paletted, r image.Rectangle, src image.Image, sp image.Point)
}

A Quantizer interface is used by an encoder to construct an image with a restricted color palette.

type StreamedGIF

type StreamedGIF struct {
	Frames chan GifFrame
	// 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
	// Disposal is the successive disposal methods, one per frame. For
	// backwards compatibility, a nil Disposal is valid to pass to EncodeAll,
	// and implies that each frame's disposal method is 0 (no disposal
	// specified).
	Disposal []byte
	// Config is the global color table (palette), width and height. A nil or
	// empty-color.Palette Config.ColorModel means that each frame has its own
	// color table and there is no global color table. Each frame's bounds must
	// be within the rectangle defined by the two points (0, 0) and
	// (Config.Width, Config.Height).
	//
	// For backwards compatibility, a zero-valued Config is valid to pass to
	// EncodeAll, and implies that the overall GIF's width and height equals
	// the first frame's bounds' Rectangle.Max point.
	Config image.Config
	// BackgroundIndex is the background index in the global color table, for
	// use with the DisposalBackground disposal method.
	BackgroundIndex byte
}

GIF represents the possibly multiple images stored in a GIF file.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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