Project

General

Profile

The Metadata in TIFF files » History » Version 8

Robin Mills, 12 Nov 2016 17:35

1 1 Robin Mills
h1. The Metadata in TIFF files
2
3
The Tagged Image File Format is a container.  It's very flexible and can deal with multiple pages, different colour spaces, frame configurations as well as metadata.  The specification is available from:  https://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf
4
5 5 Robin Mills
!Tiff2.png!
6 3 Robin Mills
7 8 Robin Mills
The format consists of an 8 byte header which provides a 2 byte endian flag (II or MM), a 2 byte type "magic number" (42) and a 4 byte offset to an _*Image File Directory*_.
8
9
The _*IFD*_ _(Image File Directory)_  has a two byte header which contains the length of the directory followed by 12 byte field or "tag".  The trailing 4 bytes of the the directory is always the offset to the next dictionary _*or*_ zero to terminate the directory chain.
10 1 Robin Mills
11 7 Robin Mills
A tag consists of a 12 byte record: TagID, TagType, Count and Offset which are 2,2,4 and 4 bytes respectively.  The TagID defines the purpose of the record (Width, Height, ColorSpace etc) and the TagType defines the data format.  Count and Offset are used to contain the raw data _*or*_ provide an offset in the file at which to read the raw data for this tag.
12 1 Robin Mills
13 7 Robin Mills
This is described in the specification.  The code in tiff image.cpp/ TiffImage::printStructure() decodes the dictionaries.
14 1 Robin Mills
15
The TIFF container is so flexible it is used as the structure for most RAW formats including Adobe's DNG.  Additionally the TIFF container is used to store the metadata that lies inside the Exif blocks embedded in JPEG and PNG files.
16 7 Robin Mills
17
There is a 64bit version of Tiff called _*BigTiff*_. This is currently not supported by exiv2.
18 1 Robin Mills
19
*Example:*
20 4 Robin Mills
The version of exiv2(.exe) which ships with v0.25 provides options _*<code>-pS</code>*_ to reveals the structure of the TIFF and option _*<code>-pX</code>*_ is used to extract the raw XMP/xml data.  The option -pa is used to print the metadata in human readable format.<pre>$ exiv2 -pa ~/tif
21 1 Robin Mills
Exif.Image.ImageWidth                        Short       1  40
22
Exif.Image.ImageLength                       Short       1  470
23
Exif.Image.BitsPerSample                     Short       3  8 8 8
24
Exif.Image.Compression                       Short       1  LZW
25
Exif.Image.PhotometricInterpretation         Short       1  RGB
26
Exif.Image.StripOffsets                      Long        1  2694
27
Exif.Image.Orientation                       Short       1  right, top
28
Exif.Image.SamplesPerPixel                   Short       1  3
29
Exif.Image.RowsPerStrip                      Short       1  1092
30
Exif.Image.StripByteCounts                   Long        1  5086
31
Exif.Image.PlanarConfiguration               Short       1  1
32
Exif.Image.Predictor                         Short       1  Horizontal differencing
33
Exif.Image.SampleFormat                      Short       3  Unsigned integer data
34
Exif.Image.XMLPacket                         Byte      2500  (Binary value suppressed)
35
Xmp.dc.title                                 LangAlt     1  lang="x-default" this is a title
36
/Users/rmills/tif: (No IPTC data found in the file)
37
$ exiv2 -pS ~/tif
38
STRUCTURE OF TIFF FILE: /Users/rmills/tif
39
 address |    tag                      |      type |    count |   offset | value
40
      10 | 0x0100 ImageWidth           |     SHORT |        1 |  2621440 | 40
41
      22 | 0x0101 ImageLength          |     SHORT |        1 | 30801920 | 470
42
      34 | 0x0102 BitsPerSample        |     SHORT |        3 |      182 | 
43
      46 | 0x0103 Compression          |     SHORT |        1 |   327680 | 5
44
      58 | 0x0106 PhotometricInterpret |     SHORT |        1 |   131072 | 2
45
      70 | 0x0111 StripOffsets         |      LONG |        1 |     2694 | 0
46
      82 | 0x0112 Orientation          |     SHORT |        1 |   393216 | 6
