ReactOS 0.4.16-dev-2574-g474348f
tiffio.h File Reference
#include "tiff.h"
#include "tiffvers.h"
#include <stdarg.h>
#include <stdio.h>
Include dependency graph for tiffio.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  TIFFDisplay
 
struct  TIFFYCbCrToRGB
 
struct  TIFFCIELabToRGB
 
struct  _TIFFRGBAImage
 
struct  TIFFCodec
 
struct  TIFFRational_t
 
struct  TIFFTagMethods
 
struct  TIFFFieldInfo
 

Macros

#define TIFF_TMSIZE_T_MAX   (tmsize_t)(SIZE_MAX >> 1)
 
#define TIFFPRINT_NONE   0x0 /* no extra info */
 
#define TIFFPRINT_STRIPS   0x1 /* strips/tiles info */
 
#define TIFFPRINT_CURVES   0x2 /* color/gray response curves */
 
#define TIFFPRINT_COLORMAP   0x4 /* colormap */
 
#define TIFFPRINT_JPEGQTABLES   0x100 /* JPEG Q matrices */
 
#define TIFFPRINT_JPEGACTABLES   0x200 /* JPEG AC tables */
 
#define TIFFPRINT_JPEGDCTABLES   0x200 /* JPEG DC tables */
 
#define D65_X0   (95.0470F)
 
#define D65_Y0   (100.0F)
 
#define D65_Z0   (108.8827F)
 
#define D50_X0   (96.4250F)
 
#define D50_Y0   (100.0F)
 
#define D50_Z0   (82.4680F)
 
#define CIELABTORGB_TABLE_RANGE   1500
 
#define TIFFGetR(abgr)   ((abgr)&0xff)
 
#define TIFFGetG(abgr)   (((abgr) >> 8) & 0xff)
 
#define TIFFGetB(abgr)   (((abgr) >> 16) & 0xff)
 
#define TIFFGetA(abgr)   (((abgr) >> 24) & 0xff)
 
#define LOGLUV_PUBLIC   1
 
#define TIFF_ATTRIBUTE(x)   /*nothing*/
 
#define TIFF_ANY   TIFF_NOTYPE /* for field descriptor searching */
 
#define TIFF_VARIABLE   -1 /* marker for variable length tags */
 
#define TIFF_SPP   -2 /* marker for SamplesPerPixel tags */
 
#define TIFF_VARIABLE2   -3 /* marker for uint32_t var-length tags */
 
#define FIELD_CUSTOM   65
 
#define U_NEU   0.210526316
 
#define V_NEU   0.473684211
 
#define UVSCALE   410.
 

Typedefs

typedef struct tiff TIFF
 
typedef TIFF_SSIZE_T tmsize_t
 
typedef uint64_t toff_t
 
typedef uint32_t tdir_t
 
typedef uint32_t ttag_t
 
typedef uint16_t tsample_t
 
typedef uint32_t tstrile_t
 
typedef tstrile_t tstrip_t
 
typedef tstrile_t ttile_t
 
typedef tmsize_t tsize_t
 
typedef voidtdata_t
 
typedef voidthandle_t
 
typedef unsigned char TIFFRGBValue
 
typedef struct _TIFFRGBAImage TIFFRGBAImage
 
typedef void(* tileContigRoutine) (TIFFRGBAImage *, uint32_t *, uint32_t, uint32_t, uint32_t, uint32_t, int32_t, int32_t, unsigned char *)
 
typedef void(* tileSeparateRoutine) (TIFFRGBAImage *, uint32_t *, uint32_t, uint32_t, uint32_t, uint32_t, int32_t, int32_t, unsigned char *, unsigned char *, unsigned char *, unsigned char *)
 
typedef int(* TIFFInitMethod) (TIFF *, int)
 
typedef void(* TIFFErrorHandler) (const char *, const char *, va_list)
 
typedef void(* TIFFErrorHandlerExt) (thandle_t, const char *, const char *, va_list)
 
typedef int(* TIFFErrorHandlerExtR) (TIFF *, void *user_data, const char *, const char *, va_list)
 
typedef tmsize_t(* TIFFReadWriteProc) (thandle_t, void *, tmsize_t)
 
typedef toff_t(* TIFFSeekProc) (thandle_t, toff_t, int)
 
typedef int(* TIFFCloseProc) (thandle_t)
 
typedef toff_t(* TIFFSizeProc) (thandle_t)
 
typedef int(* TIFFMapFileProc) (thandle_t, void **base, toff_t *size)
 
typedef void(* TIFFUnmapFileProc) (thandle_t, void *base, toff_t size)
 
typedef void(* TIFFExtendProc) (TIFF *)
 
typedef struct _TIFFField TIFFField
 
typedef struct _TIFFFieldArray TIFFFieldArray
 
typedef int(* TIFFVSetMethod) (TIFF *, uint32_t, va_list)
 
typedef int(* TIFFVGetMethod) (TIFF *, uint32_t, va_list)
 
typedef void(* TIFFPrintMethod) (TIFF *, FILE *, long)
 
typedef typedefvoid void struct TIFFOpenOptions TIFFOpenOptions
 

Functions

const charTIFFGetVersion (void)
 
const TIFFCodecTIFFFindCODEC (uint16_t)
 
TIFFCodecTIFFRegisterCODEC (uint16_t, const char *, TIFFInitMethod)
 
void TIFFUnRegisterCODEC (TIFFCodec *)
 
int TIFFIsCODECConfigured (uint16_t)
 
TIFFCodecTIFFGetConfiguredCODECs (void)
 
void_TIFFmalloc (tmsize_t s)
 
void_TIFFcalloc (tmsize_t nmemb, tmsize_t siz)
 
void_TIFFrealloc (void *p, tmsize_t s)
 
void _TIFFfree (void *p)
 
void _TIFFmemset (void *p, int v, tmsize_t c)
 
void _TIFFmemcpy (void *d, const void *s, tmsize_t c)
 
int _TIFFmemcmp (const void *p1, const void *p2, tmsize_t c)
 
int TIFFGetTagListCount (TIFF *)
 
uint32_t TIFFGetTagListEntry (TIFF *, int tag_index)
 
const TIFFFieldTIFFFindField (TIFF *, uint32_t, TIFFDataType)
 
const TIFFFieldTIFFFieldWithTag (TIFF *, uint32_t)
 
const TIFFFieldTIFFFieldWithName (TIFF *, const char *)
 
uint32_t TIFFFieldTag (const TIFFField *)
 
const charTIFFFieldName (const TIFFField *)
 
TIFFDataType TIFFFieldDataType (const TIFFField *)
 
int TIFFFieldPassCount (const TIFFField *)
 
int TIFFFieldReadCount (const TIFFField *)
 
int TIFFFieldWriteCount (const TIFFField *)
 
int TIFFFieldSetGetSize (const TIFFField *)
 
int TIFFFieldSetGetCountSize (const TIFFField *)
 
int TIFFFieldIsAnonymous (const TIFFField *)
 
TIFFTagMethodsTIFFAccessTagMethods (TIFF *)
 
voidTIFFGetClientInfo (TIFF *, const char *)
 
void TIFFSetClientInfo (TIFF *, void *, const char *)
 
void TIFFCleanup (TIFF *tif)
 
void TIFFClose (TIFF *tif)
 
int TIFFFlush (TIFF *tif)
 
int TIFFFlushData (TIFF *tif)
 
int TIFFGetField (TIFF *tif, uint32_t tag,...)
 
int TIFFVGetField (TIFF *tif, uint32_t tag, va_list ap)
 
int TIFFGetFieldDefaulted (TIFF *tif, uint32_t tag,...)
 
int TIFFVGetFieldDefaulted (TIFF *tif, uint32_t tag, va_list ap)
 
int TIFFReadDirectory (TIFF *tif)
 
int TIFFReadCustomDirectory (TIFF *tif, toff_t diroff, const TIFFFieldArray *infoarray)
 
int TIFFReadEXIFDirectory (TIFF *tif, toff_t diroff)
 
int TIFFReadGPSDirectory (TIFF *tif, toff_t diroff)
 
uint64_t TIFFScanlineSize64 (TIFF *tif)
 
tmsize_t TIFFScanlineSize (TIFF *tif)
 
uint64_t TIFFRasterScanlineSize64 (TIFF *tif)
 
tmsize_t TIFFRasterScanlineSize (TIFF *tif)
 
uint64_t TIFFStripSize64 (TIFF *tif)
 
tmsize_t TIFFStripSize (TIFF *tif)
 
uint64_t TIFFRawStripSize64 (TIFF *tif, uint32_t strip)
 
tmsize_t TIFFRawStripSize (TIFF *tif, uint32_t strip)
 
uint64_t TIFFVStripSize64 (TIFF *tif, uint32_t nrows)
 
tmsize_t TIFFVStripSize (TIFF *tif, uint32_t nrows)
 
uint64_t TIFFTileRowSize64 (TIFF *tif)
 
tmsize_t TIFFTileRowSize (TIFF *tif)
 
uint64_t TIFFTileSize64 (TIFF *tif)
 
tmsize_t TIFFTileSize (TIFF *tif)
 
uint64_t TIFFVTileSize64 (TIFF *tif, uint32_t nrows)
 
tmsize_t TIFFVTileSize (TIFF *tif, uint32_t nrows)
 
uint32_t TIFFDefaultStripSize (TIFF *tif, uint32_t request)
 
void TIFFDefaultTileSize (TIFF *, uint32_t *, uint32_t *)
 
int TIFFFileno (TIFF *)
 
int TIFFSetFileno (TIFF *, int)
 
thandle_t TIFFClientdata (TIFF *)
 
thandle_t TIFFSetClientdata (TIFF *, thandle_t)
 
int TIFFGetMode (TIFF *)
 
int TIFFSetMode (TIFF *, int)
 
int TIFFIsTiled (TIFF *)
 
int TIFFIsByteSwapped (TIFF *)
 
int TIFFIsUpSampled (TIFF *)
 
int TIFFIsMSB2LSB (TIFF *)
 
int TIFFIsBigEndian (TIFF *)
 
int TIFFIsBigTIFF (TIFF *)
 
TIFFReadWriteProc TIFFGetReadProc (TIFF *)
 
TIFFReadWriteProc TIFFGetWriteProc (TIFF *)
 
TIFFSeekProc TIFFGetSeekProc (TIFF *)
 
TIFFCloseProc TIFFGetCloseProc (TIFF *)
 
TIFFSizeProc TIFFGetSizeProc (TIFF *)
 
TIFFMapFileProc TIFFGetMapFileProc (TIFF *)
 
TIFFUnmapFileProc TIFFGetUnmapFileProc (TIFF *)
 
uint32_t TIFFCurrentRow (TIFF *)
 
tdir_t TIFFCurrentDirectory (TIFF *)
 
tdir_t TIFFNumberOfDirectories (TIFF *)
 
uint64_t TIFFCurrentDirOffset (TIFF *)
 
uint32_t TIFFCurrentStrip (TIFF *)
 
uint32_t TIFFCurrentTile (TIFF *tif)
 
int TIFFReadBufferSetup (TIFF *tif, void *bp, tmsize_t size)
 
int TIFFWriteBufferSetup (TIFF *tif, void *bp, tmsize_t size)
 
int TIFFSetupStrips (TIFF *)
 
int TIFFWriteCheck (TIFF *, int, const char *)
 
void TIFFFreeDirectory (TIFF *)
 
int TIFFCreateDirectory (TIFF *)
 
int TIFFCreateCustomDirectory (TIFF *, const TIFFFieldArray *)
 
int TIFFCreateEXIFDirectory (TIFF *)
 
int TIFFCreateGPSDirectory (TIFF *)
 
int TIFFLastDirectory (TIFF *)
 
int TIFFSetDirectory (TIFF *, tdir_t)
 
int TIFFSetSubDirectory (TIFF *, uint64_t)
 
int TIFFUnlinkDirectory (TIFF *, tdir_t)
 
int TIFFSetField (TIFF *, uint32_t,...)
 
int TIFFVSetField (TIFF *, uint32_t, va_list)
 
int TIFFUnsetField (TIFF *, uint32_t)
 
int TIFFWriteDirectory (TIFF *)
 
int TIFFWriteCustomDirectory (TIFF *, uint64_t *)
 
int TIFFCheckpointDirectory (TIFF *)
 
int TIFFRewriteDirectory (TIFF *)
 
int TIFFDeferStrileArrayWriting (TIFF *)
 
int TIFFForceStrileArrayWriting (TIFF *)
 
void TIFFPrintDirectory (TIFF *, FILE *, long)
 
int TIFFReadScanline (TIFF *tif, void *buf, uint32_t row, uint16_t sample)
 
int TIFFWriteScanline (TIFF *tif, void *buf, uint32_t row, uint16_t sample)
 
int TIFFReadRGBAImage (TIFF *, uint32_t, uint32_t, uint32_t *, int)
 
int TIFFReadRGBAImageOriented (TIFF *, uint32_t, uint32_t, uint32_t *, int, int)
 
int TIFFReadRGBAStrip (TIFF *, uint32_t, uint32_t *)
 
int TIFFReadRGBATile (TIFF *, uint32_t, uint32_t, uint32_t *)
 
int TIFFReadRGBAStripExt (TIFF *, uint32_t, uint32_t *, int stop_on_error)
 
int TIFFReadRGBATileExt (TIFF *, uint32_t, uint32_t, uint32_t *, int stop_on_error)
 
int TIFFRGBAImageOK (TIFF *, char[1024])
 
int TIFFRGBAImageBegin (TIFFRGBAImage *, TIFF *, int, char[1024])
 
int TIFFRGBAImageGet (TIFFRGBAImage *, uint32_t *, uint32_t, uint32_t)
 
void TIFFRGBAImageEnd (TIFFRGBAImage *)
 
const charTIFFFileName (TIFF *)
 
const charTIFFSetFileName (TIFF *, const char *)
 
