Return-Path: <awaresystems.be+caf_=filtered=awaresystems.be@gmail.com>
Delivered-To: filtered@awaresystems.be
Received: from mx-x.one.com (mx-x.one.com [195.47.247.149])
	by mail6.local.one.com (Postfix) with ESMTP id EFFFB30050339E
	for <filtered@awaresystems.be>; Wed, 15 Oct 2014 03:08:16 +0000 (UTC)
X-Virus-Scanned: by one.com
Received-SPF: pass (mx-x: domain of awaresystems.be+caf_=filtered=awaresystems.be@gmail.com designates 209.85.215.50 as permitted sender)
X-Greylist: whitelisted by SQLgrey-1.8.0-rc2
Received: from mail-la0-f50.google.com (mail-la0-f50.google.com [209.85.215.50])
	by mx-x.one.com (Postfix) with ESMTP id C442920C1EE8B
	for <filtered@awaresystems.be>; Wed, 15 Oct 2014 03:08:16 +0000 (UTC)
Received: by mail-la0-f50.google.com with SMTP id s18so269962lam.37
        for <filtered@awaresystems.be>; Tue, 14 Oct 2014 20:08:16 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-original-authentication-results:delivered-to:delivered-to
         :x_cmae_category:message-id:date:from:user-agent:mime-version:to
         :references:in-reply-to:subject:precedence:list-id:list-unsubscribe
         :list-archive:list-post:list-help:list-subscribe:content-type
         :content-transfer-encoding:sender:errors-to;
        bh=yjYJbNQA6yE/gg6Oplw1ZFjFyqOfPYJ7sfMteYWqaxU=;
        b=QlNlQZ4wyFP9+dcYh83Pz0wOHVsb/8hsE2X8hdviUwNtuLVZ5/lA56gz/+3w8/AFNT
         /pUdlapDL1qH6Up0SAGexy0QJuyDj0THw/V5xSBQLtvl8fAq93jvYPE3WYcVVHFpHdeb
         AT+gNfVBrcJnho/GP+CSuxEzCTtM+6RJNXyu6jmmWxQyrKOrtFvjDyMRV7bqwXjxo9LN
         CsFO7UuWW15Ckh9e2+C4XndHAIm6EbrD3qTbxsv7JN+tM1RviaoU5Qead/nQXPAnTWxa
         6M65Fpn/0nDxuVQe0DZekF0Xlc8iYe9tE1hXnrDRtVr/81vx3kHBeidzGLexFaGHDWPo
         vnqA==
X-Original-Authentication-Results: mx.google.com;       spf=neutral (google.com: tiff-bounces@lists.maptools.org does not designate permitted sender hosts) smtp.mail=tiff-bounces@lists.maptools.org
X-Received: by 10.152.10.143 with SMTP id i15mr9372580lab.5.1413342496509;
        Tue, 14 Oct 2014 20:08:16 -0700 (PDT)
X-Forwarded-To: filtered@awaresystems.be
X-Forwarded-For: awaresystems.be@gmail.com filtered@awaresystems.be
Delivered-To: awaresystems.be@gmail.com
Received: by 10.114.111.103 with SMTP id ih7csp81354ldb;
        Tue, 14 Oct 2014 20:08:16 -0700 (PDT)
X-Received: by 10.112.198.226 with SMTP id jf2mr92924lbc.84.1413342494242;
        Tue, 14 Oct 2014 20:08:14 -0700 (PDT)
Authentication-Results: mx.google.com;
       spf=neutral (google.com: tiff-bounces@lists.maptools.org does not designate permitted sender hosts) smtp.mail=tiff-bounces@lists.maptools.org
Received-SPF: none (google.com: tiff-bounces@lists.maptools.org does not designate permitted sender hosts) client-ip=91.198.169.52;
Received: by 10.112.34.139 with POP3 id z11mf194080lbi.17;
        Tue, 14 Oct 2014 20:08:14 -0700 (PDT)
X-Gmail-Fetch-Info: info@awaresystems.be 1 pop.awaresystems.be 110 info@awaresystems.be
Delivered-To: info@awaresystems.be
Received: from mx-e.one.com (mx-e.one.com [91.198.169.52])
	by mail6.local.one.com (Postfix) with ESMTP id 82A493000E15F3
	for <info@awaresystems.be>; Wed, 15 Oct 2014 02:57:29 +0000 (UTC)
X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0-rc2
Received: from lists.maptools.org (ks365428.kimsufi.com [94.23.4.142])
	by mx-e.one.com (Postfix) with ESMTP id 4FCF090BDA8
	for <info@awaresystems.be>; Wed, 15 Oct 2014 02:57:29 +0000 (UTC)
Received: from [10.1.0.241] (localhost.localdomain [127.0.0.1])
	by lists.maptools.org (Postfix) with ESMTP id 0436635C04B;
	Tue, 14 Oct 2014 21:56:45 -0500 (EST)
Received: from smtp.centurylink.net (mail.centurylink.net [205.219.233.9])
	by lists.maptools.org (Postfix) with ESMTPS id 853D735C02C
	for <tiff@lists.maptools.org>; Tue, 14 Oct 2014 21:56:30 -0500 (EST)
