mirror of https://github.com/opencv/opencv.git
libtiff upgrade to version 4.6.0 (#25096)
* libtiff upgrade to version 4.6.0 * fix tiffvers.h cmake generation * temp: force build 3rd party deps from source * remove libport.h and spintf.c * cmake fixes * don't use tiff_dummy_namespace on windows * introduce numeric_types namespace alias * include cstdint * uint16_t is not a numeric_types type * fix uint16 and uint32 type defs * use standard c++ types * remove unused files * remove more unused files * revert build 3rd party code from source --------- Co-authored-by: Misha Klatis <misha.klatis@autodesk.com>pull/25255/head
parent
3afe8ddaf8
commit
52f3f5a3f6
64 changed files with 45842 additions and 35316 deletions
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,69 @@ |
||||
TIFF Software Distribution |
||||
-------------------------- |
||||
This file is just a placeholder; the entire documentation is now located |
||||
as reStructuredText in the doc directory. To view the documentation |
||||
as HTML, visit https://libtiff.gitlab.io/libtiff/ or |
||||
http://www.simplesystems.org/libtiff/ or within the release package |
||||
in the doc/html-prebuilt directory. The manual pages are |
||||
located at doc/man-prebuilt. |
||||
|
||||
The release package can be downloaded at |
||||
|
||||
http://download.osgeo.org/libtiff/ |
||||
|
||||
If you can't hack either of these options then basically what you |
||||
want to do is: |
||||
|
||||
% ./configure |
||||
% make |
||||
% su |
||||
# make install |
||||
|
||||
More information, email contacts, and mailing list information can be |
||||
found online at http://www.simplesystems.org/libtiff/ |
||||
|
||||
Source code repository |
||||
---------------------- |
||||
|
||||
[GitLab](https://gitlab.com/libtiff/libtiff) |
||||
|
||||
Bug database |
||||
------------ |
||||
|
||||
[GitLab issues](https://gitlab.com/libtiff/libtiff/issues) |
||||
|
||||
Previously, the project used |
||||
[Bugzilla](http://bugzilla.maptools.org/buglist.cgi?product=libtiff). This |
||||
is no longer in use, and all remaining issues have been migrated to GitLab. |
||||
|
||||
Use and Copyright |
||||
----------------- |
||||
Silicon Graphics has seen fit to allow us to give this work away. It |
||||
is free. There is no support or guarantee of any sort as to its |
||||
operations, correctness, or whatever. If you do anything useful with |
||||
all or parts of it you need to honor the copyright notices. I would |
||||
also be interested in knowing about it and, hopefully, be acknowledged. |
||||
|
||||
The legal way of saying that is: |
||||
|
||||
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. |
@ -1,71 +0,0 @@ |
||||
/*
|
||||
* Copyright (c) 2009 Frank Warmerdam |
||||
* |
||||
* 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. |
||||
*/ |
||||
|
||||
#ifndef _LIBPORT_ |
||||
#define _LIBPORT_ |
||||
|
||||
#if defined(HAVE_CONFIG_H) |
||||
# include <tif_config.h> |
||||
#endif |
||||
|
||||
int getopt(int argc, char * const argv[], const char *optstring); |
||||
extern char *optarg; |
||||
extern int opterr; |
||||
extern int optind; |
||||
extern int optopt; |
||||
|
||||
int strcasecmp(const char *s1, const char *s2); |
||||
|
||||
#ifndef HAVE_GETOPT |
||||
# define HAVE_GETOPT 1 |
||||
#endif |
||||
|
||||
#if !defined(HAVE_STRTOL) |
||||
long strtol(const char *nptr, char **endptr, int base); |
||||
#endif |
||||
#if !defined(HAVE_STRTOLL) |
||||
long long strtoll(const char *nptr, char **endptr, int base); |
||||
#endif |
||||
#if !defined(HAVE_STRTOUL) |
||||
unsigned long strtoul(const char *nptr, char **endptr, int base); |
||||
#endif |
||||
#if !defined(HAVE_STRTOULL) |
||||
unsigned long long strtoull(const char *nptr, char **endptr, int base); |
||||
#endif |
||||
|
||||
#if 0 |
||||
void * |
||||
lfind(const void *key, const void *base, size_t *nmemb, size_t size, |
||||
int(*compar)(const void *, const void *)); |
||||
#endif |
||||
|
||||
#if !defined(HAVE_SNPRINTF) |
||||
#undef vsnprintf |
||||
#define vsnprintf _TIFF_vsnprintf_f |
||||
|
||||
#undef snprintf |
||||
#define snprintf _TIFF_snprintf_f |
||||
int snprintf(char* str, size_t size, const char* format, ...); |
||||
#endif |
||||
|
||||
#endif /* ndef _LIBPORT_ */ |
@ -1,42 +0,0 @@ |
||||
/**
|
||||
* Workaround for lack of snprintf(3) in Visual Studio. See |
||||
* http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010/8712996#8712996
|
||||
* It's a trivial wrapper around the builtin _vsnprintf_s and |
||||
* _vscprintf functions. |
||||
*/ |
||||
|
||||
#ifdef _MSC_VER |
||||
|
||||
#include <stdio.h> |
||||
#include <stdarg.h> |
||||
#include "libport.h" |
||||
|
||||
int _TIFF_vsnprintf_f(char* str, size_t size, const char* format, va_list ap) |
||||
{ |
||||
int count = -1; |
||||
|
||||
if (size != 0) |
||||
#if _MSC_VER <= 1310 |
||||
count = _vsnprintf(str, size, format, ap); |
||||
#else |
||||
count = _vsnprintf_s(str, size, _TRUNCATE, format, ap); |
||||
#endif |
||||
if (count == -1) |
||||
count = _vscprintf(format, ap); |
||||
|
||||
return count; |
||||
} |
||||
|
||||
int _TIFF_snprintf_f(char* str, size_t size, const char* format, ...) |
||||
{ |
||||
int count; |
||||
va_list ap; |
||||
|
||||
va_start(ap, format); |
||||
count = vsnprintf(str, size, format, ap); |
||||
va_end(ap); |
||||
|
||||
return count; |
||||
} |
||||
|
||||
#endif // _MSC_VER
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,603 @@ |
||||
/**********************************************************************
|
||||
* |
||||
* Name: tif_hash_set.c |
||||
* Purpose: Hash set functions. |
||||
* Author: Even Rouault, <even dot rouault at spatialys.com> |
||||
* |
||||
********************************************************************** |
||||
* Copyright (c) 2008-2009, Even Rouault <even dot rouault at spatialys.com> |
||||
* |
||||
* Permission is hereby granted, free of charge, to any person obtaining a |
||||
* copy of this software and associated documentation files (the "Software"), |
||||
* to deal in the Software without restriction, including without limitation |
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
* and/or sell copies of the Software, and to permit persons to whom the |
||||
* Software is furnished to do so, subject to the following conditions: |
||||
* |
||||
* The above copyright notice and this permission notice shall be included |
||||
* in all copies or substantial portions of the Software. |
||||
* |
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
* DEALINGS IN THE SOFTWARE. |
||||
****************************************************************************/ |
||||
|
||||
#include "tif_config.h" |
||||
|
||||
#include "tif_hash_set.h" |
||||
|
||||
#include <assert.h> |
||||
#include <stdbool.h> |
||||
#include <stdint.h> |
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
|
||||
/** List element structure. */ |
||||
typedef struct _TIFFList TIFFList; |
||||
|
||||
/** List element structure. */ |
||||
struct _TIFFList |
||||
{ |
||||
/*! Pointer to the data object. Should be allocated and freed by the
|
||||
* caller. |
||||
* */ |
||||
void *pData; |
||||
/*! Pointer to the next element in list. NULL, if current element is the
|
||||
* last one. |
||||
*/ |
||||
struct _TIFFList *psNext; |
||||
}; |
||||
|
||||
struct _TIFFHashSet |
||||
{ |
||||
TIFFHashSetHashFunc fnHashFunc; |
||||
TIFFHashSetEqualFunc fnEqualFunc; |
||||
TIFFHashSetFreeEltFunc fnFreeEltFunc; |
||||
TIFFList **tabList; |
||||
int nSize; |
||||
int nIndiceAllocatedSize; |
||||
int nAllocatedSize; |
||||
TIFFList *psRecyclingList; |
||||
int nRecyclingListSize; |
||||
bool bRehash; |
||||
#ifdef HASH_DEBUG |
||||
int nCollisions; |
||||
#endif |
||||
}; |
||||
|
||||
static const int anPrimes[] = { |
||||
53, 97, 193, 389, 769, 1543, 3079, |
||||
6151, 12289, 24593, 49157, 98317, 196613, 393241, |
||||
786433, 1572869, 3145739, 6291469, 12582917, 25165843, 50331653, |
||||
100663319, 201326611, 402653189, 805306457, 1610612741}; |
||||
|
||||
/************************************************************************/ |
||||
/* TIFFHashSetHashPointer() */ |
||||
/************************************************************************/ |
||||
|
||||
/**
|
||||
* Hash function for an arbitrary pointer |
||||
* |
||||
* @param elt the arbitrary pointer to hash |
||||
* |
||||
* @return the hash value of the pointer |
||||
*/ |
||||
|
||||
static unsigned long TIFFHashSetHashPointer(const void *elt) |
||||
{ |
||||
return (unsigned long)(uintptr_t)((void *)(elt)); |
||||
} |
||||
|
||||
/************************************************************************/ |
||||
/* TIFFHashSetEqualPointer() */ |
||||
/************************************************************************/ |
||||
|
||||
/**
|
||||
* Equality function for arbitrary pointers |
||||
* |
||||
* @param elt1 the first arbitrary pointer to compare |
||||
* @param elt2 the second arbitrary pointer to compare |
||||
* |
||||
* @return true if the pointers are equal |
||||
*/ |
||||
|
||||
static bool TIFFHashSetEqualPointer(const void *elt1, const void *elt2) |
||||
{ |
||||
return elt1 == elt2; |
||||
} |
||||
|
||||
/************************************************************************/ |
||||
/* TIFFHashSetNew() */ |
||||
/************************************************************************/ |
||||
|
||||
/**
|
||||
* Creates a new hash set |
||||
* |
||||
* The hash function must return a hash value for the elements to insert. |
||||
* If fnHashFunc is NULL, TIFFHashSetHashPointer will be used. |
||||
* |
||||
* The equal function must return if two elements are equal. |
||||
* If fnEqualFunc is NULL, TIFFHashSetEqualPointer will be used. |
||||
* |
||||
* The free function is used to free elements inserted in the hash set, |
||||
* when the hash set is destroyed, when elements are removed or replaced. |
||||
* If fnFreeEltFunc is NULL, elements inserted into the hash set will not be |
||||
* freed. |
||||
* |
||||
* @param fnHashFunc hash function. May be NULL. |
||||
* @param fnEqualFunc equal function. May be NULL. |
||||
* @param fnFreeEltFunc element free function. May be NULL. |
||||
* |
||||
* @return a new hash set |
||||
*/ |
||||
|
||||
TIFFHashSet *TIFFHashSetNew(TIFFHashSetHashFunc fnHashFunc, |
||||
TIFFHashSetEqualFunc fnEqualFunc, |
||||
TIFFHashSetFreeEltFunc fnFreeEltFunc) |
||||
{ |
||||
TIFFHashSet *set = (TIFFHashSet *)malloc(sizeof(TIFFHashSet)); |
||||
if (set == NULL) |
||||
return NULL; |
||||
set->fnHashFunc = fnHashFunc ? fnHashFunc : TIFFHashSetHashPointer; |
||||
set->fnEqualFunc = fnEqualFunc ? fnEqualFunc : TIFFHashSetEqualPointer; |
||||
set->fnFreeEltFunc = fnFreeEltFunc; |
||||
set->nSize = 0; |
||||
set->tabList = (TIFFList **)(calloc(sizeof(TIFFList *), 53)); |
||||
if (set->tabList == NULL) |
||||
{ |
||||
free(set); |
||||
return NULL; |
||||
} |
||||
set->nIndiceAllocatedSize = 0; |
||||
set->nAllocatedSize = 53; |
||||
set->psRecyclingList = NULL; |
||||
set->nRecyclingListSize = 0; |
||||
set->bRehash = false; |
||||
#ifdef HASH_DEBUG |
||||
set->nCollisions = 0; |
||||
#endif |
||||
return set; |
||||
} |
||||
|
||||
/************************************************************************/ |
||||
/* TIFFHashSetSize() */ |
||||
/************************************************************************/ |
||||
|
||||
/**
|
||||
* Returns the number of elements inserted in the hash set |
||||
* |
||||
* Note: this is not the internal size of the hash set |
||||
* |
||||
* @param set the hash set |
||||
* |
||||
* @return the number of elements in the hash set |
||||
*/ |
||||
|
||||
int TIFFHashSetSize(const TIFFHashSet *set) |
||||
{ |
||||
assert(set != NULL); |
||||
return set->nSize; |
||||
} |
||||
|
||||
/************************************************************************/ |
||||
/* TIFFHashSetGetNewListElt() */ |
||||
/************************************************************************/ |
||||
|
||||
static TIFFList *TIFFHashSetGetNewListElt(TIFFHashSet *set) |
||||
{ |
||||
if (set->psRecyclingList) |
||||
{ |
||||
TIFFList *psRet = set->psRecyclingList; |
||||
psRet->pData = NULL; |
||||
set->nRecyclingListSize--; |
||||
set->psRecyclingList = psRet->psNext; |
||||
return psRet; |
||||
} |
||||
|
||||
return (TIFFList *)malloc(sizeof(TIFFList)); |
||||
} |
||||
|
||||
/************************************************************************/ |
||||
/* TIFFHashSetReturnListElt() */ |
||||
/************************************************************************/ |
||||
|
||||
static void TIFFHashSetReturnListElt(TIFFHashSet *set, TIFFList *psList) |
||||
{ |
||||
if (set->nRecyclingListSize < 128) |
||||
{ |
||||
psList->psNext = set->psRecyclingList; |
||||
set->psRecyclingList = psList; |
||||
set->nRecyclingListSize++; |
||||
} |
||||
else |
||||
{ |
||||
free(psList); |
||||
} |
||||
} |
||||
|
||||
/************************************************************************/ |
||||
/* TIFFHashSetClearInternal() */ |
||||
/************************************************************************/ |
||||
|
||||
static void TIFFHashSetClearInternal(TIFFHashSet *set, bool bFinalize) |
||||
{ |
||||
assert(set != NULL); |
||||
for (int i = 0; i < set->nAllocatedSize; i++) |
||||
{ |
||||
TIFFList *cur = set->tabList[i]; |
||||
while (cur) |
||||
{ |
||||
if (set->fnFreeEltFunc) |
||||
set->fnFreeEltFunc(cur->pData); |
||||
TIFFList *psNext = cur->psNext; |
||||
if (bFinalize) |
||||
free(cur); |
||||
else |
||||
TIFFHashSetReturnListElt(set, cur); |
||||
cur = psNext; |
||||
} |
||||
set->tabList[i] = NULL; |
||||
} |
||||
set->bRehash = false; |
||||
} |
||||
|
||||
/************************************************************************/ |
||||
/* TIFFListDestroy() */ |
||||
/************************************************************************/ |
||||
|
||||
/**
|
||||
* Destroy a list. Caller responsible for freeing data objects contained in |
||||
* list elements. |
||||
* |
||||
* @param psList pointer to list head. |
||||
* |
||||
*/ |
||||
|
||||
static void TIFFListDestroy(TIFFList *psList) |
||||
{ |
||||
TIFFList *psCurrent = psList; |
||||
|
||||
while (psCurrent) |
||||
{ |
||||
TIFFList *const psNext = psCurrent->psNext; |
||||
free(psCurrent); |
||||
psCurrent = psNext; |
||||
} |
||||
} |
||||
|
||||
/************************************************************************/ |
||||
/* TIFFHashSetDestroy() */ |
||||
/************************************************************************/ |
||||
|
||||
/**
|
||||
* Destroys an allocated hash set. |
||||
* |
||||
* This function also frees the elements if a free function was |
||||
* provided at the creation of the hash set. |
||||
* |
||||
* @param set the hash set |
||||
*/ |
||||
|
||||
void TIFFHashSetDestroy(TIFFHashSet *set) |
||||
{ |
||||
if (set) |
||||
{ |
||||
TIFFHashSetClearInternal(set, true); |
||||
free(set->tabList); |
||||
TIFFListDestroy(set->psRecyclingList); |
||||
free(set); |
||||
} |
||||
} |
||||
|
||||
#ifdef notused |
||||
/************************************************************************/ |
||||
/* TIFFHashSetClear() */ |
||||
/************************************************************************/ |
||||
|
||||
/**
|
||||
* Clear all elements from a hash set. |
||||
* |
||||
* This function also frees the elements if a free function was |
||||
* provided at the creation of the hash set. |
||||
* |
||||
* @param set the hash set |
||||
*/ |
||||
|
||||
void TIFFHashSetClear(TIFFHashSet *set) |
||||
{ |
||||
TIFFHashSetClearInternal(set, false); |
||||
set->nIndiceAllocatedSize = 0; |
||||
set->nAllocatedSize = 53; |
||||
#ifdef HASH_DEBUG |
||||
set->nCollisions = 0; |
||||
#endif |
||||
set->nSize = 0; |
||||
} |
||||
|
||||
/************************************************************************/ |
||||
/* TIFFHashSetForeach() */ |
||||
/************************************************************************/ |
||||
|
||||
/**
|
||||
* Walk through the hash set and runs the provided function on all the |
||||
* elements |
||||
* |
||||
* This function is provided the user_data argument of TIFFHashSetForeach. |
||||
* It must return true to go on the walk through the hash set, or FALSE to |
||||
* make it stop. |
||||
* |
||||
* Note : the structure of the hash set must *NOT* be modified during the |
||||
* walk. |
||||
* |
||||
* @param set the hash set. |
||||
* @param fnIterFunc the function called on each element. |
||||
* @param user_data the user data provided to the function. |
||||
*/ |
||||
|
||||
void TIFFHashSetForeach(TIFFHashSet *set, TIFFHashSetIterEltFunc fnIterFunc, |
||||
void *user_data) |
||||
{ |
||||
assert(set != NULL); |
||||
if (!fnIterFunc) |
||||
return; |
||||
|
||||
for (int i = 0; i < set->nAllocatedSize; i++) |
||||
{ |
||||
TIFFList *cur = set->tabList[i]; |
||||
while (cur) |
||||
{ |
||||
if (!fnIterFunc(cur->pData, user_data)) |
||||
return; |
||||
|
||||
cur = cur->psNext; |
||||
} |
||||
} |
||||
} |
||||
#endif |
||||
|
||||
/************************************************************************/ |
||||
/* TIFFHashSetRehash() */ |
||||
/************************************************************************/ |
||||
|
||||
static bool TIFFHashSetRehash(TIFFHashSet *set) |
||||
{ |
||||
int nNewAllocatedSize = anPrimes[set->nIndiceAllocatedSize]; |
||||
TIFFList **newTabList = |
||||
(TIFFList **)(calloc(sizeof(TIFFList *), nNewAllocatedSize)); |
||||
if (newTabList == NULL) |
||||
return false; |
||||
#ifdef HASH_DEBUG |
||||
TIFFDebug("TIFFHASH", |
||||
"hashSet=%p, nSize=%d, nCollisions=%d, " |
||||
"fCollisionRate=%.02f", |
||||
set, set->nSize, set->nCollisions, |
||||
set->nCollisions * 100.0 / set->nSize); |
||||
set->nCollisions = 0; |
||||
#endif |
||||
for (int i = 0; i < set->nAllocatedSize; i++) |
||||
{ |
||||
TIFFList *cur = set->tabList[i]; |
||||
while (cur) |
||||
{ |
||||
const unsigned long nNewHashVal = |
||||
set->fnHashFunc(cur->pData) % nNewAllocatedSize; |
||||
#ifdef HASH_DEBUG |
||||
if (newTabList[nNewHashVal]) |
||||
set->nCollisions++; |
||||
#endif |
||||
TIFFList *psNext = cur->psNext; |
||||
cur->psNext = newTabList[nNewHashVal]; |
||||
newTabList[nNewHashVal] = cur; |
||||
cur = psNext; |
||||
} |
||||
} |
||||
free(set->tabList); |
||||
set->tabList = newTabList; |
||||
set->nAllocatedSize = nNewAllocatedSize; |
||||
set->bRehash = false; |
||||
return true; |
||||
} |
||||
|
||||
/************************************************************************/ |
||||
/* TIFFHashSetFindPtr() */ |
||||
/************************************************************************/ |
||||
|
||||
static void **TIFFHashSetFindPtr(TIFFHashSet *set, const void *elt) |
||||
{ |
||||
const unsigned long nHashVal = set->fnHashFunc(elt) % set->nAllocatedSize; |
||||
TIFFList *cur = set->tabList[nHashVal]; |
||||
while (cur) |
||||
{ |
||||
if (set->fnEqualFunc(cur->pData, elt)) |
||||
return &cur->pData; |
||||
cur = cur->psNext; |
||||
} |
||||
return NULL; |
||||
} |
||||
|
||||
/************************************************************************/ |
||||
/* TIFFHashSetInsert() */ |
||||
/************************************************************************/ |
||||
|
||||
/**
|
||||
* Inserts an element into a hash set. |
||||
* |
||||
* If the element was already inserted in the hash set, the previous |
||||
* element is replaced by the new element. If a free function was provided, |
||||
* it is used to free the previously inserted element |
||||
* |
||||
* @param set the hash set |
||||
* @param elt the new element to insert in the hash set |
||||
* |
||||
* @return true if success. If false is returned, elt has not been inserted, |
||||
* but TIFFHashSetInsert() will have run the free function if provided. |
||||
*/ |
||||
|
||||
bool TIFFHashSetInsert(TIFFHashSet *set, void *elt) |
||||
{ |
||||
assert(set != NULL); |
||||
void **pElt = TIFFHashSetFindPtr(set, elt); |
||||
if (pElt) |
||||
{ |
||||
if (set->fnFreeEltFunc) |
||||
set->fnFreeEltFunc(*pElt); |
||||
|
||||
*pElt = elt; |
||||
return true; |
||||
} |
||||
|
||||
if (set->nSize >= 2 * set->nAllocatedSize / 3 || |
||||
(set->bRehash && set->nIndiceAllocatedSize > 0 && |
||||
set->nSize <= set->nAllocatedSize / 2)) |
||||
{ |
||||
set->nIndiceAllocatedSize++; |
||||
if (!TIFFHashSetRehash(set)) |
||||
{ |
||||
set->nIndiceAllocatedSize--; |
||||
if (set->fnFreeEltFunc) |
||||
set->fnFreeEltFunc(elt); |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
const unsigned long nHashVal = set->fnHashFunc(elt) % set->nAllocatedSize; |
||||
#ifdef HASH_DEBUG |
||||
if (set->tabList[nHashVal]) |
||||
set->nCollisions++; |
||||
#endif |
||||
|
||||
TIFFList *new_elt = TIFFHashSetGetNewListElt(set); |
||||
if (new_elt == NULL) |
||||
{ |
||||
if (set->fnFreeEltFunc) |
||||
set->fnFreeEltFunc(elt); |
||||
return false; |
||||
} |
||||
new_elt->pData = elt; |
||||
new_elt->psNext = set->tabList[nHashVal]; |
||||
set->tabList[nHashVal] = new_elt; |
||||
set->nSize++; |
||||
|
||||
return true; |
||||
} |
||||
|
||||
/************************************************************************/ |
||||
/* TIFFHashSetLookup() */ |
||||
/************************************************************************/ |
||||
|
||||
/**
|
||||
* Returns the element found in the hash set corresponding to the element to |
||||
* look up The element must not be modified. |
||||
* |
||||
* @param set the hash set |
||||
* @param elt the element to look up in the hash set |
||||
* |
||||
* @return the element found in the hash set or NULL |
||||
*/ |
||||
|
||||
void *TIFFHashSetLookup(TIFFHashSet *set, const void *elt) |
||||
{ |
||||
assert(set != NULL); |
||||
void **pElt = TIFFHashSetFindPtr(set, elt); |
||||
if (pElt) |
||||
return *pElt; |
||||
|
||||
return NULL; |
||||
} |
||||
|
||||
/************************************************************************/ |
||||
/* TIFFHashSetRemoveInternal() */ |
||||
/************************************************************************/ |
||||
|
||||
static bool TIFFHashSetRemoveInternal(TIFFHashSet *set, const void *elt, |
||||
bool bDeferRehash) |
||||
{ |
||||
assert(set != NULL); |
||||
if (set->nIndiceAllocatedSize > 0 && set->nSize <= set->nAllocatedSize / 2) |
||||
{ |
||||
set->nIndiceAllocatedSize--; |
||||
if (bDeferRehash) |
||||
set->bRehash = true; |
||||
else |
||||
{ |
||||
if (!TIFFHashSetRehash(set)) |
||||
{ |
||||
set->nIndiceAllocatedSize++; |
||||
return false; |
||||
} |
||||
} |
||||
} |
||||
|
||||
int nHashVal = (int)(set->fnHashFunc(elt) % set->nAllocatedSize); |
||||
TIFFList *cur = set->tabList[nHashVal]; |
||||
TIFFList *prev = NULL; |
||||
while (cur) |
||||
{ |
||||
if (set->fnEqualFunc(cur->pData, elt)) |
||||
{ |
||||
if (prev) |
||||
prev->psNext = cur->psNext; |
||||
else |
||||
set->tabList[nHashVal] = cur->psNext; |
||||
|
||||
if (set->fnFreeEltFunc) |
||||
set->fnFreeEltFunc(cur->pData); |
||||
|
||||
TIFFHashSetReturnListElt(set, cur); |
||||
#ifdef HASH_DEBUG |
||||
if (set->tabList[nHashVal]) |
||||
set->nCollisions--; |
||||
#endif |
||||
set->nSize--; |
||||
return true; |
||||
} |
||||
prev = cur; |
||||
cur = cur->psNext; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/************************************************************************/ |
||||
/* TIFFHashSetRemove() */ |
||||
/************************************************************************/ |
||||
|
||||
/**
|
||||
* Removes an element from a hash set |
||||
* |
||||
* @param set the hash set |
||||
* @param elt the new element to remove from the hash set |
||||
* |
||||
* @return true if the element was in the hash set |
||||
*/ |
||||
|
||||
bool TIFFHashSetRemove(TIFFHashSet *set, const void *elt) |
||||
{ |
||||
return TIFFHashSetRemoveInternal(set, elt, false); |
||||
} |
||||
|
||||
#ifdef notused |
||||
/************************************************************************/ |
||||
/* TIFFHashSetRemoveDeferRehash() */ |
||||
/************************************************************************/ |
||||
|
||||
/**
|
||||
* Removes an element from a hash set. |
||||
* |
||||
* This will defer potential rehashing of the set to later calls to |
||||
* TIFFHashSetInsert() or TIFFHashSetRemove(). |
||||
* |
||||
* @param set the hash set |
||||
* @param elt the new element to remove from the hash set |
||||
* |
||||
* @return true if the element was in the hash set |
||||
*/ |
||||
|
||||
bool TIFFHashSetRemoveDeferRehash(TIFFHashSet *set, const void *elt) |
||||
{ |
||||
return TIFFHashSetRemoveInternal(set, elt, true); |
||||
} |
||||
#endif |
@ -0,0 +1,100 @@ |
||||
/**********************************************************************
|
||||
* $Id$ |
||||
* |
||||
* Name: tif_hash_set.h |
||||
* Project: TIFF - Common Portability Library |
||||
* Purpose: Hash set functions. |
||||
* Author: Even Rouault, <even dot rouault at spatialys.com> |
||||
* |
||||
********************************************************************** |
||||
* Copyright (c) 2008-2009, Even Rouault <even dot rouault at spatialys.com> |
||||
* |
||||
* Permission is hereby granted, free of charge, to any person obtaining a |
||||
* copy of this software and associated documentation files (the "Software"), |
||||
* to deal in the Software without restriction, including without limitation |
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
* and/or sell copies of the Software, and to permit persons to whom the |
||||
* Software is furnished to do so, subject to the following conditions: |
||||
* |
||||
* The above copyright notice and this permission notice shall be included |
||||
* in all copies or substantial portions of the Software. |
||||
* |
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
* DEALINGS IN THE SOFTWARE. |
||||
****************************************************************************/ |
||||
|
||||
#ifndef TIFF_HASH_SET_H_INCLUDED |
||||
#define TIFF_HASH_SET_H_INCLUDED |
||||
|
||||
#include <stdbool.h> |
||||
|
||||
/**
|
||||
* \file tif_hash_set.h |
||||
* |
||||
* Hash set implementation. |
||||
* |
||||
* An hash set is a data structure that holds elements that are unique |
||||
* according to a comparison function. Operations on the hash set, such as |
||||
* insertion, removal or lookup, are supposed to be fast if an efficient |
||||
* "hash" function is provided. |
||||
*/ |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" |
||||
{ |
||||
#endif |
||||
|
||||
/* Types */ |
||||
|
||||
/** Opaque type for a hash set */ |
||||
typedef struct _TIFFHashSet TIFFHashSet; |
||||
|
||||
/** TIFFHashSetHashFunc */ |
||||
typedef unsigned long (*TIFFHashSetHashFunc)(const void *elt); |
||||
|
||||
/** TIFFHashSetEqualFunc */ |
||||
typedef bool (*TIFFHashSetEqualFunc)(const void *elt1, const void *elt2); |
||||
|
||||
/** TIFFHashSetFreeEltFunc */ |
||||
typedef void (*TIFFHashSetFreeEltFunc)(void *elt); |
||||
|
||||
/* Functions */ |
||||
|
||||
TIFFHashSet *TIFFHashSetNew(TIFFHashSetHashFunc fnHashFunc, |
||||
TIFFHashSetEqualFunc fnEqualFunc, |
||||
TIFFHashSetFreeEltFunc fnFreeEltFunc); |
||||
|
||||
void TIFFHashSetDestroy(TIFFHashSet *set); |
||||
|
||||
int TIFFHashSetSize(const TIFFHashSet *set); |
||||
|
||||
#ifdef notused |
||||
void TIFFHashSetClear(TIFFHashSet *set); |
||||
|
||||
/** TIFFHashSetIterEltFunc */ |
||||
typedef int (*TIFFHashSetIterEltFunc)(void *elt, void *user_data); |
||||
|
||||
void TIFFHashSetForeach(TIFFHashSet *set, TIFFHashSetIterEltFunc fnIterFunc, |
||||
void *user_data); |
||||
#endif |
||||
|
||||
bool TIFFHashSetInsert(TIFFHashSet *set, void *elt); |
||||
|
||||
void *TIFFHashSetLookup(TIFFHashSet *set, const void *elt); |
||||
|
||||
bool TIFFHashSetRemove(TIFFHashSet *set, const void *elt); |
||||
|
||||
#ifdef notused |
||||
bool TIFFHashSetRemoveDeferRehash(TIFFHashSet *set, const void *elt); |
||||
#endif |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* TIFF_HASH_SET_H_INCLUDED */ |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,9 +0,0 @@ |
||||
#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.2.0\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc." |
||||
/*
|
||||
* This define can be used in code that requires |
||||
* compilation-related definitions specific to a |
||||
* version or versions of the library. Runtime |
||||
* version checking should be done based on the |
||||
* string returned by TIFFGetVersion. |
||||
*/ |
||||
#define TIFFLIB_VERSION 20201219 |
@ -0,0 +1,36 @@ |
||||
/* tiffvers.h version information is updated according to version information |
||||
* in configure.ac */ |
||||
|
||||
/* clang-format off */ |
||||
|
||||
/* clang-format disabled because FindTIFF.cmake is very sensitive to the |
||||
* formatting of below line being a single line. |
||||
* Furthermore, configure_file variables of type "@VAR@" are |
||||
* modified by clang-format and won't be substituted by CMake. |
||||
*/ |
||||
#define TIFFLIB_VERSION_STR "LIBTIFF, Version @LIBTIFF_VERSION@\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc." |
||||
/* |
||||
* This define can be used in code that requires |
||||
* compilation-related definitions specific to a |
||||
* version or versions of the library. Runtime |
||||
* version checking should be done based on the |
||||
* string returned by TIFFGetVersion. |
||||
*/ |
||||
#define TIFFLIB_VERSION @LIBTIFF_RELEASE_DATE@ |
||||
|
||||
/* The following defines have been added in 4.5.0 */ |
||||
#define TIFFLIB_MAJOR_VERSION @LIBTIFF_MAJOR_VERSION@ |
||||
#define TIFFLIB_MINOR_VERSION @LIBTIFF_MINOR_VERSION@ |
||||
#define TIFFLIB_MICRO_VERSION @LIBTIFF_MICRO_VERSION@ |
||||
#define TIFFLIB_VERSION_STR_MAJ_MIN_MIC "@LIBTIFF_VERSION@" |
||||
|
||||
/* Macro added in 4.5.0. Returns TRUE if the current libtiff version is |
||||
* greater or equal to major.minor.micro |
||||
*/ |
||||
#define TIFFLIB_AT_LEAST(major, minor, micro) \ |
||||
(TIFFLIB_MAJOR_VERSION > (major) || \ |
||||
(TIFFLIB_MAJOR_VERSION == (major) && TIFFLIB_MINOR_VERSION > (minor)) || \ |
||||
(TIFFLIB_MAJOR_VERSION == (major) && TIFFLIB_MINOR_VERSION == (minor) && \ |
||||
TIFFLIB_MICRO_VERSION >= (micro))) |
||||
|
||||
/* clang-format on */ |
Loading…
Reference in new issue