void TIFFError (const char *, const char *,...) TIFF_ATTRIBUTE((__format__(__printf__
 
void void TIFFErrorExt (thandle_t, const char *, const char *,...) TIFF_ATTRIBUTE((__format__(__printf__
 
void void void TIFFWarning (const char *, const char *,...) TIFF_ATTRIBUTE((__format__(__printf__
 
void void void void TIFFWarningExt (thandle_t, const char *, const char *,...) TIFF_ATTRIBUTE((__format__(__printf__
 
void void void void TIFFErrorHandler TIFFSetErrorHandler (TIFFErrorHandler)
 
TIFFErrorHandlerExt TIFFSetErrorHandlerExt (TIFFErrorHandlerExt)
 
TIFFErrorHandler TIFFSetWarningHandler (TIFFErrorHandler)
 
TIFFErrorHandlerExt TIFFSetWarningHandlerExt (TIFFErrorHandlerExt)
 
void TIFFWarningExtR (TIFF *, const char *, const char *,...) TIFF_ATTRIBUTE((__format__(__printf__
 
void void TIFFErrorExtR (TIFF *, const char *, const char *,...) TIFF_ATTRIBUTE((__format__(__printf__
 
TIFFOpenOptionsTIFFOpenOptionsAlloc (void)
 
void TIFFOpenOptionsFree (TIFFOpenOptions *)
 
void TIFFOpenOptionsSetMaxSingleMemAlloc (TIFFOpenOptions *opts, tmsize_t max_single_mem_alloc)
 
void TIFFOpenOptionsSetMaxCumulatedMemAlloc (TIFFOpenOptions *opts, tmsize_t max_cumulated_mem_alloc)
 
void TIFFOpenOptionsSetWarnAboutUnknownTags (TIFFOpenOptions *opts, int warn_about_unknown_tags)
 
void TIFFOpenOptionsSetErrorHandlerExtR (TIFFOpenOptions *opts, TIFFErrorHandlerExtR handler, void *errorhandler_user_data)
 
void TIFFOpenOptionsSetWarningHandlerExtR (TIFFOpenOptions *opts, TIFFErrorHandlerExtR handler, void *warnhandler_user_data)
 
TIFFTIFFOpen (const char *, const char *)
 
TIFFTIFFOpenExt (const char *, const char *, TIFFOpenOptions *opts)
 
TIFFTIFFFdOpen (int, const char *, const char *)
 
TIFFTIFFFdOpenExt (int, const char *, const char *, TIFFOpenOptions *opts)
 
TIFFTIFFClientOpen (const char *, const char *, thandle_t, TIFFReadWriteProc, TIFFReadWriteProc, TIFFSeekProc, TIFFCloseProc, TIFFSizeProc, TIFFMapFileProc, TIFFUnmapFileProc)
 
TIFFTIFFClientOpenExt (const char *, const char *, thandle_t, TIFFReadWriteProc, TIFFReadWriteProc, TIFFSeekProc, TIFFCloseProc, TIFFSizeProc, TIFFMapFileProc, TIFFUnmapFileProc, TIFFOpenOptions *opts)
 
TIFFExtendProc TIFFSetTagExtender (TIFFExtendProc)
 
uint32_t TIFFComputeTile (TIFF *tif, uint32_t x, uint32_t y, uint32_t z, uint16_t s)
 
int TIFFCheckTile (TIFF *tif, uint32_t x, uint32_t y, uint32_t z, uint16_t s)
 
uint32_t TIFFNumberOfTiles (TIFF *)
 
tmsize_t TIFFReadTile (TIFF *tif, void *buf, uint32_t x, uint32_t y, uint32_t z, uint16_t s)
 
tmsize_t TIFFWriteTile (TIFF *tif, void *buf, uint32_t x, uint32_t y, uint32_t z, uint16_t s)
 
uint32_t TIFFComputeStrip (TIFF *, uint32_t, uint16_t)
 
uint32_t TIFFNumberOfStrips (TIFF *)
 
tmsize_t TIFFReadEncodedStrip (TIFF *tif, uint32_t strip, void *buf, tmsize_t size)
 
tmsize_t TIFFReadRawStrip (TIFF *tif, uint32_t strip, void *buf, tmsize_t size)
 
tmsize_t TIFFReadEncodedTile (TIFF *tif, uint32_t tile, void *buf, tmsize_t size)
 
tmsize_t TIFFReadRawTile (TIFF *tif, uint32_t tile, void *buf, tmsize_t size)
 
int TIFFReadFromUserBuffer (TIFF *tif, uint32_t strile, void *inbuf, tmsize_t insize, void *outbuf, tmsize_t outsize)
 
tmsize_t TIFFWriteEncodedStrip (TIFF *tif, uint32_t strip, void *data, tmsize_t cc)
 
tmsize_t TIFFWriteRawStrip (TIFF *tif, uint32_t strip, void *data, tmsize_t cc)
 
tmsize_t TIFFWriteEncodedTile (TIFF *tif, uint32_t tile, void *data, tmsize_t cc)
 
tmsize_t TIFFWriteRawTile (TIFF *tif, uint32_t tile, void *data, tmsize_t cc)
 
int TIFFDataWidth (TIFFDataType)
 
void TIFFSetWriteOffset (TIFF *tif, toff_t off)
 
void TIFFSwabShort (uint16_t *)
 
void TIFFSwabLong (uint32_t *)
 
void TIFFSwabLong8 (uint64_t *)
 
void TIFFSwabFloat (float *)
 
void TIFFSwabDouble (double *)
 
void TIFFSwabArrayOfShort (uint16_t *wp, tmsize_t n)
 
void TIFFSwabArrayOfTriples (uint8_t *tp, tmsize_t n)
 
void TIFFSwabArrayOfLong (uint32_t *lp, tmsize_t n)
 
void TIFFSwabArrayOfLong8 (uint64_t *lp, tmsize_t n)
 
void TIFFSwabArrayOfFloat (float *fp, tmsize_t n)
 
void TIFFSwabArrayOfDouble (double *dp, tmsize_t n)
 
void TIFFReverseBits (uint8_t *cp, tmsize_t n)
 
const unsigned charTIFFGetBitRevTable (int)
 
uint64_t TIFFGetStrileOffset (TIFF *tif, uint32_t strile)
 
uint64_t TIFFGetStrileByteCount (TIFF *tif, uint32_t strile)
 
uint64_t TIFFGetStrileOffsetWithErr (TIFF *tif, uint32_t strile, int *pbErr)
 
uint64_t TIFFGetStrileByteCountWithErr (TIFF *tif, uint32_t strile, int *pbErr)
 
double LogL16toY (int)
 
double LogL10toY (int)
 
void XYZtoRGB24 (float *, uint8_t *)
 
int uv_decode (double *, double *, int)
 
void LogLuv24toXYZ (uint32_t, float *)
 
void LogLuv32toXYZ (uint32_t, float *)
 
int LogL16fromY (double, int)
 
int LogL10fromY (double, int)
 
int uv_encode (double, double, int)
 
uint32_t LogLuv24fromXYZ (float *, int)
 
uint32_t LogLuv32fromXYZ (float *, int)
 
int TIFFCIELabToRGBInit (TIFFCIELabToRGB *, const TIFFDisplay *, float *)
 
void TIFFCIELabToXYZ (TIFFCIELabToRGB *, uint32_t, int32_t, int32_t, float *, float *, float *)
 
void TIFFXYZToRGB (TIFFCIELabToRGB *, float, float, float, uint32_t *, uint32_t *, uint32_t *)
 
int TIFFYCbCrToRGBInit (TIFFYCbCrToRGB *, float *, float *)
 
void TIFFYCbCrtoRGB (TIFFYCbCrToRGB *, uint32_t, int32_t, int32_t, uint32_t *, uint32_t *, uint32_t *)
 
int TIFFMergeFieldInfo (TIFF *, const TIFFFieldInfo[], uint32_t)
 

Macro Definition Documentation

◆ CIELABTORGB_TABLE_RANGE

#define CIELABTORGB_TABLE_RANGE   1500

Definition at line 182 of file tiffio.h.

◆ D50_X0

#define D50_X0   (96.4250F)

Definition at line 132 of file tiffio.h.

◆ D50_Y0

#define D50_Y0   (100.0F)

Definition at line 133 of file tiffio.h.

◆ D50_Z0

#define D50_Z0   (82.4680F)

Definition at line 134 of file tiffio.h.

◆ D65_X0

#define D65_X0   (95.0470F)

Definition at line 128 of file tiffio.h.

◆ D65_Y0

#define D65_Y0   (100.0F)

Definition at line 129 of file tiffio.h.

◆ D65_Z0

#define D65_Z0   (108.8827F)

Definition at line 130 of file tiffio.h.

◆ FIELD_CUSTOM

#define FIELD_CUSTOM   65

Definition at line 346 of file tiffio.h.

◆ LOGLUV_PUBLIC

#define LOGLUV_PUBLIC   1

Definition at line 288 of file tiffio.h.

◆ TIFF_ANY

#define TIFF_ANY   TIFF_NOTYPE /* for field descriptor searching */

Definition at line 341 of file tiffio.h.

◆ TIFF_ATTRIBUTE

#define TIFF_ATTRIBUTE (   x)    /*nothing*/

Definition at line 294 of file tiffio.h.

◆ TIFF_SPP

#define TIFF_SPP   -2 /* marker for SamplesPerPixel tags */

Definition at line 343 of file tiffio.h.

◆ TIFF_TMSIZE_T_MAX

#define TIFF_TMSIZE_T_MAX   (tmsize_t)(SIZE_MAX >> 1)

Definition at line 68 of file tiffio.h.

◆ TIFF_VARIABLE

#define TIFF_VARIABLE   -1 /* marker for variable length tags */

Definition at line 342 of file tiffio.h.

◆ TIFF_VARIABLE2

#define TIFF_VARIABLE2   -3 /* marker for uint32_t var-length tags */

Definition at line 344 of file tiffio.h.

◆ TIFFGetA

#define TIFFGetA (   abgr)    (((abgr) >> 24) & 0xff)

Definition at line 260 of file tiffio.h.

◆ TIFFGetB

#define TIFFGetB (   abgr)    (((abgr) >> 16) & 0xff)

Definition at line 259 of file tiffio.h.

◆ TIFFGetG

#define TIFFGetG (   abgr)    (((abgr) >> 8) & 0xff)

Definition at line 258 of file tiffio.h.

◆ TIFFGetR

#define TIFFGetR (   abgr)    ((abgr)&0xff)

Definition at line 257 of file tiffio.h.

◆ TIFFPRINT_COLORMAP

#define TIFFPRINT_COLORMAP   0x4 /* colormap */

Definition at line 118 of file tiffio.h.

◆ TIFFPRINT_CURVES

#define TIFFPRINT_CURVES   0x2 /* color/gray response curves */

Definition at line 117 of file tiffio.h.

◆ TIFFPRINT_JPEGACTABLES

#define TIFFPRINT_JPEGACTABLES   0x200 /* JPEG AC tables */

Definition at line 120 of file tiffio.h.

◆ TIFFPRINT_JPEGDCTABLES

#define TIFFPRINT_JPEGDCTABLES   0x200 /* JPEG DC tables */

Definition at line 121 of file tiffio.h.

◆ TIFFPRINT_JPEGQTABLES

#define TIFFPRINT_JPEGQTABLES   0x100 /* JPEG Q matrices */

Definition at line 119 of file tiffio.h.

◆ TIFFPRINT_NONE

#define TIFFPRINT_NONE   0x0 /* no extra info */

Definition at line 115 of file tiffio.h.

◆ TIFFPRINT_STRIPS

#define TIFFPRINT_STRIPS   0x1 /* strips/tiles info */

Definition at line 116 of file tiffio.h.

◆ U_NEU

#define U_NEU   0.210526316

Definition at line 612 of file tiffio.h.

◆ UVSCALE

#define UVSCALE   410.

Definition at line 614 of file tiffio.h.

◆ V_NEU

#define V_NEU   0.473684211

Definition at line 613 of file tiffio.h.

Typedef Documentation

◆ tdata_t

typedef void* tdata_t

Definition at line 81 of file tiffio.h.

◆ tdir_t

typedef uint32_t tdir_t

Definition at line 71 of file tiffio.h.

◆ thandle_t

typedef void* thandle_t

Definition at line 106 of file tiffio.h.

◆ TIFF

typedef struct tiff TIFF

Definition at line 38 of file tiffio.h.

◆ TIFFCloseProc

typedef int(* TIFFCloseProc) (thandle_t)

Definition at line 308 of file tiffio.h.

◆ TIFFErrorHandler

typedef void(* TIFFErrorHandler) (const char *, const char *, va_list)

Definition at line 301 of file tiffio.h.

◆ TIFFErrorHandlerExt

typedef void(* TIFFErrorHandlerExt) (thandle_t, const char *, const char *, va_list)

Definition at line 302 of file tiffio.h.

◆ TIFFErrorHandlerExtR

typedef int(* TIFFErrorHandlerExtR) (TIFF *, void *user_data, const char *, const char *, va_list)

Definition at line 304 of file tiffio.h.

◆ TIFFExtendProc

typedef void(* TIFFExtendProc) (TIFF *)

Definition at line 312 of file tiffio.h.

◆ TIFFField

Definition at line 348 of file tiffio.h.

◆ TIFFFieldArray

Definition at line 349 of file tiffio.h.

◆ TIFFInitMethod

typedef int(* TIFFInitMethod) (TIFF *, int)

Definition at line 269 of file tiffio.h.

◆ TIFFMapFileProc

typedef int(* TIFFMapFileProc) (thandle_t, void **base, toff_t *size)

Definition at line 310 of file tiffio.h.

◆ TIFFOpenOptions

Definition at line 516 of file tiffio.h.

◆ TIFFPrintMethod

typedef void(* TIFFPrintMethod) (TIFF *, FILE *, long)

Definition at line 371 of file tiffio.h.

◆ TIFFReadWriteProc

typedef tmsize_t(* TIFFReadWriteProc) (thandle_t, void *, tmsize_t)

Definition at line 306 of file tiffio.h.

◆ TIFFRGBAImage

Definition at line 194 of file tiffio.h.

◆ TIFFRGBValue

Definition at line 138 of file tiffio.h.

◆ TIFFSeekProc

typedef toff_t(* TIFFSeekProc) (thandle_t, toff_t, int)

Definition at line 307 of file tiffio.h.

◆ TIFFSizeProc

typedef toff_t(* TIFFSizeProc) (thandle_t)

Definition at line 309 of file tiffio.h.

◆ TIFFUnmapFileProc

typedef void(* TIFFUnmapFileProc) (thandle_t, void *base, toff_t size)

Definition at line 311 of file tiffio.h.

◆ TIFFVGetMethod

typedef int(* TIFFVGetMethod) (TIFF *, uint32_t, va_list)

Definition at line 370 of file tiffio.h.

◆ TIFFVSetMethod

typedef int(* TIFFVSetMethod) (TIFF *, uint32_t, va_list)

Definition at line 369 of file tiffio.h.

◆ tileContigRoutine

typedef void(* tileContigRoutine) (TIFFRGBAImage *, uint32_t *, uint32_t, uint32_t, uint32_t, uint32_t, int32_t, int32_t, unsigned char *)

Definition at line 205 of file tiffio.h.

◆ tileSeparateRoutine

Definition at line 208 of file tiffio.h.

◆ tmsize_t

Definition at line 67 of file tiffio.h.

◆ toff_t

typedef uint64_t toff_t

Definition at line 70 of file tiffio.h.

◆ tsample_t

Definition at line 76 of file tiffio.h.

◆ tsize_t

typedef tmsize_t tsize_t

Definition at line 80 of file tiffio.h.

◆ tstrile_t

Definition at line 77 of file tiffio.h.

◆ tstrip_t

Definition at line 78 of file tiffio.h.

◆ ttag_t

typedef uint32_t ttag_t

Definition at line 75 of file tiffio.h.

◆ ttile_t

typedef tstrile_t ttile_t

Definition at line 79 of file tiffio.h.

Function Documentation

◆ _TIFFcalloc()

void * _TIFFcalloc ( tmsize_t  nmemb,
tmsize_t  siz 
)

Definition at line 341 of file tif_unix.c.

342{
343 if (nmemb == 0 || siz == 0)
344 return ((void *)NULL);
345
346 return calloc((size_t)nmemb, (size_t)siz);
347}
#define NULL
Definition: types.h:112
#define calloc
Definition: rosglue.h:14

Referenced by _TIFFcallocExt(), and TIFFOpenOptionsAlloc().

◆ _TIFFfree()

void _TIFFfree ( void p)

Definition at line 349 of file tif_unix.c.

349{ free(p); }
#define free
Definition: debug_ros.c:5
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by _TIFFfreeExt(), TIFFOpenOptionsFree(), and TIFFOpenWExt().

◆ _TIFFmalloc()

void * _TIFFmalloc ( tmsize_t  s)

Definition at line 333 of file tif_unix.c.

334{
335 if (s == 0)
336 return ((void *)NULL);
337
338 return (malloc((size_t)s));
339}
#define malloc
Definition: debug_ros.c:4
GLdouble s
Definition: gl.h:2039

Referenced by _TIFFmallocExt(), and TIFFOpenWExt().

◆ _TIFFmemcmp()

int _TIFFmemcmp ( const void p1,
const void p2,
tmsize_t  c 
)

Definition at line 360 of file tif_unix.c.

361{
362 return (memcmp(p1, p2, (size_t)c));
363}
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2802
const GLubyte * c
Definition: glext.h:8905

Referenced by TIFFWriteDirectoryTagTransferfunction().

◆ _TIFFmemcpy()

◆ _TIFFmemset()

◆ _TIFFrealloc()

void * _TIFFrealloc ( void p,
tmsize_t  s 
)

Definition at line 351 of file tif_unix.c.

351{ return (realloc(p, (size_t)s)); }
#define realloc
Definition: debug_ros.c:6

Referenced by _TIFFreallocExt().

◆ LogL10fromY()

int LogL10fromY ( double  ,
int   
)

◆ LogL10toY()

double LogL10toY ( int  )

◆ LogL16fromY()

int LogL16fromY ( double  ,
int   
)

◆ LogL16toY()

double LogL16toY ( int  )

◆ LogLuv24fromXYZ()

uint32_t LogLuv24fromXYZ ( float ,
int   
)

◆ LogLuv24toXYZ()

void LogLuv24toXYZ ( uint32_t  ,
float  
)

◆ LogLuv32fromXYZ()

uint32_t LogLuv32fromXYZ ( float ,
int   
)

◆ LogLuv32toXYZ()

void LogLuv32toXYZ ( uint32_t  ,
float  
)

◆ TIFFAccessTagMethods()

TIFFTagMethods * TIFFAccessTagMethods ( TIFF tif)

Definition at line 58 of file tif_extension.c.

60{
61 return &(tif->tif_tagmethods);
62}
TIFFTagMethods tif_tagmethods
Definition: tiffiop.h:244

◆ TIFFCheckpointDirectory()

int TIFFCheckpointDirectory ( TIFF tif)

Definition at line 292 of file tif_dirwrite.c.

293{
294 int rc;
295 /* Setup the strips arrays, if they haven't already been. */
296 if (tif->tif_dir.td_stripoffset_p == NULL)
297 (void)TIFFSetupStrips(tif);
300 return rc;
301}
#define SEEK_END
Definition: cabinet.c:29
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
uint64_t * td_stripoffset_p
Definition: tif_dir.h:113
TIFFDirectory tif_dir
Definition: tiffiop.h:157
static int TIFFWriteDirectorySec(TIFF *tif, int isimage, int imagedone, uint64_t *pdiroff)
Definition: tif_dirwrite.c:488
void TIFFSetWriteOffset(TIFF *tif, toff_t off)
Definition: tif_write.c:961
int TIFFSetupStrips(TIFF *tif)
Definition: tif_write.c:553
#define TIFFSeekFile(tif, off, whence)
Definition: tiffiop.h:282

◆ TIFFCheckTile()

int TIFFCheckTile ( TIFF tif,
uint32_t  x,
uint32_t  y,
uint32_t  z,
uint16_t  s 
)

Definition at line 71 of file tif_tile.c.

72{
73 TIFFDirectory *td = &tif->tif_dir;
74
75 if (x >= td->td_imagewidth)
76 {
77 TIFFErrorExtR(tif, tif->tif_name, "%lu: Col out of range, max %lu",
78 (unsigned long)x, (unsigned long)(td->td_imagewidth - 1));
79 return (0);
80 }
81 if (y >= td->td_imagelength)
82 {
83 TIFFErrorExtR(tif, tif->tif_name, "%lu: Row out of range, max %lu",
84 (unsigned long)y,
85 (unsigned long)(td->td_imagelength - 1));
86 return (0);
87 }
88 if (z >= td->td_imagedepth)
89 {
90 TIFFErrorExtR(tif, tif->tif_name, "%lu: Depth out of range, max %lu",
91 (unsigned long)z, (unsigned long)(td->td_imagedepth - 1));
92 return (0);
93 }
95 s >= td->td_samplesperpixel)
96 {
97 TIFFErrorExtR(tif, tif->tif_name, "%lu: Sample out of range, max %lu",
98 (unsigned long)s,
99 (unsigned long)(td->td_samplesperpixel - 1));
100 return (0);
101 }
102 return (1);
103}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLdouble GLdouble z
Definition: glext.h:5874
uint32_t td_imagewidth
Definition: tif_dir.h:83
uint32_t td_imagedepth
Definition: tif_dir.h:83
uint16_t td_planarconfig
Definition: tif_dir.h:100
uint16_t td_samplesperpixel
Definition: tif_dir.h:93
uint32_t td_imagelength
Definition: tif_dir.h:83
char * tif_name
Definition: tiffiop.h:114
void TIFFErrorExtR(TIFF *tif, const char *module, const char *fmt,...)
Definition: tif_error.c:107
#define PLANARCONFIG_SEPARATE
Definition: tiff.h:266

Referenced by _TIFFReadTileAndAllocBuffer(), TIFFReadTile(), and TIFFWriteTile().

◆ TIFFCIELabToRGBInit()

int TIFFCIELabToRGBInit ( TIFFCIELabToRGB cielab,
const TIFFDisplay display,
float refWhite 
)

Definition at line 135 of file tif_color.c.

137{
138 size_t i;
139 double dfGamma;
140
142
143 _TIFFmemcpy(&cielab->display, display, sizeof(TIFFDisplay));
144
145 /* Red */
146 dfGamma = 1.0 / cielab->display.d_gammaR;
147 cielab->rstep =
148 (cielab->display.d_YCR - cielab->display.d_Y0R) / cielab->range;
149 for (i = 0; i <= (size_t)cielab->range; i++)
150 {
151 cielab->Yr2r[i] = cielab->display.d_Vrwr *
152 ((float)pow((double)i / cielab->range, dfGamma));
153 }
154
155 /* Green */
156 dfGamma = 1.0 / cielab->display.d_gammaG;
157 cielab->gstep =
158 (cielab->display.d_YCR - cielab->display.d_Y0R) / cielab->range;
159 for (i = 0; i <= (size_t)cielab->range; i++)
160 {
161 cielab->Yg2g[i] = cielab->display.d_Vrwg *
162 ((float)pow((double)i / cielab->range, dfGamma));
163 }
164
165 /* Blue */
166 dfGamma = 1.0 / cielab->display.d_gammaB;
167 cielab->bstep =
168 (cielab->display.d_YCR - cielab->display.d_Y0R) / cielab->range;
169 for (i = 0; i <= (size_t)cielab->range; i++)
170 {
171 cielab->Yb2b[i] = cielab->display.d_Vrwb *
172 ((float)pow((double)i / cielab->range, dfGamma));
173 }
174
175 /* Init reference white point */
176 cielab->X0 = refWhite[0];
177 cielab->Y0 = refWhite[1];
178 cielab->Z0 = refWhite[2];
179
180 return 0;
181}
unsigned int size_t
Definition: corecrt.h:203
double pow(double x, double y)
Definition: freeldr.c:179
for(i=0;i< ARRAY_SIZE(offsets);i++)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static float(__cdecl *square_half_float)(float x
float Yb2b[CIELABTORGB_TABLE_RANGE+1]
Definition: tiffio.h:188
float bstep
Definition: tiffio.h:183
TIFFDisplay display
Definition: tiffio.h:185
float rstep
Definition: tiffio.h:183
float gstep
Definition: tiffio.h:183
float Yr2r[CIELABTORGB_TABLE_RANGE+1]
Definition: tiffio.h:186
float Yg2g[CIELABTORGB_TABLE_RANGE+1]
Definition: tiffio.h:187
float d_gammaG
Definition: tiffio.h:153
uint32_t d_Vrwr
Definition: tiffio.h:146
float d_Y0R
Definition: tiffio.h:149
float d_gammaR
Definition: tiffio.h:152
float d_YCR
Definition: tiffio.h:143
uint32_t d_Vrwg
Definition: tiffio.h:147
float d_gammaB
Definition: tiffio.h:154
uint32_t d_Vrwb
Definition: tiffio.h:148
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Definition: tif_unix.c:355
#define CIELABTORGB_TABLE_RANGE
Definition: tiffio.h:182
int * display
Definition: x11stubs.c:12

Referenced by initCIELabConversion().

◆ TIFFCIELabToXYZ()

void TIFFCIELabToXYZ ( TIFFCIELabToRGB cielab,
uint32_t  l,
int32_t  a,
int32_t  b,
float X,
float Y,
float Z 
)

Definition at line 43 of file tif_color.c.

45{
46 TIFFCIELab16ToXYZ(cielab, l * 257, a * 256, b * 256, X, Y, Z);
47}
r l[0]
Definition: byte_order.h:168
#define Z(I)
#define Y(I)
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
void TIFFCIELab16ToXYZ(TIFFCIELabToRGB *cielab, uint32_t l, int32_t a, int32_t b, float *X, float *Y, float *Z)
Definition: tif_color.c:55

Referenced by DECLAREContigPutFunc().

◆ TIFFCleanup()

void TIFFCleanup ( TIFF tif)

Auxiliary function to free the TIFF structure. Given structure will be completely freed, so you should save opened file handle and pointer to the close procedure in external variables before calling _TIFFCleanup(), if you will need these ones to close the file.

Parameters
tifA TIFF pointer.

Definition at line 44 of file tif_close.c.

45{
46 /*
47 * Flush buffered data and directory (if dirty).
48 */
49 if (tif->tif_mode != O_RDONLY)
50 TIFFFlush(tif);
52
54
55 /*
56 * Clean up client info links.
57 */
58 while (tif->tif_clientinfo)
59 {
61
62 tif->tif_clientinfo = psLink->next;
63 _TIFFfreeExt(tif, psLink->name);
64 _TIFFfreeExt(tif, psLink);
65 }
66
67 if (tif->tif_rawdata && (tif->tif_flags & TIFF_MYBUFFER))
68 _TIFFfreeExt(tif, tif->tif_rawdata);
69 if (isMapped(tif))
71
72 /*
73 * Clean up custom fields.
74 */
75 if (tif->tif_fields && tif->tif_nfields > 0)
76 {
77 uint32_t i;
78
79 for (i = 0; i < tif->tif_nfields; i++)
80 {
81 TIFFField *fld = tif->tif_fields[i];
82 if (fld->field_name != NULL)
83 {
84 if (fld->field_bit == FIELD_CUSTOM &&
85 /* caution: tif_fields[i] must not be the beginning of a
86 * fields-array. Otherwise the following tags are also freed
87 * with the first free().
88 */
90 {
91 _TIFFfreeExt(tif, fld->field_name);
92 _TIFFfreeExt(tif, fld);
93 }
94 }
95 }
96
97 _TIFFfreeExt(tif, tif->tif_fields);
98 }
99
100 if (tif->tif_nfieldscompat > 0)
101 {
102 uint32_t i;
103
104 for (i = 0; i < tif->tif_nfieldscompat; i++)
105 {
108 }
110 }
111
112 if (tif->tif_cur_cumulated_mem_alloc != 0)
113 {
114 TIFFErrorExtR(tif, "TIFFCleanup",
115 "tif_cur_cumulated_mem_alloc = %" PRIu64 " whereas it "
116 "should be 0",
118 }
119
120 _TIFFfreeExt(NULL, tif);
121}
UINT32 uint32_t
Definition: types.h:75
UINT64 uint64_t
Definition: types.h:77
#define O_RDONLY
Definition: fcntl.h:34
#define PRIu64
Definition: inttypes.h:28
uint32_t allocated_size
Definition: tif_dir.h:324
TIFFField * fields
Definition: tif_dir.h:327
char * field_name
Definition: tif_dir.h:343
unsigned short field_bit
Definition: tif_dir.h:340
struct client_info * next
Definition: tiffiop.h:76
char * name
Definition: tiffiop.h:78
size_t tif_nfields
Definition: tiffiop.h:242
TIFFClientInfoLink * tif_clientinfo
Definition: tiffiop.h:245
TIFFField ** tif_fields
Definition: tiffiop.h:241
tmsize_t tif_size
Definition: tiffiop.h:228
tmsize_t tif_cur_cumulated_mem_alloc
Definition: tiffiop.h:257
uint8_t * tif_rawdata
Definition: tiffiop.h:220
uint32_t tif_flags
Definition: tiffiop.h:117
size_t tif_nfieldscompat
Definition: tiffiop.h:249
int tif_mode
Definition: tiffiop.h:116
TIFFFieldArray * tif_fieldscompat
Definition: tiffiop.h:248
uint8_t * tif_base
Definition: tiffiop.h:227
void _TIFFCleanupIFDOffsetAndNumberMaps(TIFF *tif)
Definition: tif_close.c:127
void TIFFFreeDirectory(TIFF *tif)
Definition: tif_dir.c:1619
int TIFFFieldIsAnonymous(const TIFFField *fip)
Definition: tif_dirinfo.c:879
int TIFFFlush(TIFF *tif)
Definition: tif_flush.c:30
void _TIFFfreeExt(TIFF *tif, void *p)
Definition: tif_open.c:275
#define FIELD_CUSTOM
Definition: tiffio.h:346
uint64_t toff_t
Definition: tiffio.h:70
#define TIFF_MYBUFFER
Definition: tiffiop.h:126
#define TIFFUnmapFileContents(tif, addr, size)
Definition: tiffiop.h:288
#define isMapped(tif)
Definition: tiffiop.h:275

Referenced by TIFFClientOpenExt(), and TIFFClose().

◆ TIFFClientdata()

thandle_t TIFFClientdata ( TIFF tif)

Definition at line 828 of file tif_open.c.

828{ return (tif->tif_clientdata); }
thandle_t tif_clientdata
Definition: tiffiop.h:232

◆ TIFFClientOpen()

TIFF * TIFFClientOpen ( const char name,
const char mode,
thandle_t  clientdata,
TIFFReadWriteProc  readproc,
TIFFReadWriteProc  writeproc,
TIFFSeekProc  seekproc,
TIFFCloseProc  closeproc,
TIFFSizeProc  sizeproc,
TIFFMapFileProc  mapproc,
TIFFUnmapFileProc  unmapproc 
)

Definition at line 289 of file tif_open.c.

294{
295 return TIFFClientOpenExt(name, mode, clientdata, readproc, writeproc,
296 seekproc, closeproc, sizeproc, mapproc, unmapproc,
297 NULL);
298}
GLenum mode
Definition: glext.h:6217
static BOOL readproc(HANDLE proc, LPVOID address, PVOID target, DWORD size)
Definition: env.c:217
Definition: name.c:39
TIFF * TIFFClientOpenExt(const char *name, const char *mode, thandle_t clientdata, TIFFReadWriteProc readproc, TIFFReadWriteProc writeproc, TIFFSeekProc seekproc, TIFFCloseProc closeproc, TIFFSizeProc sizeproc, TIFFMapFileProc mapproc, TIFFUnmapFileProc unmapproc, TIFFOpenOptions *opts)
Definition: tif_open.c:300

Referenced by _tiffStreamOpen(), and tiff_open_stream().

◆ TIFFClientOpenExt()

TIFF * TIFFClientOpenExt ( const char name,
const char mode,
thandle_t  clientdata,
TIFFReadWriteProc  readproc,
TIFFReadWriteProc  writeproc,
TIFFSeekProc  seekproc,
TIFFCloseProc  closeproc,
TIFFSizeProc  sizeproc,
TIFFMapFileProc  mapproc,
TIFFUnmapFileProc  unmapproc,
TIFFOpenOptions opts 
)

Definition at line 300 of file tif_open.c.

306{
307 static const char module[] = "TIFFClientOpenExt";
308 TIFF *tif;
309 int m;
310 const char *cp;
311
312 /* The following are configuration checks. They should be redundant, but
313 * should not compile to any actual code in an optimised release build
314 * anyway. If any of them fail, (makefile-based or other) configuration is
315 * not correct */
316 assert(sizeof(uint8_t) == 1);
317 assert(sizeof(int8_t) == 1);
318 assert(sizeof(uint16_t) == 2);
319 assert(sizeof(int16_t) == 2);
320 assert(sizeof(uint32_t) == 4);
321 assert(sizeof(int32_t) == 4);
322 assert(sizeof(uint64_t) == 8);
323 assert(sizeof(int64_t) == 8);
324 {
325 union
326 {
327 uint8_t a8[2];
328 uint16_t a16;
329 } n;
330 n.a8[0] = 1;
331 n.a8[1] = 0;
332 (void)n;
333#ifdef WORDS_BIGENDIAN
334 assert(n.a16 == 256);
335#else
336 assert(n.a16 == 1);
337#endif
338 }
339
340 m = _TIFFgetMode(opts, clientdata, mode, module);
341 if (m == -1)
342 goto bad2;
343 tmsize_t size_to_alloc = (tmsize_t)(sizeof(TIFF) + strlen(name) + 1);
344 if (opts && opts->max_single_mem_alloc > 0 &&
345 size_to_alloc > opts->max_single_mem_alloc)
346 {
347 _TIFFErrorEarly(opts, clientdata, module,
348 "%s: Memory allocation of %" PRIu64
349 " bytes is beyond the %" PRIu64
350 " byte limit defined in open options",
351 name, (uint64_t)size_to_alloc,
353 goto bad2;
354 }
355 if (opts && opts->max_cumulated_mem_alloc > 0 &&
356 size_to_alloc > opts->max_cumulated_mem_alloc)
357 {
358 _TIFFErrorEarly(opts, clientdata, module,
359 "%s: Memory allocation of %" PRIu64
360 " bytes is beyond the %" PRIu64
361 " cumulated byte limit defined in open options",
362 name, (uint64_t)size_to_alloc,
364 goto bad2;
365 }
366 tif = (TIFF *)_TIFFmallocExt(NULL, size_to_alloc);
367 if (tif == NULL)
368 {
369 _TIFFErrorEarly(opts, clientdata, module,
370 "%s: Out of memory (TIFF structure)", name);
371 goto bad2;
372 }
373 _TIFFmemset(tif, 0, sizeof(*tif));
374 tif->tif_name = (char *)tif + sizeof(TIFF);
375 strcpy(tif->tif_name, name);
376 tif->tif_mode = m & ~(O_CREAT | O_TRUNC);
377 tif->tif_curdir = TIFF_NON_EXISTENT_DIR_NUMBER; /* non-existent directory */
379 tif->tif_curoff = 0;
380 tif->tif_curstrip = (uint32_t)-1; /* invalid strip */
381 tif->tif_row = (uint32_t)-1; /* read/write pre-increment */
382 tif->tif_clientdata = clientdata;
383 tif->tif_readproc = readproc;
384 tif->tif_writeproc = writeproc;
385 tif->tif_seekproc = seekproc;
386 tif->tif_closeproc = closeproc;
387 tif->tif_sizeproc = sizeproc;
388 tif->tif_mapproc = mapproc ? mapproc : _tiffDummyMapProc;
389 tif->tif_unmapproc = unmapproc ? unmapproc : _tiffDummyUnmapProc;
390 if (opts)
391 {
392 tif->tif_errorhandler = opts->errorhandler;
394 tif->tif_warnhandler = opts->warnhandler;
399 }
400
401 if (!readproc || !writeproc || !seekproc || !closeproc || !sizeproc)
402 {
404 "One of the client procedures is NULL pointer.");
405 _TIFFfreeExt(NULL, tif);
406 goto bad2;
407 }
408
409 _TIFFSetDefaultCompressionState(tif); /* setup default state */
410 /*
411 * Default is to return data MSB2LSB and enable the
412 * use of memory-mapped files and strip chopping when
413 * a file is opened read-only.
414 */
416 if (m == O_RDONLY)
417 tif->tif_flags |= TIFF_MAPPED;
418
419#ifdef STRIPCHOP_DEFAULT
420 if (m == O_RDONLY || m == O_RDWR)
422#endif
423
424 /*
425 * Process library-specific flags in the open mode string.
426 * The following flags may be used to control intrinsic library
427 * behavior that may or may not be desirable (usually for
428 * compatibility with some application that claims to support
429 * TIFF but only supports some brain dead idea of what the
430 * vendor thinks TIFF is):
431 *
432 * 'l' use little-endian byte order for creating a file
433 * 'b' use big-endian byte order for creating a file
434 * 'L' read/write information using LSB2MSB bit order
435 * 'B' read/write information using MSB2LSB bit order
436 * 'H' read/write information using host bit order
437 * 'M' enable use of memory-mapped files when supported
438 * 'm' disable use of memory-mapped files
439 * 'C' enable strip chopping support when reading
440 * 'c' disable strip chopping support
441 * 'h' read TIFF header only, do not load the first IFD
442 * '4' ClassicTIFF for creating a file (default)
443 * '8' BigTIFF for creating a file
444 * 'D' enable use of deferred strip/tile offset/bytecount array loading.
445 * 'O' on-demand loading of values instead of whole array loading (implies
446 * D)
447 *
448 * The use of the 'l' and 'b' flags is strongly discouraged.
449 * These flags are provided solely because numerous vendors,
450 * typically on the PC, do not correctly support TIFF; they
451 * only support the Intel little-endian byte order. This
452 * support is not configured by default because it supports
453 * the violation of the TIFF spec that says that readers *MUST*
454 * support both byte orders. It is strongly recommended that
455 * you not use this feature except to deal with busted apps
456 * that write invalid TIFF. And even in those cases you should
457 * bang on the vendors to fix their software.
458 *
459 * The 'L', 'B', and 'H' flags are intended for applications
460 * that can optimize operations on data by using a particular
461 * bit order. By default the library returns data in MSB2LSB
462 * bit order for compatibility with older versions of this
463 * library. Returning data in the bit order of the native CPU
464 * makes the most sense but also requires applications to check
465 * the value of the FillOrder tag; something they probably do
466 * not do right now.
467 *
468 * The 'M' and 'm' flags are provided because some virtual memory
469 * systems exhibit poor behavior when large images are mapped.
470 * These options permit clients to control the use of memory-mapped
471 * files on a per-file basis.
472 *
473 * The 'C' and 'c' flags are provided because the library support
474 * for chopping up large strips into multiple smaller strips is not
475 * application-transparent and as such can cause problems. The 'c'
476 * option permits applications that only want to look at the tags,
477 * for example, to get the unadulterated TIFF tag information.
478 */
479 for (cp = mode; *cp; cp++)
480 switch (*cp)
481 {
482 case 'b':
483#ifndef WORDS_BIGENDIAN
484 if (m & O_CREAT)
485 tif->tif_flags |= TIFF_SWAB;
486#endif
487 break;
488 case 'l':
489#ifdef WORDS_BIGENDIAN
490 if ((m & O_CREAT))
491 tif->tif_flags |= TIFF_SWAB;
492#endif
493 break;
494 case 'B':
495 tif->tif_flags =
496 (tif->tif_flags & ~TIFF_FILLORDER) | FILLORDER_MSB2LSB;
497 break;
498 case 'L':
499 tif->tif_flags =
500 (tif->tif_flags & ~TIFF_FILLORDER) | FILLORDER_LSB2MSB;
501 break;
502 case 'H':
504 "H(ost) mode is deprecated. Since "
505 "libtiff 4.5.1, it is an alias of 'B' / "
506 "FILLORDER_MSB2LSB.");
507 tif->tif_flags =
508 (tif->tif_flags & ~TIFF_FILLORDER) | FILLORDER_MSB2LSB;
509 break;
510 case 'M':
511 if (m == O_RDONLY)
512 tif->tif_flags |= TIFF_MAPPED;
513 break;
514 case 'm':
515 if (m == O_RDONLY)
516 tif->tif_flags &= ~TIFF_MAPPED;
517 break;
518 case 'C':
519 if (m == O_RDONLY)
521 break;
522 case 'c':
523 if (m == O_RDONLY)
524 tif->tif_flags &= ~TIFF_STRIPCHOP;
525 break;
526 case 'h':
528 break;
529 case '8':
530 if (m & O_CREAT)
531 tif->tif_flags |= TIFF_BIGTIFF;
532 break;
533 case 'D':
535 break;
536 case 'O':
537 if (m == O_RDONLY)
538 tif->tif_flags |=
540 break;
541 }
542
543#ifdef DEFER_STRILE_LOAD
544 /* Compatibility with old DEFER_STRILE_LOAD compilation flag */
545 /* Probably unneeded, since to the best of my knowledge (E. Rouault) */
546 /* GDAL was the only user of this, and will now use the new 'D' flag */
548#endif
549
550 /*
551 * Read in TIFF header.
552 */
553 if ((m & O_TRUNC) ||
554 !ReadOK(tif, &tif->tif_header, sizeof(TIFFHeaderClassic)))
555 {
556 if (tif->tif_mode == O_RDONLY)
557 {
558 TIFFErrorExtR(tif, name, "Cannot read TIFF header");
559 goto bad;
560 }
561 /*
562 * Setup header and write.
563 */
564#ifdef WORDS_BIGENDIAN
567#else
570#endif
571 TIFFHeaderUnion tif_header_swapped;
572 if (!(tif->tif_flags & TIFF_BIGTIFF))
573 {
576 tif->tif_header_size = sizeof(TIFFHeaderClassic);
577 /* Swapped copy for writing */
578 _TIFFmemcpy(&tif_header_swapped, &tif->tif_header,
579 sizeof(TIFFHeaderUnion));
580 if (tif->tif_flags & TIFF_SWAB)
581 TIFFSwabShort(&tif_header_swapped.common.tiff_version);
582 }
583 else
584 {
587 tif->tif_header.big.tiff_unused = 0;
588 tif->tif_header.big.tiff_diroff = 0;
589 tif->tif_header_size = sizeof(TIFFHeaderBig);
590 /* Swapped copy for writing */
591 _TIFFmemcpy(&tif_header_swapped, &tif->tif_header,
592 sizeof(TIFFHeaderUnion));
593 if (tif->tif_flags & TIFF_SWAB)
594 {
595 TIFFSwabShort(&tif_header_swapped.common.tiff_version);
596 TIFFSwabShort(&tif_header_swapped.big.tiff_offsetsize);
597 }
598 }
599 /*
600 * The doc for "fopen" for some STD_C_LIBs says that if you
601 * open a file for modify ("+"), then you must fseek (or
602 * fflush?) between any freads and fwrites. This is not
603 * necessary on most systems, but has been shown to be needed
604 * on Solaris.
605 */
606 TIFFSeekFile(tif, 0, SEEK_SET);
607 if (!WriteOK(tif, &tif_header_swapped,
608 (tmsize_t)(tif->tif_header_size)))
609 {
610 TIFFErrorExtR(tif, name, "Error writing TIFF header");
611 goto bad;
612 }
613 /*
614 * Setup default directory.
615 */
616 if (!TIFFDefaultDirectory(tif))
617 goto bad;
618 tif->tif_diroff = 0;
619 tif->tif_lastdiroff = 0;
621 /* tif_curdircount = 0 means 'empty file opened for writing, but no IFD
622 * written yet' */
623 tif->tif_curdircount = 0;
624 return (tif);
625 }
626
627 /*
628 * Setup the byte order handling according to the opened file for reading.
629 */
632#if MDI_SUPPORT
633 &&
636#else
638#endif
639 )
640 {
641 TIFFErrorExtR(tif, name,
642 "Not a TIFF or MDI file, bad magic number %" PRIu16
643 " (0x%" PRIx16 ")",
644#else
645 )
646 {
647 TIFFErrorExtR(tif, name,
648 "Not a TIFF file, bad magic number %" PRIu16
649 " (0x%" PRIx16 ")",
650#endif
653 goto bad;
654 }
656 {
657#ifndef WORDS_BIGENDIAN
658 tif->tif_flags |= TIFF_SWAB;
659#endif
660 }
661 else
662 {
663#ifdef WORDS_BIGENDIAN
664 tif->tif_flags |= TIFF_SWAB;
665#endif
666 }
667 if (tif->tif_flags & TIFF_SWAB)
671 {
672 TIFFErrorExtR(tif, name,
673 "Not a TIFF file, bad version number %" PRIu16
674 " (0x%" PRIx16 ")",
677 goto bad;
678 }
680 {
681 if (tif->tif_flags & TIFF_SWAB)
683 tif->tif_header_size = sizeof(TIFFHeaderClassic);
684 }
685 else
686 {
687 if (!ReadOK(tif,
688 ((uint8_t *)(&tif->tif_header) + sizeof(TIFFHeaderClassic)),
689 (sizeof(TIFFHeaderBig) - sizeof(TIFFHeaderClassic))))
690 {
691 TIFFErrorExtR(tif, name, "Cannot read TIFF header");
692 goto bad;
693 }
694 if (tif->tif_flags & TIFF_SWAB)
695 {
698 }
699 if (tif->tif_header.big.tiff_offsetsize != 8)
700 {
701 TIFFErrorExtR(tif, name,
702 "Not a TIFF file, bad BigTIFF offsetsize %" PRIu16
703 " (0x%" PRIx16 ")",
706 goto bad;
707 }
708 if (tif->tif_header.big.tiff_unused != 0)
709 {
710 TIFFErrorExtR(tif, name,
711 "Not a TIFF file, bad BigTIFF unused %" PRIu16
712 " (0x%" PRIx16 ")",
715 goto bad;
716 }
717 tif->tif_header_size = sizeof(TIFFHeaderBig);
718 tif->tif_flags |= TIFF_BIGTIFF;
719 }
720 tif->tif_flags |= TIFF_MYBUFFER;
721 tif->tif_rawcp = tif->tif_rawdata = 0;
722 tif->tif_rawdatasize = 0;
723 tif->tif_rawdataoff = 0;
724 tif->tif_rawdataloaded = 0;
725
726 switch (mode[0])
727 {
728 case 'r':
729 if (!(tif->tif_flags & TIFF_BIGTIFF))
731 else
733 /*
734 * Try to use a memory-mapped file if the client
735 * has not explicitly suppressed usage with the
736 * 'm' flag in the open mode (see above).
737 */
738 if (tif->tif_flags & TIFF_MAPPED)
739 {
740 toff_t n;
741 if (TIFFMapFileContents(tif, (void **)(&tif->tif_base), &n))
742 {
743 tif->tif_size = (tmsize_t)n;
744 assert((toff_t)tif->tif_size == n);
745 }
746 else
747 tif->tif_flags &= ~TIFF_MAPPED;
748 }
749 /*
750 * Sometimes we do not want to read the first directory (for
751 * example, it may be broken) and want to proceed to other
752 * directories. I this case we use the TIFF_HEADERONLY flag to open
753 * file and return immediately after reading TIFF header.
754 * However, the pointer to TIFFSetField() and TIFFGetField()
755 * (i.e. tif->tif_tagmethods.vsetfield and
756 * tif->tif_tagmethods.vgetfield) need to be initialized, which is
757 * done in TIFFDefaultDirectory().
758 */
759 if (tif->tif_flags & TIFF_HEADERONLY)
760 {
761 if (!TIFFDefaultDirectory(tif))
762 goto bad;
763 return (tif);
764 }
765
766 /*
767 * Setup initial directory.
768 */
769 if (TIFFReadDirectory(tif))
770 {
771 return (tif);
772 }
773 break;
774 case 'a':
775 /*
776 * New directories are automatically append
777 * to the end of the directory chain when they
778 * are written out (see TIFFWriteDirectory).
779 */
780 if (!TIFFDefaultDirectory(tif))
781 goto bad;
782 return (tif);
783 }
784bad:
785 tif->tif_mode = O_RDONLY; /* XXX avoid flush */
786 TIFFCleanup(tif);
787bad2:
788 return ((TIFF *)0);
789}
INT32 int32_t
Definition: types.h:71
INT16 int16_t
Definition: types.h:70
INT64 int64_t
Definition: types.h:72
#define assert(_expr)
Definition: assert.h:32
#define O_CREAT
Definition: fcntl.h:43
#define O_RDWR
Definition: fcntl.h:36
#define O_TRUNC
Definition: fcntl.h:44
#define PRIx16
Definition: inttypes.h:100
#define PRIu16
Definition: inttypes.h:83
unsigned short uint16_t
Definition: stdint.h:35
unsigned char uint8_t
Definition: stdint.h:33
signed char int8_t
Definition: stdint.h:32
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
GLdouble n
Definition: glext.h:7729
const GLfloat * m
Definition: glext.h:10848
#define SEEK_SET
Definition: jmemansi.c:26
if(dx< 0)
Definition: linetemp.h:194
POINT cp
Definition: magnifier.c:59
#define uint32_t
Definition: nsiface.idl:61
strcpy
Definition: string.h:131
uint64_t tiff_diroff
Definition: tiff.h:122
uint16_t tiff_unused
Definition: tiff.h:121
uint16_t tiff_offsetsize
Definition: tiff.h:120
uint32_t tiff_diroff
Definition: tiff.h:114
uint16_t tiff_magic
Definition: tiff.h:107
uint16_t tiff_version
Definition: tiff.h:108
void * errorhandler_user_data
Definition: tiffiop.h:264
tmsize_t max_cumulated_mem_alloc
Definition: tiffiop.h:268
TIFFErrorHandlerExtR errorhandler
Definition: tiffiop.h:263
int warn_about_unknown_tags
Definition: tiffiop.h:269
TIFFErrorHandlerExtR warnhandler
Definition: tiffiop.h:265
void * warnhandler_user_data
Definition: tiffiop.h:266
tmsize_t max_single_mem_alloc
Definition: tiffiop.h:267
Definition: tiffiop.h:113
TIFFReadWriteProc tif_readproc
Definition: tiffiop.h:233
int tif_warn_about_unknown_tags
Definition: tiffiop.h:258
TIFFReadWriteProc tif_writeproc
Definition: tiffiop.h:234
tdir_t tif_curdircount
Definition: tiffiop.h:183
tmsize_t tif_max_single_mem_alloc
Definition: tiffiop.h:255
TIFFUnmapFileProc tif_unmapproc
Definition: tiffiop.h:230
TIFFSeekProc tif_seekproc
Definition: tiffiop.h:235
int tif_setdirectory_force_absolute
Definition: tiffiop.h:155
TIFFErrorHandlerExtR tif_errorhandler
Definition: tiffiop.h:251
tmsize_t tif_rawdataloaded
Definition: tiffiop.h:223
uint64_t tif_curoff
Definition: tiffiop.h:185
uint64_t tif_nextdiroff
Definition: tiffiop.h:151
void * tif_errorhandler_user_data
Definition: tiffiop.h:252
TIFFCloseProc tif_closeproc
Definition: tiffiop.h:236
uint64_t tif_diroff
Definition: tiffiop.h:150
TIFFErrorHandlerExtR tif_warnhandler
Definition: tiffiop.h:253
uint16_t tif_header_size
Definition: tiffiop.h:161
tdir_t tif_curdir
Definition: tiffiop.h:179
void * tif_warnhandler_user_data
Definition: tiffiop.h:254
uint8_t * tif_rawcp
Definition: tiffiop.h:224
TIFFMapFileProc tif_mapproc
Definition: tiffiop.h:229
TIFFHeaderUnion tif_header
Definition: tiffiop.h:160
tmsize_t tif_rawdatasize
Definition: tiffiop.h:221
tmsize_t tif_max_cumulated_mem_alloc
Definition: tiffiop.h:256
tmsize_t tif_rawdataoff
Definition: tiffiop.h:222
uint32_t tif_row
Definition: tiffiop.h:162
uint64_t tif_lastdiroff
Definition: tiffiop.h:152
uint32_t tif_curstrip
Definition: tiffiop.h:184
TIFFSizeProc tif_sizeproc
Definition: tiffiop.h:237
void TIFFCleanup(TIFF *tif)
Definition: tif_close.c:44
void _TIFFSetDefaultCompressionState(TIFF *tif)
Definition: tif_compress.c:142
int TIFFDefaultDirectory(TIFF *tif)
Definition: tif_dir.c:1752
int TIFFReadDirectory(TIFF *tif)
Definition: tif_dirread.c:4236
void _TIFFErrorEarly(TIFFOpenOptions *opts, thandle_t clientdata, const char *module, const char *fmt,...)
Definition: tif_error.c:80
int _tiffDummyMapProc(thandle_t fd, void **pbase, toff_t *psize)
Definition: tif_open.c:40
int _TIFFgetMode(TIFFOpenOptions *opts, thandle_t clientdata, const char *mode, const char *module)
Definition: tif_open.c:55
void * _TIFFmallocExt(TIFF *tif, tmsize_t s)
Definition: tif_open.c:173
void _tiffDummyUnmapProc(thandle_t fd, void *base, toff_t size)
Definition: tif_open.c:48
void TIFFSwabLong8(uint64_t *lp)
Definition: tif_swab.c:60
void TIFFSwabShort(uint16_t *wp)
Definition: tif_swab.c:33
void TIFFSwabLong(uint32_t *lp)
Definition: tif_swab.c:45
void _TIFFmemset(void *p, int v, tmsize_t c)
Definition: tif_unix.c:353
void TIFFWarningExtR(TIFF *tif, const char *module, const char *fmt,...)
Definition: tif_warning.c:80
#define FILLORDER_LSB2MSB
Definition: tiff.h:242
#define TIFF_LITTLEENDIAN
Definition: tiff.h:52
#define MDI_LITTLEENDIAN
Definition: tiff.h:53
#define FILLORDER_MSB2LSB
Definition: tiff.h:241
#define MDI_BIGENDIAN
Definition: tiff.h:54
#define TIFF_VERSION_BIG
Definition: tiff.h:49
#define TIFF_VERSION_CLASSIC
Definition: tiff.h:48
#define TIFF_BIGENDIAN
Definition: tiff.h:51
#define HOST_BIGENDIAN
Definition: tiffconf.h:70
#define STRIPCHOP_DEFAULT
Definition: tiffconf.h:114
#define MDI_SUPPORT
Definition: tiffconf.h:129
TIFF_SSIZE_T tmsize_t
Definition: tiffio.h:67
#define TIFF_NON_EXISTENT_DIR_NUMBER
Definition: tiffiop.h:64
#define TIFF_LAZYSTRILELOAD
Definition: tiffiop.h:146
#define WriteOK(tif, buf, size)
Definition: tiffiop.h:301
#define ReadOK(tif, buf, size)
Definition: tiffiop.h:295
#define TIFF_HEADERONLY
Definition: tiffiop.h:133
#define TIFFMapFileContents(tif, paddr, psize)
Definition: tiffiop.h:286
#define TIFF_STRIPCHOP
Definition: tiffiop.h:132
#define TIFF_DEFERSTRILELOAD
Definition: tiffiop.h:144
#define TIFF_MAPPED
Definition: tiffiop.h:128
#define TIFF_BIGTIFF
Definition: tiffiop.h:138
#define TIFF_SWAB
Definition: tiffiop.h:124
TIFFHeaderCommon common
Definition: tiffiop.h:107
TIFFHeaderClassic classic
Definition: tiffiop.h:108
TIFFHeaderBig big
Definition: tiffiop.h:109

Referenced by TIFFClientOpen(), and TIFFFdOpenExt().

◆ TIFFClose()

void TIFFClose ( TIFF tif)

Close a previously opened TIFF file.

TIFFClose closes a file that was previously opened with TIFFOpen(). Any buffered data are flushed to the file, including the contents of the current directory (if modified); and all resources are reclaimed.

Parameters
tifA TIFF pointer.

Definition at line 155 of file tif_close.c.

156{
157 if (tif != NULL)
158 {
159 TIFFCloseProc closeproc = tif->tif_closeproc;
161
162 TIFFCleanup(tif);
163 (void)(*closeproc)(fd);
164 }
165}
static int fd
Definition: io.c:51
int(* TIFFCloseProc)(thandle_t)
Definition: tiffio.h:308

Referenced by tiff_decoder_destroy(), tiff_decoder_initialize(), tiff_encoder_commit_file(), and tiff_encoder_destroy().

◆ TIFFComputeStrip()

uint32_t TIFFComputeStrip ( TIFF tif,
uint32_t  row,
uint16_t  sample 
)

Definition at line 35 of file tif_strip.c.

36{
37 static const char module[] = "TIFFComputeStrip";
38 TIFFDirectory *td = &tif->tif_dir;
39 uint32_t strip;
40
41 if (td->td_rowsperstrip == 0)
42 {
44 "Cannot compute strip: RowsPerStrip is zero");
45 return 0;
46 }
47 strip = row / td->td_rowsperstrip;
49 {
50 if (sample >= td->td_samplesperpixel)
51 {
52 TIFFErrorExtR(tif, module, "%lu: Sample out of range, max %lu",
53 (unsigned long)sample,
54 (unsigned long)td->td_samplesperpixel);
55 return (0);
56 }
57 strip += (uint32_t)sample * td->td_stripsperimage;
58 }
59 return (strip);
60}
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:78
uint32_t td_rowsperstrip
Definition: tif_dir.h:94
uint32_t td_stripsperimage
Definition: tif_dir.h:110

Referenced by gtStripContig(), and gtStripSeparate().

◆ TIFFComputeTile()

uint32_t TIFFComputeTile ( TIFF tif,
uint32_t  x,
uint32_t  y,
uint32_t  z,
uint16_t  s 
)

Definition at line 35 of file tif_tile.c.

37{
38 TIFFDirectory *td = &tif->tif_dir;
41 uint32_t dz = td->td_tiledepth;
42 uint32_t tile = 1;
43
44 if (td->td_imagedepth == 1)
45 z = 0;
46 if (dx == (uint32_t)-1)
47 dx = td->td_imagewidth;
48 if (dy == (uint32_t)-1)
49 dy = td->td_imagelength;
50 if (dz == (uint32_t)-1)
51 dz = td->td_imagedepth;
52 if (dx != 0 && dy != 0 && dz != 0)
53 {
57
59 tile = (xpt * ypt * zpt) * s + (xpt * ypt) * (z / dz) +
60 xpt * (y / dy) + x / dx;
61 else
62 tile = (xpt * ypt) * (z / dz) + xpt * (y / dy) + x / dx;
63 }
64 return (tile);
65}
GLint dy
Definition: linetemp.h:97
GLint dx
Definition: linetemp.h:97
uint32_t td_tiledepth
Definition: tif_dir.h:84
uint32_t td_tilewidth
Definition: tif_dir.h:84
uint32_t td_tilelength
Definition: tif_dir.h:84
#define TIFFhowmany_32(x, y)
Definition: tiffiop.h:305

Referenced by _TIFFReadTileAndAllocBuffer(), TIFFReadTile(), and TIFFWriteTile().

◆ TIFFCreateCustomDirectory()

int TIFFCreateCustomDirectory ( TIFF tif,
const TIFFFieldArray infoarray 
)

Definition at line 1704 of file tif_dir.c.

1705{
1706 /* Free previously allocated memory and setup default values. */
1707 TIFFFreeDirectory(tif);
1709
1710 /*
1711 * Reset the field definitions to match the application provided list.
1712 * Hopefully TIFFDefaultDirectory() won't have done anything irreversible
1713 * based on it's assumption this is an image directory.
1714 */
1715 _TIFFSetupFields(tif, infoarray);
1716
1717 tif->tif_diroff = 0;
1718 tif->tif_nextdiroff = 0;
1719 tif->tif_curoff = 0;
1720 tif->tif_row = (uint32_t)-1;
1721 tif->tif_curstrip = (uint32_t)-1;
1722 /* invalidate directory index */
1724 /* invalidate IFD loop lists */
1726 /* To be able to return from SubIFD or custom-IFD to main-IFD */
1728
1729 return 0;
1730}
void _TIFFSetupFields(TIFF *tif, const TIFFFieldArray *fieldarray)
Definition: tif_dirinfo.c:513

Referenced by TIFFCreateEXIFDirectory(), and TIFFCreateGPSDirectory().

◆ TIFFCreateDirectory()

int TIFFCreateDirectory ( TIFF tif)

Definition at line 1689 of file tif_dir.c.

1690{
1691 /* Free previously allocated memory and setup default values. */
1692 TIFFFreeDirectory(tif);
1694 tif->tif_diroff = 0;
1695 tif->tif_nextdiroff = 0;
1696 tif->tif_curoff = 0;
1697 tif->tif_row = (uint32_t)-1;
1698 tif->tif_curstrip = (uint32_t)-1;
1700
1701 return 0;
1702}
unsigned char td_iswrittentofile
Definition: tif_dir.h:149

Referenced by TIFFWriteDirectorySec().

◆ TIFFCreateEXIFDirectory()

int TIFFCreateEXIFDirectory ( TIFF tif)

Definition at line 1732 of file tif_dir.c.

1733{
1737}
int TIFFCreateCustomDirectory(TIFF *tif, const TIFFFieldArray *infoarray)
Definition: tif_dir.c:1704
static const TIFFFieldArray exifFieldArray
Definition: tif_dirinfo.c:49
const TIFFFieldArray * _TIFFGetExifFields(void)
Definition: tif_dirinfo.c:509

◆ TIFFCreateGPSDirectory()

int TIFFCreateGPSDirectory ( TIFF tif)

Definition at line 1742 of file tif_dir.c.

1743{
1747}
static const TIFFFieldArray gpsFieldArray
Definition: tif_dirinfo.c:50
const TIFFFieldArray * _TIFFGetGpsFields(void)
Definition: tif_dirinfo.c:511

◆ TIFFCurrentDirectory()

tdir_t TIFFCurrentDirectory ( TIFF tif)

Definition at line 869 of file tif_open.c.

869{ return (tif->tif_curdir); }

◆ TIFFCurrentDirOffset()

uint64_t TIFFCurrentDirOffset ( TIFF tif)

Definition at line 2223 of file tif_dir.c.

2223{ return (tif->tif_diroff); }

Referenced by tiff_decoder_get_metadata_blocks().

◆ TIFFCurrentRow()

uint32_t TIFFCurrentRow ( TIFF tif)

Definition at line 864 of file tif_open.c.

864{ return (tif->tif_row); }

◆ TIFFCurrentStrip()

uint32_t TIFFCurrentStrip ( TIFF tif)

Definition at line 874 of file tif_open.c.

874{ return (tif->tif_curstrip); }

◆ TIFFCurrentTile()

uint32_t TIFFCurrentTile ( TIFF tif)

Definition at line 879 of file tif_open.c.

879{ return (tif->tif_curtile); }
uint32_t tif_curtile
Definition: tiffiop.h:194

◆ TIFFDataWidth()

int TIFFDataWidth ( TIFFDataType  type)

Definition at line 637 of file tif_dirinfo.c.

638{
639 switch (type)
640 {
641 case 0: /* nothing */
642 case TIFF_BYTE:
643 case TIFF_ASCII:
644 case TIFF_SBYTE:
645 case TIFF_UNDEFINED:
646 return 1;
647 case TIFF_SHORT:
648 case TIFF_SSHORT:
649 return 2;
650 case TIFF_LONG:
651 case TIFF_SLONG:
652 case TIFF_FLOAT:
653 case TIFF_IFD:
654 return 4;
655 case TIFF_RATIONAL:
656 case TIFF_SRATIONAL:
657 case TIFF_DOUBLE:
658 case TIFF_LONG8:
659 case TIFF_SLONG8:
660 case TIFF_IFD8:
661 return 8;
662 default:
663 return 0; /* will return 0 for unknown types */
664 }
665}
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
@ TIFF_SSHORT
Definition: tiff.h:155
@ TIFF_SLONG
Definition: tiff.h:156
@ TIFF_BYTE
Definition: tiff.h:148
@ TIFF_SBYTE
Definition: tiff.h:153
@ TIFF_IFD
Definition: tiff.h:160
@ TIFF_SHORT
Definition: tiff.h:150
@ TIFF_UNDEFINED
Definition: tiff.h:154
@ TIFF_LONG
Definition: tiff.h:151
@ TIFF_SLONG8
Definition: tiff.h:162
@ TIFF_LONG8
Definition: tiff.h:161
@ TIFF_ASCII
Definition: tiff.h:149
@ TIFF_FLOAT
Definition: tiff.h:158
@ TIFF_DOUBLE
Definition: tiff.h:159
@ TIFF_IFD8
Definition: tiff.h:163
@ TIFF_SRATIONAL
Definition: tiff.h:157
@ TIFF_RATIONAL
Definition: tiff.h:152

Referenced by _TIFFRewriteField(), EstimateStripByteCounts(), EvaluateIFDdatasizeReading(), and TIFFReadDirEntryArrayWithLimit().

◆ TIFFDefaultStripSize()

uint32_t TIFFDefaultStripSize ( TIFF tif,
uint32_t  request 
)

Definition at line 218 of file tif_strip.c.

219{
220 return (*tif->tif_defstripsize)(tif, request);
221}
Definition: tftpd.h:86
TIFFStripMethod tif_defstripsize
Definition: tiffiop.h:214

◆ TIFFDefaultTileSize()

void TIFFDefaultTileSize ( TIFF tif,
uint32_t tw,
uint32_t th 
)

Definition at line 267 of file tif_tile.c.

268{
269 (*tif->tif_deftilesize)(tif, tw, th);
270}
TIFFTileMethod tif_deftilesize
Definition: tiffiop.h:215

◆ TIFFDeferStrileArrayWriting()

int TIFFDeferStrileArrayWriting ( TIFF tif)

Definition at line 268 of file tif_dirwrite.c.

269{
270 static const char module[] = "TIFFDeferStrileArrayWriting";
271 if (tif->tif_mode == O_RDONLY)
272 {
273 TIFFErrorExtR(tif, tif->tif_name, "File opened in read-only mode");
274 return 0;
275 }
276 if (tif->tif_diroff != 0)
277 {
278 TIFFErrorExtR(tif, module, "Directory has already been written");
279 return 0;
280 }
281
283 return 1;
284}
unsigned char td_deferstrilearraywriting
Definition: tif_dir.h:146

◆ TIFFError()

void TIFFError ( const char ,
const char ,
  ... 
)

◆ TIFFErrorExt()

void void TIFFErrorExt ( thandle_t  ,
const char ,
const char ,
  ... 
)

◆ TIFFErrorExtR()

void void TIFFErrorExtR ( TIFF ,
const char ,
const char ,
  ... 
)

◆ TIFFFdOpen()

TIFF * TIFFFdOpen ( int  fd,
const char name,
const char mode 
)

Definition at line 209 of file tif_unix.c.

210{
211 return TIFFFdOpenExt(fd, name, mode, NULL);
212}
TIFF * TIFFFdOpenExt(int fd, const char *name, const char *mode, TIFFOpenOptions *opts)
Definition: tif_unix.c:214

◆ TIFFFdOpenExt()

TIFF * TIFFFdOpenExt ( int  fd,
const char name,
const char mode,
TIFFOpenOptions opts 
)

Definition at line 214 of file tif_unix.c.

216{
217 TIFF *tif;
218
220 fdh.fd = fd;
224 if (tif)
225 tif->tif_fd = fd;
226 return (tif);
227}
int tif_fd
Definition: tiffiop.h:115
static tmsize_t _tiffReadProc(thandle_t fd, void *buf, tmsize_t size)
Definition: tif_unix.c:68
static void _tiffUnmapProc(thandle_t fd, void *base, toff_t size)
Definition: tif_unix.c:198
static tmsize_t _tiffWriteProc(thandle_t fd, void *buf, tmsize_t size)
Definition: tif_unix.c:99
static uint64_t _tiffSeekProc(thandle_t fd, uint64_t off, int whence)
Definition: tif_unix.c:131
static int _tiffCloseProc(thandle_t fd)
Definition: tif_unix.c:144
static uint64_t _tiffSizeProc(thandle_t fd)
Definition: tif_unix.c:151
static int _tiffMapProc(thandle_t fd, void **pbase, toff_t *psize)
Definition: tif_unix.c:190
thandle_t h
Definition: tif_unix.c:65

Referenced by TIFFFdOpen(), TIFFOpenExt(), and TIFFOpenWExt().

◆ TIFFFieldDataType()

TIFFDataType TIFFFieldDataType ( const TIFFField fip)

Definition at line 871 of file tif_dirinfo.c.

871{ return fip->field_type; }
TIFFDataType field_type
Definition: tif_dir.h:335

◆ TIFFFieldIsAnonymous()

int TIFFFieldIsAnonymous ( const TIFFField fip)

Definition at line 879 of file tif_dirinfo.c.

879{ return fip->field_anonymous; }
uint32_t field_anonymous
Definition: tif_dir.h:336

Referenced by _TIFFPrettyPrintField(), _TIFFPrintField(), _TIFFSetupFields(), TIFFCleanup(), and TIFFReadCustomDirectory().

◆ TIFFFieldName()

const char * TIFFFieldName ( const TIFFField fip)

Definition at line 869 of file tif_dirinfo.c.

869{ return fip->field_name; }

◆ TIFFFieldPassCount()

int TIFFFieldPassCount ( const TIFFField fip)

Definition at line 873 of file tif_dirinfo.c.

873{ return fip->field_passcount; }
unsigned char field_passcount
Definition: tif_dir.h:342

◆ TIFFFieldReadCount()

int TIFFFieldReadCount ( const TIFFField fip)

Definition at line 875 of file tif_dirinfo.c.

875{ return fip->field_readcount; }
short field_readcount
Definition: tif_dir.h:333

◆ TIFFFieldSetGetCountSize()

int TIFFFieldSetGetCountSize ( const TIFFField fip)

Definition at line 757 of file tif_dirinfo.c.

758{
759 if (fip == NULL)
760 return 0;
761
762 switch (fip->set_get_field_type)
763 {
776 return 2;
789 return 4;
790 default:
791 return 0;
792 }
793} /*-- TIFFFieldSetGetCountSize() --- */
TIFFSetGetFieldType set_get_field_type
Definition: tif_dir.h:338
@ TIFF_SETGET_C16_UINT8
Definition: tif_dir.h:273
@ TIFF_SETGET_C32_SINT32
Definition: tif_dir.h:290
@ TIFF_SETGET_C16_FLOAT
Definition: tif_dir.h:281
@ TIFF_SETGET_C32_ASCII
Definition: tif_dir.h:284
@ TIFF_SETGET_C32_UINT8
Definition: tif_dir.h:285
@ TIFF_SETGET_C32_UINT16
Definition: tif_dir.h:287
@ TIFF_SETGET_C16_DOUBLE
Definition: tif_dir.h:282
@ TIFF_SETGET_C16_UINT32
Definition: tif_dir.h:277
@ TIFF_SETGET_C32_SINT16
Definition: tif_dir.h:288
@ TIFF_SETGET_C16_UINT16
Definition: tif_dir.h:275
@ TIFF_SETGET_C16_SINT64
Definition: tif_dir.h:280
@ TIFF_SETGET_C16_UINT64
Definition: tif_dir.h:279
@ TIFF_SETGET_C32_UINT32
Definition: tif_dir.h:289
@ TIFF_SETGET_C32_SINT8
Definition: tif_dir.h:286
@ TIFF_SETGET_C16_SINT16
Definition: tif_dir.h:276
@ TIFF_SETGET_C16_SINT8
Definition: tif_dir.h:274
@ TIFF_SETGET_C16_SINT32
Definition: tif_dir.h:278
@ TIFF_SETGET_C32_IFD8
Definition: tif_dir.h:295
@ TIFF_SETGET_C32_SINT64
Definition: tif_dir.h:292
@ TIFF_SETGET_C16_ASCII
Definition: tif_dir.h:272
@ TIFF_SETGET_C32_DOUBLE
Definition: tif_dir.h:294
@ TIFF_SETGET_C32_UINT64
Definition: tif_dir.h:291
@ TIFF_SETGET_C16_IFD8
Definition: tif_dir.h:283
@ TIFF_SETGET_C32_FLOAT
Definition: tif_dir.h:293

◆ TIFFFieldSetGetSize()

int TIFFFieldSetGetSize ( const TIFFField fip)

Definition at line 673 of file tif_dirinfo.c.

674{
675 /*
676 * TIFFSetField() and TIFFGetField() must provide the parameter accordingly
677 * to the definition of "set_get_field_type" of the tag definition in
678 * dir_info.c. This function returns the data size for that purpose.
679 *
680 * Furthermore, this data size is also used for the internal storage,
681 * even for TIFF_RATIONAL values for FIELD_CUSTOM, which are stored
682 * internally as 4-byte float, but some of them should be stored internally
683 * as 8-byte double, depending on the "set_get_field_type" _FLOAT_ or
684 * _DOUBLE_.
685 */
686 if (fip == NULL)
687 return 0;
688
689 switch (fip->set_get_field_type)
690 {
697 return 1;
706 return 1;
715 return 2;
716 case TIFF_SETGET_INT:
730 return 4;
734 case TIFF_SETGET_IFD8:
747 return 8;
748 default:
749 return 0;
750 }
751} /*-- TIFFFieldSetGetSize() --- */
@ TIFF_SETGET_C0_SINT64
Definition: tif_dir.h:268
@ TIFF_SETGET_DOUBLE
Definition: tif_dir.h:256
@ TIFF_SETGET_SINT64
Definition: tif_dir.h:254
@ TIFF_SETGET_UNDEFINED
Definition: tif_dir.h:245
@ TIFF_SETGET_SINT8
Definition: tif_dir.h:248
@ TIFF_SETGET_INT
Definition: tif_dir.h:258
@ TIFF_SETGET_IFD8
Definition: tif_dir.h:257
@ TIFF_SETGET_UINT64
Definition: tif_dir.h:253
@ TIFF_SETGET_C0_UINT32
Definition: tif_dir.h:265
@ TIFF_SETGET_UINT16_PAIR
Definition: tif_dir.h:259
@ TIFF_SETGET_C0_FLOAT
Definition: tif_dir.h:269
@ TIFF_SETGET_C0_SINT32
Definition: tif_dir.h:266
@ TIFF_SETGET_C0_ASCII
Definition: tif_dir.h:260
@ TIFF_SETGET_UINT16
Definition: tif_dir.h:249
@ TIFF_SETGET_C0_UINT8
Definition: tif_dir.h:261
@ TIFF_SETGET_ASCII
Definition: tif_dir.h:246
@ TIFF_SETGET_C0_SINT8
Definition: tif_dir.h:262
@ TIFF_SETGET_OTHER
Definition: tif_dir.h:296
@ TIFF_SETGET_C0_UINT64
Definition: tif_dir.h:267
@ TIFF_SETGET_FLOAT
Definition: tif_dir.h:255
@ TIFF_SETGET_SINT16
Definition: tif_dir.h:250
@ TIFF_SETGET_C0_SINT16
Definition: tif_dir.h:264
@ TIFF_SETGET_UINT32
Definition: tif_dir.h:251
@ TIFF_SETGET_UINT8
Definition: tif_dir.h:247
@ TIFF_SETGET_C0_UINT16
Definition: tif_dir.h:263
@ TIFF_SETGET_C0_IFD8
Definition: tif_dir.h:271
@ TIFF_SETGET_SINT32
Definition: tif_dir.h:252
@ TIFF_SETGET_C0_DOUBLE
Definition: tif_dir.h:270

Referenced by _TIFFPrintField(), _TIFFVGetField(), _TIFFVSetField(), TIFFPrintDirectory(), and TIFFWriteDirectorySec().

◆ TIFFFieldTag()

uint32_t TIFFFieldTag ( const TIFFField fip)

Definition at line 867 of file tif_dirinfo.c.

867{ return fip->field_tag; }
uint32_t field_tag
Definition: tif_dir.h:332

Referenced by TIFFWriteDirectorySec().

◆ TIFFFieldWithName()

const TIFFField * TIFFFieldWithName ( TIFF tif,
const char field_name 
)

Definition at line 856 of file tif_dirinfo.c.

857{
858 const TIFFField *fip = _TIFFFindFieldByName(tif, field_name, TIFF_ANY);
859 if (!fip)
860 {
861 TIFFWarningExtR(tif, "TIFFFieldWithName", "Warning, unknown tag %s",
862 field_name);
863 }
864 return (fip);
865}
static const TIFFField * _TIFFFindFieldByName(TIFF *tif, const char *field_name, TIFFDataType dt)
Definition: tif_dirinfo.c:818
#define TIFF_ANY
Definition: tiffio.h:341

◆ TIFFFieldWithTag()

const TIFFField * TIFFFieldWithTag ( TIFF tif,
uint32_t  tag 
)

Definition at line 845 of file tif_dirinfo.c.

846{
847 const TIFFField *fip = TIFFFindField(tif, tag, TIFF_ANY);
848 if (!fip)
849 {
850 TIFFWarningExtR(tif, "TIFFFieldWithTag", "Warning, unknown tag 0x%x",
851 (unsigned int)tag);
852 }
853 return (fip);
854}
Definition: ecma_167.h:138
const TIFFField * TIFFFindField(TIFF *tif, uint32_t tag, TIFFDataType dt)
Definition: tif_dirinfo.c:795

Referenced by _TIFFVSetField(), CheckDirCount(), TIFFFetchStripThing(), TIFFPrintDirectory(), TIFFReadDirectory(), and TIFFUnsetField().

◆ TIFFFieldWriteCount()

int TIFFFieldWriteCount ( const TIFFField fip)

Definition at line 877 of file tif_dirinfo.c.

877{ return fip->field_writecount; }
short field_writecount
Definition: tif_dir.h:334

◆ TIFFFileName()

◆ TIFFFileno()

int TIFFFileno ( TIFF tif)

Definition at line 813 of file tif_open.c.

813{ return (tif->tif_fd); }

◆ TIFFFindCODEC()

const TIFFCodec * TIFFFindCODEC ( uint16_t  scheme)

Definition at line 192 of file tif_compress.c.

193{
194 const TIFFCodec *c;
195 codec_t *cd;
196
197 for (cd = registeredCODECS; cd; cd = cd->next)
198 if (cd->info->scheme == scheme)
199 return ((const TIFFCodec *)cd->info);
200 for (c = _TIFFBuiltinCODECS; c->name; c++)
201 if (c->scheme == scheme)
202 return (c);
203 return ((const TIFFCodec *)0);
204}
InitDirComponents & cd
#define c
Definition: ke_i.h:80
DWORD scheme
char * name
Definition: tiffio.h:272
const TIFFCodec _TIFFBuiltinCODECS[]
Definition: tif_codec.c:86
static codec_t * registeredCODECS
Definition: tif_compress.c:190

Referenced by _notConfigured(), TIFFIsCODECConfigured(), TIFFNoDecode(), TIFFNoEncode(), TIFFPrintDirectory(), and TIFFSetCompressionScheme().

◆ TIFFFindField()

const TIFFField * TIFFFindField ( TIFF tif,
uint32_t  tag,
TIFFDataType  dt 
)

Definition at line 795 of file tif_dirinfo.c.

796{
797 TIFFField key = {0, 0, 0, TIFF_NOTYPE, 0, 0, 0, 0, 0, NULL, NULL};
798 TIFFField *pkey = &key;
799 const TIFFField **ret;
800 if (tif->tif_foundfield && tif->tif_foundfield->field_tag == tag &&
801 (dt == TIFF_ANY || dt == tif->tif_foundfield->field_type))
802 return tif->tif_foundfield;
803
804 /* If we are invoked with no field information, then just return. */
805 if (!tif->tif_fields)
806 return NULL;
807
808 /* NB: use sorted search (e.g. binary search) */
809
810 key.field_tag = tag;
811 key.field_type = dt;
812
813 ret = (const TIFFField **)bsearch(&pkey, tif->tif_fields, tif->tif_nfields,
814 sizeof(TIFFField *), tagCompare);
815 return tif->tif_foundfield = (ret ? *ret : NULL);
816}
return ret
Definition: mutex.c:146
Definition: copy.c:22
const TIFFField * tif_foundfield
Definition: tiffiop.h:243
#define bsearch
static int tagCompare(const void *a, const void *b)
Definition: tif_dirinfo.c:546
@ TIFF_NOTYPE
Definition: tiff.h:147

Referenced by _TIFFFindOrRegisterField(), _TIFFMergeFields(), _TIFFRewriteField(), _TIFFVGetField(), _TIFFVSetField(), OkToChangeTag(), TIFFFieldWithTag(), and TIFFVGetField().

◆ TIFFFlush()

int TIFFFlush ( TIFF tif)

Definition at line 30 of file tif_flush.c.

31{
32 if (tif->tif_mode == O_RDONLY)
33 return 1;
34
35 if (!TIFFFlushData(tif))
36 return (0);
37
38 /* In update (r+) mode we try to detect the case where
39 only the strip/tile map has been altered, and we try to
40 rewrite only that portion of the directory without
41 making any other changes */
42
43 if ((tif->tif_flags & TIFF_DIRTYSTRIP) &&
44 !(tif->tif_flags & TIFF_DIRTYDIRECT) && tif->tif_mode == O_RDWR)
45 {
47 return 1;
48 }
49
52 return (0);
53
54 return (1);
55}
int TIFFRewriteDirectory(TIFF *tif)
Definition: tif_dirwrite.c:483
int TIFFForceStrileArrayWriting(TIFF *tif)
Definition: tif_flush.c:76
int TIFFFlushData(TIFF *tif)
Definition: tif_flush.c:146
#define TIFF_DIRTYSTRIP
Definition: tiffiop.h:140
#define TIFF_DIRTYDIRECT
Definition: tiffiop.h:120

Referenced by TIFFCleanup().

◆ TIFFFlushData()

int TIFFFlushData ( TIFF tif)

Definition at line 146 of file tif_flush.c.

147{
148 if ((tif->tif_flags & TIFF_BEENWRITING) == 0)
149 return (1);
150 if (tif->tif_flags & TIFF_POSTENCODE)
151 {
152 tif->tif_flags &= ~TIFF_POSTENCODE;
153 if (!(*tif->tif_postencode)(tif))
154 return (0);
155 }
156 return (TIFFFlushData1(tif));
157}
TIFFBoolMethod tif_postencode
Definition: tiffiop.h:204
int TIFFFlushData1(TIFF *tif)
Definition: tif_write.c:931
#define TIFF_POSTENCODE
Definition: tiffiop.h:129
#define TIFF_BEENWRITING
Definition: tiffiop.h:123

Referenced by TIFFFlush(), and TIFFWriteScanline().

◆ TIFFForceStrileArrayWriting()

int TIFFForceStrileArrayWriting ( TIFF tif)

Definition at line 76 of file tif_flush.c.

77{
78 static const char module[] = "TIFFForceStrileArrayWriting";
79 const int isTiled = TIFFIsTiled(tif);
80
81 if (tif->tif_mode == O_RDONLY)
82 {
83 TIFFErrorExtR(tif, tif->tif_name, "File opened in read-only mode");
84 return 0;
85 }
86 if (tif->tif_diroff == 0)
87 {
88 TIFFErrorExtR(tif, module, "Directory has not yet been written");
89 return 0;
90 }
91 if ((tif->tif_flags & TIFF_DIRTYDIRECT) != 0)
92 {
94 "Directory has changes other than the strile arrays. "
95 "TIFFRewriteDirectory() should be called instead");
96 return 0;
97 }
98
99 if (!(tif->tif_flags & TIFF_DIRTYSTRIP))
100 {
101 if (!(tif->tif_dir.td_stripoffset_entry.tdir_tag != 0 &&
109 {
111 "Function not called together with "
112 "TIFFDeferStrileArrayWriting()");
113 return 0;
114 }
115
116 if (tif->tif_dir.td_stripoffset_p == NULL && !TIFFSetupStrips(tif))
117 return 0;
118 }
119
120 if (_TIFFRewriteField(tif,
128 {
129 tif->tif_flags &= ~TIFF_DIRTYSTRIP;
130 tif->tif_flags &= ~TIFF_BEENWRITING;
131 return 1;
132 }
133
134 return 0;
135}
uint64_t tdir_count
Definition: tif_dir.h:57
uint16_t tdir_type
Definition: tif_dir.h:56
union TIFFDirEntry::@3701 tdir_offset
uint64_t toff_long8
Definition: tif_dir.h:62
uint16_t tdir_tag
Definition: tif_dir.h:55
TIFFDirEntry td_stripoffset_entry
Definition: tif_dir.h:127
uint64_t * td_stripbytecount_p
Definition: tif_dir.h:114
uint32_t td_nstrips
Definition: tif_dir.h:111
TIFFDirEntry td_stripbytecount_entry
Definition: tif_dir.h:128
int _TIFFRewriteField(TIFF *tif, uint16_t tag, TIFFDataType in_datatype, tmsize_t count, void *data)
int TIFFIsTiled(TIFF *tif)
Definition: tif_open.c:859
#define TIFFTAG_TILEBYTECOUNTS
Definition: tiff.h:314
#define TIFFTAG_STRIPBYTECOUNTS
Definition: tiff.h:259
#define TIFFTAG_TILEOFFSETS
Definition: tiff.h:313
#define TIFFTAG_STRIPOFFSETS
Definition: tiff.h:247
#define isTiled(tif)
Definition: tiffiop.h:274

Referenced by TIFFFlush(), and TIFFWriteCheck().

◆ TIFFFreeDirectory()

void TIFFFreeDirectory ( TIFF tif)

Definition at line 1619 of file tif_dir.c.

1620{
1621 TIFFDirectory *td = &tif->tif_dir;
1622 int i;
1623
1624 (*tif->tif_cleanup)(tif);
1625 _TIFFmemset(td->td_fieldsset, 0, sizeof(td->td_fieldsset));
1626 CleanupField(td_sminsamplevalue);
1627 CleanupField(td_smaxsamplevalue);
1628 CleanupField(td_colormap[0]);
1629 CleanupField(td_colormap[1]);
1630 CleanupField(td_colormap[2]);
1631 CleanupField(td_sampleinfo);
1632 CleanupField(td_subifd);
1633 CleanupField(td_inknames);
1634 CleanupField(td_refblackwhite);
1635 CleanupField(td_transferfunction[0]);
1636 CleanupField(td_transferfunction[1]);
1637 CleanupField(td_transferfunction[2]);
1638 CleanupField(td_stripoffset_p);
1639 CleanupField(td_stripbytecount_p);
1643
1644 /* Cleanup custom tag values */
1645 for (i = 0; i < td->td_customValueCount; i++)
1646 {
1647 if (td->td_customValues[i].value)
1649 }
1650
1651 td->td_customValueCount = 0;
1652 CleanupField(td_customValues);
1653
1654 _TIFFmemset(&(td->td_stripoffset_entry), 0, sizeof(TIFFDirEntry));
1656
1657 /* Reset some internal parameters for IFD data size checking. */
1661 {
1665 }
1667}
int td_customValueCount
Definition: tif_dir.h:142
uint32_t td_dirdatasize_Noffsets
Definition: tif_dir.h:159
uint64_t td_dirdatasize_read
Definition: tif_dir.h:157
uint32_t td_fieldsset[FIELDSET_ITEMS]
Definition: tif_dir.h:81
TIFFTagValue * td_customValues
Definition: tif_dir.h:143
uint64_t td_dirdatasize_write
Definition: tif_dir.h:155
uint32_t td_stripoffsetbyteallocsize
Definition: tif_dir.h:117
TIFFEntryOffsetAndLength * td_dirdatasize_offsets
Definition: tif_dir.h:162
void * value
Definition: tif_dir.h:39
TIFFVoidMethod tif_cleanup
Definition: tiffiop.h:213
#define CleanupField(member)
Definition: tif_dir.c:1607
#define FIELD_YCBCRSUBSAMPLING
Definition: tif_dir.h:211
#define FIELD_YCBCRPOSITIONING
Definition: tif_dir.h:212
#define TIFFClrFieldBit(tif, field)
Definition: tif_dir.h:238

Referenced by TIFFCleanup(), TIFFCreateCustomDirectory(), TIFFCreateDirectory(), TIFFReadCustomDirectory(), TIFFReadDirectory(), TIFFUnlinkDirectory(), and TIFFWriteDirectorySec().

◆ TIFFGetBitRevTable()

const unsigned char * TIFFGetBitRevTable ( int  reversed)

Definition at line 305 of file tif_swab.c.

306{
307 return (reversed ? TIFFBitRevTable : TIFFNoBitRevTable);
308}
static const unsigned char TIFFBitRevTable[256]
Definition: tif_swab.c:257
static const unsigned char TIFFNoBitRevTable[256]
Definition: tif_swab.c:280

◆ TIFFGetClientInfo()

void * TIFFGetClientInfo ( TIFF tif,
const char name 
)

Definition at line 64 of file tif_extension.c.

66{
68
69 while (psLink != NULL && strcmp(psLink->name, name) != 0)
70 psLink = psLink->next;
71
72 if (psLink != NULL)
73 return psLink->data;
74 else
75 return NULL;
76}
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3319
void * data
Definition: tiffiop.h:77

◆ TIFFGetCloseProc()

TIFFCloseProc TIFFGetCloseProc ( TIFF tif)

Definition at line 927 of file tif_open.c.

927{ return (tif->tif_closeproc); }

◆ TIFFGetConfiguredCODECs()

TIFFCodec * TIFFGetConfiguredCODECs ( void  )

Get list of configured codecs, both built-in and registered by user. Caller is responsible to free this structure.

Returns
returns array of TIFFCodec records (the last record should be NULL) or NULL if function failed.

Definition at line 261 of file tif_compress.c.

262{
263 int i = 1;
264 codec_t *cd;
265 const TIFFCodec *c;
267 TIFFCodec *new_codecs;
268
269 for (cd = registeredCODECS; cd; cd = cd->next)
270 {
271 new_codecs =
273 if (!new_codecs)
274 {
276 return NULL;
277 }
278 codecs = new_codecs;
279 _TIFFmemcpy(codecs + i - 1, cd->info, sizeof(TIFFCodec));
280 i++;
281 }
282 for (c = _TIFFBuiltinCODECS; c->name; c++)
283 {
284 if (TIFFIsCODECConfigured(c->scheme))
285 {
286 new_codecs = (TIFFCodec *)_TIFFreallocExt(NULL, codecs,
287 i * sizeof(TIFFCodec));
288 if (!new_codecs)
289 {
291 return NULL;
292 }
293 codecs = new_codecs;
294 _TIFFmemcpy(codecs + i - 1, (const void *)c, sizeof(TIFFCodec));
295 i++;
296 }
297 }
298
299 new_codecs =
301 if (!new_codecs)
302 {
304 return NULL;
305 }
306 codecs = new_codecs;
307 _TIFFmemset(codecs + i - 1, 0, sizeof(TIFFCodec));
308
309 return codecs;
310}
static const struct image_codec codecs[NUM_CODECS]
Definition: image.c:4283
int TIFFIsCODECConfigured(uint16_t scheme)
Definition: tif_codec.c:146
void * _TIFFreallocExt(TIFF *tif, void *p, tmsize_t s)
Definition: tif_open.c:235

◆ TIFFGetField()

int TIFFGetField ( TIFF tif,
uint32_t  tag,
  ... 
)

Definition at line 1582 of file tif_dir.c.

1583{
1584 int status;
1585 va_list ap;
1586
1587 va_start(ap, tag);
1588 status = TIFFVGetField(tif, tag, ap);
1589 va_end(ap);
1590 return (status);
1591}
#define va_end(v)
Definition: stdarg.h:28
#define va_start(v, l)
Definition: stdarg.h:26
char * va_list
Definition: vadefs.h:50
Definition: ps.c:97
int TIFFVGetField(TIFF *tif, uint32_t tag, va_list ap)
Definition: tif_dir.c:1599
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36

Referenced by gtTileContig(), gtTileSeparate(), isCCITTCompression(), tiff_decoder_get_color_context(), tiff_get_decode_info(), TIFFPrintDirectory(), TIFFRGBAImageBegin(), TIFFRGBAImageOK(), and TIFFWriteDirectorySec().

◆ TIFFGetFieldDefaulted()

int TIFFGetFieldDefaulted ( TIFF tif,
uint32_t  tag,
  ... 
)

Definition at line 380 of file tif_aux.c.

381{
382 int ok;
383 va_list ap;
384
385 va_start(ap, tag);
387 va_end(ap);
388 return (ok);
389}
#define ok(value,...)
Definition: atltest.h:57
int TIFFVGetFieldDefaulted(TIFF *tif, uint32_t tag, va_list ap)
Definition: tif_aux.c:217

Referenced by gtStripContig(), gtStripSeparate(), initCIELabConversion(), initYCbCrConversion(), PickContigCase(), PickSeparateCase(), TIFFReadRGBAStripExt(), TIFFReadRGBATileExt(), TIFFRGBAImageBegin(), TIFFRGBAImageOK(), TIFFScanlineSize64(), TIFFVStripSize64(), TIFFVTileSize64(), and TIFFWriteDirectorySec().

◆ TIFFGetMapFileProc()

TIFFMapFileProc TIFFGetMapFileProc ( TIFF tif)

Definition at line 937 of file tif_open.c.

937{ return (tif->tif_mapproc); }

◆ TIFFGetMode()

int TIFFGetMode ( TIFF tif)

Definition at line 843 of file tif_open.c.

843{ return (tif->tif_mode); }

◆ TIFFGetReadProc()

TIFFReadWriteProc TIFFGetReadProc ( TIFF tif)

Definition at line 912 of file tif_open.c.

912{ return (tif->tif_readproc); }

◆ TIFFGetSeekProc()

TIFFSeekProc TIFFGetSeekProc ( TIFF tif)

Definition at line 922 of file tif_open.c.

922{ return (tif->tif_seekproc); }

◆ TIFFGetSizeProc()

TIFFSizeProc TIFFGetSizeProc ( TIFF tif)

Definition at line 932 of file tif_open.c.

932{ return (tif->tif_sizeproc); }

◆ TIFFGetStrileByteCount()

◆ TIFFGetStrileByteCountWithErr()

uint64_t TIFFGetStrileByteCountWithErr ( TIFF tif,
uint32_t  strile,
int pbErr 
)

Definition at line 8373 of file tif_dirread.c.

8374{
8375 TIFFDirectory *td = &tif->tif_dir;
8377 tif, strile, &(td->td_stripbytecount_entry), &(td->td_stripbytecount_p),
8378 pbErr);
8379}
static uint64_t _TIFFGetStrileOffsetOrByteCountValue(TIFF *tif, uint32_t strile, TIFFDirEntry *dirent, uint64_t **parray, int *pbErr)
Definition: tif_dirread.c:8303

Referenced by TIFFGetStrileByteCount().

◆ TIFFGetStrileOffset()

uint64_t TIFFGetStrileOffset ( TIFF tif,
uint32_t  strile 
)

◆ TIFFGetStrileOffsetWithErr()

uint64_t TIFFGetStrileOffsetWithErr ( TIFF tif,
uint32_t  strile,
int pbErr 
)

Definition at line 8356 of file tif_dirread.c.

8357{
8358 TIFFDirectory *td = &tif->tif_dir;
8359 return _TIFFGetStrileOffsetOrByteCountValue(tif, strile,
8360 &(td->td_stripoffset_entry),
8361 &(td->td_stripoffset_p), pbErr);
8362}

Referenced by TIFFGetStrileOffset().

◆ TIFFGetTagListCount()

int TIFFGetTagListCount ( TIFF tif)

Definition at line 34 of file tif_extension.c.

36{
37 TIFFDirectory *td = &tif->tif_dir;
38
39 return td->td_customValueCount;
40}

Referenced by TIFFPrintDirectory().

◆ TIFFGetTagListEntry()

uint32_t TIFFGetTagListEntry ( TIFF tif,
int  tag_index 
)

Definition at line 42 of file tif_extension.c.

44{
45 TIFFDirectory *td = &tif->tif_dir;
46
47 if (tag_index < 0 || tag_index >= td->td_customValueCount)
48 return (uint32_t)(-1);
49 else
50 return td->td_customValues[tag_index].info->field_tag;
51}
const TIFFField * info
Definition: tif_dir.h:37

Referenced by TIFFPrintDirectory().

◆ TIFFGetUnmapFileProc()

TIFFUnmapFileProc TIFFGetUnmapFileProc ( TIFF tif)

Definition at line 942 of file tif_open.c.

943{
944 return (tif->tif_unmapproc);
945}

◆ TIFFGetVersion()

const char * TIFFGetVersion ( void  )

Definition at line 28 of file tif_version.c.

28{ return (TIFFVersion); }
static const char TIFFVersion[]
Definition: tif_version.c:26

◆ TIFFGetWriteProc()

TIFFReadWriteProc TIFFGetWriteProc ( TIFF tif)

Definition at line 917 of file tif_open.c.

917{ return (tif->tif_writeproc); }

◆ TIFFIsBigEndian()

int TIFFIsBigEndian ( TIFF tif)

Definition at line 899 of file tif_open.c.

900{
902}

◆ TIFFIsBigTIFF()

int TIFFIsBigTIFF ( TIFF tif)

Definition at line 907 of file tif_open.c.

907{ return ((tif->tif_flags & TIFF_BIGTIFF) != 0); }

◆ TIFFIsByteSwapped()

int TIFFIsByteSwapped ( TIFF tif)

Definition at line 884 of file tif_open.c.

884{ return ((tif->tif_flags & TIFF_SWAB) != 0); }

Referenced by tiff_decoder_get_metadata_blocks(), and tiff_decoder_read_tile().

◆ TIFFIsCODECConfigured()

int TIFFIsCODECConfigured ( uint16_t  scheme)

Check whether we have working codec for the specific coding scheme.

Returns
returns 1 if the codec is configured and working. Otherwise 0 will be returned.

Definition at line 146 of file tif_codec.c.

147{
148 const TIFFCodec *codec = TIFFFindCODEC(scheme);
149
150 if (codec == NULL)
151 {
152 return 0;
153 }
154 if (codec->init == NULL)
155 {
156 return 0;
157 }
158 if (codec->init != NotConfigured)
159 {
160 return 1;
161 }
162 return 0;
163}
TIFFInitMethod init
Definition: tiffio.h:274
static int NotConfigured(TIFF *, int)
Definition: tif_codec.c:123
const TIFFCodec * TIFFFindCODEC(uint16_t scheme)
Definition: tif_compress.c:192

Referenced by _TIFFCheckFieldIsValidForCodec(), and TIFFGetConfiguredCODECs().

◆ TIFFIsMSB2LSB()

int TIFFIsMSB2LSB ( TIFF tif)

Definition at line 894 of file tif_open.c.

894{ return (isFillOrder(tif, FILLORDER_MSB2LSB)); }
#define isFillOrder(tif, o)
Definition: tiffiop.h:276

◆ TIFFIsTiled()

int TIFFIsTiled ( TIFF tif)

◆ TIFFIsUpSampled()

int TIFFIsUpSampled ( TIFF tif)

Definition at line 889 of file tif_open.c.

889{ return (isUpSampled(tif)); }
#define isUpSampled(tif)
Definition: tiffiop.h:277

◆ TIFFLastDirectory()

int TIFFLastDirectory ( TIFF tif)

Definition at line 2229 of file tif_dir.c.

2229{ return (tif->tif_nextdiroff == 0); }

◆ TIFFMergeFieldInfo()

int TIFFMergeFieldInfo ( TIFF tif,
const  TIFFFieldInfo[],
uint32_t  n 
)

Definition at line 1147 of file tif_dirinfo.c.

1148{
1149 static const char module[] = "TIFFMergeFieldInfo";
1150 static const char reason[] = "for fields array";
1151 TIFFField *tp;
1152 size_t nfields;
1153 uint32_t i;
1154
1155 if (tif->tif_nfieldscompat > 0)
1156 {
1158 tif, tif->tif_fieldscompat, tif->tif_nfieldscompat + 1,
1159 sizeof(TIFFFieldArray), reason);
1160 }
1161 else
1162 {
1164 tif, 1, sizeof(TIFFFieldArray), reason);
1165 }
1166 if (!tif->tif_fieldscompat)
1167 {
1168 TIFFErrorExtR(tif, module, "Failed to allocate fields array");
1169 return -1;
1170 }
1171 nfields = tif->tif_nfieldscompat++;
1172
1173 tif->tif_fieldscompat[nfields].type = tfiatOther;
1174 tif->tif_fieldscompat[nfields].allocated_size = n;
1175 tif->tif_fieldscompat[nfields].count = n;
1176 tif->tif_fieldscompat[nfields].fields =
1177 (TIFFField *)_TIFFCheckMalloc(tif, n, sizeof(TIFFField), reason);
1178 if (!tif->tif_fieldscompat[nfields].fields)
1179 {
1180 TIFFErrorExtR(tif, module, "Failed to allocate fields array");
1181 return -1;
1182 }
1183
1184 tp = tif->tif_fieldscompat[nfields].fields;
1185 for (i = 0; i < n; i++)
1186 {
1187 tp->field_tag = info[i].field_tag;
1188 if (info[i].field_readcount < TIFF_VARIABLE2 ||
1189 info[i].field_writecount < TIFF_VARIABLE2)
1190 {
1191 /* The fields (field_readcount) and (field_writecount) may use the
1192 * values TIFF_VARIABLE (-1), TIFF_SPP (-2), TIFF_VARIABLE2 (-3). */
1194 tif, module,
1195 "The value of field_readcount %d and field_writecount %d "
1196 "must be greater than or equal to -3.",
1197 info[i].field_readcount, info[i].field_writecount);
1198 return -1;
1199 }
1200 if ((info[i].field_readcount == 0 || info[i].field_writecount == 0) &&
1201 info[i].field_bit != FIELD_IGNORE)
1202 {
1203 /* The fields (field_readcount) and (field_writecount) may only
1204 be zero for pseudo_tags or ignored tags. */
1206 tif, module,
1207 "The value of field_readcount %d and field_writecount %d "
1208 "may only be zero for field_bit = 0 (i.e. ignored tags).",
1209 info[i].field_readcount, info[i].field_writecount);
1210 return -1;
1211 }
1212 tp->field_readcount = info[i].field_readcount;
1213 tp->field_writecount = info[i].field_writecount;
1214 tp->field_type = info[i].field_type;
1215 tp->field_anonymous = 0;
1216 tp->set_get_field_type =
1217 _TIFFSetGetType(info[i].field_type, info[i].field_writecount,
1218 info[i].field_passcount);
1219 tp->field_bit = info[i].field_bit;
1220 tp->field_oktochange = info[i].field_oktochange;
1221 tp->field_passcount = info[i].field_passcount;
1222 /* Define an empty static string to be passed as field_name where a NULL
1223 * pointer is passed in. Otherwise, this will lead to buffer overflow
1224 * furtheron. */
1225 if (info[i].field_name == NULL)
1226 {
1227 static const char *string_static_empty = "";
1228 tp->field_name = (char *)string_static_empty;
1229 }
1230 else
1231 {
1232 tp->field_name = info[i].field_name;
1233 }
1234 tp->field_subfields = NULL;
1235 tp++;
1236 }
1237
1238 if (!_TIFFMergeFields(tif, tif->tif_fieldscompat[nfields].fields, n))
1239 {
1240 TIFFErrorExtR(tif, module, "Setting up field info failed");
1241 return -1;
1242 }
1243
1244 return 0;
1245}
static WCHAR reason[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1904
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2996
TIFFFieldArrayType type
Definition: tif_dir.h:322
uint32_t count
Definition: tif_dir.h:326
void * _TIFFCheckRealloc(TIFF *tif, void *buffer, tmsize_t nmemb, tmsize_t elem_size, const char *what)
Definition: tif_aux.c:97
void * _TIFFCheckMalloc(TIFF *tif, tmsize_t nmemb, tmsize_t elem_size, const char *what)
Definition: tif_aux.c:122
#define FIELD_IGNORE
Definition: tif_dir.h:178
@ tfiatOther
Definition: tif_dir.h:317
int _TIFFMergeFields(TIFF *tif, const TIFFField info[], uint32_t n)
Definition: tif_dirinfo.c:573
static TIFFSetGetFieldType _TIFFSetGetType(TIFFDataType type, short count, unsigned char passcount)
Definition: tif_dirinfo.c:990
#define TIFF_VARIABLE2
Definition: tiffio.h:344

◆ TIFFNumberOfDirectories()

tdir_t TIFFNumberOfDirectories ( TIFF tif)

Definition at line 2032 of file tif_dir.c.

2033{
2034 uint64_t nextdiroff;
2035 tdir_t nextdirnum;
2036 tdir_t n;
2037 if (!(tif->tif_flags & TIFF_BIGTIFF))
2038 nextdiroff = tif->tif_header.classic.tiff_diroff;
2039 else
2040 nextdiroff = tif->tif_header.big.tiff_diroff;
2041 nextdirnum = 0;
2042 n = 0;
2043 while (nextdiroff != 0 &&
2044 TIFFAdvanceDirectory(tif, &nextdiroff, NULL, &nextdirnum))
2045 {
2046 ++n;
2047 }
2048 /* Update number of main-IFDs in file. */
2049 tif->tif_curdircount = n;
2050 return (n);
2051}
static int TIFFAdvanceDirectory(TIFF *tif, uint64_t *nextdiroff, uint64_t *off, tdir_t *nextdirnum)
Definition: tif_dir.c:1838
uint32_t tdir_t
Definition: tiffio.h:71

Referenced by _TIFFGetDirNumberFromOffset(), tiff_decoder_initialize(), and TIFFWriteDirectorySec().

◆ TIFFNumberOfStrips()

uint32_t TIFFNumberOfStrips ( TIFF tif)

Definition at line 65 of file tif_strip.c.

66{
67 TIFFDirectory *td = &tif->tif_dir;
68 uint32_t nstrips;
69
70 if (td->td_rowsperstrip == 0)
71 {
72 TIFFWarningExtR(tif, "TIFFNumberOfStrips", "RowsPerStrip is zero");
73 return 0;
74 }
75 nstrips = (td->td_rowsperstrip == (uint32_t)-1
76 ? 1
79 nstrips =
81 "TIFFNumberOfStrips");
82 return (nstrips);
83}
uint32_t _TIFFMultiply32(TIFF *tif, uint32_t first, uint32_t second, const char *where)
Definition: tif_aux.c:35

Referenced by TIFFReadDirectory(), and TIFFSetupStrips().

◆ TIFFNumberOfTiles()

uint32_t TIFFNumberOfTiles ( TIFF tif)

Definition at line 108 of file tif_tile.c.

109{
110 TIFFDirectory *td = &tif->tif_dir;
113 uint32_t dz = td->td_tiledepth;
114 uint32_t ntiles;
115
116 if (dx == (uint32_t)-1)
117 dx = td->td_imagewidth;
118 if (dy == (uint32_t)-1)
119 dy = td->td_imagelength;
120 if (dz == (uint32_t)-1)
121 dz = td->td_imagedepth;
122 ntiles =
123 (dx == 0 || dy == 0 || dz == 0)
124 ? 0
126 tif,
129 "TIFFNumberOfTiles"),
130 TIFFhowmany_32(td->td_imagedepth, dz), "TIFFNumberOfTiles");
132 ntiles = _TIFFMultiply32(tif, ntiles, td->td_samplesperpixel,
133 "TIFFNumberOfTiles");
134 return (ntiles);
135}

Referenced by TIFFReadDirectory(), and TIFFSetupStrips().

◆ TIFFOpen()

TIFF * TIFFOpen ( const char name,
const char mode 
)

Definition at line 232 of file tif_unix.c.

233{
234 return TIFFOpenExt(name, mode, NULL);
235}
TIFF * TIFFOpenExt(const char *name, const char *mode, TIFFOpenOptions *opts)
Definition: tif_unix.c:237

◆ TIFFOpenExt()

TIFF * TIFFOpenExt ( const char name,
const char mode,
TIFFOpenOptions opts 
)

Definition at line 237 of file tif_unix.c.

238{
239 static const char module[] = "TIFFOpen";
240 int m, fd;
241 TIFF *tif;
242
243 m = _TIFFgetMode(opts, NULL, mode, module);
244 if (m == -1)
245 return ((TIFF *)0);
246
247/* for cygwin and mingw */
248#ifdef O_BINARY
249 m |= O_BINARY;
250#endif
251
252 fd = open(name, m, 0666);
253 if (fd < 0)
254 {
255 if (errno > 0 && strerror(errno) != NULL)
256 {
257 _TIFFErrorEarly(opts, NULL, module, "%s: %s", name,
258 strerror(errno));
259 }
260 else
261 {
262 _TIFFErrorEarly(opts, NULL, module, "%s: Cannot open", name);
263 }
264 return ((TIFF *)0);
265 }
266
267 tif = TIFFFdOpenExt((int)fd, name, mode, opts);
268 if (!tif)
269 close(fd);
270 return tif;
271}
#define close
Definition: acwin.h:98
char *CDECL strerror(int err)
Definition: errno.c:273
#define errno
Definition: errno.h:120
#define O_BINARY
Definition: fcntl.h:47
#define open
Definition: io.h:44

Referenced by TIFFOpen().

◆ TIFFOpenOptionsAlloc()

TIFFOpenOptions * TIFFOpenOptionsAlloc ( void  )

Definition at line 80 of file tif_open.c.

81{
82 TIFFOpenOptions *opts =
84 return opts;
85}
void * _TIFFcalloc(tmsize_t nmemb, tmsize_t siz)
Definition: tif_unix.c:341

◆ TIFFOpenOptionsFree()

void TIFFOpenOptionsFree ( TIFFOpenOptions opts)

Definition at line 87 of file tif_open.c.

87{ _TIFFfree(opts); }
void _TIFFfree(void *p)
Definition: tif_unix.c:349

◆ TIFFOpenOptionsSetErrorHandlerExtR()

void TIFFOpenOptionsSetErrorHandlerExtR ( TIFFOpenOptions opts,
TIFFErrorHandlerExtR  handler,
void errorhandler_user_data 
)

Definition at line 121 of file tif_open.c.

124{
125 opts->errorhandler = handler;
126 opts->errorhandler_user_data = errorhandler_user_data;
127}
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7512

◆ TIFFOpenOptionsSetMaxCumulatedMemAlloc()

void TIFFOpenOptionsSetMaxCumulatedMemAlloc ( TIFFOpenOptions opts,
tmsize_t  max_cumulated_mem_alloc 
)

Define a limit in bytes for the cumulated memory allocations done by libtiff on a given TIFF handle. If max_cumulated_mem_alloc is set to 0, which is the default, no other limit that the underlying _TIFFmalloc() or TIFFOpenOptionsSetMaxSingleMemAlloc() will be applied.

Definition at line 106 of file tif_open.c.

108{
109 opts->max_cumulated_mem_alloc = max_cumulated_mem_alloc;
110}

◆ TIFFOpenOptionsSetMaxSingleMemAlloc()

void TIFFOpenOptionsSetMaxSingleMemAlloc ( TIFFOpenOptions opts,
tmsize_t  max_single_mem_alloc 
)

Define a limit in bytes for a single memory allocation done by libtiff. If max_single_mem_alloc is set to 0, which is the default, no other limit that the underlying _TIFFmalloc() or TIFFOpenOptionsSetMaxCumulatedMemAlloc() will be applied.

Definition at line 94 of file tif_open.c.

96{
97 opts->max_single_mem_alloc = max_single_mem_alloc;
98}

◆ TIFFOpenOptionsSetWarnAboutUnknownTags()

void TIFFOpenOptionsSetWarnAboutUnknownTags ( TIFFOpenOptions opts,
int  warn_about_unknown_tags 
)

Whether a warning should be emitted when encountering a unknown tag. Default is FALSE since libtiff 4.7.1

Definition at line 115 of file tif_open.c.

117{
118 opts->warn_about_unknown_tags = warn_about_unknown_tags;
119}

◆ TIFFOpenOptionsSetWarningHandlerExtR()

void TIFFOpenOptionsSetWarningHandlerExtR ( TIFFOpenOptions opts,
TIFFErrorHandlerExtR  handler,
void warnhandler_user_data 
)

Definition at line 129 of file tif_open.c.

132{
133 opts->warnhandler = handler;
134 opts->warnhandler_user_data = warnhandler_user_data;
135}

◆ TIFFPrintDirectory()

void TIFFPrintDirectory ( TIFF tif,
FILE fd,
long  flags 
)

Definition at line 244 of file tif_print.c.

245{
246 TIFFDirectory *td = &tif->tif_dir;
247 char *sep;
248 long l, n;
249
250 fprintf(fd, "TIFF Directory at offset 0x%" PRIx64 " (%" PRIu64 ")\n",
251 tif->tif_diroff, tif->tif_diroff);
253 {
254 fprintf(fd, " Subfile Type:");
255 sep = " ";
257 {
258 fprintf(fd, "%sreduced-resolution image", sep);
259 sep = "/";
260 }
262 {
263 fprintf(fd, "%smulti-page document", sep);
264 sep = "/";
265 }
267 fprintf(fd, "%stransparency mask", sep);
268 fprintf(fd, " (%" PRIu32 " = 0x%" PRIx32 ")\n", td->td_subfiletype,
269 td->td_subfiletype);
270 }
272 {
273 fprintf(fd, " Image Width: %" PRIu32 " Image Length: %" PRIu32,
276 fprintf(fd, " Image Depth: %" PRIu32, td->td_imagedepth);
277 fprintf(fd, "\n");
278 }
280 {
281 fprintf(fd, " Tile Width: %" PRIu32 " Tile Length: %" PRIu32,
282 td->td_tilewidth, td->td_tilelength);
284 fprintf(fd, " Tile Depth: %" PRIu32, td->td_tiledepth);
285 fprintf(fd, "\n");
286 }
288 {
289 fprintf(fd, " Resolution: %g, %g", td->td_xresolution,
290 td->td_yresolution);
292 {
293 switch (td->td_resolutionunit)
294 {
295 case RESUNIT_NONE:
296 fprintf(fd, " (unitless)");
297 break;
298 case RESUNIT_INCH:
299 fprintf(fd, " pixels/inch");
300 break;
302 fprintf(fd, " pixels/cm");
303 break;
304 default:
305 fprintf(fd, " (unit %" PRIu16 " = 0x%" PRIx16 ")",
307 break;
308 }
309 }
310 fprintf(fd, "\n");
311 }
313 fprintf(fd, " Position: %g, %g\n", td->td_xposition, td->td_yposition);
315 fprintf(fd, " Bits/Sample: %" PRIu16 "\n", td->td_bitspersample);
317 {
318 fprintf(fd, " Sample Format: ");
319 switch (td->td_sampleformat)
320 {
322 fprintf(fd, "void\n");
323 break;
324 case SAMPLEFORMAT_INT:
325 fprintf(fd, "signed integer\n");
326 break;
328 fprintf(fd, "unsigned integer\n");
329 break;
331 fprintf(fd, "IEEE floating point\n");
332 break;
334 fprintf(fd, "complex signed integer\n");
335 break;
337 fprintf(fd, "complex IEEE floating point\n");
338 break;
339 default:
340 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n",
342 break;
343 }
344 }
346 {
348 fprintf(fd, " Compression Scheme: ");
349 if (c)
350 fprintf(fd, "%s\n", c->name);
351 else
352 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n", td->td_compression,
353 td->td_compression);
354 }
356 {
357 fprintf(fd, " Photometric Interpretation: ");
358 if (td->td_photometric < NPHOTONAMES)
359 fprintf(fd, "%s\n", photoNames[td->td_photometric]);
360 else
361 {
362 switch (td->td_photometric)
363 {
364 case PHOTOMETRIC_LOGL:
365 fprintf(fd, "CIE Log2(L)\n");
366 break;
368 fprintf(fd, "CIE Log2(L) (u',v')\n");
369 break;
370 default:
371 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n",
373 break;
374 }
375 }
376 }
378 {
379 uint16_t i;
380 fprintf(fd, " Extra Samples: %" PRIu16 "<", td->td_extrasamples);
381 sep = "";
382 for (i = 0; i < td->td_extrasamples; i++)
383 {
384 switch (td->td_sampleinfo[i])
385 {
387 fprintf(fd, "%sunspecified", sep);
388 break;
390 fprintf(fd, "%sassoc-alpha", sep);
391 break;
393 fprintf(fd, "%sunassoc-alpha", sep);
394 break;
395 default:
396 fprintf(fd, "%s%" PRIu16 " (0x%" PRIx16 ")", sep,
397 td->td_sampleinfo[i], td->td_sampleinfo[i]);
398 break;
399 }
400 sep = ", ";
401 }
402 fprintf(fd, ">\n");
403 }
405 {
406 char *cp;
407 uint16_t i;
408 fprintf(fd, " Ink Names: ");
409 i = td->td_samplesperpixel;
410 sep = "";
411 for (cp = td->td_inknames;
412 i > 0 && cp < td->td_inknames + td->td_inknameslen;
413 cp = strchr(cp, '\0') + 1, i--)
414 {
415 size_t max_chars = td->td_inknameslen - (cp - td->td_inknames);
416 fputs(sep, fd);
417 _TIFFprintAsciiBounded(fd, cp, max_chars);
418 sep = ", ";
419 }
420 fputs("\n", fd);
421 }
423 {
424 fprintf(fd, " NumberOfInks: %d\n", td->td_numberofinks);
425 }
427 {
428 fprintf(fd, " Thresholding: ");
429 switch (td->td_threshholding)
430 {
432 fprintf(fd, "bilevel art scan\n");
433 break;
435 fprintf(fd, "halftone or dithered scan\n");
436 break;
438 fprintf(fd, "error diffused\n");
439 break;
440 default:
441 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n",
443 break;
444 }
445 }
447 {
448 fprintf(fd, " FillOrder: ");
449 switch (td->td_fillorder)
450 {
452 fprintf(fd, "msb-to-lsb\n");
453 break;
455 fprintf(fd, "lsb-to-msb\n");
456 break;
457 default:
458 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n", td->td_fillorder,
459 td->td_fillorder);
460 break;
461 }
462 }
464 {
465 fprintf(fd, " YCbCr Subsampling: %" PRIu16 ", %" PRIu16 "\n",
467 }
469 {
470 fprintf(fd, " YCbCr Positioning: ");
471 switch (td->td_ycbcrpositioning)
472 {
474 fprintf(fd, "centered\n");
475 break;
477 fprintf(fd, "cosited\n");
478 break;
479 default:
480 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n",
482 break;
483 }
484 }
486 fprintf(fd, " Halftone Hints: light %" PRIu16 " dark %" PRIu16 "\n",
487 td->td_halftonehints[0], td->td_halftonehints[1]);
489 {
490 fprintf(fd, " Orientation: ");
492 fprintf(fd, "%s\n", orientNames[td->td_orientation]);
493 else
494 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n", td->td_orientation,
495 td->td_orientation);
496 }
498 fprintf(fd, " Samples/Pixel: %" PRIx16 "\n", td->td_samplesperpixel);
500 {
501 fprintf(fd, " Rows/Strip: ");
502 if (td->td_rowsperstrip == (uint32_t)-1)
503 fprintf(fd, "(infinite)\n");
504 else
505 fprintf(fd, "%" PRIu32 "\n", td->td_rowsperstrip);
506 }
508 fprintf(fd, " Min Sample Value: %" PRIu16 "\n", td->td_minsamplevalue);
510 fprintf(fd, " Max Sample Value: %" PRIu16 "\n", td->td_maxsamplevalue);
512 {
513 int i;
514 int count =
516 fprintf(fd, " SMin Sample Value:");
517 for (i = 0; i < count; ++i)
518 fprintf(fd, " %g", td->td_sminsamplevalue[i]);
519 fprintf(fd, "\n");
520 }
522 {
523 int i;
524 int count =
526 fprintf(fd, " SMax Sample Value:");
527 for (i = 0; i < count; ++i)
528 fprintf(fd, " %g", td->td_smaxsamplevalue[i]);
529 fprintf(fd, "\n");
530 }
532 {
533 fprintf(fd, " Planar Configuration: ");
534 switch (td->td_planarconfig)
535 {
537 fprintf(fd, "single image plane\n");
538 break;
540 fprintf(fd, "separate image planes\n");
541 break;
542 default:
543 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n",
545 break;
546 }
547 }
549 fprintf(fd, " Page Number: %" PRIu16 "-%" PRIu16 "\n",
550 td->td_pagenumber[0], td->td_pagenumber[1]);
552 {
553 fprintf(fd, " Color Map: ");
555 {
556 fprintf(fd, "\n");
557 n = 1L << td->td_bitspersample;
558 for (l = 0; l < n; l++)
559 fprintf(fd, " %5ld: %5" PRIu16 " %5" PRIu16 " %5" PRIu16 "\n",
560 l, td->td_colormap[0][l], td->td_colormap[1][l],
561 td->td_colormap[2][l]);
562 }
563 else
564 fprintf(fd, "(present)\n");
565 }
567 {
568 int i;
569 fprintf(fd, " Reference Black/White:\n");
570 for (i = 0; i < 3; i++)
571 fprintf(fd, " %2d: %5g %5g\n", i,
572 td->td_refblackwhite[2 * i + 0],
573 td->td_refblackwhite[2 * i + 1]);
574 }
576 {
577 fprintf(fd, " Transfer Function: ");
579 {
580 fprintf(fd, "\n");
581 n = 1L << td->td_bitspersample;
582 for (l = 0; l < n; l++)
583 {
584 uint16_t i;
585 fprintf(fd, " %2ld: %5" PRIu16, l,
586 td->td_transferfunction[0][l]);
587 for (i = 1;
588 i < td->td_samplesperpixel - td->td_extrasamples && i < 3;
589 i++)
590 fprintf(fd, " %5" PRIu16, td->td_transferfunction[i][l]);
591 fputc('\n', fd);
592 }
593 }
594 else
595 fprintf(fd, "(present)\n");
596 }
597 if (TIFFFieldSet(tif, FIELD_SUBIFD) && (td->td_subifd))
598 {
599 uint16_t i;
600 fprintf(fd, " SubIFD Offsets:");
601 for (i = 0; i < td->td_nsubifd; i++)
602 fprintf(fd, " %5" PRIu64, td->td_subifd[i]);
603 fputc('\n', fd);
604 }
605
606 /*
607 ** Custom tag support.
608 */
609 {
610 int i;
611 short count;
612
614 for (i = 0; i < count; i++)
615 {
617 const TIFFField *fip;
618 uint32_t value_count;
619 int mem_alloc = 0;
620 void *raw_data = NULL;
621 uint16_t dotrange[2]; /* must be kept in that scope and not moved in
622 the below TIFFTAG_DOTRANGE specific case */
623
624 fip = TIFFFieldWithTag(tif, tag);
625 if (fip == NULL)
626 continue;
627
628 if (fip->field_passcount)
629 {
631 {
632 if (TIFFGetField(tif, tag, &value_count, &raw_data) != 1)
633 continue;
634 }
635 else if (fip->field_readcount == TIFF_VARIABLE)
636 {
637 uint16_t small_value_count;
638 if (TIFFGetField(tif, tag, &small_value_count, &raw_data) !=
639 1)
640 continue;
641 value_count = small_value_count;
642 }
643 else
644 {
647 continue;
648 }
649 }
650 else
651 {
652 if (fip->field_readcount == TIFF_VARIABLE ||
654 value_count = 1;
655 else if (fip->field_readcount == TIFF_SPP)
656 value_count = td->td_samplesperpixel;
657 else
658 value_count = fip->field_readcount;
659 if (fip->field_tag == TIFFTAG_DOTRANGE &&
660 strcmp(fip->field_name, "DotRange") == 0)
661 {
662 /* TODO: This is an evil exception and should not have been
663 handled this way ... likely best if we move it into
664 the directory structure with an explicit field in
665 libtiff 4.1 and assign it a FIELD_ value */
666 raw_data = dotrange;
667 TIFFGetField(tif, tag, dotrange + 0, dotrange + 1);
668 }
669 else if (fip->field_type == TIFF_ASCII ||
672 fip->field_readcount == TIFF_SPP || value_count > 1)
673 {
674 if (TIFFGetField(tif, tag, &raw_data) != 1)
675 continue;
676 }
677 else
678 {
679 /*--: Rational2Double: For Rationals evaluate
680 * "set_get_field_type" to determine internal storage size.
681 */
682 int tv_size = TIFFFieldSetGetSize(fip);
683 raw_data = _TIFFmallocExt(tif, tv_size * value_count);
684 mem_alloc = 1;
685 if (TIFFGetField(tif, tag, raw_data) != 1)
686 {
687 _TIFFfreeExt(tif, raw_data);
688 continue;
689 }
690 }
691 }
692
693 /*
694 * Catch the tags which needs to be specially handled
695 * and pretty print them. If tag not handled in
696 * _TIFFPrettyPrintField() fall down and print it as
697 * any other tag.
698 */
699 if (raw_data != NULL &&
700 !_TIFFPrettyPrintField(tif, fip, fd, tag, value_count,
701 raw_data))
702 _TIFFPrintField(fd, fip, value_count, raw_data);
703
704 if (mem_alloc)
705 _TIFFfreeExt(tif, raw_data);
706 }
707 }
708
709 if (tif->tif_tagmethods.printdir)
710 (*tif->tif_tagmethods.printdir)(tif, fd, flags);
711
713 {
714 uint32_t s;
715
716 fprintf(fd, " %" PRIu32 " %s:\n", td->td_nstrips,
717 isTiled(tif) ? "Tiles" : "Strips");
718 for (s = 0; s < td->td_nstrips; s++)
719 fprintf(fd, " %3" PRIu32 ": [%8" PRIu64 ", %8" PRIu64 "]\n", s,
722 }
723}
#define mem_alloc(bsize)
Definition: types.h:123
int WINAPIV fprintf(FILE *file, const char *format,...)
Definition: file.c:5549
int CDECL fputs(const char *s, FILE *file)
Definition: file.c:4769
int CDECL fputc(int c, FILE *file)
Definition: file.c:4360
#define PRIx32
Definition: inttypes.h:101
#define PRIu32
Definition: inttypes.h:84
#define PRIx64
Definition: inttypes.h:29
_ACRTIMP char *__cdecl strchr(const char *, int)
Definition: string.c:3286
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
Definition: typeof.h:94
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLbitfield flags
Definition: glext.h:7161
uint16_t td_pagenumber[2]
Definition: tif_dir.h:102
float td_xposition
Definition: tif_dir.h:101
uint16_t td_fillorder
Definition: tif_dir.h:91
float td_xresolution
Definition: tif_dir.h:98
int td_inknameslen
Definition: tif_dir.h:138
uint16_t * td_sampleinfo
Definition: tif_dir.h:106
float * td_refblackwhite
Definition: tif_dir.h:136
uint16_t td_compression
Definition: tif_dir.h:88
uint16_t td_photometric
Definition: tif_dir.h:89
float td_yresolution
Definition: tif_dir.h:98
uint16_t td_extrasamples
Definition: tif_dir.h:105
uint16_t td_threshholding
Definition: tif_dir.h:90
uint16_t td_minsamplevalue
Definition: tif_dir.h:95
double * td_sminsamplevalue
Definition: tif_dir.h:96
uint16_t td_bitspersample
Definition: tif_dir.h:86
char * td_inknames
Definition: tif_dir.h:139
uint16_t * td_transferfunction[3]
Definition: tif_dir.h:135
uint16_t td_maxsamplevalue
Definition: tif_dir.h:95
uint16_t td_orientation
Definition: tif_dir.h:92
uint16_t td_resolutionunit
Definition: tif_dir.h:99
double * td_smaxsamplevalue
Definition: tif_dir.h:97
uint16_t * td_colormap[3]
Definition: tif_dir.h:103
uint16_t td_sampleformat
Definition: tif_dir.h:87
uint16_t td_ycbcrsubsampling[2]
Definition: tif_dir.h:132
uint32_t td_subfiletype
Definition: tif_dir.h:85
uint16_t td_numberofinks
Definition: tif_dir.h:140
uint16_t td_nsubifd
Definition: tif_dir.h:129
uint64_t * td_subifd
Definition: tif_dir.h:130
float td_yposition
Definition: tif_dir.h:101
uint16_t td_ycbcrpositioning
Definition: tif_dir.h:133
uint16_t td_halftonehints[2]
Definition: tif_dir.h:104
TIFFPrintMethod printdir
Definition: tiffio.h:377
int TIFFGetField(TIFF *tif, uint32_t tag,...)
Definition: tif_dir.c:1582
#define FIELD_RESOLUTION
Definition: tif_dir.h:183
#define FIELD_SUBFILETYPE
Definition: tif_dir.h:187
#define FIELD_STRIPOFFSETS
Definition: tif_dir.h:202
#define FIELD_TRANSFERFUNCTION
Definition: tif_dir.h:214
#define FIELD_HALFTONEHINTS
Definition: tif_dir.h:210
#define FIELD_ORIENTATION
Definition: tif_dir.h:193
#define FIELD_MINSAMPLEVALUE
Definition: tif_dir.h:196
#define FIELD_FILLORDER
Definition: tif_dir.h:192
#define FIELD_SMAXSAMPLEVALUE
Definition: tif_dir.h:207
#define FIELD_IMAGEDIMENSIONS
Definition: tif_dir.h:181
#define FIELD_COLORMAP
Definition: tif_dir.h:203
#define FIELD_SUBIFD
Definition: tif_dir.h:216
#define FIELD_EXTRASAMPLES
Definition: tif_dir.h:204
#define FIELD_IMAGEDEPTH
Definition: tif_dir.h:208
#define FIELD_SMINSAMPLEVALUE
Definition: tif_dir.h:206
#define TIFFFieldSet(tif, field)
Definition: tif_dir.h:236
#define FIELD_MAXSAMPLEVALUE
Definition: tif_dir.h:197
#define FIELD_NUMBEROFINKS
Definition: tif_dir.h:217
#define FIELD_TILEDEPTH
Definition: tif_dir.h:209
#define FIELD_TILEDIMENSIONS
Definition: tif_dir.h:182
#define FIELD_POSITION
Definition: tif_dir.h:184
#define FIELD_ROWSPERSTRIP
Definition: tif_dir.h:195
#define FIELD_COMPRESSION
Definition: tif_dir.h:189
#define FIELD_REFBLACKWHITE
Definition: tif_dir.h:213
#define FIELD_SAMPLEFORMAT
Definition: tif_dir.h:205
#define FIELD_PAGENUMBER
Definition: tif_dir.h:200
#define FIELD_BITSPERSAMPLE
Definition: tif_dir.h:188
#define FIELD_INKNAMES
Definition: tif_dir.h:215
#define FIELD_RESOLUTIONUNIT
Definition: tif_dir.h:199
#define FIELD_PLANARCONFIG
Definition: tif_dir.h:198
#define FIELD_SAMPLESPERPIXEL
Definition: tif_dir.h:194
#define FIELD_PHOTOMETRIC
Definition: tif_dir.h:190
#define FIELD_THRESHHOLDING
Definition: tif_dir.h:191
const TIFFField * TIFFFieldWithTag(TIFF *tif, uint32_t tag)
Definition: tif_dirinfo.c:845
int TIFFFieldSetGetSize(const TIFFField *fip)
Definition: tif_dirinfo.c:673
uint64_t TIFFGetStrileOffset(TIFF *tif, uint32_t strile)
Definition: tif_dirread.c:8349
uint64_t TIFFGetStrileByteCount(TIFF *tif, uint32_t strile)
Definition: tif_dirread.c:8366
uint32_t TIFFGetTagListEntry(TIFF *tif, int tag_index)
Definition: tif_extension.c:42
int TIFFGetTagListCount(TIFF *tif)
Definition: tif_extension.c:34
static int _TIFFPrettyPrintField(TIFF *tif, const TIFFField *fip, FILE *fd, uint32_t tag, uint32_t value_count, void *raw_data)
Definition: tif_print.c:151
#define NORIENTNAMES
Definition: tif_print.c:63
#define NPHOTONAMES
Definition: tif_print.c:50
static void _TIFFPrintField(FILE *fd, const TIFFField *fip, uint32_t value_count, void *raw_data)
Definition: tif_print.c:75
static void _TIFFprintAsciiBounded(FILE *fd, const char *cp, size_t max_chars)
Definition: tif_print.c:730
static const char *const photoNames[]
Definition: tif_print.c:37
static const char *const orientNames[]
Definition: tif_print.c:52
#define THRESHHOLD_HALFTONE
Definition: tiff.h:236
#define TIFFTAG_DOTRANGE
Definition: tiff.h:327
#define EXTRASAMPLE_UNASSALPHA
Definition: tiff.h:332
#define YCBCRPOSITION_CENTERED
Definition: tiff.h:390
#define YCBCRPOSITION_COSITED
Definition: tiff.h:391
#define RESUNIT_CENTIMETER
Definition: tiff.h:290
#define EXTRASAMPLE_ASSOCALPHA
Definition: tiff.h:331
#define FILETYPE_MASK
Definition: tiff.h:173
#define PHOTOMETRIC_LOGL
Definition: tiff.h:232
#define SAMPLEFORMAT_COMPLEXINT
Definition: tiff.h:338
#define SAMPLEFORMAT_UINT
Definition: tiff.h:334
#define EXTRASAMPLE_UNSPECIFIED
Definition: tiff.h:330
#define RESUNIT_NONE
Definition: tiff.h:288
#define FILETYPE_REDUCEDIMAGE
Definition: tiff.h:171
#define THRESHHOLD_ERRORDIFFUSE
Definition: tiff.h:237
#define PHOTOMETRIC_LOGLUV
Definition: tiff.h:233
#define FILETYPE_PAGE
Definition: tiff.h:172
#define SAMPLEFORMAT_IEEEFP
Definition: tiff.h:336
#define SAMPLEFORMAT_COMPLEXIEEEFP
Definition: tiff.h:339
#define RESUNIT_INCH
Definition: tiff.h:289
#define THRESHHOLD_BILEVEL
Definition: tiff.h:235
#define SAMPLEFORMAT_VOID
Definition: tiff.h:337
#define SAMPLEFORMAT_INT
Definition: tiff.h:335
#define PLANARCONFIG_CONTIG
Definition: tiff.h:265
#define TIFFPRINT_STRIPS
Definition: tiffio.h:116
#define TIFFPRINT_COLORMAP
Definition: tiffio.h:118
#define TIFF_SPP
Definition: tiffio.h:343
#define TIFF_VARIABLE
Definition: tiffio.h:342
#define TIFFPRINT_CURVES
Definition: tiffio.h:117
#define TIFF_PERSAMPLE
Definition: tiffiop.h:141

◆ TIFFRasterScanlineSize()

tmsize_t TIFFRasterScanlineSize ( TIFF tif)

Definition at line 375 of file tif_strip.c.

376{
377 static const char module[] = "TIFFRasterScanlineSize";
378 uint64_t m;
380 return _TIFFCastUInt64ToSSize(tif, m, module);
381}
tmsize_t _TIFFCastUInt64ToSSize(TIFF *tif, uint64_t val, const char *module)
Definition: tif_aux.c:84
uint64_t TIFFRasterScanlineSize64(TIFF *tif)
Definition: tif_strip.c:357

◆ TIFFRasterScanlineSize64()

uint64_t TIFFRasterScanlineSize64 ( TIFF tif)

Definition at line 357 of file tif_strip.c.

358{
359 static const char module[] = "TIFFRasterScanlineSize64";
360 TIFFDirectory *td = &tif->tif_dir;
361 uint64_t scanline;
362
363 scanline =
366 {
367 scanline =
368 _TIFFMultiply64(tif, scanline, td->td_samplesperpixel, module);
369 return (TIFFhowmany8_64(scanline));
370 }
371 else
372 return (_TIFFMultiply64(tif, TIFFhowmany8_64(scanline),
374}
uint64_t _TIFFMultiply64(TIFF *tif, uint64_t first, uint64_t second, const char *where)
Definition: tif_aux.c:47
#define TIFFhowmany8_64(x)
Definition: tiffiop.h:319

Referenced by TIFFRasterScanlineSize().

◆ TIFFRawStripSize()

tmsize_t TIFFRawStripSize ( TIFF tif,
uint32_t  strip 
)

Definition at line 168 of file tif_strip.c.

169{
170 static const char module[] = "TIFFRawStripSize";
171 uint64_t m;
172 tmsize_t n;
173 m = TIFFRawStripSize64(tif, strip);
174 if (m == (uint64_t)(-1))
175 n = (tmsize_t)(-1);
176 else
177 {
178 n = (tmsize_t)m;
179 if ((uint64_t)n != m)
180 {
181 TIFFErrorExtR(tif, module, "Integer overflow");
182 n = 0;
183 }
184 }
185 return (n);
186}
uint64_t TIFFRawStripSize64(TIFF *tif, uint32_t strip)
Definition: tif_strip.c:153

◆ TIFFRawStripSize64()

uint64_t TIFFRawStripSize64 ( TIFF tif,
uint32_t  strip 
)

Definition at line 153 of file tif_strip.c.

154{
155 static const char module[] = "TIFFRawStripSize64";
156 uint64_t bytecount = TIFFGetStrileByteCount(tif, strip);
157
158 if (bytecount == 0)
159 {
161 "%" PRIu64 ": Invalid strip byte count, strip %lu",
162 (uint64_t)bytecount, (unsigned long)strip);
163 bytecount = (uint64_t)-1;
164 }
165
166 return bytecount;
167}
#define uint64_t
Definition: nsiface.idl:62

Referenced by TIFFRawStripSize().

◆ TIFFReadBufferSetup()

int TIFFReadBufferSetup ( TIFF tif,
void bp,
tmsize_t  size 
)

Definition at line 1375 of file tif_read.c.

1376{
1377 static const char module[] = "TIFFReadBufferSetup";
1378
1379 assert((tif->tif_flags & TIFF_NOREADRAW) == 0);
1380 tif->tif_flags &= ~TIFF_BUFFERMMAP;
1381
1382 if (tif->tif_rawdata)
1383 {
1384 if (tif->tif_flags & TIFF_MYBUFFER)
1385 _TIFFfreeExt(tif, tif->tif_rawdata);
1386 tif->tif_rawdata = NULL;
1387 tif->tif_rawdatasize = 0;
1388 }
1389 if (bp)
1390 {
1391 tif->tif_rawdatasize = size;
1392 tif->tif_rawdata = (uint8_t *)bp;
1393 tif->tif_flags &= ~TIFF_MYBUFFER;
1394 }
1395 else
1396 {
1398 if (tif->tif_rawdatasize == 0)
1399 {
1400 TIFFErrorExtR(tif, module, "Invalid buffer size");
1401 return (0);
1402 }
1403 /* Initialize to zero to avoid uninitialized buffers in case of */
1404 /* short reads (http://bugzilla.maptools.org/show_bug.cgi?id=2651) */
1405 tif->tif_rawdata =
1406 (uint8_t *)_TIFFcallocExt(tif, 1, tif->tif_rawdatasize);
1407 tif->tif_flags |= TIFF_MYBUFFER;
1408 }
1409 if (tif->tif_rawdata == NULL)
1410 {
1411 TIFFErrorExtR(tif, module,
1412 "No space for data buffer at scanline %" PRIu32,
1413 tif->tif_row);
1414 tif->tif_rawdatasize = 0;
1415 return (0);
1416 }
1417 return (1);
1418}
GLsizeiptr size
Definition: glext.h:5919
void * _TIFFcallocExt(TIFF *tif, tmsize_t nmemb, tmsize_t siz)
Definition: tif_open.c:201
#define TIFFroundup_64(x, y)
Definition: tiffiop.h:321
#define TIFF_NOREADRAW
Definition: tiffiop.h:135

Referenced by TIFFFillStrip(), and TIFFFillTile().

◆ TIFFReadCustomDirectory()

int TIFFReadCustomDirectory ( TIFF tif,
toff_t  diroff,
const TIFFFieldArray infoarray 
)

Definition at line 5278 of file tif_dirread.c.

5280{
5281 static const char module[] = "TIFFReadCustomDirectory";
5283 uint16_t dircount;
5284 TIFFDirEntry *dp;
5285 uint16_t di;
5286 const TIFFField *fip;
5287 uint32_t fii;
5288
5289 assert(infoarray != NULL);
5290 dircount = TIFFFetchDirectory(tif, diroff, &dir, NULL);
5291 if (!dircount)
5292 {
5293 TIFFErrorExtR(tif, module,
5294 "Failed to read custom directory at offset %" PRIu64,
5295 diroff);
5296 return 0;
5297 }
5298 TIFFReadDirectoryCheckOrder(tif, dir, dircount);
5299
5300 /*
5301 * Mark duplicates of any tag to be ignored (bugzilla 1994)
5302 * to avoid certain pathological problems.
5303 */
5304 {
5305 TIFFDirEntry *ma;
5306 uint16_t mb;
5307 for (ma = dir, mb = 0; mb < dircount; ma++, mb++)
5308 {
5309 TIFFDirEntry *na;
5310 uint16_t nb;
5311 for (na = ma + 1, nb = mb + 1; nb < dircount; na++, nb++)
5312 {
5313 if (ma->tdir_tag == na->tdir_tag)
5314 {
5315 na->tdir_ignore = TRUE;
5316 }
5317 }
5318 }
5319 }
5320
5321 /* Free any old stuff and reinit. */
5322 TIFFFreeDirectory(tif);
5323 /* Even if custom directories do not need the default settings of a standard
5324 * IFD, the pointer to the TIFFSetField() and TIFFGetField() (i.e.
5325 * tif->tif_tagmethods.vsetfield and tif->tif_tagmethods.vgetfield) need to
5326 * be initialized, which is done in TIFFDefaultDirectory().
5327 * After that, the field array for the custom tags needs to be setup again.
5328 */
5330 _TIFFSetupFields(tif, infoarray);
5331
5332 /* Allocate arrays for offset values outside IFD entry for IFD data size
5333 * checking. Note: Counter are reset within TIFFFreeDirectory(). */
5336 tif, dircount * sizeof(TIFFEntryOffsetAndLength));
5338 {
5340 tif, module,
5341 "Failed to allocate memory for counting IFD data size at reading");
5342 if (dir)
5343 _TIFFfreeExt(tif, dir);
5344 return 0;
5345 }
5346
5347 for (di = 0, dp = dir; di < dircount; di++, dp++)
5348 {
5350 if (fii == FAILED_FII)
5351 {
5353 {
5355 "Unknown field with tag %" PRIu16 " (0x%" PRIx16
5356 ") encountered",
5357 dp->tdir_tag, dp->tdir_tag);
5358 }
5359 const TIFFField *fld = _TIFFCreateAnonField(
5360 tif, dp->tdir_tag, (TIFFDataType)dp->tdir_type);
5361 if (fld == NULL || !_TIFFMergeFields(tif, fld, 1))
5362 {
5364 {
5366 tif, module,
5367 "Registering anonymous field with tag %" PRIu16
5368 " (0x%" PRIx16 ") failed",
5369 dp->tdir_tag, dp->tdir_tag);
5370 }
5371 dp->tdir_ignore = TRUE;
5372 }
5373 else
5374 {
5376 assert(fii != FAILED_FII);
5377 }
5378 }
5379 if (!dp->tdir_ignore)
5380 {
5381 fip = tif->tif_fields[fii];
5382 if (fip->field_bit == FIELD_IGNORE)
5383 dp->tdir_ignore = TRUE;
5384 else
5385 {
5386 /* check data type */
5387 while ((fip->field_type != TIFF_ANY) &&
5388 (fip->field_type != dp->tdir_type))
5389 {
5390 fii++;
5391 if ((fii == tif->tif_nfields) ||
5392 (tif->tif_fields[fii]->field_tag !=
5393 (uint32_t)dp->tdir_tag))
5394 {
5395 fii = 0xFFFF;
5396 break;
5397 }
5398 fip = tif->tif_fields[fii];
5399 }
5400 if (fii == 0xFFFF)
5401 {
5403 "Wrong data type %" PRIu16
5404 " for \"%s\"; tag ignored",
5405 dp->tdir_type, fip->field_name);
5406 dp->tdir_ignore = TRUE;
5407 }
5408 else
5409 {
5410 /* check count if known in advance */
5411 if ((fip->field_readcount != TIFF_VARIABLE) &&
5413 {
5415 if (fip->field_readcount == TIFF_SPP)
5416 expected =
5418 else
5420 if (!CheckDirCount(tif, dp, expected))
5421 dp->tdir_ignore = TRUE;
5422 }
5423 }
5424 }
5425 if (!dp->tdir_ignore)
5426 {
5427 switch (dp->tdir_tag)
5428 {
5430 if (!TIFFFieldIsAnonymous(fip))
5431 {
5432 /* should only be called on a Exif directory */
5433 /* when exifFields[] is active */
5435 }
5436 else
5437 {
5438 (void)TIFFFetchNormalTag(tif, dp, TRUE);
5439 }
5440 break;
5441 default:
5442 (void)TIFFFetchNormalTag(tif, dp, TRUE);
5443 break;
5444 }
5445 } /*-- if (!dp->tdir_ignore) */
5446 }
5447 }
5448 /* Evaluate final IFD data size. */
5449 CalcFinalIFDdatasizeReading(tif, dircount);
5450
5451 /* To be able to return from SubIFD or custom-IFD to main-IFD */
5453 if (dir)
5454 _TIFFfreeExt(tif, dir);
5455 return 1;
5456}
unsigned int dir
Definition: maze.c:112
BOOL expected
Definition: store.c:2000
uint8_t tdir_ignore
Definition: tif_dir.h:64
TIFFField * _TIFFCreateAnonField(TIFF *tif, uint32_t tag, TIFFDataType field_type)
Definition: tif_dirinfo.c:898
#define FAILED_FII
Definition: tif_dirread.c:44
static void TIFFReadDirectoryFindFieldInfo(TIFF *tif, uint16_t tagid, uint32_t *fii)
Definition: tif_dirread.c:5242
static int CheckDirCount(TIFF *, TIFFDirEntry *, uint32_t)
Definition: tif_dirread.c:5947
static void CalcFinalIFDdatasizeReading(TIFF *tif, uint16_t dircount)
Definition: tif_dirread.c:4160
static void TIFFReadDirectoryCheckOrder(TIFF *tif, TIFFDirEntry *dir, uint16_t dircount)
Definition: tif_dirread.c:5206
static uint16_t TIFFFetchDirectory(TIFF *tif, uint64_t diroff, TIFFDirEntry **pdir, uint64_t *nextdiroff)
Definition: tif_dirread.c:5978
static int TIFFFetchSubjectDistance(TIFF *, TIFFDirEntry *)
Definition: tif_dirread.c:7716
static int TIFFFetchNormalTag(TIFF *, TIFFDirEntry *, int recover)
Definition: tif_dirread.c:6273
TIFFDataType
Definition: tiff.h:146
#define EXIFTAG_SUBJECTDISTANCE
Definition: tiff.h:792

Referenced by TIFFReadEXIFDirectory(), and TIFFReadGPSDirectory().

◆ TIFFReadDirectory()

int TIFFReadDirectory ( TIFF tif)

Definition at line 4236 of file tif_dirread.c.

4237{
4238 static const char module[] = "TIFFReadDirectory";
4240 uint16_t dircount;
4241 TIFFDirEntry *dp;
4242 uint16_t di;
4243 const TIFFField *fip;
4244 uint32_t fii = FAILED_FII;
4245 toff_t nextdiroff;
4246 int bitspersample_read = FALSE;
4247 int color_channels;
4248
4249 if (tif->tif_nextdiroff == 0)
4250 {
4251 /* In this special case, tif_diroff needs also to be set to 0.
4252 * This is behind the last IFD, thus no checking or reading necessary.
4253 */
4254 tif->tif_diroff = tif->tif_nextdiroff;
4255 return 0;
4256 }
4257
4258 nextdiroff = tif->tif_nextdiroff;
4259 /* tif_curdir++ and tif_nextdiroff should only be updated after SUCCESSFUL
4260 * reading of the directory. Otherwise, invalid IFD offsets could corrupt
4261 * the IFD list. */
4263 tif->tif_curdir ==
4265 ? 0
4266 : tif->tif_curdir + 1,
4267 nextdiroff))
4268 {
4269 return 0; /* bad offset (IFD looping or more than TIFF_MAX_DIR_COUNT
4270 IFDs) */
4271 }
4272 dircount = TIFFFetchDirectory(tif, nextdiroff, &dir, &tif->tif_nextdiroff);
4273 if (!dircount)
4274 {
4275 TIFFErrorExtR(tif, module,
4276 "Failed to read directory at offset %" PRIu64,
4277 nextdiroff);
4278 return 0;
4279 }
4280 /* Set global values after a valid directory has been fetched.
4281 * tif_diroff is already set to nextdiroff in TIFFFetchDirectory() in the
4282 * beginning. */
4284 tif->tif_curdir = 0;
4285 else
4286 tif->tif_curdir++;
4287
4288 TIFFReadDirectoryCheckOrder(tif, dir, dircount);
4289
4290 /*
4291 * Mark duplicates of any tag to be ignored (bugzilla 1994)
4292 * to avoid certain pathological problems.
4293 */
4294 {
4295 TIFFDirEntry *ma;
4296 uint16_t mb;
4297 for (ma = dir, mb = 0; mb < dircount; ma++, mb++)
4298 {
4299 TIFFDirEntry *na;
4300 uint16_t nb;
4301 for (na = ma + 1, nb = mb + 1; nb < dircount; na++, nb++)
4302 {
4303 if (ma->tdir_tag == na->tdir_tag)
4304 {
4305 na->tdir_ignore = TRUE;
4306 }
4307 }
4308 }
4309 }
4310
4311 tif->tif_flags &= ~TIFF_BEENWRITING; /* reset before new dir */
4312 tif->tif_flags &= ~TIFF_BUF4WRITE; /* reset before new dir */
4313 tif->tif_flags &= ~TIFF_CHOPPEDUPARRAYS;
4314
4315 /* free any old stuff and reinit */
4316 TIFFFreeDirectory(tif);
4318
4319 /* After setup a fresh directory indicate that now active IFD is also
4320 * present on file, even if its entries could not be read successfully
4321 * below. */
4323
4324 /* Allocate arrays for offset values outside IFD entry for IFD data size
4325 * checking. Note: Counter are reset within TIFFFreeDirectory(). */
4328 tif, dircount * sizeof(TIFFEntryOffsetAndLength));
4330 {
4332 tif, module,
4333 "Failed to allocate memory for counting IFD data size at reading");
4334 goto bad;
4335 }
4336 /*
4337 * Electronic Arts writes gray-scale TIFF files
4338 * without a PlanarConfiguration directory entry.
4339 * Thus we setup a default value here, even though
4340 * the TIFF spec says there is no default value.
4341 * After PlanarConfiguration is preset in TIFFDefaultDirectory()
4342 * the following setting is not needed, but does not harm either.
4343 */
4345 /*
4346 * Setup default value and then make a pass over
4347 * the fields to check type and tag information,
4348 * and to extract info required to size data
4349 * structures. A second pass is made afterwards
4350 * to read in everything not taken in the first pass.
4351 * But we must process the Compression tag first
4352 * in order to merge in codec-private tag definitions (otherwise
4353 * we may get complaints about unknown tags). However, the
4354 * Compression tag may be dependent on the SamplesPerPixel
4355 * tag value because older TIFF specs permitted Compression
4356 * to be written as a SamplesPerPixel-count tag entry.
4357 * Thus if we don't first figure out the correct SamplesPerPixel
4358 * tag value then we may end up ignoring the Compression tag
4359 * value because it has an incorrect count value (if the
4360 * true value of SamplesPerPixel is not 1).
4361 */
4362 dp =
4364 if (dp)
4365 {
4366 if (!TIFFFetchNormalTag(tif, dp, 0))
4367 goto bad;
4368 dp->tdir_ignore = TRUE;
4369 }
4371 if (dp)
4372 {
4373 /*
4374 * The 5.0 spec says the Compression tag has one value, while
4375 * earlier specs say it has one value per sample. Because of
4376 * this, we accept the tag if one value is supplied with either
4377 * count.
4378 */
4381 err = TIFFReadDirEntryShort(tif, dp, &value);
4385 {
4386 TIFFReadDirEntryOutputErr(tif, err, module, "Compression", 0);
4387 goto bad;
4388 }
4390 goto bad;
4391 dp->tdir_ignore = TRUE;
4392 }
4393 else
4394 {
4396 goto bad;
4397 }
4398 /*
4399 * First real pass over the directory.
4400 */
4401 for (di = 0, dp = dir; di < dircount; di++, dp++)
4402 {
4403 if (!dp->tdir_ignore)
4404 {
4406 if (fii == FAILED_FII)
4407 {
4409 {
4411 "Unknown field with tag %" PRIu16
4412 " (0x%" PRIx16 ") encountered",
4413 dp->tdir_tag, dp->tdir_tag);
4414 }
4415 /* the following knowingly leaks the
4416 anonymous field structure */
4417 const TIFFField *fld = _TIFFCreateAnonField(
4418 tif, dp->tdir_tag, (TIFFDataType)dp->tdir_type);
4419 if (fld == NULL || !_TIFFMergeFields(tif, fld, 1))
4420 {
4422 tif, module,
4423 "Registering anonymous field with tag %" PRIu16
4424 " (0x%" PRIx16 ") failed",
4425 dp->tdir_tag, dp->tdir_tag);
4426 dp->tdir_ignore = TRUE;
4427 }
4428 else
4429 {
4431 assert(fii != FAILED_FII);
4432 }
4433 }
4434 }
4435 if (!dp->tdir_ignore)
4436 {
4437 fip = tif->tif_fields[fii];
4438 if (fip->field_bit == FIELD_IGNORE)
4439 dp->tdir_ignore = TRUE;
4440 else
4441 {
4442 switch (dp->tdir_tag)
4443 {
4448 TIFFSetFieldBit(tif, fip->field_bit);
4449 break;
4450 case TIFFTAG_IMAGEWIDTH:
4452 case TIFFTAG_IMAGEDEPTH:
4453 case TIFFTAG_TILELENGTH:
4454 case TIFFTAG_TILEWIDTH:
4455 case TIFFTAG_TILEDEPTH:
4459 if (!TIFFFetchNormalTag(tif, dp, 0))
4460 goto bad;
4461 dp->tdir_ignore = TRUE;
4462 break;
4463 default:
4465 dp->tdir_ignore = TRUE;
4466 break;
4467 }
4468 }
4469 }
4470 }
4471 /*
4472 * XXX: OJPEG hack.
4473 * If a) compression is OJPEG, b) planarconfig tag says it's separate,
4474 * c) strip offsets/bytecounts tag are both present and
4475 * d) both contain exactly one value, then we consistently find
4476 * that the buggy implementation of the buggy compression scheme
4477 * matches contig planarconfig best. So we 'fix-up' the tag here
4478 */
4481 {
4482 if (!_TIFFFillStriles(tif))
4483 goto bad;
4484 dp = TIFFReadDirectoryFindEntry(tif, dir, dircount,
4486 if ((dp != 0) && (dp->tdir_count == 1))
4487 {
4488 dp = TIFFReadDirectoryFindEntry(tif, dir, dircount,
4490 if ((dp != 0) && (dp->tdir_count == 1))
4491 {
4494 "Planarconfig tag value assumed incorrect, "
4495 "assuming data is contig instead of chunky");
4496 }
4497 }
4498 }
4499 /*
4500 * Allocate directory structure and setup defaults.
4501 */
4503 {
4504 MissingRequired(tif, "ImageLength");
4505 goto bad;
4506 }
4507
4508 /*
4509 * Second pass: extract other information.
4510 */
4511 for (di = 0, dp = dir; di < dircount; di++, dp++)
4512 {
4513 if (!dp->tdir_ignore)
4514 {
4515 switch (dp->tdir_tag)
4516 {
4520 case TIFFTAG_DATATYPE:
4522 /*
4523 * The MinSampleValue, MaxSampleValue, BitsPerSample
4524 * DataType and SampleFormat tags are supposed to be
4525 * written as one value/sample, but some vendors
4526 * incorrectly write one value only -- so we accept
4527 * that as well (yuck). Other vendors write correct
4528 * value for NumberOfSamples, but incorrect one for
4529 * BitsPerSample and friends, and we will read this
4530 * too.
4531 */
4532 {
4535 err = TIFFReadDirEntryShort(tif, dp, &value);
4536 if (!EvaluateIFDdatasizeReading(tif, dp))
4537 goto bad;
4539 err =
4542 {
4543 fip = TIFFFieldWithTag(tif, dp->tdir_tag);
4545 tif, err, module,
4546 fip ? fip->field_name : "unknown tagname", 0);
4547 goto bad;
4548 }
4549 if (!TIFFSetField(tif, dp->tdir_tag, value))
4550 goto bad;
4552 bitspersample_read = TRUE;
4553 }
4554 break;
4557 {
4558
4559 double *data = NULL;
4561 uint32_t saved_flags;
4562 int m;
4563 if (dp->tdir_count !=
4566 else
4568 if (!EvaluateIFDdatasizeReading(tif, dp))
4569 goto bad;
4571 {
4572 fip = TIFFFieldWithTag(tif, dp->tdir_tag);
4574 tif, err, module,
4575 fip ? fip->field_name : "unknown tagname", 0);
4576 goto bad;
4577 }
4578 saved_flags = tif->tif_flags;
4579 tif->tif_flags |= TIFF_PERSAMPLE;
4580 m = TIFFSetField(tif, dp->tdir_tag, data);
4581 tif->tif_flags = saved_flags;
4582 _TIFFfreeExt(tif, data);
4583 if (!m)
4584 goto bad;
4585 }
4586 break;
4589 {
4590 switch (dp->tdir_type)
4591 {
4592 case TIFF_SHORT:
4593 case TIFF_LONG:
4594 case TIFF_LONG8:
4595 break;
4596 default:
4597 /* Warn except if directory typically created with
4598 * TIFFDeferStrileArrayWriting() */
4599 if (!(tif->tif_mode == O_RDWR &&
4600 dp->tdir_count == 0 && dp->tdir_type == 0 &&
4601 dp->tdir_offset.toff_long8 == 0))
4602 {
4603 fip = TIFFFieldWithTag(tif, dp->tdir_tag);
4605 tif, module, "Invalid data type for tag %s",
4606 fip ? fip->field_name : "unknown tagname");
4607 }
4608 break;
4609 }
4611 sizeof(TIFFDirEntry));
4612 if (!EvaluateIFDdatasizeReading(tif, dp))
4613 goto bad;
4614 }
4615 break;
4618 {
4619 switch (dp->tdir_type)
4620 {
4621 case TIFF_SHORT:
4622 case TIFF_LONG:
4623 case TIFF_LONG8:
4624 break;
4625 default:
4626 /* Warn except if directory typically created with
4627 * TIFFDeferStrileArrayWriting() */
4628 if (!(tif->tif_mode == O_RDWR &&
4629 dp->tdir_count == 0 && dp->tdir_type == 0 &&
4630 dp->tdir_offset.toff_long8 == 0))
4631 {
4632 fip = TIFFFieldWithTag(tif, dp->tdir_tag);
4634 tif, module, "Invalid data type for tag %s",
4635 fip ? fip->field_name : "unknown tagname");
4636 }
4637 break;
4638 }
4640 sizeof(TIFFDirEntry));
4641 if (!EvaluateIFDdatasizeReading(tif, dp))
4642 goto bad;
4643 }
4644 break;
4645 case TIFFTAG_COLORMAP:
4647 {
4649 uint32_t countpersample;
4650 uint32_t countrequired;
4651 uint32_t incrementpersample;
4652 uint16_t *value = NULL;
4653 /* It would be dangerous to instantiate those tag values */
4654 /* since if td_bitspersample has not yet been read (due to
4655 */
4656 /* unordered tags), it could be read afterwards with a */
4657 /* values greater than the default one (1), which may cause
4658 */
4659 /* crashes in user code */
4660 if (!bitspersample_read)
4661 {
4662 fip = TIFFFieldWithTag(tif, dp->tdir_tag);
4664 tif, module,
4665 "Ignoring %s since BitsPerSample tag not found",
4666 fip ? fip->field_name : "unknown tagname");
4667 continue;
4668 }
4669 /* ColorMap or TransferFunction for high bit */
4670 /* depths do not make much sense and could be */
4671 /* used as a denial of service vector */
4672 if (tif->tif_dir.td_bitspersample > 24)
4673 {
4674 fip = TIFFFieldWithTag(tif, dp->tdir_tag);
4676 tif, module,
4677 "Ignoring %s because BitsPerSample=%" PRIu16 ">24",
4678 fip ? fip->field_name : "unknown tagname",
4680 continue;
4681 }
4682 countpersample = (1U << tif->tif_dir.td_bitspersample);
4683 if ((dp->tdir_tag == TIFFTAG_TRANSFERFUNCTION) &&
4684 (dp->tdir_count == (uint64_t)countpersample))
4685 {
4686 countrequired = countpersample;
4687 incrementpersample = 0;
4688 }
4689 else
4690 {
4691 countrequired = 3 * countpersample;
4692 incrementpersample = countpersample;
4693 }
4694 if (dp->tdir_count != (uint64_t)countrequired)
4696 else
4698 if (!EvaluateIFDdatasizeReading(tif, dp))
4699 goto bad;
4701 {
4702 fip = TIFFFieldWithTag(tif, dp->tdir_tag);
4704 tif, err, module,
4705 fip ? fip->field_name : "unknown tagname", 1);
4706 }
4707 else
4708 {
4709 TIFFSetField(tif, dp->tdir_tag, value,
4710 value + incrementpersample,
4711 value + 2 * incrementpersample);
4712 _TIFFfreeExt(tif, value);
4713 }
4714 }
4715 break;
4716 /* BEGIN REV 4.0 COMPATIBILITY */
4718 {
4719 uint16_t valueo;
4721 if (TIFFReadDirEntryShort(tif, dp, &valueo) ==
4723 {
4724 switch (valueo)
4725 {
4728 break;
4729 case OFILETYPE_PAGE:
4731 break;
4732 default:
4733 value = 0;
4734 break;
4735 }
4736 if (value != 0)
4738 }
4739 }
4740 break;
4741 /* END REV 4.0 COMPATIBILITY */
4742#if 0
4744 /* TIFFTAG_EP_BATTERYLEVEL can be RATIONAL or ASCII.
4745 * LibTiff defines it as ASCII and converts RATIONAL to an
4746 * ASCII string. */
4747 switch (dp->tdir_type)
4748 {
4749 case TIFF_RATIONAL:
4750 {
4751 /* Read rational and convert to ASCII*/
4753 TIFFRational_t rValue;
4754 err = TIFFReadDirEntryCheckedRationalDirect(
4755 tif, dp, &rValue);
4757 {
4758 fip = TIFFFieldWithTag(tif, dp->tdir_tag);
4760 tif, err, module,
4761 fip ? fip->field_name : "unknown tagname",
4762 1);
4763 }
4764 else
4765 {
4766 char szAux[32];
4767 snprintf(szAux, sizeof(szAux) - 1, "%d/%d",
4768 rValue.uNum, rValue.uDenom);
4769 TIFFSetField(tif, dp->tdir_tag, szAux);
4770 }
4771 }
4772 break;
4773 case TIFF_ASCII:
4774 (void)TIFFFetchNormalTag(tif, dp, TRUE);
4775 break;
4776 default:
4777 fip = TIFFFieldWithTag(tif, dp->tdir_tag);
4779 "Invalid data type for tag %s. "
4780 "ASCII or RATIONAL expected",
4781 fip ? fip->field_name
4782 : "unknown tagname");
4783 break;
4784 }
4785 break;
4786#endif
4787 default:
4788 (void)TIFFFetchNormalTag(tif, dp, TRUE);
4789 break;
4790 } /* -- switch (dp->tdir_tag) -- */
4791 } /* -- if (!dp->tdir_ignore) */
4792 } /* -- for-loop -- */
4793
4794 /* Evaluate final IFD data size. */
4795 CalcFinalIFDdatasizeReading(tif, dircount);
4796
4797 /*
4798 * OJPEG hack:
4799 * - If a) compression is OJPEG, and b) photometric tag is missing,
4800 * then we consistently find that photometric should be YCbCr
4801 * - If a) compression is OJPEG, and b) photometric tag says it's RGB,
4802 * then we consistently find that the buggy implementation of the
4803 * buggy compression scheme matches photometric YCbCr instead.
4804 * - If a) compression is OJPEG, and b) bitspersample tag is missing,
4805 * then we consistently find bitspersample should be 8.
4806 * - If a) compression is OJPEG, b) samplesperpixel tag is missing,
4807 * and c) photometric is RGB or YCbCr, then we consistently find
4808 * samplesperpixel should be 3
4809 * - If a) compression is OJPEG, b) samplesperpixel tag is missing,
4810 * and c) photometric is MINISWHITE or MINISBLACK, then we consistently
4811 * find samplesperpixel should be 3
4812 */
4814 {
4816 {
4818 tif, module,
4819 "Photometric tag is missing, assuming data is YCbCr");
4821 goto bad;
4822 }
4823 else if (tif->tif_dir.td_photometric == PHOTOMETRIC_RGB)
4824 {
4827 "Photometric tag value assumed incorrect, "
4828 "assuming data is YCbCr instead of RGB");
4829 }
4831 {
4833 tif, module,
4834 "BitsPerSample tag is missing, assuming 8 bits per sample");
4835 if (!TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8))
4836 goto bad;
4837 }
4839 {
4841 {
4843 "SamplesPerPixel tag is missing, "
4844 "assuming correct SamplesPerPixel value is 3");
4846 goto bad;
4847 }
4849 {
4851 "SamplesPerPixel tag is missing, "
4852 "applying correct SamplesPerPixel value of 3");
4854 goto bad;
4855 }
4856 else if ((tif->tif_dir.td_photometric == PHOTOMETRIC_MINISWHITE) ||
4858 {
4859 /*
4860 * SamplesPerPixel tag is missing, but is not required
4861 * by spec. Assume correct SamplesPerPixel value of 1.
4862 */
4864 goto bad;
4865 }
4866 }
4867 }
4868
4869 /*
4870 * Setup appropriate structures (by strip or by tile)
4871 * We do that only after the above OJPEG hack which alters SamplesPerPixel
4872 * and thus influences the number of strips in the separate planarconfig.
4873 */
4875 {
4880 tif->tif_flags &= ~TIFF_ISTILED;
4881 }
4882 else
4883 {
4885 tif->tif_flags |= TIFF_ISTILED;
4886 }
4887 if (!tif->tif_dir.td_nstrips)
4888 {
4889 TIFFErrorExtR(tif, module, "Cannot handle zero number of %s",
4890 isTiled(tif) ? "tiles" : "strips");
4891 goto bad;
4892 }
4897 {
4898#ifdef OJPEG_SUPPORT
4900 (isTiled(tif) == 0) && (tif->tif_dir.td_nstrips == 1))
4901 {
4902 /*
4903 * XXX: OJPEG hack.
4904 * If a) compression is OJPEG, b) it's not a tiled TIFF,
4905 * and c) the number of strips is 1,
4906 * then we tolerate the absence of stripoffsets tag,
4907 * because, presumably, all required data is in the
4908 * JpegInterchangeFormat stream.
4909 */
4911 }
4912 else
4913#endif
4914 {
4915 MissingRequired(tif, isTiled(tif) ? "TileOffsets" : "StripOffsets");
4916 goto bad;
4917 }
4918 }
4919
4920 if (tif->tif_mode == O_RDWR &&
4929 {
4930 /* Directory typically created with TIFFDeferStrileArrayWriting() */
4931 TIFFSetupStrips(tif);
4932 }
4933 else if (!(tif->tif_flags & TIFF_DEFERSTRILELOAD))
4934 {
4936 {
4938 tif->tif_dir.td_nstrips,
4940 {
4941 goto bad;
4942 }
4943 }
4945 {
4947 tif, &(tif->tif_dir.td_stripbytecount_entry),
4949 {
4950 goto bad;
4951 }
4952 }
4953 }
4954
4955 /*
4956 * Make sure all non-color channels are extrasamples.
4957 * If it's not the case, define them as such.
4958 */
4959 color_channels = _TIFFGetMaxColorChannels(tif->tif_dir.td_photometric);
4960 if (color_channels &&
4962 color_channels)
4963 {
4964 uint16_t old_extrasamples;
4965 uint16_t *new_sampleinfo;
4966
4968 tif, module,
4969 "Sum of Photometric type-related "
4970 "color channels and ExtraSamples doesn't match SamplesPerPixel. "
4971 "Defining non-color channels as ExtraSamples.");
4972
4973 old_extrasamples = tif->tif_dir.td_extrasamples;
4975 (uint16_t)(tif->tif_dir.td_samplesperpixel - color_channels);
4976
4977 // sampleinfo should contain information relative to these new extra
4978 // samples
4979 new_sampleinfo = (uint16_t *)_TIFFcallocExt(
4980 tif, tif->tif_dir.td_extrasamples, sizeof(uint16_t));
4981 if (!new_sampleinfo)
4982 {
4983 TIFFErrorExtR(tif, module,
4984 "Failed to allocate memory for "
4985 "temporary new sampleinfo array "
4986 "(%" PRIu16 " 16 bit elements)",
4988 goto bad;
4989 }
4990
4991 if (old_extrasamples > 0)
4992 memcpy(new_sampleinfo, tif->tif_dir.td_sampleinfo,
4993 old_extrasamples * sizeof(uint16_t));
4994 _TIFFsetShortArrayExt(tif, &tif->tif_dir.td_sampleinfo, new_sampleinfo,
4996 _TIFFfreeExt(tif, new_sampleinfo);
4997 }
4998
4999 /*
5000 * Verify Palette image has a Colormap.
5001 */
5004 {
5005 if (tif->tif_dir.td_bitspersample >= 8 &&
5006 tif->tif_dir.td_samplesperpixel == 3)
5008 else if (tif->tif_dir.td_bitspersample >= 8)
5010 else
5011 {
5012 MissingRequired(tif, "Colormap");
5013 goto bad;
5014 }
5015 }
5016 /*
5017 * OJPEG hack:
5018 * We do no further messing with strip/tile offsets/bytecounts in OJPEG
5019 * TIFFs
5020 */
5022 {
5023 /*
5024 * Attempt to deal with a missing StripByteCounts tag.
5025 */
5027 {
5028 /*
5029 * Some manufacturers violate the spec by not giving
5030 * the size of the strips. In this case, assume there
5031 * is one uncompressed strip of data.
5032 */
5034 tif->tif_dir.td_nstrips > 1) ||
5036 tif->tif_dir.td_nstrips !=
5038 {
5039 MissingRequired(tif, "StripByteCounts");
5040 goto bad;
5041 }
5043 tif, module,
5044 "TIFF directory is missing required "
5045 "\"StripByteCounts\" field, calculating from imagelength");
5046 if (EstimateStripByteCounts(tif, dir, dircount) < 0)
5047 goto bad;
5048 }
5049 else if (tif->tif_dir.td_nstrips == 1 &&
5050 !(tif->tif_flags & TIFF_ISTILED) && ByteCountLooksBad(tif))
5051 {
5052 /*
5053 * XXX: Plexus (and others) sometimes give a value of
5054 * zero for a tag when they don't know what the
5055 * correct value is! Try and handle the simple case
5056 * of estimating the size of a one strip image.
5057 */
5059 "Bogus \"StripByteCounts\" field, ignoring and "
5060 "calculating from imagelength");
5061 if (EstimateStripByteCounts(tif, dir, dircount) < 0)
5062 goto bad;
5063 }
5064 else if (!(tif->tif_flags & TIFF_DEFERSTRILELOAD) &&
5066 tif->tif_dir.td_nstrips > 2 &&
5068 TIFFGetStrileByteCount(tif, 0) !=
5069 TIFFGetStrileByteCount(tif, 1) &&
5070 TIFFGetStrileByteCount(tif, 0) != 0 &&
5071 TIFFGetStrileByteCount(tif, 1) != 0)
5072 {
5073 /*
5074 * XXX: Some vendors fill StripByteCount array with
5075 * absolutely wrong values (it can be equal to
5076 * StripOffset array, for example). Catch this case
5077 * here.
5078 *
5079 * We avoid this check if deferring strile loading
5080 * as it would always force us to load the strip/tile
5081 * information.
5082 */
5084 "Wrong \"StripByteCounts\" field, ignoring and "
5085 "calculating from imagelength");
5086 if (EstimateStripByteCounts(tif, dir, dircount) < 0)
5087 goto bad;
5088 }
5089 }
5090 if (dir)
5091 {
5092 _TIFFfreeExt(tif, dir);
5093 dir = NULL;
5094 }
5096 {
5097 if (tif->tif_dir.td_bitspersample >= 16)
5098 tif->tif_dir.td_maxsamplevalue = 0xFFFF;
5099 else
5101 (uint16_t)((1L << tif->tif_dir.td_bitspersample) - 1);
5102 }
5103
5104#ifdef STRIPBYTECOUNTSORTED_UNUSED
5105 /*
5106 * XXX: We can optimize checking for the strip bounds using the sorted
5107 * bytecounts array. See also comments for TIFFAppendToStrip()
5108 * function in tif_write.c.
5109 */
5110 if (!(tif->tif_flags & TIFF_DEFERSTRILELOAD) && tif->tif_dir.td_nstrips > 1)
5111 {
5112 uint32_t strip;
5113
5114 tif->tif_dir.td_stripbytecountsorted = 1;
5115 for (strip = 1; strip < tif->tif_dir.td_nstrips; strip++)
5116 {
5117 if (TIFFGetStrileOffset(tif, strip - 1) >
5118 TIFFGetStrileOffset(tif, strip))
5119 {
5120 tif->tif_dir.td_stripbytecountsorted = 0;
5121 break;
5122 }
5123 }
5124 }
5125#endif
5126
5127 /*
5128 * An opportunity for compression mode dependent tag fixup
5129 */
5130 (*tif->tif_fixuptags)(tif);
5131
5132 /*
5133 * Some manufacturers make life difficult by writing
5134 * large amounts of uncompressed data as a single strip.
5135 * This is contrary to the recommendations of the spec.
5136 * The following makes an attempt at breaking such images
5137 * into strips closer to the recommended 8k bytes. A
5138 * side effect, however, is that the RowsPerStrip tag
5139 * value may be changed.
5140 */
5142 (tif->tif_dir.td_nstrips == 1) &&
5145 {
5147 }
5148
5149 /* There are also uncompressed striped files with strips larger than */
5150 /* 2 GB, which make them unfriendly with a lot of code. If possible, */
5151 /* try to expose smaller "virtual" strips. */
5155 TIFFStripSize64(tif) > 0x7FFFFFFFUL)
5156 {
5158 }
5159
5160 /*
5161 * Clear the dirty directory flag.
5162 */
5163 tif->tif_flags &= ~TIFF_DIRTYDIRECT;
5164 tif->tif_flags &= ~TIFF_DIRTYSTRIP;
5165
5166 /*
5167 * Reinitialize i/o since we are starting on a new directory.
5168 */
5169 tif->tif_row = (uint32_t)-1;
5170 tif->tif_curstrip = (uint32_t)-1;
5171 tif->tif_col = (uint32_t)-1;
5172 tif->tif_curtile = (uint32_t)-1;
5173 tif->tif_tilesize = (tmsize_t)-1;
5174
5176 if (!tif->tif_scanlinesize)
5177 {
5178 TIFFErrorExtR(tif, module, "Cannot handle zero scanline size");
5179 return (0);
5180 }
5181
5182 if (isTiled(tif))
5183 {
5184 tif->tif_tilesize = TIFFTileSize(tif);
5185 if (!tif->tif_tilesize)
5186 {
5187 TIFFErrorExtR(tif, module, "Cannot handle zero tile size");
5188 return (0);
5189 }
5190 }
5191 else
5192 {
5193 if (!TIFFStripSize(tif))
5194 {
5195 TIFFErrorExtR(tif, module, "Cannot handle zero strip size");
5196 return (0);
5197 }
5198 }
5199 return (1);
5200bad:
5201 if (dir)
5202 _TIFFfreeExt(tif, dir);
5203 return (0);
5204} /*-- TIFFReadDirectory() --*/
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define uint16_t
Definition: nsiface.idl:60
#define err(...)
uint32_t uDenom
Definition: tiffio.h:280
uint32_t uNum
Definition: tiffio.h:279
uint32_t tif_col
Definition: tiffiop.h:193
tmsize_t tif_scanlinesize
Definition: tiffiop.h:218
TIFFBoolMethod tif_fixuptags
Definition: tiffiop.h:198
tmsize_t tif_tilesize
Definition: tiffiop.h:195
int TIFFSetField(TIFF *tif, uint32_t tag,...)
Definition: tif_dir.c:1146
void _TIFFsetShortArrayExt(TIFF *tif, uint16_t **wpp, const uint16_t *wp, uint32_t n)
Definition: tif_dir.c:78
#define FIELD_STRIPBYTECOUNTS
Definition: tif_dir.h:201
#define TIFFSetFieldBit(tif, field)
Definition: tif_dir.h:237
int _TIFFCheckFieldIsValidForCodec(TIFF *tif, ttag_t tag)
Definition: tif_dirinfo.c:1247
static void MissingRequired(TIFF *, const char *)
Definition: tif_dirread.c:5613
int _TIFFCheckDirNumberAndOffset(TIFF *tif, tdir_t dirn, uint64_t diroff)
Definition: tif_dirread.c:5665
static enum TIFFReadDirEntryErr TIFFReadDirEntryShort(TIFF *tif, TIFFDirEntry *direntry, uint16_t *value)
Definition: tif_dirread.c:485
static void TryChopUpUncompressedBigTiff(TIFF *)
Definition: tif_dirread.c:7937
static int ByteCountLooksBad(TIFF *tif)
Definition: tif_dirread.c:4041
static enum TIFFReadDirEntryErr TIFFReadDirEntryDoubleArray(TIFF *tif, TIFFDirEntry *direntry, double **value)
Definition: tif_dirread.c:2988
static void TIFFReadDirEntryOutputErr(TIFF *tif, enum TIFFReadDirEntryErr err, const char *module, const char *tagname, int recover)
Definition: tif_dirread.c:3919
static TIFFDirEntry * TIFFReadDirectoryFindEntry(TIFF *tif, TIFFDirEntry *dir, uint16_t dircount, uint16_t tagid)
Definition: tif_dirread.c:5227
static void ChopUpSingleUncompressedStrip(TIFF *)
Definition: tif_dirread.c:7867
TIFFReadDirEntryErr
Definition: tif_dirread.c:58
@ TIFFReadDirEntryErrCount
Definition: tif_dirread.c:60
@ TIFFReadDirEntryErrOk
Definition: tif_dirread.c:59
static bool EvaluateIFDdatasizeReading(TIFF *tif, TIFFDirEntry *dp)
Definition: tif_dirread.c:4087
int _TIFFFillStriles(TIFF *tif)
Definition: tif_dirread.c:8381
static enum TIFFReadDirEntryErr TIFFReadDirEntryShortArray(TIFF *tif, TIFFDirEntry *direntry, uint16_t **value)
Definition: tif_dirread.c:1752
static int EstimateStripByteCounts(TIFF *tif, TIFFDirEntry *dir, uint16_t dircount)
Definition: tif_dirread.c:5475
static int _TIFFGetMaxColorChannels(uint16_t photometric)
Definition: tif_dirread.c:4016
static int TIFFFetchStripThing(TIFF *tif, TIFFDirEntry *dir, uint32_t nstrips, uint64_t **lpp)
Definition: tif_dirread.c:7643
static enum TIFFReadDirEntryErr TIFFReadDirEntryPersampleShort(TIFF *tif, TIFFDirEntry *direntry, uint16_t *value)
Definition: tif_dirread.c:3279
tmsize_t TIFFStripSize(TIFF *tif)
Definition: tif_strip.c:204
tmsize_t TIFFScanlineSize(TIFF *tif)
Definition: tif_strip.c:343
uint32_t TIFFNumberOfStrips(TIFF *tif)
Definition: tif_strip.c:65
uint64_t TIFFStripSize64(TIFF *tif)
Definition: tif_strip.c:196
tmsize_t TIFFTileSize(TIFF *tif)
Definition: tif_tile.c:253
uint32_t TIFFNumberOfTiles(TIFF *tif)
Definition: tif_tile.c:108
#define COMPRESSION_NONE
Definition: tiff.h:182
#define TIFFTAG_BITSPERSAMPLE
Definition: tiff.h:180
#define OFILETYPE_REDUCEDIMAGE
Definition: tiff.h:176
#define OFILETYPE_PAGE
Definition: tiff.h:177
#define COMPRESSION_OJPEG
Definition: tiff.h:189
#define TIFFTAG_SAMPLESPERPIXEL
Definition: tiff.h:257
#define TIFFTAG_DATATYPE
Definition: tiff.h:406
#define TIFFTAG_COLORMAP
Definition: tiff.h:309
#define TIFFTAG_IMAGEDEPTH
Definition: tiff.h:407
#define TIFFTAG_PHOTOMETRIC
Definition: tiff.h:220
#define TIFFTAG_TILELENGTH
Definition: tiff.h:312
#define TIFFTAG_OSUBFILETYPE
Definition: tiff.h:174
#define TIFFTAG_MAXSAMPLEVALUE
Definition: tiff.h:261
#define TIFFTAG_TILEDEPTH
Definition: tiff.h:408
#define PHOTOMETRIC_PALETTE
Definition: tiff.h:224
#define TIFFTAG_EXTRASAMPLES
Definition: tiff.h:329
#define TIFFTAG_IMAGEWIDTH
Definition: tiff.h:178
#define TIFFTAG_MINSAMPLEVALUE
Definition: tiff.h:260
#define PHOTOMETRIC_YCBCR
Definition: tiff.h:227
#define TIFFTAG_TRANSFERFUNCTION
Definition: tiff.h:298
#define PHOTOMETRIC_MINISWHITE
Definition: tiff.h:221
#define TIFFTAG_SMINSAMPLEVALUE
Definition: tiff.h:340
#define TIFFTAG_ROWSPERSTRIP
Definition: tiff.h:258
#define TIFFTAG_SMAXSAMPLEVALUE
Definition: tiff.h:341
#define TIFFTAG_SAMPLEFORMAT
Definition: tiff.h:333
#define TIFFTAG_TILEWIDTH
Definition: tiff.h:311
#define TIFFTAG_IMAGELENGTH
Definition: tiff.h:179
#define TIFFTAG_COMPRESSION
Definition: tiff.h:181
#define PHOTOMETRIC_MINISBLACK
Definition: tiff.h:222
#define PHOTOMETRIC_RGB
Definition: tiff.h:223
#define TIFFTAG_PLANARCONFIG
Definition: tiff.h:264
#define TIFFTAG_SUBFILETYPE
Definition: tiff.h:170
#define TIFFTAG_EP_BATTERYLEVEL
Definition: tiff.h:630
#define TIFF_ISTILED
Definition: tiffiop.h:127
Definition: pdh_main.c:96
#define snprintf
Definition: wintirpc.h:48

