webp

package
v0.0.0-...-de82042 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package webp implements a lossless WebP encoder using the VP8L bitstream format.

The encoder supports spatial prediction, subtract-green, color transform, color cache, and near-lossless quantization. Output is compatible with libwebp's dwebp decoder and golang.org/x/image/webp.

Reference: "WebP Lossless Bitstream Specification" https://developers.google.com/speed/webp/docs/webp_lossless_bitstream_spec

Index

Constants

This section is empty.

Variables

View Source
var ErrNotImplemented = errors.New("webp: not implemented")

ErrNotImplemented reports unsupported features or code paths.

Functions

func Encode

func Encode(w io.Writer, img image.Image, opts *Options) error

Encode writes a lossless WebP bitstream for the given image.

func ValidateOptions

func ValidateOptions(opts *Options) error

ValidateOptions validates encoder options for basic ranges.

Types

type LZ77Mode

type LZ77Mode int

LZ77Mode selects the match-finding strategy.

const (
	// LZ77ModeAuto picks the default match-finding strategy.
	LZ77ModeAuto LZ77Mode = iota
	// LZ77ModeNaive uses the simple O(n*window) matcher.
	LZ77ModeNaive
	// LZ77ModeHash uses a hashed ring buffer for match candidates.
	LZ77ModeHash
)

type Options

type Options struct {
	// UsePredictor enables spatial prediction transform.
	UsePredictor bool
	// UseColorTransform enables the color transform.
	UseColorTransform bool
	// UseSubtractGreen enables the subtract-green transform.
	UseSubtractGreen bool
	// UseColorCache enables color cache with the given size (0 disables).
	ColorCacheBits int
	// Auto selects transforms based on image content.
	Auto bool
	// NearLossless sets near-lossless quality in [0..100], 0 disables.
	NearLossless int
	// HuffmanGroupBits controls meta Huffman groups (0 disables).
	HuffmanGroupBits int
	// LZ77Mode selects the match-finding strategy.
	LZ77Mode LZ77Mode
	// LZ77HashBits controls hash table size for LZ77ModeHash.
	LZ77HashBits int
	// LZ77Chain controls candidate count per hash bucket for LZ77ModeHash.
	LZ77Chain int
}

Options defines encoder behavior.

func AutoOptions

func AutoOptions(img image.Image) Options

AutoOptions picks a simple, deterministic transform set based on image content.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns a sensible baseline for lossless encoding. Enables all three transforms (predictor, color, subtract-green) which works well on photographic content.

Jump to

Keyboard shortcuts

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