ReactOS 0.4.15-dev-7961-gdcf9eb0
tif_dir.c File Reference
#include <precomp.h>
#include <float.h>
Include dependency graph for tif_dir.c:

Go to the source code of this file.

Macros

#define DATATYPE_VOID   0 /* !untyped data */
 
#define DATATYPE_INT   1 /* !signed integer data */
 
#define DATATYPE_UINT   2 /* !unsigned integer data */
 
#define DATATYPE_IEEEFP   3 /* !IEEE floating point data */
 
#define EXTRASAMPLE_COREL_UNASSALPHA   999
 
#define CleanupField(member)
 

Functions

static void setByteArray (void **vpp, void *vp, size_t nmemb, size_t elem_size)
 
void _TIFFsetByteArray (void **vpp, void *vp, uint32 n)
 
void _TIFFsetString (char **cpp, char *cp)
 
static void _TIFFsetNString (char **cpp, char *cp, uint32 n)
 
void _TIFFsetShortArray (uint16 **wpp, uint16 *wp, uint32 n)
 
void _TIFFsetLongArray (uint32 **lpp, uint32 *lp, uint32 n)
 
static void _TIFFsetLong8Array (uint64 **lpp, uint64 *lp, uint32 n)
 
void _TIFFsetFloatArray (float **fpp, float *fp, uint32 n)
 
void _TIFFsetDoubleArray (double **dpp, double *dp, uint32 n)
 
static void setDoubleArrayOneValue (double **vpp, double value, size_t nmemb)
 
static int setExtraSamples (TIFF *tif, va_list ap, uint32 *v)
 
static uint32 checkInkNamesString (TIFF *tif, uint32 slen, const char *s)
 
static int _TIFFVSetField (TIFF *tif, uint32 tag, va_list ap)
 
static int OkToChangeTag (TIFF *tif, uint32 tag)
 
int TIFFSetField (TIFF *tif, uint32 tag,...)
 
int TIFFUnsetField (TIFF *tif, uint32 tag)
 
int TIFFVSetField (TIFF *tif, uint32 tag, va_list ap)
 
static int _TIFFVGetField (TIFF *tif, uint32 tag, va_list ap)
 
int TIFFGetField (TIFF *tif, uint32 tag,...)
 
int TIFFVGetField (TIFF *tif, uint32 tag, va_list ap)
 
void TIFFFreeDirectory (TIFF *tif)
 
TIFFExtendProc TIFFSetTagExtender (TIFFExtendProc extender)
 
int TIFFCreateDirectory (TIFF *tif)
 
int TIFFCreateCustomDirectory (TIFF *tif, const TIFFFieldArray *infoarray)
 
int TIFFCreateEXIFDirectory (TIFF *tif)
 
int TIFFDefaultDirectory (TIFF *tif)
 
static int TIFFAdvanceDirectory (TIFF *tif, uint64 *nextdir, uint64 *off)
 
uint16 TIFFNumberOfDirectories (TIFF *tif)
 
int TIFFSetDirectory (TIFF *tif, uint16 dirn)
 
int TIFFSetSubDirectory (TIFF *tif, uint64 diroff)
 
uint64 TIFFCurrentDirOffset (TIFF *tif)
 
int TIFFLastDirectory (TIFF *tif)
 
int TIFFUnlinkDirectory (TIFF *tif, uint16 dirn)
 

Variables

static TIFFExtendProc _TIFFextender = (TIFFExtendProc) NULL
 

Macro Definition Documentation

◆ CleanupField

#define CleanupField (   member)
Value:
{ \
if (td->member) { \
_TIFFfree(td->member); \
td->member = 0; \
} \
}

Definition at line 1257 of file tif_dir.c.

◆ DATATYPE_IEEEFP

#define DATATYPE_IEEEFP   3 /* !IEEE floating point data */

Definition at line 40 of file tif_dir.c.

◆ DATATYPE_INT

#define DATATYPE_INT   1 /* !signed integer data */

Definition at line 38 of file tif_dir.c.

◆ DATATYPE_UINT

#define DATATYPE_UINT   2 /* !unsigned integer data */

Definition at line 39 of file tif_dir.c.

◆ DATATYPE_VOID

#define DATATYPE_VOID   0 /* !untyped data */

Definition at line 37 of file tif_dir.c.

◆ EXTRASAMPLE_COREL_UNASSALPHA

#define EXTRASAMPLE_COREL_UNASSALPHA   999

Function Documentation

◆ _TIFFsetByteArray()

void _TIFFsetByteArray ( void **  vpp,
void vp,
uint32  n 
)

Definition at line 57 of file tif_dir.c.

58 { setByteArray(vpp, vp, n, 1); }
GLdouble n
Definition: glext.h:7729
static void setByteArray(void **vpp, void *vp, size_t nmemb, size_t elem_size)
Definition: tif_dir.c:43

◆ _TIFFsetDoubleArray()

void _TIFFsetDoubleArray ( double **  dpp,
double dp,
uint32  n 
)

Definition at line 71 of file tif_dir.c.

72 { setByteArray((void**) dpp, (void*) dp, n, sizeof (double)); }

Referenced by _TIFFVSetField().

◆ _TIFFsetFloatArray()

void _TIFFsetFloatArray ( float **  fpp,
float fp,
uint32  n 
)

Definition at line 69 of file tif_dir.c.

70 { setByteArray((void**) fpp, (void*) fp, n, sizeof (float)); }

Referenced by _TIFFVSetField().

◆ _TIFFsetLong8Array()

static void _TIFFsetLong8Array ( uint64 **  lpp,
uint64 lp,
uint32  n 
)
static

Definition at line 67 of file tif_dir.c.

68 { setByteArray((void**) lpp, (void*) lp, n, sizeof (uint64)); }
unsigned long long uint64
Definition: platform.h:18

Referenced by _TIFFVSetField().

◆ _TIFFsetLongArray()

void _TIFFsetLongArray ( uint32 **  lpp,
uint32 lp,
uint32  n 
)

Definition at line 65 of file tif_dir.c.

66 { setByteArray((void**) lpp, (void*) lp, n, sizeof (uint32)); }
unsigned int uint32
Definition: types.h:32

◆ _TIFFsetNString()

static void _TIFFsetNString ( char **  cpp,
char cp,
uint32  n 
)
static

Definition at line 61 of file tif_dir.c.

62 { setByteArray((void**) cpp, (void*) cp, n, 1); }
POINT cp
Definition: magnifier.c:59

Referenced by _TIFFVSetField().

◆ _TIFFsetShortArray()

void _TIFFsetShortArray ( uint16 **  wpp,
uint16 wp,
uint32  n 
)

Definition at line 63 of file tif_dir.c.

64 { setByteArray((void**) wpp, (void*) wp, n, sizeof (uint16)); }
unsigned short uint16
Definition: types.h:30

Referenced by _TIFFVSetField(), setExtraSamples(), and TIFFReadDirectory().

◆ _TIFFsetString()

void _TIFFsetString ( char **  cpp,
char cp 
)

Definition at line 59 of file tif_dir.c.

60 { setByteArray((void**) cpp, (void*) cp, strlen(cp)+1, 1); }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269

◆ _TIFFVGetField()

static int _TIFFVGetField ( TIFF tif,
uint32  tag,
va_list  ap 
)
static

Definition at line 873 of file tif_dir.c.

