Return-Path: <awaresystems.be+caf_=filtered=awaresystems.be@gmail.com>
Delivered-To: filtered@awaresystems.be
Received: from mx-m.one.com (mx-m.one.com [91.198.169.60])
	by mail6.local (Postfix) with ESMTP id E8615300191B17
	for <filtered@awaresystems.be>; Wed, 14 May 2014 15:21:20 +0000 (UTC)
X-Virus-Scanned: by one.com
Received-SPF: pass (mx-m: domain of awaresystems.be+caf_=filtered=awaresystems.be@gmail.com designates 209.85.215.44 as permitted sender)
X-Greylist: whitelisted by SQLgrey-1.8.0-rc2
Received: from mail-la0-f44.google.com (mail-la0-f44.google.com [209.85.215.44])
	by mx-m.one.com (Postfix) with ESMTP id B677322A71EE8
	for <filtered@awaresystems.be>; Wed, 14 May 2014 15:21:20 +0000 (UTC)
Received: by mail-la0-f44.google.com with SMTP id hr17so1560074lab.17
        for <filtered@awaresystems.be>; Wed, 14 May 2014 08:21:20 -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:date
         :from:to:message-id:references:mime-version:content-disposition
         :in-reply-to:user-agent:subject:precedence:list-id:list-unsubscribe
         :list-archive:list-post:list-help:list-subscribe:content-type
         :content-transfer-encoding:sender:errors-to;
        bh=jEQgE5BIm2TrRy1b06Xju8b3KjYqAvwe9MytGo8lDxs=;
        b=j80MH8wabBpPvY1HoDtG5leLBBJuWFnLSZV57S+az/dYwLuGj35QGhQVeOtpiw8VDc
         bkUdg51+kVJFe8nMeAiJ3XgJ0WNbCCO+peUp1RSmVmeVmoEbgxMTWC/XeNOZ8MC6H9Cd
         jMnSkjg0JEentn7LE4Kub1SPXRdsisFplGry2VWoqEK09zUxIAvRN3XbzGpQtLdtmvNt
         Ef8xi96IFlzwhfYfQ8rG6m/IOPi/8NN1NqVwvl9i/e7zMznKWLpXyRXUJrHyMQmEvLB+
         Opmf2EWooat6bQSfWp9jI86VliIhfiQBzjXn1HCNZPadgsXTIjSlsCkihDSHsfLl9bDZ
         7sfA==
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.112.73.211 with SMTP id n19mr238149lbv.84.1400080880345;
        Wed, 14 May 2014 08:21:20 -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.18.137 with SMTP id w9csp228967ldd;
        Wed, 14 May 2014 08:21:19 -0700 (PDT)
X-Received: by 10.152.21.200 with SMTP id x8mr2029956lae.58.1400080878349;
        Wed, 14 May 2014 08:21:18 -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.59;
Received: by 10.112.33.104 with POP3 id q8mf387000lbi.20;
        Wed, 14 May 2014 08:21:18 -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-l.one.com (mx-l.one.com [91.198.169.59])
	by mail6.local (Postfix) with ESMTP id 28A33300191B18
	for <info@awaresystems.be>; Wed, 14 May 2014 14:47:26 +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-l.one.com (Postfix) with ESMTP id EE1BC21D4D873
	for <info@awaresystems.be>; Wed, 14 May 2014 14:47:25 +0000 (UTC)
Received: from [10.1.0.241] (localhost.localdomain [127.0.0.1])
	by lists.maptools.org (Postfix) with ESMTP id 3D2F035C02B;
	Wed, 14 May 2014 09:46:42 -0500 (EST)
Received: from nagini.codelibre.net (nagini.codelibre.net [80.68.93.164])
	by lists.maptools.org (Postfix) with ESMTP id 7B85A35C02B
	for <tiff@lists.maptools.org>; Wed, 14 May 2014 09:45:02 -0500 (EST)
Received: by nagini.codelibre.net (Postfix, from userid 1000)
	id 06FC518195; Wed, 14 May 2014 15:44:54 +0100 (BST)
Date: Wed, 14 May 2014 15:44:54 +0100
From: Roger Leigh <rleigh@codelibre.net>
To: tiff@lists.maptools.org
Message-ID: <20140514144453.GD30912@codelibre.net>
References: <20140421145458.GP30912@codelibre.net>
MIME-Version: 1.0
Content-Disposition: inline
In-Reply-To: <20140421145458.GP30912@codelibre.net>
User-Agent: Mutt/1.5.21 (2010-09-15)
Subject: Re: [Tiff] Correct use of TIFFGetField with FieldInfo
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

On Mon, Apr 21, 2014 at 03:54:58PM +0100, Roger Leigh wrote:
> Hi,
> 
> Looking at the documentation, TIFFGetField appears to require
> calling TIFFFieldReadCount and TIFFFieldPassCount to determine
> which parameters need to be passed in the argument list.
> 
> However, taking TIFFTAG_BITSPERSAMPLE as an example, this
> has TIFFFieldReadCount == -1 (TIFF_VARIABLE) and
> TIFFFieldPassCount == 0.  All the examples I've looked at in the
> source tree use a uint16 pointer directly to retrieve the value,
> but I'm not sure how this squares with a TIFF_VARIABLE read count.
> Why isn't the count 1?  (I'm aware libtiff doesn't match the spec
> exactly for this tag, but why does it appear to be different from
> the implementated behaviour--is it possible to use this safely?)
> 
> Is it possible to safely call TIFF(Get|Set)Field using only
> the information available in FieldInfo, or are there any cases
> where this isn't correct and calling requires a priori
> knowledge of how the interface behaves?

I'm still running into additional examples of this.  For example:

TIFFTAG_COMPRESSION
    readcount documented+specified to be 1
    dirinfo is: -1/TIFF_VARIABLE
    getfield is: 1
TIFFTAG_DATATYPE
    readcount documented to be 1
    dirinfo is: -2/TIFF_SPP
    getfield is: 1
TIFFTAG_(MIN|MAX)SAMPLEVALUE
    read/writecount documented to be 1
    dirinfo is TIFF_SPP/TIFF_VARIABLE resp.
    get/setfield is 1
TIFFTAG_SAMPLEFORMAT
    read/writecount documented to be 1
    dirinfo is: TIFF_VARIABLE
    get/setfield are: 1

By documented, I mean what's in the manpages, which doesn't necessarily match
the TIFF spec.  The default FieldInfo seems to mostly follow the spec, but
when libtiff doesn't support e.g. multiple values for TIFF_SPP, it seems
to leave the FieldInfo using TIFF_SPP/TIFF_VARIABLE while the actual
interface for Get/SetField is using single values.  Could anyone please
confirm what the intended logic and usage are here?  I'd like to be able to
call TIFF[V]Get/SetField safely based upon the content of the FieldInfo for
the tag in use, but this doesn't appear to be possible due to these
discrepancies, which are leading me to hardcode behaviour.  But this seems
very fragile: if the libtiff internal behaviour changes to match the
FieldInfo data at some point, my code will start crashing.


Regards,
Roger

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux    http://people.debian.org/~rleigh/
 `. `'   schroot and sbuild  http://alioth.debian.org/projects/buildd-tools
   `-    GPG Public Key      F33D 281D 470A B443 6756 147C 07B3 C8BC 4083 E800
_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
