gd.pas 49 KB

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