874{
875 TIFFDirectory* td = &tif->tif_dir;
876 int ret_val = 1;
877 uint32 standard_tag = tag;
878 const TIFFField* fip = TIFFFindField(tif, tag, TIFF_ANY);
879 if( fip == NULL ) /* cannot happen since TIFFGetField() already checks it */
880 return 0;
881
882 /*
883 * We want to force the custom code to be used for custom
884 * fields even if the tag happens to match a well known
885 * one - important for reinterpreted handling of standard
886 * tag values in custom directories (i.e. EXIF)
887 */
888 if (fip->field_bit == FIELD_CUSTOM) {
889 standard_tag = 0;
890 }
891
892 if( standard_tag == TIFFTAG_NUMBEROFINKS )
893 {
894 int i;
895 for (i = 0; i < td->td_customValueCount; i++) {
896 uint16 val;
897 TIFFTagValue *tv = td->td_customValues + i;
898 if (tv->info->field_tag != standard_tag)
899 continue;
900 if( tv->value == NULL )
901 return 0;
902 val = *(uint16 *)tv->value;
903 /* Truncate to SamplesPerPixel, since the */
904 /* setting code for INKNAMES assume that there are SamplesPerPixel */
905 /* inknames. */
906 /* Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2599 */
907 if( val > td->td_samplesperpixel )
908 {
909 TIFFWarningExt(tif->tif_clientdata,"_TIFFVGetField",
910 "Truncating NumberOfInks from %u to %u",
913 }
914 *va_arg(ap, uint16*) = val;
915 return 1;
916 }
917 return 0;
918 }
919
920 switch (standard_tag) {
922 *va_arg(ap, uint32*) = td->td_subfiletype;
923 break;
925 *va_arg(ap, uint32*) = td->td_imagewidth;
926 break;
928 *va_arg(ap, uint32*) = td->td_imagelength;
929 break;
932 break;
934 *va_arg(ap, uint16*) = td->td_compression;
935 break;
937 *va_arg(ap, uint16*) = td->td_photometric;
938 break;
941 break;
943 *va_arg(ap, uint16*) = td->td_fillorder;
944 break;
946 *va_arg(ap, uint16*) = td->td_orientation;
947 break;
950 break;
953 break;
956 break;
959 break;
961 if (tif->tif_flags & TIFF_PERSAMPLE)
962 *va_arg(ap, double**) = td->td_sminsamplevalue;
963 else
964 {
965 /* libtiff historically treats this as a single value. */
966 uint16 i;
967 double v = td->td_sminsamplevalue[0];
968 for (i=1; i < td->td_samplesperpixel; ++i)
969 if( td->td_sminsamplevalue[i] < v )
970 v = td->td_sminsamplevalue[i];
971 *va_arg(ap, double*) = v;
972 }
973 break;
975 if (tif->tif_flags & TIFF_PERSAMPLE)
976 *va_arg(ap, double**) = td->td_smaxsamplevalue;
977 else
978 {
979 /* libtiff historically treats this as a single value. */
980 uint16 i;
981 double v = td->td_smaxsamplevalue[0];
982 for (i=1; i < td->td_samplesperpixel; ++i)
983 if( td->td_smaxsamplevalue[i] > v )
984 v = td->td_smaxsamplevalue[i];
985 *va_arg(ap, double*) = v;
986 }
987 break;
989 *va_arg(ap, float*) = td->td_xresolution;
990 break;
992 *va_arg(ap, float*) = td->td_yresolution;
993 break;
996 break;
998 *va_arg(ap, float*) = td->td_xposition;
999 break;
1000 case TIFFTAG_YPOSITION:
1001 *va_arg(ap, float*) = td->td_yposition;
1002 break;
1005 break;
1006 case TIFFTAG_PAGENUMBER:
1007 *va_arg(ap, uint16*) = td->td_pagenumber[0];
1008 *va_arg(ap, uint16*) = td->td_pagenumber[1];
1009 break;
1011 *va_arg(ap, uint16*) = td->td_halftonehints[0];
1012 *va_arg(ap, uint16*) = td->td_halftonehints[1];
1013 break;
1014 case TIFFTAG_COLORMAP:
1015 *va_arg(ap, uint16**) = td->td_colormap[0];
1016 *va_arg(ap, uint16**) = td->td_colormap[1];
1017 *va_arg(ap, uint16**) = td->td_colormap[2];
1018 break;
1021 _TIFFFillStriles( tif );
1022 *va_arg(ap, uint64**) = td->td_stripoffset_p;
1023 break;
1026 _TIFFFillStriles( tif );
1028 break;
1029 case TIFFTAG_MATTEING:
1030 *va_arg(ap, uint16*) =
1031 (td->td_extrasamples == 1 &&
1033 break;
1035 *va_arg(ap, uint16*) = td->td_extrasamples;
1036 *va_arg(ap, uint16**) = td->td_sampleinfo;
1037 break;
1038 case TIFFTAG_TILEWIDTH:
1039 *va_arg(ap, uint32*) = td->td_tilewidth;
1040 break;
1041 case TIFFTAG_TILELENGTH:
1042 *va_arg(ap, uint32*) = td->td_tilelength;
1043 break;
1044 case TIFFTAG_TILEDEPTH:
1045 *va_arg(ap, uint32*) = td->td_tiledepth;
1046 break;
1047 case TIFFTAG_DATATYPE:
1048 switch (td->td_sampleformat) {
1049 case SAMPLEFORMAT_UINT:
1051 break;
1052 case SAMPLEFORMAT_INT:
1054 break;
1057 break;
1058 case SAMPLEFORMAT_VOID:
1060 break;
1061 }
1062 break;
1064 *va_arg(ap, uint16*) = td->td_sampleformat;
1065 break;
1066 case TIFFTAG_IMAGEDEPTH:
1067 *va_arg(ap, uint32*) = td->td_imagedepth;
1068 break;
1069 case TIFFTAG_SUBIFD:
1070 *va_arg(ap, uint16*) = td->td_nsubifd;
1071 *va_arg(ap, uint64**) = td->td_subifd;
1072 break;
1075 break;
1077 *va_arg(ap, uint16*) = td->td_ycbcrsubsampling[0];
1078 *va_arg(ap, uint16*) = td->td_ycbcrsubsampling[1];
1079 break;
1081 *va_arg(ap, uint16**) = td->td_transferfunction[0];
1082 if (td->td_samplesperpixel - td->td_extrasamples > 1) {
1083 *va_arg(ap, uint16**) = td->td_transferfunction[1];
1084 *va_arg(ap, uint16**) = td->td_transferfunction[2];
1085 } else {
1086 *va_arg(ap, uint16**) = NULL;
1087 *va_arg(ap, uint16**) = NULL;
1088 }
1089 break;
1091 *va_arg(ap, float**) = td->td_refblackwhite;
1092 break;
1093 case TIFFTAG_INKNAMES:
1094 *va_arg(ap, char**) = td->td_inknames;
1095 break;
1096 default:
1097 {
1098 int i;
1099
1100 /*
1101 * This can happen if multiple images are open
1102 * with different codecs which have private
1103 * tags. The global tag information table may
1104 * then have tags that are valid for one file
1105 * but not the other. If the client tries to
1106 * get a tag that is not valid for the image's
1107 * codec then we'll arrive here.
1108 */
1109 if( fip->field_bit != FIELD_CUSTOM )
1110 {
1111 TIFFErrorExt(tif->tif_clientdata, "_TIFFVGetField",
1112 "%s: Invalid %stag \"%s\" "
1113 "(not supported by codec)",
1114 tif->tif_name,
1115 isPseudoTag(tag) ? "pseudo-" : "",
1116 fip->field_name);
1117 ret_val = 0;
1118 break;
1119 }
1120
1121 /*
1122 * Do we have a custom value?
1123 */
1124 ret_val = 0;
1125 for (i = 0; i < td->td_customValueCount; i++) {
1126 TIFFTagValue *tv = td->td_customValues + i;
1127
1128 if (tv->info->field_tag != tag)
1129 continue;
1130
1131 if (fip->field_passcount) {
1132 if (fip->field_readcount == TIFF_VARIABLE2)
1133 *va_arg(ap, uint32*) = (uint32)tv->count;
1134 else /* Assume TIFF_VARIABLE */
1135 *va_arg(ap, uint16*) = (uint16)tv->count;
1136 *va_arg(ap, void **) = tv->value;
1137 ret_val = 1;
1138 } else if (fip->field_tag == TIFFTAG_DOTRANGE
1139 && strcmp(fip->field_name,"DotRange") == 0) {
1140 /* TODO: This is an evil exception and should not have been
1141 handled this way ... likely best if we move it into
1142 the directory structure with an explicit field in
1143 libtiff 4.1 and assign it a FIELD_ value */
1144 *va_arg(ap, uint16*) = ((uint16 *)tv->value)[0];
1145 *va_arg(ap, uint16*) = ((uint16 *)tv->value)[1];
1146 ret_val = 1;
1147 } else {
1148 if (fip->field_type == TIFF_ASCII
1151 || fip->field_readcount == TIFF_SPP
1152 || tv->count > 1) {
1153 *va_arg(ap, void **) = tv->value;
1154 ret_val = 1;
1155 } else {
1156 char *val = (char *)tv->value;
1157 assert( tv->count == 1 );
1158 switch (fip->field_type) {
1159 case TIFF_BYTE:
1160 case TIFF_UNDEFINED:
1161 *va_arg(ap, uint8*) =
1162 *(uint8 *)val;
1163 ret_val = 1;
1164 break;
1165 case TIFF_SBYTE:
1166 *va_arg(ap, int8*) =
1167 *(int8 *)val;
1168 ret_val = 1;
1169 break;
1170 case TIFF_SHORT:
1171 *va_arg(ap, uint16*) =
1172 *(uint16 *)val;
1173 ret_val = 1;
1174 break;
1175 case TIFF_SSHORT:
1176 *va_arg(ap, int16*) =
1177 *(int16 *)val;
1178 ret_val = 1;
1179 break;
1180 case TIFF_LONG:
1181 case TIFF_IFD:
1182 *va_arg(ap, uint32*) =
1183 *(uint32 *)val;
1184 ret_val = 1;
1185 break;
1186 case TIFF_SLONG:
1187 *va_arg(ap, int32*) =
1188 *(int32 *)val;
1189 ret_val = 1;
1190 break;
1191 case TIFF_LONG8:
1192 case TIFF_IFD8:
1193 *va_arg(ap, uint64*) =
1194 *(uint64 *)val;
1195 ret_val = 1;
1196 break;
1197 case TIFF_SLONG8:
1198 *va_arg(ap, int64*) =
1199 *(int64 *)val;
1200 ret_val = 1;
1201 break;
1202 case TIFF_RATIONAL:
1203 case TIFF_SRATIONAL:
1204 case TIFF_FLOAT:
1205 *va_arg(ap, float*) =
1206 *(float *)val;
1207 ret_val = 1;
1208 break;
1209 case TIFF_DOUBLE:
1210 *va_arg(ap, double*) =
1211 *(double *)val;
1212 ret_val = 1;
1213 break;
1214 default:
1215 ret_val = 0;
1216 break;
1217 }
1218 }
1219 }
1220 break;
1221 }
1222 }
1223 }
1224 return(ret_val);
1225}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define va_arg(ap, T)
Definition: acmsvcex.h:89
unsigned char uint8
Definition: types.h:28
#define NULL
Definition: types.h:112
#define assert(x)
Definition: debug.h:53
short int16
Definition: platform.h:11
long int32
Definition: platform.h:12
char int8
Definition: platform.h:10
long long int64
Definition: platform.h:13
const GLdouble * v
Definition: gl.h:2040
GLuint GLfloat * val
Definition: glext.h:7180
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
int td_customValueCount
Definition: tif_dir.h:121
float td_xposition
Definition: tif_dir.h:90
uint16 td_resolutionunit
Definition: tif_dir.h:88
uint64 * td_stripbytecount_p
Definition: tif_dir.h:102
uint16 td_sampleformat
Definition: tif_dir.h:76
uint16 td_samplesperpixel
Definition: tif_dir.h:82
uint32 td_imagedepth
Definition: tif_dir.h:72
float td_xresolution
Definition: tif_dir.h:87
uint16 td_pagenumber[2]
Definition: tif_dir.h:91
float * td_refblackwhite
Definition: tif_dir.h:116
uint16 td_bitspersample
Definition: tif_dir.h:75
uint32 td_imagewidth
Definition: tif_dir.h:72
uint16 td_maxsamplevalue
Definition: tif_dir.h:84
uint32 td_rowsperstrip
Definition: tif_dir.h:83
uint32 td_tiledepth
Definition: tif_dir.h:73
float td_yresolution
Definition: tif_dir.h:87
uint16 td_photometric
Definition: tif_dir.h:78
uint16 td_fillorder
Definition: tif_dir.h:80
uint32 td_subfiletype
Definition: tif_dir.h:74
double * td_sminsamplevalue
Definition: tif_dir.h:85
uint16 td_minsamplevalue
Definition: tif_dir.h:84
uint16 td_threshholding
Definition: tif_dir.h:79
char * td_inknames
Definition: tif_dir.h:119
uint16 td_planarconfig
Definition: tif_dir.h:89
uint16 td_nsubifd
Definition: tif_dir.h:109
uint32 td_tilelength
Definition: tif_dir.h:73
uint16 * td_transferfunction[3]
Definition: tif_dir.h:115
uint16 td_ycbcrpositioning
Definition: tif_dir.h:113
TIFFTagValue * td_customValues
Definition: tif_dir.h:122
uint16 * td_sampleinfo
Definition: tif_dir.h:95
double * td_smaxsamplevalue
Definition: tif_dir.h:86
uint16 td_compression
Definition: tif_dir.h:77
uint32 td_tilewidth
Definition: tif_dir.h:73
uint32 td_imagelength
Definition: tif_dir.h:72
uint16 td_extrasamples
Definition: tif_dir.h:94
uint64 * td_stripoffset_p
Definition: tif_dir.h:101
uint16 td_halftonehints[2]
Definition: tif_dir.h:93
uint16 td_orientation
Definition: tif_dir.h:81
uint16 * td_colormap[3]
Definition: tif_dir.h:92
uint16 td_ycbcrsubsampling[2]
Definition: tif_dir.h:112
uint64 * td_subifd
Definition: tif_dir.h:110
float td_yposition
Definition: tif_dir.h:90
void * value
Definition: tif_dir.h:38
int count
Definition: tif_dir.h:37
const TIFFField * info
Definition: tif_dir.h:36
uint32 field_tag
Definition: tif_dir.h:283
TIFFDataType field_type
Definition: tif_dir.h:286
unsigned char field_passcount
Definition: tif_dir.h:292
char * field_name
Definition: tif_dir.h:293
unsigned short field_bit
Definition: tif_dir.h:290
short field_readcount
Definition: tif_dir.h:284
Definition: ecma_167.h:138
thandle_t tif_clientdata
Definition: tiffiop.h:207
char * tif_name
Definition: tiffiop.h:116
uint32 tif_flags
Definition: tiffiop.h:119
TIFFDirectory tif_dir
Definition: tiffiop.h:151
#define DATATYPE_INT
Definition: tif_dir.c:38
#define DATATYPE_UINT
Definition: tif_dir.c:39
#define DATATYPE_IEEEFP
Definition: tif_dir.c:40
#define DATATYPE_VOID
Definition: tif_dir.c:37
const TIFFField * TIFFFindField(TIFF *tif, uint32 tag, TIFFDataType dt)
Definition: tif_dirinfo.c:506
int _TIFFFillStriles(TIFF *tif)
Definition: tif_dirread.c:6320
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_error.c:65
void TIFFWarningExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_warning.c:65
#define TIFFTAG_BITSPERSAMPLE
Definition: tiff.h:156
#define TIFFTAG_RESOLUTIONUNIT
Definition: tiff.h:261
#define TIFFTAG_DOTRANGE
Definition: tiff.h:301
#define TIFFTAG_SUBIFD
Definition: tiff.h:295
#define EXTRASAMPLE_ASSOCALPHA
Definition: tiff.h:305
#define TIFFTAG_FILLORDER
Definition: tiff.h:214
#define TIFFTAG_SAMPLESPERPIXEL
Definition: tiff.h:231
#define TIFFTAG_DATATYPE
Definition: tiff.h:377
#define TIFFTAG_YPOSITION
Definition: tiff.h:243
#define SAMPLEFORMAT_UINT
Definition: tiff.h:308
#define TIFFTAG_COLORMAP
Definition: tiff.h:283
@ TIFF_SSHORT
Definition: tiff.h:132
@ TIFF_SLONG
Definition: tiff.h:133
@ TIFF_BYTE
Definition: tiff.h:125
@ TIFF_SBYTE
Definition: tiff.h:130
@ TIFF_IFD
Definition: tiff.h:137
@ TIFF_SHORT
Definition: tiff.h:127
@ TIFF_UNDEFINED
Definition: tiff.h:131
@ TIFF_LONG
Definition: tiff.h:128
@ TIFF_SLONG8
Definition: tiff.h:139
@ TIFF_LONG8
Definition: tiff.h:138
@ TIFF_ASCII
Definition: tiff.h:126
@ TIFF_FLOAT
Definition: tiff.h:135
@ TIFF_DOUBLE
Definition: tiff.h:136
@ TIFF_IFD8
Definition: tiff.h:140
@ TIFF_SRATIONAL
Definition: tiff.h:134
@ TIFF_RATIONAL
Definition: tiff.h:129
#define TIFFTAG_IMAGEDEPTH
Definition: tiff.h:378
#define TIFFTAG_PHOTOMETRIC
Definition: tiff.h:194
#define TIFFTAG_TILELENGTH
Definition: tiff.h:286
#define TIFFTAG_MAXSAMPLEVALUE
Definition: tiff.h:235
#define TIFFTAG_TILEDEPTH
Definition: tiff.h:379
#define TIFFTAG_EXTRASAMPLES
Definition: tiff.h:303
#define TIFFTAG_IMAGEWIDTH
Definition: tiff.h:154
#define TIFFTAG_XRESOLUTION
Definition: tiff.h:236
#define TIFFTAG_ORIENTATION
Definition: tiff.h:222
#define TIFFTAG_HALFTONEHINTS
Definition: tiff.h:284
#define TIFFTAG_MATTEING
Definition: tiff.h:376
#define TIFFTAG_MINSAMPLEVALUE
Definition: tiff.h:234
#define TIFFTAG_NUMBEROFINKS
Definition: tiff.h:300
#define SAMPLEFORMAT_IEEEFP
Definition: tiff.h:310
#define TIFFTAG_TRANSFERFUNCTION
Definition: tiff.h:272
#define TIFFTAG_YRESOLUTION
Definition: tiff.h:237
#define TIFFTAG_TILEBYTECOUNTS
Definition: tiff.h:288
#define TIFFTAG_STRIPBYTECOUNTS
Definition: tiff.h:233
#define TIFFTAG_SMINSAMPLEVALUE
Definition: tiff.h:314
#define TIFFTAG_YCBCRSUBSAMPLING
Definition: tiff.h:362
#define TIFFTAG_TILEOFFSETS
Definition: tiff.h:287
#define TIFFTAG_ROWSPERSTRIP
Definition: tiff.h:232
#define TIFFTAG_SMAXSAMPLEVALUE
Definition: tiff.h:315
#define TIFFTAG_SAMPLEFORMAT
Definition: tiff.h:307
#define TIFFTAG_REFERENCEBLACKWHITE
Definition: tiff.h:366
#define TIFFTAG_TILEWIDTH
Definition: tiff.h:285
#define TIFFTAG_IMAGELENGTH
Definition: tiff.h:155
#define TIFFTAG_PAGENUMBER
Definition: tiff.h:265
#define TIFFTAG_COMPRESSION
Definition: tiff.h:157
#define TIFFTAG_PLANARCONFIG
Definition: tiff.h:238
#define TIFFTAG_STRIPOFFSETS
Definition: tiff.h:221
#define TIFFTAG_SUBFILETYPE
Definition: tiff.h:146
#define TIFFTAG_XPOSITION
Definition: tiff.h:242
#define SAMPLEFORMAT_VOID
Definition: tiff.h:311
#define TIFFTAG_YCBCRPOSITIONING
Definition: tiff.h:363
#define TIFFTAG_INKNAMES
Definition: tiff.h:299
#define TIFFTAG_THRESHHOLDING
Definition: tiff.h:208
#define SAMPLEFORMAT_INT
Definition: tiff.h:309
#define FIELD_CUSTOM
Definition: tiffio.h:312
#define TIFF_SPP
Definition: tiffio.h:309
#define TIFF_VARIABLE
Definition: tiffio.h:308
#define TIFF_ANY
Definition: tiffio.h:307
#define TIFF_VARIABLE2
Definition: tiffio.h:310
#define TIFF_PERSAMPLE
Definition: tiffiop.h:141
#define isPseudoTag(t)
Definition: tiffiop.h:227
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36

Referenced by TIFFDefaultDirectory().

◆ _TIFFVSetField()

static int _TIFFVSetField ( TIFF tif,
uint32  tag,
va_list  ap 
)
static

Definition at line 171 of file tif_dir.c.

172{
173 static const char module[] = "_TIFFVSetField";
174
175 TIFFDirectory* td = &tif->tif_dir;
176 int status = 1;
177 uint32 v32, i, v;
178 double dblval;
179 char* s;
180 const TIFFField *fip = TIFFFindField(tif, tag, TIFF_ANY);
181 uint32 standard_tag = tag;
182 if( fip == NULL ) /* cannot happen since OkToChangeTag() already checks it */
183 return 0;
184 /*
185 * We want to force the custom code to be used for custom
186 * fields even if the tag happens to match a well known
187 * one - important for reinterpreted handling of standard
188 * tag values in custom directories (i.e. EXIF)
189 */
190 if (fip->field_bit == FIELD_CUSTOM) {
191 standard_tag = 0;
192 }
193
194 switch (standard_tag) {
197 break;
200 break;
203 break;
206 /*
207 * If the data require post-decoding processing to byte-swap
208 * samples, set it up here. Note that since tags are required
209 * to be ordered, compression code can override this behaviour
210 * in the setup method if it wants to roll the post decoding
211 * work in with its normal work.
212 */
213 if (tif->tif_flags & TIFF_SWAB) {
214 if (td->td_bitspersample == 8)
216 else if (td->td_bitspersample == 16)
218 else if (td->td_bitspersample == 24)
220 else if (td->td_bitspersample == 32)
222 else if (td->td_bitspersample == 64)
224 else if (td->td_bitspersample == 128) /* two 64's */
226 }
227 break;
230 /*
231 * If we're changing the compression scheme, the notify the
232 * previous module so that it can cleanup any state it's
233 * setup.
234 */
236 if ((uint32)td->td_compression == v)
237 break;
238 (*tif->tif_cleanup)(tif);
239 tif->tif_flags &= ~TIFF_CODERSETUP;
240 }
241 /*
242 * Setup new compression routine state.
243 */
244 if( (status = TIFFSetCompressionScheme(tif, v)) != 0 )
245 td->td_compression = (uint16) v;
246 else
247 status = 0;
248 break;
251 break;
254 break;
258 goto badvalue;
259 td->td_fillorder = (uint16) v;
260 break;
264 goto badvalue;
265 else
266 td->td_orientation = (uint16) v;
267 break;
270 if (v == 0)
271 goto badvalue;
272 if( v != td->td_samplesperpixel )
273 {
274 /* See http://bugzilla.maptools.org/show_bug.cgi?id=2500 */
275 if( td->td_sminsamplevalue != NULL )
276 {
278 "SamplesPerPixel tag value is changing, "
279 "but SMinSampleValue tag was read with a different value. Cancelling it");
283 }
284 if( td->td_smaxsamplevalue != NULL )
285 {
287 "SamplesPerPixel tag value is changing, "
288 "but SMaxSampleValue tag was read with a different value. Cancelling it");
292 }
293 /* Test if 3 transfer functions instead of just one are now needed
294 See http://bugzilla.maptools.org/show_bug.cgi?id=2820 */
295 if( td->td_transferfunction[0] != NULL && (v - td->td_extrasamples > 1) &&
296 !(td->td_samplesperpixel - td->td_extrasamples > 1))
297 {
299 "SamplesPerPixel tag value is changing, "
300 "but TransferFunction was read with a different value. Cancelling it");
303 td->td_transferfunction[0] = NULL;
304 }
305 }
307 break;
309 v32 = (uint32) va_arg(ap, uint32);
310 if (v32 == 0)
311 goto badvalue32;
312 td->td_rowsperstrip = v32;
314 td->td_tilelength = v32;
315 td->td_tilewidth = td->td_imagewidth;
316 }
317 break;
320 break;
323 break;
325 if (tif->tif_flags & TIFF_PERSAMPLE)
327 else
329 break;
331 if (tif->tif_flags & TIFF_PERSAMPLE)
333 else
335 break;
337 dblval = va_arg(ap, double);
338 if( dblval < 0 )
339 goto badvaluedouble;
341 break;
343 dblval = va_arg(ap, double);
344 if( dblval < 0 )
345 goto badvaluedouble;
347 break;
351 goto badvalue;
352 td->td_planarconfig = (uint16) v;
353 break;
356 break;
359 break;
363 goto badvalue;
364 td->td_resolutionunit = (uint16) v;
365 break;
369 break;
373 break;
374 case TIFFTAG_COLORMAP:
375 v32 = (uint32)(1L<<td->td_bitspersample);
379 break;
381 if (!setExtraSamples(tif, ap, &v))
382 goto badvalue;
383 break;
384 case TIFFTAG_MATTEING:
385 td->td_extrasamples = (((uint16) va_arg(ap, uint16_vap)) != 0);
386 if (td->td_extrasamples) {
388 _TIFFsetShortArray(&td->td_sampleinfo, &sv, 1);
389 }
390 break;
392 v32 = (uint32) va_arg(ap, uint32);
393 if (v32 % 16) {
394 if (tif->tif_mode != O_RDONLY)
395 goto badvalue32;
397 "Nonstandard tile width %d, convert file", v32);
398 }
399 td->td_tilewidth = v32;
400 tif->tif_flags |= TIFF_ISTILED;
401 break;
403 v32 = (uint32) va_arg(ap, uint32);
404 if (v32 % 16) {
405 if (tif->tif_mode != O_RDONLY)
406 goto badvalue32;
408 "Nonstandard tile length %d, convert file", v32);
409 }
410 td->td_tilelength = v32;
411 tif->tif_flags |= TIFF_ISTILED;
412 break;
414 v32 = (uint32) va_arg(ap, uint32);
415 if (v32 == 0)
416 goto badvalue32;
417 td->td_tiledepth = v32;
418 break;
419 case TIFFTAG_DATATYPE:
421 switch (v) {
422 case DATATYPE_VOID: v = SAMPLEFORMAT_VOID; break;
423 case DATATYPE_INT: v = SAMPLEFORMAT_INT; break;
424 case DATATYPE_UINT: v = SAMPLEFORMAT_UINT; break;
426 default: goto badvalue;
427 }
428 td->td_sampleformat = (uint16) v;
429 break;
433 goto badvalue;
434 td->td_sampleformat = (uint16) v;
435
436 /* Try to fix up the SWAB function for complex data. */
438 && td->td_bitspersample == 32
443 && td->td_bitspersample == 64
446 break;
449 break;
450 case TIFFTAG_SUBIFD:
451 if ((tif->tif_flags & TIFF_INSUBIFD) == 0) {
454 (uint32) td->td_nsubifd);
455 } else {
457 "%s: Sorry, cannot nest SubIFDs",
458 tif->tif_name);
459 status = 0;
460 }
461 break;
464 break;
468 break;
470 v = (td->td_samplesperpixel - td->td_extrasamples) > 1 ? 3 : 1;
471 for (i = 0; i < v; i++)
473 va_arg(ap, uint16*), 1U<<td->td_bitspersample);
474 break;
476 /* XXX should check for null range */
477 _TIFFsetFloatArray(&td->td_refblackwhite, va_arg(ap, float*), 6);
478 break;
479 case TIFFTAG_INKNAMES:
481 s = va_arg(ap, char*);
482 v = checkInkNamesString(tif, v, s);
483 status = v > 0;
484 if( v > 0 ) {
486 td->td_inknameslen = v;
487 }
488 break;
491 if( v == PERSAMPLE_MULTI )
493 else
494 tif->tif_flags &= ~TIFF_PERSAMPLE;
495 break;
496 default: {
497 TIFFTagValue *tv;
498 int tv_size, iCustom;
499
500 /*
501 * This can happen if multiple images are open with different
502 * codecs which have private tags. The global tag information
503 * table may then have tags that are valid for one file but not
504 * the other. If the client tries to set a tag that is not valid
505 * for the image's codec then we'll arrive here. This
506 * happens, for example, when tiffcp is used to convert between
507 * compression schemes and codec-specific tags are blindly copied.
508 */
509 if(fip->field_bit != FIELD_CUSTOM) {
511 "%s: Invalid %stag \"%s\" (not supported by codec)",
512 tif->tif_name, isPseudoTag(tag) ? "pseudo-" : "",
513 fip->field_name);
514 status = 0;
515 break;
516 }
517
518 /*
519 * Find the existing entry for this custom value.
520 */
521 tv = NULL;
522 for (iCustom = 0; iCustom < td->td_customValueCount; iCustom++) {
523 if (td->td_customValues[iCustom].info->field_tag == tag) {
524 tv = td->td_customValues + iCustom;
525 if (tv->value != NULL) {
526 _TIFFfree(tv->value);
527 tv->value = NULL;
528 }
529 break;
530 }
531 }
532
533 /*
534 * Grow the custom list if the entry was not found.
535 */
536 if(tv == NULL) {
537 TIFFTagValue *new_customValues;
538
540 new_customValues = (TIFFTagValue *)
542 sizeof(TIFFTagValue) * td->td_customValueCount);
543 if (!new_customValues) {
545 "%s: Failed to allocate space for list of custom values",
546 tif->tif_name);
547 status = 0;
548 goto end;
549 }
550
551 td->td_customValues = new_customValues;
552
553 tv = td->td_customValues + (td->td_customValueCount - 1);
554 tv->info = fip;
555 tv->value = NULL;
556 tv->count = 0;
557 }
558
559 /*
560 * Set custom value ... save a copy of the custom tag value.
561 */
562 tv_size = _TIFFDataSize(fip->field_type);
563 if (tv_size == 0) {
564 status = 0;
566 "%s: Bad field type %d for \"%s\"",
567 tif->tif_name, fip->field_type,
568 fip->field_name);
569 goto end;
570 }
571
572 if (fip->field_type == TIFF_ASCII)
573 {
574 uint32 ma;
575 char* mb;
576 if (fip->field_passcount)
577 {
579 ma=(uint32)va_arg(ap,uint32);
580 mb=(char*)va_arg(ap,char*);
581 }
582 else
583 {
584 mb=(char*)va_arg(ap,char*);
585 ma=(uint32)(strlen(mb)+1);
586 }
587 tv->count=ma;
588 setByteArray(&tv->value,mb,ma,1);
589 }
590 else
591 {
592 if (fip->field_passcount) {
594 tv->count = (uint32) va_arg(ap, uint32);
595 else
596 tv->count = (int) va_arg(ap, int);
597 } else if (fip->field_writecount == TIFF_VARIABLE
599 tv->count = 1;
600 else if (fip->field_writecount == TIFF_SPP)
601 tv->count = td->td_samplesperpixel;
602 else
603 tv->count = fip->field_writecount;
604
605 if (tv->count == 0) {
606 status = 0;
608 "%s: Null count for \"%s\" (type "
609 "%d, writecount %d, passcount %d)",
610 tif->tif_name,
611 fip->field_name,
612 fip->field_type,
613 fip->field_writecount,
614 fip->field_passcount);
615 goto end;
616 }
617
618 tv->value = _TIFFCheckMalloc(tif, tv->count, tv_size,
619 "custom tag binary object");
620 if (!tv->value) {
621 status = 0;
622 goto end;
623 }
624
625 if (fip->field_tag == TIFFTAG_DOTRANGE
626 && strcmp(fip->field_name,"DotRange") == 0) {
627 /* TODO: This is an evil exception and should not have been
628 handled this way ... likely best if we move it into
629 the directory structure with an explicit field in
630 libtiff 4.1 and assign it a FIELD_ value */
631 uint16 v2[2];
632 v2[0] = (uint16)va_arg(ap, int);
633 v2[1] = (uint16)va_arg(ap, int);
634 _TIFFmemcpy(tv->value, &v2, 4);
635 }
636
637 else if (fip->field_passcount
640 || fip->field_writecount == TIFF_SPP
641 || tv->count > 1) {
642 _TIFFmemcpy(tv->value, va_arg(ap, void *),
643 tv->count * tv_size);
644 } else {
645 char *val = (char *)tv->value;
646 assert( tv->count == 1 );
647
648 switch (fip->field_type) {
649 case TIFF_BYTE:
650 case TIFF_UNDEFINED:
651 {
652 uint8 v2 = (uint8)va_arg(ap, int);
653 _TIFFmemcpy(val, &v2, tv_size);
654 }
655 break;
656 case TIFF_SBYTE:
657 {
658 int8 v2 = (int8)va_arg(ap, int);
659 _TIFFmemcpy(val, &v2, tv_size);
660 }
661 break;
662 case TIFF_SHORT:
663 {
664 uint16 v2 = (uint16)va_arg(ap, int);
665 _TIFFmemcpy(val, &v2, tv_size);
666 }
667 break;
668 case TIFF_SSHORT:
669 {
670 int16 v2 = (int16)va_arg(ap, int);
671 _TIFFmemcpy(val, &v2, tv_size);
672 }
673 break;
674 case TIFF_LONG:
675 case TIFF_IFD:
676 {
678 _TIFFmemcpy(val, &v2, tv_size);
679 }
680 break;
681 case TIFF_SLONG:
682 {
683 int32 v2 = va_arg(ap, int32);
684 _TIFFmemcpy(val, &v2, tv_size);
685 }
686 break;
687 case TIFF_LONG8:
688 case TIFF_IFD8:
689 {
691 _TIFFmemcpy(val, &v2, tv_size);
692 }
693 break;
694 case TIFF_SLONG8:
695 {
696 int64 v2 = va_arg(ap, int64);
697 _TIFFmemcpy(val, &v2, tv_size);
698 }
699 break;
700 case TIFF_RATIONAL:
701 case TIFF_SRATIONAL:
702 case TIFF_FLOAT:
703 {
704 float v2 = _TIFFClampDoubleToFloat(va_arg(ap, double));
705 _TIFFmemcpy(val, &v2, tv_size);
706 }
707 break;
708 case TIFF_DOUBLE:
709 {
710 double v2 = va_arg(ap, double);
711 _TIFFmemcpy(val, &v2, tv_size);
712 }
713 break;
714 default:
715 _TIFFmemset(val, 0, tv_size);
716 status = 0;
717 break;
718 }
719 }
720 }
721 }
722 }
723 if (status) {
724 const TIFFField* fip2=TIFFFieldWithTag(tif,tag);
725 if (fip2)
726 TIFFSetFieldBit(tif, fip2->field_bit);
728 }
729
730end:
731 va_end(ap);
732 return (status);
734 {
735 const TIFFField* fip2=TIFFFieldWithTag(tif,tag);
737 "%s: Bad value %u for \"%s\" tag",
738 tif->tif_name, v,
739 fip2 ? fip2->field_name : "Unknown");
740 va_end(ap);
741 }
742 return (0);
743badvalue32:
744 {
745 const TIFFField* fip2=TIFFFieldWithTag(tif,tag);
747 "%s: Bad value %u for \"%s\" tag",
748 tif->tif_name, v32,
749 fip2 ? fip2->field_name : "Unknown");
750 va_end(ap);
751 }
752 return (0);
753badvaluedouble:
754 {
755 const TIFFField* fip2=TIFFFieldWithTag(tif,tag);
757 "%s: Bad value %f for \"%s\" tag",
758 tif->tif_name, dblval,
759 fip2 ? fip2->field_name : "Unknown");
760 va_end(ap);
761 }
762 return (0);
763}
#define va_end(ap)
Definition: acmsvcex.h:90
#define O_RDONLY
Definition: acwin.h:108
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
GLdouble s
Definition: gl.h:2039
GLuint GLuint end
Definition: gl.h:1545
GLfloat GLfloat GLfloat v2
Definition: glext.h:6063
int badvalue
Definition: class.c:929
int td_inknameslen
Definition: tif_dir.h:118
short field_writecount
Definition: tif_dir.h:285
Definition: ps.c:97
TIFFPostMethod tif_postdecode
Definition: tiffiop.h:214
TIFFVoidMethod tif_cleanup
Definition: tiffiop.h:188
int tif_mode
Definition: tiffiop.h:118
void * _TIFFCheckMalloc(TIFF *tif, tmsize_t nmemb, tmsize_t elem_size, const char *what)
Definition: tif_aux.c:121
float _TIFFClampDoubleToFloat(double val)
Definition: tif_aux.c:397
int TIFFSetCompressionScheme(TIFF *tif, int scheme)
Definition: tif_compress.c:160
static int setExtraSamples(TIFF *tif, va_list ap, uint32 *v)
Definition: tif_dir.c:91
static void setDoubleArrayOneValue(double **vpp, double value, size_t nmemb)
Definition: tif_dir.c:75
static void _TIFFsetNString(char **cpp, char *cp, uint32 n)
Definition: tif_dir.c:61
static void _TIFFsetLong8Array(uint64 **lpp, uint64 *lp, uint32 n)
Definition: tif_dir.c:67
void _TIFFsetDoubleArray(double **dpp, double *dp, uint32 n)
Definition: tif_dir.c:71
void _TIFFsetShortArray(uint16 **wpp, uint16 *wp, uint32 n)
Definition: tif_dir.c:63
static uint32 checkInkNamesString(TIFF *tif, uint32 slen, const char *s)
Definition: tif_dir.c:145
void _TIFFsetFloatArray(float **fpp, float *fp, uint32 n)
Definition: tif_dir.c:69
#define FIELD_TRANSFERFUNCTION
Definition: tif_dir.h:174
#define FIELD_SMAXSAMPLEVALUE
Definition: tif_dir.h:167
#define FIELD_SMINSAMPLEVALUE
Definition: tif_dir.h:166
#define TIFFFieldSet(tif, field)
Definition: tif_dir.h:196
#define FIELD_TILEDIMENSIONS
Definition: tif_dir.h:142
#define FIELD_COMPRESSION
Definition: tif_dir.h:149
#define TIFFClrFieldBit(tif, field)
Definition: tif_dir.h:198
#define TIFFSetFieldBit(tif, field)
Definition: tif_dir.h:197
const TIFFField * TIFFFieldWithTag(TIFF *tif, uint32 tag)
Definition: tif_dirinfo.c:558
int _TIFFDataSize(TIFFDataType type)
Definition: tif_dirinfo.c:476
void _TIFFNoPostDecode(TIFF *tif, uint8 *buf, tmsize_t cc)
Definition: tif_read.c:1603
void _TIFFSwab32BitData(TIFF *tif, uint8 *buf, tmsize_t cc)
Definition: tif_read.c:1625
void _TIFFSwab16BitData(TIFF *tif, uint8 *buf, tmsize_t cc)
Definition: tif_read.c:1609
void _TIFFSwab64BitData(TIFF *tif, uint8 *buf, tmsize_t cc)
Definition: tif_read.c:1633
void _TIFFSwab24BitData(TIFF *tif, uint8 *buf, tmsize_t cc)
Definition: tif_read.c:1617
void _TIFFfree(void *p)
Definition: tif_unix.c:326
void _TIFFmemset(void *p, int v, tmsize_t c)
Definition: tif_unix.c:338
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Definition: tif_unix.c:344
void * _TIFFrealloc(void *p, tmsize_t s)
Definition: tif_unix.c:332
#define PLANARCONFIG_SEPARATE
Definition: tiff.h:240
int uint16_vap
Definition: tiff.h:86
#define RESUNIT_CENTIMETER
Definition: tiff.h:264
#define ORIENTATION_TOPLEFT
Definition: tiff.h:223
#define FILLORDER_LSB2MSB
Definition: tiff.h:216
#define SAMPLEFORMAT_COMPLEXINT
Definition: tiff.h:312
#define RESUNIT_NONE
Definition: tiff.h:262
#define PERSAMPLE_MULTI
Definition: tiff.h:568
#define FILLORDER_MSB2LSB
Definition: tiff.h:215
#define ORIENTATION_LEFTBOT
Definition: tiff.h:230
#define TIFFTAG_PERSAMPLE
Definition: tiff.h:566
#define SAMPLEFORMAT_COMPLEXIEEEFP
Definition: tiff.h:313
#define PLANARCONFIG_CONTIG
Definition: tiff.h:239
#define TIFF_INSUBIFD
Definition: tiffiop.h:132
#define TIFF_DIRTYDIRECT
Definition: tiffiop.h:122
#define TIFF_SWAB
Definition: tiffiop.h:126
#define TIFF_ISTILED
Definition: tiffiop.h:129

