Uploaded image for project: 'Commons Imaging'
  1. Commons Imaging
  2. IMAGING-16

Writing an ascii TiffOutputField from a TiffConstant tag type fails - fix included with report

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.94-incubator
    • 1.0-alpha1
    • None
    • None
    • FC8, java 6

    Description

      Hi,

      I was trying to write ascii field types when I ran across this. I was trying to add an TiffConstant TiffConstants.EXIF_TAG_DATE_TIME_ORIGINAL with a value like "2003:10:31 15:44:19", but the current code was not doing it...

      After taking a dive into the code I noticed two issues:

      1. the code was assuming all ascii values were represented by:
        tagInfo.dataTypes == FIELD_TYPE_DESCRIPTION_ASCII

        which is not the case. TiffConstants types that have ascii values are represented

        tagInfo.dataTypes[0] == FIELD_TYPE_ASCII
      2. the code was assuming that an ASCII TiffOutputField had length of 1

      I think that the first problem is caused by the use of an anonymous array wrapper around FIELD_TYPE_DESCRIPTION_ASCII, rather than a globally identifiable instance like FIELD_TYPE_DESCRIPTION_ASCII. Not being sure of what your design objectives are I took the most prudent path to getting the code to function correctly, but this fix does assume that the ascii TiffConstants all work the same way.

      Please see comments in code.
      Feel free to contact me with questions at jottos@gmail.com

      Modified src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputField.java

      public static TiffOutputField create(TagInfo tagInfo, int byteOrder,
                                           String value) throws ImageWriteException
      {
          FieldType fieldType;
          if (tagInfo.dataTypes == null)
              fieldType = FIELD_TYPE_ASCII;
          else if (tagInfo.dataTypes == FIELD_TYPE_DESCRIPTION_ASCII ||
                   // added a second test here to look for dataTypes[] array
                   // I looked at code examples in lib and saw only a single 
                   // entry in most on only a single entry when a string fieldtype
                   // was being added. Big assumption I have no way of validating...
                   tagInfo.dataTypes[0] == FIELD_TYPE_ASCII)
              fieldType = FIELD_TYPE_ASCII;
          else
              throw new ImageWriteException("Tag has unexpected data type.");
      
          byte bytes[] = fieldType.writeData(value, byteOrder);
      
          // the count "1" in the original code (see commented out original)
          // is  wrong as it assumes the field being updated is a single ascii char
          //return new TiffOutputField(tagInfo.tag, tagInfo, fieldType, 1, bytes);
          return new TiffOutputField(tagInfo.tag, tagInfo, fieldType, value.length(), bytes);
      }
      

      Changed from a check out I did a couple weeks ago

      public static TiffOutputField create(TagInfo tagInfo, int byteOrder,
                                           String value) throws ImageWriteException
      {
          FieldType fieldType;
          if (tagInfo.dataTypes == null)
              fieldType = FIELD_TYPE_ASCII;
          else if (tagInfo.dataTypes == FIELD_TYPE_DESCRIPTION_ASCII)
              fieldType = FIELD_TYPE_ASCII;
          else
              throw new ImageWriteException("Tag has unexpected data type.");
      
          byte bytes[] = fieldType.writeData(value, byteOrder);
      
          return new TiffOutputField(tagInfo.tag, tagInfo, fieldType, 1, bytes);
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            jottos john schneider
            Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: