commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Emmanuel Bourg (Updated) (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (SANSELAN-12) Writing an ascii TiffOutputField from a TiffConstant tag type fails - fix included with report
Date Tue, 20 Dec 2011 11:01:31 GMT

     [ https://issues.apache.org/jira/browse/SANSELAN-12?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Emmanuel Bourg updated SANSELAN-12:
-----------------------------------

      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:

# the code was assuming all ascii values were represented by:
       {code}tagInfo.dataTypes == FIELD_TYPE_DESCRIPTION_ASCII{code}
   which is not the case. TiffConstants types that have ascii values are represented
       {code}tagInfo.dataTypes[0] == FIELD_TYPE_ASCII{code}
# 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

{code: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);
}
{code}


Changed from a check out I did a couple weeks ago

{code: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)
        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);
}
{code}


  was:
/**
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 instace
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);
}



    Fix Version/s: 1.0
    
> Writing an ascii TiffOutputField from a TiffConstant  tag type fails - fix included with
report
> -----------------------------------------------------------------------------------------------
>
>                 Key: SANSELAN-12
>                 URL: https://issues.apache.org/jira/browse/SANSELAN-12
>             Project: Commons Sanselan
>          Issue Type: Bug
>    Affects Versions: 0.94-incubator
>         Environment: FC8, java 6
>            Reporter: john schneider
>             Fix For: 1.0
>
>
> 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:
> # the code was assuming all ascii values were represented by:
>        {code}tagInfo.dataTypes == FIELD_TYPE_DESCRIPTION_ASCII{code}
>    which is not the case. TiffConstants types that have ascii values are represented
>        {code}tagInfo.dataTypes[0] == FIELD_TYPE_ASCII{code}
> # 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
> {code: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);
> }
> {code}
> Changed from a check out I did a couple weeks ago
> {code: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)
>         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);
> }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message