Referenced by TIFFDefaultDirectory().

◆ checkInkNamesString()

static uint32 checkInkNamesString ( TIFF tif,
uint32  slen,
const char s 
)
static

Definition at line 145 of file tif_dir.c.

146{
147 TIFFDirectory* td = &tif->tif_dir;
149
150 if (slen > 0) {
151 const char* ep = s+slen;
152 const char* cp = s;
153 for (; i > 0; i--) {
154 for (; cp < ep && *cp != '\0'; cp++) {}
155 if (cp >= ep)
156 goto bad;
157 cp++; /* skip \0 */
158 }
159 return ((uint32)(cp-s));
160 }
161bad:
162 TIFFErrorExt(tif->tif_clientdata, "TIFFSetField",
163 "%s: Invalid InkNames value; expecting %d names, found %d",
164 tif->tif_name,
167 return (0);
168}

Referenced by _TIFFVSetField().

◆ OkToChangeTag()

static int OkToChangeTag ( TIFF tif,
uint32  tag 
)
static

Definition at line 775 of file tif_dir.c.

776{
777 const TIFFField* fip = TIFFFindField(tif, tag, TIFF_ANY);
778 if (!fip) { /* unknown tag */
779 TIFFErrorExt(tif->tif_clientdata, "TIFFSetField", "%s: Unknown %stag %u",
780 tif->tif_name, isPseudoTag(tag) ? "pseudo-" : "", tag);
781 return (0);
782 }
784 !fip->field_oktochange) {
785 /*
786 * Consult info table to see if tag can be changed
787 * after we've started writing. We only allow changes
788 * to those tags that don't/shouldn't affect the
789 * compression and/or format of the data.
790 */
791 TIFFErrorExt(tif->tif_clientdata, "TIFFSetField",
792 "%s: Cannot modify tag \"%s\" while writing",
793 tif->tif_name, fip->field_name);
794 return (0);
795 }
796 return (1);
797}
unsigned char field_oktochange
Definition: tif_dir.h:291
#define TIFF_BEENWRITING
Definition: tiffiop.h:125

