gd.pas 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  1. {
  2. Translation of the libgd headers for FreePascal
  3. Copyright(C) 2009 by Ivo Steinmann
  4. }
  5. {$IFNDEF FPC_DOTTEDUNITS}
  6. unit gd;
  7. {$ENDIF FPC_DOTTEDUNITS}
  8. {$MODE objfpc}
  9. {$MACRO on}
  10. {$H+}
  11. {$MINENUMSIZE 4}
  12. {$DEFINE FPC_TARGET_SUPPORTS_DYNLIBS}
  13. {$IFDEF GO32V2}
  14. {$UNDEF FPC_TARGET_SUPPORTS_DYNLIBS}
  15. {$ENDIF GO32V2}
  16. {$IFDEF WATCOM}
  17. {$UNDEF FPC_TARGET_SUPPORTS_DYNLIBS}
  18. {$ENDIF WATCOM}
  19. {$IFDEF AMIGA}
  20. {$UNDEF FPC_TARGET_SUPPORTS_DYNLIBS}
  21. {$ENDIF AMIGA}
  22. {$IFDEF MORPHOS}
  23. {$UNDEF FPC_TARGET_SUPPORTS_DYNLIBS}
  24. {$ENDIF MORPHOS}
  25. {$IFDEF AROS}
  26. {$UNDEF FPC_TARGET_SUPPORTS_DYNLIBS}
  27. {$ENDIF AROS}
  28. {$IFDEF GBA}
  29. {$UNDEF FPC_TARGET_SUPPORTS_DYNLIBS}
  30. {$ENDIF GBA}
  31. {$IFDEF NDS}
  32. {$UNDEF FPC_TARGET_SUPPORTS_DYNLIBS}
  33. {$ENDIF NDS}
  34. interface
  35. {$IFDEF FPC_DOTTEDUNITS}
  36. uses
  37. System.Classes,
  38. {$IFDEF FPC_TARGET_SUPPORTS_DYNLIBS}
  39. System.DynLibs,
  40. {$ENDIF FPC_TARGET_SUPPORTS_DYNLIBS}
  41. System.CTypes;
  42. {$ELSE FPC_DOTTEDUNITS}
  43. uses
  44. Classes,
  45. {$IFDEF FPC_TARGET_SUPPORTS_DYNLIBS}
  46. dynlibs,
  47. {$ENDIF FPC_TARGET_SUPPORTS_DYNLIBS}
  48. ctypes;
  49. {$ENDIF FPC_DOTTEDUNITS}
  50. (* cdecl as default unless defined differently below *)
  51. {$DEFINE EXTDECL := cdecl}
  52. {$IFDEF UNIX}
  53. {$DEFINE EXTDECL := cdecl}
  54. const
  55. gdlib = 'libgd.'+sharedsuffix;
  56. clib = 'libc.'+sharedsuffix;
  57. {$ENDIF}
  58. {$IFDEF NETWARE}
  59. {$DEFINE EXTDECL := cdecl}
  60. const
  61. gdlib = 'libgd.nlm';
  62. clib = 'clib.nlm';
  63. {$ENDIF}
  64. {$IFDEF NETWLIBC}
  65. {$DEFINE EXTDECL := cdecl}
  66. const
  67. gdlib = 'libgd.nlm';
  68. clib = 'libc.nlm';
  69. {$ENDIF}
  70. {$IFDEF WINDOWS}
  71. {$DEFINE EXTDECL := stdcall}
  72. const
  73. gdlib = 'bgd.dll';
  74. clib = 'msvcrt.dll';
  75. {$ENDIF}
  76. {$IFDEF GO32V2}
  77. {$DEFINE EXTDECL := cdecl}
  78. {$DEFINE gdlib := }
  79. {$DEFINE clib := }
  80. {$linklib gd}
  81. {$linklib c}
  82. {$UNDEF LOAD_DYNAMICALLY}
  83. {$ENDIF GO32V2}
  84. {$IFDEF WATCOM}
  85. {$DEFINE EXTDECL := cdecl}
  86. {$DEFINE gdlib := }
  87. {$DEFINE clib := }
  88. {$linklib gd}
  89. {$linklib c}
  90. {$UNDEF LOAD_DYNAMICALLY}
  91. {$ENDIF WATCOM}
  92. {$IFDEF OS2}
  93. (* Force static linking under OS/2 for now to avoid *)
  94. (* dependency on dll for a one particular libc version. *)
  95. {$UNDEF LOAD_DYNAMICALLY}
  96. {$DEFINE gdlib := }
  97. {$DEFINE clib := }
  98. {$ENDIF OS2}
  99. {$IFDEF AMIGA}
  100. {$UNDEF LOAD_DYNAMICALLY}
  101. {$DEFINE gdlib := }
  102. {$DEFINE clib := }
  103. {$ENDIF AMIGA}
  104. {$IFDEF MORPHOS}
  105. {$UNDEF LOAD_DYNAMICALLY}
  106. {$DEFINE gdlib := }
  107. {$DEFINE clib := }
  108. {$ENDIF MORPHOS}
  109. {$IFDEF AROS}
  110. {$UNDEF LOAD_DYNAMICALLY}
  111. {$DEFINE gdlib := }
  112. {$DEFINE clib := }
  113. {$ENDIF AROS}
  114. {$IFDEF GBA}
  115. {$UNDEF LOAD_DYNAMICALLY}
  116. {$DEFINE gdlib := }
  117. {$DEFINE clib := }
  118. {$ENDIF GBA}
  119. {$IFDEF NDS}
  120. {$UNDEF LOAD_DYNAMICALLY}
  121. {$DEFINE gdlib := }
  122. {$DEFINE clib := }
  123. {$ENDIF NDS}
  124. {$IFNDEF LOAD_DYNAMICALLY}
  125. {$IFDEF darwin}
  126. {$linklib c}
  127. {$linklib gd}
  128. {$ENDIF}
  129. {$ENDIF}
  130. type
  131. ppcint = ^pcint;
  132. PFILE = pointer;
  133. const
  134. GD_MAJOR_VERSION = 2;
  135. GD_MINOR_VERSION = 0;
  136. GD_RELEASE_VERSION = 35;
  137. GD_EXTRA_VERSION = '';
  138. GD_VERSION_STRING = '2.0.35';
  139. (* gd.h: declarations file for the graphic-draw module.
  140. * Permission to use, copy, modify, and distribute this software and its
  141. * documentation for any purpose and without fee is hereby granted, provided
  142. * that the above copyright notice appear in all copies and that both that
  143. * copyright notice and this permission notice appear in supporting
  144. * documentation. This software is provided "AS IS." Thomas Boutell and
  145. * Boutell.Com, Inc. disclaim all warranties, either express or implied,
  146. * including but not limited to implied warranties of merchantability and
  147. * fitness for a particular purpose, with respect to this code and accompanying
  148. * documentation. *)
  149. (* stdio is needed for file I/O. *)
  150. //#include <stdio.h>
  151. //#include "gd_io.h"
  152. type
  153. gdIOCtxPtr = ^gdIOCtx;
  154. gdIOCtx = record
  155. getC : function(ctx: gdIOCtxPtr): cint; EXTDECL;
  156. getBuf : function(ctx: gdIOCtxPtr; buf: pointer; len: cint): cint; EXTDECL;
  157. putC : procedure(ctx: gdIOCtxPtr; len: cint); EXTDECL;
  158. putBuf : procedure(ctx: gdIOCtxPtr; buf: pointer; len: cint); EXTDECL;
  159. (* seek must return 1 on SUCCESS, 0 on FAILURE. Unlike fseek! *)
  160. seek : function(ctx: gdIOCtxPtr; pos: cint): cint; EXTDECL;
  161. tell : function(ctx: gdIOCtxPtr): clong; EXTDECL;
  162. gd_free : procedure(ctx: gdIOCtxPtr); EXTDECL;
  163. end;
  164. function fopen(filename, rights: PAnsiChar): PFile; EXTDECL; external clib;
  165. procedure fclose(f: PFile); EXTDECL; external clib;
  166. (* The maximum number of palette entries in palette-based images.
  167. In the wonderful new world of gd 2.0, you can of course have
  168. many more colors when using truecolor mode. *)
  169. const
  170. gdMaxColors = 256;
  171. (* Image type. See functions below; you will not need to change
  172. the elements directly. Use the provided macros to
  173. access sx, sy, the color table, and colorsTotal for
  174. read-only purposes. *)
  175. (* If 'truecolor' is set true, the image is truecolor;
  176. pixels are represented by integers, which
  177. must be 32 bits wide or more.
  178. True colors are repsented as follows:
  179. ARGB
  180. Where 'A'(alpha channel) occupies only the
  181. LOWER 7 BITS of the MSB. This very small
  182. loss of alpha channel resolution allows gd 2.x
  183. to keep backwards compatibility by allowing
  184. signed integers to be used to represent colors,
  185. and negative numbers to represent special cases,
  186. just as in gd 1.x. *)
  187. const
  188. gdAlphaMax = 127;
  189. gdAlphaOpaque = 0;
  190. gdAlphaTransparent = 127;
  191. gdRedMax = 255;
  192. gdGreenMax = 255;
  193. gdBlueMax = 255;
  194. function gdTrueColorGetAlpha(c: cint): cint; inline;
  195. function gdTrueColorGetRed(c: cint): cint; inline;
  196. function gdTrueColorGetGreen(c: cint): cint; inline;
  197. function gdTrueColorGetBlue(c: cint): cint; inline;
  198. (* This function accepts truecolor pixel values only. The
  199. source color is composited with the destination color
  200. based on the alpha channel value of the source color.
  201. The resulting color is opaque. *)
  202. function gdAlphaBlend(dest: cint; src: cint): cint; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdAlphaBlend@8'{$ENDIF};
  203. type
  204. gdImagePtr = ^gdImage;
  205. gdImage = record
  206. (* Palette-based image pixels *)
  207. pixels: ppbyte;
  208. sx: cint;
  209. sy: cint;
  210. (* These are valid in palette images only. See also
  211. 'alpha', which appears later in the structure to
  212. preserve binary backwards compatibility *)
  213. colorsTotal: cint;
  214. red: array[0..gdMaxColors-1] of cint;
  215. green: array[0..gdMaxColors-1] of cint;
  216. blue: array[0..gdMaxColors-1] of cint;
  217. open: array[0..gdMaxColors-1] of cint;
  218. (* For backwards compatibility, this is set to the
  219. first palette entry with 100% transparency,
  220. and is also set and reset by the
  221. gdImageColorTransparent function. Newer
  222. applications can allocate palette entries
  223. with any desired level of transparency; however,
  224. bear in mind that many viewers, notably
  225. many web browsers, fail to implement
  226. full alpha channel for PNG and provide
  227. support for full opacity or transparency only. *)
  228. transparent: cint;
  229. polyInts: pcint;
  230. polyAllocated: cint;
  231. brush: gdImagePtr;
  232. tile: gdImagePtr;
  233. brushColorMap: array[0..gdMaxColors-1] of cint;
  234. tileColorMap: array[0..gdMaxColors-1] of cint;
  235. styleLength: cint;
  236. stylePos: cint;
  237. style: pcint;
  238. interlace: cint;
  239. (* New in 2.0: thickness of line. Initialized to 1. *)
  240. thick: cint;
  241. (* New in 2.0: alpha channel for palettes. Note that only
  242. Macintosh Internet Explorer and(possibly) Netscape 6
  243. really support multiple levels of transparency in
  244. palettes, to my knowledge, as of 2/15/01. Most
  245. common browsers will display 100% opaque and
  246. 100% transparent correctly, and do something
  247. unpredictable and/or undesirable for levels
  248. in between. TBB *)
  249. alpha: array[0..gdMaxColors-1] of cint;
  250. (* Truecolor flag and pixels. New 2.0 fields appear here at the
  251. end to minimize breakage of existing object code. *)
  252. trueColor: cint;
  253. tpixels: ppcint;
  254. (* Should alpha channel be copied, or applied, each time a
  255. pixel is drawn? This applies to truecolor images only.
  256. No attempt is made to alpha-blend in palette images,
  257. even if semitransparent palette entries exist.
  258. To do that, build your image as a truecolor image,
  259. then quantize down to 8 bits. *)
  260. alphaBlendingFlag: cint;
  261. (* Should the alpha channel of the image be saved? This affects
  262. PNG at the moment; other future formats may also
  263. have that capability. JPEG doesn't. *)
  264. saveAlphaFlag: cint;
  265. (* There should NEVER BE ACCESSOR MACROS FOR ITEMS BELOW HERE, so this
  266. part of the structure can be safely changed in new releases. *)
  267. (* 2.0.12: anti-aliased globals. 2.0.26: just a few vestiges after
  268. switching to the fast, memory-cheap implementation from PHP-gd. *)
  269. AA: cint;
  270. AA_color: cint;
  271. AA_dont_blend: cint;
  272. (* 2.0.12: simple clipping rectangle. These values
  273. must be checked for safety when set; please use
  274. gdImageSetClip *)
  275. cx1: cint;
  276. cy1: cint;
  277. cx2: cint;
  278. cy2: cint;
  279. end;
  280. gdFontPtr = ^gdFont;
  281. gdFont = record
  282. (* # of characters in font *)
  283. nchars: cint;
  284. (* First character is numbered...(usually 32 = space) *)
  285. offset: cint;
  286. (* Character width and height *)
  287. w: cint;
  288. h: cint;
  289. (* Font data; array of characters, one row after another.
  290. Easily included in code, also easily loaded from
  291. data files. *)
  292. data: PAnsiChar;
  293. end;
  294. (* For backwards compatibility only. Use gdImageSetStyle()
  295. for MUCH more flexible line drawing. Also see
  296. gdImageSetBrush(). *)
  297. const
  298. gdDashSize = 4;
  299. (* Special colors. *)
  300. gdStyled =(-2);
  301. gdBrushed =(-3);
  302. gdStyledBrushed =(-4);
  303. gdTiled =(-5);
  304. (* NOT the same as the transparent color index.
  305. This is used in line styles only. *)
  306. gdTransparent =(-6);
  307. gdAntiAliased =(-7);
  308. (* Functions to manipulate images. *)
  309. (* Creates a palette-based image(up to 256 colors). *)
  310. function gdImageCreate(sx: cint; sy: cint): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreate@8'{$ENDIF};
  311. (* An alternate name for the above(2.0). *)
  312. function gdImageCreatePalette(sx: cint; sy: cint): gdImagePtr;
  313. (* Creates a truecolor image(millions of colors). *)
  314. function gdImageCreateTrueColor(sx: cint; sy: cint): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateTrueColor@8'{$ENDIF};
  315. (* Creates an image from various file types. These functions
  316. return a palette or truecolor image based on the
  317. nature of the file being loaded. Truecolor PNG
  318. stays truecolor; palette PNG stays palette-based;
  319. JPEG is always truecolor. *)
  320. function gdImageCreateFromPng(fd: PFILE): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromPng@4'{$ENDIF};
  321. function gdImageCreateFromPngCtx(_in: gdIOCtxPtr): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromPngCtx@4'{$ENDIF};
  322. function gdImageCreateFromPngPtr(size: cint; data: pointer): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromPngPtr@8'{$ENDIF};
  323. (* These read the first frame only *)
  324. function gdImageCreateFromGif(fd: PFILE): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromGif@4'{$ENDIF};
  325. function gdImageCreateFromGifCtx(_in: gdIOCtxPtr): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromGifCtx@4'{$ENDIF};
  326. function gdImageCreateFromGifPtr(size: cint; data: pointer): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromGifPtr@8'{$ENDIF};
  327. function gdImageCreateFromWBMP(fd: PFILE): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromWBMP@4'{$ENDIF};
  328. function gdImageCreateFromWBMPCtx(_in: gdIOCtxPtr): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromWBMPCtx@4'{$ENDIF};
  329. function gdImageCreateFromWBMPPtr(size: cint; data: pointer): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromWBMPPtr@8'{$ENDIF};
  330. function gdImageCreateFromJpeg(fd: PFILE): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromJpeg@4'{$ENDIF};
  331. function gdImageCreateFromJpegCtx(_in: gdIOCtxPtr): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromJpegCtx@4'{$ENDIF};
  332. function gdImageCreateFromJpegPtr(size: cint; data: pointer): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromJpegPtr@8'{$ENDIF};
  333. (* A custom data source. *)
  334. (* The source function must return -1 on error, otherwise the number
  335. of bytes fetched. 0 is EOF, not an error! *)
  336. (* context will be passed to your source function. *)
  337. type
  338. gdSourcePtr = ^gdSource;
  339. gdSource = record
  340. source : function(context: pointer; buffer: PAnsiChar; len: cint): cint; EXTDECL;
  341. context : pointer;
  342. end;
  343. (* Deprecated in favor of gdImageCreateFromPngCtx *)
  344. function gdImageCreateFromPngSource(_in: gdSourcePtr): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromPngSource@4'{$ENDIF};
  345. function gdImageCreateFromGd(_in: PFILE): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromGd@4'{$ENDIF};
  346. function gdImageCreateFromGdCtx(_in: gdIOCtxPtr): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromGdCtx@4'{$ENDIF};
  347. function gdImageCreateFromGdPtr(size: cint; data: pointer): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromGdPtr@8'{$ENDIF};
  348. function gdImageCreateFromGd2(_in: PFILE): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromGd2@4'{$ENDIF};
  349. function gdImageCreateFromGd2Ctx(_in: gdIOCtxPtr): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromGd2Ctx@4'{$ENDIF};
  350. function gdImageCreateFromGd2Ptr(size: cint; data: pointer): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromGd2Ptr@8'{$ENDIF};
  351. function gdImageCreateFromGd2Part(_in: PFILE; srcx: cint; srcy: cint; w: cint; h: cint): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromGd2Part@20'{$ENDIF};
  352. function gdImageCreateFromGd2PartCtx(_in: gdIOCtxPtr; srcx: cint; srcy: cint; w: cint; h: cint): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromGd2PartCtx@20'{$ENDIF};
  353. function gdImageCreateFromGd2PartPtr(size: cint; data: pointer; srcx: cint; srcy: cint; w: cint; h: cint): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromGd2PartCtx@24'{$ENDIF};
  354. (* 2.0.10: prototype was missing *)
  355. function gdImageCreateFromXbm(_in: PFILE): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromXbm@4'{$ENDIF};
  356. (* NOTE: filename, not FILE *)
  357. function gdImageCreateFromXpm(filename: PAnsiChar): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreateFromXpm@4'{$ENDIF};
  358. procedure gdImageDestroy(im: gdImagePtr); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageDestroy@4'{$ENDIF};
  359. (* Replaces or blends with the background depending on the
  360. most recent call to gdImageAlphaBlending and the
  361. alpha channel value of 'color'; default is to overwrite.
  362. Tiling and line styling are also implemented
  363. here. All other gd drawing functions pass through this call,
  364. allowing for many useful effects. *)
  365. procedure gdImageSetPixel(im: gdImagePtr; x: cint; y: cint; color: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageSetPixel@16'{$ENDIF};
  366. (* FreeType 2 text output with hook to extra flags *)
  367. function gdImageGetPixel(im: gdImagePtr; x: cint; y: cint): cint; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageGetPixel@12'{$ENDIF};
  368. function gdImageGetTrueColorPixel(im: gdImagePtr; x: cint; y: cint): cint; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageGetTrueColorPixel@12'{$ENDIF};
  369. procedure gdImageAABlend(im: gdImagePtr); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageAABlend@4'{$ENDIF};
  370. procedure gdImageLine(im: gdImagePtr; x1: cint; y1: cint; x2: cint; y2: cint; color: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageLine@24'{$ENDIF};
  371. (* For backwards compatibility only. Use gdImageSetStyle()
  372. for much more flexible line drawing. *)
  373. procedure gdImageDashedLine(im: gdImagePtr; x1: cint; y1: cint; x2: cint; y2: cint; color: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageDashedLine@24'{$ENDIF};
  374. (* Corners specified(not width and height). Upper left first, lower right
  375. second. *)
  376. procedure gdImageRectangle(im: gdImagePtr; x1: cint; y1: cint; x2: cint; y2: cint; color: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageRectangle@24'{$ENDIF};
  377. (* Solid bar. Upper left corner first, lower right corner second. *)
  378. procedure gdImageFilledRectangle(im: gdImagePtr; x1: cint; y1: cint; x2: cint; y2: cint; color: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageFilledRectangle@24'{$ENDIF};
  379. procedure gdImageSetClip(im: gdImagePtr; x1: cint; y1: cint; x2: cint; y2: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageSetClip@20'{$ENDIF};
  380. procedure gdImageGetClip(im: gdImagePtr; var x1: cint; var y1: cint; var x2: cint; var y2: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageGetClip@20'{$ENDIF};
  381. function gdImageBoundsSafe(im: gdImagePtr; x: cint; y: cint): cint; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageBoundsSafe@12'{$ENDIF};
  382. procedure gdImageChar(im: gdImagePtr; f: gdFontPtr; x: cint; y: cint; c: cint; color: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageChar@24'{$ENDIF};
  383. procedure gdImageCharUp(im: gdImagePtr; f: gdFontPtr; x: cint; y: cint; c: cint; color: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCharUp@24'{$ENDIF};
  384. procedure gdImageString(im: gdImagePtr; f: gdFontPtr; x: cint; y: cint; s: PAnsiChar; color: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageString@24'{$ENDIF};
  385. procedure gdImageStringUp(im: gdImagePtr; f: gdFontPtr; x: cint; y: cint; s: PAnsiChar; color: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageStringUp@24'{$ENDIF};
  386. procedure gdImageString16(im: gdImagePtr; f: gdFontPtr; x: cint; y: cint; s: pwidechar; color: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageString16@24'{$ENDIF};
  387. procedure gdImageStringUp16(im: gdImagePtr; f: gdFontPtr; x: cint; y: cint; s: pwidechar; color: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageStringUp16@24'{$ENDIF};
  388. (* 2.0.16: for thread-safe use of gdImageStringFT and friends,
  389. call this before allowing any thread to call gdImageStringFT.
  390. Otherwise it is invoked by the first thread to invoke
  391. gdImageStringFT, with a very small but real risk of a race condition.
  392. Return 0 on success, nonzero on failure to initialize freetype. *)
  393. function gdFontCacheSetup(): cint; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdFontCacheSetup@0'{$ENDIF};
  394. (* Optional: clean up after application is done using fonts in
  395. BGD_DECLARE( ) gdImageStringFT(). *)
  396. procedure gdFontCacheShutdown(); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdFontCacheShutdown@0'{$ENDIF};
  397. (* 2.0.20: for backwards compatibility. A few applications did start calling
  398. this function when it first appeared although it was never documented.
  399. Simply invokes gdFontCacheShutdown. *)
  400. procedure gdFreeFontCache(); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdFreeFontCache@0'{$ENDIF};
  401. (* Calls gdImageStringFT. Provided for backwards compatibility only. *)
  402. function gdImageStringTTF(im: gdImagePtr; brect: pcint; fg: cint; fontlist: PAnsiChar; ptsize: double; angle: double; x: cint; y: cint; str: PAnsiChar): PAnsiChar; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageStringTTF@36'{$ENDIF};
  403. (* FreeType 2 text output *)
  404. function gdImageStringFT(im: gdImagePtr; brect: pcint; fg: cint; fontlist: PAnsiChar; ptsize: double; angle: double; x: cint; y: cint; str: PAnsiChar): PAnsiChar; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageStringFT@36'{$ENDIF};
  405. (* 2.0.5: provides an extensible way to pass additional parameters.
  406. Thanks to Wez Furlong, sorry for the delay. *)
  407. type
  408. gdFTStringExtraPtr = ^gdFTStringExtra;
  409. gdFTStringExtra = record
  410. flags: cint; (* Logical OR of gdFTEX_ values *)
  411. linespacing: double; (* fine tune line spacing for '\n' *)
  412. charmap: cint;
  413. (* TBB: 2.0.12: may be gdFTEX_Unicode,
  414. gdFTEX_Shift_JIS, gdFTEX_Big5,
  415. or gdFTEX_Adobe_Custom;
  416. when not specified, maps are searched
  417. for in the above order. *)
  418. hdpi: cint; (* if(flags & gdFTEX_RESOLUTION) *)
  419. vdpi: cint; (* if(flags & gdFTEX_RESOLUTION) *)
  420. xshow: PAnsiChar;
  421. (* if(flags & gdFTEX_XSHOW)
  422. then, on return, xshow is a malloc'ed
  423. string contining xshow position data for
  424. the last string.
  425. NB. The caller is responsible for gdFree'ing
  426. the xshow string.
  427. *)
  428. fontpath: PAnsiChar; (* if(flags & gdFTEX_RETURNFONTPATHNAME)
  429. then, on return, fontpath is a malloc'ed
  430. string containing the actual font file path name
  431. used, which can be interesting when fontconfig
  432. is in use.
  433. The caller is responsible for gdFree'ing the
  434. fontpath string.
  435. *)
  436. end;
  437. const
  438. gdFTEX_LINESPACE = 1;
  439. gdFTEX_CHARMAP = 2;
  440. gdFTEX_RESOLUTION = 4;
  441. gdFTEX_DISABLE_KERNING = 8;
  442. gdFTEX_XSHOW = 16;
  443. (* The default unless gdFTUseFontConfig(1); has been called:
  444. fontlist is a full or partial font file pathname or list thereof
  445. (i.e. just like before 2.0.29) *)
  446. gdFTEX_FONTPATHNAME = 32;
  447. (* Necessary to use fontconfig patterns instead of font pathnames
  448. as the fontlist argument, unless gdFTUseFontConfig(1); has
  449. been called. New in 2.0.29 *)
  450. gdFTEX_FONTCONFIG = 64;
  451. (* Sometimes interesting when fontconfig is used: the fontpath
  452. element of the structure above will contain a gdMalloc'd string
  453. copy of the actual font file pathname used, if this flag is set
  454. when the call is made *)
  455. gdFTEX_RETURNFONTPATHNAME = 128;
  456. (* If flag is nonzero, the fontlist parameter to gdImageStringFT
  457. and gdImageStringFTEx shall be assumed to be a fontconfig font pattern
  458. if fontconfig was compiled into gd. This function returns zero
  459. if fontconfig is not available, nonzero otherwise. *)
  460. function gdFTUseFontConfig(flag: cint): cint; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdFTUseFontConfig@4'{$ENDIF};
  461. (* These are NOT flags; set one in 'charmap' if you set the
  462. gdFTEX_CHARMAP bit in 'flags'. *)
  463. const
  464. gdFTEX_Unicode = 0;
  465. gdFTEX_Shift_JIS = 1;
  466. gdFTEX_Big5 = 2;
  467. gdFTEX_Adobe_Custom = 3;
  468. function gdImageStringFTEx(im: gdImagePtr; brect: pcint; fg: cint; fontlist: PAnsiChar; ptsize: double; angle: double; x: cint; y: cint; str: PAnsiChar; strex: gdFTStringExtraPtr): PAnsiChar; EXTDECL;
  469. external gdlib {$IFDEF WIN32}name '_gdImageStringFTEx@40'{$ENDIF};
  470. (* Point type for use in polygon drawing. *)
  471. type
  472. gdPointPtr = ^gdPoint;
  473. gdPoint = record
  474. x, y: cint;
  475. end;
  476. procedure gdImagePolygon(im: gdImagePtr; p: gdPointPtr; n: cint; c: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImagePolygon@16'{$ENDIF};
  477. procedure gdImageOpenPolygon(im: gdImagePtr; p: gdPointPtr; n: cint; c: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageOpenPolygon@16'{$ENDIF};
  478. procedure gdImageFilledPolygon(im: gdImagePtr; p: gdPointPtr; n: cint; c: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageFilledPolygon@16'{$ENDIF};
  479. (* These functions still work with truecolor images,
  480. for which they never return error. *)
  481. function gdImageColorAllocate(im: gdImagePtr; r: cint; g: cint; b: cint): cint; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageColorAllocate@16'{$ENDIF};
  482. (* gd 2.0: palette entries with non-opaque transparency are permitted. *)
  483. function gdImageColorAllocateAlpha(im: gdImagePtr; r: cint; g: cint; b: cint; a: cint): cint; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageColorAllocateAlpha@20'{$ENDIF};
  484. (* Assumes opaque is the preferred alpha channel value *)
  485. function gdImageColorClosest(im: gdImagePtr; r: cint; g: cint; b: cint): cint; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageColorClosest@16'{$ENDIF};
  486. (* Closest match taking all four parameters into account.
  487. A slightly different color with the same transparency
  488. beats the exact same color with radically different
  489. transparency *)
  490. function gdImageColorClosestAlpha(im: gdImagePtr; r: cint; g: cint; b: cint; a: cint): cint; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageColorClosestAlpha@20'{$ENDIF};
  491. (* An alternate method *)
  492. function gdImageColorClosestHWB(im: gdImagePtr; r: cint; g: cint; b: cint): cint; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageColorClosestHWB@16'{$ENDIF};
  493. (* Returns exact, 100% opaque matches only *)
  494. function gdImageColorExact(im: gdImagePtr; r: cint; g: cint; b: cint): cint; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageColorExact@16'{$ENDIF};
  495. (* Returns an exact match only, including alpha *)
  496. function gdImageColorExactAlpha(im: gdImagePtr; r: cint; g: cint; b: cint; a: cint): cint; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageColorExactAlpha@20'{$ENDIF};
  497. (* Opaque only *)
  498. function gdImageColorResolve(im: gdImagePtr; r: cint; g: cint; b: cint): cint; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageColorResolve@16'{$ENDIF};
  499. (* Based on gdImageColorExactAlpha and gdImageColorClosestAlpha *)
  500. function gdImageColorResolveAlpha(im: gdImagePtr; r: cint; g: cint; b: cint; a: cint): cint; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageColorResolveAlpha@20'{$ENDIF};
  501. (* A simpler way to obtain an opaque truecolor value for drawing on a
  502. truecolor image. Not for use with palette images! *)
  503. function gdTrueColor(r: cint; g: cint; b: cint): cint;
  504. (* Returns a truecolor value with an alpha channel component.
  505. gdAlphaMax(127, **NOT 255** ) is transparent, 0 is completely
  506. opaque. *)
  507. function gdTrueColorAlpha(r: cint; g: cint; b: cint; a: cint): cint;
  508. procedure gdImageColorDeallocate(im: gdImagePtr; color: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageColorDeallocate@8'{$ENDIF};
  509. (* Converts a truecolor image to a palette-based image,
  510. using a high-quality two-pass quantization routine
  511. which attempts to preserve alpha channel information
  512. as well as R/G/B color information when creating
  513. a palette. If ditherFlag is set, the image will be
  514. dithered to approximate colors better, at the expense
  515. of some obvious "speckling." colorsWanted can be
  516. anything up to 256. If the original source image
  517. includes photographic information or anything that
  518. came out of a JPEG, 256 is strongly recommended.
  519. Better yet, don't use these function -- write real
  520. truecolor PNGs and JPEGs. The disk space gain of
  521. conversion to palette is not great(for small images
  522. it can be negative) and the quality loss is ugly.
  523. DIFFERENCES: gdImageCreatePaletteFromTrueColor creates and
  524. returns a new image. gdImageTrueColorToPalette modifies
  525. an existing image, and the truecolor pixels are discarded. *)
  526. function gdImageCreatePaletteFromTrueColor(im: gdImagePtr; ditherFlag: cint; colorsWanted: cint): gdImagePtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCreatePaletteFromTrueColor@16'{$ENDIF};
  527. procedure gdImageTrueColorToPalette(im: gdImagePtr; ditherFlag: cint; colorsWanted: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageTrueColorToPalette@16'{$ENDIF};
  528. (* Specifies a color index(if a palette image) or an
  529. RGB color(if a truecolor image) which should be
  530. considered 100% transparent. FOR TRUECOLOR IMAGES,
  531. THIS IS IGNORED IF AN ALPHA CHANNEL IS BEING
  532. SAVED. Use gdImageSaveAlpha(im, 0); to
  533. turn off the saving of a full alpha channel in
  534. a truecolor image. Note that gdImageColorTransparent
  535. is usually compatible with older browsers that
  536. do not understand full alpha channels well. TBB *)
  537. procedure gdImageColorTransparent(im: gdImagePtr; color: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageColorTransparent@8'{$ENDIF};
  538. procedure gdImagePaletteCopy(dst: gdImagePtr; src: gdImagePtr); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImagePaletteCopy@8'{$ENDIF};
  539. procedure gdImageGif(im: gdImagePtr; _out: PFILE); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageGif@8'{$ENDIF};
  540. procedure gdImagePng(im: gdImagePtr; _out: PFILE); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImagePng@8'{$ENDIF};
  541. procedure gdImagePngCtx(im: gdImagePtr; _out: gdIOCtxPtr); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImagePngCtx@8'{$ENDIF};
  542. procedure gdImageGifCtx(im: gdImagePtr; _out: gdIOCtxPtr); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageGifCtx@8'{$ENDIF};
  543. (* 2.0.12: Compression level: 0-9 or -1, where 0 is NO COMPRESSION at all,
  544. 1 is FASTEST but produces larger files, 9 provides the best
  545. compression(smallest files) but takes a long time to compress, and
  546. -1 selects the default compiled into the zlib library. *)
  547. procedure gdImagePngEx(im: gdImagePtr; _out: PFILE; level: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImagePngEx@12'{$ENDIF};
  548. procedure gdImagePngCtxEx(im: gdImagePtr; _out: gdIOCtxPtr; level: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImagePngCtxEx@12'{$ENDIF};
  549. procedure gdImageWBMP(image: gdImagePtr; fg: cint; _out: PFILE); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageWBMP@12'{$ENDIF};
  550. procedure gdImageWBMPCtx(image: gdImagePtr; fg: cint; _out: gdIOCtxPtr); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageWBMPCtx@12'{$ENDIF};
  551. (* Guaranteed to correctly free memory returned
  552. by the gdImage*Ptr functions *)
  553. procedure gdFree(m: pointer); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdFree@4'{$ENDIF};
  554. (* Best to free this memory with gdFree(), not free() *)
  555. function gdImageWBMPPtr(im: gdImagePtr; size: pcint; fg: cint): pointer; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageWBMPPtr@12'{$ENDIF};
  556. (* 100 is highest quality(there is always a little loss with JPEG).
  557. 0 is lowest. 10 is about the lowest useful setting. *)
  558. procedure gdImageJpeg(im: gdImagePtr; _out: PFILE; quality: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageJpeg@12'{$ENDIF};
  559. procedure gdImageJpegCtx(im: gdImagePtr; _out: gdIOCtxPtr; quality: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageJpegCtx@12'{$ENDIF};
  560. (* Best to free this memory with gdFree(), not free() *)
  561. function gdImageJpegPtr(im: gdImagePtr; size: pcint; quality: cint): pointer; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageJpegPtr@12'{$ENDIF};
  562. (* Legal values for Disposal. gdDisposalNone is always used by
  563. the built-in optimizer if previm is passed. *)
  564. (*
  565. enum {
  566. gdDisposalUnknown,
  567. gdDisposalNone,
  568. gdDisposalRestoreBackground,
  569. gdDisposalRestorePrevious
  570. };
  571. procedure gdImageGifAnimBegin(im: gdImagePtr; _outFile: PFILE; int GlobalCM, int Loops); EXTDECL; BGD_DECLARE;
  572. procedure gdImageGifAnimAdd(im: gdImagePtr; _outFile: PFILE; int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, gdImagePtr previm); EXTDECL; BGD_DECLARE;
  573. procedure gdImageGifAnimEnd(_outFile: PFILE); EXTDECL; BGD_DECLARE;
  574. procedure gdImageGifAnimBeginCtx(im: gdImagePtr; gdIOCtx *out, int GlobalCM, int Loops); EXTDECL; BGD_DECLARE;
  575. procedure gdImageGifAnimAddCtx(im: gdImagePtr; gdIOCtx *out, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, gdImagePtr previm); EXTDECL; BGD_DECLARE;
  576. procedure gdImageGifAnimEndCtx(gdIOCtx *out); EXTDECL; BGD_DECLARE;
  577. function gdImageGifAnimBeginPtr(im: gdImagePtr; int *size, int GlobalCM, int Loops): pointer; EXTDECL; BGD_DECLARE;
  578. function gdImageGifAnimAddPtr(im: gdImagePtr; int *size, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, gdImagePtr previm): pointer; EXTDECL; BGD_DECLARE;
  579. function gdImageGifAnimEndPtr(int *size): pointer; EXTDECL; BGD_DECLARE;
  580. *)
  581. {$warning TODO}
  582. (* A custom data sink. For backwards compatibility. Use
  583. gdIOCtx instead. *)
  584. (* The sink function must return -1 on error, otherwise the number
  585. of bytes written, which must be equal to len. *)
  586. (* context will be passed to your sink function. *)
  587. type
  588. gdSinkPtr = ^gdSink;
  589. gdSink = record
  590. sink : function(context: pointer; buffer: PAnsiChar; len: cint): cint; EXTDECL;
  591. context : pointer;
  592. end;
  593. procedure gdImagePngToSink(im: gdImagePtr; _out: gdSinkPtr); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImagePngToSink@8'{$ENDIF};
  594. procedure gdImageGd(im: gdImagePtr; _out: PFILE); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageGd@8'{$ENDIF};
  595. procedure gdImageGd2(im: gdImagePtr; _out: PFILE; cs: cint; fmt: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageGd2@16'{$ENDIF};
  596. (* Best to free this memory with gdFree(), not free() *)
  597. function gdImageGifPtr(im: gdImagePtr; var size: cint): pointer; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageGifPtr@8'{$ENDIF};
  598. (* Best to free this memory with gdFree(), not free() *)
  599. function gdImagePngPtr(im: gdImagePtr; var size: cint): pointer; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImagePngPtr@8'{$ENDIF};
  600. function gdImagePngPtrEx(im: gdImagePtr; var size: cint; level: cint): pointer; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImagePngPtrEx@12'{$ENDIF};
  601. (* Best to free this memory with gdFree(), not free() *)
  602. function gdImageGdPtr(im: gdImagePtr; var size: cint): pointer; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageGdPtr@8'{$ENDIF};
  603. (* Best to free this memory with gdFree(), not free() *)
  604. function gdImageGd2Ptr(im: gdImagePtr; cs: cint; fmt: cint; var size: cint): pointer; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageGd2Ptr@16'{$ENDIF};
  605. (* Style is a bitwise OR( | operator ) of these.
  606. gdArc and gdChord are mutually exclusive;
  607. gdChord just connects the starting and ending
  608. angles with a straight line, while gdArc produces
  609. a rounded edge. gdPie is a synonym for gdArc.
  610. gdNoFill indicates that the arc or chord should be
  611. outlined, not filled. gdEdged, used together with
  612. gdNoFill, indicates that the beginning and ending
  613. angles should be connected to the center; this is
  614. a good way to outline(rather than fill) a
  615. 'pie slice'. *)
  616. const
  617. gdArc = 0;
  618. gdPie = gdArc;
  619. gdChord = 1;
  620. gdNoFill = 2;
  621. gdEdged = 4;
  622. procedure gdImageFilledArc(im: gdImagePtr; cx: cint; cy: cint; w: cint; h: cint; s: cint; e: cint; color: cint; style: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageFilledArc@36'{$ENDIF};
  623. procedure gdImageArc(im: gdImagePtr; cx: cint; cy: cint; w: cint; h: cint; s: cint; e: cint; color: cint; style: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageArc@36'{$ENDIF};
  624. procedure gdImageEllipse(im: gdImagePtr; cx: cint; cy: cint; w: cint; h: cint; color: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageEllipse@24'{$ENDIF};
  625. procedure gdImageFilledEllipse(im: gdImagePtr; cx: cint; cy: cint; w: cint; h: cint; color: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageFilledEllipse@24'{$ENDIF};
  626. procedure gdImageFillToBorder(im: gdImagePtr; cx: cint; cy: cint; border: cint; color: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageFillToBorder@20'{$ENDIF};
  627. procedure gdImageFill(im: gdImagePtr; x: cint; y: cint; color: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageFill@16'{$ENDIF};
  628. procedure gdImageCopy(dst: gdImagePtr; src: gdImagePtr; dstX: cint; dstY: cint; srcX: cint; srcY: cint; w: cint; h: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCopy@32'{$ENDIF};
  629. procedure gdImageCopyMerge(dst: gdImagePtr; src: gdImagePtr; dstX: cint; dstY: cint; srcX: cint; srcY: cint; w: cint; h: cint; pct: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCopyMerge@36'{$ENDIF};
  630. procedure gdImageCopyMergeGray(dst: gdImagePtr; src: gdImagePtr; dstX: cint; dstY: cint; srcX: cint; srcY: cint; w: cint; h: cint; pct: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCopyMergeGray@36'{$ENDIF};
  631. (* Stretches or shrinks to fit, as needed. Does NOT attempt
  632. to average the entire set of source pixels that scale down onto the
  633. destination pixel. *)
  634. procedure gdImageCopyResized(dst: gdImagePtr; src: gdImagePtr; dstX: cint; dstY: cint; srcX: cint; srcY: cint; dstW: cint; dstH: cint; srcW: cint; srcH: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCopyResized@40'{$ENDIF};
  635. (* gd 2.0: stretches or shrinks to fit, as needed. When called with a
  636. truecolor destination image, this function averages the
  637. entire set of source pixels that scale down onto the
  638. destination pixel, taking into account what portion of the
  639. destination pixel each source pixel represents. This is a
  640. floating point operation, but this is not a performance issue
  641. on modern hardware, except for some embedded devices. If the
  642. destination is a palette image, gdImageCopyResized is
  643. substituted automatically. *)
  644. procedure gdImageCopyResampled(dst: gdImagePtr; src: gdImagePtr; dstX: cint; dstY: cint; srcX: cint; srcY: cint; dstW: cint; dstH: cint; srcW: cint; srcH: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCopyResampled@40'{$ENDIF};
  645. (* gd 2.0.8: gdImageCopyRotated is added. Source
  646. is a rectangle, with its upper left corner at
  647. srcX and srcY. Destination is the *center* of
  648. the rotated copy. Angle is in degrees, same as
  649. gdImageArc. Floating point destination center
  650. coordinates allow accurate rotation of
  651. objects of odd-numbered width or height. *)
  652. procedure gdImageCopyRotated(dst: gdImagePtr; src: gdImagePtr; dstX: double; dstY: double; srcX: cint; srcY: cint; srcWidth: cint; srcHeight: cint; angle: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCopyRotated@36'{$ENDIF};
  653. procedure gdImageSetBrush(im: gdImagePtr; brush: gdImagePtr); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageSetBrush@8'{$ENDIF};
  654. procedure gdImageSetTile(im: gdImagePtr; tile: gdImagePtr); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageSetTile@8'{$ENDIF};
  655. procedure gdImageSetAntiAliased(im: gdImagePtr; c: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageSetAntiAliased@8'{$ENDIF};
  656. procedure gdImageSetAntiAliasedDontBlend(im: gdImagePtr; c: cint; dont_blend: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageSetAntiAliasedDontBlend@12'{$ENDIF};
  657. procedure gdImageSetStyle(im: gdImagePtr; style: pcint; noOfPixels: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageSetStyle@12'{$ENDIF};
  658. (* Line thickness(defaults to 1). Affects lines, ellipses,
  659. rectangles, polygons and so forth. *)
  660. procedure gdImageSetThickness(im: gdImagePtr; thickness: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageSetThickness@8'{$ENDIF};
  661. (* On or off(1 or 0) for all three of these. *)
  662. procedure gdImageInterlace(im: gdImagePtr; interlaceArg: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageInterlace@8'{$ENDIF};
  663. procedure gdImageAlphaBlending(im: gdImagePtr; alphaBlendingArg: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageAlphaBlending@8'{$ENDIF};
  664. procedure gdImageSaveAlpha(im: gdImagePtr; saveAlphaArg: cint); EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageSaveAlpha@8'{$ENDIF};
  665. (* Macros to access information about images. *)
  666. (* Returns nonzero if the image is a truecolor image,
  667. zero for a palette image. *)
  668. function gdImageTrueColor(im: gdImagePtr): cint; inline;
  669. function gdImageSX(im: gdImagePtr): cint; inline;
  670. function gdImageSY(im: gdImagePtr): cint; inline;
  671. function gdImageColorsTotal(im: gdImagePtr): cint; inline;
  672. function gdImageRed(im: gdImagePtr; c: cint): cint; inline;
  673. function gdImageGreen(im: gdImagePtr; c: cint): cint; inline;
  674. function gdImageBlue(im: gdImagePtr; c: cint): cint; inline;
  675. function gdImageAlpha(im: gdImagePtr; c: cint): cint; inline;
  676. function gdImageGetTransparent(im: gdImagePtr): cint; inline;
  677. function gdImageGetInterlaced(im: gdImagePtr): cint; inline;
  678. (* These macros provide direct access to pixels in
  679. palette-based and truecolor images, respectively.
  680. If you use these macros, you must perform your own
  681. bounds checking. Use of the macro for the correct type
  682. of image is also your responsibility. *)
  683. function gdImagePalettePixel(im: gdImagePtr; x, y: cint): cint; inline;
  684. function gdImageTrueColorPixel(im: gdImagePtr; x, y: cint): cint; inline;
  685. (* I/O Support routines. *)
  686. function gdNewFileCtx(p: PFILE): gdIOCtxPtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdNewFileCtx@4'{$ENDIF};
  687. (* If data is null, size is ignored and an initial data buffer is
  688. allocated automatically. NOTE: this function assumes gd has the right
  689. to free or reallocate "data" at will! Also note that gd will free
  690. "data" when the IO context is freed. If data is not null, it must point
  691. to memory allocated with gdMalloc, or by a call to gdImage[something]Ptr.
  692. If not, see gdNewDynamicCtxEx for an alternative. *)
  693. function gdNewDynamicCtx(size: cint; data: pointer): gdIOCtxPtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdNewDynamicCtx@8'{$ENDIF};
  694. (* 2.0.21: if freeFlag is nonzero, gd will free and/or reallocate "data" as
  695. needed as described above. If freeFlag is zero, gd will never free
  696. or reallocate "data," which means that the context should only be used
  697. for *reading* an image from a memory buffer, or writing an image to a
  698. memory buffer which is already large enough. If the memory buffer is
  699. not large enough and an image write is attempted, the write operation
  700. will fail. Those wishing to write an image to a buffer in memory have
  701. a much simpler alternative in the gdImage[something]Ptr functions. *)
  702. function gdNewDynamicCtxEx(size: cint; data: pointer; freeFlag: cint): gdIOCtxPtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdNewDynamicCtxEx@12'{$ENDIF};
  703. function gdNewSSCtx(_in: gdSourcePtr; _out: gdSinkPtr): gdIOCtxPtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdNewSSCtx@8'{$ENDIF};
  704. function gdDPExtractData(ctx: gdIOCtxPtr; size: pcint): pointer; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdDPExtractData@8'{$ENDIF};
  705. function gdNewStreamCtx(Stream: TStream; free: boolean): gdIOCtxPtr;
  706. // NOTE: don't forget to call ctx^.gd_free(ctx)
  707. const
  708. GD2_CHUNKSIZE = 128;
  709. GD2_CHUNKSIZE_MIN = 64;
  710. GD2_CHUNKSIZE_MAX = 4096;
  711. GD2_VERS = 2;
  712. GD2_ID = 'gd2';
  713. GD2_FMT_RAW = 1;
  714. GD2_FMT_COMPRESSED = 2;
  715. (* Image comparison definitions *)
  716. function gdImageCompare(im1: gdImagePtr; im2: gdImagePtr): cint; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdImageCompare@8'{$ENDIF};
  717. const
  718. GD_CMP_IMAGE = 1; (* Actual image IS different *)
  719. GD_CMP_NUM_COLORS = 2; (* Number of Colours in pallette differ *)
  720. GD_CMP_COLOR = 4; (* Image colours differ *)
  721. GD_CMP_SIZE_X = 8; (* Image width differs *)
  722. GD_CMP_SIZE_Y = 16; (* Image heights differ *)
  723. GD_CMP_TRANSPARENT = 32; (* Transparent colour *)
  724. GD_CMP_BACKGROUND = 64; (* Background colour *)
  725. GD_CMP_INTERLACE = 128; (* Interlaced setting *)
  726. GD_CMP_TRUECOLOR = 256; (* Truecolor vs palette differs *)
  727. (* resolution affects ttf font rendering, particularly hinting *)
  728. GD_RESOLUTION = 96; (* pixels per inch *)
  729. (* newfangled special effects *)
  730. //#include "gdfx.h"
  731. function gdFontGetLarge(): gdFontPtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdFontGetLarge@0'{$ENDIF};
  732. function gdFontGetSmall(): gdFontPtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdFontGetSmall@0'{$ENDIF};
  733. function gdFontGetGiant(): gdFontPtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdFontGetGiant@0'{$ENDIF};
  734. function gdFontGetMediumBold(): gdFontPtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdFontGetMediumBold@0'{$ENDIF};
  735. function gdFontGetTiny(): gdFontPtr; EXTDECL; external gdlib {$IFDEF WIN32}name '_gdFontGetTiny@0'{$ENDIF};
  736. {$ifdef windows}
  737. function gdFontLarge(): gdFontPtr; inline;
  738. function gdFontSmall(): gdFontPtr; inline;
  739. function gdFontGiant(): gdFontPtr; inline;
  740. function gdFontMediumBold(): gdFontPtr; inline;
  741. function gdFontTiny(): gdFontPtr; inline;
  742. {$else}
  743. var
  744. {$ifndef darwin}
  745. gdFontLarge : gdFontPtr; cvar; external gdlib;
  746. gdFontSmall : gdFontPtr; cvar; external gdlib;
  747. gdFontGiant : gdFontPtr; cvar; external gdlib;
  748. gdFontMediumBold : gdFontPtr; cvar; external gdlib;
  749. gdFontTiny : gdFontPtr; cvar; external gdlib;
  750. {$else darwin}
  751. gdFontLarge : gdFontPtr; external gdlib name 'gdFontLarge';
  752. gdFontSmall : gdFontPtr; external gdlib name 'gdFontSmall';
  753. gdFontGiant : gdFontPtr; external gdlib name 'gdFontGiant';
  754. gdFontMediumBold : gdFontPtr; external gdlib name 'gdFontMediumBold';
  755. gdFontTiny : gdFontPtr; external gdlib name 'gdFontTiny';
  756. {$endif darwin}
  757. {$endif}
  758. {overloaded pascal functions}
  759. function fopen(filename, rights: AnsiString): PFile;
  760. procedure gdImageChar(im: gdImagePtr; f: gdFontPtr; x: cint; y: cint; c: AnsiChar; color: cint);
  761. procedure gdImageCharUp(im: gdImagePtr; f: gdFontPtr; x: cint; y: cint; c: AnsiChar; color: cint);
  762. procedure gdImageString(im: gdImagePtr; f: gdFontPtr; x: cint; y: cint; s: AnsiString; color: cint);
  763. procedure gdImageStringUp(im: gdImagePtr; f: gdFontPtr; x: cint; y: cint; s: AnsiString; color: cint);
  764. procedure gdImageString16(im: gdImagePtr; f: gdFontPtr; x: cint; y: cint; s: WideString; color: cint);
  765. procedure gdImageStringUp16(im: gdImagePtr; f: gdFontPtr; x: cint; y: cint; s: WideString; color: cint);
  766. implementation
  767. {$ifdef windows}
  768. function gdFontLarge(): gdFontPtr; inline;
  769. begin
  770. Result := gdFontGetLarge();
  771. end;
  772. function gdFontSmall(): gdFontPtr; inline;
  773. begin
  774. Result := gdFontGetSmall();
  775. end;
  776. function gdFontGiant(): gdFontPtr; inline;
  777. begin
  778. Result := gdFontGetGiant();
  779. end;
  780. function gdFontMediumBold(): gdFontPtr; inline;
  781. begin
  782. Result := gdFontGetMediumBold();
  783. end;
  784. function gdFontTiny(): gdFontPtr; inline;
  785. begin
  786. Result := gdFontGetTiny();
  787. end;
  788. {$endif}
  789. function gdTrueColorGetAlpha(c: cint): cint;
  790. begin
  791. Result :=(c and $7F000000) shr 24;
  792. end;
  793. function gdTrueColorGetRed(c: cint): cint;
  794. begin
  795. Result :=(c and $FF0000) shr 16;
  796. end;
  797. function gdTrueColorGetGreen(c: cint): cint;
  798. begin
  799. Result :=(c and $00FF00) shr 8;
  800. end;
  801. function gdTrueColorGetBlue(c: cint): cint;
  802. begin
  803. Result := c and $0000FF;
  804. end;
  805. function gdImageCreatePalette(sx: cint; sy: cint): gdImagePtr;
  806. begin
  807. Result := gdImageCreate(sx, sy);
  808. end;
  809. function gdTrueColor(r: cint; g: cint; b: cint): cint;
  810. begin
  811. result := (r shl 16) or (g shl 8) or (b);
  812. end;
  813. function gdTrueColorAlpha(r: cint; g: cint; b: cint; a: cint): cint;
  814. begin
  815. result := (a shl 24) or (r shl 16) or (g shl 8) or (b);
  816. end;
  817. function gdImageTrueColor(im: gdImagePtr): cint;
  818. begin
  819. Result := im^.trueColor;
  820. end;
  821. function gdImageSX(im: gdImagePtr): cint;
  822. begin
  823. Result := im^.sx;
  824. end;
  825. function gdImageSY(im: gdImagePtr): cint;
  826. begin
  827. Result := im^.sy;
  828. end;
  829. function gdImageColorsTotal(im: gdImagePtr): cint;
  830. begin
  831. Result := im^.colorsTotal;
  832. end;
  833. function gdImageRed(im: gdImagePtr; c: cint): cint;
  834. begin
  835. if im^.trueColor <> 0 then
  836. Result := gdTrueColorGetRed(c)
  837. else
  838. Result := im^.red[c];
  839. end;
  840. function gdImageGreen(im: gdImagePtr; c: cint): cint;
  841. begin
  842. if im^.trueColor <> 0 then
  843. Result := gdTrueColorGetGreen(c)
  844. else
  845. Result := im^.green[c];
  846. end;
  847. function gdImageBlue(im: gdImagePtr; c: cint): cint;
  848. begin
  849. if im^.trueColor <> 0 then
  850. Result := gdTrueColorGetBlue(c)
  851. else
  852. Result := im^.blue[c];
  853. end;
  854. function gdImageAlpha(im: gdImagePtr; c: cint): cint;
  855. begin
  856. if im^.trueColor <> 0 then
  857. Result := gdTrueColorGetAlpha(c)
  858. else
  859. Result := im^.alpha[c];
  860. end;
  861. function gdImageGetTransparent(im: gdImagePtr): cint;
  862. begin
  863. Result := im^.transparent;
  864. end;
  865. function gdImageGetInterlaced(im: gdImagePtr): cint;
  866. begin
  867. Result := im^.interlace;
  868. end;
  869. function gdImagePalettePixel(im: gdImagePtr; x, y: cint): cint;
  870. begin
  871. Result := im^.pixels[y][x];
  872. end;
  873. function gdImageTrueColorPixel(im: gdImagePtr; x, y: cint): cint;
  874. begin
  875. Result := im^.tpixels[y][x];
  876. end;
  877. function fopen(filename, rights: AnsiString): PFile;
  878. begin
  879. Result := fopen(PAnsiChar(filename), PAnsiChar(rights));
  880. end;
  881. procedure gdImageChar(im: gdImagePtr; f: gdFontPtr; x: cint; y: cint; c: AnsiChar; color: cint);
  882. begin
  883. gdImageChar(im,f,x,y,ord(c),color);
  884. end;
  885. procedure gdImageCharUp(im: gdImagePtr; f: gdFontPtr; x: cint; y: cint; c: AnsiChar; color: cint);
  886. begin
  887. gdImageCharUp(im,f,x,y,ord(c),color);
  888. end;
  889. procedure gdImageString(im: gdImagePtr; f: gdFontPtr; x: cint; y: cint; s: AnsiString; color: cint);
  890. begin
  891. gdImageString(im,f,x,y,PAnsiChar(s),color);
  892. end;
  893. procedure gdImageStringUp(im: gdImagePtr; f: gdFontPtr; x: cint; y: cint; s: AnsiString; color: cint);
  894. begin
  895. gdImageStringUp(im,f,x,y,PAnsiChar(s),color);
  896. end;
  897. procedure gdImageString16(im: gdImagePtr; f: gdFontPtr; x: cint; y: cint; s: WideString; color: cint);
  898. begin
  899. gdImageString16(im,f,x,y,PWideChar(s),color);
  900. end;
  901. procedure gdImageStringUp16(im: gdImagePtr; f: gdFontPtr; x: cint; y: cint; s: WideString; color: cint);
  902. begin
  903. gdImageStringUp16(im,f,x,y,PWideChar(s),color);
  904. end;
  905. type
  906. stream_gdIOCtxPtr = ^stream_gdIOCtx;
  907. stream_gdIOCtx = record
  908. ctx: gdIOCtx;
  909. strm: TStream;
  910. free: Boolean;
  911. end;
  912. function stream_getC(ctx: gdIOCtxPtr): cint; EXTDECL;
  913. var
  914. s: stream_gdIOCtxPtr absolute ctx;
  915. begin
  916. result := 255;
  917. s^.strm.read(result, 1);
  918. end;
  919. function stream_getBuf(ctx: gdIOCtxPtr; buf: pointer; len: cint): cint; EXTDECL;
  920. var
  921. s: stream_gdIOCtxPtr absolute ctx;
  922. begin
  923. result := s^.strm.read(buf^, len);
  924. end;
  925. procedure stream_putC(ctx: gdIOCtxPtr; len: cint); EXTDECL;
  926. var
  927. s: stream_gdIOCtxPtr absolute ctx;
  928. begin
  929. s^.strm.write(len, 1);
  930. end;
  931. procedure stream_putBuf(ctx: gdIOCtxPtr; buf: pointer; len: cint); EXTDECL;
  932. var
  933. s: stream_gdIOCtxPtr absolute ctx;
  934. begin
  935. s^.strm.write(buf^, len);
  936. end;
  937. function stream_seek(ctx: gdIOCtxPtr; pos: cint): cint; EXTDECL;
  938. var
  939. s: stream_gdIOCtxPtr absolute ctx;
  940. begin
  941. result := s^.strm.seek(soFromBeginning, pos);
  942. end;
  943. function stream_tell(ctx: gdIOCtxPtr): clong; EXTDECL;
  944. var
  945. s: stream_gdIOCtxPtr absolute ctx;
  946. begin
  947. result := s^.strm.position;
  948. end;
  949. procedure stream_gd_free(ctx: gdIOCtxPtr); EXTDECL;
  950. var
  951. s: stream_gdIOCtxPtr absolute ctx;
  952. begin
  953. if s^.free then
  954. s^.strm.Free;
  955. FreeMem(s);
  956. end;
  957. function gdNewStreamCtx(Stream: TStream; free: boolean): gdIOCtxPtr;
  958. var
  959. res: stream_gdIOCtxPtr;
  960. begin
  961. GetMem(res, Sizeof(stream_gdIOCtx));
  962. res^.ctx.getC := @stream_getC;
  963. res^.ctx.getBuf := @stream_getBuf;
  964. res^.ctx.putC := @stream_putC;
  965. res^.ctx.putBuf := @stream_putBuf;
  966. res^.ctx.seek := @stream_seek;
  967. res^.ctx.tell := @stream_tell;
  968. res^.ctx.gd_free := @stream_gd_free;
  969. res^.strm := Stream;
  970. res^.free := free;
  971. Result := @res^.ctx;
  972. end;
  973. end.