Referenced by TIFFClientOpenExt(), TIFFSetDirectory(), and TIFFSetSubDirectory().

◆ TIFFReadEncodedStrip()

tmsize_t TIFFReadEncodedStrip ( TIFF tif,
uint32_t  strip,
void buf,
tmsize_t  size 
)

Definition at line 534 of file tif_read.c.

536{
537 static const char module[] = "TIFFReadEncodedStrip";
538 TIFFDirectory *td = &tif->tif_dir;
539 tmsize_t stripsize;
541
542 stripsize = TIFFReadEncodedStripGetStripSize(tif, strip, &plane);
543 if (stripsize == ((tmsize_t)(-1)))
544 return ((tmsize_t)(-1));
545
546 /* shortcut to avoid an extra memcpy() */
547 if (td->td_compression == COMPRESSION_NONE && size != (tmsize_t)(-1) &&
548 size >= stripsize && !isMapped(tif) &&
549 ((tif->tif_flags & TIFF_NOREADRAW) == 0))
550 {
551 if (TIFFReadRawStrip1(tif, strip, buf, stripsize, module) != stripsize)
552 return ((tmsize_t)(-1));
553
554 if (!isFillOrder(tif, td->td_fillorder) &&
555 (tif->tif_flags & TIFF_NOBITREV) == 0)
556 TIFFReverseBits(buf, stripsize);
557
558 (*tif->tif_postdecode)(tif, buf, stripsize);
559 return (stripsize);
560 }
561
562 if ((size != (tmsize_t)(-1)) && (size < stripsize))
563 stripsize = size;
564 if (!TIFFFillStrip(tif, strip))
565 {
566 /* The output buf may be NULL, in particular if TIFFTAG_FAXFILLFUNC
567 is being used. Thus, memset must be conditional on buf not NULL. */
568 if (buf)
569 memset(buf, 0, (size_t)stripsize);
570 return ((tmsize_t)(-1));
571 }
572 if ((*tif->tif_decodestrip)(tif, buf, stripsize, plane) <= 0)
573 return ((tmsize_t)(-1));
574 (*tif->tif_postdecode)(tif, buf, stripsize);
575 return (stripsize);
576}
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint GLenum GLenum GLenum GLint GLuint GLenum GLenum GLfloat GLenum GLfloat GLenum GLint const GLfloat GLenum GLint const GLushort GLint GLint GLsizei GLsizei GLenum GLsizei GLsizei GLenum GLenum const GLvoid GLenum plane
Definition: glfuncs.h:270
TIFFCodeMethod tif_decodestrip
Definition: tiffiop.h:207
TIFFPostMethod tif_postdecode
Definition: tiffiop.h:239
static tmsize_t TIFFReadRawStrip1(TIFF *tif, uint32_t strip, void *buf, tmsize_t size, const char *module)
Definition: tif_read.c:620
static tmsize_t TIFFReadEncodedStripGetStripSize(TIFF *tif, uint32_t strip, uint16_t *pplane)
Definition: tif_read.c:488
int TIFFFillStrip(TIFF *tif, uint32_t strip)
Definition: tif_read.c:759
void TIFFReverseBits(uint8_t *cp, tmsize_t n)
Definition: tif_swab.c:310
#define TIFF_NOBITREV
Definition: tiffiop.h:125

