roentgen b75cab
/* $Id: tif_dir.h,v 1.54 2011-02-18 20:53:05 fwarmerdam Exp $ */
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
 * Copyright (c) 1988-1997 Sam Leffler
roentgen b75cab
 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
roentgen b75cab
 *
roentgen b75cab
 * Permission to use, copy, modify, distribute, and sell this software and 
roentgen b75cab
 * its documentation for any purpose is hereby granted without fee, provided
roentgen b75cab
 * that (i) the above copyright notices and this permission notice appear in
roentgen b75cab
 * all copies of the software and related documentation, and (ii) the names of
roentgen b75cab
 * Sam Leffler and Silicon Graphics may not be used in any advertising or
roentgen b75cab
 * publicity relating to the software without the specific, prior written
roentgen b75cab
 * permission of Sam Leffler and Silicon Graphics.
roentgen b75cab
 * 
roentgen b75cab
 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
roentgen b75cab
 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
roentgen b75cab
 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
roentgen b75cab
 * 
roentgen b75cab
 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
roentgen b75cab
 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
roentgen b75cab
 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
roentgen b75cab
 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
roentgen b75cab
 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
roentgen b75cab
 * OF THIS SOFTWARE.
roentgen b75cab
 */
roentgen b75cab
roentgen b75cab
#ifndef _TIFFDIR_
roentgen b75cab
#define	_TIFFDIR_
roentgen b75cab
/*
roentgen b75cab
 * ``Library-private'' Directory-related Definitions.
roentgen b75cab
 */
roentgen b75cab
roentgen b75cab
typedef struct {
roentgen b75cab
	const TIFFField *info;
roentgen b75cab
	int             count;
roentgen b75cab
	void           *value;
roentgen b75cab
} TIFFTagValue;
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
 * TIFF Image File Directories are comprised of a table of field
roentgen b75cab
 * descriptors of the form shown below.  The table is sorted in
roentgen b75cab
 * ascending order by tag.  The values associated with each entry are
roentgen b75cab
 * disjoint and may appear anywhere in the file (so long as they are
roentgen b75cab
 * placed on a word boundary).
roentgen b75cab
 *
roentgen b75cab
 * If the value is 4 bytes or less, in ClassicTIFF, or 8 bytes or less in
roentgen b75cab
 * BigTIFF, then it is placed in the offset field to save space. If so,
roentgen b75cab
 * it is left-justified in the offset field.
roentgen b75cab
 */
roentgen b75cab
typedef struct {
roentgen b75cab
	uint16 tdir_tag;        /* see below */
roentgen b75cab
	uint16 tdir_type;       /* data type; see below */
roentgen b75cab
	uint64 tdir_count;      /* number of items; length in spec */
roentgen b75cab
	union {
roentgen b75cab
		uint16 toff_short;
roentgen b75cab
		uint32 toff_long;
roentgen b75cab
		uint64 toff_long8;
roentgen b75cab
	} tdir_offset;		/* either offset or the data itself if fits */
roentgen b75cab
} TIFFDirEntry;
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
 * Internal format of a TIFF directory entry.
roentgen b75cab
 */
