chromium/third_party/pdfium/third_party/libtiff/tiffiop.h

/*
 * Copyright (c) 1988-1997 Sam Leffler
 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 *
 * Permission to use, copy, modify, distribute, and sell this software and
 * its documentation for any purpose is hereby granted without fee, provided
 * that (i) the above copyright notices and this permission notice appear in
 * all copies of the software and related documentation, and (ii) the names of
 * Sam Leffler and Silicon Graphics may not be used in any advertising or
 * publicity relating to the software without the specific, prior written
 * permission of Sam Leffler and Silicon Graphics.
 *
 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
 *
 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
 * OF THIS SOFTWARE.
 */

#ifndef _TIFFIOP_
#define _TIFFIOP_
/*
 * ``Library-private'' definitions.
 */

#include "tiffconf.h"

#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif

#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif

#include <string.h>

#ifdef HAVE_ASSERT_H
#include <assert.h>
#else
#define assert
#endif

#include "tif_hash_set.h"
#include "tiffio.h"

#include "tif_dir.h"

#include <limits.h>

#ifndef STRIP_SIZE_DEFAULT
#define STRIP_SIZE_DEFAULT
#endif

#ifndef TIFF_MAX_DIR_COUNT
#define TIFF_MAX_DIR_COUNT
#endif

#define TIFF_NON_EXISTENT_DIR_NUMBER

#define streq(a, b)
#define strneq(a, b, n)

#ifndef TRUE
#define TRUE
#define FALSE
#endif

TIFFClientInfoLink;

/*
 * Typedefs for ``method pointers'' used internally.
 * these are deprecated and provided only for backwards compatibility.
 */
tidataval_t; /* internal image data value type */
tidata_t;     /* reference to internal image data */

TIFFVoidMethod;
TIFFBoolMethod;
TIFFPreMethod;
TIFFCodeMethod;
TIFFSeekMethod;
TIFFPostMethod;
TIFFStripMethod;
TIFFTileMethod;

struct TIFFOffsetAndDirNumber
{};
TIFFOffsetAndDirNumber;

struct tiff
{};

struct TIFFOpenOptions
{};

#define isPseudoTag(t)

#define isTiled(tif)
#define isMapped(tif)
#define isFillOrder(tif, o)
#define isUpSampled(tif)
#define TIFFReadFile(tif, buf, size)
#define TIFFWriteFile(tif, buf, size)
#define TIFFSeekFile(tif, off, whence)
#define TIFFCloseFile(tif)
#define TIFFGetFileSize(tif)
#define TIFFMapFileContents(tif, paddr, psize)
#define TIFFUnmapFileContents(tif, addr, size)

/*
 * Default Read/Seek/Write definitions.
 */
#ifndef ReadOK
#define ReadOK(tif, buf, size)
#endif
#ifndef SeekOK
#define SeekOK(tif, off)
#endif
#ifndef WriteOK
#define WriteOK(tif, buf, size)
#endif

/* NB: the uint32_t casts are to silence certain ANSI-C compilers */
#define TIFFhowmany_32(x, y)
/* Variant of TIFFhowmany_32() that doesn't return 0 if x close to MAXUINT. */
/* Caution: TIFFhowmany_32_maxuint_compat(x,y)*y might overflow */
#define TIFFhowmany_32_maxuint_compat(x, y)
#define TIFFhowmany8_32(x)
#define TIFFroundup_32(x, y)
#define TIFFhowmany_64(x, y)
#define TIFFhowmany8_64(x)
#define TIFFroundup_64(x, y)

/* 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)

#define TIFFmax(A, B)
#define TIFFmin(A, B)

#define TIFFArrayCount(a)

/*
  Support for large files.

  Windows read/write APIs support only 'unsigned int' rather than 'size_t'.
  Windows off_t is only 32-bit, even in 64-bit builds.
*/
#if defined(HAVE_FSEEKO)
/*
  Use fseeko() and ftello() if they are available since they use
  'off_t' rather than 'long'.  It is wrong to use fseeko() and
  ftello() only on systems with special LFS support since some systems
  (e.g. FreeBSD) support a 64-bit off_t by default.

  For MinGW, __MSVCRT_VERSION__ must be at least 0x800 to expose these
  interfaces. The MinGW compiler must support the requested version.  MinGW
  does not distribute the CRT (it is supplied by Microsoft) so the correct CRT
  must be available on the target computer in order for the program to run.
*/
#if defined(HAVE_FSEEKO)
#define fseek
#define ftell
#endif
#endif
#if defined(__WIN32__) && !(defined(_MSC_VER) && _MSC_VER < 1400) &&           \
    !(defined(__MSVCRT_VERSION__) && __MSVCRT_VERSION__ < 0x800)
