commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benedikt Ritter <brit...@apache.org>
Subject Re: Creating EXIF tags (TiffOutputField) the right way
Date Sun, 22 May 2016 13:29:33 GMT
Hello Joakim

Joakim Knudsen <joakim.grahl@gmail.com> schrieb am Sa., 21. Mai 2016 um
19:29 Uhr:

> Hi List!
>
> I'm working on an Android app, where I want to read and write "EXIF tags"
> to JPEG files on the device. Sanselan 0.97 seems to work perfectly,
> although it's a bit complicated to work with EXIF tags/directories.
>
> The specific tags I'm interested in, is EXIF_TAG_USER_COMMENT and
> EXIF_TAG_IMAGE_DESCRIPTION.
> According to the documentation I could find, UserComment is of field type
> "undefined", whereas ImageDescription is of field type ASCII.
>
> http://www.awaresystems.be/imaging/tiff/tifftags/privateifd/exif/usercomment.html
> http://www.awaresystems.be/imaging/tiff/tifftags/imagedescription.html
>
> What's the proper way of creating those tags, wrt. charset etc? I want as
> wide as possible character support (æøå etc).
>
> I find different discussions online, with different advice. Seems two
> constructors are going around, where the simpler one does not deal with
> charset/encoding at all. This one uses the .create method:
>
> String textToSet = "Some Text æøå";
>
> TiffOutputField exif_comment = TiffOutputField.create(
>                 TiffConstants.EXIF_TAG_USER_COMMENT,
>                 outputSet.byteOrder, textToSet);
>
>
> while this one uses the standard constructor:
>
> byte b[] = ExifTagConstants.EXIF_TAG_USER_COMMENT.encodeValue(
>         TiffFieldTypeConstants.FIELD_TYPE_ASCII,
>         textToSet, outputSet.byteOrder
> );
>
> // constructor arguments: taginfo tag fieldtype count bytes
> TiffOutputField exif_comment2 = new
> TiffOutputField(TiffConstants.EXIF_TAG_USER_COMMENT.tag,
>         TiffConstants.EXIF_TAG_USER_COMMENT,
> TiffFieldTypeConstants.FIELD_TYPE_UNDEFINED,
>         b.length, b);
>
> In this last one, the string to set has been converted to a byte array
> first. But can/should I set the encoding anywhere?
>
> Is the field type even ASCII? This information seems to indicate it's
> not ASCII...
>
> http://www.awaresystems.be/imaging/tiff/tifftags/privateifd/exif/usercomment.html
>
>
> Need some help here, as you can see, to get this right. The second
> approach above does seem to work in my app, but I'd like to be sure
> I'm not somehow messing up the JPEGs on the deviced.
>

I've looked at the code of
org.apache.commons.imaging.formats.tiff.taginfos.TagInfoGpsText
(ExifTagConstants.EXIF_TAG_USER_COMMENT is an instance of TagInfoGpsText).
Here are my observations:

- The FieldType parameter, which you have set to
TiffFieldTypeConstants.FIELD_TYPE_ASCII is never used in the implemenation
of encodeValue(FieldType, Object, ByteOrder)
- When converting the input String to byte array, String.getBytes(String
charsetName) is used
- For charsetName "US-ASCII" is always used (it can not be configured by
the user)

So my guess is, that the code will not handle characters not in the
US-ASCII charset correctly.

Benedikt


>
>
>
> Joakim
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message