/* * 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. * * Core Directory Tag Support. */ #include "tiffiop.h" #include <stdlib.h> /* * NOTE: THIS ARRAY IS ASSUMED TO BE SORTED BY TAG. * * NOTE: The second field (field_readcount) and third field (field_writecount) * sometimes use the values TIFF_VARIABLE (-1), TIFF_VARIABLE2 (-3) * and TIFF_SPP (-2). The macros should be used but would throw off * the formatting of the code, so please interpret the -1, -2 and -3 * values accordingly. */ /* const object should be initialized */ #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4132) #endif static const TIFFFieldArray tiffFieldArray; static const TIFFFieldArray exifFieldArray; static const TIFFFieldArray gpsFieldArray; #ifdef _MSC_VER #pragma warning(pop) #endif /*--: Rational2Double: -- * The Rational2Double upgraded libtiff functionality allows the definition and * achievement of true double-precision accuracy for TIFF tags of RATIONAL type * and field_bit=FIELD_CUSTOM using the set_field_type = TIFF_SETGET_DOUBLE. * Unfortunately, that changes the old implemented interface for TIFFGetField(). * In order to keep the old TIFFGetField() interface behavior those tags have to * be redefined with set_field_type = TIFF_SETGET_FLOAT! * * Rational custom arrays are already defined as _Cxx_FLOAT, thus can stay. * */ /* clang-format off */ /* for better readability of tag comments */ static const TIFFField tiffFields[] = …; /* * EXIF tags (Version 2.31, July 2016 plus version 2.32 May 2019) */ static const TIFFField exifFields[] = …; /* * EXIF-GPS tags (Version 2.31, July 2016; nothing changed for version 2.32 May * 2019) */ static const TIFFField gpsFields[] = …; /* clang-format on */ /* was off for better readability of tag comments */ static const TIFFFieldArray tiffFieldArray = …; static const TIFFFieldArray exifFieldArray = …; static const TIFFFieldArray gpsFieldArray = …; /* * We have our own local lfind() equivalent to avoid subtle differences * in types passed to lfind() on different systems. */ static void *td_lfind(const void *key, const void *base, size_t *nmemb, size_t size, int (*compar)(const void *, const void *)) { … } const TIFFFieldArray *_TIFFGetFields(void) { … } const TIFFFieldArray *_TIFFGetExifFields(void) { … } const TIFFFieldArray *_TIFFGetGpsFields(void) { … } void _TIFFSetupFields(TIFF *tif, const TIFFFieldArray *fieldarray) { … } static int tagCompare(const void *a, const void *b) { … } static int tagNameCompare(const void *a, const void *b) { … } int _TIFFMergeFields(TIFF *tif, const TIFFField info[], uint32_t n) { … } void _TIFFPrintFieldInfo(TIFF *tif, FILE *fd) { … } /* * Return size of TIFFDataType within TIFF-file in bytes */ int TIFFDataWidth(TIFFDataType type) { … } /* * Return internal storage size of TIFFSetGetFieldType in bytes. * TIFFSetField() and TIFFGetField() have to provide the parameter accordingly. * Replaces internal functions _TIFFDataSize() and _TIFFSetGetFieldSize() * with now extern available function TIFFFieldSetGetSize(). */ int TIFFFieldSetGetSize(const TIFFField *fip) { … } /*-- TIFFFieldSetGetSize() --- */ /* * Return size of count parameter of TIFFSetField() and TIFFGetField() * and also if it is required: 0=none, 2=uint16_t, 4=uint32_t */ int TIFFFieldSetGetCountSize(const TIFFField *fip) { … } /*-- TIFFFieldSetGetCountSize() --- */ const TIFFField *TIFFFindField(TIFF *tif, uint32_t tag, TIFFDataType dt) { … } static const TIFFField *_TIFFFindFieldByName(TIFF *tif, const char *field_name, TIFFDataType dt) { … } const TIFFField *TIFFFieldWithTag(TIFF *tif, uint32_t tag) { … } const TIFFField *TIFFFieldWithName(TIFF *tif, const char *field_name) { … } uint32_t TIFFFieldTag(const TIFFField *fip) { … } const char *TIFFFieldName(const TIFFField *fip) { … } TIFFDataType TIFFFieldDataType(const TIFFField *fip) { … } int TIFFFieldPassCount(const TIFFField *fip) { … } int TIFFFieldReadCount(const TIFFField *fip) { … } int TIFFFieldWriteCount(const TIFFField *fip) { … } int TIFFFieldIsAnonymous(const TIFFField *fip) { … } const TIFFField *_TIFFFindOrRegisterField(TIFF *tif, uint32_t tag, TIFFDataType dt) { … } TIFFField *_TIFFCreateAnonField(TIFF *tif, uint32_t tag, TIFFDataType field_type) { … } /**************************************************************************** * O B S O L E T E D I N T E R F A C E S * * Don't use this stuff in your applications, it may be removed in the future * libtiff versions. ****************************************************************************/ static TIFFSetGetFieldType _TIFFSetGetType(TIFFDataType type, short count, unsigned char passcount) { … } int TIFFMergeFieldInfo(TIFF *tif, const TIFFFieldInfo info[], uint32_t n) { … } int _TIFFCheckFieldIsValidForCodec(TIFF *tif, ttag_t tag) { … }