Referenced by _TIFFReadEncodedStripAndAllocBuffer(), gtStripSeparate(), and tiff_decoder_read_tile().

◆ TIFFReadEncodedTile()

tmsize_t TIFFReadEncodedTile ( TIFF tif,
uint32_t  tile,
void buf,
tmsize_t  size 
)

Definition at line 953 of file tif_read.c.

954{
955 static const char module[] = "TIFFReadEncodedTile";
956 TIFFDirectory *td = &tif->tif_dir;
957 tmsize_t tilesize = tif->tif_tilesize;
958
959 if (!TIFFCheckRead(tif, 1))
960 return ((tmsize_t)(-1));
961 if (tile >= td->td_nstrips)
962 {
964 "%" PRIu32 ": Tile out of range, max %" PRIu32, tile,
965 td->td_nstrips);
966 return ((tmsize_t)(-1));
967 }
968
969 /* shortcut to avoid an extra memcpy() */
970 if (td->td_compression == COMPRESSION_NONE && size != (tmsize_t)(-1) &&
971 size >= tilesize && !isMapped(tif) &&
972 ((tif->tif_flags & TIFF_NOREADRAW) == 0))
973 {
974 if (TIFFReadRawTile1(tif, tile, buf, tilesize, module) != tilesize)
975 return ((tmsize_t)(-1));
976
977 if (!isFillOrder(tif, td->td_fillorder) &&
978 (tif->tif_flags & TIFF_NOBITREV) == 0)
979 TIFFReverseBits(buf, tilesize);
980
981 (*tif->tif_postdecode)(tif, buf, tilesize);
982 return (tilesize);
983 }
984
985 if (size == (tmsize_t)(-1))
986 size = tilesize;
987 else if (size > tilesize)
988 size = tilesize;
989 if (!TIFFFillTile(tif, tile))
990 {
991 /* See TIFFReadEncodedStrip comment regarding TIFFTAG_FAXFILLFUNC. */
992 if (buf)
993 memset(buf, 0, (size_t)size);
994 return ((tmsize_t)(-1));
995 }
996 else if ((*tif->tif_decodetile)(tif, (uint8_t *)buf, size,
997 (uint16_t)(tile / td->td_stripsperimage)))
998 {
999 (*tif->tif_postdecode)(tif, (uint8_t *)buf, size);
1000 return (size);
1001 }
1002 else
1003 return ((tmsize_t)(-1));
1004}
TIFFCodeMethod tif_decodetile
Definition: tiffiop.h:209
static int TIFFCheckRead(TIFF *, int)
Definition: tif_read.c:1519
int TIFFFillTile(TIFF *tif, uint32_t tile)
Definition: tif_read.c:1215
static tmsize_t TIFFReadRawTile1(TIFF *tif, uint32_t tile, void *buf, tmsize_t size, const char *module)
Definition: tif_read.c:1119

