tif_dirinfo.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  1. /* $Id: tif_dirinfo.c,v 1.114 2011-05-17 00:21:17 fwarmerdam Exp $ */
  2. /*
  3. * Copyright (c) 1988-1997 Sam Leffler
  4. * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  5. *
  6. * Permission to use, copy, modify, distribute, and sell this software and
  7. * its documentation for any purpose is hereby granted without fee, provided
  8. * that (i) the above copyright notices and this permission notice appear in
  9. * all copies of the software and related documentation, and (ii) the names of
  10. * Sam Leffler and Silicon Graphics may not be used in any advertising or
  11. * publicity relating to the software without the specific, prior written
  12. * permission of Sam Leffler and Silicon Graphics.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
  15. * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  16. * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  17. *
  18. * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  19. * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  20. * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
  22. * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  23. * OF THIS SOFTWARE.
  24. */
  25. /*
  26. * TIFF Library.
  27. *
  28. * Core Directory Tag Support.
  29. */
  30. #include "tiffiop.h"
  31. #include <stdlib.h>
  32. /*
  33. * NOTE: THIS ARRAY IS ASSUMED TO BE SORTED BY TAG.
  34. *
  35. * NOTE: The second field (field_readcount) and third field (field_writecount)
  36. * sometimes use the values TIFF_VARIABLE (-1), TIFF_VARIABLE2 (-3)
  37. * and TIFF_SPP (-2). The macros should be used but would throw off
  38. * the formatting of the code, so please interprete the -1, -2 and -3
  39. * values accordingly.
  40. */
  41. static TIFFFieldArray tiffFieldArray;
  42. static TIFFFieldArray exifFieldArray;
  43. static TIFFField
  44. tiffFields[] = {
  45. { TIFFTAG_SUBFILETYPE, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_SUBFILETYPE, 1, 0, "SubfileType", NULL },
  46. { TIFFTAG_OSUBFILETYPE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_SUBFILETYPE, 1, 0, "OldSubfileType", NULL },
  47. { TIFFTAG_IMAGEWIDTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_IMAGEDIMENSIONS, 0, 0, "ImageWidth", NULL },
  48. { TIFFTAG_IMAGELENGTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_IMAGEDIMENSIONS, 1, 0, "ImageLength", NULL },
  49. { TIFFTAG_BITSPERSAMPLE, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_BITSPERSAMPLE, 0, 0, "BitsPerSample", NULL },
  50. { TIFFTAG_COMPRESSION, -1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_COMPRESSION, 0, 0, "Compression", NULL },
  51. { TIFFTAG_PHOTOMETRIC, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_PHOTOMETRIC, 0, 0, "PhotometricInterpretation", NULL },
  52. { TIFFTAG_THRESHHOLDING, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_THRESHHOLDING, 1, 0, "Threshholding", NULL },
  53. { TIFFTAG_CELLWIDTH, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "CellWidth", NULL },
  54. { TIFFTAG_CELLLENGTH, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "CellLength", NULL },
  55. { TIFFTAG_FILLORDER, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_FILLORDER, 0, 0, "FillOrder", NULL },
  56. { TIFFTAG_DOCUMENTNAME, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DocumentName", NULL },
  57. { TIFFTAG_IMAGEDESCRIPTION, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageDescription", NULL },
  58. { TIFFTAG_MAKE, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Make", NULL },
  59. { TIFFTAG_MODEL, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Model", NULL },
  60. { TIFFTAG_STRIPOFFSETS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_STRIPOFFSETS, 0, 0, "StripOffsets", NULL },
  61. { TIFFTAG_ORIENTATION, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_ORIENTATION, 0, 0, "Orientation", NULL },
  62. { TIFFTAG_SAMPLESPERPIXEL, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_SAMPLESPERPIXEL, 0, 0, "SamplesPerPixel", NULL },
  63. { TIFFTAG_ROWSPERSTRIP, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_ROWSPERSTRIP, 0, 0, "RowsPerStrip", NULL },
  64. { TIFFTAG_STRIPBYTECOUNTS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_STRIPBYTECOUNTS, 0, 0, "StripByteCounts", NULL },
  65. { TIFFTAG_MINSAMPLEVALUE, -2, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_MINSAMPLEVALUE, 1, 0, "MinSampleValue", NULL },
  66. { TIFFTAG_MAXSAMPLEVALUE, -2, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_MAXSAMPLEVALUE, 1, 0, "MaxSampleValue", NULL },
  67. { TIFFTAG_XRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_RESOLUTION, 1, 0, "XResolution", NULL },
  68. { TIFFTAG_YRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_RESOLUTION, 1, 0, "YResolution", NULL },
  69. { TIFFTAG_PLANARCONFIG, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_PLANARCONFIG, 0, 0, "PlanarConfiguration", NULL },
  70. { TIFFTAG_PAGENAME, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PageName", NULL },
  71. { TIFFTAG_XPOSITION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_POSITION, 1, 0, "XPosition", NULL },
  72. { TIFFTAG_YPOSITION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_POSITION, 1, 0, "YPosition", NULL },
  73. { TIFFTAG_FREEOFFSETS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 0, 0, "FreeOffsets", NULL },
  74. { TIFFTAG_FREEBYTECOUNTS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 0, 0, "FreeByteCounts", NULL },
  75. { TIFFTAG_GRAYRESPONSEUNIT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "GrayResponseUnit", NULL },
  76. { TIFFTAG_GRAYRESPONSECURVE, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "GrayResponseCurve", NULL },
  77. { TIFFTAG_RESOLUTIONUNIT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_RESOLUTIONUNIT, 1, 0, "ResolutionUnit", NULL },
  78. { TIFFTAG_PAGENUMBER, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_UINT16_PAIR, TIFF_SETGET_UNDEFINED, FIELD_PAGENUMBER, 1, 0, "PageNumber", NULL },
  79. { TIFFTAG_COLORRESPONSEUNIT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "ColorResponseUnit", NULL },
  80. { TIFFTAG_TRANSFERFUNCTION, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_OTHER, TIFF_SETGET_UNDEFINED, FIELD_TRANSFERFUNCTION, 1, 0, "TransferFunction", NULL },
  81. { TIFFTAG_SOFTWARE, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Software", NULL },
  82. { TIFFTAG_DATETIME, 20, 20, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DateTime", NULL },
  83. { TIFFTAG_ARTIST, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Artist", NULL },
  84. { TIFFTAG_HOSTCOMPUTER, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "HostComputer", NULL },
  85. { TIFFTAG_WHITEPOINT, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "WhitePoint", NULL },
  86. { TIFFTAG_PRIMARYCHROMATICITIES, 6, 6, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PrimaryChromaticities", NULL },
  87. { TIFFTAG_COLORMAP, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_OTHER, TIFF_SETGET_UNDEFINED, FIELD_COLORMAP, 1, 0, "ColorMap", NULL },
  88. { TIFFTAG_HALFTONEHINTS, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_UINT16_PAIR, TIFF_SETGET_UNDEFINED, FIELD_HALFTONEHINTS, 1, 0, "HalftoneHints", NULL },
  89. { TIFFTAG_TILEWIDTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_TILEDIMENSIONS, 0, 0, "TileWidth", NULL },
  90. { TIFFTAG_TILELENGTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_TILEDIMENSIONS, 0, 0, "TileLength", NULL },
  91. { TIFFTAG_TILEOFFSETS, -1, 1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_STRIPOFFSETS, 0, 0, "TileOffsets", NULL },
  92. { TIFFTAG_TILEBYTECOUNTS, -1, 1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_STRIPBYTECOUNTS, 0, 0, "TileByteCounts", NULL },
  93. { TIFFTAG_SUBIFD, -1, -1, TIFF_IFD8, 0, TIFF_SETGET_C16_IFD8, TIFF_SETGET_UNDEFINED, FIELD_SUBIFD, 1, 1, "SubIFD", &tiffFieldArray },
  94. { TIFFTAG_INKSET, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "InkSet", NULL },
  95. { TIFFTAG_INKNAMES, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_C16_ASCII, TIFF_SETGET_UNDEFINED, FIELD_INKNAMES, 1, 1, "InkNames", NULL },
  96. { TIFFTAG_NUMBEROFINKS, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "NumberOfInks", NULL },
  97. { TIFFTAG_DOTRANGE, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_UINT16_PAIR, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DotRange", NULL },
  98. { TIFFTAG_TARGETPRINTER, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "TargetPrinter", NULL },
  99. { TIFFTAG_EXTRASAMPLES, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_EXTRASAMPLES, 0, 1, "ExtraSamples", NULL },
  100. { TIFFTAG_SAMPLEFORMAT, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_SAMPLEFORMAT, 0, 0, "SampleFormat", NULL },
  101. { TIFFTAG_SMINSAMPLEVALUE, -2, -1, TIFF_ANY, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_SMINSAMPLEVALUE, 1, 0, "SMinSampleValue", NULL },
  102. { TIFFTAG_SMAXSAMPLEVALUE, -2, -1, TIFF_ANY, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_SMAXSAMPLEVALUE, 1, 0, "SMaxSampleValue", NULL },
  103. { TIFFTAG_CLIPPATH, -1, -3, TIFF_BYTE, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ClipPath", NULL },
  104. { TIFFTAG_XCLIPPATHUNITS, 1, 1, TIFF_SLONG, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "XClipPathUnits", NULL },
  105. { TIFFTAG_XCLIPPATHUNITS, 1, 1, TIFF_SBYTE, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "XClipPathUnits", NULL },
  106. { TIFFTAG_YCLIPPATHUNITS, 1, 1, TIFF_SLONG, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "YClipPathUnits", NULL },
  107. { TIFFTAG_YCBCRCOEFFICIENTS, 3, 3, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "YCbCrCoefficients", NULL },
  108. { TIFFTAG_YCBCRSUBSAMPLING, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_UINT16_PAIR, TIFF_SETGET_UNDEFINED, FIELD_YCBCRSUBSAMPLING, 0, 0, "YCbCrSubsampling", NULL },
  109. { TIFFTAG_YCBCRPOSITIONING, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_YCBCRPOSITIONING, 0, 0, "YCbCrPositioning", NULL },
  110. { TIFFTAG_REFERENCEBLACKWHITE, 6, 6, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_REFBLACKWHITE, 1, 0, "ReferenceBlackWhite", NULL },
  111. { TIFFTAG_XMLPACKET, -3, -3, TIFF_BYTE, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "XMLPacket", NULL },
  112. /* begin SGI tags */
  113. { TIFFTAG_MATTEING, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_EXTRASAMPLES, 0, 0, "Matteing", NULL },
  114. { TIFFTAG_DATATYPE, -2, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_SAMPLEFORMAT, 0, 0, "DataType", NULL },
  115. { TIFFTAG_IMAGEDEPTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_IMAGEDEPTH, 0, 0, "ImageDepth", NULL },
  116. { TIFFTAG_TILEDEPTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_TILEDEPTH, 0, 0, "TileDepth", NULL },
  117. /* end SGI tags */
  118. /* begin Pixar tags */
  119. { TIFFTAG_PIXAR_IMAGEFULLWIDTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageFullWidth", NULL },
  120. { TIFFTAG_PIXAR_IMAGEFULLLENGTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageFullLength", NULL },
  121. { TIFFTAG_PIXAR_TEXTUREFORMAT, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "TextureFormat", NULL },
  122. { TIFFTAG_PIXAR_WRAPMODES, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "TextureWrapModes", NULL },
  123. { TIFFTAG_PIXAR_FOVCOT, 1, 1, TIFF_FLOAT, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FieldOfViewCotangent", NULL },
  124. { TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN, 16, 16, TIFF_FLOAT, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MatrixWorldToScreen", NULL },
  125. { TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA, 16, 16, TIFF_FLOAT, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MatrixWorldToCamera", NULL },
  126. { TIFFTAG_COPYRIGHT, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Copyright", NULL },
  127. /* end Pixar tags */
  128. { TIFFTAG_RICHTIFFIPTC, -3, -3, TIFF_LONG, 0, TIFF_SETGET_C32_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "RichTIFFIPTC", NULL },
  129. { TIFFTAG_PHOTOSHOP, -3, -3, TIFF_BYTE, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "Photoshop", NULL },
  130. { TIFFTAG_EXIFIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "EXIFIFDOffset", &exifFieldArray },
  131. { TIFFTAG_ICCPROFILE, -3, -3, TIFF_UNDEFINED, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ICC Profile", NULL },
  132. { TIFFTAG_GPSIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "GPSIFDOffset", NULL },
  133. { TIFFTAG_FAXRECVPARAMS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UINT32, FIELD_CUSTOM, TRUE, FALSE, "FaxRecvParams", NULL },
  134. { TIFFTAG_FAXSUBADDRESS, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_ASCII, FIELD_CUSTOM, TRUE, FALSE, "FaxSubAddress", NULL },
  135. { TIFFTAG_FAXRECVTIME, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UINT32, FIELD_CUSTOM, TRUE, FALSE, "FaxRecvTime", NULL },
  136. { TIFFTAG_FAXDCS, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_ASCII, FIELD_CUSTOM, TRUE, FALSE, "FaxDcs", NULL },
  137. { TIFFTAG_STONITS, 1, 1, TIFF_DOUBLE, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "StoNits", NULL },
  138. { TIFFTAG_INTEROPERABILITYIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "InteroperabilityIFDOffset", NULL },
  139. /* begin DNG tags */
  140. { TIFFTAG_DNGVERSION, 4, 4, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DNGVersion", NULL },
  141. { TIFFTAG_DNGBACKWARDVERSION, 4, 4, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DNGBackwardVersion", NULL },
  142. { TIFFTAG_UNIQUECAMERAMODEL, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "UniqueCameraModel", NULL },
  143. { TIFFTAG_LOCALIZEDCAMERAMODEL, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "LocalizedCameraModel", NULL },
  144. { TIFFTAG_CFAPLANECOLOR, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CFAPlaneColor", NULL },
  145. { TIFFTAG_CFALAYOUT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CFALayout", NULL },
  146. { TIFFTAG_LINEARIZATIONTABLE, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "LinearizationTable", NULL },
  147. { TIFFTAG_BLACKLEVELREPEATDIM, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_C0_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BlackLevelRepeatDim", NULL },
  148. { TIFFTAG_BLACKLEVEL, -1, -1, TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "BlackLevel", NULL },
  149. { TIFFTAG_BLACKLEVELDELTAH, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "BlackLevelDeltaH", NULL },
  150. { TIFFTAG_BLACKLEVELDELTAV, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "BlackLevelDeltaV", NULL },
  151. { TIFFTAG_WHITELEVEL, -1, -1, TIFF_LONG, 0, TIFF_SETGET_C16_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "WhiteLevel", NULL },
  152. { TIFFTAG_DEFAULTSCALE, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DefaultScale", NULL },
  153. { TIFFTAG_BESTQUALITYSCALE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BestQualityScale", NULL },
  154. { TIFFTAG_DEFAULTCROPORIGIN, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DefaultCropOrigin", NULL },
  155. { TIFFTAG_DEFAULTCROPSIZE, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DefaultCropSize", NULL },
  156. { TIFFTAG_COLORMATRIX1, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ColorMatrix1", NULL },
  157. { TIFFTAG_COLORMATRIX2, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ColorMatrix2", NULL },
  158. { TIFFTAG_CAMERACALIBRATION1, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CameraCalibration1", NULL },
  159. { TIFFTAG_CAMERACALIBRATION2, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CameraCalibration2", NULL },
  160. { TIFFTAG_REDUCTIONMATRIX1, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ReductionMatrix1", NULL },
  161. { TIFFTAG_REDUCTIONMATRIX2, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ReductionMatrix2", NULL },
  162. { TIFFTAG_ANALOGBALANCE, -1, -1, TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "AnalogBalance", NULL },
  163. { TIFFTAG_ASSHOTNEUTRAL, -1, -1, TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "AsShotNeutral", NULL },
  164. { TIFFTAG_ASSHOTWHITEXY, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "AsShotWhiteXY", NULL },
  165. { TIFFTAG_BASELINEEXPOSURE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BaselineExposure", NULL },
  166. { TIFFTAG_BASELINENOISE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BaselineNoise", NULL },
  167. { TIFFTAG_BASELINESHARPNESS, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BaselineSharpness", NULL },
  168. { TIFFTAG_BAYERGREENSPLIT, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BayerGreenSplit", NULL },
  169. { TIFFTAG_LINEARRESPONSELIMIT, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "LinearResponseLimit", NULL },
  170. { TIFFTAG_CAMERASERIALNUMBER, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CameraSerialNumber", NULL },
  171. { TIFFTAG_LENSINFO, 4, 4, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "LensInfo", NULL },
  172. { TIFFTAG_CHROMABLURRADIUS, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ChromaBlurRadius", NULL },
  173. { TIFFTAG_ANTIALIASSTRENGTH, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "AntiAliasStrength", NULL },
  174. { TIFFTAG_SHADOWSCALE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ShadowScale", NULL },
  175. { TIFFTAG_DNGPRIVATEDATA, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "DNGPrivateData", NULL },
  176. { TIFFTAG_MAKERNOTESAFETY, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "MakerNoteSafety", NULL },
  177. { TIFFTAG_CALIBRATIONILLUMINANT1, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CalibrationIlluminant1", NULL },
  178. { TIFFTAG_CALIBRATIONILLUMINANT2, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CalibrationIlluminant2", NULL },
  179. { TIFFTAG_RAWDATAUNIQUEID, 16, 16, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "RawDataUniqueID", NULL },
  180. { TIFFTAG_ORIGINALRAWFILENAME, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "OriginalRawFileName", NULL },
  181. { TIFFTAG_ORIGINALRAWFILEDATA, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "OriginalRawFileData", NULL },
  182. { TIFFTAG_ACTIVEAREA, 4, 4, TIFF_LONG, 0, TIFF_SETGET_C0_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ActiveArea", NULL },
  183. { TIFFTAG_MASKEDAREAS, -1, -1, TIFF_LONG, 0, TIFF_SETGET_C16_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "MaskedAreas", NULL },
  184. { TIFFTAG_ASSHOTICCPROFILE, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "AsShotICCProfile", NULL },
  185. { TIFFTAG_ASSHOTPREPROFILEMATRIX, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "AsShotPreProfileMatrix", NULL },
  186. { TIFFTAG_CURRENTICCPROFILE, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CurrentICCProfile", NULL },
  187. { TIFFTAG_CURRENTPREPROFILEMATRIX, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CurrentPreProfileMatrix", NULL },
  188. /* end DNG tags */
  189. /* begin TIFF/FX tags */
  190. { TIFFTAG_INDEXED, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "Indexed" },
  191. { TIFFTAG_GLOBALPARAMETERSIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "GlobalParametersIFD", NULL },
  192. { TIFFTAG_PROFILETYPE, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ProfileType", NULL },
  193. { TIFFTAG_FAXPROFILE, 1, 1, TIFF_BYTE, 0, TIFF_SETGET_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "FaxProfile", NULL },
  194. { TIFFTAG_CODINGMETHODS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CodingMethods", NULL },
  195. { TIFFTAG_VERSIONYEAR, 4, 4, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "VersionYear", NULL },
  196. { TIFFTAG_MODENUMBER, 1, 1, TIFF_BYTE, 0, TIFF_SETGET_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ModeNumber", NULL },
  197. { TIFFTAG_DECODE, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "Decode", NULL },
  198. { TIFFTAG_IMAGEBASECOLOR, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ImageBaseColor", NULL },
  199. { TIFFTAG_T82OPTIONS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "T82Options", NULL },
  200. { TIFFTAG_STRIPROWCOUNTS, -1, -1, TIFF_LONG, 0, TIFF_SETGET_C16_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "StripRowCounts", NULL },
  201. { TIFFTAG_IMAGELAYER, 2, 2, TIFF_LONG, 0, TIFF_SETGET_C0_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ImageLayer", NULL },
  202. /* end TIFF/FX tags */
  203. /* begin pseudo tags */
  204. { TIFFTAG_PERSAMPLE, 0, 0, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "PerSample", NULL},
  205. };
  206. static TIFFField
  207. exifFields[] = {
  208. { EXIFTAG_EXPOSURETIME, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureTime", NULL },
  209. { EXIFTAG_FNUMBER, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FNumber", NULL },
  210. { EXIFTAG_EXPOSUREPROGRAM, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureProgram", NULL },
  211. { EXIFTAG_SPECTRALSENSITIVITY, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SpectralSensitivity", NULL },
  212. { EXIFTAG_ISOSPEEDRATINGS, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "ISOSpeedRatings", NULL },
  213. { EXIFTAG_OECF, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "OptoelectricConversionFactor", NULL },
  214. { EXIFTAG_EXIFVERSION, 4, 4, TIFF_UNDEFINED, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExifVersion", NULL },
  215. { EXIFTAG_DATETIMEORIGINAL, 20, 20, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DateTimeOriginal", NULL },
  216. { EXIFTAG_DATETIMEDIGITIZED, 20, 20, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DateTimeDigitized", NULL },
  217. { EXIFTAG_COMPONENTSCONFIGURATION, 4, 4, TIFF_UNDEFINED, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ComponentsConfiguration", NULL },
  218. { EXIFTAG_COMPRESSEDBITSPERPIXEL, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CompressedBitsPerPixel", NULL },
  219. { EXIFTAG_SHUTTERSPEEDVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ShutterSpeedValue", NULL },
  220. { EXIFTAG_APERTUREVALUE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ApertureValue", NULL },
  221. { EXIFTAG_BRIGHTNESSVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "BrightnessValue", NULL },
  222. { EXIFTAG_EXPOSUREBIASVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureBiasValue", NULL },
  223. { EXIFTAG_MAXAPERTUREVALUE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MaxApertureValue", NULL },
  224. { EXIFTAG_SUBJECTDISTANCE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubjectDistance", NULL },
  225. { EXIFTAG_METERINGMODE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MeteringMode", NULL },
  226. { EXIFTAG_LIGHTSOURCE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "LightSource", NULL },
  227. { EXIFTAG_FLASH, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Flash", NULL },
  228. { EXIFTAG_FOCALLENGTH, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalLength", NULL },
  229. { EXIFTAG_SUBJECTAREA, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "SubjectArea", NULL },
  230. { EXIFTAG_MAKERNOTE, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "MakerNote", NULL },
  231. { EXIFTAG_USERCOMMENT, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "UserComment", NULL },
  232. { EXIFTAG_SUBSECTIME, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubSecTime", NULL },
  233. { EXIFTAG_SUBSECTIMEORIGINAL, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubSecTimeOriginal", NULL },
  234. { EXIFTAG_SUBSECTIMEDIGITIZED, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubSecTimeDigitized", NULL },
  235. { EXIFTAG_FLASHPIXVERSION, 4, 4, TIFF_UNDEFINED, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FlashpixVersion", NULL },
  236. { EXIFTAG_COLORSPACE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ColorSpace", NULL },
  237. { EXIFTAG_PIXELXDIMENSION, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PixelXDimension", NULL },
  238. { EXIFTAG_PIXELYDIMENSION, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PixelYDimension", NULL },
  239. { EXIFTAG_RELATEDSOUNDFILE, 13, 13, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "RelatedSoundFile", NULL },
  240. { EXIFTAG_FLASHENERGY, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FlashEnergy", NULL },
  241. { EXIFTAG_SPATIALFREQUENCYRESPONSE, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "SpatialFrequencyResponse", NULL },
  242. { EXIFTAG_FOCALPLANEXRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalPlaneXResolution", NULL },
  243. { EXIFTAG_FOCALPLANEYRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalPlaneYResolution", NULL },
  244. { EXIFTAG_FOCALPLANERESOLUTIONUNIT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalPlaneResolutionUnit", NULL },
  245. { EXIFTAG_SUBJECTLOCATION, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_C0_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubjectLocation", NULL },
  246. { EXIFTAG_EXPOSUREINDEX, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureIndex", NULL },
  247. { EXIFTAG_SENSINGMETHOD, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SensingMethod", NULL },
  248. { EXIFTAG_FILESOURCE, 1, 1, TIFF_UNDEFINED, 0, TIFF_SETGET_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FileSource", NULL },
  249. { EXIFTAG_SCENETYPE, 1, 1, TIFF_UNDEFINED, 0, TIFF_SETGET_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SceneType", NULL },
  250. { EXIFTAG_CFAPATTERN, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "CFAPattern", NULL },
  251. { EXIFTAG_CUSTOMRENDERED, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CustomRendered", NULL },
  252. { EXIFTAG_EXPOSUREMODE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureMode", NULL },
  253. { EXIFTAG_WHITEBALANCE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "WhiteBalance", NULL },
  254. { EXIFTAG_DIGITALZOOMRATIO, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DigitalZoomRatio", NULL },
  255. { EXIFTAG_FOCALLENGTHIN35MMFILM, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalLengthIn35mmFilm", NULL },
  256. { EXIFTAG_SCENECAPTURETYPE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SceneCaptureType", NULL },
  257. { EXIFTAG_GAINCONTROL, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "GainControl", NULL },
  258. { EXIFTAG_CONTRAST, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Contrast", NULL },
  259. { EXIFTAG_SATURATION, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Saturation", NULL },
  260. { EXIFTAG_SHARPNESS, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Sharpness", NULL },
  261. { EXIFTAG_DEVICESETTINGDESCRIPTION, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "DeviceSettingDescription", NULL },
  262. { EXIFTAG_SUBJECTDISTANCERANGE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubjectDistanceRange", NULL },
  263. { EXIFTAG_IMAGEUNIQUEID, 33, 33, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageUniqueID", NULL }
  264. };
  265. static TIFFFieldArray
  266. tiffFieldArray = { tfiatImage, 0, TIFFArrayCount(tiffFields), tiffFields };
  267. static TIFFFieldArray
  268. exifFieldArray = { tfiatExif, 0, TIFFArrayCount(exifFields), exifFields };
  269. /*
  270. * We have our own local lfind() equivelent to avoid subtle differences
  271. * in types passed to lfind() on different systems.
  272. */
  273. static void *
  274. td_lfind(const void *key, const void *base, size_t *nmemb, size_t size,
  275. int(*compar)(const void *, const void *))
  276. {
  277. char *element, *end;
  278. end = (char *)base + *nmemb * size;
  279. for (element = (char *)base; element < end; element += size)
  280. if (!compar(key, element)) /* key found */
  281. return element;
  282. return NULL;
  283. }
  284. const TIFFFieldArray*
  285. _TIFFGetFields(void)
  286. {
  287. return(&tiffFieldArray);
  288. }
  289. const TIFFFieldArray*
  290. _TIFFGetExifFields(void)
  291. {
  292. return(&exifFieldArray);
  293. }
  294. void
  295. _TIFFSetupFields(TIFF* tif, const TIFFFieldArray* fieldarray)
  296. {
  297. if (tif->tif_fields && tif->tif_nfields > 0) {
  298. uint32 i;
  299. for (i = 0; i < tif->tif_nfields; i++) {
  300. TIFFField *fld = tif->tif_fields[i];
  301. if (fld->field_bit == FIELD_CUSTOM &&
  302. strncmp("Tag ", fld->field_name, 4) == 0) {
  303. _TIFFfree(fld->field_name);
  304. _TIFFfree(fld);
  305. }
  306. }
  307. _TIFFfree(tif->tif_fields);
  308. tif->tif_fields = NULL;
  309. tif->tif_nfields = 0;
  310. }
  311. if (!_TIFFMergeFields(tif, fieldarray->fields, fieldarray->count)) {
  312. TIFFErrorExt(tif->tif_clientdata, "_TIFFSetupFields",
  313. "Setting up field info failed");
  314. }
  315. }
  316. static int
  317. tagCompare(const void* a, const void* b)
  318. {
  319. const TIFFField* ta = *(const TIFFField**) a;
  320. const TIFFField* tb = *(const TIFFField**) b;
  321. /* NB: be careful of return values for 16-bit platforms */
  322. if (ta->field_tag != tb->field_tag)
  323. return (int)ta->field_tag - (int)tb->field_tag;
  324. else
  325. return (ta->field_type == TIFF_ANY) ?
  326. 0 : ((int)tb->field_type - (int)ta->field_type);
  327. }
  328. static int
  329. tagNameCompare(const void* a, const void* b)
  330. {
  331. const TIFFField* ta = *(const TIFFField**) a;
  332. const TIFFField* tb = *(const TIFFField**) b;
  333. int ret = strcmp(ta->field_name, tb->field_name);
  334. if (ret)
  335. return ret;
  336. else
  337. return (ta->field_type == TIFF_ANY) ?
  338. 0 : ((int)tb->field_type - (int)ta->field_type);
  339. }
  340. int
  341. _TIFFMergeFields(TIFF* tif, const TIFFField info[], uint32 n)
  342. {
  343. static const char module[] = "_TIFFMergeFields";
  344. static const char reason[] = "for fields array";
  345. TIFFField** tp;
  346. uint32 i;
  347. tif->tif_foundfield = NULL;
  348. if (tif->tif_fields && tif->tif_nfields > 0) {
  349. tif->tif_fields = (TIFFField**)
  350. _TIFFCheckRealloc(tif, tif->tif_fields,
  351. (tif->tif_nfields + n),
  352. sizeof(TIFFField *), reason);
  353. } else {
  354. tif->tif_fields = (TIFFField **)
  355. _TIFFCheckMalloc(tif, n, sizeof(TIFFField *),
  356. reason);
  357. }
  358. if (!tif->tif_fields) {
  359. TIFFErrorExt(tif->tif_clientdata, module,
  360. "Failed to allocate fields array");
  361. return 0;
  362. }
  363. tp = tif->tif_fields + tif->tif_nfields;
  364. for (i = 0; i < n; i++) {
  365. const TIFFField *fip =
  366. TIFFFindField(tif, info[i].field_tag, TIFF_ANY);
  367. /* only add definitions that aren't already present */
  368. if (!fip) {
  369. tif->tif_fields[tif->tif_nfields] = (TIFFField *) (info+i);
  370. tif->tif_nfields++;
  371. }
  372. }
  373. /* Sort the field info by tag number */
  374. qsort(tif->tif_fields, tif->tif_nfields,
  375. sizeof(TIFFField *), tagCompare);
  376. return n;
  377. }
  378. void
  379. _TIFFPrintFieldInfo(TIFF* tif, FILE* fd)
  380. {
  381. uint32 i;
  382. fprintf(fd, "%s: \n", tif->tif_name);
  383. for (i = 0; i < tif->tif_nfields; i++) {
  384. const TIFFField* fip = tif->tif_fields[i];
  385. fprintf(fd, "field[%2d] %5lu, %2d, %2d, %d, %2d, %5s, %5s, %s\n"
  386. , (int)i
  387. , (unsigned long) fip->field_tag
  388. , fip->field_readcount, fip->field_writecount
  389. , fip->field_type
  390. , fip->field_bit
  391. , fip->field_oktochange ? "TRUE" : "FALSE"
  392. , fip->field_passcount ? "TRUE" : "FALSE"
  393. , fip->field_name
  394. );
  395. }
  396. }
  397. /*
  398. * Return size of TIFFDataType in bytes
  399. */
  400. int
  401. TIFFDataWidth(TIFFDataType type)
  402. {
  403. switch(type)
  404. {
  405. case 0: /* nothing */
  406. case TIFF_BYTE:
  407. case TIFF_ASCII:
  408. case TIFF_SBYTE:
  409. case TIFF_UNDEFINED:
  410. return 1;
  411. case TIFF_SHORT:
  412. case TIFF_SSHORT:
  413. return 2;
  414. case TIFF_LONG:
  415. case TIFF_SLONG:
  416. case TIFF_FLOAT:
  417. case TIFF_IFD:
  418. return 4;
  419. case TIFF_RATIONAL:
  420. case TIFF_SRATIONAL:
  421. case TIFF_DOUBLE:
  422. case TIFF_LONG8:
  423. case TIFF_SLONG8:
  424. case TIFF_IFD8:
  425. return 8;
  426. default:
  427. return 0; /* will return 0 for unknown types */
  428. }
  429. }
  430. /*
  431. * Return size of TIFFDataType in bytes.
  432. *
  433. * XXX: We need a separate function to determine the space needed
  434. * to store the value. For TIFF_RATIONAL values TIFFDataWidth() returns 8,
  435. * but we use 4-byte float to represent rationals.
  436. */
  437. int
  438. _TIFFDataSize(TIFFDataType type)
  439. {
  440. switch (type)
  441. {
  442. case TIFF_BYTE:
  443. case TIFF_SBYTE:
  444. case TIFF_ASCII:
  445. case TIFF_UNDEFINED:
  446. return 1;
  447. case TIFF_SHORT:
  448. case TIFF_SSHORT:
  449. return 2;
  450. case TIFF_LONG:
  451. case TIFF_SLONG:
  452. case TIFF_FLOAT:
  453. case TIFF_IFD:
  454. case TIFF_RATIONAL:
  455. case TIFF_SRATIONAL:
  456. return 4;
  457. case TIFF_DOUBLE:
  458. case TIFF_LONG8:
  459. case TIFF_SLONG8:
  460. case TIFF_IFD8:
  461. return 8;
  462. default:
  463. return 0;
  464. }
  465. }
  466. const TIFFField*
  467. TIFFFindField(TIFF* tif, uint32 tag, TIFFDataType dt)
  468. {
  469. TIFFField key = {0, 0, 0, TIFF_NOTYPE, 0, 0, 0, 0, 0, 0, NULL, NULL};
  470. TIFFField* pkey = &key;
  471. const TIFFField **ret;
  472. if (tif->tif_foundfield && tif->tif_foundfield->field_tag == tag &&
  473. (dt == TIFF_ANY || dt == tif->tif_foundfield->field_type))
  474. return tif->tif_foundfield;
  475. /* If we are invoked with no field information, then just return. */
  476. if (!tif->tif_fields)
  477. return NULL;
  478. /* NB: use sorted search (e.g. binary search) */
  479. key.field_tag = tag;
  480. key.field_type = dt;
  481. ret = (const TIFFField **) bsearch(&pkey, tif->tif_fields,
  482. tif->tif_nfields,
  483. sizeof(TIFFField *), tagCompare);
  484. return tif->tif_foundfield = (ret ? *ret : NULL);
  485. }
  486. const TIFFField*
  487. _TIFFFindFieldByName(TIFF* tif, const char *field_name, TIFFDataType dt)
  488. {
  489. TIFFField key = {0, 0, 0, TIFF_NOTYPE, 0, 0, 0, 0, 0, 0, NULL, NULL};
  490. TIFFField* pkey = &key;
  491. const TIFFField **ret;
  492. if (tif->tif_foundfield
  493. && streq(tif->tif_foundfield->field_name, field_name)
  494. && (dt == TIFF_ANY || dt == tif->tif_foundfield->field_type))
  495. return (tif->tif_foundfield);
  496. /* If we are invoked with no field information, then just return. */
  497. if (!tif->tif_fields)
  498. return NULL;
  499. /* NB: use linear search since list is sorted by key#, not name */
  500. key.field_name = (char *)field_name;
  501. key.field_type = dt;
  502. ret = (const TIFFField **)
  503. td_lfind(&pkey, tif->tif_fields, &tif->tif_nfields,
  504. sizeof(TIFFField *), tagNameCompare);
  505. return tif->tif_foundfield = (ret ? *ret : NULL);
  506. }
  507. const TIFFField*
  508. TIFFFieldWithTag(TIFF* tif, uint32 tag)
  509. {
  510. const TIFFField* fip = TIFFFindField(tif, tag, TIFF_ANY);
  511. if (!fip) {
  512. TIFFErrorExt(tif->tif_clientdata, "TIFFFieldWithTag",
  513. "Internal error, unknown tag 0x%x",
  514. (unsigned int) tag);
  515. }
  516. return (fip);
  517. }
  518. const TIFFField*
  519. TIFFFieldWithName(TIFF* tif, const char *field_name)
  520. {
  521. const TIFFField* fip =
  522. _TIFFFindFieldByName(tif, field_name, TIFF_ANY);
  523. if (!fip) {
  524. TIFFErrorExt(tif->tif_clientdata, "TIFFFieldWithName",
  525. "Internal error, unknown tag %s", field_name);
  526. }
  527. return (fip);
  528. }
  529. const TIFFField*
  530. _TIFFFindOrRegisterField(TIFF *tif, uint32 tag, TIFFDataType dt)
  531. {
  532. const TIFFField *fld;
  533. fld = TIFFFindField(tif, tag, dt);
  534. if (fld == NULL) {
  535. fld = _TIFFCreateAnonField(tif, tag, dt);
  536. if (!_TIFFMergeFields(tif, fld, 1))
  537. return NULL;
  538. }
  539. return fld;
  540. }
  541. TIFFField*
  542. _TIFFCreateAnonField(TIFF *tif, uint32 tag, TIFFDataType field_type)
  543. {
  544. TIFFField *fld;
  545. (void) tif;
  546. fld = (TIFFField *) _TIFFmalloc(sizeof (TIFFField));
  547. if (fld == NULL)
  548. return NULL;
  549. _TIFFmemset(fld, 0, sizeof(TIFFField));
  550. fld->field_tag = tag;
  551. fld->field_readcount = TIFF_VARIABLE2;
  552. fld->field_writecount = TIFF_VARIABLE2;
  553. fld->field_type = field_type;
  554. fld->reserved = 0;
  555. switch (field_type)
  556. {
  557. case TIFF_BYTE:
  558. case TIFF_UNDEFINED:
  559. fld->set_field_type = TIFF_SETGET_C32_UINT8;
  560. fld->get_field_type = TIFF_SETGET_C32_UINT8;
  561. break;
  562. case TIFF_ASCII:
  563. fld->set_field_type = TIFF_SETGET_C32_ASCII;
  564. fld->get_field_type = TIFF_SETGET_C32_ASCII;
  565. break;
  566. case TIFF_SHORT:
  567. fld->set_field_type = TIFF_SETGET_C32_UINT16;
  568. fld->get_field_type = TIFF_SETGET_C32_UINT16;
  569. break;
  570. case TIFF_LONG:
  571. fld->set_field_type = TIFF_SETGET_C32_UINT32;
  572. fld->get_field_type = TIFF_SETGET_C32_UINT32;
  573. break;
  574. case TIFF_RATIONAL:
  575. case TIFF_SRATIONAL:
  576. case TIFF_FLOAT:
  577. fld->set_field_type = TIFF_SETGET_C32_FLOAT;
  578. fld->get_field_type = TIFF_SETGET_C32_FLOAT;
  579. break;
  580. case TIFF_SBYTE:
  581. fld->set_field_type = TIFF_SETGET_C32_SINT8;
  582. fld->get_field_type = TIFF_SETGET_C32_SINT8;
  583. break;
  584. case TIFF_SSHORT:
  585. fld->set_field_type = TIFF_SETGET_C32_SINT16;
  586. fld->get_field_type = TIFF_SETGET_C32_SINT16;
  587. break;
  588. case TIFF_SLONG:
  589. fld->set_field_type = TIFF_SETGET_C32_SINT32;
  590. fld->get_field_type = TIFF_SETGET_C32_SINT32;
  591. break;
  592. case TIFF_DOUBLE:
  593. fld->set_field_type = TIFF_SETGET_C32_DOUBLE;
  594. fld->get_field_type = TIFF_SETGET_C32_DOUBLE;
  595. break;
  596. case TIFF_IFD:
  597. case TIFF_IFD8:
  598. fld->set_field_type = TIFF_SETGET_C32_IFD8;
  599. fld->get_field_type = TIFF_SETGET_C32_IFD8;
  600. break;
  601. case TIFF_LONG8:
  602. fld->set_field_type = TIFF_SETGET_C32_UINT64;
  603. fld->get_field_type = TIFF_SETGET_C32_UINT64;
  604. break;
  605. case TIFF_SLONG8:
  606. fld->set_field_type = TIFF_SETGET_C32_SINT64;
  607. fld->get_field_type = TIFF_SETGET_C32_SINT64;
  608. break;
  609. default:
  610. fld->set_field_type = TIFF_SETGET_UNDEFINED;
  611. fld->get_field_type = TIFF_SETGET_UNDEFINED;
  612. break;
  613. }
  614. fld->field_bit = FIELD_CUSTOM;
  615. fld->field_oktochange = TRUE;
  616. fld->field_passcount = TRUE;
  617. fld->field_name = (char *) _TIFFmalloc(32);
  618. if (fld->field_name == NULL) {
  619. _TIFFfree(fld);
  620. return NULL;
  621. }
  622. fld->field_subfields = NULL;
  623. /*
  624. * note that this name is a special sign to TIFFClose() and
  625. * _TIFFSetupFields() to free the field
  626. */
  627. sprintf(fld->field_name, "Tag %d", (int) tag);
  628. return fld;
  629. }
  630. /****************************************************************************
  631. * O B S O L E T E D I N T E R F A C E S
  632. *
  633. * Don't use this stuff in your applications, it may be removed in the future
  634. * libtiff versions.
  635. ****************************************************************************/
  636. static TIFFSetGetFieldType
  637. _TIFFSetGetType(TIFFDataType type, short count, unsigned char passcount)
  638. {
  639. if (type == TIFF_ASCII && count == TIFF_VARIABLE && passcount == 0)
  640. return TIFF_SETGET_ASCII;
  641. else if (count == 1 && passcount == 0) {
  642. switch (type)
  643. {
  644. case TIFF_BYTE:
  645. case TIFF_UNDEFINED:
  646. return TIFF_SETGET_UINT8;
  647. case TIFF_ASCII:
  648. return TIFF_SETGET_ASCII;
  649. case TIFF_SHORT:
  650. return TIFF_SETGET_UINT16;
  651. case TIFF_LONG:
  652. return TIFF_SETGET_UINT32;
  653. case TIFF_RATIONAL:
  654. case TIFF_SRATIONAL:
  655. case TIFF_FLOAT:
  656. return TIFF_SETGET_FLOAT;
  657. case TIFF_SBYTE:
  658. return TIFF_SETGET_SINT8;
  659. case TIFF_SSHORT:
  660. return TIFF_SETGET_SINT16;
  661. case TIFF_SLONG:
  662. return TIFF_SETGET_SINT32;
  663. case TIFF_DOUBLE:
  664. return TIFF_SETGET_DOUBLE;
  665. case TIFF_IFD:
  666. case TIFF_IFD8:
  667. return TIFF_SETGET_IFD8;
  668. case TIFF_LONG8:
  669. return TIFF_SETGET_UINT64;
  670. case TIFF_SLONG8:
  671. return TIFF_SETGET_SINT64;
  672. default:
  673. return TIFF_SETGET_UNDEFINED;
  674. }
  675. }
  676. else if (count >= 1 && passcount == 0) {
  677. switch (type)
  678. {
  679. case TIFF_BYTE:
  680. case TIFF_UNDEFINED:
  681. return TIFF_SETGET_C0_UINT8;
  682. case TIFF_ASCII:
  683. return TIFF_SETGET_C0_ASCII;
  684. case TIFF_SHORT:
  685. return TIFF_SETGET_C0_UINT16;
  686. case TIFF_LONG:
  687. return TIFF_SETGET_C0_UINT32;
  688. case TIFF_RATIONAL:
  689. case TIFF_SRATIONAL:
  690. case TIFF_FLOAT:
  691. return TIFF_SETGET_C0_FLOAT;
  692. case TIFF_SBYTE:
  693. return TIFF_SETGET_C0_SINT8;
  694. case TIFF_SSHORT:
  695. return TIFF_SETGET_C0_SINT16;
  696. case TIFF_SLONG:
  697. return TIFF_SETGET_C0_SINT32;
  698. case TIFF_DOUBLE:
  699. return TIFF_SETGET_C0_DOUBLE;
  700. case TIFF_IFD:
  701. case TIFF_IFD8:
  702. return TIFF_SETGET_C0_IFD8;
  703. case TIFF_LONG8:
  704. return TIFF_SETGET_C0_UINT64;
  705. case TIFF_SLONG8:
  706. return TIFF_SETGET_C0_SINT64;
  707. default:
  708. return TIFF_SETGET_UNDEFINED;
  709. }
  710. }
  711. else if (count == TIFF_VARIABLE && passcount == 1) {
  712. switch (type)
  713. {
  714. case TIFF_BYTE:
  715. case TIFF_UNDEFINED:
  716. return TIFF_SETGET_C16_UINT8;
  717. case TIFF_ASCII:
  718. return TIFF_SETGET_C16_ASCII;
  719. case TIFF_SHORT:
  720. return TIFF_SETGET_C16_UINT16;
  721. case TIFF_LONG:
  722. return TIFF_SETGET_C16_UINT32;
  723. case TIFF_RATIONAL:
  724. case TIFF_SRATIONAL:
  725. case TIFF_FLOAT:
  726. return TIFF_SETGET_C16_FLOAT;
  727. case TIFF_SBYTE:
  728. return TIFF_SETGET_C16_SINT8;
  729. case TIFF_SSHORT:
  730. return TIFF_SETGET_C16_SINT16;
  731. case TIFF_SLONG:
  732. return TIFF_SETGET_C16_SINT32;
  733. case TIFF_DOUBLE:
  734. return TIFF_SETGET_C16_DOUBLE;
  735. case TIFF_IFD:
  736. case TIFF_IFD8:
  737. return TIFF_SETGET_C16_IFD8;
  738. case TIFF_LONG8:
  739. return TIFF_SETGET_C16_UINT64;
  740. case TIFF_SLONG8:
  741. return TIFF_SETGET_C16_SINT64;
  742. default:
  743. return TIFF_SETGET_UNDEFINED;
  744. }
  745. }
  746. else if (count == TIFF_VARIABLE2 && passcount == 1) {
  747. switch (type)
  748. {
  749. case TIFF_BYTE:
  750. case TIFF_UNDEFINED:
  751. return TIFF_SETGET_C32_UINT8;
  752. case TIFF_ASCII:
  753. return TIFF_SETGET_C32_ASCII;
  754. case TIFF_SHORT:
  755. return TIFF_SETGET_C32_UINT16;
  756. case TIFF_LONG:
  757. return TIFF_SETGET_C32_UINT32;
  758. case TIFF_RATIONAL:
  759. case TIFF_SRATIONAL:
  760. case TIFF_FLOAT:
  761. return TIFF_SETGET_C32_FLOAT;
  762. case TIFF_SBYTE:
  763. return TIFF_SETGET_C32_SINT8;
  764. case TIFF_SSHORT:
  765. return TIFF_SETGET_C32_SINT16;
  766. case TIFF_SLONG:
  767. return TIFF_SETGET_C32_SINT32;
  768. case TIFF_DOUBLE:
  769. return TIFF_SETGET_C32_DOUBLE;
  770. case TIFF_IFD:
  771. case TIFF_IFD8:
  772. return TIFF_SETGET_C32_IFD8;
  773. case TIFF_LONG8:
  774. return TIFF_SETGET_C32_UINT64;
  775. case TIFF_SLONG8:
  776. return TIFF_SETGET_C32_SINT64;
  777. default:
  778. return TIFF_SETGET_UNDEFINED;
  779. }
  780. }
  781. return TIFF_SETGET_UNDEFINED;
  782. }
  783. int
  784. TIFFMergeFieldInfo(TIFF* tif, const TIFFFieldInfo info[], uint32 n)
  785. {
  786. static const char module[] = "TIFFMergeFieldInfo";
  787. static const char reason[] = "for fields array";
  788. TIFFField *tp;
  789. size_t nfields;
  790. uint32 i;
  791. if (tif->tif_nfieldscompat > 0) {
  792. tif->tif_fieldscompat = (TIFFFieldArray *)
  793. _TIFFCheckRealloc(tif, tif->tif_fieldscompat,
  794. tif->tif_nfieldscompat + 1,
  795. sizeof(TIFFFieldArray), reason);
  796. } else {
  797. tif->tif_fieldscompat = (TIFFFieldArray *)
  798. _TIFFCheckMalloc(tif, 1, sizeof(TIFFFieldArray),
  799. reason);
  800. }
  801. if (!tif->tif_fieldscompat) {
  802. TIFFErrorExt(tif->tif_clientdata, module,
  803. "Failed to allocate fields array");
  804. return -1;
  805. }
  806. nfields = tif->tif_nfieldscompat++;
  807. tif->tif_fieldscompat[nfields].type = tfiatOther;
  808. tif->tif_fieldscompat[nfields].allocated_size = n;
  809. tif->tif_fieldscompat[nfields].count = n;
  810. tif->tif_fieldscompat[nfields].fields =
  811. (TIFFField *)_TIFFCheckMalloc(tif, n, sizeof(TIFFField),
  812. reason);
  813. if (!tif->tif_fieldscompat[nfields].fields) {
  814. TIFFErrorExt(tif->tif_clientdata, module,
  815. "Failed to allocate fields array");
  816. return -1;
  817. }
  818. tp = tif->tif_fieldscompat[nfields].fields;
  819. for (i = 0; i < n; i++) {
  820. tp->field_tag = info[i].field_tag;
  821. tp->field_readcount = info[i].field_readcount;
  822. tp->field_writecount = info[i].field_writecount;
  823. tp->field_type = info[i].field_type;
  824. tp->reserved = 0;
  825. tp->set_field_type =
  826. _TIFFSetGetType(info[i].field_type,
  827. info[i].field_readcount,
  828. info[i].field_passcount);
  829. tp->get_field_type =
  830. _TIFFSetGetType(info[i].field_type,
  831. info[i].field_readcount,
  832. info[i].field_passcount);
  833. tp->field_bit = info[i].field_bit;
  834. tp->field_oktochange = info[i].field_oktochange;
  835. tp->field_passcount = info[i].field_passcount;
  836. tp->field_name = info[i].field_name;
  837. tp->field_subfields = NULL;
  838. tp++;
  839. }
  840. if (!_TIFFMergeFields(tif, tif->tif_fieldscompat[nfields].fields, n)) {
  841. TIFFErrorExt(tif->tif_clientdata, module,
  842. "Setting up field info failed");
  843. return -1;
  844. }
  845. return 0;
  846. }
  847. /* vim: set ts=8 sts=8 sw=8 noet: */
  848. /*
  849. * Local Variables:
  850. * mode: c
  851. * c-basic-offset: 8
  852. * fill-column: 78
  853. * End:
  854. */