gif

Imports

Imports #

"bufio"
"compress/lzw"
"errors"
"fmt"
"image"
"image/color"
"io"
"bufio"
"bytes"
"compress/lzw"
"errors"
"image"
"image/color"
"image/color/palette"
"image/draw"
"internal/byteorder"
"io"

Constants & Variables

DisposalBackground const #

Disposal Methods.

const DisposalBackground = 0x02

DisposalNone const #

Disposal Methods.

const DisposalNone = 0x01

DisposalPrevious const #

Disposal Methods.

const DisposalPrevious = 0x03

eApplication const #

Extensions.

const eApplication = 0xFF

eComment const #

Extensions.

const eComment = 0xFE

eGraphicControl const #

Extensions.

const eGraphicControl = 0xF9

eText const #

Extensions.

const eText = 0x01

errBadPixel var #

var errBadPixel = *ast.CallExpr

errNotEnough var #

var errNotEnough = *ast.CallExpr

errTooMuch var #

var errTooMuch = *ast.CallExpr

fColorTable const #

Fields.

const fColorTable = *ast.BinaryExpr

fColorTableBitsMask const #

Masks etc.

const fColorTableBitsMask = 7

fInterlace const #

Masks etc.

const fInterlace = *ast.BinaryExpr

gcBlockSize const #

Graphic control extension fields.

const gcBlockSize = 0x04

gcDisposalMethodMask const #

Masks etc.

const gcDisposalMethodMask = *ast.BinaryExpr

gcLabel const #

Graphic control extension fields.

const gcLabel = 0xF9

gcTransparentColorSet const #

Graphic control flags.

const gcTransparentColorSet = *ast.BinaryExpr

interlacing var #

interlacing represents the set of scans in an interlaced GIF image.

var interlacing = []interlaceScan{...}

log2Lookup var #

var log2Lookup = [8]int{...}

sExtension const #

Section indicators.

const sExtension = 0x21

sImageDescriptor const #

Section indicators.

const sImageDescriptor = 0x2C

sTrailer const #

Section indicators.

const sTrailer = 0x3B

Interfaces

reader interface #

If the io.Reader does not also have ReadByte, then decode will introduce its own buffering.

type reader interface {
io.Reader
io.ByteReader
}

writer interface #

writer is a buffered writer.

type writer interface {
Flush() error
io.Writer
io.ByteWriter
}

Structs

GIF struct #

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

type GIF struct {
Image []*image.Paletted
Delay []int
LoopCount int
Disposal []byte
Config image.Config
BackgroundIndex byte
}

Options struct #

Options are the encoding parameters.

type Options struct {
NumColors int
Quantizer draw.Quantizer
Drawer draw.Drawer
}

blockReader struct #

blockReader parses the block structure of GIF image data, which comprises (n, (n bytes)) blocks, with 1 <= n <= 255. It is the reader given to the LZW decoder, which is thus immune to the blocking. After the LZW decoder completes, there will be a 0-byte block remaining (0, ()), which is consumed when checking that the blockReader is exhausted. To avoid the allocation of a bufio.Reader for the lzw Reader, blockReader implements io.ByteReader and buffers blocks into the decoder's "tmp" buffer.

type blockReader struct {
d *decoder
i uint8
j uint8
err error
}

blockWriter struct #

blockWriter writes the block structure of GIF image data, which comprises (n, (n bytes)) blocks, with 1 <= n <= 255. It is the writer given to the LZW encoder, which is thus immune to the blocking.

type blockWriter struct {
e *encoder
}

decoder struct #

decoder is the type used to decode a GIF file.

type decoder struct {
r reader
vers string
width int
height int
loopCount int
delayTime int
backgroundIndex byte
disposalMethod byte
imageFields byte
transparentIndex byte
hasTransparentIndex bool
globalColorTable color.Palette
delay []int
disposal []byte
image []*image.Paletted
tmp [1024]byte
}

encoder struct #

encoder encodes an image to the GIF format.

type encoder struct {
w writer
err error
g GIF
globalCT int
buf [256]byte
globalColorTable [*ast.BinaryExpr]byte
localColorTable [*ast.BinaryExpr]byte
}

interlaceScan struct #

interlaceScan defines the ordering for a pass of the interlace algorithm.

type interlaceScan struct {
skip int
start int
}

Functions

Decode function #

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

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

DecodeAll function #

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

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

DecodeConfig function #

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

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

Encode function #

Encode writes the Image m to w in GIF format.

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

EncodeAll function #

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

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

Flush method #

func (b blockWriter) Flush() error

Read method #

blockReader must implement io.Reader, but its Read shouldn't ever actually be called in practice. The compress/lzw package will only call [blockReader.ReadByte].

func (b *blockReader) Read(p []byte) (int, error)

ReadByte method #

func (b *blockReader) ReadByte() (byte, error)

Write method #

blockWriter must be an io.Writer for lzw.NewWriter, but this is never actually called.

func (b blockWriter) Write(data []byte) (int, error)

WriteByte method #

func (b blockWriter) WriteByte(c byte) error

close method #

func (b blockWriter) close()

close method #

close primarily detects whether or not a block terminator was encountered after reading a sequence of data sub-blocks. It allows at most one trailing sub-block worth of data. I.e., if some number of bytes exist in one sub-block following the end of LZW data, the very next sub-block must be the block terminator. If the very end of LZW data happened to fill one sub-block, at most one more sub-block of length 1 may exist before the block-terminator. These accommodations allow us to support GIFs created by less strict encoders. See https://golang.org/issue/16146.

func (b *blockReader) close() error

colorTablesMatch method #

func (e *encoder) colorTablesMatch(localLen int, transparentIndex int) bool

decode method #

decode reads a GIF image from r and stores the result in d.

func (d *decoder) decode(r io.Reader, configOnly bool, keepAllFrames bool) error

encodeColorTable function #

func encodeColorTable(dst []byte, p color.Palette, size int) (int, error)

fill method #

func (b *blockReader) fill()

flush method #

func (e *encoder) flush()

init function #

func init()

log2 function #

func log2(x int) int

newImageFromDescriptor method #

func (d *decoder) newImageFromDescriptor() (*image.Paletted, error)

readBlock method #

func (d *decoder) readBlock() (int, error)

readByte function #

func readByte(r io.ByteReader) (byte, error)

readColorTable method #

func (d *decoder) readColorTable(fields byte) (color.Palette, error)

readExtension method #

func (d *decoder) readExtension() error

readFull function #

func readFull(r io.Reader, b []byte) error

readGraphicControl method #

func (d *decoder) readGraphicControl() error

readHeaderAndScreenDescriptor method #

func (d *decoder) readHeaderAndScreenDescriptor() error

readImageDescriptor method #

func (d *decoder) readImageDescriptor(keepAllFrames bool) error

setup method #

func (b blockWriter) setup()

uninterlace function #

uninterlace rearranges the pixels in m to account for interlaced input.

func uninterlace(m *image.Paletted)

write method #

func (e *encoder) write(p []byte)

writeByte method #

func (e *encoder) writeByte(b byte)

writeHeader method #

func (e *encoder) writeHeader()

writeImageBlock method #

func (e *encoder) writeImageBlock(pm *image.Paletted, delay int, disposal byte)

Generated with Arrow