gd.h 34 KB

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