X_CMAE_Category: , ,
X-CNFS-Analysis: v=2.0 cv=Yf8/Fntf c=1 sm=1 a=FAmuYjJ1MI3AGZxwVn94JA==:17
	a=eV-di8Q2jpsA:10 a=YTHtZiAxaJsA:10 a=8nJEP1OIZ-IA:10
	a=I_5RNyk1AAAA:8 a=doihScJbo5F9O66MO20A:9 a=wPNLvfGTeEIA:10
	a=yfI91NNDK9cDgm8N:21 a=frOzj0XMOfCEqnYn:21
	a=FAmuYjJ1MI3AGZxwVn94JA==:117
X-CM-Score: 0
X-Scanned-by: Cloudmark Authority Engine
X-Authed-Username: cmljaGFyZC5ub2xkZUBjZW50dXJ5bGluay5uZXQ=
Authentication-Results: smtp01.agate.dfw.synacor.com
	smtp.user=richard.nolde@centurylink.net; auth=pass (LOGIN)
Received: from [67.6.169.154] ([67.6.169.154:35664]
	helo=zephyrus.wriverody.net)
	by smtp.centurylink.net (envelope-from <richard.nolde@centurylink.net>)
	(ecelerity 3.5.1.37854 r(Momo-dev:3.5.1.0)) with ESMTPSA
	(cipher=CAMELLIA256-SHA) 
	id 42/DA-15037-162ED345; Tue, 14 Oct 2014 22:56:33 -0400
Message-ID: <543DE260.5050205@centurylink.net>
Date: Tue, 14 Oct 2014 20:56:32 -0600
From: Richard Nolde <richard.nolde@centurylink.net>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:17.0) Gecko/20130625 Thunderbird/17.0.7
MIME-Version: 1.0
To: tiff@lists.maptools.org
References: <mailman.9751.1413339813.24645.tiff@lists.maptools.org>
In-Reply-To: <mailman.9751.1413339813.24645.tiff@lists.maptools.org>
Subject: [Tiff] Tiff2pdf page ordering
X-BeenThere: tiff@lists.maptools.org
X-Mailman-Version: 2.1.9
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>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org

Regarding the strange page order:

tiff2pdf built is generating pages out of order for one of our test  
files 123.tiff (attached). That tiff file is viewable in Windows Photo  
Viewer and the pages have numbers 1, 2 and 3. The generated pdf is  
231.pdf (attached). As you can see the first page is generated at the  
end instead. 

I have no access to a Winders build environment, but I remember looking at Ross' code when I thought I could add PDF output to tiffcrop some years back.  I believe the key factor here is that he parses the TIFF directories with a routine that includes the code below.  He isn't just reading the directories one after the other and writing them out as he finds them. I never figured out why this was necessary or what it accomplished unless it was to deal with some combinations of subfile types and out of order presentation. Is it possible that the qsort call works differently in that environment? 

I wasn't able to download the sample TIFFs so I haven't seem them.  Since the PDF output is limited to version 1.1 or 1.2, it might be worth seeing if changing the version makes a difference.  Also, the early types aren't hard to decipher with any file viewer that handles binary files. If someone want send me the Windows source file and the PDF produced from it, I'll take a peak inside.

Richard Nolde

...
        for(i=0;i<directorycount;i++){

                uint32 subfiletype = 0;
               
                if(!TIFFSetDirectory(input, i)){
                        TIFFError(
                                TIFF2PDF_MODULE,
                                "Can't set directory %u of input file %s",
                                i,
                                TIFFFileName(input));
                        return;
                }
                if(TIFFGetField(input, TIFFTAG_PAGENUMBER, &pagen, &paged)){
                        if((pagen>paged) && (paged != 0)){
                               
t2p->tiff_pages[t2p->tiff_pagecount].page_number =
                                        paged;
                        } else {
                               
t2p->tiff_pages[t2p->tiff_pagecount].page_number =
                                        pagen;
                        }
                        goto ispage2;
                }
                if(TIFFGetField(input, TIFFTAG_SUBFILETYPE, &subfiletype)){
                        if ( ((subfiletype & FILETYPE_PAGE) != 0)
                             || (subfiletype == 0)){
                                goto ispage;
                        } else {
                                goto isnotpage;
                        }
                }
                if(TIFFGetField(input, TIFFTAG_OSUBFILETYPE, &subfiletype)){
                        if ((subfiletype == OFILETYPE_IMAGE)
                                || (subfiletype == OFILETYPE_PAGE)
                                || (subfiletype == 0) ){
                                goto ispage;
                        } else {
                                goto isnotpage;
                        }
                }
                ispage:
               
t2p->tiff_pages[t2p->tiff_pagecount].page_number=t2p->tiff_pagecount;
                ispage2:
                t2p->tiff_pages[t2p->tiff_pagecount].page_directory=i;
                if(TIFFIsTiled(input)){
                       
t2p->tiff_pages[t2p->tiff_pagecount].page_tilecount =
                                TIFFNumberOfTiles(input);
                }
                t2p->tiff_pagecount++;
                isnotpage:
                (void)0;
       }
       
        qsort((void*) t2p->tiff_pages, t2p->tiff_pagecount,
              sizeof(T2P_PAGE), t2p_cmp_t2p_page);

        for(i=0;i<t2p->tiff_pagecount;i++){
                t2p->pdf_xrefcount += 5;
                TIFFSetDirectory(input, t2p->tiff_pages[i].page_directory );
                if((TIFFGetField(input, TIFFTAG_PHOTOMETRIC, &xuint16)
                    && (xuint16==PHOTOMETRIC_PALETTE))
                   || TIFFGetField(input, TIFFTAG_INDEXED, &xuint16)) {
                        t2p->tiff_pages[i].page_extra++;
                        t2p->pdf_xrefcount++;
                }

_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