Referenced by _TIFFReadEncodedTileAndAllocBuffer(), tiff_decoder_read_tile(), and TIFFReadTile().

◆ TIFFReadEXIFDirectory()

int TIFFReadEXIFDirectory ( TIFF tif,
toff_t  diroff 
)

Definition at line 5462 of file tif_dirread.c.

5463{
5464 return TIFFReadCustomDirectory(tif, diroff, _TIFFGetExifFields());
5465}
int TIFFReadCustomDirectory(TIFF *tif, toff_t diroff, const TIFFFieldArray *infoarray)
Definition: tif_dirread.c:5278

◆ TIFFReadFromUserBuffer()

int TIFFReadFromUserBuffer ( TIFF tif,
uint32_t  strile,
void inbuf,
tmsize_t  insize,
void outbuf,
tmsize_t  outsize 
)

Definition at line 1545 of file tif_read.c.

1547{
1548 static const char module[] = "TIFFReadFromUserBuffer";
1549 TIFFDirectory *td = &tif->tif_dir;
1550 int ret = 1;
1551 uint32_t old_tif_flags = tif->tif_flags;
1552 tmsize_t old_rawdatasize = tif->tif_rawdatasize;
1553 void *old_rawdata = tif->tif_rawdata;
1554
1555 if (tif->tif_mode == O_WRONLY)
1556 {
1557 TIFFErrorExtR(tif, tif->tif_name, "File not open for reading");
1558 return 0;
1559 }
1560 if (tif->tif_flags & TIFF_NOREADRAW)
1561 {
1562 TIFFErrorExtR(tif, module,
1563 "Compression scheme does not support access to raw "
1564 "uncompressed data");
1565 return 0;
1566 }
1567
1568 tif->tif_flags &= ~TIFF_MYBUFFER;
1569 tif->tif_flags |= TIFF_BUFFERMMAP;
1570 tif->tif_rawdatasize = insize;
1571 tif->tif_rawdata = inbuf;
1572 tif->tif_rawdataoff = 0;
1574
1575 if (!isFillOrder(tif, td->td_fillorder) &&
1576 (tif->tif_flags & TIFF_NOBITREV) == 0)
1577 {
1579 }
1580
1581 if (TIFFIsTiled(tif))
1582 {
1583 if (!TIFFStartTile(tif, strile))
1584 {
1585 ret = 0;
1586 /* See related TIFFReadEncodedStrip comment. */
1587 if (outbuf)
1588 memset(outbuf, 0, (size_t)outsize);
1589 }
1590 else if (!(*tif->tif_decodetile)(
1591 tif, (uint8_t *)outbuf, outsize,
1592 (uint16_t)(strile / td->td_stripsperimage)))
1593 {
1594 ret = 0;
1595 }
1596 }
1597 else
1598 {
1599 uint32_t rowsperstrip = td->td_rowsperstrip;
1600 uint32_t stripsperplane;
1601 if (rowsperstrip > td->td_imagelength)
1602 rowsperstrip = td->td_imagelength;
1603 if (rowsperstrip == 0)
1604 {
1605 TIFFErrorExtR(tif, module, "rowsperstrip is zero");
1606 ret = 0;
1607 }
1608 else
1609 {
1610 stripsperplane =
1612 if (!TIFFStartStrip(tif, strile))
1613 {
1614 ret = 0;
1615 /* See related TIFFReadEncodedStrip comment. */
1616 if (outbuf)
1617 memset(outbuf, 0, (size_t)outsize);
1618 }
1619 else if (!(*tif->tif_decodestrip)(
1620 tif, (uint8_t *)outbuf, outsize,
1621 (uint16_t)(strile / stripsperplane)))
1622 {
1623 ret = 0;
1624 }
1625 }
1626 }
1627 if (ret)
1628 {
1629 (*tif->tif_postdecode)(tif, (uint8_t *)outbuf, outsize);
1630 }
1631
1632 if (!isFillOrder(tif, td->td_fillorder) &&
1633 (tif->tif_flags & TIFF_NOBITREV) == 0)
1634 {
1636 }
1637
1638 tif->tif_flags = (old_tif_flags & (TIFF_MYBUFFER | TIFF_BUFFERMMAP)) |
1640 tif->tif_rawdatasize = old_rawdatasize;
1641 tif->tif_rawdata = old_rawdata;
1642 tif->tif_rawdataoff = 0;
1643 tif->tif_rawdataloaded = 0;
1644
1645 return ret;
1646}
static int inbuf
Definition: adnsresfilter.c:73
#define O_WRONLY
Definition: fcntl.h:35
const unsigned char size_t insize
Definition: jpeglib.h:986
unsigned char size_t * outsize
Definition: jpeglib.h:983
static int TIFFStartStrip(TIFF *tif, uint32_t strip)
Definition: tif_read.c:1424
static int TIFFStartTile(TIFF *tif, uint32_t tile)
Definition: tif_read.c:1469
#define TIFFhowmany_32_maxuint_compat(x, y)
Definition: tiffiop.h:311
#define TIFF_BUFFERMMAP
Definition: tiffiop.h:142

