tiff

package module
v0.0.0-...-731dac7 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2019 License: BSD-3-Clause Imports: 16 Imported by: 0

README

tiff GoDoc

Go package for working with the TIFF file structure.

====

Documentation

Overview

Package tiff implements structures and functionality for working with TIFF data structures.

References:

[TIFF6]:         http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf
[TIFFPM6]:       http://partners.adobe.com/public/developer/en/tiff/TIFFPM6.pdf
[TIFFTAGS]:      http://www.digitalpreservation.gov/formats/content/tiff_tags.shtml

Index

Constants

View Source
const (
	MagicBigEndian        = "MM\x00\x2A"
	MagicLitEndian        = "II\x2A\x00"
	Version        uint16 = 0x2A
	VersionName    string = "TIFF"
)

These constants represents the first 4 bytes of the file for each kind of TIFF along with each byte ordering. This is mostly useful for registration with the "image" package from the Go standard library.

View Source
const (
	BigEndian uint16 = 0x4D4D // "MM" or 19789
	LitEndian uint16 = 0x4949 // "II" or 18761
)

These constants represent the byte order options present at the beginning of a TIFF file.

Variables

View Source
var (
	FTByte      = NewFieldType(1, "Byte", 1, false, reprByte, rvalByte, typByte)
	FTAscii     = NewFieldType(2, "ASCII", 1, false, reprASCII, rvalASCII, typString)
	FTShort     = NewFieldType(3, "Short", 2, false, reprShort, rvalShort, typU16)
	FTLong      = NewFieldType(4, "Long", 4, false, reprLong, rvalLong, typU32)
	FTRational  = NewFieldType(5, "Rational", 8, false, reprRational, rvalRational, typBigRat)
	FTSByte     = NewFieldType(6, "SByte", 1, true, reprSByte, rvalSByte, typI8)
	FTUndefined = NewFieldType(7, "Undefined", 1, false, reprByte, rvalByte, typByte)
	FTSShort    = NewFieldType(8, "SShort", 2, true, reprSShort, rvalSShort, typI16)
	FTSLong     = NewFieldType(9, "SLong", 4, true, reprSLong, rvalSLong, typI32)
	FTSRational = NewFieldType(10, "SRational", 8, true, reprSRational, rvalSRational, typBigRat)
	FTFloat     = NewFieldType(11, "Float", 4, true, reprFloat, rvalFloat, typF32)
	FTDouble    = NewFieldType(12, "Double", 8, true, reprDouble, rvalDouble, typF64)
	FTIFD       = NewFieldType(13, "IFD", 4, false, reprLong, rvalLong, typU32)

	// TODO: These two are not complete.  Get the details and finish them.
	FTUnicode = NewFieldType(14, "Unicode", 2, false, reprByte, rvalByte, typByte)
	FTComplex = NewFieldType(15, "Complex", 8, true, reprByte, rvalByte, typByte)
)

Default set of Field types. These are exported for others to use in registering custom tags.

View Source
var BaselineTags = NewTagSet("Baseline", 1, 64999)
View Source
var DefaultFieldTypeSet = NewFieldTypeSet("Default")

DefaultFieldTypeSet is the default set of field types supported by this package. A user is free to create their own FieldTypeSet from which to support extended functionality or to provide a substitute representation for known types. Most users will be fine with the default set defined here.

View Source
var DefaultFieldTypeSpace = NewFieldTypeSpace("Default")
View Source
var DefaultTagSpace = NewTagSpace("Default")
View Source
var ExtendedTags = NewTagSet("Extended", 1, 64999)
View Source
var PrivateTags = NewTagSet("Private", 32768, 65535)

Functions

func GetByteOrder

func GetByteOrder(bo uint16) binary.ByteOrder

func GetTiffFieldPrintFullFieldValue

func GetTiffFieldPrintFullFieldValue() bool

func ListTagSpaceNames

func ListTagSpaceNames() []string

func ParseTiffFieldStructTag

func ParseTiffFieldStructTag(text string) (out *fieldStructTag)

func ParseTiffIFDStructTag

func ParseTiffIFDStructTag(text string) *ifdStructTag

func ParseTiffStructTag

func ParseTiffStructTag(text string) *tiffStructTag

func ParseTiffSubIFDStructTag

func ParseTiffSubIFDStructTag(text string) *subIFDStructTag

func RegisterFieldTypeSet

func RegisterFieldTypeSet(fts FieldTypeSet)

RegisterFieldTypeSet registers a FieldTypeSet in the DefaultFieldTypeSpace. Only FieldTypes that would not cause collisions should be registered this way.

func RegisterFieldTypeSpace

