Esempio n. 1
0
  public static TIFFTag getTag(String tagName, List tagSets) {
    Iterator iter = tagSets.iterator();
    while (iter.hasNext()) {
      TIFFTagSet tagSet = (TIFFTagSet) iter.next();
      TIFFTag tag = tagSet.getTag(tagName);
      if (tag != null) {
        return tag;
      }
    }

    return null;
  }
Esempio n. 2
0
  /**
   * Returns a <code>TIFFIFD</code> wherein all fields from the <code>BaselineTIFFTagSet</code> are
   * copied by value and all other fields copied by reference.
   */
  public TIFFIFD getShallowClone() {
    // Get the baseline TagSet.
    TIFFTagSet baselineTagSet = BaselineTIFFTagSet.getInstance();

    // If the baseline TagSet is not included just return.
    List tagSetList = getTagSetList();
    if (!tagSetList.contains(baselineTagSet)) {
      return this;
    }

    // Create a new object.
    TIFFIFD shallowClone = new TIFFIFD(tagSetList, getParentTag());

    // Get the tag numbers in the baseline set.
    Set baselineTagNumbers = baselineTagSet.getTagNumbers();

    // Iterate over the fields in this IFD.
    Iterator fields = iterator();
    while (fields.hasNext()) {
      // Get the next field.
      TIFFField field = (TIFFField) fields.next();

      // Get its tag number.
      Integer tagNumber = new Integer(field.getTagNumber());

      // Branch based on membership in baseline set.
      TIFFField fieldClone;
      if (baselineTagNumbers.contains(tagNumber)) {
        // Copy by value.
        Object fieldData = field.getData();

        int fieldType = field.getType();

        try {
          switch (fieldType) {
            case TIFFTag.TIFF_BYTE:
            case TIFFTag.TIFF_SBYTE:
            case TIFFTag.TIFF_UNDEFINED:
              fieldData = ((byte[]) fieldData).clone();
              break;
            case TIFFTag.TIFF_ASCII:
              fieldData = ((String[]) fieldData).clone();
              break;
            case TIFFTag.TIFF_SHORT:
              fieldData = ((char[]) fieldData).clone();
              break;
            case TIFFTag.TIFF_LONG:
            case TIFFTag.TIFF_IFD_POINTER:
              fieldData = ((long[]) fieldData).clone();
              break;
            case TIFFTag.TIFF_RATIONAL:
              fieldData = ((long[][]) fieldData).clone();
              break;
            case TIFFTag.TIFF_SSHORT:
              fieldData = ((short[]) fieldData).clone();
              break;
            case TIFFTag.TIFF_SLONG:
              fieldData = ((int[]) fieldData).clone();
              break;
            case TIFFTag.TIFF_SRATIONAL:
              fieldData = ((int[][]) fieldData).clone();
              break;
            case TIFFTag.TIFF_FLOAT:
              fieldData = ((float[]) fieldData).clone();
              break;
            case TIFFTag.TIFF_DOUBLE:
              fieldData = ((double[]) fieldData).clone();
              break;
            default:
              // Shouldn't happen but do nothing ...
          }
        } catch (Exception e) {
          // Ignore it and copy by reference ...
        }

        fieldClone =
            new TIFFField(
                field.getTag(), fieldType,
                field.getCount(), fieldData);
      } else {
        // Copy by reference.
        fieldClone = field;
      }

      // Add the field to the clone.
      shallowClone.addTIFFField(fieldClone);
    }

    // Set positions.
    shallowClone.setPositions(
        stripOrTileOffsetsPosition, stripOrTileByteCountsPosition, lastPosition);

    return shallowClone;
  }