1998.09.21 18:34 "colormap size problem in tiff file from PC, TIFF 3.4beta036", by Ralf Fassel

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