LibTiffDelphi.pas 67 KB

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