/* * Copyright (c) 1988-1997 Sam Leffler * Copyright (c) 1991-1997 Silicon Graphics, Inc. * * Permission to use, copy, modify, distribute, and sell this software and * its documentation for any purpose is hereby granted without fee, provided * that (i) the above copyright notices and this permission notice appear in * all copies of the software and related documentation, and (ii) the names of * Sam Leffler and Silicon Graphics may not be used in any advertising or * publicity relating to the software without the specific, prior written * permission of Sam Leffler and Silicon Graphics. * * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. * * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. */ /* * TIFF Library. * * Directory Tag Get & Set Routines. * (and also some miscellaneous stuff) */ #include "tiffiop.h" #include <float.h> /*--: for Rational2Double */ #include <limits.h> /* * These are used in the backwards compatibility code... */ #define DATATYPE_VOID … #define DATATYPE_INT … #define DATATYPE_UINT … #define DATATYPE_IEEEFP … static void setByteArray(TIFF *tif, void **vpp, const void *vp, size_t nmemb, size_t elem_size) { … } void _TIFFsetByteArray(void **vpp, const void *vp, uint32_t n) { … } void _TIFFsetByteArrayExt(TIFF *tif, void **vpp, const void *vp, uint32_t n) { … } static void _TIFFsetNString(TIFF *tif, char **cpp, const char *cp, uint32_t n) { … } void _TIFFsetShortArray(uint16_t **wpp, const uint16_t *wp, uint32_t n) { … } void _TIFFsetShortArrayExt(TIFF *tif, uint16_t **wpp, const uint16_t *wp, uint32_t n) { … } void _TIFFsetLongArray(uint32_t **lpp, const uint32_t *lp, uint32_t n) { … } void _TIFFsetLongArrayExt(TIFF *tif, uint32_t **lpp, const uint32_t *lp, uint32_t n) { … } static void _TIFFsetLong8Array(TIFF *tif, uint64_t **lpp, const uint64_t *lp, uint32_t n) { … } void _TIFFsetFloatArray(float **fpp, const float *fp, uint32_t n) { … } void _TIFFsetFloatArrayExt(TIFF *tif, float **fpp, const float *fp, uint32_t n) { … } void _TIFFsetDoubleArray(double **dpp, const double *dp, uint32_t n) { … } void _TIFFsetDoubleArrayExt(TIFF *tif, double **dpp, const double *dp, uint32_t n) { … } static void setDoubleArrayOneValue(TIFF *tif, double **vpp, double value, size_t nmemb) { … } /* * Install extra samples information. */ static int setExtraSamples(TIFF *tif, va_list ap, uint32_t *v) { … } /* * Count ink names separated by \0. Returns * zero if the ink names are not as expected. */ static uint16_t countInkNamesString(TIFF *tif, uint32_t slen, const char *s) { … } static int _TIFFVSetField(TIFF *tif, uint32_t tag, va_list ap) { … } /*-- _TIFFVSetField() --*/ /* * Return 1/0 according to whether or not * it is permissible to set the tag's value. * Note that we allow ImageLength to be changed * so that we can append and extend to images. * Any other tag may not be altered once writing * has commenced, unless its value has no effect * on the format of the data that is written. */ static int OkToChangeTag(TIFF *tif, uint32_t tag) { … } /* * Record the value of a field in the * internal directory structure. The * field will be written to the file * when/if the directory structure is * updated. */ int TIFFSetField(TIFF *tif, uint32_t tag, ...) { … } /* * Clear the contents of the field in the internal structure. */ int TIFFUnsetField(TIFF *tif, uint32_t tag) { … } /* * Like TIFFSetField, but taking a varargs * parameter list. This routine is useful * for building higher-level interfaces on * top of the library. */ int TIFFVSetField(TIFF *tif, uint32_t tag, va_list ap) { … } static int _TIFFVGetField(TIFF *tif, uint32_t tag, va_list ap) { … } /* * Return the value of a field in the * internal directory structure. */ int TIFFGetField(TIFF *tif, uint32_t tag, ...) { … } /* * Like TIFFGetField, but taking a varargs * parameter list. This routine is useful * for building higher-level interfaces on * top of the library. */ int TIFFVGetField(TIFF *tif, uint32_t tag, va_list ap) { … } #define CleanupField … /* * Release storage associated with a directory. */ void TIFFFreeDirectory(TIFF *tif) { … } #undef CleanupField /* * Client Tag extension support (from Niles Ritter). */ static TIFFExtendProc _TIFFextender = …; TIFFExtendProc TIFFSetTagExtender(TIFFExtendProc extender) { … } /* * Setup for a new directory. Should we automatically call * TIFFWriteDirectory() if the current one is dirty? * * The newly created directory will not exist on the file till * TIFFWriteDirectory(), TIFFFlush() or TIFFClose() is called. */ int TIFFCreateDirectory(TIFF *tif) { … } int TIFFCreateCustomDirectory(TIFF *tif, const TIFFFieldArray *infoarray) { … } int TIFFCreateEXIFDirectory(TIFF *tif) { … } /* * Creates the EXIF GPS custom directory */ int TIFFCreateGPSDirectory(TIFF *tif) { … } /* * Setup a default directory structure. */ int TIFFDefaultDirectory(TIFF *tif) { … } static int TIFFAdvanceDirectory(TIFF *tif, uint64_t *nextdiroff, uint64_t *off, tdir_t *nextdirnum) { … } /* * Count the number of directories in a file. */ tdir_t TIFFNumberOfDirectories(TIFF *tif) { … } /* * Set the n-th directory as the current directory. * NB: Directories are numbered starting at 0. */ int TIFFSetDirectory(TIFF *tif, tdir_t dirn) { … } /* * Set the current directory to be the directory * located at the specified file offset. This interface * is used mainly to access directories linked with * the SubIFD tag (e.g. thumbnail images). */ int TIFFSetSubDirectory(TIFF *tif, uint64_t diroff) { … } /* * Return file offset of the current directory. */ uint64_t TIFFCurrentDirOffset(TIFF *tif) { … } /* * Return an indication of whether or not we are * at the last directory in the file. */ int TIFFLastDirectory(TIFF *tif) { … } /* * Unlink the specified directory from the directory chain. * Note: First directory starts with number dirn=1. * This is different to TIFFSetDirectory() where the first directory starts with * zero. */ int TIFFUnlinkDirectory(TIFF *tif, tdir_t dirn) { … }