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, or gdFTEX_Big5; 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 491 /* FreeType 2 text output with fine tuning */ 492 char * 493 gdImageStringFTEx(gdImage * im, int *brect, int fg, char * fontlist, 494 double ptsize, double angle, int x, int y, char * string, 495 gdFTStringExtraPtr strex); 496 497 498 /* Point type for use in polygon drawing. */ 499 typedef struct { 500 int x, y; 501 } gdPoint, *gdPointPtr; 502 503 void gdImagePolygon(gdImagePtr im, gdPointPtr p, int n, int c); 504 void gdImageFilledPolygon(gdImagePtr im, gdPointPtr p, int n, int c); 505 506 /* These functions still work with truecolor images, 507 for which they never return error. */ 508 int gdImageColorAllocate(gdImagePtr im, int r, int g, int b); 509 /* gd 2.0: palette entries with non-opaque transparency are permitted. */ 510 int gdImageColorAllocateAlpha(gdImagePtr im, int r, int g, int b, int a); 511 /* Assumes opaque is the preferred alpha channel value */ 512 int gdImageColorClosest(gdImagePtr im, int r, int g, int b); 513 /* Closest match taking all four parameters into account. 514 A slightly different color with the same transparency 515 beats the exact same color with radically different 516 transparency */ 517 int gdImageColorClosestAlpha(gdImagePtr im, int r, int g, int b, int a); 518 /* An alternate method */ 519 int gdImageColorClosestHWB(gdImagePtr im, int r, int g, int b); 520 /* Returns exact, 100% opaque matches only */ 521 int gdImageColorExact(gdImagePtr im, int r, int g, int b); 522 /* Returns an exact match only, including alpha */ 523 int gdImageColorExactAlpha(gdImagePtr im, int r, int g, int b, int a); 524 /* Opaque only */ 525 int gdImageColorResolve(gdImagePtr im, int r, int g, int b); 526 /* Based on gdImageColorExactAlpha and gdImageColorClosestAlpha */ 527 int gdImageColorResolveAlpha(gdImagePtr im, int r, int g, int b, int a); 528 529 /* A simpler way to obtain an opaque truecolor value for drawing on a 530 truecolor image. Not for use with palette images! */ 531 532 #define gdTrueColor(r, g, b) (((r) << 16) + \ 533 ((g) << 8) + \ 534 (b)) 535 536 /* Returns a truecolor value with an alpha channel component. 537 gdAlphaMax (127, **NOT 255**) is transparent, 0 is completely 538 opaque. */ 539 540 #define gdTrueColorAlpha(r, g, b, a) (((a) << 24) + \ 541 ((r) << 16) + \ 542 ((g) << 8) + \ 543 (b)) 544 545 void gdImageColorDeallocate(gdImagePtr im, int color); 546 547 /* Converts a truecolor image to a palette-based image, 548 using a high-quality two-pass quantization routine 549 which attempts to preserve alpha channel information 550 as well as R/G/B color information when creating 551 a palette. If ditherFlag is set, the image will be 552 dithered to approximate colors better, at the expense 553 of some obvious "speckling." colorsWanted can be 554 anything up to 256. If the original source image 555 includes photographic information or anything that 556 came out of a JPEG, 256 is strongly recommended. 557 558 Better yet, don't use this function -- write real 559 truecolor PNGs and JPEGs. The disk space gain of 560 conversion to palette is not great (for small images 561 it can be negative) and the quality loss is ugly. */ 562 563 gdImagePtr gdImageCreatePaletteFromTrueColor (gdImagePtr im, int ditherFlag, int colorsWanted); 564 565 void gdImageTrueColorToPalette(gdImagePtr im, int ditherFlag, int colorsWanted); 566 int gdImagePaletteToTrueColor(gdImagePtr src); 567 568 /* An attempt at getting the results of gdImageTrueColorToPalette 569 to look a bit more like the original (im1 is the original 570 and im2 is the palette version */ 571 int gdImageColorMatch(gdImagePtr im1, gdImagePtr im2); 572 573 /* Specifies a color index (if a palette image) or an 574 RGB color (if a truecolor image) which should be 575 considered 100% transparent. FOR TRUECOLOR IMAGES, 576 THIS IS IGNORED IF AN ALPHA CHANNEL IS BEING 577 SAVED. Use gdImageSaveAlpha(im, 0); to 578 turn off the saving of a full alpha channel in 579 a truecolor image. Note that gdImageColorTransparent 580 is usually compatible with older browsers that 581 do not understand full alpha channels well. TBB */ 582 void gdImageColorTransparent(gdImagePtr im, int color); 583 584 void gdImagePaletteCopy(gdImagePtr dst, gdImagePtr src); 585 void gdImagePng(gdImagePtr im, FILE *out); 586 void gdImagePngCtx(gdImagePtr im, gdIOCtx *out); 587 void gdImageGif(gdImagePtr im, FILE *out); 588 void gdImageGifCtx(gdImagePtr im, gdIOCtx *out); 589 /* 2.0.12: Compression level: 0-9 or -1, where 0 is NO COMPRESSION at all, 590 * 1 is FASTEST but produces larger files, 9 provides the best 591 * compression (smallest files) but takes a long time to compress, and 592 * -1 selects the default compiled into the zlib library. 593 */ 594 void gdImagePngEx(gdImagePtr im, FILE * out, int level, int basefilter); 595 void gdImagePngCtxEx(gdImagePtr im, gdIOCtx * out, int level, int basefilter); 596 597 void gdImageWBMP(gdImagePtr image, int fg, FILE *out); 598 void gdImageWBMPCtx(gdImagePtr image, int fg, gdIOCtx *out); 599 600 /* Guaranteed to correctly free memory returned 601 by the gdImage*Ptr functions */ 602 void gdFree(void *m); 603 604 /* Best to free this memory with gdFree(), not free() */ 605 void *gdImageWBMPPtr(gdImagePtr im, int *size, int fg); 606 607 /* 100 is highest quality (there is always a little loss with JPEG). 608 0 is lowest. 10 is about the lowest useful setting. */ 609 void gdImageJpeg(gdImagePtr im, FILE *out, int quality); 610 void gdImageJpegCtx(gdImagePtr im, gdIOCtx *out, int quality); 611 612 void gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quantization); 613 614 /* Best to free this memory with gdFree(), not free() */ 615 void *gdImageJpegPtr(gdImagePtr im, int *size, int quality); 616 617 gdImagePtr gdImageCreateFromGif(FILE *fd); 618 gdImagePtr gdImageCreateFromGifCtx(gdIOCtxPtr in); 619 gdImagePtr gdImageCreateFromGifSource(gdSourcePtr in); 620 621 /* A custom data sink. For backwards compatibility. Use 622 gdIOCtx instead. */ 623 /* The sink function must return -1 on error, otherwise the number 624 of bytes written, which must be equal to len. */ 625 /* context will be passed to your sink function. */ 626 typedef struct { 627 int (*sink) (void *context, const char *buffer, int len); 628 void *context; 629 } gdSink, *gdSinkPtr; 630 631 void gdImagePngToSink(gdImagePtr im, gdSinkPtr out); 632 633 void gdImageGd(gdImagePtr im, FILE *out); 634 void gdImageGd2(gdImagePtr im, FILE *out, int cs, int fmt); 635 636 /* Best to free this memory with gdFree(), not free() */ 637 void* gdImagePngPtr(gdImagePtr im, int *size); 638 639 /* Best to free this memory with gdFree(), not free() */ 640 void* gdImageGdPtr(gdImagePtr im, int *size); 641 void *gdImagePngPtrEx(gdImagePtr im, int *size, int level, int basefilter); 642 643 /* Best to free this memory with gdFree(), not free() */ 644 void* gdImageGd2Ptr(gdImagePtr im, int cs, int fmt, int *size); 645 646 void gdImageEllipse(gdImagePtr im, int cx, int cy, int w, int h, int c); 647 648 /* Style is a bitwise OR ( | operator ) of these. 649 gdArc and gdChord are mutually exclusive; 650 gdChord just connects the starting and ending 651 angles with a straight line, while gdArc produces 652 a rounded edge. gdPie is a synonym for gdArc. 653 gdNoFill indicates that the arc or chord should be 654 outlined, not filled. gdEdged, used together with 655 gdNoFill, indicates that the beginning and ending 656 angles should be connected to the center; this is 657 a good way to outline (rather than fill) a 658 'pie slice'. */ 659 #define gdArc 0 660 #define gdPie gdArc 661 #define gdChord 1 662 #define gdNoFill 2 663 #define gdEdged 4 664 665 void gdImageFilledArc(gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color, int style); 666 void gdImageArc(gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color); 667 void gdImageFilledEllipse(gdImagePtr im, int cx, int cy, int w, int h, int color); 668 void gdImageFillToBorder(gdImagePtr im, int x, int y, int border, int color); 669 void gdImageFill(gdImagePtr im, int x, int y, int color); 670 void gdImageCopy(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h); 671 void gdImageCopyMerge(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, 672 int srcX, int srcY, int w, int h, int pct); 673 void gdImageCopyMergeGray(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, 674 int srcX, int srcY, int w, int h, int pct); 675 676 /* Stretches or shrinks to fit, as needed. Does NOT attempt 677 to average the entire set of source pixels that scale down onto the 678 destination pixel. */ 679 void gdImageCopyResized(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH); 680 681 /* gd 2.0: stretches or shrinks to fit, as needed. When called with a 682 truecolor destination image, this function averages the 683 entire set of source pixels that scale down onto the 684 destination pixel, taking into account what portion of the 685 destination pixel each source pixel represents. This is a 686 floating point operation, but this is not a performance issue 687 on modern hardware, except for some embedded devices. If the 688 destination is a palette image, gdImageCopyResized is 689 substituted automatically. */ 690 void gdImageCopyResampled(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH); 691 692 gdImagePtr gdImageRotate90(gdImagePtr src, int ignoretransparent); 693 gdImagePtr gdImageRotate180(gdImagePtr src, int ignoretransparent); 694 gdImagePtr gdImageRotate270(gdImagePtr src, int ignoretransparent); 695 gdImagePtr gdImageRotate45(gdImagePtr src, double dAngle, int clrBack, int ignoretransparent); 696 gdImagePtr gdImageRotate (gdImagePtr src, double dAngle, int clrBack, int ignoretransparent); 697 gdImagePtr gdImageRotateInterpolated(const gdImagePtr src, const float angle, int bgcolor); 698 699 void gdImageSetBrush(gdImagePtr im, gdImagePtr brush); 700 void gdImageSetTile(gdImagePtr im, gdImagePtr tile); 701 void gdImageSetAntiAliased(gdImagePtr im, int c); 702 void gdImageSetAntiAliasedDontBlend(gdImagePtr im, int c, int dont_blend); 703 void gdImageSetStyle(gdImagePtr im, int *style, int noOfPixels); 704 /* Line thickness (defaults to 1). Affects lines, ellipses, 705 rectangles, polygons and so forth. */ 706 void gdImageSetThickness(gdImagePtr im, int thickness); 707 /* On or off (1 or 0) for all three of these. */ 708 void gdImageInterlace(gdImagePtr im, int interlaceArg); 709 void gdImageAlphaBlending(gdImagePtr im, int alphaBlendingArg); 710 void gdImageAntialias(gdImagePtr im, int antialias); 711 void gdImageSaveAlpha(gdImagePtr im, int saveAlphaArg); 712 713 enum gdPixelateMode { 714 GD_PIXELATE_UPPERLEFT, 715 GD_PIXELATE_AVERAGE 716 }; 717 718 int gdImagePixelate(gdImagePtr im, int block_size, const unsigned int mode); 719 720 /* Macros to access information about images. */ 721 722 /* Returns nonzero if the image is a truecolor image, 723 zero for a palette image. */ 724 725 #define gdImageTrueColor(im) ((im)->trueColor) 726 727 #define gdImageSX(im) ((im)->sx) 728 #define gdImageSY(im) ((im)->sy) 729 #define gdImageColorsTotal(im) ((im)->colorsTotal) 730 #define gdImageRed(im, c) ((im)->trueColor ? gdTrueColorGetRed(c) : \ 731 (im)->red[(c)]) 732 #define gdImageGreen(im, c) ((im)->trueColor ? gdTrueColorGetGreen(c) : \ 733 (im)->green[(c)]) 734 #define gdImageBlue(im, c) ((im)->trueColor ? gdTrueColorGetBlue(c) : \ 735 (im)->blue[(c)]) 736 #define gdImageAlpha(im, c) ((im)->trueColor ? gdTrueColorGetAlpha(c) : \ 737 (im)->alpha[(c)]) 738 #define gdImageGetTransparent(im) ((im)->transparent) 739 #define gdImageGetInterlaced(im) ((im)->interlace) 740 741 /* These macros provide direct access to pixels in 742 palette-based and truecolor images, respectively. 743 If you use these macros, you must perform your own 744 bounds checking. Use of the macro for the correct type 745 of image is also your responsibility. */ 746 #define gdImagePalettePixel(im, x, y) (im)->pixels[(y)][(x)] 747 #define gdImageTrueColorPixel(im, x, y) (im)->tpixels[(y)][(x)] 748 749 /* I/O Support routines. */ 750 751 gdIOCtx* gdNewFileCtx(FILE*); 752 gdIOCtx* gdNewDynamicCtx(int, void*); 753 gdIOCtx *gdNewDynamicCtxEx(int size, void *data, int freeFlag); 754 gdIOCtx* gdNewSSCtx(gdSourcePtr in, gdSinkPtr out); 755 void* gdDPExtractData(struct gdIOCtx* ctx, int *size); 756 757 #define GD2_CHUNKSIZE 128 758 #define GD2_CHUNKSIZE_MIN 64 759 #define GD2_CHUNKSIZE_MAX 4096 760 761 #define GD2_VERS 2 762 #define GD2_ID "gd2" 763 #define GD2_FMT_RAW 1 764 #define GD2_FMT_COMPRESSED 2 765 766 767 /* filters section 768 * 769 * Negate the imag src, white becomes black, 770 * The red, green, and blue intensities of an image are negated. 771 * White becomes black, yellow becomes blue, etc. 772 */ 773 int gdImageNegate(gdImagePtr src); 774 775 /* Convert the image src to a grayscale image */ 776 int gdImageGrayScale(gdImagePtr src); 777 778 /* Set the brightness level <brightness> for the image src */ 779 int gdImageBrightness(gdImagePtr src, int brightness); 780 781 /* Set the contrast level <contrast> for the image <src> */ 782 int gdImageContrast(gdImagePtr src, double contrast); 783 784 /* Simply adds or substracts respectively red, green or blue to a pixel */ 785 int gdImageColor(gdImagePtr src, const int red, const int green, const int blue, const int alpha); 786 787 /* Image convolution by a 3x3 custom matrix */ 788 int gdImageConvolution(gdImagePtr src, float ft[3][3], float filter_div, float offset); 789 790 int gdImageEdgeDetectQuick(gdImagePtr src); 791 792 int gdImageGaussianBlur(gdImagePtr im); 793 794 int gdImageSelectiveBlur( gdImagePtr src); 795 796 int gdImageEmboss(gdImagePtr im); 797 798 int gdImageMeanRemoval(gdImagePtr im); 799 800 int gdImageSmooth(gdImagePtr im, float weight); 801 802 /* Image comparison definitions */ 803 int gdImageCompare(gdImagePtr im1, gdImagePtr im2); 804 805 void gdImageFlipHorizontal(gdImagePtr im); 806 void gdImageFlipVertical(gdImagePtr im); 807 void gdImageFlipBoth(gdImagePtr im); 808 809 #define GD_FLIP_HORINZONTAL 1 810 #define GD_FLIP_VERTICAL 2 811 #define GD_FLIP_BOTH 3 812 813 /** 814 * Group: Crop 815 * 816 * Constants: gdCropMode 817 * GD_CROP_DEFAULT - Default crop mode (4 corners or background) 818 * GD_CROP_TRANSPARENT - Crop using the transparent color 819 * GD_CROP_BLACK - Crop black borders 820 * GD_CROP_WHITE - Crop white borders 821 * GD_CROP_SIDES - Crop using colors of the 4 corners 822 * 823 * See also: 824 * <gdImageAutoCrop> 825 **/ 826 enum gdCropMode { 827 GD_CROP_DEFAULT = 0, 828 GD_CROP_TRANSPARENT, 829 GD_CROP_BLACK, 830 GD_CROP_WHITE, 831 GD_CROP_SIDES, 832 GD_CROP_THRESHOLD 833 }; 834 835 gdImagePtr gdImageCrop(gdImagePtr src, const gdRectPtr crop); 836 gdImagePtr gdImageCropAuto(gdImagePtr im, const unsigned int mode); 837 gdImagePtr gdImageCropThreshold(gdImagePtr im, const unsigned int color, const float threshold); 838 839 int gdImageSetInterpolationMethod(gdImagePtr im, gdInterpolationMethod id); 840 841 gdImagePtr gdImageScaleBilinear(gdImagePtr im, const unsigned int new_width, const unsigned int new_height); 842 gdImagePtr gdImageScaleBicubic(gdImagePtr src_img, const unsigned int new_width, const unsigned int new_height); 843 gdImagePtr gdImageScaleBicubicFixed(gdImagePtr src, const unsigned int width, const unsigned int height); 844 gdImagePtr gdImageScaleNearestNeighbour(gdImagePtr im, const unsigned int width, const unsigned int height); 845 gdImagePtr gdImageScaleTwoPass(const gdImagePtr pOrigImage, const unsigned int uOrigWidth, const unsigned int uOrigHeight, const unsigned int uNewWidth, const unsigned int uNewHeight); 846 gdImagePtr gdImageScale(const gdImagePtr src, const unsigned int new_width, const unsigned int new_height); 847 848 gdImagePtr gdImageRotateNearestNeighbour(gdImagePtr src, const float degrees, const int bgColor); 849 gdImagePtr gdImageRotateBilinear(gdImagePtr src, const float degrees, const int bgColor); 850 gdImagePtr gdImageRotateBicubicFixed(gdImagePtr src, const float degrees, const int bgColor); 851 gdImagePtr gdImageRotateGeneric(gdImagePtr src, const float degrees, const int bgColor); 852 853 854 855 typedef enum { 856 GD_AFFINE_TRANSLATE = 0, 857 GD_AFFINE_SCALE, 858 GD_AFFINE_ROTATE, 859 GD_AFFINE_SHEAR_HORIZONTAL, 860 GD_AFFINE_SHEAR_VERTICAL, 861 } gdAffineStandardMatrix; 862 863 int gdAffineApplyToPointF (gdPointFPtr dst, const gdPointFPtr src, const double affine[6]); 864 int gdAffineInvert (double dst[6], const double src[6]); 865 int gdAffineFlip (double dst_affine[6], const double src_affine[6], const int flip_h, const int flip_v); 866 int gdAffineConcat (double dst[6], const double m1[6], const double m2[6]); 867 868 int gdAffineIdentity (double dst[6]); 869 int gdAffineScale (double dst[6], const double scale_x, const double scale_y); 870 int gdAffineRotate (double dst[6], const double angle); 871 int gdAffineShearHorizontal (double dst[6], const double angle); 872 int gdAffineShearVertical(double dst[6], const double angle); 873 int gdAffineTranslate (double dst[6], const double offset_x, const double offset_y); 874 double gdAffineExpansion (const double src[6]); 875 int gdAffineRectilinear (const double src[6]); 876 int gdAffineEqual (const double matrix1[6], const double matrix2[6]); 877 int gdTransformAffineGetImage(gdImagePtr *dst, const gdImagePtr src, gdRectPtr src_area, const double affine[6]); 878 int gdTransformAffineCopy(gdImagePtr dst, int dst_x, int dst_y, const gdImagePtr src, gdRectPtr src_region, const double affine[6]); 879 /* 880 gdTransformAffineCopy(gdImagePtr dst, int x0, int y0, int x1, int y1, 881 const gdImagePtr src, int src_width, int src_height, 882 const double affine[6]); 883 */ 884 int gdTransformAffineBoundingBox(gdRectPtr src, const double affine[6], gdRectPtr bbox); 885 886 887 #define GD_CMP_IMAGE 1 /* Actual image IS different */ 888 #define GD_CMP_NUM_COLORS 2 /* Number of Colours in pallette differ */ 889 #define GD_CMP_COLOR 4 /* Image colours differ */ 890 #define GD_CMP_SIZE_X 8 /* Image width differs */ 891 #define GD_CMP_SIZE_Y 16 /* Image heights differ */ 892 #define GD_CMP_TRANSPARENT 32 /* Transparent colour */ 893 #define GD_CMP_BACKGROUND 64 /* Background colour */ 894 #define GD_CMP_INTERLACE 128 /* Interlaced setting */ 895 #define GD_CMP_TRUECOLOR 256 /* Truecolor vs palette differs */ 896 897 /* resolution affects ttf font rendering, particularly hinting */ 898 #define GD_RESOLUTION 96 /* pixels per inch */ 899 900 #ifdef __cplusplus 901 } 902 #endif 903 904 /* 2.0.12: this now checks the clipping rectangle */ 905 #define gdImageBoundsSafe(im, x, y) (!((((y) < (im)->cy1) || ((y) > (im)->cy2)) || (((x) < (im)->cx1) || ((x) > (im)->cx2)))) 906 907 #endif /* GD_H */ 908