func RegisterFieldTypeSpace(ftsp FieldTypeSpace)

func RegisterTagSet

func RegisterTagSet(ts TagSet)

RegisterTagSet registers a TagSet in the DefaultTagSpace. Only tags that would not cause collisions should be registered this way (i.e. GPS and MakerNote tags would cause collisions with the default tiff tag space.)

func RegisterTagSpace

func RegisterTagSpace(tsp TagSpace)

func RegisterVersion

func RegisterVersion(v uint16, tp TIFFParser)

func SetTiffFieldPrintFullFieldValue

func SetTiffFieldPrintFullFieldValue(b bool)

func UnmarshalIFD

func UnmarshalIFD(ifd IFD, out interface{}) error

func UnmarshalSubIFDs

func UnmarshalSubIFDs(ifd IFD, br BReader, tsp TagSpace, out interface{}) error

func UnmarshalTIFF

func UnmarshalTIFF(t TIFF, out interface{}) error

Types

type BReader

type BReader interface {
	BRead(data interface{}) error
	BReadSection(data interface{}, offset int64, n int64) error
	ByteOrder() binary.ByteOrder
	ReadAtReadSeeker
}

BReader wraps a ReadAtReadSeeker with a specific binary.ByteOrder.

func NewBReader

func NewBReader(r ReadAtReadSeeker, o binary.ByteOrder) BReader

type Entry

type Entry interface {
	TagID() uint16
	TypeID() uint16
	Count() uint32
	ValueOffset() [4]byte
}

Entry represents a single entry in an IFD in a TIFF file. This is the mostly uninterpreted core 12 byte data structure only.

func ParseEntry

func ParseEntry(br BReader) (out Entry, err error)

type ErrInvalidByteOrder

type ErrInvalidByteOrder struct {
	Order [2]byte
}

func (ErrInvalidByteOrder) Error

func (e ErrInvalidByteOrder) Error() string

type ErrUnsuppConversion

type ErrUnsuppConversion struct {
	From FieldType
	To   reflect.Type
}

func (ErrUnsuppConversion) Error

func (e ErrUnsuppConversion) Error() string

type ErrUnsuppStructField

type ErrUnsuppStructField struct {
	T       reflect.Type
	Field   int
	Problem string
}

func (ErrUnsuppStructField) Error

func (e ErrUnsuppStructField) Error() string

type ErrUnsuppTIFFVersion

type ErrUnsuppTIFFVersion struct {
	Version uint16
}

func (ErrUnsuppTIFFVersion) Error

func (e ErrUnsuppTIFFVersion) Error() string

type Field

type Field interface {
	Tag() Tag
	Type() FieldType
	Count() uint64
	Offset() uint64
	Value() FieldValue // TODO: Change to BReader??
}

Field represents a field in an IFD in a TIFF file.

func ParseField

func ParseField(br BReader, tsp TagSpace, ftsp FieldTypeSpace) (out Field, err error)

type FieldInterpreter

type FieldInterpreter func(Field) string

type FieldParser

type FieldParser func(BReader, TagSpace, FieldTypeSpace) (Field, error)

type FieldType

type FieldType interface {
	ID() uint16
	Name() string
	Size() uint64
	Signed() bool
	ReflectType() reflect.Type
	Repr() FieldTypeRepr
	Valuer() FieldTypeValuer
}

A FieldType represents all of the necessary pieces of information one needs to know about a field type including a function that knows how to represent that type of data in an often human readable string. Other string representation formats could be implemented (json, xml, etc). Field types themselves have no actual stored value inside a TIFF. They are here to help an implementer or user understand their format.

func NewFieldType

func NewFieldType(id uint16, name string, size uint64, signed bool, repr FieldTypeRepr, rval FieldTypeValuer, typ reflect.Type) FieldType

type FieldTypeRepr

type FieldTypeRepr func([]byte, binary.ByteOrder) string

type FieldTypeSet

type FieldTypeSet interface {
	GetFieldType(id uint16) (FieldType, bool)
	ListFieldTypes() []uint16
	ListFieldTypeNames() []string
	Name() string
	Register(ft FieldType) bool
	Lock()
}

FieldTypeSet represents a set of field types that may be in use within a file that uses a TIFF file structure. This can be customized for custom file formats and private IFDs.

func NewFieldTypeSet

func NewFieldTypeSet(name string) FieldTypeSet

type FieldTypeSpace

type FieldTypeSpace interface {
	Name() string
	GetFieldType(id uint16) FieldType
	GetFieldTypeSet(name string) (FieldTypeSet, bool)
	ListFieldTypeSets() []string
	RegisterFieldTypeSet(fts FieldTypeSet)
}

