1 #ifndef GD_H 2 #define GD_H 1 3 4 #include <stdlib.h> 5 6 #ifdef __cplusplus 7 extern "C" { 8 #endif 9 10 /* Version information. This gets parsed by build scripts as well as 11 * gcc so each #define line in this group must also be splittable on 12 * whitespace, take the form GD_*_VERSION and contain the magical 13 * trailing comment. */ 14 #define GD_MAJOR_VERSION 2 /*version605b5d1778*/ 15 #define GD_MINOR_VERSION 3 /*version605b5d1778*/ 16 #define GD_RELEASE_VERSION 1 /*version605b5d1778*/ 17 #define GD_EXTRA_VERSION "" /*version605b5d1778*/ 18 /* End parsable section. */ 19 20 /* The version string. This is constructed from the version number 21 * parts above via macro abuse^Wtrickery. */ 22 #define GDXXX_VERSION_STR(mjr, mnr, rev, ext) mjr "." mnr "." rev ext 23 #define GDXXX_STR(s) GDXXX_SSTR(s) /* Two levels needed to expand args. */ 24 #define GDXXX_SSTR(s) #s 25 26 #define GD_VERSION_STRING \ 27 GDXXX_VERSION_STR(GDXXX_STR(GD_MAJOR_VERSION), \ 28 GDXXX_STR(GD_MINOR_VERSION), \ 29 GDXXX_STR(GD_RELEASE_VERSION), \ 30 GD_EXTRA_VERSION) 31 32 33 /* Do the DLL dance: dllexport when building the DLL, 34 dllimport when importing from it, nothing when 35 not on Silly Silly Windows (tm Aardman Productions). */ 36 37 /* 2.0.20: for headers */ 38 39 /* 2.0.24: __stdcall also needed for Visual BASIC 40 and other languages. This breaks ABI compatibility 41 with previous DLL revs, but it's necessary. */ 42 43 /* 2.0.29: WIN32 programmers can declare the NONDLL macro if they 44 wish to build gd as a static library or by directly including 45 the gd sources in a project. */ 46 47 /* http://gcc.gnu.org/wiki/Visibility */ 48 #if defined(_WIN32) || defined(CYGWIN) || defined(_WIN32_WCE) 49 # ifdef BGDWIN32 50 # ifdef NONDLL 51 # define BGD_EXPORT_DATA_PROT 52 # else 53 # ifdef __GNUC__ 54 # define BGD_EXPORT_DATA_PROT __attribute__ ((__dllexport__)) 55 # else 56 # define BGD_EXPORT_DATA_PROT __declspec(dllexport) 57 # endif 58 # endif 59 # else 60 # ifdef __GNUC__ 61 # define BGD_EXPORT_DATA_PROT __attribute__ ((__dllimport__)) 62 # else 63 # define BGD_EXPORT_DATA_PROT __declspec(dllimport) 64 # endif 65 # endif 66 # define BGD_STDCALL __stdcall 67 # define BGD_EXPORT_DATA_IMPL 68 #else 69 # if defined(__GNUC__) || defined(__clang__) 70 # define BGD_EXPORT_DATA_PROT __attribute__ ((__visibility__ ("default"))) 71 # define BGD_EXPORT_DATA_IMPL __attribute__ ((__visibility__ ("hidden"))) 72 # else 73 # define BGD_EXPORT_DATA_PROT 74 # define BGD_EXPORT_DATA_IMPL 75 # endif 76 # define BGD_STDCALL 77 #endif 78 79 #define BGD_DECLARE(rt) BGD_EXPORT_DATA_PROT rt BGD_STDCALL 80 81 /* VS2012+ disable keyword macroizing unless _ALLOW_KEYWORD_MACROS is set 82 We define inline, snprintf, and strcasecmp if they're missing 83 */ 84 #ifdef _MSC_VER 85 # define _ALLOW_KEYWORD_MACROS 86 # ifndef inline 87 # define inline __inline 88 # endif 89 # ifndef strcasecmp 90 # define strcasecmp _stricmp 91 # endif 92 #if _MSC_VER < 1900 93 extern int snprintf(char*, size_t, const char*, ...); 94 #endif 95 #endif 96 97 /* gd.h: declarations file for the graphic-draw module. 98 * Permission to use, copy, modify, and distribute this software and its 99 * documentation for any purpose and without fee is hereby granted, provided 100 * that the above copyright notice appear in all copies and that both that 101 * copyright notice and this permission notice appear in supporting 102 * documentation. This software is provided "AS IS." Thomas Boutell and 103 * Boutell.Com, Inc. disclaim all warranties, either express or implied, 104 * including but not limited to implied warranties of merchantability and 105 * fitness for a particular purpose, with respect to this code and accompanying 106 * documentation. */ 107 108 /* stdio is needed for file I/O. */ 109 #include <stdio.h> 110 #include <stdarg.h> 111 #include "gd_io.h" 112 113 /* The maximum number of palette entries in palette-based images. 114 In the wonderful new world of gd 2.0, you can of course have 115 many more colors when using truecolor mode. */ 116 117 #define gdMaxColors 256 118 119 /* Image type. See functions below; you will not need to change 120 the elements directly. Use the provided macros to 121 access sx, sy, the color table, and colorsTotal for 122 read-only purposes. */ 123 124 /* If 'truecolor' is set true, the image is truecolor; 125 pixels are represented by integers, which 126 must be 32 bits wide or more. 127 128 True colors are repsented as follows: 129 130 ARGB 131 132 Where 'A' (alpha channel) occupies only the 133 LOWER 7 BITS of the MSB. This very small 134 loss of alpha channel resolution allows gd 2.x 135 to keep backwards compatibility by allowing 136 signed integers to be used to represent colors, 137 and negative numbers to represent special cases, 138 just as in gd 1.x. */ 139 140 #define gdAlphaMax 127 141 #define gdAlphaOpaque 0 142 #define gdAlphaTransparent 127 143 #define gdRedMax 255 144 #define gdGreenMax 255 145 #define gdBlueMax 255 146 147 /** 148 * Group: Color Decomposition 149 */ 150 151 /** 152 * Macro: gdTrueColorGetAlpha 153 * 154 * Gets the alpha channel value 155 * 156 * Parameters: 157 * c - The color 158 * 159 * See also: 160 * - <gdTrueColorAlpha> 161 */ 162 #define gdTrueColorGetAlpha(c) (((c) & 0x7F000000) >> 24) 163 164 /** 165 * Macro: gdTrueColorGetRed 166 * 167 * Gets the red channel value 168 * 169 * Parameters: 170 * c - The color 171 * 172 * See also: 173 * - <gdTrueColorAlpha> 174 */ 175 #define gdTrueColorGetRed(c) (((c) & 0xFF0000) >> 16) 176 177 /** 178 * Macro: gdTrueColorGetGreen 179 * 180 * Gets the green channel value 181 * 182 * Parameters: 183 * c - The color 184 * 185 * See also: 186 * - <gdTrueColorAlpha> 187 */ 188 #define gdTrueColorGetGreen(c) (((c) & 0x00FF00) >> 8) 189 190 /** 191 * Macro: gdTrueColorGetBlue 192 * 193 * Gets the blue channel value 194 * 195 * Parameters: 196 * c - The color 197 * 198 * See also: 199 * - <gdTrueColorAlpha> 200 */ 201 #define gdTrueColorGetBlue(c) ((c) & 0x0000FF) 202 203 /** 204 * Group: Effects 205 * 206 * The layering effect 207 * 208 * When pixels are drawn the new colors are "mixed" with the background 209 * depending on the effect. 210 * 211 * Note that the effect does not apply to palette images, where pixels 212 * are always replaced. 213 * 214 * Modes: 215 * gdEffectReplace - replace pixels 216 * gdEffectAlphaBlend - blend pixels, see <gdAlphaBlend> 217 * gdEffectNormal - default mode; same as gdEffectAlphaBlend 218 * gdEffectOverlay - overlay pixels, see <gdLayerOverlay> 219 * gdEffectMultiply - overlay pixels with multiply effect, see 220 * <gdLayerMultiply> 221 * 222 * See also: 223 * - <gdImageAlphaBlending> 224 */ 225 #define gdEffectReplace 0 226 #define gdEffectAlphaBlend 1 227 #define gdEffectNormal 2 228 #define gdEffectOverlay 3 229 #define gdEffectMultiply 4 230 231 #define GD_TRUE 1 232 #define GD_FALSE 0 233 234 #define GD_EPSILON 1e-6 235 #ifndef M_PI 236 # define M_PI 3.14159265358979323846 237 #endif 238 239 /* This function accepts truecolor pixel values only. The 240 source color is composited with the destination color 241 based on the alpha channel value of the source color. 242 The resulting color is opaque. */ 243 244 BGD_DECLARE(int) gdAlphaBlend (int dest, int src); 245 BGD_DECLARE(int) gdLayerOverlay (int dest, int src); 246 BGD_DECLARE(int) gdLayerMultiply (int dest, int src); 247 248 249 /** 250 * Group: Color Quantization 251 * 252 * Enum: gdPaletteQuantizationMethod 253 * 254 * Constants: 255 * GD_QUANT_DEFAULT - GD_QUANT_LIQ if libimagequant is available, 256 * GD_QUANT_JQUANT otherwise. 257 * GD_QUANT_JQUANT - libjpeg's old median cut. Fast, but only uses 16-bit 258 * color. 259 * GD_QUANT_NEUQUANT - NeuQuant - approximation using Kohonen neural network. 260 * GD_QUANT_LIQ - A combination of algorithms used in libimagequant 261 * aiming for the highest quality at cost of speed. 262 * 263 * Note that GD_QUANT_JQUANT does not retain the alpha channel, and 264 * GD_QUANT_NEUQUANT does not support dithering. 265 * 266 * See also: 267 * - <gdImageTrueColorToPaletteSetMethod> 268 */ 269 enum gdPaletteQuantizationMethod { 270 GD_QUANT_DEFAULT = 0, 271 GD_QUANT_JQUANT = 1, 272 GD_QUANT_NEUQUANT = 2, 273 GD_QUANT_LIQ = 3 274 }; 275 276 277 /** 278 * Group: Transform 279 * 280 * Constants: gdInterpolationMethod 281 * 282 * GD_BELL - Bell 283 * GD_BESSEL - Bessel 284 * GD_BILINEAR_FIXED - fixed point bilinear 285 * GD_BICUBIC - Bicubic 286 * GD_BICUBIC_FIXED - fixed point bicubic integer 287 * GD_BLACKMAN - Blackman 288 * GD_BOX - Box 289 * GD_BSPLINE - BSpline 290 * GD_CATMULLROM - Catmullrom 291 * GD_GAUSSIAN - Gaussian 292 * GD_GENERALIZED_CUBIC - Generalized cubic 293 * GD_HERMITE - Hermite 294 * GD_HAMMING - Hamming 295 * GD_HANNING - Hannig 296 * GD_MITCHELL - Mitchell 297 * GD_NEAREST_NEIGHBOUR - Nearest neighbour interpolation 298 * GD_POWER - Power 299 * GD_QUADRATIC - Quadratic 300 * GD_SINC - Sinc 301 * GD_TRIANGLE - Triangle 302 * GD_WEIGHTED4 - 4 pixels weighted bilinear interpolation 303 * GD_LINEAR - bilinear interpolation 304 * 305 * See also: 306 * - <gdImageSetInterpolationMethod> 307 * - <gdImageGetInterpolationMethod> 308 */ 309 typedef enum { 310 GD_DEFAULT = 0, 311 GD_BELL, 312 GD_BESSEL, 313 GD_BILINEAR_FIXED, 314 GD_BICUBIC, 315 GD_BICUBIC_FIXED, 316 GD_BLACKMAN, 317 GD_BOX, 318 GD_BSPLINE, 319 GD_CATMULLROM, 320 GD_GAUSSIAN, 321 GD_GENERALIZED_CUBIC, 322 GD_HERMITE, 323 GD_HAMMING, 324 GD_HANNING, 325 GD_MITCHELL, 326 GD_NEAREST_NEIGHBOUR, 327 GD_POWER, 328 GD_QUADRATIC, 329 GD_SINC, 330 GD_TRIANGLE, 331 GD_WEIGHTED4, 332 GD_LINEAR, 333 GD_METHOD_COUNT = 23 334 } gdInterpolationMethod; 335 336 /* define struct with name and func ptr and add it to gdImageStruct gdInterpolationMethod interpolation; */ 337 338 /* Interpolation function ptr */ 339 typedef double (* interpolation_method )(double); 340 341 342 /* 343 Group: Types 344 345 typedef: gdImage 346 347 typedef: gdImagePtr 348 349 The data structure in which gd stores images. <gdImageCreate>, 350 <gdImageCreateTrueColor> and the various image file-loading functions 351 return a pointer to this type, and the other functions expect to 352 receive a pointer to this type as their first argument. 353 354 *gdImagePtr* is a pointer to *gdImage*. 355 356 See also: 357 <Accessor Macros> 358 359 (Previous versions of this library encouraged directly manipulating 360 the contents ofthe struct but we are attempting to move away from 361 this practice so the fields are no longer documented here. If you 362 need to poke at the internals of this struct, feel free to look at 363 *gd.h*.) 364 */ 365 typedef struct gdImageStruct { 366 /* Palette-based image pixels */ 367 unsigned char **pixels; 368 int sx; 369 int sy; 370 /* These are valid in palette images only. See also 371 'alpha', which appears later in the structure to 372 preserve binary backwards compatibility */ 373 int colorsTotal; 374 int red[gdMaxColors]; 375 int green[gdMaxColors]; 376 int blue[gdMaxColors]; 377 int open[gdMaxColors]; 378 /* For backwards compatibility, this is set to the 379 first palette entry with 100% transparency, 380 and is also set and reset by the 381 gdImageColorTransparent function. Newer 382 applications can allocate palette entries 383 with any desired level of transparency; however, 384 bear in mind that many viewers, notably 385 many web browsers, fail to implement 386 full alpha channel for PNG and provide 387 support for full opacity or transparency only. */ 388 int transparent; 389 int *polyInts; 390 int polyAllocated; 391 struct gdImageStruct *brush; 392 struct gdImageStruct *tile; 393 int brushColorMap[gdMaxColors]; 394 int tileColorMap[gdMaxColors]; 395 int styleLength; 396 int stylePos; 397 int *style; 398 int interlace; 399 /* New in 2.0: thickness of line. Initialized to 1. */ 400 int thick; 401 /* New in 2.0: alpha channel for palettes. Note that only 402 Macintosh Internet Explorer and (possibly) Netscape 6 403 really support multiple levels of transparency in 404 palettes, to my knowledge, as of 2/15/01. Most 405 common browsers will display 100% opaque and 406 100% transparent correctly, and do something 407 unpredictable and/or undesirable for levels 408 in between. TBB */ 409 int alpha[gdMaxColors]; 410 /* Truecolor flag and pixels. New 2.0 fields appear here at the 411 end to minimize breakage of existing object code. */ 412 int trueColor; 413 int **tpixels; 414 /* Should alpha channel be copied, or applied, each time a 415 pixel is drawn? This applies to truecolor images only. 416 No attempt is made to alpha-blend in palette images, 417 even if semitransparent palette entries exist. 418 To do that, build your image as a truecolor image, 419 then quantize down to 8 bits. */ 420 int alphaBlendingFlag; 421 /* Should the alpha channel of the image be saved? This affects 422 PNG at the moment; other future formats may also 423 have that capability. JPEG doesn't. */ 424 int saveAlphaFlag; 425 426 /* There should NEVER BE ACCESSOR MACROS FOR ITEMS BELOW HERE, so this 427 part of the structure can be safely changed in new releases. */ 428 429 /* 2.0.12: anti-aliased globals. 2.0.26: just a few vestiges after 430 switching to the fast, memory-cheap implementation from PHP-gd. */ 431 int AA; 432 int AA_color; 433 int AA_dont_blend; 434 435 /* 2.0.12: simple clipping rectangle. These values 436 must be checked for safety when set; please use 437 gdImageSetClip */ 438 int cx1; 439 int cy1; 440 int cx2; 441 int cy2; 442 443 /* 2.1.0: allows to specify resolution in dpi */ 444 unsigned int res_x; 445 unsigned int res_y; 446 447 /* Selects quantization method, see gdImageTrueColorToPaletteSetMethod() and gdPaletteQuantizationMethod enum. */ 448 int paletteQuantizationMethod; 449 /* speed/quality trade-off. 1 = best quality, 10 = best speed. 0 = method-specific default. 450 Applicable to GD_QUANT_LIQ and GD_QUANT_NEUQUANT. */ 451 int paletteQuantizationSpeed; 452 /* Image will remain true-color if conversion to palette cannot achieve given quality. 453 Value from 1 to 100, 1 = ugly, 100 = perfect. Applicable to GD_QUANT_LIQ.*/ 454 int paletteQuantizationMinQuality; 455 /* Image will use minimum number of palette colors needed to achieve given quality. Must be higher than paletteQuantizationMinQuality 456 Value from 1 to 100, 1 = ugly, 100 = perfect. Applicable to GD_QUANT_LIQ.*/ 457 int paletteQuantizationMaxQuality; 458 gdInterpolationMethod interpolation_id; 459 interpolation_method interpolation; 460 } 461 gdImage; 462 463 typedef gdImage *gdImagePtr; 464 465 466 /* Point type for use in polygon drawing. */ 467 468 /** 469 * Group: Types 470 * 471 * typedef: gdPointF 472 * Defines a point in a 2D coordinate system using floating point 473 * values. 474 * x - Floating point position (increase from left to right) 475 * y - Floating point Row position (increase from top to bottom) 476 * 477 * typedef: gdPointFPtr 478 * Pointer to a <gdPointF> 479 * 480 * See also: 481 * <gdImageCreate>, <gdImageCreateTrueColor>, 482 **/ 483 typedef struct 484 { 485 double x, y; 486 } 487 gdPointF, *gdPointFPtr; 488 489 490 /* 491 Group: Types 492 493 typedef: gdFont 494 495 typedef: gdFontPtr 496 497 A font structure, containing the bitmaps of all characters in a 498 font. Used to declare the characteristics of a font. Text-output 499 functions expect these as their second argument, following the 500 <gdImagePtr> argument. <gdFontGetSmall> and <gdFontGetLarge> both 501 return one. 502 503 You can provide your own font data by providing such a structure and 504 the associated pixel array. You can determine the width and height 505 of a single character in a font by examining the w and h members of 506 the structure. If you will not be creating your own fonts, you will 507 not need to concern yourself with the rest of the components of this 508 structure. 509 510 Please see the files gdfontl.c and gdfontl.h for an example of 511 the proper declaration of this structure. 512 513 > typedef struct { 514 > // # of characters in font 515 > int nchars; 516 > // First character is numbered... (usually 32 = space) 517 > int offset; 518 > // Character width and height 519 > int w; 520 > int h; 521 > // Font data; array of characters, one row after another. 522 > // Easily included in code, also easily loaded from 523 > // data files. 524 > char *data; 525 > } gdFont; 526 527 gdFontPtr is a pointer to gdFont. 528 529 */ 530 typedef struct { 531 /* # of characters in font */ 532 int nchars; 533 /* First character is numbered... (usually 32 = space) */ 534 int offset; 535 /* Character width and height */ 536 int w; 537 int h; 538 /* Font data; array of characters, one row after another. 539 Easily included in code, also easily loaded from 540 data files. */ 541 char *data; 542 } 543 gdFont; 544 545 /* Text functions take these. */ 546 typedef gdFont *gdFontPtr; 547 548 typedef void(*gdErrorMethod)(int, const char *, va_list); 549 550 BGD_DECLARE(void) gdSetErrorMethod(gdErrorMethod); 551 BGD_DECLARE(void) gdClearErrorMethod(void); 552 553 /* For backwards compatibility only. Use gdImageSetStyle() 554 for MUCH more flexible line drawing. Also see 555 gdImageSetBrush(). */ 556 #define gdDashSize 4 557 558 /** 559 * Group: Colors 560 * 561 * Colors are always of type int which is supposed to be at least 32 bit large. 562 * 563 * Kinds of colors: 564 * true colors - ARGB values where the alpha channel is stored as most 565 * significant, and the blue channel as least significant 566 * byte. Note that the alpha channel only uses the 7 least 567 * significant bits. 568 * Don't rely on the internal representation, though, and 569 * use <gdTrueColorAlpha> to compose a truecolor value, and 570 * <gdTrueColorGetAlpha>, <gdTrueColorGetRed>, 571 * <gdTrueColorGetGreen> and <gdTrueColorGetBlue> to access 572 * the respective channels. 573 * palette indexes - The index of a color palette entry (0-255). 574 * special colors - As listed in the following section. 575 * 576 * Constants: Special Colors 577 * gdStyled - use the current style, see <gdImageSetStyle> 578 * gdBrushed - use the current brush, see <gdImageSetBrush> 579 * gdStyledBrushed - use the current style and brush 580 * gdTiled - use the current tile, see <gdImageSetTile> 581 * gdTransparent - indicate transparency, what is not the same as the 582 * transparent color index; used for lines only 583 * gdAntiAliased - draw anti aliased 584 */ 585 586 #define gdStyled (-2) 587 #define gdBrushed (-3) 588 #define gdStyledBrushed (-4) 589 #define gdTiled (-5) 590 #define gdTransparent (-6) 591 #define gdAntiAliased (-7) 592 593 /* Functions to manipulate images. */ 594 595 /* Creates a palette-based image (up to 256 colors). */ 596 BGD_DECLARE(gdImagePtr) gdImageCreate (int sx, int sy); 597 598 /* An alternate name for the above (2.0). */ 599 #define gdImageCreatePalette gdImageCreate 600 601 /* Creates a truecolor image (millions of colors). */ 602 BGD_DECLARE(gdImagePtr) gdImageCreateTrueColor (int sx, int sy); 603 604 /* Creates an image from various file types. These functions 605 return a palette or truecolor image based on the 606 nature of the file being loaded. Truecolor PNG 607 stays truecolor; palette PNG stays palette-based; 608 JPEG is always truecolor. */ 609 BGD_DECLARE(gdImagePtr) gdImageCreateFromPng (FILE * fd); 610 BGD_DECLARE(gdImagePtr) gdImageCreateFromPngCtx (gdIOCtxPtr in); 611 BGD_DECLARE(gdImagePtr) gdImageCreateFromPngPtr (int size, void *data); 612 613 /* These read the first frame only */ 614 BGD_DECLARE(gdImagePtr) gdImageCreateFromGif (FILE * fd); 615 BGD_DECLARE(gdImagePtr) gdImageCreateFromGifCtx (gdIOCtxPtr in); 616 BGD_DECLARE(gdImagePtr) gdImageCreateFromGifPtr (int size, void *data); 617 BGD_DECLARE(gdImagePtr) gdImageCreateFromWBMP (FILE * inFile); 618 BGD_DECLARE(gdImagePtr) gdImageCreateFromWBMPCtx (gdIOCtx * infile); 619 BGD_DECLARE(gdImagePtr) gdImageCreateFromWBMPPtr (int size, void *data); 620 BGD_DECLARE(gdImagePtr) gdImageCreateFromJpeg (FILE * infile); 621 BGD_DECLARE(gdImagePtr) gdImageCreateFromJpegEx (FILE * infile, int ignore_warning); 622 BGD_DECLARE(gdImagePtr) gdImageCreateFromJpegCtx (gdIOCtx * infile); 623 BGD_DECLARE(gdImagePtr) gdImageCreateFromJpegCtxEx (gdIOCtx * infile, int ignore_warning); 624 BGD_DECLARE(gdImagePtr) gdImageCreateFromJpegPtr (int size, void *data); 625 BGD_DECLARE(gdImagePtr) gdImageCreateFromJpegPtrEx (int size, void *data, int ignore_warning); 626 BGD_DECLARE(gdImagePtr) gdImageCreateFromWebp (FILE * inFile); 627 BGD_DECLARE(gdImagePtr) gdImageCreateFromWebpPtr (int size, void *data); 628 BGD_DECLARE(gdImagePtr) gdImageCreateFromWebpCtx (gdIOCtx * infile); 629 630 BGD_DECLARE(gdImagePtr) gdImageCreateFromTiff(FILE *inFile); 631 BGD_DECLARE(gdImagePtr) gdImageCreateFromTiffCtx(gdIOCtx *infile); 632 BGD_DECLARE(gdImagePtr) gdImageCreateFromTiffPtr(int size, void *data); 633 634 BGD_DECLARE(gdImagePtr) gdImageCreateFromTga( FILE * fp ); 635 BGD_DECLARE(gdImagePtr) gdImageCreateFromTgaCtx(gdIOCtx* ctx); 636 BGD_DECLARE(gdImagePtr) gdImageCreateFromTgaPtr(int size, void *data); 637 638 BGD_DECLARE(gdImagePtr) gdImageCreateFromBmp (FILE * inFile); 639 BGD_DECLARE(gdImagePtr) gdImageCreateFromBmpPtr (int size, void *data); 640 BGD_DECLARE(gdImagePtr) gdImageCreateFromBmpCtx (gdIOCtxPtr infile); 641 BGD_DECLARE(gdImagePtr) gdImageCreateFromFile(const char *filename); 642 643 644 /* 645 Group: Types 646 647 typedef: gdSource 648 649 typedef: gdSourcePtr 650 651 *Note:* This interface is *obsolete* and kept only for 652 *compatibility. Use <gdIOCtx> instead. 653 654 Represents a source from which a PNG can be read. Programmers who 655 do not wish to read PNGs from a file can provide their own 656 alternate input mechanism, using the <gdImageCreateFromPngSource> 657 function. See the documentation of that function for an example of 658 the proper use of this type. 659 660 > typedef struct { 661 > int (*source) (void *context, char *buffer, int len); 662 > void *context; 663 > } gdSource, *gdSourcePtr; 664 665 The source function must return -1 on error, otherwise the number 666 of bytes fetched. 0 is EOF, not an error! 667 668 'context' will be passed to your source function. 669 670 */ 671 typedef struct { 672 int (*source) (void *context, char *buffer, int len); 673 void *context; 674 } 675 gdSource, *gdSourcePtr; 676 677 /* Deprecated in favor of gdImageCreateFromPngCtx */ 678 BGD_DECLARE(gdImagePtr) gdImageCreateFromPngSource (gdSourcePtr in); 679 680 BGD_DECLARE(gdImagePtr) gdImageCreateFromGd (FILE * in); 681 BGD_DECLARE(gdImagePtr) gdImageCreateFromGdCtx (gdIOCtxPtr in); 682 BGD_DECLARE(gdImagePtr) gdImageCreateFromGdPtr (int size, void *data); 683 684 BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2 (FILE * in); 685 BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2Ctx (gdIOCtxPtr in); 686 BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2Ptr (int size, void *data); 687 688 BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2Part (FILE * in, int srcx, int srcy, int w, 689 int h); 690 BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2PartCtx (gdIOCtxPtr in, int srcx, int srcy, 691 int w, int h); 692 BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2PartPtr (int size, void *data, int srcx, int srcy, 693 int w, int h); 694 /* 2.0.10: prototype was missing */ 695 BGD_DECLARE(gdImagePtr) gdImageCreateFromXbm (FILE * in); 696 BGD_DECLARE(void) gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOCtx * out); 697 698 /* NOTE: filename, not FILE */ 699 BGD_DECLARE(gdImagePtr) gdImageCreateFromXpm (char *filename); 700 701 BGD_DECLARE(void) gdImageDestroy (gdImagePtr im); 702 703 /* Replaces or blends with the background depending on the 704 most recent call to gdImageAlphaBlending and the 705 alpha channel value of 'color'; default is to overwrite. 706 Tiling and line styling are also implemented 707 here. All other gd drawing functions pass through this call, 708 allowing for many useful effects. 709 Overlay and multiply effects are used when gdImageAlphaBlending 710 is passed gdEffectOverlay and gdEffectMultiply */ 711 712 BGD_DECLARE(void) gdImageSetPixel (gdImagePtr im, int x, int y, int color); 713 /* FreeType 2 text output with hook to extra flags */ 714 715 BGD_DECLARE(int) gdImageGetPixel (gdImagePtr im, int x, int y); 716 BGD_DECLARE(int) gdImageGetTrueColorPixel (gdImagePtr im, int x, int y); 717 718 BGD_DECLARE(void) gdImageAABlend (gdImagePtr im); 719 720 BGD_DECLARE(void) gdImageLine (gdImagePtr im, int x1, int y1, int x2, int y2, int color); 721 722 /* For backwards compatibility only. Use gdImageSetStyle() 723 for much more flexible line drawing. */ 724 BGD_DECLARE(void) gdImageDashedLine (gdImagePtr im, int x1, int y1, int x2, int y2, 725 int color); 726 /* Corners specified (not width and height). Upper left first, lower right 727 second. */ 728 BGD_DECLARE(void) gdImageRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, 729 int color); 730 /* Solid bar. Upper left corner first, lower right corner second. */ 731 BGD_DECLARE(void) gdImageFilledRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, 732 int color); 733 BGD_DECLARE(void) gdImageSetClip(gdImagePtr im, int x1, int y1, int x2, int y2); 734 BGD_DECLARE(void) gdImageGetClip(gdImagePtr im, int *x1P, int *y1P, int *x2P, int *y2P); 735 BGD_DECLARE(void) gdImageSetResolution(gdImagePtr im, const unsigned int res_x, const unsigned int res_y); 736 BGD_DECLARE(int) gdImageBoundsSafe (gdImagePtr im, int x, int y); 737 BGD_DECLARE(void) gdImageChar (gdImagePtr im, gdFontPtr f, int x, int y, int c, 738 int color); 739 BGD_DECLARE(void) gdImageCharUp (gdImagePtr im, gdFontPtr f, int x, int y, int c, 740 int color); 741 BGD_DECLARE(void) gdImageString (gdImagePtr im, gdFontPtr f, int x, int y, 742 unsigned char *s, int color); 743 BGD_DECLARE(void) gdImageStringUp (gdImagePtr im, gdFontPtr f, int x, int y, 744 unsigned char *s, int color); 745 BGD_DECLARE(void) gdImageString16 (gdImagePtr im, gdFontPtr f, int x, int y, 746 unsigned short *s, int color); 747 BGD_DECLARE(void) gdImageStringUp16 (gdImagePtr im, gdFontPtr f, int x, int y, 748 unsigned short *s, int color); 749 750 /* 2.0.16: for thread-safe use of gdImageStringFT and friends, 751 call this before allowing any thread to call gdImageStringFT. 752 Otherwise it is invoked by the first thread to invoke 753 gdImageStringFT, with a very small but real risk of a race condition. 754 Return 0 on success, nonzero on failure to initialize freetype. */ 755 BGD_DECLARE(int) gdFontCacheSetup (void); 756 757 /* Optional: clean up after application is done using fonts in 758 gdImageStringFT(). */ 759 BGD_DECLARE(void) gdFontCacheShutdown (void); 760 /* 2.0.20: for backwards compatibility. A few applications did start calling 761 this function when it first appeared although it was never documented. 762 Simply invokes gdFontCacheShutdown. */ 763 BGD_DECLARE(void) gdFreeFontCache (void); 764 765 /* Calls gdImageStringFT. Provided for backwards compatibility only. */ 766 BGD_DECLARE(char *) gdImageStringTTF (gdImage * im, int *brect, int fg, const char *fontlist, 767 double ptsize, double angle, int x, int y, 768 const char *string); 769 770 /* FreeType 2 text output */ 771 BGD_DECLARE(char *) gdImageStringFT (gdImage * im, int *brect, int fg, const char *fontlist, 772 double ptsize, double angle, int x, int y, 773 const char *string); 774 775 776 /* 777 Group: Types 778 779 typedef: gdFTStringExtra 780 781 typedef: gdFTStringExtraPtr 782 783 A structure and associated pointer type used to pass additional 784 parameters to the <gdImageStringFTEx> function. See 785 <gdImageStringFTEx> for the structure definition. 786 787 Thanks to Wez Furlong. 788 */ 789 790 /* 2.0.5: provides an extensible way to pass additional parameters. 791 Thanks to Wez Furlong, sorry for the delay. */ 792 typedef struct { 793 int flags; /* Logical OR of gdFTEX_ values */ 794 double linespacing; /* fine tune line spacing for '\n' */ 795 int charmap; /* TBB: 2.0.12: may be gdFTEX_Unicode, 796 gdFTEX_Shift_JIS, gdFTEX_Big5, 797 or gdFTEX_Adobe_Custom; 798 when not specified, maps are searched 799 for in the above order. */ 800 int hdpi; /* if (flags & gdFTEX_RESOLUTION) */ 801 int vdpi; /* if (flags & gdFTEX_RESOLUTION) */ 802 char *xshow; /* if (flags & gdFTEX_XSHOW) 803 then, on return, xshow is a malloc'ed 804 string containing xshow position data for 805 the last string. 806 807 NB. The caller is responsible for gdFree'ing 808 the xshow string. 809 */ 810 char *fontpath; /* if (flags & gdFTEX_RETURNFONTPATHNAME) 811 then, on return, fontpath is a malloc'ed 812 string containing the actual font file path name 813 used, which can be interesting when fontconfig 814 is in use. 815 816 The caller is responsible for gdFree'ing the 817 fontpath string. 818 */ 819 820 } 821 gdFTStringExtra, *gdFTStringExtraPtr; 822 823 #define gdFTEX_LINESPACE 1 824 #define gdFTEX_CHARMAP 2 825 #define gdFTEX_RESOLUTION 4 826 #define gdFTEX_DISABLE_KERNING 8 827 #define gdFTEX_XSHOW 16 828 /* The default unless gdFTUseFontConfig(1); has been called: 829 fontlist is a full or partial font file pathname or list thereof 830 (i.e. just like before 2.0.29) */ 831 #define gdFTEX_FONTPATHNAME 32 832 /* Necessary to use fontconfig patterns instead of font pathnames 833 as the fontlist argument, unless gdFTUseFontConfig(1); has 834 been called. New in 2.0.29 */ 835 #define gdFTEX_FONTCONFIG 64 836 /* Sometimes interesting when fontconfig is used: the fontpath 837 element of the structure above will contain a gdMalloc'd string 838 copy of the actual font file pathname used, if this flag is set 839 when the call is made */ 840 #define gdFTEX_RETURNFONTPATHNAME 128 841 842 /* If flag is nonzero, the fontlist parameter to gdImageStringFT 843 and gdImageStringFTEx shall be assumed to be a fontconfig font pattern 844 if fontconfig was compiled into gd. This function returns zero 845 if fontconfig is not available, nonzero otherwise. */ 846 BGD_DECLARE(int) gdFTUseFontConfig(int flag); 847 848 /* These are NOT flags; set one in 'charmap' if you set the 849 gdFTEX_CHARMAP bit in 'flags'. */ 850 #define gdFTEX_Unicode 0 851 #define gdFTEX_Shift_JIS 1 852 #define gdFTEX_Big5 2 853 #define gdFTEX_Adobe_Custom 3 854 855 BGD_DECLARE(char *) gdImageStringFTEx (gdImage * im, int *brect, int fg, const char *fontlist, 856 double ptsize, double angle, int x, int y, 857 const char *string, gdFTStringExtraPtr strex); 858 859 860 /* 861 Group: Types 862 863 typedef: gdPoint 864 865 typedef: gdPointPtr 866 867 Represents a point in the coordinate space of the image; used by 868 <gdImagePolygon>, <gdImageOpenPolygon> and <gdImageFilledPolygon> 869 for polygon drawing. 870 871 > typedef struct { 872 > int x, y; 873 > } gdPoint, *gdPointPtr; 874 875 */ 876 typedef struct { 877 int x, y; 878 } 879 gdPoint, *gdPointPtr; 880 881 /** 882 * Typedef: gdRect 883 * 884 * A rectangle in the coordinate space of the image 885 * 886 * Members: 887 * x - The x-coordinate of the upper left corner. 888 * y - The y-coordinate of the upper left corner. 889 * width - The width. 890 * height - The height. 891 * 892 * Typedef: gdRectPtr 893 * 894 * A pointer to a <gdRect> 895 */ 896 typedef struct { 897 int x, y; 898 int width, height; 899 } 900 gdRect, *gdRectPtr; 901 902 903 BGD_DECLARE(void) gdImagePolygon (gdImagePtr im, gdPointPtr p, int n, int c); 904 BGD_DECLARE(void) gdImageOpenPolygon (gdImagePtr im, gdPointPtr p, int n, int c); 905 BGD_DECLARE(void) gdImageFilledPolygon (gdImagePtr im, gdPointPtr p, int n, int c); 906 907 /* These functions still work with truecolor images, 908 for which they never return error. */ 909 BGD_DECLARE(int) gdImageColorAllocate (gdImagePtr im, int r, int g, int b); 910 /* gd 2.0: palette entries with non-opaque transparency are permitted. */ 911 BGD_DECLARE(int) gdImageColorAllocateAlpha (gdImagePtr im, int r, int g, int b, int a); 912 /* Assumes opaque is the preferred alpha channel value */ 913 BGD_DECLARE(int) gdImageColorClosest (gdImagePtr im, int r, int g, int b); 914 /* Closest match taking all four parameters into account. 915 A slightly different color with the same transparency 916 beats the exact same color with radically different 917 transparency */ 918 BGD_DECLARE(int) gdImageColorClosestAlpha (gdImagePtr im, int r, int g, int b, int a); 919 /* An alternate method */ 920 BGD_DECLARE(int) gdImageColorClosestHWB (gdImagePtr im, int r, int g, int b); 921 /* Returns exact, 100% opaque matches only */ 922 BGD_DECLARE(int) gdImageColorExact (gdImagePtr im, int r, int g, int b); 923 /* Returns an exact match only, including alpha */ 924 BGD_DECLARE(int) gdImageColorExactAlpha (gdImagePtr im, int r, int g, int b, int a); 925 /* Opaque only */ 926 BGD_DECLARE(int) gdImageColorResolve (gdImagePtr im, int r, int g, int b); 927 /* Based on gdImageColorExactAlpha and gdImageColorClosestAlpha */ 928 BGD_DECLARE(int) gdImageColorResolveAlpha (gdImagePtr im, int r, int g, int b, int a); 929 930 /* A simpler way to obtain an opaque truecolor value for drawing on a 931 truecolor image. Not for use with palette images! */ 932 933 #define gdTrueColor(r, g, b) (((r) << 16) + \ 934 ((g) << 8) + \ 935 (b)) 936 937 /** 938 * Group: Color Composition 939 * 940 * Macro: gdTrueColorAlpha 941 * 942 * Compose a truecolor value from its components 943 * 944 * Parameters: 945 * r - The red channel (0-255) 946 * g - The green channel (0-255) 947 * b - The blue channel (0-255) 948 * a - The alpha channel (0-127, where 127 is fully transparent, and 0 is 949 * completely opaque). 950 * 951 * See also: 952 * - <gdTrueColorGetAlpha> 953 * - <gdTrueColorGetRed> 954 * - <gdTrueColorGetGreen> 955 * - <gdTrueColorGetBlue> 956 * - <gdImageColorExactAlpha> 957 */ 958 #define gdTrueColorAlpha(r, g, b, a) (((a) << 24) + \ 959 ((r) << 16) + \ 960 ((g) << 8) + \ 961 (b)) 962 963 BGD_DECLARE(void) gdImageColorDeallocate (gdImagePtr im, int color); 964 965 /* Converts a truecolor image to a palette-based image, 966 using a high-quality two-pass quantization routine 967 which attempts to preserve alpha channel information 968 as well as R/G/B color information when creating 969 a palette. If ditherFlag is set, the image will be 970 dithered to approximate colors better, at the expense 971 of some obvious "speckling." colorsWanted can be 972 anything up to 256. If the original source image 973 includes photographic information or anything that 974 came out of a JPEG, 256 is strongly recommended. 975 976 Better yet, don't use these function -- write real 977 truecolor PNGs and JPEGs. The disk space gain of 978 conversion to palette is not great (for small images 979 it can be negative) and the quality loss is ugly. 980 981 DIFFERENCES: gdImageCreatePaletteFromTrueColor creates and 982 returns a new image. gdImageTrueColorToPalette modifies 983 an existing image, and the truecolor pixels are discarded. 984 985 gdImageTrueColorToPalette() returns TRUE on success, FALSE on failure. 986 */ 987 988 BGD_DECLARE(gdImagePtr) gdImageCreatePaletteFromTrueColor (gdImagePtr im, int ditherFlag, 989 int colorsWanted); 990 991 BGD_DECLARE(int) gdImageTrueColorToPalette (gdImagePtr im, int ditherFlag, 992 int colorsWanted); 993 994 BGD_DECLARE(int) gdImagePaletteToTrueColor(gdImagePtr src); 995 996 /* An attempt at getting the results of gdImageTrueColorToPalette to 997 * look a bit more like the original (im1 is the original and im2 is 998 * the palette version */ 999 1000 BGD_DECLARE(int) gdImageColorMatch(gdImagePtr im1, gdImagePtr im2); 1001 1002 /* Selects quantization method used for subsequent gdImageTrueColorToPalette calls. 1003 See gdPaletteQuantizationMethod enum (e.g. GD_QUANT_NEUQUANT, GD_QUANT_LIQ). 1004 Speed is from 1 (highest quality) to 10 (fastest). 1005 Speed 0 selects method-specific default (recommended). 1006 1007 Returns FALSE if the given method is invalid or not available. 1008 */ 1009 BGD_DECLARE(int) gdImageTrueColorToPaletteSetMethod (gdImagePtr im, int method, int speed); 1010 1011 /* 1012 Chooses quality range that subsequent call to gdImageTrueColorToPalette will aim for. 1013 Min and max quality is in range 1-100 (1 = ugly, 100 = perfect). Max must be higher than min. 1014 If palette cannot represent image with at least min_quality, then image will remain true-color. 1015 If palette can represent image with quality better than max_quality, then lower number of colors will be used. 1016 This function has effect only when GD_QUANT_LIQ method has been selected and the source image is true-color. 1017 */ 1018 BGD_DECLARE(void) gdImageTrueColorToPaletteSetQuality (gdImagePtr im, int min_quality, int max_quality); 1019 1020 /* Specifies a color index (if a palette image) or an 1021 RGB color (if a truecolor image) which should be 1022 considered 100% transparent. FOR TRUECOLOR IMAGES, 1023 THIS IS IGNORED IF AN ALPHA CHANNEL IS BEING 1024 SAVED. Use gdImageSaveAlpha(im, 0); to 1025 turn off the saving of a full alpha channel in 1026 a truecolor image. Note that gdImageColorTransparent 1027 is usually compatible with older browsers that 1028 do not understand full alpha channels well. TBB */ 1029 BGD_DECLARE(void) gdImageColorTransparent (gdImagePtr im, int color); 1030 1031 BGD_DECLARE(void) gdImagePaletteCopy (gdImagePtr dst, gdImagePtr src); 1032 1033 typedef int (*gdCallbackImageColor)(gdImagePtr im, int src); 1034 1035 BGD_DECLARE(int) gdImageColorReplace(gdImagePtr im, int src, int dst); 1036 BGD_DECLARE(int) gdImageColorReplaceThreshold(gdImagePtr im, int src, int dst, float threshold); 1037 BGD_DECLARE(int) gdImageColorReplaceArray(gdImagePtr im, int len, int *src, int *dst); 1038 BGD_DECLARE(int) gdImageColorReplaceCallback(gdImagePtr im, gdCallbackImageColor callback); 1039 1040 BGD_DECLARE(void) gdImageGif (gdImagePtr im, FILE * out); 1041 BGD_DECLARE(void) gdImagePng (gdImagePtr im, FILE * out); 1042 BGD_DECLARE(void) gdImagePngCtx (gdImagePtr im, gdIOCtx * out); 1043 BGD_DECLARE(void) gdImageGifCtx (gdImagePtr im, gdIOCtx * out); 1044 BGD_DECLARE(void) gdImageTiff(gdImagePtr im, FILE *outFile); 1045 BGD_DECLARE(void *) gdImageTiffPtr(gdImagePtr im, int *size); 1046 BGD_DECLARE(void) gdImageTiffCtx(gdImagePtr image, gdIOCtx *out); 1047 1048 BGD_DECLARE(void *) gdImageBmpPtr(gdImagePtr im, int *size, int compression); 1049 BGD_DECLARE(void) gdImageBmp(gdImagePtr im, FILE *outFile, int compression); 1050 BGD_DECLARE(void) gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression); 1051 1052 /* 2.0.12: Compression level: 0-9 or -1, where 0 is NO COMPRESSION at all, 1053 1 is FASTEST but produces larger files, 9 provides the best 1054 compression (smallest files) but takes a long time to compress, and 1055 -1 selects the default compiled into the zlib library. */ 1056 BGD_DECLARE(void) gdImagePngEx (gdImagePtr im, FILE * out, int level); 1057 BGD_DECLARE(void) gdImagePngCtxEx (gdImagePtr im, gdIOCtx * out, int level); 1058 1059 BGD_DECLARE(void) gdImageWBMP (gdImagePtr image, int fg, FILE * out); 1060 BGD_DECLARE(void) gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out); 1061 1062 BGD_DECLARE(int) gdImageFile(gdImagePtr im, const char *filename); 1063 BGD_DECLARE(int) gdSupportsFileType(const char *filename, int writing); 1064 1065 1066 /* Guaranteed to correctly free memory returned by the gdImage*Ptr 1067 functions */ 1068 BGD_DECLARE(void) gdFree (void *m); 1069 1070 /* Best to free this memory with gdFree(), not free() */ 1071 BGD_DECLARE(void *) gdImageWBMPPtr (gdImagePtr im, int *size, int fg); 1072 1073 /* 100 is highest quality (there is always a little loss with JPEG). 1074 0 is lowest. 10 is about the lowest useful setting. */ 1075 BGD_DECLARE(void) gdImageJpeg (gdImagePtr im, FILE * out, int quality); 1076 BGD_DECLARE(void) gdImageJpegCtx (gdImagePtr im, gdIOCtx * out, int quality); 1077 1078 /* Best to free this memory with gdFree(), not free() */ 1079 BGD_DECLARE(void *) gdImageJpegPtr (gdImagePtr im, int *size, int quality); 1080 1081 BGD_DECLARE(void) gdImageWebpEx (gdImagePtr im, FILE * outFile, int quantization); 1082 BGD_DECLARE(void) gdImageWebp (gdImagePtr im, FILE * outFile); 1083 BGD_DECLARE(void *) gdImageWebpPtr (gdImagePtr im, int *size); 1084 BGD_DECLARE(void *) gdImageWebpPtrEx (gdImagePtr im, int *size, int quantization); 1085 BGD_DECLARE(void) gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quantization); 1086 1087 1088 /** 1089 * Group: GifAnim 1090 * 1091 * Legal values for Disposal. gdDisposalNone is always used by 1092 * the built-in optimizer if previm is passed. 1093 * 1094 * Constants: gdImageGifAnim 1095 * 1096 * gdDisposalUnknown - Not recommended 1097 * gdDisposalNone - Preserve previous frame 1098 * gdDisposalRestoreBackground - First allocated color of palette 1099 * gdDisposalRestorePrevious - Restore to before start of frame 1100 * 1101 * See also: 1102 * - <gdImageGifAnimAdd> 1103 */ 1104 enum { 1105 gdDisposalUnknown, 1106 gdDisposalNone, 1107 gdDisposalRestoreBackground, 1108 gdDisposalRestorePrevious 1109 }; 1110 1111 BGD_DECLARE(void) gdImageGifAnimBegin(gdImagePtr im, FILE *outFile, int GlobalCM, int Loops); 1112 BGD_DECLARE(void) gdImageGifAnimAdd(gdImagePtr im, FILE *outFile, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, gdImagePtr previm); 1113 BGD_DECLARE(void) gdImageGifAnimEnd(FILE *outFile); 1114 BGD_DECLARE(void) gdImageGifAnimBeginCtx(gdImagePtr im, gdIOCtx *out, int GlobalCM, int Loops); 1115 BGD_DECLARE(void) gdImageGifAnimAddCtx(gdImagePtr im, gdIOCtx *out, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, gdImagePtr previm); 1116 BGD_DECLARE(void) gdImageGifAnimEndCtx(gdIOCtx *out); 1117 BGD_DECLARE(void *) gdImageGifAnimBeginPtr(gdImagePtr im, int *size, int GlobalCM, int Loops); 1118 BGD_DECLARE(void *) gdImageGifAnimAddPtr(gdImagePtr im, int *size, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, gdImagePtr previm); 1119 BGD_DECLARE(void *) gdImageGifAnimEndPtr(int *size); 1120 1121 1122 1123 /* 1124 Group: Types 1125 1126 typedef: gdSink 1127 1128 typedef: gdSinkPtr 1129 1130 *Note:* This interface is *obsolete* and kept only for 1131 *compatibility*. Use <gdIOCtx> instead. 1132 1133 Represents a "sink" (destination) to which a PNG can be 1134 written. Programmers who do not wish to write PNGs to a file can 1135 provide their own alternate output mechanism, using the 1136 <gdImagePngToSink> function. See the documentation of that 1137 function for an example of the proper use of this type. 1138 1139 > typedef struct { 1140 > int (*sink) (void *context, char *buffer, int len); 1141 > void *context; 1142 > } gdSink, *gdSinkPtr; 1143 1144 The _sink_ function must return -1 on error, otherwise the number of 1145 bytes written, which must be equal to len. 1146 1147 _context_ will be passed to your sink function. 1148 1149 */ 1150 1151 typedef struct { 1152 int (*sink) (void *context, const char *buffer, int len); 1153 void *context; 1154 } 1155 gdSink, *gdSinkPtr; 1156 1157 BGD_DECLARE(void) gdImagePngToSink (gdImagePtr im, gdSinkPtr out); 1158 1159 BGD_DECLARE(void) gdImageGd (gdImagePtr im, FILE * out); 1160 BGD_DECLARE(void) gdImageGd2 (gdImagePtr im, FILE * out, int cs, int fmt); 1161 1162 /* Best to free this memory with gdFree(), not free() */ 1163 BGD_DECLARE(void *) gdImageGifPtr (gdImagePtr im, int *size); 1164 1165 /* Best to free this memory with gdFree(), not free() */ 1166 BGD_DECLARE(void *) gdImagePngPtr (gdImagePtr im, int *size); 1167 BGD_DECLARE(void *) gdImagePngPtrEx (gdImagePtr im, int *size, int level); 1168 1169 /* Best to free this memory with gdFree(), not free() */ 1170 BGD_DECLARE(void *) gdImageGdPtr (gdImagePtr im, int *size); 1171 1172 /* Best to free this memory with gdFree(), not free() */ 1173 BGD_DECLARE(void *) gdImageGd2Ptr (gdImagePtr im, int cs, int fmt, int *size); 1174 1175 /* Style is a bitwise OR ( | operator ) of these. 1176 gdArc and gdChord are mutually exclusive; 1177 gdChord just connects the starting and ending 1178 angles with a straight line, while gdArc produces 1179 a rounded edge. gdPie is a synonym for gdArc. 1180 gdNoFill indicates that the arc or chord should be 1181 outlined, not filled. gdEdged, used together with 1182 gdNoFill, indicates that the beginning and ending 1183 angles should be connected to the center; this is 1184 a good way to outline (rather than fill) a 1185 'pie slice'. */ 1186 #define gdArc 0 1187 #define gdPie gdArc 1188 #define gdChord 1 1189 #define gdNoFill 2 1190 #define gdEdged 4 1191 1192 BGD_DECLARE(void) gdImageFilledArc (gdImagePtr im, int cx, int cy, int w, int h, int s, 1193 int e, int color, int style); 1194 BGD_DECLARE(void) gdImageArc (gdImagePtr im, int cx, int cy, int w, int h, int s, int e, 1195 int color); 1196 BGD_DECLARE(void) gdImageEllipse(gdImagePtr im, int cx, int cy, int w, int h, int color); 1197 BGD_DECLARE(void) gdImageFilledEllipse (gdImagePtr im, int cx, int cy, int w, int h, 1198 int color); 1199 BGD_DECLARE(void) gdImageFillToBorder (gdImagePtr im, int x, int y, int border, 1200 int color); 1201 BGD_DECLARE(void) gdImageFill (gdImagePtr im, int x, int y, int color); 1202 BGD_DECLARE(void) gdImageCopy (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, 1203 int srcX, int srcY, int w, int h); 1204 BGD_DECLARE(void) gdImageCopyMerge (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, 1205 int srcX, int srcY, int w, int h, int pct); 1206 BGD_DECLARE(void) gdImageCopyMergeGray (gdImagePtr dst, gdImagePtr src, int dstX, 1207 int dstY, int srcX, int srcY, int w, int h, 1208 int pct); 1209 1210 /* Stretches or shrinks to fit, as needed. Does NOT attempt 1211 to average the entire set of source pixels that scale down onto the 1212 destination pixel. */ 1213 BGD_DECLARE(void) gdImageCopyResized (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, 1214 int srcX, int srcY, int dstW, int dstH, int srcW, 1215 int srcH); 1216 1217 /* gd 2.0: stretches or shrinks to fit, as needed. When called with a 1218 truecolor destination image, this function averages the 1219 entire set of source pixels that scale down onto the 1220 destination pixel, taking into account what portion of the 1221 destination pixel each source pixel represents. This is a 1222 floating point operation, but this is not a performance issue 1223 on modern hardware, except for some embedded devices. If the 1224 destination is a palette image, gdImageCopyResized is 1225 substituted automatically. */ 1226 BGD_DECLARE(void) gdImageCopyResampled (gdImagePtr dst, gdImagePtr src, int dstX, 1227 int dstY, int srcX, int srcY, int dstW, int dstH, 1228 int srcW, int srcH); 1229 1230 /* gd 2.0.8: gdImageCopyRotated is added. Source 1231 is a rectangle, with its upper left corner at 1232 srcX and srcY. Destination is the *center* of 1233 the rotated copy. Angle is in degrees, same as 1234 gdImageArc. Floating point destination center 1235 coordinates allow accurate rotation of 1236 objects of odd-numbered width or height. */ 1237 BGD_DECLARE(void) gdImageCopyRotated (gdImagePtr dst, 1238 gdImagePtr src, 1239 double dstX, double dstY, 1240 int srcX, int srcY, 1241 int srcWidth, int srcHeight, int angle); 1242 1243 BGD_DECLARE(gdImagePtr) gdImageClone (gdImagePtr src); 1244 1245 BGD_DECLARE(void) gdImageSetBrush (gdImagePtr im, gdImagePtr brush); 1246 BGD_DECLARE(void) gdImageSetTile (gdImagePtr im, gdImagePtr tile); 1247 BGD_DECLARE(void) gdImageSetAntiAliased (gdImagePtr im, int c); 1248 BGD_DECLARE(void) gdImageSetAntiAliasedDontBlend (gdImagePtr im, int c, int dont_blend); 1249 BGD_DECLARE(void) gdImageSetStyle (gdImagePtr im, int *style, int noOfPixels); 1250 /* Line thickness (defaults to 1). Affects lines, ellipses, 1251 rectangles, polygons and so forth. */ 1252 BGD_DECLARE(void) gdImageSetThickness (gdImagePtr im, int thickness); 1253 /* On or off (1 or 0) for all three of these. */ 1254 BGD_DECLARE(void) gdImageInterlace (gdImagePtr im, int interlaceArg); 1255 BGD_DECLARE(void) gdImageAlphaBlending (gdImagePtr im, int alphaBlendingArg); 1256 BGD_DECLARE(void) gdImageSaveAlpha (gdImagePtr im, int saveAlphaArg); 1257 1258 BGD_DECLARE(gdImagePtr) gdImageNeuQuant(gdImagePtr im, const int max_color, int sample_factor); 1259 1260 enum gdPixelateMode { 1261 GD_PIXELATE_UPPERLEFT, 1262 GD_PIXELATE_AVERAGE 1263 }; 1264 1265 BGD_DECLARE(int) gdImagePixelate(gdImagePtr im, int block_size, const unsigned int mode); 1266 1267 typedef struct { 1268 int sub; 1269 int plus; 1270 unsigned int num_colors; 1271 int *colors; 1272 unsigned int seed; 1273 } gdScatter, *gdScatterPtr; 1274 1275 BGD_DECLARE(int) gdImageScatter(gdImagePtr im, int sub, int plus); 1276 BGD_DECLARE(int) gdImageScatterColor(gdImagePtr im, int sub, int plus, int colors[], unsigned int num_colors); 1277 BGD_DECLARE(int) gdImageScatterEx(gdImagePtr im, gdScatterPtr s); 1278 BGD_DECLARE(int) gdImageSmooth(gdImagePtr im, float weight); 1279 BGD_DECLARE(int) gdImageMeanRemoval(gdImagePtr im); 1280 BGD_DECLARE(int) gdImageEmboss(gdImagePtr im); 1281 BGD_DECLARE(int) gdImageGaussianBlur(gdImagePtr im); 1282 BGD_DECLARE(int) gdImageEdgeDetectQuick(gdImagePtr src); 1283 BGD_DECLARE(int) gdImageSelectiveBlur( gdImagePtr src); 1284 BGD_DECLARE(int) gdImageConvolution(gdImagePtr src, float filter[3][3], float filter_div, float offset); 1285 BGD_DECLARE(int) gdImageColor(gdImagePtr src, const int red, const int green, const int blue, const int alpha); 1286 BGD_DECLARE(int) gdImageContrast(gdImagePtr src, double contrast); 1287 BGD_DECLARE(int) gdImageBrightness(gdImagePtr src, int brightness); 1288 BGD_DECLARE(int) gdImageGrayScale(gdImagePtr src); 1289 BGD_DECLARE(int) gdImageNegate(gdImagePtr src); 1290 1291 BGD_DECLARE(gdImagePtr) gdImageCopyGaussianBlurred(gdImagePtr src, int radius, 1292 double sigma); 1293 1294 1295 /** 1296 * Group: Accessor Macros 1297 */ 1298 1299 /** 1300 * Macro: gdImageTrueColor 1301 * 1302 * Whether an image is a truecolor image. 1303 * 1304 * Parameters: 1305 * im - The image. 1306 * 1307 * Returns: 1308 * Non-zero if the image is a truecolor image, zero for palette images. 1309 */ 1310 #define gdImageTrueColor(im) ((im)->trueColor) 1311 1312 /** 1313 * Macro: gdImageSX 1314 * 1315 * Gets the width (in pixels) of an image. 1316 * 1317 * Parameters: 1318 * im - The image. 1319 */ 1320 #define gdImageSX(im) ((im)->sx) 1321 1322 /** 1323 * Macro: gdImageSY 1324 * 1325 * Gets the height (in pixels) of an image. 1326 * 1327 * Parameters: 1328 * im - The image. 1329 */ 1330 #define gdImageSY(im) ((im)->sy) 1331 1332 /** 1333 * Macro: gdImageColorsTotal 1334 * 1335 * Gets the number of colors in the palette. 1336 * 1337 * This macro is only valid for palette images. 1338 * 1339 * Parameters: 1340 * im - The image 1341 */ 1342 #define gdImageColorsTotal(im) ((im)->colorsTotal) 1343 1344 /** 1345 * Macro: gdImageRed 1346 * 1347 * Gets the red component value of a given color. 1348 * 1349 * Parameters: 1350 * im - The image. 1351 * c - The color. 1352 */ 1353 #define gdImageRed(im, c) ((im)->trueColor ? gdTrueColorGetRed(c) : \ 1354 (im)->red[(c)]) 1355 1356 /** 1357 * Macro: gdImageGreen 1358 * 1359 * Gets the green component value of a given color. 1360 * 1361 * Parameters: 1362 * im - The image. 1363 * c - The color. 1364 */ 1365 #define gdImageGreen(im, c) ((im)->trueColor ? gdTrueColorGetGreen(c) : \ 1366 (im)->green[(c)]) 1367 1368 /** 1369 * Macro: gdImageBlue 1370 * 1371 * Gets the blue component value of a given color. 1372 * 1373 * Parameters: 1374 * im - The image. 1375 * c - The color. 1376 */ 1377 #define gdImageBlue(im, c) ((im)->trueColor ? gdTrueColorGetBlue(c) : \ 1378 (im)->blue[(c)]) 1379 1380 /** 1381 * Macro: gdImageAlpha 1382 * 1383 * Gets the alpha component value of a given color. 1384 * 1385 * Parameters: 1386 * im - The image. 1387 * c - The color. 1388 */ 1389 #define gdImageAlpha(im, c) ((im)->trueColor ? gdTrueColorGetAlpha(c) : \ 1390 (im)->alpha[(c)]) 1391 1392 /** 1393 * Macro: gdImageGetTransparent 1394 * 1395 * Gets the transparent color of the image. 1396 * 1397 * Parameters: 1398 * im - The image. 1399 * 1400 * See also: 1401 * - <gdImageColorTransparent> 1402 */ 1403 #define gdImageGetTransparent(im) ((im)->transparent) 1404 1405 /** 1406 * Macro: gdImageGetInterlaced 1407 * 1408 * Whether an image is interlaced. 1409 * 1410 * Parameters: 1411 * im - The image. 1412 * 1413 * Returns: 1414 * Non-zero for interlaced images, zero otherwise. 1415 * 1416 * See also: 1417 * - <gdImageInterlace> 1418 */ 1419 #define gdImageGetInterlaced(im) ((im)->interlace) 1420 1421 /** 1422 * Macro: gdImagePalettePixel 1423 * 1424 * Gets the color of a pixel. 1425 * 1426 * Calling this macro is only valid for palette images. 1427 * No bounds checking is done for the coordinates. 1428 * 1429 * Parameters: 1430 * im - The image. 1431 * x - The x-coordinate. 1432 * y - The y-coordinate. 1433 * 1434 * See also: 1435 * - <gdImageTrueColorPixel> 1436 * - <gdImageGetPixel> 1437 */ 1438 #define gdImagePalettePixel(im, x, y) (im)->pixels[(y)][(x)] 1439 1440 /** 1441 * Macro: gdImageTrueColorPixel 1442 * 1443 * Gets the color of a pixel. 1444 * 1445 * Calling this macro is only valid for truecolor images. 1446 * No bounds checking is done for the coordinates. 1447 * 1448 * Parameters: 1449 * im - The image. 1450 * x - The x-coordinate. 1451 * y - The y-coordinate. 1452 * 1453 * See also: 1454 * - <gdImagePalettePixel> 1455 * - <gdImageGetTrueColorPixel> 1456 */ 1457 #define gdImageTrueColorPixel(im, x, y) (im)->tpixels[(y)][(x)] 1458 1459 /** 1460 * Macro: gdImageResolutionX 1461 * 1462 * Gets the horizontal resolution in DPI. 1463 * 1464 * Parameters: 1465 * im - The image. 1466 * 1467 * See also: 1468 * - <gdImageResolutionY> 1469 * - <gdImageSetResolution> 1470 */ 1471 #define gdImageResolutionX(im) (im)->res_x 1472 1473 /** 1474 * Macro: gdImageResolutionY 1475 * 1476 * Gets the vertical resolution in DPI. 1477 * 1478 * Parameters: 1479 * im - The image. 1480 * 1481 * See also: 1482 * - <gdImageResolutionX> 1483 * - <gdImageSetResolution> 1484 */ 1485 #define gdImageResolutionY(im) (im)->res_y 1486 1487 /* I/O Support routines. */ 1488 1489 BGD_DECLARE(gdIOCtx *) gdNewFileCtx (FILE *); 1490 /* If data is null, size is ignored and an initial data buffer is 1491 allocated automatically. NOTE: this function assumes gd has the right 1492 to free or reallocate "data" at will! Also note that gd will free 1493 "data" when the IO context is freed. If data is not null, it must point 1494 to memory allocated with gdMalloc, or by a call to gdImage[something]Ptr. 1495 If not, see gdNewDynamicCtxEx for an alternative. */ 1496 BGD_DECLARE(gdIOCtx *) gdNewDynamicCtx (int size, void *data); 1497 /* 2.0.21: if freeFlag is nonzero, gd will free and/or reallocate "data" as 1498 needed as described above. If freeFlag is zero, gd will never free 1499 or reallocate "data", which means that the context should only be used 1500 for *reading* an image from a memory buffer, or writing an image to a 1501 memory buffer which is already large enough. If the memory buffer is 1502 not large enough and an image write is attempted, the write operation 1503 will fail. Those wishing to write an image to a buffer in memory have 1504 a much simpler alternative in the gdImage[something]Ptr functions. */ 1505 BGD_DECLARE(gdIOCtx *) gdNewDynamicCtxEx (int size, void *data, int freeFlag); 1506 BGD_DECLARE(gdIOCtx *) gdNewSSCtx (gdSourcePtr in, gdSinkPtr out); 1507 BGD_DECLARE(void *) gdDPExtractData (struct gdIOCtx *ctx, int *size); 1508 1509 #define GD2_CHUNKSIZE 128 1510 #define GD2_CHUNKSIZE_MIN 64 1511 #define GD2_CHUNKSIZE_MAX 4096 1512 1513 #define GD2_VERS 2 1514 #define GD2_ID "gd2" 1515 1516 #define GD2_FMT_RAW 1 1517 #define GD2_FMT_COMPRESSED 2 1518 1519 /* Image comparison definitions */ 1520 BGD_DECLARE(int) gdImageCompare (gdImagePtr im1, gdImagePtr im2); 1521 1522 BGD_DECLARE(void) gdImageFlipHorizontal(gdImagePtr im); 1523 BGD_DECLARE(void) gdImageFlipVertical(gdImagePtr im); 1524 BGD_DECLARE(void) gdImageFlipBoth(gdImagePtr im); 1525 1526 #define GD_FLIP_HORINZONTAL 1 /* typo, kept for BC */ 1527 #define GD_FLIP_HORIZONTAL 1 1528 #define GD_FLIP_VERTICAL 2 1529 #define GD_FLIP_BOTH 3 1530 1531 /** 1532 * Group: Crop 1533 * 1534 * Constants: gdCropMode 1535 * GD_CROP_DEFAULT - Same as GD_CROP_TRANSPARENT 1536 * GD_CROP_TRANSPARENT - Crop using the transparent color 1537 * GD_CROP_BLACK - Crop black borders 1538 * GD_CROP_WHITE - Crop white borders 1539 * GD_CROP_SIDES - Crop using colors of the 4 corners 1540 * 1541 * See also: 1542 * - <gdImageCropAuto> 1543 **/ 1544 enum gdCropMode { 1545 GD_CROP_DEFAULT = 0, 1546 GD_CROP_TRANSPARENT, 1547 GD_CROP_BLACK, 1548 GD_CROP_WHITE, 1549 GD_CROP_SIDES, 1550 GD_CROP_THRESHOLD 1551 }; 1552 1553 BGD_DECLARE(gdImagePtr) gdImageCrop(gdImagePtr src, const gdRect *crop); 1554 BGD_DECLARE(gdImagePtr) gdImageCropAuto(gdImagePtr im, const unsigned int mode); 1555 BGD_DECLARE(gdImagePtr) gdImageCropThreshold(gdImagePtr im, const unsigned int color, const float threshold); 1556 1557 BGD_DECLARE(int) gdImageSetInterpolationMethod(gdImagePtr im, gdInterpolationMethod id); 1558 BGD_DECLARE(gdInterpolationMethod) gdImageGetInterpolationMethod(gdImagePtr im); 1559 1560 BGD_DECLARE(gdImagePtr) gdImageScale(const gdImagePtr src, const unsigned int new_width, const unsigned int new_height); 1561 1562 BGD_DECLARE(gdImagePtr) gdImageRotateInterpolated(const gdImagePtr src, const float angle, int bgcolor); 1563 1564 typedef enum { 1565 GD_AFFINE_TRANSLATE = 0, 1566 GD_AFFINE_SCALE, 1567 GD_AFFINE_ROTATE, 1568 GD_AFFINE_SHEAR_HORIZONTAL, 1569 GD_AFFINE_SHEAR_VERTICAL 1570 } gdAffineStandardMatrix; 1571 1572 BGD_DECLARE(int) gdAffineApplyToPointF (gdPointFPtr dst, const gdPointFPtr src, const double affine[6]); 1573 BGD_DECLARE(int) gdAffineInvert (double dst[6], const double src[6]); 1574 BGD_DECLARE(int) gdAffineFlip (double dst_affine[6], const double src_affine[6], const int flip_h, const int flip_v); 1575 BGD_DECLARE(int) gdAffineConcat (double dst[6], const double m1[6], const double m2[6]); 1576 1577 BGD_DECLARE(int) gdAffineIdentity (double dst[6]); 1578 BGD_DECLARE(int) gdAffineScale (double dst[6], const double scale_x, const double scale_y); 1579 BGD_DECLARE(int) gdAffineRotate (double dst[6], const double angle); 1580 BGD_DECLARE(int) gdAffineShearHorizontal (double dst[6], const double angle); 1581 BGD_DECLARE(int) gdAffineShearVertical(double dst[6], const double angle); 1582 BGD_DECLARE(int) gdAffineTranslate (double dst[6], const double offset_x, const double offset_y); 1583 BGD_DECLARE(double) gdAffineExpansion (const double src[6]); 1584 BGD_DECLARE(int) gdAffineRectilinear (const double src[6]); 1585 BGD_DECLARE(int) gdAffineEqual (const double matrix1[6], const double matrix2[6]); 1586 BGD_DECLARE(int) gdTransformAffineGetImage(gdImagePtr *dst, const gdImagePtr src, gdRectPtr src_area, const double affine[6]); 1587 BGD_DECLARE(int) gdTransformAffineCopy(gdImagePtr dst, int dst_x, int dst_y, const gdImagePtr src, gdRectPtr src_region, const double affine[6]); 1588 /* 1589 gdTransformAffineCopy(gdImagePtr dst, int x0, int y0, int x1, int y1, 1590 const gdImagePtr src, int src_width, int src_height, 1591 const double affine[6]); 1592 */ 1593 BGD_DECLARE(int) gdTransformAffineBoundingBox(gdRectPtr src, const double affine[6], gdRectPtr bbox); 1594 1595 /** 1596 * Group: Image Comparison 1597 * 1598 * Constants: 1599 * GD_CMP_IMAGE - Actual image IS different 1600 * GD_CMP_NUM_COLORS - Number of colors in pallette differ 1601 * GD_CMP_COLOR - Image colors differ 1602 * GD_CMP_SIZE_X - Image width differs 1603 * GD_CMP_SIZE_Y - Image heights differ 1604 * GD_CMP_TRANSPARENT - Transparent color differs 1605 * GD_CMP_BACKGROUND - Background color differs 1606 * GD_CMP_INTERLACE - Interlaced setting differs 1607 * GD_CMP_TRUECOLOR - Truecolor vs palette differs 1608 * 1609 * See also: 1610 * - <gdImageCompare> 1611 */ 1612 #define GD_CMP_IMAGE 1 1613 #define GD_CMP_NUM_COLORS 2 1614 #define GD_CMP_COLOR 4 1615 #define GD_CMP_SIZE_X 8 1616 #define GD_CMP_SIZE_Y 16 1617 #define GD_CMP_TRANSPARENT 32 1618 #define GD_CMP_BACKGROUND 64 1619 #define GD_CMP_INTERLACE 128 1620 #define GD_CMP_TRUECOLOR 256 1621 1622 /* resolution affects ttf font rendering, particularly hinting */ 1623 #define GD_RESOLUTION 96 /* pixels per inch */ 1624 1625 1626 /* Version information functions */ 1627 BGD_DECLARE(int) gdMajorVersion(void); 1628 BGD_DECLARE(int) gdMinorVersion(void); 1629 BGD_DECLARE(int) gdReleaseVersion(void); 1630 BGD_DECLARE(const char *) gdExtraVersion(void); 1631 BGD_DECLARE(const char *) gdVersionString(void); 1632 1633 /* newfangled special effects */ 1634 #include "gdfx.h" 1635 1636 #ifdef __cplusplus 1637 } 1638 #endif 1639 1640 #endif /* GD_H */ 1641