tiff

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: BSD-3-Clause Imports: 13 Imported by: 36

README

Note

This package is an improved version of x/image/tiff featuring:

  • Read support for CCITT Group3/4 compressed images using x/image/ccitt
  • Read/write support for LZW compressed images using github.com/hhrutter/lzw
  • Read/write support for the CMYK color model.

Background

Working on pdfcpu (a PDF processor) created a need for processing TIFF files and LZW compression in details beyond the standard library.

  1. CCITT compression for monochrome images was the first need. This is being addressed as part of ongoing work on x/image/ccitt.

  2. As stated in this golang proposal Go LZW implementations are spread out over the standard library at compress/lzw and x/image/tiff/lzw. As of Go 1.12 compress/lzw works reliably for GIF only. This is also the reason the TIFF package at x/image/tiff provides its own lzw implementation for compression. With PDF there is a third variant of lzw needed for reading/writing lzw compressed PDF object streams and processing embedded TIFF images. github.com/hhrutter/lzw fills this gap. It is an extended version of compress/lzw supporting GIF, PDF and TIFF.

  3. The PDF specification defines a CMYK color space. This is currently not supported at x/image/tiff.

Goal

An improved version of x/image/tiff with full read/write support for CCITT, LZW compression and the CMYK color model.

Documentation

Overview

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

It uses a consolidated version of compress/lzw (https://github.com/hhrutter/lzw) for compression and also adds support for CMYK.

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 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 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.

Types

type CompressionType

type CompressionType int

CompressionType describes the type of compression used in Options.

const (
	Uncompressed CompressionType = iota
	Deflate
	LZW
	CCITTGroup3
	CCITTGroup4
)

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

Jump to

Keyboard shortcuts

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