Project

General

Profile

The Metadata in TIFF files » History » Version 16

Robin Mills, 13 Nov 2016 09:30

1 16 Robin Mills
h2{color:#628DB6}. The Metadata in TIFF files
2 1 Robin Mills
3 16 Robin Mills
p{margin-left:60px;}. The Tagged Image File Format is a container.  It's very flexible and can deal with multiple pages, different colour spaces, different frame configurations as well as metadata.  The specification is available from:  https://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf
4 1 Robin Mills
5 16 Robin Mills
p{margin-left:60px;}. 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.
6 14 Robin Mills
7 16 Robin Mills
p{margin-left:60px;}. There is a 64bit version of Tiff called _*BigTiff*_. This is currently not supported by exiv2.
8 14 Robin Mills
9 16 Robin Mills
p{margin-left:60px;}. !Tiff.png!
10 3 Robin Mills
11 16 Robin Mills
p{margin-left:60px;}. 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*_.
12 1 Robin Mills
13 16 Robin Mills
p{margin-left:60px;}. The _*IFD*_ _(Image File Directory)_  has a two byte header which contains the length of the directory followed by 12 byte "fields" or "tags".  The trailing 4 bytes of the directory is the offset to the next directory _*or*_ zero to terminate the directory chain.
14 15 Robin Mills
15 16 Robin Mills
p{margin-left:60px;}. 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.
16 7 Robin Mills
17 16 Robin Mills
h2{color:#628DB6}. Example:
18
19 10 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.
20
21
The option _*<code>-pa</code>*_ is used to print the metadata in human readable format.<pre>$ exiv2 -pa test/data/test.tiff
22
$ exiv2 -pa test/data/test.tiff 
23
Exif.Image.NewSubfileType                    Long        1  Primary image
24
Exif.Image.ImageWidth                        Short       1  282
25
Exif.Image.ImageLength                       Short       1  212
26 1 Robin Mills
Exif.Image.BitsPerSample                     Short       3  8 8 8
27
Exif.Image.Compression                       Short       1  LZW
28
Exif.Image.PhotometricInterpretation         Short       1  RGB
29 10 Robin Mills
Exif.Image.ImageDescription                  Ascii      32                                 
30
Exif.Image.Make                              Ascii       5  SONY
31
Exif.Image.Model                             Ascii       9  DSC-S600
32
Exif.Image.StripOffsets                      Long       16  4372 ...
33
Exif.Image.Orientation                       Short       1  top, left
34 1 Robin Mills
Exif.Image.SamplesPerPixel                   Short       1  3
35 10 Robin Mills
Exif.Image.RowsPerStrip                      Long        1  14
36
Exif.Image.StripByteCounts                   Long       16  10492 ...
37
Exif.Image.XResolution                       Rational    1  96
38
Exif.Image.YResolution                       Rational    1  96
39 1 Robin Mills
Exif.Image.PlanarConfiguration               Short       1  1
40 10 Robin Mills
Exif.Image.ResolutionUnit                    Short       1  inch
41
Exif.Image.DateTime                          Ascii      20  2009:04:26 12:38:18
42
Exif.Image.Predictor                         Short       1  No prediction scheme used
43 1 Robin Mills
Exif.Image.SampleFormat                      Short       3  Unsigned integer data
44 10 Robin Mills
Exif.Image.XMLPacket                         Byte      2505  (Binary value suppressed)
45
Exif.Image.InterColorProfile                 Undefined 1352  (Binary value suppressed)
46
Xmp.dc.title                                 LangAlt     1  lang="x-default" this is a test image
47 11 Robin Mills
$ exiv2 -pS test/data/test.tiff
48 10 Robin Mills
STRUCTURE OF TIFF FILE (II): test/data/test.tiff
49
 address |    tag                           |      type |    count |    offset | value
50
      10 | 0x00fe NewSubfileType            |      LONG |        1 |         0 | 0
51
      22 | 0x0100 ImageWidth                |     SHORT |        1 |       282 | 282
52
      34 | 0x0101 ImageLength               |     SHORT |        1 |       212 | 212
53
      46 | 0x0102 BitsPerSample             |     SHORT |        3 |       290 | 8 8 8
54
      58 | 0x0103 Compression               |     SHORT |        1 |         5 | 5
55
      70 | 0x0106 PhotometricInterpretation |     SHORT |        1 |         2 | 2
56
      82 | 0x010e ImageDescription          |     ASCII |       32 |       296 |                                
57
      94 | 0x010f Make                      |     ASCII |        5 |       328 | SONY
58
     106 | 0x0110 Model                     |     ASCII |        9 |       334 | DSC-S600
59
     118 | 0x0111 StripOffsets              |      LONG |       16 |       344 | 4372 14864 25634 37110 50496 ...
60
     130 | 0x0112 Orientation               |     SHORT |        1 |         1 | 1
61
     142 | 0x0115 SamplesPerPixel           |     SHORT |        1 |         3 | 3
62
     154 | 0x0116 RowsPerStrip              |      LONG |        1 |        14 | 14
63
     166 | 0x0117 StripByteCounts           |      LONG |       16 |       408 | 10492 10770 11476 13385 13348 ...
64
     178 | 0x011a XResolution               |  RATIONAL |        1 |       472 | 96/1
65
     190 | 0x011b YResolution               |  RATIONAL |        1 |       480 | 96/1
66
     202 | 0x011c PlanarConfiguration       |     SHORT |        1 |         1 | 1
67
     214 | 0x0128 ResolutionUnit            |     SHORT |        1 |         2 | 2
68
     226 | 0x0132 DateTime                  |     ASCII |       20 |       488 | 2009:04:26 12:38:18
69
     238 | 0x013d Predictor                 |     SHORT |        1 |         1 | 1
70
     250 | 0x0153 SampleFormat              |     SHORT |        3 |       508 | 1 1 1
71
     262 | 0x02bc XMLPacket                 |      BYTE |     2505 |       514 | <?xpacket begin="..." id="W5M0Mp ...
72
     274 | 0x8773 InterColorProfile         | UNDEFINED |     1352 |      3020 | ...Happl. ..scnrRGB XYZ ....... ...
73
END test/data/test.tiff
74
$ exiv2 -pX test/data/test.tiff  | xmllint --format -
75 1 Robin Mills
<?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 10 Robin Mills
          <rdf:li xml:lang="x-default">this is a test image</rdf:li>
83 1 Robin Mills
        </rdf:Alt>
84
      </dc:title>
85
    </rdf:Description>
86
  </rdf:RDF>
87
</x:xmpmeta>
88
<?xpacket end="w"?>
89 16 Robin Mills
$ </pre>
90
91
You can use the output from _*<code>-pS</code>*_ to determine the location of the XMLPacket:<pre>$ exiv2 -pS test/data/test.tiff | grep XMLPacket 
92 10 Robin Mills
     262 | 0x02bc XMLPacket                 |      BYTE |     2505 |       514 | <?xpacket begin="..." id="W5M0Mp ...
93 16 Robin Mills
$ </pre>You can see the XMLPacket of 2505 bytes stored at offset 514.   You can extract the XMP with the following command which says:  set the block size to 1 byte, skip 514 bytes and extract 2505 bytes:<pre>$ dd bs=1 count=2505 skip=514 if=test/data/test.tiff | xmllint --format - 
94 10 Robin Mills
2505+0 records in
95
2505+0 records out
96 1 Robin Mills
2505 bytes (2.5 kB) copied, 0.0064 s, 391 kB/s
97
<?xml version="1.0"?>
98
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
99 4 Robin Mills
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 4.4.0-Exiv2">
100 1 Robin Mills
  <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
101
    <rdf:Description xmlns:dc="http://purl.org/dc/elements/1.1/" rdf:about="">
102 2 Robin Mills
      <dc:title>
103
        <rdf:Alt>
104
          <rdf:li xml:lang="x-default">this is a test image</rdf:li>
105 10 Robin Mills
        </rdf:Alt>
106 2 Robin Mills
      </dc:title>
107
    </rdf:Description>
108
  </rdf:RDF>
109
</x:xmpmeta>
110
<?xpacket end="w"?>
111 16 Robin Mills
</pre>
112 13 Robin Mills
113 16 Robin Mills
The option _*<code>-pX</code>*_ doesn't use dd to achieve the same result and is much more convenient to use.
114
115 2 Robin Mills
To demonstrate that the metadata block in a JPEG is a TIFF file, extract and print the structure.<pre>$ exiv2 -pS test/data/Reagan.jpg 
116 1 Robin Mills
$ exiv2 -pS test/data/Reagan.jpg
117
STRUCTURE OF JPEG FILE: test/data/Reagan.jpg
118
 address | marker       |  length | data
119 2 Robin Mills
       0 | 0xffd8 SOI  
120
       2 | 0xffe1 APP1  |    5718 | Exif..MM.*......................
121
    5722 | 0xffed APP13 |    3038 | Photoshop 3.0.8BIM..........Z...
122 10 Robin Mills
    8762 | 0xffe1 APP1  |    5329 | http://ns.adobe.com/xap/1.0/.<?x
123
   14093 | 0xffe2 APP2  |     576 | ICC_PROFILE......0ADBE....mntrRG chunk 1/1
124
   14671 | 0xffee APP14 |      14 | Adobe.d@......
125
   14687 | 0xffdb DQT   |     132 
126
   14821 | 0xffc0 SOF0  |      17 
127
   14840 | 0xffdd DRI   |       4 
128
   14846 | 0xffc4 DHT   |     418 
129
   15266 | 0xffda SOS  
130 16 Robin Mills
$ </pre>
131
132
We can extract the APP1/Exif data as follows:<pre>$ dd bs=1 skip=$((2+2+8)) count=$((5718-8)) if=test/data/Reagan.jpg of=ReaganExif.tiff
133 10 Robin Mills
5710+0 records in
134
5710+0 records out
135
5710 bytes (5.7 kB) copied, 0.026688 s, 214 kB/s
136
$ exiv2 -pS ReaganExif.tif 
137
STRUCTURE OF TIFF FILE (MM): ReaganExif.tif
138
 address |    tag                           |      type |    count |    offset | value
139
      10 | 0x0100 ImageWidth                |     SHORT |        1 |  13107200 | 200
140
      22 | 0x0101 ImageLength               |     SHORT |        1 |   8519680 | 130
141
      34 | 0x0102 BitsPerSample             |     SHORT |        4 |       242 | 8 8 8 8
142
      46 | 0x0103 Compression               |     SHORT |        1 |     65536 | 1
143
      58 | 0x0106 PhotometricInterpretation |     SHORT |        1 |    131072 | 2
144
      70 | 0x010e ImageDescription          |     ASCII |      403 |       250 | 040621-N-6536T-062.USS Ronald Re ...
145
      82 | 0x010f Make                      |     ASCII |       18 |       653 | NIKON CORPORATION
146
      94 | 0x0110 Model                     |     ASCII |       10 |       671 | NIKON D1X
147
     106 | 0x0112 Orientation               |     SHORT |        1 |     65536 | 1
148
     118 | 0x0115 SamplesPerPixel           |     SHORT |        1 |    262144 | 4
149
     130 | 0x011a XResolution               |  RATIONAL |        1 |       681 | 3000000/10000
150 1 Robin Mills
     142 | 0x011b YResolution               |  RATIONAL |        1 |       689 | 3000000/10000
151
     154 | 0x011c PlanarConfiguration       |     SHORT |        1 |     65536 | 1
152
     166 | 0x0128 ResolutionUnit            |     SHORT |        1 |    131072 | 2
153 10 Robin Mills
     178 | 0x0131 Software                  |     ASCII |       40 |       697 | Adobe Photoshop Elements 12.0 Ma ...
154
     190 | 0x0132 DateTime                  |     ASCII |       20 |       737 | 2016:09:13 11:58:16
155
     202 | 0x013b Artist                    |     ASCII |       34 |       757 | Photographer..s Mate 3rd Class ( ...
156
     214 | 0x8769 ExifTag                   |      LONG |        1 |       792 | 792
157
     226 | 0x8825 GPSTag                    |      LONG |        1 |      1400 | 1400
158
    1422 | 0x0103 Compression               |     SHORT |        1 |    393216 | 6
159
    1434 | 0x011a XResolution               |  RATIONAL |        1 |      1498 | 72/1
160
    1446 | 0x011b YResolution               |  RATIONAL |        1 |      1506 | 72/1
161
    1458 | 0x0128 ResolutionUnit            |     SHORT |        1 |    131072 | 2
162
    1470 | 0x0201 JPEGInterchangeFormat     |      LONG |        1 |      1514 | 1514
163
    1482 | 0x0202 JPEGInterchangeFormatLeng |      LONG |        1 |      4196 | 4196
164
END ReaganExif.tif
165 16 Robin Mills
$ </pre>
166
167
The version of the exiv2 utility that ships with v0.26 later has an option _*<code>-pR</code>*_ which _Recursively_ prints the structure of an image file.  *_Recursively*_ means  the utility prints structures embedded within other structures.  For example, the Exif metadata in a JPEG is encoded as a TIFF embedded in the APP1/Exif segment of the JPEG.<pre>$ exiv2 -pR test/data/Reagan.jpg 
168 10 Robin Mills
STRUCTURE OF JPEG FILE: test/data/Reagan.jpg
169
 address | marker       |  length | data
170
       0 | 0xffd8 SOI  
171 4 Robin Mills
       2 | 0xffe1 APP1  |    5718 | Exif..MM.*......................
172
  STRUCTURE OF TIFF FILE (MM): MemIo
173
   address |    tag                           |      type |    count |    offset | value
174
        10 | 0x0100 ImageWidth                |     SHORT |        1 |  13107200 | 200
175
        22 | 0x0101 ImageLength               |     SHORT |        1 |   8519680 | 130
176
        34 | 0x0102 BitsPerSample             |     SHORT |        4 |       242 | 8 8 8 8
177
        46 | 0x0103 Compression               |     SHORT |        1 |     65536 | 1
178
        58 | 0x0106 PhotometricInterpretation |     SHORT |        1 |    131072 | 2
179
        70 | 0x010e ImageDescription          |     ASCII |      403 |       250 | 040621-N-6536T-062.USS Ronald Re ...
180
        82 | 0x010f Make                      |     ASCII |       18 |       653 | NIKON CORPORATION
181
        94 | 0x0110 Model                     |     ASCII |       10 |       671 | NIKON D1X
182
       106 | 0x0112 Orientation               |     SHORT |        1 |     65536 | 1
183
       118 | 0x0115 SamplesPerPixel           |     SHORT |        1 |    262144 | 4
184
       130 | 0x011a XResolution               |  RATIONAL |        1 |       681 | 681/0
185
       142 | 0x011b YResolution               |  RATIONAL |        1 |       689 | 689/0
186
       154 | 0x011c PlanarConfiguration       |     SHORT |        1 |     65536 | 1
187
       166 | 0x0128 ResolutionUnit            |     SHORT |        1 |    131072 | 2
188
       178 | 0x0131 Software                  |     ASCII |       40 |       697 | Adobe Photoshop Elements 12.0 Ma ...
189
       190 | 0x0132 DateTime                  |     ASCII |       20 |       737 | 2016:09:13 11:58:16
190
       202 | 0x013b Artist                    |     ASCII |       34 |       757 | Photographer..s Mate 3rd Class ( ...
191
       214 | 0x8769 ExifTag                   |      LONG |        1 |       792 | 792
192
    STRUCTURE OF TIFF FILE (MM): MemIo
193
     address |    tag                           |      type |    count |    offset | value
194
         794 | 0x829a ExposureTime              |  RATIONAL |        1 |      1254 | 1254/0
195
         806 | 0x829d FNumber                   |  RATIONAL |        1 |      1262 | 1262/0
196
         818 | 0x8822 ExposureProgram           |     SHORT |        1 |     65536 | 1
197
         830 | 0x9000 ExifVersion               | UNDEFINED |        4 | 808596016 | 0220
198
         842 | 0x9003 DateTimeOriginal          |     ASCII |       20 |      1270 | 2004:06:21 23:37:53
199
         854 | 0x9004 DateTimeDigitized         |     ASCII |       20 |      1290 | 2004:06:21 23:37:53
200
         866 | 0x9101 ComponentsConfiguration   | UNDEFINED |        4 |  16909056 | ...
201
         878 | 0x9102 CompressedBitsPerPixel    |  RATIONAL |        1 |      1310 | 1310/0
202
         890 | 0x9201 ShutterSpeedValue         | SRATIONAL |        1 |      1318 | 1318/0
203
         902 | 0x9202 ApertureValue             |  RATIONAL |        1 |      1326 | 1326/0
204
         914 | 0x9204 ExposureBiasValue         | SRATIONAL |        1 |      1334 | 1334/0
205
         926 | 0x9205 MaxApertureValue          |  RATIONAL |        1 |      1342 | 1342/0
206
         938 | 0x9207 MeteringMode              |     SHORT |        1 |    131072 | 2
207 1 Robin Mills
         950 | 0x9208 LightSource               |     SHORT |        1 |    655360 | 10
208 4 Robin Mills
         962 | 0x9209 Flash                     |     SHORT |        1 |         0 | 0
209
         974 | 0x920a FocalLength               |  RATIONAL |        1 |      1350 | 1350/0
210
         986 | 0x9290 SubSecTime                |     ASCII |        3 | 808845312 | 06
211
         998 | 0x9291 SubSecTimeOriginal        |     ASCII |        3 | 808845312 | 06
212
        1010 | 0x9292 SubSecTimeDigitized       |     ASCII |        3 | 808845312 | 06
213
        1022 | 0xa000 FlashpixVersion           | UNDEFINED |        4 | 808529968 | 0100
214
        1034 | 0xa001 ColorSpace                |     SHORT |        1 |4294901760 | 65535
215
        1046 | 0xa002 PixelXDimension           |      LONG |        1 |       200 | 200
216
        1058 | 0xa003 PixelYDimension           |      LONG |        1 |       130 | 130
217
        1070 | 0xa217 SensingMethod             |     SHORT |        1 |    131072 | 2
218
        1082 | 0xa300 FileSource                | UNDEFINED |        1 |  50331648 | .
219
        1094 | 0xa301 SceneType                 | UNDEFINED |        1 |  16777216 | .
220
        1106 | 0xa401 CustomRendered            |     SHORT |        1 |         0 | 0
221
        1118 | 0xa402 ExposureMode              |     SHORT |        1 |     65536 | 1
222
        1130 | 0xa403 WhiteBalance              |     SHORT |        1 |     65536 | 1
223
        1142 | 0xa404 DigitalZoomRatio          |  RATIONAL |        1 |      1358 | 1358/0
224
        1154 | 0xa405 FocalLengthIn35mmFilm     |     SHORT |        1 |   4128768 | 63
225
        1166 | 0xa406 SceneCaptureType          |     SHORT |        1 |         0 | 0
226
        1178 | 0xa407 GainControl               |     SHORT |        1 |         0 | 0
227
        1190 | 0xa408 Contrast                  |     SHORT |        1 |         0 | 0
228
        1202 | 0xa409 Saturation                |     SHORT |        1 |         0 | 0
229
        1214 | 0xa40a Sharpness                 |     SHORT |        1 |         0 | 0
230
        1226 | 0xa40c SubjectDistanceRange      |     SHORT |        1 |         0 | 0
231
        1238 | 0xa420 ImageUniqueID             |     ASCII |       33 |      1366 | 127c1377b054a3f65bf2754ebb24e7f2 ...
232
    END MemIo
233
       226 | 0x8825 GPSTag                    |      LONG |        1 |      1400 | 1400
234
      1422 | 0x0103 Compression               |     SHORT |        1 |    393216 | 6
235
      1434 | 0x011a XResolution               |  RATIONAL |        1 |      1498 | 1498/0
236
      1446 | 0x011b YResolution               |  RATIONAL |        1 |      1506 | 1506/0
237
      1458 | 0x0128 ResolutionUnit            |     SHORT |        1 |    131072 | 2
238
      1470 | 0x0201 JPEGInterchangeFormat     |      LONG |        1 |      1514 | 1514
239
      1482 | 0x0202 JPEGInterchangeFormatLeng |      LONG |        1 |      4196 | 4196
240
  END MemIo
241
    5722 | 0xffed APP13 |    3038 | Photoshop 3.0.8BIM..........Z...
242
  Record | DataSet | Name                     | Length | Data
243
       1 |      90 | CharacterSet             |      3 | .%G
244
       1 |      90 | CharacterSet             |      3 | .%G
245
       2 |       0 | RecordVersion            |      2 | ..
246
       2 |     120 | Caption                  |    402 | 040621-N-6536T-062.USS Ronald Reagan (CV...
247
       2 |     122 | Writer                   |      9 | Dir. NVNS
248
       2 |      40 | SpecialInstructions      |     49 | Credit as U.S. Navy photo by Elizabeth T...
249
       2 |      80 | Byline                   |     32 | Photographer..s Mate 3rd Class (
250
       2 |      85 | BylineTitle              |     21 | U.S Navy Photographer
251
       2 |     110 | Credit                   |      8 | U.S Navy
252
       2 |     115 | Source                   |     24 | Navy Visual News Service
253
       2 |       5 | ObjectName               |     18 | 040621-N-6536T-062
254
       2 |      55 | DateCreated              |      8 | 20040621
255
       2 |      60 | TimeCreated              |     11 | 000000+0000
256
       2 |      62 | DigitizationDate         |      8 | 20040621
257
       2 |      63 | DigitizationTime         |     11 | 233753-0400
258
       2 |      90 | City                     |     19 | Straits of Magellan
259
       2 |     101 | CountryName              |     13 | South America
260 1 Robin Mills
       2 |      15 | Category                 |      1 | N
261
       2 |      20 | SuppCategory             |     12 | 703-614-9154
262
       2 |      20 | SuppCategory             |     23 | navyvisualnews@navy.mil
263
       2 |      20 | SuppCategory             |     11 | UNCLASSFIED
264
       2 |      10 | Urgency                  |      1 | 5
265
       2 |      25 | Keywords                 |     13 | ronald reagan
266
       2 |      25 | Keywords                 |      6 | reagan
267
       2 |      25 | Keywords                 |      6 | cvn 76
268
       2 |      25 | Keywords                 |      6 | cvn-76
269
       2 |      25 | Keywords                 |     18 | straights magellan
270
       2 |      25 | Keywords                 |      8 | magellan
271
       2 |      25 | Keywords                 |      7 | carrier
272
       2 |      25 | Keywords                 |     12 | nimitz-class
273
       2 |      25 | Keywords                 |      4 | ship
274
       2 |      25 | Keywords                 |      8 | underway
275
    8762 | 0xffe1 APP1  |    5329 | http://ns.adobe.com/xap/1.0/.<?x
276
   14093 | 0xffe2 APP2  |     576 | ICC_PROFILE......0ADBE....mntrRG chunk 1/1
277
   14671 | 0xffee APP14 |      14 | Adobe.d@......
278
   14687 | 0xffdb DQT   |     132 
279
   14821 | 0xffc0 SOF0  |      17 
280
   14840 | 0xffdd DRI   |       4 
281
   14846 | 0xffc4 DHT   |     418 
282 10 Robin Mills
   15266 | 0xffda SOS  
283 1 Robin Mills
$ </pre>