xref: /PHP-7.3/ext/gd/libgd/gd.h (revision c8ba185c)
1 #ifndef GD_H
2 #define GD_H 1
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
11 
12 #include "php_compat.h"
13 
14 #define GD_MAJOR_VERSION 2
15 #define GD_MINOR_VERSION 0
16 #define GD_RELEASE_VERSION 35
17 #define GD_EXTRA_VERSION ""
18 #define GD_VERSION_STRING "2.0.35"
19 
20 #ifdef NETWARE
21 /* default fontpath for netware systems */
22 #define DEFAULT_FONTPATH "sys:/java/nwgfx/lib/x11/fonts/ttf;."
23 #define PATHSEPARATOR ";"
24 #elif defined(WIN32)
25 /* default fontpath for windows systems */
26 #define DEFAULT_FONTPATH "c:\\winnt\\fonts;c:\\windows\\fonts;."
27 #define PATHSEPARATOR ";"
28 #else
29 /* default fontpath for unix systems */
30 #define DEFAULT_FONTPATH "/usr/X11R6/lib/X11/fonts/TrueType:/usr/X11R6/lib/X11/fonts/truetype:/usr/X11R6/lib/X11/fonts/TTF:/usr/share/fonts/TrueType:/usr/share/fonts/truetype:/usr/openwin/lib/X11/fonts/TrueType:/usr/X11R6/lib/X11/fonts/Type1:."
31 #define PATHSEPARATOR ":"
32 #endif
33 
34 /* gd.h: declarations file for the graphic-draw module.
35  * Permission to use, copy, modify, and distribute this software and its
36  * documentation for any purpose and without fee is hereby granted, provided
37  * that the above copyright notice appear in all copies and that both that
38  * copyright notice and this permission notice appear in supporting
39  * documentation.  This software is provided "AS IS." Thomas Boutell and
40  * Boutell.Com, Inc. disclaim all warranties, either express or implied,
41  * including but not limited to implied warranties of merchantability and
42  * fitness for a particular purpose, with respect to this code and accompanying
43  * documentation. */
44 
45 /* stdio is needed for file I/O. */
46 #include <stdio.h>
47 #include "gd_io.h"
48 
49 /* va_list needed in gdErrorMethod */
50 #ifdef PHP_WIN32
51 # include <stdarg.h>
52 #else
53 # if HAVE_STDARG_H
54 # include <stdarg.h>
55 # else
56 #  if HAVE_SYS_VARARGS_H
57 #  include <sys/varargs.h>
58 #  endif
59 # endif
60 #endif
61 
62 /* The maximum number of palette entries in palette-based images.
63 	In the wonderful new world of gd 2.0, you can of course have
64 	many more colors when using truecolor mode. */
65 
66 #define gdMaxColors 256
67 
68 /* Image type. See functions below; you will not need to change
69 	the elements directly. Use the provided macros to
70 	access sx, sy, the color table, and colorsTotal for
71 	read-only purposes. */
72 
73 /* If 'truecolor' is set true, the image is truecolor;
74 	pixels are represented by integers, which
75 	must be 32 bits wide or more.
76 
77 	True colors are repsented as follows:
78 
79 	ARGB
80 
81 	Where 'A' (alpha channel) occupies only the
82 	LOWER 7 BITS of the MSB. This very small
83 	loss of alpha channel resolution allows gd 2.x
84 	to keep backwards compatibility by allowing
85 	signed integers to be used to represent colors,
86 	and negative numbers to represent special cases,
87 	just as in gd 1.x. */
88 
89 #define gdAlphaMax 127
90 #define gdAlphaOpaque 0
91 #define gdAlphaTransparent 127
92 #define gdRedMax 255
93 #define gdGreenMax 255
94 #define gdBlueMax 255
95 #define gdTrueColorGetAlpha(c) (((c) & 0x7F000000) >> 24)
96 #define gdTrueColorGetRed(c) (((c) & 0xFF0000) >> 16)
97 #define gdTrueColorGetGreen(c) (((c) & 0x00FF00) >> 8)
98 #define gdTrueColorGetBlue(c) ((c) & 0x0000FF)
99 #define gdEffectReplace 0
100 #define gdEffectAlphaBlend 1
101 #define gdEffectNormal 2
102 #define gdEffectOverlay 3
103 #define gdEffectMultiply 4
104 
105 #define GD_TRUE 1
106 #define GD_FALSE 0
107 
108 #define GD_EPSILON 1e-6
109 
110 /* This function accepts truecolor pixel values only. The
111 	source color is composited with the destination color
112 	based on the alpha channel value of the source color.
113 	The resulting color is opaque. */
114 
115 int gdAlphaBlend(int dest, int src);
116 int gdLayerOverlay(int dst, int src);
117 int gdLayerMultiply(int dest, int src);
118 
119 /**
120  * Group: Transform
121  *
122  * Constants: gdInterpolationMethod
123 
124  *  GD_BELL				 - Bell
125  *  GD_BESSEL			 - Bessel
126  *  GD_BILINEAR_FIXED 	 - fixed point bilinear
127  *  GD_BICUBIC 			 - Bicubic
128  *  GD_BICUBIC_FIXED 	 - fixed point bicubic integer
129  *  GD_BLACKMAN			 - Blackman
130  *  GD_BOX				 - Box
131  *  GD_BSPLINE			 - BSpline
132  *  GD_CATMULLROM		 - Catmullrom
133  *  GD_GAUSSIAN			 - Gaussian
134  *  GD_GENERALIZED_CUBIC - Generalized cubic
135  *  GD_HERMITE			 - Hermite
136  *  GD_HAMMING			 - Hamming
137  *  GD_HANNING			 - Hannig
138  *  GD_MITCHELL			 - Mitchell
139  *  GD_NEAREST_NEIGHBOUR - Nearest neighbour interpolation
140  *  GD_POWER			 - Power
141  *  GD_QUADRATIC		 - Quadratic
142  *  GD_SINC				 - Sinc
143  *  GD_TRIANGLE			 - Triangle
144  *  GD_WEIGHTED4		 - 4 pixels weighted bilinear interpolation
145  *
146  * See also:
147  *  <gdSetInterpolationMethod>
148  **/
149 typedef enum {
150 	GD_DEFAULT          = 0,
151 	GD_BELL,
152 	GD_BESSEL,
153 	GD_BILINEAR_FIXED,
154 	GD_BICUBIC,
155 	GD_BICUBIC_FIXED,
156 	GD_BLACKMAN,
157 	GD_BOX,
158 	GD_BSPLINE,
159 	GD_CATMULLROM,
160 	GD_GAUSSIAN,
161 	GD_GENERALIZED_CUBIC,
162 	GD_HERMITE,
163 	GD_HAMMING,
164 	GD_HANNING,
165 	GD_MITCHELL,
166 	GD_NEAREST_NEIGHBOUR,
167 	GD_POWER,
168 	GD_QUADRATIC,
169 	GD_SINC,
170 	GD_TRIANGLE,
171 	GD_WEIGHTED4,
172 	GD_METHOD_COUNT = 21
173 } gdInterpolationMethod;
174 
175 /* define struct with name and func ptr and add it to gdImageStruct gdInterpolationMethod interpolation; */
176 
177 /* Interpolation function ptr */
178 typedef double (* interpolation_method )(double);
179 
180 typedef struct gdImageStruct {
181 	/* Palette-based image pixels */
182 	unsigned char ** pixels;
183 	int sx;
184 	int sy;
185 	/* These are valid in palette images only. See also
186 		'alpha', which appears later in the structure to
187 		preserve binary backwards compatibility */
188 	int colorsTotal;
189 	int red[gdMaxColors];
190 	int green[gdMaxColors];
191 	int blue[gdMaxColors];
192 	int open[gdMaxColors];
193 	/* For backwards compatibility, this is set to the
194 		first palette entry with 100% transparency,
195 		and is also set and reset by the
196 		gdImageColorTransparent function. Newer
197 		applications can allocate palette entries
198 		with any desired level of transparency; however,
199 		bear in mind that many viewers, notably
200 		many web browsers, fail to implement
201 		full alpha channel for PNG and provide
202 		support for full opacity or transparency only. */
203 	int transparent;
204 	int *polyInts;
205 	int polyAllocated;
206 	struct gdImageStruct *brush;
207 	struct gdImageStruct *tile;
208 	int brushColorMap[gdMaxColors];
209 	int tileColorMap[gdMaxColors];
210 	int styleLength;
211 	int stylePos;
212 	int *style;
213 	int interlace;
214 	/* New in 2.0: thickness of line. Initialized to 1. */
215 	int thick;
216 	/* New in 2.0: alpha channel for palettes. Note that only
217 		Macintosh Internet Explorer and (possibly) Netscape 6
218 		really support multiple levels of transparency in
219 		palettes, to my knowledge, as of 2/15/01. Most
220 		common browsers will display 100% opaque and
221 		100% transparent correctly, and do something
222 		unpredictable and/or undesirable for levels
223 		in between. TBB */
224 	int alpha[gdMaxColors];
225 	/* Truecolor flag and pixels. New 2.0 fields appear here at the
226 		end to minimize breakage of existing object code. */
227 	int trueColor;
228 	int ** tpixels;
229 	/* Should alpha channel be copied, or applied, each time a
230 		pixel is drawn? This applies to truecolor images only.
231 		No attempt is made to alpha-blend in palette images,
232 		even if semitransparent palette entries exist.
233 		To do that, build your image as a truecolor image,
234 		then quantize down to 8 bits. */
235 	int alphaBlendingFlag;
236 	/* Should the alpha channel of the image be saved? This affects
237 		PNG at the moment; other future formats may also
238 		have that capability. JPEG doesn't. */
239 	int saveAlphaFlag;
240 
241 	/* 2.0.12: anti-aliased globals. 2.0.26: just a few vestiges after
242 	  switching to the fast, memory-cheap implementation from PHP-gd. */
243 	int AA;
244 	int AA_color;
245 	int AA_dont_blend;
246 
247 	/* 2.0.12: simple clipping rectangle. These values must be checked for safety when set; please use gdImageSetClip */
248 	int cx1;
249 	int cy1;
250 	int cx2;
251 	int cy2;
252 	unsigned int res_x;
253 	unsigned int res_y;
254 	gdInterpolationMethod interpolation_id;
255 	interpolation_method interpolation;
256 } gdImage;
257 
258 typedef gdImage * gdImagePtr;
259 
260 /* Point type for use in polygon drawing. */
261 
262 /**
263  * Group: Types
264  *
265  * typedef: gdPointF
266  *  Defines a point in a 2D coordinate system using floating point
267  *  values.
268  * x - Floating point position (increase from left to right)
269  * y - Floating point Row position (increase from top to bottom)
270  *
271  * typedef: gdPointFPtr
272  *  Pointer to a <gdPointF>
273  *
274  * See also:
275  *  <gdImageCreate>, <gdImageCreateTrueColor>,
276  **/
277 typedef struct
278 {
279 	double x, y;
280 }
281 gdPointF, *gdPointFPtr;
282 
283 typedef struct {
284 	/* # of characters in font */
285 	int nchars;
286 	/* First character is numbered... (usually 32 = space) */
287 	int offset;
288 	/* Character width and height */
289 	int w;
290 	int h;
291 	/* Font data; array of characters, one row after another.
292 		Easily included in code, also easily loaded from
293 		data files. */
294 	char *data;
295 } gdFont;
296 
297 /* Text functions take these. */
298 typedef gdFont *gdFontPtr;
299 
300 typedef void(*gdErrorMethod)(int, const char *, va_list);
301 
302 void gdSetErrorMethod(gdErrorMethod);
303 void gdClearErrorMethod(void);
304 
305 /**
306  * Group: Types
307  *
308  * typedef: gdRect
309  *  Defines a rectilinear region.
310  *
311  *  x - left position
312  *  y - right position
313  *  width - Rectangle width
314  *  height - Rectangle height
315  *
316  * typedef: gdRectPtr
317  *  Pointer to a <gdRect>
318  *
319  * See also:
320  *  <gdSetInterpolationMethod>
321  **/
322 typedef struct
323 {
324 	int x, y;
325 	int width, height;
326 }
327 gdRect, *gdRectPtr;
328 
329 /* For backwards compatibility only. Use gdImageSetStyle()
330 	for MUCH more flexible line drawing. Also see
331 	gdImageSetBrush(). */
332 #define gdDashSize 4
333 
334 /* Special colors. */
335 
336 #define gdStyled (-2)
337 #define gdBrushed (-3)
338 #define gdStyledBrushed (-4)
339 #define gdTiled (-5)
340 
341 /* NOT the same as the transparent color index.
342 	This is used in line styles only. */
343 #define gdTransparent (-6)
344 
345 #define gdAntiAliased (-7)
346 
347 /* Functions to manipulate images. */
348 
349 /* Creates a palette-based image (up to 256 colors). */
350 gdImagePtr gdImageCreate(int sx, int sy);
351 
352 /* An alternate name for the above (2.0). */
353 #define gdImageCreatePalette gdImageCreate
354 
355 /* Creates a truecolor image (millions of colors). */
356 gdImagePtr gdImageCreateTrueColor(int sx, int sy);
357 
358 /* Creates an image from various file types. These functions
359 	return a palette or truecolor image based on the
360 	nature of the file being loaded. Truecolor PNG
361 	stays truecolor; palette PNG stays palette-based;
362 	JPEG is always truecolor. */
363 gdImagePtr gdImageCreateFromPng(FILE *fd);
364 gdImagePtr gdImageCreateFromPngCtx(gdIOCtxPtr in);
365 gdImagePtr gdImageCreateFromWBMP(FILE *inFile);
366 gdImagePtr gdImageCreateFromWBMPCtx(gdIOCtx *infile);
367 gdImagePtr gdImageCreateFromJpeg(FILE *infile);
368 gdImagePtr gdImageCreateFromJpegEx(FILE *infile, int ignore_warning);
369 gdImagePtr gdImageCreateFromJpegCtx(gdIOCtx *infile);
370 gdImagePtr gdImageCreateFromJpegCtxEx(gdIOCtx *infile, int ignore_warning);
371 gdImagePtr gdImageCreateFromJpegPtr (int size, void *data);
372 gdImagePtr gdImageCreateFromJpegPtrEx (int size, void *data, int ignore_warning);
373 gdImagePtr gdImageCreateFromWebp(FILE *fd);
374 gdImagePtr gdImageCreateFromWebpCtx(gdIOCtxPtr in);
375 gdImagePtr gdImageCreateFromWebpPtr (int size, void *data);
376 
377 gdImagePtr gdImageCreateFromBmp (FILE * inFile);
378 gdImagePtr gdImageCreateFromBmpPtr (int size, void *data);
379 gdImagePtr gdImageCreateFromBmpCtx (gdIOCtxPtr infile);
380 
381 const char * gdPngGetVersionString();
382 
383 const char * gdJpegGetVersionString();
384 
385 /* A custom data source. */
386 /* The source function must return -1 on error, otherwise the number
387         of bytes fetched. 0 is EOF, not an error! */
388 /* context will be passed to your source function. */
389 
390 typedef struct {
391         int (*source) (void *context, char *buffer, int len);
392         void *context;
393 } gdSource, *gdSourcePtr;
394 
395 gdImagePtr gdImageCreateFromPngSource(gdSourcePtr in);
396 
397 gdImagePtr gdImageCreateFromGd(FILE *in);
398 gdImagePtr gdImageCreateFromGdCtx(gdIOCtxPtr in);
399 
400 gdImagePtr gdImageCreateFromGd2(FILE *in);
401 gdImagePtr gdImageCreateFromGd2Ctx(gdIOCtxPtr in);
402 
403 gdImagePtr gdImageCreateFromGd2Part(FILE *in, int srcx, int srcy, int w, int h);
404 gdImagePtr gdImageCreateFromGd2PartCtx(gdIOCtxPtr in, int srcx, int srcy, int w, int h);
405 
406 gdImagePtr gdImageCreateFromXbm(FILE *fd);
407 void gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOCtx * out);
408 
409 gdImagePtr gdImageCreateFromXpm (char *filename);
410 
411 void gdImageDestroy(gdImagePtr im);
412 
413 /* Replaces or blends with the background depending on the
414 	most recent call to gdImageAlphaBlending and the
415 	alpha channel value of 'color'; default is to overwrite.
416 	Tiling and line styling are also implemented
417 	here. All other gd drawing functions pass through this call,
418 	allowing for many useful effects. */
419 
420 void gdImageSetPixel(gdImagePtr im, int x, int y, int color);
421 
422 int gdImageGetTrueColorPixel (gdImagePtr im, int x, int y);
423 int gdImageGetPixel(gdImagePtr im, int x, int y);
424 
425 void gdImageAABlend(gdImagePtr im);
426 
427 void gdImageLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
428 void gdImageAALine(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
429 
430 /* For backwards compatibility only. Use gdImageSetStyle()
431 	for much more flexible line drawing. */
432 void gdImageDashedLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
433 /* Corners specified (not width and height). Upper left first, lower right
434  	second. */
435 void gdImageRectangle(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
436 /* Solid bar. Upper left corner first, lower right corner second. */
437 void gdImageFilledRectangle(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
438 void gdImageSetClip(gdImagePtr im, int x1, int y1, int x2, int y2);
439 void gdImageGetClip(gdImagePtr im, int *x1P, int *y1P, int *x2P, int *y2P);
440 void gdImageSetResolution(gdImagePtr im, const unsigned int res_x, const unsigned int res_y);
441 void gdImageChar(gdImagePtr im, gdFontPtr f, int x, int y, int c, int color);
442 void gdImageCharUp(gdImagePtr im, gdFontPtr f, int x, int y, int c, int color);
443 void gdImageString(gdImagePtr im, gdFontPtr f, int x, int y, unsigned char *s, int color);
444 void gdImageStringUp(gdImagePtr im, gdFontPtr f, int x, int y, unsigned char *s, int color);
445 void gdImageString16(gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color);
446 void gdImageStringUp16(gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color);
447 
448 /*
449  * The following functions are required to be called prior to the
450  * use of any sort of threads in a module load / shutdown function
451  * respectively.
452  */
453 void gdFontCacheMutexSetup();
454 void gdFontCacheMutexShutdown();
455 
456 /* 2.0.16: for thread-safe use of gdImageStringFT and friends,
457  * call this before allowing any thread to call gdImageStringFT.
458  * Otherwise it is invoked by the first thread to invoke
459  * gdImageStringFT, with a very small but real risk of a race condition.
460  * Return 0 on success, nonzero on failure to initialize freetype.
461  */
462 int gdFontCacheSetup(void);
463 
464 /* Optional: clean up after application is done using fonts in gdImageStringFT(). */
465 void gdFontCacheShutdown(void);
466 
467 /* Calls gdImageStringFT. Provided for backwards compatibility only. */
468 char *gdImageStringTTF(gdImage *im, int *brect, int fg, char *fontlist,
469                 double ptsize, double angle, int x, int y, char *string);
470 
471 /* FreeType 2 text output */
472 char *gdImageStringFT(gdImage *im, int *brect, int fg, char *fontlist,
473                 double ptsize, double angle, int x, int y, char *string);
474 
475 typedef struct {
476 	double linespacing;	/* fine tune line spacing for '\n' */
477 	int flags;		/* Logical OR of gdFTEX_ values */
478 	int charmap;		/* TBB: 2.0.12: may be gdFTEX_Unicode,
479 				   gdFTEX_Shift_JIS, gdFTEX_Big5 or gdFTEX_MacRoman;
480 				   when not specified, maps are searched
481 				   for in the above order. */
482 	int hdpi;
483 	int vdpi;
484 }
485  gdFTStringExtra, *gdFTStringExtraPtr;
486 
487 #define gdFTEX_LINESPACE 1
488 #define gdFTEX_CHARMAP 2
489 #define gdFTEX_RESOLUTION 4
490 
491 /* These are NOT flags; set one in 'charmap' if you set the gdFTEX_CHARMAP bit in 'flags'. */
492 #define gdFTEX_Unicode 0
493 #define gdFTEX_Shift_JIS 1
494 #define gdFTEX_Big5 2
495 #define gdFTEX_MacRoman 3
496 
497 /* FreeType 2 text output with fine tuning */
498 char *
499 gdImageStringFTEx(gdImage * im, int *brect, int fg, char * fontlist,
500 		double ptsize, double angle, int x, int y, char * string,
501 		gdFTStringExtraPtr strex);
502 
503 
504 /* Point type for use in polygon drawing. */
505 typedef struct {
506 	int x, y;
507 } gdPoint, *gdPointPtr;
508 
509 void gdImagePolygon(gdImagePtr im, gdPointPtr p, int n, int c);
510 void gdImageOpenPolygon(gdImagePtr im, gdPointPtr p, int n, int c);
511 void gdImageFilledPolygon(gdImagePtr im, gdPointPtr p, int n, int c);
512 
513 /* These functions still work with truecolor images,
514 	for which they never return error. */
515 int gdImageColorAllocate(gdImagePtr im, int r, int g, int b);
516 /* gd 2.0: palette entries with non-opaque transparency are permitted. */
517 int gdImageColorAllocateAlpha(gdImagePtr im, int r, int g, int b, int a);
518 /* Assumes opaque is the preferred alpha channel value */
519 int gdImageColorClosest(gdImagePtr im, int r, int g, int b);
520 /* Closest match taking all four parameters into account.
521 	A slightly different color with the same transparency
522 	beats the exact same color with radically different
523 	transparency */
524 int gdImageColorClosestAlpha(gdImagePtr im, int r, int g, int b, int a);
525 /* An alternate method */
526 int gdImageColorClosestHWB(gdImagePtr im, int r, int g, int b);
527 /* Returns exact, 100% opaque matches only */
528 int gdImageColorExact(gdImagePtr im, int r, int g, int b);
529 /* Returns an exact match only, including alpha */
530 int gdImageColorExactAlpha(gdImagePtr im, int r, int g, int b, int a);
531 /* Opaque only */
532 int gdImageColorResolve(gdImagePtr im, int r, int g, int b);
533 /* Based on gdImageColorExactAlpha and gdImageColorClosestAlpha */
534 int gdImageColorResolveAlpha(gdImagePtr im, int r, int g, int b, int a);
535 
536 /* A simpler way to obtain an opaque truecolor value for drawing on a
537 	truecolor image. Not for use with palette images! */
538 
539 #define gdTrueColor(r, g, b) (((r) << 16) + \
540 	((g) << 8) + \
541 	(b))
542 
543 /* Returns a truecolor value with an alpha channel component.
544 	gdAlphaMax (127, **NOT 255**) is transparent, 0 is completely
545 	opaque. */
546 
547 #define gdTrueColorAlpha(r, g, b, a) (((a) << 24) + \
548 	((r) << 16) + \
549 	((g) << 8) + \
550 	(b))
551 
552 void gdImageColorDeallocate(gdImagePtr im, int color);
553 
554 /* Converts a truecolor image to a palette-based image,
555 	using a high-quality two-pass quantization routine
556 	which attempts to preserve alpha channel information
557 	as well as R/G/B color information when creating
558 	a palette. If ditherFlag is set, the image will be
559 	dithered to approximate colors better, at the expense
560 	of some obvious "speckling." colorsWanted can be
561 	anything up to 256. If the original source image
562 	includes photographic information or anything that
563 	came out of a JPEG, 256 is strongly recommended.
564 
565 	Better yet, don't use this function -- write real
566 	truecolor PNGs and JPEGs. The disk space gain of
567         conversion to palette is not great (for small images
568         it can be negative) and the quality loss is ugly. */
569 
570 gdImagePtr gdImageCreatePaletteFromTrueColor (gdImagePtr im, int ditherFlag, int colorsWanted);
571 
572 int gdImageTrueColorToPalette(gdImagePtr im, int ditherFlag, int colorsWanted);
573 int gdImagePaletteToTrueColor(gdImagePtr src);
574 
575 /* An attempt at getting the results of gdImageTrueColorToPalette
576 	to look a bit more like the original (im1 is the original
577 	and im2 is the palette version */
578 int gdImageColorMatch(gdImagePtr im1, gdImagePtr im2);
579 
580 /* Specifies a color index (if a palette image) or an
581 	RGB color (if a truecolor image) which should be
582 	considered 100% transparent. FOR TRUECOLOR IMAGES,
583 	THIS IS IGNORED IF AN ALPHA CHANNEL IS BEING
584 	SAVED. Use gdImageSaveAlpha(im, 0); to
585 	turn off the saving of a full alpha channel in
586 	a truecolor image. Note that gdImageColorTransparent
587 	is usually compatible with older browsers that
588 	do not understand full alpha channels well. TBB */
589 void gdImageColorTransparent(gdImagePtr im, int color);
590 
591 void gdImagePaletteCopy(gdImagePtr dst, gdImagePtr src);
592 void gdImagePng(gdImagePtr im, FILE *out);
593 void gdImagePngCtx(gdImagePtr im, gdIOCtx *out);
594 void gdImageGif(gdImagePtr im, FILE *out);
595 void gdImageGifCtx(gdImagePtr im, gdIOCtx *out);
596 
597 void * gdImageBmpPtr(gdImagePtr im, int *size, int compression);
598 void gdImageBmp(gdImagePtr im, FILE *outFile, int compression);
599 void gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression);
600 
601 /* 2.0.12: Compression level: 0-9 or -1, where 0 is NO COMPRESSION at all,
602  * 1 is FASTEST but produces larger files, 9 provides the best
603  * compression (smallest files) but takes a long time to compress, and
604  * -1 selects the default compiled into the zlib library.
605  */
606 void gdImagePngEx(gdImagePtr im, FILE * out, int level, int basefilter);
607 void gdImagePngCtxEx(gdImagePtr im, gdIOCtx * out, int level, int basefilter);
608 
609 void gdImageWBMP(gdImagePtr image, int fg, FILE *out);
610 void gdImageWBMPCtx(gdImagePtr image, int fg, gdIOCtx *out);
611 
612 /* Guaranteed to correctly free memory returned
613 	by the gdImage*Ptr functions */
614 void gdFree(void *m);
615 
616 /* Best to free this memory with gdFree(), not free() */
617 void *gdImageWBMPPtr(gdImagePtr im, int *size, int fg);
618 
619 /* 100 is highest quality (there is always a little loss with JPEG).
620        0 is lowest. 10 is about the lowest useful setting. */
621 void gdImageJpeg(gdImagePtr im, FILE *out, int quality);
622 void gdImageJpegCtx(gdImagePtr im, gdIOCtx *out, int quality);
623 
624 void gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quantization);
625 
626 /* Best to free this memory with gdFree(), not free() */
627 void *gdImageJpegPtr(gdImagePtr im, int *size, int quality);
628 
629 gdImagePtr gdImageCreateFromGif(FILE *fd);
630 gdImagePtr gdImageCreateFromGifCtx(gdIOCtxPtr in);
631 gdImagePtr gdImageCreateFromGifSource(gdSourcePtr in);
632 
633 /* A custom data sink. For backwards compatibility. Use
634 	gdIOCtx instead. */
635 /* The sink function must return -1 on error, otherwise the number
636         of bytes written, which must be equal to len. */
637 /* context will be passed to your sink function. */
638 typedef struct {
639         int (*sink) (void *context, const char *buffer, int len);
640         void *context;
641 } gdSink, *gdSinkPtr;
642 
643 void gdImagePngToSink(gdImagePtr im, gdSinkPtr out);
644 
645 void gdImageGd(gdImagePtr im, FILE *out);
646 void gdImageGd2(gdImagePtr im, FILE *out, int cs, int fmt);
647 
648 /* Best to free this memory with gdFree(), not free() */
649 void* gdImagePngPtr(gdImagePtr im, int *size);
650 
651 /* Best to free this memory with gdFree(), not free() */
652 void* gdImageGdPtr(gdImagePtr im, int *size);
653 void *gdImagePngPtrEx(gdImagePtr im, int *size, int level, int basefilter);
654 
655 /* Best to free this memory with gdFree(), not free() */
656 void* gdImageGd2Ptr(gdImagePtr im, int cs, int fmt, int *size);
657 
658 void gdImageEllipse(gdImagePtr im, int cx, int cy, int w, int h, int c);
659 
660 /* Style is a bitwise OR ( | operator ) of these.
661 	gdArc and gdChord are mutually exclusive;
662 	gdChord just connects the starting and ending
663 	angles with a straight line, while gdArc produces
664 	a rounded edge. gdPie is a synonym for gdArc.
665 	gdNoFill indicates that the arc or chord should be
666 	outlined, not filled. gdEdged, used together with
667 	gdNoFill, indicates that the beginning and ending
668 	angles should be connected to the center; this is
669 	a good way to outline (rather than fill) a
670 	'pie slice'. */
671 #define gdArc   0
672 #define gdPie   gdArc
673 #define gdChord 1
674 #define gdNoFill 2
675 #define gdEdged 4
676 
677 void gdImageFilledArc(gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color, int style);
678 void gdImageArc(gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color);
679 void gdImageFilledEllipse(gdImagePtr im, int cx, int cy, int w, int h, int color);
680 void gdImageFillToBorder(gdImagePtr im, int x, int y, int border, int color);
681 void gdImageFill(gdImagePtr im, int x, int y, int color);
682 void gdImageCopy(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h);
683 void gdImageCopyMerge(gdImagePtr dst, gdImagePtr src, int dstX, int dstY,
684 			int srcX, int srcY, int w, int h, int pct);
685 void gdImageCopyMergeGray(gdImagePtr dst, gdImagePtr src, int dstX, int dstY,
686                         int srcX, int srcY, int w, int h, int pct);
687 
688 /* Stretches or shrinks to fit, as needed. Does NOT attempt
689 	to average the entire set of source pixels that scale down onto the
690 	destination pixel. */
691 void gdImageCopyResized(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH);
692 
693 /* gd 2.0: stretches or shrinks to fit, as needed. When called with a
694 	truecolor destination image, this function averages the
695 	entire set of source pixels that scale down onto the
696 	destination pixel, taking into account what portion of the
697 	destination pixel each source pixel represents. This is a
698 	floating point operation, but this is not a performance issue
699 	on modern hardware, except for some embedded devices. If the
700 	destination is a palette image, gdImageCopyResized is
701 	substituted automatically. */
702 void gdImageCopyResampled(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH);
703 
704 gdImagePtr gdImageRotate90(gdImagePtr src, int ignoretransparent);
705 gdImagePtr gdImageRotate180(gdImagePtr src, int ignoretransparent);
706 gdImagePtr gdImageRotate270(gdImagePtr src, int ignoretransparent);
707 gdImagePtr gdImageRotateInterpolated(const gdImagePtr src, const float angle, int bgcolor);
708 
709 void gdImageSetBrush(gdImagePtr im, gdImagePtr brush);
710 void gdImageSetTile(gdImagePtr im, gdImagePtr tile);
711 void gdImageSetAntiAliased(gdImagePtr im, int c);
712 void gdImageSetAntiAliasedDontBlend(gdImagePtr im, int c, int dont_blend);
713 void gdImageSetStyle(gdImagePtr im, int *style, int noOfPixels);
714 /* Line thickness (defaults to 1). Affects lines, ellipses,
715 	rectangles, polygons and so forth. */
716 void gdImageSetThickness(gdImagePtr im, int thickness);
717 /* On or off (1 or 0) for all three of these. */
718 void gdImageInterlace(gdImagePtr im, int interlaceArg);
719 void gdImageAlphaBlending(gdImagePtr im, int alphaBlendingArg);
720 void gdImageAntialias(gdImagePtr im, int antialias);
721 void gdImageSaveAlpha(gdImagePtr im, int saveAlphaArg);
722 
723 enum gdPixelateMode {
724 	GD_PIXELATE_UPPERLEFT,
725 	GD_PIXELATE_AVERAGE
726 };
727 
728 int gdImagePixelate(gdImagePtr im, int block_size, const unsigned int mode);
729 
730 /* Macros to access information about images. */
731 
732 /* Returns nonzero if the image is a truecolor image,
733 	zero for a palette image. */
734 
735 #define gdImageTrueColor(im) ((im)->trueColor)
736 
737 #define gdImageSX(im) ((im)->sx)
738 #define gdImageSY(im) ((im)->sy)
739 #define gdImageColorsTotal(im) ((im)->colorsTotal)
740 #define gdImageRed(im, c) ((im)->trueColor ? gdTrueColorGetRed(c) : \
741 	(im)->red[(c)])
742 #define gdImageGreen(im, c) ((im)->trueColor ? gdTrueColorGetGreen(c) : \
743 	(im)->green[(c)])
744 #define gdImageBlue(im, c) ((im)->trueColor ? gdTrueColorGetBlue(c) : \
745 	(im)->blue[(c)])
746 #define gdImageAlpha(im, c) ((im)->trueColor ? gdTrueColorGetAlpha(c) : \
747 	(im)->alpha[(c)])
748 #define gdImageGetTransparent(im) ((im)->transparent)
749 #define gdImageGetInterlaced(im) ((im)->interlace)
750 
751 /* These macros provide direct access to pixels in
752 	palette-based and truecolor images, respectively.
753 	If you use these macros, you must perform your own
754 	bounds checking. Use of the macro for the correct type
755 	of image is also your responsibility. */
756 #define gdImagePalettePixel(im, x, y) (im)->pixels[(y)][(x)]
757 #define gdImageTrueColorPixel(im, x, y) (im)->tpixels[(y)][(x)]
758 #define gdImageResolutionX(im) (im)->res_x
759 #define gdImageResolutionY(im) (im)->res_y
760 
761 /* I/O Support routines. */
762 
763 gdIOCtx* gdNewFileCtx(FILE*);
764 gdIOCtx* gdNewDynamicCtx(int, void*);
765 gdIOCtx *gdNewDynamicCtxEx(int size, void *data, int freeFlag);
766 gdIOCtx* gdNewSSCtx(gdSourcePtr in, gdSinkPtr out);
767 void* gdDPExtractData(struct gdIOCtx* ctx, int *size);
768 
769 #define GD2_CHUNKSIZE           128
770 #define GD2_CHUNKSIZE_MIN	64
771 #define GD2_CHUNKSIZE_MAX       4096
772 
773 #define GD2_VERS                2
774 #define GD2_ID                  "gd2"
775 #define GD2_FMT_RAW             1
776 #define GD2_FMT_COMPRESSED      2
777 
778 
779 /* filters section
780  *
781  * Negate the imag src, white becomes black,
782  * The red, green, and blue intensities of an image are negated.
783  * White becomes black, yellow becomes blue, etc.
784  */
785 int gdImageNegate(gdImagePtr src);
786 
787 /* Convert the image src to a grayscale image */
788 int gdImageGrayScale(gdImagePtr src);
789 
790 /* Set the brightness level <brightness> for the image src */
791 int gdImageBrightness(gdImagePtr src, int brightness);
792 
793 /* Set the contrast level <contrast> for the image <src> */
794 int gdImageContrast(gdImagePtr src, double contrast);
795 
796 /* Simply adds or subtracts respectively red, green or blue to a pixel */
797 int gdImageColor(gdImagePtr src, const int red, const int green, const int blue, const int alpha);
798 
799 /* Image convolution by a 3x3 custom matrix */
800 int gdImageConvolution(gdImagePtr src, float ft[3][3], float filter_div, float offset);
801 
802 int gdImageEdgeDetectQuick(gdImagePtr src);
803 
804 int gdImageGaussianBlur(gdImagePtr im);
805 
806 int gdImageSelectiveBlur( gdImagePtr src);
807 
808 int gdImageEmboss(gdImagePtr im);
809 
810 int gdImageMeanRemoval(gdImagePtr im);
811 
812 int gdImageSmooth(gdImagePtr im, float weight);
813 
814 /* Image comparison definitions */
815 int gdImageCompare(gdImagePtr im1, gdImagePtr im2);
816 
817 void gdImageFlipHorizontal(gdImagePtr im);
818 void gdImageFlipVertical(gdImagePtr im);
819 void gdImageFlipBoth(gdImagePtr im);
820 
821 #define GD_FLIP_HORINZONTAL 1
822 #define GD_FLIP_VERTICAL 2
823 #define GD_FLIP_BOTH 3
824 
825 /**
826  * Group: Crop
827  *
828  * Constants: gdCropMode
829  *  GD_CROP_DEFAULT - Default crop mode (4 corners or background)
830  *  GD_CROP_TRANSPARENT - Crop using the transparent color
831  *  GD_CROP_BLACK - Crop black borders
832  *  GD_CROP_WHITE - Crop white borders
833  *  GD_CROP_SIDES - Crop using colors of the 4 corners
834  *
835  * See also:
836  *  <gdImageAutoCrop>
837  **/
838 enum gdCropMode {
839 	GD_CROP_DEFAULT = 0,
840 	GD_CROP_TRANSPARENT,
841 	GD_CROP_BLACK,
842 	GD_CROP_WHITE,
843 	GD_CROP_SIDES,
844 	GD_CROP_THRESHOLD
845 };
846 
847 gdImagePtr gdImageCrop(gdImagePtr src, const gdRectPtr crop);
848 gdImagePtr gdImageCropAuto(gdImagePtr im, const unsigned int mode);
849 gdImagePtr gdImageCropThreshold(gdImagePtr im, const unsigned int color, const float threshold);
850 
851 int gdImageSetInterpolationMethod(gdImagePtr im, gdInterpolationMethod id);
852 
853 gdImagePtr gdImageScaleBilinear(gdImagePtr im, const unsigned int new_width, const unsigned int new_height);
854 gdImagePtr gdImageScaleBicubic(gdImagePtr src_img, const unsigned int new_width, const unsigned int new_height);
855 gdImagePtr gdImageScaleBicubicFixed(gdImagePtr src, const unsigned int width, const unsigned int height);
856 gdImagePtr gdImageScaleNearestNeighbour(gdImagePtr im, const unsigned int width, const unsigned int height);
857 gdImagePtr gdImageScaleTwoPass(const gdImagePtr pOrigImage, const unsigned int uOrigWidth, const unsigned int uOrigHeight, const unsigned int uNewWidth, const unsigned int uNewHeight);
858 gdImagePtr gdImageScale(const gdImagePtr src, const unsigned int new_width, const unsigned int new_height);
859 
860 gdImagePtr gdImageRotateNearestNeighbour(gdImagePtr src, const float degrees, const int bgColor);
861 gdImagePtr gdImageRotateBilinear(gdImagePtr src, const float degrees, const int bgColor);
862 gdImagePtr gdImageRotateBicubicFixed(gdImagePtr src, const float degrees, const int bgColor);
863 gdImagePtr gdImageRotateGeneric(gdImagePtr src, const float degrees, const int bgColor);
864 gdImagePtr gdImageRotateInterpolated(const gdImagePtr src, const float angle, int bgcolor);
865 
866 typedef enum {
867 	GD_AFFINE_TRANSLATE = 0,
868 	GD_AFFINE_SCALE,
869 	GD_AFFINE_ROTATE,
870 	GD_AFFINE_SHEAR_HORIZONTAL,
871 	GD_AFFINE_SHEAR_VERTICAL,
872 } gdAffineStandardMatrix;
873 
874 int gdAffineApplyToPointF (gdPointFPtr dst, const gdPointFPtr src, const double affine[6]);
875 int gdAffineInvert (double dst[6], const double src[6]);
876 int gdAffineFlip (double dst_affine[6], const double src_affine[6], const int flip_h, const int flip_v);
877 int gdAffineConcat (double dst[6], const double m1[6], const double m2[6]);
878 
879 int gdAffineIdentity (double dst[6]);
880 int gdAffineScale (double dst[6], const double scale_x, const double scale_y);
881 int gdAffineRotate (double dst[6], const double angle);
882 int gdAffineShearHorizontal (double dst[6], const double angle);
883 int gdAffineShearVertical(double dst[6], const double angle);
884 int gdAffineTranslate (double dst[6], const double offset_x, const double offset_y);
885 double gdAffineExpansion (const double src[6]);
886 int gdAffineRectilinear (const double src[6]);
887 int gdAffineEqual (const double matrix1[6], const double matrix2[6]);
888 int gdTransformAffineGetImage(gdImagePtr *dst, const gdImagePtr src, gdRectPtr src_area, const double affine[6]);
889 int gdTransformAffineCopy(gdImagePtr dst, int dst_x, int dst_y, const gdImagePtr src, gdRectPtr src_region, const double affine[6]);
890 /*
891 gdTransformAffineCopy(gdImagePtr dst, int x0, int y0, int x1, int y1,
892 			const gdImagePtr src, int src_width, int src_height,
893 			const double affine[6]);
894 */
895 int gdTransformAffineBoundingBox(gdRectPtr src, const double affine[6], gdRectPtr bbox);
896 
897 
898 #define GD_CMP_IMAGE		1	/* Actual image IS different */
899 #define GD_CMP_NUM_COLORS	2	/* Number of Colours in pallette differ */
900 #define GD_CMP_COLOR		4	/* Image colours differ */
901 #define GD_CMP_SIZE_X		8	/* Image width differs */
902 #define GD_CMP_SIZE_Y		16	/* Image heights differ */
903 #define GD_CMP_TRANSPARENT	32	/* Transparent colour */
904 #define GD_CMP_BACKGROUND	64	/* Background colour */
905 #define GD_CMP_INTERLACE	128	/* Interlaced setting */
906 #define GD_CMP_TRUECOLOR	256	/* Truecolor vs palette differs */
907 
908 /* resolution affects ttf font rendering, particularly hinting */
909 #define GD_RESOLUTION           96      /* pixels per inch */
910 
911 #ifdef __cplusplus
912 }
913 #endif
914 
915 /* 2.0.12: this now checks the clipping rectangle */
916 #define gdImageBoundsSafe(im, x, y) (!((((y) < (im)->cy1) || ((y) > (im)->cy2)) || (((x) < (im)->cx1) || ((x) > (im)->cx2))))
917 
918 #endif /* GD_H */
919