1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
   2 <html>
   3 <head>
   4 <!--
   5 Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   6 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7 
   8 This code is free software; you can redistribute it and/or modify it
   9 under the terms of the GNU General Public License version 2 only, as
  10 published by the Free Software Foundation.  Oracle designates this
  11 particular file as subject to the "Classpath" exception as provided
  12 by Oracle in the LICENSE file that accompanied this code.
  13 
  14 This code is distributed in the hope that it will be useful, but WITHOUT
  15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  17 version 2 for more details (a copy is included in the LICENSE file that
  18 accompanied this code).
  19 
  20 You should have received a copy of the GNU General Public License version
  21 2 along with this work; if not, write to the Free Software Foundation,
  22 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  23 
  24 Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  25 or visit www.oracle.com if you need additional information or have any
  26 questions.
  27 -->
  28 
  29 <title>TIFF Metadata Format Specification and Usage Notes</title>
  30 </head>
  31 
  32 <body bgcolor="white">
  33 
  34 <center><h1>
  35 TIFF Metadata Format Specification and Usage Notes
  36 </h1></center>
  37 
  38     <p>
  39 <a href="#Reading">Reading Images</a><br/>
  40 <font size="-1">
  41 <ul>
  42 <li><a href="#ColorConversionRead">Color Conversion</a></li>
  43 <li><a href="#ColorSpacesRead">Color Spaces</a></li>
  44 <li><a href="#ICCProfilesRead">ICC Profiles</a></li>
  45 <li><a href="#MetadataIssuesRead">Metadata Issues</a>
  46 <font size="-2">
  47 <ul>
  48 <li><a href="#MapNativeStandard">Native to Standard Metadata Mapping</a></li>
  49 </ul>
  50 </font>
  51 </li>
  52 <li><a href="#ExifRead">Reading Exif Images</a>
  53 <font size="-2">
  54 <ul>
  55 <li><a href="#ExifReadTIFF">Reading Uncompressed Exif Images</a></li>
  56 <li><a href="#ExifReadJPEG">Reading Compressed Exif Images</a></li>
  57 </ul>
  58 </font>
  59 </li>
  60 </ul>
  61 </font>
  62 <a href="#Writing">Writing Images</a><br/>
  63 <font size="-1">
  64 <ul>
  65 <li><a href="#Compression">Compression</a></li>
  66 <li><a href="#ColorConversionWrite">Color Conversion</a></li>
  67 <li><a href="#ICCProfilesWrite">ICC Profiles</a></li>
  68 <li><a href="#MetadataIssuesWrite">Metadata Issues</a></li>
  69 <font size="-2">
  70 <ul>
  71 <li><a href="#MapStandardNative">Standard to Native Metadata Mapping</a></li>
  72 </ul>
  73 </font>
  74 <li><a href="#ExifWrite">Writing Exif Images</a>
  75 <font size="-2">
  76 <ul>
  77 <li><a href="#ExifWriteTIFF">Writing Uncompressed Exif Images</a></li>
  78 <li><a href="#ExifWriteJPEG">Writing Compressed Exif Images</a></li>
  79 </ul>
  80 </font>
  81 </li>
  82 </ul>
  83 </font>
  84 <a href="#StreamMetadata">Native Stream Metadata Format</a><br/>
  85 <a href="#ImageMetadata">Native Image Metadata Format</a>
  86 </p>
  87 
  88 <h3><a name="Reading"/>Reading Images</h3>
  89 
  90 TIFF images are read by an <a href="../../ImageReader.html">ImageReader</a>
  91 which may be controlled by its public interface as well as via a supplied
  92 <a href="../../plugins/tiff/TIFFImageReadParam.html">TIFFImageReadParam</a>.
  93 
  94 <!-- <h4>Supported Image Types</h4> -->
  95 
  96 <!-- Table? -->
  97 
  98 <h4><a name="ColorConversionRead"/>Color Conversion</h4>
  99 
 100 <p>If the source image data
 101 have photometric type CIE L*a*b* or YCbCr, and the destination color space
 102 type is RGB, then the source image data will be automatically converted to
 103 RGB using an internal color converter.</p>
 104 
 105 <h4><a name="ColorSpacesRead"/>Color Spaces</h4>
 106 
 107 The raw color space assigned by default, i.e., in the absence of a
 108 user-supplied <a href="../../ImageTypeSpecifier.html">ImageTypeSpecifier</a>,
 109 will be the first among the following which applies:
 110 
 111 <ul>
 112 <li>A color space created from the <a href="#ICCProfilesRead">ICC Profile</a>
 113 metadata field if it is present and compatible with the image data
 114 layout.</li>
 115 <a name="nonICCProfile"><li>sRGB if the image is monochrome/bilevel
 116 (a two-level color map is created internally).</li>
 117 <li>sRGB if the image is palette-color.</li>
 118 <li>Linear RGB if the image has three samples per pixel, has photometric type
 119 CIE L*a*b*, or has photometric type YCbCr and is <i>not</i>
 120 JPEG-compressed.</li>
 121 <li>A <a href="#DefaultCMYK">default CMYK color space</a> if the image has
 122 photometric type CMYK and four samples per pixel.</li>
 123 <li>Grayscale if the image has one or two samples per pixel and uniformly
 124 1, 2, 4, 8, 16, or 32 bits per sample or is floating point.</li>
 125 <li>sRGB if the image has three or four samples per pixel and uniformly
 126 1, 2, 4, 8, 16, or 32 bits per sample or is floating point.</li>
 127 <li>A fabricated, <a href="#GenericCS">generic color space</a> if the image
 128 has more than four samples per pixel and the number of bits per sample for
 129 all bands is the same and is a multiple of 8.</li>
 130 <li>Grayscale if the image has one or two samples per pixel regardless of
 131 the number of bits per sample.</li>
 132 <li>sRGB if the image has three or four samples per pixel regardless of
 133 the number of bits per sample.</li>
 134 <li>A fabricated, <a href="#GenericCS">generic color space</a> if the image
 135 has more than four samples per pixel regardless of the number of bits per
 136 sample.</li>
 137 </ul>
 138 
 139 <p><a name="DefaultCMYK"/>The normalized color coordinate transformations
 140 used for the default CMYK color space are defined as follows:
 141 
 142 <ul>
 143 <li>CMYK to linear RGB
 144 <pre>
 145 R = (1 - K)*(1 - C)
 146 G = (1 - K)*(1 - M)
 147 B = (1 - K)*(1 - Y)
 148 </pre>
 149 </li>
 150 <li>Linear RGB to CMYK
 151 <pre>
 152 K = min{1 - R, 1 - G, 1 - B}
 153 if(K != 1) {
 154     C = (1 - R - K)/(1 - K)
 155     M = (1 - G - K)/(1 - K)
 156     Y = (1 - B - K)/(1 - K)
 157 } else {
 158     C = M = Y = 0
 159 }
 160 </pre>
 161 </li>
 162 </ul>
 163 </p>
 164 
 165 <p><a name="GenericCS"/>The generic color space used when no other color space
 166 can be inferred is provided merely to enable the data to be loaded. It is not
 167 intended to provide accurate conversions of any kind.</p>
 168 
 169 <p>If the data are known to be in a color space not correctly handled by the
 170 foregoing, then an <code>ImageTypeSpecifier</code> should be
 171 supplied to the reader and should be derived from a color space which is correct
 172 for the data in question.</p>
 173 
 174 <h4><a name="ICCProfilesRead"/>ICC Profiles</h4>
 175 
 176 If an ICC profile is contained in the image metadata
 177 (<a href="../../plugins/tiff/BaselineTIFFTagSet.html">
 178 BaselineTIFFTagSet</a>.TAG_ICC_PROFILE, tag number 34675),
 179 an attempt will be made to use it to create the color space
 180 of the loaded image. It will be used if the data layout is of component type
 181 and the number of samples per pixel equals or is one greater than the number
 182 of components described by the ICC profile. If the ICC profile is not used
 183 then the color space will be inferred in one of the subsequent steps described
 184 <a href="#nonICCProfile">above</a>.
 185 
 186 <p>If for some reason the embedded ICC profile is not used automatically, then
 187 it may be used manually by following this procedure:
 188 
 189 <ol>
 190 <li>Obtain the image metadata from
 191 <code>ImageReader.getImageMetadata</code></li>
 192 <li>Extract the ICC profile field and its value.</li>
 193 <li>Create an <a href="../../../../java/awt/color/ICC_ColorSpace.html">
 194 ICC_ColorSpace</a> from an
 195 <a href="../../../../java/awt/color/ICC_Profile.html">
 196 ICC_Profile</a> created from the ICC profile field data
 197 using <code>ICC_Profile.getInstance(byte[])</code>.</li>
 198 <li>Create an <code>ImageTypeSpecifier</code> from the new color
 199 space using one of its factory methods which accepts an
 200 <code>ICC_ColorSpace</code>.
 201 <li>Create a compatible <a href="../../ImageReadParam.html">ImageReadParam</a>
 202 and set the <code>ImageTypeSpecifier</code> using
 203 <code>ImageReadParam.setDestinationType</code>.</li>
 204 <li>Pass the parameter object to the appropriate <code>read</code> method.</li>
 205 </ol>
 206 </p>
 207 
 208 <p>If the inferred color space not based on the ICC Profile field is compatible
 209 with the ICC profile-based color space, then a second
 210 <code>ImageTypeSpecifier</code> derived from this inferred color
 211 space will be included in the
 212 <a href="../../../../java/util/Iterator.html">Iterator</a> returned by
 213 <code>ImageReader.getImageTypes</code>. If the iterator contains
 214 more than one type, the first one will be based on the ICC profile and the
 215 second on the inferred color space.</p>
 216 
 217 <h4><a name="MetadataIssuesRead"/>Metadata Issues</h4>
 218 
 219 By default all recognized fields in the TIFF image file directory (IFD) are
 220 loaded into the native image metadata object. Which fields are loaded may be
 221 controlled by setting which TIFF tags the reader is allowed to recognize,
 222 whether to read fields with unrecognized tags, and whether to ignore all
 223 metadata. The reader is informed to disregard all metadata as usual via the
 224 <code>ignoreMetadata</code> parameter of
 225 <code>ImageReader.setInput(Object,boolean,boolean)</code>. It is
 226 informed of which <a href="../../plugins/tiff/TIFFTag.html">TIFFTag</a>s to
 227 recognize or not to recognize via
 228 <code>TIFFImageReadParam.addAllowedTagSet(TIFFTagSet)</code> and
 229 <code>TIFFImageReadParam.removeAllowedTagSet(TIFFTagSet)</code>.
 230 If <code>ignoreMetadata</code> is <code>true</code>, then only metadata
 231 essential to reading the image will be loaded into the native image metadata
 232 object. If <code>ignoreMetadata</code> is <code>false</code>, then the reader
 233 will by default load into the native image metadata object only those fields
 234 which are either essential to reading the image or have a <code>TIFFTag</code>
 235 contained in the one of the allowed <code>TIFFTagSet</code>s. Reading of
 236 fields with tags not in the allowed <code>TIFFTagSet</code>s may be forced
 237 by passing in a <code>TIFFImageReadParam</code> on which
 238 <code>TIFFImageReadParam.setReadUnknownTags(boolean)</code> has been
 239 invoked with parameter <code>true</code>.
 240 
 241 <p>Use of a <a href="../../plugins/tiff/TIFFDirectory.html">TIFFDirectory</a>
 242 object may simplify gaining access to metadata values. An instance of
 243 <code>TIFFDirectory</code> may be created from the <code>IIOMetadata</code>
 244 object returned by the TIFF reader using the
 245 <code>TIFFDirectory.createFromMetadata</code> method.</p>
 246 
 247 <h5><a name="MapNativeStandard"/>
 248 Mapping of TIFF Native Image Metadata to the Standard Metadata Format</h5>
 249 
 250 The derivation of standard metadata format
 251 <a href="standard_metadata.html">javax_imageio_1.0</a>
 252 elements from <a href="#ImageMetadata">TIFF native image metadata</a> is given
 253 in the following table.
 254 
 255 <p>
 256 <table border="1">
 257 <tr>
 258 <th>Standard Metadata Element</th>
 259 <th>Derivation from TIFF Fields</th>
 260 </tr>
 261 <tr>
 262 <td>/Chroma/ColorSpaceType@name</td>
 263 <td>PhotometricInterpretation: WhiteIsZero, BlackIsZero, TransparencyMask =
 264 "GRAY"; RGB, PaletteColor => "RGB"; CMYK => "CMYK";
 265 YCbCr => "YCbCr";
 266 CIELab, ICCLab => "Lab".</td>
 267 </tr>
 268 <tr>
 269 <td>/Chroma/NumChannels@value</td>
 270 <td>SamplesPerPixel</td>
 271 </tr>
 272 <tr>
 273 <td>/Chroma/BlackIsZero@value</td>
 274 <td>"TRUE" <=> PhotometricInterpretation => WhiteIsZero</td>
 275 </tr>
 276 <tr>
 277 <td>/Chroma/Palette</td>
 278 <td>ColorMap</td>
 279 </tr>
 280 <tr>
 281 <td>/Compression/CompressionTypeName@value</td>
 282 <td>Compression: Uncompressed => "none"; CCITT 1D => "CCITT
 283 RLE";
 284 Group 3 Fax => "CCITT T.4"; Group 4 Fax => "CCITT T.6";
 285 LZW => "LZW";
 286 JPEG => "Old JPEG"; New JPEG => "JPEG"; Zlib =>> "ZLib"; PackBits =>
 287 "PackBits";
 288 Deflate => "Deflate"; Exif JPEG => "JPEG".</td>
 289 </tr>
 290 <tr>
 291 <td>/Compression/Lossless@value</td>
 292 <td>Compression: JPEG or New JPEG => "FALSE"; otherwise "TRUE".</td>
 293 </tr>
 294 <tr>
 295 <td>/Data/PlanarConfiguration@value</td>
 296 <td>Chunky => "PixelInterleaved"; Planar => "PlaneInterleaved".</td>
 297 </tr>
 298 <tr>
 299 <td>/Data/SampleFormat@value</td>
 300 <td>PhotometricInterpretation PaletteColor => "Index";
 301 SampleFormat unsigned integer data => "UnsignedIntegral";
 302 SampleFormat two's complement signed integer data => "SignedIntegral";
 303 SampleFormat IEEE floating point data => "Real";
 304 otherwise element not emitted.
 305 </td>
 306 </tr>
 307 <tr>
 308 <td>/Data/BitsPerSample@value</td>
 309 <td>BitsPerSample as a space-separated list.</td>
 310 </tr>
 311 <tr>
 312 <td>/Data/SampleMSB@value</td>
 313 <td>FillOrder: left-to-right => space-separated list of BitsPerSample-1;
 314 right-to-left => space-separated list of 0s.</td>
 315 </tr>
 316 <tr>
 317 <td>/Dimension/PixelAspectRatio@value</td>
 318 <td>(1/XResolution)/(1/YResolution)</td>
 319 </tr>
 320 <tr>
 321 <td>/Dimension/ImageOrientation@value</td>
 322 <td>Orientation</td>
 323 </tr>
 324 <tr>
 325 <td>/Dimension/HorizontalPixelSize@value</td>
 326 <td>1/XResolution in millimeters if ResolutionUnit is not None.</td>
 327 </tr>
 328 <tr>
 329 <td>/Dimension/VerticalPixelSize@value</td>
 330 <td>1/YResolution in millimeters if ResolutionUnit is not None.</td>
 331 </tr>
 332 <tr>
 333 <td>/Dimension/HorizontalPosition@value</td>
 334 <td>XPosition in millimeters if ResolutionUnit is not None.</td>
 335 </tr>
 336 <tr>
 337 <td>/Dimension/VerticalPosition@value</td>
 338 <td>YPosition in millimeters if ResolutionUnit is not None.</td>
 339 </tr>
 340 <tr>
 341 <td>/Document/FormatVersion@value</td>
 342 <td>6.0</td>
 343 </tr>
 344 <tr>
 345 <td>/Document/SubimageInterpretation@value</td>
 346 <td>NewSubFileType: transparency => "TransparencyMask";
 347 reduced-resolution => "ReducedResolution";
 348 single page => "SinglePage".</td>
 349 </tr>
 350 <tr>
 351 <td>/Document/ImageCreationTime@value</td>
 352 <td>DateTime</td>
 353 </tr>
 354 <tr>
 355 <td>/Text/TextEntry</td>
 356 <td>DocumentName, ImageDescription, Make, Model, PageName, Software,
 357 Artist, HostComputer, InkNames, Copyright:
 358 /Text/TextEntry@keyword = field name,
 359 /Text/TextEntry@value = field value.<br>
 360 Example: TIFF Software field => /Text/TextEntry@keyword = "Software",
 361 /Text/TextEntry@value = Name and version number of the software package(s)
 362 used to create the image.</td>
 363 </tr>
 364 <tr>
 365 <td>/Transparency/Alpha@value</td>
 366 <td>ExtraSamples: associated alpha => "premultiplied";
 367 unassociated alpha => "nonpremultiplied".</td>
 368 </tr>
 369 </table>
 370 </p>
 371 
 372 <h4><a name="ExifRead"/>Reading Exif Images</h4>
 373 
 374 The TIFF reader may be used to read an uncompressed Exif image or the
 375 contents of the <tt>APP1</tt> marker segment of a compressed Exif image.
 376 
 377 <h5><a name="ExifReadTIFF"/>Reading Uncompressed Exif Images</h5>
 378 
 379 An uncompressed Exif image is a one- or two-page uncompressed TIFF image
 380 with a specific ordering of its IFD and image data content. Each pixel
 381 has three 8-bit samples with photometric interpretation RGB or YCbCr.
 382 The image stream must contain a single primary image and may contain a
 383 single thumbnail which if present must also be uncompressed. The usual
 384 <code>ImageReader</code> methods may be used to read the image
 385 data and metadata:
 386 
 387 <pre><code>
 388     ImageInputStream input;
 389     ImageReader tiffReader;
 390     ImageReadParam tiffReadParam;
 391 
 392     tiffReader.setInput(input);
 393 
 394     // Read primary image and IFD.
 395     BufferedImage image = tiffReader.read(0, tiffReadParam);
 396     IIOMetadata primaryIFD = tiffReader.getImageMetadata(0);
 397 
 398     // Read thumbnail if present.
 399     BufferedImage thumbnail = null;
 400     if (tiffReader.getNumImages(true) > 1) {
 401         thumbnail = tiffReader.read(1, tiffReadParam);
 402     }
 403 </code></pre>
 404 
 405 Note that the Exif thumbnail is treated as a separate page in the TIFF
 406 stream and not as a thumbnail, i.e.,
 407 <code>tiffReader.hasThumbnails(0)</code> will return <code>false</code>.
 408 
 409 <h5><a name="ExifReadJPEG"/>Reading Compressed Exif Images</h5>
 410 
 411 A compressed Exif image is a 3-band ISO/IEC 10918-1 baseline DCT JPEG stream
 412 with an inserted <tt>APP1</tt> marker segment. The parameters of the marker
 413 segment after the length are the 6-byte sequence
 414 <code>{'E',&nbsp;'x',&nbsp;'i',&nbsp;'f',&nbsp;0x00,&nbsp;0x00}</code></code>
 415 followed by a complete TIFF stream. The embedded TIFF stream contains a primary
 416 IFD describing the JPEG image optionally followed by a thumbnail IFD and
 417 compressed or uncompressed thumbnail image data. Note that the embedded TIFF
 418 stream does not contain any image data associated with the primary IFD
 419 nor any descriptive fields which duplicate information found in the JPEG
 420 stream itself.
 421 
 422 <p>The parameter content of the <tt>APP1</tt> marker segment may be obtained
 423 from the user object of the associated <code>Node</code> in a
 424 <tt>javax_imageio_jpeg_image_1.0</tt> native image metadata tree extracted
 425 from the image metadata object returned by the JPEG reader. This APP1 Exif
 426 node will be a child of the node named "markerSequence" and will
 427 have name <tt>unknown</tt> and an attribute named <tt>MarkerTag</tt> with
 428 integral value <code>0xE1</code> (<code>String</code> value
 429 <code>"225"</code>). The user object of this node will be a byte array
 430 which starts with the six bytes <code>{'E', 'x', 'i', 'f', '0', '0'}</code>.
 431 The primary IFD and the thumbnail IFD and image may be
 432 read from the user object by the usual <code>ImageReader</code>
 433 methods:
 434 
 435 <pre><code>
 436     ImageReader jpegReader;
 437     ImageReader tiffReader;
 438 
 439     // Obtain the APP1 Exif marker data from the JPEG image metadata.
 440     IIOMetadata jpegImageMetadata = jpegReader.getImageMetadata(0);
 441     String nativeFormat = jpegImageMetadata.getNativeMetadataFormatName();
 442     Node jpegImageMetadataTree = jpegImageMetadata.getAsTree(nativeFormat);
 443 
 444     // getExifMarkerData() returns the byte array which is the user object
 445     // of the APP1 Exif marker node.
 446     byte[] app1Params = getExifMarkerData(jpegImageMetadataTree);
 447     if (app1Params == null) {
 448         throw new IIOException("APP1 Exif marker not found.");
 449     }
 450 
 451     // Set up input, skipping Exif ID 6-byte sequence.
 452     MemoryCacheImageInputStream app1ExifInput
 453         = new MemoryCacheImageInputStream
 454             (new ByteArrayInputStream(app1Params, 6, app1Params.length - 6));
 455     tiffReader.setInput(app1ExifInput);
 456 
 457     // Read primary IFD.
 458     IIOMetadata primaryIFD = tiffReader.getImageMetadata(0);
 459 
 460     // Read thumbnail if present.
 461     BufferedImage thumbnail = null;
 462     if (tiffReader.getNumImages(true) > 1) {
 463         thumbnail = tiffReader.read(1, tiffReadParam);
 464     }
 465 
 466     // Read the primary image.
 467     BufferedImage image = jpegReader.read(0);
 468 </code></pre>
 469 
 470 Note that <code>tiffReader.getNumImages(true)</code> returns the number of
 471 IFDs in the embedded TIFF stream including those corresponding to empty
 472 images. Calling <code>tiffReader.read(0,&nbsp;readParam)</code> will throw
 473 an exception as the primary image in the embedded TIFF stream is always
 474 empty; the primary image should be obtained using the JPEG reader itself.
 475 </p>
 476 
 477 <h3><a name="Writing"/>Writing Images</h3>
 478 
 479 TIFF images are written by a <a href="../../ImageWriter.html">ImageWriter</a> which may be
 480 controlled by its public interface as well as via a supplied
 481 <a href="../../ImageWriteParam.html">ImageWriteParam</a>.  For an <code>ImageWriteParam</code> returned
 482 by the <code>getDefaultWriteParam()</code> method of the TIFF <code>ImageWriter</code>,
 483 the <code>canWriteTiles()</code> and <code>canWriteCompressed()</code> methods
 484 will return <code>true</code>; the <code>canOffsetTiles()</code> and
 485 <code>canWriteProgressive()</code> methods will return <code>false</code>.</p>
 486 
 487 The TIFF writer supports many optional capabilities including writing tiled
 488 images, inserting images, writing or inserting empty images, and replacing image
 489 data. Pixels may be replaced in either empty or non-empty images but if and
 490 only if the data are not compressed.
 491 
 492 <p> If tiles are being written, then each of their dimensions will be
 493 rounded to the nearest multiple of 16 per the TIFF specification. If
 494 JPEG-in-TIFF compression is being used, and tiles are being written
 495 each tile dimension will be rounded to the nearest multiple of 8 times
 496 the JPEG minimum coded unit (MCU) in that dimension. If JPEG-in-TIFF
 497 compression is being used and strips are being written, the number of
 498 rows per strip is rounded to a multiple of 8 times the maximum MCU over
 499 both dimensions.</p>
 500  
 501  <!-- <h4>Supported Image Types</h4> -->
 502 
 503 <!-- Table? -->
 504 
 505 <h4><a name="Compression"/>Compression</h4>
 506 
 507 The compression type may be set via the <code>setCompressionType()</code> method of
 508 the <code>ImageWriteParam</code> after setting the compression mode to
 509 <code>MODE_EXPLICIT</code>. The set of innately
 510 supported compression types is listed in the following table:
 511 
 512 <table border=1>
 513 <caption><b>Supported Compression Types</b></caption>
 514 <tr><th>Compression Type</th> <th>Description</th> <th>Reference</th></tr>
 515 <tr>
 516 <td>CCITT RLE</td>
 517 <td>Modified Huffman compression</td>
 518 <td>TIFF 6.0 Specification, Section 10</td>
 519 </tr>
 520 <tr>
 521 <td>CCITT T.4</td>
 522 <td>CCITT T.4 bilevel encoding/Group 3 facsimile compression</td>
 523 <td>TIFF 6.0 Specification, Section 11</td>
 524 </tr>
 525 <tr>
 526 <td>CCITT T.6</td>
 527 <td>CCITT T.6 bilevel encoding/Group 4 facsimile compression</td>
 528 <td>TIFF 6.0 Specification, Section 11</td></tr>
 529 <tr>
 530 <td>LZW</td>
 531 <td>LZW compression</td>
 532 <td>TIFF 6.0 Specification, Section 13</td></tr>
 533 <tr>
 534 <td>JPEG</td>
 535 <td>"New" JPEG-in-TIFF compression</td>
 536 <td><a href="ftp://ftp.sgi.com/graphics/tiff/TTN2.draft.txt">TIFF
 537 Technical Note #2</a></td>
 538 </tr>
 539 <tr>
 540 <td>ZLib</td>
 541 <td>"Deflate/Inflate" compression (see note following this table)</td>
 542 </tr>
 543 <tr>
 544 <td>PackBits</td>
 545 <td>Byte-oriented, run length compression</td>
 546 <td>TIFF 6.0 Specification, Section 9</td>
 547 </tr>
 548 <tr>
 549 <td>Deflate</td>
 550 <td>"Zip-in-TIFF" compression (see note following this table)</td>
 551 <td><a href="https://tools.ietf.org/html/rfc1950">
 552 ZLIB Compressed Data Format Specification</a>,
 553 <a href="https://tools.ietf.org/html/rfc1951">
 554 DEFLATE Compressed Data Format Specification</a></td>
 555 </tr>
 556 <tr>
 557 <td>Exif JPEG</td>
 558 <td>Exif-specific JPEG compression (see note following this table)</td>
 559 <td><a href="http://www.exif.org/Exif2-2.PDF">Exif 2.2 Specification</a>
 560 (PDF), section 4.5.5, "Basic Structure of Thumbnail Data"</td>
 561 </table>
 562 
 563 <p>
 564 Old-style JPEG compression as described in section 22 of the TIFF 6.0
 565 Specification is <i>not</i> supported.
 566 </p>
 567 
 568 <p> The CCITT compression types are applicable to bilevel (1-bit)
 569 images only.  The JPEG compression type is applicable to byte
 570 grayscale (1-band) and RGB (3-band) images only.</p>
 571 
 572 <p>
 573 ZLib and Deflate compression are identical except for the value of the
 574 TIFF Compression field: for ZLib the Compression field has value 8
 575 whereas for Deflate it has value 32946 (0x80b2). In both cases each
 576 image segment (strip or tile) is written as a single complete zlib data
 577 stream.
 578 </p>
 579 
 580 <p>
 581 "Exif JPEG" is a compression type used when writing the contents of an
 582 APP1 Exif marker segment for inclusion in a JPEG native image metadata
 583 tree. The contents appended to the output when this compression type is
 584 used are a function of whether an empty or non-empty image is written.
 585 If the image is empty, then a TIFF IFD adhering to the specification of
 586 a compressed Exif primary IFD is appended. If the image is non-empty,
 587 then a complete IFD and image adhering to the specification of a
 588 compressed Exif thumbnail IFD and image are appended. Note that the
 589 data of the empty image may <i>not</i> later be appended using the pixel
 590 replacement capability of the TIFF writer.
 591 </p>
 592 
 593 <p> If ZLib/Deflate or JPEG compression is used, the compression quality
 594 may be set. For ZLib/Deflate the supplied floating point quality value is
 595 rescaled to the range <tt>[1,&nbsp;9]</tt> and truncated to an integer
 596 to derive the Deflate compression level. For JPEG the floating point
 597 quality value is passed directly to the JPEG writer plug-in which
 598 interprets it in the usual way.</p>
 599 
 600 <h4><a name="ColorConversionWrite"/>Color Conversion</h4>
 601 
 602 <p>If the source image data
 603 color space type is RGB, and the destination photometric type is CIE L*a*b* or
 604 YCbCr, then the source image data will be automatically converted from
 605 RGB using an internal color converter.</p>
 606 
 607 <h4><a name="ICCProfilesWrite"/>ICC Profiles</h4>
 608 
 609 An <tt>ICC Profile</tt> field will be written if either:
 610 <ul>
 611 <li>one is present in the native image metadata
 612 <a href="../IIOMetadata.html">IIOMetadata</a> instance supplied to the writer,
 613 or</li>
 614 <li>the <a href="../../../../java/awt/color/ColorSpace.html">ColorSpace</a>
 615 of the destination <code>ImageTypeSpecifier</code> is an instance of
 616 <code>ICC_ColorSpace</code> which is not one of the standard
 617 color spaces defined by the <tt>CS_*</tt> constants in the
 618 <code>ColorSpace</code> class. The destination type is set via
 619 <code>ImageWriteParam.setDestinationType(ImageTypeSpecifier)</code> and defaults
 620 to the <code>ImageTypeSpecifier</code> of the image being written.
 621 </li>
 622 </ul>
 623 
 624 <h4><a name="MetadataIssuesWrite"/>Metadata Issues</h4>
 625 
 626 Some behavior of the writer is affected by or may affect the contents of
 627 the image metadata which may be supplied by the user.
 628 
 629 <p>For bilevel images, the <tt>FillOrder</tt>, and <tt>T4Options</tt>
 630 fields affect the output data. The data will be filled right-to-left if
 631 <tt>FillOrder</tt> is present with a value of 2
 632 (<code>BaselineTIFFTagSet.FILL_ORDER_RIGHT_TO_LEFT</code>)
 633 and will be filled left-to-right otherwise. The value of <tt>T4Options</tt>
 634 specifies whether the data should be 1D- or 2D-encoded and whether EOL
 635 padding should be used.</p>
 636 
 637 <p>For all images the value of the <tt>RowsPerStrip</tt> field is used
 638 to the set the number of rows per strip if the image is not tiled. The
 639 default number of rows per strip is either 8 or the number of rows which
 640 would fill no more than 8 kilobytes, whichever is larger.</p>
 641 
 642 <p>For all images the tile dimensions may be set using the <tt>TileWidth</tt>
 643 and <tt>TileLength</tt> field values if the tiling mode is
 644 <code>ImageWriteParam.MODE_COPY_FROM_METADATA</code>. If this mode
 645 is set but the fields are not, their respective default values are the image
 646 width and height.</p>
 647 
 648 <p>When using JPEG-in-TIFF compression, a <tt>JPEGTables</tt> field will be
 649 written to the IFD and abbreviated JPEG streams to each strip or tile if and
 650 only if a <tt>JPEGTables</tt> field is contained in the metadata object
 651 provided to the writer. If the contents of the <tt>JPEGTables</tt> field is
 652 a valid tables-only JPEG stream, then it will be used; otherwise the contents
 653 of the field will be replaced with default visually lossless tables. If no
 654 such <tt>JPEGTables</tt> field is present in the metadata, then no
 655 <tt>JPEGTables</tt> field will be written to the output and each strip or
 656 tile will be written as a separate, self-contained JPEG stream.</p>
 657 
 658 <p>When using Deflate/ZLib or LZW compression, if the image has 8 bits per
 659 sample, a horizontal differencing predictor will be used if the
 660 <tt>Predictor</tt> field is present with a value of 2
 661 (<code>BaselineTIFFTagSet.PREDICTOR_HORIZONTAL_DIFFERENCING</code>).
 662 If prediction is so requested but the image does not have
 663 8 bits per sample the field will be reset to have the value 1
 664 (<code>BaselineTIFFTagSet.PREDICTOR_NONE</code>).
 665 </p>
 666 
 667 <p>Some fields may be added or modified:
 668 
 669 <ul>
 670 <li><tt>PhotometricInterpretation</tt> if not present.</li>
 671 <li><tt>PlanarConfiguration</tt> if this field is present with value
 672 <tt>Planar</tt> is is reset to <tt>Chunky</tt>.</li>
 673 <li><tt>Compression</tt> always.</li>
 674 <li><tt>BitsPerSample</tt> if the image is not bilevel.</li>
 675 <li><tt>SamplesPerPixel</tt> always.</li>
 676 <li><tt>ExtraSamples</tt> if an alpha channel is present.</li>
 677 <li><tt>SampleFormat</tt> if not present and the data are 16- or 32-bit
 678 integers or floating point.</li>
 679 <li><tt>ColorMap</tt> if the <tt>PhotometricInterpretation</tt> is
 680 <tt>RGBPalette</tt>.</li>
 681 <li><tt>ImageWidth</tt> and <tt>ImageLength</tt> always.</li>
 682 <li><tt>TileWidth</tt>, <tt>TileLength</tt>, <tt>TileOffsets</tt>, and
 683 <tt>TileByteCounts</tt> if a tiled image is being written.</li>
 684 <li><tt>RowsPerStrip</tt>, <tt>StripOffsets</tt>, and <tt>StripByteCounts</tt>
 685 if a tiled image is <i>not</i> being written.</li>
 686 <li><tt>XResolution</tt>, <tt>YResolution</tt>, and <tt>ResolutionUnit</tt>
 687 if none of these is present.</li>
 688 <li><tt>YCbCrSubsampling</tt> and <tt>YCbCrPositioning</tt> if the
 689 photometric interpretation is YCbCr and the compression type is not JPEG
 690 (only [1,&nbsp;1] subsampling and cosited positioning are supported for
 691 non-JPEG YCbCr output).</li>
 692 <li><tt>YCbCrSubsampling</tt>, <tt>YCbCrPositioning</tt>, and
 693 <tt>ReferenceBlackWhite</tt>: if the compression type is JPEG and the color
 694 space is RGB these will be reset to [2,&nbsp;2] centered subsampling with no
 695 headroom/footroom (0:255,128:255,128:255).</li>
 696 </ul>
 697 
 698 <p>Some fields may be removed:
 699 
 700 <ul>
 701 <li><tt>BitsPerSample</tt> if the image is bilevel.</li>
 702 <li><tt>ExtraSamples</tt> if the image does not have an alpha channel.</li>
 703 <li><tt>ColorMap</tt> if the photometric interpretation is not
 704 <tt>RGBPalette</tt>.</li>
 705 <li><tt>TileWidth</tt>, <tt>TileLength</tt>, <tt>TileOffsets</tt>, and
 706 <tt>TileByteCounts</tt> if tiling <i>is not</i> being used.</li>
 707 <li><tt>RowsPerStrip</tt>, <tt>StripOffsets</tt>, and <tt>StripByteCounts</tt>
 708 if tiling <i>is</i> being used.</li>
 709 <li><tt>YCbCrSubsampling</tt>, <tt>YCbCrPositioning</tt>, and
 710 <tt>ReferenceBlackWhite</tt> if the compression type is JPEG and the
 711 color space is grayscale.</li>
 712 <li><tt>JPEGProc</tt>, <tt>JPEGInterchangeFormat</tt>,
 713 <tt>JPEGInterchangeFormatLength</tt>, <tt>JPEGRestartInterval</tt>,
 714 <tt>JPEGLosslessPredictors</tt>, <tt>JPEGPointTransforms</tt>,
 715 <tt>JPEGQTables</tt>, <tt>JPEGDCTables</tt>, and
 716 <tt>JPEGACTables</tt> if the compression type is JPEG.</li>
 717 </ul>
 718 </p>
 719 
 720 <p>Other fields present in the supplied metadata are uninterpreted and will
 721 be written as supplied.</p>
 722 
 723 <p>If an Exif image is being written, the set of fields present and their
 724 values will be modified such that the result is in accord with the Exif 2.2
 725 specification.</p>
 726 
 727 <p>Setting up the image metadata to write to a TIFF stream may be simplified
 728 by using the <code>TIFFDirectory</code> class
 729 which represents a TIFF IFD. A field in a TIFF IFD is represented by an
 730 instance of <a href="../../plugins/tiff/TIFFField.html">TIFFField</a>. For each
 731 field to be written a <code>TIFFField</code> may be added to the
 732 <code>TIFFDirectory</code> and the latter converted to an
 733 <code>IIOMetadata</code> object by invoking
 734 <code>TIFFDirectory.getAsMetadata</code>. The
 735 <code>IIOMetadata</code> object so obtained may then be passed to the TIFF
 736 writer.</p>
 737 
 738 <h5><a name="MapStandardNative"/>
 739 Mapping of the Standard Metadata Format to TIFF Native Image Metadata</h5>
 740 
 741 The derivation of <a href="#ImageMetadata">TIFF native image metadata</a>
 742 elements from the standard metadata format
 743 <a href="standard_metadata.html">javax_imageio_1.0</a> is
 744 given in the following table.
 745 
 746 <p>
 747 <table border="1">
 748 <tr>
 749 <th>TIFF Field</th>
 750 <th>Derivation from Standard Metadata Elements</th>
 751 </tr>
 752 <tr>
 753 <td>
 754 PhotometricInterpretation
 755 </td>
 756 <td>/Chroma/ColorSpaceType@name: "GRAY" and /Chroma/BlackIsZero@value = "FALSE"
 757 => WhiteIsZero; "GRAY" and /Document/SubimageInterpretation@value =
 758 "TransparencyMask" => TransparencyMask; "RGB" and /Chroma/Palette present =>
 759 PaletteColor; "GRAY" => BlackIsZero; "RGB" => RGB; "YCbCr" => YCbCr;
 760 "CMYK" => CMYK; "Lab" => CIELab.</td>
 761 </tr>
 762 <tr>
 763 <td>SamplesPerPixel</td>
 764 <td>/Chroma/NumChannels@value</td>
 765 </tr>
 766 <tr>
 767 <td>ColorMap</td>
 768 <td>/Chroma/Palette</td>
 769 </tr>
 770 <tr>
 771 <td>Compression</td>
 772 <td>/Compression/CompressionTypeName@value: "none" => Uncompressed;
 773 "CCITT RLE" => CCITT 1D; "CCITT T.4" => Group 3 Fax; "CCITT T.6" => Group 4
 774 Fax; "LZW" => LZW; "Old JPEG" => JPEG; "JPEG" => New JPEG; "ZLib" => ZLib;
 775 "PackBits" => PackBits; "Deflate" => Deflate.</td>
 776 </tr>
 777 <tr>
 778 <td>PlanarConfiguration</td>
 779 <td>/Data/PlanarConfiguration@value: "PixelInterleaved" => Chunky;
 780 "PlaneInterleaved" => Planar.</td>
 781 </tr>
 782 <tr>
 783 <td>SampleFormat</td>
 784 <td>/Data/SampleFormat@value: "SignedIntegral" => two's complement signed
 785 integer data; "UnsignedIntegral" => unsigned integer data; "Real" =>
 786 IEEE floating point data; "Index" => unsigned integer data.
 787 </td>
 788 </tr>
 789 <tr>
 790 <td>BitsPerSample</td>
 791 <td>/Data/BitsPerSample@value: space-separated list parsed to char array.</td>
 792 </tr>
 793 <tr>
 794 <td>FillOrder</td>
 795 <td>/Data/SampleMSB@value: if all values in space-separated list are 0s =>
 796 right-to-left; otherwise => left-to-right.
 797 </td>
 798 </tr>
 799 <tr>
 800 <td>XResolution</td>
 801 <td>(10 / /Dimension/HorizontalPixelSize@value) or
 802 (10 / (/Dimension/VerticalPixelSize@value *
 803 /Dimension/PixelAspectRatio@value))</td>
 804 </tr>
 805 <tr>
 806 <td>YResolution</td>
 807 <td>(10 / /Dimension/VerticalPixelSize@value) or
 808 (10 / (/Dimension/HorizontalPixelSize@value /
 809 /Dimension/PixelAspectRatio@value))</td>
 810 </tr>
 811 <tr>
 812 <td>ResolutionUnit</td>
 813 <td>Centimeter if XResolution or YResolution set; otherwise None.</td>
 814 </tr>
 815 <tr>
 816 <td>Orientation</td>
 817 <td>/Dimension/ImageOrientation@value</td>
 818 </tr>
 819 <tr>
 820 <td>XPosition</td>
 821 <td>/Dimension/HorizontalPosition@value / 10</td>
 822 </tr>
 823 <tr>
 824 <td>YPosition</td>
 825 <td>/Dimension/VerticalPosition@value / 10</td>
 826 </tr>
 827 <tr>
 828 <td>NewSubFileType</td>
 829 <td>/Document/SubimageInterpretation@value: "TransparencyMask" =>
 830 transparency mask; "ReducedResolution" => reduced-resolution;
 831 "SinglePage" => single page.</td>
 832 </tr>
 833 <tr>
 834 <td>DateTime</td>
 835 <td>/Document/ImageCreationTime@value</td>
 836 </tr>
 837 <tr>
 838 <td>DocumentName, ImageDescription, Make, Model, PageName, Software,
 839 Artist, HostComputer, InkNames, Copyright</td>
 840 <td>/Text/TextEntry: if /Text/TextEntry@keyword is the name of any of the
 841 TIFF Fields, e.g., "Software", then the field is added with content
 842 /Text/TextEntry@value and count 1.</td>
 843 </tr>
 844 <tr>
 845 <td>ExtraSamples</td>
 846 <td>/Transparency/Alpha@value: "premultiplied" => associated alpha, count 1;
 847 "nonpremultiplied" => unassociated alpha, count 1.</td>
 848 </tr>
 849 <tr>
 850 <td></td>
 851 <td></td>
 852 </tr>
 853 </table>
 854 </p>
 855 
 856 <h4><a name="ExifWrite"/>Writing Exif Images</h4>
 857 
 858 The TIFF writer may be used to write an uncompressed Exif image or the
 859 contents of the <tt>APP1</tt> marker segment of a compressed Exif image.
 860 
 861 <h5><a name="ExifWriteTIFF"/>Writing Uncompressed Exif Images</h5>
 862 
 863 When writing a sequence of images each image is normally recorded as
 864 {IFD,&nbsp;IFD Value,&nbsp;Image Data}. The Exif specification requires
 865 that an uncompressed Exif image be structured as follows:
 866 
 867 <ol>
 868 <a name="ExifStructure"/>
 869 <li>Image File Header</li>
 870 <li>Primary IFD</li>
 871 <li>Primary IFD Value</li>
 872 <li>Thumbnail IFD</li>
 873 <li>Thumbnail IFD Value</li>
 874 <li>Thumbnail Image Data</li>
 875 <li>Primary Image Data</li>
 876 </ol>
 877 
 878 To meet the requirement of the primary image data being recorded last, the
 879 primary image must be written initially as an empty image and have its data
 880 added via pixel replacement after the thumbnail IFD and image data have been
 881 written:
 882 
 883 <pre><code>
 884     ImageWriter tiffWriter;
 885     ImageWriteParam tiffWriteParam;
 886     IIOMetadata tiffStreamMetadata;
 887     IIOMetadata primaryIFD;
 888     BufferedImage image;
 889     BufferedImage thumbnail;
 890 
 891     // Specify uncompressed output.
 892     tiffWriteParam.setCompressionMode(ImageWriteParam.MODE_DISABLED);
 893 
 894     if (thumbnail != null) {
 895         // Write the TIFF header.
 896         tiffWriter.prepareWriteSequence(tiffStreamMetadata);
 897 
 898         // Append the primary IFD.
 899         tiffWriter.prepareInsertEmpty(-1, // append
 900                 new ImageTypeSpecifier(image),
 901                 image.getWidth(),
 902                 image.getHeight(),
 903                 primaryIFD,
 904                 null, // thumbnails
 905                 tiffWriteParam);
 906         tiffWriter.endInsertEmpty();
 907 
 908         // Append the thumbnail image data.
 909         tiffWriter.writeToSequence(new IIOImage(thumbnail, null, null),
 910                 tiffWriteParam);
 911 
 912         // Insert the primary image data.
 913         tiffWriter.prepareReplacePixels(0, new Rectangle(image.getWidth(),
 914                 image.getHeight()));
 915         tiffWriter.replacePixels(image, tiffWriteParam);
 916         tiffWriter.endReplacePixels();
 917 
 918         // End writing.
 919         tiffWriter.endWriteSequence();
 920     } else {
 921         // Write only the primary IFD and image data.
 922         tiffWriter.write(tiffStreamMetadata,
 923                 new IIOImage(image, null, primaryIFD),
 924                 tiffWriteParam);
 925     }
 926 </code></pre>
 927 
 928 <h5><a name="ExifWriteJPEG"/>Writing Compressed Exif Images</h5>
 929 
 930 The structure of the embedded TIFF stream in the <tt>APP1</tt> segment of a
 931 compressed Exif image is identical to the <a href="#ExifStructure">
 932 uncompressed Exif image structure</a> except that there are no primary
 933 image data, i.e., the primary IFD does not refer to any image data.
 934 
 935 <pre><code>
 936     ImageWriter tiffWriter;
 937     ImageWriteParam tiffWriteParam;
 938     IIOMetadata tiffStreamMetadata;
 939     BufferedImage image;
 940     BufferedImage thumbnail;
 941     IIOMetadata primaryIFD;
 942     ImageOutputStream output;
 943 
 944     // Set up an output to contain the APP1 Exif TIFF stream.
 945     ByteArrayOutputStream baos = new ByteArrayOutputStream();
 946     MemoryCacheImageOutputStream app1ExifOutput =
 947         new MemoryCacheImageOutputStream(baos);
 948     tiffWriter.setOutput(app1ExifOutput);
 949 
 950     // Set compression for the thumbnail.
 951     tiffWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
 952     tiffWriteParam.setCompressionType("Exif JPEG");
 953 
 954     // Write the APP1 Exif TIFF stream.
 955     if (thumbnail != null) {
 956         // Write the TIFF header.
 957         tiffWriter.prepareWriteSequence(tiffStreamMetadata);
 958 
 959         // Append the primary IFD.
 960         tiffWriter.prepareInsertEmpty(-1, // append
 961                 new ImageTypeSpecifier(image),
 962                 image.getWidth(),
 963                 image.getHeight(),
 964                 primaryIFD,
 965                 null, // thumbnails
 966                 tiffWriteParam);
 967         tiffWriter.endInsertEmpty();
 968 
 969         // Append the thumbnail IFD and image data.
 970         tiffWriter.writeToSequence(new IIOImage(thumbnail, null,
 971                 null), tiffWriteParam);
 972 
 973         // End writing.
 974         tiffWriter.endWriteSequence();
 975     } else {
 976         // Write only the primary IFD.
 977         tiffWriter.prepareWriteEmpty(tiffStreamMetadata,
 978                 new ImageTypeSpecifier(image),
 979                 image.getWidth(),
 980                 image.getHeight(),
 981                 primaryIFD,
 982                 null, // thumbnails
 983                 tiffWriteParam);
 984         tiffWriter.endWriteEmpty();
 985     }
 986 
 987     // Flush data into byte stream.
 988     app1ExifOutput.flush();
 989 
 990     // Create APP1 parameter array.
 991     byte[] app1Parameters = new byte[6 + baos.size()];
 992 
 993     // Add APP1 Exif ID bytes.
 994     app1Parameters[0] = (byte) 'E';
 995     app1Parameters[1] = (byte) 'x';
 996     app1Parameters[2] = (byte) 'i';
 997     app1Parameters[3] = (byte) 'f';
 998     app1Parameters[4] = app1Parameters[5] = (byte) 0;
 999 
