Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

gd.h

Go to the documentation of this file.
00001 #ifdef __cplusplus
00002 extern "C" {
00003 #endif
00004 
00005 #ifndef GD_H
00006 #define GD_H 1
00007 
00008 /* Do the DLL dance: dllexport when building the DLL,
00009         dllimport when importing from it, nothing when
00010         not on Silly Silly Windows (tm Aardman Productions). */
00011 
00012 /* 2.0.20: for headers */
00013 
00014 /* 2.0.24: __stdcall also needed for Visual BASIC 
00015         and other languages. This breaks ABI compatibility
00016         with previous DLL revs, but it's necessary. */
00017 
00018 /* 2.0.29: WIN32 programmers can declare the NONDLL macro if they
00019         wish to build gd as a static library or by directly including
00020         the gd sources in a project. */
00021 
00022 #ifndef WIN32
00023 #define NONDLL 1
00024 #else
00025 #define NONDLL 1
00026 #endif /* WIN32 */
00027 
00028 #ifdef NONDLL
00029 #define BGD_DECLARE(rt) extern rt
00030 #else
00031 #ifdef BGDWIN32
00032 #define BGD_DECLARE(rt) __declspec(dllexport) rt __stdcall
00033 #else
00034 #define BGD_DECLARE(rt) __declspec(dllimport) rt _stdcall
00035 #endif /* BGDWIN32 */
00036 #endif /* NONDLL */
00037 
00038 /* 2.0.20: for actual storage of exported data, functions don't need this,
00039   currently needed only for font pointers */
00040 #ifdef NONDLL
00041 /* 2.0.25: bring back extern */
00042 #define BGD_EXPORT_DATA_PROT extern
00043 #define BGD_EXPORT_DATA_IMPL
00044 #else
00045 #ifdef BGDWIN32
00046 #define BGD_EXPORT_DATA_PROT __declspec(dllexport) extern
00047 #define BGD_EXPORT_DATA_IMPL __declspec(dllexport)
00048 #else
00049 #define BGD_EXPORT_DATA_PROT __declspec(dllimport) extern
00050 #define BGD_EXPORT_DATA_IMPL __declspec(dllimport) 
00051 #endif /* BGDWIN32 */
00052 #endif /* NONDLL */
00053 
00054 #ifdef __cplusplus
00055 extern "C"
00056 {
00057 #endif
00058 
00059 /* some might want to set DEFAULT_FONTPATH from configure in config.h */
00060 
00061 /* 2.0.23: more Type 1 fonts */
00062 #ifndef DEFAULT_FONTPATH
00063 /* default fontpath for unix systems  - whatever happened to standards ! */
00064 #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:/usr/lib/X11/fonts/Type1:/usr/openwin/lib/X11/fonts/Type1"
00065 #endif
00066 #ifndef PATHSEPARATOR
00067 #define PATHSEPARATOR ":"
00068 #endif
00069 
00070 /* gd.h: declarations file for the graphic-draw module.
00071  * Permission to use, copy, modify, and distribute this software and its
00072  * documentation for any purpose and without fee is hereby granted, provided
00073  * that the above copyright notice appear in all copies and that both that
00074  * copyright notice and this permission notice appear in supporting
00075  * documentation.  This software is provided "AS IS." Thomas Boutell and
00076  * Boutell.Com, Inc. disclaim all warranties, either express or implied, 
00077  * including but not limited to implied warranties of merchantability and 
00078  * fitness for a particular purpose, with respect to this code and accompanying
00079  * documentation. */
00080 
00081 /* stdio is needed for file I/O. */
00082 #include <stdio.h>
00083 #include "gd_io.h"
00084 
00085 /* The maximum number of palette entries in palette-based images.
00086         In the wonderful new world of gd 2.0, you can of course have
00087         many more colors when using truecolor mode. */
00088 
00089 #define gdMaxColors 256
00090 
00091 /* Image type. See functions below; you will not need to change
00092         the elements directly. Use the provided macros to
00093         access sx, sy, the color table, and colorsTotal for 
00094         read-only purposes. */
00095 
00096 /* If 'truecolor' is set true, the image is truecolor; 
00097         pixels are represented by integers, which
00098         must be 32 bits wide or more. 
00099 
00100         True colors are repsented as follows:
00101 
00102         ARGB
00103 
00104         Where 'A' (alpha channel) occupies only the
00105         LOWER 7 BITS of the MSB. This very small 
00106         loss of alpha channel resolution allows gd 2.x
00107         to keep backwards compatibility by allowing
00108         signed integers to be used to represent colors,
00109         and negative numbers to represent special cases,
00110         just as in gd 1.x. */
00111 
00112 #define gdAlphaMax 127
00113 #define gdAlphaOpaque 0
00114 #define gdAlphaTransparent 127
00115 #define gdRedMax 255
00116 #define gdGreenMax 255
00117 #define gdBlueMax 255
00118 #define gdTrueColorGetAlpha(c) (((c) & 0x7F000000) >> 24)
00119 #define gdTrueColorGetRed(c) (((c) & 0xFF0000) >> 16)
00120 #define gdTrueColorGetGreen(c) (((c) & 0x00FF00) >> 8)
00121 #define gdTrueColorGetBlue(c) ((c) & 0x0000FF)
00122 
00123 /* This function accepts truecolor pixel values only. The 
00124         source color is composited with the destination color
00125         based on the alpha channel value of the source color.
00126         The resulting color is opaque. */
00127 
00128    BGD_DECLARE(int) gdAlphaBlend (int dest, int src);
00129 
00130   typedef struct gdImageStruct
00131   {
00132     /* Palette-based image pixels */
00133     unsigned char **pixels;
00134     int sx;
00135     int sy;
00136     /* These are valid in palette images only. See also
00137        'alpha', which appears later in the structure to
00138        preserve binary backwards compatibility */
00139     int colorsTotal;
00140     int red[gdMaxColors];
00141     int green[gdMaxColors];
00142     int blue[gdMaxColors];
00143     int open[gdMaxColors];
00144     /* For backwards compatibility, this is set to the
00145        first palette entry with 100% transparency,
00146        and is also set and reset by the 
00147        gdImageColorTransparent function. Newer
00148        applications can allocate palette entries
00149        with any desired level of transparency; however,
00150        bear in mind that many viewers, notably
00151        many web browsers, fail to implement
00152        full alpha channel for PNG and provide
00153        support for full opacity or transparency only. */
00154     int transparent;
00155     int *polyInts;
00156     int polyAllocated;
00157     struct gdImageStruct *brush;
00158     struct gdImageStruct *tile;
00159     int brushColorMap[gdMaxColors];
00160     int tileColorMap[gdMaxColors];
00161     int styleLength;
00162     int stylePos;
00163     int *style;
00164     int interlace;
00165     /* New in 2.0: thickness of line. Initialized to 1. */
00166     int thick;
00167     /* New in 2.0: alpha channel for palettes. Note that only
00168        Macintosh Internet Explorer and (possibly) Netscape 6
00169        really support multiple levels of transparency in
00170        palettes, to my knowledge, as of 2/15/01. Most
00171        common browsers will display 100% opaque and
00172        100% transparent correctly, and do something 
00173        unpredictable and/or undesirable for levels
00174        in between. TBB */
00175     int alpha[gdMaxColors];
00176     /* Truecolor flag and pixels. New 2.0 fields appear here at the
00177        end to minimize breakage of existing object code. */
00178     int trueColor;
00179     int **tpixels;
00180     /* Should alpha channel be copied, or applied, each time a
00181        pixel is drawn? This applies to truecolor images only.
00182        No attempt is made to alpha-blend in palette images,
00183        even if semitransparent palette entries exist. 
00184        To do that, build your image as a truecolor image,
00185        then quantize down to 8 bits. */
00186     int alphaBlendingFlag;
00187     /* Should the alpha channel of the image be saved? This affects
00188        PNG at the moment; other future formats may also
00189        have that capability. JPEG doesn't. */
00190     int saveAlphaFlag;
00191 
00192     /* There should NEVER BE ACCESSOR MACROS FOR ITEMS BELOW HERE, so this
00193        part of the structure can be safely changed in new releases. */
00194 
00195     /* 2.0.12: anti-aliased globals. 2.0.26: just a few vestiges after
00196       switching to the fast, memory-cheap implementation from PHP-gd. */
00197     int AA;
00198     int AA_color;
00199     int AA_dont_blend;
00200 
00201     /* 2.0.12: simple clipping rectangle. These values
00202       must be checked for safety when set; please use
00203       gdImageSetClip */
00204     int cx1;
00205     int cy1;
00206     int cx2;
00207     int cy2;
00208   }
00209   gdImage;
00210 
00211   typedef gdImage *gdImagePtr;
00212 
00213   typedef struct
00214   {
00215     /* # of characters in font */
00216     int nchars;
00217     /* First character is numbered... (usually 32 = space) */
00218     int offset;
00219     /* Character width and height */
00220     int w;
00221     int h;
00222     /* Font data; array of characters, one row after another.
00223        Easily included in code, also easily loaded from
00224        data files. */
00225     char *data;
00226   }
00227   gdFont;
00228 
00229 /* Text functions take these. */
00230   typedef gdFont *gdFontPtr;
00231 
00232 /* For backwards compatibility only. Use gdImageSetStyle()
00233         for MUCH more flexible line drawing. Also see
00234         gdImageSetBrush(). */
00235 #define gdDashSize 4
00236 
00237 /* Special colors. */
00238 
00239 #define gdStyled (-2)
00240 #define gdBrushed (-3)
00241 #define gdStyledBrushed (-4)
00242 #define gdTiled (-5)
00243 
00244 /* NOT the same as the transparent color index.
00245         This is used in line styles only. */
00246 #define gdTransparent (-6)
00247 
00248 #define gdAntiAliased (-7)
00249 
00250 /* Functions to manipulate images. */
00251 
00252 /* Creates a palette-based image (up to 256 colors). */
00253 BGD_DECLARE(gdImagePtr) gdImageCreate (int sx, int sy);
00254 
00255 /* An alternate name for the above (2.0). */
00256 #define gdImageCreatePalette gdImageCreate
00257 
00258 /* Creates a truecolor image (millions of colors). */
00259 BGD_DECLARE(gdImagePtr) gdImageCreateTrueColor (int sx, int sy);
00260 
00261 /* Creates an image from various file types. These functions
00262         return a palette or truecolor image based on the
00263         nature of the file being loaded. Truecolor PNG
00264         stays truecolor; palette PNG stays palette-based;
00265         JPEG is always truecolor. */
00266 BGD_DECLARE(gdImagePtr) gdImageCreateFromPng (FILE * fd);
00267 BGD_DECLARE(gdImagePtr) gdImageCreateFromPngCtx (gdIOCtxPtr in);
00268 BGD_DECLARE(gdImagePtr) gdImageCreateFromPngPtr (int size, void *data);
00269 
00270 /* These read the first frame only */
00271 BGD_DECLARE(gdImagePtr) gdImageCreateFromGif (FILE * fd);
00272 BGD_DECLARE(gdImagePtr) gdImageCreateFromGifCtx (gdIOCtxPtr in);
00273 BGD_DECLARE(gdImagePtr) gdImageCreateFromGifPtr (int size, void *data);
00274 BGD_DECLARE(gdImagePtr) gdImageCreateFromWBMP (FILE * inFile);
00275 BGD_DECLARE(gdImagePtr) gdImageCreateFromWBMPCtx (gdIOCtx * infile);
00276 BGD_DECLARE(gdImagePtr) gdImageCreateFromWBMPPtr (int size, void *data);
00277 BGD_DECLARE(gdImagePtr) gdImageCreateFromJpeg (FILE * infile);
00278 BGD_DECLARE(gdImagePtr) gdImageCreateFromJpegCtx (gdIOCtx * infile);
00279 BGD_DECLARE(gdImagePtr) gdImageCreateFromJpegPtr (int size, void *data);
00280 
00281 /* A custom data source. */
00282 /* The source function must return -1 on error, otherwise the number
00283         of bytes fetched. 0 is EOF, not an error! */
00284 /* context will be passed to your source function. */
00285 
00286   typedef struct
00287   {
00288     int (*source) (void *context, char *buffer, int len);
00289     void *context;
00290   }
00291   gdSource, *gdSourcePtr;
00292 
00293    /* Deprecated in favor of gdImageCreateFromPngCtx */
00294 BGD_DECLARE(gdImagePtr) gdImageCreateFromPngSource (gdSourcePtr in);
00295 
00296 BGD_DECLARE(gdImagePtr) gdImageCreateFromGd (FILE * in);
00297 BGD_DECLARE(gdImagePtr) gdImageCreateFromGdCtx (gdIOCtxPtr in);
00298 BGD_DECLARE(gdImagePtr) gdImageCreateFromGdPtr (int size, void *data);
00299 
00300 BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2 (FILE * in);
00301 BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2Ctx (gdIOCtxPtr in);
00302 BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2Ptr (int size, void *data);
00303 
00304 BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2Part (FILE * in, int srcx, int srcy, int w,
00305                                        int h);
00306 BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2PartCtx (gdIOCtxPtr in, int srcx, int srcy,
00307                                           int w, int h);
00308 BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2PartPtr (int size, void *data, int srcx, int srcy,
00309                                           int w, int h);
00310   /* 2.0.10: prototype was missing */
00311 BGD_DECLARE(gdImagePtr) gdImageCreateFromXbm (FILE * in);
00312 
00313   /* NOTE: filename, not FILE */
00314 BGD_DECLARE(gdImagePtr) gdImageCreateFromXpm (char *filename);
00315 
00316 BGD_DECLARE(void) gdImageDestroy (gdImagePtr im);
00317 
00318 /* Replaces or blends with the background depending on the
00319         most recent call to gdImageAlphaBlending and the
00320         alpha channel value of 'color'; default is to overwrite. 
00321         Tiling and line styling are also implemented
00322         here. All other gd drawing functions pass through this call, 
00323         allowing for many useful effects. */
00324 
00325 BGD_DECLARE(void) gdImageSetPixel (gdImagePtr im, int x, int y, int color);
00326 /* FreeType 2 text output with hook to extra flags */
00327 
00328 BGD_DECLARE(int) gdImageGetPixel (gdImagePtr im, int x, int y);
00329 BGD_DECLARE(int) gdImageGetTrueColorPixel (gdImagePtr im, int x, int y);
00330 
00331 BGD_DECLARE(void) gdImageAABlend (gdImagePtr im);
00332 
00333 BGD_DECLARE(void) gdImageLine (gdImagePtr im, int x1, int y1, int x2, int y2, int color);
00334 
00335 /* For backwards compatibility only. Use gdImageSetStyle()
00336         for much more flexible line drawing. */
00337 BGD_DECLARE(void) gdImageDashedLine (gdImagePtr im, int x1, int y1, int x2, int y2,
00338                           int color);
00339 /* Corners specified (not width and height). Upper left first, lower right
00340         second. */
00341 BGD_DECLARE(void) gdImageRectangle (gdImagePtr im, int x1, int y1, int x2, int y2,
00342                          int color);
00343 /* Solid bar. Upper left corner first, lower right corner second. */
00344 BGD_DECLARE(void) gdImageFilledRectangle (gdImagePtr im, int x1, int y1, int x2, int y2,
00345                                int color);
00346 BGD_DECLARE(void) gdImageSetClip(gdImagePtr im, int x1, int y1, int x2, int y2);
00347 BGD_DECLARE(void) gdImageGetClip(gdImagePtr im, int *x1P, int *y1P, int *x2P, int *y2P);
00348 BGD_DECLARE(int) gdImageBoundsSafe (gdImagePtr im, int x, int y);
00349 BGD_DECLARE(void) gdImageChar (gdImagePtr im, gdFontPtr f, int x, int y, int c,
00350                     int color);
00351 BGD_DECLARE(void) gdImageCharUp (gdImagePtr im, gdFontPtr f, int x, int y, int c,
00352                       int color);
00353 BGD_DECLARE(void) gdImageString (gdImagePtr im, gdFontPtr f, int x, int y,
00354                       unsigned char *s, int color);
00355 BGD_DECLARE(void) gdImageStringUp (gdImagePtr im, gdFontPtr f, int x, int y,
00356                         unsigned char *s, int color);
00357 BGD_DECLARE(void) gdImageString16 (gdImagePtr im, gdFontPtr f, int x, int y,
00358                         unsigned short *s, int color);
00359 BGD_DECLARE(void) gdImageStringUp16 (gdImagePtr im, gdFontPtr f, int x, int y,
00360                           unsigned short *s, int color);
00361 
00362 /* 2.0.16: for thread-safe use of gdImageStringFT and friends,
00363   call this before allowing any thread to call gdImageStringFT. 
00364   Otherwise it is invoked by the first thread to invoke
00365   gdImageStringFT, with a very small but real risk of a race condition. 
00366   Return 0 on success, nonzero on failure to initialize freetype. */
00367 BGD_DECLARE(int) gdFontCacheSetup (void);
00368 
00369 /* Optional: clean up after application is done using fonts in 
00370 BGD_DECLARE( ) gdImageStringFT(). */
00371 BGD_DECLARE(void) gdFontCacheShutdown (void);
00372 /* 2.0.20: for backwards compatibility. A few applications did start calling
00373  this function when it first appeared although it was never documented. 
00374  Simply invokes gdFontCacheShutdown. */
00375 BGD_DECLARE(void) gdFreeFontCache (void);
00376 
00377 /* Calls gdImageStringFT. Provided for backwards compatibility only. */
00378 BGD_DECLARE(char *) gdImageStringTTF (gdImage * im, int *brect, int fg, char *fontlist,
00379                           double ptsize, double angle, int x, int y,
00380                           char *string);
00381 
00382 /* FreeType 2 text output */
00383 BGD_DECLARE(char *) gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist,
00384                          double ptsize, double angle, int x, int y,
00385                          char *string);
00386 
00387 /* 2.0.5: provides an extensible way to pass additional parameters.
00388         Thanks to Wez Furlong, sorry for the delay. */
00389 
00390   typedef struct
00391   {
00392     int flags;                  /* Logical OR of gdFTEX_ values */
00393     double linespacing;         /* fine tune line spacing for '\n' */
00394     int charmap;                /* TBB: 2.0.12: may be gdFTEX_Unicode,
00395                                    gdFTEX_Shift_JIS, or gdFTEX_Big5;
00396                                    when not specified, maps are searched
00397                                    for in the above order. */
00398     int hdpi;                   /* if (flags & gdFTEX_RESOLUTION) */
00399     int vdpi;                   /* if (flags & gdFTEX_RESOLUTION) */
00400     char *xshow;        /* if (flags & gdFTEX_XSHOW)
00401                            then, on return, xshow is a malloc'ed
00402                            string contining xshow position data for
00403                            the last string.
00404 
00405                            NB. The caller is responsible for gdFree'ing
00406                            the xshow string. 
00407                          */
00408     char *fontpath;     /* if (flags & gdFTEX_RETURNFONTPATHNAME)
00409                            then, on return, fontpath is a malloc'ed
00410                            string containing the actual font file path name
00411                            used, which can be interesting when fontconfig
00412                            is in use. 
00413 
00414                            The caller is responsible for gdFree'ing the
00415                            fontpath string.
00416                         */
00417 
00418   }
00419   gdFTStringExtra, *gdFTStringExtraPtr;
00420 
00421 #define gdFTEX_LINESPACE 1
00422 #define gdFTEX_CHARMAP 2
00423 #define gdFTEX_RESOLUTION 4
00424 #define gdFTEX_DISABLE_KERNING 8
00425 #define gdFTEX_XSHOW 16
00426 /* The default unless gdFTUseFontConfig(1); has been called:
00427   fontlist is a full or partial font file pathname or list thereof 
00428   (i.e. just like before 2.0.29) */
00429 #define gdFTEX_FONTPATHNAME 32
00430 /* Necessary to use fontconfig patterns instead of font pathnames
00431   as the fontlist argument, unless gdFTUseFontConfig(1); has 
00432   been called. New in 2.0.29 */
00433 #define gdFTEX_FONTCONFIG 64
00434 /* Sometimes interesting when fontconfig is used: the fontpath
00435   element of the structure above will contain a gdMalloc'd string
00436   copy of the actual font file pathname used, if this flag is set 
00437    when the call is made */
00438 #define gdFTEX_RETURNFONTPATHNAME 128
00439 
00440 /* If flag is nonzero, the fontlist parameter to gdImageStringFT 
00441   and gdImageStringFTEx shall be assumed to be a fontconfig font pattern
00442   if fontconfig was compiled into gd. This function returns zero
00443   if fontconfig is not available, nonzero otherwise. */
00444 BGD_DECLARE(int) gdFTUseFontConfig(int flag);
00445 
00446 /* These are NOT flags; set one in 'charmap' if you set the
00447         gdFTEX_CHARMAP bit in 'flags'. */
00448 #define gdFTEX_Unicode 0
00449 #define gdFTEX_Shift_JIS 1
00450 #define gdFTEX_Big5 2
00451 
00452 BGD_DECLARE(char *) gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist,
00453                            double ptsize, double angle, int x, int y,
00454                            char *string, gdFTStringExtraPtr strex);
00455 
00456 /* Point type for use in polygon drawing. */
00457   typedef struct
00458   {
00459     int x, y;
00460   }
00461   gdPoint, *gdPointPtr;
00462 
00463 BGD_DECLARE(void) gdImagePolygon (gdImagePtr im, gdPointPtr p, int n, int c);
00464 BGD_DECLARE(void) gdImageOpenPolygon (gdImagePtr im, gdPointPtr p, int n, int c);
00465 BGD_DECLARE(void) gdImageFilledPolygon (gdImagePtr im, gdPointPtr p, int n, int c);
00466 
00467 /* These functions still work with truecolor images, 
00468         for which they never return error. */
00469 BGD_DECLARE(int) gdImageColorAllocate (gdImagePtr im, int r, int g, int b);
00470 /* gd 2.0: palette entries with non-opaque transparency are permitted. */
00471 BGD_DECLARE(int) gdImageColorAllocateAlpha (gdImagePtr im, int r, int g, int b, int a);
00472 /* Assumes opaque is the preferred alpha channel value */
00473 BGD_DECLARE(int) gdImageColorClosest (gdImagePtr im, int r, int g, int b);
00474 /* Closest match taking all four parameters into account.
00475         A slightly different color with the same transparency
00476         beats the exact same color with radically different
00477         transparency */
00478 BGD_DECLARE(int) gdImageColorClosestAlpha (gdImagePtr im, int r, int g, int b, int a);
00479 /* An alternate method */
00480 BGD_DECLARE(int) gdImageColorClosestHWB (gdImagePtr im, int r, int g, int b);
00481 /* Returns exact, 100% opaque matches only */
00482 BGD_DECLARE(int) gdImageColorExact (gdImagePtr im, int r, int g, int b);
00483 /* Returns an exact match only, including alpha */
00484 BGD_DECLARE(int) gdImageColorExactAlpha (gdImagePtr im, int r, int g, int b, int a);
00485 /* Opaque only */
00486 BGD_DECLARE(int) gdImageColorResolve (gdImagePtr im, int r, int g, int b);
00487 /* Based on gdImageColorExactAlpha and gdImageColorClosestAlpha */
00488 BGD_DECLARE(int) gdImageColorResolveAlpha (gdImagePtr im, int r, int g, int b, int a);
00489 
00490 /* A simpler way to obtain an opaque truecolor value for drawing on a
00491         truecolor image. Not for use with palette images! */
00492 
00493 #define gdTrueColor(r, g, b) (((r) << 16) + \
00494         ((g) << 8) + \
00495         (b))
00496 
00497 /* Returns a truecolor value with an alpha channel component.
00498         gdAlphaMax (127, **NOT 255**) is transparent, 0 is completely
00499         opaque. */
00500 
00501 #define gdTrueColorAlpha(r, g, b, a) (((a) << 24) + \
00502         ((r) << 16) + \
00503         ((g) << 8) + \
00504         (b))
00505 
00506 BGD_DECLARE(void) gdImageColorDeallocate (gdImagePtr im, int color);
00507 
00508 /* Converts a truecolor image to a palette-based image,
00509         using a high-quality two-pass quantization routine
00510         which attempts to preserve alpha channel information
00511         as well as R/G/B color information when creating
00512         a palette. If ditherFlag is set, the image will be
00513         dithered to approximate colors better, at the expense
00514         of some obvious "speckling." colorsWanted can be
00515         anything up to 256. If the original source image
00516         includes photographic information or anything that
00517         came out of a JPEG, 256 is strongly recommended.
00518 
00519         Better yet, don't use these function -- write real
00520         truecolor PNGs and JPEGs. The disk space gain of
00521         conversion to palette is not great (for small images
00522         it can be negative) and the quality loss is ugly. 
00523 
00524         DIFFERENCES: gdImageCreatePaletteFromTrueColor creates and
00525         returns a new image. gdImageTrueColorToPalette modifies 
00526         an existing image, and the truecolor pixels are discarded. */
00527 
00528 BGD_DECLARE(gdImagePtr) gdImageCreatePaletteFromTrueColor (gdImagePtr im, int ditherFlag,
00529                                   int colorsWanted);
00530 
00531 BGD_DECLARE(void) gdImageTrueColorToPalette (gdImagePtr im, int ditherFlag,
00532                                   int colorsWanted);
00533 
00534 /* Specifies a color index (if a palette image) or an
00535         RGB color (if a truecolor image) which should be
00536         considered 100% transparent. FOR TRUECOLOR IMAGES,
00537         THIS IS IGNORED IF AN ALPHA CHANNEL IS BEING
00538         SAVED. Use gdImageSaveAlpha(im, 0); to
00539         turn off the saving of a full alpha channel in
00540         a truecolor image. Note that gdImageColorTransparent
00541         is usually compatible with older browsers that
00542         do not understand full alpha channels well. TBB */
00543 BGD_DECLARE(void) gdImageColorTransparent (gdImagePtr im, int color);
00544 
00545 BGD_DECLARE(void) gdImagePaletteCopy (gdImagePtr dst, gdImagePtr src);
00546 BGD_DECLARE(void) gdImageGif (gdImagePtr im, FILE * out);
00547 BGD_DECLARE(void) gdImagePng (gdImagePtr im, FILE * out);
00548 BGD_DECLARE(void) gdImagePngCtx (gdImagePtr im, gdIOCtx * out);
00549 BGD_DECLARE(void) gdImageGifCtx (gdImagePtr im, gdIOCtx * out);
00550 
00551 /* 2.0.12: Compression level: 0-9 or -1, where 0 is NO COMPRESSION at all,
00552   1 is FASTEST but produces larger files, 9 provides the best
00553   compression (smallest files) but takes a long time to compress, and
00554   -1 selects the default compiled into the zlib library. */
00555 BGD_DECLARE(void) gdImagePngEx (gdImagePtr im, FILE * out, int level);
00556 BGD_DECLARE(void) gdImagePngCtxEx (gdImagePtr im, gdIOCtx * out, int level);
00557 
00558 BGD_DECLARE(void) gdImageWBMP (gdImagePtr image, int fg, FILE * out);
00559 BGD_DECLARE(void) gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out);
00560 
00561 /* Guaranteed to correctly free memory returned
00562         by the gdImage*Ptr functions */
00563 BGD_DECLARE(void) gdFree (void *m);
00564 
00565 /* Best to free this memory with gdFree(), not free() */
00566 BGD_DECLARE(void *) gdImageWBMPPtr (gdImagePtr im, int *size, int fg);
00567 
00568 /* 100 is highest quality (there is always a little loss with JPEG).
00569         0 is lowest. 10 is about the lowest useful setting. */
00570 BGD_DECLARE(void) gdImageJpeg (gdImagePtr im, FILE * out, int quality);
00571 BGD_DECLARE(void) gdImageJpegCtx (gdImagePtr im, gdIOCtx * out, int quality);
00572 
00573 /* Best to free this memory with gdFree(), not free() */
00574 BGD_DECLARE(void *) gdImageJpegPtr (gdImagePtr im, int *size, int quality);
00575 
00576 /* Legal values for Disposal. gdDisposalNone is always used by
00577         the built-in optimizer if previm is passed. */
00578 
00579 enum {
00580         gdDisposalUnknown,
00581         gdDisposalNone,
00582         gdDisposalRestoreBackground,
00583         gdDisposalRestorePrevious
00584 };
00585 
00586 BGD_DECLARE(void) gdImageGifAnimBegin(gdImagePtr im, FILE *outFile, int GlobalCM, int Loops);
00587 BGD_DECLARE(void) gdImageGifAnimAdd(gdImagePtr im, FILE *outFile, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, gdImagePtr previm);
00588 BGD_DECLARE(void) gdImageGifAnimEnd(FILE *outFile);
00589 BGD_DECLARE(void) gdImageGifAnimBeginCtx(gdImagePtr im, gdIOCtx *out, int GlobalCM, int Loops);
00590 BGD_DECLARE(void) gdImageGifAnimAddCtx(gdImagePtr im, gdIOCtx *out, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, gdImagePtr previm);
00591 BGD_DECLARE(void) gdImageGifAnimEndCtx(gdIOCtx *out);
00592 BGD_DECLARE(void *) gdImageGifAnimBeginPtr(gdImagePtr im, int *size, int GlobalCM, int Loops);
00593 BGD_DECLARE(void *) gdImageGifAnimAddPtr(gdImagePtr im, int *size, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, gdImagePtr previm);
00594 BGD_DECLARE(void *) gdImageGifAnimEndPtr(int *size);
00595 
00596 /* A custom data sink. For backwards compatibility. Use
00597         gdIOCtx instead. */
00598 /* The sink function must return -1 on error, otherwise the number
00599         of bytes written, which must be equal to len. */
00600 /* context will be passed to your sink function. */
00601   typedef struct
00602   {
00603     int (*sink) (void *context, const char *buffer, int len);
00604     void *context;
00605   }
00606   gdSink, *gdSinkPtr;
00607 
00608 BGD_DECLARE(void) gdImagePngToSink (gdImagePtr im, gdSinkPtr out);
00609 
00610 BGD_DECLARE(void) gdImageGd (gdImagePtr im, FILE * out);
00611 BGD_DECLARE(void) gdImageGd2 (gdImagePtr im, FILE * out, int cs, int fmt);
00612 
00613 /* Best to free this memory with gdFree(), not free() */
00614 BGD_DECLARE(void *) gdImageGifPtr (gdImagePtr im, int *size);
00615 
00616 /* Best to free this memory with gdFree(), not free() */
00617 BGD_DECLARE(void *) gdImagePngPtr (gdImagePtr im, int *size);
00618 BGD_DECLARE(void *) gdImagePngPtrEx (gdImagePtr im, int *size, int level);
00619 
00620 /* Best to free this memory with gdFree(), not free() */
00621 BGD_DECLARE(void *) gdImageGdPtr (gdImagePtr im, int *size);
00622 
00623 /* Best to free this memory with gdFree(), not free() */
00624 BGD_DECLARE(void *) gdImageGd2Ptr (gdImagePtr im, int cs, int fmt, int *size);
00625 
00626 BGD_DECLARE(void) gdImageEllipse (gdImagePtr im, int cx, int cy, int w, int h,
00627                        int color);
00628 
00629 /* Style is a bitwise OR ( | operator ) of these.
00630         gdArc and gdChord are mutually exclusive;
00631         gdChord just connects the starting and ending
00632         angles with a straight line, while gdArc produces
00633         a rounded edge. gdPie is a synonym for gdArc. 
00634         gdNoFill indicates that the arc or chord should be
00635         outlined, not filled. gdEdged, used together with
00636         gdNoFill, indicates that the beginning and ending
00637         angles should be connected to the center; this is
00638         a good way to outline (rather than fill) a
00639         'pie slice'. */
00640 #define gdArc   0
00641 #define gdPie   gdArc
00642 #define gdChord 1
00643 #define gdNoFill 2
00644 #define gdEdged 4
00645 
00646 BGD_DECLARE(void) gdImageFilledArc (gdImagePtr im, int cx, int cy, int w, int h, int s,
00647                          int e, int color, int style);
00648 BGD_DECLARE(void) gdImageArc (gdImagePtr im, int cx, int cy, int w, int h, int s, int e,
00649                    int color);
00650 BGD_DECLARE(void) gdImageFilledEllipse (gdImagePtr im, int cx, int cy, int w, int h,
00651                              int color);
00652 BGD_DECLARE(void) gdImageFillToBorder (gdImagePtr im, int x, int y, int border,
00653                             int color);
00654 BGD_DECLARE(void) gdImageFill (gdImagePtr im, int x, int y, int color);
00655 BGD_DECLARE(void) gdImageCopy (gdImagePtr dst, gdImagePtr src, int dstX, int dstY,
00656                     int srcX, int srcY, int w, int h);
00657 BGD_DECLARE(void) gdImageCopyMerge (gdImagePtr dst, gdImagePtr src, int dstX, int dstY,
00658                          int srcX, int srcY, int w, int h, int pct);
00659 BGD_DECLARE(void) gdImageCopyMergeGray (gdImagePtr dst, gdImagePtr src, int dstX,
00660                              int dstY, int srcX, int srcY, int w, int h,
00661                              int pct);
00662 
00663 /* Stretches or shrinks to fit, as needed. Does NOT attempt
00664         to average the entire set of source pixels that scale down onto the
00665         destination pixel. */
00666 BGD_DECLARE(void) gdImageCopyResized (gdImagePtr dst, gdImagePtr src, int dstX, int dstY,
00667                            int srcX, int srcY, int dstW, int dstH, int srcW,
00668                            int srcH);
00669 
00670 /* gd 2.0: stretches or shrinks to fit, as needed. When called with a
00671         truecolor destination image, this function averages the
00672         entire set of source pixels that scale down onto the
00673         destination pixel, taking into account what portion of the
00674         destination pixel each source pixel represents. This is a
00675         floating point operation, but this is not a performance issue
00676         on modern hardware, except for some embedded devices. If the 
00677         destination is a palette image, gdImageCopyResized is 
00678         substituted automatically. */
00679 BGD_DECLARE(void) gdImageCopyResampled (gdImagePtr dst, gdImagePtr src, int dstX,
00680                              int dstY, int srcX, int srcY, int dstW, int dstH,
00681                              int srcW, int srcH);
00682 
00683 /* gd 2.0.8: gdImageCopyRotated is added. Source
00684         is a rectangle, with its upper left corner at
00685         srcX and srcY. Destination is the *center* of
00686         the rotated copy. Angle is in degrees, same as
00687         gdImageArc. Floating point destination center
00688         coordinates allow accurate rotation of
00689         objects of odd-numbered width or height. */
00690 BGD_DECLARE(void) gdImageCopyRotated (gdImagePtr dst,
00691                            gdImagePtr src,
00692                            double dstX, double dstY,
00693                            int srcX, int srcY,
00694                            int srcWidth, int srcHeight, int angle);
00695 
00696 BGD_DECLARE(void) gdImageSetBrush (gdImagePtr im, gdImagePtr brush);
00697 BGD_DECLARE(void) gdImageSetTile (gdImagePtr im, gdImagePtr tile);
00698 BGD_DECLARE(void) gdImageSetAntiAliased (gdImagePtr im, int c);
00699 BGD_DECLARE(void) gdImageSetAntiAliasedDontBlend (gdImagePtr im, int c, int dont_blend);
00700 BGD_DECLARE(void) gdImageSetStyle (gdImagePtr im, int *style, int noOfPixels);
00701 /* Line thickness (defaults to 1). Affects lines, ellipses, 
00702         rectangles, polygons and so forth. */
00703 BGD_DECLARE(void) gdImageSetThickness (gdImagePtr im, int thickness);
00704 /* On or off (1 or 0) for all three of these. */
00705 BGD_DECLARE(void) gdImageInterlace (gdImagePtr im, int interlaceArg);
00706 BGD_DECLARE(void) gdImageAlphaBlending (gdImagePtr im, int alphaBlendingArg);
00707 BGD_DECLARE(void) gdImageSaveAlpha (gdImagePtr im, int saveAlphaArg);
00708 
00709 /* Macros to access information about images. */
00710 
00711 /* Returns nonzero if the image is a truecolor image,
00712         zero for a palette image. */
00713 
00714 #define gdImageTrueColor(im) ((im)->trueColor)
00715 
00716 #define gdImageSX(im) ((im)->sx)
00717 #define gdImageSY(im) ((im)->sy)
00718 #define gdImageColorsTotal(im) ((im)->colorsTotal)
00719 #define gdImageRed(im, c) ((im)->trueColor ? gdTrueColorGetRed(c) : \
00720         (im)->red[(c)])
00721 #define gdImageGreen(im, c) ((im)->trueColor ? gdTrueColorGetGreen(c) : \
00722         (im)->green[(c)])
00723 #define gdImageBlue(im, c) ((im)->trueColor ? gdTrueColorGetBlue(c) : \
00724         (im)->blue[(c)])
00725 #define gdImageAlpha(im, c) ((im)->trueColor ? gdTrueColorGetAlpha(c) : \
00726         (im)->alpha[(c)])
00727 #define gdImageGetTransparent(im) ((im)->transparent)
00728 #define gdImageGetInterlaced(im) ((im)->interlace)
00729 
00730 /* These macros provide direct access to pixels in
00731         palette-based and truecolor images, respectively.
00732         If you use these macros, you must perform your own
00733         bounds checking. Use of the macro for the correct type
00734         of image is also your responsibility. */
00735 #define gdImagePalettePixel(im, x, y) (im)->pixels[(y)][(x)]
00736 #define gdImageTrueColorPixel(im, x, y) (im)->tpixels[(y)][(x)]
00737 
00738 /* I/O Support routines. */
00739 
00740 BGD_DECLARE(gdIOCtx *) gdNewFileCtx (FILE *);
00741   /* If data is null, size is ignored and an initial data buffer is
00742     allocated automatically. NOTE: this function assumes gd has the right 
00743     to free or reallocate "data" at will! Also note that gd will free 
00744     "data" when the IO context is freed. If data is not null, it must point
00745     to memory allocated with gdMalloc, or by a call to gdImage[something]Ptr.
00746     If not, see gdNewDynamicCtxEx for an alternative. */
00747 BGD_DECLARE(gdIOCtx *) gdNewDynamicCtx (int size, void *data);
00748   /* 2.0.21: if freeFlag is nonzero, gd will free and/or reallocate "data" as
00749     needed as described above. If freeFlag is zero, gd will never free 
00750     or reallocate "data," which means that the context should only be used
00751     for *reading* an image from a memory buffer, or writing an image to a
00752     memory buffer which is already large enough. If the memory buffer is
00753     not large enough and an image write is attempted, the write operation
00754     will fail. Those wishing to write an image to a buffer in memory have
00755     a much simpler alternative in the gdImage[something]Ptr functions. */
00756 BGD_DECLARE(gdIOCtx *) gdNewDynamicCtxEx (int size, void *data, int freeFlag);
00757 BGD_DECLARE(gdIOCtx *) gdNewSSCtx (gdSourcePtr in, gdSinkPtr out);
00758 BGD_DECLARE(void *) gdDPExtractData (struct gdIOCtx *ctx, int *size);
00759 
00760 #define GD2_CHUNKSIZE           128
00761 #define GD2_CHUNKSIZE_MIN       64
00762 #define GD2_CHUNKSIZE_MAX       4096
00763 
00764 #define GD2_VERS                2
00765 #define GD2_ID                  "gd2"
00766 
00767 #define GD2_FMT_RAW             1
00768 #define GD2_FMT_COMPRESSED      2
00769 
00770 /* Image comparison definitions */
00771 BGD_DECLARE(int) gdImageCompare (gdImagePtr im1, gdImagePtr im2);
00772 
00773 #define GD_CMP_IMAGE            1       /* Actual image IS different */
00774 #define GD_CMP_NUM_COLORS       2       /* Number of Colours in pallette differ */
00775 #define GD_CMP_COLOR            4       /* Image colours differ */
00776 #define GD_CMP_SIZE_X           8       /* Image width differs */
00777 #define GD_CMP_SIZE_Y           16      /* Image heights differ */
00778 #define GD_CMP_TRANSPARENT      32      /* Transparent colour */
00779 #define GD_CMP_BACKGROUND       64      /* Background colour */
00780 #define GD_CMP_INTERLACE        128     /* Interlaced setting */
00781 #define GD_CMP_TRUECOLOR        256     /* Truecolor vs palette differs */
00782 
00783 /* resolution affects ttf font rendering, particularly hinting */
00784 #define GD_RESOLUTION           96      /* pixels per inch */
00785 
00786 #ifdef __cplusplus
00787 }
00788 #endif
00789 
00790 /* newfangled special effects */
00791 #include "gdfx.h"
00792 
00793 #endif                          /* GD_H */
00794 
00795 #ifdef __cplusplus
00796 }
00797 #endif
Untitled Document Pesquisa Psi SourceForge.net Logo