roentgen b75cab
typedef struct {
roentgen b75cab
#define FIELD_SETLONGS 4
roentgen b75cab
	/* bit vector of fields that are set */
roentgen b75cab
	unsigned long td_fieldsset[FIELD_SETLONGS];
roentgen b75cab
roentgen b75cab
	uint32  td_imagewidth, td_imagelength, td_imagedepth;
roentgen b75cab
	uint32  td_tilewidth, td_tilelength, td_tiledepth;
roentgen b75cab
	uint32  td_subfiletype;
roentgen b75cab
	uint16  td_bitspersample;
roentgen b75cab
	uint16  td_sampleformat;
roentgen b75cab
	uint16  td_compression;
roentgen b75cab
	uint16  td_photometric;
roentgen b75cab
	uint16  td_threshholding;
roentgen b75cab
	uint16  td_fillorder;
roentgen b75cab
	uint16  td_orientation;
roentgen b75cab
	uint16  td_samplesperpixel;
roentgen b75cab
	uint32  td_rowsperstrip;
roentgen b75cab
	uint16  td_minsamplevalue, td_maxsamplevalue;
roentgen b75cab
	double* td_sminsamplevalue;
roentgen b75cab
	double* td_smaxsamplevalue;
roentgen b75cab
	float   td_xresolution, td_yresolution;
roentgen b75cab
	uint16  td_resolutionunit;
roentgen b75cab
	uint16  td_planarconfig;
roentgen b75cab
	float   td_xposition, td_yposition;
roentgen b75cab
	uint16  td_pagenumber[2];
roentgen b75cab
	uint16* td_colormap[3];
roentgen b75cab
	uint16  td_halftonehints[2];
roentgen b75cab
	uint16  td_extrasamples;
roentgen b75cab
	uint16* td_sampleinfo;
roentgen b75cab
	/* even though the name is misleading, td_stripsperimage is the number
roentgen b75cab
	 * of striles (=strips or tiles) per plane, and td_nstrips the total
roentgen b75cab
	 * number of striles */
roentgen b75cab
	uint32  td_stripsperimage;  
roentgen b75cab
	uint32  td_nstrips;              /* size of offset & bytecount arrays */
roentgen b75cab
	uint64* td_stripoffset;
roentgen b75cab
	uint64* td_stripbytecount;
roentgen b75cab
	int     td_stripbytecountsorted; /* is the bytecount array sorted ascending? */
roentgen b75cab
#if defined(DEFER_STRILE_LOAD)
roentgen b75cab
        TIFFDirEntry td_stripoffset_entry;    /* for deferred loading */
roentgen b75cab
        TIFFDirEntry td_stripbytecount_entry; /* for deferred loading */
roentgen b75cab
#endif
roentgen b75cab
	uint16  td_nsubifd;
roentgen b75cab
	uint64* td_subifd;
roentgen b75cab
	/* YCbCr parameters */
roentgen b75cab
	uint16  td_ycbcrsubsampling[2];
roentgen b75cab
	uint16  td_ycbcrpositioning;
roentgen b75cab
	/* Colorimetry parameters */
roentgen b75cab
	uint16* td_transferfunction[3];
roentgen b75cab
	float*	td_refblackwhite;
roentgen b75cab
	/* CMYK parameters */
roentgen b75cab
	int     td_inknameslen;
roentgen b75cab
	char*   td_inknames;
roentgen b75cab
roentgen b75cab
	int     td_customValueCount;
roentgen b75cab
        TIFFTagValue *td_customValues;
roentgen b75cab
} TIFFDirectory;
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
 * Field flags used to indicate fields that have been set in a directory, and
roentgen b75cab
 * to reference fields when manipulating a directory.
roentgen b75cab
 */
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
 * FIELD_IGNORE is used to signify tags that are to be processed but otherwise
roentgen b75cab
 * ignored.  This permits antiquated tags to be quietly read and discarded.
roentgen b75cab
 * Note that a bit *is* allocated for ignored tags; this is understood by the
roentgen b75cab
 * directory reading logic which uses this fact to avoid special-case handling
roentgen b75cab
 */
