2008.10.01 18:59 "Re: [Tiff] Image Orientation tag and rotating images", by Dr. Michael J. Chudobiak
- libtiff support for orientation is a little odd, because libtiff automatically adjusts for orientations 1-4 (which preserve the height and width), but not 5-8 (which swap height and width). Beware!
What file are you referring to when you say that libtiff automatically adjusts for orientations 1- 4? I should have noted that I am using the TIFFReadScanline and TIFFReadTile interfaces, not the TIFFReadRGBAImage interface as found in tif_getimage.c.
The above comments applied to TIFFReadRGBAImage, so you don't need to worry about that. But it's still good to know...
3) If you transform the data to reflect the orientation tag, the orientation tag should be reset to "top left", or be removed entirely.
However, in my case, I am not transforming the data to reflect the orientation tag, rather as a specific request to rotate the image by a multiple of 90 degrees. This leaves open the possibility that images that did not have an orientation of TOPLEFT originally will still not display properly in some applications since the code above does not handle all orientations. It forces the orientation tag to a left-handed, top or bottom, value.
In gthumb, we set it up so that you can rotate by:
1) changing the orientation tag only
2) by physically transforming the data and resetting the tag to top-left
In BOTH cases, we take into account the original orientation tag value.
We avoid physically transforming the data and having a non-top-left output orientation tag. I guess you could do that if you wanted to, but I wouldn't personally recommend it.
Officially, the EXIF standard does require you to reset the orientation tag to top-left after a rotation.
One final question about what the proper behavior should be since this is not a display application. Should the data be transformed to ORIENTATION_TOPLEFT when an image with any other orientation is loaded into memory under the assumption that this is the correct viewing orientation? Any requested rotations would then be made relative to the adjusted viewing orientation rather than to the original orientation. Or should rotations be relative to the original image orientation without regard to the proper viewing orientation. This is what I am doing now. In either case, it seems like resetting the orientation to TOPLEFT is appropriate when the data are transformed.
In gthumb, we load the data, transform it based on the orientation tag, and apply any requested operations (crop, rotate, whatever) based on the transformed data. In other words, we always honor the orientation tag, assuming that if the user didn't mean it, it wouldn't be in the file.