xref: /PHP-8.3/ext/gd/libgd/gd.h (revision eb6c9eb9)
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 gdImageCreateFromAvif(FILE *infile);
368 gdImagePtr gdImageCreateFromAvifPtr(int size, void *data);
369 gdImagePtr gdImageCreateFromAvifCtx(gdIOCtx *infile);
370 
371 gdImagePtr gdImageCreateFromTga( FILE * fp );
372 gdImagePtr gdImageCreateFromTgaCtx(gdIOCtx* ctx);
373 gdImagePtr gdImageCreateFromTgaPtr(int size, void *data);
374 
375 gdImagePtr gdImageCreateFromBmp (FILE * inFile);
376 gdImagePtr gdImageCreateFromBmpPtr (int size, void *data);
377 gdImagePtr gdImageCreateFromBmpCtx (gdIOCtxPtr infile);
378 
379 const char * gdPngGetVersionString(void);
380 
381 const char * gdJpegGetVersionString(void);
382 
383 /* A custom data source. */
384 /* The source function must return -1 on error, otherwise the number
385         of bytes fetched. 0 is EOF, not an error! */
386 /* context will be passed to your source function. */
387 
388 typedef struct {
389         int (*source) (void *context, char *buffer, int len);
390         void *context;
391 } gdSource, *gdSourcePtr;
392 
393 gdImagePtr gdImageCreateFromPngSource(gdSourcePtr in);
394 
395 gdImagePtr gdImageCreateFromGd(FILE *in);
396 gdImagePtr gdImageCreateFromGdCtx(gdIOCtxPtr in);
397 
398 gdImagePtr gdImageCreateFromGd2(FILE *in);
399 gdImagePtr gdImageCreateFromGd2Ctx(gdIOCtxPtr in);
400 
401 gdImagePtr gdImageCreateFromGd2Part(FILE *in, int srcx, int srcy, int w, int h);
402 gdImagePtr gdImageCreateFromGd2PartCtx(gdIOCtxPtr in, int srcx, int srcy, int w, int h);
403 
404 gdImagePtr gdImageCreateFromXbm(FILE *fd);
405 void gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOCtx * out);
406 
407 gdImagePtr gdImageCreateFromXpm (char *filename);
408 
409 void gdImageDestroy(gdImagePtr im);
410 
411 /* Replaces or blends with the background depending on the
412 	most recent call to gdImageAlphaBlending and the
413 	alpha channel value of 'color'; default is to overwrite.
414 	Tiling and line styling are also implemented
415 	here. All other gd drawing functions pass through this call,
416 	allowing for many useful effects. */
417 
418 void gdImageSetPixel(gdImagePtr im, int x, int y, int color);
419 
420 int gdImageGetTrueColorPixel (gdImagePtr im, int x, int y);
421 int gdImageGetPixel(gdImagePtr im, int x, int y);
422 
423 void gdImageAABlend(gdImagePtr im);
424 
425 void gdImageLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
426 void gdImageAALine(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
427 
428 /* For backwards compatibility only. Use gdImageSetStyle()
429 	for much more flexible line drawing. */
430 void gdImageDashedLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
431 /* Corners specified (not width and height). Upper left first, lower right
432  	second. */
433 void gdImageRectangle(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
434 /* Solid bar. Upper left corner first, lower right corner second. */
435 void gdImageFilledRectangle(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
436 void gdImageSetClip(gdImagePtr im, int x1, int y1, int x2, int y2);
437 void gdImageGetClip(gdImagePtr im, int *x1P, int *y1P, int *x2P, int *y2P);
438 void gdImageSetResolution(gdImagePtr im, const unsigned int res_x, const unsigned int res_y);
439 void gdImageChar(gdImagePtr im, gdFontPtr f, int x, int y, int c, int color);
440 void gdImageCharUp(gdImagePtr im, gdFontPtr f, int x, int y, int c, int color);
441 void gdImageString(gdImagePtr im, gdFontPtr f, int x, int y, unsigned char *s, int color);
442 void gdImageStringUp(gdImagePtr im, gdFontPtr f, int x, int y, unsigned char *s, int color);
443 void gdImageString16(gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color);
444 void gdImageStringUp16(gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color);
445 
446 /*
447  * The following functions are required to be called prior to the
448  * use of any sort of threads in a module load / shutdown function
449  * respectively.
450  */
451 void gdFontCacheMutexSetup(void);
452 void gdFontCacheMutexShutdown(void);
453 
454 /* 2.0.16: for thread-safe use of gdImageStringFT and friends,
455  * call this before allowing any thread to call gdImageStringFT.
456  * Otherwise it is invoked by the first thread to invoke
457  * gdImageStringFT, with a very small but real risk of a race condition.
458  * Return 0 on success, nonzero on failure to initialize freetype.
459  */
460 int gdFontCacheSetup(void);
461 
462 /* Optional: clean up after application is done using fonts in gdImageStringFT(). */
463 void gdFontCacheShutdown(void);
464 
465 /* Calls gdImageStringFT. Provided for backwards compatibility only. */
466 char *gdImageStringTTF(gdImage *im, int *brect, int fg, char *fontlist,
467                 double ptsize, double angle, int x, int y, char *string);
468 
469 /* FreeType 2 text output */
470 char *gdImageStringFT(gdImage *im, int *brect, int fg, char *fontlist,
471                 double ptsize, double angle, int x, int y, char *string);
472 
473 typedef struct {
474 	double linespacing;	/* fine tune line spacing for '\n' */
475 	int flags;		/* Logical OR of gdFTEX_ values */
476 	int charmap;		/* TBB: 2.0.12: may be gdFTEX_Unicode,
477 				   gdFTEX_Shift_JIS, gdFTEX_Big5 or gdFTEX_MacRoman;
478 				   when not specified, maps are searched
479 				   for in the above order. */
480 	int hdpi;
481 	int vdpi;
482 }
483  gdFTStringExtra, *gdFTStringExtraPtr;
484 
485 #define gdFTEX_LINESPACE 1
486 #define gdFTEX_CHARMAP 2
487 #define gdFTEX_RESOLUTION 4
488 
489 /* These are NOT flags; set one in 'charmap' if you set the gdFTEX_CHARMAP bit in 'flags'. */
490 #define gdFTEX_Unicode 0
491 #define gdFTEX_Shift_JIS 1
492 #define gdFTEX_Big5 2
493 #define gdFTEX_MacRoman 3
494 
495 /* FreeType 2 text output with fine tuning */
496 char *
497 gdImageStringFTEx(gdImage * im, int *brect, int fg, char * fontlist,
498 		double ptsize, double angle, int x, int y, char * string,
499 		gdFTStringExtraPtr strex);
500 
501 
502 /* Point type for use in polygon drawing. */
503 typedef struct {
504 	int x, y;
505 } gdPoint, *gdPointPtr;
506 
507 void gdImagePolygon(gdImagePtr im, gdPointPtr p, int n, int c);
508 void gdImageOpenPolygon(gdImagePtr im, gdPointPtr p, int n, int c);
509 void gdImageFilledPolygon(gdImagePtr im, gdPointPtr p, int n, int c);
510 
511 /* These functions still work with truecolor images,
512 	for which they never return error. */
513 int gdImageColorAllocate(gdImagePtr im, int r, int g, int b);
514 /* gd 2.0: palette entries with non-opaque transparency are permitted. */
515 int gdImageColorAllocateAlpha(gdImagePtr im, int r, int g, int b, int a);
516 /* Assumes opaque is the preferred alpha channel value */
517 int gdImageColorClosest(gdImagePtr im, int r, int g, int b);
518 /* Closest match taking all four parameters into account.
519 	A slightly different color with the same transparency
520 	beats the exact same color with radically different
521 	transparency */
522 int gdImageColorClosestAlpha(gdImagePtr im, int r, int g, int b, int a);
523 /* An alternate method */
524 int gdImageColorClosestHWB(gdImagePtr im, int r, int g, int b);
525 /* Returns exact, 100% opaque matches only */
526 int gdImageColorExact(gdImagePtr im, int r, int g, int b);
527 /* Returns an exact match only, including alpha */
528 int gdImageColorExactAlpha(gdImagePtr im, int r, int g, int b, int a);
529 /* Opaque only */
530 int gdImageColorResolve(gdImagePtr im, int r, int g, int b);
531 /* Based on gdImageColorExactAlpha and gdImageColorClosestAlpha */
532 int gdImageColorResolveAlpha(gdImagePtr im, int r, int g, int b, int a);
533 
534 /* A simpler way to obtain an opaque truecolor value for drawing on a
535 	truecolor image. Not for use with palette images! */
536 
537 #define gdTrueColor(r, g, b) (((r) << 16) + \
538 	((g) << 8) + \
539 	(b))
540 
541 /* Returns a truecolor value with an alpha channel component.
542 	gdAlphaMax (127, **NOT 255**) is transparent, 0 is completely
543 	opaque. */
544 
545 #define gdTrueColorAlpha(r, g, b, a) (((a) << 24) + \
546 	((r) << 16) + \
547 	((g) << 8) + \
548 	(b))
549 
550 void gdImageColorDeallocate(gdImagePtr im, int color);
551 
552 /* Converts a truecolor image to a palette-based image,
553 	using a high-quality two-pass quantization routine
554 	which attempts to preserve alpha channel information
555 	as well as R/G/B color information when creating
556 	a palette. If ditherFlag is set, the image will be
557 	dithered to approximate colors better, at the expense
558 	of some obvious "speckling." colorsWanted can be
559 	anything up to 256. If the original source image
560 	includes photographic information or anything that
561 	came out of a JPEG, 256 is strongly recommended.
562 
563 	Better yet, don't use this function -- write real
564 	truecolor PNGs and JPEGs. The disk space gain of
565         conversion to palette is not great (for small images
566         it can be negative) and the quality loss is ugly. */
567 
568 gdImagePtr gdImageCreatePaletteFromTrueColor (gdImagePtr im, int ditherFlag, int colorsWanted);
569 
570 int gdImageTrueColorToPalette(gdImagePtr im, int ditherFlag, int colorsWanted);
571 int gdImagePaletteToTrueColor(gdImagePtr src);
572 
573 /* An attempt at getting the results of gdImageTrueColorToPalette
574 	to look a bit more like the original (im1 is the original
575 	and im2 is the palette version */
576 int gdImageColorMatch(gdImagePtr im1, gdImagePtr im2);
577 
578 /* Specifies a color index (if a palette image) or an
579 	RGB color (if a truecolor image) which should be
580 	considered 100% transparent. FOR TRUECOLOR IMAGES,
581 	THIS IS IGNORED IF AN ALPHA CHANNEL IS BEING
582 	SAVED. Use gdImageSaveAlpha(im, 0); to
583 	turn off the saving of a full alpha channel in
584 	a truecolor image. Note that gdImageColorTransparent
585 	is usually compatible with older browsers that
586 	do not understand full alpha channels well. TBB */
587 void gdImageColorTransparent(gdImagePtr im, int color);
588 
589 void gdImagePaletteCopy(gdImagePtr dst, gdImagePtr src);
590 void gdImagePng(gdImagePtr im, FILE *out);
591 void gdImagePngCtx(gdImagePtr im, gdIOCtx *out);
592 void gdImageGif(gdImagePtr im, FILE *out);
593 void gdImageGifCtx(gdImagePtr im, gdIOCtx *out);
594 
595 void * gdImageBmpPtr(gdImagePtr im, int *size, int compression);
596 void gdImageBmp(gdImagePtr im, FILE *outFile, int compression);
597 void gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression);
598 
599 /* 2.0.12: Compression level: 0-9 or -1, where 0 is NO COMPRESSION at all,
600  * 1 is FASTEST but produces larger files, 9 provides the best
601  * compression (smallest files) but takes a long time to compress, and
602  * -1 selects the default compiled into the zlib library.
603  */
604 void gdImagePngEx(gdImagePtr im, FILE * out, int level, int basefilter);
605 void gdImagePngCtxEx(gdImagePtr im, gdIOCtx * out, int level, int basefilter);
606 
607 void gdImageWBMP(gdImagePtr image, int fg, FILE *out);
608 void gdImageWBMPCtx(gdImagePtr image, int fg, gdIOCtx *out);
609 
610 /* Guaranteed to correctly free memory returned
611 	by the gdImage*Ptr functions */
612 void gdFree(void *m);
613 
614 /* Best to free this memory with gdFree(), not free() */
615 void *gdImageWBMPPtr(gdImagePtr im, int *size, int fg);
616 
617 /* 100 is highest quality (there is always a little loss with JPEG).
618        0 is lowest. 10 is about the lowest useful setting. */
619 void gdImageJpeg(gdImagePtr im, FILE *out, int quality);
620 void gdImageJpegCtx(gdImagePtr im, gdIOCtx *out, int quality);
621 
622 /**
623  * Group: WebP
624  *
625  * Constant: gdWebpLossless
626  *
627  * Lossless quality threshold. When image quality is greater than or equal to
628  * <gdWebpLossless>, the image will be written in the lossless WebP format.
629  *
630  * See also:
631  *   - <gdImageWebpCtx>
632  */
633 #define gdWebpLossless 101
634 
635 void gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quality);
636 
637 /* Best to free this memory with gdFree(), not free() */
638 void *gdImageJpegPtr(gdImagePtr im, int *size, int quality);
639 
640 gdImagePtr gdImageCreateFromGif(FILE *fd);
641 gdImagePtr gdImageCreateFromGifCtx(gdIOCtxPtr in);
642 gdImagePtr gdImageCreateFromGifSource(gdSourcePtr in);
643 
644 void gdImageAvif(gdImagePtr im, FILE *outfile);
645 void gdImageAvifEx(gdImagePtr im, FILE *outfile, int quality, int speed);
646 void *gdImageAvifPtr(gdImagePtr im, int *size);
647 void *gdImageAvifPtrEx(gdImagePtr im, int *size, int quality, int speed);
648 void gdImageAvifCtx(gdImagePtr im, gdIOCtx *outfile, int quality, int speed);
649 
650 /* A custom data sink. For backwards compatibility. Use
651 	gdIOCtx instead. */
652 /* The sink function must return -1 on error, otherwise the number
653         of bytes written, which must be equal to len. */
654 /* context will be passed to your sink function. */
655 typedef struct {
656         int (*sink) (void *context, const char *buffer, int len);
657         void *context;
658 } gdSink, *gdSinkPtr;
659 
660 void gdImagePngToSink(gdImagePtr im, gdSinkPtr out);
661 
662 void gdImageGd(gdImagePtr im, FILE *out);
663 void gdImageGd2(gdImagePtr im, FILE *out, int cs, int fmt);
664 
665 /* Best to free this memory with gdFree(), not free() */
666 void* gdImagePngPtr(gdImagePtr im, int *size);
667 
668 /* Best to free this memory with gdFree(), not free() */
669 void* gdImageGdPtr(gdImagePtr im, int *size);
670 void *gdImagePngPtrEx(gdImagePtr im, int *size, int level, int basefilter);
671 
672 /* Best to free this memory with gdFree(), not free() */
673 void* gdImageGd2Ptr(gdImagePtr im, int cs, int fmt, int *size);
674 
675 void gdImageEllipse(gdImagePtr im, int cx, int cy, int w, int h, int c);
676 
677 /* Style is a bitwise OR ( | operator ) of these.
678 	gdArc and gdChord are mutually exclusive;
679 	gdChord just connects the starting and ending
680 	angles with a straight line, while gdArc produces
681 	a rounded edge. gdPie is a synonym for gdArc.
682 	gdNoFill indicates that the arc or chord should be
683 	outlined, not filled. gdEdged, used together with
684 	gdNoFill, indicates that the beginning and ending
685 	angles should be connected to the center; this is
686 	a good way to outline (rather than fill) a
687 	'pie slice'. */
688 #define gdArc   0
689 #define gdPie   gdArc
690 #define gdChord 1
691 #define gdNoFill 2
692 #define gdEdged 4
693 
694 void gdImageFilledArc(gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color, int style);
695 void gdImageArc(gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color);
696 void gdImageFilledEllipse(gdImagePtr im, int cx, int cy, int w, int h, int color);
697 void gdImageFillToBorder(gdImagePtr im, int x, int y, int border, int color);
698 void gdImageFill(gdImagePtr im, int x, int y, int color);
699 void gdImageCopy(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h);
700 void gdImageCopyMerge(gdImagePtr dst, gdImagePtr src, int dstX, int dstY,
701 			int srcX, int srcY, int w, int h, int pct);
702 void gdImageCopyMergeGray(gdImagePtr dst, gdImagePtr src, int dstX, int dstY,
703                         int srcX, int srcY, int w, int h, int pct);
704 
705 /* Stretches or shrinks to fit, as needed. Does NOT attempt
706 	to average the entire set of source pixels that scale down onto the
707 	destination pixel. */
708 void gdImageCopyResized(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH);
709 
710 /* gd 2.0: stretches or shrinks to fit, as needed. When called with a
711 	truecolor destination image, this function averages the
712 	entire set of source pixels that scale down onto the
713 	destination pixel, taking into account what portion of the
714 	destination pixel each source pixel represents. This is a
715 	floating point operation, but this is not a performance issue
716 	on modern hardware, except for some embedded devices. If the
717 	destination is a palette image, gdImageCopyResized is
718 	substituted automatically. */
719 void gdImageCopyResampled(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH);
720 
721 gdImagePtr gdImageRotate90(gdImagePtr src, int ignoretransparent);
722 gdImagePtr gdImageRotate180(gdImagePtr src, int ignoretransparent);
723 gdImagePtr gdImageRotate270(gdImagePtr src, int ignoretransparent);
724 gdImagePtr gdImageRotateInterpolated(const gdImagePtr src, const float angle, int bgcolor);
725 
726 void gdImageSetBrush(gdImagePtr im, gdImagePtr brush);
727 void gdImageSetTile(gdImagePtr im, gdImagePtr tile);
728 void gdImageSetAntiAliased(gdImagePtr im, int c);
729 void gdImageSetAntiAliasedDontBlend(gdImagePtr im, int c, int dont_blend);
730 void gdImageSetStyle(gdImagePtr im, int *style, int noOfPixels);
731 /* Line thickness (defaults to 1). Affects lines, ellipses,
732 	rectangles, polygons and so forth. */
733 void gdImageSetThickness(gdImagePtr im, int thickness);
734 /* On or off (1 or 0) for all three of these. */
735 void gdImageInterlace(gdImagePtr im, int interlaceArg);
736 void gdImageAlphaBlending(gdImagePtr im, int alphaBlendingArg);
737 void gdImageAntialias(gdImagePtr im, int antialias);
738 void gdImageSaveAlpha(gdImagePtr im, int saveAlphaArg);
739 
740 enum gdPixelateMode {
741 	GD_PIXELATE_UPPERLEFT,
742 	GD_PIXELATE_AVERAGE
743 };
744 
745 int gdImagePixelate(gdImagePtr im, int block_size, const unsigned int mode);
746 
747 typedef struct {
748 	int sub;
749 	int plus;
750 	unsigned int num_colors;
751 	int *colors;
752 	unsigned int seed;
753 } gdScatter, *gdScatterPtr;
754 
755 int gdImageScatter(gdImagePtr im, int sub, int plus);
756 int gdImageScatterColor(gdImagePtr im, int sub, int plus, int colors[], unsigned int num_colors);
757 int gdImageScatterEx(gdImagePtr im, gdScatterPtr s);
758 
759 /* Macros to access information about images. */
760 
761 /* Returns nonzero if the image is a truecolor image,
762 	zero for a palette image. */
763 
764 #define gdImageTrueColor(im) ((im)->trueColor)
765 
766 #define gdImageSX(im) ((im)->sx)
767 #define gdImageSY(im) ((im)->sy)
768 #define gdImageColorsTotal(im) ((im)->colorsTotal)
769 #define gdImageRed(im, c) ((im)->trueColor ? gdTrueColorGetRed(c) : \
770 	(im)->red[(c)])
771 #define gdImageGreen(im, c) ((im)->trueColor ? gdTrueColorGetGreen(c) : \
772 	(im)->green[(c)])
773 #define gdImageBlue(im, c) ((im)->trueColor ? gdTrueColorGetBlue(c) : \
774 	(im)->blue[(c)])
775 #define gdImageAlpha(im, c) ((im)->trueColor ? gdTrueColorGetAlpha(c) : \
776 	(im)->alpha[(c)])
777 #define gdImageGetTransparent(im) ((im)->transparent)
778 #define gdImageGetInterlaced(im) ((im)->interlace)
779 
780 /* These macros provide direct access to pixels in
781 	palette-based and truecolor images, respectively.
782 	If you use these macros, you must perform your own
783 	bounds checking. Use of the macro for the correct type
784 	of image is also your responsibility. */
785 #define gdImagePalettePixel(im, x, y) (im)->pixels[(y)][(x)]
786 #define gdImageTrueColorPixel(im, x, y) (im)->tpixels[(y)][(x)]
787 #define gdImageResolutionX(im) (im)->res_x
788 #define gdImageResolutionY(im) (im)->res_y
789 
790 /* I/O Support routines. */
791 
792 gdIOCtx* gdNewFileCtx(FILE*);
793 gdIOCtx* gdNewDynamicCtx(int, void*);
794 gdIOCtx *gdNewDynamicCtxEx(int size, void *data, int freeFlag);
795 gdIOCtx* gdNewSSCtx(gdSourcePtr in, gdSinkPtr out);
796 void* gdDPExtractData(struct gdIOCtx* ctx, int *size);
797 
798 #define GD2_CHUNKSIZE           128
799 #define GD2_CHUNKSIZE_MIN	64
800 #define GD2_CHUNKSIZE_MAX       4096
801 
802 #define GD2_VERS                2
803 #define GD2_ID                  "gd2"
804 #define GD2_FMT_RAW             1
805 #define GD2_FMT_COMPRESSED      2
806 
807 
808 /* filters section
809  *
810  * Negate the imag src, white becomes black,
811  * The red, green, and blue intensities of an image are negated.
812  * White becomes black, yellow becomes blue, etc.
813  */
814 int gdImageNegate(gdImagePtr src);
815 
816 /* Convert the image src to a grayscale image */
817 int gdImageGrayScale(gdImagePtr src);
818 
819 /* Set the brightness level <brightness> for the image src */
820 int gdImageBrightness(gdImagePtr src, int brightness);
821 
822 /* Set the contrast level <contrast> for the image <src> */
823 int gdImageContrast(gdImagePtr src, double contrast);
824 
825 /* Simply adds or subtracts respectively red, green or blue to a pixel */
826 int gdImageColor(gdImagePtr src, const int red, const int green, const int blue, const int alpha);
827 
828 /* Image convolution by a 3x3 custom matrix */
829 int gdImageConvolution(gdImagePtr src, float ft[3][3], float filter_div, float offset);
830 
831 int gdImageEdgeDetectQuick(gdImagePtr src);
832 
833 int gdImageGaussianBlur(gdImagePtr im);
834 
835 int gdImageSelectiveBlur( gdImagePtr src);
836 
837 int gdImageEmboss(gdImagePtr im);
838 
839 int gdImageMeanRemoval(gdImagePtr im);
840 
841 int gdImageSmooth(gdImagePtr im, float weight);
842 
843 /* Image comparison definitions */
844 int gdImageCompare(gdImagePtr im1, gdImagePtr im2);
845 
846 void gdImageFlipHorizontal(gdImagePtr im);
847 void gdImageFlipVertical(gdImagePtr im);
848 void gdImageFlipBoth(gdImagePtr im);
849 
850 #define GD_FLIP_HORIZONTAL 1
851 #define GD_FLIP_VERTICAL 2
852 #define GD_FLIP_BOTH 3
853 
854 /**
855  * Group: Crop
856  *
857  * Constants: gdCropMode
858  *  GD_CROP_DEFAULT - Default crop mode (4 corners or background)
859  *  GD_CROP_TRANSPARENT - Crop using the transparent color
860  *  GD_CROP_BLACK - Crop black borders
861  *  GD_CROP_WHITE - Crop white borders
862  *  GD_CROP_SIDES - Crop using colors of the 4 corners
863  *
864  * See also:
865  *  <gdImageAutoCrop>
866  **/
867 enum gdCropMode {
868 	GD_CROP_DEFAULT = 0,
869 	GD_CROP_TRANSPARENT,
870 	GD_CROP_BLACK,
871 	GD_CROP_WHITE,
872 	GD_CROP_SIDES,
873 	GD_CROP_THRESHOLD
874 };
875 
876 gdImagePtr gdImageCrop(gdImagePtr src, const gdRectPtr crop);
877 gdImagePtr gdImageCropAuto(gdImagePtr im, const unsigned int mode);
878 gdImagePtr gdImageCropThreshold(gdImagePtr im, const unsigned int color, const float threshold);
879 
880 int gdImageSetInterpolationMethod(gdImagePtr im, gdInterpolationMethod id);
881 
882 gdImagePtr gdImageScaleBilinear(gdImagePtr im, const unsigned int new_width, const unsigned int new_height);
883 gdImagePtr gdImageScaleBicubic(gdImagePtr src_img, const unsigned int new_width, const unsigned int new_height);
884 gdImagePtr gdImageScaleBicubicFixed(gdImagePtr src, const unsigned int width, const unsigned int height);
885 gdImagePtr gdImageScaleNearestNeighbour(gdImagePtr im, const unsigned int width, const unsigned int height);
886 gdImagePtr gdImageScaleTwoPass(const gdImagePtr pOrigImage, const unsigned int uOrigWidth, const unsigned int uOrigHeight, const unsigned int uNewWidth, const unsigned int uNewHeight);
887 gdImagePtr gdImageScale(const gdImagePtr src, const unsigned int new_width, const unsigned int new_height);
888 
889 gdImagePtr gdImageRotateNearestNeighbour(gdImagePtr src, const float degrees, const int bgColor);
890 gdImagePtr gdImageRotateBilinear(gdImagePtr src, const float degrees, const int bgColor);
891 gdImagePtr gdImageRotateBicubicFixed(gdImagePtr src, const float degrees, const int bgColor);
892 gdImagePtr gdImageRotateGeneric(gdImagePtr src, const float degrees, const int bgColor);
893 gdImagePtr gdImageRotateInterpolated(const gdImagePtr src, const float angle, int bgcolor);
894 
895 typedef enum {
896 	GD_AFFINE_TRANSLATE = 0,
897 	GD_AFFINE_SCALE,
898 	GD_AFFINE_ROTATE,
899 	GD_AFFINE_SHEAR_HORIZONTAL,
900 	GD_AFFINE_SHEAR_VERTICAL,
901 } gdAffineStandardMatrix;
902 
903 int gdAffineApplyToPointF (gdPointFPtr dst, const gdPointFPtr src, const double affine[6]);
904 int gdAffineInvert (double dst[6], const double src[6]);
905 int gdAffineFlip (double dst_affine[6], const double src_affine[6], const int flip_h, const int flip_v);
906 int gdAffineConcat (double dst[6], const double m1[6], const double m2[6]);
907 
908 int gdAffineIdentity (double dst[6]);
909 int gdAffineScale (double dst[6], const double scale_x, const double scale_y);
910 int gdAffineRotate (double dst[6], const double angle);
911 int gdAffineShearHorizontal (double dst[6], const double angle);
912 int gdAffineShearVertical(double dst[6], const double angle);
913 int gdAffineTranslate (double dst[6], const double offset_x, const double offset_y);
914 double gdAffineExpansion (const double src[6]);
915 int gdAffineRectilinear (const double src[6]);
916 int gdAffineEqual (const double matrix1[6], const double matrix2[6]);
917 int gdTransformAffineGetImage(gdImagePtr *dst, const gdImagePtr src, gdRectPtr src_area, const double affine[6]);
918 int gdTransformAffineCopy(gdImagePtr dst, int dst_x, int dst_y, const gdImagePtr src, gdRectPtr src_region, const double affine[6]);
919 /*
920 gdTransformAffineCopy(gdImagePtr dst, int x0, int y0, int x1, int y1,
921 			const gdImagePtr src, int src_width, int src_height,
922 			const double affine[6]);
923 */
924 int gdTransformAffineBoundingBox(gdRectPtr src, const double affine[6], gdRectPtr bbox);
925 
926 
927 #define GD_CMP_IMAGE		1	/* Actual image IS different */
928 #define GD_CMP_NUM_COLORS	2	/* Number of Colours in palette differ */
929 #define GD_CMP_COLOR		4	/* Image colours differ */
930 #define GD_CMP_SIZE_X		8	/* Image width differs */
931 #define GD_CMP_SIZE_Y		16	/* Image heights differ */
932 #define GD_CMP_TRANSPARENT	32	/* Transparent colour */
933 #define GD_CMP_BACKGROUND	64	/* Background colour */
934 #define GD_CMP_INTERLACE	128	/* Interlaced setting */
935 #define GD_CMP_TRUECOLOR	256	/* Truecolor vs palette differs */
936 
937 /* resolution affects ttf font rendering, particularly hinting */
938 #define GD_RESOLUTION           96      /* pixels per inch */
939 
940 #ifdef __cplusplus
941 }
942 #endif
943 
944 /* 2.0.12: this now checks the clipping rectangle */
945 #define gdImageBoundsSafe(im, x, y) (!((((y) < (im)->cy1) || ((y) > (im)->cy2)) || (((x) < (im)->cx1) || ((x) > (im)->cx2))))
946 
947 #endif /* GD_H */
948