typedef unsigned int TIFFIOSize_t;
#define _TIFF_lseek_f
/* #define _TIFF_tell_f(fildes) /\* __int64 *\/ _telli64(fildes) */
#define _TIFF_fseek_f
#define _TIFF_fstat_f
/* #define _TIFF_ftell_f(stream) /\* __int64 *\/ _ftelli64(stream) */
/* #define _TIFF_stat_f(path,stat_buff) _stati64(path,/\* struct _stati64 *\/
 * stat_buff) */
#define _TIFF_stat_s
#define _TIFF_off_t
#else
TIFFIOSize_t;
#define _TIFF_lseek_f(fildes, offset, whence)
/* #define _TIFF_tell_f(fildes) (_TIFF_lseek_f(fildes,0,SEEK_CUR)) */
#define _TIFF_fseek_f(stream, offset, whence)
#define _TIFF_fstat_f(fildes, stat_buff)
/* #define _TIFF_ftell_f(stream) ftell(stream) */
/* #define _TIFF_stat_f(path,stat_buff) stat(path,stat_buff) */
#define _TIFF_stat_s
#define _TIFF_off_t
#endif

#if defined(__has_attribute) && defined(__clang__)
#if __has_attribute(no_sanitize)
#define TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
#else
#define TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
#endif
#else
#define TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
#endif

