gd.pas 49 KB

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