home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / gd.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-06-28  |  32.0 KB  |  811 lines

  1. #ifdef __cplusplus
  2. extern "C" {
  3. #endif
  4.  
  5. #ifndef GD_H
  6. #define GD_H 1
  7.  
  8. #define GD_MAJOR_VERSION 2
  9. #define GD_MINOR_VERSION 0
  10. #define GD_RELEASE_VERSION 35
  11. #define GD_EXTRA_VERSION ""
  12. #define GD_VERSION_STRING "2.0.35"
  13.  
  14.  
  15. /* Do the DLL dance: dllexport when building the DLL,
  16.     dllimport when importing from it, nothing when
  17.     not on Silly Silly Windows (tm Aardman Productions). */
  18.  
  19. /* 2.0.20: for headers */
  20.  
  21. /* 2.0.24: __stdcall also needed for Visual BASIC 
  22.     and other languages. This breaks ABI compatibility
  23.     with previous DLL revs, but it's necessary. */
  24.  
  25. /* 2.0.29: WIN32 programmers can declare the NONDLL macro if they
  26.     wish to build gd as a static library or by directly including
  27.     the gd sources in a project. */
  28.  
  29. #ifndef WIN32
  30. #define NONDLL 1
  31. #endif /* WIN32 */
  32.  
  33. #ifdef NONDLL
  34. #define BGD_DECLARE(rt) extern rt
  35. #else
  36. #ifdef BGDWIN32
  37. #define BGD_DECLARE(rt) __declspec(dllexport) rt __stdcall
  38. #else
  39. #define BGD_DECLARE(rt) __declspec(dllimport) rt _stdcall
  40. #endif /* BGDWIN32 */
  41. #endif /* NONDLL */
  42.  
  43. /* 2.0.20: for actual storage of exported data, functions don't need this,
  44.   currently needed only for font pointers */
  45. #ifdef NONDLL
  46. /* 2.0.25: bring back extern */
  47. #define BGD_EXPORT_DATA_PROT extern
  48. #define BGD_EXPORT_DATA_IMPL
  49. #else
  50. #ifdef BGDWIN32
  51. #define BGD_EXPORT_DATA_PROT __declspec(dllexport) extern
  52. #define BGD_EXPORT_DATA_IMPL __declspec(dllexport)
  53. #else
  54. #define BGD_EXPORT_DATA_PROT __declspec(dllimport) extern
  55. #define BGD_EXPORT_DATA_IMPL __declspec(dllimport) 
  56. #endif /* BGDWIN32 */
  57. #endif /* NONDLL */
  58.  
  59. #ifdef __cplusplus
  60. extern "C"
  61. {
  62. #endif
  63.  
  64. /* some might want to set DEFAULT_FONTPATH from configure in config.h */
  65. #ifdef NETWARE
  66. /* default fontpath for netware systems, could probably be handled in configure for 2.1 */
  67. #define DEFAULT_FONTPATH "sys:/java/nwgfx/lib/x11/fonts/ttf;."
  68. #define PATHSEPARATOR ";"
  69. #endif
  70.  
  71. /* 2.0.23: more Type 1 fonts */
  72. #ifndef DEFAULT_FONTPATH
  73. /* default fontpath for unix systems  - whatever happened to standards ! */
  74. #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"
  75. #endif
  76. #ifndef PATHSEPARATOR
  77. #define PATHSEPARATOR ":"
  78. #endif
  79.  
  80. /* gd.h: declarations file for the graphic-draw module.
  81.  * Permission to use, copy, modify, and distribute this software and its
  82.  * documentation for any purpose and without fee is hereby granted, provided
  83.  * that the above copyright notice appear in all copies and that both that
  84.  * copyright notice and this permission notice appear in supporting
  85.  * documentation.  This software is provided "AS IS." Thomas Boutell and
  86.  * Boutell.Com, Inc. disclaim all warranties, either express or implied, 
  87.  * including but not limited to implied warranties of merchantability and 
  88.  * fitness for a particular purpose, with respect to this code and accompanying
  89.  * documentation. */
  90.  
  91. /* stdio is needed for file I/O. */
  92. #include <stdio.h>
  93. #include "gd_io.h"
  94.  
  95. /* The maximum number of palette entries in palette-based images.
  96.     In the wonderful new world of gd 2.0, you can of course have
  97.     many more colors when using truecolor mode. */
  98.  
  99. #define gdMaxColors 256
  100.  
  101. /* Image type. See functions below; you will not need to change
  102.     the elements directly. Use the provided macros to
  103.     access sx, sy, the color table, and colorsTotal for 
  104.     read-only purposes. */
  105.  
  106. /* If 'truecolor' is set true, the image is truecolor; 
  107.     pixels are represented by integers, which
  108.     must be 32 bits wide or more. 
  109.  
  110.     True colors are repsented as follows:
  111.  
  112.     ARGB
  113.  
  114.     Where 'A' (alpha channel) occupies only the
  115.     LOWER 7 BITS of the MSB. This very small 
  116.     loss of alpha channel resolution allows gd 2.x
  117.     to keep backwards compatibility by allowing
  118.     signed integers to be used to represent colors,
  119.     and negative numbers to represent special cases,
  120.     just as in gd 1.x. */
  121.  
  122. #define gdAlphaMax 127
  123. #define gdAlphaOpaque 0
  124. #define gdAlphaTransparent 127
  125. #define gdRedMax 255
  126. #define gdGreenMax 255
  127. #define gdBlueMax 255
  128. #define gdTrueColorGetAlpha(c) (((c) & 0x7F000000) >> 24)
  129. #define gdTrueColorGetRed(c) (((c) & 0xFF0000) >> 16)
  130. #define gdTrueColorGetGreen(c) (((c) & 0x00FF00) >> 8)
  131. #define gdTrueColorGetBlue(c) ((c) & 0x0000FF)
  132.  
  133. /* This function accepts truecolor pixel values only. The 
  134.     source color is composited with the destination color
  135.     based on the alpha channel value of the source color.
  136.     The resulting color is opaque. */
  137.  
  138.    BGD_DECLARE(int) gdAlphaBlend (int dest, int src);
  139.  
  140.   typedef struct gdImageStruct
  141.   {
  142.     /* Palette-based image pixels */
  143.     unsigned char **pixels;
  144.     int sx;
  145.     int sy;
  146.     /* These are valid in palette images only. See also
  147.        'alpha', which appears later in the structure to
  148.        preserve binary backwards compatibility */
  149.     int colorsTotal;
  150.     int red[gdMaxColors];
  151.     int green[gdMaxColors];
  152.     int blue[gdMaxColors];
  153.     int open[gdMaxColors];
  154.     /* For backwards compatibility, this is set to the
  155.        first palette entry with 100% transparency,
  156.        and is also set and reset by the 
  157.        gdImageColorTransparent function. Newer
  158.        applications can allocate palette entries
  159.        with any desired level of transparency; however,
  160.        bear in mind that many viewers, notably
  161.        many web browsers, fail to implement
  162.        full alpha channel for PNG and provide
  163.        support for full opacity or transparency only. */
  164.     int transparent;
  165.     int *polyInts;
  166.     int polyAllocated;
  167.     struct gdImageStruct *brush;
  168.     struct gdImageStruct *tile;
  169.     int brushColorMap[gdMaxColors];
  170.     int tileColorMap[gdMaxColors];
  171.     int styleLength;
  172.     int stylePos;
  173.     int *style;
  174.     int interlace;
  175.     /* New in 2.0: thickness of line. Initialized to 1. */
  176.     int thick;
  177.     /* New in 2.0: alpha channel for palettes. Note that only
  178.        Macintosh Internet Explorer and (possibly) Netscape 6
  179.        really support multiple levels of transparency in
  180.        palettes, to my knowledge, as of 2/15/01. Most
  181.        common browsers will display 100% opaque and
  182.        100% transparent correctly, and do something 
  183.        unpredictable and/or undesirable for levels
  184.        in between. TBB */
  185.     int alpha[gdMaxColors];
  186.     /* Truecolor flag and pixels. New 2.0 fields appear here at the
  187.        end to minimize breakage of existing object code. */
  188.     int trueColor;
  189.     int **tpixels;
  190.     /* Should alpha channel be copied, or applied, each time a
  191.        pixel is drawn? This applies to truecolor images only.
  192.        No attempt is made to alpha-blend in palette images,
  193.        even if semitransparent palette entries exist. 
  194.        To do that, build your image as a truecolor image,
  195.        then quantize down to 8 bits. */
  196.     int alphaBlendingFlag;
  197.     /* Should the alpha channel of the image be saved? This affects
  198.        PNG at the moment; other future formats may also
  199.        have that capability. JPEG doesn't. */
  200.     int saveAlphaFlag;
  201.  
  202.     /* There should NEVER BE ACCESSOR MACROS FOR ITEMS BELOW HERE, so this
  203.        part of the structure can be safely changed in new releases. */
  204.  
  205.     /* 2.0.12: anti-aliased globals. 2.0.26: just a few vestiges after
  206.       switching to the fast, memory-cheap implementation from PHP-gd. */
  207.     int AA;
  208.     int AA_color;
  209.     int AA_dont_blend;
  210.  
  211.     /* 2.0.12: simple clipping rectangle. These values
  212.       must be checked for safety when set; please use
  213.       gdImageSetClip */
  214.     int cx1;
  215.     int cy1;
  216.     int cx2;
  217.     int cy2;
  218.   }
  219.   gdImage;
  220.  
  221.   typedef gdImage *gdImagePtr;
  222.  
  223.   typedef struct
  224.   {
  225.     /* # of characters in font */
  226.     int nchars;
  227.     /* First character is numbered... (usually 32 = space) */
  228.     int offset;
  229.     /* Character width and height */
  230.     int w;
  231.     int h;
  232.     /* Font data; array of characters, one row after another.
  233.        Easily included in code, also easily loaded from
  234.        data files. */
  235.     char *data;
  236.   }
  237.   gdFont;
  238.  
  239. /* Text functions take these. */
  240.   typedef gdFont *gdFontPtr;
  241.  
  242. /* For backwards compatibility only. Use gdImageSetStyle()
  243.     for MUCH more flexible line drawing. Also see
  244.     gdImageSetBrush(). */
  245. #define gdDashSize 4
  246.  
  247. /* Special colors. */
  248.  
  249. #define gdStyled (-2)
  250. #define gdBrushed (-3)
  251. #define gdStyledBrushed (-4)
  252. #define gdTiled (-5)
  253.  
  254. /* NOT the same as the transparent color index.
  255.     This is used in line styles only. */
  256. #define gdTransparent (-6)
  257.  
  258. #define gdAntiAliased (-7)
  259.  
  260. /* Functions to manipulate images. */
  261.  
  262. /* Creates a palette-based image (up to 256 colors). */
  263. BGD_DECLARE(gdImagePtr) gdImageCreate (int sx, int sy);
  264.  
  265. /* An alternate name for the above (2.0). */
  266. #define gdImageCreatePalette gdImageCreate
  267.  
  268. /* Creates a truecolor image (millions of colors). */
  269. BGD_DECLARE(gdImagePtr) gdImageCreateTrueColor (int sx, int sy);
  270.  
  271. /* Creates an image from various file types. These functions
  272.     return a palette or truecolor image based on the
  273.     nature of the file being loaded. Truecolor PNG
  274.     stays truecolor; palette PNG stays palette-based;
  275.     JPEG is always truecolor. */
  276. BGD_DECLARE(gdImagePtr) gdImageCreateFromPng (FILE * fd);
  277. BGD_DECLARE(gdImagePtr) gdImageCreateFromPngCtx (gdIOCtxPtr in);
  278. BGD_DECLARE(gdImagePtr) gdImageCreateFromPngPtr (int size, void *data);
  279.  
  280. /* These read the first frame only */
  281. BGD_DECLARE(gdImagePtr) gdImageCreateFromGif (FILE * fd);
  282. BGD_DECLARE(gdImagePtr) gdImageCreateFromGifCtx (gdIOCtxPtr in);
  283. BGD_DECLARE(gdImagePtr) gdImageCreateFromGifPtr (int size, void *data);
  284. BGD_DECLARE(gdImagePtr) gdImageCreateFromWBMP (FILE * inFile);
  285. BGD_DECLARE(gdImagePtr) gdImageCreateFromWBMPCtx (gdIOCtx * infile);
  286. BGD_DECLARE(gdImagePtr) gdImageCreateFromWBMPPtr (int size, void *data);
  287. BGD_DECLARE(gdImagePtr) gdImageCreateFromJpeg (FILE * infile);
  288. BGD_DECLARE(gdImagePtr) gdImageCreateFromJpegCtx (gdIOCtx * infile);
  289. BGD_DECLARE(gdImagePtr) gdImageCreateFromJpegPtr (int size, void *data);
  290.  
  291. /* A custom data source. */
  292. /* The source function must return -1 on error, otherwise the number
  293.         of bytes fetched. 0 is EOF, not an error! */
  294. /* context will be passed to your source function. */
  295.  
  296.   typedef struct
  297.   {
  298.     int (*source) (void *context, char *buffer, int len);
  299.     void *context;
  300.   }
  301.   gdSource, *gdSourcePtr;
  302.  
  303.    /* Deprecated in favor of gdImageCreateFromPngCtx */
  304. BGD_DECLARE(gdImagePtr) gdImageCreateFromPngSource (gdSourcePtr in);
  305.  
  306. BGD_DECLARE(gdImagePtr) gdImageCreateFromGd (FILE * in);
  307. BGD_DECLARE(gdImagePtr) gdImageCreateFromGdCtx (gdIOCtxPtr in);
  308. BGD_DECLARE(gdImagePtr) gdImageCreateFromGdPtr (int size, void *data);
  309.  
  310. BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2 (FILE * in);
  311. BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2Ctx (gdIOCtxPtr in);
  312. BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2Ptr (int size, void *data);
  313.  
  314. BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2Part (FILE * in, int srcx, int srcy, int w,
  315.                        int h);
  316. BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2PartCtx (gdIOCtxPtr in, int srcx, int srcy,
  317.                       int w, int h);
  318. BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2PartPtr (int size, void *data, int srcx, int srcy,
  319.                       int w, int h);
  320.   /* 2.0.10: prototype was missing */
  321. BGD_DECLARE(gdImagePtr) gdImageCreateFromXbm (FILE * in);
  322.  
  323.   /* NOTE: filename, not FILE */
  324. BGD_DECLARE(gdImagePtr) gdImageCreateFromXpm (char *filename);
  325.  
  326. BGD_DECLARE(void) gdImageDestroy (gdImagePtr im);
  327.  
  328. /* Replaces or blends with the background depending on the
  329.     most recent call to gdImageAlphaBlending and the
  330.     alpha channel value of 'color'; default is to overwrite. 
  331.     Tiling and line styling are also implemented
  332.     here. All other gd drawing functions pass through this call, 
  333.     allowing for many useful effects. */
  334.  
  335. BGD_DECLARE(void) gdImageSetPixel (gdImagePtr im, int x, int y, int color);
  336. /* FreeType 2 text output with hook to extra flags */
  337.  
  338. BGD_DECLARE(int) gdImageGetPixel (gdImagePtr im, int x, int y);
  339. BGD_DECLARE(int) gdImageGetTrueColorPixel (gdImagePtr im, int x, int y);
  340.  
  341. BGD_DECLARE(void) gdImageAABlend (gdImagePtr im);
  342.  
  343. BGD_DECLARE(void) gdImageLine (gdImagePtr im, int x1, int y1, int x2, int y2, int color);
  344.  
  345. /* For backwards compatibility only. Use gdImageSetStyle()
  346.     for much more flexible line drawing. */
  347. BGD_DECLARE(void) gdImageDashedLine (gdImagePtr im, int x1, int y1, int x2, int y2,
  348.               int color);
  349. /* Corners specified (not width and height). Upper left first, lower right
  350.      second. */
  351. BGD_DECLARE(void) gdImageRectangle (gdImagePtr im, int x1, int y1, int x2, int y2,
  352.              int color);
  353. /* Solid bar. Upper left corner first, lower right corner second. */
  354. BGD_DECLARE(void) gdImageFilledRectangle (gdImagePtr im, int x1, int y1, int x2, int y2,
  355.                    int color);
  356. BGD_DECLARE(void) gdImageSetClip(gdImagePtr im, int x1, int y1, int x2, int y2);
  357. BGD_DECLARE(void) gdImageGetClip(gdImagePtr im, int *x1P, int *y1P, int *x2P, int *y2P);
  358. BGD_DECLARE(int) gdImageBoundsSafe (gdImagePtr im, int x, int y);
  359. BGD_DECLARE(void) gdImageChar (gdImagePtr im, gdFontPtr f, int x, int y, int c,
  360.             int color);
  361. BGD_DECLARE(void) gdImageCharUp (gdImagePtr im, gdFontPtr f, int x, int y, int c,
  362.               int color);
  363. BGD_DECLARE(void) gdImageString (gdImagePtr im, gdFontPtr f, int x, int y,
  364.               unsigned char *s, int color);
  365. BGD_DECLARE(void) gdImageStringUp (gdImagePtr im, gdFontPtr f, int x, int y,
  366.             unsigned char *s, int color);
  367. BGD_DECLARE(void) gdImageString16 (gdImagePtr im, gdFontPtr f, int x, int y,
  368.             unsigned short *s, int color);
  369. BGD_DECLARE(void) gdImageStringUp16 (gdImagePtr im, gdFontPtr f, int x, int y,
  370.               unsigned short *s, int color);
  371.  
  372. /* 2.0.16: for thread-safe use of gdImageStringFT and friends,
  373.   call this before allowing any thread to call gdImageStringFT. 
  374.   Otherwise it is invoked by the first thread to invoke
  375.   gdImageStringFT, with a very small but real risk of a race condition. 
  376.   Return 0 on success, nonzero on failure to initialize freetype. */
  377. BGD_DECLARE(int) gdFontCacheSetup (void);
  378.  
  379. /* Optional: clean up after application is done using fonts in 
  380. BGD_DECLARE( ) gdImageStringFT(). */
  381. BGD_DECLARE(void) gdFontCacheShutdown (void);
  382. /* 2.0.20: for backwards compatibility. A few applications did start calling
  383.  this function when it first appeared although it was never documented. 
  384.  Simply invokes gdFontCacheShutdown. */
  385. BGD_DECLARE(void) gdFreeFontCache (void);
  386.  
  387. /* Calls gdImageStringFT. Provided for backwards compatibility only. */
  388. BGD_DECLARE(char *) gdImageStringTTF (gdImage * im, int *brect, int fg, char *fontlist,
  389.               double ptsize, double angle, int x, int y,
  390.               char *string);
  391.  
  392. /* FreeType 2 text output */
  393. BGD_DECLARE(char *) gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist,
  394.              double ptsize, double angle, int x, int y,
  395.              char *string);
  396.  
  397. /* 2.0.5: provides an extensible way to pass additional parameters.
  398.     Thanks to Wez Furlong, sorry for the delay. */
  399.  
  400.   typedef struct
  401.   {
  402.     int flags;            /* Logical OR of gdFTEX_ values */
  403.     double linespacing;        /* fine tune line spacing for '\n' */
  404.     int charmap;        /* TBB: 2.0.12: may be gdFTEX_Unicode,
  405.                    gdFTEX_Shift_JIS, gdFTEX_Big5,
  406.                    or gdFTEX_Adobe_Custom;
  407.                    when not specified, maps are searched
  408.                    for in the above order. */
  409.     int hdpi;                   /* if (flags & gdFTEX_RESOLUTION) */
  410.     int vdpi;            /* if (flags & gdFTEX_RESOLUTION) */
  411.     char *xshow;    /* if (flags & gdFTEX_XSHOW)
  412.                then, on return, xshow is a malloc'ed
  413.                string contining xshow position data for
  414.                the last string.
  415.  
  416.                NB. The caller is responsible for gdFree'ing
  417.                the xshow string. 
  418.              */
  419.     char *fontpath;    /* if (flags & gdFTEX_RETURNFONTPATHNAME)
  420.                            then, on return, fontpath is a malloc'ed
  421.                            string containing the actual font file path name
  422.                            used, which can be interesting when fontconfig
  423.                            is in use. 
  424.  
  425.                            The caller is responsible for gdFree'ing the
  426.                            fontpath string.
  427.             */
  428.  
  429.   }
  430.   gdFTStringExtra, *gdFTStringExtraPtr;
  431.  
  432. #define gdFTEX_LINESPACE 1
  433. #define gdFTEX_CHARMAP 2
  434. #define gdFTEX_RESOLUTION 4
  435. #define gdFTEX_DISABLE_KERNING 8
  436. #define gdFTEX_XSHOW 16
  437. /* The default unless gdFTUseFontConfig(1); has been called:
  438.   fontlist is a full or partial font file pathname or list thereof 
  439.   (i.e. just like before 2.0.29) */
  440. #define gdFTEX_FONTPATHNAME 32
  441. /* Necessary to use fontconfig patterns instead of font pathnames
  442.   as the fontlist argument, unless gdFTUseFontConfig(1); has 
  443.   been called. New in 2.0.29 */
  444. #define gdFTEX_FONTCONFIG 64
  445. /* Sometimes interesting when fontconfig is used: the fontpath
  446.   element of the structure above will contain a gdMalloc'd string
  447.   copy of the actual font file pathname used, if this flag is set 
  448.    when the call is made */
  449. #define gdFTEX_RETURNFONTPATHNAME 128
  450.  
  451. /* If flag is nonzero, the fontlist parameter to gdImageStringFT 
  452.   and gdImageStringFTEx shall be assumed to be a fontconfig font pattern
  453.   if fontconfig was compiled into gd. This function returns zero
  454.   if fontconfig is not available, nonzero otherwise. */
  455. BGD_DECLARE(int) gdFTUseFontConfig(int flag);
  456.  
  457. /* These are NOT flags; set one in 'charmap' if you set the
  458.     gdFTEX_CHARMAP bit in 'flags'. */
  459. #define gdFTEX_Unicode 0
  460. #define gdFTEX_Shift_JIS 1
  461. #define gdFTEX_Big5 2
  462. #define gdFTEX_Adobe_Custom 3
  463.  
  464. BGD_DECLARE(char *) gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist,
  465.                double ptsize, double angle, int x, int y,
  466.                char *string, gdFTStringExtraPtr strex);
  467.  
  468. /* Point type for use in polygon drawing. */
  469.   typedef struct
  470.   {
  471.     int x, y;
  472.   }
  473.   gdPoint, *gdPointPtr;
  474.  
  475. BGD_DECLARE(void) gdImagePolygon (gdImagePtr im, gdPointPtr p, int n, int c);
  476. BGD_DECLARE(void) gdImageOpenPolygon (gdImagePtr im, gdPointPtr p, int n, int c);
  477. BGD_DECLARE(void) gdImageFilledPolygon (gdImagePtr im, gdPointPtr p, int n, int c);
  478.  
  479. /* These functions still work with truecolor images, 
  480.     for which they never return error. */
  481. BGD_DECLARE(int) gdImageColorAllocate (gdImagePtr im, int r, int g, int b);
  482. /* gd 2.0: palette entries with non-opaque transparency are permitted. */
  483. BGD_DECLARE(int) gdImageColorAllocateAlpha (gdImagePtr im, int r, int g, int b, int a);
  484. /* Assumes opaque is the preferred alpha channel value */
  485. BGD_DECLARE(int) gdImageColorClosest (gdImagePtr im, int r, int g, int b);
  486. /* Closest match taking all four parameters into account.
  487.     A slightly different color with the same transparency
  488.     beats the exact same color with radically different
  489.     transparency */
  490. BGD_DECLARE(int) gdImageColorClosestAlpha (gdImagePtr im, int r, int g, int b, int a);
  491. /* An alternate method */
  492. BGD_DECLARE(int) gdImageColorClosestHWB (gdImagePtr im, int r, int g, int b);
  493. /* Returns exact, 100% opaque matches only */
  494. BGD_DECLARE(int) gdImageColorExact (gdImagePtr im, int r, int g, int b);
  495. /* Returns an exact match only, including alpha */
  496. BGD_DECLARE(int) gdImageColorExactAlpha (gdImagePtr im, int r, int g, int b, int a);
  497. /* Opaque only */
  498. BGD_DECLARE(int) gdImageColorResolve (gdImagePtr im, int r, int g, int b);
  499. /* Based on gdImageColorExactAlpha and gdImageColorClosestAlpha */
  500. BGD_DECLARE(int) gdImageColorResolveAlpha (gdImagePtr im, int r, int g, int b, int a);
  501.  
  502. /* A simpler way to obtain an opaque truecolor value for drawing on a
  503.     truecolor image. Not for use with palette images! */
  504.  
  505. #define gdTrueColor(r, g, b) (((r) << 16) + \
  506.     ((g) << 8) + \
  507.     (b))
  508.  
  509. /* Returns a truecolor value with an alpha channel component.
  510.     gdAlphaMax (127, **NOT 255**) is transparent, 0 is completely
  511.     opaque. */
  512.  
  513. #define gdTrueColorAlpha(r, g, b, a) (((a) << 24) + \
  514.     ((r) << 16) + \
  515.     ((g) << 8) + \
  516.     (b))
  517.  
  518. BGD_DECLARE(void) gdImageColorDeallocate (gdImagePtr im, int color);
  519.  
  520. /* Converts a truecolor image to a palette-based image,
  521.     using a high-quality two-pass quantization routine
  522.     which attempts to preserve alpha channel information
  523.     as well as R/G/B color information when creating
  524.     a palette. If ditherFlag is set, the image will be
  525.     dithered to approximate colors better, at the expense
  526.     of some obvious "speckling." colorsWanted can be
  527.     anything up to 256. If the original source image
  528.     includes photographic information or anything that
  529.     came out of a JPEG, 256 is strongly recommended.
  530.  
  531.     Better yet, don't use these function -- write real
  532.     truecolor PNGs and JPEGs. The disk space gain of
  533.         conversion to palette is not great (for small images
  534.         it can be negative) and the quality loss is ugly. 
  535.  
  536.     DIFFERENCES: gdImageCreatePaletteFromTrueColor creates and
  537.     returns a new image. gdImageTrueColorToPalette modifies 
  538.     an existing image, and the truecolor pixels are discarded. */
  539.  
  540. BGD_DECLARE(gdImagePtr) gdImageCreatePaletteFromTrueColor (gdImagePtr im, int ditherFlag,
  541.                   int colorsWanted);
  542.  
  543. BGD_DECLARE(void) gdImageTrueColorToPalette (gdImagePtr im, int ditherFlag,
  544.                   int colorsWanted);
  545.  
  546. /* Specifies a color index (if a palette image) or an
  547.     RGB color (if a truecolor image) which should be
  548.     considered 100% transparent. FOR TRUECOLOR IMAGES,
  549.     THIS IS IGNORED IF AN ALPHA CHANNEL IS BEING
  550.     SAVED. Use gdImageSaveAlpha(im, 0); to
  551.     turn off the saving of a full alpha channel in
  552.     a truecolor image. Note that gdImageColorTransparent
  553.     is usually compatible with older browsers that
  554.     do not understand full alpha channels well. TBB */
  555. BGD_DECLARE(void) gdImageColorTransparent (gdImagePtr im, int color);
  556.  
  557. BGD_DECLARE(void) gdImagePaletteCopy (gdImagePtr dst, gdImagePtr src);
  558. BGD_DECLARE(void) gdImageGif (gdImagePtr im, FILE * out);
  559. BGD_DECLARE(void) gdImagePng (gdImagePtr im, FILE * out);
  560. BGD_DECLARE(void) gdImagePngCtx (gdImagePtr im, gdIOCtx * out);
  561. BGD_DECLARE(void) gdImageGifCtx (gdImagePtr im, gdIOCtx * out);
  562.  
  563. /* 2.0.12: Compression level: 0-9 or -1, where 0 is NO COMPRESSION at all,
  564.   1 is FASTEST but produces larger files, 9 provides the best
  565.   compression (smallest files) but takes a long time to compress, and
  566.   -1 selects the default compiled into the zlib library. */
  567. BGD_DECLARE(void) gdImagePngEx (gdImagePtr im, FILE * out, int level);
  568. BGD_DECLARE(void) gdImagePngCtxEx (gdImagePtr im, gdIOCtx * out, int level);
  569.  
  570. BGD_DECLARE(void) gdImageWBMP (gdImagePtr image, int fg, FILE * out);
  571. BGD_DECLARE(void) gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out);
  572.  
  573. /* Guaranteed to correctly free memory returned
  574.     by the gdImage*Ptr functions */
  575. BGD_DECLARE(void) gdFree (void *m);
  576.  
  577. /* Best to free this memory with gdFree(), not free() */
  578. BGD_DECLARE(void *) gdImageWBMPPtr (gdImagePtr im, int *size, int fg);
  579.  
  580. /* 100 is highest quality (there is always a little loss with JPEG).
  581.     0 is lowest. 10 is about the lowest useful setting. */
  582. BGD_DECLARE(void) gdImageJpeg (gdImagePtr im, FILE * out, int quality);
  583. BGD_DECLARE(void) gdImageJpegCtx (gdImagePtr im, gdIOCtx * out, int quality);
  584.  
  585. /* Best to free this memory with gdFree(), not free() */
  586. BGD_DECLARE(void *) gdImageJpegPtr (gdImagePtr im, int *size, int quality);
  587.  
  588. /* Legal values for Disposal. gdDisposalNone is always used by
  589.     the built-in optimizer if previm is passed. */
  590.  
  591. enum {
  592.     gdDisposalUnknown,
  593.     gdDisposalNone,
  594.     gdDisposalRestoreBackground,
  595.     gdDisposalRestorePrevious
  596. };
  597.  
  598. BGD_DECLARE(void) gdImageGifAnimBegin(gdImagePtr im, FILE *outFile, int GlobalCM, int Loops);
  599. BGD_DECLARE(void) gdImageGifAnimAdd(gdImagePtr im, FILE *outFile, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, gdImagePtr previm);
  600. BGD_DECLARE(void) gdImageGifAnimEnd(FILE *outFile);
  601. BGD_DECLARE(void) gdImageGifAnimBeginCtx(gdImagePtr im, gdIOCtx *out, int GlobalCM, int Loops);
  602. BGD_DECLARE(void) gdImageGifAnimAddCtx(gdImagePtr im, gdIOCtx *out, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, gdImagePtr previm);
  603. BGD_DECLARE(void) gdImageGifAnimEndCtx(gdIOCtx *out);
  604. BGD_DECLARE(void *) gdImageGifAnimBeginPtr(gdImagePtr im, int *size, int GlobalCM, int Loops);
  605. BGD_DECLARE(void *) gdImageGifAnimAddPtr(gdImagePtr im, int *size, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, gdImagePtr previm);
  606. BGD_DECLARE(void *) gdImageGifAnimEndPtr(int *size);
  607.  
  608. /* A custom data sink. For backwards compatibility. Use
  609.     gdIOCtx instead. */
  610. /* The sink function must return -1 on error, otherwise the number
  611.         of bytes written, which must be equal to len. */
  612. /* context will be passed to your sink function. */
  613.   typedef struct
  614.   {
  615.     int (*sink) (void *context, const char *buffer, int len);
  616.     void *context;
  617.   }
  618.   gdSink, *gdSinkPtr;
  619.  
  620. BGD_DECLARE(void) gdImagePngToSink (gdImagePtr im, gdSinkPtr out);
  621.  
  622. BGD_DECLARE(void) gdImageGd (gdImagePtr im, FILE * out);
  623. BGD_DECLARE(void) gdImageGd2 (gdImagePtr im, FILE * out, int cs, int fmt);
  624.  
  625. /* Best to free this memory with gdFree(), not free() */
  626. BGD_DECLARE(void *) gdImageGifPtr (gdImagePtr im, int *size);
  627.  
  628. /* Best to free this memory with gdFree(), not free() */
  629. BGD_DECLARE(void *) gdImagePngPtr (gdImagePtr im, int *size);
  630. BGD_DECLARE(void *) gdImagePngPtrEx (gdImagePtr im, int *size, int level);
  631.  
  632. /* Best to free this memory with gdFree(), not free() */
  633. BGD_DECLARE(void *) gdImageGdPtr (gdImagePtr im, int *size);
  634.  
  635. /* Best to free this memory with gdFree(), not free() */
  636. BGD_DECLARE(void *) gdImageGd2Ptr (gdImagePtr im, int cs, int fmt, int *size);
  637.  
  638. BGD_DECLARE(void) gdImageEllipse (gdImagePtr im, int cx, int cy, int w, int h,
  639.                int color);
  640.  
  641. /* Style is a bitwise OR ( | operator ) of these.
  642.     gdArc and gdChord are mutually exclusive;
  643.     gdChord just connects the starting and ending
  644.     angles with a straight line, while gdArc produces
  645.     a rounded edge. gdPie is a synonym for gdArc. 
  646.     gdNoFill indicates that the arc or chord should be
  647.     outlined, not filled. gdEdged, used together with
  648.     gdNoFill, indicates that the beginning and ending
  649.     angles should be connected to the center; this is
  650.     a good way to outline (rather than fill) a
  651.     'pie slice'. */
  652. #define gdArc   0
  653. #define gdPie   gdArc
  654. #define gdChord 1
  655. #define gdNoFill 2
  656. #define gdEdged 4
  657.  
  658. BGD_DECLARE(void) gdImageFilledArc (gdImagePtr im, int cx, int cy, int w, int h, int s,
  659.              int e, int color, int style);
  660. BGD_DECLARE(void) gdImageArc (gdImagePtr im, int cx, int cy, int w, int h, int s, int e,
  661.            int color);
  662. BGD_DECLARE(void) gdImageEllipse(gdImagePtr im, int cx, int cy, int w, int h, int color);
  663. BGD_DECLARE(void) gdImageFilledEllipse (gdImagePtr im, int cx, int cy, int w, int h,
  664.                  int color);
  665. BGD_DECLARE(void) gdImageFillToBorder (gdImagePtr im, int x, int y, int border,
  666.                 int color);
  667. BGD_DECLARE(void) gdImageFill (gdImagePtr im, int x, int y, int color);
  668. BGD_DECLARE(void) gdImageCopy (gdImagePtr dst, gdImagePtr src, int dstX, int dstY,
  669.             int srcX, int srcY, int w, int h);
  670. BGD_DECLARE(void) gdImageCopyMerge (gdImagePtr dst, gdImagePtr src, int dstX, int dstY,
  671.              int srcX, int srcY, int w, int h, int pct);
  672. BGD_DECLARE(void) gdImageCopyMergeGray (gdImagePtr dst, gdImagePtr src, int dstX,
  673.                  int dstY, int srcX, int srcY, int w, int h,
  674.                  int pct);
  675.  
  676. /* Stretches or shrinks to fit, as needed. Does NOT attempt
  677.     to average the entire set of source pixels that scale down onto the
  678.     destination pixel. */
  679. BGD_DECLARE(void) gdImageCopyResized (gdImagePtr dst, gdImagePtr src, int dstX, int dstY,
  680.                int srcX, int srcY, int dstW, int dstH, int srcW,
  681.                int srcH);
  682.  
  683. /* gd 2.0: stretches or shrinks to fit, as needed. When called with a
  684.     truecolor destination image, this function averages the
  685.     entire set of source pixels that scale down onto the
  686.     destination pixel, taking into account what portion of the
  687.     destination pixel each source pixel represents. This is a
  688.     floating point operation, but this is not a performance issue
  689.     on modern hardware, except for some embedded devices. If the 
  690.     destination is a palette image, gdImageCopyResized is 
  691.     substituted automatically. */
  692. BGD_DECLARE(void) gdImageCopyResampled (gdImagePtr dst, gdImagePtr src, int dstX,
  693.                  int dstY, int srcX, int srcY, int dstW, int dstH,
  694.                  int srcW, int srcH);
  695.  
  696. /* gd 2.0.8: gdImageCopyRotated is added. Source
  697.         is a rectangle, with its upper left corner at
  698.         srcX and srcY. Destination is the *center* of
  699.         the rotated copy. Angle is in degrees, same as
  700.         gdImageArc. Floating point destination center
  701.         coordinates allow accurate rotation of
  702.         objects of odd-numbered width or height. */
  703. BGD_DECLARE(void) gdImageCopyRotated (gdImagePtr dst,
  704.                gdImagePtr src,
  705.                double dstX, double dstY,
  706.                int srcX, int srcY,
  707.                int srcWidth, int srcHeight, int angle);
  708.  
  709. BGD_DECLARE(void) gdImageSetBrush (gdImagePtr im, gdImagePtr brush);
  710. BGD_DECLARE(void) gdImageSetTile (gdImagePtr im, gdImagePtr tile);
  711. BGD_DECLARE(void) gdImageSetAntiAliased (gdImagePtr im, int c);
  712. BGD_DECLARE(void) gdImageSetAntiAliasedDontBlend (gdImagePtr im, int c, int dont_blend);
  713. BGD_DECLARE(void) gdImageSetStyle (gdImagePtr im, int *style, int noOfPixels);
  714. /* Line thickness (defaults to 1). Affects lines, ellipses, 
  715.     rectangles, polygons and so forth. */
  716. BGD_DECLARE(void) gdImageSetThickness (gdImagePtr im, int thickness);
  717. /* On or off (1 or 0) for all three of these. */
  718. BGD_DECLARE(void) gdImageInterlace (gdImagePtr im, int interlaceArg);
  719. BGD_DECLARE(void) gdImageAlphaBlending (gdImagePtr im, int alphaBlendingArg);
  720. BGD_DECLARE(void) gdImageSaveAlpha (gdImagePtr im, int saveAlphaArg);
  721.  
  722. /* Macros to access information about images. */
  723.  
  724. /* Returns nonzero if the image is a truecolor image,
  725.     zero for a palette image. */
  726.  
  727. #define gdImageTrueColor(im) ((im)->trueColor)
  728.  
  729. #define gdImageSX(im) ((im)->sx)
  730. #define gdImageSY(im) ((im)->sy)
  731. #define gdImageColorsTotal(im) ((im)->colorsTotal)
  732. #define gdImageRed(im, c) ((im)->trueColor ? gdTrueColorGetRed(c) : \
  733.     (im)->red[(c)])
  734. #define gdImageGreen(im, c) ((im)->trueColor ? gdTrueColorGetGreen(c) : \
  735.     (im)->green[(c)])
  736. #define gdImageBlue(im, c) ((im)->trueColor ? gdTrueColorGetBlue(c) : \
  737.     (im)->blue[(c)])
  738. #define gdImageAlpha(im, c) ((im)->trueColor ? gdTrueColorGetAlpha(c) : \
  739.     (im)->alpha[(c)])
  740. #define gdImageGetTransparent(im) ((im)->transparent)
  741. #define gdImageGetInterlaced(im) ((im)->interlace)
  742.  
  743. /* These macros provide direct access to pixels in
  744.     palette-based and truecolor images, respectively.
  745.     If you use these macros, you must perform your own
  746.     bounds checking. Use of the macro for the correct type
  747.     of image is also your responsibility. */
  748. #define gdImagePalettePixel(im, x, y) (im)->pixels[(y)][(x)]
  749. #define gdImageTrueColorPixel(im, x, y) (im)->tpixels[(y)][(x)]
  750.  
  751. /* I/O Support routines. */
  752.  
  753. BGD_DECLARE(gdIOCtx *) gdNewFileCtx (FILE *);
  754.   /* If data is null, size is ignored and an initial data buffer is
  755.     allocated automatically. NOTE: this function assumes gd has the right 
  756.     to free or reallocate "data" at will! Also note that gd will free 
  757.     "data" when the IO context is freed. If data is not null, it must point
  758.     to memory allocated with gdMalloc, or by a call to gdImage[something]Ptr.
  759.     If not, see gdNewDynamicCtxEx for an alternative. */
  760. BGD_DECLARE(gdIOCtx *) gdNewDynamicCtx (int size, void *data);
  761.   /* 2.0.21: if freeFlag is nonzero, gd will free and/or reallocate "data" as
  762.     needed as described above. If freeFlag is zero, gd will never free 
  763.     or reallocate "data," which means that the context should only be used
  764.     for *reading* an image from a memory buffer, or writing an image to a
  765.     memory buffer which is already large enough. If the memory buffer is
  766.     not large enough and an image write is attempted, the write operation
  767.     will fail. Those wishing to write an image to a buffer in memory have
  768.     a much simpler alternative in the gdImage[something]Ptr functions. */
  769. BGD_DECLARE(gdIOCtx *) gdNewDynamicCtxEx (int size, void *data, int freeFlag);
  770. BGD_DECLARE(gdIOCtx *) gdNewSSCtx (gdSourcePtr in, gdSinkPtr out);
  771. BGD_DECLARE(void *) gdDPExtractData (struct gdIOCtx *ctx, int *size);
  772.  
  773. #define GD2_CHUNKSIZE           128
  774. #define GD2_CHUNKSIZE_MIN    64
  775. #define GD2_CHUNKSIZE_MAX       4096
  776.  
  777. #define GD2_VERS                2
  778. #define GD2_ID                  "gd2"
  779.  
  780. #define GD2_FMT_RAW             1
  781. #define GD2_FMT_COMPRESSED      2
  782.  
  783. /* Image comparison definitions */
  784. BGD_DECLARE(int) gdImageCompare (gdImagePtr im1, gdImagePtr im2);
  785.  
  786. #define GD_CMP_IMAGE        1    /* Actual image IS different */
  787. #define GD_CMP_NUM_COLORS    2    /* Number of Colours in pallette differ */
  788. #define GD_CMP_COLOR        4    /* Image colours differ */
  789. #define GD_CMP_SIZE_X        8    /* Image width differs */
  790. #define GD_CMP_SIZE_Y        16    /* Image heights differ */
  791. #define GD_CMP_TRANSPARENT    32    /* Transparent colour */
  792. #define GD_CMP_BACKGROUND    64    /* Background colour */
  793. #define GD_CMP_INTERLACE    128    /* Interlaced setting */
  794. #define GD_CMP_TRUECOLOR    256    /* Truecolor vs palette differs */
  795.  
  796. /* resolution affects ttf font rendering, particularly hinting */
  797. #define GD_RESOLUTION           96    /* pixels per inch */
  798.  
  799. #ifdef __cplusplus
  800. }
  801. #endif
  802.  
  803. /* newfangled special effects */
  804. #include "gdfx.h"
  805.  
  806. #endif                /* GD_H */
  807.  
  808. #ifdef __cplusplus
  809. }
  810. #endif
  811.