< prev index next >

src/java.desktop/share/classes/javax/imageio/plugins/tiff/TIFFTag.java

Print this page




 223      * is negative or specifies an out of range type.
 224      *
 225      * @see #TIFFTag(String, int, int, int)
 226      */
 227     public TIFFTag(String name, int number, int dataTypes) {
 228         this(name, number, dataTypes, -1);
 229     }
 230 
 231     /**
 232      * Returns the number of bytes used to store a value of the given
 233      * data type.
 234      *
 235      * @param dataType the data type to be queried.
 236      *
 237      * @return the number of bytes used to store the given data type.
 238      *
 239      * @throws IllegalArgumentException if {@code datatype} is
 240      * less than {@code MIN_DATATYPE} or greater than
 241      * {@code MAX_DATATYPE}.
 242      */
 243     public static int getSizeOfType(int dataType) {
 244         if (dataType < MIN_DATATYPE ||dataType > MAX_DATATYPE) {
 245             throw new IllegalArgumentException("dataType out of range!");
 246         }
 247 
 248         return SIZE_OF_TYPE[dataType];
 249     }
 250 
 251     /**
 252      * Returns the name of the tag, as it will appear in image metadata.
 253      *
 254      * @return the tag name, as a {@code String}.
 255      */
 256     public String getName() {
 257         return name;
 258     }
 259 
 260     /**
 261      * Returns the integer used to represent the tag.
 262      *
 263      * @return the tag number, as an {@code int}.
 264      */
 265     public int getNumber() {
 266         return number;
 267     }
 268 
 269     /**
 270      * Returns a bit mask indicating the set of data types that may
 271      * be used to store the data associated with the tag.
 272      * For example, a tag that can store both SHORT and LONG values
 273      * would return a value of:
 274      *
 275      * <pre>
 276      * (1 &lt;&lt; TIFFTag.TIFF_SHORT) | (1 &lt;&lt; TIFFTag.TIFF_LONG)
 277      * </pre>
 278      *
 279      * @return an {@code int} containing a bitmask encoding the
 280      * set of valid data types.
 281      */
 282     public int getDataTypes() {
 283         return dataTypes;
 284     }
 285 
 286     /**
 287      * Returns the value count of this tag. If this value is positive, it
 288      * represents the required number of values for a {@code TIFFField}
 289      * which has this tag. If the value is negative, the count is undefined.
 290      * In the latter case the count may be derived, e.g., the number of values
 291      * of the {@code BitsPerSample} field is {@code SamplesPerPixel},
 292      * or it may be variable as in the case of most {@code US-ASCII}
 293      * fields.
 294      *
 295      * @return the value count of this tag.
 296      */
 297     public int getCount() {
 298         return count;
 299     }
 300 
 301     /**
 302      * Returns {@code true} if the given data type
 303      * may be used for the data associated with this tag.
 304      *
 305      * @param dataType the data type to be queried, one of
 306      * {@code TIFF_BYTE}, {@code TIFF_SHORT}, etc.
 307      *
 308      * @return a {@code boolean} indicating whether the given
 309      * data type may be used with this tag.
 310      *
 311      * @throws IllegalArgumentException if {@code datatype} is
 312      * less than {@code MIN_DATATYPE} or greater than
 313      * {@code MAX_DATATYPE}.
 314      */
 315     public boolean isDataTypeOK(int dataType) {
 316         if (dataType < MIN_DATATYPE || dataType > MAX_DATATYPE) {
 317             throw new IllegalArgumentException("datatype not in range!");
 318         }
 319         return (dataTypes & (1 << dataType)) != 0;
 320     }
 321 
 322     /**
 323      * Returns the {@code TIFFTagSet} of which this tag is a part.
 324      *
 325      * @return the containing {@code TIFFTagSet}.
 326      */
 327     public TIFFTagSet getTagSet() {
 328         return tagSet;
 329     }
 330 
 331     /**
 332      * Returns {@code true} if this tag is used to point to an IFD
 333      * structure containing additional tags. A {@code TIFFTag} represents
 334      * an IFD pointer if and only if its {@code TIFFTagSet} is
 335      * non-{@code null} or the data type {@code TIFF_IFD_POINTER} is
 336      * legal. This condition will be satisfied if and only if either
 337      * {@code getTagSet() != null} or
 338      * {@code isDataTypeOK(TIFF_IFD_POINTER) == true}.
 339      *
 340      * <p>Many TIFF extensions use the IFD mechanism in order to limit the
 341      * number of new tags that may appear in the root IFD.</p>
 342      *
 343      * @return {@code true} if this tag points to an IFD.
 344      */
 345     public boolean isIFDPointer() {
 346         return tagSet != null || isDataTypeOK(TIFF_IFD_POINTER);
 347     }
 348 
 349     /**
 350      * Returns {@code true} if there are mnemonic names associated with
 351      * the set of legal values for the data associated with this tag.  Mnemonic
 352      * names apply only to tags which have integral data type.
 353      *
 354      * @return {@code true} if mnemonic value names are available.
 355      */
 356     public boolean hasValueNames() {
 357         return valueNames != null;
 358     }
 359 
 360     /**
 361      * Adds a mnemonic name for a particular value that this tag's data may take
 362      * on.  Mnemonic names apply only to tags which have integral data type.
 363      *
 364      * @param value the data value.
 365      * @param name the name to associate with the value.
 366      */
 367     protected void addValueName(int value, String name) {
 368         if (valueNames == null) {
 369             valueNames = new TreeMap<Integer,String>();
 370         }
 371         valueNames.put(Integer.valueOf(value), name);
 372     }
 373 
 374     /**
 375      * Returns the mnemonic name associated with a particular value
 376      * that this tag's data may take on, or {@code null} if
 377      * no name is present.  Mnemonic names apply only to tags which have
 378      * integral data type.
 379      *
 380      * @param value the data value.
 381      *
 382      * @return the mnemonic name associated with the value, as a
 383      * {@code String}.
 384      */
 385     public String getValueName(int value) {
 386         if (valueNames == null) {
 387             return null;
 388         }
 389         return valueNames.get(Integer.valueOf(value));
 390     }
 391 
 392     /**
 393      * Returns an array of values for which mnemonic names are defined.  The
 394      * method {@link #getValueName(int) getValueName()} will return
 395      * non-{@code null} only for values contained in the returned array.
 396      * Mnemonic names apply only to tags which have integral data type.
 397      *
 398      * @return the values for which there is a mnemonic name.
 399      */
 400     public int[] getNamedValues() {
 401         int[] intValues = null;
 402         if (valueNames != null) {
 403             Set<Integer> values = valueNames.keySet();
 404             Iterator<Integer> iter = values.iterator();
 405             intValues = new int[values.size()];
 406             int i = 0;
 407             while (iter.hasNext()) {
 408                 intValues[i++] = iter.next();
 409             }
 410         }
 411         return intValues;
 412     }
 413 }


 223      * is negative or specifies an out of range type.
 224      *
 225      * @see #TIFFTag(String, int, int, int)
 226      */
 227     public TIFFTag(String name, int number, int dataTypes) {
 228         this(name, number, dataTypes, -1);
 229     }
 230 
 231     /**
 232      * Returns the number of bytes used to store a value of the given
 233      * data type.
 234      *
 235      * @param dataType the data type to be queried.
 236      *
 237      * @return the number of bytes used to store the given data type.
 238      *
 239      * @throws IllegalArgumentException if {@code datatype} is
 240      * less than {@code MIN_DATATYPE} or greater than
 241      * {@code MAX_DATATYPE}.
 242      */
 243     public static final int getSizeOfType(int dataType) {
 244         if (dataType < MIN_DATATYPE ||dataType > MAX_DATATYPE) {
 245             throw new IllegalArgumentException("dataType out of range!");
 246         }
 247 
 248         return SIZE_OF_TYPE[dataType];
 249     }
 250 
 251     /**
 252      * Returns the name of the tag, as it will appear in image metadata.
 253      *
 254      * @return the tag name, as a {@code String}.
 255      */
 256     public final String getName() {
 257         return name;
 258     }
 259 
 260     /**
 261      * Returns the integer used to represent the tag.
 262      *
 263      * @return the tag number, as an {@code int}.
 264      */
 265     public final int getNumber() {
 266         return number;
 267     }
 268 
 269     /**
 270      * Returns a bit mask indicating the set of data types that may
 271      * be used to store the data associated with the tag.
 272      * For example, a tag that can store both SHORT and LONG values
 273      * would return a value of:
 274      *
 275      * <pre>
 276      * (1 &lt;&lt; TIFFTag.TIFF_SHORT) | (1 &lt;&lt; TIFFTag.TIFF_LONG)
 277      * </pre>
 278      *
 279      * @return an {@code int} containing a bitmask encoding the
 280      * set of valid data types.
 281      */
 282     public final int getDataTypes() {
 283         return dataTypes;
 284     }
 285 
 286     /**
 287      * Returns the value count of this tag. If this value is positive, it
 288      * represents the required number of values for a {@code TIFFField}
 289      * which has this tag. If the value is negative, the count is undefined.
 290      * In the latter case the count may be derived, e.g., the number of values
 291      * of the {@code BitsPerSample} field is {@code SamplesPerPixel},
 292      * or it may be variable as in the case of most {@code US-ASCII}
 293      * fields.
 294      *
 295      * @return the value count of this tag.
 296      */
 297     public final int getCount() {
 298         return count;
 299     }
 300 
 301     /**
 302      * Returns {@code true} if the given data type
 303      * may be used for the data associated with this tag.
 304      *
 305      * @param dataType the data type to be queried, one of
 306      * {@code TIFF_BYTE}, {@code TIFF_SHORT}, etc.
 307      *
 308      * @return a {@code boolean} indicating whether the given
 309      * data type may be used with this tag.
 310      *
 311      * @throws IllegalArgumentException if {@code datatype} is
 312      * less than {@code MIN_DATATYPE} or greater than
 313      * {@code MAX_DATATYPE}.
 314      */
 315     public final boolean isDataTypeOK(int dataType) {
 316         if (dataType < MIN_DATATYPE || dataType > MAX_DATATYPE) {
 317             throw new IllegalArgumentException("datatype not in range!");
 318         }
 319         return (dataTypes & (1 << dataType)) != 0;
 320     }
 321 
 322     /**
 323      * Returns the {@code TIFFTagSet} of which this tag is a part.
 324      *
 325      * @return the containing {@code TIFFTagSet}.
 326      */
 327     public final TIFFTagSet getTagSet() {
 328         return tagSet;
 329     }
 330 
 331     /**
 332      * Returns {@code true} if this tag is used to point to an IFD
 333      * structure containing additional tags. A {@code TIFFTag} represents
 334      * an IFD pointer if and only if its {@code TIFFTagSet} is
 335      * non-{@code null} or the data type {@code TIFF_IFD_POINTER} is
 336      * legal. This condition will be satisfied if and only if either
 337      * {@code getTagSet() != null} or
 338      * {@code isDataTypeOK(TIFF_IFD_POINTER) == true}.
 339      *
 340      * <p>Many TIFF extensions use the IFD mechanism in order to limit the
 341      * number of new tags that may appear in the root IFD.</p>
 342      *
 343      * @return {@code true} if this tag points to an IFD.
 344      */
 345     public final boolean isIFDPointer() {
 346         return tagSet != null || isDataTypeOK(TIFF_IFD_POINTER);
 347     }
 348 
 349     /**
 350      * Returns {@code true} if there are mnemonic names associated with
 351      * the set of legal values for the data associated with this tag.  Mnemonic
 352      * names apply only to tags which have integral data type.
 353      *
 354      * @return {@code true} if mnemonic value names are available.
 355      */
 356     public final boolean hasValueNames() {
 357         return valueNames != null;
 358     }
 359 
 360     /**
 361      * Adds a mnemonic name for a particular value that this tag's data may take
 362      * on.  Mnemonic names apply only to tags which have integral data type.
 363      *
 364      * @param value the data value.
 365      * @param name the name to associate with the value.
 366      */
 367     protected void addValueName(int value, String name) {
 368         if (valueNames == null) {
 369             valueNames = new TreeMap<Integer,String>();
 370         }
 371         valueNames.put(Integer.valueOf(value), name);
 372     }
 373 
 374     /**
 375      * Returns the mnemonic name associated with a particular value
 376      * that this tag's data may take on, or {@code null} if
 377      * no name is present.  Mnemonic names apply only to tags which have
 378      * integral data type.
 379      *
 380      * @param value the data value.
 381      *
 382      * @return the mnemonic name associated with the value, as a
 383      * {@code String}.
 384      */
 385     public final String getValueName(int value) {
 386         if (valueNames == null) {
 387             return null;
 388         }
 389         return valueNames.get(Integer.valueOf(value));
 390     }
 391 
 392     /**
 393      * Returns an array of values for which mnemonic names are defined.  The
 394      * method {@link #getValueName(int) getValueName()} will return
 395      * non-{@code null} only for values contained in the returned array.
 396      * Mnemonic names apply only to tags which have integral data type.
 397      *
 398      * @return the values for which there is a mnemonic name.
 399      */
 400     public final int[] getNamedValues() {
 401         int[] intValues = null;
 402         if (valueNames != null) {
 403             Set<Integer> values = valueNames.keySet();
 404             Iterator<Integer> iter = values.iterator();
 405             intValues = new int[values.size()];
 406             int i = 0;
 407             while (iter.hasNext()) {
 408                 intValues[i++] = iter.next();
 409             }
 410         }
 411         return intValues;
 412     }
 413 }
< prev index next >