consts.go 3.3 KB

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