#if defined(__cplusplus)
extern "C"
{
#endif
    extern int _TIFFgetMode(TIFFOpenOptions *opts, thandle_t clientdata,
                            const char *mode, const char *module);
    extern int _TIFFNoRowEncode(TIFF *tif, uint8_t *pp, tmsize_t cc,
                                uint16_t s);
    extern int _TIFFNoStripEncode(TIFF *tif, uint8_t *pp, tmsize_t cc,
                                  uint16_t s);
    extern int _TIFFNoTileEncode(TIFF *, uint8_t *pp, tmsize_t cc, uint16_t s);
    extern int _TIFFNoRowDecode(TIFF *tif, uint8_t *pp, tmsize_t cc,
                                uint16_t s);
    extern int _TIFFNoStripDecode(TIFF *tif, uint8_t *pp, tmsize_t cc,
                                  uint16_t s);
    extern int _TIFFNoTileDecode(TIFF *, uint8_t *pp, tmsize_t cc, uint16_t s);
    extern void _TIFFNoPostDecode(TIFF *tif, uint8_t *buf, tmsize_t cc);
    extern int _TIFFNoPreCode(TIFF *tif, uint16_t s);
    extern int _TIFFNoSeek(TIFF *tif, uint32_t off);
    extern void _TIFFSwab16BitData(TIFF *tif, uint8_t *buf, tmsize_t cc);
    extern void _TIFFSwab24BitData(TIFF *tif, uint8_t *buf, tmsize_t cc);
    extern void _TIFFSwab32BitData(TIFF *tif, uint8_t *buf, tmsize_t cc);
    extern void _TIFFSwab64BitData(TIFF *tif, uint8_t *buf, tmsize_t cc);
    extern int TIFFFlushData1(TIFF *tif);
    extern int TIFFDefaultDirectory(TIFF *tif);
    extern void _TIFFSetDefaultCompressionState(TIFF *tif);
    extern int _TIFFRewriteField(TIFF *, uint16_t, TIFFDataType, tmsize_t,
                                 void *);
    extern int TIFFSetCompressionScheme(TIFF *tif, int scheme);
    extern int TIFFSetDefaultCompressionState(TIFF *tif);
    extern uint32_t _TIFFDefaultStripSize(TIFF *tif, uint32_t s);
    extern void _TIFFDefaultTileSize(TIFF *tif, uint32_t *tw, uint32_t *th);

    extern void _TIFFsetByteArray(void **, const void *, uint32_t);
    extern void _TIFFsetByteArrayExt(TIFF *, void **, const void *, uint32_t);
    extern void _TIFFsetShortArray(uint16_t **, const uint16_t *, uint32_t);
    extern void _TIFFsetShortArrayExt(TIFF *, uint16_t **, const uint16_t *,
                                      uint32_t);
    extern void _TIFFsetLongArray(uint32_t **, const uint32_t *, uint32_t);
    extern void _TIFFsetLongArrayExt(TIFF *, uint32_t **, const uint32_t *,
                                     uint32_t);
    extern void _TIFFsetFloatArray(float **, const float *, uint32_t);
    extern void _TIFFsetFloatArrayExt(TIFF *, float **, const float *,
                                      uint32_t);
    extern void _TIFFsetDoubleArray(double **, const double *, uint32_t);
    extern void _TIFFsetDoubleArrayExt(TIFF *, double **, const double *,
                                       uint32_t);

    extern void _TIFFprintAscii(FILE *, const char *);
    extern void _TIFFprintAsciiTag(FILE *, const char *, const char *);

    extern TIFFErrorHandler _TIFFwarningHandler;
    extern TIFFErrorHandler _TIFFerrorHandler;
    extern TIFFErrorHandlerExt _TIFFwarningHandlerExt;
    extern TIFFErrorHandlerExt _TIFFerrorHandlerExt;
    void _TIFFErrorEarly(TIFFOpenOptions *opts, thandle_t clientdata,
                         const char *module, const char *fmt, ...)
        TIFF_ATTRIBUTE((__format__(__printf__, 4, 5)));

    extern uint32_t _TIFFMultiply32(TIFF *, uint32_t, uint32_t, const char *);
    extern uint64_t _TIFFMultiply64(TIFF *, uint64_t, uint64_t, const char *);
    extern tmsize_t _TIFFMultiplySSize(TIFF *, tmsize_t, tmsize_t,
                                       const char *);
    extern tmsize_t _TIFFCastUInt64ToSSize(TIFF *, uint64_t, 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_t);
    extern float _TIFFUInt64ToFloat(uint64_t);

    extern float _TIFFClampDoubleToFloat(double);
    extern uint32_t _TIFFClampDoubleToUInt32(double);

    extern void _TIFFCleanupIFDOffsetAndNumberMaps(TIFF *tif);

    extern tmsize_t _TIFFReadEncodedStripAndAllocBuffer(TIFF *tif,
                                                        uint32_t strip,
                                                        void **buf,
                                                        tmsize_t bufsizetoalloc,
                                                        tmsize_t size_to_read);
    extern tmsize_t _TIFFReadEncodedTileAndAllocBuffer(TIFF *tif, uint32_t tile,
                                                       void **buf,
                                                       tmsize_t bufsizetoalloc,
                                                       tmsize_t size_to_read);
    extern tmsize_t _TIFFReadTileAndAllocBuffer(TIFF *tif, void **buf,
                                                tmsize_t bufsizetoalloc,
                                                uint32_t x, uint32_t y,
                                                uint32_t z, uint16_t s);
    extern int _TIFFSeekOK(TIFF *tif, toff_t off);

    extern int TIFFInitDumpMode(TIFF *, int);
#ifdef PACKBITS_SUPPORT
    extern int TIFFInitPackBits(TIFF *, int);
#endif
#ifdef CCITT_SUPPORT
    extern int TIFFInitCCITTRLE(TIFF *, int), TIFFInitCCITTRLEW(TIFF *, int);
    extern int TIFFInitCCITTFax3(TIFF *, int), TIFFInitCCITTFax4(TIFF *, int);
#endif
#ifdef THUNDER_SUPPORT
    extern int TIFFInitThunderScan(TIFF *, int);
#endif
#ifdef NEXT_SUPPORT
    extern int TIFFInitNeXT(TIFF *, int);
#endif
#ifdef LZW_SUPPORT
    extern int TIFFInitLZW(TIFF *, int);
#endif
#ifdef OJPEG_SUPPORT
    extern int TIFFInitOJPEG(TIFF *, int);
#endif
#ifdef JPEG_SUPPORT
    extern int TIFFInitJPEG(TIFF *, int);
    extern int TIFFJPEGIsFullStripRequired(TIFF *);
#endif
#ifdef JBIG_SUPPORT
    extern int TIFFInitJBIG(TIFF *, int);
#endif
#ifdef ZIP_SUPPORT
    extern int TIFFInitZIP(TIFF *, int);
#endif
#ifdef PIXARLOG_SUPPORT
    extern int TIFFInitPixarLog(TIFF *, int);
#endif
#ifdef LOGLUV_SUPPORT
    extern int TIFFInitSGILog(TIFF *, int);
#endif
#ifdef LERC_SUPPORT
    extern int TIFFInitLERC(TIFF *tif, int);
#endif
#ifdef LZMA_SUPPORT
    extern int TIFFInitLZMA(TIFF *, int);
#endif
#ifdef ZSTD_SUPPORT
    extern int TIFFInitZSTD(TIFF *, int);
#endif
#ifdef WEBP_SUPPORT
    extern int TIFFInitWebP(TIFF *, int);
#endif
    extern const TIFFCodec _TIFFBuiltinCODECS[];
    extern void TIFFCIELab16ToXYZ(TIFFCIELabToRGB *, uint32_t l, int32_t a,
                                  int32_t b, float *, float *, float *);

    extern void *_TIFFmallocExt(TIFF *tif, tmsize_t s);
    extern void *_TIFFcallocExt(TIFF *tif, tmsize_t nmemb, tmsize_t siz);
    extern void *_TIFFreallocExt(TIFF *tif, void *p, tmsize_t s);
    extern void _TIFFfreeExt(TIFF *tif, void *p);

#if defined(__cplusplus)
}
#endif
#endif /* _TIFFIOP_ */