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