47
      94 | 0x0115 SamplesPerPixel      |     SHORT |        1 |   196608 | 3
48
     106 | 0x0116 RowsPerStrip         |     SHORT |        1 | 71565312 | 1092
49
     118 | 0x0117 StripByteCounts      |      LONG |        1 |     5086 | 0
50
     130 | 0x011c PlanarConfiguration  |     SHORT |        1 |    65536 | 1
51
     142 | 0x013d Predictor            |     SHORT |        1 |   131072 | 2
52
     154 | 0x0153 SampleFormat         |     SHORT |        3 |      188 | 
53
     166 | 0x02bc XMLPacket            |      BYTE |     2500 |      194 | <?xpacket begin="..." id="W5M0Mp ...
54
$ exiv2 -pX ~/tif | xmllint -pretty 1 -
55
<?xml version="1.0"?>
56
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
57
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 4.4.0-Exiv2">
58
  <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
59
    <rdf:Description xmlns:dc="http://purl.org/dc/elements/1.1/" rdf:about="">
60
      <dc:title>
61
        <rdf:Alt>
62
          <rdf:li xml:lang="x-default">this is a title</rdf:li>
63
        </rdf:Alt>
64
      </dc:title>
65
    </rdf:Description>
66
  </rdf:RDF>
67
</x:xmpmeta>
68
<?xpacket end="w"?>
69
855 rmills@rmillsmbp:~/Documents/exiv2 $ </pre>
70
71 2 Robin Mills
You can clearly see the XMLPacket is stored at offset 194 into the file and consists of 2500 bytes.   You can of course directly extract the XMP with the following command which says:  set the block size to 1 byte, skip 194 bytes and dump the next 2500 bytes:<pre>863 rmills@rmillsmbp:~/Documents/exiv2 $ dd bs=1 skip=194 count=2500 if=~/tif  | xmllint -pretty 1 -
72 1 Robin Mills
2500+0 records in
73
2500+0 records out
74
2500 bytes transferred in 0.005714 secs (437526 bytes/sec)
75
<?xml version="1.0"?>
76
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
77
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 4.4.0-Exiv2">
78
  <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
79
    <rdf:Description xmlns:dc="http://purl.org/dc/elements/1.1/" rdf:about="">
80
      <dc:title>
81
        <rdf:Alt>
82
          <rdf:li xml:lang="x-default">this is a title</rdf:li>
83
        </rdf:Alt>
84
      </dc:title>
85
    </rdf:Description>
86
  </rdf:RDF>
87
</x:xmpmeta>
88
<?xpacket end="w"?>
89 4 Robin Mills
864 rmills@rmillsmbp:~/Documents/exiv2 $ </pre>The option _*<code>-pX</code>*_ doesn't actually use dd to achieve the same result and is much more convenient to use.
90 2 Robin Mills
91
To demonstrate that the metadata block in a JPEG is a TIFF file, extract and print the structure.<pre>$ exiv2 -pS ~/jpg 
92
STRUCTURE OF JPEG FILE: /Users/rmills/jpg
93
 address | marker     | length  | data
94
       2 | 0xd8 SOI  
95
       4 | 0xe1 APP1  |   14862 | Exif..II*.....................
96
   14868 | 0xe1 APP1  |    2720 | http://ns.adobe.com/xap/1.0/.<
97
   17590 | 0xed APP13 |     110 | Photoshop 3.0.8BIM.......6....
98
   17702 | 0xe2 APP2  |    4094 | MPF.II*...............0100....
99
   21798 | 0xdb DQT   |     132 
100
   21932 | 0xc0 SOF0  |      17 
101
   21951 | 0xc4 DHT   |     418 
102
   22371 | 0xda SOS   |      12 
103
$ dd bs=1 skip=12 count=14862 if=~/jpg of=bull.tif
104
14862+0 records in
105
14862+0 records out
106
14862 bytes transferred in 0.038783 secs (383211 bytes/sec)
107
$ exiv2 -pS bull.tif
108
STRUCTURE OF TIFF FILE: bull.tif
109
 address |    tag                      |      type |    count |   offset | value
110
      10 | 0x010f Make                 |     ASCII |       18 |      134 | NIKON CORPORATION.
