G:/ScriptBasic/source/extensions/gd/gd.h

Go to the documentation of this file.
00001 #ifndef GD_H
00002 #define GD_H 1
00003 
00004 #ifdef __cplusplus
00005 extern "C" {
00006 #endif
00007 
00008 /* gd.h: declarations file for the graphic-draw module.
00009  * Permission to use, copy, modify, and distribute this software and its
00010  * documentation for any purpose and without fee is hereby granted, provided
00011  * that the above copyright notice appear in all copies and that both that
00012  * copyright notice and this permission notice appear in supporting
00013  * documentation.  This software is provided "AS IS." Thomas Boutell and
00014  * Boutell.Com, Inc. disclaim all warranties, either express or implied, 
00015  * including but not limited to implied warranties of merchantability and 
00016  * fitness for a particular purpose, with respect to this code and accompanying
00017  * documentation. */
00018 
00019 /* stdio is needed for file I/O. */
00020 #include <stdio.h>
00021 #include "gd_io.h"
00022 
00023 /* This can't be changed in the current palette-only version of gd. */
00024 
00025 #define gdMaxColors 256
00026 
00027 /* Image type. See functions below; you will not need to change
00028         the elements directly. Use the provided macros to
00029         access sx, sy, the color table, and colorsTotal for 
00030         read-only purposes. */
00031 
00032 typedef struct gdImageStruct {
00033         unsigned char ** pixels;
00034         int sx;
00035         int sy;
00036         int colorsTotal;
00037         int red[gdMaxColors];
00038         int green[gdMaxColors];
00039         int blue[gdMaxColors]; 
00040         int open[gdMaxColors];
00041         int transparent;
00042         int *polyInts;
00043         int polyAllocated;
00044         struct gdImageStruct *brush;
00045         struct gdImageStruct *tile;     
00046         int brushColorMap[gdMaxColors];
00047         int tileColorMap[gdMaxColors];
00048         int styleLength;
00049         int stylePos;
00050         int *style;
00051         int interlace;
00052 } gdImage;
00053 
00054 typedef gdImage * gdImagePtr;
00055 
00056 typedef struct {
00057         /* # of characters in font */
00058         int nchars;
00059         /* First character is numbered... (usually 32 = space) */
00060         int offset;
00061         /* Character width and height */
00062         int w;
00063         int h;
00064         /* Font data; array of characters, one row after another.
00065                 Easily included in code, also easily loaded from
00066                 data files. */
00067         char *data;
00068 } gdFont;
00069 
00070 /* Text functions take these. */
00071 typedef gdFont *gdFontPtr;
00072 
00073 /* For backwards compatibility only. Use gdImageSetStyle()
00074         for MUCH more flexible line drawing. Also see
00075         gdImageSetBrush(). */
00076 #define gdDashSize 4
00077 
00078 /* Special colors. */
00079 
00080 #define gdStyled (-2)
00081 #define gdBrushed (-3)
00082 #define gdStyledBrushed (-4)
00083 #define gdTiled (-5)
00084 
00085 /* NOT the same as the transparent color index.
00086         This is used in line styles only. */
00087 #define gdTransparent (-6)
00088 
00089 /* Functions to manipulate images. */
00090 
00091 gdImagePtr gdImageCreate(int sx, int sy);
00092 gdImagePtr gdImageCreateFromPng(FILE *fd);
00093 gdImagePtr gdImageCreateFromPngCtx(gdIOCtxPtr in);
00094 
00095 /* A custom data source. */
00096 /* The source function must return -1 on error, otherwise the number
00097         of bytes fetched. 0 is EOF, not an error! */
00098 /* context will be passed to your source function. */
00099 
00100 typedef struct {
00101         int (*source) (void *context, char *buffer, int len);
00102         void *context;
00103 } gdSource, *gdSourcePtr;
00104 
00105 gdImagePtr gdImageCreateFromPngSource(gdSourcePtr in);
00106 
00107 gdImagePtr gdImageCreateFromGd(FILE *in);
00108 gdImagePtr gdImageCreateFromGdCtx(gdIOCtxPtr in);
00109 
00110 gdImagePtr gdImageCreateFromGd2(FILE *in);
00111 gdImagePtr gdImageCreateFromGd2Ctx(gdIOCtxPtr in);
00112 
00113 gdImagePtr gdImageCreateFromGd2Part(FILE *in, int srcx, int srcy, int w, int h);
00114 gdImagePtr gdImageCreateFromGd2PartCtx(gdIOCtxPtr in, int srcx, int srcy, int w, int h);
00115 
00116 gdImagePtr gdImageCreateFromXbm(FILE *fd);
00117 
00118 void gdImageDestroy(gdImagePtr im);
00119 void gdImageSetPixel(gdImagePtr im, int x, int y, int color);
00120 int gdImageGetPixel(gdImagePtr im, int x, int y);
00121 void gdImageLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
00122 /* For backwards compatibility only. Use gdImageSetStyle()
00123         for much more flexible line drawing. */
00124 void gdImageDashedLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
00125 /* Corners specified (not width and height). Upper left first, lower right
00126         second. */
00127 void gdImageRectangle(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
00128 /* Solid bar. Upper left corner first, lower right corner second. */
00129 void gdImageFilledRectangle(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
00130 int gdImageBoundsSafe(gdImagePtr im, int x, int y);
00131 void gdImageChar(gdImagePtr im, gdFontPtr f, int x, int y, int c, int color);
00132 void gdImageCharUp(gdImagePtr im, gdFontPtr f, int x, int y, int c, int color);
00133 void gdImageString(gdImagePtr im, gdFontPtr f, int x, int y, unsigned char *s, int color);
00134 void gdImageStringUp(gdImagePtr im, gdFontPtr f, int x, int y, unsigned char *s, int color);
00135 void gdImageString16(gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color);
00136 void gdImageStringUp16(gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color);
00137 
00138 char *gdImageStringTTF(gdImage *im, int *brect, int fg, char *fontname,
00139                 double ptsize, double angle, int x, int y, char *string);
00140 
00141 /* Point type for use in polygon drawing. */
00142 
00143 typedef struct {
00144         int x, y;
00145 } gdPoint, *gdPointPtr;
00146 
00147 void gdImagePolygon(gdImagePtr im, gdPointPtr p, int n, int c);
00148 void gdImageFilledPolygon(gdImagePtr im, gdPointPtr p, int n, int c);
00149 
00150 int gdImageColorAllocate(gdImagePtr im, int r, int g, int b);
00151 int gdImageColorClosest(gdImagePtr im, int r, int g, int b);
00152 int gdImageColorExact(gdImagePtr im, int r, int g, int b);
00153 int gdImageColorResolve(gdImagePtr im, int r, int g, int b);
00154 void gdImageColorDeallocate(gdImagePtr im, int color);
00155 void gdImageColorTransparent(gdImagePtr im, int color);
00156 void gdImagePaletteCopy(gdImagePtr dst, gdImagePtr src);
00157 void gdImagePng(gdImagePtr im, FILE *out);
00158 void gdImagePngCtx(gdImagePtr im, gdIOCtx *out);
00159 
00160 /* A custom data sink. */
00161 /* The sink function must return -1 on error, otherwise the number
00162         of bytes written, which must be equal to len. */
00163 /* context will be passed to your sink function. */
00164 typedef struct {
00165         int (*sink) (void *context, const char *buffer, int len);
00166         void *context;
00167 } gdSink, *gdSinkPtr;
00168 
00169 void gdImagePngToSink(gdImagePtr im, gdSinkPtr out);
00170 
00171 void gdImageGd(gdImagePtr im, FILE *out);
00172 void gdImageGd2(gdImagePtr im, FILE *out, int cs, int fmt);
00173 void* gdImagePngPtr(gdImagePtr im, int *size);
00174 void* gdImageGdPtr(gdImagePtr im, int *size);
00175 void* gdImageGd2Ptr(gdImagePtr im, int cs, int fmt, int *size);
00176 void gdImageArc(gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color);
00177 void gdImageFillToBorder(gdImagePtr im, int x, int y, int border, int color);
00178 void gdImageFill(gdImagePtr im, int x, int y, int color);
00179 void gdImageCopy(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h);
00180 void gdImageCopyMerge(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, 
00181                         int srcX, int srcY, int w, int h, int pct);
00182 void gdImageCopyMergeGray(gdImagePtr dst, gdImagePtr src, int dstX, int dstY,
00183                         int srcX, int srcY, int w, int h, int pct);
00184 
00185 /* Stretches or shrinks to fit, as needed */
00186 void gdImageCopyResized(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH);
00187 void gdImageSetBrush(gdImagePtr im, gdImagePtr brush);
00188 void gdImageSetTile(gdImagePtr im, gdImagePtr tile);
00189 void gdImageSetStyle(gdImagePtr im, int *style, int noOfPixels);
00190 /* On or off (1 or 0) */
00191 void gdImageInterlace(gdImagePtr im, int interlaceArg);
00192 
00193 /* Macros to access information about images. READ ONLY. Changing
00194         these values will NOT have the desired result. */
00195 #define gdImageSX(im) ((im)->sx)
00196 #define gdImageSY(im) ((im)->sy)
00197 #define gdImageColorsTotal(im) ((im)->colorsTotal)
00198 #define gdImageRed(im, c) ((im)->red[(c)])
00199 #define gdImageGreen(im, c) ((im)->green[(c)])
00200 #define gdImageBlue(im, c) ((im)->blue[(c)])
00201 #define gdImageGetTransparent(im) ((im)->transparent)
00202 #define gdImageGetInterlaced(im) ((im)->interlace)
00203 
00204 /* I/O Support routines. */
00205 
00206 gdIOCtx* gdNewFileCtx(FILE*);
00207 gdIOCtx* gdNewDynamicCtx(int, void*);
00208 gdIOCtx* gdNewSSCtx(gdSourcePtr in, gdSinkPtr out);
00209 void* gdDPExtractData(struct gdIOCtx* ctx, int *size);
00210 
00211 
00212 #define GD2_CHUNKSIZE           128 
00213 #define GD2_CHUNKSIZE_MIN       64
00214 #define GD2_CHUNKSIZE_MAX       4096
00215 
00216 #define GD2_VERS                1
00217 #define GD2_ID                  "gd2"
00218 #define GD2_FMT_RAW             1
00219 #define GD2_FMT_COMPRESSED      2
00220 
00221 /* Image comparison definitions */
00222 int gdImageCompare(gdImagePtr im1, gdImagePtr im2);
00223 
00224 #define GD_CMP_IMAGE            1       /* Actual image IS different */
00225 #define GD_CMP_NUM_COLORS       2       /* Number of Colours in pallette differ */
00226 #define GD_CMP_COLOR            4       /* Image colours differ */
00227 #define GD_CMP_SIZE_X           8       /* Image width differs */
00228 #define GD_CMP_SIZE_Y           16      /* Image heights differ */
00229 #define GD_CMP_TRANSPARENT      32      /* Transparent colour */
00230 #define GD_CMP_BACKGROUND       64      /* Background colour */
00231 #define GD_CMP_INTERLACE        128     /* Interlaced setting */
00232 
00233 #ifdef __cplusplus
00234 }
00235 #endif
00236 
00237 #endif /* GD_H */

Generated on Sun Mar 12 23:56:30 2006 for ScriptBasic by  doxygen 1.4.6-NO