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 representing the tags found in a GeoTIFF IFD.  GeoTIFF is a
  32  * standard for annotating georeferenced or geocoded raster imagery.
  33  * The GeoTIFF specification may be found at <a
  34  * href="http://www.remotesensing.org/geotiff/spec/geotiffhome.html">
  35  * <code>http://www.remotesensing.org/geotiff/spec/geotiffhome.html</code>
  36  * </a>. This class does <i>not</i> handle the <i>GeoKey</i>s referenced
  37  * from a <i>GeoKeyDirectoryTag</i> as those are not TIFF tags per se.
  38  *
  39  * <p>The definitions of the data types referenced by the field
  40  * definitions may be found in the {@link TIFFTag TIFFTag} class.</p>
  41  *
  42  * @since 1.9
  43  */
  44 public class GeoTIFFTagSet extends TIFFTagSet {
  45 
  46     private static GeoTIFFTagSet theInstance = null;
  47 
  48     /**
  49      * A tag used to specify the size of raster pixel spacing in
  50      * model space units.
  51      */
  52     public static final int TAG_MODEL_PIXEL_SCALE = 33550;
  53 
  54     /**
  55      * A tag used to specify the transformation matrix between the raster
  56      * space and the model space.
  57      */
  58     public static final int TAG_MODEL_TRANSFORMATION = 34264;
  59 
  60     /** A tag used to store raster-to-model tiepoint pairs. */
  61     public static final int TAG_MODEL_TIE_POINT = 33922;
  62 
  63     /** A tag used to store the <i>GeoKey</i> directory. */
  64     public static final int TAG_GEO_KEY_DIRECTORY = 34735;
  65 
  66     /** A tag used to store all <code>double</code>-values <i>GeoKey</i>s. */
  67     public static final int TAG_GEO_DOUBLE_PARAMS = 34736;
  68 
  69     /** A tag used to store all ASCII-values <i>GeoKey</i>s. */
  70     public static final int TAG_GEO_ASCII_PARAMS = 34737;
  71 
  72     // GeoTIFF tags
  73 
  74     static class ModelPixelScale extends TIFFTag {
  75         public ModelPixelScale() {
  76             super("ModelPixelScaleTag",
  77                   TAG_MODEL_PIXEL_SCALE,
  78                   1 << TIFFTag.TIFF_DOUBLE);
  79         }
  80     }
  81 
  82     static class ModelTransformation extends TIFFTag {
  83         public ModelTransformation() {
  84             super("ModelTransformationTag",
  85                   TAG_MODEL_TRANSFORMATION,
  86                   1 << TIFFTag.TIFF_DOUBLE);
  87         }
  88     }
  89 
  90     static class ModelTiePoint extends TIFFTag {
  91         public ModelTiePoint() {
  92             super("ModelTiePointTag",
  93                   TAG_MODEL_TIE_POINT,
  94                   1 << TIFFTag.TIFF_DOUBLE);
  95         }
  96     }
  97 
  98     static class GeoKeyDirectory extends TIFFTag {
  99         public GeoKeyDirectory() {
 100             super("GeoKeyDirectory",
 101                   TAG_GEO_KEY_DIRECTORY,
 102                   1 << TIFFTag.TIFF_SHORT);
 103         }
 104     }
 105 
 106     static class GeoDoubleParams extends TIFFTag {
 107         public GeoDoubleParams() {
 108             super("GeoDoubleParams",
 109                   TAG_GEO_DOUBLE_PARAMS,
 110                   1 << TIFFTag.TIFF_DOUBLE);
 111         }
 112     }
 113 
 114     static class GeoAsciiParams extends TIFFTag {
 115         public GeoAsciiParams() {
 116             super("GeoAsciiParams",
 117                   TAG_GEO_ASCII_PARAMS,
 118                   1 << TIFFTag.TIFF_ASCII);
 119         }
 120     }
 121 
 122     private static List<TIFFTag> tags;
 123 
 124     private static void initTags() {
 125         tags = new ArrayList<TIFFTag>(42);
 126 
 127         tags.add(new GeoTIFFTagSet.ModelPixelScale());
 128         tags.add(new GeoTIFFTagSet.ModelTransformation());
 129         tags.add(new GeoTIFFTagSet.ModelTiePoint());
 130         tags.add(new GeoTIFFTagSet.GeoKeyDirectory());
 131         tags.add(new GeoTIFFTagSet.GeoDoubleParams());
 132         tags.add(new GeoTIFFTagSet.GeoAsciiParams());
 133     }
 134 
 135     private GeoTIFFTagSet() {
 136         super(tags);
 137     }
 138 
 139     /**
 140      * Returns a shared instance of a <code>GeoTIFFTagSet</code>.
 141      *
 142      * @return a <code>GeoTIFFTagSet</code> instance.
 143      */
 144     public synchronized static GeoTIFFTagSet getInstance() {
 145         if (theInstance == null) {
 146             initTags();
 147             theInstance = new GeoTIFFTagSet();
 148             tags = null;
 149         }
 150         return theInstance;
 151     }
 152 }