LibTiffDelphi.pas 67 KB

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