Repo for the search and displace ingest module that takes odf, docx and pdf and transforms it into .md to be used with search and displace operations
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1510 lines
66 KiB

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