Back to index

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