Referenced by TIFFVSetField().

◆ setByteArray()

static void setByteArray ( void **  vpp,
void vp,
size_t  nmemb,
size_t  elem_size 
)
static

Definition at line 43 of file tif_dir.c.

44{
45 if (*vpp) {
46 _TIFFfree(*vpp);
47 *vpp = 0;
48 }
49 if (vp) {
50 tmsize_t bytes = _TIFFMultiplySSize(NULL, nmemb, elem_size, NULL);
51 if (bytes)
52 *vpp = (void*) _TIFFmalloc(bytes);
53 if (*vpp)
54 _TIFFmemcpy(*vpp, vp, bytes);
55 }
56}
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
tmsize_t _TIFFMultiplySSize(TIFF *tif, tmsize_t first, tmsize_t second, const char *where)
Definition: tif_aux.c:59
void * _TIFFmalloc(tmsize_t s)
Definition: tif_unix.c:309
TIFF_SSIZE_T tmsize_t
Definition: tiffio.h:65

Referenced by _TIFFsetByteArray(), _TIFFsetDoubleArray(), _TIFFsetFloatArray(), _TIFFsetLong8Array(), _TIFFsetLongArray(), _TIFFsetNString(), _TIFFsetShortArray(), _TIFFsetString(), and _TIFFVSetField().

