[
https://issues.apache.org/jira/browse/SANSELAN-12?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Damjan Jovanovic resolved SANSELAN-12.
--------------------------------------
Resolution: Fixed
Fixed by commit 1212318, resolving fixed.
> 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
>
> /**
> 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 [email protected]
> */
> 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);
> }
--
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