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