jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFIFD.java
changeset 42188 471f232f8ea8
parent 40442 e97e9982be6d
child 42749 91fb907a8732
equal deleted inserted replaced
42187:b2f0bdbfd4f2 42188:471f232f8ea8
    47 
    47 
    48     private long stripOrTileByteCountsPosition = -1;
    48     private long stripOrTileByteCountsPosition = -1;
    49     private long stripOrTileOffsetsPosition = -1;
    49     private long stripOrTileOffsetsPosition = -1;
    50     private long lastPosition = -1;
    50     private long lastPosition = -1;
    51 
    51 
       
    52     //
       
    53     // A set of tag numbers corresponding to tags essential to decoding
       
    54     // the image and metadata required to interpret its samples.
       
    55     //
       
    56     private static volatile Set<Integer> essentialTags = null;
       
    57 
       
    58     private static void initializeEssentialTags() {
       
    59         Set<Integer> tags = essentialTags;
       
    60         if (tags == null) {
       
    61             essentialTags = tags = Set.of(
       
    62                 BaselineTIFFTagSet.TAG_BITS_PER_SAMPLE,
       
    63                 BaselineTIFFTagSet.TAG_COLOR_MAP,
       
    64                 BaselineTIFFTagSet.TAG_COMPRESSION,
       
    65                 BaselineTIFFTagSet.TAG_EXTRA_SAMPLES,
       
    66                 BaselineTIFFTagSet.TAG_FILL_ORDER,
       
    67                 BaselineTIFFTagSet.TAG_ICC_PROFILE,
       
    68                 BaselineTIFFTagSet.TAG_IMAGE_LENGTH,
       
    69                 BaselineTIFFTagSet.TAG_IMAGE_WIDTH,
       
    70                 BaselineTIFFTagSet.TAG_JPEG_AC_TABLES,
       
    71                 BaselineTIFFTagSet.TAG_JPEG_DC_TABLES,
       
    72                 BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT,
       
    73                 BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT_LENGTH,
       
    74                 BaselineTIFFTagSet.TAG_JPEG_PROC,
       
    75                 BaselineTIFFTagSet.TAG_JPEG_Q_TABLES,
       
    76                 BaselineTIFFTagSet.TAG_JPEG_RESTART_INTERVAL,
       
    77                 BaselineTIFFTagSet.TAG_JPEG_TABLES,
       
    78                 BaselineTIFFTagSet.TAG_PHOTOMETRIC_INTERPRETATION,
       
    79                 BaselineTIFFTagSet.TAG_PLANAR_CONFIGURATION,
       
    80                 BaselineTIFFTagSet.TAG_PREDICTOR,
       
    81                 BaselineTIFFTagSet.TAG_REFERENCE_BLACK_WHITE,
       
    82                 BaselineTIFFTagSet.TAG_ROWS_PER_STRIP,
       
    83                 BaselineTIFFTagSet.TAG_SAMPLES_PER_PIXEL,
       
    84                 BaselineTIFFTagSet.TAG_SAMPLE_FORMAT,
       
    85                 BaselineTIFFTagSet.TAG_STRIP_BYTE_COUNTS,
       
    86                 BaselineTIFFTagSet.TAG_STRIP_OFFSETS,
       
    87                 BaselineTIFFTagSet.TAG_T4_OPTIONS,
       
    88                 BaselineTIFFTagSet.TAG_T6_OPTIONS,
       
    89                 BaselineTIFFTagSet.TAG_TILE_BYTE_COUNTS,
       
    90                 BaselineTIFFTagSet.TAG_TILE_LENGTH,
       
    91                 BaselineTIFFTagSet.TAG_TILE_OFFSETS,
       
    92                 BaselineTIFFTagSet.TAG_TILE_WIDTH,
       
    93                 BaselineTIFFTagSet.TAG_Y_CB_CR_COEFFICIENTS,
       
    94                 BaselineTIFFTagSet.TAG_Y_CB_CR_SUBSAMPLING
       
    95             );
       
    96         }
       
    97     }
    52 
    98 
    53     /**
    99     /**
    54      * Converts a {@code TIFFDirectory} to a {@code TIFFIFD}.
   100      * Converts a {@code TIFFDirectory} to a {@code TIFFIFD}.
    55      */
   101      */
    56     public static TIFFIFD getDirectoryAsIFD(TIFFDirectory dir) {
   102     public static TIFFIFD getDirectoryAsIFD(TIFFDirectory dir) {
   505         long streamLength = stream.length();
   551         long streamLength = stream.length();
   506         boolean haveStreamLength = streamLength != -1;
   552         boolean haveStreamLength = streamLength != -1;
   507 
   553 
   508         List<TIFFTagSet> tagSetList = getTagSetList();
   554         List<TIFFTagSet> tagSetList = getTagSetList();
   509 
   555 
       
   556         boolean ensureEssentialTags = false;
       
   557         TIFFTagSet baselineTagSet = null;
       
   558         if (isPrimaryIFD && ignoreUnknownFields
       
   559             && !tagSetList.contains(BaselineTIFFTagSet.getInstance())) {
       
   560             ensureEssentialTags = true;
       
   561             initializeEssentialTags();
       
   562             baselineTagSet = BaselineTIFFTagSet.getInstance();
       
   563         }
       
   564 
   510         List<Object> entries = new ArrayList<>();
   565         List<Object> entries = new ArrayList<>();
   511         Object[] entryData = new Object[1]; // allocate once for later reuse.
   566         Object[] entryData = new Object[1]; // allocate once for later reuse.
   512 
   567 
   513         // Read the IFD entries, loading the field values which are no more than
   568         // Read the IFD entries, loading the field values which are no more than
   514         // four bytes long, and storing the 4-byte offsets for the others.
   569         // four bytes long, and storing the 4-byte offsets for the others.
   527             }
   582             }
   528             long longCount = stream.readUnsignedInt();
   583             long longCount = stream.readUnsignedInt();
   529 
   584 
   530             // Get the associated TIFFTag.
   585             // Get the associated TIFFTag.
   531             TIFFTag tag = getTag(tagNumber, tagSetList);
   586             TIFFTag tag = getTag(tagNumber, tagSetList);
       
   587 
       
   588             if (tag == null && ensureEssentialTags
       
   589                 && essentialTags.contains(tagNumber)) {
       
   590                 tag = baselineTagSet.getTag(tagNumber);
       
   591             }
   532 
   592 
   533             // Ignore unknown fields, fields with unknown type, and fields
   593             // Ignore unknown fields, fields with unknown type, and fields
   534             // with count out of int range.
   594             // with count out of int range.
   535             if((tag == null && ignoreUnknownFields)
   595             if((tag == null && ignoreUnknownFields)
   536                 || (tag != null && !tag.isDataTypeOK(type))
   596                 || (tag != null && !tag.isDataTypeOK(type))