111
      22 | 0x0110 Model                |     ASCII |       12 |      152 | NIKON D5300.
112
      34 | 0x0112 Orientation          |     SHORT |        1 |        1 | 1
113
      46 | 0x011a XResolution          |  RATIONAL |        1 |      164 | 
114
      58 | 0x011b YResolution          |  RATIONAL |        1 |      172 | 
115
      70 | 0x0128 ResolutionUnit       |     SHORT |        1 |        2 | 2
116
      82 | 0x0131 Software             |     ASCII |       10 |      180 | Ver.1.00 .
117
      94 | 0x0132 DateTime             |     ASCII |       20 |      190 | 2015:02:13 20:46:51.
118
     106 | 0x0213 YCbCrPositioning     |     SHORT |        1 |        1 | 1
119
     118 | 0x8769 ExifTag              |      LONG |        1 |      210 | 210
120
    4080 | 0x0103 Compression          |     SHORT |        1 |        6 | 6
121
    4092 | 0x011a XResolution          |  RATIONAL |        1 |     4168 | 
122
    4104 | 0x011b YResolution          |  RATIONAL |        1 |     4176 | 
123 1 Robin Mills
    4116 | 0x0128 ResolutionUnit       |     SHORT |        1 |        2 | 2
124
    4128 | 0x0201 JPEGInterchangeForma |      LONG |        1 |     4184 | 4184
125
    4140 | 0x0202 JPEGInterchangeForma |      LONG |        1 |    10670 | 10670
126
    4152 | 0x0213 YCbCrPositioning     |     SHORT |        1 |        1 | 1
127 6 Robin Mills
$ </pre>The version of the exiv2 command-line program that ships with v0.26 later has an option _*<code>-pR</code>*_ with recursively prints the structure of an image file.  By *_recursive*_ we mean  the utility will print the structures while reside inside other structures.  For example, the Exif metadata in a JPEG is a encoded as a TIFF embedded in the file.  <pre>543 rmills@rmillsmbp:~/gnu/exiv2/trunk $ exiv2 -pR test/data/Reagan.jpg 
128 4 Robin Mills
STRUCTURE OF JPEG FILE: test/data/Reagan.jpg
129
 address | marker       |  length | data
130
       0 | 0xffd8 SOI  
131
       2 | 0xffe1 APP1  |    5718 | Exif..MM.*......................
132
  STRUCTURE OF TIFF FILE (MM): MemIo
133
   address |    tag                           |      type |    count |    offset | value
134
        10 | 0x0100 ImageWidth                |     SHORT |        1 |  13107200 | 200
135
        22 | 0x0101 ImageLength               |     SHORT |        1 |   8519680 | 130
136
        34 | 0x0102 BitsPerSample             |     SHORT |        4 |       242 | 8 8 8 8
137
        46 | 0x0103 Compression               |     SHORT |        1 |     65536 | 1
138
        58 | 0x0106 PhotometricInterpretation |     SHORT |        1 |    131072 | 2
139
        70 | 0x010e ImageDescription          |     ASCII |      403 |       250 | 040621-N-6536T-062.USS Ronald Re ...
140
        82 | 0x010f Make                      |     ASCII |       18 |       653 | NIKON CORPORATION
141
        94 | 0x0110 Model                     |     ASCII |       10 |       671 | NIKON D1X
142
       106 | 0x0112 Orientation               |     SHORT |        1 |     65536 | 1
143
       118 | 0x0115 SamplesPerPixel           |     SHORT |        1 |    262144 | 4
144
       130 | 0x011a XResolution               |  RATIONAL |        1 |       681 | 681/0
145
       142 | 0x011b YResolution               |  RATIONAL |        1 |       689 | 689/0
146
       154 | 0x011c PlanarConfiguration       |     SHORT |        1 |     65536 | 1
147
       166 | 0x0128 ResolutionUnit            |     SHORT |        1 |    131072 | 2
148
       178 | 0x0131 Software                  |     ASCII |       40 |       697 | Adobe Photoshop Elements 12.0 Ma ...
149
       190 | 0x0132 DateTime                  |     ASCII |       20 |       737 | 2016:09:13 11:58:16