◆ setDoubleArrayOneValue()

static void setDoubleArrayOneValue ( double **  vpp,
double  value,
size_t  nmemb 
)
static

Definition at line 75 of file tif_dir.c.

76{
77 if (*vpp)
78 _TIFFfree(*vpp);
79 *vpp = _TIFFmalloc(nmemb*sizeof(double));
80 if (*vpp)
81 {
82 while (nmemb--)
83 ((double*)*vpp)[nmemb] = value;
84 }
85}
Definition: pdh_main.c:94

Referenced by _TIFFVSetField().

◆ setExtraSamples()

static int setExtraSamples ( TIFF tif,
va_list  ap,
uint32 v 
)
static

Definition at line 91 of file tif_dir.c.

92{
93/* XXX: Unassociated alpha data == 999 is a known Corel Draw bug, see below */
94#define EXTRASAMPLE_COREL_UNASSALPHA 999
95
96 uint16* va;
97 uint32 i;
98 TIFFDirectory* td = &tif->tif_dir;
99 static const char module[] = "setExtraSamples";
100
101 *v = (uint16) va_arg(ap, uint16_vap);
102 if ((uint16) *v > td->td_samplesperpixel)
103 return 0;
104 va = va_arg(ap, uint16*);
105 if (*v > 0 && va == NULL) /* typically missing param */
106 return 0;
107 for (i = 0; i < *v; i++) {
108 if (va[i] > EXTRASAMPLE_UNASSALPHA) {
109 /*
110 * XXX: Corel Draw is known to produce incorrect
111 * ExtraSamples tags which must be patched here if we
112 * want to be able to open some of the damaged TIFF
113 * files:
114 */
117 else
118 return 0;
119 }
120 }
121
122 if ( td->td_transferfunction[0] != NULL && (td->td_samplesperpixel - *v > 1) &&
123 !(td->td_samplesperpixel - td->td_extrasamples > 1))
124 {
126 "ExtraSamples tag value is changing, "
127 "but TransferFunction was read with a different value. Cancelling it");
130 td->td_transferfunction[0] = NULL;
131 }
132
133 td->td_extrasamples = (uint16) *v;
135 return 1;
136
137#undef EXTRASAMPLE_COREL_UNASSALPHA
138}
#define EXTRASAMPLE_COREL_UNASSALPHA
#define EXTRASAMPLE_UNASSALPHA
Definition: tiff.h:306

