consts.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. tStripOffsets = 273
  38. tSamplesPerPixel = 277
  39. tRowsPerStrip = 278
  40. tStripByteCounts = 279
  41. tTileWidth = 322
  42. tTileLength = 323
  43. tTileOffsets = 324
  44. tTileByteCounts = 325
  45. tXResolution = 282
  46. tYResolution = 283
  47. tResolutionUnit = 296
  48. tPredictor = 317
  49. tColorMap = 320
  50. tExtraSamples = 338
  51. tSampleFormat = 339
  52. )
  53. // Compression types (defined in various places in the spec and supplements).
  54. const (
  55. cNone = 1
  56. cCCITT = 2
  57. cG3 = 3 // Group 3 Fax.
  58. cG4 = 4 // Group 4 Fax.
  59. cLZW = 5
  60. cJPEGOld = 6 // Superseded by cJPEG.
  61. cJPEG = 7
  62. cDeflate = 8 // zlib compression.
  63. cPackBits = 32773
  64. cDeflateOld = 32946 // Superseded by cDeflate.
  65. )
  66. // Photometric interpretation values (see p. 37 of the spec).
  67. const (
  68. pWhiteIsZero = 0
  69. pBlackIsZero = 1
  70. pRGB = 2
  71. pPaletted = 3
  72. pTransMask = 4 // transparency mask
  73. pCMYK = 5
  74. pYCbCr = 6
  75. pCIELab = 8
  76. )
  77. // Values for the tPredictor tag (page 64-65 of the spec).
  78. const (
  79. prNone = 1
  80. prHorizontal = 2
  81. )
  82. // Values for the tResolutionUnit tag (page 18).
  83. const (
  84. resNone = 1
  85. resPerInch = 2 // Dots per inch.
  86. resPerCM = 3 // Dots per centimeter.
  87. )
  88. // imageMode represents the mode of the image.
  89. type imageMode int
  90. const (
  91. mBilevel imageMode = iota
  92. mPaletted
  93. mGray
  94. mGrayInvert
  95. mRGB
  96. mRGBA
  97. mNRGBA
  98. )
  99. // CompressionType describes the type of compression used in Options.
  100. type CompressionType int
  101. const (
  102. Uncompressed CompressionType = iota
  103. Deflate
  104. )
  105. // specValue returns the compression type constant from the TIFF spec that
  106. // is equivalent to c.
  107. func (c CompressionType) specValue() uint32 {
  108. switch c {
  109. case Deflate:
  110. return cDeflate
  111. }
  112. return cNone
  113. }