◆ TIFFReadGPSDirectory()

int TIFFReadGPSDirectory ( TIFF tif,
toff_t  diroff 
)

Definition at line 5470 of file tif_dirread.c.

5471{
5472 return TIFFReadCustomDirectory(tif, diroff, _TIFFGetGpsFields());
5473}

◆ TIFFReadRawStrip()

tmsize_t TIFFReadRawStrip ( TIFF tif,
uint32_t  strip,
void buf,
tmsize_t  size 
)

Definition at line 717 of file tif_read.c.

718{
719 static const char module[] = "TIFFReadRawStrip";
720 TIFFDirectory *td = &tif->tif_dir;
721 uint64_t bytecount64;
722 tmsize_t bytecountm;
723
724 if (!TIFFCheckRead(tif, 0))
725 return ((tmsize_t)(-1));
726 if (strip >= td->td_nstrips)
727 {
729 "%" PRIu32 ": Strip out of range, max %" PRIu32, strip,
730 td->td_nstrips);
731 return ((tmsize_t)(-1));
732 }
733 if (tif->tif_flags & TIFF_NOREADRAW)
734 {
736 "Compression scheme does not support access to raw "
737 "uncompressed data");
738 return ((tmsize_t)(-1));
739 }
740 bytecount64 = TIFFGetStrileByteCount(tif, strip);
741 if (size != (tmsize_t)(-1) && (uint64_t)size <= bytecount64)
742 bytecountm = size;
743 else
744 bytecountm = _TIFFCastUInt64ToSSize(tif, bytecount64, module);
745 if (bytecountm == 0)
746 {
747 return ((tmsize_t)(-1));
748 }
749 return (TIFFReadRawStrip1(tif, strip, buf, bytecountm, module));
750}

◆ TIFFReadRawTile()

tmsize_t TIFFReadRawTile ( TIFF tif,
uint32_t  tile,
void buf,
tmsize_t  size 
)

Definition at line 1176 of file tif_read.c.

1177{
1178 static const char module[] = "TIFFReadRawTile";
1179 TIFFDirectory *td = &tif->tif_dir;
1180 uint64_t bytecount64;
1181 tmsize_t bytecountm;
1182
1183 if (!TIFFCheckRead(tif, 1))
1184 return ((tmsize_t)(-1));
1185 if (tile >= td->td_nstrips)
1186 {
1187 TIFFErrorExtR(tif, module,
1188 "%" PRIu32 ": Tile out of range, max %" PRIu32, tile,
1189 td->td_nstrips);
1190 return ((tmsize_t)(-1));
1191 }
1192 if (tif->tif_flags & TIFF_NOREADRAW)
1193 {
1194 TIFFErrorExtR(tif, module,
1195 "Compression scheme does not support access to raw "
1196 "uncompressed data");
1197 return ((tmsize_t)(-1));
1198 }
1199 bytecount64 = TIFFGetStrileByteCount(tif, tile);
1200 if (size != (tmsize_t)(-1) && (uint64_t)size <= bytecount64)
1201 bytecountm = size;
1202 else
1203 bytecountm = _TIFFCastUInt64ToSSize(tif, bytecount64, module);
1204 if (bytecountm == 0)
1205 {
1206 return ((tmsize_t)(-1));
1207 }
1208 return (TIFFReadRawTile1(tif, tile, buf, bytecountm, module));
1209}

◆ TIFFReadRGBAImage()

int TIFFReadRGBAImage ( TIFF tif,
uint32_t  rwidth,
uint32_t  rheight,
uint32_t raster,
int  stop 
)

Definition at line 656 of file tif_getimage.c.

658{
659 return TIFFReadRGBAImageOriented(tif, rwidth, rheight, raster,
660 ORIENTATION_BOTLEFT, stop);
661}
int TIFFReadRGBAImageOriented(TIFF *tif, uint32_t rwidth, uint32_t rheight, uint32_t *raster, int orientation, int stop)
Definition: tif_getimage.c:631
#define ORIENTATION_BOTLEFT
Definition: tiff.h:252

◆ TIFFReadRGBAImageOriented()

int TIFFReadRGBAImageOriented ( TIFF tif,
uint32_t  rwidth,
uint32_t  rheight,
uint32_t raster,
int  orientation,
int  stop 
)

Definition at line 631 of file tif_getimage.c.

633{
634 char emsg[EMSG_BUF_SIZE] = "";
636 int ok;
637
638 if (TIFFRGBAImageBegin(&img, tif, stop, emsg))
639 {
640 img.req_orientation = (uint16_t)orientation;
641 ok = TIFFRGBAImageGet(&img, raster, rwidth, rheight);
643 }
644 else
645 {
646 TIFFErrorExtR(tif, TIFFFileName(tif), "%s", emsg);
647 ok = 0;
648 }
649 return (ok);
650}
GLint GLvoid * img
Definition: gl.h:1956
#define EMSG_BUF_SIZE
Definition: tif_getimage.c:52
int TIFFRGBAImageGet(TIFFRGBAImage *img, uint32_t *raster, uint32_t w, uint32_t h)
Definition: tif_getimage.c:587
void TIFFRGBAImageEnd(TIFFRGBAImage *img)
Definition: tif_getimage.c:253
int TIFFRGBAImageBegin(TIFFRGBAImage *img, TIFF *tif, int stop, char emsg[EMSG_BUF_SIZE])
Definition: tif_getimage.c:310
const char * TIFFFileName(TIFF *tif)
Definition: tif_open.c:798

Referenced by TIFFReadRGBAImage().

◆ TIFFReadRGBAStrip()

int TIFFReadRGBAStrip ( TIFF tif,
uint32_t  row,
uint32_t raster 
)

Definition at line 3341 of file tif_getimage.c.

3343{
3344 return TIFFReadRGBAStripExt(tif, row, raster, 0);
3345}
int TIFFReadRGBAStripExt(TIFF *tif, uint32_t row, uint32_t *raster, int stop_on_error)

◆ TIFFReadRGBAStripExt()

int TIFFReadRGBAStripExt ( TIFF tif,
uint32_t  row,
uint32_t raster,
int  stop_on_error 
)

Definition at line 3347 of file tif_getimage.c.

3350{
3351 char emsg[EMSG_BUF_SIZE] = "";
3353 int ok;
3354 uint32_t rowsperstrip, rows_to_read;
3355
3356 if (TIFFIsTiled(tif))
3357 {
3358 TIFFErrorExtR(tif, TIFFFileName(tif),
3359 "Can't use TIFFReadRGBAStrip() with tiled file.");
3360 return (0);
3361 }
3362
3363 TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
3364
3365 if (rowsperstrip == 0)
3366 {
3367 TIFFErrorExtR(tif, TIFFFileName(tif), "rowsperstrip is zero");
3368 return (0);
3369 }
3370
3371 if ((row % rowsperstrip) != 0)
3372 {
3374 tif, TIFFFileName(tif),
3375 "Row passed to TIFFReadRGBAStrip() must be first in a strip.");
3376 return (0);
3377 }
3378
3379 if (TIFFRGBAImageBegin(&img, tif, stop_on_error, emsg))
3380 {
3381 if (row >= img.height)
3382 {
3383 TIFFErrorExtR(tif, TIFFFileName(tif),
3384 "Invalid row passed to TIFFReadRGBAStrip().");
3386 return (0);
3387 }
3388
3389 img.row_offset = row;
3390 img.col_offset = 0;
3391
3392 if (row + rowsperstrip > img.height)
3393 rows_to_read = img.height - row;
3394 else
3395 rows_to_read = rowsperstrip;
3396
3397 ok = TIFFRGBAImageGet(&img, raster, img.width, rows_to_read);
3398
3400 }
3401 else
3402 {
3403 TIFFErrorExtR(tif, TIFFFileName(tif), "%s", emsg);
3404 ok = 0;
3405 }
3406
3407 return (ok);
3408}
int TIFFGetFieldDefaulted(TIFF *tif, uint32_t tag,...)
Definition: tif_aux.c:380

Referenced by TIFFReadRGBAStrip().

◆ TIFFReadRGBATile()

int TIFFReadRGBATile ( TIFF tif,
uint32_t  col,
uint32_t  row,
uint32_t raster 
)

Definition at line 3416 of file tif_getimage.c.

3418{
3419 return TIFFReadRGBATileExt(tif, col, row, raster, 0);
3420}
int TIFFReadRGBATileExt(TIFF *tif, uint32_t col, uint32_t row, uint32_t *raster, int stop_on_error)

◆ TIFFReadRGBATileExt()

int TIFFReadRGBATileExt ( TIFF tif,
uint32_t  col,
uint32_t  row,
uint32_t raster,
int  stop_on_error 
)

Definition at line 3422 of file tif_getimage.c.

3424{
3425 char emsg[EMSG_BUF_SIZE] = "";
3427 int ok;
3428 uint32_t tile_xsize, tile_ysize;
3429 uint32_t read_xsize, read_ysize;
3430 uint32_t i_row;
3431
3432 /*
3433 * Verify that our request is legal - on a tile file, and on a
3434 * tile boundary.
3435 */
3436
3437 if (!TIFFIsTiled(tif))
3438 {
3439 TIFFErrorExtR(tif, TIFFFileName(tif),
3440 "Can't use TIFFReadRGBATile() with striped file.");
3441 return (0);
3442 }
3443
3444 TIFFGetFieldDefaulted(tif, TIFFTAG_TILEWIDTH, &tile_xsize);
3445 TIFFGetFieldDefaulted(tif, TIFFTAG_TILELENGTH, &tile_ysize);
3446 if (tile_xsize == 0 || tile_ysize == 0)
3447 {
3448 TIFFErrorExtR(tif, TIFFFileName(tif),
3449 "tile_xsize or tile_ysize is zero");
3450 return (0);
3451 }
3452
3453 if ((col % tile_xsize) != 0 || (row % tile_ysize) != 0)
3454 {
3455 TIFFErrorExtR(tif, TIFFFileName(tif),
3456 "Row/col passed to TIFFReadRGBATile() must be top"
3457 "left corner of a tile.");
3458 return (0);
3459 }
3460
3461 /*
3462 * Setup the RGBA reader.
3463 */
3464
3465 if (!TIFFRGBAImageBegin(&img, tif, stop_on_error, emsg))
3466 {
3467 TIFFErrorExtR(tif, TIFFFileName(tif), "%s", emsg);
3468 return (0);
3469 }
3470
3471 if (col >= img.width || row >= img.height)
3472 {
3473 TIFFErrorExtR(tif, TIFFFileName(tif),
3474 "Invalid row/col passed to TIFFReadRGBATile().");
3476 return (0);
3477 }
3478
3479 /*
3480 * The TIFFRGBAImageGet() function doesn't allow us to get off the
3481 * edge of the image, even to fill an otherwise valid tile. So we
3482 * figure out how much we can read, and fix up the tile buffer to
3483 * a full tile configuration afterwards.
3484 */
3485
3486 if (row + tile_ysize > img.height)
3487 read_ysize = img.height - row;
3488 else
3489 read_ysize = tile_ysize;
3490
3491 if (col + tile_xsize > img.width)
3492 read_xsize = img.width - col;
3493 else
3494 read_xsize = tile_xsize;
3495
3496 /*
3497 * Read the chunk of imagery.
3498 */
3499
3500 img.row_offset = row;
3501 img.col_offset = col;
3502
3503 ok = TIFFRGBAImageGet(&img, raster, read_xsize, read_ysize);
3504
3506
3507 /*
3508 * If our read was incomplete we will need to fix up the tile by
3509 * shifting the data around as if a full tile of data is being returned.
3510 *
3511 * This is all the more complicated because the image is organized in
3512 * bottom to top format.
3513 */
3514
3515 if (read_xsize == tile_xsize && read_ysize == tile_ysize)
3516 return (ok);
3517
3518 for (i_row = 0; i_row < read_ysize; i_row++)
3519 {
3520 memmove(raster + (size_t)(tile_ysize - i_row - 1) * tile_xsize,
3521 raster + (size_t)(read_ysize - i_row - 1) * read_xsize,
3522 read_xsize * sizeof(uint32_t));
3523 _TIFFmemset(raster + (size_t)(tile_ysize - i_row - 1) * tile_xsize +
3524 read_xsize,
3525 0, sizeof(uint32_t) * (tile_xsize - read_xsize));
3526 }
3527
3528 for (i_row = read_ysize; i_row < tile_ysize; i_row++)
3529 {
3530 _TIFFmemset(raster + (size_t)(tile_ysize - i_row - 1) * tile_xsize, 0,
3531 sizeof(uint32_t) * tile_xsize);
3532 }
3533
3534 return (ok);
3535}
#define memmove(s1, s2, n)
Definition: mkisofs.h:881

Referenced by TIFFReadRGBATile().

◆ TIFFReadScanline()

int TIFFReadScanline ( TIFF tif,
void buf,
uint32_t  row,
uint16_t  sample 
)

Definition at line 454 of file tif_read.c.

455{
456 int e;
457
458 if (!TIFFCheckRead(tif, 0))
459 return (-1);
460 if ((e = TIFFSeek(tif, row, sample)) != 0)
461 {
462 /*
463 * Decompress desired row into user buffer.
464 */
465 e = (*tif->tif_decoderow)(tif, (uint8_t *)buf, tif->tif_scanlinesize,
466 sample);
467
468 /* we are now poised at the beginning of the next row */
469 tif->tif_row = row + 1;
470
471 if (e)
472 (*tif->tif_postdecode)(tif, (uint8_t *)buf, tif->tif_scanlinesize);
473 }
474 else
475 {
476 /* See TIFFReadEncodedStrip comment regarding TIFFTAG_FAXFILLFUNC. */
477 if (buf)
478 memset(buf, 0, (size_t)tif->tif_scanlinesize);
479 }
480 return (e > 0 ? 1 : -1);
481}
#define e
Definition: ke_i.h:82
TIFFCodeMethod tif_decoderow
Definition: tiffiop.h:205
static int TIFFSeek(TIFF *tif, uint32_t row, uint16_t sample)
Definition: tif_read.c:309

◆ TIFFReadTile()

tmsize_t TIFFReadTile ( TIFF tif,
void buf,
uint32_t  x,
uint32_t  y,
uint32_t  z,
uint16_t  s 
)

Definition at line 940 of file tif_read.c.

942{
943 if (!TIFFCheckRead(tif, 1) || !TIFFCheckTile(tif, x, y, z, s))
944 return ((tmsize_t)(-1));
945 return (TIFFReadEncodedTile(tif, TIFFComputeTile(tif, x, y, z, s), buf,
946 (tmsize_t)(-1)));
947}
tmsize_t TIFFReadEncodedTile(TIFF *tif, uint32_t tile, void *buf, tmsize_t size)
Definition: tif_read.c:953
uint32_t TIFFComputeTile(TIFF *tif, uint32_t x, uint32_t y, uint32_t z, uint16_t s)
Definition: tif_tile.c:35
int TIFFCheckTile(TIFF *tif, uint32_t x, uint32_t y, uint32_t z, uint16_t s)
Definition: tif_tile.c:71

Referenced by gtTileSeparate().

◆ TIFFRegisterCODEC()

TIFFCodec * TIFFRegisterCODEC ( uint16_t  scheme,
const char name,
TIFFInitMethod  init 
)

Definition at line 206 of file tif_compress.c.

208{
210 NULL,
211 (tmsize_t)(sizeof(codec_t) + sizeof(TIFFCodec) + strlen(name) + 1));
212
213 if (cd != NULL)
214 {
215 cd->info = (TIFFCodec *)((uint8_t *)cd + sizeof(codec_t));
216 cd->info->name = (char *)((uint8_t *)cd->info + sizeof(TIFFCodec));
217 strcpy(cd->info->name, name);
218 cd->info->scheme = scheme;
219 cd->info->init = init;
220 cd->next = registeredCODECS;
222 }
223 else
224 {
225 TIFFErrorExt(0, "TIFFRegisterCODEC",
226 "No space to register compression scheme %s", name);
227 return NULL;
228 }
229 return (cd->info);
230}
struct _codec codec_t
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_error.c:63
static int init
Definition: wintirpc.c:33

◆ TIFFReverseBits()

void TIFFReverseBits ( uint8_t cp,
tmsize_t  n 
)

Definition at line 310 of file tif_swab.c.

311{
312 for (; n > 8; n -= 8)
313 {
314 cp[0] = TIFFBitRevTable[cp[0]];
315 cp[1] = TIFFBitRevTable[cp[1]];
316 cp[2] = TIFFBitRevTable[cp[2]];
317 cp[3] = TIFFBitRevTable[cp[3]];
318 cp[4] = TIFFBitRevTable[cp[4]];
319 cp[5] = TIFFBitRevTable[cp[5]];
320 cp[6] = TIFFBitRevTable[cp[6]];
321 cp[7] = TIFFBitRevTable[cp[7]];
322 cp += 8;
323 }
324 while (n-- > 0)
325 {
326 *cp = TIFFBitRevTable[*cp];
327 cp++;
328 }
329}

Referenced by TIFFFillStrip(), TIFFFillStripPartial(), TIFFFillTile(), TIFFFlushData1(), TIFFReadEncodedStrip(), TIFFReadEncodedTile(), TIFFReadFromUserBuffer(), TIFFWriteEncodedStrip(), and TIFFWriteEncodedTile().

◆ TIFFRewriteDirectory()

int TIFFRewriteDirectory ( TIFF tif)

Definition at line 483 of file tif_dirwrite.c.

484{
485 return TIFFRewriteDirectorySec(tif, TRUE, TRUE, NULL);
486}
static int TIFFRewriteDirectorySec(TIFF *tif, int isimage, int imagedone, uint64_t *pdiroff)
Definition: tif_dirwrite.c:315

Referenced by TIFFFlush().

◆ TIFFRGBAImageBegin()

int TIFFRGBAImageBegin ( TIFFRGBAImage ,
TIFF ,
int  ,
char  [1024] 
)

◆ TIFFRGBAImageEnd()

void TIFFRGBAImageEnd ( TIFFRGBAImage img)

Definition at line 253 of file tif_getimage.c.

254{
255 if (img->Map)
256 {
257 _TIFFfreeExt(img->tif, img->Map);
258 img->Map = NULL;
259 }
260 if (img->BWmap)
261 {
262 _TIFFfreeExt(img->tif, img->BWmap);
263 img->BWmap = NULL;
264 }
265 if (img->PALmap)
266 {
267 _TIFFfreeExt(img->tif, img->PALmap);
268 img->PALmap = NULL;
269 }
270 if (img->ycbcr)
271 {
272 _TIFFfreeExt(img->tif, img->ycbcr);
273 img->ycbcr = NULL;
274 }
275 if (img->cielab)
276 {
277 _TIFFfreeExt(img->tif, img->cielab);
278 img->cielab = NULL;
279 }
280 if (img->UaToAa)
281 {
282 _TIFFfreeExt(img->tif, img->UaToAa);
283 img->UaToAa = NULL;
284 }
285 if (img->Bitdepth16To8)
286 {
287 _TIFFfreeExt(img->tif, img->Bitdepth16To8);
288 img->Bitdepth16To8 = NULL;
289 }
290
291 if (img->redcmap)
292 {
293 _TIFFfreeExt(img->tif, img->redcmap);
294 _TIFFfreeExt(img->tif, img->greencmap);
295 _TIFFfreeExt(img->tif, img->bluecmap);
296 img->redcmap = img->greencmap = img->bluecmap = NULL;
297 }
298}

Referenced by TIFFReadRGBAImageOriented(), TIFFReadRGBAStripExt(), TIFFReadRGBATileExt(), and TIFFRGBAImageBegin().

◆ TIFFRGBAImageGet()

int TIFFRGBAImageGet ( TIFFRGBAImage img,
uint32_t raster,
uint32_t  w,
uint32_t  h 
)

Definition at line 587 of file tif_getimage.c.

