mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-10-06 00:30:10 -06:00
plugin/tif: 4.1.0, plugin/lz4: 1.9.2
git-svn-id: svn://ultimatepp.org/upp/trunk@14972 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
33f64867f0
commit
67788a810d
46 changed files with 4502 additions and 5122 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* LZ4 - Fast LZ compression algorithm
|
||||
* Header File
|
||||
* Copyright (C) 2011-2017, Yann Collet.
|
||||
* Copyright (C) 2011-present, Yann Collet.
|
||||
|
||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
||||
|
||||
|
|
@ -46,24 +46,31 @@ extern "C" {
|
|||
/**
|
||||
Introduction
|
||||
|
||||
LZ4 is lossless compression algorithm, providing compression speed at 400 MB/s per core,
|
||||
LZ4 is lossless compression algorithm, providing compression speed >500 MB/s per core,
|
||||
scalable with multi-cores CPU. It features an extremely fast decoder, with speed in
|
||||
multiple GB/s per core, typically reaching RAM speed limits on multi-core systems.
|
||||
|
||||
The LZ4 compression library provides in-memory compression and decompression functions.
|
||||
It gives full buffer control to user.
|
||||
Compression can be done in:
|
||||
- a single step (described as Simple Functions)
|
||||
- a single step, reusing a context (described in Advanced Functions)
|
||||
- unbounded multiple steps (described as Streaming compression)
|
||||
|
||||
lz4.h provides block compression functions. It gives full buffer control to user.
|
||||
Decompressing an lz4-compressed block also requires metadata (such as compressed size).
|
||||
Each application is free to encode such metadata in whichever way it wants.
|
||||
lz4.h generates and decodes LZ4-compressed blocks (doc/lz4_Block_format.md).
|
||||
Decompressing such a compressed block requires additional metadata.
|
||||
Exact metadata depends on exact decompression function.
|
||||
For the typical case of LZ4_decompress_safe(),
|
||||
metadata includes block's compressed size, and maximum bound of decompressed size.
|
||||
Each application is free to encode and pass such metadata in whichever way it wants.
|
||||
|
||||
An additional format, called LZ4 frame specification (doc/lz4_Frame_format.md),
|
||||
take care of encoding standard metadata alongside LZ4-compressed blocks.
|
||||
If your application requires interoperability, it's recommended to use it.
|
||||
A library is provided to take care of it, see lz4frame.h.
|
||||
lz4.h only handle blocks, it can not generate Frames.
|
||||
|
||||
Blocks are different from Frames (doc/lz4_Frame_format.md).
|
||||
Frames bundle both blocks and metadata in a specified manner.
|
||||
Embedding metadata is required for compressed data to be self-contained and portable.
|
||||
Frame format is delivered through a companion API, declared in lz4frame.h.
|
||||
The `lz4` CLI can only manage frames.
|
||||
*/
|
||||
|
||||
/*^***************************************************************
|
||||
|
|
@ -72,24 +79,28 @@ extern "C" {
|
|||
/*
|
||||
* LZ4_DLL_EXPORT :
|
||||
* Enable exporting of functions when building a Windows DLL
|
||||
* LZ4LIB_API :
|
||||
* LZ4LIB_VISIBILITY :
|
||||
* Control library symbols visibility.
|
||||
*/
|
||||
#if defined(LZ4_DLL_EXPORT) && (LZ4_DLL_EXPORT==1)
|
||||
# define LZ4LIB_API __declspec(dllexport)
|
||||
#elif defined(LZ4_DLL_IMPORT) && (LZ4_DLL_IMPORT==1)
|
||||
# define LZ4LIB_API __declspec(dllimport) /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
|
||||
#elif defined(__GNUC__) && (__GNUC__ >= 4)
|
||||
# define LZ4LIB_API __attribute__ ((__visibility__ ("default")))
|
||||
#else
|
||||
# define LZ4LIB_API
|
||||
#ifndef LZ4LIB_VISIBILITY
|
||||
# if defined(__GNUC__) && (__GNUC__ >= 4)
|
||||
# define LZ4LIB_VISIBILITY __attribute__ ((visibility ("default")))
|
||||
# else
|
||||
# define LZ4LIB_VISIBILITY
|
||||
# endif
|
||||
#endif
|
||||
#if defined(LZ4_DLL_EXPORT) && (LZ4_DLL_EXPORT==1)
|
||||
# define LZ4LIB_API __declspec(dllexport) LZ4LIB_VISIBILITY
|
||||
#elif defined(LZ4_DLL_IMPORT) && (LZ4_DLL_IMPORT==1)
|
||||
# define LZ4LIB_API __declspec(dllimport) LZ4LIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
|
||||
#else
|
||||
# define LZ4LIB_API LZ4LIB_VISIBILITY
|
||||
#endif
|
||||
|
||||
|
||||
/*------ Version ------*/
|
||||
#define LZ4_VERSION_MAJOR 1 /* for breaking interface changes */
|
||||
#define LZ4_VERSION_MINOR 8 /* for new (non-breaking) interface capabilities */
|
||||
#define LZ4_VERSION_RELEASE 0 /* for tweaks, bug-fixes, or development */
|
||||
#define LZ4_VERSION_MINOR 9 /* for new (non-breaking) interface capabilities */
|
||||
#define LZ4_VERSION_RELEASE 2 /* for tweaks, bug-fixes, or development */
|
||||
|
||||
#define LZ4_VERSION_NUMBER (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE)
|
||||
|
||||
|
|
@ -98,8 +109,8 @@ extern "C" {
|
|||
#define LZ4_EXPAND_AND_QUOTE(str) LZ4_QUOTE(str)
|
||||
#define LZ4_VERSION_STRING LZ4_EXPAND_AND_QUOTE(LZ4_LIB_VERSION)
|
||||
|
||||
LZ4LIB_API int LZ4_versionNumber (void); /**< library version number; to be used when checking dll version */
|
||||
LZ4LIB_API const char* LZ4_versionString (void); /**< library version string; to be used when checking dll version */
|
||||
LZ4LIB_API int LZ4_versionNumber (void); /**< library version number; useful to check dll version */
|
||||
LZ4LIB_API const char* LZ4_versionString (void); /**< library version string; useful to check dll version */
|
||||
|
||||
|
||||
/*-************************************
|
||||
|
|
@ -108,42 +119,49 @@ LZ4LIB_API const char* LZ4_versionString (void); /**< library version string;
|
|||
/*!
|
||||
* LZ4_MEMORY_USAGE :
|
||||
* Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; etc.)
|
||||
* Increasing memory usage improves compression ratio
|
||||
* Reduced memory usage can improve speed, due to cache effect
|
||||
* Increasing memory usage improves compression ratio.
|
||||
* Reduced memory usage may improve speed, thanks to better cache locality.
|
||||
* Default value is 14, for 16KB, which nicely fits into Intel x86 L1 cache
|
||||
*/
|
||||
#ifndef LZ4_MEMORY_USAGE
|
||||
# define LZ4_MEMORY_USAGE 14
|
||||
#endif
|
||||
|
||||
|
||||
/*-************************************
|
||||
* Simple Functions
|
||||
**************************************/
|
||||
/*! LZ4_compress_default() :
|
||||
Compresses 'sourceSize' bytes from buffer 'source'
|
||||
into already allocated 'dest' buffer of size 'maxDestSize'.
|
||||
Compression is guaranteed to succeed if 'maxDestSize' >= LZ4_compressBound(sourceSize).
|
||||
It also runs faster, so it's a recommended setting.
|
||||
If the function cannot compress 'source' into a more limited 'dest' budget,
|
||||
compression stops *immediately*, and the function result is zero.
|
||||
As a consequence, 'dest' content is not valid.
|
||||
This function never writes outside 'dest' buffer, nor read outside 'source' buffer.
|
||||
sourceSize : Max supported value is LZ4_MAX_INPUT_VALUE
|
||||
maxDestSize : full or partial size of buffer 'dest' (which must be already allocated)
|
||||
return : the number of bytes written into buffer 'dest' (necessarily <= maxOutputSize)
|
||||
or 0 if compression fails */
|
||||
LZ4LIB_API int LZ4_compress_default(const char* source, char* dest, int sourceSize, int maxDestSize);
|
||||
* Compresses 'srcSize' bytes from buffer 'src'
|
||||
* into already allocated 'dst' buffer of size 'dstCapacity'.
|
||||
* Compression is guaranteed to succeed if 'dstCapacity' >= LZ4_compressBound(srcSize).
|
||||
* It also runs faster, so it's a recommended setting.
|
||||
* If the function cannot compress 'src' into a more limited 'dst' budget,
|
||||
* compression stops *immediately*, and the function result is zero.
|
||||
* In which case, 'dst' content is undefined (invalid).
|
||||
* srcSize : max supported value is LZ4_MAX_INPUT_SIZE.
|
||||
* dstCapacity : size of buffer 'dst' (which must be already allocated)
|
||||
* @return : the number of bytes written into buffer 'dst' (necessarily <= dstCapacity)
|
||||
* or 0 if compression fails
|
||||
* Note : This function is protected against buffer overflow scenarios (never writes outside 'dst' buffer, nor read outside 'source' buffer).
|
||||
*/
|
||||
LZ4LIB_API int LZ4_compress_default(const char* src, char* dst, int srcSize, int dstCapacity);
|
||||
|
||||
/*! LZ4_decompress_safe() :
|
||||
compressedSize : is the precise full size of the compressed block.
|
||||
maxDecompressedSize : is the size of destination buffer, which must be already allocated.
|
||||
return : the number of bytes decompressed into destination buffer (necessarily <= maxDecompressedSize)
|
||||
If destination buffer is not large enough, decoding will stop and output an error code (<0).
|
||||
If the source stream is detected malformed, the function will stop decoding and return a negative result.
|
||||
This function is protected against buffer overflow exploits, including malicious data packets.
|
||||
It never writes outside output buffer, nor reads outside input buffer.
|
||||
*/
|
||||
LZ4LIB_API int LZ4_decompress_safe (const char* source, char* dest, int compressedSize, int maxDecompressedSize);
|
||||
* compressedSize : is the exact complete size of the compressed block.
|
||||
* dstCapacity : is the size of destination buffer (which must be already allocated), presumed an upper bound of decompressed size.
|
||||
* @return : the number of bytes decompressed into destination buffer (necessarily <= dstCapacity)
|
||||
* If destination buffer is not large enough, decoding will stop and output an error code (negative value).
|
||||
* If the source stream is detected malformed, the function will stop decoding and return a negative result.
|
||||
* Note 1 : This function is protected against malicious data packets :
|
||||
* it will never writes outside 'dst' buffer, nor read outside 'source' buffer,
|
||||
* even if the compressed block is maliciously modified to order the decoder to do these actions.
|
||||
* In such case, the decoder stops immediately, and considers the compressed block malformed.
|
||||
* Note 2 : compressedSize and dstCapacity must be provided to the function, the compressed block does not contain them.
|
||||
* The implementation is free to send / store / derive this information in whichever way is most beneficial.
|
||||
* If there is a need for a different format which bundles together both compressed data and its metadata, consider looking at lz4frame.h instead.
|
||||
*/
|
||||
LZ4LIB_API int LZ4_decompress_safe (const char* src, char* dst, int compressedSize, int dstCapacity);
|
||||
|
||||
|
||||
/*-************************************
|
||||
|
|
@ -152,194 +170,389 @@ LZ4LIB_API int LZ4_decompress_safe (const char* source, char* dest, int compress
|
|||
#define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */
|
||||
#define LZ4_COMPRESSBOUND(isize) ((unsigned)(isize) > (unsigned)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
|
||||
|
||||
/*!
|
||||
LZ4_compressBound() :
|
||||
/*! LZ4_compressBound() :
|
||||
Provides the maximum size that LZ4 compression may output in a "worst case" scenario (input data not compressible)
|
||||
This function is primarily useful for memory allocation purposes (destination buffer size).
|
||||
Macro LZ4_COMPRESSBOUND() is also provided for compilation-time evaluation (stack memory allocation for example).
|
||||
Note that LZ4_compress_default() compress faster when dest buffer size is >= LZ4_compressBound(srcSize)
|
||||
Note that LZ4_compress_default() compresses faster when dstCapacity is >= LZ4_compressBound(srcSize)
|
||||
inputSize : max supported value is LZ4_MAX_INPUT_SIZE
|
||||
return : maximum output size in a "worst case" scenario
|
||||
or 0, if input size is too large ( > LZ4_MAX_INPUT_SIZE)
|
||||
or 0, if input size is incorrect (too large or negative)
|
||||
*/
|
||||
LZ4LIB_API int LZ4_compressBound(int inputSize);
|
||||
|
||||
/*!
|
||||
LZ4_compress_fast() :
|
||||
Same as LZ4_compress_default(), but allows to select an "acceleration" factor.
|
||||
/*! LZ4_compress_fast() :
|
||||
Same as LZ4_compress_default(), but allows selection of "acceleration" factor.
|
||||
The larger the acceleration value, the faster the algorithm, but also the lesser the compression.
|
||||
It's a trade-off. It can be fine tuned, with each successive value providing roughly +~3% to speed.
|
||||
An acceleration value of "1" is the same as regular LZ4_compress_default()
|
||||
Values <= 0 will be replaced by ACCELERATION_DEFAULT (see lz4.c), which is 1.
|
||||
Values <= 0 will be replaced by ACCELERATION_DEFAULT (currently == 1, see lz4.c).
|
||||
*/
|
||||
LZ4LIB_API int LZ4_compress_fast (const char* source, char* dest, int sourceSize, int maxDestSize, int acceleration);
|
||||
LZ4LIB_API int LZ4_compress_fast (const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
|
||||
|
||||
|
||||
/*!
|
||||
LZ4_compress_fast_extState() :
|
||||
Same compression function, just using an externally allocated memory space to store compression state.
|
||||
Use LZ4_sizeofState() to know how much memory must be allocated,
|
||||
and allocate it on 8-bytes boundaries (using malloc() typically).
|
||||
Then, provide it as 'void* state' to compression function.
|
||||
*/
|
||||
/*! LZ4_compress_fast_extState() :
|
||||
* Same as LZ4_compress_fast(), using an externally allocated memory space for its state.
|
||||
* Use LZ4_sizeofState() to know how much memory must be allocated,
|
||||
* and allocate it on 8-bytes boundaries (using `malloc()` typically).
|
||||
* Then, provide this buffer as `void* state` to compression function.
|
||||
*/
|
||||
LZ4LIB_API int LZ4_sizeofState(void);
|
||||
LZ4LIB_API int LZ4_compress_fast_extState (void* state, const char* source, char* dest, int inputSize, int maxDestSize, int acceleration);
|
||||
LZ4LIB_API int LZ4_compress_fast_extState (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
|
||||
|
||||
|
||||
/*!
|
||||
LZ4_compress_destSize() :
|
||||
Reverse the logic, by compressing as much data as possible from 'source' buffer
|
||||
into already allocated buffer 'dest' of size 'targetDestSize'.
|
||||
This function either compresses the entire 'source' content into 'dest' if it's large enough,
|
||||
or fill 'dest' buffer completely with as much data as possible from 'source'.
|
||||
*sourceSizePtr : will be modified to indicate how many bytes where read from 'source' to fill 'dest'.
|
||||
New value is necessarily <= old value.
|
||||
return : Nb bytes written into 'dest' (necessarily <= targetDestSize)
|
||||
or 0 if compression fails
|
||||
/*! LZ4_compress_destSize() :
|
||||
* Reverse the logic : compresses as much data as possible from 'src' buffer
|
||||
* into already allocated buffer 'dst', of size >= 'targetDestSize'.
|
||||
* This function either compresses the entire 'src' content into 'dst' if it's large enough,
|
||||
* or fill 'dst' buffer completely with as much data as possible from 'src'.
|
||||
* note: acceleration parameter is fixed to "default".
|
||||
*
|
||||
* *srcSizePtr : will be modified to indicate how many bytes where read from 'src' to fill 'dst'.
|
||||
* New value is necessarily <= input value.
|
||||
* @return : Nb bytes written into 'dst' (necessarily <= targetDestSize)
|
||||
* or 0 if compression fails.
|
||||
*/
|
||||
LZ4LIB_API int LZ4_compress_destSize (const char* source, char* dest, int* sourceSizePtr, int targetDestSize);
|
||||
LZ4LIB_API int LZ4_compress_destSize (const char* src, char* dst, int* srcSizePtr, int targetDstSize);
|
||||
|
||||
|
||||
/*!
|
||||
LZ4_decompress_fast() :
|
||||
originalSize : is the original and therefore uncompressed size
|
||||
return : the number of bytes read from the source buffer (in other words, the compressed size)
|
||||
If the source stream is detected malformed, the function will stop decoding and return a negative result.
|
||||
Destination buffer must be already allocated. Its size must be a minimum of 'originalSize' bytes.
|
||||
note : This function fully respect memory boundaries for properly formed compressed data.
|
||||
It is a bit faster than LZ4_decompress_safe().
|
||||
However, it does not provide any protection against intentionally modified data stream (malicious input).
|
||||
Use this function in trusted environment only (data to decode comes from a trusted source).
|
||||
*/
|
||||
LZ4LIB_API int LZ4_decompress_fast (const char* source, char* dest, int originalSize);
|
||||
|
||||
/*!
|
||||
LZ4_decompress_safe_partial() :
|
||||
This function decompress a compressed block of size 'compressedSize' at position 'source'
|
||||
into destination buffer 'dest' of size 'maxDecompressedSize'.
|
||||
The function tries to stop decompressing operation as soon as 'targetOutputSize' has been reached,
|
||||
reducing decompression time.
|
||||
return : the number of bytes decoded in the destination buffer (necessarily <= maxDecompressedSize)
|
||||
Note : this number can be < 'targetOutputSize' should the compressed block to decode be smaller.
|
||||
Always control how many bytes were decoded.
|
||||
If the source stream is detected malformed, the function will stop decoding and return a negative result.
|
||||
This function never writes outside of output buffer, and never reads outside of input buffer. It is therefore protected against malicious data packets
|
||||
*/
|
||||
LZ4LIB_API int LZ4_decompress_safe_partial (const char* source, char* dest, int compressedSize, int targetOutputSize, int maxDecompressedSize);
|
||||
/*! LZ4_decompress_safe_partial() :
|
||||
* Decompress an LZ4 compressed block, of size 'srcSize' at position 'src',
|
||||
* into destination buffer 'dst' of size 'dstCapacity'.
|
||||
* Up to 'targetOutputSize' bytes will be decoded.
|
||||
* The function stops decoding on reaching this objective,
|
||||
* which can boost performance when only the beginning of a block is required.
|
||||
*
|
||||
* @return : the number of bytes decoded in `dst` (necessarily <= dstCapacity)
|
||||
* If source stream is detected malformed, function returns a negative result.
|
||||
*
|
||||
* Note : @return can be < targetOutputSize, if compressed block contains less data.
|
||||
*
|
||||
* Note 2 : this function features 2 parameters, targetOutputSize and dstCapacity,
|
||||
* and expects targetOutputSize <= dstCapacity.
|
||||
* It effectively stops decoding on reaching targetOutputSize,
|
||||
* so dstCapacity is kind of redundant.
|
||||
* This is because in a previous version of this function,
|
||||
* decoding operation would not "break" a sequence in the middle.
|
||||
* As a consequence, there was no guarantee that decoding would stop at exactly targetOutputSize,
|
||||
* it could write more bytes, though only up to dstCapacity.
|
||||
* Some "margin" used to be required for this operation to work properly.
|
||||
* This is no longer necessary.
|
||||
* The function nonetheless keeps its signature, in an effort to not break API.
|
||||
*/
|
||||
LZ4LIB_API int LZ4_decompress_safe_partial (const char* src, char* dst, int srcSize, int targetOutputSize, int dstCapacity);
|
||||
|
||||
|
||||
/*-*********************************************
|
||||
* Streaming Compression Functions
|
||||
***********************************************/
|
||||
typedef union LZ4_stream_u LZ4_stream_t; /* incomplete type (defined later) */
|
||||
typedef union LZ4_stream_u LZ4_stream_t; /* incomplete type (defined later) */
|
||||
|
||||
/*! LZ4_createStream() and LZ4_freeStream() :
|
||||
* LZ4_createStream() will allocate and initialize an `LZ4_stream_t` structure.
|
||||
* LZ4_freeStream() releases its memory.
|
||||
*/
|
||||
LZ4LIB_API LZ4_stream_t* LZ4_createStream(void);
|
||||
LZ4LIB_API int LZ4_freeStream (LZ4_stream_t* streamPtr);
|
||||
|
||||
/*! LZ4_resetStream() :
|
||||
* An LZ4_stream_t structure can be allocated once and re-used multiple times.
|
||||
* Use this function to start compressing a new stream.
|
||||
/*! LZ4_resetStream_fast() : v1.9.0+
|
||||
* Use this to prepare an LZ4_stream_t for a new chain of dependent blocks
|
||||
* (e.g., LZ4_compress_fast_continue()).
|
||||
*
|
||||
* An LZ4_stream_t must be initialized once before usage.
|
||||
* This is automatically done when created by LZ4_createStream().
|
||||
* However, should the LZ4_stream_t be simply declared on stack (for example),
|
||||
* it's necessary to initialize it first, using LZ4_initStream().
|
||||
*
|
||||
* After init, start any new stream with LZ4_resetStream_fast().
|
||||
* A same LZ4_stream_t can be re-used multiple times consecutively
|
||||
* and compress multiple streams,
|
||||
* provided that it starts each new stream with LZ4_resetStream_fast().
|
||||
*
|
||||
* LZ4_resetStream_fast() is much faster than LZ4_initStream(),
|
||||
* but is not compatible with memory regions containing garbage data.
|
||||
*
|
||||
* Note: it's only useful to call LZ4_resetStream_fast()
|
||||
* in the context of streaming compression.
|
||||
* The *extState* functions perform their own resets.
|
||||
* Invoking LZ4_resetStream_fast() before is redundant, and even counterproductive.
|
||||
*/
|
||||
LZ4LIB_API void LZ4_resetStream (LZ4_stream_t* streamPtr);
|
||||
LZ4LIB_API void LZ4_resetStream_fast (LZ4_stream_t* streamPtr);
|
||||
|
||||
/*! LZ4_loadDict() :
|
||||
* Use this function to load a static dictionary into LZ4_stream_t.
|
||||
* Any previous data will be forgotten, only 'dictionary' will remain in memory.
|
||||
* Use this function to reference a static dictionary into LZ4_stream_t.
|
||||
* The dictionary must remain available during compression.
|
||||
* LZ4_loadDict() triggers a reset, so any previous data will be forgotten.
|
||||
* The same dictionary will have to be loaded on decompression side for successful decoding.
|
||||
* Dictionary are useful for better compression of small data (KB range).
|
||||
* While LZ4 accept any input as dictionary,
|
||||
* results are generally better when using Zstandard's Dictionary Builder.
|
||||
* Loading a size of 0 is allowed, and is the same as reset.
|
||||
* @return : dictionary size, in bytes (necessarily <= 64 KB)
|
||||
* @return : loaded dictionary size, in bytes (necessarily <= 64 KB)
|
||||
*/
|
||||
LZ4LIB_API int LZ4_loadDict (LZ4_stream_t* streamPtr, const char* dictionary, int dictSize);
|
||||
|
||||
/*! LZ4_compress_fast_continue() :
|
||||
* Compress content into 'src' using data from previously compressed blocks, improving compression ratio.
|
||||
* 'dst' buffer must be already allocated.
|
||||
* Compress 'src' content using data from previously compressed blocks, for better compression ratio.
|
||||
* 'dst' buffer must be already allocated.
|
||||
* If dstCapacity >= LZ4_compressBound(srcSize), compression is guaranteed to succeed, and runs faster.
|
||||
*
|
||||
* Important : Up to 64KB of previously compressed data is assumed to remain present and unmodified in memory !
|
||||
* Special 1 : If input buffer is a double-buffer, it can have any size, including < 64 KB.
|
||||
* Special 2 : If input buffer is a ring-buffer, it can have any size, including < 64 KB.
|
||||
*
|
||||
* @return : size of compressed block
|
||||
* or 0 if there is an error (typically, compressed data cannot fit into 'dst')
|
||||
* After an error, the stream status is invalid, it can only be reset or freed.
|
||||
* or 0 if there is an error (typically, cannot fit into 'dst').
|
||||
*
|
||||
* Note 1 : Each invocation to LZ4_compress_fast_continue() generates a new block.
|
||||
* Each block has precise boundaries.
|
||||
* Each block must be decompressed separately, calling LZ4_decompress_*() with relevant metadata.
|
||||
* It's not possible to append blocks together and expect a single invocation of LZ4_decompress_*() to decompress them together.
|
||||
*
|
||||
* Note 2 : The previous 64KB of source data is __assumed__ to remain present, unmodified, at same address in memory !
|
||||
*
|
||||
* Note 3 : When input is structured as a double-buffer, each buffer can have any size, including < 64 KB.
|
||||
* Make sure that buffers are separated, by at least one byte.
|
||||
* This construction ensures that each block only depends on previous block.
|
||||
*
|
||||
* Note 4 : If input buffer is a ring-buffer, it can have any size, including < 64 KB.
|
||||
*
|
||||
* Note 5 : After an error, the stream status is undefined (invalid), it can only be reset or freed.
|
||||
*/
|
||||
LZ4LIB_API int LZ4_compress_fast_continue (LZ4_stream_t* streamPtr, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
|
||||
|
||||
/*! LZ4_saveDict() :
|
||||
* If previously compressed data block is not guaranteed to remain available at its current memory location,
|
||||
* If last 64KB data cannot be guaranteed to remain available at its current memory location,
|
||||
* save it into a safer place (char* safeBuffer).
|
||||
* Note : it's not necessary to call LZ4_loadDict() after LZ4_saveDict(), dictionary is immediately usable.
|
||||
* @return : saved dictionary size in bytes (necessarily <= dictSize), or 0 if error.
|
||||
* This is schematically equivalent to a memcpy() followed by LZ4_loadDict(),
|
||||
* but is much faster, because LZ4_saveDict() doesn't need to rebuild tables.
|
||||
* @return : saved dictionary size in bytes (necessarily <= maxDictSize), or 0 if error.
|
||||
*/
|
||||
LZ4LIB_API int LZ4_saveDict (LZ4_stream_t* streamPtr, char* safeBuffer, int dictSize);
|
||||
LZ4LIB_API int LZ4_saveDict (LZ4_stream_t* streamPtr, char* safeBuffer, int maxDictSize);
|
||||
|
||||
|
||||
/*-**********************************************
|
||||
* Streaming Decompression Functions
|
||||
* Bufferless synchronous API
|
||||
************************************************/
|
||||
typedef union LZ4_streamDecode_u LZ4_streamDecode_t; /* incomplete type (defined later) */
|
||||
typedef union LZ4_streamDecode_u LZ4_streamDecode_t; /* tracking context */
|
||||
|
||||
/*! LZ4_createStreamDecode() and LZ4_freeStreamDecode() :
|
||||
* creation / destruction of streaming decompression tracking structure.
|
||||
* A tracking structure can be re-used multiple times sequentially. */
|
||||
* creation / destruction of streaming decompression tracking context.
|
||||
* A tracking context can be re-used multiple times.
|
||||
*/
|
||||
LZ4LIB_API LZ4_streamDecode_t* LZ4_createStreamDecode(void);
|
||||
LZ4LIB_API int LZ4_freeStreamDecode (LZ4_streamDecode_t* LZ4_stream);
|
||||
|
||||
/*! LZ4_setStreamDecode() :
|
||||
* An LZ4_streamDecode_t structure can be allocated once and re-used multiple times.
|
||||
* An LZ4_streamDecode_t context can be allocated once and re-used multiple times.
|
||||
* Use this function to start decompression of a new stream of blocks.
|
||||
* A dictionary can optionnally be set. Use NULL or size 0 for a simple reset order.
|
||||
* A dictionary can optionally be set. Use NULL or size 0 for a reset order.
|
||||
* Dictionary is presumed stable : it must remain accessible and unmodified during next decompression.
|
||||
* @return : 1 if OK, 0 if error
|
||||
*/
|
||||
LZ4LIB_API int LZ4_setStreamDecode (LZ4_streamDecode_t* LZ4_streamDecode, const char* dictionary, int dictSize);
|
||||
|
||||
/*! LZ4_decoderRingBufferSize() : v1.8.2+
|
||||
* Note : in a ring buffer scenario (optional),
|
||||
* blocks are presumed decompressed next to each other
|
||||
* up to the moment there is not enough remaining space for next block (remainingSize < maxBlockSize),
|
||||
* at which stage it resumes from beginning of ring buffer.
|
||||
* When setting such a ring buffer for streaming decompression,
|
||||
* provides the minimum size of this ring buffer
|
||||
* to be compatible with any source respecting maxBlockSize condition.
|
||||
* @return : minimum ring buffer size,
|
||||
* or 0 if there is an error (invalid maxBlockSize).
|
||||
*/
|
||||
LZ4LIB_API int LZ4_decoderRingBufferSize(int maxBlockSize);
|
||||
#define LZ4_DECODER_RING_BUFFER_SIZE(maxBlockSize) (65536 + 14 + (maxBlockSize)) /* for static allocation; maxBlockSize presumed valid */
|
||||
|
||||
/*! LZ4_decompress_*_continue() :
|
||||
* These decoding functions allow decompression of consecutive blocks in "streaming" mode.
|
||||
* A block is an unsplittable entity, it must be presented entirely to a decompression function.
|
||||
* Decompression functions only accept one block at a time.
|
||||
* Previously decoded blocks *must* remain available at the memory position where they were decoded (up to 64 KB).
|
||||
* Decompression functions only accepts one block at a time.
|
||||
* The last 64KB of previously decoded data *must* remain available and unmodified at the memory position where they were decoded.
|
||||
* If less than 64KB of data has been decoded, all the data must be present.
|
||||
*
|
||||
* Special : if application sets a ring buffer for decompression, it must respect one of the following conditions :
|
||||
* - Exactly same size as encoding buffer, with same update rule (block boundaries at same positions)
|
||||
* In which case, the decoding & encoding ring buffer can have any size, including very small ones ( < 64 KB).
|
||||
* - Larger than encoding buffer, by a minimum of maxBlockSize more bytes.
|
||||
* maxBlockSize is implementation dependent. It's the maximum size of any single block.
|
||||
* Special : if decompression side sets a ring buffer, it must respect one of the following conditions :
|
||||
* - Decompression buffer size is _at least_ LZ4_decoderRingBufferSize(maxBlockSize).
|
||||
* maxBlockSize is the maximum size of any single block. It can have any value > 16 bytes.
|
||||
* In which case, encoding and decoding buffers do not need to be synchronized.
|
||||
* Actually, data can be produced by any source compliant with LZ4 format specification, and respecting maxBlockSize.
|
||||
* - Synchronized mode :
|
||||
* Decompression buffer size is _exactly_ the same as compression buffer size,
|
||||
* and follows exactly same update rule (block boundaries at same positions),
|
||||
* and decoding function is provided with exact decompressed size of each block (exception for last block of the stream),
|
||||
* _then_ decoding & encoding ring buffer can have any size, including small ones ( < 64 KB).
|
||||
* - Decompression buffer is larger than encoding buffer, by a minimum of maxBlockSize more bytes.
|
||||
* In which case, encoding and decoding buffers do not need to be synchronized,
|
||||
* and encoding ring buffer can have any size, including small ones ( < 64 KB).
|
||||
* - _At least_ 64 KB + 8 bytes + maxBlockSize.
|
||||
* In which case, encoding and decoding buffers do not need to be synchronized,
|
||||
* and encoding ring buffer can have any size, including larger than decoding buffer.
|
||||
* Whenever these conditions are not possible, save the last 64KB of decoded data into a safe buffer,
|
||||
* and indicate where it is saved using LZ4_setStreamDecode() before decompressing next block.
|
||||
*
|
||||
* Whenever these conditions are not possible,
|
||||
* save the last 64KB of decoded data into a safe buffer where it can't be modified during decompression,
|
||||
* then indicate where this data is saved using LZ4_setStreamDecode(), before decompressing next block.
|
||||
*/
|
||||
LZ4LIB_API int LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int compressedSize, int maxDecompressedSize);
|
||||
LZ4LIB_API int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int originalSize);
|
||||
LZ4LIB_API int LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* src, char* dst, int srcSize, int dstCapacity);
|
||||
|
||||
|
||||
/*! LZ4_decompress_*_usingDict() :
|
||||
* These decoding functions work the same as
|
||||
* a combination of LZ4_setStreamDecode() followed by LZ4_decompress_*_continue()
|
||||
* They are stand-alone, and don't need an LZ4_streamDecode_t structure.
|
||||
* Dictionary is presumed stable : it must remain accessible and unmodified during decompression.
|
||||
* Performance tip : Decompression speed can be substantially increased
|
||||
* when dst == dictStart + dictSize.
|
||||
*/
|
||||
LZ4LIB_API int LZ4_decompress_safe_usingDict (const char* source, char* dest, int compressedSize, int maxDecompressedSize, const char* dictStart, int dictSize);
|
||||
LZ4LIB_API int LZ4_decompress_fast_usingDict (const char* source, char* dest, int originalSize, const char* dictStart, int dictSize);
|
||||
LZ4LIB_API int LZ4_decompress_safe_usingDict (const char* src, char* dst, int srcSize, int dstCapcity, const char* dictStart, int dictSize);
|
||||
|
||||
#endif /* LZ4_H_2983827168210 */
|
||||
|
||||
|
||||
/*^**********************************************
|
||||
/*^*************************************
|
||||
* !!!!!! STATIC LINKING ONLY !!!!!!
|
||||
***********************************************/
|
||||
/*-************************************
|
||||
* Private definitions
|
||||
**************************************
|
||||
* Do not use these definitions.
|
||||
* They are exposed to allow static allocation of `LZ4_stream_t` and `LZ4_streamDecode_t`.
|
||||
* Using these definitions will expose code to API and/or ABI break in future versions of the library.
|
||||
**************************************/
|
||||
***************************************/
|
||||
|
||||
/*-****************************************************************************
|
||||
* Experimental section
|
||||
*
|
||||
* Symbols declared in this section must be considered unstable. Their
|
||||
* signatures or semantics may change, or they may be removed altogether in the
|
||||
* future. They are therefore only safe to depend on when the caller is
|
||||
* statically linked against the library.
|
||||
*
|
||||
* To protect against unsafe usage, not only are the declarations guarded,
|
||||
* the definitions are hidden by default
|
||||
* when building LZ4 as a shared/dynamic library.
|
||||
*
|
||||
* In order to access these declarations,
|
||||
* define LZ4_STATIC_LINKING_ONLY in your application
|
||||
* before including LZ4's headers.
|
||||
*
|
||||
* In order to make their implementations accessible dynamically, you must
|
||||
* define LZ4_PUBLISH_STATIC_FUNCTIONS when building the LZ4 library.
|
||||
******************************************************************************/
|
||||
|
||||
#ifdef LZ4_STATIC_LINKING_ONLY
|
||||
|
||||
#ifndef LZ4_STATIC_3504398509
|
||||
#define LZ4_STATIC_3504398509
|
||||
|
||||
#ifdef LZ4_PUBLISH_STATIC_FUNCTIONS
|
||||
#define LZ4LIB_STATIC_API LZ4LIB_API
|
||||
#else
|
||||
#define LZ4LIB_STATIC_API
|
||||
#endif
|
||||
|
||||
|
||||
/*! LZ4_compress_fast_extState_fastReset() :
|
||||
* A variant of LZ4_compress_fast_extState().
|
||||
*
|
||||
* Using this variant avoids an expensive initialization step.
|
||||
* It is only safe to call if the state buffer is known to be correctly initialized already
|
||||
* (see above comment on LZ4_resetStream_fast() for a definition of "correctly initialized").
|
||||
* From a high level, the difference is that
|
||||
* this function initializes the provided state with a call to something like LZ4_resetStream_fast()
|
||||
* while LZ4_compress_fast_extState() starts with a call to LZ4_resetStream().
|
||||
*/
|
||||
LZ4LIB_STATIC_API int LZ4_compress_fast_extState_fastReset (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
|
||||
|
||||
/*! LZ4_attach_dictionary() :
|
||||
* This is an experimental API that allows
|
||||
* efficient use of a static dictionary many times.
|
||||
*
|
||||
* Rather than re-loading the dictionary buffer into a working context before
|
||||
* each compression, or copying a pre-loaded dictionary's LZ4_stream_t into a
|
||||
* working LZ4_stream_t, this function introduces a no-copy setup mechanism,
|
||||
* in which the working stream references the dictionary stream in-place.
|
||||
*
|
||||
* Several assumptions are made about the state of the dictionary stream.
|
||||
* Currently, only streams which have been prepared by LZ4_loadDict() should
|
||||
* be expected to work.
|
||||
*
|
||||
* Alternatively, the provided dictionaryStream may be NULL,
|
||||
* in which case any existing dictionary stream is unset.
|
||||
*
|
||||
* If a dictionary is provided, it replaces any pre-existing stream history.
|
||||
* The dictionary contents are the only history that can be referenced and
|
||||
* logically immediately precede the data compressed in the first subsequent
|
||||
* compression call.
|
||||
*
|
||||
* The dictionary will only remain attached to the working stream through the
|
||||
* first compression call, at the end of which it is cleared. The dictionary
|
||||
* stream (and source buffer) must remain in-place / accessible / unchanged
|
||||
* through the completion of the first compression call on the stream.
|
||||
*/
|
||||
LZ4LIB_STATIC_API void LZ4_attach_dictionary(LZ4_stream_t* workingStream, const LZ4_stream_t* dictionaryStream);
|
||||
|
||||
|
||||
/*! In-place compression and decompression
|
||||
*
|
||||
* It's possible to have input and output sharing the same buffer,
|
||||
* for highly contrained memory environments.
|
||||
* In both cases, it requires input to lay at the end of the buffer,
|
||||
* and decompression to start at beginning of the buffer.
|
||||
* Buffer size must feature some margin, hence be larger than final size.
|
||||
*
|
||||
* |<------------------------buffer--------------------------------->|
|
||||
* |<-----------compressed data--------->|
|
||||
* |<-----------decompressed size------------------>|
|
||||
* |<----margin---->|
|
||||
*
|
||||
* This technique is more useful for decompression,
|
||||
* since decompressed size is typically larger,
|
||||
* and margin is short.
|
||||
*
|
||||
* In-place decompression will work inside any buffer
|
||||
* which size is >= LZ4_DECOMPRESS_INPLACE_BUFFER_SIZE(decompressedSize).
|
||||
* This presumes that decompressedSize > compressedSize.
|
||||
* Otherwise, it means compression actually expanded data,
|
||||
* and it would be more efficient to store such data with a flag indicating it's not compressed.
|
||||
* This can happen when data is not compressible (already compressed, or encrypted).
|
||||
*
|
||||
* For in-place compression, margin is larger, as it must be able to cope with both
|
||||
* history preservation, requiring input data to remain unmodified up to LZ4_DISTANCE_MAX,
|
||||
* and data expansion, which can happen when input is not compressible.
|
||||
* As a consequence, buffer size requirements are much higher,
|
||||
* and memory savings offered by in-place compression are more limited.
|
||||
*
|
||||
* There are ways to limit this cost for compression :
|
||||
* - Reduce history size, by modifying LZ4_DISTANCE_MAX.
|
||||
* Note that it is a compile-time constant, so all compressions will apply this limit.
|
||||
* Lower values will reduce compression ratio, except when input_size < LZ4_DISTANCE_MAX,
|
||||
* so it's a reasonable trick when inputs are known to be small.
|
||||
* - Require the compressor to deliver a "maximum compressed size".
|
||||
* This is the `dstCapacity` parameter in `LZ4_compress*()`.
|
||||
* When this size is < LZ4_COMPRESSBOUND(inputSize), then compression can fail,
|
||||
* in which case, the return code will be 0 (zero).
|
||||
* The caller must be ready for these cases to happen,
|
||||
* and typically design a backup scheme to send data uncompressed.
|
||||
* The combination of both techniques can significantly reduce
|
||||
* the amount of margin required for in-place compression.
|
||||
*
|
||||
* In-place compression can work in any buffer
|
||||
* which size is >= (maxCompressedSize)
|
||||
* with maxCompressedSize == LZ4_COMPRESSBOUND(srcSize) for guaranteed compression success.
|
||||
* LZ4_COMPRESS_INPLACE_BUFFER_SIZE() depends on both maxCompressedSize and LZ4_DISTANCE_MAX,
|
||||
* so it's possible to reduce memory requirements by playing with them.
|
||||
*/
|
||||
|
||||
#define LZ4_DECOMPRESS_INPLACE_MARGIN(compressedSize) (((compressedSize) >> 8) + 32)
|
||||
#define LZ4_DECOMPRESS_INPLACE_BUFFER_SIZE(decompressedSize) ((decompressedSize) + LZ4_DECOMPRESS_INPLACE_MARGIN(decompressedSize)) /**< note: presumes that compressedSize < decompressedSize. note2: margin is overestimated a bit, since it could use compressedSize instead */
|
||||
|
||||
#ifndef LZ4_DISTANCE_MAX /* history window size; can be user-defined at compile time */
|
||||
# define LZ4_DISTANCE_MAX 65535 /* set to maximum value by default */
|
||||
#endif
|
||||
|
||||
#define LZ4_COMPRESS_INPLACE_MARGIN (LZ4_DISTANCE_MAX + 32) /* LZ4_DISTANCE_MAX can be safely replaced by srcSize when it's smaller */
|
||||
#define LZ4_COMPRESS_INPLACE_BUFFER_SIZE(maxCompressedSize) ((maxCompressedSize) + LZ4_COMPRESS_INPLACE_MARGIN) /**< maxCompressedSize is generally LZ4_COMPRESSBOUND(inputSize), but can be set to any lower value, with the risk that compression can fail (return code 0(zero)) */
|
||||
|
||||
#endif /* LZ4_STATIC_3504398509 */
|
||||
#endif /* LZ4_STATIC_LINKING_ONLY */
|
||||
|
||||
|
||||
|
||||
#ifndef LZ4_H_98237428734687
|
||||
#define LZ4_H_98237428734687
|
||||
|
||||
/*-************************************************************
|
||||
* PRIVATE DEFINITIONS
|
||||
**************************************************************
|
||||
* Do not use these definitions directly.
|
||||
* They are only exposed to allow static allocation of `LZ4_stream_t` and `LZ4_streamDecode_t`.
|
||||
* Accessing members will expose code to API and/or ABI break in future versions of the library.
|
||||
**************************************************************/
|
||||
#define LZ4_HASHLOG (LZ4_MEMORY_USAGE-2)
|
||||
#define LZ4_HASHTABLESIZE (1 << LZ4_MEMORY_USAGE)
|
||||
#define LZ4_HASH_SIZE_U32 (1 << LZ4_HASHLOG) /* required as macro for static allocation */
|
||||
|
|
@ -347,14 +560,16 @@ LZ4LIB_API int LZ4_decompress_fast_usingDict (const char* source, char* dest, in
|
|||
#if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
typedef struct LZ4_stream_t_internal LZ4_stream_t_internal;
|
||||
struct LZ4_stream_t_internal {
|
||||
uint32_t hashTable[LZ4_HASH_SIZE_U32];
|
||||
uint32_t currentOffset;
|
||||
uint32_t initCheck;
|
||||
uint16_t dirty;
|
||||
uint16_t tableType;
|
||||
const uint8_t* dictionary;
|
||||
uint8_t* bufferStart; /* obsolete, used for slideInputBuffer */
|
||||
const LZ4_stream_t_internal* dictCtx;
|
||||
uint32_t dictSize;
|
||||
} LZ4_stream_t_internal;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
const uint8_t* externalDict;
|
||||
|
|
@ -365,49 +580,67 @@ typedef struct {
|
|||
|
||||
#else
|
||||
|
||||
typedef struct {
|
||||
typedef struct LZ4_stream_t_internal LZ4_stream_t_internal;
|
||||
struct LZ4_stream_t_internal {
|
||||
unsigned int hashTable[LZ4_HASH_SIZE_U32];
|
||||
unsigned int currentOffset;
|
||||
unsigned int initCheck;
|
||||
unsigned short dirty;
|
||||
unsigned short tableType;
|
||||
const unsigned char* dictionary;
|
||||
unsigned char* bufferStart; /* obsolete, used for slideInputBuffer */
|
||||
const LZ4_stream_t_internal* dictCtx;
|
||||
unsigned int dictSize;
|
||||
} LZ4_stream_t_internal;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
const unsigned char* externalDict;
|
||||
size_t extDictSize;
|
||||
const unsigned char* prefixEnd;
|
||||
size_t extDictSize;
|
||||
size_t prefixSize;
|
||||
} LZ4_streamDecode_t_internal;
|
||||
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* LZ4_stream_t :
|
||||
* information structure to track an LZ4 stream.
|
||||
* init this structure before first use.
|
||||
* note : only use in association with static linking !
|
||||
* this definition is not API/ABI safe,
|
||||
* it may change in a future version !
|
||||
/*! LZ4_stream_t :
|
||||
* information structure to track an LZ4 stream.
|
||||
* LZ4_stream_t can also be created using LZ4_createStream(), which is recommended.
|
||||
* The structure definition can be convenient for static allocation
|
||||
* (on stack, or as part of larger structure).
|
||||
* Init this structure with LZ4_initStream() before first use.
|
||||
* note : only use this definition in association with static linking !
|
||||
* this definition is not API/ABI safe, and may change in a future version.
|
||||
*/
|
||||
#define LZ4_STREAMSIZE_U64 ((1 << (LZ4_MEMORY_USAGE-3)) + 4)
|
||||
#define LZ4_STREAMSIZE_U64 ((1 << (LZ4_MEMORY_USAGE-3)) + 4 + ((sizeof(void*)==16) ? 4 : 0) /*AS-400*/ )
|
||||
#define LZ4_STREAMSIZE (LZ4_STREAMSIZE_U64 * sizeof(unsigned long long))
|
||||
union LZ4_stream_u {
|
||||
unsigned long long table[LZ4_STREAMSIZE_U64];
|
||||
LZ4_stream_t_internal internal_donotuse;
|
||||
} ; /* previously typedef'd to LZ4_stream_t */
|
||||
|
||||
|
||||
/*!
|
||||
* LZ4_streamDecode_t :
|
||||
* information structure to track an LZ4 stream during decompression.
|
||||
* init this structure using LZ4_setStreamDecode (or memset()) before first use
|
||||
* note : only use in association with static linking !
|
||||
* this definition is not API/ABI safe,
|
||||
* and may change in a future version !
|
||||
/*! LZ4_initStream() : v1.9.0+
|
||||
* An LZ4_stream_t structure must be initialized at least once.
|
||||
* This is automatically done when invoking LZ4_createStream(),
|
||||
* but it's not when the structure is simply declared on stack (for example).
|
||||
*
|
||||
* Use LZ4_initStream() to properly initialize a newly declared LZ4_stream_t.
|
||||
* It can also initialize any arbitrary buffer of sufficient size,
|
||||
* and will @return a pointer of proper type upon initialization.
|
||||
*
|
||||
* Note : initialization fails if size and alignment conditions are not respected.
|
||||
* In which case, the function will @return NULL.
|
||||
* Note2: An LZ4_stream_t structure guarantees correct alignment and size.
|
||||
* Note3: Before v1.9.0, use LZ4_resetStream() instead
|
||||
*/
|
||||
#define LZ4_STREAMDECODESIZE_U64 4
|
||||
LZ4LIB_API LZ4_stream_t* LZ4_initStream (void* buffer, size_t size);
|
||||
|
||||
|
||||
/*! LZ4_streamDecode_t :
|
||||
* information structure to track an LZ4 stream during decompression.
|
||||
* init this structure using LZ4_setStreamDecode() before first use.
|
||||
* note : only use in association with static linking !
|
||||
* this definition is not API/ABI safe,
|
||||
* and may change in a future version !
|
||||
*/
|
||||
#define LZ4_STREAMDECODESIZE_U64 (4 + ((sizeof(void*)==16) ? 2 : 0) /*AS-400*/ )
|
||||
#define LZ4_STREAMDECODESIZE (LZ4_STREAMDECODESIZE_U64 * sizeof(unsigned long long))
|
||||
union LZ4_streamDecode_u {
|
||||
unsigned long long table[LZ4_STREAMDECODESIZE_U64];
|
||||
|
|
@ -415,25 +648,29 @@ union LZ4_streamDecode_u {
|
|||
} ; /* previously typedef'd to LZ4_streamDecode_t */
|
||||
|
||||
|
||||
|
||||
/*-************************************
|
||||
* Obsolete Functions
|
||||
**************************************/
|
||||
|
||||
/*! Deprecation warnings
|
||||
Should deprecation warnings be a problem,
|
||||
it is generally possible to disable them,
|
||||
typically with -Wno-deprecated-declarations for gcc
|
||||
or _CRT_SECURE_NO_WARNINGS in Visual.
|
||||
Otherwise, it's also possible to define LZ4_DISABLE_DEPRECATE_WARNINGS */
|
||||
*
|
||||
* Deprecated functions make the compiler generate a warning when invoked.
|
||||
* This is meant to invite users to update their source code.
|
||||
* Should deprecation warnings be a problem, it is generally possible to disable them,
|
||||
* typically with -Wno-deprecated-declarations for gcc
|
||||
* or _CRT_SECURE_NO_WARNINGS in Visual.
|
||||
*
|
||||
* Another method is to define LZ4_DISABLE_DEPRECATE_WARNINGS
|
||||
* before including the header file.
|
||||
*/
|
||||
#ifdef LZ4_DISABLE_DEPRECATE_WARNINGS
|
||||
# define LZ4_DEPRECATED(message) /* disable deprecation warnings */
|
||||
#else
|
||||
# define LZ4_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
|
||||
# if defined(__clang__) /* clang doesn't handle mixed C++11 and CNU attributes */
|
||||
# define LZ4_DEPRECATED(message) __attribute__((deprecated(message)))
|
||||
# elif defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */
|
||||
# if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */
|
||||
# define LZ4_DEPRECATED(message) [[deprecated(message)]]
|
||||
# elif (LZ4_GCC_VERSION >= 405)
|
||||
# elif (LZ4_GCC_VERSION >= 405) || defined(__clang__)
|
||||
# define LZ4_DEPRECATED(message) __attribute__((deprecated(message)))
|
||||
# elif (LZ4_GCC_VERSION >= 301)
|
||||
# define LZ4_DEPRECATED(message) __attribute__((deprecated))
|
||||
|
|
@ -446,28 +683,80 @@ union LZ4_streamDecode_u {
|
|||
#endif /* LZ4_DISABLE_DEPRECATE_WARNINGS */
|
||||
|
||||
/* Obsolete compression functions */
|
||||
LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_default() instead") int LZ4_compress (const char* source, char* dest, int sourceSize);
|
||||
LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_default() instead") int LZ4_compress_limitedOutput (const char* source, char* dest, int sourceSize, int maxOutputSize);
|
||||
LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize);
|
||||
LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
|
||||
LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") int LZ4_compress_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize);
|
||||
LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
|
||||
LZ4_DEPRECATED("use LZ4_compress_default() instead") LZ4LIB_API int LZ4_compress (const char* src, char* dest, int srcSize);
|
||||
LZ4_DEPRECATED("use LZ4_compress_default() instead") LZ4LIB_API int LZ4_compress_limitedOutput (const char* src, char* dest, int srcSize, int maxOutputSize);
|
||||
LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") LZ4LIB_API int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize);
|
||||
LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") LZ4LIB_API int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
|
||||
LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") LZ4LIB_API int LZ4_compress_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize);
|
||||
LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") LZ4LIB_API int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
|
||||
|
||||
/* Obsolete decompression functions */
|
||||
LZ4LIB_API LZ4_DEPRECATED("use LZ4_decompress_fast() instead") int LZ4_uncompress (const char* source, char* dest, int outputSize);
|
||||
LZ4LIB_API LZ4_DEPRECATED("use LZ4_decompress_safe() instead") int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize);
|
||||
LZ4_DEPRECATED("use LZ4_decompress_fast() instead") LZ4LIB_API int LZ4_uncompress (const char* source, char* dest, int outputSize);
|
||||
LZ4_DEPRECATED("use LZ4_decompress_safe() instead") LZ4LIB_API int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize);
|
||||
|
||||
/* Obsolete streaming functions; use new streaming interface whenever possible */
|
||||
LZ4LIB_API LZ4_DEPRECATED("use LZ4_createStream() instead") void* LZ4_create (char* inputBuffer);
|
||||
LZ4LIB_API LZ4_DEPRECATED("use LZ4_createStream() instead") int LZ4_sizeofStreamState(void);
|
||||
LZ4LIB_API LZ4_DEPRECATED("use LZ4_resetStream() instead") int LZ4_resetStreamState(void* state, char* inputBuffer);
|
||||
LZ4LIB_API LZ4_DEPRECATED("use LZ4_saveDict() instead") char* LZ4_slideInputBuffer (void* state);
|
||||
/* Obsolete streaming functions; degraded functionality; do not use!
|
||||
*
|
||||
* In order to perform streaming compression, these functions depended on data
|
||||
* that is no longer tracked in the state. They have been preserved as well as
|
||||
* possible: using them will still produce a correct output. However, they don't
|
||||
* actually retain any history between compression calls. The compression ratio
|
||||
* achieved will therefore be no better than compressing each chunk
|
||||
* independently.
|
||||
*/
|
||||
LZ4_DEPRECATED("Use LZ4_createStream() instead") LZ4LIB_API void* LZ4_create (char* inputBuffer);
|
||||
LZ4_DEPRECATED("Use LZ4_createStream() instead") LZ4LIB_API int LZ4_sizeofStreamState(void);
|
||||
LZ4_DEPRECATED("Use LZ4_resetStream() instead") LZ4LIB_API int LZ4_resetStreamState(void* state, char* inputBuffer);
|
||||
LZ4_DEPRECATED("Use LZ4_saveDict() instead") LZ4LIB_API char* LZ4_slideInputBuffer (void* state);
|
||||
|
||||
/* Obsolete streaming decoding functions */
|
||||
LZ4LIB_API LZ4_DEPRECATED("use LZ4_decompress_safe_usingDict() instead") int LZ4_decompress_safe_withPrefix64k (const char* src, char* dst, int compressedSize, int maxDstSize);
|
||||
LZ4LIB_API LZ4_DEPRECATED("use LZ4_decompress_fast_usingDict() instead") int LZ4_decompress_fast_withPrefix64k (const char* src, char* dst, int originalSize);
|
||||
LZ4_DEPRECATED("use LZ4_decompress_safe_usingDict() instead") LZ4LIB_API int LZ4_decompress_safe_withPrefix64k (const char* src, char* dst, int compressedSize, int maxDstSize);
|
||||
LZ4_DEPRECATED("use LZ4_decompress_fast_usingDict() instead") LZ4LIB_API int LZ4_decompress_fast_withPrefix64k (const char* src, char* dst, int originalSize);
|
||||
|
||||
#endif /* LZ4_H_2983827168210 */
|
||||
/*! LZ4_decompress_fast() : **unsafe!**
|
||||
* These functions used to be faster than LZ4_decompress_safe(),
|
||||
* but it has changed, and they are now slower than LZ4_decompress_safe().
|
||||
* This is because LZ4_decompress_fast() doesn't know the input size,
|
||||
* and therefore must progress more cautiously in the input buffer to not read beyond the end of block.
|
||||
* On top of that `LZ4_decompress_fast()` is not protected vs malformed or malicious inputs, making it a security liability.
|
||||
* As a consequence, LZ4_decompress_fast() is strongly discouraged, and deprecated.
|
||||
*
|
||||
* The last remaining LZ4_decompress_fast() specificity is that
|
||||
* it can decompress a block without knowing its compressed size.
|
||||
* Such functionality could be achieved in a more secure manner,
|
||||
* by also providing the maximum size of input buffer,
|
||||
* but it would require new prototypes, and adaptation of the implementation to this new use case.
|
||||
*
|
||||
* Parameters:
|
||||
* originalSize : is the uncompressed size to regenerate.
|
||||
* `dst` must be already allocated, its size must be >= 'originalSize' bytes.
|
||||
* @return : number of bytes read from source buffer (== compressed size).
|
||||
* The function expects to finish at block's end exactly.
|
||||
* If the source stream is detected malformed, the function stops decoding and returns a negative result.
|
||||
* note : LZ4_decompress_fast*() requires originalSize. Thanks to this information, it never writes past the output buffer.
|
||||
* However, since it doesn't know its 'src' size, it may read an unknown amount of input, past input buffer bounds.
|
||||
* Also, since match offsets are not validated, match reads from 'src' may underflow too.
|
||||
* These issues never happen if input (compressed) data is correct.
|
||||
* But they may happen if input data is invalid (error or intentional tampering).
|
||||
* As a consequence, use these functions in trusted environments with trusted data **only**.
|
||||
*/
|
||||
|
||||
LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe() instead")
|
||||
LZ4LIB_API int LZ4_decompress_fast (const char* src, char* dst, int originalSize);
|
||||
LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe_continue() instead")
|
||||
LZ4LIB_API int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* src, char* dst, int originalSize);
|
||||
LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe_usingDict() instead")
|
||||
LZ4LIB_API int LZ4_decompress_fast_usingDict (const char* src, char* dst, int originalSize, const char* dictStart, int dictSize);
|
||||
|
||||
/*! LZ4_resetStream() :
|
||||
* An LZ4_stream_t structure must be initialized at least once.
|
||||
* This is done with LZ4_initStream(), or LZ4_resetStream().
|
||||
* Consider switching to LZ4_initStream(),
|
||||
* invoking LZ4_resetStream() will trigger deprecation warnings in the future.
|
||||
*/
|
||||
LZ4LIB_API void LZ4_resetStream (LZ4_stream_t* streamPtr);
|
||||
|
||||
|
||||
#endif /* LZ4_H_98237428734687 */
|
||||
|
||||
|
||||
#if defined (__cplusplus)
|
||||
|
|
|
|||
|
|
@ -1,169 +0,0 @@
|
|||
# CMake build for libtiff
|
||||
#
|
||||
# Copyright © 2015 Open Microscopy Environment / University of Dundee
|
||||
# Written by Roger Leigh <rleigh@codelibre.net>
|
||||
#
|
||||
# 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.
|
||||
|
||||
# Generate headers
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tif_config.h.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/tif_config.h
|
||||
@ONLY)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tiffconf.h.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/tiffconf.h
|
||||
@ONLY)
|
||||
|
||||
extra_dist(
|
||||
SConstruct
|
||||
tif_config.h-vms
|
||||
tif_config.vc.h
|
||||
tif_config.wince.h
|
||||
tiffconf.vc.h
|
||||
tiffconf.wince.h
|
||||
libtiff.def
|
||||
libtiff.map
|
||||
libtiffxx.map)
|
||||
|
||||
set(tiff_HEADERS
|
||||
tiff.h
|
||||
tiffio.h
|
||||
tiffvers.h)
|
||||
|
||||
set(tiff_noinst_HEADERS
|
||||
t4.h
|
||||
tif_dir.h
|
||||
tif_predict.h
|
||||
tiffiop.h
|
||||
uvcode.h)
|
||||
|
||||
set(nodist_tiff_HEADERS
|
||||
${CMAKE_CURRENT_BINARY_DIR}/tiffconf.h)
|
||||
|
||||
set(tiff_SOURCES
|
||||
tif_aux.c
|
||||
tif_close.c
|
||||
tif_codec.c
|
||||
tif_color.c
|
||||
tif_compress.c
|
||||
tif_dir.c
|
||||
tif_dirinfo.c
|
||||
tif_dirread.c
|
||||
tif_dirwrite.c
|
||||
tif_dumpmode.c
|
||||
tif_error.c
|
||||
tif_extension.c
|
||||
tif_fax3.c
|
||||
tif_fax3sm.c
|
||||
tif_flush.c
|
||||
tif_getimage.c
|
||||
tif_jbig.c
|
||||
tif_jpeg.c
|
||||
tif_jpeg_12.c
|
||||
tif_luv.c
|
||||
tif_lzma.c
|
||||
tif_lzw.c
|
||||
tif_next.c
|
||||
tif_ojpeg.c
|
||||
tif_open.c
|
||||
tif_packbits.c
|
||||
tif_pixarlog.c
|
||||
tif_predict.c
|
||||
tif_print.c
|
||||
tif_read.c
|
||||
tif_strip.c
|
||||
tif_swab.c
|
||||
tif_thunder.c
|
||||
tif_tile.c
|
||||
tif_version.c
|
||||
tif_warning.c
|
||||
tif_webp.c
|
||||
tif_write.c
|
||||
tif_zip.c
|
||||
tif_zstd.c)
|
||||
|
||||
set(tiffxx_HEADERS
|
||||
tiffio.hxx)
|
||||
|
||||
set(tiffxx_SOURCES
|
||||
tif_stream.cxx)
|
||||
|
||||
if(WIN32_IO)
|
||||
extra_dist(tif_unix.c)
|
||||
list(APPEND tiff_SOURCES tif_win32.c)
|
||||
else()
|
||||
extra_dist(tif_win32.c)
|
||||
list(APPEND tiff_SOURCES tif_unix.c)
|
||||
endif()
|
||||
|
||||
add_library(tiff ${tiff_SOURCES} ${tiff_HEADERS} ${nodist_tiff_HEADERS}
|
||||
${tiff_port_SOURCES} libtiff.def)
|
||||
target_include_directories(tiff
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
|
||||
${TIFF_INCLUDES}
|
||||
)
|
||||
target_link_libraries(tiff ${TIFF_LIBRARY_DEPS})
|
||||
set_target_properties(tiff PROPERTIES SOVERSION ${SO_COMPATVERSION})
|
||||
if(NOT CYGWIN)
|
||||
# This property causes shared libraries on Linux to have the full version
|
||||
# encoded into their final filename. We disable this on Cygwin because
|
||||
# it causes cygz-${TIFF_FULL_VERSION}.dll to be created when cygz.dll
|
||||
# seems to be the default.
|
||||
set_target_properties(tiff PROPERTIES VERSION ${SO_VERSION})
|
||||
endif()
|
||||
if(HAVE_LD_VERSION_SCRIPT)
|
||||
set_target_properties(tiff PROPERTIES LINK_FLAGS
|
||||
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libtiff.map")
|
||||
endif()
|
||||
|
||||
install(TARGETS tiff
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR})
|
||||
|
||||
install(FILES ${tiff_HEADERS} ${nodist_tiff_HEADERS}
|
||||
DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
|
||||
|
||||
if(CXX_SUPPORT)
|
||||
add_library(tiffxx ${tiffxx_SOURCES} ${tiffxx_HEADERS})
|
||||
target_link_libraries(tiffxx tiff)
|
||||
set_target_properties(tiffxx PROPERTIES SOVERSION ${SO_COMPATVERSION})
|
||||
if(NOT CYGWIN)
|
||||
# This property causes shared libraries on Linux to have the full version
|
||||
# encoded into their final filename. We disable this on Cygwin because
|
||||
# it causes cygz-${TIFF_FULL_VERSION}.dll to be created when cygz.dll
|
||||
# seems to be the default.
|
||||
set_target_properties(tiffxx PROPERTIES VERSION ${SO_VERSION})
|
||||
endif()
|
||||
if(HAVE_LD_VERSION_SCRIPT)
|
||||
set_target_properties(tiffxx PROPERTIES LINK_FLAGS
|
||||
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libtiffxx.map")
|
||||
endif()
|
||||
|
||||
install(TARGETS tiffxx
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR})
|
||||
|
||||
install(FILES ${tiffxx_HEADERS}
|
||||
DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
|
||||
|
||||
endif()
|
||||
|
|
@ -1,156 +0,0 @@
|
|||
# Tag Image File Format (TIFF) Software
|
||||
#
|
||||
# Copyright (C) 2004, Andrey Kiselev <dron@ak4719.spb.edu>
|
||||
#
|
||||
# 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.
|
||||
|
||||
# Process this file with automake to produce Makefile.in.
|
||||
|
||||
LIBPORT = $(top_builddir)/port/libport.la
|
||||
LIBTIFF = $(top_builddir)/libtiff/libtiff.la
|
||||
libtiffincludedir = $(includedir)
|
||||
|
||||
EXTRA_DIST = \
|
||||
CMakeLists.txt \
|
||||
Makefile.vc \
|
||||
SConstruct \
|
||||
libtiff.def \
|
||||
libtiff.map \
|
||||
libtiffxx.map \
|
||||
tif_config.h-vms \
|
||||
tif_config.h.cmake.in \
|
||||
tif_config.vc.h \
|
||||
tif_config.wince.h \
|
||||
tiffconf.h.cmake.in \
|
||||
tiffconf.vc.h \
|
||||
tiffconf.wince.h
|
||||
|
||||
libtiffinclude_HEADERS = \
|
||||
tiff.h \
|
||||
tiffio.h \
|
||||
tiffvers.h
|
||||
|
||||
if HAVE_CXX
|
||||
libtiffinclude_HEADERS += tiffio.hxx
|
||||
endif
|
||||
|
||||
noinst_HEADERS = \
|
||||
t4.h \
|
||||
tif_dir.h \
|
||||
tif_predict.h \
|
||||
tiffiop.h \
|
||||
uvcode.h
|
||||
|
||||
nodist_libtiffinclude_HEADERS = \
|
||||
tiffconf.h
|
||||
|
||||
libtiff_la_SOURCES = \
|
||||
tif_aux.c \
|
||||
tif_close.c \
|
||||
tif_codec.c \
|
||||
tif_color.c \
|
||||
tif_compress.c \
|
||||
tif_dir.c \
|
||||
tif_dirinfo.c \
|
||||
tif_dirread.c \
|
||||
tif_dirwrite.c \
|
||||
tif_dumpmode.c \
|
||||
tif_error.c \
|
||||
tif_extension.c \
|
||||
tif_fax3.c \
|
||||
tif_fax3sm.c \
|
||||
tif_flush.c \
|
||||
tif_getimage.c \
|
||||
tif_jbig.c \
|
||||
tif_jpeg.c \
|
||||
tif_jpeg_12.c \
|
||||
tif_luv.c \
|
||||
tif_lzma.c \
|
||||
tif_lzw.c \
|
||||
tif_next.c \
|
||||
tif_ojpeg.c \
|
||||
tif_open.c \
|
||||
tif_packbits.c \
|
||||
tif_pixarlog.c \
|
||||
tif_predict.c \
|
||||
tif_print.c \
|
||||
tif_read.c \
|
||||
tif_strip.c \
|
||||
tif_swab.c \
|
||||
tif_thunder.c \
|
||||
tif_tile.c \
|
||||
tif_version.c \
|
||||
tif_warning.c \
|
||||
tif_webp.c \
|
||||
tif_write.c \
|
||||
tif_zip.c \
|
||||
tif_zstd.c
|
||||
|
||||
libtiffxx_la_SOURCES = \
|
||||
tif_stream.cxx
|
||||
|
||||
if WIN32_IO
|
||||
EXTRA_DIST += tif_unix.c
|
||||
libtiff_la_SOURCES += tif_win32.c
|
||||
else
|
||||
EXTRA_DIST += tif_win32.c
|
||||
libtiff_la_SOURCES += tif_unix.c
|
||||
endif
|
||||
|
||||
lib_LTLIBRARIES = libtiff.la
|
||||
if HAVE_CXX
|
||||
lib_LTLIBRARIES += libtiffxx.la
|
||||
endif
|
||||
|
||||
libtiff_la_LDFLAGS = \
|
||||
-no-undefined \
|
||||
-version-info $(LIBTIFF_VERSION_INFO)
|
||||
if HAVE_RPATH
|
||||
libtiff_la_LDFLAGS += $(LIBDIR)
|
||||
endif
|
||||
if HAVE_LD_VERSION_SCRIPT
|
||||
libtiff_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libtiff.map
|
||||
endif
|
||||
libtiff_la_LIBADD = $(LIBPORT)
|
||||
|
||||
libtiffxx_la_LDFLAGS = \
|
||||
-no-undefined \
|
||||
-version-info $(LIBTIFF_VERSION_INFO)
|
||||
if HAVE_RPATH
|
||||
libtiffxx_la_LDFLAGS += $(LIBDIR)
|
||||
endif
|
||||
if HAVE_LD_VERSION_SCRIPT
|
||||
libtiffxx_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libtiffxx.map
|
||||
endif
|
||||
libtiffxx_la_LIBADD = $(LIBTIFF) $(LIBPORT)
|
||||
libtiffxx_la_DEPENDENCIES = libtiff.la
|
||||
|
||||
#
|
||||
# The finite state machine tables used by the G3/G4 decoders
|
||||
# are generated by the mkg3states program. On systems without
|
||||
# make these rules have to be manually carried out.
|
||||
#
|
||||
noinst_PROGRAMS = mkg3states
|
||||
mkg3states_SOURCES = mkg3states.c tif_fax3.h
|
||||
mkg3states_LDADD = $(LIBPORT)
|
||||
|
||||
faxtable: mkg3states
|
||||
(rm -f tif_fax3sm.c && ./mkg3states -b -c const tif_fax3sm.c)
|
||||
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,100 +0,0 @@
|
|||
# Copyright (C) 2004, Andrey Kiselev <dron@ak4719.spb.edu>
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# Makefile for MS Visual C and Watcom C compilers.
|
||||
#
|
||||
# To build:
|
||||
# C:\libtiff\libtiff> nmake /f makefile.vc all
|
||||
#
|
||||
|
||||
!INCLUDE ..\nmake.opt
|
||||
|
||||
INCL = -I. $(JPEG_INCLUDE) $(ZLIB_INCLUDE) $(JBIG_INCLUDE)
|
||||
|
||||
!IFDEF USE_WIN_CRT_LIB
|
||||
OBJ_SYSDEP_MODULE = tif_unix.obj
|
||||
!ELSE
|
||||
OBJ_SYSDEP_MODULE = tif_win32.obj
|
||||
!ENDIF
|
||||
|
||||
OBJ = \
|
||||
tif_aux.obj \
|
||||
tif_close.obj \
|
||||
tif_codec.obj \
|
||||
tif_color.obj \
|
||||
tif_compress.obj \
|
||||
tif_dir.obj \
|
||||
tif_dirinfo.obj \
|
||||
tif_dirread.obj \
|
||||
tif_dirwrite.obj \
|
||||
tif_dumpmode.obj \
|
||||
tif_error.obj \
|
||||
tif_extension.obj \
|
||||
tif_fax3.obj \
|
||||
tif_fax3sm.obj \
|
||||
tif_getimage.obj \
|
||||
tif_jbig.obj \
|
||||
tif_jpeg.obj \
|
||||
tif_jpeg_12.obj \
|
||||
tif_ojpeg.obj \
|
||||
tif_flush.obj \
|
||||
tif_luv.obj \
|
||||
tif_lzw.obj \
|
||||
tif_next.obj \
|
||||
tif_open.obj \
|
||||
tif_packbits.obj \
|
||||
tif_pixarlog.obj \
|
||||
tif_predict.obj \
|
||||
tif_print.obj \
|
||||
tif_read.obj \
|
||||
tif_stream.obj \
|
||||
tif_swab.obj \
|
||||
tif_strip.obj \
|
||||
tif_thunder.obj \
|
||||
tif_tile.obj \
|
||||
tif_version.obj \
|
||||
tif_warning.obj \
|
||||
tif_write.obj \
|
||||
tif_zip.obj \
|
||||
$(OBJ_SYSDEP_MODULE)
|
||||
|
||||
all: libtiff.lib $(DLLNAME)
|
||||
|
||||
tif_config.h: tif_config.vc.h
|
||||
copy tif_config.vc.h tif_config.h
|
||||
|
||||
tiffconf.h: tiffconf.vc.h
|
||||
copy tiffconf.vc.h tiffconf.h
|
||||
|
||||
libtiff.lib: tif_config.h tiffconf.h $(OBJ)
|
||||
$(AR) /out:libtiff.lib ..\port\libport.lib $(OBJ) $(LIBS)
|
||||
|
||||
$(DLLNAME): tif_config.h tiffconf.h libtiff.def $(OBJ)
|
||||
$(LD) /debug /dll /def:libtiff.def /out:$(DLLNAME) \
|
||||
/implib:libtiff_i.lib ..\port\libport.lib $(OBJ) $(LIBS)
|
||||
|
||||
clean:
|
||||
-del tif_config.h tiffconf.h
|
||||
-del *.obj
|
||||
-del *.lib
|
||||
-del *.dll
|
||||
-del *.dll.manifest
|
||||
-del *.pdb
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
# Tag Image File Format (TIFF) Software
|
||||
#
|
||||
# Copyright (C) 2005, Andrey Kiselev <dron@ak4719.spb.edu>
|
||||
#
|
||||
# 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.
|
||||
|
||||
# This file contains rules to build software with the SCons tool
|
||||
# (see the http://www.scons.org/ for details on SCons).
|
||||
|
||||
# Import globally defined options
|
||||
Import([ 'env', 'idir_lib' ])
|
||||
|
||||
SRCS = [ \
|
||||
'tif_aux.c', \
|
||||
'tif_close.c', \
|
||||
'tif_codec.c', \
|
||||
'tif_color.c', \
|
||||
'tif_compress.c', \
|
||||
'tif_dir.c', \
|
||||
'tif_dirinfo.c', \
|
||||
'tif_dirread.c', \
|
||||
'tif_dirwrite.c', \
|
||||
'tif_dumpmode.c', \
|
||||
'tif_error.c', \
|
||||
'tif_extension.c', \
|
||||
'tif_fax3.c', \
|
||||
'tif_fax3sm.c', \
|
||||
'tif_flush.c', \
|
||||
'tif_getimage.c', \
|
||||
'tif_jbig.c', \
|
||||
'tif_jpeg.c', \
|
||||
'tif_luv.c', \
|
||||
'tif_lzw.c', \
|
||||
'tif_next.c', \
|
||||
'tif_ojpeg.c', \
|
||||
'tif_open.c', \
|
||||
'tif_packbits.c', \
|
||||
'tif_pixarlog.c', \
|
||||
'tif_predict.c', \
|
||||
'tif_print.c', \
|
||||
'tif_read.c', \
|
||||
'tif_strip.c', \
|
||||
'tif_swab.c', \
|
||||
'tif_thunder.c', \
|
||||
'tif_tile.c', \
|
||||
'tif_unix.c', \
|
||||
'tif_version.c', \
|
||||
'tif_warning.c', \
|
||||
'tif_write.c', \
|
||||
'tif_zip.c' ]
|
||||
|
||||
StaticLibrary('tiff', SRCS)
|
||||
SharedLibrary('tiff', SRCS)
|
||||
|
||||
|
|
@ -1,168 +0,0 @@
|
|||
EXPORTS TIFFAccessTagMethods
|
||||
TIFFCIELabToRGBInit
|
||||
TIFFCIELabToXYZ
|
||||
TIFFCheckTile
|
||||
TIFFCheckpointDirectory
|
||||
TIFFCleanup
|
||||
TIFFClientOpen
|
||||
TIFFClientdata
|
||||
TIFFClose
|
||||
TIFFComputeStrip
|
||||
TIFFComputeTile
|
||||
TIFFCreateCustomDirectory
|
||||
TIFFCreateDirectory
|
||||
TIFFCreateEXIFDirectory
|
||||
TIFFCurrentDirOffset
|
||||
TIFFCurrentDirectory
|
||||
TIFFCurrentRow
|
||||
TIFFCurrentStrip
|
||||
TIFFCurrentTile
|
||||
TIFFDataWidth
|
||||
TIFFDefaultStripSize
|
||||
TIFFDefaultTileSize
|
||||
TIFFError
|
||||
TIFFErrorExt
|
||||
TIFFFdOpen
|
||||
TIFFFieldDataType
|
||||
TIFFFieldName
|
||||
TIFFFieldPassCount
|
||||
TIFFFieldReadCount
|
||||
TIFFFieldTag
|
||||
TIFFFieldWithName
|
||||
TIFFFieldWithTag
|
||||
TIFFFieldWriteCount
|
||||
TIFFFileName
|
||||
TIFFFileno
|
||||
TIFFFindCODEC
|
||||
TIFFFindField
|
||||
TIFFFlush
|
||||
TIFFFlushData
|
||||
TIFFFreeDirectory
|
||||
TIFFGetBitRevTable
|
||||
TIFFGetClientInfo
|
||||
TIFFGetCloseProc
|
||||
TIFFGetConfiguredCODECs
|
||||
TIFFGetField
|
||||
TIFFGetFieldDefaulted
|
||||
TIFFGetMapFileProc
|
||||
TIFFGetMode
|
||||
TIFFGetReadProc
|
||||
TIFFGetSeekProc
|
||||
TIFFGetSizeProc
|
||||
TIFFGetTagListCount
|
||||
TIFFGetTagListEntry
|
||||
TIFFGetUnmapFileProc
|
||||
TIFFGetVersion
|
||||
TIFFGetWriteProc
|
||||
TIFFIsBigEndian
|
||||
TIFFIsByteSwapped
|
||||
TIFFIsCODECConfigured
|
||||
TIFFIsMSB2LSB
|
||||
TIFFIsTiled
|
||||
TIFFIsUpSampled
|
||||
TIFFLastDirectory
|
||||
TIFFMergeFieldInfo
|
||||
TIFFNumberOfDirectories
|
||||
TIFFNumberOfStrips
|
||||
TIFFNumberOfTiles
|
||||
TIFFOpen
|
||||
TIFFOpenW
|
||||
TIFFPrintDirectory
|
||||
TIFFRGBAImageBegin
|
||||
TIFFRGBAImageEnd
|
||||
TIFFRGBAImageGet
|
||||
TIFFRGBAImageOK
|
||||
TIFFRasterScanlineSize
|
||||
TIFFRasterScanlineSize64
|
||||
TIFFRawStripSize
|
||||
TIFFRawStripSize64
|
||||
TIFFReadBufferSetup
|
||||
TIFFReadCustomDirectory
|
||||
TIFFReadDirectory
|
||||
TIFFReadEXIFDirectory
|
||||
TIFFReadEncodedStrip
|
||||
TIFFReadEncodedTile
|
||||
TIFFReadRGBAImage
|
||||
TIFFReadRGBAImageOriented
|
||||
TIFFReadRGBAStrip
|
||||
TIFFReadRGBAStripExt
|
||||
TIFFReadRGBATile
|
||||
TIFFReadRGBATileExt
|
||||
TIFFReadRawStrip
|
||||
TIFFReadRawTile
|
||||
TIFFReadScanline
|
||||
TIFFReadTile
|
||||
TIFFRegisterCODEC
|
||||
TIFFReverseBits
|
||||
TIFFRewriteDirectory
|
||||
TIFFScanlineSize
|
||||
TIFFScanlineSize64
|
||||
TIFFSetClientInfo
|
||||
TIFFSetClientdata
|
||||
TIFFSetCompressionScheme
|
||||
TIFFSetDirectory
|
||||
TIFFSetErrorHandler
|
||||
TIFFSetErrorHandlerExt
|
||||
TIFFSetField
|
||||
TIFFSetFileName
|
||||
TIFFSetFileno
|
||||
TIFFSetMode
|
||||
TIFFSetSubDirectory
|
||||
TIFFSetTagExtender
|
||||
TIFFSetWarningHandler
|
||||
TIFFSetWarningHandlerExt
|
||||
TIFFSetWriteOffset
|
||||
TIFFSetupStrips
|
||||
TIFFStripSize
|
||||
TIFFStripSize64
|
||||
TIFFSwabArrayOfDouble
|
||||
TIFFSwabArrayOfFloat
|
||||
TIFFSwabArrayOfLong
|
||||
TIFFSwabArrayOfLong8
|
||||
TIFFSwabArrayOfShort
|
||||
TIFFSwabArrayOfTriples
|
||||
TIFFSwabDouble
|
||||
TIFFSwabFloat
|
||||
TIFFSwabLong
|
||||
TIFFSwabLong8
|
||||
TIFFSwabShort
|
||||
TIFFTileRowSize
|
||||
TIFFTileRowSize64
|
||||
TIFFTileSize
|
||||
TIFFTileSize64
|
||||
TIFFUnRegisterCODEC
|
||||
TIFFUnlinkDirectory
|
||||
TIFFUnsetField
|
||||
TIFFVGetField
|
||||
TIFFVGetFieldDefaulted
|
||||
TIFFVSetField
|
||||
TIFFVStripSize
|
||||
TIFFVStripSize64
|
||||
TIFFVTileSize
|
||||
TIFFVTileSize64
|
||||
TIFFWarning
|
||||
TIFFWarningExt
|
||||
TIFFWriteBufferSetup
|
||||
TIFFWriteCheck
|
||||
TIFFWriteCustomDirectory
|
||||
TIFFWriteDirectory
|
||||
TIFFWriteEncodedStrip
|
||||
TIFFWriteEncodedTile
|
||||
TIFFWriteRawStrip
|
||||
TIFFWriteRawTile
|
||||
TIFFWriteScanline
|
||||
TIFFWriteTile
|
||||
TIFFXYZToRGB
|
||||
TIFFYCbCrToRGBInit
|
||||
TIFFYCbCrtoRGB
|
||||
_TIFFCheckMalloc
|
||||
_TIFFCheckRealloc
|
||||
_TIFFRewriteField
|
||||
_TIFFfree
|
||||
_TIFFmalloc
|
||||
_TIFFmemcmp
|
||||
_TIFFmemcpy
|
||||
_TIFFmemset
|
||||
_TIFFrealloc
|
||||
_TIFFMultiply32
|
||||
_TIFFMultiply64
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
LIBTIFF_4.0 {
|
||||
global:
|
||||
*;
|
||||
};
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
LIBTIFFXX_4.0 {
|
||||
global:
|
||||
*;
|
||||
};
|
||||
|
|
@ -40,7 +40,7 @@
|
|||
#include "tif_fax3.h"
|
||||
|
||||
#ifndef HAVE_GETOPT
|
||||
extern int getopt(int, char**, char*);
|
||||
extern int getopt(int argc, char * const argv[], const char *optstring);
|
||||
#endif
|
||||
|
||||
#define streq(a,b) (strcmp(a,b) == 0)
|
||||
|
|
|
|||
|
|
@ -30,31 +30,66 @@
|
|||
#include "tiffiop.h"
|
||||
#include "tif_predict.h"
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
uint32
|
||||
_TIFFMultiply32(TIFF* tif, uint32 first, uint32 second, const char* where)
|
||||
{
|
||||
uint32 bytes = first * second;
|
||||
|
||||
if (second && bytes / second != first) {
|
||||
if (second && first > TIFF_UINT32_MAX / second) {
|
||||
TIFFErrorExt(tif->tif_clientdata, where, "Integer overflow in %s", where);
|
||||
bytes = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return bytes;
|
||||
return first * second;
|
||||
}
|
||||
|
||||
uint64
|
||||
_TIFFMultiply64(TIFF* tif, uint64 first, uint64 second, const char* where)
|
||||
{
|
||||
uint64 bytes = first * second;
|
||||
|
||||
if (second && bytes / second != first) {
|
||||
if (second && first > TIFF_UINT64_MAX / second) {
|
||||
TIFFErrorExt(tif->tif_clientdata, where, "Integer overflow in %s", where);
|
||||
bytes = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return bytes;
|
||||
return first * second;
|
||||
}
|
||||
|
||||
tmsize_t
|
||||
_TIFFMultiplySSize(TIFF* tif, tmsize_t first, tmsize_t second, const char* where)
|
||||
{
|
||||
if( first <= 0 || second <= 0 )
|
||||
{
|
||||
if( tif != NULL && where != NULL )
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata, where,
|
||||
"Invalid argument to _TIFFMultiplySSize() in %s", where);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( first > TIFF_TMSIZE_T_MAX / second )
|
||||
{
|
||||
if( tif != NULL && where != NULL )
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata, where,
|
||||
"Integer overflow in %s", where);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return first * second;
|
||||
}
|
||||
|
||||
tmsize_t _TIFFCastUInt64ToSSize(TIFF* tif, uint64 val, const char* module)
|
||||
{
|
||||
if( val > (uint64)TIFF_TMSIZE_T_MAX )
|
||||
{
|
||||
if( tif != NULL && module != NULL )
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return (tmsize_t)val;
|
||||
}
|
||||
|
||||
void*
|
||||
|
|
@ -62,13 +97,14 @@ _TIFFCheckRealloc(TIFF* tif, void* buffer,
|
|||
tmsize_t nmemb, tmsize_t elem_size, const char* what)
|
||||
{
|
||||
void* cp = NULL;
|
||||
tmsize_t bytes = nmemb * elem_size;
|
||||
|
||||
tmsize_t count = _TIFFMultiplySSize(tif, nmemb, elem_size, NULL);
|
||||
/*
|
||||
* XXX: Check for integer overflow.
|
||||
* Check for integer overflow.
|
||||
*/
|
||||
if (nmemb && elem_size && bytes / elem_size == nmemb)
|
||||
cp = _TIFFrealloc(buffer, bytes);
|
||||
if (count != 0)
|
||||
{
|
||||
cp = _TIFFrealloc(buffer, count);
|
||||
}
|
||||
|
||||
if (cp == NULL) {
|
||||
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
|
||||
|
|
@ -357,6 +393,15 @@ _TIFFUInt64ToDouble(uint64 ui64)
|
|||
}
|
||||
}
|
||||
|
||||
float _TIFFClampDoubleToFloat( double val )
|
||||
{
|
||||
if( val > FLT_MAX )
|
||||
return FLT_MAX;
|
||||
if( val < -FLT_MAX )
|
||||
return -FLT_MAX;
|
||||
return (float)val;
|
||||
}
|
||||
|
||||
int _TIFFSeekOK(TIFF* tif, toff_t off)
|
||||
{
|
||||
/* Huge offsets, especially -1 / UINT64_MAX, can cause issues */
|
||||
|
|
|
|||
|
|
@ -50,10 +50,7 @@
|
|||
/* Unsigned 64-bit type */
|
||||
#define TIFF_UINT64_T unsigned __int64
|
||||
|
||||
#define TIFF_SSIZE_T ptrdiff_t
|
||||
#define TIFF_SIZE_T size_t
|
||||
|
||||
#if _WIN64
|
||||
#if _WIN64
|
||||
/*
|
||||
Windows 64-bit build
|
||||
*/
|
||||
|
|
@ -68,10 +65,14 @@
|
|||
# define TIFF_SIZE_FORMAT TIFF_INT64_FORMAT
|
||||
|
||||
/* Unsigned size type */
|
||||
#define TIFF_SIZE_T size_t
|
||||
|
||||
/* Signed size type formatter */
|
||||
# define TIFF_SSIZE_FORMAT TIFF_INT64_FORMAT
|
||||
|
||||
/* Signed size type */
|
||||
#define TIFF_SSIZE_T ptrdiff_t
|
||||
|
||||
#else
|
||||
/*
|
||||
Windows 32-bit build
|
||||
|
|
@ -89,8 +90,15 @@
|
|||
/* Size type formatter */
|
||||
# define TIFF_SIZE_FORMAT "%u"
|
||||
|
||||
/* Unsigned size type */
|
||||
# define TIFF_SIZE_T unsigned int
|
||||
|
||||
/* Signed size type formatter */
|
||||
# define TIFF_SSIZE_FORMAT "%d"
|
||||
|
||||
/* Signed size type */
|
||||
# define TIFF_SSIZE_T signed int
|
||||
|
||||
#endif
|
||||
|
||||
/* Set the native cpu bit order */
|
||||
|
|
|
|||
|
|
@ -1,46 +0,0 @@
|
|||
/* Define to 1 if you have the <assert.h> header file. */
|
||||
#define HAVE_ASSERT_H 1
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#define HAVE_FCNTL_H 1
|
||||
|
||||
/* Define as 0 or 1 according to the floating point format suported by the
|
||||
machine */
|
||||
#define HAVE_IEEEFP 1
|
||||
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
#define HAVE_STRING_H 1
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <io.h> header file. */
|
||||
//#define HAVE_IO_H 1
|
||||
|
||||
/* Define to 1 if you have the <search.h> header file. */
|
||||
//#define HAVE_SEARCH_H 1
|
||||
|
||||
/* The size of a `int', as computed by sizeof. */
|
||||
#define SIZEOF_INT 4
|
||||
|
||||
/* The size of a `long', as computed by sizeof. */
|
||||
#define SIZEOF_LONG 4
|
||||
|
||||
/* Set the native cpu bit order */
|
||||
#define HOST_FILLORDER FILLORDER_LSB2MSB
|
||||
|
||||
/* Define to 1 if your processor stores words with the most significant byte
|
||||
first (like Motorola and SPARC, unlike Intel and VAX). */
|
||||
/* #undef WORDS_BIGENDIAN */
|
||||
|
||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||
/*
|
||||
#ifndef __cplusplus
|
||||
# ifndef inline
|
||||
# define inline __inline
|
||||
# endif
|
||||
#endif
|
||||
*/
|
||||
|
||||
// #define lfind _lfind
|
||||
|
|
@ -1,231 +0,0 @@
|
|||
/* libtiff/tif_config.h.cmake.in. Not generated, but originated from autoheader. */
|
||||
/* This file must be kept up-to-date with needed substitutions from libtiff/tif_config.h.in. */
|
||||
|
||||
/* Support CCITT Group 3 & 4 algorithms */
|
||||
#cmakedefine CCITT_SUPPORT 1
|
||||
|
||||
/* Pick up YCbCr subsampling info from the JPEG data stream to support files
|
||||
lacking the tag (default enabled). */
|
||||
#cmakedefine CHECK_JPEG_YCBCR_SUBSAMPLING 1
|
||||
|
||||
/* enable partial strip reading for large strips (experimental) */
|
||||
#cmakedefine CHUNKY_STRIP_READ_SUPPORT 1
|
||||
|
||||
/* Support C++ stream API (requires C++ compiler) */
|
||||
#cmakedefine CXX_SUPPORT 1
|
||||
|
||||
/* enable deferred strip/tile offset/size loading (experimental) */
|
||||
#cmakedefine DEFER_STRILE_LOAD 1
|
||||
|
||||
/* Define to 1 if you have the <assert.h> header file. */
|
||||
#cmakedefine HAVE_ASSERT_H 1
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#cmakedefine HAVE_DLFCN_H 1
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#cmakedefine HAVE_FCNTL_H 1
|
||||
|
||||
/* Define to 1 if you have the `getopt' function. */
|
||||
#cmakedefine HAVE_GETOPT 1
|
||||
|
||||
/* Define to 1 if you have the <GLUT/glut.h> header file. */
|
||||
#cmakedefine HAVE_GLUT_GLUT_H 1
|
||||
|
||||
/* Define to 1 if you have the <GL/glut.h> header file. */
|
||||
#cmakedefine HAVE_GL_GLUT_H 1
|
||||
|
||||
/* Define to 1 if you have the <GL/glu.h> header file. */
|
||||
#cmakedefine HAVE_GL_GLU_H 1
|
||||
|
||||
/* Define to 1 if you have the <GL/gl.h> header file. */
|
||||
#cmakedefine HAVE_GL_GL_H 1
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#cmakedefine HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <io.h> header file. */
|
||||
#cmakedefine HAVE_IO_H 1
|
||||
|
||||
/* Define to 1 if you have the `jbg_newlen' function. */
|
||||
#cmakedefine HAVE_JBG_NEWLEN 1
|
||||
|
||||
/* Define to 1 if you have the `lfind' function. */
|
||||
#cmakedefine HAVE_LFIND 1
|
||||
|
||||
/* Define to 1 if you have the `mmap' function. */
|
||||
#cmakedefine HAVE_MMAP 1
|
||||
|
||||
/* Define to 1 if you have the <OpenGL/glu.h> header file. */
|
||||
#cmakedefine HAVE_OPENGL_GLU_H 1
|
||||
|
||||
/* Define to 1 if you have the <OpenGL/gl.h> header file. */
|
||||
#cmakedefine HAVE_OPENGL_GL_H 1
|
||||
|
||||
/* Define to 1 if you have the <search.h> header file. */
|
||||
#cmakedefine HAVE_SEARCH_H 1
|
||||
|
||||
/* Define to 1 if you have the `setmode' function. */
|
||||
#cmakedefine HAVE_SETMODE 1
|
||||
|
||||
/* Define to 1 if you have the `snprintf' function. */
|
||||
#cmakedefine HAVE_SNPRINTF 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#cmakedefine HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the `strcasecmp' function. */
|
||||
#cmakedefine HAVE_STRCASECMP 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#cmakedefine HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#cmakedefine HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the `strtol' function. */
|
||||
#cmakedefine HAVE_STRTOL 1
|
||||
|
||||
/* Define to 1 if you have the `strtoll' function. */
|
||||
#cmakedefine HAVE_STRTOLL 1
|
||||
|
||||
/* Define to 1 if you have the `strtoul' function. */
|
||||
#cmakedefine HAVE_STRTOUL 1
|
||||
|
||||
/* Define to 1 if you have the `strtoull' function. */
|
||||
#cmakedefine HAVE_STRTOULL 1
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#cmakedefine HAVE_SYS_TIME_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#cmakedefine HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#cmakedefine HAVE_UNISTD_H 1
|
||||
|
||||
/* 8/12 bit libjpeg dual mode enabled */
|
||||
#cmakedefine JPEG_DUAL_MODE_8_12 1
|
||||
|
||||
/* 12bit libjpeg primary include file with path */
|
||||
#define LIBJPEG_12_PATH @LIBJPEG_12_PATH@
|
||||
|
||||
/* Support LZMA2 compression */
|
||||
#cmakedefine LZMA_SUPPORT 1
|
||||
|
||||
/* Support ZSTD compression */
|
||||
#cmakedefine ZSTD_SUPPORT 1
|
||||
|
||||
/* Support WEBP compression */
|
||||
#cmakedefine WEBP_SUPPORT 1
|
||||
|
||||
/* Name of package */
|
||||
#define PACKAGE "@PACKAGE_NAME@"
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@"
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "@PACKAGE_NAME@"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "@PACKAGE_STRING@"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "@PACKAGE_TARNAME@"
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#define PACKAGE_URL "@PACKAGE_URL@"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "@PACKAGE_VERSION@"
|
||||
|
||||
/* The size of `signed int', as computed by sizeof. */
|
||||
#define SIZEOF_SIGNED_INT @SIZEOF_SIGNED_INT@
|
||||
|
||||
/* The size of `signed long', as computed by sizeof. */
|
||||
#define SIZEOF_SIGNED_LONG @SIZEOF_SIGNED_LONG@
|
||||
|
||||
/* The size of `signed long long', as computed by sizeof. */
|
||||
#define SIZEOF_SIGNED_LONG_LONG @SIZEOF_SIGNED_LONG_LONG@
|
||||
|
||||
/* The size of `unsigned char *', as computed by sizeof. */
|
||||
#define SIZEOF_UNSIGNED_CHAR_P @SIZEOF_UNSIGNED_CHAR_P@
|
||||
|
||||
/* The size of `unsigned int', as computed by sizeof. */
|
||||
#define SIZEOF_UNSIGNED_INT @SIZEOF_UNSIGNED_INT@
|
||||
|
||||
/* The size of `unsigned long', as computed by sizeof. */
|
||||
#define SIZEOF_UNSIGNED_LONG @SIZEOF_UNSIGNED_LONG@
|
||||
|
||||
/* The size of `unsigned long long', as computed by sizeof. */
|
||||
#define SIZEOF_UNSIGNED_LONG_LONG @SIZEOF_UNSIGNED_LONG_LONG@
|
||||
|
||||
/* The size of `unsigned short', as computed by sizeof. */
|
||||
#define SIZEOF_UNSIGNED_SHORT @SIZEOF_UNSIGNED_SHORT@
|
||||
|
||||
/* Default size of the strip in bytes (when strip chopping enabled) */
|
||||
#define STRIP_SIZE_DEFAULT @STRIP_SIZE_DEFAULT@
|
||||
|
||||
/* Signed 32-bit type formatter */
|
||||
#define TIFF_INT32_FORMAT "@TIFF_INT32_FORMAT@"
|
||||
|
||||
/* Signed 64-bit type formatter */
|
||||
#define TIFF_INT64_FORMAT "@TIFF_INT64_FORMAT@"
|
||||
|
||||
/* Pointer difference type formatter */
|
||||
#define TIFF_PTRDIFF_FORMAT "@TIFF_PTRDIFF_FORMAT@"
|
||||
|
||||
/* Unsigned size type formatter */
|
||||
#define TIFF_SIZE_FORMAT "@TIFF_SIZE_FORMAT@"
|
||||
|
||||
/* Signed size type formatter */
|
||||
#define TIFF_SSIZE_FORMAT "@TIFF_SSIZE_FORMAT@"
|
||||
|
||||
/* Unsigned 32-bit type formatter */
|
||||
#define TIFF_UINT32_FORMAT "@TIFF_UINT32_FORMAT@"
|
||||
|
||||
/* Unsigned 64-bit type formatter */
|
||||
#define TIFF_UINT64_FORMAT "@TIFF_UINT64_FORMAT@"
|
||||
|
||||
/* Unsigned 8-bit type */
|
||||
#define TIFF_UINT8_T @TIFF_UINT8_T@
|
||||
|
||||
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#undef TIME_WITH_SYS_TIME
|
||||
|
||||
/* Define to 1 if your <sys/time.h> declares `struct tm'. */
|
||||
#cmakedefine TM_IN_SYS_TIME 1
|
||||
|
||||
/* define to use win32 IO system */
|
||||
#cmakedefine USE_WIN32_FILEIO 1
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "@PACKAGE_VERSION@"
|
||||
|
||||
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
|
||||
significant byte first (like Motorola and SPARC, unlike Intel). */
|
||||
#if defined AC_APPLE_UNIVERSAL_BUILD
|
||||
# if defined __BIG_ENDIAN__
|
||||
# define WORDS_BIGENDIAN 1
|
||||
# endif
|
||||
#else
|
||||
# ifndef WORDS_BIGENDIAN
|
||||
# undef WORDS_BIGENDIAN
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Number of bits in a file offset, on hosts where this is settable. */
|
||||
#define _FILE_OFFSET_BITS @FILE_OFFSET_BITS@
|
||||
|
||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||
#ifndef __cplusplus
|
||||
#define inline @INLINE_KEYWORD@
|
||||
#endif
|
||||
|
||||
/* Define to `long int' if <sys/types.h> does not define. */
|
||||
#undef off_t
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
#undef size_t
|
||||
|
|
@ -1,368 +0,0 @@
|
|||
/* libtiff/tif_config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Define if building universal (internal helper macro) */
|
||||
#undef AC_APPLE_UNIVERSAL_BUILD
|
||||
|
||||
/* Support CCITT Group 3 & 4 algorithms */
|
||||
#undef CCITT_SUPPORT
|
||||
|
||||
/* Pick up YCbCr subsampling info from the JPEG data stream to support files
|
||||
lacking the tag (default enabled). */
|
||||
#undef CHECK_JPEG_YCBCR_SUBSAMPLING
|
||||
|
||||
/* enable partial strip reading for large strips (experimental) */
|
||||
#undef CHUNKY_STRIP_READ_SUPPORT
|
||||
|
||||
/* Support C++ stream API (requires C++ compiler) */
|
||||
#undef CXX_SUPPORT
|
||||
|
||||
/* Treat extra sample as alpha (default enabled). The RGBA interface will
|
||||
treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many
|
||||
packages produce RGBA files but don't mark the alpha properly. */
|
||||
#undef DEFAULT_EXTRASAMPLE_AS_ALPHA
|
||||
|
||||
/* enable deferred strip/tile offset/size loading (experimental) */
|
||||
#undef DEFER_STRILE_LOAD
|
||||
|
||||
/* Define to 1 if you have the <assert.h> header file. */
|
||||
#undef HAVE_ASSERT_H
|
||||
|
||||
/* Define to 1 if you have the declaration of `optarg', and to 0 if you don't.
|
||||
*/
|
||||
#undef HAVE_DECL_OPTARG
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#undef HAVE_DLFCN_H
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#undef HAVE_FCNTL_H
|
||||
|
||||
/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
|
||||
#undef HAVE_FSEEKO
|
||||
|
||||
/* Define to 1 if you have the `getopt' function. */
|
||||
#undef HAVE_GETOPT
|
||||
|
||||
/* Define to 1 if you have the <GLUT/glut.h> header file. */
|
||||
#undef HAVE_GLUT_GLUT_H
|
||||
|
||||
/* Define to 1 if you have the <GL/glut.h> header file. */
|
||||
#undef HAVE_GL_GLUT_H
|
||||
|
||||
/* Define to 1 if you have the <GL/glu.h> header file. */
|
||||
#undef HAVE_GL_GLU_H
|
||||
|
||||
/* Define to 1 if you have the <GL/gl.h> header file. */
|
||||
#undef HAVE_GL_GL_H
|
||||
|
||||
/* Define as 0 or 1 according to the floating point format suported by the
|
||||
machine */
|
||||
#undef HAVE_IEEEFP
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define to 1 if you have the <io.h> header file. */
|
||||
#undef HAVE_IO_H
|
||||
|
||||
/* Define to 1 if you have the `jbg_newlen' function. */
|
||||
#undef HAVE_JBG_NEWLEN
|
||||
|
||||
/* Define to 1 if you have the `lfind' function. */
|
||||
#undef HAVE_LFIND
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the `mmap' function. */
|
||||
#undef HAVE_MMAP
|
||||
|
||||
/* Define to 1 if you have the <OpenGL/glu.h> header file. */
|
||||
#undef HAVE_OPENGL_GLU_H
|
||||
|
||||
/* Define to 1 if you have the <OpenGL/gl.h> header file. */
|
||||
#undef HAVE_OPENGL_GL_H
|
||||
|
||||
/* Define if you have POSIX threads libraries and header files. */
|
||||
#undef HAVE_PTHREAD
|
||||
|
||||
/* Define to 1 if you have the <search.h> header file. */
|
||||
#undef HAVE_SEARCH_H
|
||||
|
||||
/* Define to 1 if you have the `setmode' function. */
|
||||
#undef HAVE_SETMODE
|
||||
|
||||
/* Define to 1 if you have the `snprintf' function. */
|
||||
#undef HAVE_SNPRINTF
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
/* Define to 1 if you have the `strcasecmp' function. */
|
||||
#undef HAVE_STRCASECMP
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#undef HAVE_STRINGS_H
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#undef HAVE_STRING_H
|
||||
|
||||
/* Define to 1 if you have the `strtol' function. */
|
||||
#undef HAVE_STRTOL
|
||||
|
||||
/* Define to 1 if you have the `strtoll' function. */
|
||||
#undef HAVE_STRTOLL
|
||||
|
||||
/* Define to 1 if you have the `strtoul' function. */
|
||||
#undef HAVE_STRTOUL
|
||||
|
||||
/* Define to 1 if you have the `strtoull' function. */
|
||||
#undef HAVE_STRTOULL
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Use nonstandard varargs form for the GLU tesselator callback */
|
||||
#undef HAVE_VARARGS_GLU_TESSCB
|
||||
|
||||
/* Define to 1 if you have the <windows.h> header file. */
|
||||
#undef HAVE_WINDOWS_H
|
||||
|
||||
/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian
|
||||
(Intel) */
|
||||
#undef HOST_BIGENDIAN
|
||||
|
||||
/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */
|
||||
#undef HOST_FILLORDER
|
||||
|
||||
/* Support ISO JBIG compression (requires JBIG-KIT library) */
|
||||
#undef JBIG_SUPPORT
|
||||
|
||||
/* 8/12 bit libjpeg dual mode enabled */
|
||||
#undef JPEG_DUAL_MODE_8_12
|
||||
|
||||
/* Support JPEG compression (requires IJG JPEG library) */
|
||||
#undef JPEG_SUPPORT
|
||||
|
||||
/* 12bit libjpeg primary include file with path */
|
||||
#undef LIBJPEG_12_PATH
|
||||
|
||||
/* Support LogLuv high dynamic range encoding */
|
||||
#undef LOGLUV_SUPPORT
|
||||
|
||||
/* Define to the sub-directory where libtool stores uninstalled libraries. */
|
||||
#undef LT_OBJDIR
|
||||
|
||||
/* Support LZMA2 compression */
|
||||
#undef LZMA_SUPPORT
|
||||
|
||||
/* Support LZW algorithm */
|
||||
#undef LZW_SUPPORT
|
||||
|
||||
/* Support Microsoft Document Imaging format */
|
||||
#undef MDI_SUPPORT
|
||||
|
||||
/* Support NeXT 2-bit RLE algorithm */
|
||||
#undef NEXT_SUPPORT
|
||||
|
||||
/* Support Old JPEG compresson (read-only) */
|
||||
#undef OJPEG_SUPPORT
|
||||
|
||||
/* Name of package */
|
||||
#undef PACKAGE
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#undef PACKAGE_BUGREPORT
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#undef PACKAGE_NAME
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#undef PACKAGE_STRING
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#undef PACKAGE_TARNAME
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#undef PACKAGE_URL
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#undef PACKAGE_VERSION
|
||||
|
||||
/* Support Macintosh PackBits algorithm */
|
||||
#undef PACKBITS_SUPPORT
|
||||
|
||||
/* Support Pixar log-format algorithm (requires Zlib) */
|
||||
#undef PIXARLOG_SUPPORT
|
||||
|
||||
/* Define to necessary symbol if this constant uses a non-standard name on
|
||||
your system. */
|
||||
#undef PTHREAD_CREATE_JOINABLE
|
||||
|
||||
/* The size of `signed int', as computed by sizeof. */
|
||||
#undef SIZEOF_SIGNED_INT
|
||||
|
||||
/* The size of `signed long', as computed by sizeof. */
|
||||
#undef SIZEOF_SIGNED_LONG
|
||||
|
||||
/* The size of `signed long long', as computed by sizeof. */
|
||||
#undef SIZEOF_SIGNED_LONG_LONG
|
||||
|
||||
/* The size of `size_t', as computed by sizeof. */
|
||||
#undef SIZEOF_SIZE_T
|
||||
|
||||
/* The size of `unsigned char *', as computed by sizeof. */
|
||||
#undef SIZEOF_UNSIGNED_CHAR_P
|
||||
|
||||
/* The size of `unsigned int', as computed by sizeof. */
|
||||
#undef SIZEOF_UNSIGNED_INT
|
||||
|
||||
/* The size of `unsigned long', as computed by sizeof. */
|
||||
#undef SIZEOF_UNSIGNED_LONG
|
||||
|
||||
/* The size of `unsigned long long', as computed by sizeof. */
|
||||
#undef SIZEOF_UNSIGNED_LONG_LONG
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Support strip chopping (whether or not to convert single-strip uncompressed
|
||||
images to mutiple strips of specified size to reduce memory usage) */
|
||||
#undef STRIPCHOP_DEFAULT
|
||||
|
||||
/* Default size of the strip in bytes (when strip chopping enabled) */
|
||||
#undef STRIP_SIZE_DEFAULT
|
||||
|
||||
/* Enable SubIFD tag (330) support */
|
||||
#undef SUBIFD_SUPPORT
|
||||
|
||||
/* Support ThunderScan 4-bit RLE algorithm */
|
||||
#undef THUNDER_SUPPORT
|
||||
|
||||
/* Signed 16-bit type */
|
||||
#undef TIFF_INT16_T
|
||||
|
||||
/* Signed 32-bit type formatter */
|
||||
#undef TIFF_INT32_FORMAT
|
||||
|
||||
/* Signed 32-bit type */
|
||||
#undef TIFF_INT32_T
|
||||
|
||||
/* Signed 64-bit type formatter */
|
||||
#undef TIFF_INT64_FORMAT
|
||||
|
||||
/* Signed 64-bit type */
|
||||
#undef TIFF_INT64_T
|
||||
|
||||
/* Signed 8-bit type */
|
||||
#undef TIFF_INT8_T
|
||||
|
||||
/* Pointer difference type formatter */
|
||||
#undef TIFF_PTRDIFF_FORMAT
|
||||
|
||||
/* Pointer difference type */
|
||||
#undef TIFF_PTRDIFF_T
|
||||
|
||||
/* Size type formatter */
|
||||
#undef TIFF_SIZE_FORMAT
|
||||
|
||||
/* Unsigned size type */
|
||||
#undef TIFF_SIZE_T
|
||||
|
||||
/* Signed size type formatter */
|
||||
#undef TIFF_SSIZE_FORMAT
|
||||
|
||||
/* Signed size type */
|
||||
#undef TIFF_SSIZE_T
|
||||
|
||||
/* Unsigned 16-bit type */
|
||||
#undef TIFF_UINT16_T
|
||||
|
||||
/* Unsigned 32-bit type formatter */
|
||||
#undef TIFF_UINT32_FORMAT
|
||||
|
||||
/* Unsigned 32-bit type */
|
||||
#undef TIFF_UINT32_T
|
||||
|
||||
/* Unsigned 64-bit type formatter */
|
||||
#undef TIFF_UINT64_FORMAT
|
||||
|
||||
/* Unsigned 64-bit type */
|
||||
#undef TIFF_UINT64_T
|
||||
|
||||
/* Unsigned 8-bit type */
|
||||
#undef TIFF_UINT8_T
|
||||
|
||||
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#undef TIME_WITH_SYS_TIME
|
||||
|
||||
/* Define to 1 if your <sys/time.h> declares `struct tm'. */
|
||||
#undef TM_IN_SYS_TIME
|
||||
|
||||
/* define to use win32 IO system */
|
||||
#undef USE_WIN32_FILEIO
|
||||
|
||||
/* Version number of package */
|
||||
#undef VERSION
|
||||
|
||||
/* Support webp compression */
|
||||
#undef WEBP_SUPPORT
|
||||
|
||||
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
|
||||
significant byte first (like Motorola and SPARC, unlike Intel). */
|
||||
#if defined AC_APPLE_UNIVERSAL_BUILD
|
||||
# if defined __BIG_ENDIAN__
|
||||
# define WORDS_BIGENDIAN 1
|
||||
# endif
|
||||
#else
|
||||
# ifndef WORDS_BIGENDIAN
|
||||
# undef WORDS_BIGENDIAN
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Define to 1 if the X Window System is missing or not being used. */
|
||||
#undef X_DISPLAY_MISSING
|
||||
|
||||
/* Support Deflate compression */
|
||||
#undef ZIP_SUPPORT
|
||||
|
||||
/* Support zstd compression */
|
||||
#undef ZSTD_SUPPORT
|
||||
|
||||
/* Enable large inode numbers on Mac OS X 10.5. */
|
||||
#ifndef _DARWIN_USE_64_BIT_INODE
|
||||
# define _DARWIN_USE_64_BIT_INODE 1
|
||||
#endif
|
||||
|
||||
/* Number of bits in a file offset, on hosts where this is settable. */
|
||||
#undef _FILE_OFFSET_BITS
|
||||
|
||||
/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
|
||||
#undef _LARGEFILE_SOURCE
|
||||
|
||||
/* Define for large files, on AIX-style hosts. */
|
||||
#undef _LARGE_FILES
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
#undef const
|
||||
|
||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||
#ifndef __cplusplus
|
||||
#undef inline
|
||||
#endif
|
||||
|
||||
/* Define to `long int' if <sys/types.h> does not define. */
|
||||
#undef off_t
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
#undef size_t
|
||||
|
|
@ -29,7 +29,6 @@
|
|||
* (and also some miscellaneous stuff)
|
||||
*/
|
||||
#include "tiffiop.h"
|
||||
#include <float.h>
|
||||
|
||||
/*
|
||||
* These are used in the backwards compatibility code...
|
||||
|
|
@ -47,8 +46,8 @@ setByteArray(void** vpp, void* vp, size_t nmemb, size_t elem_size)
|
|||
*vpp = 0;
|
||||
}
|
||||
if (vp) {
|
||||
tmsize_t bytes = (tmsize_t)(nmemb * elem_size);
|
||||
if (elem_size && bytes / elem_size == nmemb)
|
||||
tmsize_t bytes = _TIFFMultiplySSize(NULL, nmemb, elem_size, NULL);
|
||||
if (bytes)
|
||||
*vpp = (void*) _TIFFmalloc(bytes);
|
||||
if (*vpp)
|
||||
_TIFFmemcpy(*vpp, vp, bytes);
|
||||
|
|
@ -88,13 +87,15 @@ setDoubleArrayOneValue(double** vpp, double value, size_t nmemb)
|
|||
* Install extra samples information.
|
||||
*/
|
||||
static int
|
||||
setExtraSamples(TIFFDirectory* td, va_list ap, uint32* v)
|
||||
setExtraSamples(TIFF* tif, va_list ap, uint32* v)
|
||||
{
|
||||
/* XXX: Unassociated alpha data == 999 is a known Corel Draw bug, see below */
|
||||
#define EXTRASAMPLE_COREL_UNASSALPHA 999
|
||||
|
||||
uint16* va;
|
||||
uint32 i;
|
||||
TIFFDirectory* td = &tif->tif_dir;
|
||||
static const char module[] = "setExtraSamples";
|
||||
|
||||
*v = (uint16) va_arg(ap, uint16_vap);
|
||||
if ((uint16) *v > td->td_samplesperpixel)
|
||||
|
|
@ -116,6 +117,18 @@ setExtraSamples(TIFFDirectory* td, va_list ap, uint32* v)
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ( td->td_transferfunction[0] != NULL && (td->td_samplesperpixel - *v > 1) &&
|
||||
!(td->td_samplesperpixel - td->td_extrasamples > 1))
|
||||
{
|
||||
TIFFWarningExt(tif->tif_clientdata,module,
|
||||
"ExtraSamples tag value is changing, "
|
||||
"but TransferFunction was read with a different value. Cancelling it");
|
||||
TIFFClrFieldBit(tif,FIELD_TRANSFERFUNCTION);
|
||||
_TIFFfree(td->td_transferfunction[0]);
|
||||
td->td_transferfunction[0] = NULL;
|
||||
}
|
||||
|
||||
td->td_extrasamples = (uint16) *v;
|
||||
_TIFFsetShortArray(&td->td_sampleinfo, va, td->td_extrasamples);
|
||||
return 1;
|
||||
|
|
@ -153,15 +166,6 @@ bad:
|
|||
return (0);
|
||||
}
|
||||
|
||||
static float TIFFClampDoubleToFloat( double val )
|
||||
{
|
||||
if( val > FLT_MAX )
|
||||
return FLT_MAX;
|
||||
if( val < -FLT_MAX )
|
||||
return -FLT_MAX;
|
||||
return (float)val;
|
||||
}
|
||||
|
||||
static int
|
||||
_TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
|
||||
{
|
||||
|
|
@ -285,6 +289,18 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
|
|||
_TIFFfree(td->td_smaxsamplevalue);
|
||||
td->td_smaxsamplevalue = NULL;
|
||||
}
|
||||
/* Test if 3 transfer functions instead of just one are now needed
|
||||
See http://bugzilla.maptools.org/show_bug.cgi?id=2820 */
|
||||
if( td->td_transferfunction[0] != NULL && (v - td->td_extrasamples > 1) &&
|
||||
!(td->td_samplesperpixel - td->td_extrasamples > 1))
|
||||
{
|
||||
TIFFWarningExt(tif->tif_clientdata,module,
|
||||
"SamplesPerPixel tag value is changing, "
|
||||
"but TransferFunction was read with a different value. Cancelling it");
|
||||
TIFFClrFieldBit(tif,FIELD_TRANSFERFUNCTION);
|
||||
_TIFFfree(td->td_transferfunction[0]);
|
||||
td->td_transferfunction[0] = NULL;
|
||||
}
|
||||
}
|
||||
td->td_samplesperpixel = (uint16) v;
|
||||
break;
|
||||
|
|
@ -320,13 +336,13 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
|
|||
dblval = va_arg(ap, double);
|
||||
if( dblval < 0 )
|
||||
goto badvaluedouble;
|
||||
td->td_xresolution = TIFFClampDoubleToFloat( dblval );
|
||||
td->td_xresolution = _TIFFClampDoubleToFloat( dblval );
|
||||
break;
|
||||
case TIFFTAG_YRESOLUTION:
|
||||
dblval = va_arg(ap, double);
|
||||
if( dblval < 0 )
|
||||
goto badvaluedouble;
|
||||
td->td_yresolution = TIFFClampDoubleToFloat( dblval );
|
||||
td->td_yresolution = _TIFFClampDoubleToFloat( dblval );
|
||||
break;
|
||||
case TIFFTAG_PLANARCONFIG:
|
||||
v = (uint16) va_arg(ap, uint16_vap);
|
||||
|
|
@ -335,10 +351,10 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
|
|||
td->td_planarconfig = (uint16) v;
|
||||
break;
|
||||
case TIFFTAG_XPOSITION:
|
||||
td->td_xposition = TIFFClampDoubleToFloat( va_arg(ap, double) );
|
||||
td->td_xposition = _TIFFClampDoubleToFloat( va_arg(ap, double) );
|
||||
break;
|
||||
case TIFFTAG_YPOSITION:
|
||||
td->td_yposition = TIFFClampDoubleToFloat( va_arg(ap, double) );
|
||||
td->td_yposition = _TIFFClampDoubleToFloat( va_arg(ap, double) );
|
||||
break;
|
||||
case TIFFTAG_RESOLUTIONUNIT:
|
||||
v = (uint16) va_arg(ap, uint16_vap);
|
||||
|
|
@ -361,7 +377,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
|
|||
_TIFFsetShortArray(&td->td_colormap[2], va_arg(ap, uint16*), v32);
|
||||
break;
|
||||
case TIFFTAG_EXTRASAMPLES:
|
||||
if (!setExtraSamples(td, ap, &v))
|
||||
if (!setExtraSamples(tif, ap, &v))
|
||||
goto badvalue;
|
||||
break;
|
||||
case TIFFTAG_MATTEING:
|
||||
|
|
@ -684,7 +700,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
|
|||
case TIFF_SRATIONAL:
|
||||
case TIFF_FLOAT:
|
||||
{
|
||||
float v2 = TIFFClampDoubleToFloat(va_arg(ap, double));
|
||||
float v2 = _TIFFClampDoubleToFloat(va_arg(ap, double));
|
||||
_TIFFmemcpy(val, &v2, tv_size);
|
||||
}
|
||||
break;
|
||||
|
|
@ -1002,12 +1018,12 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
|
|||
case TIFFTAG_STRIPOFFSETS:
|
||||
case TIFFTAG_TILEOFFSETS:
|
||||
_TIFFFillStriles( tif );
|
||||
*va_arg(ap, uint64**) = td->td_stripoffset;
|
||||
*va_arg(ap, uint64**) = td->td_stripoffset_p;
|
||||
break;
|
||||
case TIFFTAG_STRIPBYTECOUNTS:
|
||||
case TIFFTAG_TILEBYTECOUNTS:
|
||||
_TIFFFillStriles( tif );
|
||||
*va_arg(ap, uint64**) = td->td_stripbytecount;
|
||||
*va_arg(ap, uint64**) = td->td_stripbytecount_p;
|
||||
break;
|
||||
case TIFFTAG_MATTEING:
|
||||
*va_arg(ap, uint16*) =
|
||||
|
|
@ -1266,8 +1282,9 @@ TIFFFreeDirectory(TIFF* tif)
|
|||
CleanupField(td_transferfunction[0]);
|
||||
CleanupField(td_transferfunction[1]);
|
||||
CleanupField(td_transferfunction[2]);
|
||||
CleanupField(td_stripoffset);
|
||||
CleanupField(td_stripbytecount);
|
||||
CleanupField(td_stripoffset_p);
|
||||
CleanupField(td_stripbytecount_p);
|
||||
td->td_stripoffsetbyteallocsize = 0;
|
||||
TIFFClrFieldBit(tif, FIELD_YCBCRSUBSAMPLING);
|
||||
TIFFClrFieldBit(tif, FIELD_YCBCRPOSITIONING);
|
||||
|
||||
|
|
@ -1280,10 +1297,8 @@ TIFFFreeDirectory(TIFF* tif)
|
|||
td->td_customValueCount = 0;
|
||||
CleanupField(td_customValues);
|
||||
|
||||
#if defined(DEFER_STRILE_LOAD)
|
||||
_TIFFmemset( &(td->td_stripoffset_entry), 0, sizeof(TIFFDirEntry));
|
||||
_TIFFmemset( &(td->td_stripbytecount_entry), 0, sizeof(TIFFDirEntry));
|
||||
#endif
|
||||
}
|
||||
#undef CleanupField
|
||||
|
||||
|
|
@ -1371,7 +1386,9 @@ TIFFDefaultDirectory(TIFF* tif)
|
|||
td->td_tilewidth = 0;
|
||||
td->td_tilelength = 0;
|
||||
td->td_tiledepth = 1;
|
||||
#ifdef STRIPBYTECOUNTSORTED_UNUSED
|
||||
td->td_stripbytecountsorted = 1; /* Our own arrays always sorted. */
|
||||
#endif
|
||||
td->td_resolutionunit = RESUNIT_INCH;
|
||||
td->td_sampleformat = SAMPLEFORMAT_UINT;
|
||||
td->td_imagedepth = 1;
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ typedef struct {
|
|||
uint32 toff_long;
|
||||
uint64 toff_long8;
|
||||
} tdir_offset; /* either offset or the data itself if fits */
|
||||
uint8 tdir_ignore; /* flag status to ignore tag when parsing tags in tif_dirread.c */
|
||||
} TIFFDirEntry;
|
||||
|
||||
/*
|
||||
|
|
@ -97,13 +98,14 @@ typedef struct {
|
|||
* number of striles */
|
||||
uint32 td_stripsperimage;
|
||||
uint32 td_nstrips; /* size of offset & bytecount arrays */
|
||||
uint64* td_stripoffset;
|
||||
uint64* td_stripbytecount;
|
||||
uint64* td_stripoffset_p; /* should be accessed with TIFFGetStrileOffset */
|
||||
uint64* td_stripbytecount_p; /* should be accessed with TIFFGetStrileByteCount */
|
||||
uint32 td_stripoffsetbyteallocsize; /* number of elements currently allocated for td_stripoffset/td_stripbytecount. Only used if TIFF_LAZYSTRILELOAD is set */
|
||||
#ifdef STRIPBYTECOUNTSORTED_UNUSED
|
||||
int td_stripbytecountsorted; /* is the bytecount array sorted ascending? */
|
||||
#if defined(DEFER_STRILE_LOAD)
|
||||
#endif
|
||||
TIFFDirEntry td_stripoffset_entry; /* for deferred loading */
|
||||
TIFFDirEntry td_stripbytecount_entry; /* for deferred loading */
|
||||
#endif
|
||||
uint16 td_nsubifd;
|
||||
uint64* td_subifd;
|
||||
/* YCbCr parameters */
|
||||
|
|
@ -118,6 +120,8 @@ typedef struct {
|
|||
|
||||
int td_customValueCount;
|
||||
TIFFTagValue *td_customValues;
|
||||
|
||||
unsigned char td_deferstrilearraywriting; /* see TIFFDeferStrileArrayWriting() */
|
||||
} TIFFDirectory;
|
||||
|
||||
/*
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -28,7 +28,6 @@
|
|||
* Directory Write Support Routines.
|
||||
*/
|
||||
#include "tiffiop.h"
|
||||
#include <float.h>
|
||||
|
||||
#ifdef HAVE_IEEEFP
|
||||
#define TIFFCvtNativeToIEEEFloat(tif, n, fp)
|
||||
|
|
@ -182,6 +181,51 @@ TIFFWriteDirectory(TIFF* tif)
|
|||
return TIFFWriteDirectorySec(tif,TRUE,TRUE,NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is an advanced writing function that must be used in a particular
|
||||
* sequence, and generally together with TIFFForceStrileArrayWriting(),
|
||||
* to make its intended effect. Its aim is to modify the location
|
||||
* where the [Strip/Tile][Offsets/ByteCounts] arrays are located in the file.
|
||||
* More precisely, when TIFFWriteCheck() will be called, the tag entries for
|
||||
* those arrays will be written with type = count = offset = 0 as a temporary
|
||||
* value.
|
||||
*
|
||||
* Its effect is only valid for the current directory, and before
|
||||
* TIFFWriteDirectory() is first called, and will be reset when
|
||||
* changing directory.
|
||||
*
|
||||
* The typical sequence of calls is:
|
||||
* TIFFOpen()
|
||||
* [ TIFFCreateDirectory(tif) ]
|
||||
* Set fields with calls to TIFFSetField(tif, ...)
|
||||
* TIFFDeferStrileArrayWriting(tif)
|
||||
* TIFFWriteCheck(tif, ...)
|
||||
* TIFFWriteDirectory(tif)
|
||||
* ... potentially create other directories and come back to the above directory
|
||||
* TIFFForceStrileArrayWriting(tif): emit the arrays at the end of file
|
||||
*
|
||||
* Returns 1 in case of success, 0 otherwise.
|
||||
*/
|
||||
int TIFFDeferStrileArrayWriting(TIFF* tif)
|
||||
{
|
||||
static const char module[] = "TIFFDeferStrileArrayWriting";
|
||||
if (tif->tif_mode == O_RDONLY)
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
|
||||
"File opened in read-only mode");
|
||||
return 0;
|
||||
}
|
||||
if( tif->tif_diroff != 0 )
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
"Directory has already been written");
|
||||
return 0;
|
||||
}
|
||||
|
||||
tif->tif_dir.td_deferstrilearraywriting = TRUE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Similar to TIFFWriteDirectory(), writes the directory out
|
||||
* but leaves all data structures in memory so that it can be
|
||||
|
|
@ -193,7 +237,7 @@ TIFFCheckpointDirectory(TIFF* tif)
|
|||
{
|
||||
int rc;
|
||||
/* Setup the strips arrays, if they haven't already been. */
|
||||
if (tif->tif_dir.td_stripoffset == NULL)
|
||||
if (tif->tif_dir.td_stripoffset_p == NULL)
|
||||
(void) TIFFSetupStrips(tif);
|
||||
rc = TIFFWriteDirectorySec(tif,TRUE,FALSE,NULL);
|
||||
(void) TIFFSetWriteOffset(tif, TIFFSeekFile(tif, 0, SEEK_END));
|
||||
|
|
@ -528,12 +572,12 @@ TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff)
|
|||
{
|
||||
if (!isTiled(tif))
|
||||
{
|
||||
if (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_STRIPBYTECOUNTS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripbytecount))
|
||||
if (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_STRIPBYTECOUNTS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripbytecount_p))
|
||||
goto bad;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_TILEBYTECOUNTS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripbytecount))
|
||||
if (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_TILEBYTECOUNTS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripbytecount_p))
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
|
|
@ -541,7 +585,7 @@ TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff)
|
|||
{
|
||||
if (!isTiled(tif))
|
||||
{
|
||||
/* td_stripoffset might be NULL in an odd OJPEG case. See
|
||||
/* td_stripoffset_p might be NULL in an odd OJPEG case. See
|
||||
* tif_dirread.c around line 3634.
|
||||
* XXX: OJPEG hack.
|
||||
* If a) compression is OJPEG, b) it's not a tiled TIFF,
|
||||
|
|
@ -552,13 +596,13 @@ TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff)
|
|||
* We can get here when using tiffset on such a file.
|
||||
* See http://bugzilla.maptools.org/show_bug.cgi?id=2500
|
||||
*/
|
||||
if (tif->tif_dir.td_stripoffset != NULL &&
|
||||
!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_STRIPOFFSETS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripoffset))
|
||||
if (tif->tif_dir.td_stripoffset_p != NULL &&
|
||||
!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_STRIPOFFSETS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripoffset_p))
|
||||
goto bad;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_TILEOFFSETS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripoffset))
|
||||
if (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_TILEOFFSETS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripoffset_p))
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
|
|
@ -946,15 +990,6 @@ bad:
|
|||
return(0);
|
||||
}
|
||||
|
||||
static float TIFFClampDoubleToFloat( double val )
|
||||
{
|
||||
if( val > FLT_MAX )
|
||||
return FLT_MAX;
|
||||
if( val < -FLT_MAX )
|
||||
return -FLT_MAX;
|
||||
return (float)val;
|
||||
}
|
||||
|
||||
static int8 TIFFClampDoubleToInt8( double val )
|
||||
{
|
||||
if( val > 127 )
|
||||
|
|
@ -1029,7 +1064,7 @@ TIFFWriteDirectoryTagSampleformatArray(TIFF* tif, uint32* ndir, TIFFDirEntry* di
|
|||
if (tif->tif_dir.td_bitspersample<=32)
|
||||
{
|
||||
for (i = 0; i < count; ++i)
|
||||
((float*)conv)[i] = TIFFClampDoubleToFloat(value[i]);
|
||||
((float*)conv)[i] = _TIFFClampDoubleToFloat(value[i]);
|
||||
ok = TIFFWriteDirectoryTagFloatArray(tif,ndir,dir,tag,count,(float*)conv);
|
||||
}
|
||||
else
|
||||
|
|
@ -1661,22 +1696,52 @@ TIFFWriteDirectoryTagShortLong(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint1
|
|||
return(TIFFWriteDirectoryTagCheckedLong(tif,ndir,dir,tag,value));
|
||||
}
|
||||
|
||||
static int _WriteAsType(TIFF* tif, uint64 strile_size, uint64 uncompressed_threshold)
|
||||
{
|
||||
const uint16 compression = tif->tif_dir.td_compression;
|
||||
if ( compression == COMPRESSION_NONE )
|
||||
{
|
||||
return strile_size > uncompressed_threshold;
|
||||
}
|
||||
else if ( compression == COMPRESSION_JPEG ||
|
||||
compression == COMPRESSION_LZW ||
|
||||
compression == COMPRESSION_ADOBE_DEFLATE ||
|
||||
compression == COMPRESSION_LZMA ||
|
||||
compression == COMPRESSION_LERC ||
|
||||
compression == COMPRESSION_ZSTD ||
|
||||
compression == COMPRESSION_WEBP )
|
||||
{
|
||||
/* For a few select compression types, we assume that in the worst */
|
||||
/* case the compressed size will be 10 times the uncompressed size */
|
||||
/* This is overly pessismistic ! */
|
||||
return strile_size >= uncompressed_threshold / 10;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int WriteAsLong8(TIFF* tif, uint64 strile_size)
|
||||
{
|
||||
return _WriteAsType(tif, strile_size, 0xFFFFFFFFU);
|
||||
}
|
||||
|
||||
static int WriteAsLong4(TIFF* tif, uint64 strile_size)
|
||||
{
|
||||
return _WriteAsType(tif, strile_size, 0xFFFFU);
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* TIFFWriteDirectoryTagLongLong8Array() */
|
||||
/* */
|
||||
/* Write out LONG8 array as LONG8 for BigTIFF or LONG for */
|
||||
/* Classic TIFF with some checking. */
|
||||
/* Write out LONG8 array and write a SHORT/LONG/LONG8 depending */
|
||||
/* on strile size and Classic/BigTIFF mode. */
|
||||
/************************************************************************/
|
||||
|
||||
static int
|
||||
TIFFWriteDirectoryTagLongLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value)
|
||||
{
|
||||
static const char module[] = "TIFFWriteDirectoryTagLongLong8Array";
|
||||
uint64* ma;
|
||||
uint32 mb;
|
||||
uint32* p;
|
||||
uint32* q;
|
||||
int o;
|
||||
int write_aslong4;
|
||||
|
||||
/* is this just a counting pass? */
|
||||
if (dir==NULL)
|
||||
|
|
@ -1685,37 +1750,105 @@ TIFFWriteDirectoryTagLongLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir,
|
|||
return(1);
|
||||
}
|
||||
|
||||
/* We always write LONG8 for BigTIFF, no checking needed. */
|
||||
if( tif->tif_flags&TIFF_BIGTIFF )
|
||||
return TIFFWriteDirectoryTagCheckedLong8Array(tif,ndir,dir,
|
||||
tag,count,value);
|
||||
|
||||
/*
|
||||
** For classic tiff we want to verify everything is in range for LONG
|
||||
** and convert to long format.
|
||||
*/
|
||||
|
||||
p = _TIFFmalloc(count*sizeof(uint32));
|
||||
if (p==NULL)
|
||||
if( tif->tif_dir.td_deferstrilearraywriting )
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata,module,"Out of memory");
|
||||
return(0);
|
||||
return TIFFWriteDirectoryTagData(tif, ndir, dir, tag, TIFF_NOTYPE, 0, 0, NULL);
|
||||
}
|
||||
|
||||
for (q=p, ma=value, mb=0; mb<count; ma++, mb++, q++)
|
||||
if( tif->tif_flags&TIFF_BIGTIFF )
|
||||
{
|
||||
if (*ma>0xFFFFFFFF)
|
||||
int write_aslong8 = 1;
|
||||
/* In the case of ByteCounts array, we may be able to write them on */
|
||||
/* LONG if the strip/tilesize is not too big. */
|
||||
/* Also do that for count > 1 in the case someone would want to create */
|
||||
/* a single-strip file with a growing height, in which case using */
|
||||
/* LONG8 will be safer. */
|
||||
if( count > 1 && tag == TIFFTAG_STRIPBYTECOUNTS )
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata,module,
|
||||
"Attempt to write value larger than 0xFFFFFFFF in Classic TIFF file.");
|
||||
_TIFFfree(p);
|
||||
write_aslong8 = WriteAsLong8(tif, TIFFStripSize64(tif));
|
||||
}
|
||||
else if( count > 1 && tag == TIFFTAG_TILEBYTECOUNTS )
|
||||
{
|
||||
write_aslong8 = WriteAsLong8(tif, TIFFTileSize64(tif));
|
||||
}
|
||||
if( write_aslong8 )
|
||||
{
|
||||
return TIFFWriteDirectoryTagCheckedLong8Array(tif,ndir,dir,
|
||||
tag,count,value);
|
||||
}
|
||||
}
|
||||
|
||||
write_aslong4 = 1;
|
||||
if( count > 1 && tag == TIFFTAG_STRIPBYTECOUNTS )
|
||||
{
|
||||
write_aslong4 = WriteAsLong4(tif, TIFFStripSize64(tif));
|
||||
}
|
||||
else if( count > 1 && tag == TIFFTAG_TILEBYTECOUNTS )
|
||||
{
|
||||
write_aslong4 = WriteAsLong4(tif, TIFFTileSize64(tif));
|
||||
}
|
||||
if( write_aslong4 )
|
||||
{
|
||||
/*
|
||||
** For classic tiff we want to verify everything is in range for LONG
|
||||
** and convert to long format.
|
||||
*/
|
||||
|
||||
uint32* p = _TIFFmalloc(count*sizeof(uint32));
|
||||
uint32* q;
|
||||
uint64* ma;
|
||||
uint32 mb;
|
||||
|
||||
if (p==NULL)
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata,module,"Out of memory");
|
||||
return(0);
|
||||
}
|
||||
*q= (uint32)(*ma);
|
||||
}
|
||||
|
||||
o=TIFFWriteDirectoryTagCheckedLongArray(tif,ndir,dir,tag,count,p);
|
||||
_TIFFfree(p);
|
||||
for (q=p, ma=value, mb=0; mb<count; ma++, mb++, q++)
|
||||
{
|
||||
if (*ma>0xFFFFFFFF)
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata,module,
|
||||
"Attempt to write value larger than 0xFFFFFFFF in LONG array.");
|
||||
_TIFFfree(p);
|
||||
return(0);
|
||||
}
|
||||
*q= (uint32)(*ma);
|
||||
}
|
||||
|
||||
o=TIFFWriteDirectoryTagCheckedLongArray(tif,ndir,dir,tag,count,p);
|
||||
_TIFFfree(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint16* p = _TIFFmalloc(count*sizeof(uint16));
|
||||
uint16* q;
|
||||
uint64* ma;
|
||||
uint32 mb;
|
||||
|
||||
if (p==NULL)
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata,module,"Out of memory");
|
||||
return(0);
|
||||
}
|
||||
|
||||
for (q=p, ma=value, mb=0; mb<count; ma++, mb++, q++)
|
||||
{
|
||||
if (*ma>0xFFFF)
|
||||
{
|
||||
/* Should not happen normally given the check we did before */
|
||||
TIFFErrorExt(tif->tif_clientdata,module,
|
||||
"Attempt to write value larger than 0xFFFF in SHORT array.");
|
||||
_TIFFfree(p);
|
||||
return(0);
|
||||
}
|
||||
*q= (uint16)(*ma);
|
||||
}
|
||||
|
||||
o=TIFFWriteDirectoryTagCheckedShortArray(tif,ndir,dir,tag,count,p);
|
||||
_TIFFfree(p);
|
||||
}
|
||||
|
||||
return(o);
|
||||
}
|
||||
|
|
@ -1893,12 +2026,14 @@ TIFFWriteDirectoryTagTransferfunction(TIFF* tif, uint32* ndir, TIFFDirEntry* dir
|
|||
n=3;
|
||||
if (n==3)
|
||||
{
|
||||
if (!_TIFFmemcmp(tif->tif_dir.td_transferfunction[0],tif->tif_dir.td_transferfunction[2],m*sizeof(uint16)))
|
||||
if (tif->tif_dir.td_transferfunction[2] == NULL ||
|
||||
!_TIFFmemcmp(tif->tif_dir.td_transferfunction[0],tif->tif_dir.td_transferfunction[2],m*sizeof(uint16)))
|
||||
n=2;
|
||||
}
|
||||
if (n==2)
|
||||
{
|
||||
if (!_TIFFmemcmp(tif->tif_dir.td_transferfunction[0],tif->tif_dir.td_transferfunction[1],m*sizeof(uint16)))
|
||||
if (tif->tif_dir.td_transferfunction[1] == NULL ||
|
||||
!_TIFFmemcmp(tif->tif_dir.td_transferfunction[0],tif->tif_dir.td_transferfunction[1],m*sizeof(uint16)))
|
||||
n=1;
|
||||
}
|
||||
if (n==0)
|
||||
|
|
@ -2428,7 +2563,12 @@ TIFFWriteDirectoryTagData(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag
|
|||
dir[m].tdir_count=count;
|
||||
dir[m].tdir_offset.toff_long8 = 0;
|
||||
if (datalength<=((tif->tif_flags&TIFF_BIGTIFF)?0x8U:0x4U))
|
||||
_TIFFmemcpy(&dir[m].tdir_offset,data,datalength);
|
||||
{
|
||||
if( data && datalength )
|
||||
{
|
||||
_TIFFmemcpy(&dir[m].tdir_offset,data,datalength);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64 na,nb;
|
||||
|
|
@ -2820,13 +2960,60 @@ _TIFFRewriteField(TIFF* tif, uint16 tag, TIFFDataType in_datatype,
|
|||
TIFFSwabLong8( &entry_offset );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* When a dummy tag was written due to TIFFDeferStrileArrayWriting() */
|
||||
/* -------------------------------------------------------------------- */
|
||||
if( entry_offset == 0 && entry_count == 0 && entry_type == 0 )
|
||||
{
|
||||
if( tag == TIFFTAG_TILEOFFSETS || tag == TIFFTAG_STRIPOFFSETS )
|
||||
{
|
||||
entry_type = (tif->tif_flags&TIFF_BIGTIFF) ? TIFF_LONG8 : TIFF_LONG;
|
||||
}
|
||||
else
|
||||
{
|
||||
int write_aslong8 = 1;
|
||||
if( count > 1 && tag == TIFFTAG_STRIPBYTECOUNTS )
|
||||
{
|
||||
write_aslong8 = WriteAsLong8(tif, TIFFStripSize64(tif));
|
||||
}
|
||||
else if( count > 1 && tag == TIFFTAG_TILEBYTECOUNTS )
|
||||
{
|
||||
write_aslong8 = WriteAsLong8(tif, TIFFTileSize64(tif));
|
||||
}
|
||||
if( write_aslong8 )
|
||||
{
|
||||
entry_type = TIFF_LONG8;
|
||||
}
|
||||
else
|
||||
{
|
||||
int write_aslong4 = 1;
|
||||
if( count > 1 && tag == TIFFTAG_STRIPBYTECOUNTS )
|
||||
{
|
||||
write_aslong4 = WriteAsLong4(tif, TIFFStripSize64(tif));
|
||||
}
|
||||
else if( count > 1 && tag == TIFFTAG_TILEBYTECOUNTS )
|
||||
{
|
||||
write_aslong4 = WriteAsLong4(tif, TIFFTileSize64(tif));
|
||||
}
|
||||
if( write_aslong4 )
|
||||
{
|
||||
entry_type = TIFF_LONG;
|
||||
}
|
||||
else
|
||||
{
|
||||
entry_type = TIFF_SHORT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* What data type do we want to write this as? */
|
||||
/* -------------------------------------------------------------------- */
|
||||
if( TIFFDataWidth(in_datatype) == 8 && !(tif->tif_flags&TIFF_BIGTIFF) )
|
||||
{
|
||||
if( in_datatype == TIFF_LONG8 )
|
||||
datatype = TIFF_LONG;
|
||||
datatype = entry_type == TIFF_SHORT ? TIFF_SHORT : TIFF_LONG;
|
||||
else if( in_datatype == TIFF_SLONG8 )
|
||||
datatype = TIFF_SLONG;
|
||||
else if( in_datatype == TIFF_IFD8 )
|
||||
|
|
@ -2834,8 +3021,21 @@ _TIFFRewriteField(TIFF* tif, uint16 tag, TIFFDataType in_datatype,
|
|||
else
|
||||
datatype = in_datatype;
|
||||
}
|
||||
else
|
||||
datatype = in_datatype;
|
||||
else
|
||||
{
|
||||
if( in_datatype == TIFF_LONG8 &&
|
||||
(entry_type == TIFF_SHORT || entry_type == TIFF_LONG ||
|
||||
entry_type == TIFF_LONG8 ) )
|
||||
datatype = entry_type;
|
||||
else if( in_datatype == TIFF_SLONG8 &&
|
||||
(entry_type == TIFF_SLONG || entry_type == TIFF_SLONG8 ) )
|
||||
datatype = entry_type;
|
||||
else if( in_datatype == TIFF_IFD8 &&
|
||||
(entry_type == TIFF_IFD || entry_type == TIFF_IFD8 ) )
|
||||
datatype = entry_type;
|
||||
else
|
||||
datatype = in_datatype;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* Prepare buffer of actual data to write. This includes */
|
||||
|
|
@ -2884,6 +3084,29 @@ _TIFFRewriteField(TIFF* tif, uint16 tag, TIFFDataType in_datatype,
|
|||
}
|
||||
}
|
||||
}
|
||||
else if( datatype == TIFF_SHORT && in_datatype == TIFF_LONG8 )
|
||||
{
|
||||
tmsize_t i;
|
||||
|
||||
for( i = 0; i < count; i++ )
|
||||
{
|
||||
((uint16 *) buf_to_write)[i] =
|
||||
(uint16) ((uint64 *) data)[i];
|
||||
if( (uint64) ((uint16 *) buf_to_write)[i] != ((uint64 *) data)[i] )
|
||||
{
|
||||
_TIFFfree( buf_to_write );
|
||||
TIFFErrorExt( tif->tif_clientdata, module,
|
||||
"Value exceeds 16bit range of output type." );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TIFFErrorExt( tif->tif_clientdata, module,
|
||||
"Unhandled type conversion." );
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( TIFFDataWidth(datatype) > 1 && (tif->tif_flags&TIFF_SWAB) )
|
||||
{
|
||||
|
|
@ -2915,6 +3138,23 @@ _TIFFRewriteField(TIFF* tif, uint16 tag, TIFFDataType in_datatype,
|
|||
}
|
||||
}
|
||||
|
||||
if( (tag == TIFFTAG_TILEOFFSETS || tag == TIFFTAG_STRIPOFFSETS) &&
|
||||
tif->tif_dir.td_stripoffset_entry.tdir_count == 0 &&
|
||||
tif->tif_dir.td_stripoffset_entry.tdir_type == 0 &&
|
||||
tif->tif_dir.td_stripoffset_entry.tdir_offset.toff_long8 == 0 )
|
||||
{
|
||||
tif->tif_dir.td_stripoffset_entry.tdir_type = datatype;
|
||||
tif->tif_dir.td_stripoffset_entry.tdir_count = count;
|
||||
}
|
||||
else if( (tag == TIFFTAG_TILEBYTECOUNTS || tag == TIFFTAG_STRIPBYTECOUNTS) &&
|
||||
tif->tif_dir.td_stripbytecount_entry.tdir_count == 0 &&
|
||||
tif->tif_dir.td_stripbytecount_entry.tdir_type == 0 &&
|
||||
tif->tif_dir.td_stripbytecount_entry.tdir_offset.toff_long8 == 0 )
|
||||
{
|
||||
tif->tif_dir.td_stripbytecount_entry.tdir_type = datatype;
|
||||
tif->tif_dir.td_stripbytecount_entry.tdir_count = count;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* If the tag type, and count match, then we just write it out */
|
||||
/* over the old values without altering the directory entry at */
|
||||
|
|
@ -2966,6 +3206,7 @@ _TIFFRewriteField(TIFF* tif, uint16 tag, TIFFDataType in_datatype,
|
|||
/* Adjust the directory entry. */
|
||||
/* -------------------------------------------------------------------- */
|
||||
entry_type = datatype;
|
||||
entry_count = (uint64)count;
|
||||
memcpy( direntry_raw + 2, &entry_type, sizeof(uint16) );
|
||||
if (tif->tif_flags&TIFF_SWAB)
|
||||
TIFFSwabShort( (uint16 *) (direntry_raw + 2) );
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* WARNING, this file was automatically generated by the
|
||||
mkg3states program */
|
||||
#include "tiffiop.h"
|
||||
#include "tiff.h"
|
||||
#include "tif_fax3.h"
|
||||
const TIFFFaxTabEnt TIFFFaxMainTable[128] = {
|
||||
{12,7,0},{3,1,0},{5,3,1},{3,1,0},{2,3,0},{3,1,0},{4,3,1},{3,1,0},{1,4,0},{3,1,0},
|
||||
|
|
|
|||
|
|
@ -45,36 +45,8 @@ TIFFFlush(TIFF* tif)
|
|||
&& !(tif->tif_flags & TIFF_DIRTYDIRECT)
|
||||
&& tif->tif_mode == O_RDWR )
|
||||
{
|
||||
uint64 *offsets=NULL, *sizes=NULL;
|
||||
|
||||
if( TIFFIsTiled(tif) )
|
||||
{
|
||||
if( TIFFGetField( tif, TIFFTAG_TILEOFFSETS, &offsets )
|
||||
&& TIFFGetField( tif, TIFFTAG_TILEBYTECOUNTS, &sizes )
|
||||
&& _TIFFRewriteField( tif, TIFFTAG_TILEOFFSETS, TIFF_LONG8,
|
||||
tif->tif_dir.td_nstrips, offsets )
|
||||
&& _TIFFRewriteField( tif, TIFFTAG_TILEBYTECOUNTS, TIFF_LONG8,
|
||||
tif->tif_dir.td_nstrips, sizes ) )
|
||||
{
|
||||
tif->tif_flags &= ~TIFF_DIRTYSTRIP;
|
||||
tif->tif_flags &= ~TIFF_BEENWRITING;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( TIFFGetField( tif, TIFFTAG_STRIPOFFSETS, &offsets )
|
||||
&& TIFFGetField( tif, TIFFTAG_STRIPBYTECOUNTS, &sizes )
|
||||
&& _TIFFRewriteField( tif, TIFFTAG_STRIPOFFSETS, TIFF_LONG8,
|
||||
tif->tif_dir.td_nstrips, offsets )
|
||||
&& _TIFFRewriteField( tif, TIFFTAG_STRIPBYTECOUNTS, TIFF_LONG8,
|
||||
tif->tif_dir.td_nstrips, sizes ) )
|
||||
{
|
||||
tif->tif_flags &= ~TIFF_DIRTYSTRIP;
|
||||
tif->tif_flags &= ~TIFF_BEENWRITING;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if( TIFFForceStrileArrayWriting(tif) )
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((tif->tif_flags & (TIFF_DIRTYDIRECT|TIFF_DIRTYSTRIP))
|
||||
|
|
@ -84,6 +56,92 @@ TIFFFlush(TIFF* tif)
|
|||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is an advanced writing function that must be used in a particular
|
||||
* sequence, and together with TIFFDeferStrileArrayWriting(),
|
||||
* to make its intended effect. Its aim is to force the writing of
|
||||
* the [Strip/Tile][Offsets/ByteCounts] arrays at the end of the file, when
|
||||
* they have not yet been rewritten.
|
||||
*
|
||||
* The typical sequence of calls is:
|
||||
* TIFFOpen()
|
||||
* [ TIFFCreateDirectory(tif) ]
|
||||
* Set fields with calls to TIFFSetField(tif, ...)
|
||||
* TIFFDeferStrileArrayWriting(tif)
|
||||
* TIFFWriteCheck(tif, ...)
|
||||
* TIFFWriteDirectory(tif)
|
||||
* ... potentially create other directories and come back to the above directory
|
||||
* TIFFForceStrileArrayWriting(tif)
|
||||
*
|
||||
* Returns 1 in case of success, 0 otherwise.
|
||||
*/
|
||||
int TIFFForceStrileArrayWriting(TIFF* tif)
|
||||
{
|
||||
static const char module[] = "TIFFForceStrileArrayWriting";
|
||||
const int isTiled = TIFFIsTiled(tif);
|
||||
|
||||
if (tif->tif_mode == O_RDONLY)
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
|
||||
"File opened in read-only mode");
|
||||
return 0;
|
||||
}
|
||||
if( tif->tif_diroff == 0 )
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
"Directory has not yet been written");
|
||||
return 0;
|
||||
}
|
||||
if( (tif->tif_flags & TIFF_DIRTYDIRECT) != 0 )
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
"Directory has changes other than the strile arrays. "
|
||||
"TIFFRewriteDirectory() should be called instead");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( !(tif->tif_flags & TIFF_DIRTYSTRIP) )
|
||||
{
|
||||
if( !(tif->tif_dir.td_stripoffset_entry.tdir_tag != 0 &&
|
||||
tif->tif_dir.td_stripoffset_entry.tdir_count == 0 &&
|
||||
tif->tif_dir.td_stripoffset_entry.tdir_type == 0 &&
|
||||
tif->tif_dir.td_stripoffset_entry.tdir_offset.toff_long8 == 0 &&
|
||||
tif->tif_dir.td_stripbytecount_entry.tdir_tag != 0 &&
|
||||
tif->tif_dir.td_stripbytecount_entry.tdir_count == 0 &&
|
||||
tif->tif_dir.td_stripbytecount_entry.tdir_type == 0 &&
|
||||
tif->tif_dir.td_stripbytecount_entry.tdir_offset.toff_long8 == 0) )
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
"Function not called together with "
|
||||
"TIFFDeferStrileArrayWriting()");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (tif->tif_dir.td_stripoffset_p == NULL && !TIFFSetupStrips(tif))
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( _TIFFRewriteField( tif,
|
||||
isTiled ? TIFFTAG_TILEOFFSETS :
|
||||
TIFFTAG_STRIPOFFSETS,
|
||||
TIFF_LONG8,
|
||||
tif->tif_dir.td_nstrips,
|
||||
tif->tif_dir.td_stripoffset_p )
|
||||
&& _TIFFRewriteField( tif,
|
||||
isTiled ? TIFFTAG_TILEBYTECOUNTS :
|
||||
TIFFTAG_STRIPBYTECOUNTS,
|
||||
TIFF_LONG8,
|
||||
tif->tif_dir.td_nstrips,
|
||||
tif->tif_dir.td_stripbytecount_p ) )
|
||||
{
|
||||
tif->tif_flags &= ~TIFF_DIRTYSTRIP;
|
||||
tif->tif_flags &= ~TIFF_BEENWRITING;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Flush buffered data to the file.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -755,9 +755,8 @@ gtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
|
|||
uint32 leftmost_tw;
|
||||
|
||||
tilesize = TIFFTileSize(tif);
|
||||
bufsize = TIFFSafeMultiply(tmsize_t,alpha?4:3,tilesize);
|
||||
bufsize = _TIFFMultiplySSize(tif, alpha?4:3,tilesize, "gtTileSeparate");
|
||||
if (bufsize == 0) {
|
||||
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in %s", "gtTileSeparate");
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
@ -950,16 +949,23 @@ gtStripContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
|
|||
fromskew = (w < imagewidth ? imagewidth - w : 0);
|
||||
for (row = 0; row < h; row += nrow)
|
||||
{
|
||||
uint32 temp;
|
||||
rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip;
|
||||
nrow = (row + rowstoread > h ? h - row : rowstoread);
|
||||
nrowsub = nrow;
|
||||
if ((nrowsub%subsamplingver)!=0)
|
||||
nrowsub+=subsamplingver-nrowsub%subsamplingver;
|
||||
temp = (row + img->row_offset)%rowsperstrip + nrowsub;
|
||||
if( scanline > 0 && temp > (size_t)(TIFF_TMSIZE_T_MAX / scanline) )
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in gtStripContig");
|
||||
return 0;
|
||||
}
|
||||
if (_TIFFReadEncodedStripAndAllocBuffer(tif,
|
||||
TIFFComputeStrip(tif,row+img->row_offset, 0),
|
||||
(void**)(&buf),
|
||||
maxstripsize,
|
||||
((row + img->row_offset)%rowsperstrip + nrowsub) * scanline)==(tmsize_t)(-1)
|
||||
temp * scanline)==(tmsize_t)(-1)
|
||||
&& (buf == NULL || img->stoponerr))
|
||||
{
|
||||
ret = 0;
|
||||
|
|
@ -1019,9 +1025,8 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
|
|||
uint16 colorchannels;
|
||||
|
||||
stripsize = TIFFStripSize(tif);
|
||||
bufsize = TIFFSafeMultiply(tmsize_t,alpha?4:3,stripsize);
|
||||
bufsize = _TIFFMultiplySSize(tif,alpha?4:3,stripsize, "gtStripSeparate");
|
||||
if (bufsize == 0) {
|
||||
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in %s", "gtStripSeparate");
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
@ -1053,15 +1058,22 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
|
|||
fromskew = (w < imagewidth ? imagewidth - w : 0);
|
||||
for (row = 0; row < h; row += nrow)
|
||||
{
|
||||
uint32 temp;
|
||||
rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip;
|
||||
nrow = (row + rowstoread > h ? h - row : rowstoread);
|
||||
offset_row = row + img->row_offset;
|
||||
temp = (row + img->row_offset)%rowsperstrip + nrow;
|
||||
if( scanline > 0 && temp > (size_t)(TIFF_TMSIZE_T_MAX / scanline) )
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in gtStripSeparate");
|
||||
return 0;
|
||||
}
|
||||
if( buf == NULL )
|
||||
{
|
||||
if (_TIFFReadEncodedStripAndAllocBuffer(
|
||||
tif, TIFFComputeStrip(tif, offset_row, 0),
|
||||
(void**) &buf, bufsize,
|
||||
((row + img->row_offset)%rowsperstrip + nrow) * scanline)==(tmsize_t)(-1)
|
||||
temp * scanline)==(tmsize_t)(-1)
|
||||
&& (buf == NULL || img->stoponerr))
|
||||
{
|
||||
ret = 0;
|
||||
|
|
@ -1081,7 +1093,7 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
|
|||
}
|
||||
}
|
||||
else if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 0),
|
||||
p0, ((row + img->row_offset)%rowsperstrip + nrow) * scanline)==(tmsize_t)(-1)
|
||||
p0, temp * scanline)==(tmsize_t)(-1)
|
||||
&& img->stoponerr)
|
||||
{
|
||||
ret = 0;
|
||||
|
|
@ -1089,7 +1101,7 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
|
|||
}
|
||||
if (colorchannels > 1
|
||||
&& TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 1),
|
||||
p1, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) == (tmsize_t)(-1)
|
||||
p1, temp * scanline) == (tmsize_t)(-1)
|
||||
&& img->stoponerr)
|
||||
{
|
||||
ret = 0;
|
||||
|
|
@ -1097,7 +1109,7 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
|
|||
}
|
||||
if (colorchannels > 1
|
||||
&& TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 2),
|
||||
p2, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) == (tmsize_t)(-1)
|
||||
p2, temp * scanline) == (tmsize_t)(-1)
|
||||
&& img->stoponerr)
|
||||
{
|
||||
ret = 0;
|
||||
|
|
@ -1106,7 +1118,7 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
|
|||
if (alpha)
|
||||
{
|
||||
if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, colorchannels),
|
||||
pa, ((row + img->row_offset)%rowsperstrip + nrow) * scanline)==(tmsize_t)(-1)
|
||||
pa, temp * scanline)==(tmsize_t)(-1)
|
||||
&& img->stoponerr)
|
||||
{
|
||||
ret = 0;
|
||||
|
|
@ -2957,7 +2969,7 @@ TIFFReadRGBATileExt(TIFF* tif, uint32 col, uint32 row, uint32 * raster, int stop
|
|||
if( !TIFFIsTiled( tif ) )
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif),
|
||||
"Can't use TIFFReadRGBATile() with stripped file.");
|
||||
"Can't use TIFFReadRGBATile() with striped file.");
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -780,12 +780,9 @@ JPEGFixupTagsSubsampling(TIFF* tif)
|
|||
*/
|
||||
static const char module[] = "JPEGFixupTagsSubsampling";
|
||||
struct JPEGFixupTagsSubsamplingData m;
|
||||
uint64 fileoffset = TIFFGetStrileOffset(tif, 0);
|
||||
|
||||
_TIFFFillStriles( tif );
|
||||
|
||||
if( tif->tif_dir.td_stripbytecount == NULL
|
||||
|| tif->tif_dir.td_stripoffset == NULL
|
||||
|| tif->tif_dir.td_stripbytecount[0] == 0 )
|
||||
if( fileoffset == 0 )
|
||||
{
|
||||
/* Do not even try to check if the first strip/tile does not
|
||||
yet exist, as occurs when GDAL has created a new NULL file
|
||||
|
|
@ -804,9 +801,9 @@ JPEGFixupTagsSubsampling(TIFF* tif)
|
|||
}
|
||||
m.buffercurrentbyte=NULL;
|
||||
m.bufferbytesleft=0;
|
||||
m.fileoffset=tif->tif_dir.td_stripoffset[0];
|
||||
m.fileoffset=fileoffset;
|
||||
m.filepositioned=0;
|
||||
m.filebytesleft=tif->tif_dir.td_stripbytecount[0];
|
||||
m.filebytesleft=TIFFGetStrileByteCount(tif, 0);
|
||||
if (!JPEGFixupTagsSubsamplingSec(&m))
|
||||
TIFFWarningExt(tif->tif_clientdata,module,
|
||||
"Unable to auto-correct subsampling values, likely corrupt JPEG compressed data in first strip/tile; auto-correcting skipped");
|
||||
|
|
@ -1566,7 +1563,7 @@ JPEGDecodeRaw(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s)
|
|||
JSAMPLE *outptr = (JSAMPLE*)tmpbuf + clumpoffset;
|
||||
#else
|
||||
JSAMPLE *outptr = (JSAMPLE*)buf + clumpoffset;
|
||||
if (cc < (tmsize_t) (clumpoffset + samples_per_clump*(clumps_per_line-1) + hsamp)) {
|
||||
if (cc < (tmsize_t)(clumpoffset + (tmsize_t)samples_per_clump*(clumps_per_line-1) + hsamp)) {
|
||||
TIFFErrorExt(tif->tif_clientdata, "JPEGDecodeRaw",
|
||||
"application buffer not large enough for all data, possible subsampling issue");
|
||||
return 0;
|
||||
|
|
@ -2126,8 +2123,8 @@ JPEGEncodeRaw(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s)
|
|||
/* data is expected to be supplied in multiples of a clumpline */
|
||||
/* a clumpline is equivalent to v_sampling desubsampled scanlines */
|
||||
/* TODO: the following calculation of bytesperclumpline, should substitute calculation of sp->bytesperline, except that it is per v_sampling lines */
|
||||
bytesperclumpline = (((sp->cinfo.c.image_width+sp->h_sampling-1)/sp->h_sampling)
|
||||
*(sp->h_sampling*sp->v_sampling+2)*sp->cinfo.c.data_precision+7)
|
||||
bytesperclumpline = ((((tmsize_t)sp->cinfo.c.image_width+sp->h_sampling-1)/sp->h_sampling)
|
||||
*((tmsize_t)sp->h_sampling*sp->v_sampling+2)*sp->cinfo.c.data_precision+7)
|
||||
/8;
|
||||
|
||||
nrows = ( cc / bytesperclumpline ) * sp->v_sampling;
|
||||
|
|
|
|||
|
|
@ -742,9 +742,14 @@ LogLuvEncodeTile(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
|
|||
#undef exp2 /* Conflict with C'99 function */
|
||||
#define exp2(x) exp(M_LN2*(x))
|
||||
|
||||
#define itrunc(x,m) ((m)==SGILOGENCODE_NODITHER ? \
|
||||
(int)(x) : \
|
||||
(int)((x) + rand()*(1./RAND_MAX) - .5))
|
||||
static int itrunc(double x, int m)
|
||||
{
|
||||
if( m == SGILOGENCODE_NODITHER )
|
||||
return (int)x;
|
||||
/* Silence CoverityScan warning about bad crypto function */
|
||||
/* coverity[dont_call] */
|
||||
return (int)(x + rand()*(1./RAND_MAX) - .5);
|
||||
}
|
||||
|
||||
#if !LOGLUV_PUBLIC
|
||||
static
|
||||
|
|
@ -1264,16 +1269,10 @@ LogL16GuessDataFmt(TIFFDirectory *td)
|
|||
return (SGILOGDATAFMT_UNKNOWN);
|
||||
}
|
||||
|
||||
|
||||
#define TIFF_SIZE_T_MAX ((size_t) ~ ((size_t)0))
|
||||
#define TIFF_TMSIZE_T_MAX (tmsize_t)(TIFF_SIZE_T_MAX >> 1)
|
||||
|
||||
static tmsize_t
|
||||
multiply_ms(tmsize_t m1, tmsize_t m2)
|
||||
{
|
||||
if( m1 == 0 || m2 > TIFF_TMSIZE_T_MAX / m1 )
|
||||
return 0;
|
||||
return m1 * m2;
|
||||
return _TIFFMultiplySSize(NULL, m1, m2, NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -1507,7 +1506,7 @@ LogLuvSetupEncode(TIFF* tif)
|
|||
switch (td->td_photometric) {
|
||||
case PHOTOMETRIC_LOGLUV:
|
||||
if (!LogLuvInitState(tif))
|
||||
break;
|
||||
return (0);
|
||||
if (td->td_compression == COMPRESSION_SGILOG24) {
|
||||
tif->tif_encoderow = LogLuvEncode24;
|
||||
switch (sp->user_datafmt) {
|
||||
|
|
@ -1540,7 +1539,7 @@ LogLuvSetupEncode(TIFF* tif)
|
|||
break;
|
||||
case PHOTOMETRIC_LOGL:
|
||||
if (!LogL16InitState(tif))
|
||||
break;
|
||||
return (0);
|
||||
tif->tif_encoderow = LogL16Encode;
|
||||
switch (sp->user_datafmt) {
|
||||
case SGILOGDATAFMT_FLOAT:
|
||||
|
|
@ -1556,7 +1555,7 @@ LogLuvSetupEncode(TIFF* tif)
|
|||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
"Inappropriate photometric interpretation %d for SGILog compression; %s",
|
||||
td->td_photometric, "must be either LogLUV or LogL");
|
||||
break;
|
||||
return (0);
|
||||
}
|
||||
sp->encoder_state = 1;
|
||||
return (1);
|
||||
|
|
|
|||
|
|
@ -247,6 +247,8 @@ LZWSetupDecode(TIFF* tif)
|
|||
/*
|
||||
* Zero-out the unused entries
|
||||
*/
|
||||
/* Silence false positive */
|
||||
/* coverity[overrun-buffer-arg] */
|
||||
_TIFFmemset(&sp->dec_codetab[CODE_CLEAR], 0,
|
||||
(CODE_FIRST - CODE_CLEAR) * sizeof (code_t));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -243,6 +243,7 @@ typedef enum {
|
|||
typedef struct {
|
||||
TIFF* tif;
|
||||
int decoder_ok;
|
||||
int error_in_raw_data_decoding;
|
||||
#ifndef LIBJPEG_ENCAP_EXTERNAL
|
||||
JMP_BUF exit_jmpbuf;
|
||||
#endif
|
||||
|
|
@ -678,7 +679,7 @@ OJPEGPreDecode(TIFF* tif, uint16 s)
|
|||
if (OJPEGReadSecondarySos(tif,s)==0)
|
||||
return(0);
|
||||
}
|
||||
if isTiled(tif)
|
||||
if (isTiled(tif))
|
||||
m=tif->tif_curtile;
|
||||
else
|
||||
m=tif->tif_curstrip;
|
||||
|
|
@ -742,6 +743,7 @@ OJPEGPreDecodeSkipRaw(TIFF* tif)
|
|||
}
|
||||
m-=sp->subsampling_convert_clines-sp->subsampling_convert_state;
|
||||
sp->subsampling_convert_state=0;
|
||||
sp->error_in_raw_data_decoding=0;
|
||||
}
|
||||
while (m>=sp->subsampling_convert_clines)
|
||||
{
|
||||
|
|
@ -792,6 +794,10 @@ OJPEGDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s)
|
|||
TIFFErrorExt(tif->tif_clientdata,module,"Cannot decode: decoder not correctly initialized");
|
||||
return 0;
|
||||
}
|
||||
if( sp->error_in_raw_data_decoding )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (sp->libjpeg_jpeg_query_style==0)
|
||||
{
|
||||
if (OJPEGDecodeRaw(tif,buf,cc)==0)
|
||||
|
|
@ -831,8 +837,41 @@ OJPEGDecodeRaw(TIFF* tif, uint8* buf, tmsize_t cc)
|
|||
{
|
||||
if (sp->subsampling_convert_state==0)
|
||||
{
|
||||
if (jpeg_read_raw_data_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),sp->subsampling_convert_ycbcrimage,sp->subsampling_ver*8)==0)
|
||||
const jpeg_decompress_struct* cinfo = &sp->libjpeg_jpeg_decompress_struct;
|
||||
int width = 0;
|
||||
int last_col_width = 0;
|
||||
int jpeg_bytes;
|
||||
int expected_bytes;
|
||||
int i;
|
||||
if (cinfo->MCUs_per_row == 0)
|
||||
{
|
||||
sp->error_in_raw_data_decoding = 1;
|
||||
return 0;
|
||||
}
|
||||
for (i = 0; i < cinfo->comps_in_scan; ++i)
|
||||
{
|
||||
const jpeg_component_info* info = cinfo->cur_comp_info[i];
|
||||
#if JPEG_LIB_VERSION >= 70
|
||||
width += info->MCU_width * info->DCT_h_scaled_size;
|
||||
last_col_width += info->last_col_width * info->DCT_h_scaled_size;
|
||||
#else
|
||||
width += info->MCU_width * info->DCT_scaled_size;
|
||||
last_col_width += info->last_col_width * info->DCT_scaled_size;
|
||||
#endif
|
||||
}
|
||||
jpeg_bytes = (cinfo->MCUs_per_row - 1) * width + last_col_width;
|
||||
expected_bytes = sp->subsampling_convert_clinelenout * sp->subsampling_ver * sp->subsampling_hor;
|
||||
if (jpeg_bytes != expected_bytes)
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata,module,"Inconsistent number of MCU in codestream");
|
||||
sp->error_in_raw_data_decoding = 1;
|
||||
return(0);
|
||||
}
|
||||
if (jpeg_read_raw_data_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),sp->subsampling_convert_ycbcrimage,sp->subsampling_ver*8)==0)
|
||||
{
|
||||
sp->error_in_raw_data_decoding = 1;
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
oy=sp->subsampling_convert_ybuf+sp->subsampling_convert_state*sp->subsampling_ver*sp->subsampling_convert_ylinelen;
|
||||
ocb=sp->subsampling_convert_cbbuf+sp->subsampling_convert_state*sp->subsampling_convert_clinelen;
|
||||
|
|
@ -990,7 +1029,6 @@ OJPEGSubsamplingCorrect(TIFF* tif)
|
|||
OJPEGState* sp=(OJPEGState*)tif->tif_data;
|
||||
uint8 mh;
|
||||
uint8 mv;
|
||||
_TIFFFillStriles( tif );
|
||||
|
||||
assert(sp->subsamplingcorrect_done==0);
|
||||
if ((tif->tif_dir.td_samplesperpixel!=3) || ((tif->tif_dir.td_photometric!=PHOTOMETRIC_YCBCR) &&
|
||||
|
|
@ -1046,7 +1084,7 @@ OJPEGReadHeaderInfo(TIFF* tif)
|
|||
assert(sp->readheader_done==0);
|
||||
sp->image_width=tif->tif_dir.td_imagewidth;
|
||||
sp->image_length=tif->tif_dir.td_imagelength;
|
||||
if isTiled(tif)
|
||||
if (isTiled(tif))
|
||||
{
|
||||
sp->strile_width=tif->tif_dir.td_tilewidth;
|
||||
sp->strile_length=tif->tif_dir.td_tilelength;
|
||||
|
|
@ -1082,6 +1120,12 @@ OJPEGReadHeaderInfo(TIFF* tif)
|
|||
}
|
||||
if (sp->strile_length<sp->image_length)
|
||||
{
|
||||
if (((sp->subsampling_hor!=1) && (sp->subsampling_hor!=2) && (sp->subsampling_hor!=4)) ||
|
||||
((sp->subsampling_ver!=1) && (sp->subsampling_ver!=2) && (sp->subsampling_ver!=4)))
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata,module,"Invalid subsampling values");
|
||||
return(0);
|
||||
}
|
||||
if (sp->strile_length%(sp->subsampling_ver*8)!=0)
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata,module,"Incompatible vertical subsampling and image strip/tile length");
|
||||
|
|
@ -1197,7 +1241,13 @@ OJPEGWriteHeaderInfo(TIFF* tif)
|
|||
sp->subsampling_convert_ybuflen=sp->subsampling_convert_ylinelen*sp->subsampling_convert_ylines;
|
||||
sp->subsampling_convert_cbuflen=sp->subsampling_convert_clinelen*sp->subsampling_convert_clines;
|
||||
sp->subsampling_convert_ycbcrbuflen=sp->subsampling_convert_ybuflen+2*sp->subsampling_convert_cbuflen;
|
||||
sp->subsampling_convert_ycbcrbuf=_TIFFmalloc(sp->subsampling_convert_ycbcrbuflen);
|
||||
/* The calloc is not normally necessary, except in some edge/broken cases */
|
||||
/* for example for a tiled image of height 1 with a tile height of 1 and subsampling_hor=subsampling_ver=2 */
|
||||
/* In that case, libjpeg will only fill the 8 first lines of the 16 lines */
|
||||
/* See https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=16844 */
|
||||
/* Even if this case is allowed (?), its handling is broken because OJPEGPreDecode() should also likely */
|
||||
/* reset subsampling_convert_state to 0 when changing tile. */
|
||||
sp->subsampling_convert_ycbcrbuf=_TIFFcalloc(1, sp->subsampling_convert_ycbcrbuflen);
|
||||
if (sp->subsampling_convert_ycbcrbuf==0)
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata,module,"Out of memory");
|
||||
|
|
@ -1223,10 +1273,11 @@ OJPEGWriteHeaderInfo(TIFF* tif)
|
|||
*m++=sp->subsampling_convert_cbbuf+n*sp->subsampling_convert_clinelen;
|
||||
for (n=0; n<sp->subsampling_convert_clines; n++)
|
||||
*m++=sp->subsampling_convert_crbuf+n*sp->subsampling_convert_clinelen;
|
||||
sp->subsampling_convert_clinelenout=((sp->strile_width+sp->subsampling_hor-1)/sp->subsampling_hor);
|
||||
sp->subsampling_convert_clinelenout=sp->strile_width/sp->subsampling_hor + ((sp->strile_width % sp->subsampling_hor) != 0 ? 1 : 0);
|
||||
sp->subsampling_convert_state=0;
|
||||
sp->error_in_raw_data_decoding=0;
|
||||
sp->bytes_per_line=sp->subsampling_convert_clinelenout*(sp->subsampling_ver*sp->subsampling_hor+2);
|
||||
sp->lines_per_strile=((sp->strile_length+sp->subsampling_ver-1)/sp->subsampling_ver);
|
||||
sp->lines_per_strile=sp->strile_length/sp->subsampling_ver + ((sp->strile_length % sp->subsampling_ver) != 0 ? 1 : 0);
|
||||
sp->subsampling_convert_log=1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1272,7 +1323,9 @@ OJPEGReadHeaderInfoSec(TIFF* tif)
|
|||
}
|
||||
else
|
||||
{
|
||||
if ((sp->jpeg_interchange_format_length==0) || (sp->jpeg_interchange_format+sp->jpeg_interchange_format_length>sp->file_size))
|
||||
if ((sp->jpeg_interchange_format_length==0) ||
|
||||
(sp->jpeg_interchange_format > TIFF_UINT64_MAX - sp->jpeg_interchange_format_length) ||
|
||||
(sp->jpeg_interchange_format+sp->jpeg_interchange_format_length>sp->file_size))
|
||||
sp->jpeg_interchange_format_length=sp->file_size-sp->jpeg_interchange_format;
|
||||
}
|
||||
}
|
||||
|
|
@ -1989,32 +2042,30 @@ OJPEGReadBufferFill(OJPEGState* sp)
|
|||
sp->in_buffer_source=osibsStrile;
|
||||
break;
|
||||
case osibsStrile:
|
||||
if (!_TIFFFillStriles( sp->tif )
|
||||
|| sp->tif->tif_dir.td_stripoffset == NULL
|
||||
|| sp->tif->tif_dir.td_stripbytecount == NULL)
|
||||
return 0;
|
||||
|
||||
if (sp->in_buffer_next_strile==sp->in_buffer_strile_count)
|
||||
sp->in_buffer_source=osibsEof;
|
||||
else
|
||||
{
|
||||
sp->in_buffer_file_pos=sp->tif->tif_dir.td_stripoffset[sp->in_buffer_next_strile];
|
||||
int err = 0;
|
||||
sp->in_buffer_file_pos=TIFFGetStrileOffsetWithErr(sp->tif, sp->in_buffer_next_strile, &err);
|
||||
if( err )
|
||||
return 0;
|
||||
if (sp->in_buffer_file_pos!=0)
|
||||
{
|
||||
uint64 bytecount = TIFFGetStrileByteCountWithErr(sp->tif, sp->in_buffer_next_strile, &err);
|
||||
if( err )
|
||||
return 0;
|
||||
if (sp->in_buffer_file_pos>=sp->file_size)
|
||||
sp->in_buffer_file_pos=0;
|
||||
else if (sp->tif->tif_dir.td_stripbytecount==NULL)
|
||||
else if (bytecount==0)
|
||||
sp->in_buffer_file_togo=sp->file_size-sp->in_buffer_file_pos;
|
||||
else
|
||||
{
|
||||
if (sp->tif->tif_dir.td_stripbytecount == 0) {
|
||||
TIFFErrorExt(sp->tif->tif_clientdata,sp->tif->tif_name,"Strip byte counts are missing");
|
||||
return(0);
|
||||
}
|
||||
sp->in_buffer_file_togo=sp->tif->tif_dir.td_stripbytecount[sp->in_buffer_next_strile];
|
||||
sp->in_buffer_file_togo=bytecount;
|
||||
if (sp->in_buffer_file_togo==0)
|
||||
sp->in_buffer_file_pos=0;
|
||||
else if (sp->in_buffer_file_pos+sp->in_buffer_file_togo>sp->file_size)
|
||||
else if (sp->in_buffer_file_pos > TIFF_UINT64_MAX - sp->in_buffer_file_togo ||
|
||||
sp->in_buffer_file_pos+sp->in_buffer_file_togo>sp->file_size)
|
||||
sp->in_buffer_file_togo=sp->file_size-sp->in_buffer_file_pos;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -131,6 +131,7 @@ TIFFClientOpen(
|
|||
if (!readproc || !writeproc || !seekproc || !closeproc || !sizeproc) {
|
||||
TIFFErrorExt(clientdata, module,
|
||||
"One of the client procedures is NULL pointer.");
|
||||
_TIFFfree(tif);
|
||||
goto bad2;
|
||||
}
|
||||
tif->tif_readproc = readproc;
|
||||
|
|
@ -181,6 +182,8 @@ TIFFClientOpen(
|
|||
* 'h' read TIFF header only, do not load the first IFD
|
||||
* '4' ClassicTIFF for creating a file (default)
|
||||
* '8' BigTIFF for creating a file
|
||||
* 'D' enable use of deferred strip/tile offset/bytecount array loading.
|
||||
* 'O' on-demand loading of values instead of whole array loading (implies D)
|
||||
*
|
||||
* The use of the 'l' and 'b' flags is strongly discouraged.
|
||||
* These flags are provided solely because numerous vendors,
|
||||
|
|
@ -262,7 +265,22 @@ TIFFClientOpen(
|
|||
if (m&O_CREAT)
|
||||
tif->tif_flags |= TIFF_BIGTIFF;
|
||||
break;
|
||||
case 'D':
|
||||
tif->tif_flags |= TIFF_DEFERSTRILELOAD;
|
||||
break;
|
||||
case 'O':
|
||||
if( m == O_RDONLY )
|
||||
tif->tif_flags |= (TIFF_LAZYSTRILELOAD | TIFF_DEFERSTRILELOAD);
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef DEFER_STRILE_LOAD
|
||||
/* Compatibility with old DEFER_STRILE_LOAD compilation flag */
|
||||
/* Probably unneeded, since to the best of my knowledge (E. Rouault) */
|
||||
/* GDAL was the only user of this, and will now use the new 'D' flag */
|
||||
tif->tif_flags |= TIFF_DEFERSTRILELOAD;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Read in TIFF header.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -634,20 +634,16 @@ PixarLogGuessDataFmt(TIFFDirectory *td)
|
|||
return guess;
|
||||
}
|
||||
|
||||
#define TIFF_SIZE_T_MAX ((size_t) ~ ((size_t)0))
|
||||
#define TIFF_TMSIZE_T_MAX (tmsize_t)(TIFF_SIZE_T_MAX >> 1)
|
||||
|
||||
static tmsize_t
|
||||
multiply_ms(tmsize_t m1, tmsize_t m2)
|
||||
{
|
||||
if( m1 == 0 || m2 > TIFF_TMSIZE_T_MAX / m1 )
|
||||
return 0;
|
||||
return m1 * m2;
|
||||
return _TIFFMultiplySSize(NULL, m1, m2, NULL);
|
||||
}
|
||||
|
||||
static tmsize_t
|
||||
add_ms(tmsize_t m1, tmsize_t m2)
|
||||
{
|
||||
assert(m1 >= 0 && m2 >= 0);
|
||||
/* if either input is zero, assume overflow already occurred */
|
||||
if (m1 == 0 || m2 == 0)
|
||||
return 0;
|
||||
|
|
@ -817,9 +813,7 @@ PixarLogDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
|
|||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
"Decoding error at scanline %lu, %s",
|
||||
(unsigned long) tif->tif_row, sp->stream.msg ? sp->stream.msg : "(null)");
|
||||
if (inflateSync(&sp->stream) != Z_OK)
|
||||
return (0);
|
||||
continue;
|
||||
return (0);
|
||||
}
|
||||
if (state != Z_OK) {
|
||||
TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s",
|
||||
|
|
@ -1153,7 +1147,7 @@ PixarLogEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
|
|||
|
||||
llen = sp->stride * td->td_imagewidth;
|
||||
/* Check against the number of elements (of size uint16) of sp->tbuf */
|
||||
if( n > (tmsize_t)(td->td_rowsperstrip * llen) )
|
||||
if( n > ((tmsize_t)td->td_rowsperstrip * llen) )
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
"Too many input bytes provided");
|
||||
|
|
|
|||
|
|
@ -652,8 +652,6 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
|
|||
if (tif->tif_tagmethods.printdir)
|
||||
(*tif->tif_tagmethods.printdir)(tif, fd, flags);
|
||||
|
||||
_TIFFFillStriles( tif );
|
||||
|
||||
if ((flags & TIFFPRINT_STRIPS) &&
|
||||
TIFFFieldSet(tif,FIELD_STRIPOFFSETS)) {
|
||||
uint32 s;
|
||||
|
|
@ -665,13 +663,13 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
|
|||
#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
|
||||
fprintf(fd, " %3lu: [%8I64u, %8I64u]\n",
|
||||
(unsigned long) s,
|
||||
td->td_stripoffset ? (unsigned __int64) td->td_stripoffset[s] : 0,
|
||||
td->td_stripbytecount ? (unsigned __int64) td->td_stripbytecount[s] : 0);
|
||||
(unsigned __int64) TIFFGetStrileOffset(tif, s),
|
||||
(unsigned __int64) TIFFGetStrileByteCount(tif, s));
|
||||
#else
|
||||
fprintf(fd, " %3lu: [%8llu, %8llu]\n",
|
||||
(unsigned long) s,
|
||||
td->td_stripoffset ? (unsigned long long) td->td_stripoffset[s] : 0,
|
||||
td->td_stripbytecount ? (unsigned long long) td->td_stripbytecount[s] : 0);
|
||||
(unsigned long long) TIFFGetStrileOffset(tif, s),
|
||||
(unsigned long long) TIFFGetStrileByteCount(tif, s));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,9 +29,6 @@
|
|||
#include "tiffiop.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define TIFF_SIZE_T_MAX ((size_t) ~ ((size_t)0))
|
||||
#define TIFF_TMSIZE_T_MAX (tmsize_t)(TIFF_SIZE_T_MAX >> 1)
|
||||
|
||||
int TIFFFillStrip(TIFF* tif, uint32 strip);
|
||||
int TIFFFillTile(TIFF* tif, uint32 tile);
|
||||
static int TIFFStartStrip(TIFF* tif, uint32 strip);
|
||||
|
|
@ -49,6 +46,8 @@ TIFFReadRawTile1(TIFF* tif, uint32 tile, void* buf, tmsize_t size, const char* m
|
|||
#define THRESHOLD_MULTIPLIER 10
|
||||
#define MAX_THRESHOLD (THRESHOLD_MULTIPLIER * THRESHOLD_MULTIPLIER * THRESHOLD_MULTIPLIER * INITIAL_THRESHOLD)
|
||||
|
||||
#define TIFF_INT64_MAX ((((int64)0x7FFFFFFF) << 32) | 0xFFFFFFFF)
|
||||
|
||||
/* Read 'size' bytes in tif_rawdata buffer starting at offset 'rawdata_offset'
|
||||
* Returns 1 in case of success, 0 otherwise. */
|
||||
static int TIFFReadAndRealloc( TIFF* tif, tmsize_t size,
|
||||
|
|
@ -61,6 +60,22 @@ static int TIFFReadAndRealloc( TIFF* tif, tmsize_t size,
|
|||
#endif
|
||||
tmsize_t already_read = 0;
|
||||
|
||||
|
||||
#if SIZEOF_SIZE_T != 8
|
||||
/* On 32 bit processes, if the request is large enough, check against */
|
||||
/* file size */
|
||||
if( size > 1000 * 1000 * 1000 )
|
||||
{
|
||||
uint64 filesize = TIFFGetFileSize(tif);
|
||||
if( (uint64)size >= filesize )
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
"Chunk size requested is larger than file size.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* On 64 bit processes, read first a maximum of 1 MB, then 10 MB, etc */
|
||||
/* so as to avoid allocating too much memory in case the file is too */
|
||||
/* short. We could ask for the file size, but this might be */
|
||||
|
|
@ -103,6 +118,11 @@ static int TIFFReadAndRealloc( TIFF* tif, tmsize_t size,
|
|||
}
|
||||
tif->tif_rawdata = new_rawdata;
|
||||
}
|
||||
if( tif->tif_rawdata == NULL )
|
||||
{
|
||||
/* should not happen in practice but helps CoverityScan */
|
||||
return 0;
|
||||
}
|
||||
|
||||
bytes_read = TIFFReadFile(tif,
|
||||
tif->tif_rawdata + rawdata_offset + already_read, to_read);
|
||||
|
|
@ -170,17 +190,14 @@ TIFFFillStripPartial( TIFF *tif, int strip, tmsize_t read_ahead, int restart )
|
|||
tmsize_t to_read;
|
||||
tmsize_t read_ahead_mod;
|
||||
/* tmsize_t bytecountm; */
|
||||
|
||||
if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount)
|
||||
return 0;
|
||||
|
||||
|
||||
/*
|
||||
* Expand raw data buffer, if needed, to hold data
|
||||
* strip coming from file (perhaps should set upper
|
||||
* bound on the size of a buffer we'll use?).
|
||||
*/
|
||||
|
||||
/* bytecountm=(tmsize_t) td->td_stripbytecount[strip]; */
|
||||
/* bytecountm=(tmsize_t) TIFFGetStrileByteCount(tif, strip); */
|
||||
|
||||
/* Not completely sure where the * 2 comes from, but probably for */
|
||||
/* an exponentional growth strategy of tif_rawdatasize */
|
||||
|
|
@ -224,7 +241,7 @@ TIFFFillStripPartial( TIFF *tif, int strip, tmsize_t read_ahead, int restart )
|
|||
/*
|
||||
** Seek to the point in the file where more data should be read.
|
||||
*/
|
||||
read_offset = td->td_stripoffset[strip]
|
||||
read_offset = TIFFGetStrileOffset(tif, strip)
|
||||
+ tif->tif_rawdataoff + tif->tif_rawdataloaded;
|
||||
|
||||
if (!SeekOK(tif, read_offset)) {
|
||||
|
|
@ -241,10 +258,10 @@ TIFFFillStripPartial( TIFF *tif, int strip, tmsize_t read_ahead, int restart )
|
|||
to_read = read_ahead_mod - unused_data;
|
||||
else
|
||||
to_read = tif->tif_rawdatasize - unused_data;
|
||||
if( (uint64) to_read > td->td_stripbytecount[strip]
|
||||
if( (uint64) to_read > TIFFGetStrileByteCount(tif, strip)
|
||||
- tif->tif_rawdataoff - tif->tif_rawdataloaded )
|
||||
{
|
||||
to_read = (tmsize_t) td->td_stripbytecount[strip]
|
||||
to_read = (tmsize_t) TIFFGetStrileByteCount(tif, strip)
|
||||
- tif->tif_rawdataoff - tif->tif_rawdataloaded;
|
||||
}
|
||||
|
||||
|
|
@ -283,7 +300,7 @@ TIFFFillStripPartial( TIFF *tif, int strip, tmsize_t read_ahead, int restart )
|
|||
/* For JPEG, if there are multiple scans (can generally be known */
|
||||
/* with the read_ahead used), we need to read the whole strip */
|
||||
if( tif->tif_dir.td_compression==COMPRESSION_JPEG &&
|
||||
(uint64)tif->tif_rawcc < td->td_stripbytecount[strip] )
|
||||
(uint64)tif->tif_rawcc < TIFFGetStrileByteCount(tif, strip) )
|
||||
{
|
||||
if( TIFFJPEGIsFullStripRequired(tif) )
|
||||
{
|
||||
|
|
@ -342,9 +359,7 @@ TIFFSeek(TIFF* tif, uint32 row, uint16 sample )
|
|||
* read it a few lines at a time?
|
||||
*/
|
||||
#if defined(CHUNKY_STRIP_READ_SUPPORT)
|
||||
if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount)
|
||||
return 0;
|
||||
whole_strip = tif->tif_dir.td_stripbytecount[strip] < 10
|
||||
whole_strip = TIFFGetStrileByteCount(tif, strip) < 10
|
||||
|| isMapped(tif);
|
||||
if( td->td_compression == COMPRESSION_LERC ||
|
||||
td->td_compression == COMPRESSION_JBIG )
|
||||
|
|
@ -397,7 +412,7 @@ TIFFSeek(TIFF* tif, uint32 row, uint16 sample )
|
|||
else if( !whole_strip )
|
||||
{
|
||||
if( ((tif->tif_rawdata + tif->tif_rawdataloaded) - tif->tif_rawcp) < read_ahead
|
||||
&& (uint64) tif->tif_rawdataoff+tif->tif_rawdataloaded < td->td_stripbytecount[strip] )
|
||||
&& (uint64) tif->tif_rawdataoff+tif->tif_rawdataloaded < TIFFGetStrileByteCount(tif, strip) )
|
||||
{
|
||||
if( !TIFFFillStripPartial(tif,strip,read_ahead,0) )
|
||||
return 0;
|
||||
|
|
@ -594,16 +609,11 @@ static tmsize_t
|
|||
TIFFReadRawStrip1(TIFF* tif, uint32 strip, void* buf, tmsize_t size,
|
||||
const char* module)
|
||||
{
|
||||
TIFFDirectory *td = &tif->tif_dir;
|
||||
|
||||
if (!_TIFFFillStriles( tif ))
|
||||
return ((tmsize_t)(-1));
|
||||
|
||||
assert((tif->tif_flags&TIFF_NOREADRAW)==0);
|
||||
if (!isMapped(tif)) {
|
||||
tmsize_t cc;
|
||||
|
||||
if (!SeekOK(tif, td->td_stripoffset[strip])) {
|
||||
if (!SeekOK(tif, TIFFGetStrileOffset(tif, strip))) {
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
"Seek error at scanline %lu, strip %lu",
|
||||
(unsigned long) tif->tif_row, (unsigned long) strip);
|
||||
|
|
@ -629,8 +639,8 @@ TIFFReadRawStrip1(TIFF* tif, uint32 strip, void* buf, tmsize_t size,
|
|||
} else {
|
||||
tmsize_t ma = 0;
|
||||
tmsize_t n;
|
||||
if ((td->td_stripoffset[strip] > (uint64)TIFF_TMSIZE_T_MAX)||
|
||||
((ma=(tmsize_t)td->td_stripoffset[strip])>tif->tif_size))
|
||||
if ((TIFFGetStrileOffset(tif, strip) > (uint64)TIFF_TMSIZE_T_MAX)||
|
||||
((ma=(tmsize_t)TIFFGetStrileOffset(tif, strip))>tif->tif_size))
|
||||
{
|
||||
n=0;
|
||||
}
|
||||
|
|
@ -674,12 +684,10 @@ static tmsize_t
|
|||
TIFFReadRawStripOrTile2(TIFF* tif, uint32 strip_or_tile, int is_strip,
|
||||
tmsize_t size, const char* module)
|
||||
{
|
||||
TIFFDirectory *td = &tif->tif_dir;
|
||||
|
||||
assert( !isMapped(tif) );
|
||||
assert((tif->tif_flags&TIFF_NOREADRAW)==0);
|
||||
|
||||
if (!SeekOK(tif, td->td_stripoffset[strip_or_tile])) {
|
||||
if (!SeekOK(tif, TIFFGetStrileOffset(tif, strip_or_tile))) {
|
||||
if( is_strip )
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
|
|
@ -715,7 +723,7 @@ TIFFReadRawStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size)
|
|||
{
|
||||
static const char module[] = "TIFFReadRawStrip";
|
||||
TIFFDirectory *td = &tif->tif_dir;
|
||||
uint64 bytecount;
|
||||
uint64 bytecount64;
|
||||
tmsize_t bytecountm;
|
||||
|
||||
if (!TIFFCheckRead(tif, 0))
|
||||
|
|
@ -733,31 +741,23 @@ TIFFReadRawStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size)
|
|||
"Compression scheme does not support access to raw uncompressed data");
|
||||
return ((tmsize_t)(-1));
|
||||
}
|
||||
bytecount = td->td_stripbytecount[strip];
|
||||
if ((int64)bytecount <= 0) {
|
||||
#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
"%I64u: Invalid strip byte count, strip %lu",
|
||||
(unsigned __int64) bytecount,
|
||||
(unsigned long) strip);
|
||||
#else
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
"%llu: Invalid strip byte count, strip %lu",
|
||||
(unsigned long long) bytecount,
|
||||
(unsigned long) strip);
|
||||
#endif
|
||||
return ((tmsize_t)(-1));
|
||||
}
|
||||
bytecountm = (tmsize_t)bytecount;
|
||||
if ((uint64)bytecountm!=bytecount) {
|
||||
TIFFErrorExt(tif->tif_clientdata, module, "Integer overflow");
|
||||
return ((tmsize_t)(-1));
|
||||
}
|
||||
if (size != (tmsize_t)(-1) && size < bytecountm)
|
||||
bytecount64 = TIFFGetStrileByteCount(tif, strip);
|
||||
if (size != (tmsize_t)(-1) && (uint64)size <= bytecount64)
|
||||
bytecountm = size;
|
||||
else
|
||||
bytecountm = _TIFFCastUInt64ToSSize(tif, bytecount64, module);
|
||||
if( bytecountm == 0 ) {
|
||||
return ((tmsize_t)(-1));
|
||||
}
|
||||
return (TIFFReadRawStrip1(tif, strip, buf, bytecountm, module));
|
||||
}
|
||||
|
||||
TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
|
||||
static uint64 NoSantizeSubUInt64(uint64 a, uint64 b)
|
||||
{
|
||||
return a - b;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read the specified strip and setup for decoding. The data buffer is
|
||||
* expanded, as necessary, to hold the strip's data.
|
||||
|
|
@ -768,13 +768,10 @@ TIFFFillStrip(TIFF* tif, uint32 strip)
|
|||
static const char module[] = "TIFFFillStrip";
|
||||
TIFFDirectory *td = &tif->tif_dir;
|
||||
|
||||
if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount)
|
||||
return 0;
|
||||
|
||||
if ((tif->tif_flags&TIFF_NOREADRAW)==0)
|
||||
{
|
||||
uint64 bytecount = td->td_stripbytecount[strip];
|
||||
if ((int64)bytecount <= 0) {
|
||||
uint64 bytecount = TIFFGetStrileByteCount(tif, strip);
|
||||
if( bytecount == 0 || bytecount > (uint64)TIFF_INT64_MAX ) {
|
||||
#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
"Invalid strip byte count %I64u, strip %lu",
|
||||
|
|
@ -801,7 +798,7 @@ TIFFFillStrip(TIFF* tif, uint32 strip)
|
|||
(bytecount - 4096) / 10 > (uint64)stripsize )
|
||||
{
|
||||
uint64 newbytecount = (uint64)stripsize * 10 + 4096;
|
||||
if( (int64)newbytecount >= 0 )
|
||||
if( newbytecount == 0 || newbytecount > (uint64)TIFF_INT64_MAX )
|
||||
{
|
||||
#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
|
||||
TIFFWarningExt(tif->tif_clientdata, module,
|
||||
|
|
@ -826,13 +823,13 @@ TIFFFillStrip(TIFF* tif, uint32 strip)
|
|||
* We must check for overflow, potentially causing
|
||||
* an OOB read. Instead of simple
|
||||
*
|
||||
* td->td_stripoffset[strip]+bytecount > tif->tif_size
|
||||
* TIFFGetStrileOffset(tif, strip)+bytecount > tif->tif_size
|
||||
*
|
||||
* comparison (which can overflow) we do the following
|
||||
* two comparisons:
|
||||
*/
|
||||
if (bytecount > (uint64)tif->tif_size ||
|
||||
td->td_stripoffset[strip] > (uint64)tif->tif_size - bytecount) {
|
||||
TIFFGetStrileOffset(tif, strip) > (uint64)tif->tif_size - bytecount) {
|
||||
/*
|
||||
* This error message might seem strange, but
|
||||
* it's what would happen if a read were done
|
||||
|
|
@ -844,7 +841,7 @@ TIFFFillStrip(TIFF* tif, uint32 strip)
|
|||
"Read error on strip %lu; "
|
||||
"got %I64u bytes, expected %I64u",
|
||||
(unsigned long) strip,
|
||||
(unsigned __int64) tif->tif_size - td->td_stripoffset[strip],
|
||||
(unsigned __int64) NoSantizeSubUInt64(tif->tif_size, TIFFGetStrileOffset(tif, strip)),
|
||||
(unsigned __int64) bytecount);
|
||||
#else
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
|
|
@ -852,7 +849,7 @@ TIFFFillStrip(TIFF* tif, uint32 strip)
|
|||
"Read error on strip %lu; "
|
||||
"got %llu bytes, expected %llu",
|
||||
(unsigned long) strip,
|
||||
(unsigned long long) tif->tif_size - td->td_stripoffset[strip],
|
||||
(unsigned long long) NoSantizeSubUInt64(tif->tif_size, TIFFGetStrileOffset(tif, strip)),
|
||||
(unsigned long long) bytecount);
|
||||
#endif
|
||||
tif->tif_curstrip = NOSTRIP;
|
||||
|
|
@ -881,7 +878,7 @@ TIFFFillStrip(TIFF* tif, uint32 strip)
|
|||
}
|
||||
tif->tif_flags &= ~TIFF_MYBUFFER;
|
||||
tif->tif_rawdatasize = (tmsize_t)bytecount;
|
||||
tif->tif_rawdata = tif->tif_base + (tmsize_t)td->td_stripoffset[strip];
|
||||
tif->tif_rawdata = tif->tif_base + (tmsize_t)TIFFGetStrileOffset(tif, strip);
|
||||
tif->tif_rawdataoff = 0;
|
||||
tif->tif_rawdataloaded = (tmsize_t) bytecount;
|
||||
|
||||
|
|
@ -1096,16 +1093,11 @@ _TIFFReadEncodedTileAndAllocBuffer(TIFF* tif, uint32 tile,
|
|||
static tmsize_t
|
||||
TIFFReadRawTile1(TIFF* tif, uint32 tile, void* buf, tmsize_t size, const char* module)
|
||||
{
|
||||
TIFFDirectory *td = &tif->tif_dir;
|
||||
|
||||
if (!_TIFFFillStriles( tif ))
|
||||
return ((tmsize_t)(-1));
|
||||
|
||||
assert((tif->tif_flags&TIFF_NOREADRAW)==0);
|
||||
if (!isMapped(tif)) {
|
||||
tmsize_t cc;
|
||||
|
||||
if (!SeekOK(tif, td->td_stripoffset[tile])) {
|
||||
if (!SeekOK(tif, TIFFGetStrileOffset(tif, tile))) {
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
"Seek error at row %lu, col %lu, tile %lu",
|
||||
(unsigned long) tif->tif_row,
|
||||
|
|
@ -1135,9 +1127,9 @@ TIFFReadRawTile1(TIFF* tif, uint32 tile, void* buf, tmsize_t size, const char* m
|
|||
} else {
|
||||
tmsize_t ma,mb;
|
||||
tmsize_t n;
|
||||
ma=(tmsize_t)td->td_stripoffset[tile];
|
||||
ma=(tmsize_t)TIFFGetStrileOffset(tif, tile);
|
||||
mb=ma+size;
|
||||
if ((td->td_stripoffset[tile] > (uint64)TIFF_TMSIZE_T_MAX)||(ma>tif->tif_size))
|
||||
if ((TIFFGetStrileOffset(tif, tile) > (uint64)TIFF_TMSIZE_T_MAX)||(ma>tif->tif_size))
|
||||
n=0;
|
||||
else if ((mb<ma)||(mb<size)||(mb>tif->tif_size))
|
||||
n=tif->tif_size-ma;
|
||||
|
|
@ -1193,13 +1185,12 @@ TIFFReadRawTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size)
|
|||
"Compression scheme does not support access to raw uncompressed data");
|
||||
return ((tmsize_t)(-1));
|
||||
}
|
||||
bytecount64 = td->td_stripbytecount[tile];
|
||||
if (size != (tmsize_t)(-1) && (uint64)size < bytecount64)
|
||||
bytecount64 = (uint64)size;
|
||||
bytecountm = (tmsize_t)bytecount64;
|
||||
if ((uint64)bytecountm!=bytecount64)
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");
|
||||
bytecount64 = TIFFGetStrileByteCount(tif, tile);
|
||||
if (size != (tmsize_t)(-1) && (uint64)size <= bytecount64)
|
||||
bytecountm = size;
|
||||
else
|
||||
bytecountm = _TIFFCastUInt64ToSSize(tif, bytecount64, module);
|
||||
if( bytecountm == 0 ) {
|
||||
return ((tmsize_t)(-1));
|
||||
}
|
||||
return (TIFFReadRawTile1(tif, tile, buf, bytecountm, module));
|
||||
|
|
@ -1215,13 +1206,10 @@ TIFFFillTile(TIFF* tif, uint32 tile)
|
|||
static const char module[] = "TIFFFillTile";
|
||||
TIFFDirectory *td = &tif->tif_dir;
|
||||
|
||||
if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount)
|
||||
return 0;
|
||||
|
||||
if ((tif->tif_flags&TIFF_NOREADRAW)==0)
|
||||
{
|
||||
uint64 bytecount = td->td_stripbytecount[tile];
|
||||
if ((int64)bytecount <= 0) {
|
||||
uint64 bytecount = TIFFGetStrileByteCount(tif, tile);
|
||||
if( bytecount == 0 || bytecount > (uint64)TIFF_INT64_MAX ) {
|
||||
#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
"%I64u: Invalid tile byte count, tile %lu",
|
||||
|
|
@ -1248,7 +1236,7 @@ TIFFFillTile(TIFF* tif, uint32 tile)
|
|||
(bytecount - 4096) / 10 > (uint64)stripsize )
|
||||
{
|
||||
uint64 newbytecount = (uint64)stripsize * 10 + 4096;
|
||||
if( (int64)newbytecount >= 0 )
|
||||
if( newbytecount == 0 || newbytecount > (uint64)TIFF_INT64_MAX )
|
||||
{
|
||||
#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
|
||||
TIFFWarningExt(tif->tif_clientdata, module,
|
||||
|
|
@ -1273,13 +1261,13 @@ TIFFFillTile(TIFF* tif, uint32 tile)
|
|||
* We must check for overflow, potentially causing
|
||||
* an OOB read. Instead of simple
|
||||
*
|
||||
* td->td_stripoffset[tile]+bytecount > tif->tif_size
|
||||
* TIFFGetStrileOffset(tif, tile)+bytecount > tif->tif_size
|
||||
*
|
||||
* comparison (which can overflow) we do the following
|
||||
* two comparisons:
|
||||
*/
|
||||
if (bytecount > (uint64)tif->tif_size ||
|
||||
td->td_stripoffset[tile] > (uint64)tif->tif_size - bytecount) {
|
||||
TIFFGetStrileOffset(tif, tile) > (uint64)tif->tif_size - bytecount) {
|
||||
tif->tif_curtile = NOTILE;
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -1308,7 +1296,7 @@ TIFFFillTile(TIFF* tif, uint32 tile)
|
|||
|
||||
tif->tif_rawdatasize = (tmsize_t)bytecount;
|
||||
tif->tif_rawdata =
|
||||
tif->tif_base + (tmsize_t)td->td_stripoffset[tile];
|
||||
tif->tif_base + (tmsize_t)TIFFGetStrileOffset(tif, tile);
|
||||
tif->tif_rawdataoff = 0;
|
||||
tif->tif_rawdataloaded = (tmsize_t) bytecount;
|
||||
tif->tif_flags |= TIFF_BUFFERMMAP;
|
||||
|
|
@ -1367,7 +1355,8 @@ TIFFFillTile(TIFF* tif, uint32 tile)
|
|||
tif->tif_rawdataoff = 0;
|
||||
tif->tif_rawdataloaded = bytecountm;
|
||||
|
||||
if (!isFillOrder(tif, td->td_fillorder) &&
|
||||
if (tif->tif_rawdata != NULL &&
|
||||
!isFillOrder(tif, td->td_fillorder) &&
|
||||
(tif->tif_flags & TIFF_NOBITREV) == 0)
|
||||
TIFFReverseBits(tif->tif_rawdata,
|
||||
tif->tif_rawdataloaded);
|
||||
|
|
@ -1434,9 +1423,6 @@ TIFFStartStrip(TIFF* tif, uint32 strip)
|
|||
{
|
||||
TIFFDirectory *td = &tif->tif_dir;
|
||||
|
||||
if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount)
|
||||
return 0;
|
||||
|
||||
if ((tif->tif_flags & TIFF_CODERSETUP) == 0) {
|
||||
if (!(*tif->tif_setupdecode)(tif))
|
||||
return (0);
|
||||
|
|
@ -1457,7 +1443,7 @@ TIFFStartStrip(TIFF* tif, uint32 strip)
|
|||
if( tif->tif_rawdataloaded > 0 )
|
||||
tif->tif_rawcc = tif->tif_rawdataloaded;
|
||||
else
|
||||
tif->tif_rawcc = (tmsize_t)td->td_stripbytecount[strip];
|
||||
tif->tif_rawcc = (tmsize_t)TIFFGetStrileByteCount(tif, strip);
|
||||
}
|
||||
return ((*tif->tif_predecode)(tif,
|
||||
(uint16)(strip / td->td_stripsperimage)));
|
||||
|
|
@ -1474,9 +1460,6 @@ TIFFStartTile(TIFF* tif, uint32 tile)
|
|||
TIFFDirectory *td = &tif->tif_dir;
|
||||
uint32 howmany32;
|
||||
|
||||
if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount)
|
||||
return 0;
|
||||
|
||||
if ((tif->tif_flags & TIFF_CODERSETUP) == 0) {
|
||||
if (!(*tif->tif_setupdecode)(tif))
|
||||
return (0);
|
||||
|
|
@ -1507,7 +1490,7 @@ TIFFStartTile(TIFF* tif, uint32 tile)
|
|||
if( tif->tif_rawdataloaded > 0 )
|
||||
tif->tif_rawcc = tif->tif_rawdataloaded;
|
||||
else
|
||||
tif->tif_rawcc = (tmsize_t)td->td_stripbytecount[tile];
|
||||
tif->tif_rawcc = (tmsize_t)TIFFGetStrileByteCount(tif, tile);
|
||||
}
|
||||
return ((*tif->tif_predecode)(tif,
|
||||
(uint16)(tile/td->td_stripsperimage)));
|
||||
|
|
@ -1522,13 +1505,100 @@ TIFFCheckRead(TIFF* tif, int tiles)
|
|||
}
|
||||
if (tiles ^ isTiled(tif)) {
|
||||
TIFFErrorExt(tif->tif_clientdata, tif->tif_name, tiles ?
|
||||
"Can not read tiles from a stripped image" :
|
||||
"Can not read tiles from a striped image" :
|
||||
"Can not read scanlines from a tiled image");
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Use the provided input buffer (inbuf, insize) and decompress it into
|
||||
* (outbuf, outsize).
|
||||
* This function replaces the use of TIFFReadEncodedStrip()/TIFFReadEncodedTile()
|
||||
* when the user can provide the buffer for the input data, for example when
|
||||
* he wants to avoid libtiff to read the strile offset/count values from the
|
||||
* [Strip|Tile][Offsets/ByteCounts] array.
|
||||
* inbuf content must be writable (if bit reversal is needed)
|
||||
* Returns 1 in case of success, 0 otherwise.
|
||||
*/
|
||||
int TIFFReadFromUserBuffer(TIFF* tif, uint32 strile,
|
||||
void* inbuf, tmsize_t insize,
|
||||
void* outbuf, tmsize_t outsize)
|
||||
{
|
||||
static const char module[] = "TIFFReadFromUserBuffer";
|
||||
TIFFDirectory *td = &tif->tif_dir;
|
||||
int ret = 1;
|
||||
uint32 old_tif_flags = tif->tif_flags;
|
||||
tmsize_t old_rawdatasize = tif->tif_rawdatasize;
|
||||
void* old_rawdata = tif->tif_rawdata;
|
||||
|
||||
if (tif->tif_mode == O_WRONLY) {
|
||||
TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "File not open for reading");
|
||||
return 0;
|
||||
}
|
||||
if (tif->tif_flags&TIFF_NOREADRAW)
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
"Compression scheme does not support access to raw uncompressed data");
|
||||
return 0;
|
||||
}
|
||||
|
||||
tif->tif_flags &= ~TIFF_MYBUFFER;
|
||||
tif->tif_flags |= TIFF_BUFFERMMAP;
|
||||
tif->tif_rawdatasize = insize;
|
||||
tif->tif_rawdata = inbuf;
|
||||
tif->tif_rawdataoff = 0;
|
||||
tif->tif_rawdataloaded = insize;
|
||||
|
||||
if (!isFillOrder(tif, td->td_fillorder) &&
|
||||
(tif->tif_flags & TIFF_NOBITREV) == 0)
|
||||
{
|
||||
TIFFReverseBits(inbuf, insize);
|
||||
}
|
||||
|
||||
if( TIFFIsTiled(tif) )
|
||||
{
|
||||
if( !TIFFStartTile(tif, strile) ||
|
||||
!(*tif->tif_decodetile)(tif, (uint8*) outbuf, outsize,
|
||||
(uint16)(strile/td->td_stripsperimage)) )
|
||||
{
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32 rowsperstrip=td->td_rowsperstrip;
|
||||
uint32 stripsperplane;
|
||||
if (rowsperstrip>td->td_imagelength)
|
||||
rowsperstrip=td->td_imagelength;
|
||||
stripsperplane= TIFFhowmany_32_maxuint_compat(td->td_imagelength, rowsperstrip);
|
||||
if( !TIFFStartStrip(tif, strile) ||
|
||||
!(*tif->tif_decodestrip)(tif, (uint8*) outbuf, outsize,
|
||||
(uint16)(strile/stripsperplane)) )
|
||||
{
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
if( ret )
|
||||
{
|
||||
(*tif->tif_postdecode)(tif, (uint8*) outbuf, outsize);
|
||||
}
|
||||
|
||||
if (!isFillOrder(tif, td->td_fillorder) &&
|
||||
(tif->tif_flags & TIFF_NOBITREV) == 0)
|
||||
{
|
||||
TIFFReverseBits(inbuf, insize);
|
||||
}
|
||||
|
||||
tif->tif_flags = old_tif_flags;
|
||||
tif->tif_rawdatasize = old_rawdatasize;
|
||||
tif->tif_rawdata = old_rawdata;
|
||||
tif->tif_rawdataoff = 0;
|
||||
tif->tif_rawdataloaded = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
_TIFFNoPostDecode(TIFF* tif, uint8* buf, tmsize_t cc)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,434 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 1988-1996 Sam Leffler
|
||||
* Copyright (c) 1991-1996 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 UNIX-specific Routines.
|
||||
*/
|
||||
#include "tiffiop.h"
|
||||
#include <iostream>
|
||||
|
||||
#ifndef __VMS
|
||||
using namespace std;
|
||||
#endif
|
||||
|
||||
/*
|
||||
ISO C++ uses a 'std::streamsize' type to define counts. This makes
|
||||
it similar to, (but perhaps not the same as) size_t.
|
||||
|
||||
The std::ios::pos_type is used to represent stream positions as used
|
||||
by tellg(), tellp(), seekg(), and seekp(). This makes it similar to
|
||||
(but perhaps not the same as) 'off_t'. The std::ios::streampos type
|
||||
is used for character streams, but is documented to not be an
|
||||
integral type anymore, so it should *not* be assigned to an integral
|
||||
type.
|
||||
|
||||
The std::ios::off_type is used to specify relative offsets needed by
|
||||
the variants of seekg() and seekp() which accept a relative offset
|
||||
argument.
|
||||
|
||||
Useful prototype knowledge:
|
||||
|
||||
Obtain read position
|
||||
ios::pos_type basic_istream::tellg()
|
||||
|
||||
Set read position
|
||||
basic_istream& basic_istream::seekg(ios::pos_type)
|
||||
basic_istream& basic_istream::seekg(ios::off_type, ios_base::seekdir)
|
||||
|
||||
Read data
|
||||
basic_istream& istream::read(char *str, streamsize count)
|
||||
|
||||
Number of characters read in last unformatted read
|
||||
streamsize istream::gcount();
|
||||
|
||||
Obtain write position
|
||||
ios::pos_type basic_ostream::tellp()
|
||||
|
||||
Set write position
|
||||
basic_ostream& basic_ostream::seekp(ios::pos_type)
|
||||
basic_ostream& basic_ostream::seekp(ios::off_type, ios_base::seekdir)
|
||||
|
||||
Write data
|
||||
basic_ostream& ostream::write(const char *str, streamsize count)
|
||||
*/
|
||||
|
||||
struct tiffis_data;
|
||||
struct tiffos_data;
|
||||
|
||||
extern "C" {
|
||||
|
||||
static tmsize_t _tiffosReadProc(thandle_t, void*, tmsize_t);
|
||||
static tmsize_t _tiffisReadProc(thandle_t fd, void* buf, tmsize_t size);
|
||||
static tmsize_t _tiffosWriteProc(thandle_t fd, void* buf, tmsize_t size);
|
||||
static tmsize_t _tiffisWriteProc(thandle_t, void*, tmsize_t);
|
||||
static uint64 _tiffosSeekProc(thandle_t fd, uint64 off, int whence);
|
||||
static uint64 _tiffisSeekProc(thandle_t fd, uint64 off, int whence);
|
||||
static uint64 _tiffosSizeProc(thandle_t fd);
|
||||
static uint64 _tiffisSizeProc(thandle_t fd);
|
||||
static int _tiffosCloseProc(thandle_t fd);
|
||||
static int _tiffisCloseProc(thandle_t fd);
|
||||
static int _tiffDummyMapProc(thandle_t , void** base, toff_t* size );
|
||||
static void _tiffDummyUnmapProc(thandle_t , void* base, toff_t size );
|
||||
static TIFF* _tiffStreamOpen(const char* name, const char* mode, void *fd);
|
||||
|
||||
struct tiffis_data
|
||||
{
|
||||
istream *stream;
|
||||
ios::pos_type start_pos;
|
||||
};
|
||||
|
||||
struct tiffos_data
|
||||
{
|
||||
ostream *stream;
|
||||
ios::pos_type start_pos;
|
||||
};
|
||||
|
||||
static tmsize_t
|
||||
_tiffosReadProc(thandle_t, void*, tmsize_t)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static tmsize_t
|
||||
_tiffisReadProc(thandle_t fd, void* buf, tmsize_t size)
|
||||
{
|
||||
tiffis_data *data = reinterpret_cast<tiffis_data *>(fd);
|
||||
|
||||
// Verify that type does not overflow.
|
||||
streamsize request_size = size;
|
||||
if (static_cast<tmsize_t>(request_size) != size)
|
||||
return static_cast<tmsize_t>(-1);
|
||||
|
||||
data->stream->read((char *) buf, request_size);
|
||||
|
||||
return static_cast<tmsize_t>(data->stream->gcount());
|
||||
}
|
||||
|
||||
static tmsize_t
|
||||
_tiffosWriteProc(thandle_t fd, void* buf, tmsize_t size)
|
||||
{
|
||||
tiffos_data *data = reinterpret_cast<tiffos_data *>(fd);
|
||||
ostream *os = data->stream;
|
||||
ios::pos_type pos = os->tellp();
|
||||
|
||||
// Verify that type does not overflow.
|
||||
streamsize request_size = size;
|
||||
if (static_cast<tmsize_t>(request_size) != size)
|
||||
return static_cast<tmsize_t>(-1);
|
||||
|
||||
os->write(reinterpret_cast<const char *>(buf), request_size);
|
||||
|
||||
return static_cast<tmsize_t>(os->tellp() - pos);
|
||||
}
|
||||
|
||||
static tmsize_t
|
||||
_tiffisWriteProc(thandle_t, void*, tmsize_t)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint64
|
||||
_tiffosSeekProc(thandle_t fd, uint64 off, int whence)
|
||||
{
|
||||
tiffos_data *data = reinterpret_cast<tiffos_data *>(fd);
|
||||
ostream *os = data->stream;
|
||||
|
||||
// if the stream has already failed, don't do anything
|
||||
if( os->fail() )
|
||||
return static_cast<uint64>(-1);
|
||||
|
||||
switch(whence) {
|
||||
case SEEK_SET:
|
||||
{
|
||||
// Compute 64-bit offset
|
||||
uint64 new_offset = static_cast<uint64>(data->start_pos) + off;
|
||||
|
||||
// Verify that value does not overflow
|
||||
ios::off_type offset = static_cast<ios::off_type>(new_offset);
|
||||
if (static_cast<uint64>(offset) != new_offset)
|
||||
return static_cast<uint64>(-1);
|
||||
|
||||
os->seekp(offset, ios::beg);
|
||||
break;
|
||||
}
|
||||
case SEEK_CUR:
|
||||
{
|
||||
// Verify that value does not overflow
|
||||
ios::off_type offset = static_cast<ios::off_type>(off);
|
||||
if (static_cast<uint64>(offset) != off)
|
||||
return static_cast<uint64>(-1);
|
||||
|
||||
os->seekp(offset, ios::cur);
|
||||
break;
|
||||
}
|
||||
case SEEK_END:
|
||||
{
|
||||
// Verify that value does not overflow
|
||||
ios::off_type offset = static_cast<ios::off_type>(off);
|
||||
if (static_cast<uint64>(offset) != off)
|
||||
return static_cast<uint64>(-1);
|
||||
|
||||
os->seekp(offset, ios::end);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Attempt to workaround problems with seeking past the end of the
|
||||
// stream. ofstream doesn't have a problem with this but
|
||||
// ostrstream/ostringstream does. In that situation, add intermediate
|
||||
// '\0' characters.
|
||||
if( os->fail() ) {
|
||||
#ifdef __VMS
|
||||
int old_state;
|
||||
#else
|
||||
ios::iostate old_state;
|
||||
#endif
|
||||
ios::pos_type origin;
|
||||
|
||||
old_state = os->rdstate();
|
||||
// reset the fail bit or else tellp() won't work below
|
||||
os->clear(os->rdstate() & ~ios::failbit);
|
||||
switch( whence ) {
|
||||
case SEEK_SET:
|
||||
default:
|
||||
origin = data->start_pos;
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
origin = os->tellp();
|
||||
break;
|
||||
case SEEK_END:
|
||||
os->seekp(0, ios::end);
|
||||
origin = os->tellp();
|
||||
break;
|
||||
}
|
||||
// restore original stream state
|
||||
os->clear(old_state);
|
||||
|
||||
// only do something if desired seek position is valid
|
||||
if( (static_cast<uint64>(origin) + off) > static_cast<uint64>(data->start_pos) ) {
|
||||
uint64 num_fill;
|
||||
|
||||
// clear the fail bit
|
||||
os->clear(os->rdstate() & ~ios::failbit);
|
||||
|
||||
// extend the stream to the expected size
|
||||
os->seekp(0, ios::end);
|
||||
num_fill = (static_cast<uint64>(origin)) + off - os->tellp();
|
||||
for( uint64 i = 0; i < num_fill; i++ )
|
||||
os->put('\0');
|
||||
|
||||
// retry the seek
|
||||
os->seekp(static_cast<ios::off_type>(static_cast<uint64>(origin) + off), ios::beg);
|
||||
}
|
||||
}
|
||||
|
||||
return static_cast<uint64>(os->tellp());
|
||||
}
|
||||
|
||||
static uint64
|
||||
_tiffisSeekProc(thandle_t fd, uint64 off, int whence)
|
||||
{
|
||||
tiffis_data *data = reinterpret_cast<tiffis_data *>(fd);
|
||||
|
||||
switch(whence) {
|
||||
case SEEK_SET:
|
||||
{
|
||||
// Compute 64-bit offset
|
||||
uint64 new_offset = static_cast<uint64>(data->start_pos) + off;
|
||||
|
||||
// Verify that value does not overflow
|
||||
ios::off_type offset = static_cast<ios::off_type>(new_offset);
|
||||
if (static_cast<uint64>(offset) != new_offset)
|
||||
return static_cast<uint64>(-1);
|
||||
|
||||
data->stream->seekg(offset, ios::beg);
|
||||
break;
|
||||
}
|
||||
case SEEK_CUR:
|
||||
{
|
||||
// Verify that value does not overflow
|
||||
ios::off_type offset = static_cast<ios::off_type>(off);
|
||||
if (static_cast<uint64>(offset) != off)
|
||||
return static_cast<uint64>(-1);
|
||||
|
||||
data->stream->seekg(offset, ios::cur);
|
||||
break;
|
||||
}
|
||||
case SEEK_END:
|
||||
{
|
||||
// Verify that value does not overflow
|
||||
ios::off_type offset = static_cast<ios::off_type>(off);
|
||||
if (static_cast<uint64>(offset) != off)
|
||||
return static_cast<uint64>(-1);
|
||||
|
||||
data->stream->seekg(offset, ios::end);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (uint64) (data->stream->tellg() - data->start_pos);
|
||||
}
|
||||
|
||||
static uint64
|
||||
_tiffosSizeProc(thandle_t fd)
|
||||
{
|
||||
tiffos_data *data = reinterpret_cast<tiffos_data *>(fd);
|
||||
ostream *os = data->stream;
|
||||
ios::pos_type pos = os->tellp();
|
||||
ios::pos_type len;
|
||||
|
||||
os->seekp(0, ios::end);
|
||||
len = os->tellp();
|
||||
os->seekp(pos);
|
||||
|
||||
return (uint64) len;
|
||||
}
|
||||
|
||||
static uint64
|
||||
_tiffisSizeProc(thandle_t fd)
|
||||
{
|
||||
tiffis_data *data = reinterpret_cast<tiffis_data *>(fd);
|
||||
ios::pos_type pos = data->stream->tellg();
|
||||
ios::pos_type len;
|
||||
|
||||
data->stream->seekg(0, ios::end);
|
||||
len = data->stream->tellg();
|
||||
data->stream->seekg(pos);
|
||||
|
||||
return (uint64) len;
|
||||
}
|
||||
|
||||
static int
|
||||
_tiffosCloseProc(thandle_t fd)
|
||||
{
|
||||
// Our stream was not allocated by us, so it shouldn't be closed by us.
|
||||
delete reinterpret_cast<tiffos_data *>(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_tiffisCloseProc(thandle_t fd)
|
||||
{
|
||||
// Our stream was not allocated by us, so it shouldn't be closed by us.
|
||||
delete reinterpret_cast<tiffis_data *>(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_tiffDummyMapProc(thandle_t , void** base, toff_t* size )
|
||||
{
|
||||
(void) base;
|
||||
(void) size;
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
_tiffDummyUnmapProc(thandle_t , void* base, toff_t size )
|
||||
{
|
||||
(void) base;
|
||||
(void) size;
|
||||
}
|
||||
|
||||
/*
|
||||
* Open a TIFF file descriptor for read/writing.
|
||||
*/
|
||||
static TIFF*
|
||||
_tiffStreamOpen(const char* name, const char* mode, void *fd)
|
||||
{
|
||||
TIFF* tif;
|
||||
|
||||
if( strchr(mode, 'w') ) {
|
||||
tiffos_data *data = new tiffos_data;
|
||||
data->stream = reinterpret_cast<ostream *>(fd);
|
||||
data->start_pos = data->stream->tellp();
|
||||
|
||||
// Open for writing.
|
||||
tif = TIFFClientOpen(name, mode,
|
||||
reinterpret_cast<thandle_t>(data),
|
||||
_tiffosReadProc,
|
||||
_tiffosWriteProc,
|
||||
_tiffosSeekProc,
|
||||
_tiffosCloseProc,
|
||||
_tiffosSizeProc,
|
||||
_tiffDummyMapProc,
|
||||
_tiffDummyUnmapProc);
|
||||
if (!tif) {
|
||||
delete data;
|
||||
}
|
||||
} else {
|
||||
tiffis_data *data = new tiffis_data;
|
||||
data->stream = reinterpret_cast<istream *>(fd);
|
||||
data->start_pos = data->stream->tellg();
|
||||
// Open for reading.
|
||||
tif = TIFFClientOpen(name, mode,
|
||||
reinterpret_cast<thandle_t>(data),
|
||||
_tiffisReadProc,
|
||||
_tiffisWriteProc,
|
||||
_tiffisSeekProc,
|
||||
_tiffisCloseProc,
|
||||
_tiffisSizeProc,
|
||||
_tiffDummyMapProc,
|
||||
_tiffDummyUnmapProc);
|
||||
if (!tif) {
|
||||
delete data;
|
||||
}
|
||||
}
|
||||
|
||||
return (tif);
|
||||
}
|
||||
|
||||
} /* extern "C" */
|
||||
|
||||
TIFF*
|
||||
TIFFStreamOpen(const char* name, ostream *os)
|
||||
{
|
||||
// If os is either a ostrstream or ostringstream, and has no data
|
||||
// written to it yet, then tellp() will return -1 which will break us.
|
||||
// We workaround this by writing out a dummy character and
|
||||
// then seek back to the beginning.
|
||||
if( !os->fail() && static_cast<int>(os->tellp()) < 0 ) {
|
||||
*os << '\0';
|
||||
os->seekp(0);
|
||||
}
|
||||
|
||||
// NB: We don't support mapped files with streams so add 'm'
|
||||
return _tiffStreamOpen(name, "wm", os);
|
||||
}
|
||||
|
||||
TIFF*
|
||||
TIFFStreamOpen(const char* name, istream *is)
|
||||
{
|
||||
// NB: We don't support mapped files with streams so add 'm'
|
||||
return _tiffStreamOpen(name, "rm", is);
|
||||
}
|
||||
|
||||
/* vim: set ts=8 sts=8 sw=8 noet: */
|
||||
/*
|
||||
* Local Variables:
|
||||
* mode: c
|
||||
* c-basic-offset: 8
|
||||
* fill-column: 78
|
||||
* End:
|
||||
*/
|
||||
|
||||
|
|
@ -129,15 +129,8 @@ TIFFVStripSize(TIFF* tif, uint32 nrows)
|
|||
{
|
||||
static const char module[] = "TIFFVStripSize";
|
||||
uint64 m;
|
||||
tmsize_t n;
|
||||
m=TIFFVStripSize64(tif,nrows);
|
||||
n=(tmsize_t)m;
|
||||
if ((uint64)n!=m)
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");
|
||||
n=0;
|
||||
}
|
||||
return(n);
|
||||
return _TIFFCastUInt64ToSSize(tif, m, module);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -147,8 +140,7 @@ uint64
|
|||
TIFFRawStripSize64(TIFF* tif, uint32 strip)
|
||||
{
|
||||
static const char module[] = "TIFFRawStripSize64";
|
||||
TIFFDirectory* td = &tif->tif_dir;
|
||||
uint64 bytecount = td->td_stripbytecount[strip];
|
||||
uint64 bytecount = TIFFGetStrileByteCount(tif, strip);
|
||||
|
||||
if (bytecount == 0)
|
||||
{
|
||||
|
|
@ -211,15 +203,8 @@ TIFFStripSize(TIFF* tif)
|
|||
{
|
||||
static const char module[] = "TIFFStripSize";
|
||||
uint64 m;
|
||||
tmsize_t n;
|
||||
m=TIFFStripSize64(tif);
|
||||
n=(tmsize_t)m;
|
||||
if ((uint64)n!=m)
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");
|
||||
n=0;
|
||||
}
|
||||
return(n);
|
||||
return _TIFFCastUInt64ToSSize(tif, m, module);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -330,14 +315,8 @@ TIFFScanlineSize(TIFF* tif)
|
|||
{
|
||||
static const char module[] = "TIFFScanlineSize";
|
||||
uint64 m;
|
||||
tmsize_t n;
|
||||
m=TIFFScanlineSize64(tif);
|
||||
n=(tmsize_t)m;
|
||||
if ((uint64)n!=m) {
|
||||
TIFFErrorExt(tif->tif_clientdata,module,"Integer arithmetic overflow");
|
||||
n=0;
|
||||
}
|
||||
return(n);
|
||||
return _TIFFCastUInt64ToSSize(tif, m, module);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -366,15 +345,8 @@ TIFFRasterScanlineSize(TIFF* tif)
|
|||
{
|
||||
static const char module[] = "TIFFRasterScanlineSize";
|
||||
uint64 m;
|
||||
tmsize_t n;
|
||||
m=TIFFRasterScanlineSize64(tif);
|
||||
n=(tmsize_t)m;
|
||||
if ((uint64)n!=m)
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata,module,"Integer arithmetic overflow");
|
||||
n=0;
|
||||
}
|
||||
return(n);
|
||||
return _TIFFCastUInt64ToSSize(tif, m, module);
|
||||
}
|
||||
|
||||
/* vim: set ts=8 sts=8 sw=8 noet: */
|
||||
|
|
|
|||
|
|
@ -122,17 +122,17 @@ ThunderDecode(TIFF* tif, uint8* op, tmsize_t maxpixels)
|
|||
break;
|
||||
case THUNDER_2BITDELTAS: /* 2-bit deltas */
|
||||
if ((delta = ((n >> 4) & 3)) != DELTA2_SKIP)
|
||||
SETPIXEL(op, lastpixel + twobitdeltas[delta]);
|
||||
SETPIXEL(op, (unsigned)((int)lastpixel + twobitdeltas[delta]));
|
||||
if ((delta = ((n >> 2) & 3)) != DELTA2_SKIP)
|
||||
SETPIXEL(op, lastpixel + twobitdeltas[delta]);
|
||||
SETPIXEL(op, (unsigned)((int)lastpixel + twobitdeltas[delta]));
|
||||
if ((delta = (n & 3)) != DELTA2_SKIP)
|
||||
SETPIXEL(op, lastpixel + twobitdeltas[delta]);
|
||||
SETPIXEL(op, (unsigned)((int)lastpixel + twobitdeltas[delta]));
|
||||
break;
|
||||
case THUNDER_3BITDELTAS: /* 3-bit deltas */
|
||||
if ((delta = ((n >> 3) & 7)) != DELTA3_SKIP)
|
||||
SETPIXEL(op, lastpixel + threebitdeltas[delta]);
|
||||
SETPIXEL(op, (unsigned)((int)lastpixel + threebitdeltas[delta]));
|
||||
if ((delta = (n & 7)) != DELTA3_SKIP)
|
||||
SETPIXEL(op, lastpixel + threebitdeltas[delta]);
|
||||
SETPIXEL(op, (unsigned)((int)lastpixel + threebitdeltas[delta]));
|
||||
break;
|
||||
case THUNDER_RAW: /* raw data */
|
||||
SETPIXEL(op, n);
|
||||
|
|
|
|||
|
|
@ -181,15 +181,8 @@ TIFFTileRowSize(TIFF* tif)
|
|||
{
|
||||
static const char module[] = "TIFFTileRowSize";
|
||||
uint64 m;
|
||||
tmsize_t n;
|
||||
m=TIFFTileRowSize64(tif);
|
||||
n=(tmsize_t)m;
|
||||
if ((uint64)n!=m)
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");
|
||||
n=0;
|
||||
}
|
||||
return(n);
|
||||
return _TIFFCastUInt64ToSSize(tif, m, module);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -248,15 +241,8 @@ TIFFVTileSize(TIFF* tif, uint32 nrows)
|
|||
{
|
||||
static const char module[] = "TIFFVTileSize";
|
||||
uint64 m;
|
||||
tmsize_t n;
|
||||
m=TIFFVTileSize64(tif,nrows);
|
||||
n=(tmsize_t)m;
|
||||
if ((uint64)n!=m)
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");
|
||||
n=0;
|
||||
}
|
||||
return(n);
|
||||
return _TIFFCastUInt64ToSSize(tif, m, module);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -272,15 +258,8 @@ TIFFTileSize(TIFF* tif)
|
|||
{
|
||||
static const char module[] = "TIFFTileSize";
|
||||
uint64 m;
|
||||
tmsize_t n;
|
||||
m=TIFFTileSize64(tif);
|
||||
n=(tmsize_t)m;
|
||||
if ((uint64)n!=m)
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");
|
||||
n=0;
|
||||
}
|
||||
return(n);
|
||||
return _TIFFCastUInt64ToSSize(tif, m, module);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -349,6 +349,12 @@ TWebPSetupEncode(TIFF* tif)
|
|||
|
||||
sp->state |= LSTATE_INIT_ENCODE;
|
||||
|
||||
if (!WebPPictureInit(&sp->sPicture)) {
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
"Error initializing WebP picture.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!WebPConfigInitInternal(&sp->sEncoderConfig, WEBP_PRESET_DEFAULT,
|
||||
sp->quality_level,
|
||||
WEBP_ENCODER_ABI_VERSION)) {
|
||||
|
|
@ -357,9 +363,13 @@ TWebPSetupEncode(TIFF* tif)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if WEBP_ENCODER_ABI_VERSION >= 0x0100
|
||||
sp->sEncoderConfig.lossless = sp->lossless;
|
||||
#endif
|
||||
// WebPConfigInitInternal above sets lossless to false
|
||||
#if WEBP_ENCODER_ABI_VERSION >= 0x0100
|
||||
sp->sEncoderConfig.lossless = sp->lossless;
|
||||
if (sp->lossless) {
|
||||
sp->sPicture.use_argb = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!WebPValidateConfig(&sp->sEncoderConfig)) {
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
|
|
@ -367,12 +377,6 @@ TWebPSetupEncode(TIFF* tif)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (!WebPPictureInit(&sp->sPicture)) {
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
"Error initializing WebP picture.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -415,6 +419,12 @@ TWebPPreEncode(TIFF* tif, uint16 s)
|
|||
/* set up buffer for raw data */
|
||||
/* given above check and that nSamples <= 4, buffer_size is <= 1 GB */
|
||||
sp->buffer_size = segment_width * segment_height * sp->nSamples;
|
||||
|
||||
if (sp->pBuffer != NULL) {
|
||||
_TIFFfree(sp->pBuffer);
|
||||
sp->pBuffer = NULL;
|
||||
}
|
||||
|
||||
sp->pBuffer = _TIFFmalloc(sp->buffer_size);
|
||||
if( !sp->pBuffer) {
|
||||
TIFFErrorExt(tif->tif_clientdata, module, "Cannot allocate buffer");
|
||||
|
|
@ -460,7 +470,7 @@ TWebPPostEncode(TIFF* tif)
|
|||
"WebPPictureImportRGB() failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (!WebPEncode(&sp->sEncoderConfig, &sp->sPicture)) {
|
||||
|
||||
#if WEBP_ENCODER_ABI_VERSION >= 0x0100
|
||||
|
|
@ -540,15 +550,13 @@ TWebPCleanup(TIFF* tif)
|
|||
}
|
||||
|
||||
if (sp->pBuffer != NULL) {
|
||||
_TIFFfree(sp->pBuffer);
|
||||
sp->pBuffer = NULL;
|
||||
_TIFFfree(sp->pBuffer);
|
||||
sp->pBuffer = NULL;
|
||||
}
|
||||
|
||||
if (tif->tif_data) {
|
||||
_TIFFfree(tif->tif_data);
|
||||
tif->tif_data = NULL;
|
||||
}
|
||||
|
||||
_TIFFfree(tif->tif_data);
|
||||
tif->tif_data = NULL;
|
||||
|
||||
_TIFFSetDefaultCompressionState(tif);
|
||||
}
|
||||
|
||||
|
|
@ -570,6 +578,9 @@ TWebPVSetField(TIFF* tif, uint32 tag, va_list ap)
|
|||
case TIFFTAG_WEBP_LOSSLESS:
|
||||
#if WEBP_ENCODER_ABI_VERSION >= 0x0100
|
||||
sp->lossless = va_arg(ap, int);
|
||||
if (sp->lossless){
|
||||
sp->quality_level = 100.0f;
|
||||
}
|
||||
return 1;
|
||||
#else
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
|
|
|
|||
|
|
@ -128,10 +128,10 @@ TIFFWriteScanline(TIFF* tif, void* buf, uint32 row, uint16 sample)
|
|||
tif->tif_rawcc = 0;
|
||||
tif->tif_rawcp = tif->tif_rawdata;
|
||||
|
||||
if( td->td_stripbytecount[strip] > 0 )
|
||||
if( td->td_stripbytecount_p[strip] > 0 )
|
||||
{
|
||||
/* if we are writing over existing tiles, zero length */
|
||||
td->td_stripbytecount[strip] = 0;
|
||||
td->td_stripbytecount_p[strip] = 0;
|
||||
|
||||
/* this forces TIFFAppendToStrip() to do a seek */
|
||||
tif->tif_curoff = 0;
|
||||
|
|
@ -176,6 +176,32 @@ TIFFWriteScanline(TIFF* tif, void* buf, uint32 row, uint16 sample)
|
|||
return (status);
|
||||
}
|
||||
|
||||
/* Make sure that at the first attempt of rewriting a tile/strip, we will have */
|
||||
/* more bytes available in the output buffer than the previous byte count, */
|
||||
/* so that TIFFAppendToStrip() will detect the overflow when it is called the first */
|
||||
/* time if the new compressed tile is bigger than the older one. (GDAL #4771) */
|
||||
static int _TIFFReserveLargeEnoughWriteBuffer(TIFF* tif, uint32 strip_or_tile)
|
||||
{
|
||||
TIFFDirectory *td = &tif->tif_dir;
|
||||
if( td->td_stripbytecount_p[strip_or_tile] > 0 )
|
||||
{
|
||||
/* The +1 is to ensure at least one extra bytes */
|
||||
/* The +4 is because the LZW encoder flushes 4 bytes before the limit */
|
||||
uint64 safe_buffer_size = (uint64)(td->td_stripbytecount_p[strip_or_tile] + 1 + 4);
|
||||
if( tif->tif_rawdatasize <= (tmsize_t)safe_buffer_size )
|
||||
{
|
||||
if( !(TIFFWriteBufferSetup(tif, NULL,
|
||||
(tmsize_t)TIFFroundup_64(safe_buffer_size, 1024))) )
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Force TIFFAppendToStrip() to consider placing data at end
|
||||
of file. */
|
||||
tif->tif_curoff = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Encode the supplied data and write it to the
|
||||
* specified strip.
|
||||
|
|
@ -222,6 +248,13 @@ TIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc)
|
|||
tif->tif_flags |= TIFF_BUF4WRITE;
|
||||
tif->tif_curstrip = strip;
|
||||
|
||||
if( !_TIFFReserveLargeEnoughWriteBuffer(tif, strip) ) {
|
||||
return ((tmsize_t)(-1));
|
||||
}
|
||||
|
||||
tif->tif_rawcc = 0;
|
||||
tif->tif_rawcp = tif->tif_rawdata;
|
||||
|
||||
if (td->td_stripsperimage == 0) {
|
||||
TIFFErrorExt(tif->tif_clientdata, module, "Zero strips per image");
|
||||
return ((tmsize_t) -1);
|
||||
|
|
@ -234,27 +267,6 @@ TIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc)
|
|||
tif->tif_flags |= TIFF_CODERSETUP;
|
||||
}
|
||||
|
||||
if( td->td_stripbytecount[strip] > 0 )
|
||||
{
|
||||
/* Make sure that at the first attempt of rewriting the tile, we will have */
|
||||
/* more bytes available in the output buffer than the previous byte count, */
|
||||
/* so that TIFFAppendToStrip() will detect the overflow when it is called the first */
|
||||
/* time if the new compressed tile is bigger than the older one. (GDAL #4771) */
|
||||
if( tif->tif_rawdatasize <= (tmsize_t)td->td_stripbytecount[strip] )
|
||||
{
|
||||
if( !(TIFFWriteBufferSetup(tif, NULL,
|
||||
(tmsize_t)TIFFroundup_64((uint64)(td->td_stripbytecount[strip] + 1), 1024))) )
|
||||
return ((tmsize_t)(-1));
|
||||
}
|
||||
|
||||
/* Force TIFFAppendToStrip() to consider placing data at end
|
||||
of file. */
|
||||
tif->tif_curoff = 0;
|
||||
}
|
||||
|
||||
tif->tif_rawcc = 0;
|
||||
tif->tif_rawcp = tif->tif_rawdata;
|
||||
|
||||
tif->tif_flags &= ~TIFF_POSTENCODE;
|
||||
|
||||
/* shortcut to avoid an extra memcpy() */
|
||||
|
|
@ -402,22 +414,8 @@ TIFFWriteEncodedTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc)
|
|||
tif->tif_flags |= TIFF_BUF4WRITE;
|
||||
tif->tif_curtile = tile;
|
||||
|
||||
if( td->td_stripbytecount[tile] > 0 )
|
||||
{
|
||||
/* Make sure that at the first attempt of rewriting the tile, we will have */
|
||||
/* more bytes available in the output buffer than the previous byte count, */
|
||||
/* so that TIFFAppendToStrip() will detect the overflow when it is called the first */
|
||||
/* time if the new compressed tile is bigger than the older one. (GDAL #4771) */
|
||||
if( tif->tif_rawdatasize <= (tmsize_t) td->td_stripbytecount[tile] )
|
||||
{
|
||||
if( !(TIFFWriteBufferSetup(tif, NULL,
|
||||
(tmsize_t)TIFFroundup_64((uint64)(td->td_stripbytecount[tile] + 1), 1024))) )
|
||||
return ((tmsize_t)(-1));
|
||||
}
|
||||
|
||||
/* Force TIFFAppendToStrip() to consider placing data at end
|
||||
of file. */
|
||||
tif->tif_curoff = 0;
|
||||
if( !_TIFFReserveLargeEnoughWriteBuffer(tif, tile) ) {
|
||||
return ((tmsize_t)(-1));
|
||||
}
|
||||
|
||||
tif->tif_rawcc = 0;
|
||||
|
|
@ -537,20 +535,20 @@ TIFFSetupStrips(TIFF* tif)
|
|||
td->td_nstrips = td->td_stripsperimage;
|
||||
if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
|
||||
td->td_stripsperimage /= td->td_samplesperpixel;
|
||||
td->td_stripoffset = (uint64 *)
|
||||
td->td_stripoffset_p = (uint64 *)
|
||||
_TIFFCheckMalloc(tif, td->td_nstrips, sizeof (uint64),
|
||||
"for \"StripOffsets\" array");
|
||||
td->td_stripbytecount = (uint64 *)
|
||||
td->td_stripbytecount_p = (uint64 *)
|
||||
_TIFFCheckMalloc(tif, td->td_nstrips, sizeof (uint64),
|
||||
"for \"StripByteCounts\" array");
|
||||
if (td->td_stripoffset == NULL || td->td_stripbytecount == NULL)
|
||||
if (td->td_stripoffset_p == NULL || td->td_stripbytecount_p == NULL)
|
||||
return (0);
|
||||
/*
|
||||
* Place data at the end-of-file
|
||||
* (by setting offsets to zero).
|
||||
*/
|
||||
_TIFFmemset(td->td_stripoffset, 0, td->td_nstrips*sizeof (uint64));
|
||||
_TIFFmemset(td->td_stripbytecount, 0, td->td_nstrips*sizeof (uint64));
|
||||
_TIFFmemset(td->td_stripoffset_p, 0, td->td_nstrips*sizeof (uint64));
|
||||
_TIFFmemset(td->td_stripbytecount_p, 0, td->td_nstrips*sizeof (uint64));
|
||||
TIFFSetFieldBit(tif, FIELD_STRIPOFFSETS);
|
||||
TIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS);
|
||||
return (1);
|
||||
|
|
@ -572,7 +570,7 @@ TIFFWriteCheck(TIFF* tif, int tiles, const char* module)
|
|||
}
|
||||
if (tiles ^ isTiled(tif)) {
|
||||
TIFFErrorExt(tif->tif_clientdata, module, tiles ?
|
||||
"Can not write tiles to a stripped image" :
|
||||
"Can not write tiles to a striped image" :
|
||||
"Can not write scanlines to a tiled image");
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -610,7 +608,7 @@ TIFFWriteCheck(TIFF* tif, int tiles, const char* module)
|
|||
return (0);
|
||||
}
|
||||
}
|
||||
if (tif->tif_dir.td_stripoffset == NULL && !TIFFSetupStrips(tif)) {
|
||||
if (tif->tif_dir.td_stripoffset_p == NULL && !TIFFSetupStrips(tif)) {
|
||||
tif->tif_dir.td_nstrips = 0;
|
||||
TIFFErrorExt(tif->tif_clientdata, module, "No space for %s arrays",
|
||||
isTiled(tif) ? "tile" : "strip");
|
||||
|
|
@ -628,6 +626,20 @@ TIFFWriteCheck(TIFF* tif, int tiles, const char* module)
|
|||
if (tif->tif_scanlinesize == 0)
|
||||
return (0);
|
||||
tif->tif_flags |= TIFF_BEENWRITING;
|
||||
|
||||
if( tif->tif_dir.td_stripoffset_entry.tdir_tag != 0 &&
|
||||
tif->tif_dir.td_stripoffset_entry.tdir_count == 0 &&
|
||||
tif->tif_dir.td_stripoffset_entry.tdir_type == 0 &&
|
||||
tif->tif_dir.td_stripoffset_entry.tdir_offset.toff_long8 == 0 &&
|
||||
tif->tif_dir.td_stripbytecount_entry.tdir_tag != 0 &&
|
||||
tif->tif_dir.td_stripbytecount_entry.tdir_count == 0 &&
|
||||
tif->tif_dir.td_stripbytecount_entry.tdir_type == 0 &&
|
||||
tif->tif_dir.td_stripbytecount_entry.tdir_offset.toff_long8 == 0 &&
|
||||
!(tif->tif_flags & TIFF_DIRTYDIRECT) )
|
||||
{
|
||||
TIFFForceStrileArrayWriting(tif);
|
||||
}
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
|
@ -684,9 +696,9 @@ TIFFGrowStrips(TIFF* tif, uint32 delta, const char* module)
|
|||
uint64* new_stripbytecount;
|
||||
|
||||
assert(td->td_planarconfig == PLANARCONFIG_CONTIG);
|
||||
new_stripoffset = (uint64*)_TIFFrealloc(td->td_stripoffset,
|
||||
new_stripoffset = (uint64*)_TIFFrealloc(td->td_stripoffset_p,
|
||||
(td->td_nstrips + delta) * sizeof (uint64));
|
||||
new_stripbytecount = (uint64*)_TIFFrealloc(td->td_stripbytecount,
|
||||
new_stripbytecount = (uint64*)_TIFFrealloc(td->td_stripbytecount_p,
|
||||
(td->td_nstrips + delta) * sizeof (uint64));
|
||||
if (new_stripoffset == NULL || new_stripbytecount == NULL) {
|
||||
if (new_stripoffset)
|
||||
|
|
@ -697,11 +709,11 @@ TIFFGrowStrips(TIFF* tif, uint32 delta, const char* module)
|
|||
TIFFErrorExt(tif->tif_clientdata, module, "No space to expand strip arrays");
|
||||
return (0);
|
||||
}
|
||||
td->td_stripoffset = new_stripoffset;
|
||||
td->td_stripbytecount = new_stripbytecount;
|
||||
_TIFFmemset(td->td_stripoffset + td->td_nstrips,
|
||||
td->td_stripoffset_p = new_stripoffset;
|
||||
td->td_stripbytecount_p = new_stripbytecount;
|
||||
_TIFFmemset(td->td_stripoffset_p + td->td_nstrips,
|
||||
0, delta*sizeof (uint64));
|
||||
_TIFFmemset(td->td_stripbytecount + td->td_nstrips,
|
||||
_TIFFmemset(td->td_stripbytecount_p + td->td_nstrips,
|
||||
0, delta*sizeof (uint64));
|
||||
td->td_nstrips += delta;
|
||||
tif->tif_flags |= TIFF_DIRTYDIRECT;
|
||||
|
|
@ -720,12 +732,12 @@ TIFFAppendToStrip(TIFF* tif, uint32 strip, uint8* data, tmsize_t cc)
|
|||
uint64 m;
|
||||
int64 old_byte_count = -1;
|
||||
|
||||
if (td->td_stripoffset[strip] == 0 || tif->tif_curoff == 0) {
|
||||
if (td->td_stripoffset_p[strip] == 0 || tif->tif_curoff == 0) {
|
||||
assert(td->td_nstrips > 0);
|
||||
|
||||
if( td->td_stripbytecount[strip] != 0
|
||||
&& td->td_stripoffset[strip] != 0
|
||||
&& td->td_stripbytecount[strip] >= (uint64) cc )
|
||||
if( td->td_stripbytecount_p[strip] != 0
|
||||
&& td->td_stripoffset_p[strip] != 0
|
||||
&& td->td_stripbytecount_p[strip] >= (uint64) cc )
|
||||
{
|
||||
/*
|
||||
* There is already tile data on disk, and the new tile
|
||||
|
|
@ -734,7 +746,7 @@ TIFFAppendToStrip(TIFF* tif, uint32 strip, uint8* data, tmsize_t cc)
|
|||
* more data to append to this strip before we are done
|
||||
* depending on how we are getting called.
|
||||
*/
|
||||
if (!SeekOK(tif, td->td_stripoffset[strip])) {
|
||||
if (!SeekOK(tif, td->td_stripoffset_p[strip])) {
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
"Seek error at scanline %lu",
|
||||
(unsigned long)tif->tif_row);
|
||||
|
|
@ -747,17 +759,17 @@ TIFFAppendToStrip(TIFF* tif, uint32 strip, uint8* data, tmsize_t cc)
|
|||
* Seek to end of file, and set that as our location to
|
||||
* write this strip.
|
||||
*/
|
||||
td->td_stripoffset[strip] = TIFFSeekFile(tif, 0, SEEK_END);
|
||||
td->td_stripoffset_p[strip] = TIFFSeekFile(tif, 0, SEEK_END);
|
||||
tif->tif_flags |= TIFF_DIRTYSTRIP;
|
||||
}
|
||||
|
||||
tif->tif_curoff = td->td_stripoffset[strip];
|
||||
tif->tif_curoff = td->td_stripoffset_p[strip];
|
||||
|
||||
/*
|
||||
* We are starting a fresh strip/tile, so set the size to zero.
|
||||
*/
|
||||
old_byte_count = td->td_stripbytecount[strip];
|
||||
td->td_stripbytecount[strip] = 0;
|
||||
old_byte_count = td->td_stripbytecount_p[strip];
|
||||
td->td_stripbytecount_p[strip] = 0;
|
||||
}
|
||||
|
||||
m = tif->tif_curoff+cc;
|
||||
|
|
@ -774,9 +786,9 @@ TIFFAppendToStrip(TIFF* tif, uint32 strip, uint8* data, tmsize_t cc)
|
|||
return (0);
|
||||
}
|
||||
tif->tif_curoff = m;
|
||||
td->td_stripbytecount[strip] += cc;
|
||||
td->td_stripbytecount_p[strip] += cc;
|
||||
|
||||
if( (int64) td->td_stripbytecount[strip] != old_byte_count )
|
||||
if( (int64) td->td_stripbytecount_p[strip] != old_byte_count )
|
||||
tif->tif_flags |= TIFF_DIRTYSTRIP;
|
||||
|
||||
return (1);
|
||||
|
|
|
|||
|
|
@ -124,7 +124,6 @@ ZIPSetupDecode(TIFF* tif)
|
|||
static int
|
||||
ZIPPreDecode(TIFF* tif, uint16 s)
|
||||
{
|
||||
static const char module[] = "ZIPPreDecode";
|
||||
ZIPState* sp = DecoderState(tif);
|
||||
|
||||
(void) s;
|
||||
|
|
@ -138,12 +137,7 @@ ZIPPreDecode(TIFF* tif, uint16 s)
|
|||
we need to simplify this code to reflect a ZLib that is likely updated
|
||||
to deal with 8byte memory sizes, though this code will respond
|
||||
appropriately even before we simplify it */
|
||||
sp->stream.avail_in = (uInt) tif->tif_rawcc;
|
||||
if ((tmsize_t)sp->stream.avail_in != tif->tif_rawcc)
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size");
|
||||
return (0);
|
||||
}
|
||||
sp->stream.avail_in = (uint64)tif->tif_rawcc < 0xFFFFFFFFU ? (uInt) tif->tif_rawcc : 0xFFFFFFFFU;
|
||||
return (inflateReset(&sp->stream) == Z_OK);
|
||||
}
|
||||
|
||||
|
|
@ -158,46 +152,43 @@ ZIPDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
|
|||
assert(sp->state == ZSTATE_INIT_DECODE);
|
||||
|
||||
sp->stream.next_in = tif->tif_rawcp;
|
||||
sp->stream.avail_in = (uInt) tif->tif_rawcc;
|
||||
|
||||
sp->stream.next_out = op;
|
||||
assert(sizeof(sp->stream.avail_out)==4); /* if this assert gets raised,
|
||||
we need to simplify this code to reflect a ZLib that is likely updated
|
||||
to deal with 8byte memory sizes, though this code will respond
|
||||
appropriately even before we simplify it */
|
||||
sp->stream.avail_out = (uInt) occ;
|
||||
if ((tmsize_t)sp->stream.avail_out != occ)
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size");
|
||||
return (0);
|
||||
}
|
||||
do {
|
||||
int state = inflate(&sp->stream, Z_PARTIAL_FLUSH);
|
||||
int state;
|
||||
uInt avail_in_before = (uint64)tif->tif_rawcc <= 0xFFFFFFFFU ? (uInt)tif->tif_rawcc : 0xFFFFFFFFU;
|
||||
uInt avail_out_before = (uint64)occ < 0xFFFFFFFFU ? (uInt) occ : 0xFFFFFFFFU;
|
||||
sp->stream.avail_in = avail_in_before;
|
||||
sp->stream.avail_out = avail_out_before;
|
||||
state = inflate(&sp->stream, Z_PARTIAL_FLUSH);
|
||||
tif->tif_rawcc -= (avail_in_before - sp->stream.avail_in);
|
||||
occ -= (avail_out_before - sp->stream.avail_out);
|
||||
if (state == Z_STREAM_END)
|
||||
break;
|
||||
if (state == Z_DATA_ERROR) {
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
"Decoding error at scanline %lu, %s",
|
||||
(unsigned long) tif->tif_row, SAFE_MSG(sp));
|
||||
if (inflateSync(&sp->stream) != Z_OK)
|
||||
return (0);
|
||||
continue;
|
||||
return (0);
|
||||
}
|
||||
if (state != Z_OK) {
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
"ZLib error: %s", SAFE_MSG(sp));
|
||||
return (0);
|
||||
}
|
||||
} while (sp->stream.avail_out > 0);
|
||||
if (sp->stream.avail_out != 0) {
|
||||
} while (occ > 0);
|
||||
if (occ != 0) {
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
"Not enough data at scanline %lu (short " TIFF_UINT64_FORMAT " bytes)",
|
||||
(unsigned long) tif->tif_row, (TIFF_UINT64_T) sp->stream.avail_out);
|
||||
(unsigned long) tif->tif_row, (TIFF_UINT64_T) occ);
|
||||
return (0);
|
||||
}
|
||||
|
||||
tif->tif_rawcp = sp->stream.next_in;
|
||||
tif->tif_rawcc = sp->stream.avail_in;
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
|
@ -229,7 +220,6 @@ ZIPSetupEncode(TIFF* tif)
|
|||
static int
|
||||
ZIPPreEncode(TIFF* tif, uint16 s)
|
||||
{
|
||||
static const char module[] = "ZIPPreEncode";
|
||||
ZIPState *sp = EncoderState(tif);
|
||||
|
||||
(void) s;
|
||||
|
|
@ -242,12 +232,7 @@ ZIPPreEncode(TIFF* tif, uint16 s)
|
|||
we need to simplify this code to reflect a ZLib that is likely updated
|
||||
to deal with 8byte memory sizes, though this code will respond
|
||||
appropriately even before we simplify it */
|
||||
sp->stream.avail_out = (uInt)tif->tif_rawdatasize;
|
||||
if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize)
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size");
|
||||
return (0);
|
||||
}
|
||||
sp->stream.avail_out = (uint64)tif->tif_rawdatasize <= 0xFFFFFFFFU ? (uInt)tif->tif_rawdatasize : 0xFFFFFFFFU;
|
||||
return (deflateReset(&sp->stream) == Z_OK);
|
||||
}
|
||||
|
||||
|
|
@ -269,13 +254,9 @@ ZIPEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
|
|||
we need to simplify this code to reflect a ZLib that is likely updated
|
||||
to deal with 8byte memory sizes, though this code will respond
|
||||
appropriately even before we simplify it */
|
||||
sp->stream.avail_in = (uInt) cc;
|
||||
if ((tmsize_t)sp->stream.avail_in != cc)
|
||||
{
|
||||
TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size");
|
||||
return (0);
|
||||
}
|
||||
do {
|
||||
uInt avail_in_before = (uint64)cc <= 0xFFFFFFFFU ? (uInt)cc : 0xFFFFFFFFU;
|
||||
sp->stream.avail_in = avail_in_before;
|
||||
if (deflate(&sp->stream, Z_NO_FLUSH) != Z_OK) {
|
||||
TIFFErrorExt(tif->tif_clientdata, module,
|
||||
"Encoder error: %s",
|
||||
|
|
@ -286,9 +267,10 @@ ZIPEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
|
|||
tif->tif_rawcc = tif->tif_rawdatasize;
|
||||
TIFFFlushData1(tif);
|
||||
sp->stream.next_out = tif->tif_rawdata;
|
||||
sp->stream.avail_out = (uInt) tif->tif_rawdatasize; /* this is a safe typecast, as check is made already in ZIPPreEncode */
|
||||
sp->stream.avail_out = (uint64)tif->tif_rawdatasize <= 0xFFFFFFFFU ? (uInt)tif->tif_rawdatasize : 0xFFFFFFFFU;
|
||||
}
|
||||
} while (sp->stream.avail_in > 0);
|
||||
cc -= (avail_in_before - sp->stream.avail_in);
|
||||
} while (cc > 0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
|
@ -314,7 +296,7 @@ ZIPPostEncode(TIFF* tif)
|
|||
tif->tif_rawcc = tif->tif_rawdatasize - sp->stream.avail_out;
|
||||
TIFFFlushData1(tif);
|
||||
sp->stream.next_out = tif->tif_rawdata;
|
||||
sp->stream.avail_out = (uInt) tif->tif_rawdatasize; /* this is a safe typecast, as check is made already in ZIPPreEncode */
|
||||
sp->stream.avail_out = (uint64)tif->tif_rawdatasize <= 0xFFFFFFFFU ? (uInt)tif->tif_rawdatasize : 0xFFFFFFFFU;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -1,121 +0,0 @@
|
|||
/*
|
||||
Configuration defines for installed libtiff.
|
||||
This file maintained for backward compatibility. Do not use definitions
|
||||
from this file in your programs.
|
||||
*/
|
||||
|
||||
#ifndef _TIFFCONF_
|
||||
#define _TIFFCONF_
|
||||
|
||||
/* Signed 16-bit type */
|
||||
#define TIFF_INT16_T @TIFF_INT16_T@
|
||||
|
||||
/* Signed 32-bit type */
|
||||
#define TIFF_INT32_T @TIFF_INT32_T@
|
||||
|
||||
/* Signed 64-bit type */
|
||||
#define TIFF_INT64_T @TIFF_INT64_T@
|
||||
|
||||
/* Signed 8-bit type */
|
||||
#define TIFF_INT8_T @TIFF_INT8_T@
|
||||
|
||||
/* Unsigned 16-bit type */
|
||||
#define TIFF_UINT16_T @TIFF_UINT16_T@
|
||||
|
||||
/* Unsigned 32-bit type */
|
||||
#define TIFF_UINT32_T @TIFF_UINT32_T@
|
||||
|
||||
/* Unsigned 64-bit type */
|
||||
#define TIFF_UINT64_T @TIFF_UINT64_T@
|
||||
|
||||
/* Unsigned 8-bit type */
|
||||
#define TIFF_UINT8_T @TIFF_UINT8_T@
|
||||
|
||||
/* Unsigned size type */
|
||||
#define TIFF_SIZE_T @TIFF_SIZE_T@
|
||||
|
||||
/* Signed size type */
|
||||
#define TIFF_SSIZE_T @TIFF_SSIZE_T@
|
||||
|
||||
/* Pointer difference type */
|
||||
#define TIFF_PTRDIFF_T @TIFF_PTRDIFF_T@
|
||||
|
||||
/* Compatibility stuff. */
|
||||
|
||||
/* Define as 0 or 1 according to the floating point format suported by the
|
||||
machine */
|
||||
#cmakedefine HAVE_IEEEFP 1
|
||||
|
||||
/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */
|
||||
#define HOST_FILLORDER @HOST_FILLORDER@
|
||||
|
||||
/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian
|
||||
(Intel) */
|
||||
#define HOST_BIGENDIAN @HOST_BIG_ENDIAN@
|
||||
|
||||
/* Support CCITT Group 3 & 4 algorithms */
|
||||
#cmakedefine CCITT_SUPPORT 1
|
||||
|
||||
/* Support JPEG compression (requires IJG JPEG library) */
|
||||
#cmakedefine JPEG_SUPPORT 1
|
||||
|
||||
/* Support JBIG compression (requires JBIG-KIT library) */
|
||||
#cmakedefine JBIG_SUPPORT
|
||||
|
||||
/* Support LogLuv high dynamic range encoding */
|
||||
#cmakedefine LOGLUV_SUPPORT 1
|
||||
|
||||
/* Support LZW algorithm */
|
||||
#cmakedefine LZW_SUPPORT 1
|
||||
|
||||
/* Support NeXT 2-bit RLE algorithm */
|
||||
#cmakedefine NEXT_SUPPORT 1
|
||||
|
||||
/* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation
|
||||
fails with unpatched IJG JPEG library) */
|
||||
#cmakedefine OJPEG_SUPPORT 1
|
||||
|
||||
/* Support Macintosh PackBits algorithm */
|
||||
#cmakedefine PACKBITS_SUPPORT 1
|
||||
|
||||
/* Support Pixar log-format algorithm (requires Zlib) */
|
||||
#cmakedefine PIXARLOG_SUPPORT 1
|
||||
|
||||
/* Support ThunderScan 4-bit RLE algorithm */
|
||||
#cmakedefine THUNDER_SUPPORT 1
|
||||
|
||||
/* Support Deflate compression */
|
||||
#cmakedefine ZIP_SUPPORT 1
|
||||
|
||||
/* Support strip chopping (whether or not to convert single-strip uncompressed
|
||||
images to mutiple strips of ~8Kb to reduce memory usage) */
|
||||
#cmakedefine STRIPCHOP_DEFAULT 1
|
||||
|
||||
/* Enable SubIFD tag (330) support */
|
||||
#cmakedefine SUBIFD_SUPPORT 1
|
||||
|
||||
/* Treat extra sample as alpha (default enabled). The RGBA interface will
|
||||
treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many
|
||||
packages produce RGBA files but don't mark the alpha properly. */
|
||||
#cmakedefine DEFAULT_EXTRASAMPLE_AS_ALPHA 1
|
||||
|
||||
/* Pick up YCbCr subsampling info from the JPEG data stream to support files
|
||||
lacking the tag (default enabled). */
|
||||
#cmakedefine CHECK_JPEG_YCBCR_SUBSAMPLING 1
|
||||
|
||||
/* Support MS MDI magic number files as TIFF */
|
||||
#cmakedefine MDI_SUPPORT 1
|
||||
|
||||
/*
|
||||
* Feature support definitions.
|
||||
* XXX: These macros are obsoleted. Don't use them in your apps!
|
||||
* Macros stays here for backward compatibility and should be always defined.
|
||||
*/
|
||||
#define COLORIMETRY_SUPPORT
|
||||
#define YCBCR_SUPPORT
|
||||
#define CMYK_SUPPORT
|
||||
#define ICC_SUPPORT
|
||||
#define PHOTOSHOP_SUPPORT
|
||||
#define IPTC_SUPPORT
|
||||
|
||||
#endif /* _TIFFCONF_ */
|
||||
|
|
@ -1,118 +0,0 @@
|
|||
/*
|
||||
Configuration defines for installed libtiff.
|
||||
This file maintained for backward compatibility. Do not use definitions
|
||||
from this file in your programs.
|
||||
*/
|
||||
|
||||
#ifndef _TIFFCONF_
|
||||
#define _TIFFCONF_
|
||||
|
||||
/* Signed 16-bit type */
|
||||
#undef TIFF_INT16_T
|
||||
|
||||
/* Signed 32-bit type */
|
||||
#undef TIFF_INT32_T
|
||||
|
||||
/* Signed 64-bit type */
|
||||
#undef TIFF_INT64_T
|
||||
|
||||
/* Signed 8-bit type */
|
||||
#undef TIFF_INT8_T
|
||||
|
||||
/* Unsigned 16-bit type */
|
||||
#undef TIFF_UINT16_T
|
||||
|
||||
/* Unsigned 32-bit type */
|
||||
#undef TIFF_UINT32_T
|
||||
|
||||
/* Unsigned 64-bit type */
|
||||
#undef TIFF_UINT64_T
|
||||
|
||||
/* Unsigned 8-bit type */
|
||||
#undef TIFF_UINT8_T
|
||||
|
||||
/* Signed size type */
|
||||
#undef TIFF_SSIZE_T
|
||||
|
||||
/* Pointer difference type */
|
||||
#undef TIFF_PTRDIFF_T
|
||||
|
||||
/* Compatibility stuff. */
|
||||
|
||||
/* Define as 0 or 1 according to the floating point format suported by the
|
||||
machine */
|
||||
#undef HAVE_IEEEFP
|
||||
|
||||
/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */
|
||||
#undef HOST_FILLORDER
|
||||
|
||||
/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian
|
||||
(Intel) */
|
||||
#undef HOST_BIGENDIAN
|
||||
|
||||
/* Support CCITT Group 3 & 4 algorithms */
|
||||
#undef CCITT_SUPPORT
|
||||
|
||||
/* Support JPEG compression (requires IJG JPEG library) */
|
||||
#undef JPEG_SUPPORT
|
||||
|
||||
/* Support JBIG compression (requires JBIG-KIT library) */
|
||||
#undef JBIG_SUPPORT
|
||||
|
||||
/* Support LogLuv high dynamic range encoding */
|
||||
#undef LOGLUV_SUPPORT
|
||||
|
||||
/* Support LZW algorithm */
|
||||
#undef LZW_SUPPORT
|
||||
|
||||
/* Support NeXT 2-bit RLE algorithm */
|
||||
#undef NEXT_SUPPORT
|
||||
|
||||
/* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation
|
||||
fails with unpatched IJG JPEG library) */
|
||||
#undef OJPEG_SUPPORT
|
||||
|
||||
/* Support Macintosh PackBits algorithm */
|
||||
#undef PACKBITS_SUPPORT
|
||||
|
||||
/* Support Pixar log-format algorithm (requires Zlib) */
|
||||
#undef PIXARLOG_SUPPORT
|
||||
|
||||
/* Support ThunderScan 4-bit RLE algorithm */
|
||||
#undef THUNDER_SUPPORT
|
||||
|
||||
/* Support Deflate compression */
|
||||
#undef ZIP_SUPPORT
|
||||
|
||||
/* Support strip chopping (whether or not to convert single-strip uncompressed
|
||||
images to mutiple strips of ~8Kb to reduce memory usage) */
|
||||
#undef STRIPCHOP_DEFAULT
|
||||
|
||||
/* Enable SubIFD tag (330) support */
|
||||
#undef SUBIFD_SUPPORT
|
||||
|
||||
/* Treat extra sample as alpha (default enabled). The RGBA interface will
|
||||
treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many
|
||||
packages produce RGBA files but don't mark the alpha properly. */
|
||||
#undef DEFAULT_EXTRASAMPLE_AS_ALPHA
|
||||
|
||||
/* Pick up YCbCr subsampling info from the JPEG data stream to support files
|
||||
lacking the tag (default enabled). */
|
||||
#undef CHECK_JPEG_YCBCR_SUBSAMPLING
|
||||
|
||||
/* Support MS MDI magic number files as TIFF */
|
||||
#undef MDI_SUPPORT
|
||||
|
||||
/*
|
||||
* Feature support definitions.
|
||||
* XXX: These macros are obsoleted. Don't use them in your apps!
|
||||
* Macros stays here for backward compatibility and should be always defined.
|
||||
*/
|
||||
#define COLORIMETRY_SUPPORT
|
||||
#define YCBCR_SUPPORT
|
||||
#define CMYK_SUPPORT
|
||||
#define ICC_SUPPORT
|
||||
#define PHOTOSHOP_SUPPORT
|
||||
#define IPTC_SUPPORT
|
||||
|
||||
#endif /* _TIFFCONF_ */
|
||||
|
|
@ -411,6 +411,8 @@ extern int TIFFWriteDirectory(TIFF *);
|
|||
extern int TIFFWriteCustomDirectory(TIFF *, uint64 *);
|
||||
extern int TIFFCheckpointDirectory(TIFF *);
|
||||
extern int TIFFRewriteDirectory(TIFF *);
|
||||
extern int TIFFDeferStrileArrayWriting(TIFF *);
|
||||
extern int TIFFForceStrileArrayWriting(TIFF* );
|
||||
|
||||
#if defined(c_plusplus) || defined(__cplusplus)
|
||||
extern void TIFFPrintDirectory(TIFF*, FILE*, long = 0);
|
||||
|
|
@ -468,6 +470,9 @@ extern tmsize_t TIFFReadEncodedStrip(TIFF* tif, uint32 strip, void* buf, tmsize_
|
|||
extern tmsize_t TIFFReadRawStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size);
|
||||
extern tmsize_t TIFFReadEncodedTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size);
|
||||
extern tmsize_t TIFFReadRawTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size);
|
||||
extern int TIFFReadFromUserBuffer(TIFF* tif, uint32 strile,
|
||||
void* inbuf, tmsize_t insize,
|
||||
void* outbuf, tmsize_t outsize);
|
||||
extern tmsize_t TIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc);
|
||||
extern tmsize_t TIFFWriteRawStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc);
|
||||
extern tmsize_t TIFFWriteEncodedTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc);
|
||||
|
|
@ -488,6 +493,11 @@ extern void TIFFSwabArrayOfDouble(double* dp, tmsize_t n);
|
|||
extern void TIFFReverseBits(uint8* cp, tmsize_t n);
|
||||
extern const unsigned char* TIFFGetBitRevTable(int);
|
||||
|
||||
extern uint64 TIFFGetStrileOffset(TIFF *tif, uint32 strile);
|
||||
extern uint64 TIFFGetStrileByteCount(TIFF *tif, uint32 strile);
|
||||
extern uint64 TIFFGetStrileOffsetWithErr(TIFF *tif, uint32 strile, int *pbErr);
|
||||
extern uint64 TIFFGetStrileByteCountWithErr(TIFF *tif, uint32 strile, int *pbErr);
|
||||
|
||||
#ifdef LOGLUV_PUBLIC
|
||||
#define U_NEU 0.210526316
|
||||
#define V_NEU 0.473684211
|
||||
|
|
|
|||
|
|
@ -77,6 +77,19 @@ extern int snprintf(char* str, size_t size, const char* format, ...);
|
|||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
#define TIFF_SIZE_T_MAX ((size_t) ~ ((size_t)0))
|
||||
#define TIFF_TMSIZE_T_MAX (tmsize_t)(TIFF_SIZE_T_MAX >> 1)
|
||||
|
||||
/*
|
||||
* Largest 32-bit unsigned integer value.
|
||||
*/
|
||||
#define TIFF_UINT32_MAX 0xFFFFFFFFU
|
||||
|
||||
/*
|
||||
* Largest 64-bit unsigned integer value.
|
||||
*/
|
||||
#define TIFF_UINT64_MAX (((uint64)(TIFF_UINT32_MAX)) << 32 | TIFF_UINT32_MAX)
|
||||
|
||||
typedef struct client_info {
|
||||
struct client_info *next;
|
||||
void *data;
|
||||
|
|
@ -127,6 +140,9 @@ struct tiff {
|
|||
#define TIFF_DIRTYSTRIP 0x200000U /* stripoffsets/stripbytecount dirty*/
|
||||
#define TIFF_PERSAMPLE 0x400000U /* get/set per sample tags as arrays */
|
||||
#define TIFF_BUFFERMMAP 0x800000U /* read buffer (tif_rawdata) points into mmap() memory */
|
||||
#define TIFF_DEFERSTRILELOAD 0x1000000U /* defer strip/tile offset/bytecount array loading. */
|
||||
#define TIFF_LAZYSTRILELOAD 0x2000000U /* lazy/ondemand loading of strip/tile offset/bytecount values. Only used if TIFF_DEFERSTRILELOAD is set and in read-only mode */
|
||||
#define TIFF_CHOPPEDUPARRAYS 0x4000000U /* set when allocChoppedUpStripArrays() has modified strip array */
|
||||
uint64 tif_diroff; /* file offset of current directory */
|
||||
uint64 tif_nextdiroff; /* file offset of following directory */
|
||||
uint64* tif_dirlist; /* list of offsets to already seen directories to prevent IFD looping */
|
||||
|
|
@ -258,7 +274,7 @@ struct tiff {
|
|||
#define TIFFhowmany8_64(x) (((x)&0x07)?((uint64)(x)>>3)+1:(uint64)(x)>>3)
|
||||
#define TIFFroundup_64(x, y) (TIFFhowmany_64(x,y)*(y))
|
||||
|
||||
/* Safe multiply which returns zero if there is an integer overflow */
|
||||
/* Safe multiply which returns zero if there is an *unsigned* integer overflow. This macro is not safe for *signed* integer types */
|
||||
#define TIFFSafeMultiply(t,v,m) ((((t)(m) != (t)0) && (((t)(((v)*(m))/(m))) == (t)(v))) ? (t)((v)*(m)) : (t)0)
|
||||
|
||||
#define TIFFmax(A,B) ((A)>(B)?(A):(B))
|
||||
|
|
@ -368,12 +384,16 @@ extern TIFFErrorHandlerExt _TIFFerrorHandlerExt;
|
|||
|
||||
extern uint32 _TIFFMultiply32(TIFF*, uint32, uint32, const char*);
|
||||
extern uint64 _TIFFMultiply64(TIFF*, uint64, uint64, const char*);
|
||||
extern tmsize_t _TIFFMultiplySSize(TIFF*, tmsize_t, tmsize_t, const char*);
|
||||
extern tmsize_t _TIFFCastUInt64ToSSize(TIFF*, uint64, const char*);
|
||||
extern void* _TIFFCheckMalloc(TIFF*, tmsize_t, tmsize_t, const char*);
|
||||
extern void* _TIFFCheckRealloc(TIFF*, void*, tmsize_t, tmsize_t, const char*);
|
||||
|
||||
extern double _TIFFUInt64ToDouble(uint64);
|
||||
extern float _TIFFUInt64ToFloat(uint64);
|
||||
|
||||
extern float _TIFFClampDoubleToFloat(double);
|
||||
|
||||
extern tmsize_t
|
||||
_TIFFReadEncodedStripAndAllocBuffer(TIFF* tif, uint32 strip,
|
||||
void **buf, tmsize_t bufsizetoalloc,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.0.10\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc."
|
||||
#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.1.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
|
||||
|
|
@ -6,4 +6,4 @@
|
|||
* version checking should be done based on the
|
||||
* string returned by TIFFGetVersion.
|
||||
*/
|
||||
#define TIFFLIB_VERSION 20181110
|
||||
#define TIFFLIB_VERSION 20191103
|
||||
|
|
|
|||
|
|
@ -26,19 +26,9 @@ file
|
|||
tifupp.cpp,
|
||||
tifreg.icpp,
|
||||
lib readonly separator,
|
||||
lib\Version,
|
||||
lib\Copyright,
|
||||
lib\zlib.h,
|
||||
lib\jerror.h,
|
||||
lib\jpeg.patch1,
|
||||
lib\jpeg.patch2,
|
||||
lib\jpeglib.h,
|
||||
lib\libtiff.def,
|
||||
lib\Makefile.am,
|
||||
lib\Makefile.in,
|
||||
lib\Makefile.lcc,
|
||||
lib\Makefile.vc,
|
||||
lib\ojpeg.patch,
|
||||
lib\t4.h,
|
||||
lib\tif_aux.c,
|
||||
lib\tif_close.c,
|
||||
|
|
@ -46,8 +36,6 @@ file
|
|||
lib\tif_color.c,
|
||||
lib\tif_compress.c,
|
||||
lib\tif_config.h,
|
||||
lib\tif_config.h.in,
|
||||
lib\tif_config.h.vc,
|
||||
lib\tif_dir.c,
|
||||
lib\tif_dir.h,
|
||||
lib\tif_dirinfo.c,
|
||||
|
|
@ -84,8 +72,6 @@ file
|
|||
lib\tiff.h,
|
||||
lib\tiffcomp.h,
|
||||
lib\tiffconf.h,
|
||||
lib\tiffconf.h.in,
|
||||
lib\tiffconf.h.vc,
|
||||
lib\tiffio.h,
|
||||
lib\tiffio.hxx,
|
||||
lib\tiffiop.h,
|
||||
|
|
|
|||
Loading…
Reference in a new issue