Referenced by _TIFFVSetField().

◆ TIFFAdvanceDirectory()

static int TIFFAdvanceDirectory ( TIFF tif,
uint64 nextdir,
uint64 off 
)
static

Definition at line 1444 of file tif_dir.c.

1445{
1446 static const char module[] = "TIFFAdvanceDirectory";
1447 if (isMapped(tif))
1448 {
1449 uint64 poff=*nextdir;
1450 if (!(tif->tif_flags&TIFF_BIGTIFF))
1451 {
1452 tmsize_t poffa,poffb,poffc,poffd;
1453 uint16 dircount;
1454 uint32 nextdir32;
1455 poffa=(tmsize_t)poff;
1456 poffb=poffa+sizeof(uint16);
1457 if (((uint64)poffa!=poff)||(poffb<poffa)||(poffb<(tmsize_t)sizeof(uint16))||(poffb>tif->tif_size))
1458 {
1459 TIFFErrorExt(tif->tif_clientdata,module,"Error fetching directory count");
1460 *nextdir=0;
1461 return(0);
1462 }
1463 _TIFFmemcpy(&dircount,tif->tif_base+poffa,sizeof(uint16));
1464 if (tif->tif_flags&TIFF_SWAB)
1465 TIFFSwabShort(&dircount);
1466 poffc=poffb+dircount*12;
1467 poffd=poffc+sizeof(uint32);
1468 if ((poffc<poffb)||(poffc<dircount*12)||(poffd<poffc)||(poffd<(tmsize_t)sizeof(uint32))||(poffd>tif->tif_size))
1469 {
1470 TIFFErrorExt(tif->tif_clientdata,module,"Error fetching directory link");
1471 return(0);
1472 }
1473 if (off!=NULL)
1474 *off=(uint64)poffc;
1475 _TIFFmemcpy(&nextdir32,tif->tif_base+poffc,sizeof(uint32));
1476 if (tif->tif_flags&TIFF_SWAB)
1477 TIFFSwabLong(&nextdir32);
1478 *nextdir=nextdir32;
1479 }
1480 else
1481 {
1482 tmsize_t poffa,poffb,poffc,poffd;
1483 uint64 dircount64;
1484 uint16 dircount16;
1485 poffa=(tmsize_t)poff;
1486 poffb=poffa+sizeof(uint64);
1487 if (((uint64)poffa!=poff)||(poffb<poffa)||(poffb<(tmsize_t)sizeof(uint64))||(poffb>tif->tif_size))
1488 {
1489 TIFFErrorExt(tif->tif_clientdata,module,"Error fetching directory count");
1490 return(0);
1491 }
1492 _TIFFmemcpy(&dircount64,tif->tif_base+poffa,sizeof(uint64));
1493 if (tif->tif_flags&TIFF_SWAB)
1494 TIFFSwabLong8(&dircount64);
1495 if (dircount64>0xFFFF)
1496 {
1497 TIFFErrorExt(tif->tif_clientdata,module,"Sanity check on directory count failed");
1498 return(0);
1499 }
1500 dircount16=(uint16)dircount64;
1501 poffc=poffb+dircount16*20;
1502 poffd=poffc+sizeof(uint64);
1503 if ((poffc<poffb)||(poffc<dircount16*20)||(poffd<poffc)||(poffd<(tmsize_t)sizeof(uint64))||(poffd>tif->tif_size))
1504 {
1505 TIFFErrorExt(tif->tif_clientdata,module,"Error fetching directory link");
1506 return(0);
1507 }
1508 if (off!=NULL)
1509 *off=(uint64)poffc;
1510 _TIFFmemcpy(nextdir,tif->tif_base+poffc,sizeof(uint64));
1511 if (tif->tif_flags&TIFF_SWAB)
1512 TIFFSwabLong8(nextdir);
1513 }
1514 return(1);
1515 }
1516 else
1517 {
1518 if (!(tif->tif_flags&TIFF_BIGTIFF))
1519 {
1520 uint16 dircount;
1521 uint32 nextdir32;
1522 if (!SeekOK(tif, *nextdir) ||
1523 !ReadOK(tif, &dircount, sizeof (uint16))) {
1524 TIFFErrorExt(tif->tif_clientdata, module, "%s: Error fetching directory count",
1525 tif->tif_name);
1526 return (0);
1527 }
1528 if (tif->tif_flags & TIFF_SWAB)
1529 TIFFSwabShort(&dircount);
1530 if (off != NULL)
1531 *off = TIFFSeekFile(tif,
1532 dircount*12, SEEK_CUR);
1533 else
1534 (void) TIFFSeekFile(tif,
1535 dircount*12, SEEK_CUR);
1536 if (!ReadOK(tif, &nextdir32, sizeof (uint32))) {
1537 TIFFErrorExt(tif->tif_clientdata, module, "%s: Error fetching directory link",
1538 tif->tif_name);
1539 return (0);
1540 }
1541 if (tif->tif_flags & TIFF_SWAB)
1542 TIFFSwabLong(&nextdir32);
1543 *nextdir=nextdir32;
1544 }
1545 else
1546 {
1547 uint64 dircount64;
1548 uint16 dircount16;
1549 if (!SeekOK(tif, *nextdir) ||
1550 !ReadOK(tif, &dircount64, sizeof (uint64))) {
1551 TIFFErrorExt(tif->tif_clientdata, module, "%s: Error fetching directory count",
1552 tif->tif_name);
1553 return (0);
1554 }
1555 if (tif->tif_flags & TIFF_SWAB)
1556 TIFFSwabLong8(&dircount64);
1557 if (dircount64>0xFFFF)
1558 {
1559 TIFFErrorExt(tif->tif_clientdata, module, "Error fetching directory count");
1560 return(0);
1561 }
1562 dircount16 = (uint16)dircount64;
1563 if (off != NULL)
1564 *off = TIFFSeekFile(tif,
1565 dircount16*20, SEEK_CUR);
1566 else
1567 (void) TIFFSeekFile(tif,
1568 dircount16*20, SEEK_CUR);
1569 if (!ReadOK(tif, nextdir, sizeof (uint64))) {
1571 "%s: Error fetching directory link",
1572 tif->tif_name);
1573 return (0);
1574 }
1575 if (tif->tif_flags & TIFF_SWAB)
1576 TIFFSwabLong8(nextdir);
1577 }
1578 return (1);
1579 }
1580}
#define SEEK_CUR
Definition: util.h:63
uint8 * tif_base
Definition: tiffiop.h:202
tmsize_t tif_size
Definition: tiffiop.h:203
void TIFFSwabLong(uint32 *lp)
Definition: tif_swab.c:45
void TIFFSwabShort(uint16 *wp)
Definition: tif_swab.c:34
void TIFFSwabLong8(uint64 *lp)
Definition: tif_swab.c:57
#define ReadOK(tif, buf, size)
Definition: tiffiop.h:252
#define SeekOK(tif, off)
Definition: tiffiop.h:256
#define isMapped(tif)
Definition: tiffiop.h:230
#define TIFFSeekFile(tif, off, whence)
Definition: tiffiop.h:237
#define TIFF_BIGTIFF
Definition: tiffiop.h:138

