Help us shape the future of Go! Take the 2026 Go Developer Survey

tiff

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: BSD-3-Clause Imports: 17 Imported by: 85

README

tiff

This package extends golang.org/x/image/tiff with CCITT, LZW, JPEG, CMYK, and multi-page support. It originated in pdfcpu.

Compression support

Compression Decode Encode
Uncompressed Yes Yes
PackBits Yes No
Deflate, including the legacy tag when decoding Yes Yes
LZW Yes Yes
CCITT RLE (Modified Huffman) Yes No
CCITT Group 3 (1-D) and Group 4 Yes No
JPEG (compression 6 and 7) Yes No

CCITT decoding uses x/image/ccitt. Group 3 byte alignment is supported; Group 3 2-D and CCITT uncompressed modes are not. LZW decoding uses x/image/tiff/lzw, with encoding provided locally.

Images and pages

The package reads and writes 8-bit CMYK. It decodes unspecified four-component RGB as associated-alpha RGBA and handles padded edge tiles for packed and 16-bit samples.

Encode writes one image and EncodeAll writes multiple pages. Decode uses the first IFD; DecodeAt uses an IFD byte offset. Configuration variants follow the same rule. LZW and Deflate support horizontal prediction.

Decoder checks

Checked IFD counts, offsets, and block sizes bound parsing and decompression. JPEG frame dimensions must match their strip or tile. These checks do not impose an absolute image-size cap.

YCbCr JPEG decoding

YCbCr JPEG uses three interleaved 8-bit components and returns image.RGBA. Strips, tiles, complete streams, shared JPEGTables, and sequential Huffman frames with one interleaved scan are supported.

Subsampling [1,1], [2,1], and [2,2] is supported with centered chroma where applicable. Standard defaults apply to optional YCbCr fields. Missing ReferenceBlackWhite defaults to [0,255,128,255,128,255]; explicit values must match. Other compression, component layouts, color parameters, and JPEG processes return an error.

Documentation

Overview

Package tiff is an enhanced version of x/image/tiff.

It adds support for LZW compression and the CMYK color model.

More information: https://github.com/hhrutter/tiff

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

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

Decode reads a TIFF image from r and returns it as an image.Image. The type of Image returned depends on the contents of the TIFF.

func DecodeAt added in v1.0.2

func DecodeAt(r io.Reader, ifdOffset int64) (img image.Image, err error)

DecodeAt reads a TIFF image from r at ifdOffset and returns it as an image.Image. The type of Image returned depends on the contents of the TIFF.

func DecodeConfig

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

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

func DecodeConfigAt added in v1.0.2

func DecodeConfigAt(r io.Reader, ifdOffset int64) (image.Config, error)

DecodeConfigAt returns the color model and dimensions of a TIFF image at ifdOffset without decoding the entire image.

func Encode

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

Encode writes the image m to w. opt determines the options used for encoding, such as the compression type. If opt is nil, an uncompressed image is written.

func EncodeAll added in v1.0.4

func EncodeAll(w io.Writer, m []image.Image, opt *Options) error

EncodeAll writes the images in m to w as a multi-page TIFF. opt determines the options used for encoding each image, such as the compression type. If opt is nil, uncompressed images are written.

Types

type CompressionType

type CompressionType int

CompressionType describes the type of compression used in Options.

const (
	Uncompressed CompressionType = iota
	Deflate
	LZW
	CCITTGroup3
	CCITTGroup4
	JPEGOld
	JPEG
)

Constants for supported compression types.

type FormatError

type FormatError string

A FormatError reports that the input is not a valid TIFF image.

func (FormatError) Error

func (e FormatError) Error() string

type Options

type Options struct {
	// Compression is the type of compression used.
	Compression CompressionType
	// Predictor determines whether a differencing predictor is used;
	// if true, instead of each pixel's color, the color difference to the
	// preceding one is saved.  This improves the compression for certain
	// types of images and compressors. For example, it works well for
	// photos with Deflate compression.
	Predictor bool
}

Options are the encoding parameters.

type UnsupportedError

type UnsupportedError string

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

func (UnsupportedError) Error

func (e UnsupportedError) Error() string

Directories

Path Synopsis
internal
lzw
Package lzw implements the Lempel-Ziv-Welch variant used by TIFF.
Package lzw implements the Lempel-Ziv-Welch variant used by TIFF.

Jump to

Keyboard shortcuts

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