consts.go

  1// Copyright 2011 The Go Authors. All rights reserved.
  2// Use of this source code is governed by a BSD-style
  3// license that can be found in the LICENSE file.
  4
  5package tiff
  6
  7// A tiff image file contains one or more images. The metadata
  8// of each image is contained in an Image File Directory (IFD),
  9// which contains entries of 12 bytes each and is described
 10// on page 14-16 of the specification. An IFD entry consists of
 11//
 12//  - a tag, which describes the signification of the entry,
 13//  - the data type and length of the entry,
 14//  - the data itself or a pointer to it if it is more than 4 bytes.
 15//
 16// The presence of a length means that each IFD is effectively an array.
 17
 18const (
 19	leHeader = "II\x2A\x00" // Header for little-endian files.
 20	beHeader = "MM\x00\x2A" // Header for big-endian files.
 21
 22	ifdLen = 12 // Length of an IFD entry in bytes.
 23)
 24
 25// Data types (p. 14-16 of the spec).
 26const (
 27	dtByte     = 1
 28	dtASCII    = 2
 29	dtShort    = 3
 30	dtLong     = 4
 31	dtRational = 5
 32)
 33
 34// The length of one instance of each data type in bytes.
 35var lengths = [...]uint32{0, 1, 1, 2, 4, 8}
 36
 37// Tags (see p. 28-41 of the spec).
 38const (
 39	tImageWidth                = 256
 40	tImageLength               = 257
 41	tBitsPerSample             = 258
 42	tCompression               = 259
 43	tPhotometricInterpretation = 262
 44
 45	tFillOrder = 266
 46
 47	tStripOffsets    = 273
 48	tSamplesPerPixel = 277
 49	tRowsPerStrip    = 278
 50	tStripByteCounts = 279
 51
 52	tT4Options = 292 // CCITT Group 3 options, a set of 32 flag bits.
 53	tT6Options = 293 // CCITT Group 4 options, a set of 32 flag bits.
 54
 55	tTileWidth      = 322
 56	tTileLength     = 323
 57	tTileOffsets    = 324
 58	tTileByteCounts = 325
 59
 60	tXResolution    = 282
 61	tYResolution    = 283
 62	tResolutionUnit = 296
 63
 64	tPredictor    = 317
 65	tColorMap     = 320
 66	tExtraSamples = 338
 67	tSampleFormat = 339
 68)
 69
 70// Compression types (defined in various places in the spec and supplements).
 71const (
 72	cNone       = 1
 73	cCCITT      = 2
 74	cG3         = 3 // Group 3 Fax.
 75	cG4         = 4 // Group 4 Fax.
 76	cLZW        = 5
 77	cJPEGOld    = 6 // Superseded by cJPEG.
 78	cJPEG       = 7
 79	cDeflate    = 8 // zlib compression.
 80	cPackBits   = 32773
 81	cDeflateOld = 32946 // Superseded by cDeflate.
 82)
 83
 84// Photometric interpretation values (see p. 37 of the spec).
 85const (
 86	pWhiteIsZero = 0
 87	pBlackIsZero = 1
 88	pRGB         = 2
 89	pPaletted    = 3
 90	pTransMask   = 4 // transparency mask
 91	pCMYK        = 5
 92	pYCbCr       = 6
 93	pCIELab      = 8
 94)
 95
 96// Values for the tPredictor tag (page 64-65 of the spec).
 97const (
 98	prNone       = 1
 99	prHorizontal = 2
100)
101
102// Values for the tResolutionUnit tag (page 18).
103const (
104	resNone    = 1
105	resPerInch = 2 // Dots per inch.
106	resPerCM   = 3 // Dots per centimeter.
107)
108
109// imageMode represents the mode of the image.
110type imageMode int
111
112const (
113	mBilevel imageMode = iota
114	mPaletted
115	mGray
116	mGrayInvert
117	mRGB
118	mRGBA
119	mNRGBA
120	mCMYK
121)
122
123// CompressionType describes the type of compression used in Options.
124type CompressionType int
125
126// Constants for supported compression types.
127const (
128	Uncompressed CompressionType = iota
129	Deflate
130	LZW
131	CCITTGroup3
132	CCITTGroup4
133)
134
135// specValue returns the compression type constant from the TIFF spec that
136// is equivalent to c.
137func (c CompressionType) specValue() uint32 {
138	switch c {
139	case LZW:
140		return cLZW
141	case Deflate:
142		return cDeflate
143	case CCITTGroup3:
144		return cG3
145	case CCITTGroup4:
146		return cG4
147	}
148	return cNone
149}