Referenced by TIFFNumberOfDirectories(), TIFFSetDirectory(), and TIFFUnlinkDirectory().

◆ TIFFCreateCustomDirectory()

int TIFFCreateCustomDirectory ( TIFF tif,
const TIFFFieldArray infoarray 
)

Definition at line 1340 of file tif_dir.c.

1341{
1343
1344 /*
1345 * Reset the field definitions to match the application provided list.
1346 * Hopefully TIFFDefaultDirectory() won't have done anything irreversable
1347 * based on it's assumption this is an image directory.
1348 */
1349 _TIFFSetupFields(tif, infoarray);
1350
1351 tif->tif_diroff = 0;
1352 tif->tif_nextdiroff = 0;
1353 tif->tif_curoff = 0;
1354 tif->tif_row = (uint32) -1;
1355 tif->tif_curstrip = (uint32) -1;
1356
1357 return 0;
1358}
uint64 tif_nextdiroff
Definition: tiffiop.h:147
uint32 tif_curstrip
Definition: tiffiop.h:161
uint32 tif_row
Definition: tiffiop.h:159
uint64 tif_diroff
Definition: tiffiop.h:146
uint64 tif_curoff
Definition: tiffiop.h:162
int TIFFDefaultDirectory(TIFF *tif)
Definition: tif_dir.c:1372
void _TIFFSetupFields(TIFF *tif, const TIFFFieldArray *fieldarray)
Definition: tif_dirinfo.c:317

Referenced by TIFFCreateEXIFDirectory().

◆ TIFFCreateDirectory()

int TIFFCreateDirectory ( TIFF tif)

Definition at line 1327 of file tif_dir.c.

1328{
1330 tif->tif_diroff = 0;
1331 tif->tif_nextdiroff = 0;
1332 tif->tif_curoff = 0;
1333 tif->tif_row = (uint32) -1;
1334 tif->tif_curstrip = (uint32) -1;
1335
1336 return 0;
1337}

Referenced by TIFFWriteDirectorySec().

◆ TIFFCreateEXIFDirectory()

int TIFFCreateEXIFDirectory ( TIFF tif)

Definition at line 1361 of file tif_dir.c.

1362{
1366}
int TIFFCreateCustomDirectory(TIFF *tif, const TIFFFieldArray *infoarray)
Definition: tif_dir.c:1340
static const TIFFFieldArray exifFieldArray
Definition: tif_dirinfo.c:49
const TIFFFieldArray * _TIFFGetExifFields(void)
Definition: tif_dirinfo.c:311

◆ TIFFCurrentDirOffset()

uint64 TIFFCurrentDirOffset ( TIFF tif)

Definition at line 1666 of file tif_dir.c.

1667{
1668 return (tif->tif_diroff);
1669}

◆ TIFFDefaultDirectory()

int TIFFDefaultDirectory ( TIFF tif)

Definition at line 1372 of file tif_dir.c.

1373{
1374 register TIFFDirectory* td = &tif->tif_dir;
1376
1379
1380 _TIFFmemset(td, 0, sizeof (*td));
1382 td->td_bitspersample = 1;
1385 td->td_samplesperpixel = 1;
1386 td->td_rowsperstrip = (uint32) -1;
1387 td->td_tilewidth = 0;
1388 td->td_tilelength = 0;
1389 td->td_tiledepth = 1;
1390#ifdef STRIPBYTECOUNTSORTED_UNUSED
1391 td->td_stripbytecountsorted = 1; /* Our own arrays always sorted. */
1392#endif
1395 td->td_imagedepth = 1;
1396 td->td_ycbcrsubsampling[0] = 2;
1397 td->td_ycbcrsubsampling[1] = 2;
1400 tif->tif_foundfield = NULL;
1404 /*
1405 * Give client code a chance to install their own
1406 * tag extensions & methods, prior to compression overloads,
1407 * but do some prior cleanup first. (http://trac.osgeo.org/gdal/ticket/5054)
1408 */
1409 if (tif->tif_nfieldscompat > 0) {
1410 uint32 i;
1411
1412 for (i = 0; i < tif->tif_nfieldscompat; i++) {
1415 }
1417 tif->tif_nfieldscompat = 0;
1418 tif->tif_fieldscompat = NULL;
1419 }
1420 if (_TIFFextender)
1421 (*_TIFFextender)(tif);
1423 /*
1424 * NB: The directory is marked dirty as a result of setting
1425 * up the default compression scheme. However, this really
1426 * isn't correct -- we want TIFF_DIRTYDIRECT to be set only
1427 * if the user does something. We could just do the setup
1428 * by hand, but it seems better to use the normal mechanism
1429 * (i.e. TIFFSetField).
1430 */
1431 tif->tif_flags &= ~TIFF_DIRTYDIRECT;
1432
1433 /*
1434 * As per http://bugzilla.remotesensing.org/show_bug.cgi?id=19
1435 * we clear the ISTILED flag when setting up a new directory.
1436 * Should we also be clearing stuff like INSUBIFD?
1437 */
1438 tif->tif_flags &= ~TIFF_ISTILED;
1439
1440 return (1);
1441}
TIFFVGetMethod vgetfield
Definition: tiffio.h:334
TIFFVSetMethod vsetfield
Definition: tiffio.h:333
TIFFPrintMethod printdir
Definition: tiffio.h:335
TIFFField * fields
Definition: tif_dir.h:279
uint32 allocated_size
Definition: tif_dir.h:277
const TIFFField * tif_foundfield
Definition: tiffiop.h:218
TIFFTagMethods tif_tagmethods
Definition: tiffiop.h:219
size_t tif_nfieldscompat
Definition: tiffiop.h:224
TIFFFieldArray * tif_fieldscompat
Definition: tiffiop.h:223
static int _TIFFVGetField(TIFF *tif, uint32 tag, va_list ap)
Definition: tif_dir.c:873
int TIFFSetField(TIFF *tif, uint32 tag,...)
Definition: tif_dir.c:807
static TIFFExtendProc _TIFFextender
Definition: tif_dir.c:1309
static int _TIFFVSetField(TIFF *tif, uint32 tag, va_list ap)
Definition: tif_dir.c:171
const TIFFFieldArray * _TIFFGetFields(void)
Definition: tif_dirinfo.c:305
static const TIFFFieldArray tiffFieldArray
Definition: tif_dirinfo.c:48
#define COMPRESSION_NONE
Definition: tiff.h:158
#define YCBCRPOSITION_CENTERED
Definition: tiff.h:364
#define RESUNIT_INCH
Definition: tiff.h:263
#define THRESHHOLD_BILEVEL
Definition: tiff.h:209

Referenced by TIFFClientOpen(), TIFFCreateCustomDirectory(), TIFFCreateDirectory(), TIFFReadDirectory(), and TIFFUnlinkDirectory().

◆ TIFFFreeDirectory()

void TIFFFreeDirectory ( TIFF tif)

Definition at line 1268 of file tif_dir.c.

1269{
1270 TIFFDirectory *td = &tif->tif_dir;
1271 int i;
1272
1274 CleanupField(td_sminsamplevalue);
1275 CleanupField(td_smaxsamplevalue);
1276 CleanupField(td_colormap[0]);
1277 CleanupField(td_colormap[1]);
1278 CleanupField(td_colormap[2]);
1279 CleanupField(td_sampleinfo);
1280 CleanupField(td_subifd);
1281 CleanupField(td_inknames);
1282 CleanupField(td_refblackwhite);
1283 CleanupField(td_transferfunction[0]);
1284 CleanupField(td_transferfunction[1]);
1285 CleanupField(td_transferfunction[2]);
1286 CleanupField(td_stripoffset_p);
1287 CleanupField(td_stripbytecount_p);
1291
1292 /* Cleanup custom tag values */
1293 for( i = 0; i < td->td_customValueCount; i++ ) {
1294 if (td->td_customValues[i].value)
1296 }
1297
1298 td->td_customValueCount = 0;
1299 CleanupField(td_customValues);
1300
1301 _TIFFmemset( &(td->td_stripoffset_entry), 0, sizeof(TIFFDirEntry));
1303}
uint32 td_stripoffsetbyteallocsize
Definition: tif_dir.h:103
TIFFDirEntry td_stripoffset_entry
Definition: tif_dir.h:107
unsigned long td_fieldsset[FIELD_SETLONGS]
Definition: tif_dir.h:70
TIFFDirEntry td_stripbytecount_entry
Definition: tif_dir.h:108
#define CleanupField(member)
Definition: tif_dir.c:1257
#define FIELD_SETLONGS
Definition: tif_dir.h:68
#define FIELD_YCBCRSUBSAMPLING
Definition: tif_dir.h:171
#define FIELD_YCBCRPOSITIONING
Definition: tif_dir.h:172

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

◆ TIFFGetField()

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

Definition at line 1232 of file tif_dir.c.

1233{
1234 int status;
1235 va_list ap;
1236
1237 va_start(ap, tag);
1238 status = TIFFVGetField(tif, tag, ap);
1239 va_end(ap);
1240 return (status);
1241}
char * va_list
Definition: acmsvcex.h:78
#define va_start(ap, A)
Definition: acmsvcex.h:91
int TIFFVGetField(TIFF *tif, uint32 tag, va_list ap)
Definition: tif_dir.c:1250

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

◆ TIFFLastDirectory()

int TIFFLastDirectory ( TIFF tif)

Definition at line 1676 of file tif_dir.c.

1677{
1678 return (tif->tif_nextdiroff == 0);
1679}

◆ TIFFNumberOfDirectories()

uint16 TIFFNumberOfDirectories ( TIFF tif)

Definition at line 1586 of file tif_dir.c.

