Return-Path: <tiff-bounces@lists.maptools.org>
Delivered-To: info@awaresystems.be
Received: (qmail 32718 invoked from network); 1 Oct 2008 16:33:48 -0000
Received: from cheryl.telenet-ops.be ([195.130.136.3])
          (envelope-sender <tiff-bounces@lists.maptools.org>)
          by angelia.telenet-ops.be (qmail-ldap-1.03) with SMTP
          for <info@awaresystems.be>; 1 Oct 2008 16:33:48 -0000
Received: from mindy.telenet-ops.be (mindy.telenet-ops.be [195.130.136.8])
	by cheryl.telenet-ops.be (8.13.1/8.13.1) with ESMTP id m91GXmIC019418
	for <info@awaresystems.be>; Wed, 1 Oct 2008 18:33:48 +0200
Received: from pierre.telenet-ops.be (pierre.telenet-ops.be [195.130.132.34])
	by mindy.telenet-ops.be (Postfix) with ESMTP id 4BC0360004
	for <info@awaresystems.be>; Wed,  1 Oct 2008 18:33:48 +0200 (CEST)
Received: from apate.telenet-ops.be ([195.130.132.43])
	by pierre.telenet-ops.be with bizsmtp
	id MUZo1a00M0wL6ob01UZoRy; Wed, 01 Oct 2008 18:33:48 +0200
Received: from duke.maptools.org (r153.dmsolutions.ca [209.217.116.153])
	by apate.telenet-ops.be (Postfix) with ESMTP id CDBA627EC36
	for <info@awaresystems.be>; Wed,  1 Oct 2008 18:33:47 +0200 (CEST)
Received: from duke.maptools.org (duke.maptools.org [127.0.0.1])
	by duke.maptools.org (8.12.11/8.12.10) with ESMTP id m91GWWBQ004431;
	Wed, 1 Oct 2008 12:32:59 -0400
Received: from mpls-qmqp-03.inet.qwest.net (mpls-qmqp-03.inet.qwest.net
	[63.231.195.114])
	by duke.maptools.org (8.12.11/8.12.10) with ESMTP id m91GWSSZ004426
	for <tiff@lists.maptools.org>; Wed, 1 Oct 2008 12:32:29 -0400
Received: from mpls-pop-13.inet.qwest.net (mpls-pop-13.inet.qwest.net
	[63.231.195.13]) by mpls-qmqp-03.inet.qwest.net (Postfix) with QMQP
	id 4C753621E9E; Wed,  1 Oct 2008 16:32:23 +0000 (UTC)
Received: from 75-171-195-215.hlrn.qwest.net (HELO css2.css.com)
	(75.171.195.215)
	by mpls-pop-13.inet.qwest.net with SMTP; 1 Oct 2008 16:32:22 -0000
Message-ID: <48E3A616.7040100@qwest.net>
Date: Wed, 01 Oct 2008 10:32:22 -0600
From: Richard Nolde <nrichard8@qwest.net>
User-Agent: Thunderbird 2.0.0.14 (X11/20080501)
MIME-Version: 1.0
To: "Dr. Michael J. Chudobiak" <mjc@avtechpulse.com>
Subject: Re: [Tiff] Image Orientation tag and rotating images
References: <200809281220.m8SCKUdx016387@duke.maptools.org>
	<48E2E87D.3@qwest.net> <48E36F4B.8030405@avtechpulse.com>
In-Reply-To: <48E36F4B.8030405@avtechpulse.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Cc: tiff@lists.maptools.org
X-BeenThere: tiff@lists.maptools.org
X-Mailman-Version: 2.1.4
Precedence: list
List-Id: TIFF and libtiff discussion <tiff.lists.maptools.org>
List-Unsubscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=unsubscribe>
List-Archive: <http://lists.maptools.org/mailman/private/tiff>
List-Post: <mailto:tiff@lists.maptools.org>
List-Help: <mailto:tiff-request@lists.maptools.org?subject=help>
List-Subscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=subscribe>
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org
X-SpamCatcher-Score: 50 [XX]

Dr. Michael J. Chudobiak wrote:
> Richard Nolde wrote:
>> My first question is whether I have made the correct adjustments to 
>> the orientation tag for rotations of 90, 180, and 270 degrees 
>> clockwise. ...
> Some comments:
>
> 1) 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 current code to read and write 
images is based on tiffcp.c which includes the following lines for 
determining and then updating the orientation tag. This code suggests to 
me that the issue is in the TIFFReadScanline and TIFFReadTile functions 
which do not have any options to reverse the data in the input stream if 
the orientation is right-handed as do TIFFReadRGBAImage related 
functions in tif_getimage.c. It would not be hard to add this 
functionality, but it isn't clear that it is going to solve anything for 
the readers that don't handle the orientation tag properly.

  TIFFGetFieldDefaulted(in, TIFFTAG_ORIENTATION, &orientation);
  switch (orientation) {
    case ORIENTATION_BOTRIGHT:
    case ORIENTATION_RIGHTBOT:    /* XXX */
         TIFFWarning(TIFFFileName(in), "using bottom-left orientation");
         orientation = ORIENTATION_BOTLEFT;
         /* fall thru... */
    case ORIENTATION_LEFTBOT:    /* XXX */
    case ORIENTATION_BOTLEFT:
         break;
    case ORIENTATION_TOPRIGHT:
    case ORIENTATION_RIGHTTOP:    /* XXX */
    default:
         TIFFWarning(TIFFFileName(in), "using top-left orientation");
         orientation = ORIENTATION_TOPLEFT;
         /* fall thru... */
    case ORIENTATION_LEFTTOP:    /* XXX */
    case ORIENTATION_TOPLEFT:
         break;
   }

  TIFFSetField(out, TIFFTAG_ORIENTATION, orientation);

which I have replaced with

  TIFFSetField(out, TIFFTAG_ORIENTATION, image->orientation);

where image->orientation is set by the code previously noted based on 
the original orientation and the desired rotation.
> 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.
> 4) Orientation tag support for tiff is spotty, so the safest route is 
> to transform the data and remove the orientation tag.
> - Mike
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.

Does anyone have images with orientations other than TOPLEFT that are 
small enough to use for testing?
Richard
_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
