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