1587{
1588 static const char module[] = "TIFFNumberOfDirectories";
1589 uint64 nextdir;
1590 uint16 n;
1591 if (!(tif->tif_flags&TIFF_BIGTIFF))
1592 nextdir = tif->tif_header.classic.tiff_diroff;
1593 else
1594 nextdir = tif->tif_header.big.tiff_diroff;
1595 n = 0;
1596 while (nextdir != 0 && TIFFAdvanceDirectory(tif, &nextdir, NULL))
1597 {
1598 if (n != 65535) {
1599 ++n;
1600 }
1601 else
1602 {
1604 "Directory count exceeded 65535 limit,"
1605 " giving up on counting.");
1606 return (65535);
1607 }
1608 }
1609 return (n);
1610}
uint64 tiff_diroff
Definition: tiff.h:105
uint32 tiff_diroff
Definition: tiff.h:98
TIFFHeaderClassic classic
Definition: tiffiop.h:155
TIFFHeaderBig big
Definition: tiffiop.h:156
union tiff::@3468 tif_header
static int TIFFAdvanceDirectory(TIFF *tif, uint64 *nextdir, uint64 *off)
Definition: tif_dir.c:1444

◆ TIFFSetDirectory()

int TIFFSetDirectory ( TIFF tif,
uint16  dirn 
)

Definition at line 1617 of file tif_dir.c.

1618{
1619 uint64 nextdir;
1620 uint16 n;
1621
1622 if (!(tif->tif_flags&TIFF_BIGTIFF))
1623 nextdir = tif->tif_header.classic.tiff_diroff;
1624 else
1625 nextdir = tif->tif_header.big.tiff_diroff;
1626 for (n = dirn; n > 0 && nextdir != 0; n--)
1627 if (!TIFFAdvanceDirectory(tif, &nextdir, NULL))
1628 return (0);
1629 tif->tif_nextdiroff = nextdir;
1630 /*
1631 * Set curdir to the actual directory index. The
1632 * -1 is because TIFFReadDirectory will increment
1633 * tif_curdir after successfully reading the directory.
1634 */
1635 tif->tif_curdir = (dirn - n) - 1;
1636 /*
1637 * Reset tif_dirnumber counter and start new list of seen directories.
1638 * We need this to prevent IFD loops.
1639 */
1640 tif->tif_dirnumber = 0;
1641 return (TIFFReadDirectory(tif));
1642}
uint16 tif_dirnumber
Definition: tiffiop.h:150
uint16 tif_curdir
Definition: tiffiop.h:160
int TIFFReadDirectory(TIFF *tif)
Definition: tif_dirread.c:3574

◆ TIFFSetField()

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

Definition at line 807 of file tif_dir.c.

808{
809 va_list ap;
810 int status;
811
812 va_start(ap, tag);
813 status = TIFFVSetField(tif, tag, ap);
814 va_end(ap);
815 return (status);
816}
int TIFFVSetField(TIFF *tif, uint32 tag, va_list ap)
Definition: tif_dir.c:866

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

◆ TIFFSetSubDirectory()

int TIFFSetSubDirectory ( TIFF tif,
uint64  diroff 
)

Definition at line 1651 of file tif_dir.c.

1652{
1653 tif->tif_nextdiroff = diroff;
1654 /*
1655 * Reset tif_dirnumber counter and start new list of seen directories.
1656 * We need this to prevent IFD loops.
1657 */
1658 tif->tif_dirnumber = 0;
1659 return (TIFFReadDirectory(tif));
1660}

◆ TIFFSetTagExtender()

TIFFExtendProc TIFFSetTagExtender ( TIFFExtendProc  extender)

Definition at line 1312 of file tif_dir.c.

1313{
1315 _TIFFextender = extender;
1316 return (prev);
1317}
void(* TIFFExtendProc)(TIFF *)
Definition: tiffio.h:279

◆ TIFFUnlinkDirectory()

int TIFFUnlinkDirectory ( TIFF tif,
uint16  dirn 
)

Definition at line 1685 of file tif_dir.c.

1686{
1687 static const char module[] = "TIFFUnlinkDirectory";
1688 uint64 nextdir;
1689 uint64 off;
1690 uint16 n;
1691
1692 if (tif->tif_mode == O_RDONLY) {
1694 "Can not unlink directory in read-only file");
1695 return (0);
1696 }
1697 /*
1698 * Go to the directory before the one we want
1699 * to unlink and nab the offset of the link
1700 * field we'll need to patch.
1701 */
1702 if (!(tif->tif_flags&TIFF_BIGTIFF))
1703 {
1704 nextdir = tif->tif_header.classic.tiff_diroff;
1705 off = 4;
1706 }
1707 else
1708 {
1709 nextdir = tif->tif_header.big.tiff_diroff;
1710 off = 8;
1711 }
1712 for (n = dirn-1; n > 0; n--) {
1713 if (nextdir == 0) {
1714 TIFFErrorExt(tif->tif_clientdata, module, "Directory %d does not exist", dirn);
1715 return (0);
1716 }
1717 if (!TIFFAdvanceDirectory(tif, &nextdir, &off))
1718 return (0);
1719 }
1720 /*
1721 * Advance to the directory to be unlinked and fetch
1722 * the offset of the directory that follows.
1723 */
1724 if (!TIFFAdvanceDirectory(tif, &nextdir, NULL))
1725 return (0);
1726 /*
1727 * Go back and patch the link field of the preceding
1728 * directory to point to the offset of the directory
1729 * that follows.
1730 */
1731 (void) TIFFSeekFile(tif, off, SEEK_SET);
1732 if (!(tif->tif_flags&TIFF_BIGTIFF))
1733 {
1734 uint32 nextdir32;
1735 nextdir32=(uint32)nextdir;
1736 assert((uint64)nextdir32==nextdir);
1737 if (tif->tif_flags & TIFF_SWAB)
1738 TIFFSwabLong(&nextdir32);
1739 if (!WriteOK(tif, &nextdir32, sizeof (uint32))) {
1740 TIFFErrorExt(tif->tif_clientdata, module, "Error writing directory link");
1741 return (0);
1742 }
1743 }
1744 else
1745 {
1746 if (tif->tif_flags & TIFF_SWAB)
1747 TIFFSwabLong8(&nextdir);
1748 if (!WriteOK(tif, &nextdir, sizeof (uint64))) {
1749 TIFFErrorExt(tif->tif_clientdata, module, "Error writing directory link");
1750 return (0);
1751 }
1752 }
1753 /*
1754 * Leave directory state setup safely. We don't have
1755 * facilities for doing inserting and removing directories,
1756 * so it's safest to just invalidate everything. This
1757 * means that the caller can only append to the directory
1758 * chain.
1759 */
1760 (*tif->tif_cleanup)(tif);
1761 if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata) {
1762 _TIFFfree(tif->tif_rawdata);
1763 tif->tif_rawdata = NULL;
1764 tif->tif_rawcc = 0;
1765 tif->tif_rawdataoff = 0;
1766 tif->tif_rawdataloaded = 0;
1767 }
1769 TIFFFreeDirectory(tif);
1771 tif->tif_diroff = 0; /* force link on next write */
1772 tif->tif_nextdiroff = 0; /* next write must be at end */
1773 tif->tif_curoff = 0;
1774 tif->tif_row = (uint32) -1;
1775 tif->tif_curstrip = (uint32) -1;
1776 return (1);
1777}
#define SEEK_SET
Definition: jmemansi.c:26
tmsize_t tif_rawdataloaded
Definition: tiffiop.h:198
tmsize_t tif_rawcc
Definition: tiffiop.h:200
tmsize_t tif_rawdataoff
Definition: tiffiop.h:197
uint8 * tif_rawdata
Definition: tiffiop.h:195
void TIFFFreeDirectory(TIFF *tif)
Definition: tif_dir.c:1268
#define WriteOK(tif, buf, size)
Definition: tiffiop.h:259
#define TIFF_MYBUFFER
Definition: tiffiop.h:128
#define TIFF_BUFFERSETUP
Definition: tiffiop.h:123
#define TIFF_POSTENCODE
Definition: tiffiop.h:131
#define TIFF_BUF4WRITE
Definition: tiffiop.h:139

◆ TIFFUnsetField()

int TIFFUnsetField ( TIFF tif,
uint32  tag 
)

Definition at line 822 of file tif_dir.c.

823{
824 const TIFFField *fip = TIFFFieldWithTag(tif, tag);
825 TIFFDirectory* td = &tif->tif_dir;
826
827 if( !fip )
828 return 0;
829
830 if( fip->field_bit != FIELD_CUSTOM )
831 TIFFClrFieldBit(tif, fip->field_bit);
832 else
833 {
834 TIFFTagValue *tv = NULL;
835 int i;
836
837 for (i = 0; i < td->td_customValueCount; i++) {
838
839 tv = td->td_customValues + i;
840 if( tv->info->field_tag == tag )
841 break;
842 }
843
844 if( i < td->td_customValueCount )
845 {
846 _TIFFfree(tv->value);
847 for( ; i < td->td_customValueCount-1; i++) {
848 td->td_customValues[i] = td->td_customValues[i+1];
849 }
851 }
852 }
853
855
856 return (1);
857}

◆ TIFFVGetField()

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

Definition at line 1250 of file tif_dir.c.

1251{
1252 const TIFFField* fip = TIFFFindField(tif, tag, TIFF_ANY);
1253 return (fip && (isPseudoTag(tag) || TIFFFieldSet(tif, fip->field_bit)) ?
1254 (*tif->tif_tagmethods.vgetfield)(tif, tag, ap) : 0);
1255}

Referenced by TIFFGetField(), and TIFFVGetFieldDefaulted().

◆ TIFFVSetField()

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

Definition at line 866 of file tif_dir.c.

867{
868 return OkToChangeTag(tif, tag) ?
869 (*tif->tif_tagmethods.vsetfield)(tif, tag, ap) : 0;
870}
static int OkToChangeTag(TIFF *tif, uint32 tag)
Definition: tif_dir.c:775

Referenced by TIFFSetField().

Variable Documentation

◆ _TIFFextender

TIFFExtendProc _TIFFextender = (TIFFExtendProc) NULL
static

Definition at line 1309 of file tif_dir.c.

Referenced by TIFFDefaultDirectory(), and TIFFSetTagExtender().