Received: by whizzer.wpd.sgi.com (/911001.SGI)
	 id AA00567; Sat, 12 Feb 94 05:32:37 GMT
Received: from sgi.sgi.com by whizzer.wpd.sgi.com via SMTP (/911001.SGI)
	for /usr/people/sam/majordomo/wrapper resend -l tiff -h sgi.sgi.com -f tiff-owner -s -m "-oi -odq -om" tiff-list id AA00560; Fri, 11 Feb 94 21:32:33 -0800
Received: from sloop.cpac.washington.edu by sgi.sgi.com via SMTP (931110.SGI/910110.SGI)
	for tiff-relay@whizzer.wpd.sgi.com id AA11849; Fri, 11 Feb 94 21:32:30 -0800
Received: from yucca.omnigroup.com by sloop.cpac.washington.edu
	(5.65/UW-NDC Revision: 2.29 ) id AA12627; Fri, 11 Feb 94 21:35:43 -0800
Received: from manatee by omnigroup.com (NX5.67d/NX3.0M)
	id AA29937; Fri, 11 Feb 94 21:32:35 -0800
From: Timothy J. Wood <bungi@omnigroup.com>
Message-Id: <9402120532.AA29937@omnigroup.com>
Received: by manatee.omnigroup.com (NX5.67d/NX3.0X)
	id AA08357; Fri, 11 Feb 94 21:32:30 -0800
Date: Fri, 11 Feb 94 21:32:30 -0800
Received: by NeXT.Mailer (1.99.1)
Received: by NeXT Mailer (1.99.1)
To: tiff@sgi.sgi.com
Subject: Problem using tiled images
Reply-To: tjw@omnigroup.com
Sender: tiff-owner@sgi.sgi.com



  I just recently started using libtiff, so I may be doing something  
obviously wrong.  However, I didn't find any useful info in the archives.  I  
have a feeling that if I spent a week or so figuring out tiffcp.c that my  
answer would lay in there, but I'm sure that the problem is simpler than  
that.

  I'm using the latest version from sgi.com (v3.3) on a NeXT running NEXTSTEP  
3.2.

  What I am attempting to do is create an rather large tiff for later running  
through Aldus PrePrint on a Mac.  To optimize the creation of the image, I  
need to be able to write the tiff as tiles.  I wrote a test program (appended  
to the end of this message) that generate a 256x256 image consiting of a  
single tile.  Running tiffdump on the output gives:

foo.tiff:
Magic: 0x4d4d <big-endian> Version: 0x2a
Directory 0: offset 138198 (0x21bd6)
ImageWidth (256) SHORT (3) 1<256>
ImageLength (257) SHORT (3) 1<256>
BitsPerSample (258) SHORT (3) 3<8 8 8>
Compression (259) SHORT (3) 1<5>
Photometric (262) SHORT (3) 1<2>
Orientation (274) SHORT (3) 1<1>
SamplesPerPixel (277) SHORT (3) 1<3>
RowsPerStrip (278) SHORT (3) 1<256>
MinSampleValue (280) SHORT (3) 3<0 0 0>
MaxSampleValue (281) SHORT (3) 3<255 255 255>
XResolution (282) RATIONAL (5) 1<300>
YResolution (283) RATIONAL (5) 1<300>
PlanarConfig (284) SHORT (3) 1<1>
ResolutionUnit (296) SHORT (3) 1<2>
TileWidth (322) SHORT (3) 1<256>
TileLength (323) SHORT (3) 1<256>
TileOffsets (324) LONG (4) 1<8>
TileByteCounts (325) LONG (4) 1<138190>


  This seems fine to me, but when I run tiffdump on one of the sample images  
from sgi.com (cramps-tile.tiff), I get:

/Users/bungi/Source/Unix/libtiff/pics/cramps-tile.tiff:
Magic: 0x4d4d <big-endian> Version: 0x2a
Directory 0: offset 786440 (0xc0008)
ImageWidth (256) SHORT (3) 1<800>
ImageLength (257) SHORT (3) 1<607>
BitsPerSample (258) SHORT (3) 1<8>
Compression (259) SHORT (3) 1<1>
Photometric (262) SHORT (3) 1<0>
StripOffsets (273) LONG (4) 12<8 65544 131080 196616 262152 327688 393224  
458760 524296 589832 655368 720904>
Orientation (274) SHORT (3) 1<1>
SamplesPerPixel (277) SHORT (3) 1<1>
RowsPerStrip (278) LONG (4) 1<256>
StripByteCounts (279) LONG (4) 12<65536 65536 65536 65536 65536 65536 65536  
65536 65536 65536 65536 65536>
MinSampleValue (280) SHORT (3) 1<0>
MaxSampleValue (281) SHORT (3) 1<255>
PlanarConfig (284) SHORT (3) 1<1>
TileWidth (322) SHORT (3) 1<256>
TileLength (323) SHORT (3) 1<256>
OBSOLETE DataType (Silicon Graphics) (32996) SHORT (3) 1<0>
ImageDepth (Silicon Graphics) (32997) SHORT (3) 1<1>
TileDepth (Silicon Graphics) (32998) SHORT (3) 1<1>


  Ignoring the SGI entries, the part that worries me is that the sample image  
is specified as being tiled, and yet it has tags for StripOffsets and  
StripByteCounts.  My image, on the other hand, has TileOffsets and  
TileByteCounts.  This seems more correct to me, but apparently its not since  
my image viewer loads the sample image correctly and not my image.

  Any clues to these problems would be appreciated a lot.

Tim Wood
The Omni Group

--- tifftest.c ---
#include "tiffio.h"

#define TILE_SIZE 256

typedef struct {
	unsigned char r, g, b;
} pixel_t;
pixel_t image[TILE_SIZE][TILE_SIZE];

int main(int argc, char *argv[])
{
    TIFF               *tif;
    ttile_t             tile;
    int                 i, j;

    for (i = 0; i < TILE_SIZE; i++) {
	for (j = 0; j < TILE_SIZE; j++) {
	    image[i][j].r = i;
	    image[i][j].g = 0 /*(i < j) ? i : j*/;
	    image[i][j].b = j;
	}
    }

    tif = TIFFOpen("foo.tiff", "w");

    /*
     * Don't know why this is necessary, but tiffdump reports no directories
     * if this isn't called 

     */
    TIFFSetDirectory(tif, 0);
    TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, TILE_SIZE);
    TIFFSetField(tif, TIFFTAG_IMAGELENGTH, TILE_SIZE);
    TIFFSetField(tif, TIFFTAG_TILEWIDTH, TILE_SIZE);
    TIFFSetField(tif, TIFFTAG_TILELENGTH, TILE_SIZE);
    TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
    TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
    TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
    TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
    TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
    TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
    TIFFSetField(tif, TIFFTAG_XRESOLUTION, 300.0);
    TIFFSetField(tif, TIFFTAG_YRESOLUTION, 300.0);
    TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
    TIFFSetField(tif, TIFFTAG_MINSAMPLEVALUE, 0);
    TIFFSetField(tif, TIFFTAG_MAXSAMPLEVALUE, 255);
    TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, TILE_SIZE);

    tile = TIFFComputeTile(tif, 0, 0, 0, 0);
    TIFFWriteEncodedTile(tif, tile, &image, TIFFTileSize(tif));

    TIFFClose(tif);

    exit(0);
}


