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