1 /*
   2  * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package javax.imageio.plugins.tiff;
  26 
  27 import java.util.ArrayList;
  28 import java.util.List;
  29 
  30 /**
  31  * A class containing the TIFF tags used to reference the Exif and GPS IFDs.
  32  * This tag set should be added to the root tag set by means of the
  33  * {@link TIFFImageReadParam#addAllowedTagSet(TIFFTagSet)
  34  * TIFFImageReadParam.addAllowedTagSet} method if Exif
  35  * support is desired.
  36  *
  37  * @since 9
  38  */
  39 public class ExifParentTIFFTagSet extends TIFFTagSet {
  40 
  41     private static ExifParentTIFFTagSet theInstance = null;
  42 
  43     // 34665 - Exif IFD Pointer                   (LONG/1)
  44     /** Tag pointing to the Exif IFD (type LONG). */
  45     public static final int TAG_EXIF_IFD_POINTER = 34665;
  46 
  47     /** Tag pointing to a GPS info IFD (type LONG). */
  48     public static final int TAG_GPS_INFO_IFD_POINTER = 34853;
  49 
  50     // To be inserted into parent (root) TIFFTagSet
  51     static class ExifIFDPointer extends TIFFTag {
  52 
  53         public ExifIFDPointer() {
  54             super("ExifIFDPointer",
  55                   TAG_EXIF_IFD_POINTER,
  56                   ExifTIFFTagSet.getInstance());
  57         }
  58     }
  59 
  60     // To be inserted into parent (root) TIFFTagSet
  61     static class GPSInfoIFDPointer extends TIFFTag {
  62 
  63         public GPSInfoIFDPointer() {
  64             super("GPSInfoIFDPointer",
  65                   TAG_GPS_INFO_IFD_POINTER,
  66                   ExifGPSTagSet.getInstance());
  67         }
  68     }
  69 
  70     private static List<TIFFTag> tags;
  71 
  72     private static void initTags() {
  73         tags = new ArrayList<TIFFTag>(1);
  74         tags.add(new ExifParentTIFFTagSet.ExifIFDPointer());
  75         tags.add(new ExifParentTIFFTagSet.GPSInfoIFDPointer());
  76     }
  77 
  78     private ExifParentTIFFTagSet() {
  79         super(tags);
  80     }
  81 
  82     /**
  83      * Returns a shared instance of an <code>ExifParentTIFFTagSet</code>.
  84      *
  85      * @return an <code>ExifParentTIFFTagSet</code> instance.
  86      */
  87     public synchronized static ExifParentTIFFTagSet getInstance() {
  88         if (theInstance == null) {
  89             initTags();
  90             theInstance = new ExifParentTIFFTagSet();
  91             tags = null;
  92         }
  93         return theInstance;
  94     }
  95 }