roentgen b75cab
#define FIELD_IGNORE                   0
roentgen b75cab
roentgen b75cab
/* multi-item fields */
roentgen b75cab
#define FIELD_IMAGEDIMENSIONS          1
roentgen b75cab
#define FIELD_TILEDIMENSIONS           2
roentgen b75cab
#define FIELD_RESOLUTION               3
roentgen b75cab
#define FIELD_POSITION                 4
roentgen b75cab
roentgen b75cab
/* single-item fields */
roentgen b75cab
#define FIELD_SUBFILETYPE              5
roentgen b75cab
#define FIELD_BITSPERSAMPLE            6
roentgen b75cab
#define FIELD_COMPRESSION              7
roentgen b75cab
#define FIELD_PHOTOMETRIC              8
roentgen b75cab
#define FIELD_THRESHHOLDING            9
roentgen b75cab
#define FIELD_FILLORDER                10
roentgen b75cab
#define FIELD_ORIENTATION              15
roentgen b75cab
#define FIELD_SAMPLESPERPIXEL          16
roentgen b75cab
#define FIELD_ROWSPERSTRIP             17
roentgen b75cab
#define FIELD_MINSAMPLEVALUE           18
roentgen b75cab
#define FIELD_MAXSAMPLEVALUE           19
roentgen b75cab
#define FIELD_PLANARCONFIG             20
roentgen b75cab
#define FIELD_RESOLUTIONUNIT           22
roentgen b75cab
#define FIELD_PAGENUMBER               23
roentgen b75cab
#define FIELD_STRIPBYTECOUNTS          24
roentgen b75cab
#define FIELD_STRIPOFFSETS             25
roentgen b75cab
#define FIELD_COLORMAP                 26
roentgen b75cab
#define FIELD_EXTRASAMPLES             31
roentgen b75cab
#define FIELD_SAMPLEFORMAT             32
roentgen b75cab
#define FIELD_SMINSAMPLEVALUE          33
roentgen b75cab
#define FIELD_SMAXSAMPLEVALUE          34
roentgen b75cab
#define FIELD_IMAGEDEPTH               35
roentgen b75cab
#define FIELD_TILEDEPTH                36
roentgen b75cab
#define FIELD_HALFTONEHINTS            37
roentgen b75cab
#define FIELD_YCBCRSUBSAMPLING         39
roentgen b75cab
#define FIELD_YCBCRPOSITIONING         40
roentgen b75cab
#define	FIELD_REFBLACKWHITE            41
roentgen b75cab
#define FIELD_TRANSFERFUNCTION         44
roentgen b75cab
#define FIELD_INKNAMES                 46
roentgen b75cab
#define FIELD_SUBIFD                   49
roentgen b75cab
/*      FIELD_CUSTOM (see tiffio.h)    65 */
roentgen b75cab
/* end of support for well-known tags; codec-private tags follow */
roentgen b75cab
#define FIELD_CODEC                    66  /* base of codec-private tags */
roentgen b75cab
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
 * Pseudo-tags don't normally need field bits since they are not written to an
roentgen b75cab
 * output file (by definition). The library also has express logic to always
roentgen b75cab
 * query a codec for a pseudo-tag so allocating a field bit for one is a
roentgen b75cab
 * waste.   If codec wants to promote the notion of a pseudo-tag being ``set''
roentgen b75cab
 * or ``unset'' then it can do using internal state flags without polluting
roentgen b75cab
 * the field bit space defined for real tags.
roentgen b75cab
 */