589{
590 if (img->get == NULL)
591 {
592 TIFFErrorExtR(img->tif, TIFFFileName(img->tif),
593 "No \"get\" routine setup");
594 return (0);
595 }
596 if (img->put.any == NULL)
597 {
599 img->tif, TIFFFileName(img->tif),
600 "No \"put\" routine setupl; probably can not handle image format");
601 return (0);
602 }
603 /* Verify raster height against image height.
604 * Width is checked in img->get() function individually. */
605 if (0 <= img->row_offset && (uint32_t)img->row_offset < img->height)
606 {
607 uint32_t hx = img->height - img->row_offset;
608 if (h > hx)
609 {
610 /* Adapt parameters to read only available lines and put image
611 * at the bottom of the raster. */
612 raster += (size_t)(h - hx) * w;
613 h = hx;
614 }
615 }
616 else
617 {
618 TIFFErrorExtR(img->tif, TIFFFileName(img->tif),
619 "Error in TIFFRGBAImageGet: row offset %d exceeds "
620 "image height %d",
621 img->row_offset, img->height);
622 return 0;
623 }
624 return (*img->get)(img, raster, w, h);
625}
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723

Referenced by TIFFReadRGBAImageOriented(), TIFFReadRGBAStripExt(), and TIFFReadRGBATileExt().

◆ TIFFRGBAImageOK()

int TIFFRGBAImageOK ( TIFF ,
char  [1024] 
)

◆ TIFFScanlineSize()

tmsize_t TIFFScanlineSize ( TIFF tif)

Definition at line 343 of file tif_strip.c.

344{
345 static const char module[] = "TIFFScanlineSize";
346 uint64_t m;
347 m = TIFFScanlineSize64(tif);
348 return _TIFFCastUInt64ToSSize(tif, m, module);
349}
uint64_t TIFFScanlineSize64(TIFF *tif)
Definition: tif_strip.c:257

Referenced by gtStripContig(), gtStripSeparate(), PredictorSetup(), TIFFReadDirectory(), and TIFFWriteCheck().

◆ TIFFScanlineSize64()

uint64_t TIFFScanlineSize64 ( TIFF tif)

Definition at line 257 of file tif_strip.c.

258{
259 static const char module[] = "TIFFScanlineSize64";
260 TIFFDirectory *td = &tif->tif_dir;
261 uint64_t scanline_size;
263 {
264 if ((td->td_photometric == PHOTOMETRIC_YCBCR) &&
265 (td->td_samplesperpixel == 3) && (!isUpSampled(tif)))
266 {
267 uint16_t ycbcrsubsampling[2];
268 uint16_t samplingblock_samples;
269 uint32_t samplingblocks_hor;
270 uint64_t samplingrow_samples;
271 uint64_t samplingrow_size;
272 if (td->td_samplesperpixel != 3)
273 {
274 TIFFErrorExtR(tif, module, "Invalid td_samplesperpixel value");
275 return 0;
276 }
278 ycbcrsubsampling + 0, ycbcrsubsampling + 1);
279 if (((ycbcrsubsampling[0] != 1) && (ycbcrsubsampling[0] != 2) &&
280 (ycbcrsubsampling[0] != 4)) ||
281 ((ycbcrsubsampling[1] != 1) && (ycbcrsubsampling[1] != 2) &&
282 (ycbcrsubsampling[1] != 4)) ||
283 ((ycbcrsubsampling[0] == 0) || (ycbcrsubsampling[1] == 0)))
284 {
285 TIFFErrorExtR(tif, module, "Invalid YCbCr subsampling");
286 return 0;
287 }
288 samplingblock_samples =
289 ycbcrsubsampling[0] * ycbcrsubsampling[1] + 2;
290 samplingblocks_hor =
291 TIFFhowmany_32(td->td_imagewidth, ycbcrsubsampling[0]);
292 samplingrow_samples = _TIFFMultiply64(
293 tif, samplingblocks_hor, samplingblock_samples, module);
294 samplingrow_size =
295 TIFFhowmany_64(_TIFFMultiply64(tif, samplingrow_samples,
297 8);
298 scanline_size = (samplingrow_size / ycbcrsubsampling[1]);
299 }
300 else
301 {
302 uint64_t scanline_samples;
303 uint32_t scanline_width = td->td_imagewidth;
304
305#if 0
306 // Tries to fix https://gitlab.com/libtiff/libtiff/-/merge_requests/564
307 // but causes regression when decoding legit files with tiffcp -c none
308 // Cf https://gitlab.com/libtiff/libtiff/-/merge_requests/644
310 {
311 uint16_t subsampling_hor;
314 &subsampling_hor, &ignored);
315 if (subsampling_hor > 1) // roundup width for YCbCr
316 scanline_width =
317 TIFFroundup_32(scanline_width, subsampling_hor);
318 }
319#endif
320
321 scanline_samples = _TIFFMultiply64(tif, scanline_width,
323 scanline_size =
324 TIFFhowmany_64(_TIFFMultiply64(tif, scanline_samples,
326 8);
327 }
328 }
329 else
330 {
331 scanline_size =
334 8);
335 }
336 if (scanline_size == 0)
337 {
338 TIFFErrorExtR(tif, module, "Computed scanline size is zero");
339 return 0;
340 }
341 return (scanline_size);
342}
uint8_t ignored[3]
Definition: fsck.fat.h:0
#define TIFFTAG_YCBCRSUBSAMPLING
Definition: tiff.h:388
#define TIFFhowmany_64(x, y)
Definition: tiffiop.h:317
#define TIFFroundup_32(x, y)
Definition: tiffiop.h:316

Referenced by _TIFFDefaultStripSize(), ByteCountLooksBad(), EstimateStripByteCounts(), TIFFScanlineSize(), and TIFFVStripSize64().

◆ TIFFSetClientdata()

thandle_t TIFFSetClientdata ( TIFF tif,
thandle_t  newvalue 
)

Definition at line 833 of file tif_open.c.

834{
836 tif->tif_clientdata = newvalue;
837 return m;
838}

◆ TIFFSetClientInfo()

void TIFFSetClientInfo ( TIFF tif,
void data,
const char name 
)

Definition at line 78 of file tif_extension.c.

80{
82
83 /*
84 ** Do we have an existing link with this name? If so, just
85 ** set it.
86 */
87 while (psLink != NULL && strcmp(psLink->name, name) != 0)
88 psLink = psLink->next;
89
90 if (psLink != NULL)
91 {
92 psLink->data = data;
93 return;
94 }
95
96 /*
97 ** Create a new link.
98 */
99
100 psLink =
102 assert(psLink != NULL);
103 psLink->next = tif->tif_clientinfo;
104 psLink->name = (char *)_TIFFmallocExt(tif, (tmsize_t)(strlen(name) + 1));
105 assert(psLink->name != NULL);
106 strcpy(psLink->name, name);
107 psLink->data = data;
108
109 tif->tif_clientinfo = psLink;
110}

◆ TIFFSetDirectory()

int TIFFSetDirectory ( TIFF tif,
tdir_t  dirn 
)

Definition at line 2057 of file tif_dir.c.

2058{
2059 uint64_t nextdiroff;
2060 tdir_t nextdirnum = 0;
2061 tdir_t n;
2062
2064 {
2065 /* tif_setdirectory_force_absolute=1 will force parsing the main IFD
2066 * chain from the beginning, thus IFD directory list needs to be cleared
2067 * from possible SubIFD offsets.
2068 */
2069 _TIFFCleanupIFDOffsetAndNumberMaps(tif); /* invalidate IFD loop lists */
2070 }
2071
2072 /* Even faster path, if offset is available within IFD loop hash list. */
2074 _TIFFGetOffsetFromDirNumber(tif, dirn, &nextdiroff))
2075 {
2076 /* Set parameters for following TIFFReadDirectory() below. */
2077 tif->tif_nextdiroff = nextdiroff;
2078 tif->tif_curdir = dirn;
2079 /* Reset to relative stepping */
2081 }
2082 else
2083 {
2084
2085 /* Fast path when we just advance relative to the current directory:
2086 * start at the current dir offset and continue to seek from there.
2087 * Check special cases when relative is not allowed:
2088 * - jump back from SubIFD or custom directory
2089 * - right after TIFFWriteDirectory() jump back to that directory
2090 * using TIFFSetDirectory() */
2091 const int relative = (dirn >= tif->tif_curdir) &&
2092 (tif->tif_diroff != 0) &&
2094
2095 if (relative)
2096 {
2097 nextdiroff = tif->tif_diroff;
2098 dirn -= tif->tif_curdir;
2099 nextdirnum = tif->tif_curdir;
2100 }
2101 else if (!(tif->tif_flags & TIFF_BIGTIFF))
2102 nextdiroff = tif->tif_header.classic.tiff_diroff;
2103 else
2104 nextdiroff = tif->tif_header.big.tiff_diroff;
2105
2106 /* Reset to relative stepping */
2108
2109 for (n = dirn; n > 0 && nextdiroff != 0; n--)
2110 if (!TIFFAdvanceDirectory(tif, &nextdiroff, NULL, &nextdirnum))
2111 return (0);
2112 /* If the n-th directory could not be reached (does not exist),
2113 * return here without touching anything further. */
2114 if (nextdiroff == 0 || n > 0)
2115 return (0);
2116
2117 tif->tif_nextdiroff = nextdiroff;
2118
2119 /* Set curdir to the actual directory index. */
2120 if (relative)
2121 tif->tif_curdir += dirn - n;
2122 else
2123 tif->tif_curdir = dirn - n;
2124 }
2125
2126 /* The -1 decrement is because TIFFReadDirectory will increment
2127 * tif_curdir after successfully reading the directory. */
2128 if (tif->tif_curdir == 0)
2130 else
2131 tif->tif_curdir--;
2132
2133 tdir_t curdir = tif->tif_curdir;
2134
2135 int retval = TIFFReadDirectory(tif);
2136
2137 if (!retval && tif->tif_curdir == curdir)
2138 {
2139 /* If tif_curdir has not be incremented, TIFFFetchDirectory() in
2140 * TIFFReadDirectory() has failed and tif_curdir shall be set
2141 * specifically. */
2143 }
2144 return (retval);
2145}
int _TIFFGetOffsetFromDirNumber(TIFF *tif, tdir_t dirn, uint64_t *diroff)
Definition: tif_dirread.c:5873
int retval
Definition: wcstombs.cpp:91

Referenced by tiff_decoder_select_frame().

◆ TIFFSetErrorHandler()

void void void void TIFFErrorHandler TIFFSetErrorHandler ( TIFFErrorHandler  handler)

Definition at line 32 of file tif_error.c.

33{
36 return (prev);
37}
TIFFErrorHandler _TIFFerrorHandler
Definition: tif_unix.c:382
void(* TIFFErrorHandler)(const char *, const char *, va_list)
Definition: tiffio.h:301

Referenced by tiff_decoder_create(), and tiff_encoder_create().

◆ TIFFSetErrorHandlerExt()

TIFFErrorHandlerExt TIFFSetErrorHandlerExt ( TIFFErrorHandlerExt  handler)

Definition at line 39 of file tif_error.c.

40{
43 return (prev);
44}
TIFFErrorHandlerExt _TIFFerrorHandlerExt
Definition: tif_error.c:30
void(* TIFFErrorHandlerExt)(thandle_t, const char *, const char *, va_list)
Definition: tiffio.h:302

◆ TIFFSetField()

int TIFFSetField ( TIFF tif,
uint32_t  tag,
  ... 
)

Definition at line 1146 of file tif_dir.c.

1147{
1148 va_list ap;
1149 int status;
1150
1151 va_start(ap, tag);
1152 status = TIFFVSetField(tif, tag, ap);
1153 va_end(ap);
1154 return (status);
1155}
int TIFFVSetField(TIFF *tif, uint32_t tag, va_list ap)
Definition: tif_dir.c:1205

Referenced by allocChoppedUpStripArrays(), tiff_encoder_create_frame(), TIFFDefaultDirectory(), TIFFFetchNormalTag(), TIFFFetchSubjectDistance(), TIFFReadDirectory(), and TIFFRGBAImageBegin().

◆ TIFFSetFileName()

const char * TIFFSetFileName ( TIFF tif,
const char name 
)

Definition at line 803 of file tif_open.c.

804{
805 const char *old_name = tif->tif_name;
806 tif->tif_name = (char *)name;
807 return (old_name);
808}

◆ TIFFSetFileno()

int TIFFSetFileno ( TIFF tif,
int  fd 
)

Definition at line 818 of file tif_open.c.

819{
820 int old_fd = tif->tif_fd;
821 tif->tif_fd = fd;
822 return old_fd;
823}

◆ TIFFSetMode()

int TIFFSetMode ( TIFF tif,
int  mode 
)

Definition at line 848 of file tif_open.c.

849{
850 int old_mode = tif->tif_mode;
851 tif->tif_mode = mode;
852 return (old_mode);
853}

◆ TIFFSetSubDirectory()

int TIFFSetSubDirectory ( TIFF tif,
uint64_t  diroff 
)

Definition at line 2153 of file tif_dir.c.

2154{
2155 /* Match nextdiroff and curdir for consistent IFD-loop checking.
2156 * Only with TIFFSetSubDirectory() the IFD list can be corrupted with
2157 * invalid offsets within the main IFD tree. In the case of several subIFDs
2158 * of a main image, there are two possibilities that are not even mutually
2159 * exclusive. a.) The subIFD tag contains an array with all offsets of the
2160 * subIFDs. b.) The SubIFDs are concatenated with their NextIFD parameters.
2161 * (refer to
2162 * https://www.awaresystems.be/imaging/tiff/specification/TIFFPM6.pdf.)
2163 */
2164 int retval;
2165 uint32_t curdir = 0;
2166 int8_t probablySubIFD = 0;
2167 if (diroff == 0)
2168 {
2169 /* Special case to set tif_diroff=0, which is done in
2170 * TIFFReadDirectory() below to indicate that the currently read IFD is
2171 * treated as a new, fresh IFD. */
2174 }
2175 else
2176 {
2177 if (!_TIFFGetDirNumberFromOffset(tif, diroff, &curdir))
2178 {
2179 /* Non-existing offsets might point to a SubIFD or invalid IFD.*/
2180 probablySubIFD = 1;
2181 }
2182 /* -1 because TIFFReadDirectory() will increment tif_curdir. */
2183 if (curdir >= 1)
2184 tif->tif_curdir = curdir - 1;
2185 else
2187 }
2188 curdir = tif->tif_curdir;
2189
2190 tif->tif_nextdiroff = diroff;
2192
2193 /* tif_curdir is incremented in TIFFReadDirectory(), but if it has not been
2194 * incremented, TIFFFetchDirectory() has failed there and tif_curdir shall
2195 * be set specifically. */
2196 if (!retval && diroff != 0 && tif->tif_curdir == curdir)
2197 {
2199 }
2200
2201 if (probablySubIFD)
2202 {
2203 if (retval)
2204 {
2205 /* Reset IFD list to start new one for SubIFD chain and also start
2206 * SubIFD chain with tif_curdir=0 for IFD loop checking. */
2207 /* invalidate IFD loop lists */
2209 tif->tif_curdir = 0; /* first directory of new chain */
2210 /* add this offset to new IFD list */
2211 retval = _TIFFCheckDirNumberAndOffset(tif, tif->tif_curdir, diroff);
2212 }
2213 /* To be able to return from SubIFD or custom-IFD to main-IFD */
2215 }
2216
2217 return (retval);
2218}
int _TIFFGetDirNumberFromOffset(TIFF *tif, uint64_t diroff, tdir_t *dirn)
Definition: tif_dirread.c:5828

◆ TIFFSetTagExtender()

TIFFExtendProc TIFFSetTagExtender ( TIFFExtendProc  extender)

Definition at line 1675 of file tif_dir.c.

1676{
1678 _TIFFextender = extender;
1679 return (prev);
1680}
static TIFFExtendProc _TIFFextender
Definition: tif_dir.c:1673
void(* TIFFExtendProc)(TIFF *)
Definition: tiffio.h:312

◆ TIFFSetupStrips()

int TIFFSetupStrips ( TIFF tif)

Definition at line 553 of file tif_write.c.

554{
555 TIFFDirectory *td = &tif->tif_dir;
556
557 if (isTiled(tif))
560 : TIFFNumberOfTiles(tif);
561 else
564 : TIFFNumberOfStrips(tif);
566 /* TIFFWriteDirectoryTagData has a limitation to 0x80000000U bytes */
567 if (td->td_nstrips >=
568 0x80000000U / ((tif->tif_flags & TIFF_BIGTIFF) ? 0x8U : 0x4U))
569 {
570 TIFFErrorExtR(tif, "TIFFSetupStrips",
571 "Too large Strip/Tile Offsets/ByteCounts arrays");
572 return 0;
573 }
576
577 if (td->td_stripoffset_p != NULL)
580 tif, td->td_nstrips, sizeof(uint64_t), "for \"StripOffsets\" array");
581 if (td->td_stripbytecount_p != NULL)
584 tif, td->td_nstrips, sizeof(uint64_t), "for \"StripByteCounts\" array");
585 if (td->td_stripoffset_p == NULL || td->td_stripbytecount_p == NULL)
586 return (0);
587 /*
588 * Place data at the end-of-file
589 * (by setting offsets to zero).
590 */
591 _TIFFmemset(td->td_stripoffset_p, 0, td->td_nstrips * sizeof(uint64_t));
592 _TIFFmemset(td->td_stripbytecount_p, 0, td->td_nstrips * sizeof(uint64_t));
595 return (1);
596}
#define isUnspecified(tif, f)
Definition: tif_write.c:550

Referenced by TIFFCheckpointDirectory(), TIFFForceStrileArrayWriting(), TIFFReadDirectory(), and TIFFWriteCheck().

◆ TIFFSetWarningHandler()

TIFFErrorHandler TIFFSetWarningHandler ( TIFFErrorHandler  handler)

Definition at line 32 of file tif_warning.c.

33{
36 return (prev);
37}
TIFFErrorHandler _TIFFwarningHandler
Definition: tif_unix.c:373

Referenced by tiff_decoder_create(), and tiff_encoder_create().

◆ TIFFSetWarningHandlerExt()

TIFFErrorHandlerExt TIFFSetWarningHandlerExt ( TIFFErrorHandlerExt  handler)

Definition at line 39 of file tif_warning.c.

40{
43 return (prev);
44}
TIFFErrorHandlerExt _TIFFwarningHandlerExt
Definition: tif_warning.c:30

◆ TIFFSetWriteOffset()

void TIFFSetWriteOffset ( TIFF tif,
toff_t  off 
)

Definition at line 961 of file tif_write.c.

962{
963 tif->tif_curoff = off;
964 tif->tif_lastvalidoff = 0;
965}
uint64_t tif_lastvalidoff
Definition: tiffiop.h:186

Referenced by TIFFCheckpointDirectory().

◆ TIFFStripSize()

tmsize_t TIFFStripSize ( TIFF tif)

Definition at line 204 of file tif_strip.c.

205{
206 static const char module[] = "TIFFStripSize";
207 uint64_t m;
208 m = TIFFStripSize64(tif);
209 return _TIFFCastUInt64ToSSize(tif, m, module);
210}

Referenced by gtStripContig(), gtStripSeparate(), TIFFFillStrip(), TIFFReadDirectory(), and TIFFWriteBufferSetup().

◆ TIFFStripSize64()

uint64_t TIFFStripSize64 ( TIFF tif)

Definition at line 196 of file tif_strip.c.

197{
198 TIFFDirectory *td = &tif->tif_dir;
199 uint32_t rps = td->td_rowsperstrip;
200 if (rps > td->td_imagelength)
201 rps = td->td_imagelength;
202 return (TIFFVStripSize64(tif, rps));
203}
uint64_t TIFFVStripSize64(TIFF *tif, uint32_t nrows)
Definition: tif_strip.c:88

Referenced by _TIFFRewriteField(), TIFFReadDirectory(), TIFFStripSize(), TIFFWriteDirectoryTagLongLong8Array(), and TryChopUpUncompressedBigTiff().

◆ TIFFSwabArrayOfDouble()

void TIFFSwabArrayOfDouble ( double dp,
tmsize_t  n 
)

Definition at line 222 of file tif_swab.c.

223{
224 register unsigned char *cp;
225 register unsigned char t;
226 assert(sizeof(double) == 8);
227 /* XXX unroll loop some */
228 while (n-- > 0)
229 {
230 cp = (unsigned char *)dp;
231 t = cp[7];
232 cp[7] = cp[0];
233 cp[0] = t;
234 t = cp[6];
235 cp[6] = cp[1];
236 cp[1] = t;
237 t = cp[5];
238 cp[5] = cp[2];
239 cp[2] = t;
240 t = cp[4];
241 cp[4] = cp[3];
242 cp[3] = t;
243 dp++;
244 }
245}
GLdouble GLdouble t
Definition: gl.h:2047

Referenced by _TIFFSwab64BitData(), and TIFFWriteDirectoryTagCheckedDoubleArray().

◆ TIFFSwabArrayOfFloat()

void TIFFSwabArrayOfFloat ( float fp,
tmsize_t  n 
)

◆ TIFFSwabArrayOfLong()

void TIFFSwabArrayOfLong ( uint32_t lp,
tmsize_t  n 
)

◆ TIFFSwabArrayOfLong8()

void TIFFSwabArrayOfLong8 ( uint64_t lp,
tmsize_t  n 
)

◆ TIFFSwabArrayOfShort()

void TIFFSwabArrayOfShort ( uint16_t wp,
tmsize_t  n 
)

◆ TIFFSwabArrayOfTriples()

void TIFFSwabArrayOfTriples ( uint8_t tp,
tmsize_t  n 
)

◆ TIFFSwabDouble()

void TIFFSwabDouble ( double dp)

Definition at line 201 of file tif_swab.c.

202{
203 register unsigned char *cp = (unsigned char *)dp;
204 unsigned char t;
205 assert(sizeof(double) == 8);
206 t = cp[7];
207 cp[7] = cp[0];
208 cp[0] = t;
209 t = cp[6];
210 cp[6] = cp[1];
211 cp[1] = t;
212 t = cp[5];
213 cp[5] = cp[2];
214 cp[2] = t;
215 t = cp[4];
216 cp[4] = cp[3];
217 cp[3] = t;
218}

◆ TIFFSwabFloat()

void TIFFSwabFloat ( float fp)

Definition at line 165 of file tif_swab.c.

166{
167 register unsigned char *cp = (unsigned char *)fp;
168 unsigned char t;
169 assert(sizeof(float) == 4);
170 t = cp[3];
171 cp[3] = cp[0];
172 cp[0] = t;
173 t = cp[2];
174 cp[2] = cp[1];
175 cp[1] = t;
176}

◆ TIFFSwabLong()

◆ TIFFSwabLong8()

◆ TIFFSwabShort()

◆ TIFFTileRowSize()

tmsize_t TIFFTileRowSize ( TIFF tif)

Definition at line 177 of file tif_tile.c.

178{
179 static const char module[] = "TIFFTileRowSize";
180 uint64_t m;
181 m = TIFFTileRowSize64(tif);
182 return _TIFFCastUInt64ToSSize(tif, m, module);
183}
uint64_t TIFFTileRowSize64(TIFF *tif)
Definition: tif_tile.c:140

Referenced by gtTileContig(), gtTileSeparate(), and PredictorSetup().

◆ TIFFTileRowSize64()

uint64_t TIFFTileRowSize64 ( TIFF tif)

Definition at line 140 of file tif_tile.c.

141{
142 static const char module[] = "TIFFTileRowSize64";
143 TIFFDirectory *td = &tif->tif_dir;
144 uint64_t rowsize;
145 uint64_t tilerowsize;
146
147 if (td->td_tilelength == 0)
148 {
149 TIFFErrorExtR(tif, module, "Tile length is zero");
150 return 0;
151 }
152 if (td->td_tilewidth == 0)
153 {
154 TIFFErrorExtR(tif, module, "Tile width is zero");
155 return (0);
156 }
157 rowsize = _TIFFMultiply64(tif, td->td_bitspersample, td->td_tilewidth,
158 "TIFFTileRowSize");
160 {
161 if (td->td_samplesperpixel == 0)
162 {
163 TIFFErrorExtR(tif, module, "Samples per pixel is zero");
164 return 0;
165 }
166 rowsize = _TIFFMultiply64(tif, rowsize, td->td_samplesperpixel,
167 "TIFFTileRowSize");
168 }
169 tilerowsize = TIFFhowmany8_64(rowsize);
170 if (tilerowsize == 0)
171 {
172 TIFFErrorExtR(tif, module, "Computed tile row size is zero");
173 return 0;
174 }
175 return (tilerowsize);
176}

Referenced by TIFFTileRowSize(), and TIFFVTileSize64().

◆ TIFFTileSize()

tmsize_t TIFFTileSize ( TIFF tif)

Definition at line 253 of file tif_tile.c.

254{
255 static const char module[] = "TIFFTileSize";
256 uint64_t m;
257 m = TIFFTileSize64(tif);
258 return _TIFFCastUInt64ToSSize(tif, m, module);
259}
uint64_t TIFFTileSize64(TIFF *tif)
Definition: tif_tile.c:249

Referenced by gtTileContig(), gtTileSeparate(), TIFFFillTile(), TIFFReadDirectory(), and TIFFWriteCheck().

◆ TIFFTileSize64()

uint64_t TIFFTileSize64 ( TIFF tif)

Definition at line 249 of file tif_tile.c.

250{
251 return (TIFFVTileSize64(tif, tif->tif_dir.td_tilelength));
252}
uint64_t TIFFVTileSize64(TIFF *tif, uint32_t nrows)
Definition: tif_tile.c:188

Referenced by _TIFFRewriteField(), EstimateStripByteCounts(), TIFFTileSize(), and TIFFWriteDirectoryTagLongLong8Array().

◆ TIFFUnlinkDirectory()

int TIFFUnlinkDirectory ( TIFF tif,
tdir_t  dirn 
)

Definition at line 2237 of file tif_dir.c.

2238{
2239 static const char module[] = "TIFFUnlinkDirectory";
2240 uint64_t nextdir;
2241 tdir_t nextdirnum;
2242 uint64_t off;
2243 tdir_t n;
2244
2245 if (tif->tif_mode == O_RDONLY)
2246 {
2247 TIFFErrorExtR(tif, module,
2248 "Can not unlink directory in read-only file");
2249 return (0);
2250 }
2251 if (dirn == 0)
2252 {
2253 TIFFErrorExtR(tif, module,
2254 "For TIFFUnlinkDirectory() first directory starts with "
2255 "number 1 and not 0");
2256 return (0);
2257 }
2258 /*
2259 * Go to the directory before the one we want
2260 * to unlink and nab the offset of the link
2261 * field we'll need to patch.
2262 */
2263 if (!(tif->tif_flags & TIFF_BIGTIFF))
2264 {
2265 nextdir = tif->tif_header.classic.tiff_diroff;
2266 off = 4;
2267 }
2268 else
2269 {
2270 nextdir = tif->tif_header.big.tiff_diroff;
2271 off = 8;
2272 }
2273 nextdirnum = 0; /* First directory is dirn=0 */
2274
2275 for (n = dirn - 1; n > 0; n--)
2276 {
2277 if (nextdir == 0)
2278 {
2279 TIFFErrorExtR(tif, module, "Directory %u does not exist", dirn);
2280 return (0);
2281 }
2282 if (!TIFFAdvanceDirectory(tif, &nextdir, &off, &nextdirnum))
2283 return (0);
2284 }
2285 /*
2286 * Advance to the directory to be unlinked and fetch
2287 * the offset of the directory that follows.
2288 */
2289 if (!TIFFAdvanceDirectory(tif, &nextdir, NULL, &nextdirnum))
2290 return (0);
2291 /*
2292 * Go back and patch the link field of the preceding
2293 * directory to point to the offset of the directory
2294 * that follows.
2295 */
2296 (void)TIFFSeekFile(tif, off, SEEK_SET);
2297 if (!(tif->tif_flags & TIFF_BIGTIFF))
2298 {
2299 uint32_t nextdir32;
2300 nextdir32 = (uint32_t)nextdir;
2301 assert((uint64_t)nextdir32 == nextdir);
2302 if (tif->tif_flags & TIFF_SWAB)
2303 TIFFSwabLong(&nextdir32);
2304 if (!WriteOK(tif, &nextdir32, sizeof(uint32_t)))
2305 {
2306 TIFFErrorExtR(tif, module, "Error writing directory link");
2307 return (0);
2308 }
2309 }
2310 else
2311 {
2312 /* Need local swap because nextdir has to be used unswapped below. */
2313 uint64_t nextdir64 = nextdir;
2314 if (tif->tif_flags & TIFF_SWAB)
2315 TIFFSwabLong8(&nextdir64);
2316 if (!WriteOK(tif, &nextdir64, sizeof(uint64_t)))
2317 {
2318 TIFFErrorExtR(tif, module, "Error writing directory link");
2319 return (0);
2320 }
2321 }
2322
2323 /* For dirn=1 (first directory) also update the libtiff internal
2324 * base offset variables. */
2325 if (dirn == 1)
2326 {
2327 if (!(tif->tif_flags & TIFF_BIGTIFF))
2328 tif->tif_header.classic.tiff_diroff = (uint32_t)nextdir;
2329 else
2330 tif->tif_header.big.tiff_diroff = nextdir;
2331 }
2332
2333 /*
2334 * Leave directory state setup safely. We don't have
2335 * facilities for doing inserting and removing directories,
2336 * so it's safest to just invalidate everything. This
2337 * means that the caller can only append to the directory
2338 * chain.
2339 */
2340 if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)
2341 {
2342 _TIFFfreeExt(tif, tif->tif_rawdata);
2343 tif->tif_rawdata = NULL;
2344 tif->tif_rawcc = 0;
2345 tif->tif_rawcp = NULL;
2346 tif->tif_rawdataoff = 0;
2347 tif->tif_rawdataloaded = 0;
2348 }
2351 TIFFFreeDirectory(tif);
2353 tif->tif_diroff = 0; /* force link on next write */
2354 tif->tif_nextdiroff = 0; /* next write must be at end */
2355 tif->tif_lastdiroff = 0; /* will be updated on next link */
2356 tif->tif_curoff = 0;
2357 tif->tif_row = (uint32_t)-1;
2358 tif->tif_curstrip = (uint32_t)-1;
2360 if (tif->tif_curdircount > 0)
2361 tif->tif_curdircount--;
2362 else
2364 _TIFFCleanupIFDOffsetAndNumberMaps(tif); /* invalidate IFD loop lists */
2365 return (1);
2366}
tmsize_t tif_rawcc
Definition: tiffiop.h:225
#define TIFF_BUFFERSETUP
Definition: tiffiop.h:121
#define TIFF_BUF4WRITE
Definition: tiffiop.h:139

◆ TIFFUnRegisterCODEC()

void TIFFUnRegisterCODEC ( TIFFCodec c)

Definition at line 232 of file tif_compress.c.

233{
234 codec_t *cd;
235 codec_t **pcd;
236
237 for (pcd = &registeredCODECS; (cd = *pcd) != NULL; pcd = &cd->next)
238 if (cd->info == c)
239 {
240 *pcd = cd->next;
242 return;
243 }
244 TIFFErrorExt(0, "TIFFUnRegisterCODEC",
245 "Cannot remove compression scheme %s; not registered",
246 c->name);
247}

◆ TIFFUnsetField()

int TIFFUnsetField ( TIFF tif,
uint32_t  tag 
)

Definition at line 1160 of file tif_dir.c.

1161{
1162 const TIFFField *fip = TIFFFieldWithTag(tif, tag);
1163 TIFFDirectory *td = &tif->tif_dir;
1164
1165 if (!fip)
1166 return 0;
1167
1168 if (fip->field_bit != FIELD_CUSTOM)
1169 TIFFClrFieldBit(tif, fip->field_bit);
1170 else
1171 {
1172 TIFFTagValue *tv = NULL;
1173 int i;
1174
1175 for (i = 0; i < td->td_customValueCount; i++)
1176 {
1177
1178 tv = td->td_customValues + i;
1179 if (tv->info->field_tag == tag)
1180 break;
1181 }
1182
1183 if (i < td->td_customValueCount)
1184 {
1185 _TIFFfreeExt(tif, tv->value);
1186 for (; i < td->td_customValueCount - 1; i++)
1187 {
1188 td->td_customValues[i] = td->td_customValues[i + 1];
1189 }
1190 td->td_customValueCount--;
1191 }
1192 }
1193
1195
1196 return (1);
1197}

◆ TIFFVGetField()

int TIFFVGetField ( TIFF tif,
uint32_t  tag,
va_list  ap 
)

Definition at line 1599 of file tif_dir.c.

1600{
1601 const TIFFField *fip = TIFFFindField(tif, tag, TIFF_ANY);
1602 return (fip && (isPseudoTag(tag) || TIFFFieldSet(tif, fip->field_bit))
1603 ? (*tif->tif_tagmethods.vgetfield)(tif, tag, ap)
1604 : 0);
1605}
TIFFVGetMethod vgetfield
Definition: tiffio.h:376
#define isPseudoTag(t)
Definition: tiffiop.h:272

Referenced by TIFFGetField(), and TIFFVGetFieldDefaulted().

◆ TIFFVGetFieldDefaulted()

int TIFFVGetFieldDefaulted ( TIFF tif,
uint32_t  tag,
va_list  ap 
)

Definition at line 217 of file tif_aux.c.

218{
219 TIFFDirectory *td = &tif->tif_dir;
220
221 if (TIFFVGetField(tif, tag, ap))
222 return (1);
223 switch (tag)
224 {
226 *va_arg(ap, uint32_t *) = td->td_subfiletype;
227 return (1);
230 return (1);
233 return (1);
235 *va_arg(ap, uint16_t *) = td->td_fillorder;
236 return (1);
238 *va_arg(ap, uint16_t *) = td->td_orientation;
239 return (1);
242 return (1);
245 return (1);
248 return (1);
250 {
251 uint16_t maxsamplevalue;
252 /* td_bitspersample=1 is always set in TIFFDefaultDirectory().
253 * Therefore, td_maxsamplevalue has to be re-calculated in
254 * TIFFGetFieldDefaulted(). */
255 if (td->td_bitspersample > 0)
256 {
257 /* This shift operation into a uint16_t limits the value to
258 * 65535 even if td_bitspersamle is > 16 */
259 if (td->td_bitspersample <= 16)
260 {
261 maxsamplevalue = (1 << td->td_bitspersample) -
262 1; /* 2**(BitsPerSample) - 1 */
263 }
264 else
265 {
266 maxsamplevalue = 65535;
267 }
268 }
269 else
270 {
271 maxsamplevalue = 0;
272 }
273 *va_arg(ap, uint16_t *) = maxsamplevalue;
274 return (1);
275 }
278 return (1);
281 return (1);
283 {
285 if (sp == NULL)
286 {
288 tif, tif->tif_name,
289 "Cannot get \"Predictor\" tag as plugin is not configured");
290 *va_arg(ap, uint16_t *) = 0;
291 return 0;
292 }
293 *va_arg(ap, uint16_t *) = (uint16_t)sp->predictor;
294 return 1;
295 }
296 case TIFFTAG_DOTRANGE:
297 *va_arg(ap, uint16_t *) = 0;
298 *va_arg(ap, uint16_t *) = (1 << td->td_bitspersample) - 1;
299 return (1);
300 case TIFFTAG_INKSET:
302 return 1;
304 *va_arg(ap, uint16_t *) = 4;
305 return (1);
308 *va_arg(ap, const uint16_t **) = td->td_sampleinfo;
309 return (1);
310 case TIFFTAG_MATTEING:
311 *va_arg(ap, uint16_t *) =
312 (td->td_extrasamples == 1 &&
314 return (1);
316 *va_arg(ap, uint32_t *) = td->td_tiledepth;
317 return (1);
318 case TIFFTAG_DATATYPE:
319 *va_arg(ap, uint16_t *) = td->td_sampleformat - 1;
320 return (1);
323 return (1);
325 *va_arg(ap, uint32_t *) = td->td_imagedepth;
326 return (1);
328 {
329 /* defaults are from CCIR Recommendation 601-1 */
330 static const float ycbcrcoeffs[] = {0.299f, 0.587f, 0.114f};
331 *va_arg(ap, const float **) = ycbcrcoeffs;
332 return 1;
333 }
337 return (1);
340 return (1);
342 {
343 /* TIFF 6.0 specification tells that it is no default
344 value for the WhitePoint, but AdobePhotoshop TIFF
345 Technical Note tells that it should be CIE D50. */
346 static const float whitepoint[] = {
347 D50_X0 / (D50_X0 + D50_Y0 + D50_Z0),
348 D50_Y0 / (D50_X0 + D50_Y0 + D50_Z0)};
349 *va_arg(ap, const float **) = whitepoint;
350 return 1;
351 }
353 if (!td->td_transferfunction[0] &&
355 {
356 TIFFErrorExtR(tif, tif->tif_name,
357 "No space for \"TransferFunction\" tag");
358 return (0);
359 }
360 *va_arg(ap, const uint16_t **) = td->td_transferfunction[0];
361 if (td->td_samplesperpixel - td->td_extrasamples > 1)
362 {
363 *va_arg(ap, const uint16_t **) = td->td_transferfunction[1];
364 *va_arg(ap, const uint16_t **) = td->td_transferfunction[2];
365 }
366 return (1);
368 if (!td->td_refblackwhite && !TIFFDefaultRefBlackWhite(tif, td))
369 return (0);
370 *va_arg(ap, const float **) = td->td_refblackwhite;
371 return (1);
372 }
373 return 0;
374}
#define va_arg(v, l)
Definition: stdarg.h:27
static const WCHAR sp[]
Definition: suminfo.c:287
uint8_t * tif_data
Definition: tiffiop.h:216
static int TIFFDefaultTransferFunction(TIFF *tif, TIFFDirectory *td)
Definition: tif_aux.c:128
static int TIFFDefaultRefBlackWhite(TIFF *tif, TIFFDirectory *td)
Definition: tif_aux.c:176
#define TIFFTAG_RESOLUTIONUNIT
Definition: tiff.h:287
#define TIFFTAG_WHITEPOINT
Definition: tiff.h:307
#define TIFFTAG_FILLORDER
Definition: tiff.h:240
#define TIFFTAG_INKSET
Definition: tiff.h:322
#define TIFFTAG_YCBCRCOEFFICIENTS
Definition: tiff.h:387
#define TIFFTAG_ORIENTATION
Definition: tiff.h:248
#define TIFFTAG_MATTEING
Definition: tiff.h:405
#define TIFFTAG_NUMBEROFINKS
Definition: tiff.h:326
#define INKSET_CMYK
Definition: tiff.h:323
#define TIFFTAG_REFERENCEBLACKWHITE
Definition: tiff.h:392
#define TIFFTAG_PREDICTOR
Definition: tiff.h:303
#define TIFFTAG_YCBCRPOSITIONING
Definition: tiff.h:389
#define TIFFTAG_THRESHHOLDING
Definition: tiff.h:234
#define D50_X0
Definition: tiffio.h:132
#define D50_Y0
Definition: tiffio.h:133
#define D50_Z0
Definition: tiffio.h:134

Referenced by TIFFGetFieldDefaulted().

◆ TIFFVSetField()

int TIFFVSetField ( TIFF tif,
uint32_t  tag,
va_list  ap 
)

Definition at line 1205 of file tif_dir.c.

1206{
1207 return OkToChangeTag(tif, tag)
1208 ? (*tif->tif_tagmethods.vsetfield)(tif, tag, ap)
1209 : 0;
1210}
TIFFVSetMethod vsetfield
Definition: tiffio.h:375
static int OkToChangeTag(TIFF *tif, uint32_t tag)
Definition: tif_dir.c:1113

Referenced by TIFFSetField().

◆ TIFFVStripSize()

tmsize_t TIFFVStripSize ( TIFF tif,
uint32_t  nrows 
)

Definition at line 142 of file tif_strip.c.

143{
144 static const char module[] = "TIFFVStripSize";
145 uint64_t m;
146 m = TIFFVStripSize64(tif, nrows);
147 return _TIFFCastUInt64ToSSize(tif, m, module);
148}

Referenced by TIFFReadEncodedStripGetStripSize().

◆ TIFFVStripSize64()

uint64_t TIFFVStripSize64 ( TIFF tif,
uint32_t  nrows 
)

Definition at line 88 of file tif_strip.c.

89{
90 static const char module[] = "TIFFVStripSize64";
91 TIFFDirectory *td = &tif->tif_dir;
92 if (nrows == (uint32_t)(-1))
93 nrows = td->td_imagelength;
96 {
97 /*
98 * Packed YCbCr data contain one Cb+Cr for every
99 * HorizontalSampling*VerticalSampling Y values.
100 * Must also roundup width and height when calculating
101 * since images that are not a multiple of the
102 * horizontal/vertical subsampling area include
103 * YCbCr data for the extended image.
104 */
105 uint16_t ycbcrsubsampling[2];
106 uint16_t samplingblock_samples;
107 uint32_t samplingblocks_hor;
108 uint32_t samplingblocks_ver;
109 uint64_t samplingrow_samples;
110 uint64_t samplingrow_size;
111 if (td->td_samplesperpixel != 3)
112 {
113 TIFFErrorExtR(tif, module, "Invalid td_samplesperpixel value");
114 return 0;
115 }
117 ycbcrsubsampling + 0, ycbcrsubsampling + 1);
118 if ((ycbcrsubsampling[0] != 1 && ycbcrsubsampling[0] != 2 &&
119 ycbcrsubsampling[0] != 4) ||
120 (ycbcrsubsampling[1] != 1 && ycbcrsubsampling[1] != 2 &&
121 ycbcrsubsampling[1] != 4) ||
122 (ycbcrsubsampling[0] == 0 || ycbcrsubsampling[1] == 0))
123 {
124 TIFFErrorExtR(tif, module, "Invalid YCbCr subsampling (%dx%d)",
125 ycbcrsubsampling[0], ycbcrsubsampling[1]);
126 return 0;
127 }
128 samplingblock_samples = ycbcrsubsampling[0] * ycbcrsubsampling[1] + 2;
129 samplingblocks_hor =
130 TIFFhowmany_32(td->td_imagewidth, ycbcrsubsampling[0]);
131 samplingblocks_ver = TIFFhowmany_32(nrows, ycbcrsubsampling[1]);
132 samplingrow_samples = _TIFFMultiply64(tif, samplingblocks_hor,
133 samplingblock_samples, module);
134 samplingrow_size = TIFFhowmany8_64(_TIFFMultiply64(
135 tif, samplingrow_samples, td->td_bitspersample, module));
136 return (
137 _TIFFMultiply64(tif, samplingrow_size, samplingblocks_ver, module));
138 }
139 else
140 return (_TIFFMultiply64(tif, nrows, TIFFScanlineSize64(tif), module));
141}

