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