LibTiffDelphi.pas 65 KB

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