roentgen b75cab
#define FIELD_PSEUDO			0
roentgen b75cab
roentgen b75cab
#define FIELD_LAST			(32*FIELD_SETLONGS-1)
roentgen b75cab
roentgen b75cab
#define BITn(n)				(((unsigned long)1L)<<((n)&0x1f))
roentgen b75cab
#define BITFIELDn(tif, n)		((tif)->tif_dir.td_fieldsset[(n)/32])
roentgen b75cab
#define TIFFFieldSet(tif, field)	(BITFIELDn(tif, field) & BITn(field))
roentgen b75cab
#define TIFFSetFieldBit(tif, field)	(BITFIELDn(tif, field) |= BITn(field))
roentgen b75cab
#define TIFFClrFieldBit(tif, field)	(BITFIELDn(tif, field) &= ~BITn(field))
roentgen b75cab
roentgen b75cab
#define FieldSet(fields, f)		(fields[(f)/32] & BITn(f))
roentgen b75cab
#define ResetFieldBit(fields, f)	(fields[(f)/32] &= ~BITn(f))
roentgen b75cab
roentgen b75cab
typedef enum {
roentgen b75cab
	TIFF_SETGET_UNDEFINED = 0,
roentgen b75cab
	TIFF_SETGET_ASCII = 1,
roentgen b75cab
	TIFF_SETGET_UINT8 = 2,
roentgen b75cab
	TIFF_SETGET_SINT8 = 3,
roentgen b75cab
	TIFF_SETGET_UINT16 = 4,
roentgen b75cab
	TIFF_SETGET_SINT16 = 5,
roentgen b75cab
	TIFF_SETGET_UINT32 = 6,
roentgen b75cab
	TIFF_SETGET_SINT32 = 7,
roentgen b75cab
	TIFF_SETGET_UINT64 = 8,
roentgen b75cab
	TIFF_SETGET_SINT64 = 9,
roentgen b75cab
	TIFF_SETGET_FLOAT = 10,
roentgen b75cab
	TIFF_SETGET_DOUBLE = 11,
roentgen b75cab
	TIFF_SETGET_IFD8 = 12,
roentgen b75cab
	TIFF_SETGET_INT = 13,
roentgen b75cab
	TIFF_SETGET_UINT16_PAIR = 14,
roentgen b75cab
	TIFF_SETGET_C0_ASCII = 15,
roentgen b75cab
	TIFF_SETGET_C0_UINT8 = 16,
roentgen b75cab
	TIFF_SETGET_C0_SINT8 = 17,
roentgen b75cab
	TIFF_SETGET_C0_UINT16 = 18,
roentgen b75cab
	TIFF_SETGET_C0_SINT16 = 19,
roentgen b75cab
	TIFF_SETGET_C0_UINT32 = 20,
roentgen b75cab
	TIFF_SETGET_C0_SINT32 = 21,
roentgen b75cab
	TIFF_SETGET_C0_UINT64 = 22,
roentgen b75cab
	TIFF_SETGET_C0_SINT64 = 23,
roentgen b75cab
	TIFF_SETGET_C0_FLOAT = 24,
roentgen b75cab
	TIFF_SETGET_C0_DOUBLE = 25,
roentgen b75cab
	TIFF_SETGET_C0_IFD8 = 26,
roentgen b75cab
	TIFF_SETGET_C16_ASCII = 27,
roentgen b75cab
	TIFF_SETGET_C16_UINT8 = 28,
roentgen b75cab
	TIFF_SETGET_C16_SINT8 = 29,
roentgen b75cab
	TIFF_SETGET_C16_UINT16 = 30,
roentgen b75cab
	TIFF_SETGET_C16_SINT16 = 31,
roentgen b75cab
	TIFF_SETGET_C16_UINT32 = 32,
roentgen b75cab
	TIFF_SETGET_C16_SINT32 = 33,
roentgen b75cab
	TIFF_SETGET_C16_UINT64 = 34,
roentgen b75cab
	TIFF_SETGET_C16_SINT64 = 35,
roentgen b75cab
	TIFF_SETGET_C16_FLOAT = 36,
roentgen b75cab
	TIFF_SETGET_C16_DOUBLE = 37,
roentgen b75cab
	TIFF_SETGET_C16_IFD8 = 38,
roentgen b75cab
	TIFF_SETGET_C32_ASCII = 39,
roentgen b75cab
	TIFF_SETGET_C32_UINT8 = 40,
roentgen b75cab
	TIFF_SETGET_C32_SINT8 = 41,
roentgen b75cab
	TIFF_SETGET_C32_UINT16 = 42,
roentgen b75cab
	TIFF_SETGET_C32_SINT16 = 43,
roentgen b75cab
	TIFF_SETGET_C32_UINT32 = 44,
roentgen b75cab
	TIFF_SETGET_C32_SINT32 = 45,
roentgen b75cab
	TIFF_SETGET_C32_UINT64 = 46,
roentgen b75cab
	TIFF_SETGET_C32_SINT64 = 47,
roentgen b75cab
	TIFF_SETGET_C32_FLOAT = 48,
roentgen b75cab
	TIFF_SETGET_C32_DOUBLE = 49,
roentgen b75cab
	TIFF_SETGET_C32_IFD8 = 50,
roentgen b75cab
	TIFF_SETGET_OTHER = 51
roentgen b75cab
} TIFFSetGetFieldType;
roentgen b75cab
roentgen b75cab
#if defined(__cplusplus)
roentgen b75cab
extern "C" {
roentgen b75cab
#endif
roentgen b75cab
roentgen b75cab
extern const TIFFFieldArray* _TIFFGetFields(void);
roentgen b75cab
extern const TIFFFieldArray* _TIFFGetExifFields(void);
roentgen b75cab
extern void _TIFFSetupFields(TIFF* tif, const TIFFFieldArray* infoarray);
roentgen b75cab
extern void _TIFFPrintFieldInfo(TIFF*, FILE*);
roentgen b75cab
roentgen b75cab
extern int _TIFFFillStriles(TIFF*);        
roentgen b75cab
roentgen b75cab
typedef enum {
roentgen b75cab
	tfiatImage,
roentgen b75cab
	tfiatExif,
roentgen b75cab
	tfiatOther
roentgen b75cab
} TIFFFieldArrayType;
roentgen b75cab
roentgen b75cab
struct _TIFFFieldArray {
roentgen b75cab
	TIFFFieldArrayType type;    /* array type, will be used to determine if IFD is image and such */
roentgen b75cab
	uint32 allocated_size;      /* 0 if array is constant, other if modified by future definition extension support */
roentgen b75cab
	uint32 count;               /* number of elements in fields array */
roentgen b75cab
	TIFFField* fields;          /* actual field info */
roentgen b75cab
};
roentgen b75cab
roentgen b75cab
struct _TIFFField {
roentgen b75cab
	uint32 field_tag;                       /* field's tag */
roentgen b75cab
	short field_readcount;                  /* read count/TIFF_VARIABLE/TIFF_SPP */
roentgen b75cab
	short field_writecount;                 /* write count/TIFF_VARIABLE */
roentgen b75cab
	TIFFDataType field_type;                /* type of associated data */
roentgen b75cab
	uint32 reserved;                        /* reserved for future extension */
roentgen b75cab
	TIFFSetGetFieldType set_field_type;     /* type to be passed to TIFFSetField */
roentgen b75cab
	TIFFSetGetFieldType get_field_type;     /* type to be passed to TIFFGetField */
roentgen b75cab
	unsigned short field_bit;               /* bit in fieldsset bit vector */
roentgen b75cab
	unsigned char field_oktochange;         /* if true, can change while writing */
roentgen b75cab
	unsigned char field_passcount;          /* if true, pass dir count on set */
roentgen b75cab
	char* field_name;                       /* ASCII name */
roentgen b75cab
	TIFFFieldArray* field_subfields;        /* if field points to child ifds, child ifd field definition array */
roentgen b75cab
};
roentgen b75cab
roentgen b75cab
extern int _TIFFMergeFields(TIFF*, const TIFFField[], uint32);
roentgen b75cab
extern const TIFFField* _TIFFFindOrRegisterField(TIFF *, uint32, TIFFDataType);
roentgen b75cab
extern  TIFFField* _TIFFCreateAnonField(TIFF *, uint32, TIFFDataType);
roentgen b75cab
roentgen b75cab
#if defined(__cplusplus)
roentgen b75cab
}
roentgen b75cab
#endif
roentgen b75cab
#endif /* _TIFFDIR_ */
roentgen b75cab
roentgen b75cab
/* vim: set ts=8 sts=8 sw=8 noet: */
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
 * Local Variables:
roentgen b75cab
 * mode: c
roentgen b75cab
 * c-basic-offset: 8
roentgen b75cab
 * fill-column: 78
roentgen b75cab
 * End:
roentgen b75cab
 */