150
       202 | 0x013b Artist                    |     ASCII |       34 |       757 | Photographer..s Mate 3rd Class ( ...
151
       214 | 0x8769 ExifTag                   |      LONG |        1 |       792 | 792
152
    STRUCTURE OF TIFF FILE (MM): MemIo
153
     address |    tag                           |      type |    count |    offset | value
154
         794 | 0x829a ExposureTime              |  RATIONAL |        1 |      1254 | 1254/0
155
         806 | 0x829d FNumber                   |  RATIONAL |        1 |      1262 | 1262/0
156
         818 | 0x8822 ExposureProgram           |     SHORT |        1 |     65536 | 1
157
         830 | 0x9000 ExifVersion               | UNDEFINED |        4 | 808596016 | 0220
158
         842 | 0x9003 DateTimeOriginal          |     ASCII |       20 |      1270 | 2004:06:21 23:37:53
159
         854 | 0x9004 DateTimeDigitized         |     ASCII |       20 |      1290 | 2004:06:21 23:37:53
160
         866 | 0x9101 ComponentsConfiguration   | UNDEFINED |        4 |  16909056 | ...
161
         878 | 0x9102 CompressedBitsPerPixel    |  RATIONAL |        1 |      1310 | 1310/0
162
         890 | 0x9201 ShutterSpeedValue         | SRATIONAL |        1 |      1318 | 1318/0
163
         902 | 0x9202 ApertureValue             |  RATIONAL |        1 |      1326 | 1326/0
164
         914 | 0x9204 ExposureBiasValue         | SRATIONAL |        1 |      1334 | 1334/0
165
         926 | 0x9205 MaxApertureValue          |  RATIONAL |        1 |      1342 | 1342/0
166
         938 | 0x9207 MeteringMode              |     SHORT |        1 |    131072 | 2
167
         950 | 0x9208 LightSource               |     SHORT |        1 |    655360 | 10
168
         962 | 0x9209 Flash                     |     SHORT |        1 |         0 | 0
169
         974 | 0x920a FocalLength               |  RATIONAL |        1 |      1350 | 1350/0
170
         986 | 0x9290 SubSecTime                |     ASCII |        3 | 808845312 | 06
171
         998 | 0x9291 SubSecTimeOriginal        |     ASCII |        3 | 808845312 | 06
172
        1010 | 0x9292 SubSecTimeDigitized       |     ASCII |        3 | 808845312 | 06
173
        1022 | 0xa000 FlashpixVersion           | UNDEFINED |        4 | 808529968 | 0100
174
        1034 | 0xa001 ColorSpace                |     SHORT |        1 |4294901760 | 65535
175
        1046 | 0xa002 PixelXDimension           |      LONG |        1 |       200 | 200
176
        1058 | 0xa003 PixelYDimension           |      LONG |        1 |       130 | 130
177
        1070 | 0xa217 SensingMethod             |     SHORT |        1 |    131072 | 2
178
        1082 | 0xa300 FileSource                | UNDEFINED |        1 |  50331648 | .
179
        1094 | 0xa301 SceneType                 | UNDEFINED |        1 |  16777216 | .
180
        1106 | 0xa401 CustomRendered            |     SHORT |        1 |         0 | 0
181
        1118 | 0xa402 ExposureMode              |     SHORT |        1 |     65536 | 1
182
        1130 | 0xa403 WhiteBalance              |     SHORT |        1 |     65536 | 1
183
        1142 | 0xa404 DigitalZoomRatio          |  RATIONAL |        1 |      1358 | 1358/0
184
        1154 | 0xa405 FocalLengthIn35mmFilm     |     SHORT |        1 |   4128768 | 63
185
        1166 | 0xa406 SceneCaptureType          |     SHORT |        1 |         0 | 0
186
        1178 | 0xa407 GainControl               |     SHORT |        1 |         0 | 0
187
        1190 | 0xa408 Contrast                  |     SHORT |        1 |         0 | 0
188
        1202 | 0xa409 Saturation                |     SHORT |        1 |         0 | 0
189
        1214 | 0xa40a Sharpness                 |     SHORT |        1 |         0 | 0
190
        1226 | 0xa40c SubjectDistanceRange      |     SHORT |        1 |         0 | 0
191
        1238 | 0xa420 ImageUniqueID             |     ASCII |       33 |      1366 | 127c1377b054a3f65bf2754ebb24e7f2 ...
192
    END MemIo
193
       226 | 0x8825 GPSTag                    |      LONG |        1 |      1400 | 1400
194
      1422 | 0x0103 Compression               |     SHORT |        1 |    393216 | 6
195
      1434 | 0x011a XResolution               |  RATIONAL |        1 |      1498 | 1498/0
196
      1446 | 0x011b YResolution               |  RATIONAL |        1 |      1506 | 1506/0
197
      1458 | 0x0128 ResolutionUnit            |     SHORT |        1 |    131072 | 2
198
      1470 | 0x0201 JPEGInterchangeFormat     |      LONG |        1 |      1514 | 1514
199
      1482 | 0x0202 JPEGInterchangeFormatLeng |      LONG |        1 |      4196 | 4196
200
  END MemIo
201
    5722 | 0xffed APP13 |    3038 | Photoshop 3.0.8BIM..........Z...
202
  Record | DataSet | Name                     | Length | Data
203
       1 |      90 | CharacterSet             |      3 | .%G
204
       1 |      90 | CharacterSet             |      3 | .%G
205
       2 |       0 | RecordVersion            |      2 | ..
206
       2 |     120 | Caption                  |    402 | 040621-N-6536T-062.USS Ronald Reagan (CV...
207
       2 |     122 | Writer                   |      9 | Dir. NVNS
208
       2 |      40 | SpecialInstructions      |     49 | Credit as U.S. Navy photo by Elizabeth T...
209
       2 |      80 | Byline                   |     32 | Photographer..s Mate 3rd Class (
210
       2 |      85 | BylineTitle              |     21 | U.S Navy Photographer
211
       2 |     110 | Credit                   |      8 | U.S Navy
212
       2 |     115 | Source                   |     24 | Navy Visual News Service
213
       2 |       5 | ObjectName               |     18 | 040621-N-6536T-062
214
       2 |      55 | DateCreated              |      8 | 20040621
215
       2 |      60 | TimeCreated              |     11 | 000000+0000
216
       2 |      62 | DigitizationDate         |      8 | 20040621
217
       2 |      63 | DigitizationTime         |     11 | 233753-0400
218
       2 |      90 | City                     |     19 | Straits of Magellan
219
       2 |     101 | CountryName              |     13 | South America
220
       2 |      15 | Category                 |      1 | N
221
       2 |      20 | SuppCategory             |     12 | 703-614-9154
222
       2 |      20 | SuppCategory             |     23 | navyvisualnews@navy.mil
223
       2 |      20 | SuppCategory             |     11 | UNCLASSFIED
224
       2 |      10 | Urgency                  |      1 | 5
225
       2 |      25 | Keywords                 |     13 | ronald reagan
226
       2 |      25 | Keywords                 |      6 | reagan
227
       2 |      25 | Keywords                 |      6 | cvn 76
228
       2 |      25 | Keywords                 |      6 | cvn-76
229
       2 |      25 | Keywords                 |     18 | straights magellan
230
       2 |      25 | Keywords                 |      8 | magellan
231
       2 |      25 | Keywords                 |      7 | carrier
232
       2 |      25 | Keywords                 |     12 | nimitz-class
233
       2 |      25 | Keywords                 |      4 | ship
234
       2 |      25 | Keywords                 |      8 | underway
235
    8762 | 0xffe1 APP1  |    5329 | http://ns.adobe.com/xap/1.0/.<?x
236
   14093 | 0xffe2 APP2  |     576 | ICC_PROFILE......0ADBE....mntrRG chunk 1/1
237
   14671 | 0xffee APP14 |      14 | Adobe.d@......
238
   14687 | 0xffdb DQT   |     132 
239
   14821 | 0xffc0 SOF0  |      17 
240
   14840 | 0xffdd DRI   |       4 
241
   14846 | 0xffc4 DHT   |     418 
242
   15266 | 0xffda SOS  
243
544 rmills@rmillsmbp:~/gnu/exiv2/trunk $ </pre>