Referenced by TIFFStripSize64(), TIFFVStripSize(), and TryChopUpUncompressedBigTiff().

◆ TIFFVTileSize()

tmsize_t TIFFVTileSize ( TIFF tif,
uint32_t  nrows 
)

Definition at line 238 of file tif_tile.c.

239{
240 static const char module[] = "TIFFVTileSize";
241 uint64_t m;
242 m = TIFFVTileSize64(tif, nrows);
243 return _TIFFCastUInt64ToSSize(tif, m, module);
244}

◆ TIFFVTileSize64()

uint64_t TIFFVTileSize64 ( TIFF tif,
uint32_t  nrows 
)

Definition at line 188 of file tif_tile.c.

189{
190 static const char module[] = "TIFFVTileSize64";
191 TIFFDirectory *td = &tif->tif_dir;
192 if (td->td_tilelength == 0 || td->td_tilewidth == 0 ||
193 td->td_tiledepth == 0)
194 return (0);
197 (td->td_samplesperpixel == 3) && (!isUpSampled(tif)))
198 {
199 /*
200 * Packed YCbCr data contain one Cb+Cr for every
201 * HorizontalSampling*VerticalSampling Y values.
202 * Must also roundup width and height when calculating
203 * since images that are not a multiple of the
204 * horizontal/vertical subsampling area include
205 * YCbCr data for the extended image.
206 */
207 uint16_t ycbcrsubsampling[2];
208 uint16_t samplingblock_samples;
209 uint32_t samplingblocks_hor;
210 uint32_t samplingblocks_ver;
211 uint64_t samplingrow_samples;
212 uint64_t samplingrow_size;
214 ycbcrsubsampling + 0, ycbcrsubsampling + 1);
215 if ((ycbcrsubsampling[0] != 1 && ycbcrsubsampling[0] != 2 &&
216 ycbcrsubsampling[0] != 4) ||
217 (ycbcrsubsampling[1] != 1 && ycbcrsubsampling[1] != 2 &&
218 ycbcrsubsampling[1] != 4))
219 {
220 TIFFErrorExtR(tif, module, "Invalid YCbCr subsampling (%dx%d)",
221 ycbcrsubsampling[0], ycbcrsubsampling[1]);
222 return 0;
223 }
224 samplingblock_samples = ycbcrsubsampling[0] * ycbcrsubsampling[1] + 2;
225 samplingblocks_hor =
226 TIFFhowmany_32(td->td_tilewidth, ycbcrsubsampling[0]);
227 samplingblocks_ver = TIFFhowmany_32(nrows, ycbcrsubsampling[1]);
228 samplingrow_samples = _TIFFMultiply64(tif, samplingblocks_hor,
229 samplingblock_samples, module);
230 samplingrow_size = TIFFhowmany8_64(_TIFFMultiply64(
231 tif, samplingrow_samples, td->td_bitspersample, module));
232 return (
233 _TIFFMultiply64(tif, samplingrow_size, samplingblocks_ver, module));
234 }
235 else
236 return (_TIFFMultiply64(tif, nrows, TIFFTileRowSize64(tif), module));
237}

Referenced by ChopUpSingleUncompressedStrip(), TIFFTileSize64(), and TIFFVTileSize().

◆ TIFFWarning()

void void void TIFFWarning ( const char ,
const char ,
  ... 
)

◆ TIFFWarningExt()

void void void void TIFFWarningExt ( thandle_t  ,
const char ,
const char ,
  ... 
)

◆ TIFFWarningExtR()

void TIFFWarningExtR ( TIFF ,
const char ,
const char ,
  ... 
)

◆ TIFFWriteBufferSetup()

int TIFFWriteBufferSetup ( TIFF tif,
void bp,
tmsize_t  size 
)

Definition at line 677 of file tif_write.c.

678{
679 static const char module[] = "TIFFWriteBufferSetup";
680
681 if (tif->tif_rawdata)
682 {
683 if (tif->tif_flags & TIFF_MYBUFFER)
684 {
685 _TIFFfreeExt(tif, tif->tif_rawdata);
686 tif->tif_flags &= ~TIFF_MYBUFFER;
687 }
688 tif->tif_rawdata = NULL;
689 }
690 if (size == (tmsize_t)(-1))
691 {
692 size = (isTiled(tif) ? tif->tif_tilesize : TIFFStripSize(tif));
693
694 /* Adds 10% margin for cases where compression would expand a bit */
695 if (size < TIFF_TMSIZE_T_MAX - size / 10)
696 size += size / 10;
697 /*
698 * Make raw data buffer at least 8K
699 */
700 if (size < 8 * 1024)
701 size = 8 * 1024;
702 bp = NULL; /* NB: force malloc */
703 }
704 if (bp == NULL)
705 {
706 bp = _TIFFmallocExt(tif, size);
707 if (bp == NULL)
708 {
709 TIFFErrorExtR(tif, module, "No space for output buffer");
710 return (0);
711 }
712 tif->tif_flags |= TIFF_MYBUFFER;
713 }
714 else
715 tif->tif_flags &= ~TIFF_MYBUFFER;
716 tif->tif_rawdata = (uint8_t *)bp;
717 tif->tif_rawdatasize = size;
718 tif->tif_rawcc = 0;
719 tif->tif_rawcp = tif->tif_rawdata;
721 return (1);
722}
#define TIFF_TMSIZE_T_MAX
Definition: tiffio.h:68

Referenced by _TIFFReserveLargeEnoughWriteBuffer().

◆ TIFFWriteCheck()

int TIFFWriteCheck ( TIFF tif,
int  tiles,
const char module 
)

Definition at line 605 of file tif_write.c.

606{
607 if (tif->tif_mode == O_RDONLY)
608 {
609 TIFFErrorExtR(tif, module, "File not open for writing");
610 return (0);
611 }
612 if (tiles ^ isTiled(tif))
613 {
615 tiles ? "Can not write tiles to a striped image"
616 : "Can not write scanlines to a tiled image");
617 return (0);
618 }
619
620 _TIFFFillStriles(tif);
621
622 /*
623 * On the first write verify all the required information
624 * has been setup and initialize any data structures that
625 * had to wait until directory information was set.
626 * Note that a lot of our work is assumed to remain valid
627 * because we disallow any of the important parameters
628 * from changing after we start writing (i.e. once
629 * TIFF_BEENWRITING is set, TIFFSetField will only allow
630 * the image's length to be changed).
631 */
633 {
635 "Must set \"ImageWidth\" before writing data");
636 return (0);
637 }
638 if (tif->tif_dir.td_stripoffset_p == NULL && !TIFFSetupStrips(tif))
639 {
640 tif->tif_dir.td_nstrips = 0;
641 TIFFErrorExtR(tif, module, "No space for %s arrays",
642 isTiled(tif) ? "tile" : "strip");
643 return (0);
644 }
645 if (isTiled(tif))
646 {
647 tif->tif_tilesize = TIFFTileSize(tif);
648 if (tif->tif_tilesize == 0)
649 return (0);
650 }
651 else
652 tif->tif_tilesize = (tmsize_t)(-1);
654 if (tif->tif_scanlinesize == 0)
655 return (0);
657
658 if (tif->tif_dir.td_stripoffset_entry.tdir_tag != 0 &&
666 !(tif->tif_flags & TIFF_DIRTYDIRECT))
667 {
669 }
670
671 return (1);
672}

◆ TIFFWriteCustomDirectory()

int TIFFWriteCustomDirectory ( TIFF tif,
uint64_t pdiroff 
)

Definition at line 303 of file tif_dirwrite.c.

304{
305 return TIFFWriteDirectorySec(tif, FALSE, FALSE, pdiroff);
306}

◆ TIFFWriteDirectory()

int TIFFWriteDirectory ( TIFF tif)

Definition at line 238 of file tif_dirwrite.c.

239{
240 return TIFFWriteDirectorySec(tif, TRUE, TRUE, NULL);
241}

Referenced by tiff_encoder_create_frame(), and TIFFRewriteDirectorySec().

◆ TIFFWriteEncodedStrip()

tmsize_t TIFFWriteEncodedStrip ( TIFF tif,
uint32_t  strip,
void data,
tmsize_t  cc 
)

Definition at line 215 of file tif_write.c.

217{
218 static const char module[] = "TIFFWriteEncodedStrip";
219 TIFFDirectory *td = &tif->tif_dir;
220 uint16_t sample;
221
222 if (!WRITECHECKSTRIPS(tif, module))
223 return ((tmsize_t)-1);
224 /*
225 * Check strip array to make sure there's space.
226 * We don't support dynamically growing files that
227 * have data organized in separate bitplanes because
228 * it's too painful. In that case we require that
229 * the imagelength be set properly before the first
230 * write (so that the strips array will be fully
231 * allocated above).
232 */
233 if (strip >= td->td_nstrips)
234 {
236 {
238 tif, module,
239 "Can not grow image by strips when using separate planes");
240 return ((tmsize_t)-1);
241 }
242 if (!TIFFGrowStrips(tif, 1, module))
243 return ((tmsize_t)-1);
246 }
247 /*
248 * Handle delayed allocation of data buffer. This
249 * permits it to be sized according to the directory
250 * info.
251 */
252 if (!BUFFERCHECK(tif))
253 return ((tmsize_t)-1);
254
256
257 tif->tif_curstrip = strip;
258
259 /* this informs TIFFAppendToStrip() we have changed or reset strip */
260 tif->tif_curoff = 0;
261
262 if (!_TIFFReserveLargeEnoughWriteBuffer(tif, strip))
263 {
264 return ((tmsize_t)(-1));
265 }
266
267 tif->tif_rawcc = 0;
268 tif->tif_rawcp = tif->tif_rawdata;
269
270 if (td->td_stripsperimage == 0)
271 {
272 TIFFErrorExtR(tif, module, "Zero strips per image");
273 return ((tmsize_t)-1);
274 }
275
276 tif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip;
277 if ((tif->tif_flags & TIFF_CODERSETUP) == 0)
278 {
279 if (!(*tif->tif_setupencode)(tif))
280 return ((tmsize_t)-1);
282 }
283
284 tif->tif_flags &= ~TIFF_POSTENCODE;
285
286 /* shortcut to avoid an extra memcpy() */
288 {
289 /* swab if needed - note that source buffer will be altered */
290 tif->tif_postdecode(tif, (uint8_t *)data, cc);
291
292 if (!isFillOrder(tif, td->td_fillorder) &&
293 (tif->tif_flags & TIFF_NOBITREV) == 0)
295
296 if (cc > 0 && !TIFFAppendToStrip(tif, strip, (uint8_t *)data, cc))
297 return ((tmsize_t)-1);
298 return (cc);
299 }
300
301 sample = (uint16_t)(strip / td->td_stripsperimage);
302 if (!(*tif->tif_preencode)(tif, sample))
303 return ((tmsize_t)-1);
304
305 /* swab if needed - note that source buffer will be altered */
306 tif->tif_postdecode(tif, (uint8_t *)data, cc);
307
308 if (!(*tif->tif_encodestrip)(tif, (uint8_t *)data, cc, sample))
309 return ((tmsize_t)-1);
310 if (!(*tif->tif_postencode)(tif))
311 return ((tmsize_t)-1);
312 if (!isFillOrder(tif, td->td_fillorder) &&
313 (tif->tif_flags & TIFF_NOBITREV) == 0)
315 if (tif->tif_rawcc > 0 &&
316 !TIFFAppendToStrip(tif, strip, tif->tif_rawdata, tif->tif_rawcc))
317 return ((tmsize_t)-1);
318 tif->tif_rawcc = 0;
319 tif->tif_rawcp = tif->tif_rawdata;
320 return (cc);
321}
uint32_t cc
Definition: isohybrid.c:75
TIFFCodeMethod tif_encodestrip
Definition: tiffiop.h:208
TIFFPreMethod tif_preencode
Definition: tiffiop.h:203
TIFFBoolMethod tif_setupencode
Definition: tiffiop.h:201
#define BUFFERCHECK(tif)
Definition: tif_write.c:39
static int _TIFFReserveLargeEnoughWriteBuffer(TIFF *tif, uint32_t strip_or_tile)
Definition: tif_write.c:189
static int TIFFAppendToStrip(TIFF *tif, uint32_t strip, uint8_t *data, tmsize_t cc)
Definition: tif_write.c:764
static int TIFFGrowStrips(TIFF *tif, uint32_t delta, const char *module)
Definition: tif_write.c:727
#define WRITECHECKSTRIPS(tif, module)
Definition: tif_write.c:35
#define TIFF_CODERSETUP
Definition: tiffiop.h:122

◆ TIFFWriteEncodedTile()

tmsize_t TIFFWriteEncodedTile ( TIFF tif,
uint32_t  tile,
void data,
tmsize_t  cc 
)

Definition at line 414 of file tif_write.c.

415{
416 static const char module[] = "TIFFWriteEncodedTile";
417 TIFFDirectory *td;
418 uint16_t sample;
419 uint32_t howmany32;
420
421 if (!WRITECHECKTILES(tif, module))
422 return ((tmsize_t)(-1));
423 td = &tif->tif_dir;
424 if (tile >= td->td_nstrips)
425 {
426 TIFFErrorExtR(tif, module, "Tile %lu out of range, max %lu",
427 (unsigned long)tile, (unsigned long)td->td_nstrips);
428 return ((tmsize_t)(-1));
429 }
430 /*
431 * Handle delayed allocation of data buffer. This
432 * permits it to be sized more intelligently (using
433 * directory information).
434 */
435 if (!BUFFERCHECK(tif))
436 return ((tmsize_t)(-1));
437
439
440 tif->tif_curtile = tile;
441
442 /* this informs TIFFAppendToStrip() we have changed or reset tile */
443 tif->tif_curoff = 0;
444
446 {
447 return ((tmsize_t)(-1));
448 }
449
450 tif->tif_rawcc = 0;
451 tif->tif_rawcp = tif->tif_rawdata;
452
453 /*
454 * Compute tiles per row & per column to compute
455 * current row and column
456 */
457 howmany32 = TIFFhowmany_32(td->td_imagelength, td->td_tilelength);
458 if (howmany32 == 0)
459 {
460 TIFFErrorExtR(tif, module, "Zero tiles");
461 return ((tmsize_t)(-1));
462 }
463 tif->tif_row = (tile % howmany32) * td->td_tilelength;
464 howmany32 = TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth);
465 if (howmany32 == 0)
466 {
467 TIFFErrorExtR(tif, module, "Zero tiles");
468 return ((tmsize_t)(-1));
469 }
470 tif->tif_col = (tile % howmany32) * td->td_tilewidth;
471
472 if ((tif->tif_flags & TIFF_CODERSETUP) == 0)
473 {
474 if (!(*tif->tif_setupencode)(tif))
475 return ((tmsize_t)(-1));
477 }
478 tif->tif_flags &= ~TIFF_POSTENCODE;
479
480 /*
481 * Clamp write amount to the tile size. This is mostly
482 * done so that callers can pass in some large number
483 * (e.g. -1) and have the tile size used instead.
484 */
485 if (cc < 1 || cc > tif->tif_tilesize)
486 cc = tif->tif_tilesize;
487
488 /* shortcut to avoid an extra memcpy() */
490 {
491 /* swab if needed - note that source buffer will be altered */
492 tif->tif_postdecode(tif, (uint8_t *)data, cc);
493
494 if (!isFillOrder(tif, td->td_fillorder) &&
495 (tif->tif_flags & TIFF_NOBITREV) == 0)
497
498 if (cc > 0 && !TIFFAppendToStrip(tif, tile, (uint8_t *)data, cc))
499 return ((tmsize_t)-1);
500 return (cc);
501 }
502
503 sample = (uint16_t)(tile / td->td_stripsperimage);
504 if (!(*tif->tif_preencode)(tif, sample))
505 return ((tmsize_t)(-1));
506 /* swab if needed - note that source buffer will be altered */
507 tif->tif_postdecode(tif, (uint8_t *)data, cc);
508
509 if (!(*tif->tif_encodetile)(tif, (uint8_t *)data, cc, sample))
510 return ((tmsize_t)-1);
511 if (!(*tif->tif_postencode)(tif))
512 return ((tmsize_t)(-1));
513 if (!isFillOrder(tif, td->td_fillorder) &&
514 (tif->tif_flags & TIFF_NOBITREV) == 0)
516 if (tif->tif_rawcc > 0 &&
517 !TIFFAppendToStrip(tif, tile, tif->tif_rawdata, tif->tif_rawcc))
518 return ((tmsize_t)(-1));
519 tif->tif_rawcc = 0;
520 tif->tif_rawcp = tif->tif_rawdata;
521 return (cc);
522}
TIFFCodeMethod tif_encodetile
Definition: tiffiop.h:210
#define WRITECHECKTILES(tif, module)
Definition: tif_write.c:37

Referenced by TIFFWriteTile().

◆ TIFFWriteRawStrip()

tmsize_t TIFFWriteRawStrip ( TIFF tif,
uint32_t  strip,
void data,
tmsize_t  cc 
)

Definition at line 328 of file tif_write.c.

329{
330 static const char module[] = "TIFFWriteRawStrip";
331 TIFFDirectory *td = &tif->tif_dir;
332
333 if (!WRITECHECKSTRIPS(tif, module))
334 return ((tmsize_t)-1);
335 /*
336 * Check strip array to make sure there's space.
337 * We don't support dynamically growing files that
338 * have data organized in separate bitplanes because
339 * it's too painful. In that case we require that
340 * the imagelength be set properly before the first
341 * write (so that the strips array will be fully
342 * allocated above).
343 */
344 if (strip >= td->td_nstrips)
345 {
347 {
349 tif, module,
350 "Can not grow image by strips when using separate planes");
351 return ((tmsize_t)-1);
352 }
353 /*
354 * Watch out for a growing image. The value of
355 * strips/image will initially be 1 (since it
356 * can't be deduced until the imagelength is known).
357 */
358 if (strip >= td->td_stripsperimage)
361 if (!TIFFGrowStrips(tif, 1, module))
362 return ((tmsize_t)-1);
363 }
364
365 if (tif->tif_curstrip != strip)
366 {
367 tif->tif_curstrip = strip;
368
369 /* this informs TIFFAppendToStrip() we have changed or reset strip */
370 tif->tif_curoff = 0;
371 }
372
373 if (td->td_stripsperimage == 0)
374 {
375 TIFFErrorExtR(tif, module, "Zero strips per image");
376 return ((tmsize_t)-1);
377 }
378 tif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip;
379 return (TIFFAppendToStrip(tif, strip, (uint8_t *)data, cc) ? cc
380 : (tmsize_t)-1);
381}
return
Definition: dirsup.c:529

◆ TIFFWriteRawTile()

tmsize_t TIFFWriteRawTile ( TIFF tif,
uint32_t  tile,
void data,
tmsize_t  cc 
)

Definition at line 533 of file tif_write.c.

534{
535 static const char module[] = "TIFFWriteRawTile";
536
537 if (!WRITECHECKTILES(tif, module))
538 return ((tmsize_t)(-1));
539 if (tile >= tif->tif_dir.td_nstrips)
540 {
541 TIFFErrorExtR(tif, module, "Tile %lu out of range, max %lu",
542 (unsigned long)tile,
543 (unsigned long)tif->tif_dir.td_nstrips);
544 return ((tmsize_t)(-1));
545 }
546 return (TIFFAppendToStrip(tif, tile, (uint8_t *)data, cc) ? cc
547 : (tmsize_t)(-1));
548}

◆ TIFFWriteScanline()

int TIFFWriteScanline ( TIFF tif,
void buf,
uint32_t  row,
uint16_t  sample 
)

Definition at line 47 of file tif_write.c.

48{
49 static const char module[] = "TIFFWriteScanline";
50 register TIFFDirectory *td;
51 int status, imagegrew = 0;
52 uint32_t strip;
53
54 if (!WRITECHECKSTRIPS(tif, module))
55 return (-1);
56 /*
57 * Handle delayed allocation of data buffer. This
58 * permits it to be sized more intelligently (using
59 * directory information).
60 */
61 if (!BUFFERCHECK(tif))
62 return (-1);
63 tif->tif_flags |= TIFF_BUF4WRITE; /* not strictly sure this is right*/
64
65 td = &tif->tif_dir;
66 /*
67 * Extend image length if needed
68 * (but only for PlanarConfig=1).
69 */
70 if (row >= td->td_imagelength)
71 { /* extend image */
73 {
75 tif, module,
76 "Can not change \"ImageLength\" when using separate planes");
77 return (-1);
78 }
79 td->td_imagelength = row + 1;
80 imagegrew = 1;
81 }
82 /*
83 * Calculate strip and check for crossings.
84 */
86 {
87 if (sample >= td->td_samplesperpixel)
88 {
89 TIFFErrorExtR(tif, module, "%lu: Sample out of range, max %lu",
90 (unsigned long)sample,
91 (unsigned long)td->td_samplesperpixel);
92 return (-1);
93 }
94 strip = sample * td->td_stripsperimage + row / td->td_rowsperstrip;
95 }
96 else
97 strip = row / td->td_rowsperstrip;
98 /*
99 * Check strip array to make sure there's space. We don't support
100 * dynamically growing files that have data organized in separate
101 * bitplanes because it's too painful. In that case we require that
102 * the imagelength be set properly before the first write (so that the
103 * strips array will be fully allocated above).
104 */
105 if (strip >= td->td_nstrips && !TIFFGrowStrips(tif, 1, module))
106 return (-1);
107 if (strip != tif->tif_curstrip)
108 {
109 /*
110 * Changing strips -- flush any data present.
111 */
112 if (!TIFFFlushData(tif))
113 return (-1);
114 tif->tif_curstrip = strip;
115 /*
116 * Watch out for a growing image. The value of strips/image
117 * will initially be 1 (since it can't be deduced until the
118 * imagelength is known).
119 */
120 if (strip >= td->td_stripsperimage && imagegrew)
123 if (td->td_stripsperimage == 0)
124 {
125 TIFFErrorExtR(tif, module, "Zero strips per image");
126 return (-1);
127 }
128 tif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip;
129 if ((tif->tif_flags & TIFF_CODERSETUP) == 0)
130 {
131 if (!(*tif->tif_setupencode)(tif))
132 return (-1);
134 }
135
136 tif->tif_rawcc = 0;
137 tif->tif_rawcp = tif->tif_rawdata;
138
139 /* this informs TIFFAppendToStrip() we have changed strip */
140 tif->tif_curoff = 0;
141
142 if (!(*tif->tif_preencode)(tif, sample))
143 return (-1);
145 }
146 /*
147 * Ensure the write is either sequential or at the
148 * beginning of a strip (or that we can randomly
149 * access the data -- i.e. no encoding).
150 */
151 if (row != tif->tif_row)
152 {
153 if (row < tif->tif_row)
154 {
155 /*
156 * Moving backwards within the same strip:
157 * backup to the start and then decode
158 * forward (below).
159 */
160 tif->tif_row =
161 (strip % td->td_stripsperimage) * td->td_rowsperstrip;
162 tif->tif_rawcp = tif->tif_rawdata;
163 }
164 /*
165 * Seek forward to the desired row.
166 */
167 if (!(*tif->tif_seek)(tif, row - tif->tif_row))
168 return (-1);
169 tif->tif_row = row;
170 }
171
172 /* swab if needed - note that source buffer will be altered */
173 tif->tif_postdecode(tif, (uint8_t *)buf, tif->tif_scanlinesize);
174
175 status = (*tif->tif_encoderow)(tif, (uint8_t *)buf, tif->tif_scanlinesize,
176 sample);
177
178 /* we are now poised at the beginning of the next row */
179 tif->tif_row = row + 1;
180 return (status);
181}
TIFFSeekMethod tif_seek
Definition: tiffiop.h:212
TIFFCodeMethod tif_encoderow
Definition: tiffiop.h:206

Referenced by tiff_encoder_write_lines().

◆ TIFFWriteTile()

tmsize_t TIFFWriteTile ( TIFF tif,
void buf,
uint32_t  x,
uint32_t  y,
uint32_t  z,
uint16_t  s 
)

Definition at line 387 of file tif_write.c.

389{
390 if (!TIFFCheckTile(tif, x, y, z, s))
391 return ((tmsize_t)(-1));
392 /*
393 * NB: A tile size of -1 is used instead of tif_tilesize knowing
394 * that TIFFWriteEncodedTile will clamp this to the tile size.
395 * This is done because the tile size may not be defined until
396 * after the output buffer is setup in TIFFWriteBufferSetup.
397 */
398 return (TIFFWriteEncodedTile(tif, TIFFComputeTile(tif, x, y, z, s), buf,
399 (tmsize_t)(-1)));
400}
tmsize_t TIFFWriteEncodedTile(TIFF *tif, uint32_t tile, void *data, tmsize_t cc)
Definition: tif_write.c:414

◆ TIFFXYZToRGB()

void TIFFXYZToRGB ( TIFFCIELabToRGB cielab,
float  X,
float  Y,
float  Z,
uint32_t r,
uint32_t g,
uint32_t b 
)

Definition at line 89 of file tif_color.c.

91{
92 size_t i;
93 float Yr, Yg, Yb;
94 float *matrix = &cielab->display.d_mat[0][0];
95
96 /* Multiply through the matrix to get luminosity values. */
97 Yr = matrix[0] * X + matrix[1] * Y + matrix[2] * Z;
98 Yg = matrix[3] * X + matrix[4] * Y + matrix[5] * Z;
99 Yb = matrix[6] * X + matrix[7] * Y + matrix[8] * Z;
100
101 /* Clip input */
102 Yr = TIFFmax(Yr, cielab->display.d_Y0R);
103 Yg = TIFFmax(Yg, cielab->display.d_Y0G);
104 Yb = TIFFmax(Yb, cielab->display.d_Y0B);
105
106 /* Avoid overflow in case of wrong input values */
107 Yr = TIFFmin(Yr, cielab->display.d_YCR);
108 Yg = TIFFmin(Yg, cielab->display.d_YCG);
109 Yb = TIFFmin(Yb, cielab->display.d_YCB);
110
111 /* Turn luminosity to colour value. */
112 i = (size_t)((Yr - cielab->display.d_Y0R) / cielab->rstep);
113 i = TIFFmin((size_t)cielab->range, i);
114 *r = RINT(cielab->Yr2r[i]);
115
116 i = (size_t)((Yg - cielab->display.d_Y0G) / cielab->gstep);
117 i = TIFFmin((size_t)cielab->range, i);
118 *g = RINT(cielab->Yg2g[i]);
119
120 i = (size_t)((Yb - cielab->display.d_Y0B) / cielab->bstep);
121 i = TIFFmin((size_t)cielab->range, i);
122 *b = RINT(cielab->Yb2b[i]);
123
124 /* Clip output. */
125 *r = TIFFmin(*r, cielab->display.d_Vrwr);
126 *g = TIFFmin(*g, cielab->display.d_Vrwg);
127 *b = TIFFmin(*b, cielab->display.d_Vrwb);
128}
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLuint GLenum matrix
Definition: glext.h:9407
GLboolean GLboolean g
Definition: glext.h:6204
#define Yb
Definition: i386-dis.c:436
float d_mat[3][3]
Definition: tiffio.h:142
float d_YCB
Definition: tiffio.h:145
float d_YCG
Definition: tiffio.h:144
float d_Y0G
Definition: tiffio.h:150
float d_Y0B
Definition: tiffio.h:151
#define RINT(R)
Definition: tif_color.c:85
#define TIFFmax(A, B)
Definition: tiffiop.h:330
#define TIFFmin(A, B)
Definition: tiffiop.h:331

Referenced by DECLAREContigPutFunc().

◆ TIFFYCbCrtoRGB()

void TIFFYCbCrtoRGB ( TIFFYCbCrToRGB ycbcr,
uint32_t  Y,
int32_t  Cb,
int32_t  Cr,
uint32_t r,
uint32_t g,
uint32_t b 
)

Definition at line 199 of file tif_color.c.

201{
202 int32_t i;
203
204 /* XXX: Only 8-bit YCbCr input supported for now */
205 Y = HICLAMP(Y, 255);
206 Cb = CLAMP(Cb, 0, 255);
207 Cr = CLAMP(Cr, 0, 255);
208
209 i = ycbcr->Y_tab[Y] + ycbcr->Cr_r_tab[Cr];
210 *r = CLAMP(i, 0, 255);
211 i = ycbcr->Y_tab[Y] +
212 (int)((ycbcr->Cb_g_tab[Cb] + ycbcr->Cr_g_tab[Cr]) >> SHIFT);
213 *g = CLAMP(i, 0, 255);
214 i = ycbcr->Y_tab[Y] + ycbcr->Cb_b_tab[Cb];
215 *b = CLAMP(i, 0, 255);
216}
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
int * Cr_r_tab
Definition: tiffio.h:172
int32_t * Cb_g_tab
Definition: tiffio.h:175
int32_t * Y_tab
Definition: tiffio.h:176
int * Cb_b_tab
Definition: tiffio.h:173
int32_t * Cr_g_tab
Definition: tiffio.h:174
#define CLAMP(f, min, max)
Definition: tif_color.c:195
#define SHIFT
Definition: tif_color.c:188
#define HICLAMP(f, max)
Definition: tif_color.c:197

Referenced by DECLARESepPutFunc().

◆ TIFFYCbCrToRGBInit()

int TIFFYCbCrToRGBInit ( TIFFYCbCrToRGB ycbcr,
float luma,
float refBlackWhite 
)

Definition at line 251 of file tif_color.c.

252{
253 TIFFRGBValue *clamptab;
254 int i;
255
256#define LumaRed luma[0]
257#define LumaGreen luma[1]
258#define LumaBlue luma[2]
259
260 clamptab =
261 (TIFFRGBValue *)((uint8_t *)ycbcr +
262 TIFFroundup_32(sizeof(TIFFYCbCrToRGB), sizeof(long)));
263 _TIFFmemset(clamptab, 0, 256); /* v < 0 => 0 */
264 ycbcr->clamptab = (clamptab += 256);
265 for (i = 0; i < 256; i++)
266 clamptab[i] = (TIFFRGBValue)i;
267 _TIFFmemset(clamptab + 256, 255, 2 * 256); /* v > 255 => 255 */
268 ycbcr->Cr_r_tab = (int *)(clamptab + 3 * 256);
269 ycbcr->Cb_b_tab = ycbcr->Cr_r_tab + 256;
270 ycbcr->Cr_g_tab = (int32_t *)(ycbcr->Cb_b_tab + 256);
271 ycbcr->Cb_g_tab = ycbcr->Cr_g_tab + 256;
272 ycbcr->Y_tab = ycbcr->Cb_g_tab + 256;
273
274 {
275 float f1 = 2 - 2 * LumaRed;
276 int32_t D1 = FIX(CLAMP(f1, 0.0F, 2.0F));
277 float f2 = LumaRed * f1 / LumaGreen;
278 int32_t D2 = -FIX(CLAMP(f2, 0.0F, 2.0F));
279 float f3 = 2 - 2 * LumaBlue;
280 int32_t D3 = FIX(CLAMP(f3, 0.0F, 2.0F));
281 float f4 = LumaBlue * f3 / LumaGreen;
282 int32_t D4 = -FIX(CLAMP(f4, 0.0F, 2.0F));
283 int x;
284
285#undef LumaBlue
286#undef LumaGreen
287#undef LumaRed
288
289 /*
290 * i is the actual input pixel value in the range 0..255
291 * Cb and Cr values are in the range -128..127 (actually
292 * they are in a range defined by the ReferenceBlackWhite
293 * tag) so there is some range shifting to do here when
294 * constructing tables indexed by the raw pixel data.
295 */
296 for (i = 0, x = -128; i < 256; i++, x++)
297 {
298 int32_t Cr = (int32_t)CLAMPw(Code2V(x, refBlackWhite[4] - 128.0F,
299 refBlackWhite[5] - 128.0F, 127),
300 -128.0F * 32, 128.0F * 32);
301 int32_t Cb = (int32_t)CLAMPw(Code2V(x, refBlackWhite[2] - 128.0F,
302 refBlackWhite[3] - 128.0F, 127),
303 -128.0F * 32, 128.0F * 32);
304
305 ycbcr->Cr_r_tab[i] = (int32_t)((D1 * Cr + ONE_HALF) >> SHIFT);
306 ycbcr->Cb_b_tab[i] = (int32_t)((D3 * Cb + ONE_HALF) >> SHIFT);
307 ycbcr->Cr_g_tab[i] = D2 * Cr;
308 ycbcr->Cb_g_tab[i] = D4 * Cb + ONE_HALF;
309 ycbcr->Y_tab[i] = (int32_t)CLAMPw(
310 Code2V(x + 128, refBlackWhite[0], refBlackWhite[1], 255),
311 -128.0F * 32, 128.0F * 32);
312 }
313 }
314
315 return 0;
316}
#define int32_t
Definition: nsiface.idl:56
#define f2(x, y, z)
Definition: sha1.c:31
#define f1(x, y, z)
Definition: sha1.c:30
#define f4(x, y, z)
Definition: sha1.c:33
#define f3(x, y, z)
Definition: sha1.c:32
TIFFRGBValue * clamptab
Definition: tiffio.h:171
static float CLAMPw(float v, float vmin, float vmax)
Definition: tif_color.c:220
#define LumaRed
#define LumaBlue
#define FIX(x)
Definition: tif_color.c:189
#define Code2V(c, RB, RW, CR)
Definition: tif_color.c:191
#define ONE_HALF
Definition: tif_color.c:190
#define LumaGreen
unsigned char TIFFRGBValue
Definition: tiffio.h:138

Referenced by initYCbCrConversion().

◆ uv_decode()

int uv_decode ( double ,
double ,
int   
)

◆ uv_encode()

int uv_encode ( double  ,
double  ,
int   
)

◆ XYZtoRGB24()

void XYZtoRGB24 ( float ,
uint8_t  
)