1000     // Append TIFF stream to APP1 parameters.
1001     System.arraycopy(baos.toByteArray(), 0, app1Parameters, 6, baos.size());
1002 
1003     // Create the APP1 Exif node to be added to native JPEG image metadata.
1004     IIOMetadataNode app1Node = new IIOMetadataNode("unknown");
1005     app1Node.setAttribute("MarkerTag", String.valueOf(0xE1));
1006     app1Node.setUserObject(app1Parameters);
1007 
1008     // Append the APP1 Exif marker to the "markerSequence" node.
1009     IIOMetadata jpegImageMetadata =
1010         jpegWriter.getDefaultImageMetadata(new ImageTypeSpecifier(image),
1011             jpegWriteParam);
1012     String nativeFormat = jpegImageMetadata.getNativeMetadataFormatName();
1013     Node tree = jpegImageMetadata.getAsTree(nativeFormat);
1014     NodeList children = tree.getChildNodes();
1015     int numChildren = children.getLength();
1016     for (int i = 0; i < numChildren; i++) {
1017         Node child = children.item(i);
1018         if (child.getNodeName().equals("markerSequence")) {
1019             child.appendChild(app1Node);
1020             break;
1021         }
1022     }
1023     jpegImageMetadata.setFromTree(nativeFormat, tree);
1024 
1025     // Write the JPEG image data including the APP1 Exif marker.
1026     jpegWriter.setOutput(output);
1027     jpegWriter.write(new IIOImage(image, null, jpegImageMetadata));
1028 </code></pre>
1029 
1030 The <code>"unknown"</code> node created above would be appended to the
1031 <code>"markerSequence"</code> node of the native JPEG image metadata
1032 and written to the JPEG stream when the primary image is written using
1033 the JPEG writer.
1034 
1035 <h3><a name="StreamMetadata"/>Stream Metadata</h3>
1036 
1037 The DTD for the TIFF native stream metadata format is as follows:
1038 
1039 <pre>
1040 &lt;!DOCTYPE "javax_imageio_tiff_stream_1.0" [
1041 
1042   &lt;!ELEMENT "javax_imageio_tiff_stream_1.0" (ByteOrder)>
1043 
1044     &lt;!ELEMENT "ByteOrder" EMPTY&gt;
1045       &lt;!-- The stream byte order --&gt; 
1046       &lt;!ATTLIST "ByteOrder" "value" #CDATA #REQUIRED&gt;
1047         &lt;!-- One of "BIG_ENDIAN" or "LITTLE_ENDIAN" --&gt; 
1048         &lt;!-- Data type: String --&gt;
1049 ]&gt;
1050 </pre>
1051 
1052 <h3><a name="ImageMetadata"/>Image Metadata</h3>
1053 
1054 The DTD for the TIFF native image metadata format is as follows:
1055 
1056 <pre>
1057 &lt;!DOCTYPE "javax_imageio_tiff_image_1.0" [
1058 
1059   &lt;!ELEMENT "javax_imageio_tiff_image_1.0" (TIFFIFD)*&gt;
1060 
1061     &lt;!ELEMENT "TIFFIFD" (TIFFField | TIFFIFD)*&gt;
1062       &lt;!-- An IFD (directory) containing fields --&gt; 
1063       &lt;!ATTLIST "TIFFIFD" "tagSets" #CDATA #REQUIRED&gt;
1064         &lt;!-- Data type: String --&gt;
1065       &lt;!ATTLIST "TIFFIFD" "parentTagNumber" #CDATA #IMPLIED&gt;
1066         &lt;!-- The tag number of the field pointing to this IFD --&gt; 
1067         &lt;!-- Data type: Integer --&gt;
1068       &lt;!ATTLIST "TIFFIFD" "parentTagName" #CDATA #IMPLIED&gt;
1069         &lt;!-- A mnemonic name for the field pointing to this IFD, if known 
1070              --&gt; 
1071         &lt;!-- Data type: String --&gt;
1072 
1073       &lt;!ELEMENT "TIFFField" (TIFFBytes | TIFFAsciis |
1074         TIFFShorts | TIFFSShorts | TIFFLongs | TIFFSLongs |
1075         TIFFRationals | TIFFSRationals |
1076         TIFFFloats | TIFFDoubles | TIFFUndefined)&gt;
1077         &lt;!-- A field containing data --&gt; 
1078         &lt;!ATTLIST "TIFFField" "number" #CDATA #REQUIRED&gt;
1079           &lt;!-- The tag number asociated with the field --&gt; 
1080           &lt;!-- Data type: String --&gt;
1081         &lt;!ATTLIST "TIFFField" "name" #CDATA #IMPLIED&gt;
1082           &lt;!-- A mnemonic name associated with the field, if known --&gt; 
1083           &lt;!-- Data type: String --&gt;
1084 
1085         &lt;!ELEMENT "TIFFBytes" (TIFFByte)*&gt;
1086           &lt;!-- A sequence of TIFFByte nodes --&gt; 
1087 
1088           &lt;!ELEMENT "TIFFByte" EMPTY&gt;
1089             &lt;!-- An integral value between 0 and 255 --&gt; 
1090             &lt;!ATTLIST "TIFFByte" "value" #CDATA #IMPLIED&gt;
1091               &lt;!-- The value --&gt; 
1092               &lt;!-- Data type: String --&gt;
1093             &lt;!ATTLIST "TIFFByte" "description" #CDATA #IMPLIED&gt;
1094               &lt;!-- A description, if available --&gt; 
1095               &lt;!-- Data type: String --&gt;
1096 
1097         &lt;!ELEMENT "TIFFAsciis" (TIFFAscii)*&gt;
1098           &lt;!-- A sequence of TIFFAscii nodes --&gt; 
1099 
1100           &lt;!ELEMENT "TIFFAscii" EMPTY&gt;
1101             &lt;!-- A String value --&gt; 
1102             &lt;!ATTLIST "TIFFAscii" "value" #CDATA #IMPLIED&gt;
1103               &lt;!-- The value --&gt; 
1104               &lt;!-- Data type: String --&gt;
1105 
1106         &lt;!ELEMENT "TIFFShorts" (TIFFShort)*&gt;
1107           &lt;!-- A sequence of TIFFShort nodes --&gt; 
1108 
1109           &lt;!ELEMENT "TIFFShort" EMPTY&gt;
1110             &lt;!-- An integral value between 0 and 65535 --&gt; 
1111             &lt;!ATTLIST "TIFFShort" "value" #CDATA #IMPLIED&gt;
1112               &lt;!-- The value --&gt; 
1113               &lt;!-- Data type: String --&gt;
1114             &lt;!ATTLIST "TIFFShort" "description" #CDATA #IMPLIED&gt;
1115               &lt;!-- A description, if available --&gt; 
1116               &lt;!-- Data type: String --&gt;
1117 
1118         &lt;!ELEMENT "TIFFSShorts" (TIFFSShort)*&gt;
1119           &lt;!-- A sequence of TIFFSShort nodes --&gt; 
1120 
1121           &lt;!ELEMENT "TIFFSShort" EMPTY&gt;
1122             &lt;!-- An integral value between -32768 and 32767 --&gt; 
1123             &lt;!ATTLIST "TIFFSShort" "value" #CDATA #IMPLIED&gt;
1124               &lt;!-- The value --&gt; 
1125               &lt;!-- Data type: String --&gt;
1126             &lt;!ATTLIST "TIFFSShort" "description" #CDATA #IMPLIED&gt;
1127               &lt;!-- A description, if available --&gt; 
1128               &lt;!-- Data type: String --&gt;
1129 
1130         &lt;!ELEMENT "TIFFLongs" (TIFFLong)*&gt;
1131           &lt;!-- A sequence of TIFFLong nodes --&gt; 
1132 
1133           &lt;!ELEMENT "TIFFLong" EMPTY&gt;
1134             &lt;!-- An integral value between 0 and 4294967295 --&gt; 
1135             &lt;!ATTLIST "TIFFLong" "value" #CDATA #IMPLIED&gt;
1136               &lt;!-- The value --&gt; 
1137               &lt;!-- Data type: String --&gt;
1138             &lt;!ATTLIST "TIFFLong" "description" #CDATA #IMPLIED&gt;
1139               &lt;!-- A description, if available --&gt; 
1140               &lt;!-- Data type: String --&gt;
1141 
1142         &lt;!ELEMENT "TIFFSLongs" (TIFFSLong)*&gt;
1143           &lt;!-- A sequence of TIFFSLong nodes --&gt; 
1144 
1145           &lt;!ELEMENT "TIFFSLong" EMPTY&gt;
1146             &lt;!-- An integral value between -2147483648 and 2147482647 --&gt; 
1147             &lt;!ATTLIST "TIFFSLong" "value" #CDATA #IMPLIED&gt;
1148               &lt;!-- The value --&gt; 
1149               &lt;!-- Data type: String --&gt;
1150             &lt;!ATTLIST "TIFFSLong" "description" #CDATA #IMPLIED&gt;
1151               &lt;!-- A description, if available --&gt; 
1152               &lt;!-- Data type: String --&gt;
1153 
1154         &lt;!ELEMENT "TIFFRationals" (TIFFRational)*&gt;
1155           &lt;!-- A sequence of TIFFRational nodes --&gt; 
1156 
1157           &lt;!ELEMENT "TIFFRational" EMPTY&gt;
1158             &lt;!-- A rational value consisting of an unsigned numerator and 
1159                  denominator --&gt; 
1160             &lt;!ATTLIST "TIFFRational" "value" #CDATA #IMPLIED&gt;
1161               &lt;!-- The numerator and denominator, separated by a slash --&gt; 
1162               &lt;!-- Data type: String --&gt;
1163 
1164         &lt;!ELEMENT "TIFFSRationals" (TIFFSRational)*&gt;
1165           &lt;!-- A sequence of TIFFSRational nodes --&gt; 
1166 
1167           &lt;!ELEMENT "TIFFSRational" EMPTY&gt;
1168             &lt;!-- A rational value consisting of a signed numerator and 
1169                  denominator --&gt; 
1170             &lt;!ATTLIST "TIFFSRational" "value" #CDATA #IMPLIED&gt;
1171               &lt;!-- The numerator and denominator, separated by a slash --&gt; 
1172               &lt;!-- Data type: String --&gt;
1173 
1174         &lt;!ELEMENT "TIFFFloats" (TIFFFloat)*&gt;
1175           &lt;!-- A sequence of TIFFFloat nodes --&gt; 
1176 
1177           &lt;!ELEMENT "TIFFFloat" EMPTY&gt;
1178             &lt;!-- A single-precision floating-point value --&gt; 
1179             &lt;!ATTLIST "TIFFFloat" "value" #CDATA #IMPLIED&gt;
1180               &lt;!-- The value --&gt; 
1181               &lt;!-- Data type: String --&gt;
1182 
1183         &lt;!ELEMENT "TIFFDoubles" (TIFFDouble)*&gt;
1184           &lt;!-- A sequence of TIFFDouble nodes --&gt; 
1185 
1186           &lt;!ELEMENT "TIFFDouble" EMPTY&gt;
1187             &lt;!-- A double-precision floating-point value --&gt; 
1188             &lt;!ATTLIST "TIFFDouble" "value" #CDATA #IMPLIED&gt;
1189               &lt;!-- The value --&gt; 
1190               &lt;!-- Data type: String --&gt;
1191 
1192         &lt;!ELEMENT "TIFFUndefined" EMPTY&gt;
1193           &lt;!-- Uninterpreted byte data --&gt; 
1194           &lt;!ATTLIST "TIFFUndefined" "value" #CDATA #IMPLIED&gt;
1195             &lt;!-- A list of comma-separated byte values --&gt; 
1196             &lt;!-- Data type: String --&gt;
1197 ]&gt;
1198 </pre>
1199 
1200 @since 9
1201 
1202 </body>
1203 </html>