Received: from [204.94.214.10] by phillip.cerious.com (NTMail 3.03.0017/7.aaxh) with ESMTP id pcrews for <pcrews@cerious.com>; Mon, 21 Sep 1998 15:14:33 -0400
Received: from odin.corp.sgi.com (fddi-odin.corp.sgi.com [198.29.75.194]) by deliverator.sgi.com (980309.SGI.8.8.8-aspam-6.2/980310.SGI-aspam) via SMTP id MAA27794; Mon, 21 Sep 1998 12:12:14 -0700 (PDT)
	mail_from (owner-tiff@fddi-sgi.sgi.com)
Received: from sgi.sgi.com by odin.corp.sgi.com via ESMTP (951211.SGI.8.6.12.PATCH1502/951211.SGI)
	 id MAA05044; Mon, 21 Sep 1998 12:13:47 -0700
Received: from cthulhu.engr.sgi.com (cthulhu.engr.sgi.com [192.26.80.2]) 
	by sgi.sgi.com (980327.SGI.8.8.8-aspam/980304.SGI-aspam:
       SGI does not authorize the use of its proprietary
       systems or networks for unsolicited or bulk email
       from the Internet.) 
	via ESMTP id MAA06019; Mon, 21 Sep 1998 12:13:13 -0700 (PDT)
	mail_from (owner-tiff@sgi.engr.sgi.com)
Received: (from majordomo-owner@localhost)
	by cthulhu.engr.sgi.com (980427.SGI.8.8.8/970903.SGI.AUTOCF)
	id LAA31942
	for tiff-list;
	Mon, 21 Sep 1998 11:35:01 -0700 (PDT)
	mail_from (owner-tiff@sgi.sgi.com)
Received: from sgi.sgi.com (sgi.engr.sgi.com [192.26.80.37])
	by cthulhu.engr.sgi.com (980427.SGI.8.8.8/970903.SGI.AUTOCF)
	via ESMTP id LAA25844
	for <tiff-relay@cthulhu.engr.sgi.com>;
	Mon, 21 Sep 1998 11:35:00 -0700 (PDT)
	mail_from (owner-tiff@sgi.sgi.com)
Received: from gate.akutech.de (www.akutech.de [195.27.37.98]) 
	by sgi.sgi.com (980327.SGI.8.8.8-aspam/980304.SGI-aspam:
       SGI does not authorize the use of its proprietary
       systems or networks for unsolicited or bulk email
       from the Internet.) 
	via ESMTP id LAA01737
	for <tiff@sgi.com>; Mon, 21 Sep 1998 11:34:56 -0700 (PDT)
	mail_from (ralf@akutech.de)
Received: from jupiter.akutech.de ([192.168.1.201])
	by gate.akutech.de (8.8.8/8.8.8) with SMTP id UAA04256
	for <@gate.akutech.de:tiff@sgi.com>; Mon, 21 Sep 1998 20:35:24 +0200
Received: (from ralf@localhost) by jupiter.akutech.de (950413.SGI.8.6.12/950213.SGI.AUTOCF) id UAA20327; Mon, 21 Sep 1998 20:34:43 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-ID: <13830.40003.403762.987365@jupiter.akutech.de>
Date: Mon, 21 Sep 1998 20:34:43 +0200 (MDT)
From: Ralf Fassel <ralf@akutech.de>
To: tiff@sgi.com
Subject: colormap size problem in tiff file from PC, TIFF 3.4beta036
Organization: Akustik Technologie Goettingen (ATG)
Sender: owner-tiff@fddi-sgi.sgi.com
Precedence: bulk

Today we received some TIFF file from a customer which was unreadable
by libtiff 3.4beta036:
    tiff-v3.4beta036/tools/tiffinfo Filterbank.tif 
    Filterbank.tif: Warning, unknown field with tag 32934 (0x80a6) ignored. 
    Filterbank.tif: Warning, incorrect count for field "ColorMap" (678, expecting 768); tag ignored. 
    Filterbank.tif: TIFF directory is missing required "Colormap" field.
The file was, however, readily displayed on an NT 4.0 box.  It turns
out that the bail-out-point is in libtiff/tif_dirread.c, around #416
ff.

	case TIFFTAG_COLORMAP:
	case TIFFTAG_TRANSFERFUNCTION:
		/*
		 * TransferFunction can have either 1x or 3x data
		 * values; Colormap can have only 3x items.
		 */
(1)		v = 1L<<td->td_bitspersample;
		if (dp->tdir_tag == TIFFTAG_COLORMAP ||
		    dp->tdir_count != (uint32) v) {
(2)			if (!CheckDirCount(tif, dp, (uint32)(3*v)))
				break;
		}
		v *= sizeof (uint16);

It turned out that (1) td->td_bitspersample == 8, thus v==256, and
dp->tdir_count == 678 (which is only 3*226).  Now, the check in (2)
CheckDirCount() made the code bail out here, while simply setting v to
dp->tdir_count/3 in the debugger fixed the problem in this case and
analysed the file properly (and eg. allowed to convert it to
postscript).

		v = 1L<<td->td_bitspersample;
    (gdb) print v
    $1 = 256
    (gdb) set variable v=226 
    (gdb) continue
    TIFF Directory at offset 0x8
      Subfile Type: (0 = 0x0)
      Image Width: 393 Image Length: 393
      Resolution: 100, 100 pixels/inch
      Bits/Sample: 8
      Compression Scheme: None
      Photometric Interpretation: palette color (RGB from colormap)
      FillOrder: msb-to-lsb
      Software: "Oi/GFS, writer v00.06.00P, (c) Wang Labs, Inc. 1990, 1991"
      Orientation: row 0 top, col 0 lhs
      Samples/Pixel: 1
      Rows/Strip: 80
      Planar Configuration: single image plane
      Color Map: (present)
    Program exited normally.
    (gdb)

I don't know what the *real* problem is and whether the other software
is in error in writing a tdir_count of 226 instead of the expected
256, but maybe the problem at this point could be `solved' by
resetting v to what was found in the file instead of ignoring the
stuff?

Anybody knowledgeable can comment on that topic?  The TIFF file in
question is available on request.

Regards
R'
-- 
Don't forget about `C-c C-p C-p' and `C-u C-c C-p c C-t'.
                    --Barry A. Warsaw on gnu.emacs.help
