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