tiff

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2016 License: BSD-2-Clause, AGPL-3.0, Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package tiff implements TIFF decoding as defined in TIFF 6.0 specification at http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf

Index

Constants

View Source
const (
	DTByte      DataType = 1
	DTAscii              = 2
	DTShort              = 3
	DTLong               = 4
	DTRational           = 5
	DTSByte              = 6
	DTUndefined          = 7
	DTSShort             = 8
	DTSLong              = 9
	DTSRational          = 10
	DTFloat              = 11
	DTDouble             = 12
)

Variables

View Source
var ErrShortReadTagValue = errors.New("tiff: short read of tag value")

Functions

This section is empty.

Types

type DataType

type DataType uint16

DataType represents the basic tiff tag data types.

type Dir

type Dir struct {
	Tags []*Tag
}

Dir provides access to the parsed content of a tiff Image File Directory (IFD).

func DecodeDir

func DecodeDir(r ReadAtReader, order binary.ByteOrder) (d *Dir, offset int32, err error)

DecodeDir parses a tiff-encoded IFD from r and returns a Dir object. offset is the offset to the next IFD. The first read from r should be at the first byte of the IFD. ReadAt offsets should generally be relative to the beginning of the tiff structure (not relative to the beginning of the IFD).

func (*Dir) String

func (d *Dir) String() string

type Format

type Format int

Format specifies the Go type equivalent used to represent the basic tiff data types.

const (
	IntVal Format = iota
	FloatVal
	RatVal
	StringVal
	UndefVal
	OtherVal
)

type ReadAtReader

type ReadAtReader interface {
	io.Reader
	io.ReaderAt
}

ReadAtReader is used when decoding Tiff tags and directories

type Tag

type Tag struct {
	// Id is the 2-byte tiff tag identifier.
	Id uint16
	// Type is an integer (1 through 12) indicating the tag value's data type.
	Type DataType
	// Count is the number of type Type stored in the tag's value (i.e. the
	// tag's value is an array of type Type and length Count).
	Count uint32
	// Val holds the bytes that represent the tag's value.
	Val []byte
	// ValOffset holds byte offset of the tag value w.r.t. the beginning of the
	// reader it was decoded from. Zero if the tag value fit inside the offset
	// field.
	ValOffset uint32
	// contains filtered or unexported fields
}

Tag reflects the parsed content of a tiff IFD tag.

func DecodeTag

func DecodeTag(r ReadAtReader, order binary.ByteOrder) (*Tag, error)

DecodeTag parses a tiff-encoded IFD tag from r and returns a Tag object. The first read from r should be the first byte of the tag. ReadAt offsets should generally be relative to the beginning of the tiff structure (not relative to the beginning of the tag).

func (*Tag) Float

func (t *Tag) Float(i int) (float64, error)

Float returns the tag's i'th value as a float. It returns an error if the tag's Format is not IntVal. It panics if i is out of range.

func (*Tag) Format

func (t *Tag) Format() Format

Format returns a value indicating which method can be called to retrieve the tag's value properly typed (e.g. integer, rational, etc.).

func (*Tag) Int

func (t *Tag) Int(i int) (int, error)

Int returns the tag's i'th value as an integer. It returns an error if the tag's Format is not IntVal. It panics if i is out of range.

func (*Tag) Int64

func (t *Tag) Int64(i int) (int64, error)

Int64 returns the tag's i'th value as an integer. It returns an error if the tag's Format is not IntVal. It panics if i is out of range.

func (*Tag) MarshalJSON

func (t *Tag) MarshalJSON() ([]byte, error)

func (*Tag) Rat

func (t *Tag) Rat(i int) (*big.Rat, error)

Rat returns the tag's i'th value as a rational number. It returns a nil and an error if this tag's Format is not RatVal. It panics for zero deminators or if i is out of range.

func (*Tag) Rat2

func (t *Tag) Rat2(i int) (num, den int64, err error)

Rat2 returns the tag's i'th value as a rational number represented by a numerator-denominator pair. It returns an error if the tag's Format is not RatVal. It panics if i is out of range.

func (*Tag) String

func (t *Tag) String() string

String returns a nicely formatted version of the tag.

func (*Tag) StringVal

func (t *Tag) StringVal() (string, error)

StringVal returns the tag's value as a string. It returns an error if the tag's Format is not StringVal. It panics if i is out of range.

type Tiff

type Tiff struct {
	// Dirs is an ordered slice of the tiff's Image File Directories (IFDs).
	// The IFD at index 0 is IFD0.
	Dirs []*Dir
	// The tiff's byte-encoding (i.e. big/little endian).
	Order binary.ByteOrder
}

Tiff provides access to a decoded tiff data structure.

func Decode

func Decode(r io.Reader) (*Tiff, error)

Decode parses tiff-encoded data from r and returns a Tiff struct that reflects the structure and content of the tiff data. The first read from r should be the first byte of the tiff-encoded data and not necessarily the first byte of an os.File object.

func (*Tiff) String

func (tf *Tiff) String() string

Jump to

Keyboard shortcuts

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