A FieldTypeSpace represents a group of FieldTypeSets where each of the FieldTypes from one FieldTypeSet should not collide with any of the FieldTypes from another FieldTypeSet.

func GetFieldTypeSpace

func GetFieldTypeSpace(name string) FieldTypeSpace

func NewFieldTypeSpace

func NewFieldTypeSpace(name string) FieldTypeSpace

type FieldTypeValuer

type FieldTypeValuer func([]byte, binary.ByteOrder) reflect.Value

type FieldValue

type FieldValue interface {
	Order() binary.ByteOrder
	Bytes() []byte
}
type Header interface {
	Order() string
	Version() uint16
	OffsetSize() uint16
	FirstOffset() uint64
}

type IFD

type IFD interface {
	NumEntries() uint64
	Fields() []Field
	NextOffset() uint64
	HasField(tagID uint16) bool
	GetField(tagID uint16) Field
}

IFD represents the data structure of an IFD in a TIFF File.

func ParseIFD

func ParseIFD(br BReader, offset uint64, tsp TagSpace, ftsp FieldTypeSpace) (out IFD, err error)

type IFDParser

type IFDParser func(br BReader, offset uint64, tsp TagSpace, ftsp FieldTypeSpace) (IFD, error)

type ReadAtReadSeeker

type ReadAtReadSeeker interface {
	io.ReadSeeker
	io.ReaderAt
}

ReadAtReadSeeker is the interface that wraps the Read, ReadAt, and Seek methods. Typical use cases would satisfy this with a bytes.Reader (in memory) or an os.File (on disk). For truly large files, such as BigTIFF, a user may want to create a custom solution that combines both in memory and on disk solutions for accessing the contents.

func NewReadAtReadSeeker

func NewReadAtReadSeeker(r io.Reader) ReadAtReadSeeker

NewReadAtReadSeeker converts r (an io.Reader) into a ReadAtReadSeeker. If the underlying type of r can satisfy a ReadAtReadSeeker, it is asserted as such and used directly instead of being wrapped.

type TIFF

type TIFF interface {
	Header
	IFDs() []IFD
	R() BReader
}

func Parse

func Parse(r ReadAtReadSeeker, tsp TagSpace, ftsp FieldTypeSpace) (TIFF, error)

func ParseTIFF

func ParseTIFF(ordr [2]byte, vers uint16, br BReader, tsp TagSpace, ftsp FieldTypeSpace) (out TIFF, err error)

type TIFFParser

type TIFFParser func(ordr [2]byte, vers uint16, br BReader, tsp TagSpace, ftsp FieldTypeSpace) (TIFF, error)

func GetVersionParser

func GetVersionParser(v uint16) TIFFParser

type Tag

type Tag interface {
	ID() uint16
	Name() string
	Interpreter() FieldInterpreter
}

func NewTag

func NewTag(id uint16, name string, fi FieldInterpreter) Tag

type TagSet

type TagSet interface {
	GetTag(id uint16) (Tag, bool)
	ListTags() []uint16
	ListTagNames() []string
	Name() string
	Register(t Tag) bool
	Lock()
}

func NewTagSet

func NewTagSet(name string, lower, upper uint16) TagSet

type TagSpace

type TagSpace interface {
	Name() string
	GetTag(id uint16) Tag
	GetTagSet(name string) (TagSet, bool)
	GetTagSetNameFromTag(id uint16) string
	ListTagSets() []string
	RegisterTagSet(ts TagSet)
}

A TagSpace represents a group of TagSet where each of the tags from one TagSet should not collide with any of the tags from another TagSet.

func GetTagSpace

func GetTagSpace(name string) TagSpace

func NewTagSpace

func NewTagSpace(name string) TagSpace

Directories

Path Synopsis
Package bigtiff implements structures and functionality for working with BigTIFF data structures.
Package bigtiff implements structures and functionality for working with BigTIFF data structures.
References: [GEOTIFF]: http://www.remotesensing.org/geotiff/spec/geotiffhome.html [INTERGRAPH]: http://www.awaresystems.be/imaging/tiff/tifftags/docs/intergraph.html
References: [GEOTIFF]: http://www.remotesensing.org/geotiff/spec/geotiffhome.html [INTERGRAPH]: http://www.awaresystems.be/imaging/tiff/tifftags/docs/intergraph.html
Package modi provides tiff extensions for working with Microsoft Office Document Imaging based tiff files.
Package modi provides tiff extensions for working with Microsoft Office Document Imaging based tiff files.
Package tiff85 provides parsing for a tiff file with a version number of 85.
Package tiff85 provides parsing for a tiff file with a version number of 85.

Jump to

Keyboard shortcuts

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