LibTiffDelphi.pas 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695
  1. unit LibTiffDelphi;
  2. (*
  3. {$IFOPT D+}
  4. {$DEFINE LIBTIFF_DEBUG}
  5. {$ENDIF}
  6. *)
  7. {$ALIGN 8}
  8. {$MINENUMSIZE 1}
  9. interface
  10. uses
  11. Windows, SysUtils, Classes;
  12. const
  13. //DW
  14. LibTiffDelphiVersionString = 'LibTiffDelphi 3.9.1.00'#13#10'Pre-compiled LibTiff for Delphi'#13#10'http://www.awaresystems.be/'#13#10'3.9.1 implementaion by Do-wan Kim'#13#10;
  15. TIFF_NOTYPE = 0;
  16. TIFF_BYTE = 1; { 8-bit unsigned integer }
  17. TIFF_ASCII = 2; { 8-bit bytes w/ last byte null }
  18. TIFF_SHORT = 3; { 16-bit unsigned integer }
  19. TIFF_LONG = 4; { 32-bit unsigned integer }
  20. TIFF_RATIONAL = 5; { 64-bit unsigned fraction }
  21. TIFF_SBYTE = 6; { !8-bit signed integer }
  22. TIFF_UNDEFINED = 7; { !8-bit untyped data }
  23. TIFF_SSHORT = 8; { !16-bit signed integer }
  24. TIFF_SLONG = 9; { !32-bit signed integer }
  25. TIFF_SRATIONAL = 10; { !64-bit signed fraction }
  26. TIFF_FLOAT = 11; { !32-bit IEEE floating point }
  27. TIFF_DOUBLE = 12; { !64-bit IEEE floating point }
  28. TIFF_IFD = 13; { %32-bit unsigned integer (offset) }
  29. TIFF_UNICODE = 14;
  30. TIFF_COMPLEX = 15;
  31. TIFF_LONG8 = 16;
  32. TIFF_SLONG8 = 17;
  33. TIFF_IFD8 = 18;
  34. TIFFTAG_SUBFILETYPE = 254; { subfile data descriptor }
  35. FILETYPE_REDUCEDIMAGE = $1; { reduced resolution version }
  36. FILETYPE_PAGE = $2; { one page of many }
  37. FILETYPE_MASK = $4; { transparency mask }
  38. TIFFTAG_OSUBFILETYPE = 255; { kind of data in subfile }
  39. OFILETYPE_IMAGE = 1; { full resolution image data }
  40. OFILETYPE_REDUCEDIMAGE = 2; { reduced size image data }
  41. OFILETYPE_PAGE = 3; { one page of many }
  42. TIFFTAG_IMAGEWIDTH = 256; { image width in pixels }
  43. TIFFTAG_IMAGELENGTH = 257; { image height in pixels }
  44. TIFFTAG_BITSPERSAMPLE = 258; { bits per channel (sample) }
  45. TIFFTAG_COMPRESSION = 259; { data compression technique }
  46. COMPRESSION_NONE = 1; { dump mode }
  47. COMPRESSION_CCITTRLE = 2; { CCITT modified Huffman RLE }
  48. COMPRESSION_CCITTFAX3 = 3; { CCITT Group 3 fax encoding }
  49. COMPRESSION_CCITT_T4 = 3; { CCITT T.4 (TIFF 6 name) }
  50. COMPRESSION_CCITTFAX4 = 4; { CCITT Group 4 fax encoding }
  51. COMPRESSION_CCITT_T6 = 4; { CCITT T.6 (TIFF 6 name) }
  52. COMPRESSION_LZW = 5; { Lempel-Ziv & Welch }
  53. COMPRESSION_OJPEG = 6; { !6.0 JPEG }
  54. COMPRESSION_JPEG = 7; { %JPEG DCT compression }
  55. COMPRESSION_NEXT = 32766; { NeXT 2-bit RLE }
  56. COMPRESSION_CCITTRLEW = 32771; { #1 w/ word alignment }
  57. COMPRESSION_PACKBITS = 32773; { Macintosh RLE }
  58. COMPRESSION_THUNDERSCAN = 32809; { ThunderScan RLE }
  59. { codes 32895-32898 are reserved for ANSI IT8 TIFF/IT <[email protected]) }
  60. COMPRESSION_IT8CTPAD = 32895; { IT8 CT w/padding }
  61. COMPRESSION_IT8LW = 32896; { IT8 Linework RLE }
  62. COMPRESSION_IT8MP = 32897; { IT8 Monochrome picture }
  63. COMPRESSION_IT8BL = 32898; { IT8 Binary line art }
  64. { compression codes 32908-32911 are reserved for Pixar }
  65. COMPRESSION_PIXARFILM = 32908; { Pixar companded 10bit LZW }
  66. COMPRESSION_PIXARLOG = 32909; { Pixar companded 11bit ZIP }
  67. COMPRESSION_DEFLATE = 32946; { Deflate compression }
  68. COMPRESSION_ADOBE_DEFLATE = 8; { Deflate compression, as recognized by Adobe }
  69. { compression code 32947 is reserved for Oceana Matrix <[email protected]> }
  70. COMPRESSION_DCS = 32947; { Kodak DCS encoding }
  71. COMPRESSION_JBIG = 34661; { ISO JBIG }
  72. COMPRESSION_SGILOG = 34676; { SGI Log Luminance RLE }
  73. COMPRESSION_SGILOG24 = 34677; { SGI Log 24-bit packed }
  74. COMPRESSION_JP2000 = 34712; { Leadtools JPEG2000 }
  75. TIFFTAG_PHOTOMETRIC = 262; { photometric interpretation }
  76. PHOTOMETRIC_MINISWHITE = 0; { min value is white }
  77. PHOTOMETRIC_MINISBLACK = 1; { min value is black }
  78. PHOTOMETRIC_RGB = 2; { RGB color model }
  79. PHOTOMETRIC_PALETTE = 3; { color map indexed }
  80. PHOTOMETRIC_MASK = 4; { $holdout mask }
  81. PHOTOMETRIC_SEPARATED = 5; { !color separations }
  82. PHOTOMETRIC_YCBCR = 6; { !CCIR 601 }
  83. PHOTOMETRIC_CIELAB = 8; { !1976 CIE L*a*b* }
  84. PHOTOMETRIC_ICCLAB = 9; { ICC L*a*b* [Adobe TIFF Technote 4] }
  85. PHOTOMETRIC_ITULAB = 10; { ITU L*a*b* }
  86. PHOTOMETRIC_LOGL = 32844; { CIE Log2(L) }
  87. PHOTOMETRIC_LOGLUV = 32845; { CIE Log2(L) (u',v') }
  88. TIFFTAG_THRESHHOLDING = 263; { thresholding used on data }
  89. THRESHHOLD_BILEVEL = 1; { b&w art scan }
  90. THRESHHOLD_HALFTONE = 2; { or dithered scan }
  91. THRESHHOLD_ERRORDIFFUSE = 3; { usually floyd-steinberg }
  92. TIFFTAG_CELLWIDTH = 264; { +dithering matrix width }
  93. TIFFTAG_CELLLENGTH = 265; { +dithering matrix height }
  94. TIFFTAG_FILLORDER = 266; { data order within a byte }
  95. FILLORDER_MSB2LSB = 1; { most significant -> least }
  96. FILLORDER_LSB2MSB = 2; { least significant -> most }
  97. TIFFTAG_DOCUMENTNAME = 269; { name of doc. image is from }
  98. TIFFTAG_IMAGEDESCRIPTION = 270; { info about image }
  99. TIFFTAG_MAKE = 271; { scanner manufacturer name }
  100. TIFFTAG_MODEL = 272; { scanner model name/number }
  101. TIFFTAG_STRIPOFFSETS = 273; { offsets to data strips }
  102. TIFFTAG_ORIENTATION = 274; { +image orientation }
  103. ORIENTATION_TOPLEFT = 1; { row 0 top, col 0 lhs }
  104. ORIENTATION_TOPRIGHT = 2; { row 0 top, col 0 rhs }
  105. ORIENTATION_BOTRIGHT = 3; { row 0 bottom, col 0 rhs }
  106. ORIENTATION_BOTLEFT = 4; { row 0 bottom, col 0 lhs }
  107. ORIENTATION_LEFTTOP = 5; { row 0 lhs, col 0 top }
  108. ORIENTATION_RIGHTTOP = 6; { row 0 rhs, col 0 top }
  109. ORIENTATION_RIGHTBOT = 7; { row 0 rhs, col 0 bottom }
  110. ORIENTATION_LEFTBOT = 8; { row 0 lhs, col 0 bottom }
  111. TIFFTAG_SAMPLESPERPIXEL = 277; { samples per pixel }
  112. TIFFTAG_ROWSPERSTRIP = 278; { rows per strip of data }
  113. TIFFTAG_STRIPBYTECOUNTS = 279; { bytes counts for strips }
  114. TIFFTAG_MINSAMPLEVALUE = 280; { +minimum sample value }
  115. TIFFTAG_MAXSAMPLEVALUE = 281; { +maximum sample value }
  116. TIFFTAG_XRESOLUTION = 282; { pixels/resolution in x }
  117. TIFFTAG_YRESOLUTION = 283; { pixels/resolution in y }
  118. TIFFTAG_PLANARCONFIG = 284; { storage organization }
  119. PLANARCONFIG_CONTIG = 1; { single image plane }
  120. PLANARCONFIG_SEPARATE = 2; { separate planes of data }
  121. TIFFTAG_PAGENAME = 285; { page name image is from }
  122. TIFFTAG_XPOSITION = 286; { x page offset of image lhs }
  123. TIFFTAG_YPOSITION = 287; { y page offset of image lhs }
  124. TIFFTAG_FREEOFFSETS = 288; { +byte offset to free block }
  125. TIFFTAG_FREEBYTECOUNTS = 289; { +sizes of free blocks }
  126. {matched with tag reference up to this point}
  127. TIFFTAG_GRAYRESPONSEUNIT = 290; { $gray scale curve accuracy }
  128. GRAYRESPONSEUNIT_10S = 1; { tenths of a unit }
  129. GRAYRESPONSEUNIT_100S = 2; { hundredths of a unit }
  130. GRAYRESPONSEUNIT_1000S = 3; { thousandths of a unit }
  131. GRAYRESPONSEUNIT_10000S = 4; { ten-thousandths of a unit }
  132. GRAYRESPONSEUNIT_100000S = 5; { hundred-thousandths }
  133. TIFFTAG_GRAYRESPONSECURVE = 291; { $gray scale response curve }
  134. TIFFTAG_GROUP3OPTIONS = 292; { 32 flag bits }
  135. TIFFTAG_T4OPTIONS = 292; { TIFF 6.0 proper name alias }
  136. GROUP3OPT_2DENCODING = $1; { 2-dimensional coding }
  137. GROUP3OPT_UNCOMPRESSED = $2; { data not compressed }
  138. GROUP3OPT_FILLBITS = $4; { fill to byte boundary }
  139. TIFFTAG_GROUP4OPTIONS = 293; { 32 flag bits }
  140. TIFFTAG_T6OPTIONS = 293; { TIFF 6.0 proper name }
  141. GROUP4OPT_UNCOMPRESSED = $2; { data not compressed }
  142. TIFFTAG_RESOLUTIONUNIT = 296; { units of resolutions }
  143. RESUNIT_NONE = 1; { no meaningful units }
  144. RESUNIT_INCH = 2; { english }
  145. RESUNIT_CENTIMETER = 3; { metric }
  146. TIFFTAG_PAGENUMBER = 297; { page numbers of multi-page }
  147. TIFFTAG_COLORRESPONSEUNIT = 300; { $color curve accuracy }
  148. COLORRESPONSEUNIT_10S = 1; { tenths of a unit }
  149. COLORRESPONSEUNIT_100S = 2; { hundredths of a unit }
  150. COLORRESPONSEUNIT_1000S = 3; { thousandths of a unit }
  151. COLORRESPONSEUNIT_10000S = 4; { ten-thousandths of a unit }
  152. COLORRESPONSEUNIT_100000S = 5; { hundred-thousandths }
  153. TIFFTAG_TRANSFERFUNCTION = 301; { !colorimetry info }
  154. TIFFTAG_SOFTWARE = 305; { name & release }
  155. TIFFTAG_DATETIME = 306; { creation date and time }
  156. TIFFTAG_ARTIST = 315; { creator of image }
  157. TIFFTAG_HOSTCOMPUTER = 316; { machine where created }
  158. TIFFTAG_PREDICTOR = 317; { prediction scheme w/ LZW }
  159. TIFFTAG_WHITEPOINT = 318; { image white point }
  160. TIFFTAG_PRIMARYCHROMATICITIES = 319; { !primary chromaticities }
  161. TIFFTAG_COLORMAP = 320; { RGB map for pallette image }
  162. TIFFTAG_HALFTONEHINTS = 321; { !highlight+shadow info }
  163. TIFFTAG_TILEWIDTH = 322; { !rows/data tile }
  164. TIFFTAG_TILELENGTH = 323; { !cols/data tile }
  165. TIFFTAG_TILEOFFSETS = 324; { !offsets to data tiles }
  166. TIFFTAG_TILEBYTECOUNTS = 325; { !byte counts for tiles }
  167. TIFFTAG_BADFAXLINES = 326; { lines w/ wrong pixel count }
  168. TIFFTAG_CLEANFAXDATA = 327; { regenerated line info }
  169. CLEANFAXDATA_CLEAN = 0; { no errors detected }
  170. CLEANFAXDATA_REGENERATED = 1; { receiver regenerated lines }
  171. CLEANFAXDATA_UNCLEAN = 2; { uncorrected errors exist }
  172. TIFFTAG_CONSECUTIVEBADFAXLINES = 328; { max consecutive bad lines }
  173. TIFFTAG_SUBIFD = 330; { subimage descriptors }
  174. TIFFTAG_INKSET = 332; { !inks in separated image }
  175. INKSET_CMYK = 1; { !cyan-magenta-yellow-black color }
  176. INKSET_MULTIINK = 2; { !multi-ink or hi-fi color }
  177. TIFFTAG_INKNAMES = 333; { !ascii names of inks }
  178. TIFFTAG_NUMBEROFINKS = 334; { !number of inks }
  179. TIFFTAG_DOTRANGE = 336; { !0% and 100% dot codes }
  180. TIFFTAG_TARGETPRINTER = 337; { !separation target }
  181. TIFFTAG_EXTRASAMPLES = 338; { !info about extra samples }
  182. EXTRASAMPLE_UNSPECIFIED = 0; { !unspecified data }
  183. EXTRASAMPLE_ASSOCALPHA = 1; { !associated alpha data }
  184. EXTRASAMPLE_UNASSALPHA = 2; { !unassociated alpha data }
  185. TIFFTAG_SAMPLEFORMAT = 339; { !data sample format }
  186. SAMPLEFORMAT_UINT = 1; { !unsigned integer data }
  187. SAMPLEFORMAT_INT = 2; { !signed integer data }
  188. SAMPLEFORMAT_IEEEFP = 3; { !IEEE floating point data }
  189. SAMPLEFORMAT_VOID = 4; { !untyped data }
  190. SAMPLEFORMAT_COMPLEXINT = 5; { !complex signed int }
  191. SAMPLEFORMAT_COMPLEXIEEEFP = 6; { !complex ieee floating }
  192. TIFFTAG_SMINSAMPLEVALUE = 340; { !variable MinSampleValue }
  193. TIFFTAG_SMAXSAMPLEVALUE = 341; { !variable MaxSampleValue }
  194. TIFFTAG_CLIPPATH = 343; { %ClipPath [Adobe TIFF technote 2] }
  195. TIFFTAG_XCLIPPATHUNITS = 344; { %XClipPathUnits [Adobe TIFF technote 2] }
  196. TIFFTAG_YCLIPPATHUNITS = 345; { %YClipPathUnits [Adobe TIFF technote 2] }
  197. TIFFTAG_INDEXED = 346; { %Indexed [Adobe TIFF Technote 3] }
  198. TIFFTAG_JPEGTABLES = 347; { %JPEG table stream }
  199. TIFFTAG_OPIPROXY = 351; { %OPI Proxy [Adobe TIFF technote] }
  200. { Tags 512-521 are obsoleted by Technical Note #2
  201. which specifies a revised JPEG-in-TIFF scheme. }
  202. TIFFTAG_JPEGPROC = 512; { !JPEG processing algorithm }
  203. JPEGPROC_BASELINE = 1; { !baseline sequential }
  204. JPEGPROC_LOSSLESS = 14; { !Huffman coded lossless }
  205. TIFFTAG_JPEGIFOFFSET = 513; { !pointer to SOI marker }
  206. TIFFTAG_JPEGIFBYTECOUNT = 514; { !JFIF stream length }
  207. TIFFTAG_JPEGRESTARTINTERVAL = 515; { !restart interval length }
  208. TIFFTAG_JPEGLOSSLESSPREDICTORS = 517; { !lossless proc predictor }
  209. TIFFTAG_JPEGPOINTTRANSFORM = 518; { !lossless point transform }
  210. TIFFTAG_JPEGQTABLES = 519; { !Q matrice offsets }
  211. TIFFTAG_JPEGDCTABLES = 520; { !DCT table offsets }
  212. TIFFTAG_JPEGACTABLES = 521; { !AC coefficient offsets }
  213. TIFFTAG_YCBCRCOEFFICIENTS = 529; { !RGB -> YCbCr transform }
  214. TIFFTAG_YCBCRSUBSAMPLING = 530; { !YCbCr subsampling factors }
  215. TIFFTAG_YCBCRPOSITIONING = 531; { !subsample positioning }
  216. YCBCRPOSITION_CENTERED = 1; { !as in PostScript Level 2 }
  217. YCBCRPOSITION_COSITED = 2; { !as in CCIR 601-1 }
  218. TIFFTAG_REFERENCEBLACKWHITE = 532; { !colorimetry info }
  219. TIFFTAG_XMLPACKET = 700; { %XML packet [Adobe XMP technote 9-14-02] ([email protected]) }
  220. TIFFTAG_OPIIMAGEID = 32781; { %OPI ImageID [Adobe TIFF technote] }
  221. { tags 32952-32956 are private tags registered to Island Graphics }
  222. TIFFTAG_REFPTS = 32953; { image reference points }
  223. TIFFTAG_REGIONTACKPOINT = 32954; { region-xform tack point }
  224. TIFFTAG_REGIONWARPCORNERS = 32955; { warp quadrilateral }
  225. TIFFTAG_REGIONAFFINE = 32956; { affine transformation mat }
  226. { tags 32995-32999 are private tags registered to SGI }
  227. TIFFTAG_MATTEING = 32995; { $use ExtraSamples }
  228. TIFFTAG_DATATYPE = 32996; { $use SampleFormat }
  229. TIFFTAG_IMAGEDEPTH = 32997; { z depth of image }
  230. TIFFTAG_TILEDEPTH = 32998; { z depth/data tile }
  231. { tags 33300-33309 are private tags registered to Pixar }
  232. { TIFFTAG_PIXAR_IMAGEFULLWIDTH and TIFFTAG_PIXAR_IMAGEFULLLENGTH are set when an image has been cropped out of a larger image.
  233. They reflect the size of the original uncropped image. The TIFFTAG_XPOSITION and TIFFTAG_YPOSITION can be used to determine the
  234. position of the smaller image in the larger one. }
  235. TIFFTAG_PIXAR_IMAGEFULLWIDTH = 33300; { full image size in x }
  236. TIFFTAG_PIXAR_IMAGEFULLLENGTH = 33301; { full image size in y }
  237. { Tags 33302-33306 are used to identify special image modes and data used by Pixar's texture formats. }
  238. TIFFTAG_PIXAR_TEXTUREFORMAT = 33302; { texture map format }
  239. TIFFTAG_PIXAR_WRAPMODES = 33303; { s & t wrap modes }
  240. TIFFTAG_PIXAR_FOVCOT = 33304; { cotan(fov) for env. maps }
  241. TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN = 33305;
  242. TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA = 33306;
  243. { tag 33405 is a private tag registered to Eastman Kodak }
  244. TIFFTAG_WRITERSERIALNUMBER = 33405; { device serial number }
  245. { tag 33432 is listed in the 6.0 spec w/ unknown ownership }
  246. TIFFTAG_COPYRIGHT = 33432; { copyright string }
  247. { IPTC TAG from RichTIFF specifications }
  248. TIFFTAG_RICHTIFFIPTC = 33723;
  249. { 34016-34029 are reserved for ANSI IT8 TIFF/IT <[email protected]) }
  250. TIFFTAG_IT8SITE = 34016; { site name }
  251. TIFFTAG_IT8COLORSEQUENCE = 34017; { color seq. [RGB,CMYK,etc] }
  252. TIFFTAG_IT8HEADER = 34018; { DDES Header }
  253. TIFFTAG_IT8RASTERPADDING = 34019; { raster scanline padding }
  254. TIFFTAG_IT8BITSPERRUNLENGTH = 34020; { # of bits in short run }
  255. TIFFTAG_IT8BITSPEREXTENDEDRUNLENGTH = 34021; { # of bits in long run }
  256. TIFFTAG_IT8COLORTABLE = 34022; { LW colortable }
  257. TIFFTAG_IT8IMAGECOLORINDICATOR = 34023; { BP/BL image color switch }
  258. TIFFTAG_IT8BKGCOLORINDICATOR = 34024; { BP/BL bg color switch }
  259. TIFFTAG_IT8IMAGECOLORVALUE = 34025; { BP/BL image color value }
  260. TIFFTAG_IT8BKGCOLORVALUE = 34026; { BP/BL bg color value }
  261. TIFFTAG_IT8PIXELINTENSITYRANGE = 34027; { MP pixel intensity value }
  262. TIFFTAG_IT8TRANSPARENCYINDICATOR = 34028; { HC transparency switch }
  263. TIFFTAG_IT8COLORCHARACTERIZATION = 34029; { color character. table }
  264. TIFFTAG_IT8HCUSAGE = 34030; { HC usage indicator }
  265. TIFFTAG_IT8TRAPINDICATOR = 34031; { Trapping indicator (untrapped=0, trapped=1) }
  266. TIFFTAG_IT8CMYKEQUIVALENT = 34032; { CMYK color equivalents }
  267. { tags 34232-34236 are private tags registered to Texas Instruments }
  268. TIFFTAG_FRAMECOUNT = 34232; { Sequence Frame Count }
  269. { tag 34750 is a private tag registered to Adobe? }
  270. TIFFTAG_ICCPROFILE = 34675; { ICC profile data }
  271. { tag 34377 is private tag registered to Adobe for PhotoShop }
  272. TIFFTAG_PHOTOSHOP = 34377;
  273. { tag 34750 is a private tag registered to Pixel Magic }
  274. TIFFTAG_JBIGOPTIONS = 34750; { JBIG options }
  275. { tags 34908-34914 are private tags registered to SGI }
  276. TIFFTAG_FAXRECVPARAMS = 34908; { encoded Class 2 ses. parms }
  277. TIFFTAG_FAXSUBADDRESS = 34909; { received SubAddr string }
  278. TIFFTAG_FAXRECVTIME = 34910; { receive time (secs) }
  279. { tags 37439-37443 are registered to SGI <[email protected]> }
  280. TIFFTAG_STONITS = 37439; { Sample value to Nits }
  281. { tag 34929 is a private tag registered to FedEx }
  282. TIFFTAG_FEDEX_EDR = 34929; { unknown use }
  283. { tag 65535 is an undefined tag used by Eastman Kodak }
  284. TIFFTAG_DCSHUESHIFTVALUES = 65535; { hue shift correction data }
  285. { The following are ``pseudo tags'' that can be used to control codec-specific functionality. These tags are not written to file.
  286. Note that these values start at 0xffff+1 so that they'll never collide with Aldus-assigned tags. }
  287. TIFFTAG_FAXMODE = 65536; { Group 3/4 format control }
  288. FAXMODE_CLASSIC = $0; { default, include RTC }
  289. FAXMODE_NORTC = $1; { no RTC at end of data }
  290. FAXMODE_NOEOL = $2; { no EOL code at end of row }
  291. FAXMODE_BYTEALIGN = $4; { byte align row }
  292. FAXMODE_WORDALIGN = $8; { word align row }
  293. FAXMODE_CLASSF = FAXMODE_NORTC; { TIFF Class F }
  294. TIFFTAG_JPEGQUALITY = 65537; { Compression quality level }
  295. { Note: quality level is on the IJG 0-100 scale. Default value is 75 }
  296. TIFFTAG_JPEGCOLORMODE = 65538; { Auto RGB<=>YCbCr convert? }
  297. JPEGCOLORMODE_RAW = $0; { no conversion (default) }
  298. JPEGCOLORMODE_RGB = $1; { do auto conversion }
  299. TIFFTAG_JPEGTABLESMODE = 65539; { What to put in JPEGTables }
  300. JPEGTABLESMODE_QUANT = $1; { include quantization tbls }
  301. JPEGTABLESMODE_HUFF = $2; { include Huffman tbls }
  302. { Note: default is JPEGTABLESMODE_QUANT | JPEGTABLESMODE_HUFF }
  303. TIFFTAG_FAXFILLFUNC = 65540; { G3/G4 fill function }
  304. TIFFTAG_PIXARLOGDATAFMT = 65549; { PixarLogCodec I/O data sz }
  305. PIXARLOGDATAFMT_8BIT = 0; { regular u_char samples }
  306. PIXARLOGDATAFMT_8BITABGR = 1; { ABGR-order u_chars }
  307. PIXARLOGDATAFMT_11BITLOG = 2; { 11-bit log-encoded (raw) }
  308. PIXARLOGDATAFMT_12BITPICIO = 3; { as per PICIO (1.0==2048) }
  309. PIXARLOGDATAFMT_16BIT = 4; { signed short samples }
  310. PIXARLOGDATAFMT_FLOAT = 5; { IEEE float samples }
  311. { 65550-65556 are allocated to Oceana Matrix <[email protected]> }
  312. TIFFTAG_DCSIMAGERTYPE = 65550; { imager model & filter }
  313. DCSIMAGERMODEL_M3 = 0; { M3 chip (1280 x 1024) }
  314. DCSIMAGERMODEL_M5 = 1; { M5 chip (1536 x 1024) }
  315. DCSIMAGERMODEL_M6 = 2; { M6 chip (3072 x 2048) }
  316. DCSIMAGERFILTER_IR = 0; { infrared filter }
  317. DCSIMAGERFILTER_MONO = 1; { monochrome filter }
  318. DCSIMAGERFILTER_CFA = 2; { color filter array }
  319. DCSIMAGERFILTER_OTHER = 3; { other filter }
  320. TIFFTAG_DCSINTERPMODE = 65551; { interpolation mode }
  321. DCSINTERPMODE_NORMAL = 0; { whole image, default }
  322. DCSINTERPMODE_PREVIEW = 1; { preview of image (384x256) }
  323. TIFFTAG_DCSBALANCEARRAY = 65552; { color balance values }
  324. TIFFTAG_DCSCORRECTMATRIX = 65553; { color correction values }
  325. TIFFTAG_DCSGAMMA = 65554; { gamma value }
  326. TIFFTAG_DCSTOESHOULDERPTS = 65555; { toe & shoulder points }
  327. TIFFTAG_DCSCALIBRATIONFD = 65556; { calibration file desc }
  328. { Note: quality level is on the ZLIB 1-9 scale. Default value is -1 }
  329. TIFFTAG_ZIPQUALITY = 65557; { compression quality level }
  330. TIFFTAG_PIXARLOGQUALITY = 65558; { PixarLog uses same scale }
  331. { 65559 is allocated to Oceana Matrix <[email protected]> }
  332. TIFFTAG_DCSCLIPRECTANGLE = 65559; { area of image to acquire }
  333. TIFFTAG_SGILOGDATAFMT = 65560; { SGILog user data format }
  334. SGILOGDATAFMT_FLOAT = 0; { IEEE float samples }
  335. SGILOGDATAFMT_16BIT = 1; { 16-bit samples }
  336. SGILOGDATAFMT_RAW = 2; { uninterpreted data }
  337. SGILOGDATAFMT_8BIT = 3; { 8-bit RGB monitor values }
  338. TIFFTAG_SGILOGENCODE = 65561; { SGILog data encoding control }
  339. SGILOGENCODE_NODITHER = 0; { do not dither encoded values }
  340. SGILOGENCODE_RANDITHER = 1; { randomly dither encd values }
  341. { Flags to pass to TIFFPrintDirectory to control printing of data structures that are potentially very large. Bit-or these flags to
  342. enable printing multiple items. }
  343. TIFFPRINT_NONE = $0; { no extra info }
  344. TIFFPRINT_STRIPS = $1; { strips/tiles info }
  345. TIFFPRINT_CURVES = $2; { color/gray response curves }
  346. TIFFPRINT_COLORMAP = $4; { colormap }
  347. TIFFPRINT_JPEGQTABLES = $100; { JPEG Q matrices }
  348. TIFFPRINT_JPEGACTABLES = $200; { JPEG AC tables }
  349. TIFFPRINT_JPEGDCTABLES = $200; { JPEG DC tables }
  350. TIFF_ANY = TIFF_NOTYPE; { for field descriptor searching }
  351. TIFF_VARIABLE = -1; { marker for variable length tags }
  352. TIFF_SPP = -2; { marker for SamplesPerPixel tags }
  353. TIFF_VARIABLE2 = -3; { marker for uint32 var-length tags }
  354. FIELD_CUSTOM = 65;
  355. type
  356. PTIFF = Pointer;
  357. PTIFFRGBAImage = Pointer;
  358. TIFFErrorHandler = procedure(a: Pointer; b: Pointer; c: Pointer); cdecl;
  359. LibTiffDelphiErrorHandler = procedure(const a,b: String);
  360. TIFFReadWriteProc = function(Fd: Cardinal; Buffer: Pointer; Size: Integer): Integer; cdecl;
  361. TIFFSeekProc = function(Fd: Cardinal; Off: Cardinal; Whence: Integer): Cardinal; cdecl;
  362. TIFFCloseProc = function(Fd: Cardinal): Integer; cdecl;
  363. TIFFSizeProc = function(Fd: Cardinal): Cardinal; cdecl;
  364. TIFFMapFileProc = function(Fd: Cardinal; PBase: PPointer; PSize: PCardinal): Integer; cdecl;
  365. TIFFUnmapFileProc = procedure(Fd: Cardinal; Base: Pointer; Size: Cardinal); cdecl;
  366. TIFFExtendProc = procedure(Handle: PTIFF); cdecl;
  367. TIFFInitMethod = function(Handle: PTIFF; Scheme: Integer): Integer; cdecl;
  368. PTIFFCodec = ^TIFFCodec;
  369. TIFFCodec = record
  370. Name: PChar;
  371. Scheme: Word;
  372. Init: TIFFInitMethod;
  373. end;
  374. PTIFFFieldInfo = ^TIFFFieldInfo;
  375. TIFFFieldInfo = record
  376. FieldTag: Cardinal; { field's tag }
  377. FieldReadCount: Smallint; { read count/TIFF_VARIABLE/TIFF_SPP }
  378. FieldWriteCount: Smallint; { write count/TIFF_VARIABLE }
  379. FieldType: Integer; { type of associated data }
  380. FieldBit: Word; { bit in fieldsset bit vector }
  381. FieldOkToChange: Byte; { if true, can change while writing }
  382. FieldPassCount: Byte; { if true, pass dir count on set }
  383. FieldName: PChar; { ASCII name }
  384. end;
  385. PTIFFTagValue = ^TIFFTagValue;
  386. TIFFTagValue = record
  387. Info: PTIFFFieldInfo;
  388. Count: Integer;
  389. Value: Pointer;
  390. end;
  391. function LibTiffDelphiVersion: String;
  392. function TIFFGetVersion: PChar; cdecl; external;
  393. function TIFFFindCODEC(Scheme: Word): PTIFFCodec; cdecl; external;
  394. function TIFFRegisterCODEC(Scheme: Word; Name: PChar; InitMethod: TIFFInitMethod): PTIFFCodec; cdecl; external;
  395. procedure TIFFUnRegisterCODEC(c: PTIFFCodec); cdecl; external;
  396. function TIFFIsCODECConfigured(Scheme: Word): Integer; cdecl; external;
  397. function TIFFGetConfiguredCODECs: PTIFFCodec; cdecl; external;
  398. function TIFFOpen(const Name: String; const Mode: String): PTIFF;
  399. function TIFFOpenStream(const Stream: TStream; const Mode: String): PTIFF;
  400. function TIFFClientOpen(Name: PChar; Mode: PChar; ClientData: Cardinal;
  401. ReadProc: TIFFReadWriteProc;
  402. WriteProc: TIFFReadWriteProc;
  403. SeekProc: TIFFSeekProc;
  404. CloseProc: TIFFCloseProc;
  405. SizeProc: TIFFSizeProc;
  406. MapProc: TIFFMapFileProc;
  407. UnmapProc: TIFFUnmapFileProc): PTIFF; cdecl; external;
  408. procedure TIFFCleanup(Handle: PTIFF); cdecl; external;
  409. procedure TIFFClose(Handle: PTIFF); cdecl; external;
  410. function TIFFFileno(Handle: PTIFF): Integer; cdecl; external;
  411. function TIFFSetFileno(Handle: PTIFF; Newvalue: Integer): Integer; cdecl; external;
  412. function TIFFClientdata(Handle: PTIFF): Cardinal; cdecl; external;
  413. function TIFFSetClientdata(Handle: PTIFF; Newvalue: Cardinal): Cardinal; cdecl; external;
  414. function TIFFGetMode(Handle: PTIFF): Integer; cdecl; external;
  415. function TIFFSetMode(Handle: PTIFF; Mode: Integer): Integer; cdecl; external;
  416. function TIFFFileName(Handle: PTIFF): Pointer; cdecl; external;
  417. function TIFFSetFileName(Handle: PTIFF; Name: PChar): PChar; cdecl; external;
  418. function TIFFGetReadProc(Handle: PTIFF): TIFFReadWriteProc; cdecl; external;
  419. function TIFFGetWriteProc(Handle: PTIFF): TIFFReadWriteProc; cdecl; external;
  420. function TIFFGetSeekProc(Handle: PTIFF): TIFFSeekProc; cdecl; external;
  421. function TIFFGetCloseProc(Handle: PTIFF): TIFFCloseProc; cdecl; external;
  422. function TIFFGetSizeProc(Handle: PTIFF): TIFFSizeProc; cdecl; external;
  423. procedure TIFFError(Module: Pointer; Fmt: Pointer); cdecl; external; varargs;
  424. function TIFFSetErrorHandler(Handler: TIFFErrorHandler): TIFFErrorHandler; cdecl; external;
  425. function LibTiffDelphiGetErrorHandler: LibTiffDelphiErrorHandler;
  426. function LibTiffDelphiSetErrorHandler(Handler: LibTiffDelphiErrorHandler): LibTiffDelphiErrorHandler;
  427. procedure TIFFWarning(Module: Pointer; Fmt: Pointer); cdecl; external; varargs;
  428. function TIFFSetWarningHandler(Handler: TIFFErrorHandler): TIFFErrorHandler; cdecl; external;
  429. function LibTiffDelphiGetWarningHandler: LibTiffDelphiErrorHandler;
  430. function LibTiffDelphiSetWarningHandler(Handler: LibTiffDelphiErrorHandler): LibTiffDelphiErrorHandler;
  431. function TIFFSetTagExtender(Extender: TIFFExtendProc): TIFFExtendProc; cdecl; external;
  432. function TIFFFlush(Handle: PTIFF): Integer; cdecl; external;
  433. function TIFFFlushData(Handle: PTIFF): Integer; cdecl; external;
  434. function TIFFReadDirectory(Handle: PTIFF): Integer; cdecl; external;
  435. function TIFFCurrentDirectory(Handle: PTIFF): Word; cdecl; external;
  436. function TIFFCurrentDirOffset(Handle: PTIFF): Cardinal; cdecl; external;
  437. function TIFFLastDirectory(Handle: PTIFF): Integer; cdecl; external;
  438. function TIFFNumberOfDirectories(Handle: PTIFF): Word; cdecl; external;
  439. function TIFFSetDirectory(Handle: PTIFF; Dirn: Word): Integer; cdecl; external;
  440. function TIFFSetSubDirectory(Handle: PTIFF; Diroff: Cardinal): Integer; cdecl; external;
  441. function TIFFCreateDirectory(Handle: PTIFF): Integer; cdecl; external;
  442. function TIFFWriteDirectory(Handle: PTIFF): Integer; cdecl; external;
  443. function TIFFUnlinkDirectory(handle: PTIFF; Dirn: Word): Integer; cdecl; external;
  444. procedure TIFFPrintDirectory(Handle: PTIFF; Fd: Pointer; Flags: Integer); cdecl; external;
  445. function TIFFGetField(Handle: PTIFF; Tag: Cardinal): Integer; cdecl; external; varargs;
  446. function TIFFGetFieldDefaulted(Handle: PTIFF; Tag: Cardinal): Integer; cdecl; external; varargs;
  447. function TIFFVGetField(Handle: PTIFF; Tag: Cardinal; Ap: Pointer): Integer; cdecl; external;
  448. function TIFFSetField(Handle: PTIFF; Tag: Cardinal): Integer; cdecl; external; varargs;
  449. function TIFFVSetField(Handle: PTIFF; Tag: Cardinal; Ap: Pointer): Integer; cdecl; external;
  450. function TIFFIsBigEndian(Handle: PTIFF): Integer; cdecl; external;
  451. function TIFFIsTiled(Handle: PTIFF): Integer; cdecl; external;
  452. function TIFFIsByteSwapped(Handle: PTIFF): Integer; cdecl; external;
  453. function TIFFIsUpSampled(Handle: PTIFF): Integer; cdecl; external;
  454. function TIFFIsMSB2LSB(Handle: PTIFF): Integer; cdecl; external;
  455. function TIFFGetTagListCount(Handle: PTIFF): Integer; cdecl; external;
  456. function TIFFGetTagListEntry(Handle: PTIFF; TagIndex: Integer): Cardinal; cdecl; external;
  457. procedure TIFFMergeFieldInfo(Handle: PTIFF; Info: PTIFFFieldInfo; N: Integer); cdecl; external;
  458. function TIFFFindFieldInfo(Handle: PTIFF; Tag: Cardinal; Dt: Integer): PTIFFFieldInfo; cdecl; external;
  459. function TIFFFindFieldInfoByName(Handle: PTIFF; FIeldName: PChar; Dt: Integer): PTIFFFieldInfo; cdecl; external;
  460. function TIFFFieldWithTag(Handle: PTIFF; Tag: Cardinal): PTIFFFieldInfo; cdecl; external;
  461. function TIFFFieldWithName(Handle: PTIFF; FieldName: PChar): PTIFFFieldInfo; cdecl; external;
  462. function TIFFDataWidth(DataType: Integer): Integer; cdecl; external;
  463. function TIFFReadRGBAImage(Handle: PTIFF; RWidth,RHeight: Cardinal; Raster: Pointer; Stop: Integer): Integer; cdecl; external;
  464. function TIFFReadRGBAImageOriented(Handle: PTIFF; RWidth,RHeight: Cardinal; Raster: Pointer; Orientation: Integer; Stop: Integer): Integer; cdecl; external;
  465. function TIFFReadRGBAStrip(Handle: PTIFF; Row: Cardinal; Raster: Pointer): Integer; cdecl; external;
  466. function TIFFReadRGBATile(Handle: PTIFF; Col,Row: Cardinal; Raster: Pointer): Integer; cdecl; external;
  467. function TIFFRGBAImageOk(Handle: PTIFF; Emsg: PChar): Integer; cdecl; external;
  468. function TIFFRGBAImageBegin(Img: PTIFFRGBAImage; Handle: PTIFF; Stop: Integer; Emsg: PChar): Integer; cdecl; external;
  469. function TIFFRGBAImageGet(Img: PTIFFRGBAImage; Raster: Pointer; W,H: Cardinal): Integer; cdecl; external;
  470. procedure TIFFRGBAImageEnd(Img: PTIFFRGBAImage); cdecl; external;
  471. function TIFFCurrentRow(Handle: PTIFF): Cardinal; cdecl; external;
  472. function TIFFStripSize(Handle: PTIFF): Integer; cdecl; external;
  473. function TIFFRawStripSize(Handle: PTIFF; Strip: Cardinal): Integer; cdecl; external;
  474. function TIFFVStripSize(Handle: PTIFF; NRows: Cardinal): Integer; cdecl; external;
  475. function TIFFDefaultStripSize(Handle: PTIFF; Request: Cardinal): Cardinal; cdecl; external;
  476. function TIFFNumberOfStrips(Handle: PTIFF): Cardinal; cdecl; external;
  477. function TIFFComputeStrip(Handle: PTIFF; Row: Cardinal; Sample: Word): Cardinal; cdecl; external;
  478. function TIFFReadRawStrip(Handle: PTIFF; Strip: Cardinal; Buf: Pointer; Size: Integer): Integer; cdecl; external;
  479. function TIFFReadEncodedStrip(Handle: PTIFF; Strip: Cardinal; Buf: Pointer; Size: Integer): Integer; cdecl; external;
  480. function TIFFWriteRawStrip(Handle: PTIFF; Strip: Cardinal; Data: Pointer; Cc: Integer): Integer; cdecl; external;
  481. function TIFFWriteEncodedStrip(Handle: PTIFF; Strip: Cardinal; Data: Pointer; Cc: Integer): Integer; cdecl; external;
  482. function TIFFCurrentStrip(Handle: PTIFF): Cardinal; cdecl; external;
  483. function TIFFTileSize(Handle: PTIFF): Integer; cdecl; external;
  484. function TIFFTileRowSize(Handle: PTIFF): Integer; cdecl; external;
  485. function TIFFVTileSize(Handle: PTIFF; NRows: Cardinal): Integer; cdecl; external;
  486. procedure TIFFDefaultTileSize(Handle: PTIFF; Tw: PCardinal; Th: PCardinal); cdecl; external;
  487. function TIFFNumberOfTiles(Handle: PTIFF): Cardinal; cdecl; external;
  488. function TIFFComputeTile(Handle: PTIFF; X,Y,Z: Cardinal; S: Word): Cardinal; cdecl; external;
  489. function TIFFReadRawTile(Handle: PTIFF; Tile: Cardinal; Buf: Pointer; Size: Integer): Integer; cdecl; external;
  490. function TIFFReadEncodedTile(Handle: PTIFF; Tile: Cardinal; Buf: Pointer; Size: Integer): Integer; cdecl; external;
  491. function TIFFWriteRawTile(Handle: PTIFF; Tile: Cardinal; Data: Pointer; Cc: Integer): Integer; cdecl; external;
  492. function TIFFWriteEncodedTile(Handle: PTIFF; Tile: Cardinal; Data: Pointer; Cc: Integer): Integer; cdecl; external;
  493. function TIFFCurrentTile(Handle: PTIFF): Cardinal; cdecl; external;
  494. function TIFFScanlineSize(Handle: PTIFF): Integer; cdecl; external;
  495. function TIFFRasterScanlineSize(Handle: PTIFF): Integer; cdecl; external;
  496. function TIFFReadScanline(Handle: PTIFF; Buf: Pointer; Row: Cardinal; Sample: Word): Integer; cdecl; external;
  497. function TIFFWriteScanline(Handle: PTIFF; Buf: Pointer; Row: Cardinal; Sample: Word): Integer; cdecl; external;
  498. procedure TIFFSetWriteOffset(Handle: PTIFF; Off: Cardinal); cdecl; external;
  499. procedure TIFFSwabShort(Wp: PWord); cdecl; external;
  500. procedure TIFFSwabLong(Lp: PCardinal); cdecl; external;
  501. procedure TIFFSwabDouble(Dp: PDouble); cdecl; external;
  502. procedure TIFFSwabArrayOfShort(Wp: PWord; N: Cardinal); cdecl; external;
  503. procedure TIFFSwabArrayOfLong(Lp: PCardinal; N: Cardinal); cdecl; external;
  504. procedure TIFFSwabArrayOfDouble(Dp: PDouble; N: Cardinal); cdecl; external;
  505. procedure TIFFReverseBits(Cp: Pointer; N: Cardinal); cdecl; external;
  506. function TIFFGetBitRevTable(Reversed: Integer): Pointer; cdecl; external;
  507. function _TIFFmalloc(s: Longint): Pointer; cdecl;
  508. function _TIFFrealloc(p: Pointer; s: Longint): Pointer; cdecl;
  509. procedure _TIFFfree(p: Pointer); cdecl;
  510. implementation
  511. uses
  512. Math, LibDelphi, LibJpegDelphi, ZLibDelphi;
  513. type
  514. TQsortCompare = function(a,b: Pointer): Integer; cdecl;
  515. TBsearchFcmp = function(a: Pointer; b: Pointer): Integer; cdecl;
  516. function floor(x: Double): Double; cdecl; forward;
  517. function pow(x: Double; y: Double): Double; cdecl; forward;
  518. function sqrt(x: Double): Double; cdecl; forward;
  519. function atan2(y: Double; x: Double): Double; cdecl; forward;
  520. function exp(x: Double): Double; cdecl; forward;
  521. function log(x: Double): Double; cdecl; forward;
  522. function fabs(x: Double): Double; cdecl; forward;
  523. function rand: Integer; cdecl; forward;
  524. function strlen(s: Pointer): Cardinal; cdecl; forward;
  525. function strcmp(a: Pointer; b: Pointer): Integer; cdecl; forward;
  526. function strncmp(a: Pointer; b: Pointer; c: Longint): Integer; cdecl; forward;
  527. procedure qsort(base: Pointer; num: Cardinal; width: Cardinal; compare: TQSortCompare); cdecl; forward;
  528. //DW function bsearch(key: Pointer; base: Pointer; nelem: Cardinal; width: Cardinal; fcmp: TBsearchFcmp): Pointer; cdecl; forward;
  529. function memmove(dest: Pointer; src: Pointer; n: Cardinal): Pointer; cdecl; forward;
  530. function strchr(s: Pointer; c: Integer): Pointer; cdecl; forward;
  531. procedure _TIFFmemcpy(d: Pointer; s: Pointer; c: Longint); cdecl; forward;
  532. procedure _TIFFmemset(p: Pointer; v: Integer; c: Longint); cdecl; forward;
  533. function _TIFFmemcmp(buf1: Pointer; buf2: Pointer; count: Cardinal): Integer; cdecl; forward;
  534. var
  535. _TIFFwarningHandler: TIFFErrorHandler;
  536. _TIFFerrorHandler: TIFFErrorHandler;
  537. FLibTiffDelphiWarningHandler: LibTiffDelphiErrorHandler;
  538. FLibTiffDelphiErrorHandler: LibTiffDelphiErrorHandler;
  539. function fabs(x: Double): Double;
  540. begin
  541. if x<0 then
  542. Result:=-x
  543. else
  544. Result:=x;
  545. end;
  546. function atan2(y: Double; x: Double): Double;
  547. begin
  548. Result:=ArcTan2(y,x);
  549. end;
  550. function rand: Integer; cdecl;
  551. begin
  552. Result:=Trunc(Random*($7FFF+1));
  553. end;
  554. function sqrt(x: Double): Double; cdecl;
  555. begin
  556. Result:=System.Sqrt(x);
  557. end;
  558. function log(x: Double): Double; cdecl;
  559. begin
  560. Result:=Ln(x);
  561. end;
  562. function exp(x: Double): Double; cdecl;
  563. begin
  564. Result:=System.Exp(x);
  565. end;
  566. function strchr(s: Pointer; c: Integer): Pointer; cdecl;
  567. begin
  568. Result:=s;
  569. while True do
  570. begin
  571. if PByte(Result)^=c then exit;
  572. if PByte(Result)^=0 then
  573. begin
  574. Result:=nil;
  575. exit;
  576. end;
  577. Inc(PByte(Result));
  578. end;
  579. end;
  580. function memmove(dest: Pointer; src: Pointer; n: Cardinal): Pointer; cdecl;
  581. begin
  582. MoveMemory(dest,src,n);
  583. Result:=dest;
  584. end;
  585. function _TIFFmemcmp(buf1: Pointer; buf2: Pointer; count: Cardinal): Integer; cdecl;
  586. var
  587. ma,mb: PByte;
  588. n: Integer;
  589. begin
  590. ma:=buf1;
  591. mb:=buf2;
  592. n:=0;
  593. while Cardinal(n)<Count do
  594. begin
  595. if ma^<>mb^ then
  596. begin
  597. if ma^<mb^ then
  598. Result:=-1
  599. else
  600. Result:=1;
  601. exit;
  602. end;
  603. Inc(ma);
  604. Inc(mb);
  605. Inc(n);
  606. end;
  607. Result:=0;
  608. end;
  609. procedure _TIFFmemset(p: Pointer; v: Integer; c: Longint); cdecl;
  610. begin
  611. FillMemory(p,c,v);
  612. end;
  613. (* DW
  614. function bsearch(key: Pointer; base: Pointer; nelem: Cardinal; width: Cardinal; fcmp: TBsearchFcmp): Pointer; cdecl;
  615. begin
  616. raise Exception.Create('LibTiffDelphi - call to bsearch - should presumably not occur');
  617. end;
  618. *)
  619. procedure qsort(base: Pointer; num: Cardinal; width: Cardinal; compare: TQSortCompare); cdecl;
  620. var
  621. m: Pointer;
  622. n: Integer;
  623. o: Pointer;
  624. oa,ob,oc: Integer;
  625. p: Integer;
  626. begin
  627. if num<2 then exit;
  628. GetMem(m,num*width);
  629. if compare(base,Pointer(Cardinal(base)+width))<=0 then
  630. CopyMemory(m,base,(width shl 1))
  631. else
  632. begin
  633. CopyMemory(m,Pointer(Cardinal(base)+width),width);
  634. CopyMemory(Pointer(Cardinal(m)+width),base,width);
  635. end;
  636. n:=2;
  637. while Cardinal(n)<num do
  638. begin
  639. o:=Pointer(Cardinal(base)+Cardinal(n)*width);
  640. if compare(m,o)>=0 then
  641. ob:=0
  642. else
  643. begin
  644. oa:=0;
  645. ob:=n;
  646. while oa+1<ob do
  647. begin
  648. oc:=((oa+ob) shr 1);
  649. p:=compare(Pointer(Cardinal(m)+Cardinal(oc)*width),o);
  650. if p<0 then
  651. oa:=oc
  652. else if p=0 then
  653. begin
  654. ob:=oc;
  655. break;
  656. end
  657. else
  658. ob:=oc;
  659. end;
  660. end;
  661. if ob=0 then
  662. begin
  663. MoveMemory(Pointer(Cardinal(m)+width),m,Cardinal(n)*width);
  664. CopyMemory(m,o,width);
  665. end
  666. else if ob=n then
  667. CopyMemory(Pointer(Cardinal(m)+Cardinal(n)*width),o,width)
  668. else
  669. begin
  670. MoveMemory(Pointer(Cardinal(m)+Cardinal(ob+1)*width),Pointer(Cardinal(m)+Cardinal(ob)*width),Cardinal(n-ob)*width);
  671. CopyMemory(Pointer(Cardinal(m)+Cardinal(ob)*width),o,width);
  672. end;
  673. Inc(n);
  674. end;
  675. CopyMemory(base,m,num*width);
  676. FreeMem(m,num*width);
  677. end;
  678. function _TIFFrealloc(p: Pointer; s: Longint): Pointer; cdecl;
  679. var
  680. m: TMemoryManager;
  681. begin
  682. GetMemoryManager(m);
  683. if p=nil then
  684. Result:=m.GetMem(s)
  685. else
  686. Result:=m.ReallocMem(p,s);
  687. end;
  688. function strncmp(a: Pointer; b: Pointer; c: Longint): Integer; cdecl;
  689. var
  690. ma,mb: PByte;
  691. n: Integer;
  692. begin
  693. ma:=a;
  694. mb:=b;
  695. n:=0;
  696. while n<c do
  697. begin
  698. if ma^<>mb^ then
  699. begin
  700. if ma^<mb^ then
  701. Result:=-1
  702. else
  703. Result:=1;
  704. exit;
  705. end;
  706. if ma^=0 then
  707. begin
  708. Result:=0;
  709. exit;
  710. end;
  711. Inc(ma);
  712. Inc(mb);
  713. Inc(n);
  714. end;
  715. Result:=0;
  716. end;
  717. function strcmp(a: Pointer; b: Pointer): Integer; cdecl;
  718. var
  719. ma,mb: PByte;
  720. begin
  721. ma:=a;
  722. mb:=b;
  723. while True do
  724. begin
  725. if ma^<>mb^ then
  726. begin
  727. if ma^<mb^ then
  728. Result:=-1
  729. else
  730. Result:=1;
  731. exit;
  732. end;
  733. if ma^=0 then
  734. begin
  735. Result:=0;
  736. exit;
  737. end;
  738. Inc(ma);
  739. Inc(mb);
  740. end;
  741. Result:=0;
  742. end;
  743. function strlen(s: Pointer): Cardinal; cdecl;
  744. var
  745. m: PByte;
  746. begin
  747. Result:=0;
  748. m:=s;
  749. while m^<>0 do
  750. begin
  751. Inc(Result);
  752. Inc(m);
  753. end;
  754. end;
  755. procedure _TIFFfree(p: Pointer); cdecl;
  756. var
  757. m: TMemoryManager;
  758. begin
  759. GetMemoryManager(m);
  760. m.FreeMem(p);
  761. end;
  762. procedure _TIFFmemcpy(d: Pointer; s: Pointer; c: Longint); cdecl;
  763. begin
  764. CopyMemory(d,s,c);
  765. end;
  766. function pow(x: Double; y: Double): Double; cdecl;
  767. begin
  768. Result:=Power(x,y);
  769. end;
  770. function floor(x: Double): Double; cdecl;
  771. begin
  772. Result:=Trunc(x);
  773. end;
  774. function _TIFFmalloc(s: Longint): Pointer; cdecl;
  775. var
  776. m: TMemoryManager;
  777. begin
  778. GetMemoryManager(m);
  779. Result:=m.GetMem(s);
  780. end;
  781. {LibTiffDelphi}
  782. function LibTiffDelphiVersion: String;
  783. var
  784. m: String;
  785. na,nb: Integer;
  786. begin
  787. Result:='';
  788. m:=TIFFGetVersion;
  789. na:=1;
  790. while True do
  791. begin
  792. nb:=na;
  793. while nb<=Length(m) do
  794. begin
  795. if m[nb]=#10 then break;
  796. Inc(nb);
  797. end;
  798. Result:=Result+System.Copy(m,na,nb-na);
  799. if nb>Length(m) then break;
  800. Result:=Result+#13#10;
  801. na:=nb+1;
  802. end;
  803. Result:=Result+#13#10+LibTiffDelphiVersionString;
  804. end;
  805. procedure LibTiffDelphiWarningThrp(a: Pointer; b: Pointer; c: Pointer); cdecl;
  806. var
  807. m: Integer;
  808. n: String;
  809. begin
  810. if @FLibTiffDelphiWarningHandler<>nil then
  811. begin
  812. m:=sprintfsec(nil,b,@c);
  813. SetLength(n,m);
  814. sprintfsec(Pointer(n),b,@c);
  815. FLibTiffDelphiWarningHandler(PChar(a),n);
  816. end;
  817. end;
  818. procedure LibTiffDelphiErrorThrp(a: Pointer; b: Pointer; c: Pointer); cdecl;
  819. var
  820. m: Integer;
  821. n: String;
  822. begin
  823. if @FLibTiffDelphiErrorHandler<>nil then
  824. begin
  825. m:=sprintfsec(nil,b,@c);
  826. SetLength(n,m);
  827. sprintfsec(Pointer(n),b,@c);
  828. FLibTiffDelphiErrorHandler(PChar(a),n);
  829. end;
  830. end;
  831. function LibTiffDelphiGetWarningHandler: LibTiffDelphiErrorHandler;
  832. begin
  833. Result:=FLibTiffDelphiWarningHandler;
  834. end;
  835. function LibTiffDelphiSetWarningHandler(Handler: LibTiffDelphiErrorHandler): LibTiffDelphiErrorHandler;
  836. begin
  837. Result:=FLibTiffDelphiWarningHandler;
  838. FLibTiffDelphiWarningHandler:=Handler;
  839. end;
  840. function LibTiffDelphiGetErrorHandler: LibTiffDelphiErrorHandler;
  841. begin
  842. Result:=FLibTiffDelphiErrorHandler;
  843. end;
  844. function LibTiffDelphiSetErrorHandler(Handler: LibTiffDelphiErrorHandler): LibTiffDelphiErrorHandler;
  845. begin
  846. Result:=FLibTiffDelphiErrorHandler;
  847. FLibTiffDelphiErrorHandler:=Handler;
  848. end;
  849. {tif_read}
  850. procedure _TIFFSwab16BitData(tif: Pointer; buf: Pointer; cc: Integer); cdecl; external;
  851. procedure _TIFFSwab24BitData(tif: pointer; buf: pointer; cc: integer); cdecl; external; //DW 3.8.2
  852. procedure _TIFFSwab32BitData(tif: Pointer; buf: Pointer; cc: Integer); cdecl; external;
  853. procedure _TIFFSwab64BitData(tif: Pointer; buf: Pointer; cc: Integer); cdecl; external;
  854. procedure _TIFFNoPostDecode(tif: Pointer; buf: Pointer; cc: Integer); cdecl; external;
  855. function TIFFReadTile(tif: Pointer; buf: Pointer; x: Cardinal; y: Cardinal; z: Cardinal; s: Word): Integer; cdecl; external;
  856. function TIFFFillTile(tif: Pointer; tile: longword):integer; cdecl; external; //DW 3.8.2
  857. {$IFDEF LIBTIFF_DEBUG}
  858. {$L LibTiffDelphi\debug\tif_read.obj}
  859. {$ELSE}
  860. {$L LibTiffDelphi\release\tif_read.obj}
  861. {$ENDIF}
  862. {tif_dirinfo}
  863. function _TIFFSampleToTagType(tif: Pointer): Integer; cdecl; external;
  864. procedure _TIFFSetupFieldInfo(tif: Pointer); cdecl; external;
  865. function _TIFFCreateAnonFieldInfo(tif: Pointer; tag: Cardinal; field_type: Integer): Pointer; cdecl; external;
  866. function _TIFFGetExifFieldInfo(size : plongint):pointer; cdecl; external; //DW 3.8.2
  867. function _TIFFDataSize(TIFFDataType : longint):longint; cdecl; external; //DW 3.8.2
  868. function _TIFFGetFieldInfo(size : plongint):pointer; cdecl; external; //DW 3.8.2
  869. function _TIFFMergeFieldInfo(tif: Pointer; fieldinfo : Pointer; n : Integer):Integer; cdecl; external; //DW 3.9.1
  870. {$IFDEF LIBTIFF_DEBUG}
  871. {$L LibTiffDelphi\debug\tif_dirinfo.obj}
  872. {$ELSE}
  873. {$L LibTiffDelphi\release\tif_dirinfo.obj}
  874. {$ENDIF}
  875. {tif_dirwrite}
  876. {$IFDEF LIBTIFF_DEBUG}
  877. {$L LibTiffDelphi\debug\tif_dirwrite.obj}
  878. {$ELSE}
  879. {$L LibTiffDelphi\release\tif_dirwrite.obj}
  880. {$ENDIF}
  881. {tif_flush}
  882. {$IFDEF LIBTIFF_DEBUG}
  883. {$L LibTiffDelphi\debug\tif_flush.obj}
  884. {$ELSE}
  885. {$L LibTiffDelphi\release\tif_flush.obj}
  886. {$ENDIF}
  887. {tif_write}
  888. function TIFFFlushData1(tif: Pointer): Integer; cdecl; external;
  889. function TIFFSetupStrips(tif: Pointer): Integer; cdecl; external;
  890. {$IFDEF LIBTIFF_DEBUG}
  891. {$L LibTiffDelphi\debug\tif_write.obj}
  892. {$ELSE}
  893. {$L LibTiffDelphi\release\tif_write.obj}
  894. {$ENDIF}
  895. {tif_dumpmode}
  896. function TIFFInitDumpMode(tif: Pointer; scheme: Integer): Integer; cdecl; external;
  897. {$IFDEF LIBTIFF_DEBUG}
  898. {$L LibTiffDelphi\debug\tif_dumpmode.obj}
  899. {$ELSE}
  900. {$L LibTiffDelphi\release\tif_dumpmode.obj}
  901. {$ENDIF}
  902. {tif_compress}
  903. function TIFFSetCompressionScheme(tif: Pointer; scheme: Integer): Integer; cdecl; external;
  904. procedure _TIFFSetDefaultCompressionState(tif: Pointer); cdecl; external;
  905. {$IFDEF LIBTIFF_DEBUG}
  906. {$L LibTiffDelphi\debug\tif_compress.obj}
  907. {$ELSE}
  908. {$L LibTiffDelphi\release\tif_compress.obj}
  909. {$ENDIF}
  910. {tif_dirread}
  911. {$IFDEF LIBTIFF_DEBUG}
  912. {$L LibTiffDelphi\debug\tif_dirread.obj}
  913. {$ELSE}
  914. {$L LibTiffDelphi\release\tif_dirread.obj}
  915. {$ENDIF}
  916. {tif_dir}
  917. procedure TIFFFreeDirectory(tif: Pointer); cdecl; external;
  918. function TIFFDefaultDirectory(tif: Pointer): Integer; cdecl; external;
  919. function TIFFReassignTagToIgnore(task: Integer; TIFFtagID: Integer): Integer; cdecl; external;
  920. procedure _TIFFsetString(cpp: Pointer; cp: Pointer); cdecl; external;
  921. procedure _TIFFsetByteArray(vpp: Pointer; vp: Pointer; n: Integer); cdecl; external;
  922. {$IFDEF LIBTIFF_DEBUG}
  923. {$L LibTiffDelphi\debug\tif_dir.obj}
  924. {$ELSE}
  925. {$L LibTiffDelphi\release\tif_dir.obj}
  926. {$ENDIF}
  927. {tif_aux}
  928. function TIFFVGetFieldDefaulted(tif: Pointer; tag: Cardinal; ap: Pointer): Integer; cdecl; external;
  929. {$IFDEF LIBTIFF_DEBUG}
  930. {$L LibTiffDelphi\debug\tif_aux.obj}
  931. {$ELSE}
  932. {$L LibTiffDelphi\release\tif_aux.obj}
  933. {$ENDIF}
  934. {tif_color}
  935. procedure TIFFCIELabToXYZ(cielab: Pointer; l: Cardinal; a: Integer; b: Integer; X: Pointer; Y: Pointer; Z: Pointer); cdecl; external;
  936. procedure TIFFXYZToRGB(cielab: Pointer; X: Single; Y: Single; Z: Single; r: Pointer; g: Pointer; b: Pointer); cdecl; external;
  937. procedure TIFFYCbCrtoRGB(ycbcr: Pointer; Y: Cardinal; Cb: Integer; Cr: Integer; r: Pointer; g: Pointer; b: Pointer); cdecl; external;
  938. function TIFFYCbCrToRGBInit(ycbcr: Pointer; luma: Pointer; refBlackWhite: Pointer): Integer; cdecl; external;
  939. function TIFFCIELabToRGBInit(cielab: Pointer; display: Pointer; refWhite: Pointer): Integer; cdecl; external;
  940. {$IFDEF LIBTIFF_DEBUG}
  941. {$L LibTiffDelphi\debug\tif_color.obj}
  942. {$ELSE}
  943. {$L LibTiffDelphi\release\tif_color.obj}
  944. {$ENDIF}
  945. {tif_close}
  946. {$IFDEF LIBTIFF_DEBUG}
  947. {$L LibTiffDelphi\debug\tif_close.obj}
  948. {$ELSE}
  949. {$L LibTiffDelphi\release\tif_close.obj}
  950. {$ENDIF}
  951. {tif_extension}
  952. {$IFDEF LIBTIFF_DEBUG}
  953. {$L LibTiffDelphi\debug\tif_extension.obj}
  954. {$ELSE}
  955. {$L LibTiffDelphi\release\tif_extension.obj}
  956. {$ENDIF}
  957. {tif_open}
  958. function _TIFFgetMode(mode: PChar; module: PChar): Integer; cdecl; external;
  959. {$IFDEF LIBTIFF_DEBUG}
  960. {$L LibTiffDelphi\debug\tif_open.obj}
  961. {$ELSE}
  962. {$L LibTiffDelphi\release\tif_open.obj}
  963. {$ENDIF}
  964. {tif_getimage}
  965. {$IFDEF LIBTIFF_DEBUG}
  966. {$L LibTiffDelphi\debug\tif_getimage.obj}
  967. {$ELSE}
  968. {$L LibTiffDelphi\release\tif_getimage.obj}
  969. {$ENDIF}
  970. {tif_predict}
  971. function TIFFPredictorInit(tif: PTIFF): Integer; cdecl; external;
  972. function TIFFPredictorCleanup(tif: PTIFF):integer; cdecl; external; //DW 3.8.2
  973. {$IFDEF LIBTIFF_DEBUG}
  974. {$L LibTiffDelphi\debug\tif_predict.obj}
  975. {$ELSE}
  976. {$L LibTiffDelphi\release\tif_predict.obj}
  977. {$ENDIF}
  978. {tif_print}
  979. {$IFDEF LIBTIFF_DEBUG}
  980. {$L LibTiffDelphi\debug\tif_print.obj}
  981. {$ELSE}
  982. {$L LibTiffDelphi\release\tif_print.obj}
  983. {$ENDIF}
  984. {tif_error}
  985. {$IFDEF LIBTIFF_DEBUG}
  986. {$L LibTiffDelphi\debug\tif_error.obj}
  987. {$ELSE}
  988. {$L LibTiffDelphi\release\tif_error.obj}
  989. {$ENDIF}
  990. {tif_strip}
  991. function _TIFFDefaultStripSize(tif: Pointer; s: Cardinal): Cardinal; cdecl; external;
  992. function TIFFOldScanlineSize(tif: Pointer):Cardinal; cdecl; external; //DW 3.9.1
  993. {$IFDEF LIBTIFF_DEBUG}
  994. {$L LibTiffDelphi\debug\tif_strip.obj}
  995. {$ELSE}
  996. {$L LibTiffDelphi\release\tif_strip.obj}
  997. {$ENDIF}
  998. {tif_swab}
  999. {$IFDEF LIBTIFF_DEBUG}
  1000. {$L LibTiffDelphi\debug\tif_swab.obj}
  1001. {$ELSE}
  1002. {$L LibTiffDelphi\release\tif_swab.obj}
  1003. {$ENDIF}
  1004. {tif_tile}
  1005. function TIFFCheckTile(tif: Pointer; x: Cardinal; y: Cardinal; z: Cardinal; s: Word): Integer; cdecl; external;
  1006. procedure _TIFFDefaultTileSize(tif: Pointer; tw: Pointer; th: Pointer); cdecl; external;
  1007. {$IFDEF LIBTIFF_DEBUG}
  1008. {$L LibTiffDelphi\debug\tif_tile.obj}
  1009. {$ELSE}
  1010. {$L LibTiffDelphi\release\tif_tile.obj}
  1011. {$ENDIF}
  1012. {tif_warning}
  1013. {$IFDEF LIBTIFF_DEBUG}
  1014. {$L LibTiffDelphi\debug\tif_warning.obj}
  1015. {$ELSE}
  1016. {$L LibTiffDelphi\release\tif_warning.obj}
  1017. {$ENDIF}
  1018. {tif_fax3}
  1019. function TIFFInitCCITTRLE(tif: PTIFF; scheme: Integer): Integer; cdecl; external;
  1020. function TIFFInitCCITTRLEW(tif: PTIFF; scheme: Integer): Integer; cdecl; external;
  1021. function TIFFInitCCITTFax3(tif: PTIFF; scheme: Integer): Integer; cdecl; external;
  1022. function TIFFInitCCITTFax4(tif: PTIFF; scheme: Integer): Integer; cdecl; external;
  1023. {$IFDEF LIBTIFF_DEBUG}
  1024. {$L LibTiffDelphi\debug\tif_fax3.obj}
  1025. {$ELSE}
  1026. {$L LibTiffDelphi\release\tif_fax3.obj}
  1027. {$ENDIF}
  1028. {tif_fax3sm}
  1029. {$IFDEF LIBTIFF_DEBUG}
  1030. {$L LibTiffDelphi\debug\tif_fax3sm.obj}
  1031. {$ELSE}
  1032. {$L LibTiffDelphi\release\tif_fax3sm.obj}
  1033. {$ENDIF}
  1034. {tif_jpeg}
  1035. procedure TIFFjpeg_error_exit_raise; cdecl;
  1036. begin
  1037. raise Exception.Create('TIFFjpeg_error_exit');
  1038. end;
  1039. function TIFFcallvjpeg_jpeg_CreateCompress(cinfo: Pointer; version: Integer; structsize: Cardinal): Integer; cdecl;
  1040. begin
  1041. try
  1042. jpeg_CreateCompress(cinfo,version,structsize);
  1043. Result:=1;
  1044. except
  1045. Result:=0;
  1046. end;
  1047. end;
  1048. function TIFFcallvjpeg_jpeg_CreateDecompress(cinfo: Pointer; version: Integer; structsize: Cardinal): Integer; cdecl;
  1049. begin
  1050. try
  1051. jpeg_CreateDecompress(cinfo,version,structsize);
  1052. Result:=1;
  1053. except
  1054. Result:=0;
  1055. end;
  1056. end;
  1057. function TIFFcallvjpeg_jpeg_set_defaults(cinfo: Pointer): Integer; cdecl;
  1058. begin
  1059. try
  1060. jpeg_set_defaults(cinfo);
  1061. Result:=1;
  1062. except
  1063. Result:=0;
  1064. end;
  1065. end;
  1066. function TIFFcallvjpeg_jpeg_set_colorspace(cinfo: Pointer; colorspace: Integer): Integer; cdecl;
  1067. begin
  1068. try
  1069. jpeg_set_colorspace(cinfo,colorspace);
  1070. Result:=1;
  1071. except
  1072. Result:=0;
  1073. end;
  1074. end;
  1075. function TIFFcallvjpeg_jpeg_set_quality(cinfo: Pointer; quality: Integer; force_baseline: Byte): Integer; cdecl;
  1076. begin
  1077. try
  1078. jpeg_set_quality(cinfo,quality,force_baseline);
  1079. Result:=1;
  1080. except
  1081. Result:=0;
  1082. end;
  1083. end;
  1084. function TIFFcallvjpeg_jpeg_suppress_tables(cinfo: PRJpegCompressStruct; suppress: Byte): Integer; cdecl;
  1085. begin
  1086. try
  1087. jpeg_suppress_tables(cinfo,suppress);
  1088. Result:=1;
  1089. except
  1090. Result:=0;
  1091. end;
  1092. end;
  1093. function TIFFcallvjpeg_jpeg_start_compress(cinfo: PRJpegCompressStruct; write_all_tables: Byte): Integer; cdecl;
  1094. begin
  1095. try
  1096. jpeg_start_compress(cinfo,write_all_tables);
  1097. Result:=1;
  1098. except
  1099. Result:=0;
  1100. end;
  1101. end;
  1102. function TIFFcalljpeg_jpeg_write_scanlines(errreturn: Integer; cinfo: PRJpegCompressStruct; scanlines: Pointer; num_lines: Cardinal): Integer; cdecl;
  1103. begin
  1104. try
  1105. Result:=jpeg_write_scanlines(cinfo,scanlines,num_lines);
  1106. except
  1107. Result:=errreturn;
  1108. end;
  1109. end;
  1110. function TIFFcalljpeg_jpeg_write_raw_data(errreturn: Integer; cinfo: PRJpegCompressStruct; data: Pointer; num_lines: Cardinal): Integer; cdecl;
  1111. begin
  1112. try
  1113. Result:=jpeg_write_raw_data(cinfo,data,num_lines);
  1114. except
  1115. Result:=errreturn;
  1116. end;
  1117. end;
  1118. function TIFFcallvjpeg_jpeg_finish_compress(cinfo: PRJpegCompressStruct): Integer; cdecl;
  1119. begin
  1120. try
  1121. jpeg_finish_compress(cinfo);
  1122. Result:=1;
  1123. except
  1124. Result:=0;
  1125. end;
  1126. end;
  1127. function TIFFcallvjpeg_jpeg_write_tables(cinfo: PRJpegCompressStruct): Integer; cdecl;
  1128. begin
  1129. try
  1130. jpeg_write_tables(cinfo);
  1131. Result:=1;
  1132. except
  1133. Result:=0;
  1134. end;
  1135. end;
  1136. function TIFFcalljpeg_jpeg_read_header(errreturn: Integer; cinfo: PRJpegDecompressStruct; require_image: Byte): Integer; cdecl;
  1137. begin
  1138. try
  1139. Result:=jpeg_read_header(cinfo,Boolean(require_image));
  1140. except
  1141. Result:=errreturn;
  1142. end;
  1143. end;
  1144. function TIFFcallvjpeg_jpeg_start_decompress(cinfo: PRJpegDecompressStruct): Integer; cdecl;
  1145. begin
  1146. try
  1147. jpeg_start_decompress(cinfo);
  1148. Result:=1;
  1149. except
  1150. Result:=0;
  1151. end;
  1152. end;
  1153. function TIFFcalljpeg_jpeg_read_scanlines(errreturn: Integer; cinfo: PRJpegDecompressStruct; scanlines: Pointer; max_lines: Cardinal): Integer; cdecl;
  1154. begin
  1155. try
  1156. Result:=jpeg_read_scanlines(cinfo,scanlines,max_lines);
  1157. except
  1158. Result:=errreturn;
  1159. end;
  1160. end;
  1161. function TIFFcalljpeg_jpeg_read_raw_data(errreturn: Integer; cinfo: PRJpegDecompressStruct; data: Pointer; max_lines: Cardinal): Integer; cdecl;
  1162. begin
  1163. try
  1164. Result:=jpeg_read_raw_data(cinfo,data,max_lines);
  1165. except
  1166. Result:=errreturn;
  1167. end;
  1168. end;
  1169. function TIFFcalljpeg_jpeg_finish_decompress(errreturn: Integer; cinfo: PRJpegDecompressStruct): Integer; cdecl;
  1170. begin
  1171. try
  1172. Result:=jpeg_finish_decompress(cinfo);
  1173. except
  1174. Result:=errreturn;
  1175. end;
  1176. end;
  1177. function TIFFcallvjpeg_jpeg_abort(cinfo: PRJpegCommonStruct): Integer; cdecl;
  1178. begin
  1179. try
  1180. jpeg_abort(cinfo);
  1181. Result:=1;
  1182. except
  1183. Result:=0;
  1184. end;
  1185. end;
  1186. function TIFFcallvjpeg_jpeg_destroy(cinfo: PRJpegCommonStruct): Integer; cdecl;
  1187. begin
  1188. try
  1189. jpeg_destroy(cinfo);
  1190. Result:=1;
  1191. except
  1192. Result:=0;
  1193. end;
  1194. end;
  1195. type
  1196. jpeg_alloc_sarray = function(cinfo: PRJpegCommonStruct; pool_id: Integer; samplesperrow: Cardinal; numrows: Cardinal): Pointer; cdecl;
  1197. function TIFFcalljpeg_alloc_sarray(alloc_sarray: jpeg_alloc_sarray; cinfo: PRJpegCommonStruct; pool_id: Integer; samplesperrow: Cardinal;
  1198. numrows: Cardinal): Pointer; cdecl;
  1199. begin
  1200. try
  1201. Result:=alloc_sarray(cinfo,pool_id,samplesperrow,numrows);
  1202. except
  1203. Result:=nil;
  1204. end;
  1205. end;
  1206. function TIFFInitJPEG(tif: PTIFF; scheme: Integer): Integer; cdecl; external;
  1207. function TIFFFillStrip(tif : PTIFF; Len : longword): integer; cdecl; external; //DW 3.8.2
  1208. {$IFDEF LIBTIFF_DEBUG}
  1209. {$L LibTiffDelphi\debug\tif_jpeg.obj}
  1210. {$ELSE}
  1211. {$L LibTiffDelphi\release\tif_jpeg.obj}
  1212. {$ENDIF}
  1213. {tif_luv}
  1214. function TIFFInitSGILog(tif: PTIFF; scheme: Integer): Integer; cdecl; external;
  1215. {$IFDEF LIBTIFF_DEBUG}
  1216. {$L LibTiffDelphi\debug\tif_luv.obj}
  1217. {$ELSE}
  1218. {$L LibTiffDelphi\release\tif_luv.obj}
  1219. {$ENDIF}
  1220. {tif_lzw}
  1221. function TIFFInitLZW(tif: PTIFF; scheme: Integer): Integer; cdecl; external;
  1222. {$IFDEF LIBTIFF_DEBUG}
  1223. {$L LibTiffDelphi\debug\tif_lzw.obj}
  1224. {$ELSE}
  1225. {$L LibTiffDelphi\release\tif_lzw.obj}
  1226. {$ENDIF}
  1227. {tif_next}
  1228. function TIFFInitNeXT(tif: PTIFF; scheme: Integer): Integer; cdecl; external;
  1229. {$IFDEF LIBTIFF_DEBUG}
  1230. {$L LibTiffDelphi\debug\tif_next.obj}
  1231. {$ELSE}
  1232. {$L LibTiffDelphi\release\tif_next.obj}
  1233. {$ENDIF}
  1234. {tif_packbits}
  1235. function TIFFInitPackBits(tif: PTIFF; scheme: Integer): Integer; cdecl; external;
  1236. {$IFDEF LIBTIFF_DEBUG}
  1237. {$L LibTiffDelphi\debug\tif_packbits.obj}
  1238. {$ELSE}
  1239. {$L LibTiffDelphi\release\tif_packbits.obj}
  1240. {$ENDIF}
  1241. {tif_pixarlog}
  1242. function TIFFInitPixarLog(tif: PTIFF; scheme: Integer): Integer; cdecl; external;
  1243. {$IFDEF LIBTIFF_DEBUG}
  1244. {$L LibTiffDelphi\debug\tif_pixarlog.obj}
  1245. {$ELSE}
  1246. {$L LibTiffDelphi\release\tif_pixarlog.obj}
  1247. {$ENDIF}
  1248. {tif_thunder}
  1249. function TIFFInitThunderScan(tif: PTIFF; scheme: Integer): Integer; cdecl; external;
  1250. {$IFDEF LIBTIFF_DEBUG}
  1251. {$L LibTiffDelphi\debug\tif_thunder.obj}
  1252. {$ELSE}
  1253. {$L LibTiffDelphi\release\tif_thunder.obj}
  1254. {$ENDIF}
  1255. {tif_version}
  1256. {$IFDEF LIBTIFF_DEBUG}
  1257. {$L LibTiffDelphi\debug\tif_version.obj}
  1258. {$ELSE}
  1259. {$L LibTiffDelphi\release\tif_version.obj}
  1260. {$ENDIF}
  1261. {tif_zip}
  1262. function TIFFInitZIP(tif: PTIFF; scheme: Integer): Integer; cdecl; external;
  1263. {$IFDEF LIBTIFF_DEBUG}
  1264. {$L LibTiffDelphi\debug\tif_zip.obj}
  1265. {$ELSE}
  1266. {$L LibTiffDelphi\release\tif_zip.obj}
  1267. {$ENDIF}
  1268. {tif_codec}
  1269. function NotConfigured(tif: PTIFF; scheme: Integer): Integer; cdecl; external;
  1270. {DW
  1271. const
  1272. _TIFFBuiltinCODECS: array[0..17] of TIFFCodec = (
  1273. (name:'None'; scheme: COMPRESSION_NONE; init: TIFFInitDumpMode),
  1274. (name:'LZW'; scheme: COMPRESSION_LZW; init: TIFFInitLZW),
  1275. (name:'PackBits'; scheme: COMPRESSION_PACKBITS; init: TIFFInitPackBits),
  1276. (name:'ThunderScan'; scheme: COMPRESSION_THUNDERSCAN; init: TIFFInitThunderScan),
  1277. (name:'NeXT'; scheme: COMPRESSION_NEXT; init: TIFFInitNeXT),
  1278. (name:'JPEG'; scheme: COMPRESSION_JPEG; init: TIFFInitJPEG),
  1279. (name:'Old-style JPEG'; scheme: COMPRESSION_OJPEG; init: NotConfigured),
  1280. (name:'CCITT RLE'; scheme: COMPRESSION_CCITTRLE; init: TIFFInitCCITTRLE),
  1281. (name:'CCITT RLE/W'; scheme: COMPRESSION_CCITTRLEW; init: TIFFInitCCITTRLEW),
  1282. (name:'CCITT Group 3'; scheme: COMPRESSION_CCITTFAX3; init: TIFFInitCCITTFax3),
  1283. (name:'CCITT Group 4'; scheme: COMPRESSION_CCITTFAX4; init: TIFFInitCCITTFax4),
  1284. (name:'ISO JBIG'; scheme: COMPRESSION_JBIG; init: NotConfigured),
  1285. (name:'Deflate'; scheme: COMPRESSION_DEFLATE; init: TIFFInitZIP),
  1286. (name:'AdobeDeflate'; scheme: COMPRESSION_ADOBE_DEFLATE; init: TIFFInitZIP),
  1287. (name:'PixarLog'; scheme: COMPRESSION_PIXARLOG; init: TIFFInitPixarLog),
  1288. (name:'SGILog'; scheme: COMPRESSION_SGILOG; init: TIFFInitSGILog),
  1289. (name:'SGILog24'; scheme: COMPRESSION_SGILOG24; init: TIFFInitSGILog),
  1290. (name:nil; scheme:0; init:nil));
  1291. }
  1292. {$IFDEF LIBTIFF_DEBUG}
  1293. {$L LibTiffDelphi\debug\tif_codec.obj}
  1294. {$ELSE}
  1295. {$L LibTiffDelphi\release\tif_codec.obj}
  1296. {$ENDIF}
  1297. {LibTiffDelphi}
  1298. function TIFFFileReadProc(Fd: Cardinal; Buffer: Pointer; Size: Integer): Integer; cdecl; forward;
  1299. function TIFFFileWriteProc(Fd: Cardinal; Buffer: Pointer; Size: Integer): Integer; cdecl; forward;
  1300. function TIFFFileSizeProc(Fd: Cardinal): Cardinal; cdecl; forward;
  1301. function TIFFFileSeekProc(Fd: Cardinal; Off: Cardinal; Whence: Integer): Cardinal; cdecl; forward;
  1302. function TIFFFileCloseProc(Fd: Cardinal): Integer; cdecl; forward;
  1303. function TIFFStreamReadProc(Fd: Cardinal; Buffer: Pointer; Size: Integer): Integer; cdecl; forward;
  1304. function TIFFStreamWriteProc(Fd: Cardinal; Buffer: Pointer; Size: Integer): Integer; cdecl; forward;
  1305. function TIFFStreamSizeProc(Fd: Cardinal): Cardinal; cdecl; forward;
  1306. function TIFFStreamSeekProc(Fd: Cardinal; Off: Cardinal; Whence: Integer): Cardinal; cdecl; forward;
  1307. function TIFFStreamCloseProc(Fd: Cardinal): Integer; cdecl; forward;
  1308. function TIFFNoMapProc(Fd: Cardinal; PBase: PPointer; PSize: PCardinal): Integer; cdecl; forward;
  1309. procedure TIFFNoUnmapProc(Fd: Cardinal; Base: Pointer; Size: Cardinal); cdecl; forward;
  1310. function TIFFFileCloseProc(Fd: Cardinal): Integer; cdecl;
  1311. begin
  1312. if CloseHandle(Fd)=True then
  1313. Result:=0
  1314. else
  1315. Result:=-1;
  1316. end;
  1317. function TIFFFileSizeProc(Fd: Cardinal): Cardinal; cdecl;
  1318. begin
  1319. Result:=GetFileSize(Fd,nil);
  1320. end;
  1321. function TIFFFileSeekProc(Fd: Cardinal; Off: Cardinal; Whence: Integer): Cardinal; cdecl;
  1322. const
  1323. SEEK_SET = 0;
  1324. SEEK_CUR = 1;
  1325. SEEK_END = 2;
  1326. var
  1327. MoveMethod: Cardinal;
  1328. begin
  1329. if Off=$ffffffff then
  1330. begin
  1331. Result:=$ffffffff;
  1332. exit;
  1333. end;
  1334. case Whence of
  1335. SEEK_SET: MoveMethod:=FILE_BEGIN;
  1336. SEEK_CUR: MoveMethod:=FILE_CURRENT;
  1337. SEEK_END: MoveMethod:=FILE_END;
  1338. else
  1339. MoveMethod:=FILE_BEGIN;
  1340. end;
  1341. Result:=SetFilePointer(Fd,Off,nil,MoveMethod);
  1342. end;
  1343. function TIFFFileReadProc(Fd: Cardinal; Buffer: Pointer; Size: Integer): Integer; cdecl;
  1344. var
  1345. m: Cardinal;
  1346. begin
  1347. if ReadFile(Fd,Buffer^,Cardinal(Size),m,nil)=False then
  1348. Result:=0
  1349. else
  1350. Result:=m;
  1351. end;
  1352. function TIFFFileWriteProc(Fd: Cardinal; Buffer: Pointer; Size: Integer): Integer; cdecl;
  1353. var
  1354. m: Cardinal;
  1355. begin
  1356. if WriteFile(Fd,Buffer^,Cardinal(Size),m,nil)=False then
  1357. Result:=0
  1358. else
  1359. Result:=m;
  1360. end;
  1361. function TIFFStreamCloseProc(Fd: Cardinal): Integer; cdecl;
  1362. begin
  1363. Result:=0;
  1364. end;
  1365. function TIFFStreamSizeProc(Fd: Cardinal): Cardinal; cdecl;
  1366. begin
  1367. try
  1368. Result:=TStream(Fd).Size;
  1369. except
  1370. Result:=0;
  1371. end;
  1372. end;
  1373. function TIFFStreamSeekProc(Fd: Cardinal; Off: Cardinal; Whence: Integer): Cardinal; cdecl;
  1374. const
  1375. SEEK_SET = 0;
  1376. SEEK_CUR = 1;
  1377. SEEK_END = 2;
  1378. var
  1379. MoveMethod: Word;
  1380. begin
  1381. if Off=$ffffffff then
  1382. begin
  1383. Result:=$ffffffff;
  1384. exit;
  1385. end;
  1386. case Whence of
  1387. SEEK_SET: MoveMethod:=soFromBeginning;
  1388. SEEK_CUR: MoveMethod:=soFromCurrent;
  1389. SEEK_END: MoveMethod:=soFromEnd;
  1390. else
  1391. MoveMethod:=soFromBeginning;
  1392. end;
  1393. try
  1394. Result:=TStream(Fd).Seek(Off,MoveMethod);
  1395. except
  1396. Result:=0;
  1397. end;
  1398. end;
  1399. function TIFFStreamReadProc(Fd: Cardinal; Buffer: Pointer; Size: Integer): Integer; cdecl;
  1400. begin
  1401. try
  1402. Result:=TStream(Fd).Read(Buffer^,Size);
  1403. except
  1404. Result:=0;
  1405. end;
  1406. end;
  1407. function TIFFStreamWriteProc(Fd: Cardinal; Buffer: Pointer; Size: Integer): Integer; cdecl;
  1408. begin
  1409. try
  1410. Result:=TStream(Fd).Write(Buffer^,Size);
  1411. except
  1412. Result:=0;
  1413. end;
  1414. end;
  1415. function TIFFNoMapProc(Fd: Cardinal; PBase: PPointer; PSize: PCardinal): Integer; cdecl;
  1416. begin
  1417. Result:=0;
  1418. end;
  1419. procedure TIFFNoUnmapProc(Fd: Cardinal; Base: Pointer; Size: Cardinal); cdecl;
  1420. begin
  1421. end;
  1422. function TIFFOpen(const Name: String; const Mode: String): PTIFF;
  1423. const
  1424. Module: String = 'TIFFOpen';
  1425. O_RDONLY = 0;
  1426. O_WRONLY = 1;
  1427. O_RDWR = 2;
  1428. O_CREAT = $0100;
  1429. O_TRUNC = $0200;
  1430. var
  1431. m: Integer;
  1432. DesiredAccess: Cardinal;
  1433. CreateDisposition: Cardinal;
  1434. FlagsAndAttributes: Cardinal;
  1435. fd: THandle;
  1436. begin
  1437. m:=_TIFFgetMode(PChar(Mode),PChar(Module));
  1438. if m=o_RDONLY then
  1439. DesiredAccess:=GENERIC_READ
  1440. else
  1441. DesiredAccess:=(GENERIC_READ or GENERIC_WRITE);
  1442. case m of
  1443. O_RDONLY: CreateDisposition:=OPEN_EXISTING;
  1444. O_RDWR: CreateDisposition:=OPEN_ALWAYS;
  1445. (O_RDWR or O_CREAT): CreateDisposition:=OPEN_ALWAYS;
  1446. (O_RDWR or O_TRUNC): CreateDisposition:=CREATE_ALWAYS;
  1447. (O_RDWR or O_CREAT or O_TRUNC): CreateDisposition:=CREATE_ALWAYS;
  1448. else
  1449. Result:=nil;
  1450. exit;
  1451. end;
  1452. if m=O_RDONLY then
  1453. FlagsAndAttributes:=FILE_ATTRIBUTE_READONLY
  1454. else
  1455. FlagsAndAttributes:=FILE_ATTRIBUTE_NORMAL;
  1456. fd:=CreateFile(PChar(Name),DesiredAccess,FILE_SHARE_READ,nil,CreateDisposition,FlagsAndAttributes,0);
  1457. if fd=INVALID_HANDLE_VALUE then
  1458. begin
  1459. TiffError(PChar(Module),PChar('%s: Cannot open'),PChar(Name));
  1460. Result:=nil;
  1461. exit;
  1462. end;
  1463. Result:=TIFFClientOpen(PChar(Name),PChar(Mode),fd,@TIFFFileReadProc,@TIFFFileWriteProc,@TIFFFileSeekProc,@TIFFFileCloseProc,
  1464. @TIFFFileSizeProc,@TIFFNoMapProc,@TIFFNoUnmapProc);
  1465. if Result<>nil then
  1466. TIFFSetFileno(Result,fd)
  1467. else
  1468. CloseHandle(fd);
  1469. end;
  1470. function TIFFOpenStream(const Stream: TStream; const Mode: String): PTIFF;
  1471. var
  1472. m: String;
  1473. begin
  1474. m:='Stream';
  1475. Result:=TIFFClientOpen(PChar(m),PChar(Mode),Cardinal(Stream),@TIFFStreamReadProc,@TIFFStreamWriteProc,@TIFFStreamSeekProc,@TIFFStreamCloseProc,
  1476. @TIFFStreamSizeProc,@TIFFNoMapProc,@TIFFNoUnmapProc);
  1477. if Result<>nil then TIFFSetFileno(Result,Cardinal(Stream));
  1478. end;
  1479. initialization
  1480. _TIFFwarningHandler:=LibTiffDelphiWarningThrp;
  1481. _TIFFerrorHandler:=LibTiffDelphiErrorThrp;
  1482. end.